RegisterBusListener() public method

public RegisterBusListener ( BusListener listener ) : void
listener BusListener
return void
コード例 #1
0
		public void TestListenerRegisteredUnregistered()
		{
			AllJoyn.BusAttachment bus = new AllJoyn.BusAttachment("BusListenerTest", true);
			AllJoyn.BusListener busListener = new TestBusListener(this);
			listenerRegistered = false;
			listenerUnregistered = false;
			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);

			bus.RegisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.Equal(true, listenerRegistered);

			bus.UnregisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.Equal(true, listenerUnregistered);

			// TODO: move these into a teardown method?
			busListener.Dispose();
			bus.Dispose();
		}
コード例 #2
0
ファイル: BasicClient.cs プロジェクト: GameClay/alljoyn_unity
        public BasicClient()
        {
            // 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)
            {
                Debug.Log("Client Interface Created.");
                testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "cat", "ss", "s", "inStr1,inStr2,outStr");
                testIntf.Activate();
            }
            else
            {
                Debug.Log("Client Failed to create interface 'org.alljoyn.Bus.method_sample'");
            }

            // Start the msg bus
            if(status)
            {
                status = sMsgBus.Start();
                if(status)
                {
                    Debug.Log("Client BusAttachment started.");
                }
                else
                {
                    Debug.Log("Client BusAttachment.Start failed.");
                }
            }

            // Connect to the bus
            if(status)
            {
                status = sMsgBus.Connect(connectArgs);
                if(status)
                {
                    Debug.Log("Client BusAttchement connected to " + connectArgs);
                }
                else
                {
                    Debug.Log("Client BusAttachment::Connect(" + connectArgs + ") failed.");
                }
            }

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

            if(status)
            {
                sMsgBus.RegisterBusListener(sBusListener);
                Debug.Log("Client BusListener Registered.");
            }
        }
コード例 #3
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 + ")");
                }
            }
        }
コード例 #4
0
ファイル: BasicClient.cs プロジェクト: hybridgroup/alljoyn
        public BasicClient()
        {
            // 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("Client Interface Created.");
                testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "cat", "ss", "s", "inStr1,inStr2,outStr");
                testIntf.Activate();
            }
            else
            {
                Console.WriteLine("Client Failed to create interface 'org.alljoyn.Bus.method_sample'");
            }

            // Start the msg bus
            if(status)
            {
                status = sMsgBus.Start();
                if(status)
                {
                    Console.WriteLine("Client BusAttachment started.");
                }
                else
                {
                    Console.WriteLine("Client 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("Client BusListener Registered.");
            }
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: GameClay/alljoyn_unity
        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());
        }
コード例 #6
0
		public void TestAddMethodHandler()
		{
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// create+start+connect bus attachment
			AllJoyn.BusAttachment servicebus = null;
			servicebus = new AllJoyn.BusAttachment("BusObjectTestService", true);
			Assert.NotNull(servicebus);

			status = servicebus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

			status = servicebus.Connect(AllJoynTestCommon.GetConnectSpec());
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// create+activate the interface
			AllJoyn.InterfaceDescription testIntf = null;
			status = servicebus.CreateInterface(INTERFACE_NAME, out testIntf);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Assert.NotNull(testIntf);

			status = testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out");
			Assert.Equal(AllJoyn.QStatus.OK, status);

			testIntf.Activate();

			// register bus listener
			AllJoyn.BusListener testBusListener = new TestBusListener(this);
			servicebus.RegisterBusListener(testBusListener);

			// create the bus object
			// the MethodTestBusObject constructor adds the interface & a handler for the ping method
			MethodTestBusObject methodTestBusObject = new MethodTestBusObject(servicebus, OBJECT_PATH);

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

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

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

			// create the proxy bus object & call methods
			AllJoyn.BusAttachment bus = null;
			bus = new AllJoyn.BusAttachment("BusObjectTest", true);
			Assert.NotNull(bus);

			status = bus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

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

			// create+activate the interface
			AllJoyn.InterfaceDescription iFace = null;
			status = bus.CreateInterface(INTERFACE_NAME, out iFace);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Assert.NotNull(iFace);

			status = iFace.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out");
			Assert.Equal(AllJoyn.QStatus.OK, status);

			iFace.Activate();

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

			AllJoyn.MsgArg input = new AllJoyn.MsgArg();
			input.Set("AllJoyn");
			AllJoyn.Message replyMsg = new AllJoyn.Message(bus);
			status = proxyBusObject.MethodCall(INTERFACE_NAME, "ping", input, replyMsg, 5000, 0);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Assert.Equal("AllJoyn", (string)replyMsg[0]);

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

			AllJoyn.MsgArgs input2 = new AllJoyn.MsgArgs(1);
			input2[0].Set("AllJoyn");
			AllJoyn.Message replyMsg2 = new AllJoyn.Message(bus);
			status = proxyBusObject.MethodCallSynch(INTERFACE_NAME, "ping", input2, replyMsg2, 5000, 0);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Assert.Equal("AllJoyn", (string)replyMsg2[0]);
#pragma warning restore 618

			methodTestBusObject.Dispose();
			servicebus.Dispose();

			// TODO: need to call dispose on proxyBusObject first otherwise you get an AccessViolation???
			proxyBusObject.Dispose();
			bus.Dispose();
		}
コード例 #7
0
		public void EnableConcurrentCallbacks_Not_Used()
		{
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;
			callbackStatus = AllJoyn.QStatus.FAIL;
			listenerRegisteredFlag = false;
			nameOwnerChangedFlag = false;

			mbus = new AllJoyn.BusAttachment("BusListenerTest", true);
			AllJoyn.BusListener busListener = new BusListenerWithBlockingCall(this);

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

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

			mbus.RegisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.True(listenerRegisteredFlag);

			mbus.RequestName(ObjectName, 0);
			Wait(MaxWaitTime);
			Assert.True(nameOwnerChangedFlag);
			/*
			 * Because of the way that callback functions are defered we can still make
			 * what would be a blocking call in alljoyn_core and it is not a blocking
			 * call in Unity.  This is a by product of the alljoyn_c deffered callback class
			 * and its usage.  I am still investigating ways to work around issues caused
			 * by the deffered callback class at some point in the future may start to work
			 * as alljoyn_core.
			 * Assert.Equal(AllJoyn.QStatus.BUS_BLOCKING_CALL_NOT_ALLOWED, callbackStatus);
			 */
			Assert.Equal(AllJoyn.QStatus.OK, callbackStatus);
			mbus.UnregisterBusListener(busListener);
			mbus.Stop();
			mbus.Join();
			mbus.Dispose();
		}
コード例 #8
0
		public void GetArgs()
		{
			//SetUp Service
			//start service BusAttachment
			AllJoyn.BusAttachment serviceBus = new AllJoyn.BusAttachment("MessageTestService", true);
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Start());
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Connect(AllJoynTestCommon.GetConnectSpec()));

			TestBusListener testBusListener = new TestBusListener(this);
			serviceBus.RegisterBusListener(testBusListener);

			//Create and activate the service Interface
			AllJoyn.InterfaceDescription testIntf = null;
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.CreateInterface(INTERFACE_NAME, out testIntf));
			Assert.NotNull(testIntf);
			Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out"));
			testIntf.Activate();

			//create and register BusObject
			MessageTestBusObject busObj = new MessageTestBusObject(OBJECT_PATH);
			busObj.AddInterface(testIntf);
			AllJoyn.InterfaceDescription.Member ping;
			ping = testIntf.GetMember("ping");
			Assert.NotNull(ping);

			Assert.Equal(AllJoyn.QStatus.OK, busObj.AddMethodHandler(ping, busObj.Ping));

			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RegisterBusObject(busObj));

			_nameOwnerChangedFlag = false;
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RequestName(WELLKNOWN_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting |
																					AllJoyn.DBus.NameFlags.DoNotQueue |
																					AllJoyn.DBus.NameFlags.AllowReplacement));
			Wait(TimeSpan.FromSeconds(2));
			Assert.True(_nameOwnerChangedFlag);


			//SetUp Client
			//start client BusAttachment
			AllJoyn.BusAttachment clientBus = new AllJoyn.BusAttachment("MessageTestClient", true);
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Start());
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Connect(AllJoynTestCommon.GetConnectSpec()));

			AllJoyn.ProxyBusObject proxyObj = new AllJoyn.ProxyBusObject(clientBus, WELLKNOWN_NAME, OBJECT_PATH, 0);

			Assert.Equal(AllJoyn.QStatus.OK, proxyObj.IntrospectRemoteObject());

			AllJoyn.Message reply = new AllJoyn.Message(clientBus);
			AllJoyn.MsgArg input = new AllJoyn.MsgArg("s", "AllJoyn");

			proxyObj.MethodCall(INTERFACE_NAME, "ping", input, reply, 25000, 0);

			//Actual tests for GetArg/GetArgs
			// call using GetArg specifying the array index
			Assert.Equal("AllJoyn", (string)reply.GetArg(0));
			// use the this[] operator call to get the MsgArg
			Assert.Equal("AllJoyn", (string)(reply[0]));
			// Return the MsgArgs note could be multiple values
			AllJoyn.MsgArg replyArg = reply.GetArgs();
			Assert.Equal(1, replyArg.Length);
			Assert.Equal("AllJoyn", (string)replyArg);
			// Parse the Message Drectly
			object replyString;
			Assert.Equal(AllJoyn.QStatus.OK, reply.GetArgs("s", out replyString));
			Assert.Equal("AllJoyn", (string)replyString);

			serviceBus.UnregisterBusListener(testBusListener);
			reply.Dispose();
			input.Dispose();
			proxyObj.Dispose();
			clientBus.Dispose();

			testBusListener.Dispose();
			busObj.Dispose();
			serviceBus.Dispose();
		}
コード例 #9
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();
		}
コード例 #10
0
		public void TestStopDisconnected()
		{
			// 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;
			busDisconnected = false;
			busStopping = false;

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

			// test disconnecting from the bus
			status = bus.Disconnect(AllJoynTestCommon.GetConnectSpec());
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Wait(MaxWaitTime);
			Assert.Equal(true, busDisconnected);

			// test stopping the bus
			status = bus.Stop();
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Wait(MaxWaitTime);
			Assert.Equal(true, busStopping);

			busListener.Dispose();
			bus.Dispose();
		}
コード例 #11
0
		public void TestNameOwnerChanged()
		{
			// 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;
			nameOwnerChanged = false;

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

			// test name owner changed
			status = bus.RequestName(ObjectName, 0);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			Wait(MaxWaitTime);
			Assert.Equal(true, nameOwnerChanged);

			busListener.Dispose();
			bus.Dispose();
		}
コード例 #12
0
		public void TestSessionJoined()
		{
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// create+start+connect bus attachment
			AllJoyn.BusAttachment servicebus = null;
			servicebus = new AllJoyn.BusAttachment("SessionTestService", true);
			Assert.NotNull(servicebus);

			status = servicebus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

			status = servicebus.Connect(AllJoynTestCommon.GetConnectSpec());
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// Create 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 = servicebus.BindSessionPort(ref sessionPort, opts, sessionPortListener);
			Assert.Equal(AllJoyn.QStatus.OK, status);

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

			// Advertise name
			status = servicebus.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
			AllJoyn.BusAttachment bus = null;
			bus = new AllJoyn.BusAttachment("SessionTest", true);
			Assert.NotNull(bus);

			status = bus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

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

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

			// find the advertised name from the "servicebus"
			status = bus.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 = bus.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);
			servicebus.ReleaseName(OBJECT_NAME);
			servicebus.Dispose();
			bus.Dispose();

		}
コード例 #13
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.");
            }
        }
コード例 #14
0
ファイル: Main.cs プロジェクト: hybridgroup/alljoyn
        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());
        }
コード例 #15
0
ファイル: BasicServer.cs プロジェクト: hybridgroup/alljoyn
        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");
        }
コード例 #16
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();
		}
コード例 #17
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");
        }
コード例 #18
0
ファイル: BasicClient.cs プロジェクト: hybridgroup/alljoyn
        public BasicClient()
        {
            clientText = "";
            clientText += "AllJoyn Library version: " + AllJoyn.GetVersion() +"\n";
            clientText += "AllJoyn Library buildInfo: " + AllJoyn.GetBuildInfo() + "\n";
            // 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)
            {

                clientText += "Client Interface Created.\n";
                Debug.Log("Client Interface Created.");
                testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "cat", "ss", "s", "inStr1,inStr2,outStr");
                testIntf.Activate();
            }
            else
            {
                clientText += "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 = sMsgBus.Start();
                if(status)
                {
                    clientText += "Client BusAttachment started.\n";
                    Debug.Log("Client BusAttachment started.");
                }
                else
                {
                    clientText += "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 = sMsgBus.Connect(connectArgs[i]);
                    if (status)
                    {
                        clientText += "BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED.\n";
                        Debug.Log("BusAttchement.Connect(" + connectArgs[i] + ") SUCCEDED.");
                        break;
                    }
                    else
                    {
                        clientText += "BusAttachment.Connect(" + connectArgs[i] + ") failed.\n";
                        Debug.Log("BusAttachment.Connect(" + connectArgs[i] + ") failed.");
                    }
                }
                if(!status)
                {
                    clientText += "BusAttachment.Connect failed.\n";
                    Debug.Log("BusAttachment.Connect failed.");
                }
            }

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

            if(status)
            {

                sMsgBus.RegisterBusListener(sBusListener);
                clientText += "Client BusListener Registered.\n";
                Debug.Log("Client BusListener Registered.");
            }

            // Begin discovery on the well-known name of the service to be called
            status = sMsgBus.FindAdvertisedName(SERVICE_NAME);
            if(!status)
            {

                clientText += "Client org.alljoyn.Bus.FindAdvertisedName failed.\n";
                Debug.Log("Client org.alljoyn.Bus.FindAdvertisedName failed.");
            }
        }
コード例 #19
0
		public void Properties()
		{
			//SetUp Service
			//start service BusAttachment
			AllJoyn.BusAttachment serviceBus = new AllJoyn.BusAttachment("MessageTestService", true);
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Start());
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.Connect(AllJoynTestCommon.GetConnectSpec()));

			TestBusListener testBusListener = new TestBusListener(this);
			serviceBus.RegisterBusListener(testBusListener);

			//Create and activate the service Interface
			AllJoyn.InterfaceDescription testIntf = null;
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.CreateInterface(INTERFACE_NAME, out testIntf));
			Assert.NotNull(testIntf);
			Assert.Equal(AllJoyn.QStatus.OK, testIntf.AddMember(AllJoyn.Message.Type.MethodCall, "ping", "s", "s", "in,out"));
			testIntf.Activate();

			//create and register BusObject
			MessageTestBusObject busObj = new MessageTestBusObject(OBJECT_PATH);
			busObj.AddInterface(testIntf);
			AllJoyn.InterfaceDescription.Member ping;
			ping = testIntf.GetMember("ping");
			Assert.NotNull(ping);

			Assert.Equal(AllJoyn.QStatus.OK, busObj.AddMethodHandler(ping, busObj.Ping));

			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RegisterBusObject(busObj));

			_nameOwnerChangedFlag = false;
			Assert.Equal(AllJoyn.QStatus.OK, serviceBus.RequestName(WELLKNOWN_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting |
																					AllJoyn.DBus.NameFlags.DoNotQueue |
																					AllJoyn.DBus.NameFlags.AllowReplacement));
			Wait(TimeSpan.FromSeconds(2));

			Assert.True(_nameOwnerChangedFlag);


			// SetUp Client
			// start client BusAttachment
			AllJoyn.BusAttachment clientBus = new AllJoyn.BusAttachment("MessageTestClient", true);
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Start());
			Assert.Equal(AllJoyn.QStatus.OK, clientBus.Connect(AllJoynTestCommon.GetConnectSpec()));

			AllJoyn.ProxyBusObject proxyObj = new AllJoyn.ProxyBusObject(clientBus, INTERFACE_NAME, OBJECT_PATH, 0);

			Assert.Equal(AllJoyn.QStatus.OK, proxyObj.IntrospectRemoteObject());

			AllJoyn.Message reply = new AllJoyn.Message(clientBus);
			AllJoyn.MsgArg input = new AllJoyn.MsgArg("s", "AllJoyn");

			proxyObj.MethodCall(INTERFACE_NAME, "ping", input, reply, 25000, 0);

			// Actual tests for GetArg/GetArgs
			// check the message properties
			Assert.False(reply.IsBroadcastSignal);
			Assert.False(reply.IsGlobalBroadcast);
			Assert.False(reply.IsSessionless);
			Assert.False(reply.IsExpired());
			uint timeLeft;
			reply.IsExpired(out timeLeft);
			Assert.True(timeLeft > 0);
			Assert.False(reply.IsUnreliable);
			Assert.False(reply.IsEncrypted);
			// we don't expect any flags
			Assert.Equal((byte)0, reply.Flags);
			// no security is being used so there should be no security mechanism
			Assert.Equal("", reply.AuthMechanism);
			Assert.Equal(AllJoyn.Message.Type.MethodReturn, reply.MessageType);
			// The serial is unknown before hand but it should not be zero
			Assert.NotEqual<uint>(0u, reply.CallSerial);
			Assert.NotEqual<uint>(0u, reply.ReplySerial);
			// A method return does not have an Object Path
			Assert.Equal("", reply.ObjectPath);
			// A method return does not have an interface specified
			Assert.Equal("", reply.Interface);
			// The member name is not specified on a message return
			Assert.Equal("", reply.MemberName);
			// TODO possible error the documentation for Sender states it should
			// be returning the well-known name however in this case it is
			// returning the unique name of the sender.
			Assert.Equal(serviceBus.UniqueName, reply.Sender);
			Assert.Equal(clientBus.UniqueName, reply.ReceiveEndPointName);
			Assert.Equal(clientBus.UniqueName, reply.Destination);
			Assert.Equal(0u, reply.CompressionToken);
			// no session set up for this test Session Id should be 0
			Assert.Equal(0u, reply.SessionId);
			String errorMsg;
			// TODO produce test that generates actual error Message
			Assert.Null(reply.GetErrorName(out errorMsg));
			Assert.Equal("", errorMsg);
			// The  ToString method only returns a string when running debug code
#if DEBUG
			Assert.True(reply.ToString().StartsWith("<message endianness="));
			Assert.True(reply.ToString().Contains("<header field=\"REPLY_SERIAL\">"));
			Assert.True(reply.ToString().Contains("<header field=\"DESTINATION\">"));
			Assert.True(reply.ToString().Contains("<header field=\"SENDER\">"));
			Assert.True(reply.ToString().Contains("<header field=\"SIGNATURE\">"));
			Assert.True(reply.ToString().Contains("<signature>s</signature>"));
			Assert.True(reply.ToString().Contains("<string>AllJoyn</string>"));
			Assert.True(reply.ToString().EndsWith("</message>"));

			// this call to description should return 'METHID_RET[<reply serial>](s)'
			Assert.True(reply.Description.StartsWith("METHOD_RET["));
#else
			Assert.Equal("", reply.ToString());
			Assert.Equal("", reply.Description);
#endif
			// TODO figure out a good way to test the TimeStamp property
			//reply.TimeStamp

			// CleanUp
			serviceBus.UnregisterBusListener(testBusListener);
			reply.Dispose();
			input.Dispose();
			proxyObj.Dispose();
			clientBus.Dispose();

			testBusListener.Dispose();
			busObj.Dispose();
			serviceBus.Dispose();
		}
コード例 #20
0
		public void EnableConcurrentCallbacks_Used()
		{
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;
			callbackStatus = AllJoyn.QStatus.FAIL;
			listenerRegisteredFlag = false;
			nameOwnerChangedFlag = false;

			mbus = new AllJoyn.BusAttachment("BusListenerTest", true);
			AllJoyn.BusListener busListener = new BusListenerEnableConcurrentCallbacks(this);

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

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

			mbus.RegisterBusListener(busListener);
			Wait(MaxWaitTime);
			Assert.True(listenerRegisteredFlag);

			mbus.RequestName(ObjectName, 0);
			Wait(MaxWaitTime);
			Assert.True(nameOwnerChangedFlag);
			Assert.Equal(AllJoyn.QStatus.OK, callbackStatus);

			mbus.UnregisterBusListener(busListener);
			mbus.Stop();
			mbus.Join();
			mbus.Dispose();
		}