Esempio n. 1
0
//Still test sending signals using obsolete Signal calls till the obsolete method is removed.
#pragma warning disable 618
            public void SendTestSignal2(String msg)
            {
                AllJoyn.MsgArgs payload = new AllJoyn.MsgArgs(1);
                payload[0].Set(msg);
                AllJoyn.QStatus status = Signal(null, 0, testSignalMember, payload, 0, 64);
                Assert.Equal(AllJoyn.QStatus.OK, status);
            }
Esempio n. 2
0
        public string CallRemoteMethod()
        {
            using (AllJoyn.ProxyBusObject remoteObj = new AllJoyn.ProxyBusObject(sMsgBus, SERVICE_NAME, SERVICE_PATH, sSessionId))
            {
                AllJoyn.InterfaceDescription alljoynTestIntf = sMsgBus.GetInterface(INTERFACE_NAME);
                if (alljoynTestIntf == null)
                {
                    throw new Exception("Client Failed to get test interface.");
                }
                remoteObj.AddInterface(alljoynTestIntf);

                AllJoyn.Message reply  = new AllJoyn.Message(sMsgBus);
                AllJoyn.MsgArgs inputs = new AllJoyn.MsgArgs(2);
                inputs[0] = "Hello ";
                inputs[1] = "World!";

                AllJoyn.QStatus status = remoteObj.MethodCallSynch(SERVICE_NAME, "cat", inputs, reply, 5000, 0);

                if (status)
                {
                    Console.WriteLine("{0}.{1} (path={2}) returned \"{3}\"", SERVICE_NAME, "cat", SERVICE_PATH,
                                      (string)reply[0]);
                    return((string)reply[0]);
                }
                else
                {
                    Console.WriteLine("MethodCall on {0}.{1} failed", SERVICE_NAME, "cat");
                    return("");
                }
            }
        }
Esempio n. 3
0
        public string CallRemoteMethod()
        {
            using (AllJoyn.ProxyBusObject remoteObj = new AllJoyn.ProxyBusObject(sMsgBus, SERVICE_NAME, SERVICE_PATH, sSessionId))
            {
                AllJoyn.InterfaceDescription alljoynTestIntf = sMsgBus.GetInterface(INTERFACE_NAME);
                if (alljoynTestIntf == null)
                {
                    //throw new Exception("Client Failed to get test interface.");
                    return("");
                }
                else
                {
                    remoteObj.AddInterface(alljoynTestIntf);

                    AllJoyn.Message reply  = new AllJoyn.Message(sMsgBus);
                    AllJoyn.MsgArgs inputs = new AllJoyn.MsgArgs(2);
                    inputs[0] = "Hello ";
                    inputs[1] = "World!";

                    AllJoyn.QStatus status = remoteObj.MethodCallSynch(SERVICE_NAME, "cat", inputs, reply, 5000, 0);

                    if (status)
                    {
                        //Debug.Log(SERVICE_NAME + ".cat(path=" + SERVICE_PATH + ") returned \"" + (string)reply[0] + "\"");
                        return((string)reply[0]);
                    }
                    else
                    {
                        Debug.Log("MethodCall on " + SERVICE_NAME + ".cat failed");
                        return("");
                    }
                }
            }
        }
Esempio n. 4
0
 public void SendChatSignal(string msg)
 {
     AllJoyn.MsgArgs payload = new AllJoyn.MsgArgs(1);
     payload[0].Set(msg);
     AllJoyn.QStatus status = Signal(null, currentSessionId, chatMember, payload, 0, 64);
     if (!status)
     {
         Debug.Log("Chat failed to send signal: " + status.ToString());
     }
 }
Esempio n. 5
0
            protected void Cat(AllJoyn.InterfaceDescription.Member member, AllJoyn.Message message)
            {
                string outStr = (string)message[0] + (string)message[1];

                AllJoyn.MsgArgs outArgs = new AllJoyn.MsgArgs(1);
                outArgs[0] = outStr;

                AllJoyn.QStatus status = MethodReply(message, outArgs);
                if (!status)
                {
                    Console.WriteLine("Server Ping: Error sending reply");
                }
            }
Esempio n. 6
0
        public void BasicAssignment()
        {
            AllJoyn.MsgArgs arg = new AllJoyn.MsgArgs(1);
            arg[0] = (byte)42;
            Assert.Equal((byte)42, (byte)arg[0]);
            arg[0] = true;
            Assert.True((bool)arg[0]);

            arg[0] = false;
            Assert.False((bool)arg[0]);

            arg[0] = (short)42;
            Assert.Equal((short)42, (short)arg[0]);

            arg[0] = (ushort)0xBEBE;
            Assert.Equal((ushort)0xBEBE, (ushort)arg[0]);

            arg[0] = (int)-9999;
            Assert.Equal((int)-9999, (int)arg[0]);

            arg[0] = (uint)0x32323232;
            Assert.Equal((uint)0x32323232, (uint)arg[0]);

            arg[0] = (long)-1;
            Assert.Equal((long)-1, (long)arg[0]);

            arg[0] = (ulong)0x6464646464646464;
            Assert.Equal((ulong)0x6464646464646464, (ulong)arg[0]);

            arg[0] = (float)1.61803f;
            Assert.Equal((float)1.61803f, (float)arg[0]);

            arg[0] = (double)3.14159265D;
            Assert.Equal((double)3.14159265D, (double)arg[0]);

            arg[0] = (string)"this is a string";
            Assert.Equal("this is a string", (string)arg[0]);

            arg[0].ObjectPath = "/org/foo/bar";
            Assert.Equal("/org/foo/bar", arg[0].ObjectPath);

            //assignment of an array
            AllJoyn.MsgArgs arg3 = new AllJoyn.MsgArgs(3);
            arg3[0] = (byte)5;
            arg3[1] = (byte)13;
            arg3[2] = (byte)42;

            Assert.Equal((byte)5, (byte)arg3[0]);
            Assert.Equal((byte)13, (byte)arg3[1]);
            Assert.Equal((byte)42, (byte)arg3[2]);
        }
Esempio n. 7
0
            public void SendEnemyHPData(string sender, string Myname, double health)
            {
                AllJoyn.MsgArgs payload = new AllJoyn.MsgArgs((uint)3);
                payload[0].Set((string)sender);
                payload[1].Set((string)Myname);
                payload[2].Set((double)health);

                byte flags = AllJoyn.ALLJOYN_FLAG_GLOBAL_BROADCAST;

                AllJoyn.QStatus status = Signal(null, 0, enemyHPMember, payload, 0, flags);
                if (!status)
                {
                    Debug.LogError("failed to send vector(data) signal: " + status.ToString());
                }
            }
Esempio n. 8
0
            public void SendEnemyAgroData(string sender, string myName, string playerName)
            {
                //Debug.LogError ("SendEnemyAgroData");
                AllJoyn.MsgArgs payload = new AllJoyn.MsgArgs((uint)3);
                payload[0].Set((string)sender);
                payload[1].Set((string)myName);
                payload[2].Set((string)playerName);

                byte flags = AllJoyn.ALLJOYN_FLAG_GLOBAL_BROADCAST;

                AllJoyn.QStatus status = Signal(null, 0, enemyAgroMember, payload, 0, flags);
                if (!status)
                {
                    Debug.LogError("failed to send vector(data) signal: " + status.ToString());
                }
            }
Esempio n. 9
0
            protected void Ping(AllJoyn.InterfaceDescription.Member member, AllJoyn.Message message)
            {
                string outStr = (string)message[0];

                AllJoyn.MsgArg outArgs = new AllJoyn.MsgArg();
                outArgs = outStr;

                AllJoyn.QStatus status = MethodReply(message, outArgs);
                Assert.Equal(AllJoyn.QStatus.OK, status);

//Continue testing obsolete method calls till they are removed.
#pragma warning disable 618
                AllJoyn.MsgArgs outArgs2 = new AllJoyn.MsgArgs(1);
                outArgs2[0] = outStr;

                status = MethodReply(message, outArgs2);
                Assert.Equal(AllJoyn.QStatus.OK, status);
#pragma warning restore 618
            }
Esempio n. 10
0
            public void SendEnemyInitData(string sender, string name, double enemyPosX, double enemyPosY, double enemyPosZ, double turning)
            {
                //Debug.LogError ("SendEnemyInitData");
                AllJoyn.MsgArgs payload = new AllJoyn.MsgArgs((uint)6);
                payload[0].Set((string)sender);
                payload[1].Set((string)name);
                payload[2].Set((double)enemyPosX);
                payload[3].Set((double)enemyPosY);
                payload[4].Set((double)enemyPosZ);
                payload[5].Set((double)turning);

                byte flags = AllJoyn.ALLJOYN_FLAG_GLOBAL_BROADCAST;

                AllJoyn.QStatus status = Signal(null, 0, enemyInitMember, payload, 0, flags);
                if (!status)
                {
                    //Debug.LogError("failed to send vector(data) signal: " + status.ToString());
                }
            }
Esempio n. 11
0
            public void SendPlayerData(string name, double enemyPosX, double enemyPosY, double enemyPosZ, double turning, bool shooting, bool walking)
            {
                AllJoyn.MsgArgs payload = new AllJoyn.MsgArgs((uint)7);
                payload[0].Set((string)name);
                payload[1].Set((double)enemyPosX);
                payload[2].Set((double)enemyPosY);
                payload[3].Set((double)enemyPosZ);
                payload[4].Set((double)turning);
                payload[5].Set((bool)shooting);
                payload[6].Set((bool)walking);

                byte flags = AllJoyn.ALLJOYN_FLAG_GLOBAL_BROADCAST;

                AllJoyn.QStatus status = Signal(null, 0, playerMember, payload, 0, flags);
                if (!status)
                {
                    //Debug.LogError("failed to send vector(data) signal: " + status.ToString());
                }
            }
Esempio n. 12
0
        public void BasicSet()
        {
            AllJoyn.MsgArgs arg = new AllJoyn.MsgArgs(1);

            Assert.Equal(AllJoyn.QStatus.OK, arg[0].Set((byte)13));
            Assert.Equal((byte)13, (byte)arg[0]);

            Assert.Equal(AllJoyn.QStatus.OK, arg[0].Set(true));
            Assert.True((bool)arg[0]);

            Assert.Equal(AllJoyn.QStatus.OK, arg[0].Set((short)42));
            Assert.Equal((short)42, (short)arg[0]);

            Assert.Equal(AllJoyn.QStatus.OK, arg[0].Set((ushort)0xBEBE));
            Assert.Equal((ushort)0xBEBE, (ushort)arg[0]);

            Assert.Equal(AllJoyn.QStatus.OK, arg[0].Set((int)-9999));
            Assert.Equal((int)-9999, (int)arg[0]);

            Assert.Equal(AllJoyn.QStatus.OK, arg[0].Set((uint)0x32323232));
            Assert.Equal((uint)0x32323232, (uint)arg[0]);

            Assert.Equal(AllJoyn.QStatus.OK, arg[0].Set((long)-1));
            Assert.Equal((long)-1, (long)arg[0]);

            Assert.Equal(AllJoyn.QStatus.OK, arg[0].Set((ulong)0x6464646464646464));
            Assert.Equal((ulong)0x6464646464646464, (ulong)arg[0]);

            Assert.Equal(AllJoyn.QStatus.OK, arg[0].Set((float)1.61803f));
            Assert.Equal((float)1.61803f, (float)arg[0]);

            Assert.Equal(AllJoyn.QStatus.OK, arg[0].Set((double)3.14159265D));
            Assert.Equal((double)3.14159265D, (double)arg[0]);

            Assert.Equal(AllJoyn.QStatus.OK, arg[0].Set((string)"this is a string"));
            Assert.Equal("this is a string", (string)arg[0]);

            arg[0].ObjectPath = "/org/foo/bar";
            Assert.Equal("/org/foo/bar", arg[0].ObjectPath);

            // todo  no support for signature type
        }
Esempio n. 13
0
        public void TestAddMethodHandler()
        {
            AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

            // create+start+connect bus attachment
            AllJoyn.BusAttachment servicebus = null;
            servicebus = new AllJoyn.BusAttachment("BusObjectTestService", true);
            Assert.NotNull(servicebus);

            status = servicebus.Start();
            Assert.Equal(AllJoyn.QStatus.OK, status);

            status = servicebus.Connect(AllJoynTestCommon.GetConnectSpec());
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // create+activate the interface
            AllJoyn.InterfaceDescription testIntf = null;
            status = servicebus.CreateInterface(INTERFACE_NAME, out testIntf);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Assert.NotNull(testIntf);

            status = testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out");
            Assert.Equal(AllJoyn.QStatus.OK, status);

            testIntf.Activate();

            // register bus listener
            AllJoyn.BusListener testBusListener = new TestBusListener(this);
            servicebus.RegisterBusListener(testBusListener);

            // create the bus object
            // the MethodTestBusObject constructor adds the interface & a handler for the ping method
            MethodTestBusObject methodTestBusObject = new MethodTestBusObject(servicebus, OBJECT_PATH);

            // register the bus object
            status = servicebus.RegisterBusObject(methodTestBusObject);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // request name
            nameOwnerChangedFlag = false;
            status = servicebus.RequestName(OBJECT_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Wait(MaxWaitTime);
            Assert.Equal(true, nameOwnerChangedFlag);

            ///////////////////////////////////////////////////////////

            // create the proxy bus object & call methods
            AllJoyn.BusAttachment bus = null;
            bus = new AllJoyn.BusAttachment("BusObjectTest", true);
            Assert.NotNull(bus);

            status = bus.Start();
            Assert.Equal(AllJoyn.QStatus.OK, status);

            status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
            Assert.Equal(AllJoyn.QStatus.OK, status);

            // create+activate the interface
            AllJoyn.InterfaceDescription iFace = null;
            status = bus.CreateInterface(INTERFACE_NAME, out iFace);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Assert.NotNull(iFace);

            status = iFace.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out");
            Assert.Equal(AllJoyn.QStatus.OK, status);

            iFace.Activate();

            AllJoyn.ProxyBusObject proxyBusObject = new AllJoyn.ProxyBusObject(bus, OBJECT_NAME, OBJECT_PATH, 0);
            status = proxyBusObject.AddInterface(iFace);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            AllJoyn.MsgArg input = new AllJoyn.MsgArg();
            input.Set("AllJoyn");
            AllJoyn.Message replyMsg = new AllJoyn.Message(bus);
            status = proxyBusObject.MethodCall(INTERFACE_NAME, "ping", input, replyMsg, 5000, 0);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Assert.Equal("AllJoyn", (string)replyMsg[0]);

//continue testing obsolete method calls till they are removed.
#pragma warning disable 618
            AllJoyn.MsgArg input1 = new AllJoyn.MsgArg();
            input1.Set("AllJoyn");
            AllJoyn.Message replyMsg1 = new AllJoyn.Message(bus);
            status = proxyBusObject.MethodCallSynch(INTERFACE_NAME, "ping", input1, replyMsg1, 5000, 0);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Assert.Equal("AllJoyn", (string)replyMsg1[0]);

            AllJoyn.MsgArgs input2 = new AllJoyn.MsgArgs(1);
            input2[0].Set("AllJoyn");
            AllJoyn.Message replyMsg2 = new AllJoyn.Message(bus);
            status = proxyBusObject.MethodCallSynch(INTERFACE_NAME, "ping", input2, replyMsg2, 5000, 0);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Assert.Equal("AllJoyn", (string)replyMsg2[0]);
#pragma warning restore 618

            methodTestBusObject.Dispose();
            servicebus.Dispose();

            // TODO: need to call dispose on proxyBusObject first otherwise you get an AccessViolation???
            proxyBusObject.Dispose();
            bus.Dispose();
        }
Esempio n. 14
0
        public void BasicArraySet()
        {
            AllJoyn.MsgArgs arg = new AllJoyn.MsgArgs(1);

            //byte
            byte[] in_byte_array = { 9, 19, 29, 39, 49 };
            arg[0].Set(in_byte_array);
            byte[] out_byte_array = (byte[])arg[0];
            Assert.Equal(in_byte_array.Length, out_byte_array.Length);
            for (int i = 0; i < out_byte_array.Length; i++)
            {
                Assert.Equal(in_byte_array[i], out_byte_array[i]);
            }

            //bool
            bool[] in_bool_array = { false, false, true, true, false };
            arg[0].Set(in_bool_array);
            bool[] out_bool_array = (bool[])arg[0];
            Assert.Equal(in_bool_array.Length, out_bool_array.Length);
            for (int i = 0; i < out_bool_array.Length; i++)
            {
                Assert.Equal(in_bool_array[i], out_bool_array[i]);
            }

            //short
            short[] in_short_array = { -9, -99, 999, 9999 };
            arg[0].Set(in_short_array);
            short[] out_short_array = (short[])arg[0];
            Assert.Equal(in_short_array.Length, out_short_array.Length);
            for (int i = 0; i < out_short_array.Length; i++)
            {
                Assert.Equal(in_short_array[i], out_short_array[i]);
            }

            //ushort
            ushort[] in_ushort_array = { 9, 99, 999, 9999 };
            arg[0].Set(in_ushort_array);
            ushort[] out_ushort_array = (ushort[])arg[0];
            Assert.Equal(in_ushort_array.Length, out_ushort_array.Length);
            for (int i = 0; i < out_short_array.Length; i++)
            {
                Assert.Equal(in_ushort_array[i], out_ushort_array[i]);
            }

            //int
            int[] in_int_array = { -8, -88, 888, 8888 };
            arg[0].Set(in_int_array);
            int[] out_int_array = (int[])arg[0];
            Assert.Equal(in_int_array.Length, out_int_array.Length);
            for (int i = 0; i < out_int_array.Length; i++)
            {
                Assert.Equal(in_int_array[i], out_int_array[i]);
            }

            //uint
            uint[] in_uint_array = { 8, 88, 888, 8888 };
            arg[0].Set(in_uint_array);
            uint[] out_uint_array = (uint[])arg[0];
            Assert.Equal(in_uint_array.Length, out_uint_array.Length);
            for (int i = 0; i < out_int_array.Length; i++)
            {
                Assert.Equal(in_uint_array[i], out_uint_array[i]);
            }

            //long
            long[] in_long_array = { -7, -77, 777, 7777 };
            arg[0].Set(in_long_array);
            long[] out_long_array = (long[])arg[0];
            Assert.Equal(in_long_array.Length, out_long_array.Length);
            for (int i = 0; i < out_long_array.Length; i++)
            {
                Assert.Equal(in_long_array[i], out_long_array[i]);
            }

            //ulong
            ulong[] in_ulong_array = { 7, 77, 777, 7777 };
            arg[0].Set(in_ulong_array);
            ulong[] out_ulong_array = (ulong[])arg[0];
            Assert.Equal(in_ulong_array.Length, out_ulong_array.Length);
            for (int i = 0; i < out_long_array.Length; i++)
            {
                Assert.Equal(in_ulong_array[i], out_ulong_array[i]);
            }

            //double
            double[] in_double_array = { 0.001, 0.01, 0.1, 1.0, 10.0, 100.0 };
            arg[0].Set(in_double_array);
            double[] out_double_array = (double[])arg[0];
            Assert.Equal(in_double_array.Length, out_double_array.Length);
            for (int i = 0; i < out_long_array.Length; i++)
            {
                Assert.Equal(in_double_array[i], out_double_array[i]);
            }

            //string
            string[] in_string_array = { "one", "two", "three", "four" };
            arg[0].Set(in_string_array);
            string[] out_string_array = (string[])arg[0];
            Assert.Equal(in_string_array.Length, out_string_array.Length);
            for (int i = 0; i < out_string_array.Length; i++)
            {
                Assert.Equal(in_string_array[i], out_string_array[i]);
            }
        }
Esempio n. 15
0
        public static void Main(string[] args)
        {
            Console.WriteLine("AllJoyn Library version: " + AllJoyn.GetVersion());
            Console.WriteLine("AllJoyn Library buildInfo: " + AllJoyn.GetBuildInfo());

            // Enable callbacks on main thread only
            AllJoyn.SetMainThreadOnlyCallbacks(true);

            // Create message bus
            sMsgBus = new AllJoyn.BusAttachment("myApp", true);

            // Add org.alljoyn.Bus.method_sample interface
            AllJoyn.InterfaceDescription testIntf;
            AllJoyn.QStatus status = sMsgBus.CreateInterface(INTERFACE_NAME, false, out testIntf);
            if (status)
            {
                Console.WriteLine("Interface Created.");
                testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "cat", "ss", "s", "inStr1,inStr2,outStr");
                testIntf.Activate();
            }
            else
            {
                Console.WriteLine("Failed to create interface 'org.alljoyn.Bus.method_sample'");
            }

            // Start the msg bus
            if (status)
            {
                status = sMsgBus.Start();
                if (status)
                {
                    Console.WriteLine("BusAttachment started.");
                }
                else
                {
                    Console.WriteLine("BusAttachment.Start failed.");
                }
            }

            // Connect to the bus
            if (status)
            {
                status = sMsgBus.Connect(connectArgs);
                if (status)
                {
                    Console.WriteLine("BusAttchement connected to " + connectArgs);
                }
                else
                {
                    Console.WriteLine("BusAttachment::Connect(" + connectArgs + ") failed.");
                }
            }

            // Create a bus listener
            sBusListener = new MyBusListener();

            if (status)
            {
                sMsgBus.RegisterBusListener(sBusListener);
                Console.WriteLine("BusListener Registered.");
            }

            // Begin discovery on the well-known name of the service to be called
            if (status)
            {
                status = sMsgBus.FindAdvertisedName(SERVICE_NAME);
                if (!status)
                {
                    Console.WriteLine("org.alljoyn.Bus.FindAdvertisedName failed.");
                }
            }

            // Wait for join session to complete
            while (sJoinComplete == false)
            {
                AllJoyn.TriggerCallbacks();                 // Pump messages
                System.Threading.Thread.Sleep(1);
            }

            if (status)
            {
                using (AllJoyn.ProxyBusObject remoteObj = new AllJoyn.ProxyBusObject(sMsgBus, SERVICE_NAME, SERVICE_PATH, sSessionId))
                {
                    AllJoyn.InterfaceDescription alljoynTestIntf = sMsgBus.GetInterface(INTERFACE_NAME);
                    if (alljoynTestIntf == null)
                    {
                        throw new Exception("Failed to get test interface.");
                    }
                    remoteObj.AddInterface(alljoynTestIntf);

                    AllJoyn.Message reply  = new AllJoyn.Message(sMsgBus);
                    AllJoyn.MsgArgs inputs = new AllJoyn.MsgArgs(2);
                    inputs[0] = "Hello ";
                    inputs[1] = "World!";

                    status = remoteObj.MethodCallSynch(SERVICE_NAME, "cat", inputs, reply, 5000, 0);

                    if (status)
                    {
                        Console.WriteLine("{0}.{1} (path={2}) returned \"{3}\"", SERVICE_NAME, "cat", SERVICE_PATH,
                                          (string)reply[0]);
                    }
                    else
                    {
                        Console.WriteLine("MethodCall on {0}.{1} failed", SERVICE_NAME, "cat");
                    }
                }
            }

            Console.WriteLine("basic client exiting with status {0} ({1})\n", status, status.ToString());
        }