From c52980e845ddd0ba013514348380d21954f07cc9 Mon Sep 17 00:00:00 2001 From: rajeev ranjan Date: Wed, 20 Jul 2016 15:25:51 +0530 Subject: [PATCH] Added Doxygen comments, incorporated recent CAPI changes Change-Id: Ib5a97c92c7bd7cc35d2f93e130cfa6f74d503e7d Signed-off-by: rajeev ranjan --- .../Interop/Interop.IoTConnectivity.Client.cs | 11 +- .../Tizen.Network.IoTConnectivity/Attributes.cs | 193 +++++++++--- .../CacheUpdatedEventArgs.cs | 3 +- .../DeviceInformationFoundEventArgs.cs | 2 +- .../FindingErrorOccurredEventArgs.cs | 6 +- .../IoTConnectivityClientManager.cs | 329 +++++++++++++++++---- .../IoTConnectivityErrorFactory.cs | 65 +--- .../IoTConnectivityServerManager.cs | 110 ++++++- .../Tizen.Network.IoTConnectivity/LiteResource.cs | 84 ++++-- .../Tizen.Network.IoTConnectivity/ObservePolicy.cs | 2 +- .../Tizen.Network.IoTConnectivity/ObserveType.cs | 2 +- .../ObserverNotifiedEventArgs.cs | 6 +- .../PlatformInformationFoundEventArgs.cs | 24 +- .../PresenceEventType.cs | 4 +- .../PresenceReceivedEventArgs.cs | 12 +- .../QualityOfService.cs | 2 +- .../RemoteResource.cs | 88 ++++-- .../RemoteResponse.cs | 3 + .../Representation.cs | 93 +++++- .../Tizen.Network.IoTConnectivity/Request.cs | 11 + .../Tizen.Network.IoTConnectivity/Resource.cs | 105 +++++-- .../ResourceFoundEventArgs.cs | 9 +- .../ResourceInterfaces.cs | 100 +++++-- .../ResourceOptions.cs | 187 ++++++++++-- .../Tizen.Network.IoTConnectivity/ResourceQuery.cs | 231 ++++++++++++--- .../Tizen.Network.IoTConnectivity/ResourceTypes.cs | 97 ++++-- .../Tizen.Network.IoTConnectivity/Response.cs | 39 ++- .../Tizen.Network.IoTConnectivity/ResponseCode.cs | 8 +- .../StateChangedEventArgs.cs | 3 +- 29 files changed, 1443 insertions(+), 386 deletions(-) mode change 100644 => 100755 src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs diff --git a/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Client.cs b/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Client.cs index e5c0dc6..22b7c96 100755 --- a/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Client.cs +++ b/src/Tizen.Network.IoTConnectivity/Interop/Interop.IoTConnectivity.Client.cs @@ -17,7 +17,7 @@ internal static partial class Interop { internal static partial class DeviceInformation { - internal delegate void DeviceInformationCallback(IntPtr deviceInfoHandle, int result, IntPtr userData); + internal delegate bool DeviceInformationCallback(IntPtr deviceInfoHandle, int result, IntPtr userData); internal enum Property { @@ -36,7 +36,7 @@ internal static partial class Interop internal static partial class PlatformInformation { - internal delegate void PlatformInformationCallback(IntPtr platformInfoHandle, int result, IntPtr userData); + internal delegate bool PlatformInformationCallback(IntPtr platformInfoHandle, int result, IntPtr userData); internal enum Propery { @@ -162,11 +162,8 @@ internal static partial class Interop 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(); + internal static extern int Initialize(string filePath); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_deinitialize")] internal static extern void Deinitialize(); @@ -190,7 +187,7 @@ internal static partial class Interop internal static partial class ResourceFinder { [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void FoundResourceCallback(IntPtr remoteResourceHandle, int result, IntPtr userData); + internal delegate bool FoundResourceCallback(IntPtr remoteResourceHandle, int result, IntPtr userData); [DllImport(Libraries.IoTCon, EntryPoint = "iotcon_find_resource")] internal static extern int AddResourceFoundCb(string hostAddress, int connectivityType, string resourceType, bool isSecure, FoundResourceCallback cb, IntPtr userData); diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs old mode 100644 new mode 100755 index 23e32c5..fdeb8d1 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Attributes.cs @@ -15,6 +15,8 @@ namespace Tizen.Network.IoTConnectivity { /// /// This class represents current attributes of a resource. + /// It provides API to manage attributes. + /// This class is accessed by using a constructor to create a new instance of this object. /// public class Attributes : IDictionary, IDisposable { @@ -23,8 +25,11 @@ namespace Tizen.Network.IoTConnectivity private bool _disposed = false; /// - /// Constructor + /// The Attributes constructor /// + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes(); + /// public Attributes() { int ret = Interop.IoTConnectivity.Common.Attributes.Create(out _resourceAttributesHandle); @@ -47,14 +52,23 @@ namespace Tizen.Network.IoTConnectivity SetAttributes(attributesHandleToClone); } + /// + /// Destructor of the Attributes class. + /// ~Attributes() { Dispose(false); } /// - /// Gets the number of status elements + /// Gets the number of keys /// + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { + /// attributes.Add("brightness", 50); + /// var count = attributes.Count; + /// Console.WriteLine("There are {0} keys in the attribute object", count); + /// public int Count { get @@ -64,8 +78,16 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Represents whether Attributes is readonly + /// Represents whether attribute is readonly /// + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { + /// { "state", "ON" }, + /// { "dim", 10 } + /// }; + /// if (attributes.IsReadOnly) + /// Console.WriteLine("Read only attribute"); + /// public bool IsReadOnly { get @@ -75,8 +97,16 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Contains all the status keys + /// Contains all the attribute keys /// + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { + /// { "state", "ON" }, + /// { "dim", 10 } + /// }; + /// var keys = attributes.Keys; + /// Console.WriteLine("Attribute contains keys {0} and {1}", keys.ElementAt(0), keys.ElementAt(1)); + /// public ICollection Keys { get @@ -86,8 +116,16 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Contains all the status values + /// Contains all the attribute values /// + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { + /// { "state", "ON" }, + /// { "dim", 10 } + /// }; + /// var values = attributes.Values; + /// Console.WriteLine("Attribute contains values {0} and {1}", values.ElementAt(0), values.ElementAt(1)); + /// public ICollection Values { get @@ -97,15 +135,23 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Gets or sets the status with the specified key. + /// Gets or sets the attribute with the specified key. /// - /// The key of the status to get or set. + /// The key of the attribute to get or set. /// The element with the specified key. + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes(); + /// attributes["state"] = "ON"; + /// Console.WriteLine("Attribute value for key 'state' : {0}", attributes["state"]); + /// public object this[string key] { get { - return _attributes[key]; + if (_attributes.ContainsKey(key)) + return _attributes[key]; + else + return null; } set @@ -115,19 +161,27 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Adds status key and value as a key value pair + /// Adds attribute key and value as a key value pair /// - /// The item to add + /// The key value pair to add + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes(); + /// attributes.Add(new KeyValuePair ("state", "ON")); + /// public void Add(KeyValuePair item) { Add(item.Key, item.Value); } /// - /// Adds status element + /// Adds an attribute /// - /// The key representing the attributes - /// The value representing the attributes + /// The key representing the attribute + /// The value representing the attribute + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes(); + /// attributes.Add("brightness", 50); + /// public void Add(string key, object value) { int ret = 0; @@ -213,6 +267,11 @@ namespace Tizen.Network.IoTConnectivity /// /// Clears attributes collection /// + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes(); + /// attributes.Add("brightness", 50); + /// attributes.Clear(); + /// public void Clear() { foreach (string key in _attributes.Keys) @@ -228,30 +287,56 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Checks the given key value pair exists in attributes collection + /// Checks whether the given key value pair exists in attributes collection /// /// The status key value pair /// true if exists. Otherwise, false + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { + /// { "state", "ON" }, + /// { "dim", 10 } + /// }; + /// if (attributes.Contains(new KeyValuePair ("dim", 10)) + /// Console.WriteLine("Attribute conatins pair ('dim', 10)"); + /// public bool Contains(KeyValuePair item) { return _attributes.Contains(item); } /// - /// Checks the given key exists in attributes collection + /// Checks whether the given key exists in attributes collection /// - /// The status key + /// The status key to look for /// true if exists. Otherwise, false + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { + /// { "state", "ON" }, + /// { "dim", 10 } + /// }; + /// if (attributes.ContainsKey("dim")) + /// Console.WriteLine("Attribute conatins key : dim"); + /// public bool ContainsKey(string key) { return _attributes.ContainsKey(key); } /// - /// Copies the elements of the attributes 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. + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { + /// { "state", "ON" }, + /// { "dim", 10 } + /// }; + /// KeyValuePair[] dest = new KeyValuePair[attributes.Count]; + /// int index = 0; + /// attributes.CopyTo(dest, index); + /// Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value); + /// public void CopyTo(KeyValuePair[] array, int arrayIndex) { _attributes.CopyTo(array, arrayIndex); @@ -261,43 +346,66 @@ namespace Tizen.Network.IoTConnectivity /// Returns an enumerator that iterates through the collection. /// /// An enumerator that can be used to iterate through the collection. + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { + /// { "state", "ON" }, + /// { "dim", 10 } + /// }; + /// foreach (KeyValuePair pair in attributes) + /// { + /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); + /// } + /// public IEnumerator> GetEnumerator() { return _attributes.GetEnumerator(); } /// - /// Removes a attributes element from collection + /// Removes an attribute from collection /// /// The attributes element to remove /// true if operation is success. Otherwise, false + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { + /// { "state", "ON" }, + /// { "dim", 10 } + /// }; + /// if (attributes.Remove(new KeyValuePair("dim", 10))) + /// Console.WriteLine("Remove was successful"); + /// public bool Remove(KeyValuePair item) { - int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, item.Key); - if (ret != (int)IoTConnectivityError.None) - { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes"); - throw IoTConnectivityErrorFactory.GetException(ret); - } - - return _attributes.Remove(item); + return Remove(item.Key); } /// - /// Removes a attributes element from collection using key + /// Removes an attribute from collection using key /// /// The attributes element to remove - /// true if operation is success. Otherwise, false + /// true if operation is successful, Otherwise, false + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { + /// { "state", "ON" }, + /// { "dim", 10 } + /// }; + /// if (attributes.Remove("state")) + /// Console.WriteLine("Remove was successful"); + /// public bool Remove(string key) { - int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key); - if (ret != (int)IoTConnectivityError.None) + bool isRemoved = _attributes.Remove(key); + if (isRemoved) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes"); - throw IoTConnectivityErrorFactory.GetException(ret); + int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes"); + throw IoTConnectivityErrorFactory.GetException(ret); + } } - return _attributes.Remove(key); + return isRemoved; } /// @@ -306,22 +414,41 @@ namespace Tizen.Network.IoTConnectivity /// The key whose value to get. /// The value associated with the specified key /// true if the attributes collection contains an element with the specified key; otherwise, false. + /// + /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() { + /// { "state", "ON" } + /// }; + /// object value; + /// var isPresent = attributes.TryGetValue("state", out value); + /// if (isPresent) + /// Console.WriteLine("value : {0}", value); + /// public bool TryGetValue(string key, out object value) { return _attributes.TryGetValue(key, out value); } + /// + /// Returns an enumerator that iterates through the collection. + /// IEnumerator IEnumerable.GetEnumerator() { return _attributes.GetEnumerator(); } + /// + /// Releases any unmanaged resources used by this object. + /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } + /// + /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. protected virtual void Dispose(bool disposing) { if (_disposed) diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/CacheUpdatedEventArgs.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/CacheUpdatedEventArgs.cs index 95a8f5b..3edb802 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/CacheUpdatedEventArgs.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/CacheUpdatedEventArgs.cs @@ -18,9 +18,8 @@ namespace Tizen.Network.IoTConnectivity internal CacheUpdatedEventArgs() { } /// - /// Representation property. + /// Indicates the updated representation of the resource /// - /// Representation Representation. public Representation Representation { get; internal set; } } } diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/DeviceInformationFoundEventArgs.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/DeviceInformationFoundEventArgs.cs index ceab212..d0cee2d 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/DeviceInformationFoundEventArgs.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/DeviceInformationFoundEventArgs.cs @@ -26,7 +26,7 @@ namespace Tizen.Network.IoTConnectivity public string Name { get; internal set; } /// - /// Indicates human friendly name for device + /// Indicates spec version of the core specification /// public string SpecVersion { get; internal set; } diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/FindingErrorOccurredEventArgs.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/FindingErrorOccurredEventArgs.cs index d5453e8..f0280a5 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/FindingErrorOccurredEventArgs.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/FindingErrorOccurredEventArgs.cs @@ -18,15 +18,13 @@ namespace Tizen.Network.IoTConnectivity internal FindingErrorOccurredEventArgs() { } /// - /// RequestId property. + /// The request id of the operation which caused this error /// - /// int RequestId. public int RequestId { get; internal set; } /// - /// Result property. + /// Contains error details. /// - /// FindingError Result. public Exception Error { get; internal set; } } } diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs index fcc7129..846df77 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityClientManager.cs @@ -13,10 +13,13 @@ using System.Runtime.InteropServices; namespace Tizen.Network.IoTConnectivity { /// - /// IoT connectivity client manager. + /// IoT connectivity client manager consists of client side APIs. /// public static class IoTConnectivityClientManager { + /// + /// The IP Address for multicast + /// public const string MulticastAddress = null; private static int s_presenceListenerId = 1; @@ -29,33 +32,49 @@ namespace Tizen.Network.IoTConnectivity private static Dictionary s_platformInformationCallbacksMap = new Dictionary(); /// - /// presence event on the resource + /// PresenceReceived event. This event is occurred when server starts sending presence of a resource. /// public static event EventHandler PresenceReceived; /// - /// Resource found event handler + /// ResourceFound event. This event is occurred when a resource is found from the remote server + /// after sending request using API StartFindingResource(). /// public static event EventHandler ResourceFound; /// - /// PlatformInformationFound event handler + /// PlatformInformationFound event. This event is occurred when platform information is found + /// after sending request using API StartFindingPlatformInformation(). /// public static event EventHandler PlatformInformationFound; /// - /// DeviceInformationFound event handler + /// DeviceInformationFound event. This event is occurred when device information is found + /// after sending request using API StartFindingDeviceInformation(). /// public static event EventHandler DeviceInformationFound; /// - /// FoundError event handler + /// FindingError event. This event is occurred when an error is found. /// public static event EventHandler FindingErrorOccurred; /// - /// Timeout property + /// Timeout in seconds /// + /// + /// Value to be set must be in range from 1 to 3600. Default timeout interval value is 30.\n + /// Sets/gets the timeout of StartFindingResource(), StartFindingDeviceInformation(), StartFindingPlatformInformation(), + /// RemoteResource.GetAsync(), RemoteResource.PutAsync(), RemoteResource.PostAsync() and RemoteResource.DeleteAsync() APIs.\n + /// Setter can throw exception. + /// + ///
+        /// Initialize() should be called to initialize
+        /// 
+ /// + /// IoTConnectivityClientManager.Initialize(); + /// IoTConnectivityClientManager.TimeOut = 120; + /// public static int TimeOut { get @@ -81,8 +100,22 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Timeout property + /// Polling interval of IoTConnectivity /// + /// + /// Sets/Gets the polling inerval(milliseconds) of IoTCon. Default value is 100 milliseconds. + /// Value to be set must be in range from 1 to 999. The closer to 0, the faster it operates. + /// Setter is invoked immediately for changing the interval. + /// If you want the faster operation, we recommend you set 10 milliseconds for polling interval. + /// Setter can throw exception. + /// + ///
+        /// Initialize() should be called to initialize
+        /// 
+ /// + /// IoTConnectivityClientManager.Initialize(); + /// IoTConnectivityClientManager.PollingInterval = 100; + /// public static int PollingInterval { get @@ -108,11 +141,30 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Connects to the iotcon service + /// Initializes IoTCon. + /// Call this function to start IoTCon. /// - public static void Initialize() + /// + /// @a filePath point to a file for handling secure virtual resources. + /// The file that is CBOR(Concise Binary Object Representation)-format must already exist + /// in @a filePath. We recommend to use application-local file for @a filePath. + /// + /// + /// http://tizen.org/privilege/network.get \n + /// http://tizen.org/privilege/internet + /// + /// The file path to point to storage for handling secure virtual resources. + /// + /// You must call Deinitialize() if IoTCon API is no longer needed. + /// + /// + /// + /// string filePath = "../../res/iotcon-test-svr-db-client.dat"; + /// IoTConnectivityClientManager.Initialize(filePath); + /// + public static void Initialize(string filePath) { - int ret = Interop.IoTConnectivity.Client.IoTCon.Initialize(); + int ret = Interop.IoTConnectivity.Client.IoTCon.Initialize(filePath); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to initialize"); @@ -121,21 +173,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 + /// Deinitializes IoTCon. /// + /// + /// This API must be called if IoTCon API is no longer needed. + /// + ///
+        /// Initialize() should be called to initialize.
+        /// 
+ /// + /// + /// + /// IoTConnectivityClientManager.Deinitialize(); + /// public static void Deinitialize() { Interop.IoTConnectivity.Client.IoTCon.Deinitialize(); @@ -144,6 +194,16 @@ namespace Tizen.Network.IoTConnectivity /// /// Invokes a next message from a queue for receiving messages from others, immediately. /// + /// + /// This API invokes a next message from a queue for receiving messages from others, immediately. + /// After calling the API, it continues the polling with existing interval. + /// + ///
+        /// Initialize() should be called to initialize.
+        /// 
+ /// + /// IoTConnectivityClientManager.InvokePolling(); + /// public static void InvokePolling() { int ret = Interop.IoTConnectivity.Client.IoTCon.InvokePolling(); @@ -157,9 +217,41 @@ namespace Tizen.Network.IoTConnectivity /// /// Starts receiving presence events /// - /// - /// PresenceId - /// + /// + /// Sends request to receive presence to an interested server's resource with resourceType. + /// If succeeded, event handler will be triggered when the server sends presence. + /// A server sends presence events when adds / removes / alters a resource or start / stop presence.\n + /// @a hostAddress could be for IPv4 multicast. + /// The length of @ resourceType should be less than or equal to 61. The @ resourceType must start with a lowercase alphabetic character, followed by a sequence + /// of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space. + /// + /// + /// http://tizen.org/privilege/internet + /// + /// The address or addressable name of the server + /// A resource type that a client is interested in + /// PresenceId - An identifier for this request + ///
Initialize() should be called to initialize.
+ /// + /// When the resource receive presence, event handler will be invoked.\n + /// You must destroy presence by calling StopReceivingPresence() if presence event is no longer needed. + /// + /// + /// + /// + /// + /// + /// EventHandler handler = (sender, e) => { + /// Console.Log("PresenceReceived, presence id :" + e.PresenceId); + /// } + /// EventHandler errorHandler = (sender, e) => { + /// Console.Log("Found error :" + e.Error.Message); + /// } + /// IoTConnectivityClientManager.PresenceReceived += handler; + /// IoTConnectivityClientManager.FindingErrorOccurred += errorHandler; + /// // Do not forget to remove these event handlers when they are not required any more. + /// int id = IoTConnectivityClientManager.StartReceivingPresence(IoTConnectivityClientManager.MulticastAddress, "oic.iot.door"); + /// public static int StartReceivingPresence(string hostAddress, string resourceType) { Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress); @@ -230,6 +322,36 @@ namespace Tizen.Network.IoTConnectivity /// /// Stops receiving presence events /// + /// + /// Sends request to not to receive server's presence any more. + /// + /// + /// http://tizen.org/privilege/internet + /// + /// The start presence request identifier + ///
+        /// Initialize() should be called to initialize.
+        /// 
+ /// + /// + /// + /// + /// + /// EventHandler handler = (sender, e) => { + /// Console.Log("PresenceReceived, presence id :" + e.PresenceId); + /// } + /// EventHandler errorHandler = (sender, e) => { + /// Console.Log("Found error :" + e.Error.Message); + /// } + /// IoTConnectivityClientManager.PresenceReceived += handler; + /// IoTConnectivityClientManager.FindingErrorOccurred += errorHandler; + /// int id = IoTConnectivityClientManager.StartReceivingPresence(IoTConnectivityClientManager.MulticastAddress, "oic.iot.door"); + /// await Task.Delay(5000); // Do other things here + /// // Call StopReceivingPresence() when receiving presence is not required any more + /// IoTConnectivityClientManager.PresenceReceived -= handler; + /// IoTConnectivityClientManager.FindingErrorOccurred -= errorHandler; + /// IoTConnectivityClientManager.StopReceivingPresence(id); + /// public static void StopReceivingPresence(int presenceId) { if (s_presenceHandlesMap.ContainsKey((IntPtr)presenceId)) @@ -258,11 +380,41 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Starts finding resource events + /// Starts finding resources. /// - /// - /// RequestId - /// + /// + /// Sends request to find a resource of @a hostAddress server with @a resourceType. + /// If succeeded, event handler will be triggered with information of the resource.\n + /// @a hostAddress could be for IPv4 multicast. + /// The length of @a resourceType should be less than or equal to 61. The @ resourceType must start with a lowercase alphabetic character, followed by a sequence + /// of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space. + /// + /// + /// http://tizen.org/privilege/internet + /// + /// The address or addressable name of the server + /// A resource type specified as a filter for the resource + /// The flag for secure communication with the server + /// RequestId - An identifier for this request + ///
Initialize() should be called to initialize.
+ /// + /// When the resource is found, event handler will be invoked. + /// + /// + /// + /// + /// + /// EventHandler handler = (sender, e) => { + /// Console.Log("Found resource at host address :" + e.Resource.HostAddress + ", uri :" + e.Resource.UriPath); + /// } + /// EventHandler errorHandler = (sender, e) => { + /// Console.Log("Found error :" + e.Error.Message); + /// } + /// IoTConnectivityClientManager.ResourceFound += handler; + /// IoTConnectivityClientManager.FindingErrorOccurred += errorHandler; + /// // Do not forget to remove these event handlers when they are not required any more. + /// int id = IoTConnectivityClientManager.StartFindingResource(null, "oic.iot.door"); + /// public static int StartFindingResource(string hostAddress, string resourceType, bool isSecure = false) { Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress); @@ -284,6 +436,9 @@ namespace Tizen.Network.IoTConnectivity } s_resourceFoundCallbacksMap[id] = (IntPtr remoteResourceHandle, int result, IntPtr userData) => { + if (ResourceFound == null) + return false; + int requestId = (int)userData; if (result == (int)IoTConnectivityError.None) { @@ -297,7 +452,7 @@ namespace Tizen.Network.IoTConnectivity catch (Exception exp) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Can't clone RemoteResource's handle: " + exp.Message); - return; + return true; } ResourceFoundEventArgs e = new ResourceFoundEventArgs() { @@ -309,7 +464,6 @@ namespace Tizen.Network.IoTConnectivity else { Log.Error(IoTConnectivityErrorFactory.LogTag, "Handle is null"); - return; } } else @@ -322,6 +476,7 @@ namespace Tizen.Network.IoTConnectivity s_resourceFoundCallbacksMap.Remove(id); } } + return true; }; int errorCode = Interop.IoTConnectivity.Client.ResourceFinder.AddResourceFoundCb(hostAddress, (int)connectivityType, resourceType, isSecure, s_resourceFoundCallbacksMap[id], id); if (errorCode != (int)IoTConnectivityError.None) @@ -337,11 +492,38 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Starts finding device information events + /// Starts finding the device information of remote server. /// - /// - /// RequestId - /// + /// + /// Requests server for device information. + /// If succeeded, event handler will be triggered with information of the device.\n + /// @a hostAddress could be for IPv4 multicast. + /// + /// + /// http://tizen.org/privilege/internet + /// + /// The host address of remote server + /// RequestId - An identifier for this request + ///
Initialize() should be called to initialize.
+ /// + /// event handler will be invoked. + /// + /// + /// + /// + /// + /// + /// EventHandler handler = (sender, e) => { + /// Console.Log("Device information found, id : " + e.RequestId + ", name : " + e.Name); + /// } + /// EventHandler errorHandler = (sender, e) => { + /// Console.Log("Found error :" + e.Error.Message); + /// } + /// IoTConnectivityClientManager.DeviceInformationFound += handler; + /// IoTConnectivityClientManager.FindingErrorOccurred += errorHandler; + /// // Do not forget to remove these event handlers when they are not required any more. + /// int id = IoTConnectivityClientManager.StartFindingDeviceInformation(IoTConnectivityClientManager.MulticastAddress); + /// public static int StartFindingDeviceInformation(string hostAddress) { Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress); @@ -358,6 +540,9 @@ namespace Tizen.Network.IoTConnectivity } s_deviceInformationCallbacksMap[id] = (IntPtr deviceInfoHandle, int result, IntPtr userData) => { + if (DeviceInformationFound == null) + return false; + int requestId = (int)userData; if (result == (int)IoTConnectivityError.None) { @@ -367,14 +552,13 @@ namespace Tizen.Network.IoTConnectivity if (e == null) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Can't get DeviceInformationFoundEventArgs"); - return; + return true; } DeviceInformationFound?.Invoke(null, e); } else { Log.Error(IoTConnectivityErrorFactory.LogTag, "Handle is null"); - return; } } else @@ -387,6 +571,7 @@ namespace Tizen.Network.IoTConnectivity s_deviceInformationCallbacksMap.Remove(id); } } + return true; }; int errorCode = Interop.IoTConnectivity.Client.DeviceInformation.Find(hostAddress, (int)connectivityType, s_deviceInformationCallbacksMap[id], id); @@ -404,11 +589,37 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Starts finding platform information events + /// Starts finding the platform information of remote server. /// - /// - /// RequestId - /// + /// + /// Requests server for platform information. + /// If succeeded, event handler will be triggered with information of the platform.\n + /// @a hostAddress could be for IPv4 multicast. + /// + /// + /// http://tizen.org/privilege/internet + /// + /// The host address of remote server + /// RequestId - An identifier for this request + ///
Initialize() should be called to initialize.
+ /// + /// event handler will be invoked. + /// + /// + /// + /// + /// + /// EventHandler handler = (sender, e) => { + /// Console.Log("PlatformInformationFound :" + e.RequestId); + /// } + /// EventHandler errorHandler = (sender, e) => { + /// Console.Log("Found error :" + e.Error.Message); + /// } + /// IoTConnectivityClientManager.PlatformInformationFound += handler; + /// IoTConnectivityClientManager.FindingErrorOccurred += errorHandler; + /// // Do not forget to remove these event handlers when they are not required any more. + /// int id = IoTConnectivityClientManager.StartFindingPlatformInformation(IoTConnectivityClientManager.MulticastAddress); + /// public static int StartFindingPlatformInformation(string hostAddress) { Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress); @@ -425,6 +636,9 @@ namespace Tizen.Network.IoTConnectivity } s_platformInformationCallbacksMap[id] = (IntPtr platformInfoHandle, int result, IntPtr userData) => { + if (PlatformInformationFound == null) + return false; + int requestId = (int)userData; if (result == (int)IoTConnectivityError.None) { @@ -434,14 +648,13 @@ namespace Tizen.Network.IoTConnectivity if (e == null) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Can't get PlatformInformationFoundEventArgs"); - return; + return true; ; } PlatformInformationFound?.Invoke(null, e); } else { Log.Error(IoTConnectivityErrorFactory.LogTag, "Handle is null"); - return; } } else @@ -454,6 +667,7 @@ namespace Tizen.Network.IoTConnectivity s_platformInformationCallbacksMap.Remove(id); } } + return true; }; int errorCode = Interop.IoTConnectivity.Client.PlatformInformation.Find(hostAddress, (int)connectivityType, s_platformInformationCallbacksMap[id], id); @@ -470,6 +684,7 @@ namespace Tizen.Network.IoTConnectivity return (int)id; } + // Private methods private static PresenceReceivedEventArgs GetPresenceReceivedEventArgs(int presenceId, IntPtr presenceResponseHandle) { int trigger; @@ -635,17 +850,17 @@ namespace Tizen.Network.IoTConnectivity PlatformInformationFoundEventArgs e = new PlatformInformationFoundEventArgs() { RequestId = requestId, - 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) + PlatformId = (platformId != IntPtr.Zero) ? Marshal.PtrToStringAuto(platformId) : string.Empty, + ManufacturerName = (manufacturerName != IntPtr.Zero) ? Marshal.PtrToStringAuto(manufacturerName) : string.Empty, + ManufacturerURL = (manufacturerUrl != IntPtr.Zero) ? Marshal.PtrToStringAuto(manufacturerUrl) : string.Empty, + DateOfManufacture = (dateOfManufacture != IntPtr.Zero) ? Marshal.PtrToStringAuto(dateOfManufacture) : string.Empty, + ModelNumber = (modelNumber != IntPtr.Zero) ? Marshal.PtrToStringAuto(modelNumber) : string.Empty, + PlatformVersion = (platformVersion != IntPtr.Zero) ? Marshal.PtrToStringAuto(platformVersion) : string.Empty, + OsVersion = (osVersion != IntPtr.Zero) ? Marshal.PtrToStringAuto(osVersion) : string.Empty, + HardwareVersion = (hardwareVersion != IntPtr.Zero) ? Marshal.PtrToStringAuto(hardwareVersion) : string.Empty, + FirmwareVersion = (firmwareVersion != IntPtr.Zero) ? Marshal.PtrToStringAuto(firmwareVersion) : string.Empty, + SupportUrl = (supportUrl != IntPtr.Zero) ? Marshal.PtrToStringAuto(supportUrl) : string.Empty, + SystemTime = (systemTime != IntPtr.Zero) ? Marshal.PtrToStringAuto(systemTime) : string.Empty }; return e; diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityErrorFactory.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityErrorFactory.cs index f0dc3be..8c897c7 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityErrorFactory.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityErrorFactory.cs @@ -7,6 +7,7 @@ /// you entered into with Samsung. using System; +using System.IO; using Tizen.Internals.Errors; namespace Tizen.Network.IoTConnectivity @@ -34,51 +35,7 @@ namespace Tizen.Network.IoTConnectivity internal static void ThrowException(int err) { - IoTConnectivityError error = (IoTConnectivityError)err; - if (error == IoTConnectivityError.OutOfMemory) - { - throw new InvalidOperationException("Out of memory"); - } - else if (error == IoTConnectivityError.InvalidParameter) - { - throw new ArgumentException("Invalid parameter"); - } - else if (error == IoTConnectivityError.Io) - { - throw new ArgumentException("I/O Error"); - } - else if (error == IoTConnectivityError.NoData) - { - throw new ArgumentException("No data found"); - } - else if (error == IoTConnectivityError.TimedOut) - { - throw new ArgumentException("timed out"); - } - else if (error == IoTConnectivityError.PermissionDenied) - { - throw new ArgumentException("Permission denied"); - } - else if (error == IoTConnectivityError.NotSupported) - { - throw new ArgumentException("Not supported"); - } - else if (error == IoTConnectivityError.Representation) - { - throw new ArgumentException("Representation error"); - } - else if (error == IoTConnectivityError.InvalidType) - { - throw new ArgumentException("Invalid type"); - } - else if (error == IoTConnectivityError.Already) - { - throw new ArgumentException("Duplicate"); - } - else if (error == IoTConnectivityError.System) - { - throw new InvalidOperationException("System error"); - } + throw GetException(err); } internal static Exception GetException(int err) @@ -86,7 +43,7 @@ namespace Tizen.Network.IoTConnectivity IoTConnectivityError error = (IoTConnectivityError)err; if (error == IoTConnectivityError.OutOfMemory) { - return new InvalidOperationException("Out of memory"); + return new OutOfMemoryException("Out of memory"); } else if (error == IoTConnectivityError.InvalidParameter) { @@ -94,27 +51,27 @@ namespace Tizen.Network.IoTConnectivity } else if (error == IoTConnectivityError.Io) { - return new ArgumentException("I/O Error"); + return new IOException("I/O Error"); } else if (error == IoTConnectivityError.NoData) { - return new ArgumentException("No data found"); + return new InvalidOperationException("No data found"); } else if (error == IoTConnectivityError.TimedOut) { - return new ArgumentException("timed out"); + return new TimeoutException("timed out"); } else if (error == IoTConnectivityError.PermissionDenied) { - return new ArgumentException("Permission denied"); + return new UnauthorizedAccessException("Permission denied"); } else if (error == IoTConnectivityError.NotSupported) { - return new ArgumentException("Not supported"); + return new NotSupportedException("Not supported"); } else if (error == IoTConnectivityError.Representation) { - return new ArgumentException("Representation error"); + return new InvalidOperationException("Representation error"); } else if (error == IoTConnectivityError.InvalidType) { @@ -122,11 +79,11 @@ namespace Tizen.Network.IoTConnectivity } else if (error == IoTConnectivityError.Already) { - return new ArgumentException("Duplicate"); + return new InvalidOperationException("Duplicate"); } else if (error == IoTConnectivityError.System) { - return new InvalidOperationException("System error"); + return new SystemException("System error"); } else { diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs index a24ca7c..c939255 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/IoTConnectivityServerManager.cs @@ -11,16 +11,34 @@ using System; namespace Tizen.Network.IoTConnectivity { /// - /// IoT connectivity server manager. + /// IoT connectivity server manager consists of server side APIs. /// public static class IoTConnectivityServerManager { /// - /// Initializes connection with IoTCon service + /// Initializes IoTCon. Call this API to start IoTCon. /// - public static void Initialize() + /// + /// @a filePath point to a file for handling secure virtual resources. + /// The file that is CBOR(Concise Binary Object Representation)-format must already exist + /// in @a filePath. We recommend to use application-local file for @a filePath. + /// + /// + /// http://tizen.org/privilege/network.get \n + /// http://tizen.org/privilege/internet + /// + /// The file path to point to storage for handling secure virtual resources. + /// + /// You must call Deinitialize() if IoTCon API is no longer needed. + /// + /// + /// + /// string filePath = "../../res/iotcon-test-svr-db-server.dat"; + /// IoTConnectivityServerManager.Initialize(filePath); + /// + public static void Initialize(string filePath) { - int ret = Interop.IoTConnectivity.Client.IoTCon.Initialize(); + int ret = Interop.IoTConnectivity.Client.IoTCon.Initialize(filePath); if (ret != (int)IoTConnectivityError.None) { Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to initialize"); @@ -29,17 +47,45 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Disconnects with IoTCon service + /// Deinitializes IoTCon. /// + /// + /// This API must be called if IoTCon API is no longer needed. + /// + ///
+        /// Initialize() should be called to initialize.
+        /// 
+ /// + /// + /// IoTConnectivityServerManager.Deinitialize(); + /// public static void Deinitialize() { Interop.IoTConnectivity.Client.IoTCon.Deinitialize(); } /// - /// Registers a resource to be available from IoTCon server + /// Registers a resource in IoTCon server /// + /// + /// http://tizen.org/privilege/internet + /// /// The resource to register + ///
+        /// Initialize() should be called to initialize.
+        /// 
+ /// + /// + /// + /// ResourceTypes types = new ResourceTypes(new List(){ "org.tizen.light" }); + /// Attributes attributes = new Attributes { { "state", "ON" }}; + /// Resource res = new LiteResource("/room/1", types, ResourcePolicy.Discoverable, attributes); + /// try { + /// IoTConnectivityServerManager.RegisterResource(res); + /// } catch(Exception ex) { + /// Console.Log("Exception caught : " + ex.Message); + /// } + /// public static void RegisterResource(Resource resource) { IntPtr handle = IntPtr.Zero; @@ -58,7 +104,30 @@ namespace Tizen.Network.IoTConnectivity /// /// Starts presence of a server /// + /// + /// Use this API to send server's announcements to clients. + /// Server can call this API when online for the first time or come back from offline to online.\n + /// If @a time is 0, server will set default value as 60 seconds.\n + /// If @a time is very big, server will set maximum value as (60 * 60 * 24) seconds, (24 hours). + /// + /// + /// http://tizen.org/privilege/internet + /// /// The interval of announcing presence in seconds. + ///
+        /// Initialize() should be called to initialize.
+        /// 
+ /// + /// + /// + /// + /// + /// try { + /// IoTConnectivityServerManager.StartSendingPresence(120); + /// } catch(Exception ex) { + /// Console.Log("Exception caught : " + ex.Message); + /// } + /// public static void StartSendingPresence(uint time) { int ret = Interop.IoTConnectivity.Server.IoTCon.StartPresence(time); @@ -72,6 +141,23 @@ namespace Tizen.Network.IoTConnectivity /// /// Stops presence of a server. /// + /// + /// Use this API to stop sending server's announcements to clients. + /// Server can call this API when terminating, entering to offline or out of network. + /// + /// + /// http://tizen.org/privilege/internet + /// + ///
+        /// Initialize() should be called to initialize.
+        /// 
+ /// + /// + /// + /// + /// + /// IoTConnectivityServerManager.StopSendingPresence(); + /// public static void StopSendingPresence() { int ret = Interop.IoTConnectivity.Server.IoTCon.StopPresence(); @@ -85,7 +171,19 @@ namespace Tizen.Network.IoTConnectivity /// /// Sets the device name /// + /// + /// This API sets the name of the local device (the device calling the API).\n + /// If the device name is set, clients can get the name using . + /// Clients can also get the name using property. + /// /// The device name + /// + /// + /// + /// + /// + /// IoTConnectivityServerManager.SetDeviceName("my-tizen"); + /// public static void SetDeviceName(string deviceName) { int ret = Interop.IoTConnectivity.Server.IoTCon.SetDeviceName(deviceName); diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/LiteResource.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/LiteResource.cs index d22ed2a..f089e30 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/LiteResource.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/LiteResource.cs @@ -6,22 +6,44 @@ /// it only in accordance with the terms of the license agreement /// you entered into with Samsung. -using System.Collections.Generic; namespace Tizen.Network.IoTConnectivity { /// - /// Class represnets a lite resource. + /// This class represents a lite resource. + /// It provides APIs to encapsulate resources. + /// This class is accessed by using a constructor to create a new instance of this object. /// public class LiteResource : Resource { /// - /// Constructor + /// The LiteResource constructor /// + /// + /// Creates a lite resource which can then be registered in server using .\n + /// When client requests some operations, it send a response to client, automatically.\n + /// @a uri length must be less than 128. + /// + /// + /// http://tizen.org/privilege/internet + /// /// The uri path of the lite resource - /// Resource type + /// The type of the resource /// Policy of the resource /// Optional attributes of the resource + ///
+        /// IoTConnectivityServerManager.Initialize() should be called to initialize
+        /// 
+ /// + /// + /// + /// + /// List list = new List() { "org.tizen.light" }; + /// Attributes attributes = new Attributes() { + /// { "state", "ON" } + /// }; + /// LiteResource res = new LiteResource("/light/1", new ResourceTypes(list), ResourcePolicy.Discoverable, attributes); + /// public LiteResource(string uri, ResourceTypes types, ResourcePolicy policy, Attributes attribs = null) : base(uri, types, new ResourceInterfaces(new string[] { ResourceInterfaces.DefaultInterface }), policy) { @@ -29,24 +51,48 @@ namespace Tizen.Network.IoTConnectivity } /// - /// The attributes of the lite resource + /// Gets or sets the attributes of the lite resource /// + /// + /// List list = new List() { "org.tizen.light" }; + /// LiteResource res = new LiteResource("/light/1", new ResourceTypes(list), ResourcePolicy.Discoverable); + /// Attributes attributes = new Attributes() { + /// { "state", "ON" } + /// }; + /// res.Attributes = newAttributes; + /// foreach (KeyValuePair pair in res.Attributes) + /// { + /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); + /// } + /// public Attributes Attributes { get; set; } /// - /// The method to accept post request + /// Decides whether to accept or reject a post request. /// + /// + /// Child classes of this class can override this method to accept or reject post request. + /// /// The new attributes of the lite resource /// true to accept post request, false to reject it + /// + /// public class MyLightResource : LiteResource + /// { + /// protected override bool OnPost(Attributes attributes) + /// { + /// object newAttributes; + /// attributes.TryGetValue("LIGHT_ATTRIBUTE", out newAttributes); + /// if((int)newAttributes == 1) + /// return true; + /// return false; + /// } + /// } + /// protected virtual bool OnPost(Attributes attribs) { return true; } - /// - /// Called on the get event. - /// - /// Request. protected sealed override Response OnGet(Request request) { Representation representation = new Representation() @@ -66,10 +112,6 @@ namespace Tizen.Network.IoTConnectivity return response; } - /// - /// Called on the put event. - /// - /// Request. protected sealed override Response OnPut(Request request) { Response response = new Response(); @@ -77,10 +119,6 @@ namespace Tizen.Network.IoTConnectivity return response; } - /// - /// Called on the post event. - /// - /// Request. protected sealed override Response OnPost(Request request) { if (OnPost(request.Representation.Attributes)) @@ -108,10 +146,6 @@ namespace Tizen.Network.IoTConnectivity }; } - /// - /// Called on the delete event. - /// - /// Request. protected sealed override Response OnDelete(Request request) { Response response = new Response(); @@ -119,12 +153,6 @@ namespace Tizen.Network.IoTConnectivity return response; } - /// - /// Called on the observing event. - /// - /// Request. - /// Observer type - /// Observe identifier. protected sealed override bool OnObserving(Request request, ObserveType observeType, int observeId) { return true; diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObservePolicy.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObservePolicy.cs index 0d013db..c4b0503 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObservePolicy.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObservePolicy.cs @@ -9,7 +9,7 @@ namespace Tizen.Network.IoTConnectivity { /// - /// Indicates delete method of request + /// Enumeration for policy of observation /// public enum ObservePolicy { diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObserveType.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObserveType.cs index 6ff7ec0..6b3619a 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObserveType.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObserveType.cs @@ -9,7 +9,7 @@ namespace Tizen.Network.IoTConnectivity { /// - /// Observe type. + /// Enumeration for type of observation /// public enum ObserveType { diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObserverNotifiedEventArgs.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObserverNotifiedEventArgs.cs index 616912a..1b2aae0 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObserverNotifiedEventArgs.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ObserverNotifiedEventArgs.cs @@ -18,15 +18,13 @@ namespace Tizen.Network.IoTConnectivity internal ObserverNotifiedEventArgs() { } /// - /// Result property. + /// Result of the observe response /// - /// ResponseCode Result. public ResponseCode Result { get; internal set; } /// - /// Representation property. + /// Representation of the resource being observed. /// - /// Representation Representation. public Representation Representation { get; internal set; } } } diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PlatformInformationFoundEventArgs.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PlatformInformationFoundEventArgs.cs index 176c425..e102d41 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PlatformInformationFoundEventArgs.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PlatformInformationFoundEventArgs.cs @@ -16,62 +16,62 @@ namespace Tizen.Network.IoTConnectivity internal PlatformInformationFoundEventArgs() { } /// - /// The request id + /// Indicates the request id /// public int RequestId { get; internal set; } /// - /// The platform identifier + /// Indicates the platform identifier /// public string PlatformId { get; internal set; } /// - /// The name of manufacturer + /// Indicates the name of manufacturer /// public string ManufacturerName { get; internal set; } /// - /// URL of the manufacturer + /// Indicates URL of the manufacturer /// public string ManufacturerURL { get; internal set; } /// - /// Model number as designated by manufacturer + /// Indicates model number as designated by manufacturer /// public string ModelNumber { get; internal set; } /// - /// Manugacturing date of the device + /// Indicates manufacturing date of the device /// public string DateOfManufacture { get; internal set; } /// - /// Version of platfrom defined by manufacturer + /// Indicates version of platfrom defined by manufacturer /// public string PlatformVersion { get; internal set; } /// - /// Version of platfrom resident OS + /// Indicates version of platfrom resident OS /// public string OsVersion { get; internal set; } /// - /// Version of platform Hardware + /// Indicates version of platform Hardware /// public string HardwareVersion { get; internal set; } /// - /// Version of device firmware + /// Indicates version of device firmware /// public string FirmwareVersion { get; internal set; } /// - /// URL that points to support information from manufacturer + /// Indicates URL that points to support information from manufacturer /// public string SupportUrl { get; internal set; } /// - /// Reference time of the device + /// Indicates reference time of the device /// public string SystemTime { get; internal set; } } diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PresenceEventType.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PresenceEventType.cs index 19d2cc4..c070974 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PresenceEventType.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PresenceEventType.cs @@ -9,7 +9,7 @@ namespace Tizen.Network.IoTConnectivity { /// - /// Enumeration for presence events. + /// Enumeration for operation of presence response. /// public enum PresenceEventType { @@ -18,7 +18,7 @@ namespace Tizen.Network.IoTConnectivity ///
ResourceCreated = 0, /// - /// Indicates for resource creation operation of server + /// Indicates for resource updation operation of server /// ResourceUpdated, /// diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PresenceReceivedEventArgs.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PresenceReceivedEventArgs.cs index 75b4c41..a66019f 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PresenceReceivedEventArgs.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/PresenceReceivedEventArgs.cs @@ -18,27 +18,23 @@ namespace Tizen.Network.IoTConnectivity internal PresenceReceivedEventArgs() { } /// - /// PresenceId property. + /// Indicates request id of presence event. /// - /// int PresenceId. public int PresenceId { get; internal set; } /// - /// EventType property. + /// Indicates event type /// - /// PresenceEventType EventType. public PresenceEventType EventType { get; internal set; } /// - /// HostAddress property. + /// Indicates host address of resource /// - /// string HostAddress. public string HostAddress { get; internal set; } /// - /// Type property. + /// Indicates type of the resource /// - /// string Type. public string Type { get; internal set; } } } diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/QualityOfService.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/QualityOfService.cs index 65624e6..7d51e56 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/QualityOfService.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/QualityOfService.cs @@ -9,7 +9,7 @@ namespace Tizen.Network.IoTConnectivity { /// - /// Indicates observation request for all notifications including stale notifications + /// Enumeration for states of remote resource. /// public enum QualityOfService { diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs index e7af5bf..c861155 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResource.cs @@ -16,6 +16,7 @@ namespace Tizen.Network.IoTConnectivity { /// /// This class represents a remote resource. + /// It provides APIs to manage remote resource. /// public class RemoteResource : IDisposable { @@ -36,8 +37,19 @@ namespace Tizen.Network.IoTConnectivity private EventHandler _stateChangedEventHandler; /// - /// Constructor + /// Creates a remote resource instance /// + /// + /// To use this API, you should provide all of the details required to correctly contact and + /// observe the object.\n + /// If not, you should discover the resource object manually.\n + /// The @a policy can contain multiple policies like ResourcePolicy.Discoverable | ResourcePolicy.Observable. + /// + /// The host address of the resource + /// The URI path of the resource + /// The policies of the resource + /// The resource types of the resource + /// The resource interfaces of the resource public RemoteResource(string hostAddress, string uriPath, ResourcePolicy policy, ResourceTypes resourceTypes, ResourceInterfaces resourceInterfaces) { if (hostAddress == null || uriPath == null || resourceTypes == null || resourceInterfaces == null) @@ -67,18 +79,21 @@ namespace Tizen.Network.IoTConnectivity SetRemoteResource(); } + /// + /// Destructor of the RemoteResource class. + /// ~RemoteResource() { Dispose(false); } /// - /// Event that is called to cache resource attribute's + /// Event that is invoked with cached resource attributes /// public event EventHandler CacheUpdated; /// - /// Observe event on the resource + /// Observe event on the resource sent by the server /// public event EventHandler ObserverNotified; @@ -160,8 +175,11 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Cache enabled property + /// Indicates the CacheEnabled status of the remote resource. /// + /// + /// Client can start caching only when this is set true. Set it to false to stop caching the resource attributes. + /// public bool CacheEnabled { get @@ -181,6 +199,10 @@ namespace Tizen.Network.IoTConnectivity /// /// Time interval of monitoring and caching API /// + /// + /// Default time interval is 10 seconds.\n + /// Seconds for time interval (must be in range from 1 to 3600) + /// public int TimeInterval { get @@ -197,7 +219,7 @@ namespace Tizen.Network.IoTConnectivity set { int ret = (int)IoTConnectivityError.InvalidParameter; - if (value < TimeOutMax && value > 0) + if (value <= TimeOutMax && value > 0) { ret = Interop.IoTConnectivity.Client.RemoteResource.SetTimeInterval(value); } @@ -215,7 +237,7 @@ namespace Tizen.Network.IoTConnectivity public string DeviceId { get; private set; } /// - /// Gets cached representation of the remote resource + /// Gets cached representation from the remote resource /// public Representation CachedRepresentation() { @@ -232,10 +254,16 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Registers the observe callback on the resource + /// Starts observing on the resource /// + /// + /// When server sends notification message, will be called. + /// + /// + /// http://tizen.org/privilege/internet + /// /// The type to specify how client wants to observe - /// The ResourceQuery to send to server + /// The query to send to server public void StartObserving(ObservePolicy policy, ResourceQuery query = null) { _observeCallback = (IntPtr resource, int err, int sequenceNumber, IntPtr response, IntPtr userData) => @@ -290,8 +318,11 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Deregisters the observe callback on the resource + /// Stops observing on the resource /// + /// + /// http://tizen.org/privilege/internet + /// public void StopObserving() { int ret = Interop.IoTConnectivity.Client.RemoteResource.DeregisterObserve(_remoteResourceHandle); @@ -303,10 +334,13 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Gets the attributes of a resource + /// Gets the attributes of a resource, asynchronously /// + /// + /// http://tizen.org/privilege/internet + /// /// The ResourceQuery to send to server - /// + /// Remote response with result and representation public async Task GetAsync(ResourceQuery query = null) { TaskCompletionSource tcsRemoteResponse = new TaskCompletionSource(); @@ -355,9 +389,12 @@ namespace Tizen.Network.IoTConnectivity /// /// Puts the representation of a resource, asynchronously. /// - /// Resource representation + /// + /// http://tizen.org/privilege/internet + /// + /// Resource representation to put /// The ResourceQuery to send to server - /// + /// Remote response with result and representation public async Task PutAsync(Representation representation, ResourceQuery query = null) { TaskCompletionSource tcsRemoteResponse = new TaskCompletionSource(); @@ -409,11 +446,14 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Post request on a resource + /// Post request on a resource, asynchronously /// - /// Resource representation + /// + /// http://tizen.org/privilege/internet + /// + /// Resource representation of request /// The ResourceQuery to send to server - /// + /// Remote response with result and representation public async Task PostAsync(Representation representation, ResourceQuery query = null) { TaskCompletionSource tcsRemoteResponse = new TaskCompletionSource(); @@ -430,7 +470,6 @@ namespace Tizen.Network.IoTConnectivity { _responseCallbacksMap.Remove(responseCallbackId); } - if (responseHandle != IntPtr.Zero) { try @@ -448,7 +487,6 @@ namespace Tizen.Network.IoTConnectivity tcsRemoteResponse.TrySetException(IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.System)); } }; - IntPtr queryHandle = (query == null) ? IntPtr.Zero : query._resourceQueryHandle; int errCode = Interop.IoTConnectivity.Client.RemoteResource.Post(_remoteResourceHandle, representation._representationHandle, queryHandle, _responseCallbacksMap[id], id); if (errCode != (int)IoTConnectivityError.None) @@ -460,9 +498,12 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Delete the resource + /// Deletes the resource, asynchronously /// - /// + /// + /// http://tizen.org/privilege/internet + /// + /// Remote response with result and representation public async Task DeleteAsync() { TaskCompletionSource tcsRemoteResponse = new TaskCompletionSource(); @@ -513,6 +554,9 @@ namespace Tizen.Network.IoTConnectivity return await tcsRemoteResponse.Task; } + /// + /// Releases any unmanaged resources used by this object. + /// public void Dispose() { Dispose(true); @@ -558,6 +602,10 @@ namespace Tizen.Network.IoTConnectivity return type; } + /// + /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. protected virtual void Dispose(bool disposing) { if (_disposed) diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResponse.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResponse.cs index a17c30d..d57472f 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResponse.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/RemoteResponse.cs @@ -10,9 +10,12 @@ namespace Tizen.Network.IoTConnectivity { /// /// This class represents remote response. + /// It represents the response of all CRUD operations. /// public class RemoteResponse { + internal RemoteResponse() { } + /// /// Indicates the result of the response /// diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs index 1a5af8a..52c5c29 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Representation.cs @@ -14,7 +14,8 @@ using System.Runtime.InteropServices; namespace Tizen.Network.IoTConnectivity { /// - /// Class containing representation of a resource. + /// This class provides API to manage representation. + /// A representation is a payload of a request or a response. /// public class Representation : IDisposable { @@ -24,8 +25,12 @@ namespace Tizen.Network.IoTConnectivity private ObservableCollection _children = new ObservableCollection(); /// - /// Constructor + /// The Representation constructor /// + /// + /// + /// Representation repr = new Representation(); + /// public Representation() { int ret = Interop.IoTConnectivity.Common.Representation.Create(out _representationHandle); @@ -55,14 +60,25 @@ namespace Tizen.Network.IoTConnectivity _children.CollectionChanged += ChildrenCollectionChanged; } + /// + /// Destructor of the Representation class. + /// ~Representation() { Dispose(false); } /// - /// The URI of resource + /// The URI path of resource /// + /// + /// Setter can throw exceptions + /// + /// + /// Representation repr = new Representation(); + /// repr.UriPath = "/a/light"; + /// Console.WriteLine("URI is {0}", repr.UriPath); //Getter + /// public string UriPath { get @@ -92,6 +108,17 @@ namespace Tizen.Network.IoTConnectivity /// /// The type of resource /// + /// + /// + /// Representation repr = new Representation(); + /// ResourceTypes types = new ResourceTypes (new List(){ "org.tizen.light" }); + /// repr.Type = types; + /// var type = repr.Type; // Getter + /// foreach (string item in type) + /// { + /// Console.WriteLine("Type is {0}", item); + /// } + /// public ResourceTypes Type { get @@ -103,6 +130,10 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type"); throw IoTConnectivityErrorFactory.GetException(ret); } + if (typeHandle == IntPtr.Zero) + { + return null; + } return new ResourceTypes(typeHandle); } set @@ -121,6 +152,17 @@ namespace Tizen.Network.IoTConnectivity /// /// The interface of the resource /// + /// + /// + /// Representation repr = new Representation(); + /// ResourceInterfaces ifaces = new ResourceInterfaces (new List(){ ResourceInterfaces.DefaultInterface }); + /// repr.Interface = ifaces; + /// var iface = repr.Interface; // Getter + /// foreach (string item in iface) + /// { + /// Console.WriteLine("Interface is {0}", iface); + /// } + /// public ResourceInterfaces Interface { get @@ -132,6 +174,10 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get interface"); throw IoTConnectivityErrorFactory.GetException(ret); } + if (interfaceHandle == IntPtr.Zero) + { + return null; + } return new ResourceInterfaces(interfaceHandle); } set @@ -150,6 +196,19 @@ namespace Tizen.Network.IoTConnectivity /// /// Current attributes of the resource /// + /// + /// + /// Representation repr = new Representation(); + /// Attributes attributes = new Attributes() { + /// { "state", "ON" }, + /// { "dim", 10 } + /// }; + /// repr.Attributes = attributes; + /// var newAttributes = repr.Attributes; // Getter + /// string strval = newAttributes["state"] as string; + /// int intval = (int)newAttributes["dim"]; + /// Console.WriteLine("attributes are {0} and {1}", strval, intval); + /// public Attributes Attributes { get @@ -181,6 +240,23 @@ namespace Tizen.Network.IoTConnectivity /// /// List of Child resource representation /// + /// + /// Representation repr = new Representation(); + /// Representation child1 = new Representation(); + /// ResourceTypes types1 = new ResourceTypes(new List() { "org.tizen.light" }); + /// child1.Type = types1; + /// ResourceInterfaces ifaces1 = new ResourceInterfaces(new List() { ResourceInterfaces.DefaultInterface }); + /// child1.Interface = ifaces1; + /// try + /// { + /// repr.Children.Add(child1); + /// Console.WriteLine("Number of children : {0}", repr.Children.Count); + /// Representation firstChild = repr.Children.ElementAt(0); + /// } catch(Exception ex) + /// { + /// Console.WriteLine("Exception caught : " + ex.Message); + /// } + /// public ICollection Children { get @@ -189,12 +265,19 @@ namespace Tizen.Network.IoTConnectivity } } + /// + /// Releases any unmanaged resources used by this object. + /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } + /// + /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. protected virtual void Dispose(bool disposing) { if (_disposed) @@ -206,6 +289,10 @@ namespace Tizen.Network.IoTConnectivity Type?.Dispose(); Interface?.Dispose(); Attributes?.Dispose(); + foreach(var child in Children) + { + child.Dispose(); + } } Interop.IoTConnectivity.Common.Representation.Destroy(_representationHandle); diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Request.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Request.cs index 929fb45..2746e54 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Request.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Request.cs @@ -12,6 +12,7 @@ namespace Tizen.Network.IoTConnectivity { /// /// Class respresenting request to a resource. + /// It provides APIs to manage client's request. /// public class Request : IDisposable { @@ -21,6 +22,9 @@ namespace Tizen.Network.IoTConnectivity { } + /// + /// Destructor of the Request class. + /// ~Request() { Dispose(false); @@ -46,12 +50,19 @@ namespace Tizen.Network.IoTConnectivity /// public ResourceOptions Options { get; internal set; } + /// + /// Releases any unmanaged resources used by this object. + /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } + /// + /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. protected virtual void Dispose(bool disposing) { if (_disposed) diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs index 8fef403..aeeefdd 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Resource.cs @@ -15,6 +15,7 @@ namespace Tizen.Network.IoTConnectivity { /// /// Abstract class respresenting a resource. + /// All resources need to inherit from this class. /// public abstract class Resource : IDisposable { @@ -26,10 +27,44 @@ namespace Tizen.Network.IoTConnectivity /// /// The constructor /// - /// URI of the resource + /// + /// @a uri format would be relative URI path like '/a/light' + /// and its length must be less than 128. + /// + /// + /// http://tizen.org/privilege/internet + /// + /// The URI path of the resource /// Resource types /// Resource interfaces - /// Policy input of the resoruce + /// The policies of the resoruce + ///
+        /// IoTConnectivityServerManager.Initialize() should be called to initialize
+        /// 
+ /// + /// + /// + /// + /// // Create a class which inherits from Resource + /// public class DoorResource : Resource + /// { + /// public DoorResource(string uri, ResourceTypes types, ResourceInterfaces interfaces, ResourcePolicy policy) + /// : base(uri, types, interfaces, policy) { + /// } + /// protected override Response OnDelete(Request request) { + /// // Do something + /// } + /// protected override Response OnGet(Request request) { + /// // Do something + /// } + /// // Override other abstract methods of Resource class + /// } + /// + /// // Use it like below + /// ResourceInterfaces ifaces = new ResourceInterfaces(new List(){ ResourceInterfaces.DefaultInterface }); + /// ResourceTypes types = new ResourceTypes(new List(){ "oic.iot.door.new" }); + /// Resource resource = new DoorResource("/door/uri1", types, ifaces, ResourcePolicy.Discoverable | ResourcePolicy.Observable); + /// protected Resource(string uri, ResourceTypes types, ResourceInterfaces interfaces, ResourcePolicy policy) { UriPath = uri; @@ -47,6 +82,9 @@ namespace Tizen.Network.IoTConnectivity } } + /// + /// Destructor of the Resource class. + /// ~Resource() { Dispose(false); @@ -63,12 +101,12 @@ namespace Tizen.Network.IoTConnectivity public ResourceInterfaces Interfaces { get; internal set; } /// - /// The policy + /// The policies of the resource /// public ResourcePolicy Policy { get; internal set; } /// - /// URI of the resource + /// URI path of the resource /// public string UriPath { get; internal set; } @@ -98,8 +136,30 @@ namespace Tizen.Network.IoTConnectivity /// /// Notify the specified representation and qos. /// + /// + /// http://tizen.org/privilege/internet + /// /// Representation. - /// Qos. + /// The quality of service for message transfer. + ///
+        /// IoTConnectivityServerManager.Initialize() should be called to initialize
+        /// 
+ /// + /// + /// + /// ResourceInterfaces ifaces = new ResourceInterfaces(new List(){ ResourceInterfaces.DefaultInterface }); + /// ResourceTypes types = new ResourceTypes(new List(){ "oic.iot.door.new.notify" }); + /// Resource resource = new DoorResource("/door/uri/new/notify", types, ifaces, ResourcePolicy.Discoverable | ResourcePolicy.Observable); + /// IoTConnectivityServerManager.RegisterResource(resource); + /// + /// Representation repr = new Representation(); + /// repr.UriPath = "/door/uri/new/notify"; + /// repr.Type = new ResourceTypes(new List(){ "oic.iot.door.new.notify" }); + /// repr.Attributes = new Attributes() { + /// _attribute, 1 } + /// }; + /// resource.Notify(repr, QualityOfService.High); + /// public void Notify(Representation representation, QualityOfService qos) { int ret = (int)IoTConnectivityError.None; @@ -112,43 +172,55 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Called on the get event. + /// This is Called when the client performs get operation on this resource. /// - /// Request. + /// A request from client + /// A response having the representation and the result protected abstract Response OnGet(Request request); /// - /// Called on the put event. + /// This is Called when the client performs put operation on this resource. /// - /// Request. + /// A request from client + /// A response protected abstract Response OnPut(Request request); /// - /// Called on the post event. + /// This is Called when the client performs post operation on this resource. /// - /// Request. + /// A request from client + /// A response having the representation and the result protected abstract Response OnPost(Request request); /// - /// Called on the delete event. + /// This is Called when the client performs delete operation on this resource. /// - /// Request. + /// A request from client + /// A response protected abstract Response OnDelete(Request request); /// /// Called on the observing event. /// - /// Request. - /// Policy. + /// A request from client + /// Observer type /// Observe identifier. + /// Returns true if it wants to be observed, else false. protected abstract bool OnObserving(Request request, ObserveType type, int observeId); + /// + /// Releases any unmanaged resources used by this object. + /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } + /// + /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. protected virtual void Dispose(bool disposing) { if (_disposed) @@ -188,7 +260,6 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to Get observe type"); return; } - if ((ObserveType)observeType != ObserveType.NoType) { int observeId; @@ -238,7 +309,6 @@ namespace Tizen.Network.IoTConnectivity } } } - int requestType; ret = Interop.IoTConnectivity.Server.Request.GetRequestType(requestHandle, out requestType); if (ret != (int)IoTConnectivityError.None) @@ -246,7 +316,6 @@ namespace Tizen.Network.IoTConnectivity Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to Get request type"); return; } - switch ((Interop.IoTConnectivity.Server.RequestType)requestType) { case Interop.IoTConnectivity.Server.RequestType.Put: diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceFoundEventArgs.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceFoundEventArgs.cs index 0d37588..050ff68 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceFoundEventArgs.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceFoundEventArgs.cs @@ -18,15 +18,16 @@ namespace Tizen.Network.IoTConnectivity internal ResourceFoundEventArgs() { } /// - /// RequestId property. + /// Indicates the request id. + /// This is the same request id returned by the API. /// - /// int RequestId. public int RequestId { get; internal set; } /// - /// Resource property. + /// Remote resource which is found after . /// - /// RemoteResource Resource. + /// + /// public RemoteResource Resource { get; internal set; } } } diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceInterfaces.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceInterfaces.cs index 95227ff..aa05b66 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceInterfaces.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceInterfaces.cs @@ -14,7 +14,8 @@ using System.Text.RegularExpressions; namespace Tizen.Network.IoTConnectivity { /// - /// Class containing resource interfaces + /// This class contains resource interfaces and provides APIs to manage, add, remove those interfaces. + /// A resource interface indicates a class or category of resources. /// public class ResourceInterfaces : IEnumerable, IDisposable { @@ -24,7 +25,7 @@ namespace Tizen.Network.IoTConnectivity public const string DefaultInterface = "oic.if.baseline"; /// - /// List Links Interface which is used to list the references to other resources contained in a resource. + /// List Links Interface which is used to list the references to other resources contained in a resource. /// public const string LinkInterface = "oic.if.ll"; @@ -49,8 +50,13 @@ namespace Tizen.Network.IoTConnectivity private bool _disposed = false; /// - /// Constructor + /// Constructor of ResourceInterfaces /// + /// + /// + /// + /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(); + /// public ResourceInterfaces() { int ret = Interop.IoTConnectivity.Common.ResourceInterfaces.Create(out _resourceInterfacesHandle); @@ -62,9 +68,13 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Constructor + /// Constructor of ResourceInterfaces using list of interfaces /// /// List of resource interfaces + /// + /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(new List() + /// { ResourceInterfaces.LinkInterface, ResourceInterfaces.ReadonlyInterface }); + /// public ResourceInterfaces(IEnumerable ifaces) { int ret = Interop.IoTConnectivity.Common.ResourceInterfaces.Create(out _resourceInterfacesHandle); @@ -79,9 +89,6 @@ namespace Tizen.Network.IoTConnectivity } } - /// - /// Constructor - /// internal ResourceInterfaces(IntPtr ifacesHandleToClone) { int ret = Interop.IoTConnectivity.Common.ResourceInterfaces.Clone(ifacesHandleToClone, out _resourceInterfacesHandle); @@ -105,6 +112,9 @@ namespace Tizen.Network.IoTConnectivity } } + /// + /// Destructor of the ResourceInterfaces class. + /// ~ResourceInterfaces() { Dispose(false); @@ -119,8 +129,13 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Count of interfaces in the list + /// Indicates count of interfaces in the list /// + /// + /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(new List() + /// { ResourceInterfaces.LinkInterface, ResourceInterfaces.ReadonlyInterface }); + /// Console.WriteLine("There are {0} interfaces", resourceInterfaces.Count); + /// public int Count { get @@ -132,7 +147,15 @@ namespace Tizen.Network.IoTConnectivity /// /// Adds a resource interface into the list. /// - /// Resource interface + /// + /// @a item could be a value such as + /// + /// The string data to insert into the resource interfaces + /// + /// + /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(); + /// resourceInterfaces.Add(ResourceInterfaces.BatchInterface); + /// public void Add(string item) { if (IsValid(item)) @@ -155,36 +178,69 @@ namespace Tizen.Network.IoTConnectivity /// /// Removes a resource interface from the list /// - /// Resource interface + /// The string data to delete from the resource ifaces + /// + /// + /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(new List(){ ResourceInterfaces.BatchInterface }); + /// resourceInterfaces.Add(ResourceInterfaces.BatchInterface); + /// public void Remove(string item) { - int ret = Interop.IoTConnectivity.Common.ResourceInterfaces.Remove(_resourceInterfacesHandle, item); - if (ret != (int)IoTConnectivityError.None) + bool isRemoved = _resourceInterfaces.Remove(item); + if (isRemoved) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add interface"); - throw IoTConnectivityErrorFactory.GetException(ret); + int ret = Interop.IoTConnectivity.Common.ResourceInterfaces.Remove(_resourceInterfacesHandle, item); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add interface"); + throw IoTConnectivityErrorFactory.GetException(ret); + } } - _resourceInterfaces.Remove(item); + else + throw IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.InvalidParameter); } /// /// Return enumerator for the list of interfaces /// /// The enumerator + /// + /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(new List() + /// { ResourceInterfaces.LinkInterface, ResourceInterfaces.ReadonlyInterface }); + /// foreach(string item in resourceInterfaces) + /// { + /// Console.WriteLine("Interface : {0}", item); + /// } + /// public IEnumerator GetEnumerator() { return _resourceInterfaces.GetEnumerator(); } - public void Dispose() + /// + /// Return enumerator for the list of interfaces + /// + /// The enumerator + /// + /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(new List() + /// { ResourceInterfaces.LinkInterface, ResourceInterfaces.ReadonlyInterface }); + /// foreach(string item in resourceInterfaces) + /// { + /// Console.WriteLine("Interface : {0}", item); + /// } + /// + IEnumerator IEnumerable.GetEnumerator() { - Dispose(true); - GC.SuppressFinalize(this); + return _resourceInterfaces.GetEnumerator(); } - IEnumerator IEnumerable.GetEnumerator() + /// + /// Releases any unmanaged resources used by this object. + /// + public void Dispose() { - return _resourceInterfaces.GetEnumerator(); + Dispose(true); + GC.SuppressFinalize(this); } internal static bool IsValid(string type) @@ -193,6 +249,10 @@ namespace Tizen.Network.IoTConnectivity return (type.Length <= MaxLength && char.IsLower(type[0]) && r.IsMatch(type)); } + /// + /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. protected virtual void Dispose(bool disposing) { if (_disposed) diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceOptions.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceOptions.cs index 055f24d..373078f 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceOptions.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceOptions.cs @@ -10,12 +10,13 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using Tizen; namespace Tizen.Network.IoTConnectivity { /// - /// This class represents resource options. + /// This class represents resource options. It provides APIs to manage them.\n + /// The iotcon options API provides methods for managing vendor specific options of coap packet.\n + /// See more about coap packet in http://tools.ietf.org/html/rfc7252. /// public class ResourceOptions : IDictionary, IDisposable { @@ -28,6 +29,14 @@ namespace Tizen.Network.IoTConnectivity private readonly IDictionary _options = new Dictionary(); private bool _disposed = false; + /// + /// The resource options constructor + /// + /// + /// + /// + /// ResourceOptions options = new ResourceOptions(); + /// public ResourceOptions() { int ret = Interop.IoTConnectivity.Common.Options.Create(out _resourceOptionsHandle); @@ -38,6 +47,7 @@ namespace Tizen.Network.IoTConnectivity } } + // internal constructor internal ResourceOptions(IntPtr handleToClone) { int ret = Interop.IoTConnectivity.Common.Options.Create(out _resourceOptionsHandle); @@ -61,6 +71,9 @@ namespace Tizen.Network.IoTConnectivity } } + /// + /// Destructor of the ResourceOptions class. + /// ~ResourceOptions() { Dispose(false); @@ -69,6 +82,13 @@ namespace Tizen.Network.IoTConnectivity /// /// Contains all the Option keys /// + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(2050, "sample-data"); + /// options.Add(2055, "sample value"); + /// var keys = options.Keys; + /// Console.WriteLine("Resource options contains keys {0} and {1}", keys.ElementAt(0), keys.ElementAt(1)); + /// public ICollection Keys { get @@ -80,6 +100,13 @@ namespace Tizen.Network.IoTConnectivity /// /// Contains all the Option values /// + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(2050, "sample-data"); + /// options.Add(2055, "sample value"); + /// var values = options.Values; + /// Console.WriteLine("Resource options contains values {0} and {1}", values.ElementAt(0), values.ElementAt(1)); + /// public ICollection Values { get @@ -91,6 +118,13 @@ namespace Tizen.Network.IoTConnectivity /// /// Gets the number of options /// + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(2050, "sample-data"); + /// options.Add(2055, "sample value"); + /// var count = options.Count; + /// Console.WriteLine("There are {0} keys in the options object", count); + /// public int Count { get @@ -102,6 +136,11 @@ namespace Tizen.Network.IoTConnectivity /// /// Represents whether the collection is readonly /// + /// + /// ResourceOptions options = new ResourceOptions(); + /// if (options.IsReadOnly) + /// Console.WriteLine("Read only options"); + /// public bool IsReadOnly { get @@ -111,17 +150,22 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Gets or sets the option + /// Gets or sets the option data /// + /// /// The option id to get or set. /// The option with the specified id. + /// + /// ResourceOptions options = new ResourceOptions(); + /// options[2055] = "sample-data"; + /// Console.WriteLine("Option has : {0}", options[2055]); + /// public string this[ushort key] { get { return _options[key]; } - set { Add(key, value); @@ -129,20 +173,36 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Checks the given key exists in Options collection + /// Checks whether the given key exists in Options collection /// /// The key to look for - /// + /// true if exists. Otherwise, false + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(2050, "sample-data"); + /// if (options.ContainsKey(2050)) + /// Console.WriteLine("options conatins key : 2050"); + /// public bool ContainsKey(ushort key) { return _options.ContainsKey(key); } /// - /// Adds option key and value + /// Adds a new id and a correspoding data into the options. /// - /// Option ID - /// Value coresponding to option + /// + /// ResourceOptions can have up to 2 options. \n + /// key is always situated between 2048 and 3000. \n + /// Length of option data is less than or equal to 15. + /// + /// The id of the option to insert + /// The string data to insert into the options + /// + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(2050, "sample-data"); + /// public void Add(ushort key, string value) { int ret = (int)IoTConnectivityError.InvalidParameter; @@ -164,28 +224,45 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Removes an option + /// Removes the id and its associated data from the options. /// - /// The option to remvoe - /// + /// The id of the option to delete + /// True if operation is successful. Otherwise, false + /// + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(2050, "12345"); + /// var result = options.Remove(2050); + /// public bool Remove(ushort key) { - int ret = Interop.IoTConnectivity.Common.Options.Remove(_resourceOptionsHandle, key); - if (ret != (int)IoTConnectivityError.None) + bool isRemoved = _options.Remove(key); + if (isRemoved) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove option"); - throw IoTConnectivityErrorFactory.GetException(ret); + int ret = Interop.IoTConnectivity.Common.Options.Remove(_resourceOptionsHandle, key); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove option"); + throw IoTConnectivityErrorFactory.GetException(ret); + } } - - return _options.Remove(key); + return isRemoved; } /// /// Gets the value associated with the specified key. /// /// The option id - /// value corresponding to option id - /// true if the key exists, false otherwise + /// Value corresponding to option id + /// True if the key exists, false otherwise + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(2050, "12345"); + /// string value; + /// var isPresent = options.TryGetValue(2050, out value); + /// if (isPresent) + /// Console.WriteLine("value : {0}", value); + /// public bool TryGetValue(ushort key, out string value) { return _options.TryGetValue(key, out value); @@ -195,6 +272,11 @@ namespace Tizen.Network.IoTConnectivity /// Adds options key and value as a key value pair /// /// The key value pair + /// + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(new KeyValuePair(2050, "12345")); + /// public void Add(KeyValuePair item) { Add(item.Key, item.Value); @@ -203,6 +285,12 @@ namespace Tizen.Network.IoTConnectivity /// /// Clears the Options collection /// + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(2050, "12345"); + /// options.Add(2055, "sample"); + /// options.Clear(); + /// public void Clear() { foreach (ushort key in Keys) @@ -221,7 +309,14 @@ namespace Tizen.Network.IoTConnectivity /// Checks if the given option pair exists /// /// The key value pair - /// + /// True if exists. Otherwise, false + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(new KeyValuePair(2050, "12345")); + /// var isPresent = options.Contains(new KeyValuePair(2050, "12345")); + /// if (isPresent) + /// Console.WriteLine("Key value pair is present"); + /// public bool Contains(KeyValuePair item) { return _options.Contains(item); @@ -232,16 +327,29 @@ namespace Tizen.Network.IoTConnectivity /// /// The destination array /// Index parameter + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(new KeyValuePair(2050, "12345")); + /// KeyValuePair[] dest = new KeyValuePair[options.Count]; + /// options.CopyTo(dest, 0); + /// Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value); + /// public void CopyTo(KeyValuePair[] array, int arrayIndex) { _options.CopyTo(array, arrayIndex); } /// - /// Remove the gien option pair + /// Remove the given key value pair from the options /// - /// The option pair to remove - /// + /// The key value pair to remove + /// True if operation is successful. Otherwise, false + /// + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(new KeyValuePair(2050, "12345")); + /// var result = options.Remove(new KeyValuePair(2050, "12345")); + /// public bool Remove(KeyValuePair item) { return Remove(item.Key); @@ -250,23 +358,52 @@ namespace Tizen.Network.IoTConnectivity /// /// Get the enumerator to options collection /// - /// Enumerator to option pairs + /// Enumerator to option pairs + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(new KeyValuePair(2050, "sample1")); + /// options.Add(new KeyValuePair(2055, "sample2")); + /// foreach (KeyValuePair pair in options) + /// { + /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); + /// } + /// public IEnumerator> GetEnumerator() { return _options.GetEnumerator(); } + /// + /// Releases any unmanaged resources used by this object. + /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } + /// + /// Get the enumerator to options collection + /// + /// Enumerator to option pairs + /// + /// ResourceOptions options = new ResourceOptions(); + /// options.Add(new KeyValuePair(2050, "sample1")); + /// options.Add(new KeyValuePair(2055, "sample2")); + /// foreach (KeyValuePair pair in options) + /// { + /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); + /// } + /// IEnumerator IEnumerable.GetEnumerator() { return _options.GetEnumerator(); } + /// + /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. protected virtual void Dispose(bool disposing) { if (_disposed) diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs index 10a872c..afc3843 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceQuery.cs @@ -14,7 +14,7 @@ using System.Runtime.InteropServices; namespace Tizen.Network.IoTConnectivity { /// - /// Class to manage query of request. + /// This class provides APIs to manage query of request. /// public class ResourceQuery : IDictionary, IDisposable { @@ -24,8 +24,13 @@ namespace Tizen.Network.IoTConnectivity private bool _disposed = false; /// - /// Constructor + /// The resource query constructor /// + /// + /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// public ResourceQuery() { int ret = Interop.IoTConnectivity.Common.Query.Create(out _resourceQueryHandle); @@ -59,14 +64,22 @@ namespace Tizen.Network.IoTConnectivity } } + /// + /// Destructor of the ResourceQuery class. + /// ~ResourceQuery() { Dispose(false); } /// - /// Resource type of the query + /// Gets and sets the resource type of the query /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Type = "org.tizen.light"; + /// Console.WriteLine("Type of query : {0}", query.Type); + /// public string Type { get @@ -95,8 +108,15 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Resource interface of the query + /// Gets and sets the resource interface of the query /// + /// + /// Setter value could be a value such as + /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Interface = ResourceInterfaces.LinkInterface; + /// public string Interface { get @@ -125,8 +145,15 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Contains all keys of Query + /// Contains all the query keys /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add("key", "value"); + /// query.Add("newKey", "sample value"); + /// var keys = query.Keys; + /// Console.WriteLine("Resource query contains keys {0} and {1}", keys.ElementAt(0), keys.ElementAt(1)); + /// public ICollection Keys { get @@ -136,8 +163,15 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Contains all the values of Query + /// Contains all the query values /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add("key", "value"); + /// query.Add("newKey", "sample value"); + /// var values = query.Values; + /// Console.WriteLine("Resource query contains values {0} and {1}", values.ElementAt(0), values.ElementAt(1)); + /// public ICollection Values { get @@ -149,6 +183,13 @@ namespace Tizen.Network.IoTConnectivity /// /// Gets the number of query elements /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add("key", "value"); + /// query.Add("newKey", "sample value"); + /// var count = query.Count; + /// Console.WriteLine("There are {0} keys in the query object", count); + /// public int Count { get @@ -158,8 +199,13 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Represents whether Query is readonly + /// Represents whether the collection is readonly /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// if (query.IsReadOnly) + /// Console.WriteLine("Read only query"); + /// public bool IsReadOnly { get @@ -169,10 +215,15 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Gets or sets the Query key.. + /// Gets or sets the query data /// - /// The key of the Query to get or set. - /// The element with the specified key. + /// The query key to get or set. + /// The query with the specified key. + /// + /// ResourceQuery query = new ResourceQuery(); + /// query["key1"] = "sample-data"; + /// Console.WriteLine("query has : {0}", query["key1"]); + /// public string this[string key] { get @@ -187,20 +238,34 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Checks the given key exists in Query + /// Checks whether the given key exists in Query collection /// - /// The Query key + /// The key to look for /// true if exists. Otherwise, false + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add("key1", "value1"); + /// if (query.ContainsKey("key1")) + /// Console.WriteLine("query conatins key : key1"); + /// public bool ContainsKey(string key) { return _query.ContainsKey(key); } /// - /// Adds Query element + /// Adds a new key and correspoding value into the query. /// - /// The key representing the Query - /// The value representing the Query + /// + /// The full length of query should be less than or equal to 64. + /// + /// The key of the query to insert + /// The string data to insert into the query + /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add("key1", "value1"); + /// public void Add(string key, string value) { if (CanAddQuery(key, value)) @@ -221,45 +286,73 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Removes a Query element from collection + /// Removes the key and its associated value from the query. /// - /// The Query element to remove - /// true if operation is success. Otherwise, false + /// The id of the query to delete + /// True if operation is successful. Otherwise, false + /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add("key1", "value1"); + /// var result = query.Remove("key1"); + /// public bool Remove(string key) { - int ret = Interop.IoTConnectivity.Common.Query.Remove(_resourceQueryHandle, key); - if (ret != (int)IoTConnectivityError.None) + bool isRemoved = _query.Remove(key); + if (isRemoved) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove query"); - throw IoTConnectivityErrorFactory.GetException(ret); + int ret = Interop.IoTConnectivity.Common.Query.Remove(_resourceQueryHandle, key); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove query"); + throw IoTConnectivityErrorFactory.GetException(ret); + } } - - return _query.Remove(key); + return isRemoved; } /// /// Gets the value associated with the specified key. /// - /// The key whose value to get. - /// The value associated with the specified key - /// true if the Query contains an element with the specified key; otherwise, false. + /// The query key + /// Value corresponding to query key + /// True if the key exists, false otherwise + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add("key1", "value1"); + /// string value; + /// var isPresent = query.TryGetValue("key1", out value); + /// if (isPresent) + /// Console.WriteLine("value : {0}", value); + /// public bool TryGetValue(string key, out string value) { return _query.TryGetValue(key, out value); } /// - /// Adds Query as a key value pair + /// Adds query key and value as a key value pair /// /// The key value pair + /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add(new KeyValuePair("key1", "value1")); + /// public void Add(KeyValuePair item) { Add(item.Key, item.Value); } /// - /// Clears Query + /// Clears the Query collection /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add("key1", "value1"); + /// query.Add("key2", "value2"); + /// query.Clear(); + /// public void Clear() { foreach (string key in _query.Keys) @@ -275,62 +368,104 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Checks the given key value pair exists in Query + /// Checks if the given query pair exists /// /// The key value pair - /// true if exists. Otherwise, false + /// True if exists. Otherwise, false + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add(new KeyValuePair("key1", "value1")); + /// var isPresent = query.Contains(new KeyValuePair("key1", "value1")); + /// if (isPresent) + /// Console.WriteLine("Key value pair is present"); + /// public bool Contains(KeyValuePair item) { return _query.Contains(item); } /// - /// Copies the elements of the Query to an Array, starting at a particular index. + /// Copies the elements of the query collection to an Array, starting at a particular index. /// /// The destination array - /// The zero-based index in array at which copying begins. + /// Index parameter + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add(new KeyValuePair("key1", "value1")); + /// KeyValuePair[] dest = new KeyValuePair[query.Count]; + /// query.CopyTo(dest, 0); + /// Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value); + /// public void CopyTo(KeyValuePair[] array, int arrayIndex) { _query.CopyTo(array, arrayIndex); } /// - /// Removes a Query element from collection + /// Remove the given key value pair from the query /// - /// The Query element to remove - /// true if operation is success. Otherwise, false + /// The key value pair to remove + /// True if operation is successful. Otherwise, false + /// + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add(new KeyValuePair("key1", "value1")); + /// var result = query.Remove(new KeyValuePair("key1", "value1")); + /// public bool Remove(KeyValuePair item) { - int ret = Interop.IoTConnectivity.Common.Query.Remove(_resourceQueryHandle, item.Key); - if (ret != (int)IoTConnectivityError.None) - { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove query"); - throw IoTConnectivityErrorFactory.GetException(ret); - } - - return _query.Remove(item); + return Remove(item.Key); } /// - /// Returns an enumerator that iterates through the collection. + /// Get the enumerator to query collection /// - /// An enumerator that can be used to iterate through the collection. + /// Enumerator to query pairs + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add(new KeyValuePair("key1", "value1")); + /// query.Add(new KeyValuePair("key2", "value2")); + /// foreach (KeyValuePair pair in query) + /// { + /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); + /// } + /// public IEnumerator> GetEnumerator() { return _query.GetEnumerator(); } + /// + /// Get the enumerator to query collection + /// + /// Enumerator to query pairs + /// + /// ResourceQuery query = new ResourceQuery(); + /// query.Add(new KeyValuePair("key1", "value1")); + /// query.Add(new KeyValuePair("key2", "value2")); + /// foreach (KeyValuePair pair in query) + /// { + /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); + /// } + /// IEnumerator IEnumerable.GetEnumerator() { return _query.GetEnumerator(); } + /// + /// Releases any unmanaged resources used by this object. + /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } + /// + /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. protected virtual void Dispose(bool disposing) { if (_disposed) @@ -350,14 +485,14 @@ namespace Tizen.Network.IoTConnectivity int queryLenth = 0; foreach (string key in Keys) { - queryLenth += key.Length; + queryLenth += key.Length + 2; } foreach (string value in Values) { queryLenth += value.Length; } - if ((newKey.Length + newValue.Length + queryLenth) < QueryMaxLenth) + if ((newKey.Length + newValue.Length + queryLenth + 2) < QueryMaxLenth) return true; return false; diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceTypes.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceTypes.cs index 83e9afa..1e3d26a 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceTypes.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResourceTypes.cs @@ -14,7 +14,8 @@ using System.Text.RegularExpressions; namespace Tizen.Network.IoTConnectivity { /// - /// Class containing resource types + /// This class contains resource types and provides APIs to manage, add, remove those types. + /// A resource type indicates a class or category of resources. /// public class ResourceTypes : IEnumerable, IDisposable { @@ -24,8 +25,13 @@ namespace Tizen.Network.IoTConnectivity private bool _disposed = false; /// - /// Constructor + /// Constructor of ResourceTypes /// + /// + /// + /// + /// ResourceTypes types = new ResourceTypes(); + /// public ResourceTypes() { int ret = Interop.IoTConnectivity.Common.ResourceTypes.Create(out _resourceTypeHandle); @@ -37,8 +43,12 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Constructor + /// Constructor of ResourceTypes using list of types /// + /// List of resource types + /// + /// ResourceTypes types = new ResourceTypes(new List() { "org.tizen.light", "oic.if.room" }); + /// public ResourceTypes(IEnumerable types) { int ret = Interop.IoTConnectivity.Common.ResourceTypes.Create(out _resourceTypeHandle); @@ -54,9 +64,6 @@ namespace Tizen.Network.IoTConnectivity } } - /// - /// Constructor - /// internal ResourceTypes(IntPtr typesHandleToClone) { int ret = Interop.IoTConnectivity.Common.ResourceTypes.Clone(typesHandleToClone, out _resourceTypeHandle); @@ -80,14 +87,21 @@ namespace Tizen.Network.IoTConnectivity } } + /// + /// Destructor of the ResourceTypes class. + /// ~ResourceTypes() { Dispose(false); } /// - /// Count of resource types in the list + /// Indicates count of types in the list /// + /// + /// ResourceTypes types = new ResourceTypes(new List() { "org.tizen.light", "oic.if.room" }); + /// Console.WriteLine("There are {0} items", types.Count); + /// public int Count { get @@ -97,9 +111,20 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Inserts a resource type into the list. + /// Adds a resource type into the list. /// - /// The resource type to add + /// + /// The length of @a item should be less than or equal to 61.\n + /// The @a item must start with a lowercase alphabetic character, followed by a sequence + /// of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space.\n + /// Duplicate strings are not allowed. + /// + /// The string data to insert into the resource types + /// + /// + /// ResourceTypes resourceTypes = new ResourceTypes(); + /// resourceTypes.Add("org.tizen.light"); + /// public void Add(string item) { if (IsValid(item)) @@ -120,35 +145,65 @@ namespace Tizen.Network.IoTConnectivity } /// - /// Removes a resource type from the list + /// Removes a resource type from the list /// - /// The resource type to remove + /// The string data to delete from the resource types + /// + /// + /// ResourceTypes resourceTypes = new ResourceTypes(new List() { "org.tizen.light", "oic.if.room" }); + /// resourceTypes.Remove("oic.if.room"); + /// public void Remove(string item) { - int ret = Interop.IoTConnectivity.Common.ResourceTypes.Remove(_resourceTypeHandle, item); - if (ret != (int)IoTConnectivityError.None) + bool isRemoved = _resourceTypes.Remove(item); + if (isRemoved) { - Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove type"); - throw IoTConnectivityErrorFactory.GetException(ret); + int ret = Interop.IoTConnectivity.Common.ResourceTypes.Remove(_resourceTypeHandle, item); + if (ret != (int)IoTConnectivityError.None) + { + Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove type"); + throw IoTConnectivityErrorFactory.GetException(ret); + } } - - _resourceTypes.Remove(item); + else + throw IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.InvalidParameter); } /// - /// Return enumerator for the list of types + /// Return enumerator for the list of types /// - /// Enumerator of the collection + /// The enumerator + /// + /// ResourceTypes resourceTypes = new ResourceTypes(new List() { "org.tizen.light", "oic.if.room" }); + /// foreach(string item in resourceTypes) + /// { + /// Console.WriteLine("Type : {0}", item); + /// } + /// public IEnumerator GetEnumerator() { return _resourceTypes.GetEnumerator(); } + /// + /// Return enumerator for the list of types + /// + /// The enumerator + /// + /// ResourceTypes resourceTypes = new ResourceTypes(new List() { "org.tizen.light", "oic.if.room" }); + /// foreach(string item in resourceTypes) + /// { + /// Console.WriteLine("Type : {0}", item); + /// } + /// IEnumerator IEnumerable.GetEnumerator() { return _resourceTypes.GetEnumerator(); } + /// + /// Releases any unmanaged resources used by this object. + /// public void Dispose() { Dispose(true); @@ -161,6 +216,10 @@ namespace Tizen.Network.IoTConnectivity return (type.Length <= MaxLength && char.IsLower(type[0]) && r.IsMatch(type)); } + /// + /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. protected virtual void Dispose(bool disposing) { if (_disposed) diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Response.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Response.cs index bab888e..858210e 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Response.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/Response.cs @@ -12,26 +12,46 @@ namespace Tizen.Network.IoTConnectivity { /// /// This class represents response from a resource. + /// It provides APIs to manage response. /// public class Response : IDisposable { private bool _disposed = false; + /// + /// Constructor of Response + /// + /// + /// Response response = new Response(); + /// + public Response() { } + + /// + /// Destructor of the Response class. + /// ~Response() { Dispose(false); } /// - /// Result corresponding to a request + /// Gets or sets the result from/into the reponse /// public ResponseCode Result { get; set; } /// - /// Representation of the resource + /// Gets or sets the representation from/into the reponse /// public Representation Representation { get; set; } + /// + /// Gets or sets the options from/into the reponse + /// + public ResourceOptions Options { get; set; } + + /// + /// Releases any unmanaged resources used by this object. + /// public void Dispose() { Dispose(true); @@ -67,6 +87,17 @@ namespace Tizen.Network.IoTConnectivity } } + if (Options != null) + { + ret = Interop.IoTConnectivity.Server.Response.SetOptions(responseHandle, Options._resourceOptionsHandle); + 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); if (ret != (int)IoTConnectivityError.None) { @@ -79,6 +110,10 @@ namespace Tizen.Network.IoTConnectivity return true; } + /// + /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. protected virtual void Dispose(bool disposing) { if (_disposed) diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResponseCode.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResponseCode.cs index 3bddc37..c610a1e 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResponseCode.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/ResponseCode.cs @@ -9,7 +9,7 @@ namespace Tizen.Network.IoTConnectivity { /// - /// Enumeration for result response + /// Enumeration for result of response /// public enum ResponseCode { @@ -18,15 +18,15 @@ namespace Tizen.Network.IoTConnectivity /// Ok = 0, /// - /// Indicates result of response for something error + /// Indicates result of response for some error /// Error, /// - /// Indicates result of response for resource has created + /// Indicates result of response for created resource /// Created, /// - /// Indicates result of response for resource has deleted + /// Indicates result of response for deleted resource /// Deleted, /// diff --git a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/StateChangedEventArgs.cs b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/StateChangedEventArgs.cs index db72864..a1b9f3b 100755 --- a/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/StateChangedEventArgs.cs +++ b/src/Tizen.Network.IoTConnectivity/Tizen.Network.IoTConnectivity/StateChangedEventArgs.cs @@ -18,9 +18,8 @@ namespace Tizen.Network.IoTConnectivity internal StateChangedEventArgs() { } /// - /// State property. + /// Indicates the new state of the resource /// - /// ResourceState State. public ResourceState State { get; internal set; } } } -- 2.7.4