public void TestFoundNameByTransport()
        {
            // create bus attachment
            AllJoyn.BusAttachment bus    = new AllJoyn.BusAttachment("BusListenerTest", true);
            AllJoyn.QStatus       status = AllJoyn.QStatus.FAIL;

            // start the bus attachment
            status = bus.Start();
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // connect to the bus
            status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
            Assert.Equal(AllJoyn.QStatus.OK, status);

            listenerRegistered  = false;
            foundAdvertisedName = false;
            nameOwnerChanged    = false;
            transportFound      = AllJoyn.TransportMask.None;

            // register the bus listener
            AllJoyn.BusListener busListener = new TestBusListener(this);
            bus.RegisterBusListener(busListener);
            Wait(MaxWaitTime);
            Assert.Equal(true, listenerRegistered);

            AllJoyn.SessionOpts sessionOpts = new AllJoyn.SessionOpts(
                AllJoyn.SessionOpts.TrafficType.Messages, false,
                AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

            // advertise the name, & see if we find it
            status = bus.FindAdvertisedNameByTransport(ObjectName, AllJoyn.TransportMask.Local);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(MaxWaitTime);
            Assert.Equal(true, foundAdvertisedName);
            Assert.Equal(AllJoyn.TransportMask.Local, transportFound);

            status = bus.CancelAdvertisedName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            status = bus.CancelFindAdvertisedNameByTransport(ObjectName, AllJoyn.TransportMask.Local);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            foundAdvertisedName = false;
            status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(TimeSpan.FromSeconds(1));
            Assert.Equal(false, foundAdvertisedName);

            busListener.Dispose();
            bus.Dispose();
        }
        public void TestFoundLostAdvertisedName()
        {
            // create bus attachment
            AllJoyn.BusAttachment bus    = new AllJoyn.BusAttachment("BusListenerTest", true);
            AllJoyn.QStatus       status = AllJoyn.QStatus.FAIL;

            // start the bus attachment
            status = bus.Start();
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // connect to the bus
            status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
            Assert.Equal(AllJoyn.QStatus.OK, status);

            listenerRegistered  = false;
            foundAdvertisedName = false;
            lostAdvertisedName  = false;

            // register the bus listener
            AllJoyn.BusListener busListener = new TestBusListener(this);
            bus.RegisterBusListener(busListener);
            Wait(MaxWaitTime);
            Assert.Equal(true, listenerRegistered);

            // advertise the name, & see if we find it
            status = bus.FindAdvertisedName(ObjectName);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            AllJoyn.SessionOpts sessionOpts = new AllJoyn.SessionOpts(
                AllJoyn.SessionOpts.TrafficType.Messages, false,
                AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

            status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(MaxWaitTime);
            Assert.Equal(true, foundAdvertisedName);

            // stop advertising the name, & see if we lose it
            status = bus.CancelAdvertisedName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(MaxWaitTime);
            Assert.Equal(true, lostAdvertisedName);

            // TODO: move these into a teardown method?
            busListener.Dispose();
            bus.Dispose();
        }
示例#3
0
        public void CloseDown()
        {
            if (msgBus == null)
            {
                return;                 //no need to clean anything up
            }
            AllJoynStarted = false;
            LeaveSession();
            AllJoyn.QStatus status = msgBus.CancelFindAdvertisedName(SERVICE_NAME);
            if (!status)
            {
                chatText = "CancelAdvertisedName failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("CancelAdvertisedName failed status(" + status.ToString() + ")");
            }
            status = msgBus.CancelAdvertisedName(myAdvertisedName, opts.Transports);
            if (!status)
            {
                chatText = "CancelAdvertisedName failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("CancelAdvertisedName failed status(" + status.ToString() + ")");
            }
            status = msgBus.ReleaseName(myAdvertisedName);
            if (!status)
            {
                chatText = "ReleaseName failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("ReleaseName status(" + status.ToString() + ")");
            }
            status = msgBus.UnbindSessionPort(SERVICE_PORT);
            if (!status)
            {
                chatText = "UnbindSessionPort failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("UnbindSessionPort status(" + status.ToString() + ")");
            }

            status = msgBus.Disconnect(connectedVal);
            if (!status)
            {
                chatText = "Disconnect failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("Disconnect status(" + status.ToString() + ")");
            }

            AllJoyn.InterfaceDescription.Member chatMember = testIntf.GetMember("chat");
            status     = msgBus.UnregisterSignalHandler(this.ChatSignalHandler, chatMember, null);
            chatMember = null;
            if (!status)
            {
                chatText = "UnregisterSignalHandler failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("UnregisterSignalHandler status(" + status.ToString() + ")");
            }
            if (sessionListener != null)
            {
                status          = msgBus.SetSessionListener(null, currentSessionId);
                sessionListener = null;
                if (!status)
                {
                    chatText = "SetSessionListener failed status(" + status.ToString() + ")\n" + chatText;
                    Debug.Log("SetSessionListener status(" + status.ToString() + ")");
                }
            }
            chatText = "No Exceptions(" + status.ToString() + ")\n" + chatText;
            Debug.Log("No Exceptions(" + status.ToString() + ")");
            currentSessionId     = 0;
            currentJoinedSession = null;
            sFoundName.Clear();

            connectedVal        = null;
            msgBus              = null;
            busListener         = null;
            sessionPortListener = null;
            testObj             = null;
            testIntf            = null;
            opts             = null;
            myAdvertisedName = null;

            AllJoynStarted = false;

            AllJoyn.StopAllJoynProcessing();             //Stop processing alljoyn callbacks
        }