summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevron Rees <tripzero.kev@gmail.com>2014-12-24 00:24:15 -0800
committerKevron Rees <tripzero.kev@gmail.com>2014-12-24 00:24:15 -0800
commit4760463776f087028f77a0fe00548fd825dab179 (patch)
tree12245417bd6cae114e84770d04866d9632a13e50
parentc6b73df909bcf61fc6f5ae19cd9a693d55e69651 (diff)
downloadautomotive-message-broker-4760463776f087028f77a0fe00548fd825dab179.tar.gz
ambctl can read input from user
-rw-r--r--plugins/database/basedb.hpp2
-rw-r--r--tools/ambctl.py181
2 files changed, 98 insertions, 85 deletions
diff --git a/plugins/database/basedb.hpp b/plugins/database/basedb.hpp
index 353b3284..4d6a1296 100644
--- a/plugins/database/basedb.hpp
+++ b/plugins/database/basedb.hpp
@@ -87,7 +87,7 @@ public:
if(! db->Connected())
{
DebugOut(0)<<"BaseDB: database not found "<<dbname<<endl;
- throw -1;
+ return;
}
q = new sqlitequery();
diff --git a/tools/ambctl.py b/tools/ambctl.py
index e3850645..e61d6c24 100644
--- a/tools/ambctl.py
+++ b/tools/ambctl.py
@@ -5,101 +5,114 @@ import dbus
import sys
import json
import gobject
+import fileinput
from dbus.mainloop.glib import DBusGMainLoop
def changed(interface, properties, invalidated):
print json.dumps(properties, indent=2)
-parser = argparse.ArgumentParser(description='Process DBus mappings.')
-parser.add_argument('command', metavar='COMMAND [help]', help='amb dbus command')
+def processCommand(command, commandArgs):
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+ bus = dbus.SystemBus()
+ managerObject = bus.get_object("org.automotive.message.broker", "/");
+ managerInterface = dbus.Interface(managerObject, "org.automotive.Manager")
-parser.add_argument('commandArgs', metavar='ARG', nargs='*',
- help='amb dbus command arguments')
+ if command == "list" :
+ supportedList = managerInterface.List();
+ for objectName in supportedList:
+ print objectName
+ return 1
+ elif command == "get":
+ if commandArgs[0] == "help":
+ print "ObjectName [ObjectName...]"
+ return 1
-args = parser.parse_args()
+ for objectName in commandArgs:
+ objects = managerInterface.FindObject(objectName);
+ print objectName
+ for o in objects:
+ propertiesInterface = dbus.Interface(bus.get_object("org.automotive.message.broker", o),"org.freedesktop.DBus.Properties")
+ print json.dumps(propertiesInterface.GetAll("org.automotive."+objectName), indent=2)
+ return 1
+ elif command == "listen":
+ if commandArgs[0] == "help":
+ print "ObjectName [ObjectName...]"
+ return 1
+ for objectName in commandArgs:
+ objects = managerInterface.FindObject(objectName);
+ for o in objects:
+ bus.add_signal_receiver(changed,
+ dbus_interface="org.freedesktop.DBus.Properties",
+ signal_name="PropertiesChanged", path=o)
+ loop = gobject.MainLoop()
+ loop.run()
+
+ elif command == "set":
+ if commandArgs[0] == "help":
+ print "ObjectName PropertyName VALUE [ZONE]"
+ return 1
+ if len(commandArgs) < 3:
+ print "set requires more arguments (see set help)"
+ return 1
+ objectName = commandArgs[0]
+ propertyName = commandArgs[1]
+ value = commandArgs[2]
+ zone = 0
+ if len(commandArgs) == 4:
+ zone = int(commandArgs[3])
+ object = managerInterface.FindObjectForZone(objectName, zone)
+ propertiesInterface = dbus.Interface(bus.get_object("org.automotive.message.broker", object),"org.freedesktop.DBus.Properties")
+ property = propertiesInterface.Get("org.automotive."+objectName, propertyName)
+ realValue = property.__class__(value)
+ propertiesInterface.Set("org.automotive."+objectName, propertyName, realValue)
+ property = propertiesInterface.Get("org.automotive."+objectName, propertyName)
+ if property == realValue:
+ print propertyName + " = ", property
+ else:
+ print "Error setting property"
+ return 1
+ elif command == "getHistory":
+ if commandArgs[0] == "help":
+ print "ObjectName [STARTTIME] [ENDTIME] [ZONE]"
+ return 1
+ if len(commandArgs) < 1:
+ print "getHistory requires more arguments (see getHistory help)"
+ return 1
+ objectName = commandArgs[0]
+ start = 1
+ if len(commandArgs) >= 2:
+ start = float(commandArgs[1])
+ end = 9999999999
+ if len(commandArgs) >= 3:
+ end = float(commandArgs[2])
+ zone = 0
+ if len(commandArgs) == 4:
+ zone = int(commandArgs[3])
+ 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)
+ else:
+ print "unknown command"
+ return 1
-dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-bus = dbus.SystemBus()
-managerObject = bus.get_object("org.automotive.message.broker", "/");
-managerInterface = dbus.Interface(managerObject, "org.automotive.Manager")
-if args.command == "list" :
- supportedList = managerInterface.List();
- for objectName in supportedList:
- print objectName
- sys.exit()
-elif args.command == "get":
- if args.commandArgs[0] == "help":
- print "ObjectName [ObjectName...]"
- sys.exit()
+parser = argparse.ArgumentParser(description='Process DBus mappings.')
+parser.add_argument('command', metavar='COMMAND [help]', nargs='?', default='stdin', help='amb dbus command')
- for objectName in args.commandArgs:
- objects = managerInterface.FindObject(objectName);
- print objectName
- for o in objects:
- propertiesInterface = dbus.Interface(bus.get_object("org.automotive.message.broker", o),"org.freedesktop.DBus.Properties")
- print json.dumps(propertiesInterface.GetAll("org.automotive."+objectName), indent=2)
- sys.exit()
+parser.add_argument('commandArgs', metavar='ARG', nargs='*',
+ help='amb dbus command arguments')
-elif args.command == "listen":
- if args.commandArgs[0] == "help":
- print "ObjectName [ObjectName...]"
- sys.exit()
- for objectName in args.commandArgs:
- objects = managerInterface.FindObject(objectName);
- for o in objects:
- bus.add_signal_receiver(changed,
- dbus_interface="org.freedesktop.DBus.Properties",
- signal_name="PropertiesChanged", path=o)
-elif args.command == "set":
- if args.commandArgs[0] == "help":
- print "ObjectName PropertyName VALUE [ZONE]"
- sys.exit()
- if len(args.commandArgs) < 3:
- print "set requires more arguments (see set help)"
- sys.exit()
- objectName = args.commandArgs[0]
- propertyName = args.commandArgs[1]
- value = args.commandArgs[2]
- zone = 0
- if len(args.commandArgs) == 4:
- zone = int(args.commandArgs[3])
- object = managerInterface.FindObjectForZone(objectName, zone)
- propertiesInterface = dbus.Interface(bus.get_object("org.automotive.message.broker", object),"org.freedesktop.DBus.Properties")
- property = propertiesInterface.Get("org.automotive."+objectName, propertyName)
- realValue = property.__class__(value)
- propertiesInterface.Set("org.automotive."+objectName, propertyName, realValue)
- property = propertiesInterface.Get("org.automotive."+objectName, propertyName)
- if property == realValue:
- print propertyName + " = ", property
- else:
- print "Error setting property"
- sys.exit()
-elif args.command == "getHistory":
- if args.commandArgs[0] == "help":
- print "ObjectName [STARTTIME] [ENDTIME] [ZONE]"
- sys.exit()
- if len(args.commandArgs) < 1:
- print "getHistory requires more arguments (see getHistory help)"
- sys.exit()
- objectName = args.commandArgs[0]
- start = 1
- if len(args.commandArgs) >= 2:
- start = float(args.commandArgs[1])
- end = 9999999999
- if len(args.commandArgs) >= 3:
- end = float(args.commandArgs[2])
- zone = 0
- if len(args.commandArgs) == 4:
- zone = int(args.commandArgs[3])
+args = parser.parse_args()
- 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)
- sys.exit()
+if args.command == "stdin":
+ while True:
+ line = raw_input("ambctl>> ")
+ if line == 'quit':
+ sys.exit()
+ words = line.split(' ')
+ print words[1:]
+ processCommand(words[0], words[1:])
else:
- print "unknown command"
- sys.exit()
-loop = gobject.MainLoop()
-loop.run()
+ processCommand(args.command, args.commandArgs)
+