From c340f7d0aefc1f2287c370fa864012ed2379c426 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Sun, 21 Dec 2008 19:04:50 -0500 Subject: remove python server; it's no longer needed --- src/tests/exampleservice.py | 420 -------------------------------------------- 1 file changed, 420 deletions(-) delete mode 100755 src/tests/exampleservice.py diff --git a/src/tests/exampleservice.py b/src/tests/exampleservice.py deleted file mode 100755 index 9b13100..0000000 --- a/src/tests/exampleservice.py +++ /dev/null @@ -1,420 +0,0 @@ -#!/usr/bin/python - -import gobject - -import dbus -import dbus.service -import dbus.mainloop.glib - -class TestException(dbus.DBusException): - _dbus_error_name = 'com.example.TestException' - - -class TestService(dbus.service.Object): - - # $ dbus-send --session --print-reply --dest=com.example.TestService /com/example/TestService com.example.TestService.HelloWorld string:Hi! - @dbus.service.method("com.example.Frob", - in_signature='s', out_signature='s') - def HelloWorld(self, hello_message): - if str(hello_message) == 'Yo': - raise TestException('Yo is not a proper greeting') - else: - return "You greeted me with '%s'. Thanks!"%(str(hello_message)) - - # $ dbus-send --session --print-reply --dest=com.example.TestService /com/example/TestService com.example.TestService.TestPrimitiveTypes byte:1 boolean:false int16:160 uint16:161 int32:320 uint32:321 int64:640 uint64:641 double:4.5 string:foo objpath:/foo - @dbus.service.method("com.example.Frob", - in_signature='ybnqiuxtdso', out_signature='ybnqiuxtdso') - def TestPrimitiveTypes(self, val_byte, val_boolean, val_int16, val_uint16, val_int32, val_uint32, val_int64, val_uint64, val_double, val_string, val_objpath): - return val_byte + 1, not val_boolean, val_int16 + 1, val_uint16 + 1, val_int32 + 1, val_uint32 + 1, val_int64 + 1, val_uint64 + 1, -val_double, val_string * 2, val_objpath + "/modified" - - # $ dbus-send --session --print-reply --dest=com.example.TestService /com/example/TestService com.example.TestService.TestArrayOfPrimitiveTypes array:byte:1,2 array:boolean:false,true array:int16:160,170 array:uint16:161,171 array:int32:320,330 array:uint32:321,331 array:int64:640,650 array:uint64:641,651 array:double:4.5,5.5 array:string:foo,foo2 array:objpath:/foo,/foo2 - @dbus.service.method("com.example.Frob", - in_signature='ayabanaqaiauaxatadasao', out_signature='ayabanaqaiauaxatadasao') - def TestArrayOfPrimitiveTypes(self, val_byte, val_boolean, val_int16, val_uint16, val_int32, val_uint32, val_int64, val_uint64, val_double, val_string, val_objpath): - return val_byte*2, val_boolean*2, val_int16*2, val_uint16*2, val_int32*2, val_uint32*2, val_int64*2, val_uint64*2, val_double*2, val_string*2, val_objpath*2 - - # no support in dbus-send - @dbus.service.method("com.example.Frob", - in_signature='(ii)(s(ii))', out_signature='(ii)(s(ii))') - def TestStructureTypes(self, s1, s2): - (x, y) = s1; - (desc, (x1, y1)) = s2; - return (x + 1, y + 1), ("replaced desc", (x1 + 2, y1 + 2)) - - # no support in dbus-send - @dbus.service.method("com.example.Frob", - in_signature='a(s(ii)s)', out_signature='a(s(ii)s)') - def TestArrayOfStructureTypes(self, a): - r = [] - n = 0 - for i in a: - (d, (x, y), e) = i; - r.append(("%s_%d"%(d,n), (x + 1, y + 1), "%s_%d"%(e,n))) - n+=1 - return r - - # no support in dbus-send - @dbus.service.method("com.example.Frob", - in_signature = 'a{ss}a{oo}a{ii}a{yy}a{nn}a{qq}a{uu}a{bb}a{xx}a{tt}a{dd}', - out_signature = 'a{ss}a{oo}a{ii}a{yy}a{nn}a{qq}a{uu}a{bb}a{xx}a{tt}a{dd}') - def TestHashTables(self, hss, hoo, hii, hyy, hnn, hqq, huu, hbb, hxx, htt, hdd): - - ret_hss = {} - for i in hss: - ret_hss[i + "mod"] = hss[i]*2 - - ret_hoo = {} - for i in hoo: - ret_hoo[i + "/mod"] = hoo[i] + "/mod2" - - ret_hii = {} - for i in hii: - ret_hii[i*2] = hii[i]*3 - - ret_hyy = {} - for i in hyy: - ret_hyy[i*2] = (hyy[i]*3) & 255 - - ret_hnn = {} - for i in hnn: - ret_hnn[i*2] = hnn[i]*3 - - ret_hqq = {} - for i in hqq: - ret_hqq[i*2] = hqq[i]*3 - - ret_huu = {} - for i in huu: - ret_huu[i*2] = huu[i]*3 - - ret_hbb = {} - for i in hbb: - ret_hbb[i] = True - - ret_hxx = {} - for i in hxx: - ret_hxx[i + 2] = hxx[i] + 1 - - ret_htt = {} - for i in htt: - ret_htt[i + 2] = htt[i] + 1 - - ret_hdd = {} - for i in hdd: - ret_hdd[i + 2.5] = hdd[i] + 5.0 - - return ret_hss, ret_hoo, ret_hii, ret_hyy, ret_hnn, ret_hqq, ret_huu, ret_hbb, ret_hxx, ret_htt, ret_hdd - - # no support in dbus-send - @dbus.service.method("com.example.Frob", - in_signature = 'a{s(ii)}', - out_signature = 'a{s(s(ii))}') - def TestHashTableOfStructures(self, hash_of_points): - ret = {} - for s in hash_of_points: - (x, y) = hash_of_points[s] - ret[s + "_new"] = (s, (x + 100, y + 200)) - return ret - - # no support in dbus-send - @dbus.service.method("com.example.Frob", - in_signature = 'a{sas}a{sao}a{sai}a{say}a{san}a{saq}a{sau}a{sab}a{sax}a{sat}a{sad}a{sa(ii)}', - out_signature = 'a{sas}a{sao}a{sai}a{say}a{san}a{saq}a{sau}a{sab}a{sax}a{sat}a{sad}a{sa(ii)}') - def TestHashTablesOfArrays(self, hsas, hsao, hsai, hsay, hsan, hsaq, hsau, hsab, hsax, hsat, hsad, hash_of_point_arrays): - - ret_hsas = {} - for i in hsas: - ret_hsas[i] = hsas[i]*2 - - ret_hsao = {} - for i in hsao: - ret_hsao[i] = hsao[i]*2 - - ret_hsai = {"k" : [1, 2]} - ret_hsay = {"k" : [3, 4]} - ret_hsan = {"k" : [5, 6]} - ret_hsaq = {"k" : [7, 8]} - ret_hsau = {"k" : [9, 10]} - ret_hsab = {"k" : [True, False, True]} - ret_hsax = {"k" : [11, 12]} - ret_hsat = {"k" : [13, 14]} - ret_hsad = {"k" : [15.5, 16.5]} - - ret_hash_of_point_arrays = {} - for s in hash_of_point_arrays: - point_array = hash_of_point_arrays[s] - new_point_array = [] - for point in point_array: - (x, y) = point - new_point_array.append ((x + 100, y + 200)) - ret_hash_of_point_arrays[s + "_new"] = new_point_array - - return ret_hsas, ret_hsao, ret_hsai, ret_hsay, ret_hsan, ret_hsaq, ret_hsau, ret_hsab, ret_hsax, ret_hsat, ret_hsad, ret_hash_of_point_arrays - - # no support in dbus-send - @dbus.service.method("com.example.Frob", - in_signature = 'a{sa{s(ii)}}', - out_signature = 'a{sa{s(ii)}}') - def TestHashTableOfHashTablesOfStructures(self, hash_of_hash_of_points): - - ret = {} - for h in hash_of_hash_of_points: - hash_of_points = hash_of_hash_of_points[h] - newh = {} - for s in hash_of_points: - (x, y) = hash_of_points[s] - newh[s + "_new_new"] = (x + 100, y + 200) - ret[h + "_new"] = newh - - return ret - - # no support in dbus-send - @dbus.service.method("com.example.Frob", - in_signature = 'aa{s(ii)}', - out_signature = 'aa{s(ii)}') - def TestArrayOfHashTablesOfStructures(self, list_of_hash_of_points): - - ret = [] - for hash_of_points in list_of_hash_of_points: - newh = {} - for s in hash_of_points: - (x, y) = hash_of_points[s] - newh[s + "_new_new"] = (x + 100, y + 200) - ret.append(newh) - - return ret - - # no support in dbus-send - @dbus.service.method("com.example.Frob", - in_signature = 'aasaa(ii)aaoaaiaayaanaaqaauaabaaxaataadaaas', - out_signature = 'aasaa(ii)aaoaaiaayaanaaqaauaabaaxaataadaaas') - def TestArrayOfArrays(self, aas, aastruct, aao, aai, aay, aan, aaq, aau, aab, aax, aat, aad, aaas): - - ret_aas = aas*2; - ret_aastruct = aastruct*2; - ret_aao = aao*2; - ret_aai = aai*2; - ret_aay = aay*2; - ret_aan = aan*2; - ret_aaq = aaq*2; - ret_aau = aau*2; - ret_aab = aab*2; - ret_aax = aax*2; - ret_aat = aat*2; - ret_aad = aad*2; - ret_aaas = aaas*2 - - return ret_aas, ret_aastruct, ret_aao, ret_aai, ret_aay, ret_aan, ret_aaq, ret_aau, ret_aab, ret_aax, ret_aat, ret_aad, ret_aaas - - # dbus-send --print-reply --session --dest=com.example.TestService /com/example/TestService com.example.TestService.TestVariantReturn string:o - @dbus.service.method("com.example.Frob", - in_signature = 's', - out_signature = 'v') - def TestVariantReturn(self, desired_variant): - - if desired_variant == "y": - ret = dbus.Byte(1) - elif desired_variant == "b": - ret = True - elif desired_variant == "n": - ret = dbus.Int16(2) - elif desired_variant == "q": - ret = dbus.UInt16(3) - elif desired_variant == "i": - ret = dbus.Int32(4) - elif desired_variant == "u": - ret = dbus.UInt32(5) - elif desired_variant == "x": - ret = dbus.Int64(6) - elif desired_variant == "t": - ret = dbus.UInt64(7) - elif desired_variant == "d": - ret = 7.5 - elif desired_variant == "s": - ret = "a string" - elif desired_variant == "o": - ret = dbus.ObjectPath("/some/object/path") - elif desired_variant == "ai": - ret = [] - ret.append(dbus.Int32(4)) - ret.append(dbus.Int32(5)) - elif desired_variant == "as": - ret = [] - ret.append("a string") - ret.append("another string") - elif desired_variant == "point": - ret = (1, 2) - elif desired_variant == "dpoint": - ret = ("the desc", (3, 4)) - elif desired_variant == "hash_of_points": - ret = {} - ret["key0"] = (1, 2) - ret["key1"] = (3, 4) - ret["key2"] = (5, 6) - ret["key3"] = (7, 8) - elif desired_variant == "unregistered_struct": - ret = ("string", - dbus.Byte(2), - dbus.Int16(3), - 4, - [0, 1, 2, 3], - {"rip" : 2, "rap" : 4, "rup" : 6}, - [(1, 2), (1, 2), (1, 2)], - [[1, 2, 3], [4, 5, 6], [7, 8, 9]], - [True, False, False], - [[True, True], [False, True]], - [dbus.Byte(0xca), dbus.Byte(0xfe), dbus.Byte(0xba), dbus.Byte(0xbe), dbus.Byte(0x00), dbus.Byte(0xde), dbus.Byte(0xad), dbus.Byte(0xbe), dbus.Byte(0xef)], - {"huey" : (2, 1), "dewey" : (4, 2), "louie" : (6, 3)}, - {"innie" : [10, 11], "minnie" : [12, 13], "minie" : [14, 15], "moe" : [16, 17]}, - {dbus.Byte(0xa0) : [10, 11], dbus.Byte(0xa1) : [12, 13], dbus.Byte(0xa2) : [14, 15]}) - else: - raise TestException("unknown desired variant '%s'"%desired_variant) - - return ret - - # $ dbus-send --print-reply --session --dest=com.example.TestService /com/example/TestService com.example.TestService.TestVariantReturn2 string:one - @dbus.service.method("com.example.Frob", - in_signature = 's', - out_signature = 'ava{sv}(siivx)') - def TestVariantReturn2(self, desired_variant): - - ret_av = [] - ret_hsv = {} - - if desired_variant == "one": - ret_av.append (dbus.Byte(1)) - ret_av.append ("a string") - ret_av.append ((1, 2)) - ret_av.append ([dbus.Int16(100), dbus.Int16(100), dbus.Int16(100)]) - ret_av.append ({"rip" : 2, "rap" : 4, "rup" : 6}) - ret_struct = ("ok, steady", 10, 11, "one", 2) - elif desired_variant == "two": - ret_hsv["1st"] = dbus.Byte(1) - ret_hsv["2nd"] = "a string" - ret_hsv["3rd"] = (1, 2) - ret_hsv["4th"] = [dbus.Int16(100), dbus.Int16(100), dbus.Int16(100)] - ret_hsv["5th"] = {"rip" : 2, "rap" : 4, "rup" : 6} - ret_struct = ("anger. fear. acceptance. CA$H!!", 10, 11, {"foo": 42, "bar": 43}, 2) - else: - raise TestException("unknown desired variant '%s'"%desired_variant) - - return ret_av, ret_hsv, ret_struct - - # $ dbus-send --print-reply --session --dest=com.example.TestService /com/example/TestService com.example.TestService.TestPassVariant variant:string:dbus-rocks - @dbus.service.method("com.example.Frob", - in_signature = 'v', - out_signature = 's') - def TestPassVariant(self, variant): - - return dbus.String(variant) + "-and-a-bag-of-chips" - - # $ dbus-send --print-reply --session --dest=com.example.TestService /com/example/TestService com.example.TestService.TestPassVariant variant:string:dbus-rocks - @dbus.service.method("com.example.Frob", - in_signature = 'ava{sv}a{sav}(siivx)', - out_signature = 's') - def TestPassVariant2(self, array_of_variants, dict_of_string_to_variants, dict_of_string_to_array_of_variants, struct_with_variant): - - return dbus.String(array_of_variants) + dbus.String(dict_of_string_to_variants) + dbus.String(dict_of_string_to_array_of_variants) + dbus.String(struct_with_variant) - - @dbus.service.method("org.freedesktop.DBus.Properties", - in_signature = 'ss', - out_signature = 'v') - def Get(self, interface_name, property_name): - - if interface_name == "com.example.Frob": - return self.frob_props[property_name] - elif interface_name == "com.example.Tweak": - return self.tweak_props[property_name] - else: - raise TestException("No such interface " + interface_name) - - @dbus.service.method("org.freedesktop.DBus.Properties", - in_signature = 's', - out_signature = 'a{sv}') - def GetAll(self, interface_name): - if interface_name == "com.example.Frob": - return self.frob_props - elif interface_name == "com.example.Tweak": - return self.tweak_props - else: - raise TestException("No such interface " + interface_name) - - @dbus.service.method("com.example.Tweak", - in_signature='s', out_signature='s') - def ICanHazGreetingz(self, hello_message): - return "Word. You haz greetz '%s'. KTHXBYE!"%(str(hello_message)) - - @dbus.service.method("com.example.Tweak", - out_signature='s') - def GetServerUniqueName(self): - return session_bus.get_unique_name() - - - - - - @dbus.service.signal("com.example.Tweak") - def NewzNotifz(self, newz): - pass - - @dbus.service.method("com.example.Tweak", - in_signature='s') - def BroadcastzNewz(self, newz_to_pass): - self.NewzNotifz("Word. Broadcastz '%s'. KTHXBYE!"%(str(newz_to_pass))) - - - @dbus.service.method("com.example.Twiddle", - in_signature='s') - def BroadcastzNewzOnTwiddle(self, newz_to_pass): - string = "Sez '%s'. KTHXBYE!"%(str(newz_to_pass)) - # manually construct the message since dbus-python doesn't appear - # to support identical signal names on different interfaces... - # - message = dbus.lowlevel.SignalMessage("/com/example/TestObject", "com.example.Twiddle", "NewzNotifz") - message.append(string) - session_bus.send_message(message) - - - -if __name__ == '__main__': - dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) - - session_bus = dbus.SessionBus() - name = dbus.service.BusName("com.example.TestService", session_bus) - - obj = TestService(session_bus, '/com/example/TestObject') - - #print "Our unique name is %s"%(session_bus.get_unique_name()) - - obj.frob_props = {} - obj.frob_props["y"] = dbus.Byte(1) - obj.frob_props["b"] = dbus.Boolean(True) - obj.frob_props["n"] = dbus.Int16(2) - obj.frob_props["q"] = dbus.UInt16(3) - obj.frob_props["i"] = dbus.Int32(4) - obj.frob_props["u"] = dbus.UInt32(5) - obj.frob_props["x"] = dbus.Int64(6) - obj.frob_props["t"] = dbus.UInt64(7) - obj.frob_props["d"] = dbus.Double(7.5) - obj.frob_props["s"] = dbus.String("a string") - obj.frob_props["o"] = dbus.ObjectPath("/some/path") - obj.frob_props["ay"] = [dbus.Byte(1), dbus.Byte(11)] - obj.frob_props["ab"] = [dbus.Boolean(True), dbus.Boolean(False)] - obj.frob_props["an"] = [dbus.Int16(2), dbus.Int16(12)] - obj.frob_props["aq"] = [dbus.UInt16(3), dbus.UInt16(13)] - obj.frob_props["ai"] = [dbus.Int32(4), dbus.Int32(14)] - obj.frob_props["au"] = [dbus.UInt32(5), dbus.UInt32(15)] - obj.frob_props["ax"] = [dbus.Int64(6), dbus.Int64(16)] - obj.frob_props["at"] = [dbus.UInt64(7), dbus.UInt64(17)] - obj.frob_props["ad"] = [dbus.Double(7.5), dbus.Double(17.5)] - obj.frob_props["as"] = [dbus.String("a string"), dbus.String("another string")] - obj.frob_props["ao"] = [dbus.ObjectPath("/some/path"), dbus.ObjectPath("/another/path")] - obj.frob_props["foo"] = "a frobbed string" - - obj.tweak_props = {} - obj.tweak_props["foo"] = "a tweaked string" - obj.tweak_props["bar"] = [1, 2] - obj.tweak_props["baz"] = (3, 4) - - mainloop = gobject.MainLoop() - mainloop.run() -- cgit v1.2.3