summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis-Francis Ratté-Boulianne <louis-francis.ratte-boulianne@collabora.co.uk>2010-10-22 14:18:00 -0400
committerLouis-Francis Ratté-Boulianne <louis-francis.ratte-boulianne@collabora.co.uk>2010-11-24 16:14:59 -0500
commit9fda86d8b94e840361164d48b93b64b8b99af0b7 (patch)
treee40a9dc1b482b4a8a65002e917d18b6763b5cb19 /src
parent67091b55189b0ab14db4462bfd816c8adcf3552e (diff)
Add function to ensure a handle by its name (create it if not found)
Connection managers can't override create_handle and normalize_handle to have more specific behaviours. Extra arguments can be given to create handles.
Diffstat (limited to 'src')
-rw-r--r--src/server/conn.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/server/conn.py b/src/server/conn.py
index 1d8ab7d..db2da89 100644
--- a/src/server/conn.py
+++ b/src/server/conn.py
@@ -158,6 +158,23 @@ class Connection(_Connection, DBusProperties):
if (type <= HANDLE_TYPE_NONE or type > LAST_HANDLE_TYPE):
raise InvalidArgument('handle type %s not known' % type)
+ def create_handle(self, type, name, **kwargs):
+ id = self.get_handle_id()
+ handle = Handle(id, handle_type, name)
+ self._handles[handle_type, id] = handle
+ return handle
+
+ def normalize_handle_name(self, type, name):
+ return name
+
+ def ensure_handle(self, type, name, **kwargs):
+ self.check_handle_type(type)
+ name = self.normalize_handle_name(type, name)
+ for candidate in self._handles.values():
+ if candidate.type == type and candidate.name == name:
+ return candidate
+ return self.create_handle(type, name, **kwargs)
+
def get_handle_id(self):
id = self._next_handle_id
self._next_handle_id += 1
@@ -251,17 +268,7 @@ class Connection(_Connection, DBusProperties):
ret = []
for name in names:
- handle = None
- for candidate in self._handles.values():
- if candidate.get_name() == name:
- handle = candidate
- break
-
- if not handle:
- id = self.get_handle_id()
- handle = Handle(id, handle_type, name)
- self._handles[handle_type, id] = handle
-
+ handle = self.ensure_handle(handle_type, name)
self.add_client_handle(handle, sender)
ret.append(handle.get_id())