public void AddSignal() { AllJoyn.QStatus status = AllJoyn.QStatus.FAIL; AllJoyn.BusAttachment bus = null; bus = new AllJoyn.BusAttachment("InterfaceDescriptionTest", true); Assert.NotNull(bus); // create the interface AllJoyn.InterfaceDescription testIntf = null; status = bus.CreateInterface(INTERFACE_NAME, out testIntf); Assert.Equal(AllJoyn.QStatus.OK, status); Assert.NotNull(testIntf); status = testIntf.AddSignal("signal1", "s", "data", AllJoyn.InterfaceDescription.AnnotationFlags.Default); Assert.Equal(AllJoyn.QStatus.OK, status); // Verify the signal AllJoyn.InterfaceDescription.Member signalMember = null; signalMember = testIntf.GetMember("signal1"); Assert.NotNull(signalMember); Assert.Equal(testIntf, signalMember.Iface); Assert.Equal(AllJoyn.Message.Type.Signal, signalMember.MemberType); Assert.Equal("signal1", signalMember.Name); Assert.Equal("s", signalMember.Signature); Assert.Equal("", signalMember.ReturnSignature); Assert.Equal("data", signalMember.ArgNames); //TODO add in code to use new annotation methods bus.Dispose(); }
public void GetSignal() { // create the interface AllJoyn.InterfaceDescription testIntf = null; status = bus.CreateInterface(INTERFACE_NAME, out testIntf); Assert.Equal(AllJoyn.QStatus.OK, status); Assert.NotNull(testIntf); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMethod("foo", "", "", "")); status = testIntf.AddSignal("chirp", "s", "data", AllJoyn.InterfaceDescription.AnnotationFlags.Default); Assert.Equal(AllJoyn.QStatus.OK, status); // Verify the signal AllJoyn.InterfaceDescription.Member signalMember = null; signalMember = testIntf.GetSignal("chirp"); Assert.NotNull(signalMember); Assert.Equal(testIntf, signalMember.Iface); Assert.Equal(AllJoyn.Message.Type.Signal, signalMember.MemberType); Assert.Equal("chirp", signalMember.Name); Assert.Equal("s", signalMember.Signature); Assert.Equal("", signalMember.ReturnSignature); Assert.Equal("data", signalMember.ArgNames); AllJoyn.InterfaceDescription.Member methodMember = null; methodMember = testIntf.GetSignal("foo"); //since "foo" is a method GetSignal should return null Assert.Null(methodMember); methodMember = testIntf.GetSignal("bar"); // "bar" is not a member of the interface it should return null Assert.Null(methodMember); }
public void GetMethod() { // create the interface AllJoyn.InterfaceDescription testIntf = null; status = bus.CreateInterface(INTERFACE_NAME, out testIntf); Assert.Equal(AllJoyn.QStatus.OK, status); Assert.NotNull(testIntf); // Test adding a MethodCall Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMethod("ping", "s", "s", "in,out")); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddSignal("foo", "", "")); // Verify the ping member AllJoyn.InterfaceDescription.Member pingMember = null; pingMember = testIntf.GetMethod("ping"); Assert.NotNull(pingMember); Assert.Equal(testIntf, pingMember.Iface); Assert.Equal(AllJoyn.Message.Type.MethodCall, pingMember.MemberType); Assert.Equal("ping", pingMember.Name); Assert.Equal("s", pingMember.Signature); Assert.Equal("s", pingMember.ReturnSignature); Assert.Equal("in,out", pingMember.ArgNames); AllJoyn.InterfaceDescription.Member fooMember = null; fooMember = testIntf.GetMethod("foo"); // since "foo" is a signal is should return null when using GetMethod Assert.Null(fooMember); fooMember = testIntf.GetMethod("bar"); // since "bar" is not a member of the interface it should be null Assert.Null(fooMember); }
public void GetMembers() { AllJoyn.QStatus status = AllJoyn.QStatus.FAIL; AllJoyn.BusAttachment bus = null; bus = new AllJoyn.BusAttachment("InterfaceDescriptionTest", true); Assert.NotNull(bus); // create the interface AllJoyn.InterfaceDescription testIntf = null; status = bus.CreateInterface(INTERFACE_NAME, out testIntf); Assert.Equal(AllJoyn.QStatus.OK, status); Assert.NotNull(testIntf); // Test adding a MethodCall Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMethod("one", "", "", "")); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMethod("two", "", "", "")); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMethod("three", "", "", "")); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMethod("four", "", "", "")); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMethod("five", "", "", "")); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMethod("six", "", "", "")); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMethod("seven", "", "", "")); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddSignal("eight", "", "")); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddSignal("nine", "", "")); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddSignal("ten", "", "")); AllJoyn.InterfaceDescription.Member[] members = testIntf.GetMembers(); Assert.Equal(10, members.Length); // This test assumes that the members are returned in alphabetic order // nothing states that the changes must be returned this way. Assert.Equal("eight", members[0].Name); Assert.Equal("five", members[1].Name); Assert.Equal("four", members[2].Name); Assert.Equal("nine", members[3].Name); Assert.Equal("one", members[4].Name); Assert.Equal("seven", members[5].Name); Assert.Equal("six", members[6].Name); Assert.Equal("ten", members[7].Name); Assert.Equal("three", members[8].Name); Assert.Equal("two", members[9].Name); }
public void InterfaceDescriptionEquals() { AllJoyn.BusAttachment servicebus = null; servicebus = new AllJoyn.BusAttachment("InterfaceDescriptionTest", true); Assert.NotNull(servicebus); // create the interface one AllJoyn.InterfaceDescription testIntf = null; Assert.Equal(AllJoyn.QStatus.OK, servicebus.CreateInterface(INTERFACE_NAME, out testIntf)); Assert.NotNull(testIntf); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMethod("ping", "s", "s", "in,out")); Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddSignal("chirp", "s", "chirp")); testIntf.Activate(); Assert.Equal(AllJoyn.QStatus.OK, servicebus.Start()); Assert.Equal(AllJoyn.QStatus.OK, servicebus.Connect(AllJoynTestCommon.GetConnectSpec())); AllJoyn.BusObject busObject = new AllJoyn.BusObject(OBJECT_PATH, false); Assert.Equal(AllJoyn.QStatus.OK, busObject.AddInterface(testIntf)); Assert.Equal(AllJoyn.QStatus.OK, servicebus.RegisterBusObject(busObject)); Assert.Equal(AllJoyn.QStatus.OK, servicebus.RequestName(WELLKNOWN_NAME, AllJoyn.DBus.NameFlags.AllowReplacement | AllJoyn.DBus.NameFlags.DoNotQueue | AllJoyn.DBus.NameFlags.ReplaceExisting)); AllJoyn.BusAttachment clientbus = null; clientbus = new AllJoyn.BusAttachment("InterfaceDescriptionTestclient", true); Assert.NotNull(clientbus); Assert.Equal(AllJoyn.QStatus.OK, clientbus.Start()); Assert.Equal(AllJoyn.QStatus.OK, clientbus.Connect(AllJoynTestCommon.GetConnectSpec())); AllJoyn.ProxyBusObject proxy = new AllJoyn.ProxyBusObject(clientbus, WELLKNOWN_NAME, OBJECT_PATH, 0); Assert.Equal(AllJoyn.QStatus.OK, proxy.IntrospectRemoteObject()); AllJoyn.InterfaceDescription testIntf2 = proxy.GetInterface(INTERFACE_NAME); Assert.NotNull(testIntf); // create the interface three AllJoyn.InterfaceDescription testIntf3 = null; Assert.Equal(AllJoyn.QStatus.OK, servicebus.CreateInterface(INTERFACE_NAME + ".three", out testIntf3)); Assert.NotNull(testIntf3); Assert.Equal(AllJoyn.QStatus.OK, testIntf3.AddMethod("ping", "s", "s", "in,out")); Assert.Equal(AllJoyn.QStatus.OK, testIntf3.AddMethod("pong", "s", "s", "in,out")); Assert.Equal(AllJoyn.QStatus.OK, testIntf3.AddSignal("chirp", "s", "chirp")); Assert.True(testIntf == testIntf2); Assert.True(testIntf.Equals(testIntf2)); Assert.True(testIntf.GetHashCode() == testIntf2.GetHashCode()); Assert.False(testIntf == testIntf3); Assert.False(testIntf.Equals(testIntf3)); Assert.False(testIntf.GetHashCode() == testIntf3.GetHashCode()); proxy.Dispose(); busObject.Dispose(); servicebus.Stop(); servicebus.Join(); clientbus.Stop(); clientbus.Join(); servicebus.Dispose(); clientbus.Dispose(); }
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 StartUp() { chatText = "Starting AllJoyn\n\n\n" + chatText; AllJoynStarted = true; AllJoyn.QStatus status = AllJoyn.QStatus.OK; { chatText = "Creating BusAttachment\n" + chatText; // Create message bus msgBus = new AllJoyn.BusAttachment("myApp", true); // Add org.alljoyn.Bus.method_sample interface status = msgBus.CreateInterface(INTERFACE_NAME, false, out testIntf); if (status) { chatText = "Chat Interface Created.\n" + chatText; Debug.Log("Chat Interface Created."); testIntf.AddSignal("chat", "s", "msg", 0); testIntf.Activate(); } else { chatText = "Failed to create interface 'org.alljoyn.Bus.chat'\n" + chatText; Debug.Log("Failed to create interface 'org.alljoyn.Bus.chat'"); } // Create a bus listener busListener = new MyBusListener(); if (status) { msgBus.RegisterBusListener(busListener); chatText = "Chat BusListener Registered.\n" + chatText; Debug.Log("Chat BusListener Registered."); } if (testObj == null) { testObj = new TestBusObject(msgBus, SERVICE_PATH); } // Start the msg bus if (status) { status = msgBus.Start(); if (status) { chatText = "Chat BusAttachment started.\n" + chatText; Debug.Log("Chat BusAttachment started."); msgBus.RegisterBusObject(testObj); for (int i = 0; i < connectArgs.Length; ++i) { chatText = "Chat Connect trying: " + connectArgs[i] + "\n" + chatText; Debug.Log("Chat Connect trying: " + connectArgs[i]); status = msgBus.Connect(connectArgs[i]); if (status) { chatText = "BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED.\n" + chatText; Debug.Log("BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED."); connectedVal = connectArgs[i]; break; } else { chatText = "BusAttachment.Connect(" + connectArgs[i] + ") failed.\n" + chatText; Debug.Log("BusAttachment.Connect(" + connectArgs[i] + ") failed."); } } if (!status) { chatText = "BusAttachment.Connect failed.\n" + chatText; Debug.Log("BusAttachment.Connect failed."); } } else { chatText = "Chat BusAttachment.Start failed.\n" + chatText; Debug.Log("Chat BusAttachment.Start failed."); } } myAdvertisedName = SERVICE_NAME + "._" + msgBus.GlobalGUIDString; AllJoyn.InterfaceDescription.Member chatMember = testIntf.GetMember("chat"); status = msgBus.RegisterSignalHandler(this.ChatSignalHandler, chatMember, null); if (!status) { chatText = "Chat Failed to add signal handler " + status + "\n" + chatText; Debug.Log("Chat Failed to add signal handler " + status); } else { chatText = "Chat add signal handler " + status + "\n" + chatText; Debug.Log("Chat add signal handler " + status); } status = msgBus.AddMatch("type='signal',member='chat'"); if (!status) { chatText = "Chat Failed to add Match " + status.ToString() + "\n" + chatText; Debug.Log("Chat Failed to add Match " + status.ToString()); } else { chatText = "Chat add Match " + status.ToString() + "\n" + chatText; Debug.Log("Chat add Match " + status.ToString()); } } // Request name if (status) { status = msgBus.RequestName(myAdvertisedName, AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue); if (!status) { chatText = "Chat RequestName(" + SERVICE_NAME + ") failed (status=" + status + ")\n" + chatText; Debug.Log("Chat RequestName(" + SERVICE_NAME + ") failed (status=" + status + ")"); } } // Create session opts = new AllJoyn.SessionOpts(AllJoyn.SessionOpts.TrafficType.Messages, false, AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any); if (status) { ushort sessionPort = SERVICE_PORT; sessionPortListener = new MySessionPortListener(); status = msgBus.BindSessionPort(ref sessionPort, opts, sessionPortListener); if (!status || sessionPort != SERVICE_PORT) { chatText = "Chat BindSessionPort failed (" + status + ")\n" + chatText; Debug.Log("Chat BindSessionPort failed (" + status + ")"); } chatText = "Chat BindSessionPort on port (" + sessionPort + ")\n" + chatText; Debug.Log("Chat BBindSessionPort on port (" + sessionPort + ")");; } // Advertise name if (status) { status = msgBus.AdvertiseName(myAdvertisedName, opts.Transports); if (!status) { chatText = "Chat Failed to advertise name " + myAdvertisedName + " (" + status + ")\n" + chatText; Debug.Log("Chat Failed to advertise name " + myAdvertisedName + " (" + status + ")"); } } status = msgBus.FindAdvertisedName(SERVICE_NAME); if (!status) { chatText = "Chat org.alljoyn.Bus.FindAdvertisedName failed.\n" + chatText; Debug.Log("Chat org.alljoyn.Bus.FindAdvertisedName failed."); } Debug.Log("Completed ChatService Constructor"); }
public void RegisterSignalHandler() { AllJoyn.QStatus status = AllJoyn.QStatus.FAIL; // create the interface description AllJoyn.InterfaceDescription testIntf = null; status = busAttachment.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 = busAttachment.Start(); Assert.Equal(AllJoyn.QStatus.OK, status); // connect to the bus status = busAttachment.Connect(AllJoynTestCommon.GetConnectSpec()); Assert.Equal(AllJoyn.QStatus.OK, status); // create the bus object & // add the interface to the bus object TestBusObject testBusObject = new TestBusObject(busAttachment, "/test"); busAttachment.RegisterBusObject(testBusObject); // get the signal member from the interface description AllJoyn.InterfaceDescription.Member testSignalMember = testIntf.GetMember("testSignal"); // register the signal handler status = busAttachment.RegisterSignalHandler(this.TestSignalHandlerOne, testSignalMember, null); Assert.Equal(AllJoyn.QStatus.OK, status); // add match for the signal status = busAttachment.AddMatch("type='signal',member='testSignal'"); Assert.Equal(AllJoyn.QStatus.OK, status); handledSignalsOne = false; signalOneMsg = null; // send a signal testBusObject.SendTestSignal("test msg"); //wait to see if we receive the signal WaitEventOne(TimeSpan.FromSeconds(10)); //System.Threading.Thread.Sleep(10000); Assert.Equal(true, handledSignalsOne); Assert.Equal("test msg", signalOneMsg); handledSignalsOne = false; signalOneMsg = ""; testBusObject.SendTestSignal2("test msg"); WaitEventOne(TimeSpan.FromSeconds(2)); Assert.Equal(true, handledSignalsOne); Assert.Equal("test msg", signalOneMsg); }
public void StartUp() { //Debug.LogError("Starting AllJoyn"); AllJoynStarted = true; AllJoyn.QStatus status = AllJoyn.QStatus.OK; { //Debug.LogError("Creating BusAttachment"); msgBus = new AllJoyn.BusAttachment("myApp", true); status = msgBus.CreateInterface(INTERFACE_NAME, false, out testIntf); if (status) { //Debug.LogError("Interface Created."); testIntf.AddSignal("player", "sddddbb", "playerPoints", 0); testIntf.AddSignal("enemyInit", "ssdddd", "enemyPoints", 0); testIntf.AddSignal("enemyAgro", "sss", "enemyPoints1", 0); testIntf.AddSignal("enemyHP", "ssd", "enemyPoints2", 0); testIntf.Activate(); } else { //Debug.LogError("Failed to create interface 'org.alljoyn.Bus.chat'"); } busListener = new MyBusListener(); if (status) { msgBus.RegisterBusListener(busListener); //Debug.LogError("BusListener Registered."); } if (testObj == null) { testObj = new TestBusObject(msgBus, SERVICE_PATH); } if (status) { status = msgBus.Start(); if (status) { //Debug.LogError("BusAttachment started."); msgBus.RegisterBusObject(testObj); for (int i = 0; i < connectArgs.Length; ++i) { //Debug.LogError("Connect trying: " + connectArgs[i]); status = msgBus.Connect(connectArgs[i]); if (status) { //Debug.LogError("BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED."); connectedVal = connectArgs[i]; break; } else { //Debug.LogError("BusAttachment.Connect(" + connectArgs[i] + ") failed."); } } if (!status) { //Debug.LogError("BusAttachment.Connect failed."); } } else { //Debug.LogError("BusAttachment.Start failed."); } } myAdvertisedName = SERVICE_NAME + "._" + msgBus.GlobalGUIDString + playerNick; AllJoyn.InterfaceDescription.Member playerMember = testIntf.GetMember("player"); status = msgBus.RegisterSignalHandler(this.PlayerSignalHandler, playerMember, null); if (!status) { //Debug.LogError("Failed to add vector signal handler " + status); } else { //Debug.LogError("add vector signal handler " + status); } AllJoyn.InterfaceDescription.Member enemyInitMember = testIntf.GetMember("enemyInit"); status = msgBus.RegisterSignalHandler(this.EnemyInitSignalHandler, enemyInitMember, null); if (!status) { Debug.LogError("Failed to add vector signal handler " + status); } else { //Debug.LogError("add vector signal handler " + status); } AllJoyn.InterfaceDescription.Member enemyAgroMember = testIntf.GetMember("enemyAgro"); status = msgBus.RegisterSignalHandler(this.EnemyAgroSignalHandler, enemyAgroMember, null); if (!status) { Debug.LogError("Failed to add vector signal handler " + status); } else { //Debug.LogError("add vector signal handler " + status); } AllJoyn.InterfaceDescription.Member enemyHPMember = testIntf.GetMember("enemyHP"); status = msgBus.RegisterSignalHandler(this.EnemyHPSignalHandler, enemyHPMember, null); if (!status) { Debug.LogError("Failed to add vector signal handler " + status); } else { //Debug.LogError("add vector signal handler " + status); } status = msgBus.AddMatch("type='signal',interface='org.alljoyn.bus.multi'"); if (!status) { Debug.LogError("Failed to add vector Match " + status.ToString()); } else { //Debug.LogError("add vector Match " + status.ToString()); } } if (status) { status = msgBus.RequestName(myAdvertisedName, AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue); if (!status) { Debug.LogError("RequestName(" + SERVICE_NAME + ") failed (status=" + status + ")"); } } opts = new AllJoyn.SessionOpts(AllJoyn.SessionOpts.TrafficType.Messages, false, AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any); if (status) { ushort sessionPort = SERVICE_PORT; sessionPortListener = new MySessionPortListener(this); status = msgBus.BindSessionPort(ref sessionPort, opts, sessionPortListener); if (!status || sessionPort != SERVICE_PORT) { Debug.LogError("BindSessionPort failed (" + status + ")"); } //Debug.LogError("BBindSessionPort on port (" + sessionPort + ")"); ; } if (status) { status = msgBus.AdvertiseName(myAdvertisedName, opts.Transports); if (!status) { Debug.LogError("Failed to advertise name " + myAdvertisedName + " (" + status + ")"); } } status = msgBus.FindAdvertisedName(SERVICE_NAME); if (!status) { Debug.LogError("org.alljoyn.Bus.FindAdvertisedName failed."); } }