Example #1
0
    public bool Connect()
    {
        if (sJoinComplete)
        {
            return(sJoinComplete);
        }

        sJoinCalled = true;
        // We found a remote bus that is advertising basic service's  well-known name so connect to it
        AllJoyn.SessionOpts opts = new AllJoyn.SessionOpts(AllJoyn.SessionOpts.TrafficType.Messages, false,
                                                           AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

        uint sessionId;

        Debug.Log("kcwon Client JoinSession sFoundName = " + sFoundName);
        Debug.Log("kcwon Client JoinSession SERVICE_PORT = " + SERVICE_PORT);

        AllJoyn.QStatus status = msgBus.JoinSession(sFoundName, SERVICE_PORT, sessionListener, out sessionId, opts);
        if (status)
        {
            serverText += "Client JoinSession SUCCESS (Session id=" + sessionId + ")\n";
            Debug.Log("Client JoinSession SUCCESS (Session id=" + sessionId + ")");
            sJoinComplete = true;
            theSessionId  = sessionId;
        }
        else
        {
            serverText += "Client JoinSession failed (status=" + status.ToString() + ")\n";
            Debug.Log("Client JoinSession failed (status=" + status.ToString() + ")");
            ajNet.manager.connectFail();
        }

        return(sJoinComplete);
    }
Example #2
0
 public void JoinSession(string session)
 {
     if (currentJoinedSession != null)
     {
         LeaveSession();
     }
     AllJoyn.QStatus status = AllJoyn.QStatus.NONE;
     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() + ")");
         }
     }
     sessionListener = new MySessionListener();
     chatText        = "About to call JoinSession (Session=" + session + ")\n" + chatText;
     Debug.Log("About to call JoinSession (Session=" + session + ")");
     status = msgBus.JoinSession(session, SERVICE_PORT, sessionListener, out currentSessionId, opts);
     if (status)
     {
         chatText = "Client JoinSession SUCCESS (Session id=" + currentSessionId + ")\n" + chatText;
         Debug.Log("Client JoinSession SUCCESS (Session id=" + currentSessionId + ")");
         currentJoinedSession = session;
     }
     else
     {
         chatText = "Chat JoinSession failed (status=" + status.ToString() + ")\n" + chatText;
         Debug.Log("Chat JoinSession failed (status=" + status.ToString() + ")");
     }
 }
Example #3
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)
                {
                    chatText = "Chat Failed to add interface " + status.ToString() + "\n" + chatText;
                    Debug.Log("Chat Failed to add interface " + status.ToString());
                }

                chatMember = exampleIntf.GetMember("chat");
            }
Example #4
0
        public bool JoinSession(string session)
        {
            AllJoyn.QStatus status = AllJoyn.QStatus.NONE;
            if (sessionListener != null)
            {
                status          = msgBus.SetSessionListener(null, currentSessionId);
                sessionListener = null;
                if (!status)
                {
                    Debug.LogError("SetSessionListener status(" + status.ToString() + ")");
                }
            }
            sessionListener = new MySessionListener(this);
            //Debug.LogError("About to call JoinSession (Session=" + session + ")");
            status = msgBus.JoinSession(session, SERVICE_PORT, sessionListener, out currentSessionId, opts);
            if (status)
            {
                //Debug.LogError("Client JoinSession SUCCESS (Session id=" + currentSessionId + ")");
                currentJoinedSession = session;
            }
            else
            {
                //Debug.LogError("RHR JoinSession failed (status=" + status.ToString() + ")");
            }

            return(status ? true : false);
        }
Example #5
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("cat");
                status = AddMethodHandler(catMember, this.Cat);
                if (!status)
                {
                    serverText += "Server Failed to add method handler " + status.ToString() + "\n";
                    Debug.Log("Server Failed to add method handler " + status.ToString());
                }
            }
Example #6
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());
     }
 }
Example #7
0
        public void ConnectToFoundName()
        {
            sJoinCalled = true;
            // We found a remote bus that is advertising basic service's  well-known name so connect to it
            AllJoyn.SessionOpts opts = new AllJoyn.SessionOpts(AllJoyn.SessionOpts.TrafficType.Messages, false,
                                                               AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

            AllJoyn.QStatus status = sMsgBus.JoinSession(sFoundName, SERVICE_PORT, null, out sSessionId, opts);
            if (status)
            {
                clientText += "Client JoinSession SUCCESS (Session id=" + sSessionId + ")\n";
                Debug.Log("Client JoinSession SUCCESS (Session id=" + sSessionId + ")");
                sJoinComplete = true;
            }
            else
            {
                clientText += "Client JoinSession failed (status=" + status.ToString() + ")\n";
                Debug.Log("Client JoinSession failed (status=" + status.ToString() + ")");
            }
        }
Example #8
0
            public void SendPointsSignal(int points)
            {
                AllJoyn.MsgArg payload = new AllJoyn.MsgArg(1);
                //Debug.Log("Send Punkte: " + points.ToString());
                payload[0].Set((int)points);

                AllJoyn.QStatus status = Signal(null, currentSessionId, pointsMember, payload, 0, 64);
                if (!status)
                {
                    Debug.Log("Points failed to send signal: " + status.ToString());
                }
            }
Example #9
0
 public void LeaveSession()
 {
     Debug.Log("in LeaveSession.");
     if (currentSessionId != 0)
     {
         AllJoyn.QStatus status = AllJoyn.QStatus.NONE;
         if (sessionListener != null)
         {
             Debug.Log("clear session listener");
             status          = msgBus.SetSessionListener(null, currentSessionId);
             sessionListener = null;
             if (!status)
             {
                 chatText = "SetSessionListener failed status(" + status.ToString() + ")\n" + chatText;
                 Debug.Log("SetSessionListener status(" + status.ToString() + ")");
             }
         }
         Debug.Log("about to leave session");
         status = msgBus.LeaveSession(currentSessionId);
         if (status)
         {
             chatText = "Chat LeaveSession SUCCESS (Session id=" + currentSessionId + ")\n" + chatText;
             Debug.Log("Chat LeaveSession SUCCESS (Session id=" + currentSessionId + ")");
             currentSessionId     = 0;
             currentJoinedSession = null;
         }
         else
         {
             chatText = "Chat LeaveSession failed (status=" + status.ToString() + ")\n" + chatText;
             Debug.Log("Chat LeaveSession failed (status=" + status.ToString() + ")");
         }
     }
     else
     {
         currentJoinedSession = null;
     }
     Debug.Log("done LeaveSession.");
 }
Example #10
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());
                }
            }
Example #11
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());
                }
            }
Example #12
0
            public void SendPositionUpdateSignal(Vector3 position)
            {
                Debug.Log("SendPositionUdateSignal");
                AllJoyn.MsgArg payload = new AllJoyn.MsgArg(3);

                payload[0].Set((double)position.x);

                payload[1].Set((double)position.y);

                payload[2].Set((double)position.z);

                AllJoyn.QStatus status = Signal(null, currentSessionId, positionMember, payload, 0, 64);
                if (!status)
                {
                    Debug.Log("Position failed to send signal: " + status.ToString());
                }
            }
Example #13
0
            protected override void FoundAdvertisedName(string name, AllJoyn.TransportMask transport, string namePrefix)
            {
                Console.WriteLine("FoundAdvertisedName(name=" + name + ", prefix=" + namePrefix + ")");
                if (string.Compare(SERVICE_NAME, name) == 0)
                {
                    // We found a remote bus that is advertising basic service's  well-known name so connect to it
                    AllJoyn.SessionOpts opts = new AllJoyn.SessionOpts(AllJoyn.SessionOpts.TrafficType.Messages, false,
                                                                       AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

                    AllJoyn.QStatus status = sMsgBus.JoinSession(name, SERVICE_PORT, null, out sSessionId, opts);
                    if (status)
                    {
                        Console.WriteLine("JoinSession SUCCESS (Session id={0})", sSessionId);
                    }
                    else
                    {
                        Console.WriteLine("JoinSession failed (status={0})", status.ToString());
                    }
                }
                sJoinComplete = true;
            }
Example #14
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());
        }
Example #15
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 #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.");
            }
        }
Example #17
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 #18
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");
        }