示例#1
0
        /// <summary>
        /// Stops browsing the SSDP remote service.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <feature>http://tizen.org/feature/network.service_discovery.ssdp</feature>
        /// <exception cref="InvalidOperationException">Thrown when any other error occured.</exception>
        /// <exception cref="NotSupportedException">Thrown when SSDP is not supported.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
        public void StopDiscovery()
        {
            int ret = Interop.Nsd.Ssdp.StopBrowsing(_browserHandle);

            if (ret != (int)SsdpError.None)
            {
                Log.Error(Globals.LogTag, "Failed to stop discovery of Ssdp remote service, Error - " + (SsdpError)ret);
                NsdErrorFactory.ThrowSsdpException(ret);
            }
        }
示例#2
0
        /// <summary>
        /// Deregisters the SSDP local service.
        /// </summary>
        /// <remarks>
        /// A local service registered using RegisterService() must be passed.
        /// </remarks>
        /// <since_tizen> 4 </since_tizen>
        /// <feature>http://tizen.org/feature/network.service_discovery.ssdp</feature>
        /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
        /// <exception cref="NotSupportedException">Thrown when the SSDP is not supported.</exception>
        public void DeregisterService()
        {
            int ret = Interop.Nsd.Ssdp.DeregisterService(_serviceHandle);

            if (ret != (int)SsdpError.None)
            {
                Log.Error(Globals.LogTag, "Failed to deregister the Ssdp local service, Error: " + (SsdpError)ret);
                NsdErrorFactory.ThrowSsdpException(ret);
            }
        }
示例#3
0
        internal static void SsdpInitialize()
        {
            int ret = Interop.Nsd.Ssdp.Initialize();

            if (ret != (int)SsdpError.None)
            {
                Log.Error(LogTag, "Failed to initialize Ssdp, Error - " + (SsdpError)ret);
                NsdErrorFactory.ThrowSsdpException(ret);
            }
        }
示例#4
0
        /// <summary>
        /// A public constructor for the SsdpBrowser class to create a SsdpBrowser instance for the given target.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="target">The target to browse for the service.</param>
        /// <feature>http://tizen.org/feature/network.service_discovery.ssdp</feature>
        /// <exception cref="ArgumentException">Thrown when the target is null.</exception>
        /// <exception cref="NotSupportedException">Thrown when SSDP is not supported.</exception>
        public SsdpBrowser(string target)
        {
            SsdpInitializer ssdpInit = Globals.s_threadSsd.Value;

            Log.Info(Globals.LogTag, "Initialize ThreadLocal<SsdpInitializer> instance = " + ssdpInit);
            if (target == null)
            {
                Log.Debug(Globals.LogTag, "target is null");
                NsdErrorFactory.ThrowSsdpException((int)SsdpError.InvalidParameter);
            }

            _target = target;
        }
示例#5
0
        internal void SsdpInitializeCreateService()
        {
            SsdpInitializer ssdpInit = Globals.s_threadSsd.Value;

            Log.Info(Globals.LogTag, "Initialize ThreadLocal<SsdpInitializer> instance = " + ssdpInit);
            int ret = Interop.Nsd.Ssdp.CreateService(_target, out _serviceHandle);

            if (ret != (int)SsdpError.None)
            {
                Log.Error(Globals.LogTag, "Failed to create a local Ssdp service handle, Error - " + (SsdpError)ret);
                NsdErrorFactory.ThrowSsdpException(ret);
            }
        }
示例#6
0
        /// <summary>
        /// Registers the SSDP local service for publishing.
        /// </summary>
        /// <remarks>
        /// A service created locally must be passed.
        /// URL and USN of the service must be set before the RegisterService is called.
        /// </remarks>
        /// <since_tizen> 4 </since_tizen>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <feature>http://tizen.org/feature/network.service_discovery.ssdp</feature>
        /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
        /// <exception cref="NotSupportedException">Thrown when the SSDP is not supported.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
        public void RegisterService()
        {
            if (!Globals.s_threadSsd.IsValueCreated)
            {
                SsdpInitializeCreateService();
            }

            _serviceRegisteredCallback = (SsdpError result, uint service, IntPtr userData) =>
            {
            };

            int ret = Interop.Nsd.Ssdp.RegisterService(_serviceHandle, _serviceRegisteredCallback, IntPtr.Zero);

            if (ret != (int)SsdpError.None)
            {
                Log.Error(Globals.LogTag, "Failed to register the Ssdp local service, Error: " + (SsdpError)ret);
                NsdErrorFactory.ThrowSsdpException(ret);
            }
        }
示例#7
0
        /// <summary>
        /// Starts browsing the SSDP remote service.
        /// </summary>
        /// <remarks>
        /// If there are any services available, the ServiceFound event will be invoked.
        /// The application will keep browsing for the available or unavailable services until it calls StopDiscovery().
        /// </remarks>
        /// <since_tizen> 4 </since_tizen>
        /// <feature>http://tizen.org/feature/network.service_discovery.ssdp</feature>
        /// <exception cref="InvalidOperationException">Thrown when any other error occured.</exception>
        /// <exception cref="NotSupportedException">Thrown when SSDP is not supported.</exception>
        public void StartDiscovery()
        {
            SsdpInitializer ssdpInit = Globals.s_threadSsd.Value;

            Log.Info(Globals.LogTag, "Initialize ThreadLocal<SsdpInitializer> instance = " + ssdpInit);

            _serviceFoundCallback = (SsdpServiceState state, uint service, IntPtr userData) =>
            {
                if (_serviceFound != null)
                {
                    Log.Info(Globals.LogTag, "Inside Service found callback");
                    SsdpService ssdpService = new SsdpService(service);
                    _serviceFound(null, new SsdpServiceFoundEventArgs(state, ssdpService));
                }
            };

            int ret = Interop.Nsd.Ssdp.StartBrowsing(_target, out _browserHandle, _serviceFoundCallback, IntPtr.Zero);

            if (ret != (int)SsdpError.None)
            {
                Log.Error(Globals.LogTag, "Failed to discover Ssdp remote service, Error - " + (SsdpError)ret);
                NsdErrorFactory.ThrowSsdpException(ret);
            }
        }