summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xTizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Server.cs1
-rwxr-xr-xTizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs39
-rwxr-xr-xTizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs5
3 files changed, 41 insertions, 4 deletions
diff --git a/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Server.cs b/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Server.cs
index 8d1745f..59b9355 100755
--- a/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Server.cs
+++ b/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Server.cs
@@ -47,6 +47,7 @@ internal static partial class Interop
internal static partial class Resource
{
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void RequestHandlerCallback(IntPtr resource, IntPtr request, IntPtr userData);
[DllImport(Libraries.IoTCon, EntryPoint = "iotcon_resource_create")]
diff --git a/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs b/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs
index 3c527b0..071c34c 100755
--- a/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs
+++ b/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs
@@ -24,6 +24,10 @@ namespace Tizen.Network.IoTConnectivity
/// </summary>
public static class IoTConnectivityServerManager
{
+
+ private static int s_requestId = 1;
+ private static Dictionary<IntPtr, Interop.IoTConnectivity.Server.Resource.RequestHandlerCallback> s_RequestHandlerCallbackMap = new Dictionary<IntPtr, Interop.IoTConnectivity.Server.Resource.RequestHandlerCallback>();
+
/// <summary>
/// Initializes IoTCon. Call this API to start IoTCon.
/// </summary>
@@ -71,6 +75,9 @@ namespace Tizen.Network.IoTConnectivity
public static void Deinitialize()
{
_resources.Clear();
+ s_requestId = 1;
+ s_RequestHandlerCallbackMap.Clear();
+
Interop.IoTConnectivity.Client.IoTCon.Deinitialize();
}
@@ -98,12 +105,38 @@ namespace Tizen.Network.IoTConnectivity
/// </code>
public static void RegisterResource(Resource resource)
{
+ Log.Error(IoTConnectivityErrorFactory.LogTag, "...");
+
+ IntPtr id = IntPtr.Zero;
+ lock (s_RequestHandlerCallbackMap)
+ {
+ id = (IntPtr)s_requestId++;
+ }
+
+ s_RequestHandlerCallbackMap[id] = (IntPtr r_resource, IntPtr request, IntPtr userData) =>
+ {
+ int requestId = (int)userData;
+
+ Log.Info(IoTConnectivityErrorFactory.LogTag, "Received s_RequestHandlerCallbackMap : " + requestId);
+
+ if (request == null)
+ {
+ Log.Error(IoTConnectivityErrorFactory.LogTag, "request is null");
+ return;
+ }
+ resource.OnRequest(r_resource, request, userData);
+ };
+
IntPtr handle = IntPtr.Zero;
- int ret = Interop.IoTConnectivity.Server.Resource.Create(resource.UriPath, resource.Types._resourceTypeHandle, resource.Interfaces.ResourceInterfacesHandle, (int)resource.Policy, resource.OnRequest, IntPtr.Zero, out handle);
- if (ret != (int)IoTConnectivityError.None)
+ int errorCode = Interop.IoTConnectivity.Server.Resource.Create(resource.UriPath, resource.Types._resourceTypeHandle, resource.Interfaces.ResourceInterfacesHandle, (int)resource.Policy, s_RequestHandlerCallbackMap[id], id, out handle);
+ if (errorCode != (int)IoTConnectivityError.None)
{
Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed create resource");
- throw IoTConnectivityErrorFactory.GetException(ret);
+ lock (s_RequestHandlerCallbackMap)
+ {
+ s_RequestHandlerCallbackMap.Remove(id);
+ }
+ throw IoTConnectivityErrorFactory.GetException(errorCode);
}
else
{
diff --git a/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs b/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs
index 13d795c..4070b94 100755
--- a/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs
+++ b/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs
@@ -148,7 +148,10 @@ namespace Tizen.Network.IoTConnectivity
Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type");
return null;
}
- return new ResourceTypes(typeHandle);
+ if (typeHandle == IntPtr.Zero)
+ return null;
+ else
+ return new ResourceTypes(typeHandle);
}
set
{