Example #1
0
        public void GetNumericVersion()
        {
            // This will only test that a number larger than 0 is returned
            uint v = AllJoyn.GetNumericVersion();

            Assert.True(v > 0);
        }
Example #2
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);
            }
        }
Example #3
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());
            }
        }
Example #4
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
    }
Example #5
0
        public void GetExtensionVersion()
        {
            // Currently this value is not well defined so it may change
            // in an upcomming release
            // A string of form #.#.# is returned
            string extensionVer = AllJoyn.GetExtensionVersion();

            string[] extVer = extensionVer.Split('.');
            Assert.Equal(3, extVer.Length);
            foreach (string s in extVer)
            {
                int aaa;
                Assert.True(int.TryParse(s, out aaa));
            }
        }
Example #6
0
        public void GetBuildInfo()
        {
            // GetBuildInfo is expecte to be a string of type
            // AllJoyn Library v#.#.# (Built <weekday> <month> dd  hh:mm:ss UTC yyyy by <username>)
            // This test code is most likely more complex than
            // the code used to generate the string but it should handle any value
            // returned
            string buildInfo = AllJoyn.GetBuildInfo();
            string failMsg   = "Expected the BuildInfo string to start with 'AllJoyn Library' actual string was \n>>>\t " + buildInfo;

            Assert.True(buildInfo.StartsWith("AllJoyn Library"), failMsg);
            string[] bInfo = buildInfo.Split(' ');

            //dummy value to pass into int.TryParse
            int aaa;

            //already checked that the string started with 'AllJoyn Library'
            string[] versionLevels = bInfo[2].Substring(1).Split('.');
            Assert.Equal(3, versionLevels.Length);
            foreach (string s in versionLevels)
            {
                Assert.True(int.TryParse(s, out aaa));
            }
            Assert.True(bInfo[3].Equals("(Built"));
            //abbreviated weekday name.  In the default locale, it is equivalent
            //to one of the following: Sun, Mon, Tue, Wed, Thu, Fri or Sat.
            Assert.Equal(3, bInfo[4].Length);
            // locale's abbreviated month name.  In the default
            //locale, it is equivalent to one of the following: Jan, Feb,
            //Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov or Dec.
            Assert.Equal(3, bInfo[5].Length);
            //day of the month
            Assert.True(int.TryParse(bInfo[6], out aaa));
            //time hh:mm:ss
            string[] time = bInfo[7].Split(':');
            Assert.Equal(3, time.Length);
            foreach (string s in time)
            {
                Assert.True(int.TryParse(s, out aaa));
            }
            Assert.True(bInfo[8].Equals("UTC"));
            //year yyyy
            Assert.True(int.TryParse(bInfo[9], out aaa));
            Assert.True(bInfo[10].Equals("by"));
            //bInfo[11] is the user name will not test
            //we know the string should end in ')'
            Assert.Equal(')', bInfo[11][bInfo[11].Length - 1]);
        }
Example #7
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));
            }
        }
Example #8
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());
        }
 void OnApplicationQuit()
 {
     AllJoyn.StopAllJoynProcessing();
 }
Example #10
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());
 }
Example #11
0
 void OnDestroy()
 {
     AllJoyn.UnityDestroy();
 }
Example #12
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());
        }
Example #13
0
        public void CloseDown()
        {
            if (msgBus == null)
            {
                return;                 //no need to clean anything up
            }
            AllJoynStarted = false;
            LeaveSession();
            AllJoyn.QStatus status = msgBus.CancelFindAdvertisedName(SERVICE_NAME);
            if (!status)
            {
                chatText = "CancelAdvertisedName failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("CancelAdvertisedName failed status(" + status.ToString() + ")");
            }
            status = msgBus.CancelAdvertisedName(myAdvertisedName, opts.Transports);
            if (!status)
            {
                chatText = "CancelAdvertisedName failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("CancelAdvertisedName failed status(" + status.ToString() + ")");
            }
            status = msgBus.ReleaseName(myAdvertisedName);
            if (!status)
            {
                chatText = "ReleaseName failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("ReleaseName status(" + status.ToString() + ")");
            }
            status = msgBus.UnbindSessionPort(SERVICE_PORT);
            if (!status)
            {
                chatText = "UnbindSessionPort failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("UnbindSessionPort status(" + status.ToString() + ")");
            }

            status = msgBus.Disconnect(connectedVal);
            if (!status)
            {
                chatText = "Disconnect failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("Disconnect status(" + status.ToString() + ")");
            }

            AllJoyn.InterfaceDescription.Member chatMember = testIntf.GetMember("chat");
            status     = msgBus.UnregisterSignalHandler(this.ChatSignalHandler, chatMember, null);
            chatMember = null;
            if (!status)
            {
                chatText = "UnregisterSignalHandler failed status(" + status.ToString() + ")\n" + chatText;
                Debug.Log("UnregisterSignalHandler status(" + status.ToString() + ")");
            }
            if (sessionListener != null)
            {
                status          = msgBus.SetSessionListener(null, currentSessionId);
                sessionListener = null;
                if (!status)
                {
                    chatText = "SetSessionListener failed status(" + status.ToString() + ")\n" + chatText;
                    Debug.Log("SetSessionListener status(" + status.ToString() + ")");
                }
            }
            chatText = "No Exceptions(" + status.ToString() + ")\n" + chatText;
            Debug.Log("No Exceptions(" + status.ToString() + ")");
            currentSessionId     = 0;
            currentJoinedSession = null;
            sFoundName.Clear();

            connectedVal        = null;
            msgBus              = null;
            busListener         = null;
            sessionPortListener = null;
            testObj             = null;
            testIntf            = null;
            opts             = null;
            myAdvertisedName = null;

            AllJoynStarted = false;

            AllJoyn.StopAllJoynProcessing();             //Stop processing alljoyn callbacks
        }
Example #14
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);
    }