Added Doxygen comments, incorporated recent CAPI changes
[platform/core/csapi/tizenfx.git] / src / 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 consists of server side APIs.
15     /// </summary>
16     public static class IoTConnectivityServerManager
17     {
18         /// <summary>
19         /// Initializes IoTCon. Call this API to start IoTCon.
20         /// </summary>
21         /// <remarks>
22         /// @a filePath point to a file for handling secure virtual resources.
23         /// The file that is CBOR(Concise Binary Object Representation)-format must already exist
24         /// in @a filePath. We recommend to use application-local file for @a filePath.
25         /// </remarks>
26         /// <privilege>
27         /// http://tizen.org/privilege/network.get \n
28         /// http://tizen.org/privilege/internet
29         /// </privilege>
30         /// <param name="filePath">The file path to point to storage for handling secure virtual resources.</param>
31         /// <post>
32         /// You must call Deinitialize() if IoTCon API is no longer needed.
33         /// </post>
34         /// <seealso cref="Deinitialize()"/>
35         /// <code>
36         /// string filePath = "../../res/iotcon-test-svr-db-server.dat";
37         /// IoTConnectivityServerManager.Initialize(filePath);
38         /// </code>
39         public static void Initialize(string filePath)
40         {
41             int ret = Interop.IoTConnectivity.Client.IoTCon.Initialize(filePath);
42             if (ret != (int)IoTConnectivityError.None)
43             {
44                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to initialize");
45                 throw IoTConnectivityErrorFactory.GetException(ret);
46             }
47         }
48
49         /// <summary>
50         /// Deinitializes IoTCon.
51         /// </summary>
52         /// <remarks>
53         /// This API must be called if IoTCon API is no longer needed.
54         /// </remarks>
55         /// <pre>
56         /// Initialize() should be called to initialize.
57         /// </pre>
58         /// <seealso cref="Initialize()"/>
59         /// <code>
60         /// IoTConnectivityServerManager.Deinitialize();
61         /// </code>
62         public static void Deinitialize()
63         {
64             Interop.IoTConnectivity.Client.IoTCon.Deinitialize();
65         }
66
67         /// <summary>
68         /// Registers a resource in IoTCon server
69         /// </summary>
70         /// <privilege>
71         /// http://tizen.org/privilege/internet
72         /// </privilege>
73         /// <param name="resource">The resource to register</param>
74         /// <pre>
75         /// Initialize() should be called to initialize.
76         /// </pre>
77         /// <seealso cref="Resource"/>
78         /// <seealso cref="LiteResource"/>
79         /// <code>
80         /// ResourceTypes types = new ResourceTypes(new List<string>(){ "org.tizen.light" });
81         /// Attributes attributes = new Attributes { { "state", "ON" }};
82         /// Resource res = new LiteResource("/room/1", types, ResourcePolicy.Discoverable, attributes);
83         /// try {
84         ///     IoTConnectivityServerManager.RegisterResource(res);
85         /// } catch(Exception ex) {
86         ///     Console.Log("Exception caught : " + ex.Message);
87         /// }
88         /// </code>
89         public static void RegisterResource(Resource resource)
90         {
91             IntPtr handle = IntPtr.Zero;
92             int ret = Interop.IoTConnectivity.Server.Resource.Create(resource.UriPath, resource.Types._resourceTypeHandle, resource.Interfaces.ResourceInterfacesHandle, (int)resource.Policy, resource.OnRequest, IntPtr.Zero, out handle);
93             if (ret != (int)IoTConnectivityError.None)
94             {
95                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed create resource");
96                 throw IoTConnectivityErrorFactory.GetException(ret);
97             }
98             else
99             {
100                 resource.ResourceHandle = handle;
101             }
102         }
103
104         /// <summary>
105         /// Starts presence of a server
106         /// </summary>
107         /// <remarks>
108         /// Use this API to send server's announcements to clients.
109         /// Server can call this API when online for the first time or come back from offline to online.\n
110         /// If @a time is 0, server will set default value as 60 seconds.\n
111         /// If @a time is very big, server will set maximum value as (60 * 60 * 24) seconds, (24 hours).
112         /// </remarks>
113         /// <privilege>
114         /// http://tizen.org/privilege/internet
115         /// </privilege>
116         /// <param name="time">The interval of announcing presence in seconds.</param>
117         /// <pre>
118         /// Initialize() should be called to initialize.
119         /// </pre>
120         /// <seealso cref="IoTConnectivityClientManager.StartReceivingPresence()"/>
121         /// <seealso cref="IoTConnectivityClientManager.StopReceivingPresence()"/>
122         /// <seealso cref="IoTConnectivityClientManager.PresenceReceived"/>
123         /// <seealso cref="StopSendingPresence()"/>
124         /// <code>
125         /// try {
126         ///     IoTConnectivityServerManager.StartSendingPresence(120);
127         /// } catch(Exception ex) {
128         ///     Console.Log("Exception caught : " + ex.Message);
129         /// }
130         /// </code>
131         public static void StartSendingPresence(uint time)
132         {
133             int ret = Interop.IoTConnectivity.Server.IoTCon.StartPresence(time);
134             if (ret != (int)IoTConnectivityError.None)
135             {
136                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to start presence");
137                 throw IoTConnectivityErrorFactory.GetException(ret);
138             }
139         }
140
141         /// <summary>
142         /// Stops presence of a server.
143         /// </summary>
144         /// <remarks>
145         /// Use this API to stop sending server's announcements to clients.
146         /// Server can call this API when terminating, entering to offline or out of network.
147         /// </remarks>
148         /// <privilege>
149         /// http://tizen.org/privilege/internet
150         /// </privilege>
151         /// <pre>
152         /// Initialize() should be called to initialize.
153         /// </pre>
154         /// <seealso cref="IoTConnectivityClientManager.StartReceivingPresence()"/>
155         /// <seealso cref="IoTConnectivityClientManager.StopReceivingPresence()"/>
156         /// <seealso cref="IoTConnectivityClientManager.PresenceReceived"/>
157         /// <seealso cref="StartSendingPresence()"/>
158         /// <code>
159         /// IoTConnectivityServerManager.StopSendingPresence();
160         /// </code>
161         public static void StopSendingPresence()
162         {
163             int ret = Interop.IoTConnectivity.Server.IoTCon.StopPresence();
164             if (ret != (int)IoTConnectivityError.None)
165             {
166                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed cancel presence");
167                 throw IoTConnectivityErrorFactory.GetException(ret);
168             }
169         }
170
171         /// <summary>
172         /// Sets the device name
173         /// </summary>
174         /// <remarks>
175         /// This API sets the name of the local device (the device calling the API).\n
176         /// If the device name is set, clients can get the name using <see cref="IoTConnectivityClientManager.StartFindingDeviceInformation()"/>.
177         /// Clients can also get the name using <see cref="RemoteResource.DeviceName"/> property.
178         /// </remarks>
179         /// <param name="deviceName">The device name</param>
180         /// <seealso cref="IoTConnectivityClientManager.DeviceInformationFound"/>
181         /// <seealso cref="IoTConnectivityClientManager.StartFindingDeviceInformation()"/>
182         /// <seealso cref="DeviceInformationFoundEventArgs"/>
183         /// <seealso cref="RemoteResource.DeviceName"/>
184         /// <code>
185         /// IoTConnectivityServerManager.SetDeviceName("my-tizen");
186         /// </code>
187         public static void SetDeviceName(string deviceName)
188         {
189             int ret = Interop.IoTConnectivity.Server.IoTCon.SetDeviceName(deviceName);
190             if (ret != (int)IoTConnectivityError.None)
191             {
192                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed set device name");
193                 throw IoTConnectivityErrorFactory.GetException(ret);
194             }
195         }
196     }
197 }