예제 #1
0
        /// <summary>
        /// Initializes a new instance of the Client class.
        /// </summary>
        /// <param name="name">The name of the client application.</param>
        /// <param name="pinReady">The event to communicate there is a pin waiting.</param>
        public Client(string name, AutoResetEvent pinReady)
        {
            this.PinReady = pinReady;

            // Create the BusAttachment and other prep for accepting input from the client(s).
            this.ConnectBus = new Task(() =>
            {
                try
                {
                    this.InitializeAllJoyn(name);
                    App app = Windows.UI.Xaml.Application.Current as App;
                    app.Bus = this.Bus;
                }
                catch (Exception ex)
                {
                    const string ErrorFormat = "Bus intialization for client produced error(s). QStatus = 0x{0:X}.";
                    QStatus status           = AllJoynException.GetErrorCode(ex.HResult);
                    string error             = string.Format(ErrorFormat, status);

                    System.Diagnostics.Debug.WriteLine(error);
                    App.OutputLine(error);
                }
            });

            this.ConnectBus.Start();
        }
예제 #2
0
 /// <summary>
 /// Advertise the well known name 'name' for client to discover
 /// </summary>
 /// <param name="name">Well known name to advertise</param>
 /// <param name="transport">Transport type for which to advertise the name over</param>
 public void DoAdvertise(string name, TransportMaskType transport)
 {
     try
     {
         lock (this.requestedNames)
         {
             if (this.requestedNames.Contains(name))
             {
                 this.busAtt.AdvertiseName(name, transport);
                 lock (this.advertisedNames)
                 {
                     this.advertisedNames.Add(name);
                 }
             }
             else
             {
                 this.mainPage.Output(name + " must first be requested from the bus before it can be advertised");
             }
         }
     }
     catch (Exception ex)
     {
         var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         this.mainPage.Output("BusAttachment.AdvertiseName(" + name + ", " + (uint)transport + ") failed: " + errMsg);
     }
 }
예제 #3
0
        /// <summary>
        /// Initialize the AllJoyn portions of the application.
        /// </summary>
        private void InitializeAllJoyn()
        {
            Task t1 = new Task(() =>
            {
                try
                {
                    Debug.UseOSLogging(true);
                    //Debug.SetDebugLevel("ALL", 1);
                    //Debug.SetDebugLevel("ALLJOYN", 7);

                    bus = new BusAttachment(ApplicationName, true, 4);
                    bus.Start();

                    const string connectSpec = "null:";
                    bus.ConnectAsync(connectSpec).AsTask().Wait();
                    DisplayStatus("Connected to AllJoyn successfully.");

                    busListeners = new Listeners(bus, this);
                    bus.RegisterBusListener(busListeners);
                    chatService = new ChatSessionObject(bus, ObjectPath, this);
                    bus.RegisterBusObject(chatService);
                    bus.FindAdvertisedName(NamePrefix);
                }
                catch (Exception ex)
                {
                    QStatus stat  = AllJoynException.GetErrorCode(ex.HResult);
                    string errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                    DisplayStatus("InitializeAllJoyn Error : " + errMsg);
                }
            });

            t1.Start();
        }
예제 #4
0
        private void RxLoop()
        {
            Task rxLoopTask = new Task(() =>
            {
                try
                {
                    while (_running)
                    {
                        byte[] buf     = new byte[2048];
                        int[] received = new int[1];
                        // sockstream is blocking
                        _sockStream.Recv(buf, buf.Length, received);
                        if (received[0] >= 0)
                        {
                            _rxCount += received[0];
                            // TODO write to file
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    var m = AllJoynException.GetErrorMessage(e.HResult);
                    var h = AllJoynException.GetErrorCode(e.HResult);
                }
            });

            rxLoopTask.Start();
        }
예제 #5
0
        /// <summary>
        /// Run the default stress op which stresses the bus attachment
        /// </summary>
        private void RunDefault()
        {
            try
            {
                BusListener busListener = new BusListener(this.busAtt);
                this.busAtt.RegisterBusListener(busListener);
                BusObject busObject = new BusObject(this.busAtt, "/default", false);
                this.busAtt.RegisterBusObject(busObject);
                this.DebugPrint("Registered BusListener and BusObject");

                uint   flags           = (uint)(RequestNameType.DBUS_NAME_REPLACE_EXISTING | RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
                string randServiceName = null;
                lock (rand)
                {
                    randServiceName = ServiceName + ".n" + rand.Next(10000000);
                }

                this.busAtt.RequestName(randServiceName, flags);
                this.busAtt.AdvertiseName(randServiceName, TransportMaskType.TRANSPORT_ANY);
                this.DebugPrint("Advertising WKN : " + randServiceName);

                this.busAtt.CancelAdvertiseName(randServiceName, TransportMaskType.TRANSPORT_ANY);
                this.busAtt.ReleaseName(randServiceName);
                this.busAtt.UnregisterBusListener(busListener);
                this.busAtt.UnregisterBusObject(busObject);
                this.DebugPrint("Successfully unraveled the default operation");
            }
            catch (Exception ex)
            {
                var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                this.DebugPrint(">>>> Default Execution Error >>>> : " + errMsg);
            }
        }
예제 #6
0
        async void InitializeAllJoyn()
        {
            Debug.UseOSLogging(true);
            Debug.SetDebugLevel("ALLJOYN", 7);

            _bus = new BusAttachment(APPLICATION_NAME, true, 4);
            string connectSpec = "null:";

            _bus.Start();

            try
            {
                _mp3Reader = new MP3Reader();

                if (_streamingSong != null)
                {
                    _streamingSongBasicProperties = await _streamingSong.GetBasicPropertiesAsync();

                    if (_streamingSongBasicProperties != null)
                    {
                        _streamingSongMusicProperties = await _streamingSong.Properties.GetMusicPropertiesAsync();

                        if (_streamingSongMusicProperties != null)
                        {
                            await _mp3Reader.SetFileAsync(_streamingSong);

                            _bus.ConnectAsync(connectSpec).AsTask().Wait();
                            _connected = true;

                            _listeners = new Listeners(_bus, this);
                            _bus.RegisterBusListener(_listeners);
                            _mediaSource = new MediaSource(_bus);
                            _audioStream = new AudioStream(_bus, "mp3", _mp3Reader, 100, 1000);
                            _mediaSource.AddStream(_audioStream);

                            /* Register MediaServer bus object */
                            _bus.RegisterBusObject(_mediaSource.MediaSourceBusObject);
                            /* Request a well known name */
                            _bus.RequestName(MediaServerName, (int)(RequestNameType.DBUS_NAME_REPLACE_EXISTING | RequestNameType.DBUS_NAME_DO_NOT_QUEUE));

                            /* Advertise name */
                            _bus.AdvertiseName(MediaServerName, TransportMaskType.TRANSPORT_ANY);

                            /* Bind a session for incoming client connections */
                            SessionOpts opts    = new SessionOpts(TrafficType.TRAFFIC_MESSAGES, true, ProximityType.PROXIMITY_ANY, TransportMaskType.TRANSPORT_ANY);
                            ushort[]    portOut = new ushort[1];
                            _bus.BindSessionPort(SESSION_PORT, portOut, opts, _listeners);
                        }
                    }
                }
            } catch (Exception ex)
            {
                string  message = ex.Message;
                QStatus status  = AllJoynException.GetErrorCode(ex.HResult);
                string  errMsg  = AllJoynException.GetErrorMessage(ex.HResult);
            }
        }
예제 #7
0
        /// <summary>
        /// connects with the bus, creates an interface and advertises a well-known name for
        /// clients to join a session with.
        /// </summary>
        /// <param name="sender">UI control which signaled the click event.</param>
        /// <param name="e">arguments associated with the click event.</param>
        private void Button_RunClick(object sender, RoutedEventArgs e)
        {
            if (busObject == null && busAtt == null)
            {
                Task task = new Task(async() =>
                {
                    try
                    {
                        busAtt = new BusAttachment("SignalServiceApp", true, 4);

                        busObject = new SignalServiceBusObject(busAtt);
                        OutputLine("BusObject Created.");

                        busListener = new SignalServiceBusListener(busAtt);
                        OutputLine("BusAttachment and BusListener Created.");
                        busAtt.RegisterBusListener(busListener);
                        OutputLine("BusListener Registered.");

                        busAtt.Start();
                        await busAtt.ConnectAsync(SignalServiceGlobals.ConnectSpec);
                        OutputLine("Bundled Daemon Registered.");
                        OutputLine("BusAttachment Connected to " + SignalServiceGlobals.ConnectSpec + ".");

                        SessionOpts sessionOpts = new SessionOpts(
                            SignalServiceGlobals.SessionProps.TrType,
                            SignalServiceGlobals.SessionProps.IsMultiPoint,
                            SignalServiceGlobals.SessionProps.PrType,
                            SignalServiceGlobals.SessionProps.TmType);
                        try
                        {
                            ushort[] portOut = new ushort[1];
                            busAtt.BindSessionPort(SignalServiceGlobals.SessionProps.SessionPort, portOut, sessionOpts, busListener);

                            busAtt.RequestName(SignalServiceGlobals.WellKnownServiceName, (int)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);

                            busAtt.AdvertiseName(SignalServiceGlobals.WellKnownServiceName, TransportMaskType.TRANSPORT_ANY);
                            OutputLine("Name is Being Advertised as: " + SignalServiceGlobals.WellKnownServiceName);
                        }
                        catch (COMException ce)
                        {
                            QStatus s = AllJoynException.GetErrorCode(ce.HResult);
                            OutputLine("Errors were produced while establishing the service.");
                            TearDown();
                        }
                    }
                    catch (Exception ex)
                    {
                        OutputLine("Errors occurred while setting up the service.");
                        QStatus status = AllJoynException.GetErrorCode(ex.HResult);
                        busObject      = null;
                        busAtt         = null;
                    }
                });
                task.Start();
            }
        }
예제 #8
0
 /// <summary>
 /// Set the specified AllJoyn module to the specified level
 /// </summary>
 /// <param name="moduleName">AllJoyn module name</param>
 /// <param name="level">Debug level</param>
 public void DoDebug(string moduleName, uint level)
 {
     try
     {
         AllJoyn.Debug.SetDebugLevel(moduleName.ToUpper(), level);
     }
     catch (Exception ex)
     {
         var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         this.mainPage.Output("AllJoyn.Debug.SetDebugLevel(" + moduleName + ", " + level + ") failed: " + errMsg);
     }
 }
예제 #9
0
 /// <summary>
 /// Cancel the previously started find advertised name action of namePrefix
 /// </summary>
 /// <param name="namePrefix">Name prefix of advertised name</param>
 public void DoCancelFind(string namePrefix)
 {
     try
     {
         this.busAtt.CancelFindAdvertisedName(namePrefix);
     }
     catch (Exception ex)
     {
         var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         this.mainPage.Output("BusAttachment.CancelFindAdvertisedName(" + namePrefix + ") failed: " + errMsg);
     }
 }
예제 #10
0
 /// <summary>
 /// Sends a 'Chat' signal using the specified parameters
 /// </summary>
 /// <param name="filter">filter to use </param>
 public void AddRule(string filter)
 {
     try
     {
         this.busObject.Bus.AddMatch(filter);
     }
     catch (Exception ex)
     {
         QStatus status = AllJoynException.GetErrorCode(ex.HResult);
         string  errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         this.sessionOps.Output("adding a rule failed: " + errMsg);
     }
 }
예제 #11
0
 /// <summary>
 /// Sends a 'Chat' signal using the specified parameters
 /// </summary>
 /// <param name="sessionId">A unique SessionId used to contain the signal</param>
 /// <param name="msg">Message that will be sent over the 'Chat' signal</param>
 /// <param name="flags">Flags for the signal</param>
 /// <param name="ttl">Time To Live for the signal</param>
 public void SendChatSignal(uint sessionId, string msg, byte flags, ushort ttl)
 {
     try
     {
         MsgArg msgArg = new MsgArg("s", new object[] { msg });
         this.busObject.Signal(string.Empty, sessionId, this.chatSignal, new MsgArg[] { msgArg }, ttl, flags);
     }
     catch (Exception ex)
     {
         var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         this.sessionOps.Output("Sending Chat Signal failed: " + errMsg);
     }
 }
예제 #12
0
        /// <summary>
        /// Run the service stress op which stresses the bus attachment in a service type
        /// configuration by advertising a well known name which an implementation of the
        /// 'cat' method
        /// </summary>
        /// <param name="isMultipoint">True if operation uses multipoint sessions</param>
        private void RunService(bool isMultipoint)
        {
            try
            {
                ServiceBusListener serviceBusListener = new ServiceBusListener(this.busAtt, this);
                ServiceBusObject   serviceBusObject   = new ServiceBusObject(this.busAtt, this);
                this.DebugPrint("Registered the Service BusListener and BusObject");

                uint   flags           = (uint)(RequestNameType.DBUS_NAME_REPLACE_EXISTING | RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
                string randServiceName = null;
                lock (rand)
                {
                    randServiceName = ServiceName + ".n" + rand.Next(10000000);
                }

                this.busAtt.RequestName(randServiceName, flags);

                SessionOpts optsIn = new SessionOpts(
                    TrafficType.TRAFFIC_MESSAGES,
                    isMultipoint,
                    ProximityType.PROXIMITY_ANY,
                    TransportMaskType.TRANSPORT_ANY);
                ushort[] portOut = new ushort[1];
                this.busAtt.BindSessionPort(ServicePort, portOut, optsIn, (SessionPortListener)serviceBusListener);

                this.busAtt.AdvertiseName(randServiceName, TransportMaskType.TRANSPORT_ANY);
                this.DebugPrint("Advertising WKN : " + randServiceName);

                int wait = 0;
                lock (rand)
                {
                    wait = 8000 + rand.Next(6000);
                }

                Task.Delay(wait).AsAsyncAction().AsTask().Wait();

                this.DebugPrint("Unraveling the service opertaion");
                this.busAtt.CancelAdvertiseName(randServiceName, TransportMaskType.TRANSPORT_ANY);
                this.busAtt.UnbindSessionPort(ServicePort);
                this.busAtt.ReleaseName(randServiceName);
                this.busAtt.UnregisterBusObject((BusObject)serviceBusObject);
                this.busAtt.UnregisterBusListener((BusListener)serviceBusListener);
                this.DebugPrint("Successfully unraveled the service opertaion");
            }
            catch (Exception ex)
            {
                var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                this.DebugPrint(">>>> Service Exectution Execution Error >>>> : " + errMsg);
            }
        }
예제 #13
0
 /// <summary>
 /// This method sends the current message to the chat service for delivery to the remote device.
 /// </summary>
 /// <param name="id">The session ID associated with this message.</param>
 /// <param name="message">The actual message being sent.</param>
 private void SendMyMessage(uint id, string message)
 {
     try
     {
         this.OnChat(this.SessionId, "Me : ", message);
         this.chatService.SendChatSignal(this.SessionId, message);
         this.MessageBox.Text = string.Empty;
     }
     catch (Exception ex)
     {
         QStatus stat   = AllJoynException.GetErrorCode(ex.HResult);
         string  errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         DisplayStatus("SendMessage Error : " + errMsg);
     }
 }
예제 #14
0
 /// <summary>
 /// Request the well known name 'name' from the bus
 /// </summary>
 /// <param name="name">Well known name to request</param>
 public void DoRequestName(string name)
 {
     try
     {
         this.busAtt.RequestName(name, (uint)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
         lock (this.requestedNames)
         {
             this.requestedNames.Add(name);
         }
     }
     catch (Exception ex)
     {
         var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         this.mainPage.Output("BusAttachment.RequestName(" + name + ") failed: " + errMsg);
     }
 }
예제 #15
0
 /// <summary>
 /// Unbind the session port previously bound
 /// </summary>
 /// <param name="port">Bound session port number</param>
 public void DoUnbind(uint port)
 {
     try
     {
         this.busAtt.UnbindSessionPort((ushort)port);
         lock (this.sessionPortMap)
         {
             this.sessionPortMap.Remove(port);
         }
     }
     catch (Exception ex)
     {
         var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         this.mainPage.Output("BusAttachment.UnbindSessionPort(" + port + ") failed: " + errMsg);
     }
 }
예제 #16
0
            public void SayHiHandler(InterfaceMember member, Message message)
            {
                Assert.AreEqual("hello", message.GetArg(0).Value.ToString());
                MsgArg retArg = new MsgArg("s", new object[] { "aloha" });

                try
                {
                    // BUGBUG: Throws exception saying signature of the msgArg is not what was expected, but its correct.
                    this.busObject.MethodReplyWithQStatus(message, QStatus.ER_OK);
                }
                catch (Exception ex)
                {
                    string err = AllJoynException.GetExceptionMessage(ex.HResult);
                    Assert.IsFalse(true);
                }
            }
예제 #17
0
        /// <summary>
        /// Leave the currently active chat session.
        /// </summary>
        private void LeaveChannel()
        {
            try
            {
                this.bus.LeaveSession(this.SessionId);
                this.DisplayStatus("Leave chat session " + this.SessionId + " successfully");
            }
            catch (Exception ex)
            {
                QStatus stat   = AllJoynException.GetErrorCode(ex.HResult);
                string  errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                this.DisplayStatus("Leave chat session " + this.SessionId + " failed: " + errMsg);
            }

            this.SessionId = 0;
        }
예제 #18
0
 /// <summary>
 /// Release well known name previously obtained through request name call
 /// </summary>
 /// <param name="name">Well Known name to release</param>
 public void DoReleaseName(string name)
 {
     try
     {
         this.busAtt.ReleaseName(name);
         lock (this.requestedNames)
         {
             this.requestedNames.Remove(name);
         }
     }
     catch (Exception ex)
     {
         var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         this.mainPage.Output("BusAttachment.ReleaseName(" + name + ") failed: " + errMsg);
     }
 }
예제 #19
0
 /// <summary>
 /// Concatenate the two string arguments and return the result to the caller
 /// </summary>
 /// <param name="member">Method interface member entry.</param>
 /// <param name="message">The received method call message containing the two strings
 /// to concatenate</param>
 public void Cat(InterfaceMember member, Message message)
 {
     try
     {
         string arg1   = message.GetArg(0).Value as string;
         string arg2   = message.GetArg(1).Value as string;
         MsgArg retArg = new MsgArg("s", new object[] { arg1 + arg2 });
         this.busObject.MethodReply(message, new MsgArg[] { retArg });
         this.DebugPrint("Method Reply successful (ret=" + arg1 + arg2 + ")");
     }
     catch (Exception ex)
     {
         var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         this.DebugPrint("Method Reply unsuccessful: " + errMsg);
     }
 }
예제 #20
0
        /// <summary>
        /// Do the work of joining a session.
        /// </summary>
        /// <param name="folder">The folder to put the received file in.</param>
        /// <returns>true if all the input variables look good.</returns>
        public bool StartJoinSessionTask(StorageFolder folder)
        {
            bool returnValue = false;

            this.Folder = folder;

            if (null != this.Bus && null != this.Folder)
            {
                Task task = new Task(async() =>
                {
                    try
                    {
                        if (0 != this.SessionId)
                        {
                            this.Bus.LeaveSession(this.SessionId);
                        }

                        this.lastIndex = 0;
                        this.CreateInterfaceAndBusObject();
                        this.AddSignalHandler();

                        // We found a remote bus that is advertising the well-known name so connect to it.
                        bool result = await this.JoinSessionAsync();

                        if (result)
                        {
                            App.OutputLine("Successfully joined session.");
                        }
                    }
                    catch (Exception ex)
                    {
                        QStatus status = AllJoynException.GetErrorCode(ex.HResult);
                        string message = string.Format(
                            "Errors were produced while establishing the application '{0}' (0x{0:X}).",
                            status.ToString(),
                            status);
                        App.OutputLine(message);
                    }
                });

                task.Start();

                returnValue = true;
            }

            return(returnValue);
        }
예제 #21
0
 /// <summary>
 /// Bind the session port
 /// </summary>
 /// <param name="port">Port number to bind</param>
 /// <param name="opts">Session options for binding the port</param>
 public void DoBind(uint port, SessionOpts opts)
 {
     try
     {
         ushort[] sessionPortOut = new ushort[1];
         this.busAtt.BindSessionPort((ushort)port, sessionPortOut, opts, (SessionPortListener)this.busListener);
         lock (this.sessionPortMap)
         {
             this.sessionPortMap.Add(port, new SessionPortInfo(port, this.busAtt.UniqueName, opts));
         }
     }
     catch (Exception ex)
     {
         var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         this.mainPage.Output("BusAttachment.BindSessionPort for port " + port + " failed: " + errMsg);
     }
 }
예제 #22
0
        /// <summary>
        /// Shut down the hosted channel.
        /// </summary>
        private void StopChannel()
        {
            try
            {
                var wellKnownName = this.MakeWellKnownName(this.channelHosted);
                this.bus.CancelAdvertiseName(wellKnownName, alljoynTransports);
                this.bus.UnbindSessionPort(ContactPort);
                this.bus.ReleaseName(wellKnownName);
                this.Channels.Remove(this.channelHosted);

                this.channelHosted = null;
            }
            catch (Exception ex)
            {
                QStatus stat   = AllJoynException.GetErrorCode(ex.HResult);
                string  errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                DisplayStatus("StopChannel Error : " + errMsg);
            }
        }
예제 #23
0
        /// <summary>
        /// Add the session details to the session port and session maps
        /// </summary>
        /// <param name="port">Port used by the session</param>
        /// <param name="sessionId">Session Id for the joined session</param>
        /// <param name="joiner">Device/Endpoint joining the session</param>
        public void SessionJoined(ushort port, uint sessionId, string joiner)
        {
            lock (this.sessionPortMap)
            {
                if (this.sessionPortMap.ContainsKey(port))
                {
                    try
                    {
                        this.busAtt.SetSessionListener(sessionId, (SessionListener)this.busListener);
                    }
                    catch (Exception ex)
                    {
                        var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                        this.mainPage.Output("BusAttachment.SetSessionListener(" + sessionId + ", ...) failed: " + errMsg);
                    }

                    lock (this.sessionMap)
                    {
                        if (!this.sessionMap.ContainsKey(sessionId))
                        {
                            this.sessionMap.Add(sessionId, new SessionInfo(sessionId, this.sessionPortMap[port]));
                        }

                        this.sessionMap[sessionId].AddPeer(joiner);
                    }

                    this.mainPage.Output("SessionJoined with " + joiner + " (sessionId=" + sessionId + ")");
                }
                else
                {
                    this.mainPage.Output("Leaving unexpected session " + sessionId + " with " + joiner);
                    try
                    {
                        this.busAtt.LeaveSession(sessionId);
                    }
                    catch (Exception ex)
                    {
                        var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                        this.mainPage.Output("BusAttachment.LeaveSession(" + sessionId + ") failed: " + errMsg);
                    }
                }
            }
        }
예제 #24
0
        /// <summary>
        /// Run the stress operation by setting up alljoyn, running the specified stress
        /// operation then tearing down alljoyn.
        /// </summary>
        /// <param name="stressType">Type of stress operation to run</param>
        /// <param name="manager">Stress manager which is managing this task</param>
        /// <param name="isMultipoint">True if operation uses multipoint sessions</param>
        public void Start(StressType stressType, StressManager manager, bool isMultipoint)
        {
            this.stressManager = manager;

            try
            {
                // Set up alljoyn
                this.DebugPrint("Creating and Starting the bus attachment");
                this.busAtt = new BusAttachment("BusStress", true, 4);
                this.busAtt.Start();
                this.busAtt.ConnectAsync(ConnectSpecs).AsTask().Wait();
                this.DebugPrint("Successfully connected to the bundled daemon");

                // Run the stress operation
                if (stressType == StressType.Default)
                {
                    this.RunDefault();
                }
                else if (stressType == StressType.Service)
                {
                    this.RunService(isMultipoint);
                }
                else
                {
                    this.foundName = new AutoResetEvent(false);
                    this.RunClient(isMultipoint);
                }

                // Tear down alljoyn
                this.DebugPrint("Disconnecting and stopping the bus attachment");
                this.busAtt.DisconnectAsync(ConnectSpecs).AsTask().Wait();
                this.busAtt.StopAsync().AsTask().Wait();
                this.DebugPrint("Successfully disconnected and stopped the bus attachment");
            }
            catch (Exception ex)
            {
                var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                this.DebugPrint(">>>> BusAttachment Error >>>> : " + errMsg);
            }

            this.busAtt = null;
        }
예제 #25
0
 /// <summary>
 /// Start up the channel we are hosting.
 /// </summary>
 /// <param name="name">The name, minus the name prefix, for the channel we are hosting.</param>
 private void StartChannel(string name)
 {
     try
     {
         this.channelHosted = name;
         string wellKnownName = this.MakeWellKnownName(name);
         this.bus.RequestName(wellKnownName, (int)RequestNameType.DBUS_NAME_DO_NOT_QUEUE);
         this.bus.AdvertiseName(wellKnownName, alljoynTransports);
         ushort[]    portOut = new ushort[1];
         SessionOpts opts    = new SessionOpts(TrafficType.TRAFFIC_MESSAGES, true, ProximityType.PROXIMITY_ANY, alljoynTransports);
         this.bus.BindSessionPort(ContactPort, portOut, opts, this.busListeners);
         DisplayStatus("Start Chat channel " + name + " successfully");
     }
     catch (Exception ex)
     {
         QStatus stat   = AllJoynException.GetErrorCode(ex.HResult);
         string  errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         DisplayStatus("StartChannel Error : " + errMsg);
     }
 }
예제 #26
0
 /// <summary>
 /// Cancel advertising the well known name 'name'
 /// </summary>
 /// <param name="name">Well known name currently being advertised</param>
 /// <param name="transport">Transport type which 'name' is being advertised over</param>
 public void DoCancelAdvertise(string name, TransportMaskType transport)
 {
     try
     {
         lock (this.advertisedNames)
         {
             if (this.advertisedNames.Contains(name))
             {
                 this.busAtt.CancelAdvertiseName(name, transport);
                 this.advertisedNames.Remove(name);
             }
             else
             {
                 this.mainPage.Output(name + " is not currently being advertised");
             }
         }
     }
     catch (Exception ex)
     {
         var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
         this.mainPage.Output("BusAttachment.CancelAdvertiseName(" + name + ", " + (uint)transport + ") failed: " + errMsg);
     }
 }
예제 #27
0
        /// <summary>
        /// Join an existing channel with the given name.
        /// </summary>
        /// <param name="name">The name of the channel to join.</param>
        private async void JoinChannel(string name)
        {
            try
            {
                this.DisplayStatus("Joining chat session: " + name);
                string        wellKnownName = this.MakeWellKnownName(name);
                SessionOpts   opts          = new SessionOpts(TrafficType.TRAFFIC_MESSAGES, true, ProximityType.PROXIMITY_ANY, alljoynTransports);
                SessionOpts[] opts_out      = new SessionOpts[1];
                this.channelJoined = name;
                JoinSessionResult result = await this.bus.JoinSessionAsync(
                    wellKnownName,
                    ContactPort,
                    this.busListeners,
                    opts,
                    opts_out,
                    null);

                if (result.Status == QStatus.ER_OK)
                {
                    this.SessionId = result.SessionId;
                    this.DisplayStatus("Join chat session " + this.SessionId + " successfully");
                    await this.coreDispatcher.RunAsync(
                        CoreDispatcherPriority.Normal,
                        () => { this.JoinChannelButton.Content = "Leave Channel"; });
                }
                else
                {
                    this.DisplayStatus("Join chat session " + result.SessionId + " failed. Error: " + result.Status);
                }
            }
            catch (Exception ex)
            {
                QStatus stat   = AllJoynException.GetErrorCode(ex.HResult);
                string  errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                DisplayStatus("JoinChannel Error : " + errMsg);
            }
        }
예제 #28
0
        private void InitializeAllJoyn()
        {
            Task _t1 = new Task(() =>
            {
                Debug.UseOSLogging(true);
                //Debug.SetDebugLevel("ALLJOYN", 7);

                string connectSpec = "null:";

                try
                {
                    _bus = new BusAttachment(APPLICATION_NAME, true, 4);
                }
                catch (Exception ex)
                {
                    QStatus stat = AllJoynException.GetErrorCode(ex.HResult);
                }
                _bus.Start();

                _bus.ConnectAsync(connectSpec).AsTask().Wait();

                _listeners = new Listeners(_bus, this);
                _bus.RegisterBusListener(_listeners);

                _mediaSink            = new MediaSink(_bus);
                _mediaRender          = new MediaRenderer();
                _mediaRender.OnOpen  += OnOpen;
                _mediaRender.OnPlay  += OnPlay;
                _mediaRender.OnPause += OnPause;
                _mediaRender.OnClose += OnClose;

                _bus.FindAdvertisedName(MEDIA_SERVER_NAME);
            });

            _t1.Start();
        }
예제 #29
0
        /// <summary>
        /// Leave the session with specified session id
        /// </summary>
        /// <param name="sessionId">Session Id of session to leave</param>
        public void DoLeave(uint sessionId)
        {
            lock (this.sessionMap)
            {
                if (this.sessionMap.ContainsKey(sessionId))
                {
                    try
                    {
                        this.busAtt.LeaveSession(sessionId);
                    }
                    catch (Exception ex)
                    {
                        var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                        this.mainPage.Output("Leave Session was unsuccessful: " + errMsg);
                    }

                    this.sessionMap.Remove(sessionId);
                }
                else
                {
                    this.mainPage.Output("Session Id doesn't exist in currently joined sessions");
                }
            }
        }
예제 #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SessionOperations"/> class. Creates and registers
        /// the bus attachment, bus listener, bus object and interface for the application then establishes
        /// the alljoyn tcp connection.
        /// </summary>
        /// <param name="mp">Main page for the application</param>
        public SessionOperations(MainPage mp)
        {
            Task task = new Task(async() =>
            {
                try
                {
                    this.mainPage = mp;

                    this.busAtt      = new BusAttachment("Sessions", true, 4);
                    this.busObject   = new MyBusObject(this.busAtt, this);
                    this.busListener = new MyBusListener(this.busAtt, this);

                    this.busAtt.Start();
                    await this.busAtt.ConnectAsync(ConnectSpecs);
                }
                catch (Exception ex)
                {
                    var errMsg = AllJoynException.GetErrorMessage(ex.HResult);
                    this.mainPage.Output("Couldn't connect to AllJoyn: " + errMsg);
                }
            });

            task.Start();
        }