public override void Close() { try { tube.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
/* * private void OnNewChannel (ObjectPath object_path, string channel_type, HandleType handle_type, * uint handle, bool suppress_handler) * { * Console.WriteLine (MSG_PREFIX + "OnNewChannel: op {0}, type {1}, handle {2}", * object_path, channel_type, handle); * * if (channel_type.Equals (CHANNEL_TYPE_DBUSTUBE)) { * itube = bus.GetObject<IDBusTube> (CONNMANAGER_GABBLE_IFACE, object_path); * //itube.NewTube += OnNewTube; * itube.TubeChannelStateChanged += OnTubeChannelStateChanged; * * // get tube initiator handle * // should be = to self_handle on client * // should be != to self_handle on server * Properties p = bus.GetObject<Properties> (CONNMANAGER_GABBLE_IFACE, object_path); * tube_initiator = (uint) p.Get (CHANNEL_IFACE, "InitiatorHandle"); * * if (tube_initiator == self_handle) { * Console.WriteLine (MSG_PREFIX + "Offering DTube"); * addr = itube.OfferDBusTube (new Dictionary<string, object>()); * Console.WriteLine (MSG_PREFIX + "Tube from {0} offered", addr); * } * else { * addr = itube.AcceptDBusTube (); * Console.WriteLine (MSG_PREFIX + "Tube from {0} accepted", addr); * } * * } * } */ /* * private void OnNewTube (uint id, uint initiator, TubeType type, string service, * IDictionary<string,object> parameters, TubeState state) * { * Console.WriteLine (MSG_PREFIX + "OnNewTube: id {0), initiator {1}, service {2}", * id, initiator, service); * switch (state) { * case TubeState.LocalPending: * if (type == TubeType.DBus && initiator != self_handle && service.Equals (DTUBETEST_IFACE)) { * Console.WriteLine (MSG_PREFIX + "Accepting DTube"); * itube.AcceptDBusTube (id); * } * break; * } * * } */ private void OnTubeChannelStateChanged(TubeChannelState state) { Console.WriteLine(MSG_PREFIX + "OnTubeStateChanged: state {0}", state); switch (state) { // this state is never reached, so accepting OnNewChannel // leaving here just in case, however case TubeChannelState.LocalPending: addr = itube.Accept(SocketAccessControl.Localhost); Console.WriteLine(MSG_PREFIX + "Tube from {0} accepted", addr); break; // tube ready. set up connection and export/get object case TubeChannelState.Open: dbus_conn = Connection.Open(addr); BusG.Init(dbus_conn); if (tube_initiator != self_handle) { RegisterDBusObject(); } else { obj = dbus_conn.GetObject <IDTubeTest> (DTUBETEST_IFACE, new ObjectPath(DTUBETEST_PATH)); obj.TestSignal += OnTestSignal; obj.Hello(); IDictionary <string, object>[] dic = obj.HelloDictionary(); Console.WriteLine(MSG_PREFIX + "Got response on tube. Dictionary array has {0} items.", dic.Length); TestStruct[] ts = obj.HelloStruct(); Console.WriteLine(MSG_PREFIX + "Got response on tube. Struct array has {0} items", ts.Length); Properties p = dbus_conn.GetObject <Properties> (DTUBETEST_IFACE, new ObjectPath(DTUBETEST_PATH)); string property = (string)p.Get(DTUBETEST_IFACE, "TestProperty"); Console.WriteLine(MSG_PREFIX + "Got response on tube. Property {0}", property); itube.Close(); } break; case TubeChannelState.NotOffered: break; } }