Mercurial > libervia-backend
comparison src/memory/disco.py @ 1216:8ad37c3d58a9
memory (disco): add nodeIdentifier parameter to getItems
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 22 Sep 2014 20:34:29 +0200 |
parents | 7d640c303140 |
children | faa1129559b8 |
comparison
equal
deleted
inserted
replaced
1215:d9c399ec5dd9 | 1216:8ad37c3d58a9 |
---|---|
114 d = client.disco.requestInfo(jid_) | 114 d = client.disco.requestInfo(jid_) |
115 d.addCallback(infosCb) | 115 d.addCallback(infosCb) |
116 return d | 116 return d |
117 | 117 |
118 @defer.inlineCallbacks | 118 @defer.inlineCallbacks |
119 def getItems(self, jid_=None, profile_key=C.PROF_KEY_NONE): | 119 def getItems(self, jid_=None, nodeIdentifier='', profile_key=C.PROF_KEY_NONE): |
120 """get disco items from jid_, cache them for our own server | 120 """get disco items from jid_, cache them for our own server |
121 | 121 |
122 @param jid_: jid of the target, or None for profile's server | 122 @param jid_ (jid.JID): jid of the target, or None for profile's server |
123 @param nodeIdentifier (str): optional node identifier | |
123 @param profile_key: %(doc_profile_key)s | 124 @param profile_key: %(doc_profile_key)s |
124 @return: a Deferred which fire disco.DiscoItems | 125 @return: a Deferred which fire disco.DiscoItems |
125 """ | 126 """ |
126 client = self.host.getClient(profile_key) | 127 client = self.host.getClient(profile_key) |
127 if jid_ is None: | 128 if jid_ is None: |
130 try: | 131 try: |
131 items = self.host.memory.getEntityData(jid_, ["DISCO_ITEMS"], client.profile)["DISCO_ITEMS"] | 132 items = self.host.memory.getEntityData(jid_, ["DISCO_ITEMS"], client.profile)["DISCO_ITEMS"] |
132 log.debug("[%s] disco items are in cache" % jid_.full()) | 133 log.debug("[%s] disco items are in cache" % jid_.full()) |
133 except KeyError: | 134 except KeyError: |
134 log.debug("Caching [%s] disco items" % jid_.full()) | 135 log.debug("Caching [%s] disco items" % jid_.full()) |
135 items = yield client.disco.requestItems(jid_) | 136 items = yield client.disco.requestItems(jid_, nodeIdentifier) |
136 self.host.memory.updateEntityData(jid_, "DISCO_ITEMS", items, client.profile) | 137 self.host.memory.updateEntityData(jid_, "DISCO_ITEMS", items, client.profile) |
137 else: | 138 else: |
138 items = yield client.disco.requestItems(jid_) | 139 items = yield client.disco.requestItems(jid_, nodeIdentifier) |
139 | 140 |
140 defer.returnValue(items) | 141 defer.returnValue(items) |
141 | 142 |
142 | 143 |
143 def _infosEb(self, failure, entity_jid): | 144 def _infosEb(self, failure, entity_jid): |
166 info_d = self.getInfos(item.entity, profile_key) | 167 info_d = self.getInfos(item.entity, profile_key) |
167 info_d.addCallbacks(infosCb, self._infosEb, [item.entity], None, [item.entity]) | 168 info_d.addCallbacks(infosCb, self._infosEb, [item.entity], None, [item.entity]) |
168 defers_list.append(info_d) | 169 defers_list.append(info_d) |
169 return defer.DeferredList(defers_list) | 170 return defer.DeferredList(defers_list) |
170 | 171 |
171 d = self.getItems(jid_, profile_key) | 172 d = self.getItems(jid_, profile_key=profile_key) |
172 d.addCallback(gotItems) | 173 d.addCallback(gotItems) |
173 d.addCallback(lambda dummy: found_entities) | 174 d.addCallback(lambda dummy: found_entities) |
174 reactor.callLater(TIMEOUT, d.cancel) # FIXME: one bad service make a general timeout | 175 reactor.callLater(TIMEOUT, d.cancel) # FIXME: one bad service make a general timeout |
175 return d | 176 return d |
176 | 177 |
211 infos_d = self.getInfos(entity, profile_key) | 212 infos_d = self.getInfos(entity, profile_key) |
212 infos_d.addCallbacks(infosCb, self._infosEb, [entity], None, [entity]) | 213 infos_d.addCallbacks(infosCb, self._infosEb, [entity], None, [entity]) |
213 defer_list.append(infos_d) | 214 defer_list.append(infos_d) |
214 return defer.DeferredList(defer_list) | 215 return defer.DeferredList(defer_list) |
215 | 216 |
216 d = self.getItems(jid_, profile_key) | 217 d = self.getItems(jid_, profile_key=profile_key) |
217 d.addCallback(gotItems) | 218 d.addCallback(gotItems) |
218 d.addCallback(lambda dummy: found_entities) | 219 d.addCallback(lambda dummy: found_entities) |
219 reactor.callLater(TIMEOUT, d.cancel) # FIXME: one bad service make a general timeout | 220 reactor.callLater(TIMEOUT, d.cancel) # FIXME: one bad service make a general timeout |
220 return d | 221 return d |
221 | 222 |
259 """ Discovery method for the bridge | 260 """ Discovery method for the bridge |
260 @param entity_jid_s: entity we want to discover | 261 @param entity_jid_s: entity we want to discover |
261 | 262 |
262 @return: list of tu""" | 263 @return: list of tu""" |
263 entity = jid.JID(entity_jid_s) | 264 entity = jid.JID(entity_jid_s) |
264 disco_items = yield self.getItems(entity, profile_key) | 265 disco_items = yield self.getItems(entity, profile_key=profile_key) |
265 defer.returnValue([(item.entity.full(), item.nodeIdentifier or '', item.name or '') for item in disco_items]) | 266 defer.returnValue([(item.entity.full(), item.nodeIdentifier or '', item.name or '') for item in disco_items]) |