[ambctl] - enablePlugin command
authorKevron Rees <kevron.m.rees@intel.com>
Fri, 9 Jan 2015 22:07:55 +0000 (14:07 -0800)
committerKevron Rees <kevron.m.rees@intel.com>
Fri, 9 Jan 2015 22:07:55 +0000 (14:07 -0800)
CMakeLists.txt
ambd/CMakeLists.txt
ambd/config.in [deleted file]
ambd/config.in.json [new file with mode: 0644]
plugins/CMakeLists.txt
plugins/dbus/CMakeLists.txt
plugins/dbus/dbus.in.json [new file with mode: 0644]
plugins/examplesink.in.json [new file with mode: 0644]
plugins/examplesource.in.json [new file with mode: 0644]
tools/ambctl.py

index 43d79db..1aeb717 100644 (file)
@@ -22,6 +22,7 @@ set (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/${CMAKE_LIBRARY_A
 set (PLUGIN_INSTALL_PATH "${LIB_INSTALL_DIR}/${PROJECT_NAME}")
 set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include")
 set (DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/packages/${PROJECT_NAME}")
+set (PLUGIN_SEGMENT_INSTALL_PATH "/etc/ambd/plugins.d")
 
 option(qtmainloop "Use QCoreApplication mainloop " OFF)
 option(websocket_plugin "websocket source and sink plugins" OFF)
index d1af565..3ca9eda 100644 (file)
@@ -34,7 +34,7 @@ add_executable(ambd ${ambd_sources})
 include_directories(${include_dirs} )
 target_link_libraries(ambd ${link_libraries} dl amb)
 
-configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.in ${CMAKE_CURRENT_BINARY_DIR}/config @ONLY)
+configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.in.json ${CMAKE_CURRENT_BINARY_DIR}/config @ONLY)
 
 install (TARGETS ambd RUNTIME DESTINATION bin)
 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/config DESTINATION /etc/ambd)
diff --git a/ambd/config.in b/ambd/config.in
deleted file mode 100644 (file)
index 850ec78..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-{
-  "sources" : [
-    {
-      "name" : "ExampleSouce",
-      "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so"
-    }
-  ],
-  "sinks": [
-    {
-      "name" : "ExampleSink",
-      "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so"
-    },
-    {
-      "name" : "DBusSink",
-      "path" : "@PLUGIN_INSTALL_PATH@/dbussinkplugin.so"
-    }
-  ]
-}
-
diff --git a/ambd/config.in.json b/ambd/config.in.json
new file mode 100644 (file)
index 0000000..1e17508
--- /dev/null
@@ -0,0 +1,6 @@
+{
+       "plugins" : "@PLUGIN_SEGMENT_INSTALL_PATH@",
+       "sources" : [   ],
+       "sinks": [      ]
+}
+
index 4580266..32a41be 100644 (file)
@@ -21,7 +21,12 @@ install(TARGETS examplesourceplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH})
 
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/exampleplugins.README.txt ${CMAKE_CURRENT_BINARY_DIR}/exampleplugins.README @ONLY)
 
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/examplesource.in.json ${CMAKE_CURRENT_BINARY_DIR}/examplesource @ONLY)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/examplesink.in.json ${CMAKE_CURRENT_BINARY_DIR}/examplesink @ONLY)
+
 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/exampleplugins.README DESTINATION ${DOC_INSTALL_DIR}/plugins)
+install (FILES ${CMAKE_CURRENT_BINARY_DIR}/examplesource DESTINATION ${PLUGIN_SEGMENT_INSTALL_PATH})
+install (FILES ${CMAKE_CURRENT_BINARY_DIR}/examplesink DESTINATION ${PLUGIN_SEGMENT_INSTALL_PATH})
 
 add_subdirectory(common)
 
index 67d6ba6..c4e6fef 100644 (file)
@@ -25,8 +25,10 @@ set(dbus_mapping_headers ${dbus_mapping_headers} ${CMAKE_CURRENT_SOURCE_DIR}/par
 set(dbus_mapping_headers ${dbus_mapping_headers} ${CMAKE_CURRENT_SOURCE_DIR}/drivingsafety.h CACHE INTERNAL "dbus mapping headers")
 set(dbus_mapping_headers ${dbus_mapping_headers} ${CMAKE_CURRENT_SOURCE_DIR}/personalization.h CACHE INTERNAL "dbus mapping headers")
 
-
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README ${CMAKE_CURRENT_BINARY_DIR}/dbus.README @ONLY)
 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/dbus.README DESTINATION ${DOC_INSTALL_DIR}/plugins)
 
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/dbus.in.json ${CMAKE_CURRENT_BINARY_DIR}/dbus @ONLY)
+install (FILES ${CMAKE_CURRENT_BINARY_DIR}/dbus DESTINATION ${PLUGIN_SEGMENT_INSTALL_PATH})
+
 add_subdirectory(amb-qt)
diff --git a/plugins/dbus/dbus.in.json b/plugins/dbus/dbus.in.json
new file mode 100644 (file)
index 0000000..c924d6c
--- /dev/null
@@ -0,0 +1,6 @@
+{
+       "name" : "DBusSink",
+       "path" : "@PLUGIN_INSTALL_PATH@/dbussinkplugin.so",
+       "frequency" : "30",
+       "enabled" : true
+}
diff --git a/plugins/examplesink.in.json b/plugins/examplesink.in.json
new file mode 100644 (file)
index 0000000..254ce54
--- /dev/null
@@ -0,0 +1,6 @@
+{
+       "name" : "ExampleSink",
+       "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so",
+       "frequency" : "30",
+       "enabled" : true
+}
diff --git a/plugins/examplesource.in.json b/plugins/examplesource.in.json
new file mode 100644 (file)
index 0000000..5a9680a
--- /dev/null
@@ -0,0 +1,6 @@
+{
+       "name" : "ExampleSouce",
+       "path" : "@PLUGIN_INSTALL_PATH@/examplesourceplugin.so",
+       "delay" : "6",
+       "enabled" : true
+}
index 581f106..0de96a1 100644 (file)
@@ -41,6 +41,7 @@ class Autocomplete:
                self.commands.append(Autocomplete.Cmd('listen', 'Listen for changes on an ObjectName'))
                self.commands.append(Autocomplete.Cmd('set', 'Set a property for an ObjectName'))
                self.commands.append(Autocomplete.Cmd('getHistory', 'Get logged data within a time range'))
+               self.commands.append(Autocomplete.Cmd('enablePlugin', 'Get logged data within a time range'))
                self.commands.append(Autocomplete.Cmd('quit', 'Exit ambctl'))
 
                bus = dbus.SystemBus()
@@ -89,6 +90,38 @@ def help():
 def changed(interface, properties, invalidated):
        print json.dumps(properties, indent=2)
 
+def listPlugins():
+       list = {}
+       for root, dirs, files in os.walk('@PLUGIN_SEGMENT_INSTALL_PATH@'):
+               for file in files:
+                       fullpath = root + "/" + file;
+                       pluginFile = open(fullpath)
+                       data = json.load(pluginFile)
+                       pluginFile.close()
+                       list.update({data["name"]:fullpath})
+
+       return list
+
+def enablePlugin(pluginName, enabled):
+       list = listPlugins()
+       if pluginName not in list:
+               return false
+
+       path = list[pluginName]
+       try :
+               file = open(path, 'rw+')
+               data = json.load(file)
+               data["enabled"] = enabled;
+               fixedData = json.JSONEncoder().encode(data)
+               file.truncate(0)
+               file.write(fixedData)
+               file.close()
+       except IOError, error:
+               print error
+       except:
+               print "Unknown error"
+
+
 def processCommand(command, commandArgs, noMain=True):
 
        if command == 'help':
@@ -189,6 +222,22 @@ def processCommand(command, commandArgs, noMain=True):
                object = managerInterface.FindObjectForZone(objectName, zone);
                propertiesInterface = dbus.Interface(bus.get_object("org.automotive.message.broker", object),"org.automotive."+objectName)
                print json.dumps(propertiesInterface.GetHistory(start, end), indent=2)
+       elif command == "enablePlugin":
+               if len(commandArgs) == 0:
+                       commandArgs = ['help']
+               if commandArgs[0] == 'help':
+                       print "[list] [pluginName] [on/off]"
+                       return 1
+               elif commandArgs[0] == 'list':
+                       for name, path in listPlugins():
+                               print name
+                       return 1
+               else:
+                       if len(commandArgs) < 2:
+                               return 1
+                       enablePlugin(commandArgs[0], commandArgs[1] == "on")
+                       return 1
+
        else:
                print "Invalid command"
        return 1
@@ -404,8 +453,7 @@ if args.command == "stdin":
                                                                                row = ""
                                                                                endRow = -1
                                                                                if len(results) >= i+3:
-                                                                                       endRow = 3
-                                                                               print "endRow: ", endRow
+                                                                                       endRow = 2
                                                                                for col in results[i : endRow]:
                                                                                        row += col
                                                                                        for i in range((longestLen + 5) - len(col)):