comparison src/bridge/bridge_constructor/dbus_frontend_template.py @ 267:bdcd535e179e

Bridge constructor: - moved constructor files in src/bridge/bridge_constructor - frontend side can now be generated
author Goffi <goffi@goffi.org>
date Mon, 24 Jan 2011 21:19:11 +0100
parents
children 1d2e0dfe7114
comparison
equal deleted inserted replaced
266:c4b84a2d2ad1 267:bdcd535e179e
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
24
25 class BridgeExceptionNoService(Exception):
26 pass
27
28 class DBusBridgeFrontend(BridgeFrontend):
29 def __init__(self):
30 try:
31 self.sessions_bus = dbus.SessionBus()
32 self.db_object = self.sessions_bus.get_object('org.goffi.SAT',
33 '/org/goffi/SAT/bridge')
34 self.db_comm_iface = dbus.Interface(self.db_object,
35 dbus_interface='org.goffi.SAT.communication')
36 self.db_req_iface = dbus.Interface(self.db_object,
37 dbus_interface='org.goffi.SAT.request')
38 except dbus.exceptions.DBusException,e:
39 if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown':
40 raise BridgeExceptionNoService
41 else:
42 raise e
43 #props = self.db_comm_iface.getProperties()
44
45 def register(self, functionName, handler, iface="communication"):
46 if iface == "communication":
47 self.db_comm_iface.connect_to_signal(functionName, handler)
48 elif iface == "request":
49 self.db_req_iface.connect_to_signal(functionName, handler)
50
51 ##METHODS_PART##
52
53 #methods from plugins
54 def getRoomJoined(self, profile_key='@DEFAULT@'):
55 return self.db_comm_iface.getRoomJoined(profile_key)
56
57 def getRoomSubjects(self, profile_key='@DEFAULT@'):
58 return self.db_comm_iface.getRoomSubjects(profile_key)
59
60 def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'):
61 return self.db_comm_iface.joinMUC(service, roomId, nick, profile_key)
62
63 def tarotGameCreate(self, room_jid, players, profile_key='@DEFAULT@'):
64 return self.db_comm_iface.tarotGameCreate(room_jid, players, profile_key)
65
66 def tarotGameReady(self, player, referee, profile_key='@DEFAULT@'):
67 return self.db_comm_iface.tarotGameReady(player, referee, profile_key)
68
69 def tarotGameContratChoosed(self, player, referee, contrat, profile_key='@DEFAULT@'):
70 return self.db_comm_iface.tarotGameContratChoosed(player, referee, contrat, profile_key)
71
72 def tarotGamePlayCards(self, player, referee, cards, profile_key='@DEFAULT@'):
73 return self.db_comm_iface.tarotGamePlayCards(player, referee, cards, profile_key)
74
75 def sendFile(self, to, path, profile_key='@DEFAULT@'):
76 return self.db_comm_iface.sendFile(to, path, profile_key)
77
78 def findGateways(self, target, profile_key='@DEFAULT@'):
79 return self.db_comm_iface.findGateways(target, profile_key)
80
81 def getCard(self, target, profile_key='@DEFAULT@'):
82 return self.db_comm_iface.getCard(target, profile_key)
83
84 def getCardCache(self, target):
85 return self.db_comm_iface.getCardCache(target)
86
87 def getAvatarFile(self, hash):
88 return self.db_comm_iface.getAvatarFile(hash)
89
90 def in_band_register(self, target, profile_key='@DEFAULT@'):
91 return self.db_comm_iface.in_band_register(target, profile_key)
92
93 def gatewayRegister(self, action, target, data, profile_key='@DEFAULT@'):
94 if data == None:
95 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
96 return self.db_req_iface.gatewayRegister(action, target, data, profile_key)
97
98