From 9807c3737648926aeb986f4606cecde804b55ff6 Mon Sep 17 00:00:00 2001 From: rajeev ranjan Date: Wed, 8 Jun 2016 17:15:23 +0530 Subject: [PATCH] Fixed issues while testing TCT Change-Id: Ie3dea868b162a0c98159da100acf5f7491380053 Signed-off-by: rajeev ranjan --- .../Interop/Interop.IoTConnectivity.Client.cs | 51 ++++-- .../Interop/Interop.IoTConnectivity.Common.cs | 134 +++++++------- .../Interop/Interop.IoTConnectivity.Server.cs | 9 +- .../Tizen.Network.IoTConnectivity.csproj | 2 +- .../{State.cs => Attributes.cs} | 198 ++++++++++----------- .../IoTConnectivityClientManager.cs | 100 ++++++++--- .../IoTConnectivityServerManager.cs | 14 ++ .../Tizen.Network.IoTConnectivity/LiteResource.cs | 22 +-- .../RemoteResource.cs | 60 +++++-- .../Representation.cs | 53 ++++-- .../Tizen.Network.IoTConnectivity/Request.cs | 8 +- .../Tizen.Network.IoTConnectivity/Resource.cs | 19 +- .../Tizen.Network.IoTConnectivity/ResourceQuery.cs | 9 +- .../Tizen.Network.IoTConnectivity/Response.cs | 16 +- 14 files changed, 415 insertions(+), 280 deletions(-) rename src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/{State.cs => Attributes.cs} (79%) mode change 100755 => 100644 diff --git a/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Client.cs b/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Client.cs index a1195ad..e5c0dc6 100755 --- a/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Client.cs +++ b/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Client.cs @@ -27,11 +27,11 @@ internal static partial class Interop DataModelVersion, } - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_get_device_info")] - internal static extern int Get(string hostAddress, int connectivityType, DeviceInformationCallback cb, IntPtr userData); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_find_device_info")] + internal static extern int Find(string hostAddress, int connectivityType, DeviceInformationCallback cb, IntPtr userData); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_device_info_get_property")] - internal static extern int GetProperty(IntPtr deviceInfoHandle, int property, out string value); + internal static extern int GetProperty(IntPtr deviceInfoHandle, int property, out IntPtr value); } internal static partial class PlatformInformation @@ -53,11 +53,11 @@ internal static partial class Interop SystemTime } - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_get_platform_info")] - internal static extern int Get(string hostAddress, int connectivityType, PlatformInformationCallback cb, IntPtr userData); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_find_platform_info")] + internal static extern int Find(string hostAddress, int connectivityType, PlatformInformationCallback cb, IntPtr userData); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_platform_info_get_property")] - internal static extern int GetProperty(IntPtr platformInfoHandle, int property, out string value); + internal static extern int GetProperty(IntPtr platformInfoHandle, int property, out IntPtr value); } internal static partial class RemoteResource @@ -120,17 +120,17 @@ internal static partial class Interop [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_stop_monitoring")] internal static extern int StopMonitoring(IntPtr resource); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_uriPath")] - internal static extern int GetUriPath(IntPtr resource, out string uriPath); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_uri_path")] + internal static extern int GetUriPath(IntPtr resource, out IntPtr uriPath); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_connectivity_type")] internal static extern int GetConnectivityType(IntPtr resource, out int connectivityType); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_host_address")] - internal static extern int GetHostAddress(IntPtr resource, out string hostAddress); + internal static extern int GetHostAddress(IntPtr resource, out IntPtr hostAddress); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_device_id")] - internal static extern int GetDeviceId(IntPtr resource, out string deviceId); + internal static extern int GetDeviceId(IntPtr resource, out IntPtr deviceId); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_types")] internal static extern int GetTypes(IntPtr resource, out IntPtr types); @@ -138,8 +138,8 @@ internal static partial class Interop [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_interfaces")] internal static extern int GetInterfaces(IntPtr resource, out IntPtr ifaces); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_properties")] - internal static extern int GetProperties(IntPtr resource, out int properties); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_policies")] + internal static extern int GetPolicies(IntPtr resource, out int properties); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_options")] internal static extern int GetOptions(IntPtr resource, out IntPtr options); @@ -151,14 +151,20 @@ internal static partial class Interop internal static extern int GetCachedRepresentation(IntPtr resource, out IntPtr representation); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_time_interval")] - internal static extern int GetTimeInterval(IntPtr resource, out int timeInterval); + internal static extern int GetTimeInterval(out int timeInterval); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_set_time_interval")] - internal static extern int SetTimeInterval(IntPtr resource, int timeInterval); + internal static extern int SetTimeInterval(int timeInterval); + + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_remote_resource_get_device_name")] + internal static extern int GetDeviceName(IntPtr resource, out IntPtr deviceName); } internal static partial class IoTCon { + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_secure_initialize")] + internal static extern int SecureInitialize(string filePath); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_initialize")] internal static extern int Initialize(); @@ -170,6 +176,15 @@ internal static partial class Interop [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_set_timeout")] internal static extern int SetTimeout(int timeoutSeconds); + + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_polling_get_interval")] + internal static extern int GetPollingInterval(out int interval); + + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_polling_set_interval")] + internal static extern int SetPollingInterval(int interval); + + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_polling_invoke")] + internal static extern int InvokePolling(); } internal static partial class ResourceFinder @@ -193,13 +208,13 @@ internal static partial class Interop internal static extern int RemovePresenceCb(IntPtr presenceHandle); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_presence_get_host_address")] - internal static extern int GetHostAddress(IntPtr presence, out string hostAddress); + internal static extern int GetHostAddress(IntPtr presence, out IntPtr hostAddress); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_presence_get_connectivity_type")] internal static extern int GetConnectivityType(IntPtr presence, out int connectivityType); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_presence_get_resource_type")] - internal static extern int GetResourceType(IntPtr presence, out string resourceType); + internal static extern int GetResourceType(IntPtr presence, out IntPtr resourceType); } internal static partial class PresenceResponse @@ -211,13 +226,13 @@ internal static partial class Interop internal static extern int GetTrigger(IntPtr response, out int trigger); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_presence_response_get_host_address")] - internal static extern int GetHostAddress(IntPtr response, out string hostAddress); + internal static extern int GetHostAddress(IntPtr response, out IntPtr hostAddress); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_presence_response_get_connectivity_type")] internal static extern int GetConnectivityType(IntPtr response, out int connectivityType); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_presence_response_get_resource_type")] - internal static extern int GetResourceType(IntPtr response, out string resourceType); + internal static extern int GetResourceType(IntPtr response, out IntPtr resourceType); } } } diff --git a/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Common.cs b/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Common.cs index 63b6447..b7c631f 100755 --- a/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Common.cs +++ b/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Common.cs @@ -25,7 +25,7 @@ internal static partial class Interop ByteStr, Null, List, - State + Attributes } internal static partial class ResourceTypes @@ -76,78 +76,78 @@ internal static partial class Interop internal static extern int Clone(IntPtr src, out IntPtr dest); } - internal static partial class State + internal static partial class Attributes { - internal delegate bool StateCallback(IntPtr state, string key, IntPtr userData); + internal delegate bool AttributesCallback(IntPtr attributes, string key, IntPtr userData); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_create")] - internal static extern int Create(out IntPtr state); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_create")] + internal static extern int Create(out IntPtr attributes); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_destroy")] - internal static extern void Destroy(IntPtr state); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_destroy")] + internal static extern void Destroy(IntPtr attributes); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_clone")] - internal static extern int Clone(IntPtr state, out IntPtr dest); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_clone")] + internal static extern int Clone(IntPtr attributes, out IntPtr attributes_clone); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_add_int")] - internal static extern int AddInt(IntPtr state, string key, int val); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_add_int")] + internal static extern int AddInt(IntPtr attributes, string key, int val); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_add_bool")] - internal static extern int AddBool(IntPtr state, string key, bool val); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_add_bool")] + internal static extern int AddBool(IntPtr attributes, string key, bool val); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_add_double")] - internal static extern int AddDouble(IntPtr state, string key, double val); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_add_double")] + internal static extern int AddDouble(IntPtr attributes, string key, double val); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_add_str")] - internal static extern int AddStr(IntPtr state, string key, string val); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_add_str")] + internal static extern int AddStr(IntPtr attributes, string key, string val); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_add_byte_str")] - internal static extern unsafe int AddByteStr(IntPtr state, string key, byte[] val, int len); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_add_byte_str")] + internal static extern int AddByteStr(IntPtr attributes, string key, byte[] val, int len); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_add_list")] - internal static extern int AddList(IntPtr state, string key, IntPtr list); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_add_list")] + internal static extern int AddList(IntPtr attributes, string key, IntPtr list); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_add_state")] - internal static extern int AddState(IntPtr dest, string key, IntPtr src); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_add_attributes")] + internal static extern int AddAttributes(IntPtr dest, string key, IntPtr src); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_add_null")] - internal static extern int AddNull(IntPtr state, string key); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_add_null")] + internal static extern int AddNull(IntPtr attributes, string key); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_get_int")] - internal static extern int GetInt(IntPtr state, string key, out int val); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_get_int")] + internal static extern int GetInt(IntPtr attributes, string key, out int val); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_get_bool")] - internal static extern int GetBool(IntPtr state, string key, out bool val); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_get_bool")] + internal static extern int GetBool(IntPtr attributes, string key, out bool val); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_get_double")] - internal static extern int GetDouble(IntPtr state, string key, out double val); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_get_double")] + internal static extern int GetDouble(IntPtr attributes, string key, out double val); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_get_str")] - internal static extern int GetStr(IntPtr state, string key, out string val); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_get_str")] + internal static extern int GetStr(IntPtr attributes, string key, out string val); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_get_byte_str")] - internal static extern int GetByteStr(IntPtr state, string key, out IntPtr value, out int size); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_get_byte_str")] + internal static extern int GetByteStr(IntPtr attributes, string key, out IntPtr value, out int size); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_get_list")] - internal static extern int GetList(IntPtr state, string key, out IntPtr list); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_get_list")] + internal static extern int GetList(IntPtr attributes, string key, out IntPtr list); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_get_state")] - internal static extern int GetState(IntPtr src, string key, out IntPtr dest); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_get_attributes")] + internal static extern int GetAttributes(IntPtr src, string key, out IntPtr dest); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_is_null")] - internal static extern int IsNull(IntPtr state, string key, out bool isNull); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_is_null")] + internal static extern int IsNull(IntPtr attributes, string key, out bool isNull); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_remove")] - internal static extern int Remove(IntPtr state, string key); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_remove")] + internal static extern int Remove(IntPtr attributes, string key); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_get_type")] - internal static extern int GetType(IntPtr state, string key, out DataType type); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_get_type")] + internal static extern int GetType(IntPtr attributes, string key, out DataType type); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_foreach")] - internal static extern int Foreach(IntPtr state, StateCallback cb, IntPtr userData); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_foreach")] + internal static extern int Foreach(IntPtr attributes, AttributesCallback cb, IntPtr userData); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_state_get_keys_count")] - internal static extern int GetKeysCount(IntPtr state, out int count); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_attributes_get_keys_count")] + internal static extern int GetKeysCount(IntPtr attributes, out int count); } internal static partial class Query @@ -161,10 +161,10 @@ internal static partial class Interop internal static extern void Destroy(IntPtr query); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_query_get_resource_type")] - internal static extern int GetResourceType(IntPtr query, out string resourceType); + internal static extern int GetResourceType(IntPtr query, out IntPtr resourceType); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_query_get_interface")] - internal static extern int GetInterface(IntPtr query, out string resourceInterface); + internal static extern int GetInterface(IntPtr query, out IntPtr resourceInterface); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_query_set_resource_type")] internal static extern int SetResourceType(IntPtr query, string resourceType); @@ -179,7 +179,7 @@ internal static partial class Interop internal static extern int Remove(IntPtr query, string key); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_query_lookup")] - internal static extern int Lookup(IntPtr query, string key, out string data); + internal static extern int Lookup(IntPtr query, string key, out IntPtr data); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_query_foreach")] internal static extern int Foreach(IntPtr query, QueryCallback cb, IntPtr userData); @@ -202,7 +202,7 @@ internal static partial class Interop internal static extern int SetUriPath(IntPtr repr, string uriPath); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_representation_get_uri_path")] - internal static extern int GetUriPath(IntPtr repr, out string uriPath); + internal static extern int GetUriPath(IntPtr repr, out IntPtr uriPath); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_representation_set_resource_types")] internal static extern int SetResourceTypes(IntPtr repr, IntPtr types); @@ -216,11 +216,11 @@ internal static partial class Interop [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_representation_get_resource_interfaces")] internal static extern int GetResourceInterfaces(IntPtr repr, out IntPtr ifaces); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_representation_set_state")] - internal static extern int SetState(IntPtr repr, IntPtr state); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_representation_set_attributes")] + internal static extern int SetAttributes(IntPtr repr, IntPtr attribs); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_representation_get_state")] - internal static extern int GetState(IntPtr repr, out IntPtr state); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_representation_get_attributes")] + internal static extern int GetAttributes(IntPtr repr, out IntPtr attribs); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_representation_add_child")] internal static extern int AddChild(IntPtr parent, IntPtr child); @@ -255,7 +255,7 @@ internal static partial class Interop internal static extern int Remove(IntPtr options, ushort id); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_options_lookup")] - internal static extern int Lookup(IntPtr options, ushort id, out string data); + internal static extern int Lookup(IntPtr options, ushort id, out IntPtr data); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_options_foreach")] internal static extern int ForEach(IntPtr options, OptionsCallback cb, IntPtr userData); @@ -275,7 +275,7 @@ internal static partial class Interop internal delegate bool ListCallback(int pos, IntPtr value, IntPtr userData); - internal delegate bool StateCallback(int pos, IntPtr value, IntPtr userData); + internal delegate bool AttribsCallback(int pos, IntPtr value, IntPtr userData); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_create")] internal static extern int Create(DataType type, out IntPtr list); @@ -301,8 +301,8 @@ internal static partial class Interop [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_add_list")] internal static extern int AddList(IntPtr list, IntPtr val, int pos); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_add_state")] - internal static extern int AddState(IntPtr list, IntPtr val, int pos); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_add_attributes")] + internal static extern int AddAttributes(IntPtr list, IntPtr val, int pos); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_get_nth_int")] internal static extern int GetNthInt(IntPtr list, int pos, out int val); @@ -314,16 +314,16 @@ internal static partial class Interop internal static extern int GetNthDouble(IntPtr list, int pos, out double val); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_get_nth_str")] - internal static extern int GetNthStr(IntPtr list, int pos, out string val); + internal static extern int GetNthStr(IntPtr list, int pos, out IntPtr val); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_get_nth_byte_str")] - internal static extern int GetNthByteStr(IntPtr list, int pos, out string val, out int len); + internal static extern int GetNthByteStr(IntPtr list, int pos, out IntPtr val, out int len); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_get_nth_list")] internal static extern int GetNthList(IntPtr src, int pos, out IntPtr dest); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_get_nth_state")] - internal static extern int GetNthState(IntPtr list, int pos, out IntPtr state); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_get_nth_attributes")] + internal static extern int GetNthAttributes(IntPtr list, int pos, out IntPtr attribs); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_remove_nth")] internal static extern int RemoveNth(IntPtr list, int pos); @@ -352,8 +352,8 @@ internal static partial class Interop [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_foreach_list")] internal static extern int ForeachList(IntPtr list, ListCallback cb, IntPtr userData); - [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_foreach_state")] - internal static extern int ForeachState(IntPtr list, StateCallback cb, IntPtr userData); + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_list_foreach_attributes")] + internal static extern int ForeachAttributes(IntPtr list, AttribsCallback cb, IntPtr userData); } } } diff --git a/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Server.cs b/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Server.cs index 8a85141..e7412a6 100755 --- a/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Server.cs +++ b/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Server.cs @@ -31,6 +31,9 @@ internal static partial class Interop [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_stop_presence")] internal static extern int StopPresence(); + + [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_set_device_name")] + internal static extern int SetDeviceName(string deviceName); } internal static partial class Resource @@ -68,7 +71,7 @@ internal static partial class Interop internal static extern int GetNthChild(IntPtr parent, int index, out IntPtr child); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_resource_get_uri_path")] - internal static extern int GetUriPath(IntPtr resource, out string uriPpath); + internal static extern int GetUriPath(IntPtr resource, out IntPtr uriPath); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_resource_get_types")] internal static extern int GetTypes(IntPtr resource, out IntPtr types); @@ -83,7 +86,7 @@ internal static partial class Interop internal static partial class Request { [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_request_get_host_address")] - internal static extern int GetHostAddress(IntPtr request, out string hostAddress); + internal static extern int GetHostAddress(IntPtr request, out IntPtr hostAddress); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_request_get_connectivity_type")] internal static extern int GetConnectivityType(IntPtr request, out int connectivityType); @@ -128,7 +131,7 @@ internal static partial class Interop internal static extern int SetResult(IntPtr resp, int result); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_response_set_representation")] - internal static extern int SetRepresentation(IntPtr resp, string iface, IntPtr repr); + internal static extern int SetRepresentation(IntPtr resp, IntPtr repr); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_response_set_options")] internal static extern int SetOptions(IntPtr resp, IntPtr options); diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity.csproj b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity.csproj index 95ad115..a7ef7f3 100644 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity.csproj +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity.csproj @@ -55,6 +55,7 @@ + @@ -71,7 +72,6 @@ - diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/State.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs old mode 100755 new mode 100644 similarity index 79% rename from src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/State.cs rename to src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs index 55c3cb2..6a6abaf --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/State.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs @@ -14,40 +14,40 @@ using System.Runtime.InteropServices; namespace Tizen.Network.IoTConnectivity { /// - /// State represents current state of a resource + /// Attributes represents current attributes of a resource /// - public class State : IDictionary, IDisposable + public class Attributes : IDictionary, IDisposable { - internal IntPtr _resourceStateHandle = IntPtr.Zero; - private readonly IDictionary _state = new Dictionary(); + internal IntPtr _resourceAttributesHandle = IntPtr.Zero; + private readonly IDictionary _attributes = new Dictionary(); private bool _disposed = false; /// /// Constructor /// - public State() + public Attributes() { - int ret = Interop.IoTConnectivity.Common.State.Create(out _resourceStateHandle); + int ret = Interop.IoTConnectivity.Common.Attributes.Create(out _resourceAttributesHandle); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create state handle"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create attributes handle"); throw IoTConnectivityErrorFactory.GetException(ret); } } - internal State(IntPtr stateHandleToClone) + internal Attributes(IntPtr attributesHandleToClone) { - int ret = Interop.IoTConnectivity.Common.State.Clone(stateHandleToClone, out _resourceStateHandle); + int ret = Interop.IoTConnectivity.Common.Attributes.Clone(attributesHandleToClone, out _resourceAttributesHandle); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create state handle"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create attributes handle"); throw IoTConnectivityErrorFactory.GetException(ret); } - SetState(stateHandleToClone); + SetAttributes(attributesHandleToClone); } - ~State() + ~Attributes() { Dispose(false); } @@ -59,18 +59,18 @@ namespace Tizen.Network.IoTConnectivity { get { - return _state.Count; + return _attributes.Count; } } /// - /// Represents whether State is readonly + /// Represents whether Attributes is readonly /// public bool IsReadOnly { get { - return _state.IsReadOnly; + return _attributes.IsReadOnly; } } @@ -81,7 +81,7 @@ namespace Tizen.Network.IoTConnectivity { get { - return _state.Keys; + return _attributes.Keys; } } @@ -92,7 +92,7 @@ namespace Tizen.Network.IoTConnectivity { get { - return _state.Values; + return _attributes.Values; } } @@ -105,7 +105,7 @@ namespace Tizen.Network.IoTConnectivity { get { - return _state[key]; + return _attributes[key]; } set @@ -126,33 +126,33 @@ namespace Tizen.Network.IoTConnectivity /// /// Adds status element /// - /// The key representing the state - /// The value representing the state + /// The key representing the attributes + /// The value representing the attributes public void Add(string key, object value) { int ret = 0; if (value is int) { - ret = Interop.IoTConnectivity.Common.State.AddInt(_resourceStateHandle, key, (int)value); + ret = Interop.IoTConnectivity.Common.Attributes.AddInt(_resourceAttributesHandle, key, (int)value); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add int"); throw IoTConnectivityErrorFactory.GetException(ret); } } - else if (value is State) + else if (value is Attributes) { - State state = (State)value; - ret = Interop.IoTConnectivity.Common.State.AddState(_resourceStateHandle, key, state._resourceStateHandle); + Attributes attribs = (Attributes)value; + ret = Interop.IoTConnectivity.Common.Attributes.AddAttributes(_resourceAttributesHandle, key, attribs._resourceAttributesHandle); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } } else if (value is string) { - ret = Interop.IoTConnectivity.Common.State.AddStr(_resourceStateHandle, key, (string)value); + ret = Interop.IoTConnectivity.Common.Attributes.AddStr(_resourceAttributesHandle, key, (string)value); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add string"); @@ -161,7 +161,7 @@ namespace Tizen.Network.IoTConnectivity } else if (value is double) { - ret = Interop.IoTConnectivity.Common.State.AddDouble(_resourceStateHandle, key, (double)value); + ret = Interop.IoTConnectivity.Common.Attributes.AddDouble(_resourceAttributesHandle, key, (double)value); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add double"); @@ -170,7 +170,7 @@ namespace Tizen.Network.IoTConnectivity } else if (value is bool) { - ret = Interop.IoTConnectivity.Common.State.AddBool(_resourceStateHandle, key, (bool)value); + ret = Interop.IoTConnectivity.Common.Attributes.AddBool(_resourceAttributesHandle, key, (bool)value); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool"); @@ -185,7 +185,7 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get byte[] val"); throw new ArgumentException("Invalid Parameter"); } - ret = Interop.IoTConnectivity.Common.State.AddByteStr(_resourceStateHandle, key, val, val.Length); + ret = Interop.IoTConnectivity.Common.Attributes.AddByteStr(_resourceAttributesHandle, key, val, val.Length); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool"); @@ -195,11 +195,10 @@ namespace Tizen.Network.IoTConnectivity else if (value is IEnumerable) { IntPtr listHandle = List.GetListHandle(value); - ret = Interop.IoTConnectivity.Common.State.AddList(_resourceStateHandle, key, listHandle); - Interop.IoTConnectivity.Common.State.Destroy(listHandle); + ret = Interop.IoTConnectivity.Common.Attributes.AddList(_resourceAttributesHandle, key, listHandle); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add list"); throw IoTConnectivityErrorFactory.GetException(ret); } } @@ -208,54 +207,54 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to Add"); throw IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.InvalidParameter); } - _state.Add(key, value); + _attributes.Add(key, value); } /// - /// Clears state collection + /// Clears attributes collection /// public void Clear() { - foreach (string key in _state.Keys) + foreach (string key in _attributes.Keys) { - int ret = Interop.IoTConnectivity.Common.State.Remove(_resourceStateHandle, key); + int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to clear state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to clear attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } } - _state.Clear(); + _attributes.Clear(); } /// - /// Checks the given key value pair exists in state collection + /// Checks the given key value pair exists in attributes collection /// /// The status key value pair /// true if exists. Otherwise, false public bool Contains(KeyValuePair item) { - return _state.Contains(item); + return _attributes.Contains(item); } /// - /// Checks the given key exists in state collection + /// Checks the given key exists in attributes collection /// /// The status key /// true if exists. Otherwise, false public bool ContainsKey(string key) { - return _state.ContainsKey(key); + return _attributes.ContainsKey(key); } /// - /// Copies the elements of the state to an Array, starting at a particular index. + /// Copies the elements of the attributes to an Array, starting at a particular index. /// /// The destination array /// The zero-based index in array at which copying begins. public void CopyTo(KeyValuePair[] array, int arrayIndex) { - _state.CopyTo(array, arrayIndex); + _attributes.CopyTo(array, arrayIndex); } /// @@ -264,41 +263,41 @@ namespace Tizen.Network.IoTConnectivity /// An enumerator that can be used to iterate through the collection. public IEnumerator> GetEnumerator() { - return _state.GetEnumerator(); + return _attributes.GetEnumerator(); } /// - /// Removes a state element from collection + /// Removes a attributes element from collection /// - /// The state element to remove + /// The attributes element to remove /// true if operation is success. Otherwise, false public bool Remove(KeyValuePair item) { - int ret = Interop.IoTConnectivity.Common.State.Remove(_resourceStateHandle, item.Key); + int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, item.Key); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } - return _state.Remove(item); + return _attributes.Remove(item); } /// - /// Removes a state element from collection using key + /// Removes a attributes element from collection using key /// - /// The state element to remove + /// The attributes element to remove /// true if operation is success. Otherwise, false public bool Remove(string key) { - int ret = Interop.IoTConnectivity.Common.State.Remove(_resourceStateHandle, key); + int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } - return _state.Remove(key); + return _attributes.Remove(key); } /// @@ -306,15 +305,15 @@ namespace Tizen.Network.IoTConnectivity /// /// The key whose value to get. /// The value associated with the specified key - /// true if the state collection contains an element with the specified key; otherwise, false. + /// true if the attributes collection contains an element with the specified key; otherwise, false. public bool TryGetValue(string key, out object value) { - return _state.TryGetValue(key, out value); + return _attributes.TryGetValue(key, out value); } IEnumerator IEnumerable.GetEnumerator() { - return _state.GetEnumerator(); + return _attributes.GetEnumerator(); } public void Dispose() @@ -333,30 +332,31 @@ namespace Tizen.Network.IoTConnectivity // Free managed objects } - Interop.IoTConnectivity.Common.State.Destroy(_resourceStateHandle); + Interop.IoTConnectivity.Common.Attributes.Destroy(_resourceAttributesHandle); _disposed = true; } - private void SetState(IntPtr stateHandle) + private void SetAttributes(IntPtr attributesHandle) { - Interop.IoTConnectivity.Common.State.StateCallback cb = (IntPtr state, string key, IntPtr userData) => + Interop.IoTConnectivity.Common.Attributes.AttributesCallback cb = (IntPtr attributes, string key, IntPtr userData) => { - Interop.IoTConnectivity.Common.DataType type = 0; - int ret = Interop.IoTConnectivity.Common.State.GetType(state, key, out type); + Interop.IoTConnectivity.Common.DataType dataType; + int ret = Interop.IoTConnectivity.Common.Attributes.GetType(attributes, key, out dataType); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type"); throw IoTConnectivityErrorFactory.GetException(ret); } - switch (type) + + switch ((Interop.IoTConnectivity.Common.DataType)dataType) { case Interop.IoTConnectivity.Common.DataType.Int: { int value; - ret = Interop.IoTConnectivity.Common.State.GetInt(state, key, out value); + ret = Interop.IoTConnectivity.Common.Attributes.GetInt(attributes, key, out value); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } Add(key, value); @@ -365,10 +365,10 @@ namespace Tizen.Network.IoTConnectivity case Interop.IoTConnectivity.Common.DataType.Bool: { bool value; - ret = Interop.IoTConnectivity.Common.State.GetBool(state, key, out value); + ret = Interop.IoTConnectivity.Common.Attributes.GetBool(attributes, key, out value); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } Add(key, value); @@ -377,10 +377,10 @@ namespace Tizen.Network.IoTConnectivity case Interop.IoTConnectivity.Common.DataType.Double: { double value; - ret = Interop.IoTConnectivity.Common.State.GetDouble(state, key, out value); + ret = Interop.IoTConnectivity.Common.Attributes.GetDouble(attributes, key, out value); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } Add(key, value); @@ -389,10 +389,10 @@ namespace Tizen.Network.IoTConnectivity case Interop.IoTConnectivity.Common.DataType.String: { string value; - ret = Interop.IoTConnectivity.Common.State.GetStr(state, key, out value); + ret = Interop.IoTConnectivity.Common.Attributes.GetStr(attributes, key, out value); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } Add(key, value); @@ -402,10 +402,10 @@ namespace Tizen.Network.IoTConnectivity { IntPtr byteStrPtr; int byteStrSize; - ret = Interop.IoTConnectivity.Common.State.GetByteStr(state, key, out byteStrPtr, out byteStrSize); + ret = Interop.IoTConnectivity.Common.Attributes.GetByteStr(attributes, key, out byteStrPtr, out byteStrSize); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } byte[] byteStr = new byte[byteStrSize]; @@ -421,25 +421,25 @@ namespace Tizen.Network.IoTConnectivity case Interop.IoTConnectivity.Common.DataType.List: { IntPtr listHandle; - ret = Interop.IoTConnectivity.Common.State.GetList(state, key, out listHandle); + ret = Interop.IoTConnectivity.Common.Attributes.GetList(attributes, key, out listHandle); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } Add(key, List.GetList(listHandle)); break; } - case Interop.IoTConnectivity.Common.DataType.State: + case Interop.IoTConnectivity.Common.DataType.Attributes: { - IntPtr stateHndle; - ret = Interop.IoTConnectivity.Common.State.GetState(state, key, out stateHndle); + IntPtr attribsHandle; + ret = Interop.IoTConnectivity.Common.Attributes.GetAttributes(attributes, key, out attribsHandle); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } - Add(key, new State(stateHndle)); + Add(key, new Attributes(attribsHandle)); break; } default: @@ -449,10 +449,10 @@ namespace Tizen.Network.IoTConnectivity return true; }; - int res = Interop.IoTConnectivity.Common.State.Foreach(stateHandle, cb, IntPtr.Zero); + int res = Interop.IoTConnectivity.Common.Attributes.Foreach(attributesHandle, cb, IntPtr.Zero); if (res != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes"); throw IoTConnectivityErrorFactory.GetException(res); } } @@ -476,7 +476,7 @@ namespace Tizen.Network.IoTConnectivity ret = Interop.IoTConnectivity.Common.List.AddList(listHandle, childList, pos++); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes"); Interop.IoTConnectivity.Common.List.Destroy(childList); throw IoTConnectivityErrorFactory.GetException(ret); } @@ -491,7 +491,7 @@ namespace Tizen.Network.IoTConnectivity ret = Interop.IoTConnectivity.Common.List.AddInt(listHandle, val, pos++); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } } @@ -505,7 +505,7 @@ namespace Tizen.Network.IoTConnectivity ret = Interop.IoTConnectivity.Common.List.AddStr(listHandle, val, pos++); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add str"); throw IoTConnectivityErrorFactory.GetException(ret); } } @@ -519,7 +519,7 @@ namespace Tizen.Network.IoTConnectivity ret = Interop.IoTConnectivity.Common.List.AddDouble(listHandle, val, pos++); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add double"); throw IoTConnectivityErrorFactory.GetException(ret); } } @@ -533,21 +533,21 @@ namespace Tizen.Network.IoTConnectivity ret = Interop.IoTConnectivity.Common.List.AddBool(listHandle, val, pos++); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add bool"); throw IoTConnectivityErrorFactory.GetException(ret); } } } - else if (list is IEnumerable) + else if (list is IEnumerable) { - ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.State, out listHandle); + ret = Interop.IoTConnectivity.Common.List.Create(Interop.IoTConnectivity.Common.DataType.Attributes, out listHandle); pos = 0; - foreach (State val in (IEnumerable)list) + foreach (Attributes val in (IEnumerable)list) { - ret = Interop.IoTConnectivity.Common.List.AddState(listHandle, val._resourceStateHandle, pos++); + ret = Interop.IoTConnectivity.Common.List.AddAttributes(listHandle, val._resourceAttributesHandle, pos++); if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } } @@ -630,15 +630,15 @@ namespace Tizen.Network.IoTConnectivity ret = Interop.IoTConnectivity.Common.List.ForeachStr(listHandle, cb, IntPtr.Zero); break; } - case Interop.IoTConnectivity.Common.DataType.State: + case Interop.IoTConnectivity.Common.DataType.Attributes: { - list = new List(); - Interop.IoTConnectivity.Common.List.StateCallback cb = (int pos, IntPtr value, IntPtr userData) => + list = new List(); + Interop.IoTConnectivity.Common.List.AttribsCallback cb = (int pos, IntPtr value, IntPtr userData) => { - list.Add(new State(value)); + list.Add(new Attributes(value)); return true; }; - ret = Interop.IoTConnectivity.Common.List.ForeachState(listHandle, cb, IntPtr.Zero); + ret = Interop.IoTConnectivity.Common.List.ForeachAttributes(listHandle, cb, IntPtr.Zero); break; } case Interop.IoTConnectivity.Common.DataType.ByteStr: @@ -669,7 +669,7 @@ namespace Tizen.Network.IoTConnectivity } if (ret != (int)IoTConnectivityError.None) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get state"); + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes"); throw IoTConnectivityErrorFactory.GetException(ret); } return list; diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs index 6b55115..0152de7 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; +using System.Runtime.InteropServices; namespace Tizen.Network.IoTConnectivity { @@ -77,6 +78,33 @@ namespace Tizen.Network.IoTConnectivity } /// + /// Timeout property + /// + public static int PollingInterval + { + get + { + int interval; + int ret = Interop.IoTConnectivity.Client.IoTCon.GetPollingInterval(out interval); + if (ret != (int)IoTConnectivityError.None) + { + Log.Warn(IoTConnectivityErrorFactory.LogTag, "Failed to get polling interval"); + return 0; + } + return interval; + } + set + { + int ret = Interop.IoTConnectivity.Client.IoTCon.SetPollingInterval(value); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to set polling interval"); + throw IoTConnectivityErrorFactory.GetException(ret); + } + } + } + + /// /// Connects to the iotcon service /// public static void Initialize() @@ -90,6 +118,19 @@ namespace Tizen.Network.IoTConnectivity } /// + /// Initializes IoTCon with secure mode. + /// + public static void SecureInitialize(string filePath) + { + int ret = Interop.IoTConnectivity.Client.IoTCon.SecureInitialize(filePath); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to initialize securely"); + throw IoTConnectivityErrorFactory.GetException(ret); + } + } + + /// /// Disconnects from the iotcon service /// public static void Deinitialize() @@ -98,6 +139,19 @@ namespace Tizen.Network.IoTConnectivity } /// + /// Invokes a next message from a queue for receiving messages from others, immediately. + /// + public static void InvokePolling() + { + int ret = Interop.IoTConnectivity.Client.IoTCon.InvokePolling(); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to invoke polling"); + throw IoTConnectivityErrorFactory.GetException(ret); + } + } + + /// /// Starts receiving presence events /// /// @@ -215,7 +269,6 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Invalid type"); throw new ArgumentException("Invalid type"); } - IntPtr id = IntPtr.Zero; lock (s_resourceFoundCallbacksMap) { @@ -257,7 +310,6 @@ namespace Tizen.Network.IoTConnectivity } } }; - int errorCode = Interop.IoTConnectivity.Client.ResourceFinder.AddResourceFoundCb(hostAddress, (int)connectivityType, resourceType, isSecure, s_resourceFoundCallbacksMap[id], id); if (errorCode != (int)IoTConnectivityError.None) { @@ -319,7 +371,7 @@ namespace Tizen.Network.IoTConnectivity } }; - int errorCode = Interop.IoTConnectivity.Client.DeviceInformation.Get(hostAddress, (int)connectivityType, s_deviceInformationCallbacksMap[id], id); + int errorCode = Interop.IoTConnectivity.Client.DeviceInformation.Find(hostAddress, (int)connectivityType, s_deviceInformationCallbacksMap[id], id); if (errorCode != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get device information"); @@ -381,7 +433,7 @@ namespace Tizen.Network.IoTConnectivity } }; - int errorCode = Interop.IoTConnectivity.Client.PlatformInformation.Get(hostAddress, (int)connectivityType, s_platformInformationCallbacksMap[id], id); + int errorCode = Interop.IoTConnectivity.Client.PlatformInformation.Find(hostAddress, (int)connectivityType, s_platformInformationCallbacksMap[id], id); if (errorCode != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get platform information"); @@ -398,7 +450,7 @@ namespace Tizen.Network.IoTConnectivity private static PresenceReceivedEventArgs GetPresenceReceivedEventArgs(int presenceId, IntPtr presenceResponseHandle) { int trigger; - string host, type; + IntPtr host, type; int ret = Interop.IoTConnectivity.Client.PresenceResponse.GetHostAddress(presenceResponseHandle, out host); if (ret != (int)IoTConnectivityError.None) @@ -424,8 +476,8 @@ namespace Tizen.Network.IoTConnectivity PresenceReceivedEventArgs e = new PresenceReceivedEventArgs() { PresenceId = presenceId, - HostAddress = host, - Type = type, + HostAddress = Marshal.PtrToStringAuto(host), + Type = Marshal.PtrToStringAuto(type), EventType = (PresenceEventType)trigger }; @@ -434,7 +486,7 @@ namespace Tizen.Network.IoTConnectivity private static DeviceInformationFoundEventArgs GetDeviceInformationFoundEventArgs(int requestId, IntPtr deviceInfoHandle) { - string name, specVersion, deviceId, dataModelVersion; + IntPtr name, specVersion, deviceId, dataModelVersion; int ret = Interop.IoTConnectivity.Client.DeviceInformation.GetProperty(deviceInfoHandle, (int)Interop.IoTConnectivity.Client.DeviceInformation.Property.Name, out name); if (ret != (int)IoTConnectivityError.None) @@ -467,10 +519,10 @@ namespace Tizen.Network.IoTConnectivity DeviceInformationFoundEventArgs e = new DeviceInformationFoundEventArgs() { RequestId = requestId, - Name = name, - SpecVersion = specVersion, - DeviceId = deviceId, - DataModelVersion = dataModelVersion + Name = Marshal.PtrToStringAuto(name), + SpecVersion = Marshal.PtrToStringAuto(specVersion), + DeviceId = Marshal.PtrToStringAuto(deviceId), + DataModelVersion = Marshal.PtrToStringAuto(dataModelVersion) }; return e; @@ -478,7 +530,7 @@ namespace Tizen.Network.IoTConnectivity private static PlatformInformationFoundEventArgs GetPlatformInformationFoundEventArgs(int requestId, IntPtr platformInfoHandle) { - string platformId, manufacturerName, manufacturerUrl, modelNumber, dateOfManufacture, platformVersion, osVersion, hardwareVersion, firmwareVersion, supportUrl, systemTime; + IntPtr platformId, manufacturerName, manufacturerUrl, modelNumber, dateOfManufacture, platformVersion, osVersion, hardwareVersion, firmwareVersion, supportUrl, systemTime; int ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.Id, out platformId); if (ret != (int)IoTConnectivityError.None) @@ -560,17 +612,17 @@ namespace Tizen.Network.IoTConnectivity PlatformInformationFoundEventArgs e = new PlatformInformationFoundEventArgs() { RequestId = requestId, - PlatformId = platformId, - ManufacturerName = manufacturerName, - ManufacturerURL = manufacturerUrl, - DateOfManufacture = dateOfManufacture, - ModelNumber = modelNumber, - PlatformVersion = platformVersion, - OsVersion = osVersion, - HardwareVersion = hardwareVersion, - FirmwareVersion = firmwareVersion, - SupportUrl = supportUrl, - SystemTime = systemTime + PlatformId = Marshal.PtrToStringAuto(platformId), + ManufacturerName = Marshal.PtrToStringAuto(manufacturerName), + ManufacturerURL = Marshal.PtrToStringAuto(manufacturerUrl), + DateOfManufacture = Marshal.PtrToStringAuto(dateOfManufacture), + ModelNumber = Marshal.PtrToStringAuto(modelNumber), + PlatformVersion = Marshal.PtrToStringAuto(platformVersion), + OsVersion = Marshal.PtrToStringAuto(osVersion), + HardwareVersion = Marshal.PtrToStringAuto(hardwareVersion), + FirmwareVersion = Marshal.PtrToStringAuto(firmwareVersion), + SupportUrl = Marshal.PtrToStringAuto(supportUrl), + SystemTime = Marshal.PtrToStringAuto(systemTime) }; return e; diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs index 11f3320..a24ca7c 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs @@ -81,5 +81,19 @@ namespace Tizen.Network.IoTConnectivity throw IoTConnectivityErrorFactory.GetException(ret); } } + + /// + /// Sets the device name + /// + /// The device name + public static void SetDeviceName(string deviceName) + { + int ret = Interop.IoTConnectivity.Server.IoTCon.SetDeviceName(deviceName); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed set device name"); + throw IoTConnectivityErrorFactory.GetException(ret); + } + } } } diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/LiteResource.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/LiteResource.cs index e55b823..53f20e9 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/LiteResource.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/LiteResource.cs @@ -18,24 +18,24 @@ namespace Tizen.Network.IoTConnectivity /// The uri path of the lite resource /// Resource type /// Policy of the resource - /// Optional State of the resource - public LiteResource(string uri, ResourceTypes types, ResourcePolicy policy, State state = null) + /// Optional attributes of the resource + public LiteResource(string uri, ResourceTypes types, ResourcePolicy policy, Attributes attribs = null) : base(uri, types, new ResourceInterfaces(new string[] { ResourceInterfaces.DefaultInterface }), policy) { - State = state; + Attributes = attribs; } /// - /// The state of the lite resource + /// The attributes of the lite resource /// - public State State { get; set; } + public Attributes Attributes { get; set; } /// /// The method to accept post request /// - /// The new state of the lite resource + /// The new attributes of the lite resource /// true to accept post request, false to reject it - public virtual bool OnPost(State state) + public virtual bool OnPost(Attributes attribs) { return true; } @@ -51,7 +51,7 @@ namespace Tizen.Network.IoTConnectivity UriPath = UriPath, Interface = Interfaces, Type = Types, - State = State + Attributes = Attributes }; Response response = new Response() @@ -80,14 +80,14 @@ namespace Tizen.Network.IoTConnectivity /// Request. public sealed override Response OnPost(Request request) { - if (OnPost(request.Representation.State)) + if (OnPost(request.Representation.Attributes)) { - State = request.Representation.State; + Attributes = request.Representation.Attributes; Representation representation = new Representation() { UriPath = UriPath, Interface = Interfaces, Type = Types, - State = State + Attributes = Attributes }; Response response = new Response() { diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs index fcfc6f0..1a44fe8 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Net; +using System.Runtime.InteropServices; using System.Threading.Tasks; namespace Tizen.Network.IoTConnectivity @@ -130,6 +131,11 @@ namespace Tizen.Network.IoTConnectivity public ResourcePolicy Policy { get; private set; } /// + /// The device name of the remote resource + /// + public string DeviceName { get; private set; } + + /// /// The header options of the resource /// public ResourceOptions Options @@ -180,7 +186,7 @@ namespace Tizen.Network.IoTConnectivity get { int interval; - int ret = Interop.IoTConnectivity.Client.RemoteResource.GetTimeInterval(_remoteResourceHandle, out interval); + int ret = Interop.IoTConnectivity.Client.RemoteResource.GetTimeInterval(out interval); if (ret != (int)IoTConnectivityError.None) { Log.Warn(IoTConnectivityErrorFactory.LogTag, "Failed to get time interval"); @@ -193,7 +199,7 @@ namespace Tizen.Network.IoTConnectivity int ret = (int)IoTConnectivityError.InvalidParameter; if (value < TimeOutMax && value > 0) { - ret = Interop.IoTConnectivity.Client.RemoteResource.SetTimeInterval(_remoteResourceHandle, value); + ret = Interop.IoTConnectivity.Client.RemoteResource.SetTimeInterval(value); } if (ret != (int)IoTConnectivityError.None) { @@ -513,7 +519,16 @@ namespace Tizen.Network.IoTConnectivity else { IPAddress address; - if (IPAddress.TryParse(hostAddress, out address)) + string hostName = hostAddress; + if (hostAddress.Contains(":")) + { + string[] hostParts = hostAddress.Split(':'); + if (hostParts.Length == 2) + { + hostName = hostParts[0]; + } + } + if (IPAddress.TryParse(hostName, out address)) { switch (address.AddressFamily) { @@ -634,19 +649,28 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get remote resource"); throw IoTConnectivityErrorFactory.GetException(ret); } + + /*IntPtr deviceName; + ret = Interop.IoTConnectivity.Client.RemoteResource.GetDeviceName(_remoteResourceHandle, out deviceName); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get device name of remote resource"); + throw IoTConnectivityErrorFactory.GetException(ret); + } + DeviceName = Marshal.PtrToStringAuto(deviceName);*/ } private void SetRemoteResource() { - string hostAddress, uriPath; - int ret = Interop.IoTConnectivity.Client.RemoteResource.GetHostAddress(_remoteResourceHandle, out hostAddress); + IntPtr hostAddressPtr, uriPathPtr; + int ret = Interop.IoTConnectivity.Client.RemoteResource.GetHostAddress(_remoteResourceHandle, out hostAddressPtr); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Faled to get host address"); throw IoTConnectivityErrorFactory.GetException(ret); } - ret = Interop.IoTConnectivity.Client.RemoteResource.GetUriPath(_remoteResourceHandle, out uriPath); + ret = Interop.IoTConnectivity.Client.RemoteResource.GetUriPath(_remoteResourceHandle, out uriPathPtr); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Faled to get uri path"); @@ -654,7 +678,7 @@ namespace Tizen.Network.IoTConnectivity } int policy = (int)ResourcePolicy.NoProperty; - ret = Interop.IoTConnectivity.Client.RemoteResource.GetProperties(_remoteResourceHandle, out policy); + ret = Interop.IoTConnectivity.Client.RemoteResource.GetPolicies(_remoteResourceHandle, out policy); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Faled to get uri path"); @@ -676,17 +700,24 @@ namespace Tizen.Network.IoTConnectivity throw IoTConnectivityErrorFactory.GetException(ret); } - string deviceId; - ret = Interop.IoTConnectivity.Client.RemoteResource.GetDeviceId(_remoteResourceHandle, out deviceId); + IntPtr deviceIdPtr; + ret = Interop.IoTConnectivity.Client.RemoteResource.GetDeviceId(_remoteResourceHandle, out deviceIdPtr); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get device id"); throw IoTConnectivityErrorFactory.GetException(ret); } - - DeviceId = deviceId; - HostAddress = hostAddress; - UriPath = uriPath; + IntPtr deviceName; + ret = Interop.IoTConnectivity.Client.RemoteResource.GetDeviceName(_remoteResourceHandle, out deviceName); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get device name of remote resource"); + throw IoTConnectivityErrorFactory.GetException(ret); + } + DeviceName = Marshal.PtrToStringAuto(deviceName); + DeviceId = Marshal.PtrToStringAuto(deviceIdPtr); + HostAddress = Marshal.PtrToStringAuto(hostAddressPtr); + UriPath = Marshal.PtrToStringAuto(uriPathPtr); Types = new ResourceTypes(typesHandle); Interfaces = new ResourceInterfaces(interfacesHandle); Policy = (ResourcePolicy)policy; @@ -716,12 +747,11 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get options"); throw IoTConnectivityErrorFactory.GetException(ret); } - return new RemoteResponse() { Result = (ResponseCode)result, Representation = new Representation(representationHandle), - Options = new ResourceOptions(optionsHandle) + Options = (optionsHandle == IntPtr.Zero)? null : new ResourceOptions(optionsHandle) }; } } diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs index 7297875..444dea7 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Runtime.InteropServices; namespace Tizen.Network.IoTConnectivity { @@ -66,14 +67,14 @@ namespace Tizen.Network.IoTConnectivity { get { - string path; + IntPtr path; int ret = Interop.IoTConnectivity.Common.Representation.GetUriPath(_representationHandle, out path); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to Get uri"); throw IoTConnectivityErrorFactory.GetException(ret); } - return path; + return Marshal.PtrToStringAuto(path); } set { @@ -125,7 +126,7 @@ namespace Tizen.Network.IoTConnectivity get { IntPtr interfaceHandle; - int ret = Interop.IoTConnectivity.Common.Representation.GetResourceTypes(_representationHandle, out interfaceHandle); + int ret = Interop.IoTConnectivity.Common.Representation.GetResourceInterfaces(_representationHandle, out interfaceHandle); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get interface"); @@ -137,7 +138,7 @@ namespace Tizen.Network.IoTConnectivity { int ret = (int)IoTConnectivityError.InvalidParameter; if (value != null) - ret = Interop.IoTConnectivity.Common.Representation.SetResourceTypes(_representationHandle, value.ResourceInterfacesHandle); + ret = Interop.IoTConnectivity.Common.Representation.SetResourceInterfaces(_representationHandle, value.ResourceInterfacesHandle); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to set interface"); @@ -147,24 +148,32 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Current state of the resource + /// Current attributes of the resource /// - public State State + public Attributes Attributes { get { - return State; + IntPtr attributeHandle; + int ret = Interop.IoTConnectivity.Common.Representation.GetAttributes(_representationHandle, out attributeHandle); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get attributes"); + throw IoTConnectivityErrorFactory.GetException(ret); + } + return new Attributes(attributeHandle); } set { - State = value; int ret = (int)IoTConnectivityError.InvalidParameter; - if (State != null) - ret = Interop.IoTConnectivity.Common.Representation.SetState(_representationHandle, State._resourceStateHandle); - if (ret != (int)IoTConnectivityError.None) + if (value != null) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to set interface"); - throw IoTConnectivityErrorFactory.GetException(ret); + ret = Interop.IoTConnectivity.Common.Representation.SetAttributes(_representationHandle, value._resourceAttributesHandle); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to set attributes"); + throw IoTConnectivityErrorFactory.GetException(ret); + } } } } @@ -194,9 +203,9 @@ namespace Tizen.Network.IoTConnectivity if (disposing) { // Free managed objects - Type.Dispose(); - Interface.Dispose(); - State?.Dispose(); + Type?.Dispose(); + Interface?.Dispose(); + Attributes?.Dispose(); } Interop.IoTConnectivity.Common.Representation.Destroy(_representationHandle); @@ -210,7 +219,11 @@ namespace Tizen.Network.IoTConnectivity foreach (Representation r in e.NewItems) { int ret = Interop.IoTConnectivity.Common.Representation.AddChild(_representationHandle, r._representationHandle); - throw IoTConnectivityErrorFactory.GetException(ret); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add child"); + throw IoTConnectivityErrorFactory.GetException(ret); + } } } else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove) @@ -218,7 +231,11 @@ namespace Tizen.Network.IoTConnectivity foreach (Representation r in e.NewItems) { int ret = Interop.IoTConnectivity.Common.Representation.RemoveChild(_representationHandle, r._representationHandle); - throw IoTConnectivityErrorFactory.GetException(ret); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove child"); + throw IoTConnectivityErrorFactory.GetException(ret); + } } } } diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Request.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Request.cs index fa46360..eeefc63 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Request.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Request.cs @@ -13,7 +13,7 @@ namespace Tizen.Network.IoTConnectivity /// /// Class respresenting Request to a resource /// - public class Request: IDisposable + public class Request : IDisposable { private bool _disposed = false; @@ -55,9 +55,9 @@ namespace Tizen.Network.IoTConnectivity if (disposing) { - Representation.Dispose(); - Query.Dispose(); - Options.Dispose(); + Representation?.Dispose(); + Query?.Dispose(); + Options?.Dispose(); } _disposed = true; diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs index 6c1b12a..af34202 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Runtime.InteropServices; namespace Tizen.Network.IoTConnectivity { @@ -152,12 +153,14 @@ namespace Tizen.Network.IoTConnectivity if (disposing) { - Types.Dispose(); - Interfaces.Dispose(); + Types?.Dispose(); + Interfaces?.Dispose(); } - Interop.IoTConnectivity.Server.Resource.Destroy(_resourceHandle); - Interop.IoTConnectivity.Server.Observers.Destroy(_observerHandle); + if (_resourceHandle != IntPtr.Zero) + Interop.IoTConnectivity.Server.Resource.Destroy(_resourceHandle); + if (_observerHandle != IntPtr.Zero) + Interop.IoTConnectivity.Server.Observers.Destroy(_observerHandle); _disposed = true; } @@ -280,15 +283,15 @@ namespace Tizen.Network.IoTConnectivity } finally { - request.Dispose(); + request?.Dispose(); response?.Dispose(); } } private Request GetRequest(IntPtr requestHandle) { - string hostAddress; - int ret = Interop.IoTConnectivity.Server.Request.GetHostAddress(requestHandle, out hostAddress); + IntPtr hostAddressPtr; + int ret = Interop.IoTConnectivity.Server.Request.GetHostAddress(requestHandle, out hostAddressPtr); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to Get host address"); @@ -354,7 +357,7 @@ namespace Tizen.Network.IoTConnectivity return new Request() { - HostAddress = hostAddress, + HostAddress = Marshal.PtrToStringAuto(hostAddressPtr), Options = opts, Query = query, Representation = representation diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs index 3f0e2bf..1f0e5e1 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs @@ -9,6 +9,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.InteropServices; namespace Tizen.Network.IoTConnectivity { @@ -70,14 +71,14 @@ namespace Tizen.Network.IoTConnectivity { get { - string type; + IntPtr type; int ret = Interop.IoTConnectivity.Common.Query.GetResourceType(_resourceQueryHandle, out type); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type"); throw IoTConnectivityErrorFactory.GetException(ret); } - return type; + return Marshal.PtrToStringAuto(type); } set { @@ -100,14 +101,14 @@ namespace Tizen.Network.IoTConnectivity { get { - string iface; + IntPtr iface; int ret = Interop.IoTConnectivity.Common.Query.GetInterface(_resourceQueryHandle, out iface); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get interface"); throw IoTConnectivityErrorFactory.GetException(ret); } - return iface; + return Marshal.PtrToStringAuto(iface); } set { diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Response.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Response.cs index 4120cc7..cf5a3dd 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Response.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Response.cs @@ -56,14 +56,15 @@ namespace Tizen.Network.IoTConnectivity return false; } - string iface = "oic.if.baseline"; - // TODO: iface parameter will be removed after native API is changed - ret = Interop.IoTConnectivity.Server.Response.SetRepresentation(responseHandle, iface, Representation._representationHandle); - if (ret != (int)IoTConnectivityError.None) + if (Representation != null) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response"); - Interop.IoTConnectivity.Server.Response.Destroy(responseHandle); - return false; + ret = Interop.IoTConnectivity.Server.Response.SetRepresentation(responseHandle, Representation._representationHandle); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send response"); + Interop.IoTConnectivity.Server.Response.Destroy(responseHandle); + return false; + } } ret = Interop.IoTConnectivity.Server.Response.Send(responseHandle); @@ -85,7 +86,6 @@ namespace Tizen.Network.IoTConnectivity if (disposing) { - Representation?.Dispose(); } _disposed = true; -- 2.7.4