[Nsd]Fixed ArgumentException and implemented IDisposable in INsdService 49/121549/12 accepted/tizen/unified/20170713.153200 submit/tizen/20170712.035209
authorshikha.ta <shikha.ta@samsung.com>
Tue, 28 Mar 2017 07:53:17 +0000 (13:23 +0530)
committerchleun.moon <chleun.moon@samsung.com>
Wed, 5 Jul 2017 07:33:32 +0000 (16:33 +0900)
Change-Id: I4bc1cb300b58aa1be09bc5376ac0e4b807e9a04a
Signed-off-by: shikha.ta <shikha.ta@samsung.com>
12 files changed:
Tizen.Network.Nsd/Tizen.Network.Nsd/DnssdBrowser.cs
Tizen.Network.Nsd/Tizen.Network.Nsd/DnssdService.cs
Tizen.Network.Nsd/Tizen.Network.Nsd/Globals.cs [new file with mode: 0755]
Tizen.Network.Nsd/Tizen.Network.Nsd/INsdBrowser.cs
Tizen.Network.Nsd/Tizen.Network.Nsd/INsdService.cs
Tizen.Network.Nsd/Tizen.Network.Nsd/NamespaceDoc.cs [new file with mode: 0644]
Tizen.Network.Nsd/Tizen.Network.Nsd/NsdEnumerations.cs
Tizen.Network.Nsd/Tizen.Network.Nsd/NsdError.cs
Tizen.Network.Nsd/Tizen.Network.Nsd/NsdEventArgs.cs
Tizen.Network.Nsd/Tizen.Network.Nsd/NsdManager.cs [deleted file]
Tizen.Network.Nsd/Tizen.Network.Nsd/SsdpBrowser.cs
Tizen.Network.Nsd/Tizen.Network.Nsd/SsdpService.cs

index 020a58a..d9e9bef 100755 (executable)
@@ -21,6 +21,7 @@ namespace Tizen.Network.Nsd
     /// <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;
@@ -31,6 +32,7 @@ namespace Tizen.Network.Nsd
         /// <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
@@ -48,15 +50,37 @@ namespace Tizen.Network.Nsd
         /// 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);
@@ -79,7 +103,14 @@ namespace Tizen.Network.Nsd
             }
         }
 
-        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)
index e84ddcc..b098a12 100755 (executable)
@@ -40,6 +40,7 @@ namespace Tizen.Network.Nsd
     /// <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;
@@ -50,9 +51,11 @@ namespace Tizen.Network.Nsd
         /// <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;
@@ -81,10 +84,14 @@ namespace Tizen.Network.Nsd
         /// </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
@@ -107,7 +114,7 @@ namespace Tizen.Network.Nsd
                     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);
@@ -120,8 +127,11 @@ namespace Tizen.Network.Nsd
         /// 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
@@ -142,11 +152,14 @@ namespace Tizen.Network.Nsd
         /// 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
@@ -179,12 +192,13 @@ namespace Tizen.Network.Nsd
         }
 
         /// <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
@@ -218,10 +232,13 @@ namespace Tizen.Network.Nsd
         /// <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);
@@ -248,9 +265,12 @@ namespace Tizen.Network.Nsd
         /// <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);
@@ -274,9 +294,19 @@ namespace Tizen.Network.Nsd
             }
         }
 
-        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();
             }
@@ -298,7 +328,17 @@ namespace Tizen.Network.Nsd
             }
         }
 
-        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)
@@ -308,19 +348,50 @@ namespace Tizen.Network.Nsd
             }
         }
 
-        ~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;
@@ -337,7 +408,8 @@ namespace Tizen.Network.Nsd
         /// <summary>
         /// The IP version 4 address of DNSSD service.
         /// </summary>
-        public IPAddress IPV4Address
+        /// <since_tizen> 4 </since_tizen>
+        public IPAddress IPv4Address
         {
             get
             {
@@ -348,7 +420,8 @@ namespace Tizen.Network.Nsd
         /// <summary>
         /// The IP version 6 address of DNSSD service.
         /// </summary>
-        public IPAddress IPV6Address
+        /// <since_tizen> 4 </since_tizen>
+        public IPAddress IPv6Address
         {
             get
             {
@@ -356,4 +429,4 @@ namespace Tizen.Network.Nsd
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/Tizen.Network.Nsd/Tizen.Network.Nsd/Globals.cs b/Tizen.Network.Nsd/Tizen.Network.Nsd/Globals.cs
new file mode 100755 (executable)
index 0000000..d1abff4
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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();
+        });
+    }
+}
index 5643bbe..524f921 100755 (executable)
@@ -21,5 +21,30 @@ namespace Tizen.Network.Nsd
     /// </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();
     }
 }
index 0b2eedc..594fbf0 100755 (executable)
  * 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();
     }
 }
diff --git a/Tizen.Network.Nsd/Tizen.Network.Nsd/NamespaceDoc.cs b/Tizen.Network.Nsd/Tizen.Network.Nsd/NamespaceDoc.cs
new file mode 100644 (file)
index 0000000..1ec8bba
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+<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 {}
index 92f301d..ce98b1e 100755 (executable)
@@ -21,6 +21,7 @@ namespace Tizen.Network.Nsd
     /// <summary>
     /// Enumeration for DNS-SD service state.
     /// </summary>
+    /// <since_tizen> 4 </since_tizen>
     public enum DnssdServiceState
     {
         /// <summary>
@@ -48,6 +49,7 @@ namespace Tizen.Network.Nsd
     /// <summary>
     /// Enumeration for SSDP service state.
     /// </summary>
+    /// <since_tizen> 4 </since_tizen>
     public enum SsdpServiceState
     {
         /// <summary>
@@ -64,6 +66,7 @@ namespace Tizen.Network.Nsd
     {
         None = ErrorCode.None,
         OutOfMemory = ErrorCode.OutOfMemory,
+        PermissionDenied = ErrorCode.PermissionDenied,
         InvalidOperation = ErrorCode.InvalidOperation,
         InvalidParameter = ErrorCode.InvalidParameter,
         NotSupported = ErrorCode.NotSupported,
@@ -79,6 +82,7 @@ namespace Tizen.Network.Nsd
     {
         None = ErrorCode.None,
         OutOfMemory = ErrorCode.OutOfMemory,
+        PermissionDenied = ErrorCode.PermissionDenied,
         InvalidParameter = ErrorCode.InvalidParameter,
         NotSupported = ErrorCode.NotSupported,
         NotInitialized = -0x01C90000 | 0x01,
index 36891f4..3eda757 100755 (executable)
@@ -27,10 +27,12 @@ namespace Tizen.Network.Nsd
             {
             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:
@@ -55,8 +57,10 @@ namespace Tizen.Network.Nsd
             {
                 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:
index c0c7d94..b68edc5 100755 (executable)
@@ -21,6 +21,7 @@ namespace Tizen.Network.Nsd
     /// <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;
@@ -35,6 +36,7 @@ namespace Tizen.Network.Nsd
         /// <summary>
         /// DNSSD service state.
         /// </summary>
+        /// <since_tizen> 4 </since_tizen>
         public DnssdServiceState State
         {
             get
@@ -46,6 +48,7 @@ namespace Tizen.Network.Nsd
         /// <summary>
         /// DNSSD service instance.
         /// </summary>
+        /// <since_tizen> 4 </since_tizen>
         public DnssdService Service
         {
             get
@@ -58,6 +61,7 @@ namespace Tizen.Network.Nsd
     /// <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;
@@ -72,6 +76,7 @@ namespace Tizen.Network.Nsd
         /// <summary>
         /// SSDP service state.
         /// </summary>
+        /// <since_tizen> 4 </since_tizen>
         public SsdpServiceState State
         {
             get
@@ -83,6 +88,7 @@ namespace Tizen.Network.Nsd
         /// <summary>
         /// SSDP service instance.
         /// </summary>
+        /// <since_tizen> 4 </since_tizen>
         public SsdpService Service
         {
             get
diff --git a/Tizen.Network.Nsd/Tizen.Network.Nsd/NsdManager.cs b/Tizen.Network.Nsd/Tizen.Network.Nsd/NsdManager.cs
deleted file mode 100755 (executable)
index b80c273..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * 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();
-            }
-        }
-    }
-}
index 7f7d1ed..2dfb586 100755 (executable)
@@ -21,6 +21,7 @@ namespace Tizen.Network.Nsd
     /// <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;
@@ -31,6 +32,7 @@ namespace Tizen.Network.Nsd
         /// <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
@@ -47,16 +49,36 @@ namespace Tizen.Network.Nsd
         /// <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);
@@ -79,7 +101,16 @@ namespace Tizen.Network.Nsd
             }
         }
 
-        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)
index 77f18ae..f19d1ad 100755 (executable)
@@ -15,6 +15,7 @@
  */
 
 using System;
+using System.Threading;
 
 namespace Tizen.Network.Nsd
 {
@@ -38,6 +39,7 @@ 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;
@@ -47,7 +49,9 @@ namespace Tizen.Network.Nsd
         /// <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;
@@ -75,61 +79,66 @@ namespace Tizen.Network.Nsd
         /// 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;
             }
         }
 
@@ -140,8 +149,11 @@ namespace Tizen.Network.Nsd
         /// 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
@@ -159,12 +171,12 @@ namespace Tizen.Network.Nsd
 
             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);
@@ -173,9 +185,22 @@ namespace Tizen.Network.Nsd
             }
         }
 
-        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();
             }
@@ -192,7 +217,17 @@ namespace Tizen.Network.Nsd
             }
         }
 
-        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)
@@ -202,13 +237,43 @@ namespace Tizen.Network.Nsd
             }
         }
 
-        ~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
     }
 }