added multisource test script in examples and added --log option 22/2522/1
authorKevron Rees <tripzero.kev@gmail.com>
Mon, 26 Nov 2012 21:40:05 +0000 (13:40 -0800)
committerKevron Rees <tripzero.kev@gmail.com>
Mon, 26 Nov 2012 21:40:05 +0000 (13:40 -0800)
ambd/main.cpp
examples/testmultiisource [new file with mode: 0755]
lib/debugout.cpp
lib/debugout.h

index b16edfc..2579c0f 100644 (file)
@@ -72,7 +72,7 @@ void daemonize();
 
 void printhelp(const char *argv0);
 
-static const char shortopts[] = "hvDc:d:";
+static const char shortopts[] = "hvDc:d:l:";
 
 static const struct option longopts[] = {
        { "help", no_argument, NULL, 'h' }, ///< Print the help text
@@ -80,6 +80,7 @@ static const struct option longopts[] = {
        { "daemonise", no_argument, NULL, 'D' }, ///< Daemonise
        { "config", required_argument, NULL, 'c' },
        { "debug", required_argument, NULL, 'd' },
+       { "log", required_argument, NULL, 'l' },
        { NULL, 0, NULL, 0 } ///< End
 };
 
@@ -90,6 +91,8 @@ int main(int argc, char **argv)
        int optc;
        int th = 0;
        string config="/etc/ambd/config";
+       ofstream logfile;
+       string logfn;
 
        while ((optc = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1)
        {
@@ -112,6 +115,9 @@ int main(int argc, char **argv)
                                th = atoi(optarg);
                                DebugOut::setDebugThreshhold(th);
                                break;
+                       case 'l':
+                               logfn = optarg;
+                               break;
                        default:
                                cerr<<"Unknown option "<<optc<<endl;
                                printhelp(argv[0]);
@@ -123,6 +129,12 @@ int main(int argc, char **argv)
        if(isdeamonize)
                daemonize();
        
+       if(!logfn.empty())
+       {
+               logfile.open(logfn, ios::out | ios::trunc);
+               DebugOut::setOutput(logfile);
+       }
+
        
 #ifdef USE_QT_CORE
 
@@ -159,6 +171,9 @@ int main(int argc, char **argv)
        
 #endif
        
+       if(logfile.is_open())
+               logfile.close();
+
        return 0;
 }
 
diff --git a/examples/testmultiisource b/examples/testmultiisource
new file mode 100755 (executable)
index 0000000..aa0b15c
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+
+numclients=$2
+config=$1
+
+#start initial ambd client:
+
+ambd -D -c $config -d5 -l host.output
+
+sleep 10
+
+for (( i=1; i<=$numclients; i++ ))
+do
+       ambd -D -c configwebsocketsource -d1 -l client.$i.output
+done
+
+sleep 60
+
+killall ambd
index 7635490..f766971 100644 (file)
@@ -21,7 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 using namespace std;
 
 int DebugOut::debugThreshhold = 0;
-ostream & DebugOut::out = cout;
+std::streambuf * DebugOut::buf = cout.rdbuf();
 
 void debugOut(string message)
 {
index 7985f05..8d598c4 100644 (file)
@@ -34,6 +34,8 @@ public:
                                
        DebugOut const& operator << (string message) const
        {
+               ostream out(buf);
+
                if(mDebugLevel <= debugThreshhold)
                         out<<message<<" ";
                return *this;
@@ -41,6 +43,8 @@ public:
 
        DebugOut const& operator << (ostream & (*manip)(std::ostream&)) const
        {
+               ostream out(buf);
+
                if(mDebugLevel <= debugThreshhold)
                         out<<endl;
                return *this;
@@ -48,6 +52,8 @@ public:
        
        DebugOut const & operator << (uint16_t val) const
        {
+               ostream out(buf);
+
                if(mDebugLevel <= debugThreshhold)
                         out<<val<<" ";
                return *this;
@@ -58,9 +64,14 @@ public:
                debugThreshhold = th;
        }
 
+       static void setOutput(ostream &o)
+       {
+               buf = o.rdbuf();
+       }
+
 private:
        static int debugThreshhold;
-       static ostream &out;
+       static std::streambuf *buf;
        int mDebugLevel;
 };