/// <summary> /// Initializes a new instance of the ChatSessionObject class. /// </summary> /// <param name="bus">The BusAttachment to be associated with.</param> /// <param name="path">The path for the BusObject.</param> /// <param name="host">The instance of the MainPage which handles the UI for this /// application.</param> public ChatSessionObject(BusAttachment bus, string path, MainPage host) { try { this.hostPage = host; this.busObject = new BusObject(bus, path, false); /* Add the interface to this object */ InterfaceDescription[] ifaceArr = new InterfaceDescription[1]; bus.CreateInterface(ChatServiceInterfaceName, ifaceArr, false); ifaceArr[0].AddSignal("Chat", "s", "str", 0, string.Empty); ifaceArr[0].Activate(); InterfaceDescription chatIfc = bus.GetInterface(ChatServiceInterfaceName); this.busObject.AddInterface(chatIfc); this.chatSignalReceiver = new MessageReceiver(bus); this.chatSignalReceiver.SignalHandler += new MessageReceiverSignalHandler(this.ChatSignalHandler); this.chatSignalMember = chatIfc.GetMember("Chat"); bus.RegisterSignalHandler(this.chatSignalReceiver, this.chatSignalMember, path); } catch (System.Exception ex) { QStatus errCode = AllJoyn.AllJoynException.GetErrorCode(ex.HResult); string errMsg = AllJoyn.AllJoynException.GetErrorMessage(ex.HResult); this.hostPage.DisplayStatus("Create ChatSessionObject Error : " + errMsg); } }
public void AddInterfaceTest() { BusAttachment bus = new BusAttachment("addinterface", true, 4); bus.CreateInterfacesFromXml(signalIntf); bus.CreateInterfacesFromXml(methodIntf); bus.CreateInterfacesFromXml(propertyIntf); bus.CreateInterfacesFromXml(mixedIntf); bus.CreateInterfacesFromXml(emptyIntf); InterfaceDescription[] annIntf = new InterfaceDescription[1]; bus.CreateInterface("org.alljoyn.Annotated", annIntf, false); annIntf[0].AddMethod("method", "ss", "s", "in1,in2,out1", (byte)0, ""); annIntf[0].AddProperty("property", "s", (byte)PropAccessType.PROP_ACCESS_RW); annIntf[0].AddSignal("signal", "suy", "str,uint,byte", (byte)0, ""); annIntf[0].AddAnnotation("org.freedesktop.DBus.Deprecated", "false"); annIntf[0].AddMemberAnnotation("method", "org.freedesktop.DBus.Method.NoReply", "true"); annIntf[0].AddPropertyAnnotation("property", "org.freedesktop.DBus.Property.EmitsChangedSignal", "true"); annIntf[0].Activate(); BusObject busObj = new BusObject(bus, "/addinterfaces", false); busObj.AddInterface(bus.GetInterface("org.alljoyn.Signals")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Methods")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Properties")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Empty")); busObj.AddInterface(bus.GetInterface("org.alljoyn.Annotated")); }
public void CreateInterfaceTest() { BusAttachment bus = new BusAttachment("interfacetest", true, 4); InterfaceDescription[] secureIntf = new InterfaceDescription[1]; InterfaceDescription[] nonsecureIntf = new InterfaceDescription[1]; bus.CreateInterface("secureIntf", secureIntf, true); bus.CreateInterface("nonsecureIntf", nonsecureIntf, false); secureIntf[0].AddMethod("foo", "say", "ab", "str,arr1,arr2", (byte)0, ""); nonsecureIntf[0].AddSignal("bar", "say", "str,arr1", (byte)0, ""); secureIntf[0].Activate(); nonsecureIntf[0].Activate(); Assert.IsNotNull(bus.GetInterface("secureIntf")); Assert.IsNotNull(bus.GetInterface("nonsecureIntf")); InterfaceDescription[] intfs = new InterfaceDescription[12]; bus.GetInterfaces(intfs); Assert.IsNotNull(intfs[0]); Assert.IsNotNull(intfs[1]); // BUGBUG: DeleteInterface is throwing an exception saying the interfaces don't exist //bus.DeleteInterface(bus.GetInterface("secureIntf")); //bus.DeleteInterface(bus.GetInterface("nonsecureIntf")); //Assert.IsNull(bus.GetInterface("secureIntf")); //Assert.IsNull(bus.GetInterface("nonsecureIntf")); //InterfaceDescription[] nullIntfs = new InterfaceDescription[2]; //bus.GetInterfaces(nullIntfs); //Assert.IsNull(nullIntfs[0]); //Assert.IsNull(nullIntfs[1]); // TODO: It doesn't seem like you can create multiple interfaces at a time //InterfaceDescription[] multiIntf = new InterfaceDescription[5]; //bus.CreateInterface("multiIntf", multiIntf, false); try { InterfaceDescription nonExisting = bus.GetInterface("notThere"); Assert.IsFalse(true); } catch (Exception ex) { Logger.LogMessage("%s", ex.Message); } }
public AddMatchBusObj(BusAttachment bus) { this.busObj = new BusObject(bus, "/test", false); InterfaceDescription[] intf = new InterfaceDescription[1]; bus.CreateInterface("org.alljoyn.addmatchtest", intf, false); intf[0].AddSignal("testSig", "s", "str", (byte)0, ""); intf[0].Activate(); this.busObj.AddInterface(intf[0]); MessageReceiver receiver = new MessageReceiver(bus); receiver.SignalHandler += new MessageReceiverSignalHandler(this.SigHandle); bus.RegisterSignalHandler(receiver, intf[0].GetSignal("testSig"), ""); bus.RegisterBusObject(this.busObj); }
/// <summary> /// Initializes a new instance of the <see cref="SignalServiceBusObject" /> class /// </summary> /// <param name="busAtt">object responsible for connecting to and optionally managing a message /// bus</param> public SignalServiceBusObject(BusAttachment busAtt) { this.BusObject = new BusObject(busAtt, SignalServiceGlobals.ServicePath, false); this.name = string.Empty; InterfaceDescription[] interfaceDescription = new InterfaceDescription[1]; busAtt.CreateInterface(SignalServiceGlobals.InterfaceName, interfaceDescription, false); interfaceDescription[0].AddSignal("nameChanged", "s", "newName", (byte)0, string.Empty); interfaceDescription[0].AddProperty("name", "s", (byte)PropAccessType.PROP_ACCESS_RW); interfaceDescription[0].Activate(); this.BusObject.AddInterface(interfaceDescription[0]); App.OutputLine("Interface created and added to the Bus Object."); this.signalMember = interfaceDescription[0].GetSignal("nameChanged"); this.BusObject.Set += this.SetHandler; busAtt.RegisterBusObject(this.BusObject); App.OutputLine("Bus Object and property set handlers Registered."); }
public MethodHandlerBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.methodhandler", intf, false); intf[0].AddMethod("cat", "ss", "s", "in1,in2,out", (byte)0, ""); intf[0].AddMethod("sayhi", "s", "s", "in,out", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); this.catMember = intf[0].GetMethod("cat"); this.sayHiMember = intf[0].GetMethod("sayhi"); MessageReceiver catReceiver = new MessageReceiver(busAtt); catReceiver.MethodHandler += new MessageReceiverMethodHandler(this.CatHandler); MessageReceiver sayHiReceiver = new MessageReceiver(busAtt); sayHiReceiver.MethodHandler += new MessageReceiverMethodHandler(this.SayHiHandler); try { busObject.AddMethodHandler(null, catReceiver); Assert.IsFalse(true); } catch (Exception ex) { Logger.LogMessage("%s", ex.Message); } try { busObject.AddMethodHandler(intf[0].GetMethod("cat"), null); Assert.IsFalse(true); } catch (Exception ex) { Logger.LogMessage("%s", ex.Message); } busObject.AddMethodHandler(intf[0].GetMethod("cat"), catReceiver); busObject.AddMethodHandler(intf[0].GetMethod("sayhi"), sayHiReceiver); busAtt.RegisterBusObject(this.busObject); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceBusObject"/> class. /// </summary> /// <param name="busAtt">Message bus for the stress operation using this</param> /// <param name="op">Stress operation using this bus object</param> public ServiceBusObject(BusAttachment busAtt, StressOperation op) { this.stressOp = op; this.busObject = new BusObject(busAtt, ServicePath, false); // Implement the 'cat' interface InterfaceDescription[] intfDescription = new InterfaceDescription[1]; busAtt.CreateInterface(InterfaceName, intfDescription, false); intfDescription[0].AddMethod("cat", "ss", "s", "inStr1,inStr2,outStr", (byte)0, string.Empty); intfDescription[0].Activate(); this.busObject.AddInterface(intfDescription[0]); // Register 'cat' method handler InterfaceMember catMethod = intfDescription[0].GetMethod("cat"); MessageReceiver catReceiver = new MessageReceiver(busAtt); catReceiver.MethodHandler += new MessageReceiverMethodHandler(this.Cat); this.busObject.AddMethodHandler(catMethod, catReceiver); busAtt.RegisterBusObject(this.busObject); }
/// <summary> /// Initializes a new instance of the <see cref="MyBusObject"/> class /// </summary> /// <param name="busAtt">Message bus for the sessions app</param> /// <param name="ops">Session Operations object for this application</param> public MyBusObject(BusAttachment busAtt, SessionOperations ops) { this.busObject = new BusObject(busAtt, BusObjectPath, false); this.sessionOps = ops; this.ChatEcho = true; // Implement the 'Chat' interface InterfaceDescription[] intfDescription = new InterfaceDescription[1]; busAtt.CreateInterface(SessionInterfaceName, intfDescription, false); intfDescription[0].AddSignal("Chat", "s", "str", (byte)0, string.Empty); intfDescription[0].Activate(); this.chatSignal = intfDescription[0].GetSignal("Chat"); this.busObject.AddInterface(intfDescription[0]); // Register chat signal handler MessageReceiver signalReceiver = new MessageReceiver(busAtt); signalReceiver.SignalHandler += new MessageReceiverSignalHandler(this.ChatSignalHandler); busAtt.RegisterSignalHandler(signalReceiver, this.chatSignal, string.Empty); busAtt.RegisterBusObject(this.busObject); }
/// <summary> /// Initializes a new instance of the <see cref="BasicServiceBusObject" /> class /// </summary> /// <param name="busAtt">object responsible for connecting to and optionally managing a message /// bus</param> public BasicServiceBusObject(BusAttachment busAtt) { this.BusObject = new BusObject(busAtt, BasicServiceGlobals.ServicePath, false); // Create 'cat' interface InterfaceDescription[] interfaceDescription = new InterfaceDescription[1]; busAtt.CreateInterface(BasicServiceGlobals.InterfaceName, interfaceDescription, false); interfaceDescription[0].AddMethod("cat", "ss", "s", "inStr1,inStr2,outStr", (byte)0, string.Empty); interfaceDescription[0].Activate(); // Create and register the 'cat' method handlers this.BusObject.AddInterface(interfaceDescription[0]); InterfaceMember catMember = interfaceDescription[0].GetMember("cat"); MessageReceiver catReceiver = new MessageReceiver(busAtt); catReceiver.MethodHandler += new MessageReceiverMethodHandler(this.CatMethodHandler); this.BusObject.AddMethodHandler(catMember, catReceiver); App.OutputLine("Created 'cat' interface and registered method handlers."); busAtt.RegisterBusObject(this.BusObject); }
public ServiceBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.SignalVariety", intf, false); intf[0].AddSignal("string", "s", "str", (byte)0, ""); intf[0].AddSignal("byte", "y", "byte", (byte)0, ""); intf[0].AddSignal("bool", "b", "bool", (byte)0, ""); intf[0].AddSignal("int16", "n", "int16", (byte)0, ""); intf[0].AddSignal("uint16", "q", "uint16", (byte)0, ""); intf[0].AddSignal("int32", "i", "int32", (byte)0, ""); intf[0].AddSignal("uint32", "u", "uint32", (byte)0, ""); intf[0].AddSignal("int64", "x", "int64", (byte)0, ""); intf[0].AddSignal("uint64", "t", "uint64", (byte)0, ""); intf[0].AddSignal("double", "d", "double", (byte)0, ""); intf[0].AddSignal("dArray", "ad", "dArray", (byte)0, ""); intf[0].AddSignal("byiStruct", "(byi)", "byiStruct", (byte)0, ""); intf[0].AddSignal("isDict", "{is}", "isDict", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); busAtt.RegisterBusObject(this.busObject); }
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 SignalBusObject(BusAttachment busAtt, string path) { this.busObject = new BusObject(busAtt, path, false); InterfaceDescription[] intf = new InterfaceDescription[1]; busAtt.CreateInterface("org.alljoyn.SignalVariety", intf, false); intf[0].AddSignal("string", "s", "str", (byte)0, ""); intf[0].AddSignal("byte", "y", "byte", (byte)0, ""); intf[0].AddSignal("bool", "b", "bool", (byte)0, ""); intf[0].AddSignal("int16", "n", "int16", (byte)0, ""); intf[0].AddSignal("uint16", "q", "uint16", (byte)0, ""); intf[0].AddSignal("int32", "i", "int32", (byte)0, ""); intf[0].AddSignal("uint32", "u", "uint32", (byte)0, ""); intf[0].AddSignal("int64", "x", "int64", (byte)0, ""); intf[0].AddSignal("uint64", "t", "uint64", (byte)0, ""); intf[0].AddSignal("double", "d", "double", (byte)0, ""); intf[0].AddSignal("dArray", "ad", "dArray", (byte)0, ""); intf[0].AddSignal("byiStruct", "(byi)", "byiStruct", (byte)0, ""); intf[0].AddSignal("isDict", "{is}", "isDict", (byte)0, ""); intf[0].Activate(); this.busObject.AddInterface(intf[0]); MessageReceiver msgReceiver1 = new MessageReceiver(busAtt); msgReceiver1.SignalHandler += new MessageReceiverSignalHandler(this.StringSig); busAtt.RegisterSignalHandler(msgReceiver1, intf[0].GetSignal("string"), ""); MessageReceiver msgReceiver2 = new MessageReceiver(busAtt); msgReceiver2.SignalHandler += new MessageReceiverSignalHandler(this.ByteSig); busAtt.RegisterSignalHandler(msgReceiver2, intf[0].GetSignal("byte"), ""); MessageReceiver msgReceiver3 = new MessageReceiver(busAtt); msgReceiver3.SignalHandler += new MessageReceiverSignalHandler(this.BoolSig); busAtt.RegisterSignalHandler(msgReceiver3, intf[0].GetSignal("bool"), ""); MessageReceiver msgReceiver4 = new MessageReceiver(busAtt); msgReceiver4.SignalHandler += new MessageReceiverSignalHandler(this.Int16Sig); busAtt.RegisterSignalHandler(msgReceiver4, intf[0].GetSignal("int16"), ""); MessageReceiver msgReceiver5 = new MessageReceiver(busAtt); msgReceiver5.SignalHandler += new MessageReceiverSignalHandler(this.Uint16Sig); busAtt.RegisterSignalHandler(msgReceiver5, intf[0].GetSignal("uint16"), ""); MessageReceiver msgReceiver6 = new MessageReceiver(busAtt); msgReceiver6.SignalHandler += new MessageReceiverSignalHandler(this.Int32Sig); busAtt.RegisterSignalHandler(msgReceiver6, intf[0].GetSignal("int32"), ""); MessageReceiver msgReceiver7 = new MessageReceiver(busAtt); msgReceiver7.SignalHandler += new MessageReceiverSignalHandler(this.Uint32Sig); busAtt.RegisterSignalHandler(msgReceiver7, intf[0].GetSignal("uint32"), ""); MessageReceiver msgReceiver8 = new MessageReceiver(busAtt); msgReceiver8.SignalHandler += new MessageReceiverSignalHandler(this.Int64Sig); busAtt.RegisterSignalHandler(msgReceiver8, intf[0].GetSignal("int64"), ""); MessageReceiver msgReceiver9 = new MessageReceiver(busAtt); msgReceiver9.SignalHandler += new MessageReceiverSignalHandler(this.Uint64Sig); busAtt.RegisterSignalHandler(msgReceiver9, intf[0].GetSignal("uint64"), ""); MessageReceiver msgReceiver10 = new MessageReceiver(busAtt); msgReceiver10.SignalHandler += new MessageReceiverSignalHandler(this.DoubleSig); busAtt.RegisterSignalHandler(msgReceiver10, intf[0].GetSignal("double"), ""); MessageReceiver msgReceiver11 = new MessageReceiver(busAtt); msgReceiver11.SignalHandler += new MessageReceiverSignalHandler(this.DArrarySig); busAtt.RegisterSignalHandler(msgReceiver11, intf[0].GetSignal("dArray"), ""); MessageReceiver msgReceiver12 = new MessageReceiver(busAtt); msgReceiver12.SignalHandler += new MessageReceiverSignalHandler(this.BYIStructSig); busAtt.RegisterSignalHandler(msgReceiver12, intf[0].GetSignal("byiStruct"), ""); MessageReceiver msgReceiver13 = new MessageReceiver(busAtt); msgReceiver13.SignalHandler += new MessageReceiverSignalHandler(this.ISDictSig); busAtt.RegisterSignalHandler(msgReceiver13, intf[0].GetSignal("isDict"), ""); busAtt.RegisterBusObject(this.busObject); }
/// <summary> /// Connects to the bus and registers a signal handler for when the 'name' property changes. /// </summary> /// <param name="sender">UI control which signaled the click event.</param> /// <param name="e">arguments associated with the click event.</param> private void Button_RunClick(object sender, RoutedEventArgs e) { if (busAtt == null) { Task task = new Task(async() => { try { busAtt = new BusAttachment("SignalConsumerApp", true, 4); // create and activate the interface InterfaceDescription[] interfaceDescription = new InterfaceDescription[1]; busAtt.CreateInterface(SignalConsumerGlobals.InterfaceName, interfaceDescription, false); interfaceDescription[0].AddSignal("nameChanged", "s", "newName", (byte)0, string.Empty); interfaceDescription[0].AddProperty("name", "s", (byte)PropAccessType.PROP_ACCESS_RW); interfaceDescription[0].Activate(); busListener = new SignalConsumerBusListener(busAtt, foundNameEvent); OutputLine("BusAttachment and BusListener Created."); busAtt.RegisterBusListener(busListener); OutputLine("BusListener Registered."); busAtt.Start(); busAtt.ConnectAsync(SignalConsumerGlobals.ConnectSpec).AsTask().Wait(); OutputLine("Bundled Daemon Registered."); OutputLine("BusAttachment Connected to " + SignalConsumerGlobals.ConnectSpec + "."); busAtt.FindAdvertisedName(SignalConsumerGlobals.WellKnownServiceName); foundNameEvent.WaitOne(); /* Configure session properties and request a session with device with wellKnownName */ SessionOpts sessionOpts = new SessionOpts( SignalConsumerGlobals.SessionProps.TrType, SignalConsumerGlobals.SessionProps.IsMultiPoint, SignalConsumerGlobals.SessionProps.PrType, SignalConsumerGlobals.SessionProps.TmType); SessionOpts[] sessionOptsOut = new SessionOpts[1]; OutputLine("Requesting a session with the well known service name."); JoinSessionResult joinResult = await busAtt.JoinSessionAsync( SignalConsumerGlobals.WellKnownServiceName, SignalConsumerGlobals.SessionProps.SessionPort, busListener, sessionOpts, sessionOptsOut, null); if (QStatus.ER_OK == joinResult.Status) { OutputLine("Join Session was successful (sessionId=" + joinResult.SessionId + ")."); busAtt.AddMatch("type='signal',interface='org.alljoyn.Bus.signal_sample',member='nameChanged'"); OutputLine("Subscribed to the 'nameChanged' signal."); } else { OutputLine("Join Session was unsuccessful."); } } catch (Exception ex) { OutputLine("Errors were produced while establishing the application."); QStatus status = AllJoynException.GetErrorCode(ex.HResult); busAtt = null; } }); task.Start(); } }
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(); } }
/// <summary> /// Connects to the bus and registers a signal handler for when the 'name' property changes. /// </summary> /// <param name="sender">UI control which signaled the click event.</param> /// <param name="e">arguments associated with the click event.</param> private void Button_RunClick(object sender, RoutedEventArgs e) { if (busAtt == null) { Task task = new Task(async () => { try { busAtt = new BusAttachment("SignalConsumerApp", true, 4); // create and activate the interface InterfaceDescription[] interfaceDescription = new InterfaceDescription[1]; busAtt.CreateInterface(SignalConsumerGlobals.InterfaceName, interfaceDescription, false); interfaceDescription[0].AddSignal("nameChanged", "s", "newName", (byte)0, string.Empty); interfaceDescription[0].AddProperty("name", "s", (byte)PropAccessType.PROP_ACCESS_RW); interfaceDescription[0].Activate(); busListener = new SignalConsumerBusListener(busAtt, foundNameEvent); OutputLine("BusAttachment and BusListener Created."); busAtt.RegisterBusListener(busListener); OutputLine("BusListener Registered."); busAtt.Start(); busAtt.ConnectAsync(SignalConsumerGlobals.ConnectSpec).AsTask().Wait(); OutputLine("Bundled Daemon Registered."); OutputLine("BusAttachment Connected to " + SignalConsumerGlobals.ConnectSpec + "."); busAtt.FindAdvertisedName(SignalConsumerGlobals.WellKnownServiceName); foundNameEvent.WaitOne(); /* Configure session properties and request a session with device with wellKnownName */ SessionOpts sessionOpts = new SessionOpts( SignalConsumerGlobals.SessionProps.TrType, SignalConsumerGlobals.SessionProps.IsMultiPoint, SignalConsumerGlobals.SessionProps.PrType, SignalConsumerGlobals.SessionProps.TmType); SessionOpts[] sessionOptsOut = new SessionOpts[1]; OutputLine("Requesting a session with the well known service name."); JoinSessionResult joinResult = await busAtt.JoinSessionAsync( SignalConsumerGlobals.WellKnownServiceName, SignalConsumerGlobals.SessionProps.SessionPort, busListener, sessionOpts, sessionOptsOut, null); if (QStatus.ER_OK == joinResult.Status) { OutputLine("Join Session was successful (sessionId=" + joinResult.SessionId + ")."); busAtt.AddMatch("type='signal',interface='org.alljoyn.Bus.signal_sample',member='nameChanged'"); OutputLine("Subscribed to the 'nameChanged' signal."); } else { OutputLine("Join Session was unsuccessful."); } } catch (Exception ex) { OutputLine("Errors were produced while establishing the application."); QStatus status = AllJoynException.GetErrorCode(ex.HResult); busAtt = null; } }); task.Start(); } }