powerguru-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Powerguru-commit] [SCM] powerguru branch, master, updated. f28ea9df835d


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. f28ea9df835df10a6ff9f4c21d42b831cd6fb9d7
Date: Tue, 11 Dec 2018 19:48:05 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "powerguru".

The branch, master has been updated
       via  f28ea9df835df10a6ff9f4c21d42b831cd6fb9d7 (commit)
       via  fea54bc34561b147f82414dd01a8c09eabd7bd23 (commit)
      from  ccab3b99a9b1a2aec91a40103ac5a5c85c2b3445 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=f28ea9df835df10a6ff9f4c21d42b831cd6fb9d7


commit f28ea9df835df10a6ff9f4c21d42b831cd6fb9d7
Author: Rob Savoye <address@hidden>
Date:   Tue Dec 11 17:47:57 2018 -0700

    Add thread support

diff --git a/client/cmd.cc b/client/cmd.cc
index 4b4a7e4..530dff8 100644
--- a/client/cmd.cc
+++ b/client/cmd.cc
@@ -33,44 +33,29 @@
 #include <sys/types.h>
 #include <cstdio>
 #include <iostream>
-// #ifdef HAVE_LIBXML
-// # include <libxml/encoding.h>
-// # include <libxml/xmlwriter.h>
-// # include <libxml/debugXML.h>
-// #endif
-//#include "xml.h"
+#include <thread>
+#include <mutex>
+#include <condition_variable>
 #include "tcpip.h"
 #include "console.h"
 #include "msgs.h"
 #include "log.h"
+#include "tcpip.h"
 #include "ownet.h"
 
-using namespace std;
-//using namespace pdev;
-
 extern LogFile dbglogfile;
 static void usage (const char *);
 
 const int INBUFSIZE = 1024;
-namespace pdev {
-class Ownet;
-}
+extern void daemon_handler(Tcpip &net);
+extern void console_handler(Tcpip &net);
 
 int
 main(int argc, char *argv[])
 {
     int         c;
-    string      filespec;
-    bool        client;
-    bool        daemon;
-    string      hostname;
-    string      user;
-    string      passwd;
-    char        *ptr;
+    std::string      hostname = "localhost";
     retcode_t   ret;
-    client = false;
-    daemon = false;
-    hostname = "localhost";
 
     // scan for the two main standard GNU options
     for (c=0; c<argc; c++) {
@@ -79,12 +64,12 @@ main(int argc, char *argv[])
             exit(0);
         }
         if (strcmp("--version", argv[c]) == 0) {
-            cerr << "PowerGuru version: " << VERSION << endl;
+            std::cerr << "PowerGuru version: " << VERSION << std::endl;
             exit(0);
         }
     }
     
-    while ((c = getopt (argc, argv, "hvdcm:u:p:V")) != -1) {
+    while ((c = getopt (argc, argv, "hvm:u:p:V")) != -1) {
         switch (c) {
           case 'h':
               usage (argv[0]);
@@ -98,57 +83,23 @@ main(int argc, char *argv[])
               hostname = strdup(optarg);
               break;
         
-              // Specify database user name.
-          case 'u': 
-              user = strdup(optarg);
-              break;
-        
-              // Specify database user password.
-          case 'p':
-              passwd = strdup(optarg);
-              break;   
-        
-          case 'c':
-              client = true;
-              daemon = false;
-              break;   
-        
           case 'V':
-              cerr << "PowerGuru version " << VERSION << endl;
+              std::cerr << "PowerGuru version " << VERSION << std::endl;
               exit (0);
               break;   
         
-          case 'd':
-              client = false;
-              daemon = true;
-              break;   
-        
           default:
               usage (argv[0]);
               break;
         }
     }
-    
-    // get the file name from the command line
-    if (optind < argc) {
-        filespec = argv[optind];
-        dbglogfile << "Will use \"" << filespec << "\" for test " << endl;
-    }
-
-    //    Tcpip tcpip;
-    Console con;
-    int ch;
-
-    //    tcpip.toggleDebug(true);
-
-    // Open a console for user input
-    con.Open();
 
-    char *buffer;
-    buffer = (char *)new char[INBUFSIZE];
-    memset(buffer, 0, INBUFSIZE);
-    Msgs msg;
+    Tcpip net;
+    net.createNetClient(DEFAULTPORT);
+    std::thread first (daemon_handler, std::ref(net));
 
+#ifdef BUILD_OWNET_XXXXX
+    // Talk directly to the OW daemon
     pdev::Ownet ownet;
     if (ownet.isConnected()) {
         if (ownet.hasSensors()) {
@@ -158,169 +109,27 @@ main(int argc, char *argv[])
             dbglogfile << "and has no sensors attached" << std::endl;
         }
     }
-
-    if (client == true || daemon == true) {
-#if 0
-        cerr << "\rWelcome " << tcpip.remoteName()
-             << " at IP address: " << tcpip.remoteIP() << endl;
-        cerr << msg.status((meter_data_t *)0) << endl;
 #endif
-        msg.toggleDebug(true);
-        std::cout << "Client or daemon not specified. exiting..." << std::endl;
-        exit(0);
-    }
-    //con.Puts("FIXME1\n");
-
-    // Make a client connection
-    if (client == true) {
-        ret = msg.init(hostname);
-        if (ret == ERROR) {
-            dbglogfile << "BARF" << std::endl;
-        }
-        msg.checkConsole();
-    }
-
-    // Start as a daemon
-    if (daemon == true) {
-        ret = msg.init(true);
-        if (ret == ERROR) {
-            dbglogfile << "BARF" << std::endl;
-        }
-    }
-    //msg.methodsDump();          // FIXME: debugging crap
-    
-    //msg.print_msg(msg.status((meter_data_t *)0));
 
-//    if (client) {
-//        msg.writeNet(msg.metersRequestCreate(Msgs::BATTERY_VOLTS));
-//    }
+    std::thread second (console_handler, std::ref(net));
 
-    // msg.cacheDump();
-    
-    while ((ch = con.Getc()) != 'q') {
-        if (ch > 0) {                // If we have something, process it
-            //con.Putc (ch);          // echo inputted character to screen
-        
-            switch (ch) {
-                // Toggle the DTR state, which is as close as we get to
-                // flow control.
-//               case 's':
-//                   if (client) {
-// #if 0
-//                       //sleep(1);
-//                       
msg.writeNet(msg.metersRequestCreate(Msgs::AC1_VOLTS_IN));
-//                       //sleep(1);
-//                       
msg.writeNet(msg.metersRequestCreate(Msgs::CHARGE_AMPS));
-//                       //sleep(1);
-//                       
msg.writeNet(msg.metersRequestCreate(Msgs::AC_LOAD_AMPS));
-//                       //sleep(1);
-//                       
msg.writeNet(msg.metersRequestCreate(Msgs::PV_AMPS_IN));
-//                       //sleep(1);
-//                       
msg.writeNet(msg.metersRequestCreate(Msgs::SELL_AMPS));
-//                       //            msg.writeNet(msg.requestCreate(""));
-// #else            
-//                       msg.writeNet(msg.requestCreate(Msgs::REVISION));
-//                       msg.writeNet(msg.requestCreate(Msgs::SYSVERSION));
-//                       msg.writeNet(msg.requestCreate(Msgs::OPMODE));
-//                       msg.writeNet(msg.requestCreate(Msgs::WARNINGMODE));
-//                       msg.writeNet(msg.requestCreate(Msgs::ERRORMODE));
-// #endif
-//                   }
-//                   break;
-              case 'Q':
-              case 'q':
-                  con.Puts("Qutting PowerGuru due to user input!\n");
-                  msg.writeNet("quit");
-                  con.Reset();
-                  exit(0);
-                  break;
-              case '?':
-                  con.Puts("PowerGuru client\n");
-                  con.Puts("\t? - help\r\n");
-                  con.Puts("\tq - Quit\r\n");
-                  con.Puts("\tQ - Quit\r\n");
-                  sleep(2);
-              default:
-                  break;
-            };
-        }
+    first.join();                // pauses until second finishes
+    second.join();                // pauses until second finishes
 
-        XML xml;
-        unsigned int i;
-        memset(buffer, 0, INBUFSIZE);
-#if 1
-        if (client == true || daemon == true) {
-            vector<const xmlChar *> messages;
-            //const xmlChar *messages[200];
-            ret = msg.anydata(messages);
-            
-            if (ret == ERROR) {
-                dbglogfile << "ERROR: Got error from socket " << endl;
-                // Start as a daemon
-                if (daemon == true) {
-                    msg.closeNet();
-                    // wait for the next connection
-                    if (msg.newNetConnection(true)) {
-                        dbglogfile << "New connection started for remote 
client." << endl;
-                    }
-                } else {
-                    if (errno != EAGAIN) {
-                        dbglogfile << "ERROR: " << errno << ":\t"<< 
strerror(errno) << endl;
-                        msg.closeNet();
-                        exit (-1);
-                    }
-                }
-            }
-            for (i=0; i < messages.size(); i++) {
-                cerr << "Got message " << messages[i] << endl;
-                string str = (const char *)messages[i];
-                delete messages[i];
-                if (xml.parseXML(str) == ERROR) {
-                    continue;
-                }
-            }
-            messages.clear();
-            msg.cacheDump();
-        }
-#else
-        ptr = buffer;
-        int bytes = msg.readNet(buffer, INBUFSIZE, 0);      
-        if (bytes > 0) {
-            while (ptr != NULL) {
-                if (ptr != buffer) {
-                    ptr++;
-                }
-                // We're at the end of the messages
-                if (strlen(ptr) == 0) {
-                    break;
-                }
-                if (xml.parseXML(ptr) == false) {
-                    break;
-                }
-                if (strncmp(buffer, "quit", 4) == 0) {
-                    exit(0);
-                }
-                ptr = strchr(ptr, '\0');
-            }
-        }
+#ifdef BUILD_OWNET
+    //third.join();                // pauses until second finishes
 #endif
-    }
-    //con.Close();
+
 }
 
 static void
 usage (const char *prog)
 {
-    cerr << "This is a simple cmmand line for the PowerGuru daemon." << endl;
-    cerr << "Usage: pguru: [h] filename" << endl;
-    //    cerr << "Usage: " << prog << ": [h] filename" << endl;
-    cerr << "-h\tHelp" << endl;
-    cerr << "-v\tVerbose output" << endl;
-    cerr << "-d\tDaemon Mode" << endl;
-    cerr << "-c\tClient Mode (default)" << endl;
-    cerr << "-m\tRemote Machine (localhost)" << endl;
-    cerr << "-u\tRemote Machine user" << endl;
-    cerr << "-p\tRemote Machine password" << endl;
+    std::cerr << "This is a simple command line for the PowerGuru daemon." << 
std::endl;
+    std::cerr << "Usage: pguru: [h] filename" << std::endl;
+    std::cerr << "-h\tHelp" << std::endl;
+    std::cerr << "-v\tVerbose output" << std::endl;
+    std::cerr << "-m\tDatabase Host(localhost)" << std::endl;
     exit (-1);
 }
 

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=fea54bc34561b147f82414dd01a8c09eabd7bd23


commit fea54bc34561b147f82414dd01a8c09eabd7bd23
Author: Rob Savoye <address@hidden>
Date:   Tue Dec 11 17:47:31 2018 -0700

    Add -lpthread

diff --git a/client/Makefile.am b/client/Makefile.am
index b86607f..a6d72fc 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -23,8 +23,8 @@ bin_PROGRAMS = pguru
 
 pguru_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)/devices
 
-pguru_SOURCES = cmd.cc
-pguru_LDADD = ../lib/libpguru.la -ldl
+pguru_SOURCES = cmd.cc threads.cc
+pguru_LDADD = ../lib/libpguru.la -lpthread -ldl
 
 if BUILD_LIBXML
 pguru_CPPFLAGS += $(LIBXML_CPPFLAGS)

-----------------------------------------------------------------------

Summary of changes:
 client/Makefile.am |   4 +-
 client/cmd.cc      | 243 ++++++-----------------------------------------------
 2 files changed, 28 insertions(+), 219 deletions(-)


hooks/post-receive
-- 
powerguru



reply via email to

[Prev in Thread] Current Thread [Next in Thread]