/// <summary>
/// This class is used for managing network service discovery using DNSSD.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public class DnssdBrowser : INsdBrowser
{
private string _serviceType;
/// <summary>
/// This event is raised when a DNSSD service is found during service discovery.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public event EventHandler<DnssdServiceFoundEventArgs> ServiceFound
{
add
/// 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.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;
}
- internal void StartDiscovery()
+ /// <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.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);
}
}
- internal void StopDiscovery()
+ /// <summary>
+ /// Stops browsing the DNSSD remote service.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <feature>http://tizen.org/feature/network.dnssd</feature>
+ /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
+ /// <exception cref="NotSupportedException">Thrown when DNSSD is not supported.</exception>
+ public void StopDiscovery()
{
int ret = Interop.Nsd.Dnssd.StopBrowsing(_browserHandle);
if (ret != (int)DnssdError.None)
/// <summary>
/// This class is used for managing local service registration and its properties using DNSSD.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public class DnssdService : INsdService
{
private uint _serviceHandle;
/// <summary>
/// Constructor to create DnssdService instance that sets the serviceType to a given value.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
/// <param name="serviceType">The DNSSD service type. It is expressed as type followed by protocol, separated by a dot(e.g. "_ftp._tcp").
/// It must begin with an underscore, followed by 1-15 characters which may be letters, digits or hyphens.
/// </param>
+ /// <feature>http://tizen.org/feature/network.dnssd</feature>
public DnssdService(string serviceType)
{
_serviceType = serviceType;
/// </summary>
/// <remarks>
/// Set Name for only unregistered service created locally.
+ /// It may be up to 63 bytes.
/// In case of error, null will be returned during get and exception will be thrown during set.
/// </remarks>
+ /// <since_tizen> 4 </since_tizen>
+ /// <feature>http://tizen.org/feature/network.dnssd</feature>
/// <exception cref="NotSupportedException">Thrown while setting this property when DNSSD is not supported.</exception>
- /// <exception cref="InvalidOperationException">Thrown while setting this property when any other error occured.</exception>
+ /// <exception cref="ArgumentException">Thrown when Name value is set to null.</exception>
+ /// <exception cref="InvalidOperationException">Thrown while setting this property when any other error occurred.</exception>
public string Name
{
get
DnssdInitializeCreateService();
}
- int ret = Interop.Nsd.Dnssd.SetName(_serviceHandle, value.ToString());
+ int ret = Interop.Nsd.Dnssd.SetName(_serviceHandle, value);
if (ret != (int)DnssdError.None)
{
Log.Error(Globals.LogTag, "Failed to set name of service, Error: " + (DnssdError)ret);
/// Type of DNSSD local/remote service.
/// </summary>
/// <remarks>
+ /// It is expressed as type followed by protocol, separated by a dot(e.g. "_ftp._tcp").
+ /// It must begin with an underscore, followed by 1-15 characters which may be letters, digits or hyphens.
/// In case of error, null will be returned.
/// </remarks>
+ /// <since_tizen> 4 </since_tizen>
public string Type
{
get
/// Port number of DNSSD local/remote service.
/// </summary>
/// <remarks>
- /// Set Port for only unregistered service created locally.
+ /// Set Port for only unregistered service created locally. The default value of Port is 0.
/// In case of error, -1 will be returned during get and exception will be thrown during set.
/// </remarks>
+ /// <since_tizen> 4 </since_tizen>
+ /// <feature>http://tizen.org/feature/network.dnssd</feature>
/// <exception cref="NotSupportedException">Thrown while setting this property when DNSSD is not supported.</exception>
- /// <exception cref="InvalidOperationException">Thrown while setting this property when any other error occured.</exception>
+ /// <exception cref="ArgumentException">Thrown if value of Port is set to less than 0 or more than 65535.</exception>
+ /// <exception cref="InvalidOperationException">Thrown while setting this property when any other error occurred.</exception>
public int Port
{
get
}
/// <summary>
- /// IP of DNSSD remote service.
+ /// IP address of DNSSD remote service.
/// </summary>
/// <remarks>
- /// If there is no IPv4 Address, then IPV4Address would contain null and if there is no IPv6 Address, then IPV6Address would contain null.
+ /// If the remote service has no IPv4 Address, then IPv4Address would contain null and if it has no IPv6 Address, then IPv6Address would contain null.
/// In case of error, null object will be returned.
/// </remarks>
+ /// <since_tizen> 4 </since_tizen>
public IPAddressInformation IP
{
get
/// <remarks>
/// TXT record should be added after registering 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 value_length is zero, then "key=" will be added with empty value.</param>
+ /// <feature>http://tizen.org/feature/network.dnssd</feature>
/// <exception cref="NotSupportedException">Thrown when DNSSD is not supported.</exception>
- /// <exception cref="InvalidOperationException">Thrown when any other error occured.</exception>
+ /// <exception cref="ArgumentException">Thrown when value of 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);
/// <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.dnssd</feature>
/// <exception cref="NotSupportedException">Thrown when DNSSD is not supported.</exception>
- /// <exception cref="InvalidOperationException">Thrown when any other error occured.</exception>
+ /// <exception cref="ArgumentException">Thrown when value of 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);
}
}
- internal void RegisterService()
+ /// <summary>
+ /// Registers the DNSSD 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.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 RegisterService()
{
- if (Globals.s_threadDns.IsValueCreated)
+ if (!Globals.s_threadDns.IsValueCreated)
{
DnssdInitializeCreateService();
}
}
}
- internal void DeregisterService()
+ /// <summary>
+ /// Deregisters the DNSSD 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.dnssd</feature>
+ /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
+ /// <exception cref="NotSupportedException">Thrown when DNSSD is not supported.</exception>
+ public void DeregisterService()
{
int ret = Interop.Nsd.Dnssd.DeregisterService(_serviceHandle);
if (ret != (int)DnssdError.None)
}
}
- ~DnssdService()
+ #region IDisposable Support
+ private bool _disposedValue = false; // To detect redundant calls
+
+ protected virtual void Dispose(bool disposing)
{
- int ret = Interop.Nsd.Dnssd.DestroyService(_serviceHandle);
- if (ret != (int)DnssdError.None)
+ if (!_disposedValue)
{
- Log.Error(Globals.LogTag, "Failed to destroy the local Dnssd service handle, Error - " + (DnssdError)ret);
+ if (disposing)
+ {
+ if (_serviceHandle != 0)
+ {
+ int ret = Interop.Nsd.Dnssd.DestroyService(_serviceHandle);
+ if (ret != (int)DnssdError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to destroy the local Dnssd service handle, Error - " + (DnssdError)ret);
+ }
+ }
+ }
+
+ _disposedValue = true;
}
}
+
+ ~DnssdService()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Disposes the memory allocated to unmanaged resources.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+ #endregion
}
/// <summary>
/// This class manages the IP address properties of DNSSD service.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public class IPAddressInformation
{
private string _ipv4, _ipv6;
/// <summary>
/// The IP version 4 address of DNSSD service.
/// </summary>
- public IPAddress IPV4Address
+ /// <since_tizen> 4 </since_tizen>
+ public IPAddress IPv4Address
{
get
{
/// <summary>
/// The IP version 6 address of DNSSD service.
/// </summary>
- public IPAddress IPV6Address
+ /// <since_tizen> 4 </since_tizen>
+ public IPAddress IPv6Address
{
get
{
}
}
}
-}
\ No newline at end of file
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Threading;
+
+namespace Tizen.Network.Nsd
+{
+ internal static class Globals
+ {
+ internal const string LogTag = "Tizen.Network.Nsd";
+
+ 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);
+ }
+ }
+
+ 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);
+ }
+ }
+
+ internal static ThreadLocal<DnssdInitializer> s_threadDns = new ThreadLocal<DnssdInitializer>(() =>
+ {
+ Log.Info(LogTag, "Inside Dnssd ThreadLocal delegate");
+ return new DnssdInitializer();
+ });
+
+ internal static ThreadLocal<SsdpInitializer> s_threadSsd = new ThreadLocal<SsdpInitializer>(() =>
+ {
+ Log.Info(LogTag, "Inside Ssdp ThreadLocal delegate");
+ return new SsdpInitializer();
+ });
+ }
+}
/// </summary>
public interface INsdBrowser
{
+ /// <summary>
+ /// Starts browsing the DNSSD/SSDP 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.dnssd</feature>
+ /// <feature>http://tizen.org/feature/network.ssdp</feature>
+ /// <exception cref="InvalidOperationException">Thrown when any other error occured.</exception>
+ /// <exception cref="NotSupportedException">Thrown when DNSSD/SSDP is not supported.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
+ void StartDiscovery();
+
+ /// <summary>
+ /// Stops browsing the DNSSD/SSDP remote service.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <feature>http://tizen.org/feature/network.dnssd</feature>
+ /// <feature>http://tizen.org/feature/network.ssdp</feature>
+ /// <exception cref="InvalidOperationException">Thrown when any other error occured.</exception>
+ /// <exception cref="NotSupportedException">Thrown when DNSSD/SSDP is not supported.</exception>
+ void StopDiscovery();
}
}
* limitations under the License.
*/
+using System;
+
namespace Tizen.Network.Nsd
{
/// <summary>
- /// This interface provides properties for managing local service discovery using DNSSD/SSDP.
+ /// This interface is used for managing local service registration using DNSSD/SSDP.
/// </summary>
- public interface INsdService
+ public interface INsdService : IDisposable
{
/// <summary>
- /// Name of local service.
+ /// Registers the DNSSD/SSDP local service for publishing.
/// </summary>
- string Name { get; set; }
+ /// <remarks>
+ /// A service created locally must be passed.
+ /// </remarks>
+ /// <since_tizen> 4 </since_tizen>
+ /// <privilege>http://tizen.org/privilege/internet</privilege>
+ /// <feature>http://tizen.org/feature/network.dnssd</feature>
+ /// <feature>http://tizen.org/feature/network.ssdp</feature>
+ /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
+ /// <exception cref="NotSupportedException">Thrown when DNSSD/SSDP is not supported.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
+ void RegisterService();
/// <summary>
- /// Type of local/remote service.
+ /// Deregisters the DNSSD/SSDP local service.
/// </summary>
- string Type { get; }
+ /// <remarks>
+ /// A local service registered using RegisterService() must be passed.
+ /// </remarks>
+ /// <since_tizen> 4 </since_tizen>
+ /// <feature>http://tizen.org/feature/network.dnssd</feature>
+ /// <feature>http://tizen.org/feature/network.ssdp</feature>
+ /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
+ /// <exception cref="NotSupportedException">Thrown when DNSSD/SSDP is not supported.</exception>
+ void DeregisterService();
}
}
--- /dev/null
+/**
+<summary>
+The Tizen.Network.Nsd namespace provides classes to manage the network service discovery protocols.
+</summary>
+<remarks>
+<h2>Overview</h2>
+<para>The Nsd API handles two network service discovery protocols: DNS-SD (DNS Service Discovery) and SSDP (Simple Service Discovery Protocol). They allows application to announce local services and search for remote services on a network.
+</para>
+<h2>Related Features</h2>
+<para>To use DNS-SD, declare the following feature requirements in the config file:<br/>
+http://tizen.org/feature/network.dnssd
+</para>
+<para>To use SSDP, declare the following feature requirements in the config file:<br/>
+http://tizen.org/feature/network.ssdp
+</para>
+
+</remarks>
+
+<example>
+The following example demonstrates how to register a DNS-SD local service.
+<code>
+DnssdService service = new DnssdService("_http._tcp");
+service.Name = "TestService";
+service.Port = "1234";
+service.RegisterService();
+</code>
+</example>
+
+*/
+namespace Tizen.Network.Nsd {}
/// <summary>
/// Enumeration for DNS-SD service state.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public enum DnssdServiceState
{
/// <summary>
/// <summary>
/// Enumeration for SSDP service state.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public enum SsdpServiceState
{
/// <summary>
{
None = ErrorCode.None,
OutOfMemory = ErrorCode.OutOfMemory,
+ PermissionDenied = ErrorCode.PermissionDenied,
InvalidOperation = ErrorCode.InvalidOperation,
InvalidParameter = ErrorCode.InvalidParameter,
NotSupported = ErrorCode.NotSupported,
{
None = ErrorCode.None,
OutOfMemory = ErrorCode.OutOfMemory,
+ PermissionDenied = ErrorCode.PermissionDenied,
InvalidParameter = ErrorCode.InvalidParameter,
NotSupported = ErrorCode.NotSupported,
NotInitialized = -0x01C90000 | 0x01,
{
case DnssdError.OutOfMemory:
throw new InvalidOperationException("Out of memory");
+ case DnssdError.PermissionDenied:
+ throw new UnauthorizedAccessException("Permission Denied");
case DnssdError.InvalidOperation:
throw new InvalidOperationException("Invalid operation");
case DnssdError.InvalidParameter:
- throw new InvalidOperationException("Invalid parameter");
+ throw new ArgumentException("Invalid parameter");
case DnssdError.NotSupported:
throw new NotSupportedException("Not supported");
case DnssdError.NotInitialized:
{
case SsdpError.OutOfMemory:
throw new InvalidOperationException("Out of memory");
+ case SsdpError.PermissionDenied:
+ throw new UnauthorizedAccessException("Permission Denied");
case SsdpError.InvalidParameter:
- throw new InvalidOperationException("Invalid parameter");
+ throw new ArgumentException("Invalid parameter");
case SsdpError.NotSupported:
throw new NotSupportedException("Not supported");
case SsdpError.NotInitialized:
/// <summary>
/// An extended EventArgs class which contains changed service state during service discovery using DNSSD.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public class DnssdServiceFoundEventArgs : EventArgs
{
private DnssdServiceState _state;
/// <summary>
/// DNSSD service state.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public DnssdServiceState State
{
get
/// <summary>
/// DNSSD service instance.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public DnssdService Service
{
get
/// <summary>
/// An extended EventArgs class which contains changed service state during service discovery using SSDP.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public class SsdpServiceFoundEventArgs : EventArgs
{
private SsdpServiceState _state;
/// <summary>
/// SSDP service state.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public SsdpServiceState State
{
get
/// <summary>
/// SSDP service instance.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public SsdpService Service
{
get
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using System.Threading;
-
-namespace Tizen.Network.Nsd
-{
- internal static class Globals
- {
- internal const string LogTag = "Tizen.Network.Nsd";
-
- 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);
- }
- }
-
- 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);
- }
- }
-
- internal static ThreadLocal<DnssdInitializer> s_threadDns = new ThreadLocal<DnssdInitializer>(() =>
- {
- Log.Info(LogTag, "Inside Dnssd ThreadLocal delegate");
- return new DnssdInitializer();
- });
-
- internal static ThreadLocal<SsdpInitializer> s_threadSsd = new ThreadLocal<SsdpInitializer>(() =>
- {
- Log.Info(LogTag, "Inside Ssdp ThreadLocal delegate");
- return new SsdpInitializer();
- });
- }
-
- /// <summary>
- /// This class is used for managing local/network service registration and discovery using DNSSD/SSDP.
- /// </summary>
- public static class NsdManager
- {
- /// <summary>
- /// Registers the DNSSD/SSDP local service for publishing.
- /// </summary>
- /// <remarks>
- /// A service created locally must be passed.
- /// Name of the service must be set for DNSSD/SSDP both. Also, Port and Url must be set for DNSSD and SSDP respectively.
- /// </remarks>
- /// <param name="service">The DNSSD/SSDP service instance.</param>
- /// <exception cref="NotSupportedException">Thrown when DNSSD/SSDP is not supported.</exception>
- /// <exception cref="InvalidOperationException">Thrown when any other error occured.</exception>
- public static void RegisterService(INsdService service)
- {
- if (service.GetType() == typeof(DnssdService))
- {
- DnssdService dnsService = (DnssdService)service;
- dnsService.RegisterService();
- }
-
- else if (service.GetType() == typeof(SsdpService))
- {
- SsdpService ssdService = (SsdpService)service;
- ssdService.RegisterService();
- }
- }
-
- /// <summary>
- /// Deregisters the DNSSD/SSDP local service.
- /// </summary>
- /// <remarks>
- /// A local service registered using RegisterService() must be passed.
- /// </remarks>
- /// <param name="service">The DNSSD/SSDP service instance.</param>
- /// <exception cref="NotSupportedException">Thrown when DNSSD/SSDP is not supported.</exception>
- /// <exception cref="InvalidOperationException">Thrown when any other error occured.</exception>
- public static void UnregisterService(INsdService service)
- {
- if (service.GetType() == typeof(DnssdService))
- {
- DnssdService dnsService = (DnssdService)service;
- dnsService.DeregisterService();
- }
-
- else if (service.GetType() == typeof(SsdpService))
- {
- SsdpService ssdService = (SsdpService)service;
- ssdService.DeregisterService();
- }
- }
-
- /// <summary>
- /// Starts browsing the DNSSD/SSDP 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>
- /// <param name="browser">The DNSSD/SSDP browser instance.</param>
- /// <exception cref="NotSupportedException">Thrown when DNSSD/SSDP is not supported.</exception>
- /// <exception cref="InvalidOperationException">Thrown when any other error occured.</exception>
- public static void StartDiscovery(INsdBrowser browser)
- {
- if (browser.GetType() == typeof(DnssdBrowser))
- {
- DnssdBrowser dnsBrowser = (DnssdBrowser)browser;
- dnsBrowser.StartDiscovery();
- }
-
- else if (browser.GetType() == typeof(SsdpBrowser))
- {
- SsdpBrowser ssdBrowser = (SsdpBrowser)browser;
- ssdBrowser.StartDiscovery();
- }
- }
-
- /// <summary>
- /// Stops browsing the DNSSD/SSDP remote service.
- /// </summary>
- /// <param name="browser">The DNSSD/SSDP browser instance.</param>
- /// <exception cref="NotSupportedException">Thrown when DNSSD/SSDP is not supported.</exception>
- /// <exception cref="InvalidOperationException">Thrown when any other error occured.</exception>
- public static void StopDiscovery(INsdBrowser browser)
- {
- if (browser.GetType() == typeof(DnssdBrowser))
- {
- DnssdBrowser dnsBrowser = (DnssdBrowser)browser;
- dnsBrowser.StopDiscovery();
- }
-
- else if (browser.GetType() == typeof(SsdpBrowser))
- {
- SsdpBrowser ssdBrowser = (SsdpBrowser)browser;
- ssdBrowser.StopDiscovery();
- }
- }
- }
-}
/// <summary>
/// This class is used for managing network service discovery using SSDP.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public class SsdpBrowser : INsdBrowser
{
private string _target;
/// <summary>
/// This event is raised when service has become available or unavailable during service discovery using SSDP.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public event EventHandler<SsdpServiceFoundEventArgs> ServiceFound
{
add
/// <summary>
/// A public constructor for 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.ssdp</feature>
+ /// <exception cref="ArgumentException">Thrown when 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;
}
- internal void StartDiscovery()
+ /// <summary>
+ /// Starts browsing the SSDP 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>
+ /// <feature>http://tizen.org/feature/network.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);
}
}
- internal void StopDiscovery()
+ /// <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.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 permission is denied.</exception>
+ public void StopDiscovery()
{
int ret = Interop.Nsd.Ssdp.StopBrowsing(_browserHandle);
if (ret != (int)SsdpError.None)
*/
using System;
+using System.Threading;
namespace Tizen.Network.Nsd
{
/// <summary>
/// This class is used for managing local service registration and its properties using SSDP.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public class SsdpService : INsdService
{
private uint _serviceHandle;
/// <summary>
/// Constructor to create SsdpService instance that sets the target to a given value.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
/// <param name="target">The SSDP local service's target. It may be a device type or a service type.</param>
+ /// <feature>http://tizen.org/feature/network.ssdp</feature>
public SsdpService(string target)
{
_target = target;
/// Unique Service Name of SSDP service.
/// </summary>
/// <remarks>
- /// Set Name for only unregistered service created locally. If service is already registered, Name will not be set.
+ /// Set Usn for only unregistered service created locally. If service is already registered, Usn will not be set.
/// In case of error, null will be returned during get and exception will be thrown during set.
/// </remarks>
+ /// <since_tizen> 4 </since_tizen>
+ /// <feature>http://tizen.org/feature/network.ssdp</feature>
/// <exception cref="NotSupportedException">Thrown while setting this property when SSDP is not supported.</exception>
- /// <exception cref="InvalidOperationException">Thrown while setting this property when any other error occured.</exception>
- public string Name
+ /// <exception cref="ArgumentException">Thrown when Usn value is set to null.</exception>
+ /// <exception cref="InvalidOperationException">Thrown while setting this property when any other error occurred.</exception>
+ public string Usn
{
get
{
- string name;
- int ret = Interop.Nsd.Ssdp.GetUsn(_serviceHandle, out name);
+ string usn;
+ int ret = Interop.Nsd.Ssdp.GetUsn(_serviceHandle, out usn);
if (ret != (int)SsdpError.None)
{
- Log.Error(Globals.LogTag, "Failed to get name of service, Error: " + (SsdpError)ret);
+ Log.Error(Globals.LogTag, "Failed to get usn of service, Error: " + (SsdpError)ret);
return null;
}
- return name;
+ return usn;
}
set
{
- if (Globals.s_threadSsd.IsValueCreated)
+ if (!Globals.s_threadSsd.IsValueCreated)
{
SsdpInitializeCreateService();
}
- int ret = Interop.Nsd.Ssdp.SetUsn(_serviceHandle, value.ToString());
+ int ret = Interop.Nsd.Ssdp.SetUsn(_serviceHandle, value);
if (ret != (int)SsdpError.None)
{
- Log.Error(Globals.LogTag, "Failed to set name of service, Error: " + (SsdpError)ret);
+ Log.Error(Globals.LogTag, "Failed to set usn of service, Error: " + (SsdpError)ret);
NsdErrorFactory.ThrowSsdpException(ret);
}
}
}
/// <summary>
- /// Type of SSDP service.
+ /// Target of SSDP service.
/// </summary>
/// <remarks>
+ /// It may be a device type or a service type specified in UPnP forum (http://upnp.org).
/// In case of error, null will be returned.
/// </remarks>
- public string Type
+ /// <since_tizen> 4 </since_tizen>
+ public string Target
{
get
{
- string type;
- int ret = Interop.Nsd.Ssdp.GetTarget(_serviceHandle, out type);
+ string target;
+ int ret = Interop.Nsd.Ssdp.GetTarget(_serviceHandle, out target);
if (ret != (int)SsdpError.None)
{
- Log.Error(Globals.LogTag, "Failed to get type of service, Error: " + (SsdpError)ret);
+ Log.Error(Globals.LogTag, "Failed to get target of service, Error: " + (SsdpError)ret);
return null;
}
- return type;
+ return target;
}
}
/// Set Url for only unregistered service created locally. If service is already registered, Url will not be set.
/// In case of error, null will be returned during get and exception will be thrown during set.
/// </remarks>
+ /// <since_tizen> 4 </since_tizen>
+ /// <feature>http://tizen.org/feature/network.ssdp</feature>
/// <exception cref="NotSupportedException">Thrown while setting this property when SSDP is not supported.</exception>
- /// <exception cref="InvalidOperationException">Thrown while setting this property when any other error occured.</exception>
+ /// <exception cref="ArgumentException">Thrown when Url value is set to null.</exception>
+ /// <exception cref="InvalidOperationException">Thrown while setting this property when any other error occurred.</exception>
public string Url
{
get
set
{
- if (Globals.s_threadSsd.IsValueCreated)
+ if (!Globals.s_threadSsd.IsValueCreated)
{
SsdpInitializeCreateService();
}
- int ret = Interop.Nsd.Ssdp.SetUrl(_serviceHandle, value.ToString());
+ int ret = Interop.Nsd.Ssdp.SetUrl(_serviceHandle, value);
if (ret != (int)SsdpError.None)
{
Log.Error(Globals.LogTag, "Failed to set url of Ssdp service, Error: " + (SsdpError)ret);
}
}
- internal void RegisterService()
+ /// <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 RegisterService is called.
+ /// </remarks>
+ /// <since_tizen> 4 </since_tizen>
+ /// <privilege>http://tizen.org/privilege/internet</privilege>
+ /// <feature>http://tizen.org/feature/network.ssdp</feature>
+ /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
+ /// <exception cref="NotSupportedException">Thrown when SSDP is not supported.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
+ public void RegisterService()
{
- if (Globals.s_threadSsd.IsValueCreated)
+ if (!Globals.s_threadSsd.IsValueCreated)
{
SsdpInitializeCreateService();
}
}
}
- internal void DeregisterService()
+ /// <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.ssdp</feature>
+ /// <exception cref="InvalidOperationException">Thrown when any other error occurred.</exception>
+ /// <exception cref="NotSupportedException">Thrown when SSDP is not supported.</exception>
+ public void DeregisterService()
{
int ret = Interop.Nsd.Ssdp.DeregisterService(_serviceHandle);
if (ret != (int)SsdpError.None)
}
}
- ~SsdpService()
+ #region IDisposable Support
+ private bool _disposedValue = false; // To detect redundant calls
+
+ protected virtual void Dispose(bool disposing)
{
- int ret = Interop.Nsd.Ssdp.DestroyService(_serviceHandle);
- if (ret != (int)SsdpError.None)
+ if (!_disposedValue)
{
- Log.Error(Globals.LogTag, "Failed to destroy the local Ssdp service handle, Error - " + (SsdpError)ret);
+ if (disposing)
+ {
+ if (_serviceHandle != 0)
+ {
+ int ret = Interop.Nsd.Ssdp.DestroyService(_serviceHandle);
+ if (ret != (int)SsdpError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to destroy the local Ssdp service handle, Error - " + (SsdpError)ret);
+ }
+ }
+ }
+
+ _disposedValue = true;
}
}
+
+ ~SsdpService()
+ {
+ Dispose(false);
+ }
+
+ /// <summary>
+ /// Disposes the memory allocated to unmanaged resources.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+ #endregion
}
}