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")); }
/// <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="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 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 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); } }
private BusObject create_my_alljoyn_busobject(BusAttachment bus, string path) { var result = new BusObject(path, false); var iface = bus.GetInterface(INTERFACE_NAME); result.AddInterface(iface); result.SetAnnounceFlag(iface, true); var member = iface.GetMember("Echo"); result.AddMethodHandler(member, OnEcho); return(result); }
public void CreateInterfacesFromXMLTest() { BusAttachment bus = new BusAttachment("xmlinterfaces", true, 4); bus.CreateInterfacesFromXml(signalIntf); bus.CreateInterfacesFromXml(methodIntf); bus.CreateInterfacesFromXml(propertyIntf); bus.CreateInterfacesFromXml(mixedIntf); InterfaceDescription i = bus.GetInterface("org.alljoyn.Signals"); Assert.IsNotNull(i); Assert.IsNotNull(bus.GetInterface("org.alljoyn.Methods")); Assert.IsNotNull(bus.GetInterface("org.alljoyn.Properties")); Assert.IsNotNull(bus.GetInterface("org.alljoyn.Mixed")); InterfaceDescription[] intfs = new InterfaceDescription[14]; bus.GetInterfaces(intfs); Assert.IsNotNull(intfs[0]); Assert.IsNotNull(intfs[1]); Assert.IsNotNull(intfs[2]); Assert.IsNotNull(intfs[3]); // BUGBUG: DeleteInterface is throwing an exception saying the interfaces don't exist //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Signals")); //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Methods")); //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Properties")); //bus.DeleteInterface(bus.GetInterface("org.alljoyn.Mixed")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Signals")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Methods")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Properties")); //Assert.IsNull(bus.GetInterface("org.alljoyn.Mixed")); //InterfaceDescription[] nullIntfs = new InterfaceDescription[14]; //bus.GetInterfaces(nullIntfs); //Assert.IsNull(nullIntfs[0]); //Assert.IsNull(nullIntfs[1]); //Assert.IsNull(nullIntfs[2]); //Assert.IsNull(nullIntfs[3]); }
public void Start() { // Create the bus attachment bus = new BusAttachment("ServiceTest", true); bus.Start(); Log.WriteLine("BusAttachment started"); bus.Connect(); Log.WriteLine("BusAttachment connect succeeded. BusName: " + bus.UniqueName); //Create interface string interfaceName = "org.test.a1234.AnnounceHandlerTest"; string interfaceQcc = "<node>" + $"<interface name='{interfaceName}'>" + " <method name='Foo'>" + " </method>" + "</interface>" + "</node>"; bus.CreateInterfacesFromXml(interfaceQcc); //Test if the interface is there var iface = bus.GetInterface(interfaceName); var secure = iface.IsSecure; var name = iface.Name; }
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 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) }