[IoTConnectivity] Added Base implementation
[platform/core/csapi/iotcon.git] / Tizen.Network.IoTConnectivity / Tizen.Network.IoTConnectivity / IoTConnectivityServerManager.cs
1 /// Copyright 2016 by Samsung Electronics, Inc.,
2 ///
3 /// This software is the confidential and proprietary information
4 /// of Samsung Electronics, Inc. ("Confidential Information"). You
5 /// shall not disclose such Confidential Information and shall use
6 /// it only in accordance with the terms of the license agreement
7 /// you entered into with Samsung.
8
9 using System;
10
11 namespace Tizen.Network.IoTConnectivity
12 {
13     /// <summary>
14     /// IoT connectivity server manager.
15     /// </summary>
16     public static class IoTConnectivityServerManager
17     {
18         /// <summary>
19         /// Initializes connection with IoTCon service
20         /// </summary>
21         public static void Initialize()
22         {
23             int ret = Interop.IoTConnectivity.Client.IoTCon.Initialize();
24             if (ret != (int)IoTConnectivityError.None)
25             {
26                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to initialize");
27                 throw IoTConnectivityErrorFactory.GetException(ret);
28             }
29         }
30
31         /// <summary>
32         /// Disconnects with IoTCon service
33         /// </summary>
34         public static void Deinitialize()
35         {
36             Interop.IoTConnectivity.Client.IoTCon.Deinitialize();
37         }
38
39         /// <summary>
40         /// Registers a resource to be available from IoTCon server
41         /// </summary>
42         /// <param name="resource">The resource to register</param>
43         public static void RegisterResource(Resource resource)
44         {
45             IntPtr handle = IntPtr.Zero;
46             int ret = Interop.IoTConnectivity.Server.Resource.Create(resource.UriPath, resource.Types._resourceTypeHandle, resource.Interfaces.ResourceInterfacesHandle, (int)resource.Policy, resource.OnRequest, IntPtr.Zero, out handle);
47             if (ret != (int)IoTConnectivityError.None)
48             {
49                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed create resource");
50                 throw IoTConnectivityErrorFactory.GetException(ret);
51             }
52             else
53             {
54                 resource.ResourceHandle = handle;
55             }
56         }
57
58         /// <summary>
59         /// Starts presence of a server
60         /// </summary>
61         /// <param name="time">The interval of announcing presence in seconds.</param>
62         public static void StartSendingPresence(uint time)
63         {
64             int ret = Interop.IoTConnectivity.Server.IoTCon.StartPresence(time);
65             if (ret != (int)IoTConnectivityError.None)
66             {
67                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to start presence");
68                 throw IoTConnectivityErrorFactory.GetException(ret);
69             }
70         }
71
72         /// <summary>
73         /// Stops presence of a server.
74         /// </summary>
75         public static void StopSendingPresence()
76         {
77             int ret = Interop.IoTConnectivity.Server.IoTCon.StopPresence();
78             if (ret != (int)IoTConnectivityError.None)
79             {
80                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed cancel presence");
81                 throw IoTConnectivityErrorFactory.GetException(ret);
82             }
83         }
84     }
85 }