예제 #1
0
        public TestBusObject(AllJoyn.BusAttachment bus, string path) : base(path, false)
        {
            AllJoyn.InterfaceDescription exampleIntf = bus.GetInterface(INTERFACE_NAME);
            AllJoyn.QStatus status = AddInterface(exampleIntf);
            if (!status)
            {
                serverText += "Server Failed to add interface " + status.ToString() + "\n";
                Debug.Log("Server Failed to add interface " + status.ToString());
            }

            AllJoyn.InterfaceDescription.Member catMember = exampleIntf.GetMember("acc");
            status = AddMethodHandler(catMember, this.Acc);
            if (!status)
            {
                serverText += "Server Failed to add method handler " + status.ToString() + "\n";
                Debug.Log("Server Failed to add method handler " + status.ToString());
            }

            catMember = exampleIntf.GetMember("data");
            status    = AddMethodHandler(catMember, this.Data);
            if (!status)
            {
                serverText += "Server Failed to add method handler " + status.ToString() + "\n";
                Debug.Log("Server Failed to add method handler " + status.ToString());
            }
        }
예제 #2
0
        public void GetMember()
        {
            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
            status = testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out", AllJoyn.InterfaceDescription.AnnotationFlags.Default);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // Test adding a Signal
            status = testIntf.AddMember(AllJoyn.Message.Type.Signal, "chirp", "", "s", "chirp", AllJoyn.InterfaceDescription.AnnotationFlags.Default);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // Verify the ping member
            AllJoyn.InterfaceDescription.Member pingMember = null;
            pingMember = testIntf.GetMember("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);
            //TODO add in code to use new annotation methods
            //Assert.Equal(AllJoyn.InterfaceDescription.AnnotationFlags.Default, pingMember.Annotation);

            // Verify the chirp member
            AllJoyn.InterfaceDescription.Member chirpMember = null;
            chirpMember = testIntf.GetMember("chirp");
            Assert.NotNull(chirpMember);

            Assert.Equal(testIntf, chirpMember.Iface);
            Assert.Equal(AllJoyn.Message.Type.Signal, chirpMember.MemberType);
            Assert.Equal("chirp", chirpMember.Name);
            Assert.Equal("", chirpMember.Signature);
            Assert.Equal("s", chirpMember.ReturnSignature);
            Assert.Equal("chirp", chirpMember.ArgNames);
            //TODO add in code to use new annotation methods
            //Assert.Equal(AllJoyn.InterfaceDescription.AnnotationFlags.Default, chirpMember.Annotation);

            bus.Dispose();
        }
예제 #3
0
            public TestBusObject(AllJoyn.BusAttachment bus, string path) : base(path, false)
            {
                AllJoyn.InterfaceDescription exampleIntf = bus.GetInterface(INTERFACE_NAME);
                AllJoyn.QStatus status = AddInterface(exampleIntf);
                if (!status)
                {
                    //Debug.LogError("Failed to add interface " + status.ToString());
                }

                playerMember    = exampleIntf.GetMember("player");
                enemyInitMember = exampleIntf.GetMember("enemyInit");
                enemyAgroMember = exampleIntf.GetMember("enemyAgro");
                enemyHPMember   = exampleIntf.GetMember("enemyHP");
            }
예제 #4
0
        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();
        }
예제 #5
0
            //private AllJoyn.InterfaceDescription.Member restartMember;

            public TestBusObject(AllJoyn.BusAttachment bus, string path)
                : base(path, false)
            {
                AllJoyn.InterfaceDescription exampleIntf = bus.GetInterface(INTERFACE_NAME);
                AllJoyn.QStatus status = AddInterface(exampleIntf);
                if (!status)
                {
                    chatText = "Chat Failed to add interface " + status.ToString() + "\n" + chatText;
                    Debug.Log("Chat Failed to add interface " + status.ToString());
                }

                chatMember     = exampleIntf.GetMember("chat");
                positionMember = exampleIntf.GetMember("positionupdate");
                pointsMember   = exampleIntf.GetMember("pointsupdate");
                //restartMember = exampleIntf.GetMember("restartupdate");
            }
예제 #6
0
        public void MethodAnnotations()
        {
            // 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
            status = testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out", AllJoyn.InterfaceDescription.AnnotationFlags.Default);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            status = testIntf.AddMemberAnnotation("ping", "one", "black_cat");
            Assert.Equal(AllJoyn.QStatus.OK, status);

            status = testIntf.AddMemberAnnotation("ping", "org.alljoyn.test.annotation.one", "here");
            Assert.Equal(AllJoyn.QStatus.OK, status);
            status = testIntf.AddMemberAnnotation("ping", "org.alljoyn.test.annotation.two", "lies");
            Assert.Equal(AllJoyn.QStatus.OK, status);
            status = testIntf.AddMemberAnnotation("ping", "org.alljoyn.test.annotation.three", "some");
            Assert.Equal(AllJoyn.QStatus.OK, status);
            status = testIntf.AddMemberAnnotation("ping", "org.alljoyn.test.annotation.four", "amazing");
            Assert.Equal(AllJoyn.QStatus.OK, status);
            status = testIntf.AddMemberAnnotation("ping", "org.alljoyn.test.annotation.five", "treasure");
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // Test adding a Signal
            status = testIntf.AddMember(AllJoyn.Message.Type.Signal, "chirp", "", "s", "chirp", AllJoyn.InterfaceDescription.AnnotationFlags.Default);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // activate the interface
            testIntf.Activate();

            string value = "";

            testIntf.GetMemberAnnotation("ping", "one", ref value);
            Assert.Equal("black_cat", value);

            AllJoyn.InterfaceDescription.Member member = testIntf.GetMember("ping");

            Assert.True(member.GetAnnotation("org.alljoyn.test.annotation.two", ref value));
            Assert.Equal("lies", value);

            Dictionary <string, string> annotations = member.GetAnnotations();

            Assert.Equal(6, annotations.Count);

            Assert.True(annotations.TryGetValue("org.alljoyn.test.annotation.one", out value));
            Assert.Equal("here", value);
            Assert.True(annotations.TryGetValue("org.alljoyn.test.annotation.two", out value));
            Assert.Equal("lies", value);
            Assert.True(annotations.TryGetValue("org.alljoyn.test.annotation.three", out value));
            Assert.Equal("some", value);
            Assert.True(annotations.TryGetValue("org.alljoyn.test.annotation.four", out value));
            Assert.Equal("amazing", value);
            Assert.True(annotations.TryGetValue("org.alljoyn.test.annotation.five", out value));
            Assert.Equal("treasure", value);
            Assert.True(annotations.TryGetValue("one", out value));
            Assert.Equal("black_cat", value);
        }
예제 #7
0
        public void SignalAnnotations()
        {
            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 Signal
            status = testIntf.AddMember(AllJoyn.Message.Type.Signal, "chirp", "", "s", "chirp", AllJoyn.InterfaceDescription.AnnotationFlags.Default);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            status = testIntf.AddMemberAnnotation("chirp", "org.alljoyn.test.annotation.one", "here");
            Assert.Equal(AllJoyn.QStatus.OK, status);
            status = testIntf.AddMemberAnnotation("chirp", "org.alljoyn.test.annotation.two", "lies");
            Assert.Equal(AllJoyn.QStatus.OK, status);
            status = testIntf.AddMemberAnnotation("chirp", "org.alljoyn.test.annotation.three", "some");
            Assert.Equal(AllJoyn.QStatus.OK, status);
            status = testIntf.AddMemberAnnotation("chirp", "org.alljoyn.test.annotation.four", "amazing");
            Assert.Equal(AllJoyn.QStatus.OK, status);
            status = testIntf.AddMemberAnnotation("chirp", "org.alljoyn.test.annotation.five", "treasure");
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // activate the interface
            testIntf.Activate();

            string value = "";

            testIntf.GetMemberAnnotation("chirp", "org.alljoyn.test.annotation.one", ref value);
            Assert.Equal("here", value);

            AllJoyn.InterfaceDescription.Member signal = testIntf.GetMember("chirp");

            Assert.True(signal.GetAnnotation("org.alljoyn.test.annotation.two", ref value));
            Assert.Equal("lies", value);

            Dictionary <string, string> annotations = signal.GetAnnotations();

            Assert.Equal(5, annotations.Count);

            Assert.True(annotations.TryGetValue("org.alljoyn.test.annotation.one", out value));
            Assert.Equal("here", value);
            Assert.True(annotations.TryGetValue("org.alljoyn.test.annotation.two", out value));
            Assert.Equal("lies", value);
            Assert.True(annotations.TryGetValue("org.alljoyn.test.annotation.three", out value));
            Assert.Equal("some", value);
            Assert.True(annotations.TryGetValue("org.alljoyn.test.annotation.four", out value));
            Assert.Equal("amazing", value);
            Assert.True(annotations.TryGetValue("org.alljoyn.test.annotation.five", out value));
            Assert.Equal("treasure", value);

            bus.Dispose();
        }
예제 #8
0
            public TestBusObject(AllJoyn.BusAttachment bus, string path)
                : base(path, false)
            {
                AllJoyn.InterfaceDescription testIntf = bus.GetInterface("org.alljoyn.test.BusAttachment");
                AllJoyn.QStatus status = AddInterface(testIntf);
                Assert.Equal(AllJoyn.QStatus.OK, status);

                testSignalMember = testIntf.GetMember("testSignal");
            }
예제 #9
0
            public MethodTestBusObject(AllJoyn.BusAttachment bus, string path)
                : base(path, false)
            {
                // add the interface to the bus object
                AllJoyn.InterfaceDescription testIntf = bus.GetInterface(INTERFACE_NAME);
                AllJoyn.QStatus status = AddInterface(testIntf);
                Assert.Equal(AllJoyn.QStatus.OK, status);

                // register a method handler for the ping method
                AllJoyn.InterfaceDescription.Member pingMember = testIntf.GetMember("ping");
                status = AddMethodHandler(pingMember, this.Ping);
                Assert.Equal(AllJoyn.QStatus.OK, status);
            }
예제 #10
0
            public TestBusObject(AllJoyn.BusAttachment bus, string path) : base(bus, path, false)
            {
                AllJoyn.InterfaceDescription exampleIntf = bus.GetInterface(INTERFACE_NAME);
                AllJoyn.QStatus status = AddInterface(exampleIntf);
                if (!status)
                {
                    Console.WriteLine("Server Failed to add interface {0}", status);
                }

                AllJoyn.InterfaceDescription.Member catMember = exampleIntf.GetMember("cat");
                status = AddMethodHandler(catMember, this.Cat);
                if (!status)
                {
                    Console.WriteLine("Server Failed to add method handler {0}", status);
                }
            }
예제 #11
0
        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();
        }
예제 #12
0
        public void Properties()
        {
            //SetUp Service
            //start service BusAttachment
            AllJoyn.BusAttachment serviceBus = new AllJoyn.BusAttachment("MessageTestService", true);
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Start());
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Connect(AllJoynTestCommon.GetConnectSpec()));

            TestBusListener testBusListener = new TestBusListener(this);

            serviceBus.RegisterBusListener(testBusListener);

            //Create and activate the service Interface
            AllJoyn.InterfaceDescription testIntf = null;
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.CreateInterface(INTERFACE_NAME, out testIntf));
            Assert.NotNull(testIntf);
            Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out"));
            testIntf.Activate();

            //create and register BusObject
            MessageTestBusObject busObj = new MessageTestBusObject(OBJECT_PATH);

            busObj.AddInterface(testIntf);
            AllJoyn.InterfaceDescription.Member ping;
            ping = testIntf.GetMember("ping");
            Assert.NotNull(ping);

            Assert.Equal(AllJoyn.QStatus.OK, busObj.AddMethodHandler(ping, busObj.Ping));

            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RegisterBusObject(busObj));

            _nameOwnerChangedFlag = false;
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RequestName(WELLKNOWN_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting |
                                                                    AllJoyn.DBus.NameFlags.DoNotQueue |
                                                                    AllJoyn.DBus.NameFlags.AllowReplacement));
            Wait(TimeSpan.FromSeconds(2));

            Assert.True(_nameOwnerChangedFlag);


            // SetUp Client
            // start client BusAttachment
            AllJoyn.BusAttachment clientBus = new AllJoyn.BusAttachment("MessageTestClient", true);
            Assert.Equal(AllJoyn.QStatus.OK, clientBus.Start());
            Assert.Equal(AllJoyn.QStatus.OK, clientBus.Connect(AllJoynTestCommon.GetConnectSpec()));

            AllJoyn.ProxyBusObject proxyObj = new AllJoyn.ProxyBusObject(clientBus, INTERFACE_NAME, OBJECT_PATH, 0);

            Assert.Equal(AllJoyn.QStatus.OK, proxyObj.IntrospectRemoteObject());

            AllJoyn.Message reply = new AllJoyn.Message(clientBus);
            AllJoyn.MsgArg  input = new AllJoyn.MsgArg("s", "AllJoyn");

            proxyObj.MethodCall(INTERFACE_NAME, "ping", input, reply, 25000, 0);

            // Actual tests for GetArg/GetArgs
            // check the message properties
            Assert.False(reply.IsBroadcastSignal);
            Assert.False(reply.IsGlobalBroadcast);
            Assert.False(reply.IsSessionless);
            Assert.False(reply.IsExpired());
            uint timeLeft;

            reply.IsExpired(out timeLeft);
            Assert.True(timeLeft > 0);
            Assert.False(reply.IsUnreliable);
            Assert.False(reply.IsEncrypted);
            // we don't expect any flags
            Assert.Equal((byte)0, reply.Flags);
            // no security is being used so there should be no security mechanism
            Assert.Equal("", reply.AuthMechanism);
            Assert.Equal(AllJoyn.Message.Type.MethodReturn, reply.MessageType);
            // The serial is unknown before hand but it should not be zero
            Assert.NotEqual <uint>(0u, reply.CallSerial);
            Assert.NotEqual <uint>(0u, reply.ReplySerial);
            // A method return does not have an Object Path
            Assert.Equal("", reply.ObjectPath);
            // A method return does not have an interface specified
            Assert.Equal("", reply.Interface);
            // The member name is not specified on a message return
            Assert.Equal("", reply.MemberName);
            // TODO possible error the documentation for Sender states it should
            // be returning the well-known name however in this case it is
            // returning the unique name of the sender.
            Assert.Equal(serviceBus.UniqueName, reply.Sender);
            Assert.Equal(clientBus.UniqueName, reply.ReceiveEndPointName);
            Assert.Equal(clientBus.UniqueName, reply.Destination);
            Assert.Equal(0u, reply.CompressionToken);
            // no session set up for this test Session Id should be 0
            Assert.Equal(0u, reply.SessionId);
            String errorMsg;

            // TODO produce test that generates actual error Message
            Assert.Null(reply.GetErrorName(out errorMsg));
            Assert.Equal("", errorMsg);
            // The  ToString method only returns a string when running debug code
#if DEBUG
            Assert.True(reply.ToString().StartsWith("<message endianness="));
            Assert.True(reply.ToString().Contains("<header field=\"REPLY_SERIAL\">"));
            Assert.True(reply.ToString().Contains("<header field=\"DESTINATION\">"));
            Assert.True(reply.ToString().Contains("<header field=\"SENDER\">"));
            Assert.True(reply.ToString().Contains("<header field=\"SIGNATURE\">"));
            Assert.True(reply.ToString().Contains("<signature>s</signature>"));
            Assert.True(reply.ToString().Contains("<string>AllJoyn</string>"));
            Assert.True(reply.ToString().EndsWith("</message>"));

            // this call to description should return 'METHID_RET[<reply serial>](s)'
            Assert.True(reply.Description.StartsWith("METHOD_RET["));
#else
            Assert.Equal("", reply.ToString());
            Assert.Equal("", reply.Description);
#endif
            // TODO figure out a good way to test the TimeStamp property
            //reply.TimeStamp

            // CleanUp
            serviceBus.UnregisterBusListener(testBusListener);
            reply.Dispose();
            input.Dispose();
            proxyObj.Dispose();
            clientBus.Dispose();

            testBusListener.Dispose();
            busObj.Dispose();
            serviceBus.Dispose();
        }
예제 #13
0
        public void GetArgs()
        {
            //SetUp Service
            //start service BusAttachment
            AllJoyn.BusAttachment serviceBus = new AllJoyn.BusAttachment("MessageTestService", true);
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Start());
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Connect(AllJoynTestCommon.GetConnectSpec()));

            TestBusListener testBusListener = new TestBusListener(this);

            serviceBus.RegisterBusListener(testBusListener);

            //Create and activate the service Interface
            AllJoyn.InterfaceDescription testIntf = null;
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.CreateInterface(INTERFACE_NAME, out testIntf));
            Assert.NotNull(testIntf);
            Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out"));
            testIntf.Activate();

            //create and register BusObject
            MessageTestBusObject busObj = new MessageTestBusObject(OBJECT_PATH);

            busObj.AddInterface(testIntf);
            AllJoyn.InterfaceDescription.Member ping;
            ping = testIntf.GetMember("ping");
            Assert.NotNull(ping);

            Assert.Equal(AllJoyn.QStatus.OK, busObj.AddMethodHandler(ping, busObj.Ping));

            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RegisterBusObject(busObj));

            _nameOwnerChangedFlag = false;
            Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RequestName(WELLKNOWN_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting |
                                                                    AllJoyn.DBus.NameFlags.DoNotQueue |
                                                                    AllJoyn.DBus.NameFlags.AllowReplacement));
            Wait(TimeSpan.FromSeconds(2));
            Assert.True(_nameOwnerChangedFlag);


            //SetUp Client
            //start client BusAttachment
            AllJoyn.BusAttachment clientBus = new AllJoyn.BusAttachment("MessageTestClient", true);
            Assert.Equal(AllJoyn.QStatus.OK, clientBus.Start());
            Assert.Equal(AllJoyn.QStatus.OK, clientBus.Connect(AllJoynTestCommon.GetConnectSpec()));

            AllJoyn.ProxyBusObject proxyObj = new AllJoyn.ProxyBusObject(clientBus, WELLKNOWN_NAME, OBJECT_PATH, 0);

            Assert.Equal(AllJoyn.QStatus.OK, proxyObj.IntrospectRemoteObject());

            AllJoyn.Message reply = new AllJoyn.Message(clientBus);
            AllJoyn.MsgArg  input = new AllJoyn.MsgArg("s", "AllJoyn");

            proxyObj.MethodCall(INTERFACE_NAME, "ping", input, reply, 25000, 0);

            //Actual tests for GetArg/GetArgs
            // call using GetArg specifying the array index
            Assert.Equal("AllJoyn", (string)reply.GetArg(0));
            // use the this[] operator call to get the MsgArg
            Assert.Equal("AllJoyn", (string)(reply[0]));
            // Return the MsgArgs note could be multiple values
            AllJoyn.MsgArg replyArg = reply.GetArgs();
            Assert.Equal(1, replyArg.Length);
            Assert.Equal("AllJoyn", (string)replyArg);
            // Parse the Message Drectly
            object replyString;

            Assert.Equal(AllJoyn.QStatus.OK, reply.GetArgs("s", out replyString));
            Assert.Equal("AllJoyn", (string)replyString);

            serviceBus.UnregisterBusListener(testBusListener);
            reply.Dispose();
            input.Dispose();
            proxyObj.Dispose();
            clientBus.Dispose();

            testBusListener.Dispose();
            busObj.Dispose();
            serviceBus.Dispose();
        }
예제 #14
0
        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");
        }
예제 #15
0
        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);
        }
예제 #16
0
        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.");
            }
        }