Example #1
0
 private static void _NameOwnerChanged(BusListener context, IntPtr busName, IntPtr previousOwner, IntPtr newOwner)
 {
     context.tmpstr0 = Marshal.PtrToStringAuto(busName);
     context.tmpstr1 = Marshal.PtrToStringAuto(previousOwner);
     context.tmpstr2 = Marshal.PtrToStringAuto(newOwner);
     context.NameOwnerChanged(context.tmpstr0, context.tmpstr1, context.tmpstr2);
 }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientBusListener" /> class.
        /// </summary>
        /// <param name="busAtt">object responsible for connecting to and optionally managing a message
        /// bus.</param>
        /// <param name="op">Stress Operation using this class as listener object</param>
        /// <param name="foundNameEvent">Event to set when the first service is discovered</param>
        public ClientBusListener(BusAttachment busAtt, StressOperation op, AutoResetEvent foundNameEvent)
        {
            this.stressOp           = op;
            this.mutex              = new Mutex();
            this.foundAvertisedName = false;
            this.foundName          = foundNameEvent;

            // Create Bus Listener and register signal handlers
            this.busListener = new BusListener(busAtt);
            this.busListener.BusDisconnected      += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
            this.busListener.BusStopping          += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
            this.busListener.FoundAdvertisedName  += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
            this.busListener.ListenerRegistered   += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
            this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
            this.busListener.LostAdvertisedName   += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
            this.busListener.NameOwnerChanged     += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);

            // Create Session Listener and register signal handlers
            this.sessionListener                       = new SessionListener(busAtt);
            this.sessionListener.SessionLost          += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost);
            this.sessionListener.SessionMemberAdded   += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded);
            this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved);

            busAtt.RegisterBusListener(this.busListener);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SignalConsumerBusListener" /> class
        /// </summary>
        /// <param name="bus">object responsible for connecting to and optionally managing a message 
        /// bus</param>
        /// <param name="foundNameEvent">event to set when the well-known name being queried 
        /// is found</param>
        public SignalConsumerBusListener(BusAttachment bus, AutoResetEvent foundNameEvent)
        {
            SessionidList = new List<uint>();
            this.busAtt = bus;
            this.foundName = foundNameEvent;

            this.busListener = new BusListener(bus);
            this.busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
            this.busListener.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
            this.busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
            this.busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
            this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
            this.busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
            this.busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);

            this.sessionListener = new SessionListener(this.busAtt);
            this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost);
            this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded);
            this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved);

            MessageReceiver signalReceiver = new MessageReceiver(bus);
            signalReceiver.SignalHandler += this.NameChangedSignalHandler;
            InterfaceDescription interfaceDescription2 = bus.GetInterface(SignalConsumerGlobals.InterfaceName);
            InterfaceMember signalMember = interfaceDescription2.GetSignal("nameChanged");
            bus.RegisterSignalHandler(signalReceiver, signalMember, string.Empty);
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MyBusListener" /> class.
        /// </summary>
        /// <param name="busAtt">object responsible for connecting to and optionally managing a message
        /// bus.</param>
        /// <param name="ops">Session operations object for this application</param>
        public MyBusListener(BusAttachment busAtt, SessionOperations ops)
        {
            this.sessionOps = ops;

            // Create Bus Listener and register signal handlers
            this.busListener = new BusListener(busAtt);
            this.busListener.BusDisconnected      += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
            this.busListener.BusStopping          += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
            this.busListener.FoundAdvertisedName  += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
            this.busListener.ListenerRegistered   += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
            this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
            this.busListener.LostAdvertisedName   += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
            this.busListener.NameOwnerChanged     += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);

            // Create Session Listener and register signal handlers
            this.sessionListener                       = new SessionListener(busAtt);
            this.sessionListener.SessionLost          += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost);
            this.sessionListener.SessionMemberAdded   += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded);
            this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved);

            // Create Session Port Listener and register signal handlers
            this.sessionPortListener = new SessionPortListener(busAtt);
            this.sessionPortListener.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler(this.SessionPortListenerAcceptSessionJoiner);
            this.sessionPortListener.SessionJoined       += new SessionPortListenerSessionJoinedHandler(this.SessionPortListenerSessionJoined);

            busAtt.RegisterBusListener(this.busListener);
        }
Example #5
0
 private static void _LostAdvertisedName(BusListener context, IntPtr name, ushort transport, IntPtr namePrefix)
 {
     context.tmpstr0 = Marshal.PtrToStringAuto(name);
     context.tmpmask = (TransportMask)transport;
     context.tmpstr1 = Marshal.PtrToStringAuto(namePrefix);
     context.LostAdvertisedName(context.tmpstr0, context.tmpmask, context.tmpstr1);
 }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MyBusListener" /> class.
        /// </summary>
        /// <param name="busAtt">object responsible for connecting to and optionally managing a message
        /// bus.</param>
        /// <param name="ops">Session operations object for this application</param>
        public MyBusListener(BusAttachment busAtt, SessionOperations ops)
        {
            this.sessionOps = ops;

            // Create Bus Listener and register signal handlers 
            this.busListener = new BusListener(busAtt);
            this.busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
            this.busListener.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
            this.busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
            this.busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
            this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
            this.busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
            this.busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);

            // Create Session Listener and register signal handlers 
            this.sessionListener = new SessionListener(busAtt);
            this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost);
            this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded);
            this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved);

            // Create Session Port Listener and register signal handlers 
            this.sessionPortListener = new SessionPortListener(busAtt);
            this.sessionPortListener.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler(this.SessionPortListenerAcceptSessionJoiner);
            this.sessionPortListener.SessionJoined += new SessionPortListenerSessionJoinedHandler(this.SessionPortListenerSessionJoined);

            busAtt.RegisterBusListener(this.busListener);
        }
Example #7
0
        /// <summary>
        /// Run the default stress op which stresses the bus attachment
        /// </summary>
        private void RunDefault()
        {
            try
            {
                BusListener busListener = new BusListener(this.busAtt);
                this.busAtt.RegisterBusListener(busListener);
                BusObject busObject = new BusObject(this.busAtt, "/default", false);
                this.busAtt.RegisterBusObject(busObject);
                this.DebugPrint("Registered BusListener and BusObject");

                uint   flags           = (uint)(RequestNameType.DBUS_NAME_REPLACE_EXISTING | RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
                string randServiceName = null;
                lock (rand)
                {
                    randServiceName = ServiceName + ".n" + rand.Next(10000000);
                }

                this.busAtt.RequestName(randServiceName, flags);
                this.busAtt.AdvertiseName(randServiceName, TransportMaskType.TRANSPORT_ANY);
                this.DebugPrint("Advertising WKN : " + randServiceName);

                this.busAtt.CancelAdvertiseName(randServiceName, TransportMaskType.TRANSPORT_ANY);
                this.busAtt.ReleaseName(randServiceName);
                this.busAtt.UnregisterBusListener(busListener);
                this.busAtt.UnregisterBusObject(busObject);
                this.DebugPrint("Successfully unraveled the default operation");
            }
            catch (Exception ex)
            {
                var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                this.DebugPrint(">>>> Default Execution Error >>>> : " + errMsg);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SignalConsumerBusListener" /> class
        /// </summary>
        /// <param name="bus">object responsible for connecting to and optionally managing a message
        /// bus</param>
        /// <param name="foundNameEvent">event to set when the well-known name being queried
        /// is found</param>
        public SignalConsumerBusListener(BusAttachment bus, AutoResetEvent foundNameEvent)
        {
            SessionidList  = new List <uint>();
            this.busAtt    = bus;
            this.foundName = foundNameEvent;

            this.busListener = new BusListener(bus);
            this.busListener.BusDisconnected      += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
            this.busListener.BusStopping          += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
            this.busListener.FoundAdvertisedName  += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
            this.busListener.ListenerRegistered   += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
            this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
            this.busListener.LostAdvertisedName   += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
            this.busListener.NameOwnerChanged     += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);

            this.sessionListener                       = new SessionListener(this.busAtt);
            this.sessionListener.SessionLost          += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost);
            this.sessionListener.SessionMemberAdded   += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded);
            this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved);

            MessageReceiver signalReceiver = new MessageReceiver(bus);

            signalReceiver.SignalHandler += this.NameChangedSignalHandler;
            InterfaceDescription interfaceDescription2 = bus.GetInterface(SignalConsumerGlobals.InterfaceName);
            InterfaceMember      signalMember          = interfaceDescription2.GetSignal("nameChanged");

            bus.RegisterSignalHandler(signalReceiver, signalMember, string.Empty);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientBusListener" /> class.
        /// </summary>
        /// <param name="busAtt">object responsible for connecting to and optionally managing a message
        /// bus.</param>
        /// <param name="op">Stress Operation using this class as listener object</param>
        /// <param name="foundNameEvent">Event to set when the first service is discovered</param>
        public ClientBusListener(BusAttachment busAtt, StressOperation op, AutoResetEvent foundNameEvent)
        {
            this.stressOp = op;
            this.mutex = new Mutex();
            this.foundAvertisedName = false;
            this.foundName = foundNameEvent;

            // Create Bus Listener and register signal handlers 
            this.busListener = new BusListener(busAtt);
            this.busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
            this.busListener.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
            this.busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
            this.busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
            this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
            this.busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
            this.busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);

            // Create Session Listener and register signal handlers 
            this.sessionListener = new SessionListener(busAtt);
            this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost);
            this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded);
            this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved);

            busAtt.RegisterBusListener(this.busListener);
        }
        public void JoinSessionAsyncTest()
        {
            BusAttachment service          = new BusAttachment("service", true, 4);
            ServiceSessionPortListener spl = new ServiceSessionPortListener(service);

            service.Start();
            service.ConnectAsync(connectSpec).AsTask().Wait();
            service.RequestName("org.alljoyn.testing.service", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            SessionOpts opts = new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY);

            service.BindSessionPort(77, new ushort[1], opts, spl.spl);
            service.AdvertiseName("org.alljoyn.testing.service", TransportMaskType.TRANSPORT_ANY);

            BusAttachment         client = new BusAttachment("client", true, 4);
            BusListener           cbl    = new BusListener(client);
            ClientSessionListener csl    = new ClientSessionListener(client);

            cbl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(
                (string name, TransportMaskType transport, string namePrefix) =>
            {
                if (namePrefix == "org.alljoyn.testing.service")
                {
                    clientFoundService.Set();
                }
            });
            client.RegisterBusListener(cbl);
            client.Start();
            client.ConnectAsync(connectSpec).AsTask().Wait();
            client.FindAdvertisedName("org.alljoyn.testing.service");
            clientFoundService.WaitOne();
            SessionOpts[]            optsOut  = new SessionOpts[1];
            Task <JoinSessionResult> joinTask = client.JoinSessionAsync("org.alljoyn.testing.service", (ushort)77, csl.sl, opts, optsOut, null).AsTask <JoinSessionResult>();

            joinTask.Wait();
            //The wait of 10ms ensures that the acceptSessionJoiner and sessionJoined callbacks are completed onthe service side.
            Task.Delay(10).Wait();
            if (QStatus.ER_OK == joinTask.Result.Status)
            {
                Assert.IsTrue(spl.AcceptSessionJoinerCalled && spl.SessionJoinedCalled);
                Assert.AreEqual(joinTask.Result.SessionId, spl.SessionId);
                Assert.AreEqual(joinTask.Result.Opts.IsMultipoint, optsOut[0].IsMultipoint);
                Assert.AreEqual(joinTask.Result.Opts.Proximity, optsOut[0].Proximity);
                Assert.AreEqual(joinTask.Result.Opts.Traffic, optsOut[0].Traffic);
                Assert.AreEqual(joinTask.Result.Opts.TransportMask, optsOut[0].TransportMask);
                Assert.AreEqual(joinTask.Result.Opts.IsMultipoint, opts.IsMultipoint);
                Assert.AreEqual(joinTask.Result.Opts.Proximity, opts.Proximity);
                Assert.AreEqual(joinTask.Result.Opts.Traffic, opts.Traffic);
                Assert.AreEqual(joinTask.Result.Opts.TransportMask, opts.TransportMask);
            }
            else
            {
                Assert.IsFalse(true);
            }
            service.LeaveSession(spl.SessionId);
            sessionLost.WaitOne();
        }
 public AdvertiseBusListener(BusAttachment bus)
 {
     this.bl                      = new BusListener(bus);
     this.FoundNames              = new HashSet <string>();
     this.LostNames               = new HashSet <string>();
     this.FoundCount              = 0;
     this.LostCount               = 0;
     this.bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
     this.bl.LostAdvertisedName  += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
     bus.RegisterBusListener(this.bl);
 }
 public BusListenerTest(BusAttachment busAtt)
 {
     this.bl = new BusListener(busAtt);
     this.bl.BusDisconnected      += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
     this.bl.BusStopping          += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
     this.bl.FoundAdvertisedName  += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
     this.bl.ListenerRegistered   += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
     this.bl.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
     this.bl.LostAdvertisedName   += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
     this.bl.NameOwnerChanged     += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);
 }
Example #13
0
 public async Task <IBusMessage> ReceiveAsync(IBusMessage request, CancellationToken stoppingToken)
 {
     if (!TryCreateChannel())
     {
         return(null);
     }
     using (BusListener listener = new BusListener(_consumer, _logger))
     {
         return(await listener.GetResponseAsync(request.Id, stoppingToken));
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="NameChangeBusListener" /> class
        /// </summary>
        /// <param name="bus">object responsible for connecting to and optionally managing a message 
        /// bus</param>
        /// <param name="foundNameEvent">event to set when the well-known name being queried 
        /// is found</param>
        public NameChangeBusListener(BusAttachment bus, AutoResetEvent foundNameEvent)
        {
            this.busAtt = bus;
            this.foundName = foundNameEvent;

            this.busListener = new BusListener(this.busAtt);
            this.busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
            this.busListener.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
            this.busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
            this.busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
            this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
            this.busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
            this.busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);

            this.sessionListener = new SessionListener(this.busAtt);
            this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost);
            this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded);
            this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="NameChangeBusListener" /> class
        /// </summary>
        /// <param name="bus">object responsible for connecting to and optionally managing a message
        /// bus</param>
        /// <param name="foundNameEvent">event to set when the well-known name being queried
        /// is found</param>
        public NameChangeBusListener(BusAttachment bus, AutoResetEvent foundNameEvent)
        {
            this.busAtt    = bus;
            this.foundName = foundNameEvent;

            this.busListener = new BusListener(this.busAtt);
            this.busListener.BusDisconnected      += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
            this.busListener.BusStopping          += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
            this.busListener.FoundAdvertisedName  += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
            this.busListener.ListenerRegistered   += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
            this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
            this.busListener.LostAdvertisedName   += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
            this.busListener.NameOwnerChanged     += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);

            this.sessionListener                       = new SessionListener(this.busAtt);
            this.sessionListener.SessionLost          += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost);
            this.sessionListener.SessionMemberAdded   += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded);
            this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved);
        }
Example #16
0
        public void SignalTest()
        {
            BusAttachment   service = new BusAttachment("signalservice", true, 4);
            SignalBusObject busObj  = new SignalBusObject(service, "/sigtest");

            service.Start();
            service.ConnectAsync(connectSpec).AsTask().Wait();
            SessionPortListener spl = new SessionPortListener(service);

            spl.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler((ushort sessionPort, string joiner, SessionOpts opts) =>
            {
                Assert.AreEqual(89, sessionPort);
                return(true);
            });
            service.RequestName("org.alljoyn.signaltesting", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            service.BindSessionPort(89, new ushort[1], new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false,
                                                                       ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), spl);
            service.AdvertiseName("org.alljoyn.signaltesting", TransportMaskType.TRANSPORT_ANY);

            BusAttachment    client = new BusAttachment("methodcaller", true, 4);
            ServiceBusObject sbo    = new ServiceBusObject(client, "/clientbusobj");
            BusListener      bl     = new BusListener(client);

            client.RegisterBusListener(bl);
            bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(
                (string name, TransportMaskType transport, string namePrefix) =>
            {
                foundSignalObjectName.Set();
            });
            client.Start();
            client.ConnectAsync(connectSpec).AsTask().Wait();
            client.FindAdvertisedName("org.alljoyn.signaltesting");
            foundSignalObjectName.WaitOne();

            Task <JoinSessionResult> joinTask = client.JoinSessionAsync("org.alljoyn.signaltesting", 89, new SessionListener(client),
                                                                        new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), new SessionOpts[1], null).AsTask <JoinSessionResult>();

            joinTask.Wait();
            Assert.IsTrue(QStatus.ER_OK == joinTask.Result.Status);

            // TODO: call BusObject.Signal() for each one of the signals in the interface and make sure
            // they're received and the data is consistent with what was sent.
        }
Example #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BasicClientBusListener" /> class
        /// </summary>
        /// <param name="bus">object responsible for connecting to and optionally managing a message 
        /// bus</param>
        /// <param name="foundNameEvent">event to set when the well-known name being queried 
        /// is found</param>
        public BasicClientBusListener(BusAttachment bus, AutoResetEvent foundNameEvent)
        {
            SessionidList = new List<uint>();
            busAtt = bus;
            foundName = foundNameEvent;

            busListener = new BusListener(bus);
            busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(BusListenerBusDisconnected);
            busListener.BusStopping += new BusListenerBusStoppingHandler(BusListenerBusStopping);
            busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(BusListenerFoundAdvertisedName);
            busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(BusListenerListenerRegistered);
            busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(BusListenerListenerUnregistered);
            busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(BusListenerLostAdvertisedName);
            busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(BusListenerNameOwnerChanged);

            sessionListener = new SessionListener(bus);
            sessionListener.SessionLost += new SessionListenerSessionLostHandler(SessionListenerSessionLost);
            sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(SessionListenerSessionMemberAdded);
            sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(SessionListenerSessionMemberRemoved);
        }
Example #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BasicClientBusListener" /> class
        /// </summary>
        /// <param name="bus">object responsible for connecting to and optionally managing a message
        /// bus</param>
        /// <param name="foundNameEvent">event to set when the well-known name being queried
        /// is found</param>
        public BasicClientBusListener(BusAttachment bus, AutoResetEvent foundNameEvent)
        {
            SessionidList = new List <uint>();
            busAtt        = bus;
            foundName     = foundNameEvent;

            busListener = new BusListener(bus);
            busListener.BusDisconnected      += new BusListenerBusDisconnectedHandler(BusListenerBusDisconnected);
            busListener.BusStopping          += new BusListenerBusStoppingHandler(BusListenerBusStopping);
            busListener.FoundAdvertisedName  += new BusListenerFoundAdvertisedNameHandler(BusListenerFoundAdvertisedName);
            busListener.ListenerRegistered   += new BusListenerListenerRegisteredHandler(BusListenerListenerRegistered);
            busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(BusListenerListenerUnregistered);
            busListener.LostAdvertisedName   += new BusListenerLostAdvertisedNameHandler(BusListenerLostAdvertisedName);
            busListener.NameOwnerChanged     += new BusListenerNameOwnerChangedHandler(BusListenerNameOwnerChanged);

            sessionListener                       = new SessionListener(bus);
            sessionListener.SessionLost          += new SessionListenerSessionLostHandler(SessionListenerSessionLost);
            sessionListener.SessionMemberAdded   += new SessionListenerSessionMemberAddedHandler(SessionListenerSessionMemberAdded);
            sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(SessionListenerSessionMemberRemoved);
        }
Example #19
0
        public Listeners(BusAttachment bus, MainPage host)
        {
            _hostPage     = host;
            _busListeners = new BusListener(bus);
            _busListeners.BusDisconnected      += new BusListenerBusDisconnectedHandler(BusListenerBusDisconnected);
            _busListeners.BusStopping          += new BusListenerBusStoppingHandler(BusListenerBusStopping);
            _busListeners.FoundAdvertisedName  += new BusListenerFoundAdvertisedNameHandler(BusListenerFoundAdvertisedName);
            _busListeners.ListenerRegistered   += new BusListenerListenerRegisteredHandler(BusListenerListenerRegistered);
            _busListeners.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(BusListenerListenerUnregistered);
            _busListeners.LostAdvertisedName   += new BusListenerLostAdvertisedNameHandler(BusListenerLostAdvertisedName);
            _busListeners.NameOwnerChanged     += new BusListenerNameOwnerChangedHandler(BusListenerNameOwnerChanged);

            _sessionPortListener = new SessionPortListener(bus);
            _sessionPortListener.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler(SessionPortListenerAcceptSessionJoiner);
            _sessionPortListener.SessionJoined       += new SessionPortListenerSessionJoinedHandler(SessionPortListenerSessionJoined);

            _sessionListener                       = new SessionListener(bus);
            _sessionListener.SessionLost          += new SessionListenerSessionLostHandler(SessionListenerSessionLost);
            _sessionListener.SessionMemberAdded   += new SessionListenerSessionMemberAddedHandler(SessionListenerSessionMemberAdded);
            _sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(SessionListenerSessionMemberRemoved);
        }
Example #20
0
        /// <summary>
        /// Initializes a new instance of the Listeners class.
        /// </summary>
        /// <param name="bus">The bus to listen on.</param>
        /// <param name="host">The main page which handles the user interface.</param>
        public Listeners(BusAttachment bus, MainPage host)
        {
            this.hostPage = host;
            this.busListeners = new BusListener(bus);
            this.busListeners.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
            this.busListeners.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
            this.busListeners.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
            this.busListeners.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
            this.busListeners.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
            this.busListeners.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
            this.busListeners.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);

            this.sessionPortListener = new SessionPortListener(bus);
            this.sessionPortListener.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler(this.SessionPortListenerAcceptSessionJoiner);
            this.sessionPortListener.SessionJoined += new SessionPortListenerSessionJoinedHandler(this.SessionPortListenerSessionJoined);

            this.sessionListener = new SessionListener(bus);
            this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost);
            this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded);
            this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved);
        }
Example #21
0
        /// <summary>
        /// Initializes a new instance of the Listeners class.
        /// </summary>
        /// <param name="bus">The BusAttachment to use.</param>
        public Listeners(BusAttachment bus)
        {
            this.bus         = bus;
            this.busListener = new BusListener(this.bus);
            this.busListener.BusDisconnected      += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
            this.busListener.BusStopping          += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
            this.busListener.FoundAdvertisedName  += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
            this.busListener.ListenerRegistered   += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
            this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
            this.busListener.LostAdvertisedName   += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
            this.busListener.NameOwnerChanged     += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);

            this.sessionPortListener = new SessionPortListener(this.bus);
            this.sessionPortListener.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler(this.SessionPortListenerAcceptSessionJoiner);
            this.sessionPortListener.SessionJoined       += new SessionPortListenerSessionJoinedHandler(this.SessionPortListenerSessionJoined);

            this.sessionListener                       = new SessionListener(this.bus);
            this.sessionListener.SessionLost          += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost);
            this.sessionListener.SessionMemberAdded   += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded);
            this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SignalServiceBusListener" /> class.
        /// </summary>
        /// <param name="bus">object responsible for connecting to and optionally managing a message
        /// bus.</param>
        public SignalServiceBusListener(BusAttachment bus)
        {
            SessionidList = new List<uint>();
            this.busAtt = bus;
            this.busListener = new BusListener(bus);
            this.busListener.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
            this.busListener.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
            this.busListener.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
            this.busListener.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
            this.busListener.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
            this.busListener.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
            this.busListener.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);

            this.sessionPortListener = new SessionPortListener(bus);
            this.sessionPortListener.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler(this.SessionPortListenerAcceptSessionJoiner);
            this.sessionPortListener.SessionJoined += new SessionPortListenerSessionJoinedHandler(this.SessionPortListenerSessionJoined);

            this.sessionListener = new SessionListener(bus);
            this.sessionListener.SessionLost += new SessionListenerSessionLostHandler(this.SessionListenerSessionLost);
            this.sessionListener.SessionMemberAdded += new SessionListenerSessionMemberAddedHandler(this.SessionListenerSessionMemberAdded);
            this.sessionListener.SessionMemberRemoved += new SessionListenerSessionMemberRemovedHandler(this.SessionListenerSessionMemberRemoved);
        }
Example #23
0
        public void SignalTest()
        {
            BusAttachment service = new BusAttachment("signalservice", true, 4);
            SignalBusObject busObj = new SignalBusObject(service, "/sigtest");
            service.Start();
            service.ConnectAsync(connectSpec).AsTask().Wait();
            SessionPortListener spl = new SessionPortListener(service);
            spl.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler((ushort sessionPort, string joiner, SessionOpts opts) =>
            {
                Assert.AreEqual(89, sessionPort);
                return true;
            });
            service.RequestName("org.alljoyn.signaltesting", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            service.BindSessionPort(89, new ushort[1], new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false,
                ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), spl);
            service.AdvertiseName("org.alljoyn.signaltesting", TransportMaskType.TRANSPORT_ANY);

            BusAttachment client = new BusAttachment("methodcaller", true, 4);
            ServiceBusObject sbo = new ServiceBusObject(client, "/clientbusobj");
            BusListener bl = new BusListener(client);
            client.RegisterBusListener(bl);
            bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(
                (string name, TransportMaskType transport, string namePrefix) =>
                {
                    foundSignalObjectName.Set();
                });
            client.Start();
            client.ConnectAsync(connectSpec).AsTask().Wait();
            client.FindAdvertisedName("org.alljoyn.signaltesting");
            foundSignalObjectName.WaitOne();

            Task<JoinSessionResult> joinTask = client.JoinSessionAsync("org.alljoyn.signaltesting", 89, new SessionListener(client),
                new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), new SessionOpts[1], null).AsTask<JoinSessionResult>();
            joinTask.Wait();
            Assert.IsTrue(QStatus.ER_OK == joinTask.Result.Status);

            // TODO: call BusObject.Signal() for each one of the signals in the interface and make sure
            // they're received and the data is consistent with what was sent.
        }
Example #24
0
        public void AddMethodHandlerTest()
        {
            BusAttachment service = new BusAttachment("methodhandler", true, 4);
            MethodHandlerBusObject busObj = new MethodHandlerBusObject(service, "/handlertest");
            service.Start();
            service.ConnectAsync(connectSpec).AsTask().Wait();
            SessionPortListener spl = new SessionPortListener(service);
            spl.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler((ushort sessionPort, string joiner, SessionOpts opts) =>
            {
                Assert.AreEqual(33, sessionPort);
                return true;
            });
            service.RequestName("org.alljoyn.methodhandlertest", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            service.BindSessionPort(33, new ushort[1], new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false,
                ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), spl);
            service.AdvertiseName("org.alljoyn.methodhandlertest", TransportMaskType.TRANSPORT_ANY);

            BusAttachment client = new BusAttachment("methodcaller", true, 4);
            BusListener bl = new BusListener(client);
            client.RegisterBusListener(bl);
            bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(
                (string name, TransportMaskType transport, string namePrefix) =>
                {
                    foundMethodObjectName.Set();
                });
            client.Start();
            client.ConnectAsync(connectSpec).AsTask().Wait();
            client.FindAdvertisedName("org.alljoyn.methodhandlertest");
            foundMethodObjectName.WaitOne();
            Task<JoinSessionResult> joinTask = client.JoinSessionAsync("org.alljoyn.methodhandlertest", 33, new SessionListener(client),
                new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), new SessionOpts[1], null).AsTask<JoinSessionResult>();
            joinTask.Wait();
            Assert.IsTrue(QStatus.ER_OK == joinTask.Result.Status);
            ProxyBusObject proxy = new ProxyBusObject(client, "org.alljoyn.methodhandlertest", "/handlertest", joinTask.Result.SessionId);
            Task<IntrospectRemoteObjectResult> introTask = proxy.IntrospectRemoteObjectAsync(null).AsTask<IntrospectRemoteObjectResult>();
            introTask.Wait();
            Assert.IsTrue(QStatus.ER_OK == introTask.Result.Status);

            MsgArg[] args1 = new MsgArg[2];
            args1[0] = new MsgArg("s", new object[] { "one" });
            args1[1] = new MsgArg("s", new object[] { "two" });
            Task<MethodCallResult> catTask = proxy.MethodCallAsync(service.GetInterface("org.alljoyn.methodhandler").GetMethod("cat"),
                args1, null, 60000, (byte)0).AsTask<MethodCallResult>();
            catTask.Wait();
            Assert.IsTrue(AllJoynMessageType.MESSAGE_METHOD_RET == catTask.Result.Message.Type);
            Assert.AreEqual("onetwo", catTask.Result.Message.GetArg(0).Value.ToString());

            // Check BUGBUG above
            //MsgArg[] args2 = new MsgArg[1];
            //args2[0] = new MsgArg("s", new object[] { "hello" });
            //Task<MethodCallResult> sayHiTask = proxy.MethodCallAsync(service.GetInterface("org.alljoyn.methodhandler").GetMethod("sayhi"),
            //    args2, null, 60000, (byte)0).AsTask<MethodCallResult>();
            //sayHiTask.Wait();
            //Assert.IsTrue(AllJoynMessageType.MESSAGE_METHOD_RET == sayHiTask.Result.Message.Type);
            //Assert.AreEqual("aloha", sayHiTask.Result.Message.GetArg(0).Value.ToString());

            // TODO: add another method call that test function with signature MethodReply(AllJoyn.Message msg, string error, string errorMessage)
        }
        public void AddMatchTest()
        {
            BusAttachment  bus    = new BusAttachment("addmatch", true, 4);
            AddMatchBusObj busObj = new AddMatchBusObj(bus);
            BusListener    bl     = new BusListener(bus);

            bus.RegisterBusListener(bl);
            busObj.MatchValid = true;
            bus.Start();
            bus.ConnectAsync(connectSpec).AsTask().Wait();

            BusAttachment service = new BusAttachment("service", true, 4);
            BusObject     busObj2 = new BusObject(service, "/serviceTest", false);

            InterfaceDescription[] intf = new InterfaceDescription[1];
            service.CreateInterface("org.alljoyn.addmatchtest", intf, false);
            intf[0].AddSignal("testSig", "s", "str", (byte)0, "");
            intf[0].Activate();
            busObj2.AddInterface(intf[0]);
            service.RegisterBusObject(busObj2);
            service.Start();
            service.ConnectAsync(connectSpec).AsTask().Wait();
            service.RequestName("org.alljoyn.addmatch", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            service.BindSessionPort(43, new ushort[1], new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false,
                                                                       ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), new SessionPortListener(service));
            service.AdvertiseName("org.alljoyn.addmatch", TransportMaskType.TRANSPORT_ANY);

            bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(
                (string name, TransportMaskType transport, string namePrefix) =>
            {
                if (namePrefix == "org.alljoyn.addmatch")
                {
                    foundService.Set();
                }
            });
            bus.FindAdvertisedName("org.alljoyn.addmatch");

            foundService.WaitOne();
            Task <JoinSessionResult> join = bus.JoinSessionAsync("org.alljoyn.addmatch", 43, new SessionListener(bus),
                                                                 new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY),
                                                                 new SessionOpts[1], null).AsTask <JoinSessionResult>();

            join.Wait();
            Assert.IsTrue(QStatus.ER_OK != join.Result.Status);

            bus.AddMatch("type='signal',interface='org.alljoyn.addmatchtest',member='testSig'");
            for (int i = 0; i < 5; i++)
            {
                calledHandle.Reset();
                MsgArg sigArg1 = new MsgArg("s", new object[] { "hello" + i });
                busObj2.Signal("", 0, intf[0].GetSignal("testSig"), new MsgArg[] { sigArg1 }, 0, (byte)AllJoynFlagType.ALLJOYN_FLAG_GLOBAL_BROADCAST);
                calledHandle.WaitOne();
            }

            bus.RemoveMatch("type='signal',interface='org.alljoyn.addmatchtest',member='testSig'");
            busObj.MatchValid = false;
            for (int i = 0; i < 10; i++)
            {
                MsgArg sigArg1 = new MsgArg("s", new object[] { "hello" + i });
                busObj2.Signal("", 0, intf[0].GetSignal("testSig"), new MsgArg[] { sigArg1 }, 0, (byte)AllJoynFlagType.ALLJOYN_FLAG_GLOBAL_BROADCAST);
            }

            bus.AddMatch("type='signal',interface='org.alljoyn.addmatchtest',member='testSig'");
            busObj.MatchValid = true;
            for (int i = 0; i < 5; i++)
            {
                calledHandle.Reset();
                MsgArg sigArg1 = new MsgArg("s", new object[] { "hello" + i });
                busObj2.Signal("", 0, intf[0].GetSignal("testSig"), new MsgArg[] { sigArg1 }, 0, (byte)AllJoynFlagType.ALLJOYN_FLAG_GLOBAL_BROADCAST);
                calledHandle.WaitOne();
            }
        }
Example #26
0
 private static void _BusStopping(BusListener context)
 {
     context.BusStopping();
 }
 public BusListenerTest(BusAttachment busAtt)
 {
     this.bl = new BusListener(busAtt);
     this.bl.BusDisconnected += new BusListenerBusDisconnectedHandler(this.BusListenerBusDisconnected);
     this.bl.BusStopping += new BusListenerBusStoppingHandler(this.BusListenerBusStopping);
     this.bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
     this.bl.ListenerRegistered += new BusListenerListenerRegisteredHandler(this.BusListenerListenerRegistered);
     this.bl.ListenerUnregistered += new BusListenerListenerUnregisteredHandler(this.BusListenerListenerUnregistered);
     this.bl.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
     this.bl.NameOwnerChanged += new BusListenerNameOwnerChangedHandler(this.BusListenerNameOwnerChanged);
 }
        public void JoinSessionAsyncTest()
        {
            BusAttachment service = new BusAttachment("service", true, 4);
            ServiceSessionPortListener spl = new ServiceSessionPortListener(service);
            service.Start();
            service.ConnectAsync(connectSpec).AsTask().Wait();
            service.RequestName("org.alljoyn.testing.service", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            SessionOpts opts = new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY);
            service.BindSessionPort(77, new ushort[1], opts, spl.spl);
            service.AdvertiseName("org.alljoyn.testing.service", TransportMaskType.TRANSPORT_ANY);

            BusAttachment client = new BusAttachment("client", true, 4);
            BusListener cbl = new BusListener(client);
            ClientSessionListener csl = new ClientSessionListener(client);
            cbl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(
                (string name, TransportMaskType transport, string namePrefix) =>
                {
                    if (namePrefix == "org.alljoyn.testing.service")
                    {
                        clientFoundService.Set();
                    }
                });
            client.RegisterBusListener(cbl);
            client.Start();
            client.ConnectAsync(connectSpec).AsTask().Wait();
            client.FindAdvertisedName("org.alljoyn.testing.service");
            clientFoundService.WaitOne();
            SessionOpts[] optsOut = new SessionOpts[1];
            Task<JoinSessionResult> joinTask = client.JoinSessionAsync("org.alljoyn.testing.service", (ushort)77, csl.sl, opts, optsOut, null).AsTask<JoinSessionResult>();
            joinTask.Wait();
            //The wait of 10ms ensures that the acceptSessionJoiner and sessionJoined callbacks are completed onthe service side.
            Task.Delay(10).Wait();
            if (QStatus.ER_OK == joinTask.Result.Status)
            {
                Assert.IsTrue(spl.AcceptSessionJoinerCalled && spl.SessionJoinedCalled);
                Assert.AreEqual(joinTask.Result.SessionId, spl.SessionId);
                Assert.AreEqual(joinTask.Result.Opts.IsMultipoint, optsOut[0].IsMultipoint);
                Assert.AreEqual(joinTask.Result.Opts.Proximity, optsOut[0].Proximity);
                Assert.AreEqual(joinTask.Result.Opts.Traffic, optsOut[0].Traffic);
                Assert.AreEqual(joinTask.Result.Opts.TransportMask, optsOut[0].TransportMask);
                Assert.AreEqual(joinTask.Result.Opts.IsMultipoint, opts.IsMultipoint);
                Assert.AreEqual(joinTask.Result.Opts.Proximity, opts.Proximity);
                Assert.AreEqual(joinTask.Result.Opts.Traffic, opts.Traffic);
                Assert.AreEqual(joinTask.Result.Opts.TransportMask, opts.TransportMask);
            } 
            else 
            {
                Assert.IsFalse(true);
            }
            service.LeaveSession(spl.SessionId);
            sessionLost.WaitOne();
        }
        public void AddMatchTest()
        {
            BusAttachment bus = new BusAttachment("addmatch", true, 4);
            AddMatchBusObj busObj = new AddMatchBusObj(bus);
            BusListener bl = new BusListener(bus);
            bus.RegisterBusListener(bl);
            busObj.MatchValid = true;
            bus.Start();
            bus.ConnectAsync(connectSpec).AsTask().Wait();

            BusAttachment service = new BusAttachment("service", true, 4);
            BusObject busObj2 = new BusObject(service, "/serviceTest", false);
            InterfaceDescription[] intf = new InterfaceDescription[1];
            service.CreateInterface("org.alljoyn.addmatchtest", intf, false);
            intf[0].AddSignal("testSig", "s", "str", (byte)0, "");
            intf[0].Activate();
            busObj2.AddInterface(intf[0]);
            service.RegisterBusObject(busObj2);
            service.Start();
            service.ConnectAsync(connectSpec).AsTask().Wait();
            service.RequestName("org.alljoyn.addmatch", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            service.BindSessionPort(43, new ushort[1], new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, 
                ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), new SessionPortListener(service));
            service.AdvertiseName("org.alljoyn.addmatch", TransportMaskType.TRANSPORT_ANY);

            bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(
                (string name, TransportMaskType transport, string namePrefix) =>
                {
                    if (namePrefix == "org.alljoyn.addmatch")
                    {
                        foundService.Set();
                    }
                });
            bus.FindAdvertisedName("org.alljoyn.addmatch");

            foundService.WaitOne();
            Task<JoinSessionResult> join = bus.JoinSessionAsync("org.alljoyn.addmatch", 43, new SessionListener(bus),
                            new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY),
                            new SessionOpts[1], null).AsTask<JoinSessionResult>();
            join.Wait();
            Assert.IsTrue(QStatus.ER_OK != join.Result.Status);

            bus.AddMatch("type='signal',interface='org.alljoyn.addmatchtest',member='testSig'");
            for (int i = 0; i < 5; i++)
            {
                calledHandle.Reset();
                MsgArg sigArg1 = new MsgArg("s", new object[] { "hello" + i });
                busObj2.Signal("", 0, intf[0].GetSignal("testSig"), new MsgArg[] { sigArg1 }, 0, (byte)AllJoynFlagType.ALLJOYN_FLAG_GLOBAL_BROADCAST);
                calledHandle.WaitOne();
            }

            bus.RemoveMatch("type='signal',interface='org.alljoyn.addmatchtest',member='testSig'");
            busObj.MatchValid = false;
            for (int i = 0; i < 10; i++)
            {
                MsgArg sigArg1 = new MsgArg("s", new object[] { "hello" + i });
                busObj2.Signal("", 0, intf[0].GetSignal("testSig"), new MsgArg[] { sigArg1 }, 0, (byte)AllJoynFlagType.ALLJOYN_FLAG_GLOBAL_BROADCAST);
            }

            bus.AddMatch("type='signal',interface='org.alljoyn.addmatchtest',member='testSig'");
            busObj.MatchValid = true;
            for (int i = 0; i < 5; i++)
            {
                calledHandle.Reset();
                MsgArg sigArg1 = new MsgArg("s", new object[] { "hello" + i });
                busObj2.Signal("", 0, intf[0].GetSignal("testSig"), new MsgArg[] { sigArg1 }, 0, (byte)AllJoynFlagType.ALLJOYN_FLAG_GLOBAL_BROADCAST);
                calledHandle.WaitOne();
            }
        }
 public AdvertiseBusListener(BusAttachment bus)
 {
     this.bl = new BusListener(bus);
     this.FoundNames = new HashSet<string>();
     this.LostNames = new HashSet<string>();
     this.FoundCount = 0;
     this.LostCount = 0;
     this.bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(this.BusListenerFoundAdvertisedName);
     this.bl.LostAdvertisedName += new BusListenerLostAdvertisedNameHandler(this.BusListenerLostAdvertisedName);
     bus.RegisterBusListener(this.bl);
 }
Example #31
0
 private static void _ListenerRegistered(BusListener context, IntPtr bus)
 {
     context._registeredBus = BusAttachment.MapBusAttachment(bus);
     context.ListenerRegistered(context._registeredBus);
 }
Example #32
0
 private static void _ListenerUnregistered(BusListener context)
 {
     context.ListenerUnregistered();
     context._registeredBus = null;
 }
Example #33
0
 public void UnregisterBusListener(BusListener listener)
 {
     alljoyn_busattachment_unregisterbuslistener(_busAttachment, listener.UnmanagedPtr);
 }
Example #34
0
 public void UnregisterBusListener(BusListener listener)
 {
     alljoyn_busattachment_unregisterbuslistener(_busAttachment, listener.UnmanagedPtr);
 }
Example #35
0
        public void AddMethodHandlerTest()
        {
            BusAttachment          service = new BusAttachment("methodhandler", true, 4);
            MethodHandlerBusObject busObj  = new MethodHandlerBusObject(service, "/handlertest");

            service.Start();
            service.ConnectAsync(connectSpec).AsTask().Wait();
            SessionPortListener spl = new SessionPortListener(service);

            spl.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler((ushort sessionPort, string joiner, SessionOpts opts) =>
            {
                Assert.AreEqual(33, sessionPort);
                return(true);
            });
            service.RequestName("org.alljoyn.methodhandlertest", (byte)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
            service.BindSessionPort(33, new ushort[1], new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false,
                                                                       ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), spl);
            service.AdvertiseName("org.alljoyn.methodhandlertest", TransportMaskType.TRANSPORT_ANY);

            BusAttachment client = new BusAttachment("methodcaller", true, 4);
            BusListener   bl     = new BusListener(client);

            client.RegisterBusListener(bl);
            bl.FoundAdvertisedName += new BusListenerFoundAdvertisedNameHandler(
                (string name, TransportMaskType transport, string namePrefix) =>
            {
                foundMethodObjectName.Set();
            });
            client.Start();
            client.ConnectAsync(connectSpec).AsTask().Wait();
            client.FindAdvertisedName("org.alljoyn.methodhandlertest");
            foundMethodObjectName.WaitOne();
            Task <JoinSessionResult> joinTask = client.JoinSessionAsync("org.alljoyn.methodhandlertest", 33, new SessionListener(client),
                                                                        new SessionOpts(TrafficType.TRAFFIC_MESSAGES, false, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY), new SessionOpts[1], null).AsTask <JoinSessionResult>();

            joinTask.Wait();
            Assert.IsTrue(QStatus.ER_OK == joinTask.Result.Status);
            ProxyBusObject proxy = new ProxyBusObject(client, "org.alljoyn.methodhandlertest", "/handlertest", joinTask.Result.SessionId);
            Task <IntrospectRemoteObjectResult> introTask = proxy.IntrospectRemoteObjectAsync(null).AsTask <IntrospectRemoteObjectResult>();

            introTask.Wait();
            Assert.IsTrue(QStatus.ER_OK == introTask.Result.Status);

            MsgArg[] args1 = new MsgArg[2];
            args1[0] = new MsgArg("s", new object[] { "one" });
            args1[1] = new MsgArg("s", new object[] { "two" });
            Task <MethodCallResult> catTask = proxy.MethodCallAsync(service.GetInterface("org.alljoyn.methodhandler").GetMethod("cat"),
                                                                    args1, null, 60000, (byte)0).AsTask <MethodCallResult>();

            catTask.Wait();
            Assert.IsTrue(AllJoynMessageType.MESSAGE_METHOD_RET == catTask.Result.Message.Type);
            Assert.AreEqual("onetwo", catTask.Result.Message.GetArg(0).Value.ToString());

            // Check BUGBUG above
            //MsgArg[] args2 = new MsgArg[1];
            //args2[0] = new MsgArg("s", new object[] { "hello" });
            //Task<MethodCallResult> sayHiTask = proxy.MethodCallAsync(service.GetInterface("org.alljoyn.methodhandler").GetMethod("sayhi"),
            //    args2, null, 60000, (byte)0).AsTask<MethodCallResult>();
            //sayHiTask.Wait();
            //Assert.IsTrue(AllJoynMessageType.MESSAGE_METHOD_RET == sayHiTask.Result.Message.Type);
            //Assert.AreEqual("aloha", sayHiTask.Result.Message.GetArg(0).Value.ToString());

            // TODO: add another method call that test function with signature MethodReply(AllJoyn.Message msg, string error, string errorMessage)
        }
Example #36
0
 private static void _BusDisconnected(BusListener context)
 {
     context.BusDisconnected();
 }
        /// <summary>
        /// Run the default stress op which stresses the bus attachment
        /// </summary>
        private void RunDefault()
        {
            try
            {
                BusListener busListener = new BusListener(this.busAtt);
                this.busAtt.RegisterBusListener(busListener);
                BusObject busObject = new BusObject(this.busAtt, "/default", false);
                this.busAtt.RegisterBusObject(busObject);
                this.DebugPrint("Registered BusListener and BusObject");

                uint flags = (uint)(RequestNameType.DBUS_NAME_REPLACE_EXISTING | RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
                string randServiceName = null;
                lock (rand)
                {
                    randServiceName = ServiceName + ".n" + rand.Next(10000000);
                }

                this.busAtt.RequestName(randServiceName, flags);
                this.busAtt.AdvertiseName(randServiceName, TransportMaskType.TRANSPORT_ANY);
                this.DebugPrint("Advertising WKN : " + randServiceName);

                this.busAtt.CancelAdvertiseName(randServiceName, TransportMaskType.TRANSPORT_ANY);
                this.busAtt.ReleaseName(randServiceName);
                this.busAtt.UnregisterBusListener(busListener);
                this.busAtt.UnregisterBusObject(busObject);
                this.DebugPrint("Successfully unraveled the default operation");
            }
            catch (Exception ex)
            {
                var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                this.DebugPrint(">>>> Default Execution Error >>>> : " + errMsg);
            }
        }