/// <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); }
/// <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); }
public ServiceSessionPortListener(BusAttachment busAtt) { AcceptSessionJoinerCalled = false; SessionJoinedCalled = false; this.spl = new SessionPortListener(busAtt); this.spl.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler(this.SessionPortListenerAcceptSessionJoiner); this.spl.SessionJoined += new SessionPortListenerSessionJoinedHandler(this.SessionPortListenerSessionJoined); }
public QStatus BindSessionPort(ref ushort sessionPort, SessionOpts opts, SessionPortListener listener) { QStatus ret = QStatus.OK; ushort otherSessionPort = sessionPort; ret = alljoyn_busattachment_bindsessionport(_busAttachment, ref otherSessionPort, opts.UnmanagedPtr, listener.UnmanagedPtr); sessionPort = otherSessionPort; return(ret); }
public void BindSessionPortTest() { BusAttachment bus = new BusAttachment("bindports", true, 4); bus.Start(); bus.ConnectAsync(connectSpec).AsTask().Wait(); SessionOpts opts = new SessionOpts(TrafficType.TRAFFIC_MESSAGES, true, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY); SessionPortListener spl = new SessionPortListener(bus); for (ushort i = 1; i <= 10; i++) { ushort[] portOut = new ushort[1]; bus.BindSessionPort((ushort)(i * 10), portOut, opts, spl); Assert.AreEqual((ushort)(i * 10), portOut[0]); } }
public QStatus BindSessionPort(ref ushort sessionPort, SessionOpts opts, SessionPortListener listener) { QStatus ret = QStatus.OK; ushort otherSessionPort = sessionPort; Thread bindThread = new Thread((object o) => { ret = alljoyn_busattachment_bindsessionport(_busAttachment, ref otherSessionPort, opts.UnmanagedPtr, listener.UnmanagedPtr); }); bindThread.Start(); while (bindThread.IsAlive) { AllJoyn.TriggerCallbacks(); Thread.Sleep(0); } sessionPort = otherSessionPort; return(ret); }
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. }
/// <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); }
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); }
/// <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); }
private async Task StartService() { serviceBus = new BusAttachment("About Service Example", true); serviceBus.Start(); serviceBus.Connect(); Log.WriteLine($"BusAttachment connect succeeded. BusName {serviceBus.UniqueName}"); Session sessionOpts = new Session(TrafficType.Messages, false, Proximity.Any, Transport.Any); sessionPortListener = new SessionPortListener(); sessionPortListener.AcceptSessionJoiner += SessionPortListener_AcceptSessionJoiner; sessionPortListener.SessionJoined += SessionPortListener_SessionJoined; var sessionPort = ASSIGNED_SESSION_PORT; serviceBus.BindSessionPort(sessionPort, sessionOpts, sessionPortListener); var aboutData = new AboutData("en"); byte[] appId = { 0x01, 0xB3, 0xBA, 0x14, 0x1E, 0x82, 0x11, 0xE4, 0x86, 0x51, 0xD1, 0x56, 0x1D, 0x5D, 0x46, 0xB0 }; aboutData.AppId = appId; aboutData.SetDeviceName("My Device Name", "en"); aboutData.DeviceId = "93c06771-c725-48c2-b1ff-6a2a59d445b8"; aboutData.SetAppName("Application", "en"); aboutData.SetManufacturer("Manufacturer2", "en"); aboutData.ModelNumber = "123456"; aboutData.SetDescription("A poetic description of this application", "en"); aboutData.DateOfManufacture = "2014-03-24"; aboutData.SoftwareVersion = "0.1.2"; aboutData.HardwareVersion = "0.0.1"; aboutData.SupportUrl = "http://www.example.org"; /* * The default language is automatically added to the `SupportedLanguages` * Users don't have to specify the AJSoftwareVersion its automatically added * to the AboutData/ * Adding Spanish Localization values to the AboutData. All strings MUST be * UTF-8 encoded. */ aboutData.SetDeviceName("Mi dispositivo Nombre", "es"); aboutData.SetAppName("aplicación", "es"); aboutData.SetManufacturer("fabricante", "es"); aboutData.SetDescription("Una descripción poética de esta aplicación", "es"); if (!aboutData.IsValid("en")) { Log.WriteLine("failed to setup about data."); } string xmlInterface = "<node>\n" + $"<interface name='{INTERFACE_NAME}'>\n" + " <method name='Echo'>\n" + " <arg name='out_arg' type='s' direction='in' />\n" + " <arg name='return_arg' type='s' direction='out' />\n" + " </method>\n" + "</interface>\n" + "</node>"; Log.WriteLine(xmlInterface); serviceBus.CreateInterfacesFromXml(xmlInterface); busObject = create_my_alljoyn_busobject(serviceBus, "/example/path"); serviceBus.RegisterBusObject(busObject); var aboutObj = new AboutObj(serviceBus, false); aboutObj.Announce(sessionPort, aboutData); Log.WriteLine("AboutObj Announce Succeeded."); Log.WriteLine("*********************************************************************************"); Log.WriteLine("*********************************************************************************"); while (!cancelSource.IsCancellationRequested) { await Task.Delay(10); } }
private static void _SessionJoined(SessionPortListener context, ushort sessionPort, uint sessionId, IntPtr joiner) { context.tempstr = Marshal.PtrToStringAuto(joiner); context.SessionJoined(sessionPort, sessionId, context.tempstr); }
private static int _AcceptSessionJoiner(SessionPortListener context, ushort sessionPort, IntPtr joiner, IntPtr opts) { context.tempstr = Marshal.PtrToStringAuto(joiner); context.tempopts = new SessionOpts(opts); return (context.AcceptSessionJoiner(sessionPort, context.tempstr, context.tempopts) ? 1 : 0); }
public QStatus BindSessionPort(ref ushort sessionPort, SessionOpts opts, SessionPortListener listener) { QStatus ret = QStatus.OK; ushort otherSessionPort = sessionPort; Thread bindThread = new Thread((object o) => { ret = alljoyn_busattachment_bindsessionport(_busAttachment, ref otherSessionPort, opts.UnmanagedPtr, listener.UnmanagedPtr); }); bindThread.Start(); while(bindThread.IsAlive) { AllJoyn.TriggerCallbacks(); Thread.Sleep(0); } sessionPort = otherSessionPort; return ret; }
public ServiceSessionPortListener(BusAttachment busAtt) { AcceptSessionJoinerCalled = false; SessionJoinedCalled = false; this.spl = new SessionPortListener(busAtt); this.spl.AcceptSessionJoiner += new SessionPortListenerAcceptSessionJoinerHandler(this.SessionPortListenerAcceptSessionJoiner); this.spl.SessionJoined += new SessionPortListenerSessionJoinedHandler(this.SessionPortListenerSessionJoined); }
public void BindSessionPortTest() { BusAttachment bus = new BusAttachment("bindports", true, 4); bus.Start(); bus.ConnectAsync(connectSpec).AsTask().Wait(); SessionOpts opts = new SessionOpts(TrafficType.TRAFFIC_MESSAGES, true, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY); SessionPortListener spl = new SessionPortListener(bus); for (ushort i = 1; i <= 10; i++) { ushort[] portOut = new ushort[1]; bus.BindSessionPort((ushort)(i * 10), portOut, opts, spl); Assert.AreEqual((ushort)(i * 10), portOut[0]); } }
private static void _SessionJoined(SessionPortListener context, ushort sessionPort, uint sessionId, IntPtr joiner) { context.tempstr = Marshal.PtrToStringAuto(joiner); context.SessionJoined(sessionPort, sessionId, context.tempstr); }
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) }
private static int _AcceptSessionJoiner(SessionPortListener context, ushort sessionPort, IntPtr joiner, IntPtr opts) { context.tempstr = Marshal.PtrToStringAuto(joiner); context.tempopts = new SessionOpts(opts); return(context.AcceptSessionJoiner(sessionPort, context.tempstr, context.tempopts) ? 1 : 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 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. }
public QStatus BindSessionPort(ref ushort sessionPort, SessionOpts opts, SessionPortListener listener) { QStatus ret = QStatus.OK; ushort otherSessionPort = sessionPort; ret = alljoyn_busattachment_bindsessionport(_busAttachment, ref otherSessionPort, opts.UnmanagedPtr, listener.UnmanagedPtr); sessionPort = otherSessionPort; return ret; }