Ejemplo n.º 1
0
        public void Start()
        {
            _busListener = new Listener();
            _sessionListener = new SessionListener();

            _busAttachment = new AllJoynUnity.AllJoyn.BusAttachment(_description.ApplicationName, true);
            _busAttachment.RegisterBusListener(_busListener);

            if (_busAttachment.Start())
            {
                if (_busAttachment.Connect(_description.ConnectionSpecification))
                {
                    var status = _busAttachment.RequestName(_description.ServiceName, AllJoynUnity.AllJoyn.DBus.NameFlags.DoNotQueue);

                    if (status)
                    {
                        AllJoynUnity.AllJoyn.SessionOpts options = new AllJoynUnity.AllJoyn.SessionOpts(AllJoynUnity.AllJoyn.SessionOpts.TrafficType.Messages, false, AllJoynUnity.AllJoyn.SessionOpts.ProximityType.Any, AllJoynUnity.AllJoyn.TransportMask.Any);

                        ushort sessionPort = _description.ServicePort;

                        status = _busAttachment.BindSessionPort(ref sessionPort, options, _sessionListener);

                        if (status)
                        {
                            status = _busAttachment.AdvertiseName(_description.ServiceName, options.Transports);

                            if (!status)
                            {
                                throw new ApplicationException(string.Format("Could not advertise service name '{0}'. Error: '{1}'", _description.ServiceName, status));
                            }
                        }
                        else
                        {
                            throw new ApplicationException(string.Format("Could not bind AllJoyn session port. Error: '{0}'", status));
                        }
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("Could not secure requested name '{0}'. Error: '{1}'", _description.ServiceName, status));
                    }
                }
                else
                {
                    throw new ApplicationException("Could not connect the AllJoyn BusAttachment");
                }
            }
            else
            {
                throw new ApplicationException("Could not start AllJoyn BusAttachment");
            }
        }