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) }