Mercurial > libervia-backend
comparison src/bridge/bridge_constructor/dbus_frontend_template.py @ 371:3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 06 Jul 2011 01:04:24 +0200 |
parents | 54c77a56b22f |
children | e66d300c5d42 |
comparison
equal
deleted
inserted
replaced
370:68cdaf6d78e3 | 371:3ea41a199b36 |
---|---|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | 20 """ |
21 | 21 |
22 from bridge_frontend import BridgeFrontend | 22 from bridge_frontend import BridgeFrontend |
23 import dbus, dbus.glib | 23 import dbus, dbus.glib |
24 from logging import debug | 24 from logging import debug, error |
25 | 25 |
26 const_INT_PREFIX = "org.goffi.SAT" #Interface prefix | 26 const_INT_PREFIX = "org.goffi.SAT" #Interface prefix |
27 const_OBJ_PATH = '/org/goffi/SAT/bridge' | 27 const_OBJ_PATH = '/org/goffi/SAT/bridge' |
28 const_COMM_SUFFIX = ".communication" | 28 const_CORE_SUFFIX = ".core" |
29 const_REQ_SUFFIX = ".request" | 29 const_PLUGIN_SUFFIX = ".plugin" |
30 | 30 |
31 class BridgeExceptionNoService(Exception): | 31 class BridgeExceptionNoService(Exception): |
32 pass | 32 pass |
33 | 33 |
34 class DBusBridgeFrontend(BridgeFrontend): | 34 class DBusBridgeFrontend(BridgeFrontend): |
35 def __init__(self): | 35 def __init__(self): |
36 try: | 36 try: |
37 self.sessions_bus = dbus.SessionBus() | 37 self.sessions_bus = dbus.SessionBus() |
38 self.db_object = self.sessions_bus.get_object(const_INT_PREFIX, | 38 self.db_object = self.sessions_bus.get_object(const_INT_PREFIX, |
39 const_OBJ_PATH) | 39 const_OBJ_PATH) |
40 self.db_comm_iface = dbus.Interface(self.db_object, | 40 self.db_core_iface = dbus.Interface(self.db_object, |
41 dbus_interface=const_INT_PREFIX + const_COMM_SUFFIX) | 41 dbus_interface=const_INT_PREFIX + const_CORE_SUFFIX) |
42 self.db_req_iface = dbus.Interface(self.db_object, | 42 self.db_plugin_iface = dbus.Interface(self.db_object, |
43 dbus_interface=const_INT_PREFIX + const_REQ_SUFFIX) | 43 dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX) |
44 except dbus.exceptions.DBusException,e: | 44 except dbus.exceptions.DBusException,e: |
45 if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown': | 45 if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown': |
46 raise BridgeExceptionNoService | 46 raise BridgeExceptionNoService |
47 else: | 47 else: |
48 raise e | 48 raise e |
49 #props = self.db_comm_iface.getProperties() | 49 #props = self.db_core_iface.getProperties() |
50 | 50 |
51 def register(self, functionName, handler, iface="communication"): | 51 def register(self, functionName, handler, iface="core"): |
52 if iface == "communication": | 52 if iface == "core": |
53 self.db_comm_iface.connect_to_signal(functionName, handler) | 53 self.db_core_iface.connect_to_signal(functionName, handler) |
54 elif iface == "request": | 54 elif iface == "plugin": |
55 self.db_req_iface.connect_to_signal(functionName, handler) | 55 self.db_plugin_iface.connect_to_signal(functionName, handler) |
56 else: | |
57 error(_('Unknown interface')) | |
56 | 58 |
57 ##METHODS_PART## | 59 ##METHODS_PART## |
58 | 60 |
59 #methods from plugins | 61 #methods from plugins |
60 def getRoomJoined(self, profile_key='@DEFAULT@'): | 62 def getRoomJoined(self, profile_key='@DEFAULT@'): |
61 return self.db_comm_iface.getRoomJoined(profile_key) | 63 return self.db_plugin_iface.getRoomJoined(profile_key) |
62 | 64 |
63 def getRoomSubjects(self, profile_key='@DEFAULT@'): | 65 def getRoomSubjects(self, profile_key='@DEFAULT@'): |
64 return self.db_comm_iface.getRoomSubjects(profile_key) | 66 return self.db_plugin_iface.getRoomSubjects(profile_key) |
65 | 67 |
66 def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'): | 68 def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'): |
67 return self.db_comm_iface.joinMUC(service, roomId, nick, profile_key) | 69 return self.db_plugin_iface.joinMUC(service, roomId, nick, profile_key) |
68 | 70 |
69 def tarotGameLaunch(self, players, profile_key='@DEFAULT@'): | 71 def tarotGameLaunch(self, players, profile_key='@DEFAULT@'): |
70 return self.db_comm_iface.tarotGameLaunch(players, profile_key) | 72 return self.db_plugin_iface.tarotGameLaunch(players, profile_key) |
71 | 73 |
72 def tarotGameCreate(self, room_jid, players, profile_key='@DEFAULT@'): | 74 def tarotGameCreate(self, room_jid, players, profile_key='@DEFAULT@'): |
73 return self.db_comm_iface.tarotGameCreate(room_jid, players, profile_key) | 75 return self.db_plugin_iface.tarotGameCreate(room_jid, players, profile_key) |
74 | 76 |
75 def tarotGameReady(self, player, referee, profile_key='@DEFAULT@'): | 77 def tarotGameReady(self, player, referee, profile_key='@DEFAULT@'): |
76 return self.db_comm_iface.tarotGameReady(player, referee, profile_key) | 78 return self.db_plugin_iface.tarotGameReady(player, referee, profile_key) |
77 | 79 |
78 def tarotGameContratChoosed(self, player, referee, contrat, profile_key='@DEFAULT@'): | 80 def tarotGameContratChoosed(self, player, referee, contrat, profile_key='@DEFAULT@'): |
79 return self.db_comm_iface.tarotGameContratChoosed(player, referee, contrat, profile_key) | 81 return self.db_plugin_iface.tarotGameContratChoosed(player, referee, contrat, profile_key) |
80 | 82 |
81 def tarotGamePlayCards(self, player, referee, cards, profile_key='@DEFAULT@'): | 83 def tarotGamePlayCards(self, player, referee, cards, profile_key='@DEFAULT@'): |
82 return self.db_comm_iface.tarotGamePlayCards(player, referee, cards, profile_key) | 84 return self.db_plugin_iface.tarotGamePlayCards(player, referee, cards, profile_key) |
83 | 85 |
84 def quizGameLaunch(self, players, profile_key='@DEFAULT@'): | 86 def quizGameLaunch(self, players, profile_key='@DEFAULT@'): |
85 return self.db_comm_iface.quizGameLaunch(players, profile_key) | 87 return self.db_plugin_iface.quizGameLaunch(players, profile_key) |
86 | 88 |
87 def quizGameCreate(self, room_jid, players, profile_key='@DEFAULT@'): | 89 def quizGameCreate(self, room_jid, players, profile_key='@DEFAULT@'): |
88 return self.db_comm_iface.quizGameCreate(room_jid, players, profile_key) | 90 return self.db_plugin_iface.quizGameCreate(room_jid, players, profile_key) |
89 | 91 |
90 def quizGameReady(self, player, referee, profile_key='@DEFAULT@'): | 92 def quizGameReady(self, player, referee, profile_key='@DEFAULT@'): |
91 return self.db_comm_iface.quizGameReady(player, referee, profile_key) | 93 return self.db_plugin_iface.quizGameReady(player, referee, profile_key) |
92 | 94 |
93 def quizGameAnswer(self, player, referee, answer, profile_key='@DEFAULT@'): | 95 def quizGameAnswer(self, player, referee, answer, profile_key='@DEFAULT@'): |
94 return self.db_comm_iface.quizGameAnswer(player, referee, answer, profile_key) | 96 return self.db_plugin_iface.quizGameAnswer(player, referee, answer, profile_key) |
95 | 97 |
96 def sendFile(self, to, path, profile_key='@DEFAULT@'): | 98 def sendFile(self, to, path, profile_key='@DEFAULT@'): |
97 return self.db_comm_iface.sendFile(to, path, profile_key) | 99 return self.db_plugin_iface.sendFile(to, path, profile_key) |
98 | 100 |
99 def findGateways(self, target, profile_key='@DEFAULT@'): | 101 def findGateways(self, target, profile_key='@DEFAULT@'): |
100 return self.db_comm_iface.findGateways(target, profile_key) | 102 return self.db_plugin_iface.findGateways(target, profile_key) |
101 | 103 |
102 def getCard(self, target, profile_key='@DEFAULT@'): | 104 def getCard(self, target, profile_key='@DEFAULT@'): |
103 return self.db_comm_iface.getCard(target, profile_key) | 105 return self.db_plugin_iface.getCard(target, profile_key) |
104 | 106 |
105 def getCardCache(self, target): | 107 def getCardCache(self, target): |
106 return self.db_comm_iface.getCardCache(target) | 108 return self.db_plugin_iface.getCardCache(target) |
107 | 109 |
108 def getAvatarFile(self, hash): | 110 def getAvatarFile(self, hash): |
109 return self.db_comm_iface.getAvatarFile(hash) | 111 return self.db_plugin_iface.getAvatarFile(hash) |
110 | 112 |
111 def in_band_register(self, target, profile_key='@DEFAULT@'): | 113 def in_band_register(self, target, profile_key='@DEFAULT@'): |
112 return self.db_comm_iface.in_band_register(target, profile_key) | 114 return self.db_plugin_iface.in_band_register(target, profile_key) |
113 | 115 |
114 def gatewayRegister(self, action, target, data, profile_key='@DEFAULT@'): | 116 def gatewayRegister(self, action, target, data, profile_key='@DEFAULT@'): |
115 if data == None: | 117 if data == None: |
116 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature | 118 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature |
117 return self.db_req_iface.gatewayRegister(action, target, data, profile_key) | 119 return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key) |
118 | 120 |
119 def getLastMicroblogs(self, jid, max_items, profile_key='@DEFAULT@', callback=None, errback=None): | 121 def getLastMicroblogs(self, jid, max_items, profile_key='@DEFAULT@', callback=None, errback=None): |
120 return self.db_comm_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback) | 122 return self.db_plugin_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback) |
121 | 123 |
122 def getMblogNodes(self, profile_key='@DEFAULT@', callback=None, errback=None): | 124 def getMblogNodes(self, profile_key='@DEFAULT@', callback=None, errback=None): |
123 return self.db_comm_iface.getMblogNodes(profile_key, reply_handler=callback, error_handler=errback) | 125 return self.db_plugin_iface.getMblogNodes(profile_key, reply_handler=callback, error_handler=errback) |
124 | 126 |
125 def sendGroupBlog(self, groups, message, profile_key='@DEFAULT@'): | 127 def sendGroupBlog(self, groups, message, profile_key='@DEFAULT@'): |
126 return self.db_comm_iface.sendGroupBlog(groups, message, profile_key) | 128 return self.db_plugin_iface.sendGroupBlog(groups, message, profile_key) |
127 | 129 |
128 def sendPersonalEvent(self, event_type, data, profile_key='@DEFAULT@'): | 130 def sendPersonalEvent(self, event_type, data, profile_key='@DEFAULT@'): |
129 return self.db_comm_iface.sendPersonalEvent(event_type, data, profile_key) | 131 return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key) |
130 | 132 |
131 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None): | 133 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None): |
132 return self.db_comm_iface.setMicroblogAccess(access, profile_key, reply_handler=callback, error_handler=errback) | 134 return self.db_plugin_iface.setMicroblogAccess(access, profile_key, reply_handler=callback, error_handler=errback) |
133 | 135 |