protected override void ProcessNewChannel(string object_path,
                                                   uint initiator_handle,
                                                   uint target_handle,
                                                   ChannelDetails c)
        {
            string service_name = (string) c.Properties[Constants.CHANNEL_TYPE_DBUSTUBE + ".ServiceName"];
            Contact contact = Connection.Roster.GetContact (target_handle);

            DBusTubeChannel tube = null;
            try {
                tube = new DBusTubeChannel (this.Connection,
                                            object_path,
                                            initiator_handle,
                                            target_handle,
                                            service_name);

                DBusActivity activity = new DBusActivity (contact, tube);
                DispatchManager dm = Connection.DispatchManager;
                dm.Add (contact, activity.Service, activity, false);
            }
            catch (Exception e) {
                Console.WriteLine (e.ToString ());
                if (tube != null) {
                    tube.Dispose ();
                }
            }
        }
        protected override bool CanProcess(ChannelDetails details)
        {
            foreach (DBusTubeChannelInfo info in Connection.SupportedChannels.GetAll<DBusTubeChannelInfo> ()) {
                if (info.Service.Equals (details.Properties[Constants.CHANNEL_TYPE_DBUSTUBE + ".ServiceName"])) {
                    return true;
                }
            }

            return false;
        }
        protected override bool CanProcess(ChannelDetails details)
        {
            foreach (FileTransferChannelInfo info in Connection.SupportedChannels.GetAll<FileTransferChannelInfo> ()) {
                string content_type = (string) details.Properties[Constants.CHANNEL_TYPE_FILETRANSFER + ".ContentType"];
                string desc = (string) details.Properties[Constants.CHANNEL_TYPE_FILETRANSFER + ".Description"];
                if (info.ContentType.Equals (content_type) && info.Description.Equals (desc)) {
                    return true;
                }
            }

            return false;
        }
        protected override void ProcessNewChannel(string object_path, 
                                                   uint initiator_handle,
                                                   uint target_handle, 
                                                   ChannelDetails c)
        {
            Console.WriteLine ("Processing new channel for file transfer");

            string filename = (string) c.Properties[Constants.CHANNEL_TYPE_FILETRANSFER + ".Filename"];
            string content_type = (string) c.Properties[Constants.CHANNEL_TYPE_FILETRANSFER + ".ContentType"];
            ulong size = (ulong) c.Properties[Constants.CHANNEL_TYPE_FILETRANSFER + ".Size"];
            Contact contact = Connection.Roster.GetContact (target_handle);

            FileTransferChannel ft = null;
            FileTransfer transfer = null;

            try {
                ft = new FileTransferChannel (this.Connection,
                                              object_path,
                                              initiator_handle,
                                              target_handle,
                                              filename,
                                              content_type,
                                             (long) size);

                if (initiator_handle != Connection.SelfHandle) {
                    transfer = new IncomingFileTransfer (contact, ft);
                }
                else {
                    transfer = new OutgoingFileTransfer (contact, ft);
                }

                if (transfer != null) {
                    DispatchManager dm = Connection.DispatchManager;
                    dm.Add (contact, transfer.OriginalFilename, transfer);
                }
            }
            catch (Exception e) {
                Console.WriteLine (e.ToString ());

                if (transfer != null) {
                    transfer.Dispose ();
                } else if (ft != null) {
                    ft.Dispose ();
                }
            }
        }
        protected override void ProcessNewChannel(string object_path, 
                                                   uint initiator_handle,
                                                   uint target_handle, 
                                                   ChannelDetails c)
        {
            string service_name = (string) c.Properties[Constants.CHANNEL_TYPE_STREAMTUBE + ".Service"];
            Contact contact = Connection.Roster.GetContact (target_handle);

            StreamTubeChannel tube = null;
            Activity activity = null;

            try {
                tube = new StreamTubeChannel (this.Connection,
                                          object_path,
                                          initiator_handle,
                                          target_handle,
                                          service_name);

                if (initiator_handle == Connection.SelfHandle) {
                    tube.ServerAddress = Connection.SupportedChannels.GetChannelInfo <StreamTubeChannelInfo> (service_name).Address;
                    activity = new StreamActivityListener (contact, tube);
                }
                else {
                    activity = new StreamActivity (contact, tube);
                }

                if (activity != null) {
                    DispatchManager dm = Connection.DispatchManager;
                    dm.Add (contact, activity.Service, activity);
                }
            }
            catch (Exception e) {
                Console.WriteLine (e.ToString ());

                if (activity != null) {
                    activity.Dispose ();
                } else if (tube != null) {
                    tube.Dispose ();
                }
            }
        }
 public void HandleChannels(ObjectPath account,
                             ObjectPath connection,
                             ChannelDetails[] channels,
                             ObjectPath[] requests_satisfied,
                             ulong user_action_time,
                             IDictionary<string,object> handler_info)
 {
 }
 protected abstract void ProcessNewChannel(string object_path, 
                                            uint initiator_handle,
                                            uint target_handle, 
                                            ChannelDetails c);
        protected void OnNewChannels(ChannelDetails[] channels)
        {
            foreach (ChannelDetails c in channels) {

                string object_path = c.Channel.ToString ();
                string channel_type = (string) c.Properties[Constants.CHANNEL_IFACE + ".ChannelType"];
                HandleType handle_type = (HandleType) c.Properties[Constants.CHANNEL_IFACE + ".TargetHandleType"];
                uint target_handle = (uint) c.Properties[Constants.CHANNEL_IFACE + ".TargetHandle"];

                if (channel_type.Equals (ChannelType) && CanProcess (c)) {
                    Console.WriteLine ("NewChannel detected: object path {0}, channel_type {1}, handle_type {2}, target_handle {3}",
                                   object_path, channel_type, handle_type.ToString (), target_handle);

                    uint initiator_handle = (uint) DBusUtility.GetProperty (Connection.Bus, Connection.BusName, object_path,
                                                                     Constants.CHANNEL_IFACE, "InitiatorHandle");
                    ProcessNewChannel (object_path, initiator_handle, target_handle, c);
                    return;
                }
            }
        }
 protected abstract bool CanProcess(ChannelDetails details);
Beispiel #10
0
        private void OnNewChannels(ChannelDetails[] channels)
        {
            foreach (ChannelDetails c in channels) {

                ObjectPath object_path = c.Channel;
                string channel_type = c.Properties["org.freedesktop.Telepathy.Channel.ChannelType"] as string;
                HandleType handle_type = (HandleType) c.Properties["org.freedesktop.Telepathy.Channel.TargetHandleType"];
                uint handle = (uint) c.Properties["org.freedesktop.Telepathy.Channel.TargetHandle"];

                Console.WriteLine (MSG_PREFIX + "OnNewChannels: op {0}, channel_type {1}, handle_type {2}, handle {3}",
                                   object_path, channel_type, handle_type, handle);

                if (channel_type.Equals (Constants.CHANNEL_TYPE_DBUSTUBE)) {
                    itube = bus.GetObject<IDBusTube> (Constants.CONNMANAGER_GABBLE_IFACE, object_path);
                    //itube.NewTube += OnNewTube;
                    itube.TubeChannelStateChanged += OnTubeChannelStateChanged;
                    itube.Closed += OnTubeClosed;

                    // get tube initiator handle
                    // should be = to self_handle on client
                    // should be != to self_handle on server
                    Properties p = bus.GetObject<Properties> (Constants.CONNMANAGER_GABBLE_IFACE, object_path);
                    tube_initiator = (uint) p.Get (Constants.CHANNEL_IFACE, "InitiatorHandle");

                    if (tube_initiator == self_handle) {
                        Console.WriteLine (MSG_PREFIX + "Offering DTube");
                        addr = itube.Offer (new Dictionary<string, object>(), SocketAccessControl.Localhost);
                        Console.WriteLine (MSG_PREFIX + "Tube from {0} offered", addr);
                    }
                    else {
                        addr = itube.Accept (SocketAccessControl.Localhost);
                        Console.WriteLine (MSG_PREFIX + "Tube from {0} accepted", addr);
                    }

                }
            }
        }