made awesome debugout
authorKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 12 Sep 2012 22:59:45 +0000 (15:59 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 12 Sep 2012 22:59:45 +0000 (15:59 -0700)
ambd/CMakeLists.txt
ambd/ambd.service [new file with mode: 0644]
ambd/main.cpp
lib/debugout.cpp
lib/debugout.h

index d301b61..76da6ba 100644 (file)
@@ -5,3 +5,4 @@ target_link_libraries(ambd ${link_libraries} amb)
 
 install (TARGETS ambd RUNTIME DESTINATION bin)
 install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/config DESTINATION /etc/ambd)
+install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/ambd.service DESTINATION /usr/lib/systemd/system)
diff --git a/ambd/ambd.service b/ambd/ambd.service
new file mode 100644 (file)
index 0000000..042a0d3
--- /dev/null
@@ -0,0 +1,17 @@
+#
+# ambd systemd service unit file
+#
+
+[Unit]
+Description=Automotive Message Broker
+After=syslog.target 
+
+[Service]
+Type=dbus
+ExecStart=/usr/bin/ambd 
+BusName=org.automotive
+
+[Install]
+WantedBy=multi-user.target
+
+
index 4902dfd..b16edfc 100644 (file)
@@ -45,6 +45,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include "pluginloader.h"
 #include "core.h"
+#include <debugout.h>
 
 using namespace std;
 
@@ -71,13 +72,14 @@ void daemonize();
 
 void printhelp(const char *argv0);
 
-static const char shortopts[] = "hvdc:";
+static const char shortopts[] = "hvDc:d:";
 
 static const struct option longopts[] = {
        { "help", no_argument, NULL, 'h' }, ///< Print the help text
        { "version", no_argument, NULL, 'v' }, ///< Print the version text
-       { "daemonise", no_argument, NULL, 'd' }, ///< Daemonise
+       { "daemonise", no_argument, NULL, 'D' }, ///< Daemonise
        { "config", required_argument, NULL, 'c' },
+       { "debug", required_argument, NULL, 'd' },
        { NULL, 0, NULL, 0 } ///< End
 };
 
@@ -86,13 +88,14 @@ int main(int argc, char **argv)
 
        bool isdeamonize=false;
        int optc;
+       int th = 0;
        string config="/etc/ambd/config";
-       
+
        while ((optc = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1)
        {
                switch (optc)
                {
-                       case 'd':
+                       case 'D':
                                isdeamonize = true;
                                break;
                                
@@ -105,6 +108,10 @@ int main(int argc, char **argv)
                                cout<<"Config: "<<optarg<<endl;
                                config=optarg;
                                break;
+                       case 'd':
+                               th = atoi(optarg);
+                               DebugOut::setDebugThreshhold(th);
+                               break;
                        default:
                                cerr<<"Unknown option "<<optc<<endl;
                                printhelp(argv[0]);
@@ -187,10 +194,11 @@ void daemonize()
 void printhelp(const char *argv0)
 {
        printf("Usage: %s [args]\n"
-       "   [-d|--daemonise]\n"
-       "   [-v|--version]\n"
-       "   [-c]--config </path/to/config> \t]\n"
-       "   [-h|--help]\n"
-       , argv0);
+                  "   [-D|--daemonise]\n"
+                  "   [-v|--version]\n"
+                  "   [-c|--config </path/to/config> \t]\n"
+                  "   [-d|--debug <level (0-5)>\t]\n"
+                  "   [-h|--help]\n"
+                  , argv0);
 }
 
index e49e907..7635490 100644 (file)
@@ -20,6 +20,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 using namespace std;
 
+int DebugOut::debugThreshhold = 0;
+ostream & DebugOut::out = cout;
+
 void debugOut(string message)
 {
        cout<<"DEBUG: "<<message<<endl;
index 8382d9a..7985f05 100644 (file)
@@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <string>
 #include <iostream>
+#include <fstream>
 
 using namespace std;
 
@@ -29,22 +30,38 @@ void debugOut(string message);
 class DebugOut 
 {
 public: 
-       DebugOut() { }
-       
-       DebugOut(string message)
+       DebugOut(int debugLevel = 4) { mDebugLevel = debugLevel; }
+                               
+       DebugOut const& operator << (string message) const
        {
-               debugOut(message);
+               if(mDebugLevel <= debugThreshhold)
+                        out<<message<<" ";
+               return *this;
        }
-               
-       ostream & operator << (string message)
+
+       DebugOut const& operator << (ostream & (*manip)(std::ostream&)) const
        {
-               return cout<<message<<" ";
+               if(mDebugLevel <= debugThreshhold)
+                        out<<endl;
+               return *this;
        }
        
-       ostream & operator << (uint16_t val)
+       DebugOut const & operator << (uint16_t val) const
+       {
+               if(mDebugLevel <= debugThreshhold)
+                        out<<val<<" ";
+               return *this;
+       }
+
+       static void setDebugThreshhold(int th)
        {
-               return cout<<val<<" ";
+               debugThreshhold = th;
        }
+
+private:
+       static int debugThreshhold;
+       static ostream &out;
+       int mDebugLevel;
 };