# HG changeset patch # User Goffi # Date 1295900351 -3600 # Node ID bdcd535e179ef188eea0423d0e7711cdeef0552b # Parent c4b84a2d2ad1d747d02cf345a106d0a98d59db3d Bridge constructor: - moved constructor files in src/bridge/bridge_constructor - frontend side can now be generated diff -r c4b84a2d2ad1 -r bdcd535e179e frontends/src/bridge/DBus.py --- a/frontends/src/bridge/DBus.py Mon Jan 24 17:47:45 2011 +0100 +++ b/frontends/src/bridge/DBus.py Mon Jan 24 21:19:11 2011 +0100 @@ -48,91 +48,7 @@ elif iface == "request": self.db_req_iface.connect_to_signal(functionName, handler) - def getVersion(self): - return self.db_req_iface.getVersion() - - def getProfileName(self, profile_key='@DEFAULT@'): - return self.db_req_iface.getProfileName(profile_key) - - def getProfilesList(self): - return self.db_req_iface.getProfilesList() - def createProfile(self, name): - return self.db_req_iface.createProfile(name) - - def deleteProfile(self, name): - return self.db_req_iface.deleteProfile(name) - - def connect(self, profile_key='@DEFAULT@'): - return self.db_comm_iface.connect(profile_key) - - def disconnect(self, profile_key='@DEFAULT@'): - return self.db_comm_iface.disconnect(profile_key) - - def isConnected(self, profile_key='@DEFAULT@'): - return self.db_comm_iface.isConnected(profile_key) - - def getContacts(self, profile_key='@DEFAULT@'): - return self.db_comm_iface.getContacts(profile_key) - - def getPresenceStatus(self, profile_key='@DEFAULT@'): - return self.db_comm_iface.getPresenceStatus(profile_key) - - def getWaitingSub(self, profile_key='@DEFAULT@'): - return self.db_comm_iface.getWaitingSub(profile_key) - - def sendMessage(self, to, message, subject='', type='chat', profile_key='@DEFAULT@'): - return self.db_comm_iface.sendMessage(to, message, subject, type, profile_key) - - def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'): - return self.db_comm_iface.setPresence(to, show, priority, statuses, profile_key) - - def subscription(self, type, entity, profile_key='@DEFAULT@'): - return self.db_comm_iface.subscription(type, entity, profile_key) - - def setParam(self, name, value, category, profile_key='@DEFAULT@'): - return self.db_comm_iface.setParam(name, value, category, profile_key) - - def getParamA(self, name, category, profile_key='@DEFAULT@'): - return self.db_comm_iface.getParamA(name, category, profile_key) - - def getParamsUI(self, profile_key='@DEFAULT@'): - return self.db_comm_iface.getParamsUI(profile_key) - - def getParams(self, profile_key='@DEFAULT@'): - return self.db_comm_iface.getParams(profile_key) - - def getParamsForCategory(self, category, profile_key='@DEFAULT@'): - return self.db_comm_iface.getParamsForCategory(category, profile_key) - - def getParamsCategories(self): - return self.db_comm_iface.getParamsCategories() - - def getHistory(self, from_jid, to_jid, size): - return self.db_comm_iface.getHistory(from_jid, to_jid, size) - - def addContact(self, jid, profile_key='@DEFAULT@'): - return self.db_comm_iface.addContact(jid, profile_key) - - def delContact(self, jid, profile_key='@DEFAULT@'): - return self.db_comm_iface.delContact(jid, profile_key) - - def launchAction(self, type, data, profile_key='@DEFAULT@'): - return self.db_req_iface.launchAction(type, data, profile_key) - - def confirmationAnswer(self, id, accepted, data): - return self.db_req_iface.confirmationAnswer(id, accepted, data) - - def getProgress(self, id): - return self.db_req_iface.getProgress(id) - - def getMenus(self): - return self.db_req_iface.getMenus() - - def getMenuHelp(self, category, name, type="NORMAL"): - return self.db_req_iface.getMenuHelp(category, name, type) - - def callMenu(self, category, name, type="NORMAL", profile_key='@DEFAULT@'): - return self.db_req_iface.callMenu(category, name, type, profile_key) +##METHODS_PART## #methods from plugins def getRoomJoined(self, profile_key='@DEFAULT@'): diff -r c4b84a2d2ad1 -r bdcd535e179e src/bridge/DBus.py --- a/src/bridge/DBus.py Mon Jan 24 17:47:45 2011 +0100 +++ b/src/bridge/DBus.py Mon Jan 24 21:19:11 2011 +0100 @@ -42,257 +42,242 @@ ### signals ### + @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, + signature='ssa{ss}') + def actionResult(self, answer_type, id, data): + pass + + @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, + signature='ssa{sa{ss}}') + def actionResultExt(self, answer_type, id, data): + pass + + @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, + signature='ssa{ss}') + def askConfirmation(self, conf_type, id, data): + pass + @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, signature='s') def connected(self, profile): - debug("Connected signal") - - @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, - signature='s') - def disconnected(self, profile): - debug("Disconnected signal") - + pass + @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, signature='ss') def connection_error(self, error_type, profile): - debug("Connection_error signal") - - @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, - signature='sa{ss}ass') - def newContact(self, contact, attributes, groups, profile): - debug("new contact signal (%s) sended (profile: %s)", contact, profile) - - @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, - signature='sssss') - def newMessage(self, from_jid, msg, type, to, profile): - debug("new message signal (from:%s msg:%s type:%s to:%s) sended", from_jid, msg, type, to) - - @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, - signature='ssss') - def newAlert(self, msg, title, type, profile): - debug("new alert signal (title:%s type:%s msg:%s profile:%s) sended", type, title, msg, profile) - - @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, - signature='ssia{ss}s') - def presenceUpdate(self, entity, show, priority, statuses, profile): - debug("presence update signal (from:%s show:%s priority:%d statuses:%s profile:%s) sended" , entity, show, priority, statuses, profile) - - @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, - signature='sss') - def subscribe(self, type, entity, profile): - debug("subscribe (type: [%s] from:[%s] profile:[%s])" , type, entity, profile) - - @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, - signature='ssss') - def paramUpdate(self, name, value, category, profile): - debug("param update signal: %s=%s in category %s (profile: %s)", name, value, category, profile) + pass @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, signature='ss') def contactDeleted(self, entity, profile): - debug("contact deleted signal: %s (profile: %s)", entity, profile) - - @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, - signature='ssa{ss}') - def askConfirmation(self, type, id, data): - debug("asking for confirmation: id = [%s] type = %s data = %s", id, type, data) + pass + + @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, + signature='s') + def disconnected(self, profile): + pass + + @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, + signature='ssss') + def newAlert(self, message, title, alert_type, profile): + pass + + @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, + signature='sa{ss}ass') + def newContact(self, contact, attributes, groups, profile): + pass - @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, - signature='ssa{ss}') - def actionResult(self, type, id, data): - debug("result of action: id = [%s] type = %s data = %s", id, type, data) + @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, + signature='sssss') + def newMessage(self, from_jid, message, mess_type, to_jid, profile): + pass + + @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, + signature='ssss') + def paramUpdate(self, name, value, category, profile): + pass - @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, - signature='ssa{sa{ss}}') - def actionResultExt(self, type, id, data): - debug("extended result of action: id = [%s] type = %s data = %s", id, type, data) - + @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, + signature='ssia{ss}s') + def presenceUpdate(self, entity, show, priority, statuses, profile): + pass + + @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, + signature='sss') + def subscribe(self, sub_type, entity, profile): + pass + @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, signature='sa{ss}') def updatedValue(self, name, value): - debug("updated value: %s = %s", name, value) + pass + ### methods ### + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='ss', out_signature='') + def addContact(self, entity, profile_key="@DEFAULT@"): + return self.cb["addContact"](unicode(entity), unicode(profile_key)) - + @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, + in_signature='ssss', out_signature='s') + def callMenu(self, category, name, menu_type, profile_key): + return self.cb["callMenu"](unicode(category), unicode(name), unicode(menu_type), unicode(profile_key)) + + @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, + in_signature='sba{ss}', out_signature='') + def confirmationAnswer(self, id, accepted, data): + return self.cb["confirmationAnswer"](unicode(id), accepted, data) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='s', out_signature='') + def connect(self, profile_key="@DEFAULT@"): + return self.cb["connect"](unicode(profile_key)) + + @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, + in_signature='s', out_signature='i') + def createProfile(self, profile): + return self.cb["createProfile"](unicode(profile)) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='ss', out_signature='') + def delContact(self, entity, profile_key="@DEFAULT@"): + return self.cb["delContact"](unicode(entity), unicode(profile_key)) + @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, - in_signature='', out_signature='s') - def getVersion(self): - return self.cb["getVersion"]() - + in_signature='s', out_signature='i') + def deleteProfile(self, profile): + return self.cb["deleteProfile"](unicode(profile)) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='s', out_signature='') + def disconnect(self, profile_key="@DEFAULT@"): + return self.cb["disconnect"](unicode(profile_key)) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='s', out_signature='a(sa{ss}as)') + def getContacts(self, profile_key="@DEFAULT@"): + return self.cb["getContacts"](unicode(profile_key)) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='ssi', out_signature='a{i(ss)}') + def getHistory(self, from_jid, to_jid, size): + return self.cb["getHistory"](unicode(from_jid), unicode(to_jid), size) + + @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, + in_signature='sss', out_signature='s') + def getMenuHelp(self, category, name, menu_type): + return self.cb["getMenuHelp"](unicode(category), unicode(name), unicode(menu_type)) + + @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, + in_signature='', out_signature='a(sss)') + def getMenus(self, ): + return self.cb["getMenus"]() + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='sss', out_signature='s') + def getParamA(self, name, category, profile_key="@DEFAULT@"): + return self.cb["getParamA"](unicode(name), unicode(category), unicode(profile_key)) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='s', out_signature='s') + def getParams(self, profile_key="@DEFAULT@"): + return self.cb["getParams"](unicode(profile_key)) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='', out_signature='as') + def getParamsCategories(self, ): + return self.cb["getParamsCategories"]() + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='ss', out_signature='s') + def getParamsForCategory(self, category, profile_key="@DEFAULT@"): + return self.cb["getParamsForCategory"](unicode(category), unicode(profile_key)) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='s', out_signature='s') + def getParamsUI(self, profile_key="@DEFAULT@"): + return self.cb["getParamsUI"](unicode(profile_key)) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='s', out_signature='a{sa{s(sia{ss})}}') + def getPresenceStatus(self, profile_key="@DEFAULT@"): + return self.cb["getPresenceStatus"](unicode(profile_key)) + @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, in_signature='s', out_signature='s') - def getProfileName(self, profile_key): - return self.cb["getProfileName"](profile_key) - + def getProfileName(self, profile_key="@DEFAULT@"): + return self.cb["getProfileName"](unicode(profile_key)) + @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, in_signature='', out_signature='as') - def getProfilesList(self): - info ('Profile list asked') + def getProfilesList(self, ): return self.cb["getProfilesList"]() @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, - in_signature='s', out_signature='i') - def createProfile(self, name): - info ('Profile creation asked') - return self.cb["createProfile"](unicode(name)) + in_signature='s', out_signature='a{ss}') + def getProgress(self, id): + return self.cb["getProgress"](unicode(id)) @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, - in_signature='s', out_signature='i') - def deleteProfile(self, name): - info ('Profile deletion asked') - return self.cb["deleteProfile"](unicode(name)) + in_signature='', out_signature='s') + def getVersion(self, ): + return self.cb["getVersion"]() + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='s', out_signature='a{ss}') + def getWaitingSub(self, profile_key="@DEFAULT@"): + return self.cb["getWaitingSub"](unicode(profile_key)) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='s', out_signature='b') + def isConnected(self, profile_key="@DEFAULT@"): + return self.cb["isConnected"](unicode(profile_key)) + + @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, + in_signature='sa{ss}s', out_signature='s') + def launchAction(self, action_type, data, profile_key="@DEFAULT@"): + return self.cb["launchAction"](unicode(action_type), data, unicode(profile_key)) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, in_signature='sssi', out_signature='s') def registerNewAccount(self, login, password, host, port=5222): - info ("New account registration asked") - return self.cb["registerNewAccount"](login, password, host, port) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='s', out_signature='') - def connect(self, profile_key='@DEFAULT@'): - info ("Connection asked") - return self.cb["connect"](profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='s', out_signature='') - def disconnect(self, profile_key='@DEFAULT@'): - info ("Disconnection asked") - return self.cb["disconnect"](profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='s', out_signature='b') - def isConnected(self, profile_key='@DEFAULT@'): - info ("Connection status asked") - return self.cb["isConnected"](profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='s', out_signature='a(sa{ss}as)') - def getContacts(self, profile_key='@DEFAULT@'): - debug("getContacts...") - return self.cb["getContacts"](profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='s', out_signature='a{sa{s(sia{ss})}}') - def getPresenceStatus(self, profile_key='@DEFAULT@'): - debug("getPresenceStatus...") - return self.cb["getPresenceStatus"](profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='s', out_signature='a{ss}') - def getWaitingSub(self, profile_key='@DEFAULT@'): - debug("getWaitingSub...") - return self.cb["getWaitingSub"](profile_key) + return self.cb["registerNewAccount"](unicode(login), unicode(password), unicode(host), port) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, in_signature='sssss', out_signature='') - def sendMessage(self, to, message, subject="", type='chat', profile_key='@DEFAULT@'): - debug("sendMessage...") - print "sendtype=", type #gof - self.cb["sendMessage"](to, message, subject, type, profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='ssia{ss}s', out_signature='') - def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'): - self.cb["setPresence"](to, show, priority, statuses, profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='sss', out_signature='') - def subscription(self, type, entity, profile_key='@DEFAULT@'): - self.cb["subscription"](type, entity, profile_key) + def sendMessage(self, to_jid, message, subject=, mess_type="chat", profile_key="@DEFAULT@"): + return self.cb["sendMessage"](unicode(to_jid), unicode(message), unicode(subject), unicode(mess_type), unicode(profile_key)) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, in_signature='ssss', out_signature='') - def setParam(self, name, value, category, profile_key='@DEFAULT@'): - self.cb["setParam"](unicode(name), unicode(value), unicode(category), profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='sss', out_signature='s') - def getParamA(self, name, category="default", profile_key='@DEFAULT@'): - return self.cb["getParamA"](name, category, profile_key = profile_key) - + def setParam(self, name, value, category, profile_key="@DEFAULT@"): + return self.cb["setParam"](unicode(name), unicode(value), unicode(category), unicode(profile_key)) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='s', out_signature='s') - def getParamsUI(self, profile_key='@DEFAULT@'): - return self.cb["getParamsUI"](profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='s', out_signature='s') - def getParams(self, profile_key='@DEFAULT@'): - return self.cb["getParams"](profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='ss', out_signature='s') - def getParamsForCategory(self, category, profile_key='@DEFAULT@'): - return self.cb["getParamsForCategory"](category, profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='', out_signature='as') - def getParamsCategories(self): - return self.cb["getParamsCategories"]() + in_signature='ssia{ss}s', out_signature='') + def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"): + return self.cb["setPresence"](unicode(to_jid), unicode(show), priority, statuses, unicode(profile_key)) @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='ssi', out_signature='a{i(ss)}') - def getHistory(self, from_jid, to_jid, size): - debug("History asked for %s", to_jid) - return self.cb["getHistory"](from_jid, to_jid, size) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='ss', out_signature='') - def addContact(self, entity, profile_key='@DEFAULT@'): - debug("Subscription asked for %s (profile %s)", entity, profile_key) - return self.cb["addContact"](entity, profile_key) - - @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, - in_signature='ss', out_signature='') - def delContact(self, entity, profile_key='@DEFAULT@'): - debug("Unsubscription asked for %s (profile %s)", entity, profile_key) - return self.cb["delContact"](entity, profile_key) + in_signature='sss', out_signature='') + def subscription(self, sub_type, entity, profile_key="@DEFAULT@"): + return self.cb["subscription"](unicode(sub_type), unicode(entity), unicode(profile_key)) - @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, - in_signature='sa{ss}s', out_signature='s') - def launchAction(self, type, data, profile_key='@DEFAULT@'): - return self.cb["launchAction"](type, data, profile_key) - - @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, - in_signature='sba{ss}', out_signature='') - def confirmationAnswer(self, id, accepted, data): - debug("Answer for confirmation [%s]: %s", id, "Accepted" if accepted else "Refused") - return self.cb["confirmationAnswer"](id, accepted, data) - - - @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, - in_signature='s', out_signature='a{ss}') - def getProgress(self, id): - #debug("Progress asked for %s", id) - return self.cb["getProgress"](id) - - @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, - in_signature='', out_signature='a(sss)') - def getMenus(self): - return self.cb["getMenus"]() - - @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, - in_signature='sss', out_signature='s') - def getMenuHelp(self, category, name, type="NORMAL"): - return self.cb["getMenuHelp"](category, name, type) - - @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, - in_signature='ssss', out_signature='s') - def callMenu(self, category, name, type, profile_key): - return self.cb["callMenu"](category, name, type, profile_key) def __attribute_string(self, in_sign): + """Return arguments to user given a in_sign + @param in_sign: in_sign in the short form (using s,a,i,b etc) + @return: list of arguments that correspond to a in_sign (e.g.: "sss" return "arg1, arg2, arg3")""" i=0 idx=0 attr_string="" while i=len(in_sign): - raise Exception #FIXME: create an exception here (the '}' is not presend) - if in_sign[i] == '}' or in_sign[i] == ')': - break + raise ParseError("missing }") + if in_sign[i] == opening_car: + opening_count+=1 + if in_sign[i] == closing_car: + opening_count-=1 + if opening_count == 0: + break i+=1 return attr_string - - def addMethod(self, name, int_suffix, in_sign, out_sign): """Dynamically add a method to Dbus Bridge""" #FIXME: Better way ??? @@ -342,56 +333,49 @@ self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge') + def actionResult(self, answer_type, id, data): + self.dbus_bridge.actionResult(answer_type, id, data) + + def actionResultExt(self, answer_type, id, data): + self.dbus_bridge.actionResultExt(answer_type, id, data) + + def askConfirmation(self, conf_type, id, data): + self.dbus_bridge.askConfirmation(conf_type, id, data) + def connected(self, profile): self.dbus_bridge.connected(profile) - + + def connection_error(self, error_type, profile): + self.dbus_bridge.connection_error(error_type, profile) + + def contactDeleted(self, entity, profile): + self.dbus_bridge.contactDeleted(entity, profile) + def disconnected(self, profile): self.dbus_bridge.disconnected(profile) - - def connection_error(self, profile, error_type): - self.dbus_bridge.connection_error(profile, error_type) - + + def newAlert(self, message, title, alert_type, profile): + self.dbus_bridge.newAlert(message, title, alert_type, profile) + def newContact(self, contact, attributes, groups, profile): self.dbus_bridge.newContact(contact, attributes, groups, profile) - def newMessage(self, from_jid, msg, type='chat', to='', profile='@NONE@'): - debug("sending message...") - self.dbus_bridge.newMessage(from_jid, msg, type, to, profile) + def newMessage(self, from_jid, message, mess_type, to_jid, profile): + self.dbus_bridge.newMessage(from_jid, message, mess_type, to_jid, profile) - def newAlert(self, msg, title="", alert_type="INFO", profile='@NONE@'): - self.dbus_bridge.newAlert(msg, title, alert_type, profile) - + def paramUpdate(self, name, value, category, profile): + self.dbus_bridge.paramUpdate(name, value, category, profile) + def presenceUpdate(self, entity, show, priority, statuses, profile): - debug("updating presence for %s",entity) self.dbus_bridge.presenceUpdate(entity, show, priority, statuses, profile) - - def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile): - self.dbus_bridge.roomJoined(room_id, room_service, room_nicks, user_nick, profile) def subscribe(self, sub_type, entity, profile): - debug("subscribe request for %s",entity) self.dbus_bridge.subscribe(sub_type, entity, profile) - def paramUpdate(self, name, value, category, profile): - debug("updating param [%s] %s ", category, name) - self.dbus_bridge.paramUpdate(name, value, category, profile) - - def contactDeleted(self, entity, profile): - debug("sending contact deleted signal %s ", entity) - self.dbus_bridge.contactDeleted(entity, profile) - - def askConfirmation(self, type, id, data): - self.dbus_bridge.askConfirmation(type, id, data) - - def actionResult(self, type, id, data): - self.dbus_bridge.actionResult(type, id, data) - - def actionResultExt(self, type, id, data): - self.dbus_bridge.actionResultExt(type, id, data) - def updatedValue(self, name, value): self.dbus_bridge.updatedValue(name, value) + def register(self, name, callback): debug("registering DBus bridge method [%s]", name) self.dbus_bridge.register(name, callback) @@ -405,4 +389,3 @@ def addSignal(self, name, int_suffix, signature): self.dbus_bridge.addSignal(name, int_suffix, signature) setattr(DBusBridge, name, getattr(self.dbus_bridge, name)) - diff -r c4b84a2d2ad1 -r bdcd535e179e src/bridge/bridge_constructor/bridge_contructor.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/bridge/bridge_constructor/bridge_contructor.py Mon Jan 24 21:19:11 2011 +0100 @@ -0,0 +1,342 @@ +#!/usr/bin/python +#-*- coding: utf-8 -*- + +""" +SAT: a jabber client +Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + + +#consts +NAME = u"bridge_constructor" +VERSION="0.1.0" +ABOUT = NAME+u""" v%s (c) Jérôme Poisson (aka Goffi) 2011 + +--- +"""+NAME+u""" Copyright (C) 2011 Jérôme Poisson (aka Goffi) +This program comes with ABSOLUTELY NO WARRANTY; +This is free software, and you are welcome to redistribute it +under certain conditions. +--- + +This script construct a SàT bridge using the given protocol +""" +MANAGED_PROTOCOLES=['dbus'] +DEFAULT_PROTOCOLE='dbus' + +import sys +import os +from os import path +from optparse import OptionParser +from ConfigParser import SafeConfigParser as Parser +from ConfigParser import NoOptionError +import re + + +class ParseError(Exception): + #Used when the signature parsing is going wrong (invalid signature ?) + pass + +class Constructor: + + def __init__(self, bridge_template, options): + self.bridge_template = bridge_template + self.options = options + + def getValues(self, name): + """Return values of a function in a dict + @param name: Name of the function to get + @return: dict, each key has the config value or None if the value is not set""" + function={} + for option in ['type','category','sig_in','sig_out','doc']: + try: + value = self.bridge_template.get(name, option) + except NoOptionError: + value = None + function[option] = value + return function + + def getDefault(self, name): + """Return default values of a function in a dict + @param name: Name of the function to get + @return: dict, each key is the integer param number (no key if no default value)""" + default_dict={} + def_re = re.compile(r"param_(\d+)_default") + + for option in self.bridge_template.options(name): + if option == 'doc_return': + default_dict['return'] = self.bridge_template.get(name, option) + continue + match = def_re.match(option) + if match: + try: + idx = int(match.group(1)) + except ValueError: + raise ParseError("Invalid value [%s] for parameter number" % match.group(1)) + default_dict[idx] = self.bridge_template.get(name, option) + + return default_dict + + def getArgumentsDoc(self, name): + """Return documentation of arguments + @param name: Name of the function to get + @return: dict, each key is the integer param number (no key if no argument doc), value is a tuple (name, doc)""" + doc_dict={} + option_re = re.compile(r"doc_param_(\d+)") + value_re = re.compile(r"^(\w+): (.*)$", re.MULTILINE | re.DOTALL) + for option in self.bridge_template.options(name): + match = option_re.match(option) + if match: + try: + idx = int(match.group(1)) + except ValueError: + raise ParseError("Invalid value [%s] for parameter number" % match.group(1)) + value_match = value_re.match(self.bridge_template.get(name, option)) + if not value_match: + raise ParseError("Invalid value for parameter doc [%i]" % idx) + doc_dict[idx]=(value_match.group(1),value_match.group(2)) + return doc_dict + + def getArguments(self, signature, name=None, default=None, unicode_protect=False): + """Return arguments to user given a signature + @param signature: signature in the short form (using s,a,i,b etc) + @param name: dictionary of arguments name like given by getArguments + @param default: dictionary of default values, like given by getDefault + @param unicode_protect: activate unicode protection on strings (return strings as unicode(str)) + @return: list of arguments that correspond to a signature (e.g.: "sss" return "arg1, arg2, arg3")""" + i=0 + idx=0 + attr_string=[] + while i. +""" + + +from bridge import Bridge +import dbus +import dbus.service +import dbus.mainloop.glib +from logging import debug, info, error + +const_INT_PREFIX = "org.goffi.SAT" #Interface prefix +const_COMM_SUFFIX = ".communication" +const_REQ_SUFFIX = ".request" + +class DbusObject(dbus.service.Object): + + def __init__(self, bus, path): + dbus.service.Object.__init__(self, bus, path) + debug("Init DbusObject...") + self.cb={} + + def register(self, name, cb): + self.cb[name]=cb + + ### signals ### + +##SIGNALS_PART## + + ### methods ### + +##METHODS_PART## + + def __attribute_string(self, in_sign): + """Return arguments to user given a in_sign + @param in_sign: in_sign in the short form (using s,a,i,b etc) + @return: list of arguments that correspond to a in_sign (e.g.: "sss" return "arg1, arg2, arg3")""" + i=0 + idx=0 + attr_string="" + while i=len(in_sign): + raise ParseError("missing }") + if in_sign[i] == opening_car: + opening_count+=1 + if in_sign[i] == closing_car: + opening_count-=1 + if opening_count == 0: + break + i+=1 + return attr_string + + def addMethod(self, name, int_suffix, in_sign, out_sign): + """Dynamically add a method to Dbus Bridge""" + #FIXME: Better way ??? + attributes = self.__attribute_string(in_sign) + + code = compile ('def '+name+' (self,'+attributes+'): return self.cb["'+name+'"]('+attributes+')', '','exec') + exec (code) + method = locals()[name] + setattr(DbusObject, name, dbus.service.method( + const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign)(method)) + + def addSignal(self, name, int_suffix, signature): + """Dynamically add a signal to Dbus Bridge""" + #FIXME: Better way ??? + attributes = self.__attribute_string(signature) + + code = compile ('def '+name+' (self,'+attributes+'): debug ("'+name+' signal")', '','exec') + exec (code) + signal = locals()[name] + setattr(DbusObject, name, dbus.service.signal( + const_INT_PREFIX+int_suffix, signature=signature)(signal)) + +class DBusBridge(Bridge): + def __init__(self): + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + Bridge.__init__(self) + info ("Init DBus...") + self.session_bus = dbus.SessionBus() + self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) + self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge') + +##DIRECT_CALLS## + + def register(self, name, callback): + debug("registering DBus bridge method [%s]", name) + self.dbus_bridge.register(name, callback) + + def addMethod(self, name, int_suffix, in_sign, out_sign, method): + """Dynamically add a method to Dbus Bridge""" + print ("Adding method [%s] to DBus bridge" % name) + self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign) + self.register(name, method) + + def addSignal(self, name, int_suffix, signature): + self.dbus_bridge.addSignal(name, int_suffix, signature) + setattr(DBusBridge, name, getattr(self.dbus_bridge, name)) + diff -r c4b84a2d2ad1 -r bdcd535e179e src/bridge/bridge_constructor/dbus_frontend_template.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/bridge/bridge_constructor/dbus_frontend_template.py Mon Jan 24 21:19:11 2011 +0100 @@ -0,0 +1,98 @@ +#!/usr/bin/python +#-*- coding: utf-8 -*- + +""" +SAT communication bridge +Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + +from bridge_frontend import BridgeFrontend +import dbus, dbus.glib + +class BridgeExceptionNoService(Exception): + pass + +class DBusBridgeFrontend(BridgeFrontend): + def __init__(self): + try: + self.sessions_bus = dbus.SessionBus() + self.db_object = self.sessions_bus.get_object('org.goffi.SAT', + '/org/goffi/SAT/bridge') + self.db_comm_iface = dbus.Interface(self.db_object, + dbus_interface='org.goffi.SAT.communication') + self.db_req_iface = dbus.Interface(self.db_object, + dbus_interface='org.goffi.SAT.request') + except dbus.exceptions.DBusException,e: + if e._dbus_error_name=='org.freedesktop.DBus.Error.ServiceUnknown': + raise BridgeExceptionNoService + else: + raise e + #props = self.db_comm_iface.getProperties() + + def register(self, functionName, handler, iface="communication"): + if iface == "communication": + self.db_comm_iface.connect_to_signal(functionName, handler) + elif iface == "request": + self.db_req_iface.connect_to_signal(functionName, handler) + +##METHODS_PART## + +#methods from plugins + def getRoomJoined(self, profile_key='@DEFAULT@'): + return self.db_comm_iface.getRoomJoined(profile_key) + + def getRoomSubjects(self, profile_key='@DEFAULT@'): + return self.db_comm_iface.getRoomSubjects(profile_key) + + def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'): + return self.db_comm_iface.joinMUC(service, roomId, nick, profile_key) + + def tarotGameCreate(self, room_jid, players, profile_key='@DEFAULT@'): + return self.db_comm_iface.tarotGameCreate(room_jid, players, profile_key) + + def tarotGameReady(self, player, referee, profile_key='@DEFAULT@'): + return self.db_comm_iface.tarotGameReady(player, referee, profile_key) + + def tarotGameContratChoosed(self, player, referee, contrat, profile_key='@DEFAULT@'): + return self.db_comm_iface.tarotGameContratChoosed(player, referee, contrat, profile_key) + + def tarotGamePlayCards(self, player, referee, cards, profile_key='@DEFAULT@'): + return self.db_comm_iface.tarotGamePlayCards(player, referee, cards, profile_key) + + def sendFile(self, to, path, profile_key='@DEFAULT@'): + return self.db_comm_iface.sendFile(to, path, profile_key) + + def findGateways(self, target, profile_key='@DEFAULT@'): + return self.db_comm_iface.findGateways(target, profile_key) + + def getCard(self, target, profile_key='@DEFAULT@'): + return self.db_comm_iface.getCard(target, profile_key) + + def getCardCache(self, target): + return self.db_comm_iface.getCardCache(target) + + def getAvatarFile(self, hash): + return self.db_comm_iface.getAvatarFile(hash) + + def in_band_register(self, target, profile_key='@DEFAULT@'): + return self.db_comm_iface.in_band_register(target, profile_key) + + def gatewayRegister(self, action, target, data, profile_key='@DEFAULT@'): + if data == None: + data = [('', '')] #XXX: we have to do this awful hack because python dbus need to guess the signature + return self.db_req_iface.gatewayRegister(action, target, data, profile_key) + + diff -r c4b84a2d2ad1 -r bdcd535e179e src/bridge/bridge_contructor.py --- a/src/bridge/bridge_contructor.py Mon Jan 24 17:47:45 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,283 +0,0 @@ -#!/usr/bin/python -#-*- coding: utf-8 -*- - -""" -SAT: a jabber client -Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -""" - - -#consts -NAME = u"bridge_constructor" -VERSION="0.1.0" -ABOUT = NAME+u""" v%s (c) Jérôme Poisson (aka Goffi) 2011 - ---- -"""+NAME+u""" Copyright (C) 2011 Jérôme Poisson (aka Goffi) -This program comes with ABSOLUTELY NO WARRANTY; -This is free software, and you are welcome to redistribute it -under certain conditions. ---- - -This script construct a SàT bridge using the given protocol -""" -MANAGED_PROTOCOLES=['dbus'] -DEFAULT_PROTOCOLE='dbus' - -import sys -import os -from os import path -from optparse import OptionParser -from ConfigParser import SafeConfigParser as Parser -from ConfigParser import NoOptionError -import re - - -class ParseError(Exception): - #Used when the signature parsing is going wrong (invalid signature ?) - pass - -class Constructor: - - def __init__(self, bridge_template, options): - self.bridge_template = bridge_template - self.options = options - - def getValues(self, name): - """Return values of a function in a dict - @param name: Name of the function to get - @return: dict, each key has the config value or None if the value is not set""" - function={} - for option in ['type','category','sig_in','sig_out','doc']: - try: - value = self.bridge_template.get(name, option) - except NoOptionError: - value = None - function[option] = value - return function - - def getDefault(self, name): - """Return default values of a function in a dict - @param name: Name of the function to get - @return: dict, each key is the integer param number (no key if no default value)""" - default_dict={} - def_re = re.compile(r"param_(\d+)_default") - - for option in self.bridge_template.options(name): - if option == 'doc_return': - default_dict['return'] = self.bridge_template.get(name, option) - continue - match = def_re.match(option) - if match: - try: - idx = int(match.group(1)) - except ValueError: - raise ParseError("Invalid value [%s] for parameter number" % match.group(1)) - default_dict[idx] = self.bridge_template.get(name, option) - - return default_dict - - def getArgumentsDoc(self, name): - """Return documentation of arguments - @param name: Name of the function to get - @return: dict, each key is the integer param number (no key if no argument doc), value is a tuple (name, doc)""" - doc_dict={} - option_re = re.compile(r"doc_param_(\d+)") - value_re = re.compile(r"^(\w+): (.*)$", re.MULTILINE | re.DOTALL) - for option in self.bridge_template.options(name): - match = option_re.match(option) - if match: - try: - idx = int(match.group(1)) - except ValueError: - raise ParseError("Invalid value [%s] for parameter number" % match.group(1)) - value_match = value_re.match(self.bridge_template.get(name, option)) - if not value_match: - raise ParseError("Invalid value for parameter doc [%i]" % idx) - doc_dict[idx]=(value_match.group(1),value_match.group(2)) - return doc_dict - - def getArguments(self, signature, name=None, default=None): - """Return arguments to user given a signature - @param signature: signature in the short form (using s,a,i,b etc) - @return: list of arguments that correspond to a signature (e.g.: "sss" return "arg1, arg2, arg3")""" - i=0 - idx=0 - attr_string="" - while i