Exemple #1
0
        public void StartStopBusAttachment()
        {
            var bus = new BusAttachment("ServiceTest", true);

            Assert.IsFalse(bus.IsStarted);
            Assert.IsFalse(bus.IsConnected);

            bus.Start();
            Assert.IsTrue(bus.IsStarted);
            Assert.IsFalse(bus.IsConnected);

            bus.Connect();
            Assert.IsTrue(bus.IsConnected);
            Assert.IsFalse(bus.IsStopping);

            Assert.IsFalse(string.IsNullOrEmpty(bus.UniqueName));

            bus.Stop();
            Assert.IsTrue(bus.IsStopping);
            Assert.IsTrue(bus.IsStarted);

            bus.Join();
            Assert.IsFalse(bus.IsStarted);
            Assert.IsFalse(bus.IsConnected);

            bus.Dispose();
        }
        private async Task StartClient()
        {
            // Create the bus attachment
            clientBus = new BusAttachment("AboutServiceTest", true);

            clientBus.Start();
            Log.WriteLine("BusAttachment started");
            clientBus.Connect();
            Log.WriteLine("BusAttachment connect succeeded. BusName: " + clientBus.UniqueName);

            clientBus.AboutAnnounced += Result_AboutAnnounced;

            string[] interfaces = new[] { INTERFACE_NAME };
            //string[] interfaces = new string[] {/* "org.alljoyn.About" */ };
            clientBus.WhoImplementsInterfaces(interfaces);
            Log.WriteLine("WhoImplements called.");
            Log.LogBreak();

            while (!cancelSource.IsCancellationRequested)
            {
                await Task.Delay(10);
            }
        }
Exemple #3
0
        public void Start()
        {
            // Create the bus attachment
            bus = new BusAttachment("ServiceTest", true);
            bus.Start();
            Log.WriteLine("BusAttachment started");
            bus.Connect();
            Log.WriteLine("BusAttachment connect succeeded. BusName: " + bus.UniqueName);
            //Create interface
            string interfaceName = "org.test.a1234.AnnounceHandlerTest";
            string interfaceQcc  = "<node>" +
                                   $"<interface name='{interfaceName}'>" +
                                   "  <method name='Foo'>" +
                                   "  </method>" +
                                   "</interface>" +
                                   "</node>";

            bus.CreateInterfacesFromXml(interfaceQcc);
            //Test if the interface is there
            var iface  = bus.GetInterface(interfaceName);
            var secure = iface.IsSecure;
            var name   = iface.Name;
        }
        private async Task StartService()
        {
            serviceBus = new BusAttachment("About Service Example", true);
            serviceBus.Start();
            serviceBus.Connect();
            Log.WriteLine($"BusAttachment connect succeeded. BusName {serviceBus.UniqueName}");
            Session sessionOpts = new Session(TrafficType.Messages, false, Proximity.Any, Transport.Any);

            sessionPortListener = new SessionPortListener();
            sessionPortListener.AcceptSessionJoiner += SessionPortListener_AcceptSessionJoiner;
            sessionPortListener.SessionJoined       += SessionPortListener_SessionJoined;
            var sessionPort = ASSIGNED_SESSION_PORT;

            serviceBus.BindSessionPort(sessionPort, sessionOpts, sessionPortListener);

            var aboutData = new AboutData("en");

            byte[] appId = { 0x01, 0xB3, 0xBA, 0x14,
                             0x1E, 0x82, 0x11, 0xE4,
                             0x86, 0x51, 0xD1, 0x56,
                             0x1D, 0x5D, 0x46, 0xB0 };
            aboutData.AppId = appId;
            aboutData.SetDeviceName("My Device Name", "en");
            aboutData.DeviceId = "93c06771-c725-48c2-b1ff-6a2a59d445b8";
            aboutData.SetAppName("Application", "en");
            aboutData.SetManufacturer("Manufacturer2", "en");
            aboutData.ModelNumber = "123456";
            aboutData.SetDescription("A poetic description of this application", "en");
            aboutData.DateOfManufacture = "2014-03-24";
            aboutData.SoftwareVersion   = "0.1.2";
            aboutData.HardwareVersion   = "0.0.1";
            aboutData.SupportUrl        = "http://www.example.org";

            /*
             * The default language is automatically added to the `SupportedLanguages`
             * Users don't have to specify the AJSoftwareVersion its automatically added
             * to the AboutData/
             * Adding Spanish Localization values to the AboutData. All strings MUST be
             * UTF-8 encoded.
             */
            aboutData.SetDeviceName("Mi dispositivo Nombre", "es");
            aboutData.SetAppName("aplicación", "es");
            aboutData.SetManufacturer("fabricante", "es");
            aboutData.SetDescription("Una descripción poética de esta aplicación", "es");
            if (!aboutData.IsValid("en"))
            {
                Log.WriteLine("failed to setup about data.");
            }

            string xmlInterface = "<node>\n" +
                                  $"<interface name='{INTERFACE_NAME}'>\n" +
                                  "  <method name='Echo'>\n" +
                                  "    <arg name='out_arg' type='s' direction='in' />\n" +
                                  "    <arg name='return_arg' type='s' direction='out' />\n" +
                                  "  </method>\n" +
                                  "</interface>\n" +
                                  "</node>";

            Log.WriteLine(xmlInterface);
            serviceBus.CreateInterfacesFromXml(xmlInterface);
            busObject = create_my_alljoyn_busobject(serviceBus, "/example/path");
            serviceBus.RegisterBusObject(busObject);
            var aboutObj = new AboutObj(serviceBus, false);

            aboutObj.Announce(sessionPort, aboutData);
            Log.WriteLine("AboutObj Announce Succeeded.");
            Log.WriteLine("*********************************************************************************");
            Log.WriteLine("*********************************************************************************");

            while (!cancelSource.IsCancellationRequested)
            {
                await Task.Delay(10);
            }
        }