Mercurial > libervia-backend
annotate src/bridge/bridge_constructor/dbus_frontend_template.py @ 388:a617af506154
core: progress callback now use id as first parameter
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 29 Sep 2011 12:14:19 +0200 |
parents | e66d300c5d42 |
children | b2caa2615c4c |
rev | line source |
---|---|
267 | 1 #!/usr/bin/python |
2 #-*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT communication bridge | |
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 from bridge_frontend import BridgeFrontend | |
23 import dbus, dbus.glib | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
24 from logging import debug, error |
267 | 25 |
359
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
26 const_INT_PREFIX = "org.goffi.SAT" #Interface prefix |
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
27 const_OBJ_PATH = '/org/goffi/SAT/bridge' |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
28 const_CORE_SUFFIX = ".core" |
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
29 const_PLUGIN_SUFFIX = ".plugin" |
359
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
30 |
267 | 31 class BridgeExceptionNoService(Exception): |
32 pass | |
33 | |
34 class DBusBridgeFrontend(BridgeFrontend): | |
35 def __init__(self): | |
36 try: | |
37 self.sessions_bus = dbus.SessionBus() | |
359
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
38 self.db_object = self.sessions_bus.get_object(const_INT_PREFIX, |
eb9d33ba4e36
bridge: templates' constants can now be overrided
Goffi <goffi@goffi.org>
parents:
337
diff
changeset
|
39 const_OBJ_PATH) |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
40 self.db_core_iface = dbus.Interface(self.db_object, |
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
41 dbus_interface=const_INT_PREFIX + const_CORE_SUFFIX) |
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
42 self.db_plugin_iface = dbus.Interface(self.db_object, |
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
43 dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX) |
267 | 44 except dbus.exceptions.DBusException,e: |
45 if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown': | |
46 raise BridgeExceptionNoService | |
47 else: | |
48 raise e | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
49 #props = self.db_core_iface.getProperties() |
267 | 50 |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
51 def register(self, functionName, handler, iface="core"): |
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
52 if iface == "core": |
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
53 self.db_core_iface.connect_to_signal(functionName, handler) |
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
54 elif iface == "plugin": |
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
55 self.db_plugin_iface.connect_to_signal(functionName, handler) |
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
56 else: |
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
57 error(_('Unknown interface')) |
267 | 58 |
59 ##METHODS_PART## | |
60 | |
61 #methods from plugins | |
62 def getRoomJoined(self, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
63 return self.db_plugin_iface.getRoomJoined(profile_key) |
267 | 64 |
65 def getRoomSubjects(self, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
66 return self.db_plugin_iface.getRoomSubjects(profile_key) |
267 | 67 |
68 def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
69 return self.db_plugin_iface.joinMUC(service, roomId, nick, profile_key) |
267 | 70 |
320
5fc5e6a7e5c3
plugin Tarot: added a launch method to automatically create a new room, invite players and create the game
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
71 def tarotGameLaunch(self, players, profile_key='@DEFAULT@'): |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
72 return self.db_plugin_iface.tarotGameLaunch(players, profile_key) |
320
5fc5e6a7e5c3
plugin Tarot: added a launch method to automatically create a new room, invite players and create the game
Goffi <goffi@goffi.org>
parents:
307
diff
changeset
|
73 |
267 | 74 def tarotGameCreate(self, room_jid, players, profile_key='@DEFAULT@'): |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
75 return self.db_plugin_iface.tarotGameCreate(room_jid, players, profile_key) |
267 | 76 |
77 def tarotGameReady(self, player, referee, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
78 return self.db_plugin_iface.tarotGameReady(player, referee, profile_key) |
267 | 79 |
80 def tarotGameContratChoosed(self, player, referee, contrat, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
81 return self.db_plugin_iface.tarotGameContratChoosed(player, referee, contrat, profile_key) |
267 | 82 |
83 def tarotGamePlayCards(self, player, referee, cards, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
84 return self.db_plugin_iface.tarotGamePlayCards(player, referee, cards, profile_key) |
267 | 85 |
361 | 86 def quizGameLaunch(self, players, profile_key='@DEFAULT@'): |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
87 return self.db_plugin_iface.quizGameLaunch(players, profile_key) |
361 | 88 |
89 def quizGameCreate(self, room_jid, players, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
90 return self.db_plugin_iface.quizGameCreate(room_jid, players, profile_key) |
361 | 91 |
92 def quizGameReady(self, player, referee, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
93 return self.db_plugin_iface.quizGameReady(player, referee, profile_key) |
361 | 94 |
363
54c77a56b22f
bridge: bridge_constuctor's frontend template update with quiz answer method
Goffi <goffi@goffi.org>
parents:
361
diff
changeset
|
95 def quizGameAnswer(self, player, referee, answer, profile_key='@DEFAULT@'): |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
96 return self.db_plugin_iface.quizGameAnswer(player, referee, answer, profile_key) |
363
54c77a56b22f
bridge: bridge_constuctor's frontend template update with quiz answer method
Goffi <goffi@goffi.org>
parents:
361
diff
changeset
|
97 |
387
e66d300c5d42
frontends, bridge: sendFile method signature change + jid parameters in bridge now use _jid suffix
Goffi <goffi@goffi.org>
parents:
371
diff
changeset
|
98 def sendFile(self, to, path, data, profile_key='@DEFAULT@'): |
e66d300c5d42
frontends, bridge: sendFile method signature change + jid parameters in bridge now use _jid suffix
Goffi <goffi@goffi.org>
parents:
371
diff
changeset
|
99 return self.db_plugin_iface.sendFile(to, path, data, profile_key) |
267 | 100 |
101 def findGateways(self, target, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
102 return self.db_plugin_iface.findGateways(target, profile_key) |
267 | 103 |
104 def getCard(self, target, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
105 return self.db_plugin_iface.getCard(target, profile_key) |
267 | 106 |
107 def getCardCache(self, target): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
108 return self.db_plugin_iface.getCardCache(target) |
267 | 109 |
110 def getAvatarFile(self, hash): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
111 return self.db_plugin_iface.getAvatarFile(hash) |
267 | 112 |
113 def in_band_register(self, target, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
114 return self.db_plugin_iface.in_band_register(target, profile_key) |
267 | 115 |
116 def gatewayRegister(self, action, target, data, profile_key='@DEFAULT@'): | |
117 if data == None: | |
118 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
119 return self.db_plugin_iface.gatewayRegister(action, target, data, profile_key) |
267 | 120 |
303
2b52a5da0978
plugin XEP_0277: microblog access model can now be changed
Goffi <goffi@goffi.org>
parents:
272
diff
changeset
|
121 def getLastMicroblogs(self, jid, max_items, profile_key='@DEFAULT@', callback=None, errback=None): |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
122 return self.db_plugin_iface.getLastMicroblogs(jid, max_items, profile_key, reply_handler=callback, error_handler=errback) |
267 | 123 |
307 | 124 def getMblogNodes(self, profile_key='@DEFAULT@', callback=None, errback=None): |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
125 return self.db_plugin_iface.getMblogNodes(profile_key, reply_handler=callback, error_handler=errback) |
307 | 126 |
127 def sendGroupBlog(self, groups, message, profile_key='@DEFAULT@'): | |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
128 return self.db_plugin_iface.sendGroupBlog(groups, message, profile_key) |
307 | 129 |
304 | 130 def sendPersonalEvent(self, event_type, data, profile_key='@DEFAULT@'): |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
131 return self.db_plugin_iface.sendPersonalEvent(event_type, data, profile_key) |
337
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
132 |
4402ac630712
bridge: async callback managed in bridge_constructor + misc
Goffi <goffi@goffi.org>
parents:
320
diff
changeset
|
133 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None): |
371
3ea41a199b36
bridge refactoring: categories are now core and plugin instead of communication and request
Goffi <goffi@goffi.org>
parents:
363
diff
changeset
|
134 return self.db_plugin_iface.setMicroblogAccess(access, profile_key, reply_handler=callback, error_handler=errback) |
304 | 135 |