Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deregisters the DNS-SD 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.dnssd</feature>
        /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
        /// <exception cref="NotSupportedException">Thrown when DNS-SD is not supported.</exception>
        public void DeregisterService()
        {
            int ret = Interop.Nsd.Dnssd.DeregisterService(_serviceHandle);

            if (ret != (int)DnssdError.None)
            {
                Log.Error(Globals.LogTag, "Failed to deregister the Dnssd local service, Error: " + (DnssdError)ret);
                NsdErrorFactory.ThrowDnssdException(ret);
            }
        }
Exemplo n.º 3
0
        private void GetTxtRecord(out ushort length, out byte[] value)
        {
            int ret = Interop.Nsd.Dnssd.GetAllTxtRecord(_serviceHandle, out length, out value);

            if (ret != (int)DnssdError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get the TXT record, Error: " + (DnssdError)ret);
                NsdErrorFactory.ThrowDnssdException(ret);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        internal static void DnssdInitialize()
        {
            int ret = Interop.Nsd.Dnssd.Initialize();

            if (ret != (int)DnssdError.None)
            {
                Log.Error(LogTag, "Failed to initialize Dnssd, Error - " + (DnssdError)ret);
                NsdErrorFactory.ThrowDnssdException(ret);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Removes the TXT record.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="key">The key of the TXT record to be removed.</param>
        /// <feature>http://tizen.org/feature/network.service_discovery.dnssd</feature>
        /// <exception cref="NotSupportedException">Thrown when DNS-SD is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the value of the key is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
        public void RemoveTXTRecord(string key)
        {
            int ret = Interop.Nsd.Dnssd.RemoveTxtRecord(_serviceHandle, key);

            if (ret != (int)DnssdError.None)
            {
                Log.Error(Globals.LogTag, "Failed to remove the TXT record, Error: " + (DnssdError)ret);
                NsdErrorFactory.ThrowDnssdException(ret);
            }
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Returns raw TXT records.
        /// </summary>
        /// <returns>Returns empty bytes array in case TXT record has not been set, else returns raw TXT record.</returns>
        /// <since_tizen> 9 </since_tizen>
        /// <feature>http://tizen.org/feature/network.service_discovery.dnssd</feature>
        /// <exception cref="NotSupportedException">Thrown when DNS-SD is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
        public byte[] GetRawTXTRecords()
        {
            int ret = Interop.Nsd.Dnssd.GetAllTxtRecord(_serviceHandle, out ushort length, out IntPtr data);

            if (ret != (int)DnssdError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get the TXT record, Error: " + (DnssdError)ret);
                NsdErrorFactory.ThrowDnssdException(ret);
            }
            byte[] value = Array.Empty <byte>();
            if (length > 0)
            {
                value = new byte[length];
                Marshal.Copy(data, value, 0, length);
                Interop.Libc.Free(data);
            }
            return(value);
        }
Exemplo n.º 12
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);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Adds the TXT record.
        /// </summary>
        /// <remarks>
        /// TXT record should be added after registering the local service using RegisterService().
        /// </remarks>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="key">The key of the TXT record. It must be a null-terminated string with 9 characters or fewer excluding null. It is case insensitive.</param>
        /// <param name="value">The value of the TXT record. If null, then "key" will be added with no value. If non-null but the value_length is zero, then "key=" will be added with an empty value.</param>
        /// <feature>http://tizen.org/feature/network.service_discovery.dnssd</feature>
        /// <exception cref="NotSupportedException">Thrown when DNS-SD is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the value of the key is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
        public void AddTXTRecord(string key, string value)
        {
            byte[] byteValue = Encoding.UTF8.GetBytes(value);
            ushort length    = Convert.ToUInt16(byteValue.Length);
            int    ret       = Interop.Nsd.Dnssd.AddTxtRecord(_serviceHandle, key, length, byteValue);

            if (ret != (int)DnssdError.None)
            {
                Log.Error(Globals.LogTag, "Failed to add the TXT record, Error: " + (DnssdError)ret);
                NsdErrorFactory.ThrowDnssdException(ret);
            }
            byte[] txtValue = GetRawTXTRecords();
            ret = Interop.Nsd.Dnssd.SetRecord(_serviceHandle, _dnsRecordtype, (ushort)txtValue.Length, txtValue);
            if (ret != (int)DnssdError.None)
            {
                Log.Error(Globals.LogTag, "Failed to set the DNS resource record, Error: " + (DnssdError)ret);
                NsdErrorFactory.ThrowDnssdException(ret);
            }
        }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Registers the DNS-SD local service for publishing.
        /// </summary>
        /// Name of the service must be set.
        /// <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 DNS-SD is not supported.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
        public void RegisterService()
        {
            if (!Globals.s_threadDns.IsValueCreated)
            {
                DnssdInitializeCreateService();
            }

            _serviceRegisteredCallback = (DnssdError result, uint service, IntPtr userData) =>
            {
                if (result != DnssdError.None)
                {
                    Log.Error(Globals.LogTag, "Failed to finish the registration of Dnssd local service, Error: " + result);
                    NsdErrorFactory.ThrowDnssdException((int)result);
                }
            };

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

            if (ret != (int)DnssdError.None)
            {
                Log.Error(Globals.LogTag, "Failed to register the Dnssd local service, Error: " + (DnssdError)ret);
                NsdErrorFactory.ThrowDnssdException(ret);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Removes the TXT record.
        /// </summary>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="key">The key of the TXT record to be removed.</param>
        /// <feature>http://tizen.org/feature/network.service_discovery.dnssd</feature>
        /// <exception cref="NotSupportedException">Thrown when DNS-SD is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when the value of the key is null.</exception>
        /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
        public void RemoveTXTRecord(string key)
        {
            int ret = Interop.Nsd.Dnssd.RemoveTxtRecord(_serviceHandle, key);

            if (ret != (int)DnssdError.None)
            {
                Log.Error(Globals.LogTag, "Failed to remove the TXT record, Error: " + (DnssdError)ret);
                NsdErrorFactory.ThrowDnssdException(ret);
            }

            byte[] txtValue;
            ushort txtLength;

            GetTxtRecord(out txtLength, out txtValue);
            if (txtLength == 0)
            {
                ret = Interop.Nsd.Dnssd.UnsetRecord(_serviceHandle, _dnsRecordtype);
                if (ret != (int)DnssdError.None)
                {
                    Log.Error(Globals.LogTag, "Failed to unset the DNS resource record, Error: " + (DnssdError)ret);
                    NsdErrorFactory.ThrowDnssdException(ret);
                }
            }
        }
Exemplo n.º 17
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);
            }
        }