Пример #1
0
        public void AccessorFunctions()
        {
            AllJoyn.SessionOpts opts = new AllJoyn.SessionOpts(AllJoyn.SessionOpts.TrafficType.Messages,
                false, AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

            Assert.Equal(AllJoyn.SessionOpts.TrafficType.Messages, opts.Traffic);
            Assert.False(opts.IsMultipoint);
            Assert.Equal(AllJoyn.SessionOpts.ProximityType.Any, opts.Proximity);
            Assert.Equal(AllJoyn.TransportMask.Any, opts.Transports);

            opts.Traffic = AllJoyn.SessionOpts.TrafficType.RawReliable;
            Assert.Equal(AllJoyn.SessionOpts.TrafficType.RawReliable, opts.Traffic);

            opts.IsMultipoint = true;
            Assert.True(opts.IsMultipoint);

            opts.Proximity = AllJoyn.SessionOpts.ProximityType.Network;
            Assert.Equal(AllJoyn.SessionOpts.ProximityType.Network, opts.Proximity);
        }
Пример #2
0
        public void TestFoundNameByTransport()
        {
            listenerRegistered = false;
            foundAdvertisedName = false;
            nameOwnerChanged = false;
            transportFound = AllJoyn.TransportMask.None;

            // register the bus listener
            bus.RegisterBusListener(busListener);
            Wait(MaxWaitTime);
            Assert.Equal(true, listenerRegistered);

            AllJoyn.SessionOpts sessionOpts = new AllJoyn.SessionOpts(
                AllJoyn.SessionOpts.TrafficType.Messages, false,
                AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

            // advertise the name, & see if we find it
            status = bus.FindAdvertisedNameByTransport(ObjectName, AllJoyn.TransportMask.Local);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(MaxWaitTime);
            Assert.Equal(true, foundAdvertisedName);
            Assert.Equal(AllJoyn.TransportMask.Local, transportFound);

            status = bus.CancelAdvertisedName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            status = bus.CancelFindAdvertisedNameByTransport(ObjectName, AllJoyn.TransportMask.Local);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            foundAdvertisedName = false;
            status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(TimeSpan.FromSeconds(1));
            Assert.Equal(false, foundAdvertisedName);
        }
Пример #3
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
        }
Пример #4
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");
        }
Пример #5
0
        public BasicServer()
        {
            // Create message bus
            msgBus = new AllJoyn.BusAttachment("myApp", true);

            // Add org.alljoyn.Bus.method_sample interface
            AllJoyn.QStatus status = msgBus.CreateInterface(INTERFACE_NAME, out testIntf);
            if(status)
            {
                Console.WriteLine("Server 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
            busListener = new MyBusListener();
            if(status)
            {
                msgBus.RegisterBusListener(busListener);
                Console.WriteLine("Server BusListener Registered.");
            }

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

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

                    for (int i = 0; i < connectArgs.Length; ++i)
                    {
                        status = msgBus.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("Server BusAttachment.Start failed.");
                }
            }

            // Request name
            if(status)
            {
                status = msgBus.RequestName(SERVICE_NAME,
                    AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue);
                if(!status)
                {
                    Console.WriteLine("Server 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;
                sessionPortListener = new MySessionPortListener();
                status = msgBus.BindSessionPort(ref sessionPort, opts, sessionPortListener);
                if(!status || sessionPort != SERVICE_PORT)
                {
                    Console.WriteLine("Server BindSessionPort failed ({0})", status);
                }
            }

            // Advertise name
            if(status)
            {
                status = msgBus.AdvertiseName(SERVICE_NAME, opts.Transports);
                if(!status)
                {
                    Console.WriteLine("Server Failed to advertise name {0} ({1})", SERVICE_NAME, status);
                }
            }
            Console.WriteLine("Should have setup server");
        }
Пример #6
0
        public BasicServer()
        {
            // Create message bus
            msgBus = new AllJoyn.BusAttachment("myApp", true);

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

            // Create a bus listener
            busListener = new MyBusListener();
            if(status)
            {
                msgBus.RegisterBusListener(busListener);
                Debug.Log("Server BusListener Registered.");
            }

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

            // Start the msg bus
            if(status)
            {
                status = msgBus.Start();
                if(status)
                {
                    Debug.Log("Server BusAttachment started.");
                    msgBus.RegisterBusObject(testObj);

                    status = msgBus.Connect(connectArgs);
                    if(status)
                    {
                        Debug.Log("Server BusAttchement connected to " + connectArgs);
                    }
                    else
                    {
                        Debug.Log("Server BusAttachment::Connect(" + connectArgs + ") failed.");
                    }
                }
                else
                {
                    Debug.Log("Server BusAttachment.Start failed.");
                }
            }

            // Request name
            if(status)
            {
                status = msgBus.RequestName(SERVICE_NAME,
                    AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue);
                if(!status)
                {
                    Debug.Log("Server RequestName(" + SERVICE_NAME + ") failed (status=" + 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;
                sessionPortListener = new MySessionPortListener();
                status = msgBus.BindSessionPort(ref sessionPort, opts, sessionPortListener);
                if(!status || sessionPort != SERVICE_PORT)
                {
                    Debug.Log("Server BindSessionPort failed (" + status + ")");
                }
            }

            // Advertise name
            if(status)
            {
                status = msgBus.AdvertiseName(SERVICE_NAME, opts.Transports);
                if(!status)
                {
                    Debug.Log("Server Failed to advertise name " + SERVICE_NAME + " (" + status + ")");
                }
            }
        }
Пример #7
0
            protected override void FoundAdvertisedName(string name, AllJoyn.TransportMask transport, string namePrefix)
            {
                Debug.Log("Client 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)
                    {
                        Debug.Log("Client JoinSession SUCCESS (Session id=" + sSessionId + ")");
                    }
                    else
                    {
                        Debug.Log("Client JoinSession failed (status=" + status.ToString() + ")");
                    }
                }
                sJoinComplete = true;
            }
Пример #8
0
        public void CloseDown()
        {
            if (msgBus == null)
                return;
            AllJoynStarted = false;
            LeaveSession();
            AllJoyn.QStatus status = msgBus.CancelFindAdvertisedName(SERVICE_NAME);
            if (!status){
                DebugLog("CancelAdvertisedName failed status(" + status.ToString() + ")");
            }
            status = msgBus.CancelAdvertisedName(myAdvertisedName, opts.Transports);
            if (!status) {
                DebugLog("CancelAdvertisedName failed status(" + status.ToString() + ")");
            }
            status = msgBus.ReleaseName(myAdvertisedName);
            if (!status) {
                DebugLog("ReleaseName status(" + status.ToString() + ")");
            }
            status = msgBus.UnbindSessionPort(SERVICE_PORT);
            if (!status) {
                DebugLog("UnbindSessionPort status(" + status.ToString() + ")");
            }

            status = msgBus.Disconnect(connectedVal);
            if (!status) {
                DebugLog("Disconnect status(" + status.ToString() + ")");
            }

            AllJoyn.InterfaceDescription.Member vectorMember = testIntf.GetMember("vector");
            status = msgBus.UnregisterSignalHandler(this.VectorSignalHandler, vectorMember, null);
            vectorMember = null;
            if (!status) {
                DebugLog("UnregisterSignalHandler Vector status(" + status.ToString() + ")");
            }
            if (sessionListener != null) {
                status = msgBus.SetSessionListener(null, currentSessionId);
                sessionListener = null;
                if (!status) {
                    DebugLog("SetSessionListener status(" + status.ToString() + ")");
                }
            }
            DebugLog("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;

            sFoundName = new ArrayList();

            AllJoyn.StopAllJoynProcessing();
        }
Пример #9
0
		public void RemoveSessionMember()
		{
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// Create session
			AllJoyn.SessionOpts opts = new AllJoyn.SessionOpts(
				AllJoyn.SessionOpts.TrafficType.Messages, true,
				AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);
			ushort sessionPort = SERVICE_PORT;

			// create the session port listener
			AllJoyn.SessionPortListener sessionPortListener = new TestSessionPortListener(this);

			// bind to the session port
			status = hostBus.BindSessionPort(ref sessionPort, opts, sessionPortListener);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// request name
			status = hostBus.RequestName(OBJECT_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// Advertise name
			status = hostBus.AdvertiseName(OBJECT_NAME, opts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// register sessionMemberOne's bus listener
			AllJoyn.BusListener busListenerMemberOne = new TestBusListener(this);
			memberOneBus.RegisterBusListener(busListenerMemberOne);
			// create the session listener
			AllJoyn.SessionListener sessionListener = new TestSessionListener2(this);

			///////////////////////////////////////////////////////////
			// have sessionMemberOne find and join the session
			foundAdvertisedNameFlag = false;
			status = memberOneBus.FindAdvertisedName(OBJECT_NAME);  // find the advertised name from the "hostbus"
			Assert.Equal(AllJoyn.QStatus.OK, status);
			EventWaitHandle ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "FoundAdvertisedName");
			ewh.WaitOne(MaxWaitTime);
			Assert.Equal(true, foundAdvertisedNameFlag);

			uint sSessionId;
			acceptSessionJoinerFlag = false;
			sessionJoinedFlag = false;
			status = memberOneBus.JoinSession(OBJECT_NAME, SERVICE_PORT, sessionListener, out sSessionId, opts);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "SessionJoined");
			ewh.WaitOne(MaxWaitTime);

			// verify that sessionMemberOne joined by checking that the sessionedJoined callback was called
			Assert.Equal(true, acceptSessionJoinerFlag);
			Assert.Equal(true, sessionJoinedFlag);

			///////////////////////////////////////////////////////////
			// Now have the host leave & verify SessionLost callback is triggered
			sessionLostReasonFlag = false;
			reasonMarker = AllJoyn.SessionListener.SessionLostReason.ALLJOYN_SESSIONLOST_INVALID;
			sessionMemberRemovedFlag = false;
			hostBus.RemoveSessionMember(sSessionId, memberOneBus.UniqueName);
			ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "SessionLostReason");
			ewh.WaitOne(MaxWaitTime);
			Assert.Equal(true, sessionLostReasonFlag);
			Assert.Equal(AllJoyn.SessionListener.SessionLostReason.ALLJOYN_SESSIONLOST_REMOVED_BY_BINDER, reasonMarker);

			// SessionMemberRemoved should also be triggered
			ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "SessionMemberRemoved");
			ewh.WaitOne(MaxWaitTime);
			Assert.Equal(true, sessionMemberRemovedFlag);

			hostBus.ReleaseName(OBJECT_NAME);
		}
Пример #10
0
		public void TestSessionMemberAddRemove()
		{
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;
			sessionMemberAddedFlag = false;

			// Create session
			AllJoyn.SessionOpts opts = new AllJoyn.SessionOpts(
				AllJoyn.SessionOpts.TrafficType.Messages, true,
				AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);
			ushort sessionPort = SERVICE_PORT;

			// create the session port listener
			AllJoyn.SessionPortListener sessionPortListener = new TestSessionPortListener(this);

			// bind to the session port
			status = hostBus.BindSessionPort(ref sessionPort, opts, sessionPortListener);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// request name
			status = hostBus.RequestName(OBJECT_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// Advertise name
			status = hostBus.AdvertiseName(OBJECT_NAME, opts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// register sessionMemberOne's bus listener
			AllJoyn.BusListener busListenerMemberOne = new TestBusListener(this);
			memberOneBus.RegisterBusListener(busListenerMemberOne);
			// create the session listener
			AllJoyn.SessionListener sessionListener = new TestSessionListener2(this);

			AllJoyn.BusListener busListenerMemberTwo = new TestBusListener(this);
			memberTwoBus.RegisterBusListener(busListenerMemberTwo);

			///////////////////////////////////////////////////////////
			// have sessionMemberOne find and join the session
			foundAdvertisedNameFlag = false;
			status = memberOneBus.FindAdvertisedName(OBJECT_NAME);  // find the advertised name from the "hostbus"
			Assert.Equal(AllJoyn.QStatus.OK, status);
			EventWaitHandle ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "FoundAdvertisedName");
			ewh.WaitOne(MaxWaitTime);
			Assert.Equal(true, foundAdvertisedNameFlag);

			uint sSessionId;
			acceptSessionJoinerFlag = false;
			sessionJoinedFlag = false;
			status = memberOneBus.JoinSession(OBJECT_NAME, SERVICE_PORT, sessionListener, out sSessionId, opts);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "SessionJoined");
			ewh.WaitOne(MaxWaitTime);

			// verify that sessionMemberOne joined by checking that the sessionedJoined callback was called
			Assert.Equal(true, acceptSessionJoinerFlag);
			Assert.Equal(true, sessionJoinedFlag);

			///////////////////////////////////////////////////////////
			// have session member two find and join the session
			sessionMemberAddedFlag = false;
			foundAdvertisedNameFlag = false;
			status = memberTwoBus.FindAdvertisedName(OBJECT_NAME);  // find the advertised name from the "hostbus"
			Assert.Equal(AllJoyn.QStatus.OK, status);
			ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "FoundAdvertisedName");
			ewh.WaitOne(MaxWaitTime);
			Assert.Equal(true, foundAdvertisedNameFlag);

			acceptSessionJoinerFlag = false;
			sessionJoinedFlag = false;
			status = memberTwoBus.JoinSession(OBJECT_NAME, SERVICE_PORT, null, out sSessionId, opts);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "SessionJoined");
			ewh.WaitOne(MaxWaitTime);

			// verify that sessionMemberTwo joined by checking that the sessionedJoined callback was called
			Assert.Equal(true, acceptSessionJoinerFlag);
			Assert.Equal(true, sessionJoinedFlag);

			///////////////////////////////////////////////////////////
			// Now that sessionMemberTwo has joined, the SessionMemberAdded callback should have been triggered
			ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "SessionMemberAdded");
			ewh.WaitOne(MaxWaitTime);
			Assert.Equal(true, sessionMemberAddedFlag);

			///////////////////////////////////////////////////////////
			// Now have sessionMemberTwo leave & verify SessionMemberRemoved callback is triggered
			sessionMemberRemovedFlag = false;
			memberTwoBus.LeaveSession(sSessionId);
			ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "SessionMemberRemoved");
			ewh.WaitOne(MaxWaitTime);
			Assert.Equal(true, sessionMemberRemovedFlag);

			hostBus.ReleaseName(OBJECT_NAME);
		}
Пример #11
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'");
            }

            // 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);

                    status = sMsgBus.Connect(connectArgs);
                    if(status)
                    {
                        Console.WriteLine("BusAttchement connected to " + connectArgs);
                    }
                    else
                    {
                        Console.WriteLine("BusAttachment::Connect(" + connectArgs + ") 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)
                {
                    AllJoyn.TriggerCallbacks(); // Pump messages
                    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());
        }
Пример #12
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() + ")");
            }
        }
Пример #13
0
		public void TestFoundLostAdvertisedName()
		{
			// create bus attachment
			AllJoyn.BusAttachment bus = new AllJoyn.BusAttachment("BusListenerTest", true);
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// start the bus attachment
			status = bus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

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

			listenerRegistered = false;
			foundAdvertisedName = false;
			lostAdvertisedName = false;

			// register the bus listener
			AllJoyn.BusListener busListener = new TestBusListener(this);
			bus.RegisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.Equal(true, listenerRegistered);

			// advertise the name, & see if we find it
			status = bus.FindAdvertisedName(ObjectName);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			AllJoyn.SessionOpts sessionOpts = new AllJoyn.SessionOpts(
				AllJoyn.SessionOpts.TrafficType.Messages, false,
				AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

			status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			Wait(MaxWaitTime);
			Assert.Equal(true, foundAdvertisedName);

			// stop advertising the name, & see if we lose it
			status = bus.CancelAdvertisedName(ObjectName, sessionOpts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			Wait(MaxWaitTime);
			Assert.Equal(true, lostAdvertisedName);

			// TODO: move these into a teardown method?
			busListener.Dispose();
			bus.Dispose();
		}
Пример #14
0
		public void TestFoundNameByTransport()
		{
			// create bus attachment
			AllJoyn.BusAttachment bus = new AllJoyn.BusAttachment("BusListenerTest", true);
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// start the bus attachment
			status = bus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

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

			listenerRegistered = false;
			foundAdvertisedName = false;
			nameOwnerChanged = false;
			transportFound = AllJoyn.TransportMask.None;

			// register the bus listener
			AllJoyn.BusListener busListener = new TestBusListener(this);
			bus.RegisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.Equal(true, listenerRegistered);

			AllJoyn.SessionOpts sessionOpts = new AllJoyn.SessionOpts(
				AllJoyn.SessionOpts.TrafficType.Messages, false,
				AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

			// advertise the name, & see if we find it
			status = bus.FindAdvertisedNameByTransport(ObjectName, AllJoyn.TransportMask.Local);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			Wait(MaxWaitTime);
			Assert.Equal(true, foundAdvertisedName);
			Assert.Equal(AllJoyn.TransportMask.Local, transportFound);

			status = bus.CancelAdvertisedName(ObjectName, sessionOpts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			status = bus.CancelFindAdvertisedNameByTransport(ObjectName, AllJoyn.TransportMask.Local);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			foundAdvertisedName = false;
			status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			Wait(TimeSpan.FromSeconds(1));
			Assert.Equal(false, foundAdvertisedName);

			busListener.Dispose();
			bus.Dispose();
		}
Пример #15
0
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                // additional clean up before disposing
                // make sure the ObjectName is not advertised or owned by the bus
                // between runs these are run regardless we actually don't expect
                // these names to be owned between runs this is here just in case
                // a test fails we want to make sure the names are cleared from
                // the daemon
                AllJoyn.SessionOpts sessionOpts = new AllJoyn.SessionOpts(
                    AllJoyn.SessionOpts.TrafficType.Messages, false,
                    AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);
                bus.CancelAdvertisedName(ObjectName, sessionOpts.Transports);
                bus.ReleaseName(ObjectName);

                if (disposing)
                {
                    busListener.Dispose();
                    bus.Dispose();
                }

                disposed = true;
            }
        }
Пример #16
0
		public void TestSessionJoined()
		{
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// Create session
			AllJoyn.SessionOpts opts = new AllJoyn.SessionOpts(
				AllJoyn.SessionOpts.TrafficType.Messages, false,
				AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);
			ushort sessionPort = SERVICE_PORT;

			// create the session port listener
			AllJoyn.SessionPortListener sessionPortListener = new TestSessionPortListener(this);

			// bind to the session port
			status = hostBus.BindSessionPort(ref sessionPort, opts, sessionPortListener);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// request name
			status = hostBus.RequestName(OBJECT_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// Advertise name
			status = hostBus.AdvertiseName(OBJECT_NAME, opts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			///////////////////////////////////////////////////////////
			foundAdvertisedNameFlag = false;
			acceptSessionJoinerFlag = false;
			sessionJoinedFlag = false;

			// try to join the session & verify callbacks are called

			// register the bus listener
			AllJoyn.BusListener busListener = new TestBusListener(this);
			memberOneBus.RegisterBusListener(busListener);

			// find the advertised name from the "servicebus"
			status = memberOneBus.FindAdvertisedName(OBJECT_NAME);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			EventWaitHandle ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "FoundAdvertisedName");
			ewh.WaitOne(MaxWaitTime);
			Assert.Equal(true, foundAdvertisedNameFlag);

			// try to join & verify that the sessionedJoined callback was called
			uint sSessionId;
			status = memberOneBus.JoinSession(OBJECT_NAME, SERVICE_PORT, null, out sSessionId, opts);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "SessionJoined");
			ewh.WaitOne(MaxWaitTime);
			Assert.Equal(true, acceptSessionJoinerFlag);
			Assert.Equal(true, sessionJoinedFlag);
			hostBus.ReleaseName(OBJECT_NAME);
		}
Пример #17
0
        public void TestFoundLostAdvertisedName()
        {
            listenerRegistered = false;
            foundAdvertisedName = false;
            lostAdvertisedName = false;

            // register the bus listener
            bus.RegisterBusListener(busListener);
            Wait(MaxWaitTime);
            Assert.Equal(true, listenerRegistered);

            // advertise the name, & see if we find it
            status = bus.FindAdvertisedName(ObjectName);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            AllJoyn.SessionOpts sessionOpts = new AllJoyn.SessionOpts(
                AllJoyn.SessionOpts.TrafficType.Messages, false,
                AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);

            status = bus.AdvertiseName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(MaxWaitTime);
            Assert.Equal(true, foundAdvertisedName);

            // stop advertising the name, & see if we lose it
            status = bus.CancelAdvertisedName(ObjectName, sessionOpts.Transports);
            Assert.Equal(AllJoyn.QStatus.OK, status);

            Wait(MaxWaitTime);
            Assert.Equal(true, lostAdvertisedName);
        }
Пример #18
0
        // FUNKCJE ODPOWIADAJACE ZA URUCHAMIANIE ALLJOYNA,
        // DOLACZANIE DO SESJI Z INNYM GRACZEM,
        // KONCZENIE SESJI ORAZ WYLACZANIE ALLJOYNA
        public void StartUp()
        {
            DebugLog("Starting AllJoyn");
            AllJoynStarted = true;
            AllJoyn.QStatus status = AllJoyn.QStatus.OK;
            {
                DebugLog("Creating BusAttachment");
                msgBus = new AllJoyn.BusAttachment("myApp", true);

                status = msgBus.CreateInterface(INTERFACE_NAME, false, out testIntf);
                if (status)
                {
                    DebugLog("RHR Interface Created.");
                    testIntf.AddSignal ("vector", "adadad", "points", 0);
                    testIntf.Activate();
                }
                else
                {
                    DebugLog("Failed to create interface 'org.alljoyn.Bus.chat'");
                }

                busListener = new MyBusListener();
                if (status)
                {
                    msgBus.RegisterBusListener(busListener);
                    DebugLog("RHR BusListener Registered.");
                }

                if (testObj == null)
                    testObj = new TestBusObject(msgBus, SERVICE_PATH);

                if (status)
                {
                    status = msgBus.Start();
                    if (status)
                    {
                        DebugLog("RHR BusAttachment started.");

                        msgBus.RegisterBusObject(testObj);
                        for (int i = 0; i < connectArgs.Length; ++i)
                        {
                            DebugLog("RHR Connect trying: "+connectArgs[i]);
                            status = msgBus.Connect(connectArgs[i]);
                            if (status)
                            {
                                DebugLog("BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED.");
                                connectedVal = connectArgs[i];
                                break;
                            }
                            else
                            {
                                DebugLog("BusAttachment.Connect(" + connectArgs[i] + ") failed.");
                            }
                        }
                        if (!status)
                        {
                            DebugLog("BusAttachment.Connect failed.");
                        }
                    }
                    else
                    {
                        DebugLog("RHR BusAttachment.Start failed.");
                    }
                }

                myAdvertisedName = SERVICE_NAME+ "._" + msgBus.GlobalGUIDString + playerNick;

                AllJoyn.InterfaceDescription.Member vectorMember = testIntf.GetMember ("vector");
                status = msgBus.RegisterSignalHandler(this.VectorSignalHandler, vectorMember, null);
                if (!status)
                {
                    DebugLog("RHR Failed to add vector signal handler " + status);
                }
                else
                {
                    DebugLog("RHR add vector signal handler " + status);
                }

                status = msgBus.AddMatch("type='signal',member='vector'");
                if (!status)
                {
                    DebugLog("RHR Failed to add vector Match " + status.ToString());
                }
                else
                {
                    DebugLog("RHR add vector Match " + status.ToString());
                }
            }

            if (status)
            {
                status = msgBus.RequestName(myAdvertisedName,
                    AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue);
                if (!status)
                {
                    DebugLog("RHR 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)
                {
                    DebugLog("RHR BindSessionPort failed (" + status + ")");
                }
                DebugLog("RHR BBindSessionPort on port (" + sessionPort + ")");;
            }

            if (status)
            {
                status = msgBus.AdvertiseName(myAdvertisedName, opts.Transports);
                if (!status)
                {
                    DebugLog("RHR Failed to advertise name " + myAdvertisedName + " (" + status + ")");
                }
            }

            status = msgBus.FindAdvertisedName(SERVICE_NAME);
            if (!status)
            {
                DebugLog("RHR org.alljoyn.Bus.FindAdvertisedName failed.");
            }
        }