{
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
{
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
{
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();
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);
{
/// <summary>
/// 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.
/// </summary>
public class Attributes : IDictionary<string, object>, IDisposable
{
private bool _disposed = false;
/// <summary>
- /// Constructor
+ /// The Attributes constructor
/// </summary>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
+ /// </code>
public Attributes()
{
int ret = Interop.IoTConnectivity.Common.Attributes.Create(out _resourceAttributesHandle);
SetAttributes(attributesHandleToClone);
}
+ /// <summary>
+ /// Destructor of the Attributes class.
+ /// </summary>
~Attributes()
{
Dispose(false);
}
/// <summary>
- /// Gets the number of status elements
+ /// Gets the number of keys
/// </summary>
+ /// <code>
+ /// 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);
+ /// </code>
public int Count
{
get
}
/// <summary>
- /// Represents whether Attributes is readonly
+ /// Represents whether attribute is readonly
/// </summary>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
+ /// { "state", "ON" },
+ /// { "dim", 10 }
+ /// };
+ /// if (attributes.IsReadOnly)
+ /// Console.WriteLine("Read only attribute");
+ /// </code>
public bool IsReadOnly
{
get
}
/// <summary>
- /// Contains all the status keys
+ /// Contains all the attribute keys
/// </summary>
+ /// <code>
+ /// 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));
+ /// </code>
public ICollection<string> Keys
{
get
}
/// <summary>
- /// Contains all the status values
+ /// Contains all the attribute values
/// </summary>
+ /// <code>
+ /// 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));
+ /// </code>
public ICollection<object> Values
{
get
}
/// <summary>
- /// Gets or sets the status with the specified key.
+ /// Gets or sets the attribute with the specified key.
/// </summary>
- /// <param name="key">The key of the status to get or set.</param>
+ /// <param name="key">The key of the attribute to get or set.</param>
/// <returns>The element with the specified key.</returns>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
+ /// attributes["state"] = "ON";
+ /// Console.WriteLine("Attribute value for key 'state' : {0}", attributes["state"]);
+ /// </code>
public object this[string key]
{
get
{
- return _attributes[key];
+ if (_attributes.ContainsKey(key))
+ return _attributes[key];
+ else
+ return null;
}
set
}
/// <summary>
- /// Adds status key and value as a key value pair
+ /// Adds attribute key and value as a key value pair
/// </summary>
- /// <param name="item">The item to add</param>
+ /// <param name="item">The key value pair to add</param>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
+ /// attributes.Add(new KeyValuePair<string, object> ("state", "ON"));
+ /// </code>
public void Add(KeyValuePair<string, object> item)
{
Add(item.Key, item.Value);
}
/// <summary>
- /// Adds status element
+ /// Adds an attribute
/// </summary>
- /// <param name="key">The key representing the attributes</param>
- /// <param name="value">The value representing the attributes</param>
+ /// <param name="key">The key representing the attribute</param>
+ /// <param name="value">The value representing the attribute</param>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
+ /// attributes.Add("brightness", 50);
+ /// </code>
public void Add(string key, object value)
{
int ret = 0;
/// <summary>
/// Clears attributes collection
/// </summary>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
+ /// attributes.Add("brightness", 50);
+ /// attributes.Clear();
+ /// </code>
public void Clear()
{
foreach (string key in _attributes.Keys)
}
/// <summary>
- /// Checks the given key value pair exists in attributes collection
+ /// Checks whether the given key value pair exists in attributes collection
/// </summary>
/// <param name="item">The status key value pair</param>
/// <returns>true if exists. Otherwise, false</returns>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
+ /// { "state", "ON" },
+ /// { "dim", 10 }
+ /// };
+ /// if (attributes.Contains(new KeyValuePair<string, object> ("dim", 10))
+ /// Console.WriteLine("Attribute conatins pair ('dim', 10)");
+ /// </code>
public bool Contains(KeyValuePair<string, object> item)
{
return _attributes.Contains(item);
}
/// <summary>
- /// Checks the given key exists in attributes collection
+ /// Checks whether the given key exists in attributes collection
/// </summary>
- /// <param name="key">The status key</param>
+ /// <param name="key">The status key to look for</param>
/// <returns>true if exists. Otherwise, false</returns>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
+ /// { "state", "ON" },
+ /// { "dim", 10 }
+ /// };
+ /// if (attributes.ContainsKey("dim"))
+ /// Console.WriteLine("Attribute conatins key : dim");
+ /// </code>
public bool ContainsKey(string key)
{
return _attributes.ContainsKey(key);
}
/// <summary>
- /// 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.
/// </summary>
/// <param name="array">The destination array</param>
/// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
+ /// { "state", "ON" },
+ /// { "dim", 10 }
+ /// };
+ /// KeyValuePair<string, object>[] dest = new KeyValuePair<string, object>[attributes.Count];
+ /// int index = 0;
+ /// attributes.CopyTo(dest, index);
+ /// Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value);
+ /// </code>
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
{
_attributes.CopyTo(array, arrayIndex);
/// Returns an enumerator that iterates through the collection.
/// </summary>
/// <returns> An enumerator that can be used to iterate through the collection.</returns>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
+ /// { "state", "ON" },
+ /// { "dim", 10 }
+ /// };
+ /// foreach (KeyValuePair<string, object> pair in attributes)
+ /// {
+ /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value);
+ /// }
+ /// </code>
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
{
return _attributes.GetEnumerator();
}
/// <summary>
- /// Removes a attributes element from collection
+ /// Removes an attribute from collection
/// </summary>
/// <param name="item">The attributes element to remove</param>
/// <returns>true if operation is success. Otherwise, false</returns>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
+ /// { "state", "ON" },
+ /// { "dim", 10 }
+ /// };
+ /// if (attributes.Remove(new KeyValuePair<string, object>("dim", 10)))
+ /// Console.WriteLine("Remove was successful");
+ /// </code>
public bool Remove(KeyValuePair<string, object> 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);
}
/// <summary>
- /// Removes a attributes element from collection using key
+ /// Removes an attribute from collection using key
/// </summary>
/// <param name="key">The attributes element to remove</param>
- /// <returns>true if operation is success. Otherwise, false</returns>
+ /// <returns>true if operation is successful, Otherwise, false</returns>
+ /// <code>
+ /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
+ /// { "state", "ON" },
+ /// { "dim", 10 }
+ /// };
+ /// if (attributes.Remove("state"))
+ /// Console.WriteLine("Remove was successful");
+ /// </code>
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;
}
/// <summary>
/// <param name="key">The key whose value to get.</param>
/// <param name="value"> The value associated with the specified key</param>
/// <returns> true if the attributes collection contains an element with the specified key; otherwise, false.</returns>
+ /// <code>
+ /// 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);
+ /// </code>
public bool TryGetValue(string key, out object value)
{
return _attributes.TryGetValue(key, out value);
}
+ /// <summary>
+ /// Returns an enumerator that iterates through the collection.
+ /// </summary>
IEnumerator IEnumerable.GetEnumerator()
{
return _attributes.GetEnumerator();
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed)
internal CacheUpdatedEventArgs() { }
/// <summary>
- /// Representation property.
+ /// Indicates the updated representation of the resource
/// </summary>
- /// <returns>Representation Representation.</returns>
public Representation Representation { get; internal set; }
}
}
public string Name { get; internal set; }
/// <summary>
- /// Indicates human friendly name for device
+ /// Indicates spec version of the core specification
/// </summary>
public string SpecVersion { get; internal set; }
internal FindingErrorOccurredEventArgs() { }
/// <summary>
- /// RequestId property.
+ /// The request id of the operation which caused this error
/// </summary>
- /// <returns>int RequestId.</returns>
public int RequestId { get; internal set; }
/// <summary>
- /// Result property.
+ /// Contains error details.
/// </summary>
- /// <returns>FindingError Result.</returns>
public Exception Error { get; internal set; }
}
}
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// IoT connectivity client manager.
+ /// IoT connectivity client manager consists of client side APIs.
/// </summary>
public static class IoTConnectivityClientManager
{
+ /// <summary>
+ /// The IP Address for multicast
+ /// </summary>
public const string MulticastAddress = null;
private static int s_presenceListenerId = 1;
private static Dictionary<IntPtr, Interop.IoTConnectivity.Client.PlatformInformation.PlatformInformationCallback> s_platformInformationCallbacksMap = new Dictionary<IntPtr, Interop.IoTConnectivity.Client.PlatformInformation.PlatformInformationCallback>();
/// <summary>
- /// presence event on the resource
+ /// PresenceReceived event. This event is occurred when server starts sending presence of a resource.
/// </summary>
public static event EventHandler<PresenceReceivedEventArgs> PresenceReceived;
/// <summary>
- /// 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().
/// </summary>
public static event EventHandler<ResourceFoundEventArgs> ResourceFound;
/// <summary>
- /// PlatformInformationFound event handler
+ /// PlatformInformationFound event. This event is occurred when platform information is found
+ /// after sending request using API StartFindingPlatformInformation().
/// </summary>
public static event EventHandler<PlatformInformationFoundEventArgs> PlatformInformationFound;
/// <summary>
- /// DeviceInformationFound event handler
+ /// DeviceInformationFound event. This event is occurred when device information is found
+ /// after sending request using API StartFindingDeviceInformation().
/// </summary>
public static event EventHandler<DeviceInformationFoundEventArgs> DeviceInformationFound;
/// <summary>
- /// FoundError event handler
+ /// FindingError event. This event is occurred when an error is found.
/// </summary>
public static event EventHandler<FindingErrorOccurredEventArgs> FindingErrorOccurred;
/// <summary>
- /// Timeout property
+ /// Timeout in seconds
/// </summary>
+ /// <remarks>
+ /// 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.
+ /// </remarks>
+ /// <pre>
+ /// Initialize() should be called to initialize
+ /// </pre>
+ /// <code>
+ /// IoTConnectivityClientManager.Initialize();
+ /// IoTConnectivityClientManager.TimeOut = 120;
+ /// </code>
public static int TimeOut
{
get
}
/// <summary>
- /// Timeout property
+ /// Polling interval of IoTConnectivity
/// </summary>
+ /// <remarks>
+ /// 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.
+ /// </remarks>
+ /// <pre>
+ /// Initialize() should be called to initialize
+ /// </pre>
+ /// <code>
+ /// IoTConnectivityClientManager.Initialize();
+ /// IoTConnectivityClientManager.PollingInterval = 100;
+ /// </code>
public static int PollingInterval
{
get
}
/// <summary>
- /// Connects to the iotcon service
+ /// Initializes IoTCon.
+ /// Call this function to start IoTCon.
/// </summary>
- public static void Initialize()
+ /// <remarks>
+ /// @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.
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/network.get \n
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <param name="filePath">The file path to point to storage for handling secure virtual resources.</param>
+ /// <post>
+ /// You must call Deinitialize() if IoTCon API is no longer needed.
+ /// </post>
+ /// <seealso cref="Deinitialize()"/>
+ /// <code>
+ /// string filePath = "../../res/iotcon-test-svr-db-client.dat";
+ /// IoTConnectivityClientManager.Initialize(filePath);
+ /// </code>
+ 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");
}
/// <summary>
- /// Initializes IoTCon with secure mode.
- /// </summary>
- 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);
- }
- }
-
- /// <summary>
- /// Disconnects from the iotcon service
+ /// Deinitializes IoTCon.
/// </summary>
+ /// <remarks>
+ /// This API must be called if IoTCon API is no longer needed.
+ /// </remarks>
+ /// <pre>
+ /// Initialize() should be called to initialize.
+ /// </pre>
+ /// <seealso cref="Initialize()"/>
+ /// <seealso cref="SecureInitialize()"/>
+ /// <code>
+ /// IoTConnectivityClientManager.Deinitialize();
+ /// </code>
public static void Deinitialize()
{
Interop.IoTConnectivity.Client.IoTCon.Deinitialize();
/// <summary>
/// Invokes a next message from a queue for receiving messages from others, immediately.
/// </summary>
+ /// <remarks>
+ /// 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.
+ /// </remarks>
+ /// <pre>
+ /// Initialize() should be called to initialize.
+ /// </pre>
+ /// <code>
+ /// IoTConnectivityClientManager.InvokePolling();
+ /// </code>
public static void InvokePolling()
{
int ret = Interop.IoTConnectivity.Client.IoTCon.InvokePolling();
/// <summary>
/// Starts receiving presence events
/// </summary>
- /// <returns>
- /// PresenceId
- /// </returns>
+ /// <remarks>
+ /// Sends request to receive presence to an interested server's resource with resourceType.
+ /// If succeeded, <see cref="PresenceReceived"/> 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 <see cref="MulticastAddress"/> 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.
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <param name="hostAddress">The address or addressable name of the server</param>
+ /// <param name="resourceType">A resource type that a client is interested in</param>
+ /// <returns>PresenceId - An identifier for this request</returns>
+ /// <pre>Initialize() should be called to initialize.</pre>
+ /// <post>
+ /// When the resource receive presence, <see cref="PresenceReceived"/> event handler will be invoked.\n
+ /// You must destroy presence by calling StopReceivingPresence() if presence event is no longer needed.
+ /// </post>
+ /// <seealso cref="IoTConnectivityServerManager.StartSendingPresence()"/>
+ /// <seealso cref="IoTConnectivityServerManager.StopSendingPresence()"/>
+ /// <seealso cref="StopReceivingPresence()"/>
+ /// <seealso cref="PresenceReceived"/>
+ /// <code>
+ /// EventHandler<PresenceReceivedEventArgs> handler = (sender, e) => {
+ /// Console.Log("PresenceReceived, presence id :" + e.PresenceId);
+ /// }
+ /// EventHandler<FindingErrorOccurredEventArgs> 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");
+ /// </code>
public static int StartReceivingPresence(string hostAddress, string resourceType)
{
Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress);
/// <summary>
/// Stops receiving presence events
/// </summary>
+ /// <remarks>
+ /// Sends request to not to receive server's presence any more.
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <param name="presenceId">The start presence request identifier</param>
+ /// <pre>
+ /// Initialize() should be called to initialize.
+ /// </pre>
+ /// <seealso cref="IoTConnectivityServerManager.StartSendingPresence()"/>
+ /// <seealso cref="IoTConnectivityServerManager.StopSendingPresence()"/>
+ /// <seealso cref="StartReceivingPresence()"/>
+ /// <seealso cref="PresenceReceived"/>
+ /// <code>
+ /// EventHandler<PresenceReceivedEventArgs> handler = (sender, e) => {
+ /// Console.Log("PresenceReceived, presence id :" + e.PresenceId);
+ /// }
+ /// EventHandler<FindingErrorOccurredEventArgs> 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);
+ /// </code>
public static void StopReceivingPresence(int presenceId)
{
if (s_presenceHandlesMap.ContainsKey((IntPtr)presenceId))
}
/// <summary>
- /// Starts finding resource events
+ /// Starts finding resources.
/// </summary>
- /// <returns>
- /// RequestId
- /// </returns>
+ /// <remarks>
+ /// Sends request to find a resource of @a hostAddress server with @a resourceType.
+ /// If succeeded, <see cref="ResourceFound"/> event handler will be triggered with information of the resource.\n
+ /// @a hostAddress could be <see cref="MulticastAddress"/> 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.
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <param name="hostAddress">The address or addressable name of the server</param>
+ /// <param name="resourceType">A resource type specified as a filter for the resource</param>
+ /// <param name="isSecure">The flag for secure communication with the server</param>
+ /// <returns>RequestId - An identifier for this request</returns>
+ /// <pre>Initialize() should be called to initialize.</pre>
+ /// <post>
+ /// When the resource is found, <see cref="ResourceFound"/> event handler will be invoked.
+ /// </post>
+ /// <seealso cref="ResourceFound"/>
+ /// <seealso cref="ResourceFoundEventArgs"/>
+ /// <seealso cref="TimeOut"/>
+ /// <code>
+ /// EventHandler<ResourceFoundEventArgs> handler = (sender, e) => {
+ /// Console.Log("Found resource at host address :" + e.Resource.HostAddress + ", uri :" + e.Resource.UriPath);
+ /// }
+ /// EventHandler<FindingErrorOccurredEventArgs> 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");
+ /// </code>
public static int StartFindingResource(string hostAddress, string resourceType, bool isSecure = false)
{
Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress);
}
s_resourceFoundCallbacksMap[id] = (IntPtr remoteResourceHandle, int result, IntPtr userData) =>
{
+ if (ResourceFound == null)
+ return false;
+
int requestId = (int)userData;
if (result == (int)IoTConnectivityError.None)
{
catch (Exception exp)
{
Log.Error(IoTConnectivityErrorFactory.LogTag, "Can't clone RemoteResource's handle: " + exp.Message);
- return;
+ return true;
}
ResourceFoundEventArgs e = new ResourceFoundEventArgs()
{
else
{
Log.Error(IoTConnectivityErrorFactory.LogTag, "Handle is null");
- return;
}
}
else
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)
}
/// <summary>
- /// Starts finding device information events
+ /// Starts finding the device information of remote server.
/// </summary>
- /// <returns>
- /// RequestId
- /// </returns>
+ /// <remarks>
+ /// Requests server for device information.
+ /// If succeeded, <see cref="DeviceInformationFound"/> event handler will be triggered with information of the device.\n
+ /// @a hostAddress could be <see cref="MulticastAddress"/> for IPv4 multicast.
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <param name="hostAddress">The host address of remote server</param>
+ /// <returns>RequestId - An identifier for this request</returns>
+ /// <pre>Initialize() should be called to initialize.</pre>
+ /// <post>
+ /// <see cref="DeviceInformationFound" /> event handler will be invoked.
+ /// </post>
+ /// <seealso cref="IoTConnectivityServerManager.SetDeviceName()"/>
+ /// <seealso cref="DeviceInformationFound"/>
+ /// <seealso cref="DeviceInformationFoundEventArgs"/>
+ /// <seealso cref="TimeOut"/>
+ /// <code>
+ /// EventHandler<DeviceInformationFoundEventArgs> handler = (sender, e) => {
+ /// Console.Log("Device information found, id : " + e.RequestId + ", name : " + e.Name);
+ /// }
+ /// EventHandler<FindingErrorOccurredEventArgs> 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);
+ /// </code>
public static int StartFindingDeviceInformation(string hostAddress)
{
Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress);
}
s_deviceInformationCallbacksMap[id] = (IntPtr deviceInfoHandle, int result, IntPtr userData) =>
{
+ if (DeviceInformationFound == null)
+ return false;
+
int requestId = (int)userData;
if (result == (int)IoTConnectivityError.None)
{
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
s_deviceInformationCallbacksMap.Remove(id);
}
}
+ return true;
};
int errorCode = Interop.IoTConnectivity.Client.DeviceInformation.Find(hostAddress, (int)connectivityType, s_deviceInformationCallbacksMap[id], id);
}
/// <summary>
- /// Starts finding platform information events
+ /// Starts finding the platform information of remote server.
/// </summary>
- /// <returns>
- /// RequestId
- /// </returns>
+ /// <remarks>
+ /// Requests server for platform information.
+ /// If succeeded, <see cref="PlatformInformationFound" /> event handler will be triggered with information of the platform.\n
+ /// @a hostAddress could be <see cref="MulticastAddress"/> for IPv4 multicast.
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <param name="hostAddress">The host address of remote server</param>
+ /// <returns>RequestId - An identifier for this request</returns>
+ /// <pre>Initialize() should be called to initialize.</pre>
+ /// <post>
+ /// <see cref="PlatformInformationFound" /> event handler will be invoked.
+ /// </post>
+ /// <seealso cref="PlatformInformationFound"/>
+ /// <seealso cref="PlatformInformationFoundEventArgs"/>
+ /// <seealso cref="TimeOut"/>
+ /// <code>
+ /// EventHandler<PlatformInformationFoundEventArgs> handler = (sender, e) => {
+ /// Console.Log("PlatformInformationFound :" + e.RequestId);
+ /// }
+ /// EventHandler<FindingErrorOccurredEventArgs> 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);
+ /// </code>
public static int StartFindingPlatformInformation(string hostAddress)
{
Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress);
}
s_platformInformationCallbacksMap[id] = (IntPtr platformInfoHandle, int result, IntPtr userData) =>
{
+ if (PlatformInformationFound == null)
+ return false;
+
int requestId = (int)userData;
if (result == (int)IoTConnectivityError.None)
{
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
s_platformInformationCallbacksMap.Remove(id);
}
}
+ return true;
};
int errorCode = Interop.IoTConnectivity.Client.PlatformInformation.Find(hostAddress, (int)connectivityType, s_platformInformationCallbacksMap[id], id);
return (int)id;
}
+ // Private methods
private static PresenceReceivedEventArgs GetPresenceReceivedEventArgs(int presenceId, IntPtr presenceResponseHandle)
{
int trigger;
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;
/// you entered into with Samsung.
using System;
+using System.IO;
using Tizen.Internals.Errors;
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)
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)
{
}
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)
{
}
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
{
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// IoT connectivity server manager.
+ /// IoT connectivity server manager consists of server side APIs.
/// </summary>
public static class IoTConnectivityServerManager
{
/// <summary>
- /// Initializes connection with IoTCon service
+ /// Initializes IoTCon. Call this API to start IoTCon.
/// </summary>
- public static void Initialize()
+ /// <remarks>
+ /// @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.
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/network.get \n
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <param name="filePath">The file path to point to storage for handling secure virtual resources.</param>
+ /// <post>
+ /// You must call Deinitialize() if IoTCon API is no longer needed.
+ /// </post>
+ /// <seealso cref="Deinitialize()"/>
+ /// <code>
+ /// string filePath = "../../res/iotcon-test-svr-db-server.dat";
+ /// IoTConnectivityServerManager.Initialize(filePath);
+ /// </code>
+ 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");
}
/// <summary>
- /// Disconnects with IoTCon service
+ /// Deinitializes IoTCon.
/// </summary>
+ /// <remarks>
+ /// This API must be called if IoTCon API is no longer needed.
+ /// </remarks>
+ /// <pre>
+ /// Initialize() should be called to initialize.
+ /// </pre>
+ /// <seealso cref="Initialize()"/>
+ /// <code>
+ /// IoTConnectivityServerManager.Deinitialize();
+ /// </code>
public static void Deinitialize()
{
Interop.IoTConnectivity.Client.IoTCon.Deinitialize();
}
/// <summary>
- /// Registers a resource to be available from IoTCon server
+ /// Registers a resource in IoTCon server
/// </summary>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
/// <param name="resource">The resource to register</param>
+ /// <pre>
+ /// Initialize() should be called to initialize.
+ /// </pre>
+ /// <seealso cref="Resource"/>
+ /// <seealso cref="LiteResource"/>
+ /// <code>
+ /// ResourceTypes types = new ResourceTypes(new List<string>(){ "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);
+ /// }
+ /// </code>
public static void RegisterResource(Resource resource)
{
IntPtr handle = IntPtr.Zero;
/// <summary>
/// Starts presence of a server
/// </summary>
+ /// <remarks>
+ /// 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).
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
/// <param name="time">The interval of announcing presence in seconds.</param>
+ /// <pre>
+ /// Initialize() should be called to initialize.
+ /// </pre>
+ /// <seealso cref="IoTConnectivityClientManager.StartReceivingPresence()"/>
+ /// <seealso cref="IoTConnectivityClientManager.StopReceivingPresence()"/>
+ /// <seealso cref="IoTConnectivityClientManager.PresenceReceived"/>
+ /// <seealso cref="StopSendingPresence()"/>
+ /// <code>
+ /// try {
+ /// IoTConnectivityServerManager.StartSendingPresence(120);
+ /// } catch(Exception ex) {
+ /// Console.Log("Exception caught : " + ex.Message);
+ /// }
+ /// </code>
public static void StartSendingPresence(uint time)
{
int ret = Interop.IoTConnectivity.Server.IoTCon.StartPresence(time);
/// <summary>
/// Stops presence of a server.
/// </summary>
+ /// <remarks>
+ /// 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.
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <pre>
+ /// Initialize() should be called to initialize.
+ /// </pre>
+ /// <seealso cref="IoTConnectivityClientManager.StartReceivingPresence()"/>
+ /// <seealso cref="IoTConnectivityClientManager.StopReceivingPresence()"/>
+ /// <seealso cref="IoTConnectivityClientManager.PresenceReceived"/>
+ /// <seealso cref="StartSendingPresence()"/>
+ /// <code>
+ /// IoTConnectivityServerManager.StopSendingPresence();
+ /// </code>
public static void StopSendingPresence()
{
int ret = Interop.IoTConnectivity.Server.IoTCon.StopPresence();
/// <summary>
/// Sets the device name
/// </summary>
+ /// <remarks>
+ /// 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 <see cref="IoTConnectivityClientManager.StartFindingDeviceInformation()"/>.
+ /// Clients can also get the name using <see cref="RemoteResource.DeviceName"/> property.
+ /// </remarks>
/// <param name="deviceName">The device name</param>
+ /// <seealso cref="IoTConnectivityClientManager.DeviceInformationFound"/>
+ /// <seealso cref="IoTConnectivityClientManager.StartFindingDeviceInformation()"/>
+ /// <seealso cref="DeviceInformationFoundEventArgs"/>
+ /// <seealso cref="RemoteResource.DeviceName"/>
+ /// <code>
+ /// IoTConnectivityServerManager.SetDeviceName("my-tizen");
+ /// </code>
public static void SetDeviceName(string deviceName)
{
int ret = Interop.IoTConnectivity.Server.IoTCon.SetDeviceName(deviceName);
/// it only in accordance with the terms of the license agreement
/// you entered into with Samsung.
-using System.Collections.Generic;
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// 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.
/// </summary>
public class LiteResource : Resource
{
/// <summary>
- /// Constructor
+ /// The LiteResource constructor
/// </summary>
+ /// <remarks>
+ /// Creates a lite resource which can then be registered in server using <see cref="IoTConnectivityServerManager.RegisterResource()"/>.\n
+ /// When client requests some operations, it send a response to client, automatically.\n
+ /// @a uri length must be less than 128.
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
/// <param name="uri">The uri path of the lite resource</param>
- /// <param name="types">Resource type</param>
+ /// <param name="types">The type of the resource</param>
/// <param name="policy">Policy of the resource</param>
/// <param name="attribs">Optional attributes of the resource</param>
+ /// <pre>
+ /// IoTConnectivityServerManager.Initialize() should be called to initialize
+ /// </pre>
+ /// <seealso cref="ResourceTypes"/>
+ /// <seealso cref="ResourcePolicy"/>
+ /// <seealso cref="Attributes"/>
+ /// <code>
+ /// List<string> list = new List<string>() { "org.tizen.light" };
+ /// Attributes attributes = new Attributes() {
+ /// { "state", "ON" }
+ /// };
+ /// LiteResource res = new LiteResource("/light/1", new ResourceTypes(list), ResourcePolicy.Discoverable, attributes);
+ /// </code>
public LiteResource(string uri, ResourceTypes types, ResourcePolicy policy, Attributes attribs = null)
: base(uri, types, new ResourceInterfaces(new string[] { ResourceInterfaces.DefaultInterface }), policy)
{
}
/// <summary>
- /// The attributes of the lite resource
+ /// Gets or sets the attributes of the lite resource
/// </summary>
+ /// <code>
+ /// List<string> list = new List<string>() { "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<string, object> pair in res.Attributes)
+ /// {
+ /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value);
+ /// }
+ /// </code>
public Attributes Attributes { get; set; }
/// <summary>
- /// The method to accept post request
+ /// Decides whether to accept or reject a post request.
/// </summary>
+ /// <remarks>
+ /// Child classes of this class can override this method to accept or reject post request.
+ /// </remarks>
/// <param name="attribs">The new attributes of the lite resource</param>
/// <returns>true to accept post request, false to reject it</returns>
+ /// <code>
+ /// 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;
+ /// }
+ /// }
+ /// </code>
protected virtual bool OnPost(Attributes attribs)
{
return true;
}
- /// <summary>
- /// Called on the get event.
- /// </summary>
- /// <param name="request">Request.</param>
protected sealed override Response OnGet(Request request)
{
Representation representation = new Representation()
return response;
}
- /// <summary>
- /// Called on the put event.
- /// </summary>
- /// <param name="request">Request.</param>
protected sealed override Response OnPut(Request request)
{
Response response = new Response();
return response;
}
- /// <summary>
- /// Called on the post event.
- /// </summary>
- /// <param name="request">Request.</param>
protected sealed override Response OnPost(Request request)
{
if (OnPost(request.Representation.Attributes))
};
}
- /// <summary>
- /// Called on the delete event.
- /// </summary>
- /// <param name="request">Request.</param>
protected sealed override Response OnDelete(Request request)
{
Response response = new Response();
return response;
}
- /// <summary>
- /// Called on the observing event.
- /// </summary>
- /// <param name="request">Request.</param>
- /// <param name="observerType">Observer type</param>
- /// <param name="observeId">Observe identifier.</param>
protected sealed override bool OnObserving(Request request, ObserveType observeType, int observeId)
{
return true;
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// Indicates delete method of request
+ /// Enumeration for policy of observation
/// </summary>
public enum ObservePolicy
{
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// Observe type.
+ /// Enumeration for type of observation
/// </summary>
public enum ObserveType
{
internal ObserverNotifiedEventArgs() { }
/// <summary>
- /// Result property.
+ /// Result of the observe response
/// </summary>
- /// <returns>ResponseCode Result.</returns>
public ResponseCode Result { get; internal set; }
/// <summary>
- /// Representation property.
+ /// Representation of the resource being observed.
/// </summary>
- /// <returns>Representation Representation.</returns>
public Representation Representation { get; internal set; }
}
}
internal PlatformInformationFoundEventArgs() { }
/// <summary>
- /// The request id
+ /// Indicates the request id
/// </summary>
public int RequestId { get; internal set; }
/// <summary>
- /// The platform identifier
+ /// Indicates the platform identifier
/// </summary>
public string PlatformId { get; internal set; }
/// <summary>
- /// The name of manufacturer
+ /// Indicates the name of manufacturer
/// </summary>
public string ManufacturerName { get; internal set; }
/// <summary>
- /// URL of the manufacturer
+ /// Indicates URL of the manufacturer
/// </summary>
public string ManufacturerURL { get; internal set; }
/// <summary>
- /// Model number as designated by manufacturer
+ /// Indicates model number as designated by manufacturer
/// </summary>
public string ModelNumber { get; internal set; }
/// <summary>
- /// Manugacturing date of the device
+ /// Indicates manufacturing date of the device
/// </summary>
public string DateOfManufacture { get; internal set; }
/// <summary>
- /// Version of platfrom defined by manufacturer
+ /// Indicates version of platfrom defined by manufacturer
/// </summary>
public string PlatformVersion { get; internal set; }
/// <summary>
- /// Version of platfrom resident OS
+ /// Indicates version of platfrom resident OS
/// </summary>
public string OsVersion { get; internal set; }
/// <summary>
- /// Version of platform Hardware
+ /// Indicates version of platform Hardware
/// </summary>
public string HardwareVersion { get; internal set; }
/// <summary>
- /// Version of device firmware
+ /// Indicates version of device firmware
/// </summary>
public string FirmwareVersion { get; internal set; }
/// <summary>
- /// URL that points to support information from manufacturer
+ /// Indicates URL that points to support information from manufacturer
/// </summary>
public string SupportUrl { get; internal set; }
/// <summary>
- /// Reference time of the device
+ /// Indicates reference time of the device
/// </summary>
public string SystemTime { get; internal set; }
}
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// Enumeration for presence events.
+ /// Enumeration for operation of presence response.
/// </summary>
public enum PresenceEventType
{
/// </summary>
ResourceCreated = 0,
/// <summary>
- /// Indicates for resource creation operation of server
+ /// Indicates for resource updation operation of server
/// </summary>
ResourceUpdated,
/// <summary>
internal PresenceReceivedEventArgs() { }
/// <summary>
- /// PresenceId property.
+ /// Indicates request id of presence event.
/// </summary>
- /// <returns>int PresenceId.</returns>
public int PresenceId { get; internal set; }
/// <summary>
- /// EventType property.
+ /// Indicates event type
/// </summary>
- /// <returns>PresenceEventType EventType.</returns>
public PresenceEventType EventType { get; internal set; }
/// <summary>
- /// HostAddress property.
+ /// Indicates host address of resource
/// </summary>
- /// <returns>string HostAddress.</returns>
public string HostAddress { get; internal set; }
/// <summary>
- /// Type property.
+ /// Indicates type of the resource
/// </summary>
- /// <returns>string Type.</returns>
public string Type { get; internal set; }
}
}
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// Indicates observation request for all notifications including stale notifications
+ /// Enumeration for states of remote resource.
/// </summary>
public enum QualityOfService
{
{
/// <summary>
/// This class represents a remote resource.
+ /// It provides APIs to manage remote resource.
/// </summary>
public class RemoteResource : IDisposable
{
private EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
/// <summary>
- /// Constructor
+ /// Creates a remote resource instance
/// </summary>
+ /// <remarks>
+ /// 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.
+ /// </remarks>
+ /// <param name="hostAddress">The host address of the resource</param>
+ /// <param name="uriPath">The URI path of the resource</param>
+ /// <param name="policy">The policies of the resource</param>
+ /// <param name="resourceTypes">The resource types of the resource</param>
+ /// <param name="resourceInterfaces">The resource interfaces of the resource</param>
public RemoteResource(string hostAddress, string uriPath, ResourcePolicy policy, ResourceTypes resourceTypes, ResourceInterfaces resourceInterfaces)
{
if (hostAddress == null || uriPath == null || resourceTypes == null || resourceInterfaces == null)
SetRemoteResource();
}
+ /// <summary>
+ /// Destructor of the RemoteResource class.
+ /// </summary>
~RemoteResource()
{
Dispose(false);
}
/// <summary>
- /// Event that is called to cache resource attribute's
+ /// Event that is invoked with cached resource attributes
/// </summary>
public event EventHandler<CacheUpdatedEventArgs> CacheUpdated;
/// <summary>
- /// Observe event on the resource
+ /// Observe event on the resource sent by the server
/// </summary>
public event EventHandler<ObserverNotifiedEventArgs> ObserverNotified;
}
/// <summary>
- /// Cache enabled property
+ /// Indicates the CacheEnabled status of the remote resource.
/// </summary>
+ /// <remarks>
+ /// Client can start caching only when this is set true. Set it to false to stop caching the resource attributes.
+ /// </remarks>
public bool CacheEnabled
{
get
/// <summary>
/// Time interval of monitoring and caching API
/// </summary>
+ /// <remarks>
+ /// Default time interval is 10 seconds.\n
+ /// Seconds for time interval (must be in range from 1 to 3600)
+ /// </remarks>
public int TimeInterval
{
get
set
{
int ret = (int)IoTConnectivityError.InvalidParameter;
- if (value < TimeOutMax && value > 0)
+ if (value <= TimeOutMax && value > 0)
{
ret = Interop.IoTConnectivity.Client.RemoteResource.SetTimeInterval(value);
}
public string DeviceId { get; private set; }
/// <summary>
- /// Gets cached representation of the remote resource
+ /// Gets cached representation from the remote resource
/// </summary>
public Representation CachedRepresentation()
{
}
/// <summary>
- /// Registers the observe callback on the resource
+ /// Starts observing on the resource
/// </summary>
+ /// <remarks>
+ /// When server sends notification message, <see cref="ObserverNotified"/> will be called.
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
/// <param name="policy">The type to specify how client wants to observe</param>
- /// <param name="query">The ResourceQuery to send to server</param>
+ /// <param name="query">The query to send to server</param>
public void StartObserving(ObservePolicy policy, ResourceQuery query = null)
{
_observeCallback = (IntPtr resource, int err, int sequenceNumber, IntPtr response, IntPtr userData) =>
}
/// <summary>
- /// Deregisters the observe callback on the resource
+ /// Stops observing on the resource
/// </summary>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
public void StopObserving()
{
int ret = Interop.IoTConnectivity.Client.RemoteResource.DeregisterObserve(_remoteResourceHandle);
}
/// <summary>
- /// Gets the attributes of a resource
+ /// Gets the attributes of a resource, asynchronously
/// </summary>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
/// <param name="query">The ResourceQuery to send to server</param>
- /// <returns></returns>
+ /// <returns>Remote response with result and representation</returns>
public async Task<RemoteResponse> GetAsync(ResourceQuery query = null)
{
TaskCompletionSource<RemoteResponse> tcsRemoteResponse = new TaskCompletionSource<RemoteResponse>();
/// <summary>
/// Puts the representation of a resource, asynchronously.
/// </summary>
- /// <param name="representation">Resource representation</param>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <param name="representation">Resource representation to put</param>
/// <param name="query">The ResourceQuery to send to server</param>
- /// <returns></returns>
+ /// <returns>Remote response with result and representation</returns>
public async Task<RemoteResponse> PutAsync(Representation representation, ResourceQuery query = null)
{
TaskCompletionSource<RemoteResponse> tcsRemoteResponse = new TaskCompletionSource<RemoteResponse>();
}
/// <summary>
- /// Post request on a resource
+ /// Post request on a resource, asynchronously
/// </summary>
- /// <param name="representation">Resource representation</param>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <param name="representation">Resource representation of request</param>
/// <param name="query">The ResourceQuery to send to server</param>
- /// <returns></returns>
+ /// <returns>Remote response with result and representation</returns>
public async Task<RemoteResponse> PostAsync(Representation representation, ResourceQuery query = null)
{
TaskCompletionSource<RemoteResponse> tcsRemoteResponse = new TaskCompletionSource<RemoteResponse>();
{
_responseCallbacksMap.Remove(responseCallbackId);
}
-
if (responseHandle != IntPtr.Zero)
{
try
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)
}
/// <summary>
- /// Delete the resource
+ /// Deletes the resource, asynchronously
/// </summary>
- /// <returns></returns>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <returns>Remote response with result and representation</returns>
public async Task<RemoteResponse> DeleteAsync()
{
TaskCompletionSource<RemoteResponse> tcsRemoteResponse = new TaskCompletionSource<RemoteResponse>();
return await tcsRemoteResponse.Task;
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
public void Dispose()
{
Dispose(true);
return type;
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
/// <summary>
/// This class represents remote response.
+ /// It represents the response of all CRUD operations.
/// </summary>
public class RemoteResponse
{
+ internal RemoteResponse() { }
+
/// <summary>
/// Indicates the result of the response
/// </summary>
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// Class containing representation of a resource.
+ /// This class provides API to manage representation.
+ /// A representation is a payload of a request or a response.
/// </summary>
public class Representation : IDisposable
{
private ObservableCollection<Representation> _children = new ObservableCollection<Representation>();
/// <summary>
- /// Constructor
+ /// The Representation constructor
/// </summary>
+ /// </summary>
+ /// <code>
+ /// Representation repr = new Representation();
+ /// </code>
public Representation()
{
int ret = Interop.IoTConnectivity.Common.Representation.Create(out _representationHandle);
_children.CollectionChanged += ChildrenCollectionChanged;
}
+ /// <summary>
+ /// Destructor of the Representation class.
+ /// </summary>
~Representation()
{
Dispose(false);
}
/// <summary>
- /// The URI of resource
+ /// The URI path of resource
/// </summary>
+ /// <remarks>
+ /// Setter can throw exceptions
+ /// </remarks>
+ /// <code>
+ /// Representation repr = new Representation();
+ /// repr.UriPath = "/a/light";
+ /// Console.WriteLine("URI is {0}", repr.UriPath); //Getter
+ /// </code>
public string UriPath
{
get
/// <summary>
/// The type of resource
/// </summary>
+ /// <seealso cref="ResourceTypes"/>
+ /// <code>
+ /// Representation repr = new Representation();
+ /// ResourceTypes types = new ResourceTypes (new List<string>(){ "org.tizen.light" });
+ /// repr.Type = types;
+ /// var type = repr.Type; // Getter
+ /// foreach (string item in type)
+ /// {
+ /// Console.WriteLine("Type is {0}", item);
+ /// }
+ /// </code>
public ResourceTypes Type
{
get
Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get type");
throw IoTConnectivityErrorFactory.GetException(ret);
}
+ if (typeHandle == IntPtr.Zero)
+ {
+ return null;
+ }
return new ResourceTypes(typeHandle);
}
set
/// <summary>
/// The interface of the resource
/// </summary>
+ /// <seealso cref="ResourceInterfaces"/>
+ /// <code>
+ /// Representation repr = new Representation();
+ /// ResourceInterfaces ifaces = new ResourceInterfaces (new List<string>(){ ResourceInterfaces.DefaultInterface });
+ /// repr.Interface = ifaces;
+ /// var iface = repr.Interface; // Getter
+ /// foreach (string item in iface)
+ /// {
+ /// Console.WriteLine("Interface is {0}", iface);
+ /// }
+ /// </code>
public ResourceInterfaces Interface
{
get
Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get interface");
throw IoTConnectivityErrorFactory.GetException(ret);
}
+ if (interfaceHandle == IntPtr.Zero)
+ {
+ return null;
+ }
return new ResourceInterfaces(interfaceHandle);
}
set
/// <summary>
/// Current attributes of the resource
/// </summary>
+ /// <seealso cref="Attributes"/>
+ /// <code>
+ /// 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);
+ /// </code>
public Attributes Attributes
{
get
/// <summary>
/// List of Child resource representation
/// </summary>
+ /// <code>
+ /// Representation repr = new Representation();
+ /// Representation child1 = new Representation();
+ /// ResourceTypes types1 = new ResourceTypes(new List<string>() { "org.tizen.light" });
+ /// child1.Type = types1;
+ /// ResourceInterfaces ifaces1 = new ResourceInterfaces(new List<string>() { 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);
+ /// }
+ /// </code>
public ICollection<Representation> Children
{
get
}
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed)
Type?.Dispose();
Interface?.Dispose();
Attributes?.Dispose();
+ foreach(var child in Children)
+ {
+ child.Dispose();
+ }
}
Interop.IoTConnectivity.Common.Representation.Destroy(_representationHandle);
{
/// <summary>
/// Class respresenting request to a resource.
+ /// It provides APIs to manage client's request.
/// </summary>
public class Request : IDisposable
{
{
}
+ /// <summary>
+ /// Destructor of the Request class.
+ /// </summary>
~Request()
{
Dispose(false);
/// </summary>
public ResourceOptions Options { get; internal set; }
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
/// <summary>
/// Abstract class respresenting a resource.
+ /// All resources need to inherit from this class.
/// </summary>
public abstract class Resource : IDisposable
{
/// <summary>
/// The constructor
/// </summary>
- /// <param name="uri">URI of the resource</param>
+ /// <remarks>
+ /// @a uri format would be relative URI path like '/a/light'
+ /// and its length must be less than 128.
+ /// </remarks>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
+ /// <param name="uri">The URI path of the resource</param>
/// <param name="types">Resource types</param>
/// <param name="interfaces">Resource interfaces</param>
- /// <param name="policy">Policy input of the resoruce</param>
+ /// <param name="policy">The policies of the resoruce</param>
+ /// <pre>
+ /// IoTConnectivityServerManager.Initialize() should be called to initialize
+ /// </pre>
+ /// <seealso cref="ResourceTypes"/>
+ /// <seealso cref="ResourceInterfaces"/>
+ /// <seealso cref="ResourcePolicy"/>
+ /// <code>
+ /// // 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<string>(){ ResourceInterfaces.DefaultInterface });
+ /// ResourceTypes types = new ResourceTypes(new List<string>(){ "oic.iot.door.new" });
+ /// Resource resource = new DoorResource("/door/uri1", types, ifaces, ResourcePolicy.Discoverable | ResourcePolicy.Observable);
+ /// </code>
protected Resource(string uri, ResourceTypes types, ResourceInterfaces interfaces, ResourcePolicy policy)
{
UriPath = uri;
}
}
+ /// <summary>
+ /// Destructor of the Resource class.
+ /// </summary>
~Resource()
{
Dispose(false);
public ResourceInterfaces Interfaces { get; internal set; }
/// <summary>
- /// The policy
+ /// The policies of the resource
/// </summary>
public ResourcePolicy Policy { get; internal set; }
/// <summary>
- /// URI of the resource
+ /// URI path of the resource
/// </summary>
public string UriPath { get; internal set; }
/// <summary>
/// Notify the specified representation and qos.
/// </summary>
+ /// <privilege>
+ /// http://tizen.org/privilege/internet
+ /// </privilege>
/// <param name="representation">Representation.</param>
- /// <param name="qos">Qos.</param>
+ /// <param name="qos">The quality of service for message transfer.</param>
+ /// <pre>
+ /// IoTConnectivityServerManager.Initialize() should be called to initialize
+ /// </pre>
+ /// <seealso cref="Representation"/>
+ /// <seealso cref="QualityOfService"/>
+ /// <code>
+ /// ResourceInterfaces ifaces = new ResourceInterfaces(new List<string>(){ ResourceInterfaces.DefaultInterface });
+ /// ResourceTypes types = new ResourceTypes(new List<string>(){ "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<string>(){ "oic.iot.door.new.notify" });
+ /// repr.Attributes = new Attributes() {
+ /// _attribute, 1 }
+ /// };
+ /// resource.Notify(repr, QualityOfService.High);
+ /// </code>
public void Notify(Representation representation, QualityOfService qos)
{
int ret = (int)IoTConnectivityError.None;
}
/// <summary>
- /// Called on the get event.
+ /// This is Called when the client performs get operation on this resource.
/// </summary>
- /// <param name="request">Request.</param>
+ /// <param name="request">A request from client</param>
+ /// <returns>A response having the representation and the result</returns>
protected abstract Response OnGet(Request request);
/// <summary>
- /// Called on the put event.
+ /// This is Called when the client performs put operation on this resource.
/// </summary>
- /// <param name="request">Request.</param>
+ /// <param name="request">A request from client</param>
+ /// <returns>A response</returns>
protected abstract Response OnPut(Request request);
/// <summary>
- /// Called on the post event.
+ /// This is Called when the client performs post operation on this resource.
/// </summary>
- /// <param name="request">Request.</param>
+ /// <param name="request">A request from client</param>
+ /// <returns>A response having the representation and the result</returns>
protected abstract Response OnPost(Request request);
/// <summary>
- /// Called on the delete event.
+ /// This is Called when the client performs delete operation on this resource.
/// </summary>
- /// <param name="request">Request.</param>
+ /// <param name="request">A request from client</param>
+ /// <returns>A response</returns>
protected abstract Response OnDelete(Request request);
/// <summary>
/// Called on the observing event.
/// </summary>
- /// <param name="request">Request.</param>
- /// <param name="policy">Policy.</param>
+ /// <param name="request">A request from client</param>
+ /// <param name="type">Observer type</param>
/// <param name="observeId">Observe identifier.</param>
+ /// <returns>Returns true if it wants to be observed, else false.</returns>
protected abstract bool OnObserving(Request request, ObserveType type, int observeId);
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed)
Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to Get observe type");
return;
}
-
if ((ObserveType)observeType != ObserveType.NoType)
{
int observeId;
}
}
}
-
int requestType;
ret = Interop.IoTConnectivity.Server.Request.GetRequestType(requestHandle, out requestType);
if (ret != (int)IoTConnectivityError.None)
Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to Get request type");
return;
}
-
switch ((Interop.IoTConnectivity.Server.RequestType)requestType)
{
case Interop.IoTConnectivity.Server.RequestType.Put:
internal ResourceFoundEventArgs() { }
/// <summary>
- /// RequestId property.
+ /// Indicates the request id.
+ /// This is the same request id returned by the <see cref="IoTConnectivityClientManager.StartFindingResource()"/> API.
/// </summary>
- /// <returns>int RequestId.</returns>
public int RequestId { get; internal set; }
/// <summary>
- /// Resource property.
+ /// Remote resource which is found after <see cref="IoTConnectivityClientManager.StartFindingResource()"/>.
/// </summary>
- /// <returns>RemoteResource Resource.</returns>
+ /// <seealso cref="IoTConnectivityClientManager.ResourceFound"/>
+ /// <seealso cref="IoTConnectivityClientManager.StartFindingResource()"/>
public RemoteResource Resource { get; internal set; }
}
}
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// 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.
/// </summary>
public class ResourceInterfaces : IEnumerable<string>, IDisposable
{
public const string DefaultInterface = "oic.if.baseline";
/// <summary>
- /// 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.
/// </summary>
public const string LinkInterface = "oic.if.ll";
private bool _disposed = false;
/// <summary>
- /// Constructor
+ /// Constructor of ResourceInterfaces
/// </summary>
+ /// <seealso cref="Add()"/>
+ /// <seealso cref="Remove()"/>
+ /// <code>
+ /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces();
+ /// </code>
public ResourceInterfaces()
{
int ret = Interop.IoTConnectivity.Common.ResourceInterfaces.Create(out _resourceInterfacesHandle);
}
/// <summary>
- /// Constructor
+ /// Constructor of ResourceInterfaces using list of interfaces
/// </summary>
/// <param name="ifaces">List of resource interfaces</param>
+ /// <code>
+ /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(new List<string>()
+ /// { ResourceInterfaces.LinkInterface, ResourceInterfaces.ReadonlyInterface });
+ /// </code>
public ResourceInterfaces(IEnumerable<string> ifaces)
{
int ret = Interop.IoTConnectivity.Common.ResourceInterfaces.Create(out _resourceInterfacesHandle);
}
}
- /// <summary>
- /// Constructor
- /// </summary>
internal ResourceInterfaces(IntPtr ifacesHandleToClone)
{
int ret = Interop.IoTConnectivity.Common.ResourceInterfaces.Clone(ifacesHandleToClone, out _resourceInterfacesHandle);
}
}
+ /// <summary>
+ /// Destructor of the ResourceInterfaces class.
+ /// </summary>
~ResourceInterfaces()
{
Dispose(false);
}
/// <summary>
- /// Count of interfaces in the list
+ /// Indicates count of interfaces in the list
/// </summary>
+ /// <code>
+ /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(new List<string>()
+ /// { ResourceInterfaces.LinkInterface, ResourceInterfaces.ReadonlyInterface });
+ /// Console.WriteLine("There are {0} interfaces", resourceInterfaces.Count);
+ /// </code>
public int Count
{
get
/// <summary>
/// Adds a resource interface into the list.
/// </summary>
- /// <param name="item"> Resource interface</param>
+ /// <remarks>
+ /// @a item could be a value such as <see cref="DefaultInterface"/>
+ /// </remarks>
+ /// <param name="item">The string data to insert into the resource interfaces</param>
+ /// <seealso cref="Remove()"/>
+ /// <code>
+ /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces();
+ /// resourceInterfaces.Add(ResourceInterfaces.BatchInterface);
+ /// </code>
public void Add(string item)
{
if (IsValid(item))
/// <summary>
/// Removes a resource interface from the list
/// </summary>
- /// <param name="item">Resource interface</param>
+ /// <param name="item">The string data to delete from the resource ifaces</param>
+ /// <seealso cref="Add()"/>
+ /// <code>
+ /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(new List<string>(){ ResourceInterfaces.BatchInterface });
+ /// resourceInterfaces.Add(ResourceInterfaces.BatchInterface);
+ /// </code>
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);
}
/// <summary>
/// Return enumerator for the list of interfaces
/// </summary>
/// <returns>The enumerator</returns>
+ /// <code>
+ /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(new List<string>()
+ /// { ResourceInterfaces.LinkInterface, ResourceInterfaces.ReadonlyInterface });
+ /// foreach(string item in resourceInterfaces)
+ /// {
+ /// Console.WriteLine("Interface : {0}", item);
+ /// }
+ /// </code>
public IEnumerator<string> GetEnumerator()
{
return _resourceInterfaces.GetEnumerator();
}
- public void Dispose()
+ /// <summary>
+ /// Return enumerator for the list of interfaces
+ /// </summary>
+ /// <returns>The enumerator</returns>
+ /// <code>
+ /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(new List<string>()
+ /// { ResourceInterfaces.LinkInterface, ResourceInterfaces.ReadonlyInterface });
+ /// foreach(string item in resourceInterfaces)
+ /// {
+ /// Console.WriteLine("Interface : {0}", item);
+ /// }
+ /// </code>
+ IEnumerator IEnumerable.GetEnumerator()
{
- Dispose(true);
- GC.SuppressFinalize(this);
+ return _resourceInterfaces.GetEnumerator();
}
- IEnumerator IEnumerable.GetEnumerator()
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
+ public void Dispose()
{
- return _resourceInterfaces.GetEnumerator();
+ Dispose(true);
+ GC.SuppressFinalize(this);
}
internal static bool IsValid(string type)
return (type.Length <= MaxLength && char.IsLower(type[0]) && r.IsMatch(type));
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed)
using System.Collections;
using System.Collections.Generic;
using System.Linq;
-using Tizen;
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// 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.
/// </summary>
public class ResourceOptions : IDictionary<ushort, string>, IDisposable
{
private readonly IDictionary<ushort, string> _options = new Dictionary<ushort, string>();
private bool _disposed = false;
+ /// <summary>
+ /// The resource options constructor
+ /// </summary>
+ /// <seealso cref="Add()"/>
+ /// <seealso cref="Remove()"/>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// </code>
public ResourceOptions()
{
int ret = Interop.IoTConnectivity.Common.Options.Create(out _resourceOptionsHandle);
}
}
+ // internal constructor
internal ResourceOptions(IntPtr handleToClone)
{
int ret = Interop.IoTConnectivity.Common.Options.Create(out _resourceOptionsHandle);
}
}
+ /// <summary>
+ /// Destructor of the ResourceOptions class.
+ /// </summary>
~ResourceOptions()
{
Dispose(false);
/// <summary>
/// Contains all the Option keys
/// </summary>
+ /// <code>
+ /// 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));
+ /// </code>
public ICollection<ushort> Keys
{
get
/// <summary>
/// Contains all the Option values
/// </summary>
+ /// <code>
+ /// 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));
+ /// </code>
public ICollection<string> Values
{
get
/// <summary>
/// Gets the number of options
/// </summary>
+ /// <code>
+ /// 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);
+ /// </code>
public int Count
{
get
/// <summary>
/// Represents whether the collection is readonly
/// </summary>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// if (options.IsReadOnly)
+ /// Console.WriteLine("Read only options");
+ /// </code>
public bool IsReadOnly
{
get
}
/// <summary>
- /// Gets or sets the option
+ /// Gets or sets the option data
/// </summary>
+ /// <remarks>
/// <param name="key">The option id to get or set.</param>
/// <returns>The option with the specified id.</returns>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options[2055] = "sample-data";
+ /// Console.WriteLine("Option has : {0}", options[2055]);
+ /// </code>
public string this[ushort key]
{
get
{
return _options[key];
}
-
set
{
Add(key, value);
}
/// <summary>
- /// Checks the given key exists in Options collection
+ /// Checks whether the given key exists in Options collection
/// </summary>
/// <param name="key">The key to look for</param>
- /// <returns></returns>
+ /// <returns>true if exists. Otherwise, false</returns>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options.Add(2050, "sample-data");
+ /// if (options.ContainsKey(2050))
+ /// Console.WriteLine("options conatins key : 2050");
+ /// </code>
public bool ContainsKey(ushort key)
{
return _options.ContainsKey(key);
}
/// <summary>
- /// Adds option key and value
+ /// Adds a new id and a correspoding data into the options.
/// </summary>
- /// <param name="key">Option ID</param>
- /// <param name="value">Value coresponding to option</param>
+ /// <remarks>
+ /// 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.
+ /// </remarks>
+ /// <param name="key">The id of the option to insert</param>
+ /// <param name="value">The string data to insert into the options</param>
+ /// <seealso cref="Remove()"/>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options.Add(2050, "sample-data");
+ /// </code>
public void Add(ushort key, string value)
{
int ret = (int)IoTConnectivityError.InvalidParameter;
}
/// <summary>
- /// Removes an option
+ /// Removes the id and its associated data from the options.
/// </summary>
- /// <param name="key">The option to remvoe</param>
- /// <returns></returns>
+ /// <param name="key">The id of the option to delete</param>
+ /// <returns>True if operation is successful. Otherwise, false</returns>
+ /// <seealso cref="Add()"/>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options.Add(2050, "12345");
+ /// var result = options.Remove(2050);
+ /// </code>
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;
}
/// <summary>
/// Gets the value associated with the specified key.
/// </summary>
/// <param name="key">The option id</param>
- /// <param name="value">value corresponding to option id</param>
- /// <returns>true if the key exists, false otherwise</returns>
+ /// <param name="value">Value corresponding to option id</param>
+ /// <returns>True if the key exists, false otherwise</returns>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options.Add(2050, "12345");
+ /// string value;
+ /// var isPresent = options.TryGetValue(2050, out value);
+ /// if (isPresent)
+ /// Console.WriteLine("value : {0}", value);
+ /// </code>
public bool TryGetValue(ushort key, out string value)
{
return _options.TryGetValue(key, out value);
/// Adds options key and value as a key value pair
/// </summary>
/// <param name="item">The key value pair</param>
+ /// <seealso cref="Remove()"/>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options.Add(new KeyValuePair<ushort, string>(2050, "12345"));
+ /// </code>
public void Add(KeyValuePair<ushort, string> item)
{
Add(item.Key, item.Value);
/// <summary>
/// Clears the Options collection
/// </summary>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options.Add(2050, "12345");
+ /// options.Add(2055, "sample");
+ /// options.Clear();
+ /// </code>
public void Clear()
{
foreach (ushort key in Keys)
/// Checks if the given option pair exists
/// </summary>
/// <param name="item">The key value pair</param>
- /// <returns></returns>
+ /// <returns>True if exists. Otherwise, false</returns>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options.Add(new KeyValuePair<ushort, string>(2050, "12345"));
+ /// var isPresent = options.Contains(new KeyValuePair<ushort, string>(2050, "12345"));
+ /// if (isPresent)
+ /// Console.WriteLine("Key value pair is present");
+ /// </code>
public bool Contains(KeyValuePair<ushort, string> item)
{
return _options.Contains(item);
/// </summary>
/// <param name="array">The destination array</param>
/// <param name="arrayIndex">Index parameter</param>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options.Add(new KeyValuePair<ushort, string>(2050, "12345"));
+ /// KeyValuePair<ushort, string>[] dest = new KeyValuePair<ushort, string>[options.Count];
+ /// options.CopyTo(dest, 0);
+ /// Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value);
+ /// </code>
public void CopyTo(KeyValuePair<ushort, string>[] array, int arrayIndex)
{
_options.CopyTo(array, arrayIndex);
}
/// <summary>
- /// Remove the gien option pair
+ /// Remove the given key value pair from the options
/// </summary>
- /// <param name="item">The option pair to remove</param>
- /// <returns></returns>
+ /// <param name="item">The key value pair to remove</param>
+ /// <returns>True if operation is successful. Otherwise, false</returns>
+ /// <seealso cref="Add()"/>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options.Add(new KeyValuePair<ushort, string>(2050, "12345"));
+ /// var result = options.Remove(new KeyValuePair<ushort, string>(2050, "12345"));
+ /// </code>
public bool Remove(KeyValuePair<ushort, string> item)
{
return Remove(item.Key);
/// <summary>
/// Get the enumerator to options collection
/// </summary>
- /// <returns> Enumerator to option pairs</returns>
+ /// <returns>Enumerator to option pairs</returns>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options.Add(new KeyValuePair<ushort, string>(2050, "sample1"));
+ /// options.Add(new KeyValuePair<ushort, string>(2055, "sample2"));
+ /// foreach (KeyValuePair<string, object> pair in options)
+ /// {
+ /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value);
+ /// }
+ /// </code>
public IEnumerator<KeyValuePair<ushort, string>> GetEnumerator()
{
return _options.GetEnumerator();
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
+ /// <summary>
+ /// Get the enumerator to options collection
+ /// </summary>
+ /// <returns>Enumerator to option pairs</returns>
+ /// <code>
+ /// ResourceOptions options = new ResourceOptions();
+ /// options.Add(new KeyValuePair<ushort, string>(2050, "sample1"));
+ /// options.Add(new KeyValuePair<ushort, string>(2055, "sample2"));
+ /// foreach (KeyValuePair<string, object> pair in options)
+ /// {
+ /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value);
+ /// }
+ /// </code>
IEnumerator IEnumerable.GetEnumerator()
{
return _options.GetEnumerator();
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed)
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// Class to manage query of request.
+ /// This class provides APIs to manage query of request.
/// </summary>
public class ResourceQuery : IDictionary<string, string>, IDisposable
{
private bool _disposed = false;
/// <summary>
- /// Constructor
+ /// The resource query constructor
/// </summary>
+ /// <seealso cref="Add()"/>
+ /// <seealso cref="Remove()"/>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// </code>
public ResourceQuery()
{
int ret = Interop.IoTConnectivity.Common.Query.Create(out _resourceQueryHandle);
}
}
+ /// <summary>
+ /// Destructor of the ResourceQuery class.
+ /// </summary>
~ResourceQuery()
{
Dispose(false);
}
/// <summary>
- /// Resource type of the query
+ /// Gets and sets the resource type of the query
/// </summary>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Type = "org.tizen.light";
+ /// Console.WriteLine("Type of query : {0}", query.Type);
+ /// </code>
public string Type
{
get
}
/// <summary>
- /// Resource interface of the query
+ /// Gets and sets the resource interface of the query
/// </summary>
+ /// <remarks>
+ /// Setter value could be a value such as <see cref="ResourceInterfaces.DefaultInterface"/>
+ /// </remarks>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Interface = ResourceInterfaces.LinkInterface;
+ /// </code>
public string Interface
{
get
}
/// <summary>
- /// Contains all keys of Query
+ /// Contains all the query keys
/// </summary>
+ /// <code>
+ /// 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));
+ /// </code>
public ICollection<string> Keys
{
get
}
/// <summary>
- /// Contains all the values of Query
+ /// Contains all the query values
/// </summary>
+ /// <code>
+ /// 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));
+ /// </code>
public ICollection<string> Values
{
get
/// <summary>
/// Gets the number of query elements
/// </summary>
+ /// <code>
+ /// 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);
+ /// </code>
public int Count
{
get
}
/// <summary>
- /// Represents whether Query is readonly
+ /// Represents whether the collection is readonly
/// </summary>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// if (query.IsReadOnly)
+ /// Console.WriteLine("Read only query");
+ /// </code>
public bool IsReadOnly
{
get
}
/// <summary>
- /// Gets or sets the Query key..
+ /// Gets or sets the query data
/// </summary>
- /// <param name="key">The key of the Query to get or set.</param>
- /// <returns>The element with the specified key.</returns>
+ /// <param name="key">The query key to get or set.</param>
+ /// <returns>The query with the specified key.</returns>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query["key1"] = "sample-data";
+ /// Console.WriteLine("query has : {0}", query["key1"]);
+ /// </code>
public string this[string key]
{
get
}
/// <summary>
- /// Checks the given key exists in Query
+ /// Checks whether the given key exists in Query collection
/// </summary>
- /// <param name="key">The Query key</param>
+ /// <param name="key">The key to look for</param>
/// <returns>true if exists. Otherwise, false</returns>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Add("key1", "value1");
+ /// if (query.ContainsKey("key1"))
+ /// Console.WriteLine("query conatins key : key1");
+ /// </code>
public bool ContainsKey(string key)
{
return _query.ContainsKey(key);
}
/// <summary>
- /// Adds Query element
+ /// Adds a new key and correspoding value into the query.
/// </summary>
- /// <param name="key">The key representing the Query</param>
- /// <param name="value">The value representing the Query</param>
+ /// <remarks>
+ /// The full length of query should be less than or equal to 64.
+ /// </remarks>
+ /// <param name="key">The key of the query to insert</param>
+ /// <param name="value">The string data to insert into the query</param>
+ /// <seealso cref="Remove()"/>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Add("key1", "value1");
+ /// </code>
public void Add(string key, string value)
{
if (CanAddQuery(key, value))
}
/// <summary>
- /// Removes a Query element from collection
+ /// Removes the key and its associated value from the query.
/// </summary>
- /// <param name="item">The Query element to remove</param>
- /// <returns>true if operation is success. Otherwise, false</returns>
+ /// <param name="key">The id of the query to delete</param>
+ /// <returns>True if operation is successful. Otherwise, false</returns>
+ /// <seealso cref="Add()"/>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Add("key1", "value1");
+ /// var result = query.Remove("key1");
+ /// </code>
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;
}
/// <summary>
/// Gets the value associated with the specified key.
/// </summary>
- /// <param name="key">The key whose value to get.</param>
- /// <param name="value"> The value associated with the specified key</param>
- /// <returns> true if the Query contains an element with the specified key; otherwise, false.</returns>
+ /// <param name="key">The query key</param>
+ /// <param name="value">Value corresponding to query key</param>
+ /// <returns>True if the key exists, false otherwise</returns>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Add("key1", "value1");
+ /// string value;
+ /// var isPresent = query.TryGetValue("key1", out value);
+ /// if (isPresent)
+ /// Console.WriteLine("value : {0}", value);
+ /// </code>
public bool TryGetValue(string key, out string value)
{
return _query.TryGetValue(key, out value);
}
/// <summary>
- /// Adds Query as a key value pair
+ /// Adds query key and value as a key value pair
/// </summary>
/// <param name="item">The key value pair</param>
+ /// <seealso cref="Remove()"/>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Add(new KeyValuePair<string, string>("key1", "value1"));
+ /// </code>
public void Add(KeyValuePair<string, string> item)
{
Add(item.Key, item.Value);
}
/// <summary>
- /// Clears Query
+ /// Clears the Query collection
/// </summary>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Add("key1", "value1");
+ /// query.Add("key2", "value2");
+ /// query.Clear();
+ /// </code>
public void Clear()
{
foreach (string key in _query.Keys)
}
/// <summary>
- /// Checks the given key value pair exists in Query
+ /// Checks if the given query pair exists
/// </summary>
/// <param name="item">The key value pair</param>
- /// <returns>true if exists. Otherwise, false</returns>
+ /// <returns>True if exists. Otherwise, false</returns>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Add(new KeyValuePair<string, string>("key1", "value1"));
+ /// var isPresent = query.Contains(new KeyValuePair<string, string>("key1", "value1"));
+ /// if (isPresent)
+ /// Console.WriteLine("Key value pair is present");
+ /// </code>
public bool Contains(KeyValuePair<string, string> item)
{
return _query.Contains(item);
}
/// <summary>
- /// 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.
/// </summary>
/// <param name="array">The destination array</param>
- /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
+ /// <param name="arrayIndex">Index parameter</param>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Add(new KeyValuePair<string, string>("key1", "value1"));
+ /// KeyValuePair<string, string>[] dest = new KeyValuePair<string, string>[query.Count];
+ /// query.CopyTo(dest, 0);
+ /// Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value);
+ /// </code>
public void CopyTo(KeyValuePair<string, string>[] array, int arrayIndex)
{
_query.CopyTo(array, arrayIndex);
}
/// <summary>
- /// Removes a Query element from collection
+ /// Remove the given key value pair from the query
/// </summary>
- /// <param name="item">The Query element to remove</param>
- /// <returns>true if operation is success. Otherwise, false</returns>
+ /// <param name="item">The key value pair to remove</param>
+ /// <returns>True if operation is successful. Otherwise, false</returns>
+ /// <seealso cref="Add()"/>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Add(new KeyValuePair<string, string>("key1", "value1"));
+ /// var result = query.Remove(new KeyValuePair<string, string>("key1", "value1"));
+ /// </code>
public bool Remove(KeyValuePair<string, string> 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);
}
/// <summary>
- /// Returns an enumerator that iterates through the collection.
+ /// Get the enumerator to query collection
/// </summary>
- /// <returns> An enumerator that can be used to iterate through the collection.</returns>
+ /// <returns>Enumerator to query pairs</returns>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Add(new KeyValuePair<string, string>("key1", "value1"));
+ /// query.Add(new KeyValuePair<string, string>("key2", "value2"));
+ /// foreach (KeyValuePair<string, string> pair in query)
+ /// {
+ /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value);
+ /// }
+ /// </code>
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
return _query.GetEnumerator();
}
+ /// <summary>
+ /// Get the enumerator to query collection
+ /// </summary>
+ /// <returns>Enumerator to query pairs</returns>
+ /// <code>
+ /// ResourceQuery query = new ResourceQuery();
+ /// query.Add(new KeyValuePair<string, string>("key1", "value1"));
+ /// query.Add(new KeyValuePair<string, string>("key2", "value2"));
+ /// foreach (KeyValuePair<string, string> pair in query)
+ /// {
+ /// Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value);
+ /// }
+ /// </code>
IEnumerator IEnumerable.GetEnumerator()
{
return _query.GetEnumerator();
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed)
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;
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// 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.
/// </summary>
public class ResourceTypes : IEnumerable<string>, IDisposable
{
private bool _disposed = false;
/// <summary>
- /// Constructor
+ /// Constructor of ResourceTypes
/// </summary>
+ /// <seealso cref="Add()"/>
+ /// <seealso cref="Remove()"/>
+ /// <code>
+ /// ResourceTypes types = new ResourceTypes();
+ /// </code>
public ResourceTypes()
{
int ret = Interop.IoTConnectivity.Common.ResourceTypes.Create(out _resourceTypeHandle);
}
/// <summary>
- /// Constructor
+ /// Constructor of ResourceTypes using list of types
/// </summary>
+ /// <param name="types">List of resource types</param>
+ /// <code>
+ /// ResourceTypes types = new ResourceTypes(new List<string>() { "org.tizen.light", "oic.if.room" });
+ /// </code>
public ResourceTypes(IEnumerable<string> types)
{
int ret = Interop.IoTConnectivity.Common.ResourceTypes.Create(out _resourceTypeHandle);
}
}
- /// <summary>
- /// Constructor
- /// </summary>
internal ResourceTypes(IntPtr typesHandleToClone)
{
int ret = Interop.IoTConnectivity.Common.ResourceTypes.Clone(typesHandleToClone, out _resourceTypeHandle);
}
}
+ /// <summary>
+ /// Destructor of the ResourceTypes class.
+ /// </summary>
~ResourceTypes()
{
Dispose(false);
}
/// <summary>
- /// Count of resource types in the list
+ /// Indicates count of types in the list
/// </summary>
+ /// <code>
+ /// ResourceTypes types = new ResourceTypes(new List<string>() { "org.tizen.light", "oic.if.room" });
+ /// Console.WriteLine("There are {0} items", types.Count);
+ /// </code>
public int Count
{
get
}
/// <summary>
- /// Inserts a resource type into the list.
+ /// Adds a resource type into the list.
/// </summary>
- /// <param name="item">The resource type to add</param>
+ /// <remarks>
+ /// 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.
+ /// </remarks>
+ /// <param name="item">The string data to insert into the resource types</param>
+ /// <seealso cref="Remove()"/>
+ /// <code>
+ /// ResourceTypes resourceTypes = new ResourceTypes();
+ /// resourceTypes.Add("org.tizen.light");
+ /// </code>
public void Add(string item)
{
if (IsValid(item))
}
/// <summary>
- /// Removes a resource type from the list
+ /// Removes a resource type from the list
/// </summary>
- /// <param name="item">The resource type to remove</param>
+ /// <param name="item">The string data to delete from the resource types</param>
+ /// <seealso cref="Add()"/>
+ /// <code>
+ /// ResourceTypes resourceTypes = new ResourceTypes(new List<string>() { "org.tizen.light", "oic.if.room" });
+ /// resourceTypes.Remove("oic.if.room");
+ /// </code>
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);
}
/// <summary>
- /// Return enumerator for the list of types
+ /// Return enumerator for the list of types
/// </summary>
- /// <returns>Enumerator of the collection</returns>
+ /// <returns>The enumerator</returns>
+ /// <code>
+ /// ResourceTypes resourceTypes = new ResourceTypes(new List<string>() { "org.tizen.light", "oic.if.room" });
+ /// foreach(string item in resourceTypes)
+ /// {
+ /// Console.WriteLine("Type : {0}", item);
+ /// }
+ /// </code>
public IEnumerator<string> GetEnumerator()
{
return _resourceTypes.GetEnumerator();
}
+ /// <summary>
+ /// Return enumerator for the list of types
+ /// </summary>
+ /// <returns>The enumerator</returns>
+ /// <code>
+ /// ResourceTypes resourceTypes = new ResourceTypes(new List<string>() { "org.tizen.light", "oic.if.room" });
+ /// foreach(string item in resourceTypes)
+ /// {
+ /// Console.WriteLine("Type : {0}", item);
+ /// }
+ /// </code>
IEnumerator IEnumerable.GetEnumerator()
{
return _resourceTypes.GetEnumerator();
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
public void Dispose()
{
Dispose(true);
return (type.Length <= MaxLength && char.IsLower(type[0]) && r.IsMatch(type));
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed)
{
/// <summary>
/// This class represents response from a resource.
+ /// It provides APIs to manage response.
/// </summary>
public class Response : IDisposable
{
private bool _disposed = false;
+ /// <summary>
+ /// Constructor of Response
+ /// </summary>
+ /// <code>
+ /// Response response = new Response();
+ /// </code>
+ public Response() { }
+
+ /// <summary>
+ /// Destructor of the Response class.
+ /// </summary>
~Response()
{
Dispose(false);
}
/// <summary>
- /// Result corresponding to a request
+ /// Gets or sets the result from/into the reponse
/// </summary>
public ResponseCode Result { get; set; }
/// <summary>
- /// Representation of the resource
+ /// Gets or sets the representation from/into the reponse
/// </summary>
public Representation Representation { get; set; }
+ /// <summary>
+ /// Gets or sets the options from/into the reponse
+ /// </summary>
+ public ResourceOptions Options { get; set; }
+
+ /// <summary>
+ /// Releases any unmanaged resources used by this object.
+ /// </summary>
public void Dispose()
{
Dispose(true);
}
}
+ 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)
{
return true;
}
+ /// <summary>
+ /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
+ /// </summary>
+ /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
protected virtual void Dispose(bool disposing)
{
if (_disposed)
namespace Tizen.Network.IoTConnectivity
{
/// <summary>
- /// Enumeration for result response
+ /// Enumeration for result of response
/// </summary>
public enum ResponseCode
{
/// </summary>
Ok = 0,
/// <summary>
- /// Indicates result of response for something error
+ /// Indicates result of response for some error
/// </summary>
Error,
/// <summary>
- /// Indicates result of response for resource has created
+ /// Indicates result of response for created resource
/// </summary>
Created,
/// <summary>
- /// Indicates result of response for resource has deleted
+ /// Indicates result of response for deleted resource
/// </summary>
Deleted,
/// <summary>
internal StateChangedEventArgs() { }
/// <summary>
- /// State property.
+ /// Indicates the new state of the resource
/// </summary>
- /// <returns>ResourceState State.</returns>
public ResourceState State { get; internal set; }
}
}