annotate sat_bridge/DBus.py @ 49:9c79eb49d51f

DBus bridge improvment: - new method to notice clients of updated values - presence update refactored - subscriptions management are now separated from presence
author Goffi <goffi@goffi.org>
date Thu, 07 Jan 2010 00:00:25 +1100
parents a61beb21d16d
children 6455fb62ff83
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 #-*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 SAT: a jabber client
goffi@necton2
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22
goffi@necton2
parents:
diff changeset
23 from bridge import Bridge
goffi@necton2
parents:
diff changeset
24 import dbus
goffi@necton2
parents:
diff changeset
25 import dbus.service
goffi@necton2
parents:
diff changeset
26 import dbus.mainloop.glib
goffi@necton2
parents:
diff changeset
27 import pdb
goffi@necton2
parents:
diff changeset
28 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
29
10
14d7861ca59e refactoring: CONST replaced by const
Goffi <goffi@goffi.org>
parents: 7
diff changeset
30 const_INT_PREFIX = "org.goffi.SAT" #Interface prefix
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
31 const_COMM_SUFFIX = ".communication"
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
32 const_REQ_SUFFIX = ".request"
7
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
33
0
goffi@necton2
parents:
diff changeset
34 class DbusObject(dbus.service.Object):
goffi@necton2
parents:
diff changeset
35
goffi@necton2
parents:
diff changeset
36 def __init__(self, bus, path):
goffi@necton2
parents:
diff changeset
37 dbus.service.Object.__init__(self, bus, path)
goffi@necton2
parents:
diff changeset
38 debug("Init DbusObject...")
goffi@necton2
parents:
diff changeset
39 self.cb={}
goffi@necton2
parents:
diff changeset
40
goffi@necton2
parents:
diff changeset
41 def register(self, name, cb):
goffi@necton2
parents:
diff changeset
42 self.cb[name]=cb
goffi@necton2
parents:
diff changeset
43
goffi@necton2
parents:
diff changeset
44 ### signals ###
goffi@necton2
parents:
diff changeset
45
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
46 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
47 signature='sa{ss}as')
goffi@necton2
parents:
diff changeset
48 def newContact(self, contact, attributes, groups):
goffi@necton2
parents:
diff changeset
49 debug("new contact signal (%s) sended", contact)
goffi@necton2
parents:
diff changeset
50
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
51 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
52 signature='ssss')
goffi@necton2
parents:
diff changeset
53 def newMessage(self, from_jid, msg, type='chat', to=''):
goffi@necton2
parents:
diff changeset
54 debug("new message signal (from:%s msg:%s type:%s to:%s) sended", from_jid, msg, type, to)
goffi@necton2
parents:
diff changeset
55
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
56 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
57 signature='ssia{ss}')
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
58 def presenceUpdate(self, entity, show, priority, statuses):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
59 debug("presence update signal (from:%s show:%s priority:%d statuses:%s) sended" , entity, show, priority, statuses)
0
goffi@necton2
parents:
diff changeset
60
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
61 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
62 signature='ss')
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
63 def subscribe(self, type, entity):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
64 debug("subscribe (type: [%s] from:[%s])" , type, entity)
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
65
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
66 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
67 signature='sss')
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
68 def paramUpdate(self, name, value, category):
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
69 debug("param update signal: %s=%s in category %s", name, value, category)
0
goffi@necton2
parents:
diff changeset
70
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
71 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
72 signature='s')
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
73 def contactDeleted(self, entity):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
74 debug("contact deleted signal: %s", entity)
0
goffi@necton2
parents:
diff changeset
75
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
76 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX,
0
goffi@necton2
parents:
diff changeset
77 signature='ssa{ss}')
goffi@necton2
parents:
diff changeset
78 def askConfirmation(self, type, id, data):
goffi@necton2
parents:
diff changeset
79 debug("asking for confirmation: id = [%s] type = %s data = %s", id, type, data)
goffi@necton2
parents:
diff changeset
80
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
81 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX,
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
82 signature='ssa{ss}')
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
83 def actionResult(self, type, id, data):
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
84 debug("result of action: id = [%s] type = %s data = %s", id, type, data)
0
goffi@necton2
parents:
diff changeset
85
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 22
diff changeset
86 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX,
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 22
diff changeset
87 signature='ssa{sa{ss}}')
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 22
diff changeset
88 def actionResultExt(self, type, id, data):
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 22
diff changeset
89 debug("extended result of action: id = [%s] type = %s data = %s", id, type, data)
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 22
diff changeset
90
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
91 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX,
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
92 signature='sa{ss}')
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
93 def updatedValue(self, name, value):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
94 debug("updated value: %s = %s", name, value)
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
95
0
goffi@necton2
parents:
diff changeset
96 ### methods ###
goffi@necton2
parents:
diff changeset
97
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
98 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
99 in_signature='sssi', out_signature='s')
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
100 def registerNewAccount(self, login, password, host, port=5222):
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
101 info ("New account registration asked")
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
102 return self.cb["registerNewAccount"](login, password, host, port)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
103
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
104 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
105 in_signature='', out_signature='')
goffi@necton2
parents:
diff changeset
106 def connect(self):
goffi@necton2
parents:
diff changeset
107 info ("Connection asked")
goffi@necton2
parents:
diff changeset
108 return self.cb["connect"]()
goffi@necton2
parents:
diff changeset
109
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
110 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
1
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
111 in_signature='', out_signature='')
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
112 def disconnect(self):
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
113 info ("Disconnection asked")
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
114 return self.cb["disconnect"]()
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
115
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
116 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
117 in_signature='', out_signature='a(sa{ss}as)')
goffi@necton2
parents:
diff changeset
118 def getContacts(self):
goffi@necton2
parents:
diff changeset
119 debug("getContacts...")
goffi@necton2
parents:
diff changeset
120 return self.cb["getContacts"]()
goffi@necton2
parents:
diff changeset
121
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
122 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
123 in_signature='', out_signature='a{sa{s(sia{ss})}}')
0
goffi@necton2
parents:
diff changeset
124 def getPresenceStatus(self):
goffi@necton2
parents:
diff changeset
125 debug("getPresenceStatus...")
goffi@necton2
parents:
diff changeset
126 return self.cb["getPresenceStatus"]()
goffi@necton2
parents:
diff changeset
127
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
128 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
129 in_signature='', out_signature='a{ss}')
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
130 def getWaitingSub(self):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
131 debug("getWaitingSub...")
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
132 return self.cb["getWaitingSub"]()
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
133
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
134 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
135 in_signature='ss', out_signature='')
goffi@necton2
parents:
diff changeset
136 def sendMessage(self, to, message):
goffi@necton2
parents:
diff changeset
137 debug("sendMessage...")
goffi@necton2
parents:
diff changeset
138 self.cb["sendMessage"](to, message)
goffi@necton2
parents:
diff changeset
139
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
140 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
141 in_signature='ssia{ss}', out_signature='')
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
142 def setPresence(self, to="", show="", priority=0, statuses={}):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
143 self.cb["setPresence"](to, show, priority, statuses)
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
144
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
145 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
146 in_signature='ss', out_signature='')
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
147 def subscription(self, type, entity):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
148 self.cb["subscription"](type, entity)
0
goffi@necton2
parents:
diff changeset
149
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
150 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
151 in_signature='sss', out_signature='')
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 16
diff changeset
152 def setParam(self, name, value, category):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 16
diff changeset
153 self.cb["setParam"](name, str(value), category)
0
goffi@necton2
parents:
diff changeset
154
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
155 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
156 in_signature='ss', out_signature='s')
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
157 def getParamA(self, name, category="default"):
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
158 return self.cb["getParamA"](name, category)
0
goffi@necton2
parents:
diff changeset
159
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
160 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
17
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 16
diff changeset
161 in_signature='', out_signature='s')
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 16
diff changeset
162 def getParams(self):
74a39f40eb6d refactoring: using xml params (not finished yet)
Goffi <goffi@goffi.org>
parents: 16
diff changeset
163 return self.cb["getParams"]()
0
goffi@necton2
parents:
diff changeset
164
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
165 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
166 in_signature='s', out_signature='s')
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
167 def getParamsForCategory(self, category):
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
168 return self.cb["getParamsForCategory"](category)
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
169
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
170 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
171 in_signature='', out_signature='as')
goffi@necton2
parents:
diff changeset
172 def getParamsCategories(self):
goffi@necton2
parents:
diff changeset
173 return self.cb["getParamsCategories"]()
goffi@necton2
parents:
diff changeset
174
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
175 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
176 in_signature='ssi', out_signature='a{i(ss)}')
goffi@necton2
parents:
diff changeset
177 def getHistory(self, from_jid, to_jid, size):
goffi@necton2
parents:
diff changeset
178 debug("History asked for %s", to_jid)
goffi@necton2
parents:
diff changeset
179 return self.cb["getHistory"](from_jid, to_jid, size)
goffi@necton2
parents:
diff changeset
180
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
181 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
182 in_signature='s', out_signature='')
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
183 def addContact(self, entity):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
184 debug("Subscription asked for %s", entity)
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
185 return self.cb["addContact"](entity)
0
goffi@necton2
parents:
diff changeset
186
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
187 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
188 in_signature='s', out_signature='')
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
189 def delContact(self, entity):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
190 debug("Unsubscription asked for %s", entity)
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
191 return self.cb["delContact"](entity)
0
goffi@necton2
parents:
diff changeset
192
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
193 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
0
goffi@necton2
parents:
diff changeset
194 in_signature='', out_signature='b')
goffi@necton2
parents:
diff changeset
195 def isConnected(self):
goffi@necton2
parents:
diff changeset
196 debug("Connection status requested")
goffi@necton2
parents:
diff changeset
197 return self.cb["isConnected"]()
goffi@necton2
parents:
diff changeset
198
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
199 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
200 in_signature='sa{ss}', out_signature='s')
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
201 def launchAction(self, type, data):
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
202 return self.cb["launchAction"](type, data)
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
203
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
204 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
0
goffi@necton2
parents:
diff changeset
205 in_signature='sba{ss}', out_signature='')
goffi@necton2
parents:
diff changeset
206 def confirmationAnswer(self, id, accepted, data):
goffi@necton2
parents:
diff changeset
207 debug("Answer for confirmation [%s]: %s", id, "Accepted" if accepted else "Refused")
goffi@necton2
parents:
diff changeset
208 return self.cb["confirmationAnswer"](id, accepted, data)
goffi@necton2
parents:
diff changeset
209
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 25
diff changeset
210
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 25
diff changeset
211 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
0
goffi@necton2
parents:
diff changeset
212 in_signature='s', out_signature='a{ss}')
goffi@necton2
parents:
diff changeset
213 def getProgress(self, id):
goffi@necton2
parents:
diff changeset
214 #debug("Progress asked for %s", id)
goffi@necton2
parents:
diff changeset
215 return self.cb["getProgress"](id)
goffi@necton2
parents:
diff changeset
216
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
217 def __attribute_string(self, in_sign):
7
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
218 i=0
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
219 idx=0
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
220 attr_string=""
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
221 while i<len(in_sign):
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
222 if in_sign[i] not in ['b','y','n','i','x','q','u','t','d','s','a']:
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
223 raise Exception #FIXME: create an exception here (unmanaged attribute type)
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
224
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
225 attr_string += ("" if idx==0 else ",") + ("arg_%i" % idx)
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
226 idx+=1
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
227
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
228 if in_sign[i] == 'a':
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
229 while (True):
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
230 i+=1
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
231 if i>=len(in_sign):
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
232 raise Exception #FIXME: create an exception here (the '}' is not presend)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
233 if in_sign[i] == '}' or in_sign[i] == ')':
7
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
234 break
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
235 i+=1
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
236 return attr_string
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
237
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
238
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
239
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
240 def addMethod(self, name, int_suffix, in_sign, out_sign):
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
241 """Dynamically add a method to Dbus Bridge"""
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
242 #FIXME: Better way ???
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
243 attributes = self.__attribute_string(in_sign)
7
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
244
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
245 code = compile ('def '+name+' (self,'+attributes+'): return self.cb["'+name+'"]('+attributes+')', '<DBus bridge>','exec')
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
246 exec (code)
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
247 method = locals()[name]
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
248 setattr(DbusObject, name, dbus.service.method(
10
14d7861ca59e refactoring: CONST replaced by const
Goffi <goffi@goffi.org>
parents: 7
diff changeset
249 const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign)(method))
7
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
250
0
goffi@necton2
parents:
diff changeset
251 class DBusBridge(Bridge):
goffi@necton2
parents:
diff changeset
252 def __init__(self):
goffi@necton2
parents:
diff changeset
253 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
goffi@necton2
parents:
diff changeset
254 Bridge.__init__(self)
goffi@necton2
parents:
diff changeset
255 info ("Init DBus...")
goffi@necton2
parents:
diff changeset
256 self.session_bus = dbus.SessionBus()
10
14d7861ca59e refactoring: CONST replaced by const
Goffi <goffi@goffi.org>
parents: 7
diff changeset
257 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus)
0
goffi@necton2
parents:
diff changeset
258 self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge')
goffi@necton2
parents:
diff changeset
259
goffi@necton2
parents:
diff changeset
260 def newContact(self, contact, attributes, groups):
goffi@necton2
parents:
diff changeset
261 self.dbus_bridge.newContact(contact, attributes, groups)
goffi@necton2
parents:
diff changeset
262
goffi@necton2
parents:
diff changeset
263 def newMessage(self,from_jid,msg,type='chat', to=''):
goffi@necton2
parents:
diff changeset
264 debug("sending message...")
goffi@necton2
parents:
diff changeset
265 self.dbus_bridge.newMessage(from_jid, msg, type, to)
goffi@necton2
parents:
diff changeset
266
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
267 def presenceUpdate(self, entity, show, priority, statuses):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
268 debug("updating presence for %s",entity)
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
269 self.dbus_bridge.presenceUpdate(entity, show, priority, statuses)
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
270
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
271 def subscribe(self, type, entity):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
272 debug("subscribe request for %s",entity)
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
273 self.dbus_bridge.subscribe(type, entity)
0
goffi@necton2
parents:
diff changeset
274
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
275 def paramUpdate(self, name, value, category):
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
276 debug("updating param [%s] %s ", category, name)
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
277 self.dbus_bridge.paramUpdate(name, value, category)
0
goffi@necton2
parents:
diff changeset
278
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
279 def contactDeleted(self, entity):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
280 debug("sending contact deleted signal %s ", entity)
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
281 self.dbus_bridge.contactDeleted(entity)
0
goffi@necton2
parents:
diff changeset
282
goffi@necton2
parents:
diff changeset
283 def askConfirmation(self, type, id, data):
goffi@necton2
parents:
diff changeset
284 self.dbus_bridge.askConfirmation(type, id, data)
goffi@necton2
parents:
diff changeset
285
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
286 def actionResult(self, type, id, data):
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
287 self.dbus_bridge.actionResult(type, id, data)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 10
diff changeset
288
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 22
diff changeset
289 def actionResultExt(self, type, id, data):
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 22
diff changeset
290 self.dbus_bridge.actionResultExt(type, id, data)
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 22
diff changeset
291
49
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
292 def updatedValue(self, name, value):
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
293 self.dbus_bridge.updatedValue(name, value)
9c79eb49d51f DBus bridge improvment:
Goffi <goffi@goffi.org>
parents: 37
diff changeset
294
0
goffi@necton2
parents:
diff changeset
295 def register(self, name, callback):
7
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
296 debug("registering DBus bridge method [%s]",name)
0
goffi@necton2
parents:
diff changeset
297 self.dbus_bridge.register(name, callback)
goffi@necton2
parents:
diff changeset
298
7
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
299 def addMethod(self, name, int_suffix, in_sign, out_sign, method):
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
300 """Dynamically add a method to Dbus Bridge"""
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
301 print ("Adding method [%s] to DBus bridge" % name)
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
302 self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign)
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
303 self.register(name, method)
c14a3a7018a5 added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents: 1
diff changeset
304