[Nsd]Fixed ArgumentException and implemented IDisposable in INsdService
[platform/core/csapi/nsd.git] / Tizen.Network.Nsd / Tizen.Network.Nsd / Globals.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Threading;
19
20 namespace Tizen.Network.Nsd
21 {
22     internal static class Globals
23     {
24         internal const string LogTag = "Tizen.Network.Nsd";
25
26         internal static void DnssdInitialize()
27         {
28             int ret = Interop.Nsd.Dnssd.Initialize();
29             if(ret!=(int)DnssdError.None)
30             {
31                 Log.Error(LogTag, "Failed to initialize Dnssd, Error - "+ (DnssdError)ret);
32                 NsdErrorFactory.ThrowDnssdException(ret);
33             }
34         }
35
36         internal static void SsdpInitialize()
37         {
38             int ret = Interop.Nsd.Ssdp.Initialize();
39             if (ret != (int)SsdpError.None)
40             {
41                 Log.Error(LogTag, "Failed to initialize Ssdp, Error - " + (SsdpError)ret);
42                 NsdErrorFactory.ThrowSsdpException(ret);
43             }
44         }
45
46         internal static ThreadLocal<DnssdInitializer> s_threadDns = new ThreadLocal<DnssdInitializer>(() =>
47        {
48            Log.Info(LogTag, "Inside Dnssd ThreadLocal delegate");
49            return new DnssdInitializer();
50        });
51
52         internal static ThreadLocal<SsdpInitializer> s_threadSsd = new ThreadLocal<SsdpInitializer>(() =>
53         {
54             Log.Info(LogTag, "Inside Ssdp ThreadLocal delegate");
55             return new SsdpInitializer();
56         });
57     }
58 }