comparison frontends/src/bridge/DBus.py @ 223:86d249b6d9b7

Files reorganisation
author Goffi <goffi@goffi.org>
date Wed, 29 Dec 2010 01:06:29 +0100
parents frontends/sat_bridge_frontend/DBus.py@879beacb8e16
children b1794cbb88e5
comparison
equal deleted inserted replaced
222:3198bfd66daa 223:86d249b6d9b7
1 #!/usr/bin/python
2 #-*- coding: utf-8 -*-
3
4 """
5 SAT communication bridge
6 Copyright (C) 2009, 2010 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 def getVersion(self):
52 return self.db_req_iface.getVersion()
53
54 def getProfileName(self, profile_key='@DEFAULT@'):
55 return self.db_req_iface.getProfileName(profile_key)
56
57 def getProfilesList(self):
58 return self.db_req_iface.getProfilesList()
59 def createProfile(self, name):
60 return self.db_req_iface.createProfile(name)
61
62 def deleteProfile(self, name):
63 return self.db_req_iface.deleteProfile(name)
64
65 def connect(self, profile_key='@DEFAULT@'):
66 return self.db_comm_iface.connect(profile_key)
67
68 def disconnect(self, profile_key='@DEFAULT@'):
69 return self.db_comm_iface.disconnect(profile_key)
70
71 def isConnected(self, profile_key='@DEFAULT@'):
72 return self.db_comm_iface.isConnected(profile_key)
73
74 def getContacts(self, profile_key='@DEFAULT@'):
75 return self.db_comm_iface.getContacts(profile_key)
76
77 def getPresenceStatus(self, profile_key='@DEFAULT@'):
78 return self.db_comm_iface.getPresenceStatus(profile_key)
79
80 def getWaitingSub(self, profile_key='@DEFAULT@'):
81 return self.db_comm_iface.getWaitingSub(profile_key)
82
83 def sendMessage(self, to, message, type='chat', profile_key='@DEFAULT@'):
84 return self.db_comm_iface.sendMessage(to, message, type, profile_key)
85
86 def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'):
87 return self.db_comm_iface.setPresence(to, show, priority, statuses, profile_key)
88
89 def subscription(self, type, entity, profile_key='@DEFAULT@'):
90 return self.db_comm_iface.subscription(type, entity, profile_key)
91
92 def setParam(self, name, value, category, profile_key='@DEFAULT@'):
93 return self.db_comm_iface.setParam(name, value, category, profile_key)
94
95 def getParamA(self, name, category, profile_key='@DEFAULT@'):
96 return self.db_comm_iface.getParamA(name, category, profile_key)
97
98 def getParamsUI(self, profile_key='@DEFAULT@'):
99 return self.db_comm_iface.getParamsUI(profile_key)
100
101 def getParams(self, profile_key='@DEFAULT@'):
102 return self.db_comm_iface.getParams(profile_key)
103
104 def getParamsForCategory(self, category, profile_key='@DEFAULT@'):
105 return self.db_comm_iface.getParamsForCategory(category, profile_key)
106
107 def getParamsCategories(self):
108 return self.db_comm_iface.getParamsCategories()
109
110 def getHistory(self, from_jid, to_jid, size):
111 return self.db_comm_iface.getHistory(from_jid, to_jid, size)
112
113 def addContact(self, jid, profile_key='@DEFAULT@'):
114 return self.db_comm_iface.addContact(jid, profile_key)
115
116 def delContact(self, jid, profile_key='@DEFAULT@'):
117 return self.db_comm_iface.delContact(jid, profile_key)
118
119 def launchAction(self, type, data, profile_key='@DEFAULT@'):
120 return self.db_req_iface.launchAction(type, data, profile_key)
121
122 def confirmationAnswer(self, id, accepted, data):
123 return self.db_req_iface.confirmationAnswer(id, accepted, data)
124
125 def getProgress(self, id):
126 return self.db_req_iface.getProgress(id)
127
128 def getMenus(self):
129 return self.db_req_iface.getMenus()
130
131 def getMenuHelp(self, category, name, type="NORMAL"):
132 return self.db_req_iface.getMenuHelp(category, name, type)
133
134 def callMenu(self, category, name, type="NORMAL", profile_key='@DEFAULT@'):
135 return self.db_req_iface.callMenu(category, name, type, profile_key)
136
137 #methods from plugins
138 def getRoomJoined(self, profile_key='@DEFAULT@'):
139 return self.db_comm_iface.getRoomJoined(profile_key)
140
141 def getRoomSubjects(self, profile_key='@DEFAULT@'):
142 return self.db_comm_iface.getRoomSubjects(profile_key)
143
144 def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'):
145 return self.db_comm_iface.joinMUC(service, roomId, nick, profile_key)
146
147 def tarotGameCreate(self, room_jid, players, profile_key='@DEFAULT@'):
148 return self.db_comm_iface.tarotGameCreate(room_jid, players, profile_key)
149
150 def tarotGameReady(self, player, referee, profile_key='@DEFAULT@'):
151 return self.db_comm_iface.tarotGameReady(player, referee, profile_key)
152
153 def tarotGameContratChoosed(self, player, referee, contrat, profile_key='@DEFAULT@'):
154 return self.db_comm_iface.tarotGameContratChoosed(player, referee, contrat, profile_key)
155
156 def tarotGamePlayCards(self, player, referee, cards, profile_key='@DEFAULT@'):
157 return self.db_comm_iface.tarotGamePlayCards(player, referee, cards, profile_key)
158
159 def sendFile(self, to, path, profile_key='@DEFAULT@'):
160 return self.db_comm_iface.sendFile(to, path, profile_key)
161
162 def findGateways(self, target, profile_key='@DEFAULT@'):
163 return self.db_comm_iface.findGateways(target, profile_key)
164
165 def getCard(self, target, profile_key='@DEFAULT@'):
166 return self.db_comm_iface.getCard(target, profile_key)
167
168 def getCardCache(self, target):
169 return self.db_comm_iface.getCardCache(target)
170
171 def getAvatarFile(self, hash):
172 return self.db_comm_iface.getAvatarFile(hash)
173
174 def in_band_register(self, target, profile_key='@DEFAULT@'):
175 return self.db_comm_iface.in_band_register(target, profile_key)
176
177 def gatewayRegister(self, action, target, data, profile_key='@DEFAULT@'):
178 if data == None:
179 data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature
180 return self.db_req_iface.gatewayRegister(action, target, data, profile_key)
181
182