1 /// Copyright 2016 by Samsung Electronics, Inc.,
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.
11 namespace Tizen.Network.IoTConnectivity
14 /// IoT connectivity server manager consists of server side APIs.
16 public static class IoTConnectivityServerManager
19 /// Initializes IoTCon. Call this API to start IoTCon.
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.
27 /// http://tizen.org/privilege/network.get \n
28 /// http://tizen.org/privilege/internet
30 /// <param name="filePath">The file path to point to storage for handling secure virtual resources.</param>
32 /// You must call Deinitialize() if IoTCon API is no longer needed.
34 /// <seealso cref="Deinitialize()"/>
36 /// string filePath = "../../res/iotcon-test-svr-db-server.dat";
37 /// IoTConnectivityServerManager.Initialize(filePath);
39 public static void Initialize(string filePath)
41 int ret = Interop.IoTConnectivity.Client.IoTCon.Initialize(filePath);
42 if (ret != (int)IoTConnectivityError.None)
44 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to initialize");
45 throw IoTConnectivityErrorFactory.GetException(ret);
50 /// Deinitializes IoTCon.
53 /// This API must be called if IoTCon API is no longer needed.
56 /// Initialize() should be called to initialize.
58 /// <seealso cref="Initialize()"/>
60 /// IoTConnectivityServerManager.Deinitialize();
62 public static void Deinitialize()
64 Interop.IoTConnectivity.Client.IoTCon.Deinitialize();
68 /// Registers a resource in IoTCon server
71 /// http://tizen.org/privilege/internet
73 /// <param name="resource">The resource to register</param>
75 /// Initialize() should be called to initialize.
77 /// <seealso cref="Resource"/>
78 /// <seealso cref="LiteResource"/>
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);
84 /// IoTConnectivityServerManager.RegisterResource(res);
85 /// } catch(Exception ex) {
86 /// Console.Log("Exception caught : " + ex.Message);
89 public static void RegisterResource(Resource resource)
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)
95 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed create resource");
96 throw IoTConnectivityErrorFactory.GetException(ret);
100 resource.ResourceHandle = handle;
105 /// Starts presence of a server
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).
114 /// http://tizen.org/privilege/internet
116 /// <param name="time">The interval of announcing presence in seconds.</param>
118 /// Initialize() should be called to initialize.
120 /// <seealso cref="IoTConnectivityClientManager.StartReceivingPresence()"/>
121 /// <seealso cref="IoTConnectivityClientManager.StopReceivingPresence()"/>
122 /// <seealso cref="IoTConnectivityClientManager.PresenceReceived"/>
123 /// <seealso cref="StopSendingPresence()"/>
126 /// IoTConnectivityServerManager.StartSendingPresence(120);
127 /// } catch(Exception ex) {
128 /// Console.Log("Exception caught : " + ex.Message);
131 public static void StartSendingPresence(uint time)
133 int ret = Interop.IoTConnectivity.Server.IoTCon.StartPresence(time);
134 if (ret != (int)IoTConnectivityError.None)
136 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to start presence");
137 throw IoTConnectivityErrorFactory.GetException(ret);
142 /// Stops presence of a server.
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.
149 /// http://tizen.org/privilege/internet
152 /// Initialize() should be called to initialize.
154 /// <seealso cref="IoTConnectivityClientManager.StartReceivingPresence()"/>
155 /// <seealso cref="IoTConnectivityClientManager.StopReceivingPresence()"/>
156 /// <seealso cref="IoTConnectivityClientManager.PresenceReceived"/>
157 /// <seealso cref="StartSendingPresence()"/>
159 /// IoTConnectivityServerManager.StopSendingPresence();
161 public static void StopSendingPresence()
163 int ret = Interop.IoTConnectivity.Server.IoTCon.StopPresence();
164 if (ret != (int)IoTConnectivityError.None)
166 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed cancel presence");
167 throw IoTConnectivityErrorFactory.GetException(ret);
172 /// Sets the device name
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.
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"/>
185 /// IoTConnectivityServerManager.SetDeviceName("my-tizen");
187 public static void SetDeviceName(string deviceName)
189 int ret = Interop.IoTConnectivity.Server.IoTCon.SetDeviceName(deviceName);
190 if (ret != (int)IoTConnectivityError.None)
192 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed set device name");
193 throw IoTConnectivityErrorFactory.GetException(ret);