Ejemplo n.º 1
0
        internal void DnssdInitializeCreateService()
        {
            DnssdInitializer dnssdInit = Globals.s_threadDns.Value;

            Log.Info(Globals.LogTag, "Initialize ThreadLocal<DnssdInitializer> instance = " + dnssdInit);
            int ret = Interop.Nsd.Dnssd.CreateService(_serviceType, out _serviceHandle);

            if (ret != (int)DnssdError.None)
            {
                Log.Error(Globals.LogTag, "Failed to create a local Dnssd service handle, Error - " + (DnssdError)ret);
                NsdErrorFactory.ThrowDnssdException(ret);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// A public constructor for DnssdBrowser class to create a DnssdBrowser instance for the given service type.
        /// </summary>
        /// <param name="serviceType">The DNSSD service type</param>
        /// <since_tizen> 4 </since_tizen>
        /// <feature>http://tizen.org/feature/network.service_discovery.dnssd</feature>
        /// <exception cref="ArgumentException">Thrown when serviceType is null.</exception>
        /// <exception cref="NotSupportedException">Thrown when DNSSD is not supported.</exception>
        public DnssdBrowser(string serviceType)
        {
            DnssdInitializer dnssdInit = Globals.s_threadDns.Value;

            Log.Info(Globals.LogTag, "Initialize ThreadLocal<DnssdInitializer> instance = " + dnssdInit);
            if (serviceType == null)
            {
                Log.Debug(Globals.LogTag, "serviceType is null");
                NsdErrorFactory.ThrowDnssdException((int)DnssdError.InvalidParameter);
            }

            _serviceType = serviceType;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts browsing the DNSSD remote service.
        /// </summary>
        /// <remarks>
        /// If there are any services available, ServiceFound event will be invoked.
        /// Application will keep browsing for available/unavailable services until it calls StopDiscovery().
        /// </remarks>
        /// <since_tizen> 4 </since_tizen>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <feature>http://tizen.org/feature/network.service_discovery.dnssd</feature>
        /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
        /// <exception cref="NotSupportedException">Thrown when DNSSD is not supported.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
        public void StartDiscovery()
        {
            DnssdInitializer dnssdInit = Globals.s_threadDns.Value;

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

            _serviceFoundCallback = (DnssdServiceState state, uint service, IntPtr userData) =>
            {
                if (_serviceFound != null)
                {
                    Log.Info(Globals.LogTag, "Inside Service found callback");
                    DnssdService dnsService = new DnssdService(service);
                    _serviceFound(null, new DnssdServiceFoundEventArgs(state, dnsService));
                }
            };

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

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