示例#1
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("");
                }
            }
        }
示例#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.");
                    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("");
                    }
                }
            }
        }
示例#3
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();
        }
示例#4
0
        public void MethodNoInputParams()
        {
            // 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, "ding", "", "s", "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 dingBusObject constructor adds the interface & a handler for the ping method
            DingBusObject dingBusObject = new DingBusObject(servicebus, OBJECT_PATH);

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

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

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

            // 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.AddMethod("ding", "", "s", "in,out");
            Assert.Equal(AllJoyn.QStatus.OK, status);

            iFace.Activate();

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

            AllJoyn.Message replyMsg = new AllJoyn.Message(bus);
            status = proxyBusObject.MethodCall(INTERFACE_NAME, "ding", AllJoyn.MsgArg.Zero, replyMsg, 5000, 0);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Assert.Equal("Hello from Ding.", (string)replyMsg[0]);

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

            AllJoyn.Message replyMsg2 = new AllJoyn.Message(bus);
            status = proxyBusObject.MethodCallSynch(INTERFACE_NAME, "ding", AllJoyn.MsgArg.Zero, replyMsg2, 5000, 0);
            Assert.Equal(AllJoyn.QStatus.OK, status);
            Assert.Equal("Hello from Ding.", (string)replyMsg2[0]);
#pragma warning restore 618

            dingBusObject.Dispose();
        }
示例#5
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());
        }