Exemple #1
0
        /// <summary>
        /// Initializes the global bus attachment
        /// </summary>
        private void InitializeAllJoyn()
        {
            InterfaceDescription[] iface = new InterfaceDescription[1];

            this.Bus = new BusAttachment("SRPSecurityServiceA", true, 4);

            this.Bus.CreateInterface(App.InterfaceName, iface, true);
            iface[0].AddMethod("Ping", "s", "s", "inStr,outStr", 0, string.Empty);
            iface[0].Activate();

            this.BusObject = new SecureBusObject(this.Bus, iface);

            this.Listeners = new Listeners(this.Bus);
            this.Listeners.NameOwnerChange     += this.NameOwnerChanged;
            this.Listeners.AcceptSessionJoiner += this.AcceptSessionJoiner;

            this.Bus.RegisterBusListener(this.Listeners);
            this.Bus.Start();

            // Enable security.
            // Note the location of the keystore file has been specified and the
            // isShared parameter is being set to true. So this keystore file can
            // be used by multiple applications.
            this.AuthenticationListener = new AuthListener(this.Bus);

            this.AuthenticationListener.RequestCredentials += this.AuthRequestCredentals;
            this.Bus.EnablePeerSecurity(
                App.SecurityType,
                this.AuthenticationListener,
                "/.alljoyn_keystore/s_central.ks",
                true);

            this.Bus.ConnectAsync(App.ConnectSpec).AsTask().Wait();

            SessionOpts sessionOpts = new SessionOpts(
                TrafficType.TRAFFIC_MESSAGES,
                false,
                ProximityType.PROXIMITY_ANY,
                TransportMaskType.TRANSPORT_ANY);

            ushort[] portOut = new ushort[1];

            this.Bus.BindSessionPort(App.ServicePort, portOut, sessionOpts, this.Listeners);

            try
            {
                uint flags = (uint)RequestNameType.DBUS_NAME_REPLACE_EXISTING + (uint)RequestNameType.DBUS_NAME_DO_NOT_QUEUE;
                this.Bus.RequestName(App.ServiceName, flags);
            }
            catch (COMException ce)
            {
                QStatus exceptionStatus = AllJoynException.GetErrorCode(ce.HResult);
                string  error           = string.Format(
                    "Well known name '{0}' was not accepted. QStatus = 0x{1:X}",
                    App.ServiceName,
                    exceptionStatus);

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

            this.Bus.AdvertiseName(App.ServiceName, sessionOpts.TransportMask);
            App.OutputLine(string.Format("Name is being advertised as: '{0}'.", App.ServiceName));
        }
Exemple #2
0
        /// <summary>
        /// Initializes the global bus attachment
        /// </summary>
        private void InitializeAllJoyn()
        {
            InterfaceDescription[] iface = new InterfaceDescription[1];

            this.Bus = new BusAttachment("SRPSecurityServiceA", true, 4);

            this.Bus.CreateInterface(App.InterfaceName, iface, true);
            iface[0].AddMethod("Ping", "s", "s", "inStr,outStr", 0, string.Empty);
            iface[0].Activate();

            this.BusObject = new SecureBusObject(this.Bus, iface);

            this.Listeners = new Listeners(this.Bus);
            this.Listeners.NameOwnerChange += this.NameOwnerChanged;
            this.Listeners.AcceptSessionJoiner += this.AcceptSessionJoiner;

            this.Bus.RegisterBusListener(this.Listeners);
            this.Bus.Start();

            // Enable security.
            // Note the location of the keystore file has been specified and the
            // isShared parameter is being set to true. So this keystore file can
            // be used by multiple applications.
            this.AuthenticationListener = new AuthListener(this.Bus);

            this.AuthenticationListener.RequestCredentials += this.AuthRequestCredentals;
            this.Bus.EnablePeerSecurity(
                                        App.SecurityType,
                                        this.AuthenticationListener,
                                        "/.alljoyn_keystore/s_central.ks",
                                        true);
            
            this.Bus.ConnectAsync(App.ConnectSpec).AsTask().Wait();

            SessionOpts sessionOpts = new SessionOpts(
                                                      TrafficType.TRAFFIC_MESSAGES,
                                                      false,
                                                      ProximityType.PROXIMITY_ANY,
                                                      TransportMaskType.TRANSPORT_ANY);
            ushort[] portOut = new ushort[1];

            this.Bus.BindSessionPort(App.ServicePort, portOut, sessionOpts, this.Listeners);

            try
            {
                uint flags = (uint)RequestNameType.DBUS_NAME_REPLACE_EXISTING + (uint)RequestNameType.DBUS_NAME_DO_NOT_QUEUE;
                this.Bus.RequestName(App.ServiceName, flags);
            }
            catch (COMException ce)
            {
                QStatus exceptionStatus = AllJoynException.GetErrorCode(ce.HResult);
                string error = string.Format(
                                             "Well known name '{0}' was not accepted. QStatus = 0x{1:X}",
                                             App.ServiceName,
                                             exceptionStatus);

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

            this.Bus.AdvertiseName(App.ServiceName, sessionOpts.TransportMask);
            App.OutputLine(string.Format("Name is being advertised as: '{0}'.", App.ServiceName));
        }