public void UnregisterSignalHandler() { AllJoyn.QStatus status = AllJoyn.QStatus.FAIL; // create bus attachment AllJoyn.BusAttachment bus = null; bus = new AllJoyn.BusAttachment("BusAttachmentTest", true); Assert.NotNull(bus); // create the interface description AllJoyn.InterfaceDescription testIntf = null; status = bus.CreateInterface("org.alljoyn.test.BusAttachment", out testIntf); Assert.Equal(AllJoyn.QStatus.OK, status); Assert.NotNull(testIntf); // add the signal member to the interface status = testIntf.AddSignal("testSignal", "s", "msg", 0); Assert.Equal(AllJoyn.QStatus.OK, status); // activate the interface testIntf.Activate(); // 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); // create the bus object & // add the interface to the bus object TestBusObject testBusObject = new TestBusObject(bus, "/test"); bus.RegisterBusObject(testBusObject); // get the signal member from the interface description AllJoyn.InterfaceDescription.Member testSignalMember = testIntf.GetMember("testSignal"); // register both signal handlers status = bus.RegisterSignalHandler(this.TestSignalHandlerOne, testSignalMember, null); Assert.Equal(AllJoyn.QStatus.OK, status); status = bus.RegisterSignalHandler(this.TestSignalHandlerTwo, testSignalMember, null); Assert.Equal(AllJoyn.QStatus.OK, status); // add match for the signal status = bus.AddMatch("type='signal',member='testSignal'"); Assert.Equal(AllJoyn.QStatus.OK, status); handledSignalsOne = false; handledSignalsTwo = false; signalOneMsg = null; signalTwoMsg = null; // send a signal testBusObject.SendTestSignal("test msg"); WaitEventOne(TimeSpan.FromSeconds(2)); WaitEventTwo(TimeSpan.FromSeconds(2)); // make sure that both handlers got the signal Assert.Equal(true, handledSignalsOne); Assert.Equal("test msg", signalOneMsg); Assert.Equal(true, handledSignalsTwo); Assert.Equal("test msg", signalTwoMsg); // now unregister one handler & make sure it doesn't receive the signal handledSignalsOne = false; handledSignalsTwo = false; signalOneMsg = null; signalTwoMsg = null; status = bus.UnregisterSignalHandler(this.TestSignalHandlerOne, testSignalMember, null); Assert.Equal(AllJoyn.QStatus.OK, status); // send another signal testBusObject.SendTestSignal("test msg"); // wait to see if we receive the signal WaitEventTwo(TimeSpan.FromSeconds(2)); // make sure that only the second handler got the signal Assert.Equal(false, handledSignalsOne); Assert.Null(signalOneMsg); Assert.Equal(true, handledSignalsTwo); Assert.Equal("test msg", signalTwoMsg); // TODO: move these into a teardown method? bus.Dispose(); }
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 }