Skip to contentSkip to conversation

Add test message agent

PATCH New Aki Niemi 1 participant 1 message Sep 9, 2010

lore
Share & tools
lore

Aki Niemi

author
#0 lore raw

PATCH v3 6/6 Add test message agent

---
 test/sms-agent |   84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 84 insertions(+), 0 deletions(-)
 create mode 100755 test/sms-agent
test/sms-agent new file +84 -0
new file mode 100755
index 0000000..2fea2a6
@@ -0,0 +1,84 @@
+#!/usr/bin/python
+
+import gobject
+
+import sys
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+
+class SmsAgent(dbus.service.Object):
+
+	def __init__(self, bus, path):
+		dbus.service.Object.__init__(self, bus, path)
+
+		print "Started agent %s at %s" % (bus, path)
+
+	@dbus.service.method("org.ofono.MessageAgent",
+				in_signature="", out_signature="")
+	def Release(self):
+		print "Release, quitting"
+		mainloop.quit()
+
+	@dbus.service.method("org.ofono.MessageAgent",
+				in_signature="sa{sv}", out_signature="")
+	def HandleMessage(self, message, props):
+		print "From: %s" % props["Sender"]
+		print "SentTime: %s" % props["SentTime"]
+		print "LocalSentTime: %s" % props["LocalSentTime"]
+		print "Text: %s" % message
+
+	@dbus.service.method("org.ofono.MessageAgent",
+					in_signature="aya{sv}", out_signature="")
+	def HandleDatagram(self, data, props):
+		print "From: %s" % props["Sender"]
+		try:
+			print "ContentType: %s" % props["ContentType"]
+		except KeyError:
+			print "DestinationPort: %s" % props["DestinationPort"]
+
+		print "SourcePort: %d" % props["SourcePort"]
+		print "SentTime: %s" % props["SentTime"]
+		print "LocalSentTime: %s" % props["LocalSentTime"]
+		print "Size: %d bytes" % len(data)
+
+		outstr = u''
+		for byte in data:
+			if byte > 128:
+				outstr += '?'
+			else:
+				outstr += chr(byte)
+
+		print outstr
+
+if __name__ == '__main__':
+	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+	if len(sys.argv) < 2:
+		print "Usage: %s <media_type>" % sys.argv[0]
+		sys.exit(1)
+
+	bus = dbus.SystemBus()
+	manager = dbus.Interface(bus.get_object("org.ofono", "/"),
+						"org.ofono.Manager")
+
+	properties = manager.GetProperties()
+
+	for path in properties["Modems"]:
+		modem = dbus.Interface(bus.get_object('org.ofono', path),
+							'org.ofono.Modem')
+
+		properties = modem.GetProperties()
+
+		if "org.ofono.MessageManager" not in properties["Interfaces"]:
+			continue
+
+		sms = dbus.Interface(bus.get_object('org.ofono', path),
+					'org.ofono.MessageManager')
+
+	path = "/test/agent"
+	agent = SmsAgent(bus, path)
+	sms.RegisterAgent(path, sys.argv[1])
+
+	mainloop = gobject.MainLoop()
+	mainloop.run()
Signature · 1 line
1.7.0.4