Exemplo n.º 1
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);

            BasicServer basicServer = new BasicServer();
            BasicClient basicClient = new BasicClient();

            basicClient.Connect();

            while (!basicClient.Connected)
            {
                AllJoyn.TriggerCallbacks();                 // Pump messages
                System.Threading.Thread.Sleep(1);
            }

            Console.WriteLine("BasicClient.CallRemoteMethod returned '{0}'", basicClient.CallRemoteMethod());

            while (basicServer.KeepRunning)
            {
                AllJoyn.TriggerCallbacks();                 // Pump messages
                System.Threading.Thread.Sleep(1);
            }
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("AllJoyn Library version: " + AllJoyn.GetVersion());
            Console.WriteLine("AllJoyn Library buildInfo: " + AllJoyn.GetBuildInfo());

            BasicServer basicServer = new BasicServer();
            BasicClient basicClient = new BasicClient();

            basicClient.Connect();

            while (!basicClient.Connected)
            {
                System.Threading.Thread.Sleep(1);
            }

            Console.WriteLine("BasicClient.CallRemoteMethod returned '{0}'", basicClient.CallRemoteMethod());

            while (basicServer.KeepRunning)
            {
                System.Threading.Thread.Sleep(1);
                //System.GC.Collect();
                //System.GC.WaitForPendingFinalizers();
                //System.GC.WaitForFullGCComplete();
                //System.GC.Collect();
                Console.WriteLine("BasicClient.CallRemoteMethod returned '{0}'", basicClient.CallRemoteMethod());
            }
        }
Exemplo n.º 3
0
    // Awake() is called before any calls to Start() on any game object are made.
    void Awake()
    {
        // Output AllJoyn version information to log
        Debug.Log("AllJoyn Library version: " + AllJoyn.GetVersion());
        Debug.Log("AllJoyn Library buildInfo: " + AllJoyn.GetBuildInfo());

#if UNITY_ANDROID
        AllJoyn.UnityInitialize("./libmono.so");
#else
        AllJoyn.UnityInitialize();
#endif
    }
Exemplo n.º 4
0
        public void GetVersion()
        {
            // version is expecte to be a string of type v#.#.# where # represents a
            // number of unknown length. This test code is most likely more complex than
            // the code used to generate the string but it should handle any value
            // returned
            string version = AllJoyn.GetVersion();

            Assert.Equal('v', version[0]);
            string[] versionLevels = version.Substring(1).Split('.');

            Assert.Equal(3, versionLevels.Length);
            foreach (string level in versionLevels)
            {
                int aaa;
                Assert.True(int.TryParse(level, out aaa));
            }
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            Console.WriteLine("AllJoyn Library version: " + AllJoyn.GetVersion());
            Console.WriteLine("AllJoyn Library buildInfo: " + AllJoyn.GetBuildInfo());

            // 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, 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)
            {
                for (int i = 0; i < connectArgs.Length; ++i)
                {
                    status = sMsgBus.Connect(connectArgs[i]);
                    if (status)
                    {
                        Console.WriteLine("BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED.");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("BusAttachment.Connect(" + connectArgs[i] + ") failed.");
                    }
                }
                if (!status)
                {
                    Console.WriteLine("BusAttachment.Connect 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)
            {
                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.MsgArg  inputs = new AllJoyn.MsgArg(2);
                    inputs[0] = "Hello ";
                    inputs[1] = "World!";

                    status = remoteObj.MethodCall(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");
                    }
                }
            }

            // Dispose of objects now
            sMsgBus.Dispose();
            sBusListener.Dispose();

            Console.WriteLine("basic client exiting with status {0} ({1})\n", status, status.ToString());
        }
Exemplo n.º 6
0
 // Awake() is called before any calls to Start() on any game object are made.
 void Awake()
 {
     // Output AllJoyn version information to log
     Debug.Log("AllJoyn Library version: " + AllJoyn.GetVersion());
     Debug.Log("AllJoyn Library buildInfo: " + AllJoyn.GetBuildInfo());
 }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            Console.WriteLine("AllJoyn Library version: " + AllJoyn.GetVersion());
            Console.WriteLine("AllJoyn Library buildInfo: " + AllJoyn.GetBuildInfo());

            // 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, 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'");
            }

            // Create a bus listener
            sBusListener = new MyBusListener();
            if (status)
            {
                sMsgBus.RegisterBusListener(sBusListener);
                Console.WriteLine("BusListener Registered.");
            }

            // Set up bus object
            TestBusObject testObj = new TestBusObject(sMsgBus, SERVICE_PATH);

            // Start the msg bus
            if (status)
            {
                status = sMsgBus.Start();
                if (status)
                {
                    Console.WriteLine("BusAttachment started.");
                    sMsgBus.RegisterBusObject(testObj);

                    for (int i = 0; i < connectArgs.Length; ++i)
                    {
                        status = sMsgBus.Connect(connectArgs[i]);
                        if (status)
                        {
                            Console.WriteLine("BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED.");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("BusAttachment.Connect(" + connectArgs[i] + ") failed.");
                        }
                    }
                    if (!status)
                    {
                        Console.WriteLine("BusAttachment.Connect failed.");
                    }
                }
                else
                {
                    Console.WriteLine("BusAttachment.Start failed.");
                }
            }

            // Request name
            if (status)
            {
                status = sMsgBus.RequestName(SERVICE_NAME,
                                             AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue);
                if (!status)
                {
                    Console.WriteLine("RequestName({0}) failed (status={1})", SERVICE_NAME, status);
                }
            }

            // Create session
            AllJoyn.SessionOpts opts = new AllJoyn.SessionOpts(AllJoyn.SessionOpts.TrafficType.Messages, false,
                                                               AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);
            if (status)
            {
                ushort sessionPort = SERVICE_PORT;
                sSessionPortListener = new MySessionPortListener();
                status = sMsgBus.BindSessionPort(ref sessionPort, opts, sSessionPortListener);
                if (!status)
                {
                    Console.WriteLine("BindSessionPort failed ({0})", status);
                }
            }

            // Advertise name
            if (status)
            {
                status = sMsgBus.AdvertiseName(SERVICE_NAME, opts.Transports);
                if (!status)
                {
                    Console.WriteLine("Failed to advertise name {0} ({1})", SERVICE_NAME, status);
                }
            }

            if (status)
            {
                while (true)
                {
                    System.Threading.Thread.Sleep(1);
                }
            }

            // Dispose of objects now
            sMsgBus.Dispose();
            sBusListener.Dispose();

            Console.WriteLine("basic server exiting with status {0} ({1})", status, status.ToString());
        }
Exemplo n.º 8
0
    public bool StartClient()
    {
        serverText  = "";
        serverText += "AllJoyn Library version: " + AllJoyn.GetVersion() + "\n";
        serverText += "AllJoyn Library buildInfo: " + AllJoyn.GetBuildInfo() + "\n";
        // Create message bus
        msgBus = new AllJoyn.BusAttachment("myApp", true);

        // Add org.alljoyn.Bus.method_sample interface
        AllJoyn.InterfaceDescription testIntf;
        AllJoyn.QStatus status = msgBus.CreateInterface(INTERFACE_NAME, false, out testIntf);
        if (status)
        {
            serverText += "Client Interface Created.\n";
            Debug.Log("Client Interface Created.");
            testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "acc", "s", "s", "in1,out1");
            testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "data", "ss", "s", "in1,in2,out1");
            testIntf.Activate();
        }
        else
        {
            serverText += "Client Failed to create interface 'org.alljoyn.Bus.method_sample'\n";
            Debug.Log("Client Failed to create interface 'org.alljoyn.Bus.method_sample'");
        }

        // Start the msg bus
        if (status)
        {
            status = msgBus.Start();
            if (status)
            {
                serverText += "Client BusAttachment started.\n";
                Debug.Log("Client BusAttachment started.");
            }
            else
            {
                serverText += "Client BusAttachment.Start failed.\n";
                Debug.Log("Client BusAttachment.Start failed.");
            }
        }

        // Connect to the bus
        if (status)
        {
            for (int i = 0; i < connectArgs.Length; ++i)
            {
                status = msgBus.Connect(connectArgs[i]);
                if (status)
                {
                    serverText += "BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED.\n";
                    Debug.Log("BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED.");
                    break;
                }
                else
                {
                    serverText += "BusAttachment.Connect(" + connectArgs[i] + ") failed.\n";
                    Debug.Log("BusAttachment.Connect(" + connectArgs[i] + ") failed.");
                }
            }
            if (!status)
            {
                serverText += "BusAttachment.Connect failed.\n";
                Debug.Log("BusAttachment.Connect failed.");
            }
        }

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

        if (status)
        {
            msgBus.RegisterBusListener(busListener);
            serverText += "Client BusListener Registered.\n";
            Debug.Log("Client BusListener Registered.");
        }

        // Begin discovery on the well-known name of the service to be called
        status = msgBus.FindAdvertisedName(SERVICE_NAME);
        if (!status)
        {
            serverText += "Client org.alljoyn.Bus.FindAdvertisedName failed.\n";
            Debug.Log("Client org.alljoyn.Bus.FindAdvertisedName failed.");
        }

        if (status)
        {
            this.status = Status.Client;
            return(true);
        }

        return(false);
    }