Beispiel #1
0
        /// <summary>
        /// Dispose the SDK instance, don't miss this after SDK usage.
        /// </summary>
        public void Dispose()
        {
            Subscriber?.Dispose();
            Subscriber = null;

            Storage?.Dispose();
            Storage = null;

            RuyiNetService?.Dispose();
            RuyiNetService = null;

            SettingSys?.Dispose();
            SettingSys = null;

            L10NService?.Dispose();
            L10NService = null;

            UserService?.Dispose();
            UserService = null;

            InputMgr?.Dispose();
            InputMgr = null;

            SpeechService?.Dispose();
            SpeechService = null;

            Media?.Dispose();
            Media = null;

            OverlayService?.Dispose();
            OverlayService = null;

            lowLatencyTransport?.Close();
            LowLatencyProtocol?.Dispose();
            lowLatencyTransport = null;
            LowLatencyProtocol  = null;

            highLatencyTransport?.Close();
            HighLatencyProtocol?.Dispose();
            HighLatencyProtocol  = null;
            highLatencyTransport = null;


            // don't clean up netmq in layer0.
            InstanceCount--;
            if (InstanceCount <= 0)
            {
                var entry = Assembly.GetEntryAssembly();
                if (entry == null)  // in a unit test
                {
                    NetMQConfig.Cleanup(false);
                    return;
                }

                // not Layer0 & not Layer1
                if (!entry.FullName.StartsWith("Layer0,", StringComparison.OrdinalIgnoreCase) &&
                    !entry.FullName.StartsWith("zpLayer1,", StringComparison.OrdinalIgnoreCase))
                {
                    NetMQConfig.Cleanup(false);
                    return;
                }
            }
        }
Beispiel #2
0
        bool Init()
        {
            if (context.Transport == null)
            {
                // init and open high/low latency transport, create protocols
                var lowLatencyPort = context.LowLatencyPort == 0 ? ConstantsSDKDataTypesConstants.low_latency_socket_port : context.LowLatencyPort;
                lowLatencyTransport = new TSocketTransportTS(context.RemoteAddress, lowLatencyPort, context.Timeout <= 0 ? SDKUtility.Instance.LowLatencyTimeout : context.Timeout);

                var highLatencyPort = context.HighLatencyPort == 0 ? ConstantsSDKDataTypesConstants.high_latency_socket_port : context.HighLatencyPort;
                highLatencyTransport = new TSocketTransportTS(context.RemoteAddress, highLatencyPort, context.Timeout <= 0 ? SDKUtility.Instance.HighLatencyTimeout : context.Timeout);
            }
            else
            {
                lowLatencyTransport  = context.Transport;
                highLatencyTransport = context.Transport;
            }

            LowLatencyProtocol  = new TBinaryProtocolTS(lowLatencyTransport);
            HighLatencyProtocol = new TBinaryProtocolTS(highLatencyTransport);

            lowLatencyTransport.Open();
            highLatencyTransport.Open();

            if (!ValidateVersion())
            {
                return(false);
            }

            if (IsFeatureEnabled(SDKFeatures.Subscriber))
            {
                var pubout = ConstantsSDKDataTypesConstants.layer0_publisher_out_uri.SetAddress(context.RemoteAddress);
                Subscriber = SubscribeClient.CreateInstance(pubout);
            }

            if (IsFeatureEnabled(SDKFeatures.Storage))
            {
                var stoProtocol = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.STORAGELAYER.ServiceID());
                Storage = new StorageLayerService.Client(stoProtocol);
            }

            if (IsFeatureEnabled(SDKFeatures.Online))
            {
                var bcProtocol = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.BCSERVICE.ServiceID());
                RuyiNetService = new RuyiNetClient(bcProtocol, Storage);
                //BCService = new BrainCloudService.Client(bcProtocal);
            }

            if (IsFeatureEnabled(SDKFeatures.Settings))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.SETTINGSYSTEM_EXTERNAL.ServiceID());
                SettingSys = new SDK.SettingSystem.Api.SettingSystemService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.L10N))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.L10NSERVICE.ServiceID());
                L10NService = new LocalizationService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Users))
            {
                var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.USER_SERVICE_EXTERNAL.ServiceID());
                UserService = new UserServExternal.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Input))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.INPUTMANAGER_EXTERNAL.ServiceID());
                InputMgr = new InputManagerService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Speech))
            {
                var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.SPEECH.ServiceID());
                SpeechService = new SpeechService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Media))
            {
                var proto = new TMultiplexedProtocol(HighLatencyProtocol, ServiceIDs.MEDIA.ServiceID());
                Media = new MediaService.Client(proto);
            }

            if (IsFeatureEnabled(SDKFeatures.Overlay))
            {
                var proto = new TMultiplexedProtocol(LowLatencyProtocol, ServiceIDs.OVERLAYMANAGER_EXTERNAL.ServiceID());
                OverlayService = new ExternalOverlayManagerService.Client(proto);
            }

            return(true);
        }