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.
16 public static class IoTConnectivityServerManager
19 /// Initializes connection with IoTCon service
21 public static void Initialize()
23 int ret = Interop.IoTConnectivity.Client.IoTCon.Initialize();
24 if (ret != (int)IoTConnectivityError.None)
26 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to initialize");
27 throw IoTConnectivityErrorFactory.GetException(ret);
32 /// Disconnects with IoTCon service
34 public static void Deinitialize()
36 Interop.IoTConnectivity.Client.IoTCon.Deinitialize();
40 /// Registers a resource to be available from IoTCon server
42 /// <param name="resource">The resource to register</param>
43 public static void RegisterResource(Resource resource)
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)
49 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed create resource");
50 throw IoTConnectivityErrorFactory.GetException(ret);
54 resource.ResourceHandle = handle;
59 /// Starts presence of a server
61 /// <param name="time">The interval of announcing presence in seconds.</param>
62 public static void StartSendingPresence(uint time)
64 int ret = Interop.IoTConnectivity.Server.IoTCon.StartPresence(time);
65 if (ret != (int)IoTConnectivityError.None)
67 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to start presence");
68 throw IoTConnectivityErrorFactory.GetException(ret);
73 /// Stops presence of a server.
75 public static void StopSendingPresence()
77 int ret = Interop.IoTConnectivity.Server.IoTCon.StopPresence();
78 if (ret != (int)IoTConnectivityError.None)
80 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed cancel presence");
81 throw IoTConnectivityErrorFactory.GetException(ret);
86 /// Sets the device name
88 /// <param name="deviceName">The device name</param>
89 public static void SetDeviceName(string deviceName)
91 int ret = Interop.IoTConnectivity.Server.IoTCon.SetDeviceName(deviceName);
92 if (ret != (int)IoTConnectivityError.None)
94 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed set device name");
95 throw IoTConnectivityErrorFactory.GetException(ret);