comparison frontends/src/bridge/DBus.py @ 372:f964dcec1611

core: plugins refactored according to bridge + updatedValue now use profile
author Goffi <goffi@goffi.org>
date Wed, 06 Jul 2011 01:06:18 +0200
parents efbfccfed623
children e66d300c5d42
comparison
equal deleted inserted replaced
371:3ea41a199b36 372:f964dcec1611
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 def addContact(self, entity, profile_key="@DEFAULT@"): 59 def addContact(self, entity, profile_key="@DEFAULT@"):
58 return self.db_comm_iface.addContact(entity, profile_key) 60 return self.db_core_iface.addContact(entity, profile_key)
59 61
60 def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None): 62 def asyncConnect(self, profile_key="@DEFAULT@", callback=None, errback=None):
61 return self.db_comm_iface.asyncConnect(profile_key, reply_handler=callback, error_handler=errback) 63 return self.db_core_iface.asyncConnect(profile_key, reply_handler=callback, error_handler=errback)
62 64
63 def callMenu(self, category, name, menu_type, profile_key): 65 def callMenu(self, category, name, menu_type, profile_key):
64 return unicode(self.db_req_iface.callMenu(category, name, menu_type, profile_key)) 66 return unicode(self.db_core_iface.callMenu(category, name, menu_type, profile_key))
65 67
66 def confirmationAnswer(self, id, accepted, data): 68 def confirmationAnswer(self, id, accepted, data):
67 return self.db_req_iface.confirmationAnswer(id, accepted, data) 69 return self.db_core_iface.confirmationAnswer(id, accepted, data)
68 70
69 def connect(self, profile_key="@DEFAULT@"): 71 def connect(self, profile_key="@DEFAULT@"):
70 return self.db_comm_iface.connect(profile_key) 72 return self.db_core_iface.connect(profile_key)
71 73
72 def createProfile(self, profile): 74 def createProfile(self, profile):
73 return self.db_req_iface.createProfile(profile) 75 return self.db_core_iface.createProfile(profile)
74 76
75 def delContact(self, entity, profile_key="@DEFAULT@"): 77 def delContact(self, entity, profile_key="@DEFAULT@"):
76 return self.db_comm_iface.delContact(entity, profile_key) 78 return self.db_core_iface.delContact(entity, profile_key)
77 79
78 def deleteProfile(self, profile): 80 def deleteProfile(self, profile):
79 return self.db_req_iface.deleteProfile(profile) 81 return self.db_core_iface.deleteProfile(profile)
80 82
81 def disconnect(self, profile_key="@DEFAULT@"): 83 def disconnect(self, profile_key="@DEFAULT@"):
82 return self.db_comm_iface.disconnect(profile_key) 84 return self.db_core_iface.disconnect(profile_key)
83 85
84 def getConfig(self, section, name): 86 def getConfig(self, section, name):
85 return unicode(self.db_comm_iface.getConfig(section, name)) 87 return unicode(self.db_core_iface.getConfig(section, name))
86 88
87 def getContacts(self, profile_key="@DEFAULT@"): 89 def getContacts(self, profile_key="@DEFAULT@"):
88 return self.db_comm_iface.getContacts(profile_key) 90 return self.db_core_iface.getContacts(profile_key)
89 91
90 def getHistory(self, from_jid, to_jid, size): 92 def getHistory(self, from_jid, to_jid, size):
91 return self.db_comm_iface.getHistory(from_jid, to_jid, size) 93 return self.db_core_iface.getHistory(from_jid, to_jid, size)
92 94
93 def getMenuHelp(self, category, name, menu_type): 95 def getMenuHelp(self, category, name, menu_type):
94 return unicode(self.db_req_iface.getMenuHelp(category, name, menu_type)) 96 return unicode(self.db_core_iface.getMenuHelp(category, name, menu_type))
95 97
96 def getMenus(self, ): 98 def getMenus(self, ):
97 return self.db_req_iface.getMenus() 99 return self.db_core_iface.getMenus()
98 100
99 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"): 101 def getParamA(self, name, category, attribute="value", profile_key="@DEFAULT@"):
100 return unicode(self.db_comm_iface.getParamA(name, category, attribute, profile_key)) 102 return unicode(self.db_core_iface.getParamA(name, category, attribute, profile_key))
101 103
102 def getParams(self, profile_key="@DEFAULT@"): 104 def getParams(self, profile_key="@DEFAULT@"):
103 return unicode(self.db_comm_iface.getParams(profile_key)) 105 return unicode(self.db_core_iface.getParams(profile_key))
104 106
105 def getParamsCategories(self, ): 107 def getParamsCategories(self, ):
106 return self.db_comm_iface.getParamsCategories() 108 return self.db_core_iface.getParamsCategories()
107 109
108 def getParamsForCategory(self, category, profile_key="@DEFAULT@"): 110 def getParamsForCategory(self, category, profile_key="@DEFAULT@"):
109 return unicode(self.db_comm_iface.getParamsForCategory(category, profile_key)) 111 return unicode(self.db_core_iface.getParamsForCategory(category, profile_key))
110 112
111 def getParamsUI(self, profile_key="@DEFAULT@"): 113 def getParamsUI(self, profile_key="@DEFAULT@"):
112 return unicode(self.db_comm_iface.getParamsUI(profile_key)) 114 return unicode(self.db_core_iface.getParamsUI(profile_key))
113 115
114 def getPresenceStatus(self, profile_key="@DEFAULT@"): 116 def getPresenceStatus(self, profile_key="@DEFAULT@"):
115 return self.db_comm_iface.getPresenceStatus(profile_key) 117 return self.db_core_iface.getPresenceStatus(profile_key)
116 118
117 def getProfileName(self, profile_key="@DEFAULT@"): 119 def getProfileName(self, profile_key="@DEFAULT@"):
118 return unicode(self.db_req_iface.getProfileName(profile_key)) 120 return unicode(self.db_core_iface.getProfileName(profile_key))
119 121
120 def getProfilesList(self, ): 122 def getProfilesList(self, ):
121 return self.db_req_iface.getProfilesList() 123 return self.db_core_iface.getProfilesList()
122 124
123 def getProgress(self, id): 125 def getProgress(self, id):
124 return self.db_req_iface.getProgress(id) 126 return self.db_core_iface.getProgress(id)
125 127
126 def getVersion(self, ): 128 def getVersion(self, ):
127 return unicode(self.db_req_iface.getVersion()) 129 return unicode(self.db_core_iface.getVersion())
128 130
129 def getWaitingSub(self, profile_key="@DEFAULT@"): 131 def getWaitingSub(self, profile_key="@DEFAULT@"):
130 return self.db_comm_iface.getWaitingSub(profile_key) 132 return self.db_core_iface.getWaitingSub(profile_key)
131 133
132 def isConnected(self, profile_key="@DEFAULT@"): 134 def isConnected(self, profile_key="@DEFAULT@"):
133 return self.db_comm_iface.isConnected(profile_key) 135 return self.db_core_iface.isConnected(profile_key)
134 136
135 def launchAction(self, action_type, data, profile_key="@DEFAULT@"): 137 def launchAction(self, action_type, data, profile_key="@DEFAULT@"):
136 return unicode(self.db_req_iface.launchAction(action_type, data, profile_key)) 138 return unicode(self.db_core_iface.launchAction(action_type, data, profile_key))
137 139
138 def registerNewAccount(self, login, password, email, host, port=5222): 140 def registerNewAccount(self, login, password, email, host, port=5222):
139 return unicode(self.db_comm_iface.registerNewAccount(login, password, email, host, port)) 141 return unicode(self.db_core_iface.registerNewAccount(login, password, email, host, port))
140 142
141 def sendMessage(self, to_jid, message, subject='', mess_type="chat", profile_key="@DEFAULT@"): 143 def sendMessage(self, to_jid, message, subject='', mess_type="chat", profile_key="@DEFAULT@"):
142 return self.db_comm_iface.sendMessage(to_jid, message, subject, mess_type, profile_key) 144 return self.db_core_iface.sendMessage(to_jid, message, subject, mess_type, profile_key)
143 145
144 def setParam(self, name, value, category, profile_key="@DEFAULT@"): 146 def setParam(self, name, value, category, profile_key="@DEFAULT@"):
145 return self.db_comm_iface.setParam(name, value, category, profile_key) 147 return self.db_core_iface.setParam(name, value, category, profile_key)
146 148
147 def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"): 149 def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"):
148 return self.db_comm_iface.setPresence(to_jid, show, priority, statuses, profile_key) 150 return self.db_core_iface.setPresence(to_jid, show, priority, statuses, profile_key)
149 151
150 def subscription(self, sub_type, entity, profile_key="@DEFAULT@"): 152 def subscription(self, sub_type, entity, profile_key="@DEFAULT@"):
151 return self.db_comm_iface.subscription(sub_type, entity, profile_key) 153 return self.db_core_iface.subscription(sub_type, entity, profile_key)
152 154
153 def updateContact(self, entity, name, groups, profile_key="@DEFAULT@"): 155 def updateContact(self, entity, name, groups, profile_key="@DEFAULT@"):
154 return self.db_comm_iface.updateContact(entity, name, groups, profile_key) 156 return self.db_core_iface.updateContact(entity, name, groups, profile_key)
155 157
156 158
157 #methods from plugins 159 #methods from plugins
158 def getRoomJoined(self, profile_key='@DEFAULT@'): 160 def getRoomJoined(self, profile_key='@DEFAULT@'):
159 return self.db_comm_iface.getRoomJoined(profile_key) 161 return self.db_plugin_iface.getRoomJoined(profile_key)
160 162
161 def getRoomSubjects(self, profile_key='@DEFAULT@'): 163 def getRoomSubjects(self, profile_key='@DEFAULT@'):
162 return self.db_comm_iface.getRoomSubjects(profile_key) 164 return self.db_plugin_iface.getRoomSubjects(profile_key)
163 165
164 def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'): 166 def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'):
165 return self.db_comm_iface.joinMUC(service, roomId, nick, profile_key) 167 return self.db_plugin_iface.joinMUC(service, roomId, nick, profile_key)
166 168
167 def tarotGameLaunch(self, players, profile_key='@DEFAULT@'): 169 def tarotGameLaunch(self, players, profile_key='@DEFAULT@'):
168 return self.db_comm_iface.tarotGameLaunch(players, profile_key) 170 return self.db_plugin_iface.tarotGameLaunch(players, profile_key)
169 171
170 def tarotGameCreate(self, room_jid, players, profile_key='@DEFAULT@'): 172 def tarotGameCreate(self, room_jid, players, profile_key='@DEFAULT@'):
171 return self.db_comm_iface.tarotGameCreate(room_jid, players, profile_key) 173 return self.db_plugin_iface.tarotGameCreate(room_jid, players, profile_key)
172 174
173 def tarotGameReady(self, player, referee, profile_key='@DEFAULT@'): 175 def tarotGameReady(self, player, referee, profile_key='@DEFAULT@'):
174 return self.db_comm_iface.tarotGameReady(player, referee, profile_key) 176 return self.db_plugin_iface.tarotGameReady(player, referee, profile_key)
175 177
176 def tarotGameContratChoosed(self, player, referee, contrat, profile_key='@DEFAULT@'): 178 def tarotGameContratChoosed(self, player, referee, contrat, profile_key='@DEFAULT@'):
177 return self.db_comm_iface.tarotGameContratChoosed(player, referee, contrat, profile_key) 179 return self.db_plugin_iface.tarotGameContratChoosed(player, referee, contrat, profile_key)
178 180
179 def tarotGamePlayCards(self, player, referee, cards, profile_key='@DEFAULT@'): 181 def tarotGamePlayCards(self, player, referee, cards, profile_key='@DEFAULT@'):
180 return self.db_comm_iface.tarotGamePlayCards(player, referee, cards, profile_key) 182 return self.db_plugin_iface.tarotGamePlayCards(player, referee, cards, profile_key)
181 183
182 def quizGameLaunch(self, players, profile_key='@DEFAULT@'): 184 def quizGameLaunch(self, players, profile_key='@DEFAULT@'):
183 return self.db_comm_iface.quizGameLaunch(players, profile_key) 185 return self.db_plugin_iface.quizGameLaunch(players, profile_key)
184 186
185 def quizGameCreate(self, room_jid, players, profile_key='@DEFAULT@'): 187 def quizGameCreate(self, room_jid, players, profile_key='@DEFAULT@'):
186 return self.db_comm_iface.quizGameCreate(room_jid, players, profile_key) 188 return self.db_plugin_iface.quizGameCreate(room_jid, players, profile_key)
187 189
188 def quizGameReady(self, player, referee, profile_key='@DEFAULT@'): 190 def quizGameReady(self, player, referee, profile_key='@DEFAULT@'):
189 return self.db_comm_iface.quizGameReady(player, referee, profile_key) 191 return self.db_plugin_iface.quizGameReady(player, referee, profile_key)
190 192
191 def quizGameAnswer(self, player, referee, answer, profile_key='@DEFAULT@'): 193 def quizGameAnswer(self, player, referee, answer, profile_key='@DEFAULT@'):
192 return self.db_comm_iface.quizGameAnswer(player, referee, answer, profile_key) 194 return self.db_plugin_iface.quizGameAnswer(player, referee, answer, profile_key)
193 195
194 def sendFile(self, to, path, profile_key='@DEFAULT@'): 196 def sendFile(self, to, path, profile_key='@DEFAULT@'):
195 return self.db_comm_iface.sendFile(to, path, profile_key) 197 return self.db_plugin_iface.sendFile(to, path, profile_key)
196 198
197 def findGateways(self, target, profile_key='@DEFAULT@'): 199 def findGateways(self, target, profile_key='@DEFAULT@'):
198 return self.db_comm_iface.findGateways(target, profile_key) 200 return self.db_plugin_iface.findGateways(target, profile_key)
199 201
200 def getCard(self, target, profile_key='@DEFAULT@'): 202 def getCard(self, target, profile_key='@DEFAULT@'):
201 return self.db_comm_iface.getCard(target, profile_key) 203 return self.db_plugin_iface.getCard(target, profile_key)
202 204
203 def getCardCache(self, target): 205 def getCardCache(self, target):
204 return self.db_comm_iface.getCardCache(target) 206 return self.db_plugin_iface.getCardCache(target)
205 207
206 def getAvatarFile(self, hash): 208 def getAvatarFile(self, hash):
207 return self.db_comm_iface.getAvatarFile(hash) 209 return self.db_plugin_iface.getAvatarFile(hash)
208 210
209 def in_band_register(self, target, profile_key='@DEFAULT@'): 211 def in_band_register(self, target, profile_key='@DEFAULT@'):
210 return self.db_comm_iface.in_band_register(target, profile_key) 212 return self.db_plugin_iface.in_band_register(target, profile_key)
211 213
212 def gatewayRegister(self, action, target, data, profile_key='@DEFAULT@'): 214 def gatewayRegister(self, action, target, data, profile_key='@DEFAULT@'):
213 if data == None: 215 if data == None:
214 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature 216 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
215 return self.db_req_iface.gatewayRegister(action, target, data, profile_key) 217 return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key)
216 218
217 def getLastMicroblogs(self, jid, max_items, profile_key='@DEFAULT@', callback=None, errback=None): 219 def getLastMicroblogs(self, jid, max_items, profile_key='@DEFAULT@', callback=None, errback=None):
218 return self.db_comm_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback) 220 return self.db_plugin_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback)
219 221
220 def getMblogNodes(self, profile_key='@DEFAULT@', callback=None, errback=None): 222 def getMblogNodes(self, profile_key='@DEFAULT@', callback=None, errback=None):
221 return self.db_comm_iface.getMblogNodes(profile_key, reply_handler=callback, error_handler=errback) 223 return self.db_plugin_iface.getMblogNodes(profile_key, reply_handler=callback, error_handler=errback)
222 224
223 def sendGroupBlog(self, groups, message, profile_key='@DEFAULT@'): 225 def sendGroupBlog(self, groups, message, profile_key='@DEFAULT@'):
224 return self.db_comm_iface.sendGroupBlog(groups, message, profile_key) 226 return self.db_plugin_iface.sendGroupBlog(groups, message, profile_key)
225 227
226 def sendPersonalEvent(self, event_type, data, profile_key='@DEFAULT@'): 228 def sendPersonalEvent(self, event_type, data, profile_key='@DEFAULT@'):
227 return self.db_comm_iface.sendPersonalEvent(event_type, data, profile_key) 229 return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key)
228 230
229 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None): 231 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None):
230 return self.db_comm_iface.setMicroblogAccess(access, profile_key, reply_handler=callback, error_handler=errback) 232 return self.db_plugin_iface.setMicroblogAccess(access, profile_key, reply_handler=callback, error_handler=errback)