Adding quit, update_now. Fixing reset_state_machine
[theonering] / src / tp / conn.py
index b761ce0..c0e1ce2 100644 (file)
@@ -42,7 +42,7 @@ from telepathy.interfaces import (CONN_INTERFACE,
 from handle import Handle
 from properties import DBusProperties
 
-from telepathy._generated.Connection import Connection as _Connection
+from _generated.Connection import Connection as _Connection
 
 _BAD = re.compile(r'(?:^[0-9])|(?:[^A-Za-z0-9])')
 
@@ -91,8 +91,11 @@ class Connection(_Connection, DBusProperties):
         self._interfaces = set()
 
         DBusProperties.__init__(self)
-        self._implement_property_get(CONN_INTERFACE,
-                {'SelfHandle': lambda: dbus.UInt32(self.GetSelfHandle())})
+        self._implement_property_get(CONN_INTERFACE, {
+                'SelfHandle': lambda: dbus.UInt32(self.GetSelfHandle()),
+                'Interfaces': lambda: dbus.Array(self.GetInterfaces(), signature='s'),
+                'Status': lambda: dbus.UInt32(self.GetStatus())
+                 })
 
         self._proto = proto
 
@@ -200,9 +203,12 @@ class Connection(_Connection, DBusProperties):
     def set_self_handle(self, handle):
         self._self_handle = handle
 
-    def get_channel_path(self):
-        ret = '%s/channel%d' % (self._object_path, self._next_channel_id)
-        self._next_channel_id += 1
+    def get_channel_path(self, suffix):
+        if not suffix:
+            ret = '%s/channel%d' % (self._object_path, self._next_channel_id)
+            self._next_channel_id += 1
+        else:
+            ret = '%s/%s' % (self._object_path, suffix)
         return ret
 
     def add_channels(self, channels, signal=True):
@@ -321,20 +327,20 @@ class Connection(_Connection, DBusProperties):
         self.check_connected()
         ret = []
         for channel in self._channels:
-            chan = (channel._object_path, channel._type, channel._get_handle_type(), channel._handle)
+            chan = (channel._object_path, channel._type, channel._handle.get_type(), channel._handle.get_id())
             ret.append(chan)
         return ret
 
 
-from telepathy._generated.Connection_Interface_Aliasing \
+from _generated.Connection_Interface_Aliasing \
         import ConnectionInterfaceAliasing
 
 
-from telepathy._generated.Connection_Interface_Avatars \
+from _generated.Connection_Interface_Avatars \
         import ConnectionInterfaceAvatars
 
 
-from telepathy._generated.Connection_Interface_Capabilities \
+from _generated.Connection_Interface_Capabilities \
         import ConnectionInterfaceCapabilities \
         as _ConnectionInterfaceCapabilities
 
@@ -392,7 +398,7 @@ class ConnectionInterfaceCapabilities(_ConnectionInterfaceCapabilities):
         # return all my capabilities
         return [(ctype, caps[1]) for ctype, caps in my_caps.iteritems()]
 
-from telepathy._generated.Connection_Interface_Requests \
+from _generated.Connection_Interface_Requests \
         import ConnectionInterfaceRequests \
         as _ConnectionInterfaceRequests
 
@@ -428,7 +434,7 @@ class ConnectionInterfaceRequests(
 
         # Allow TargetHandleType to be missing, but not to be otherwise broken.
         check_valid_type_if_exists('TargetHandleType',
-            lambda p: p > 0 and p < (2**32)-1)
+            lambda p: p >= 0 and p <= LAST_HANDLE_TYPE)
 
         # Allow TargetType to be missing, but not to be otherwise broken.
         check_valid_type_if_exists('TargetHandle',
@@ -459,9 +465,9 @@ class ConnectionInterfaceRequests(
         target_id = props.get(CHANNEL_INTERFACE + '.TargetID', None)
 
         # Handle type 0 cannot have a handle.
-        if target_handle_type == HANDLE_TYPE_NONE and target_handle != None:
+        if target_handle_type == HANDLE_TYPE_NONE and target_handle not in (None, 0):
             raise InvalidArgument('When TargetHandleType is NONE, ' +
-                'TargetHandle must be omitted')
+                'TargetHandle must be omitted or 0')
 
         # Handle type 0 cannot have a TargetID.
         if target_handle_type == HANDLE_TYPE_NONE and target_id != None:
@@ -544,11 +550,11 @@ class ConnectionInterfaceRequests(
 
         self.signal_new_channels([channel])
 
-from telepathy._generated.Connection_Interface_Presence \
+from _generated.Connection_Interface_Presence \
         import ConnectionInterfacePresence
 
-from telepathy._generated.Connection_Interface_Simple_Presence \
+from _generated.Connection_Interface_Simple_Presence \
         import ConnectionInterfaceSimplePresence
 
-from telepathy._generated.Connection_Interface_Contacts \
+from _generated.Connection_Interface_Contacts \
         import ConnectionInterfaceContacts