Update according to design review
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.IoTConnectivity / Tizen.Network.IoTConnectivity / RemoteResource.cs
old mode 100644 (file)
new mode 100755 (executable)
index dfbba19..2672517
@@ -1,10 +1,19 @@
-/// Copyright 2016 by Samsung Electronics, Inc.,
-///
-/// This software is the confidential and proprietary information
-/// of Samsung Electronics, Inc. ("Confidential Information"). You
-/// shall not disclose such Confidential Information and shall use
-/// it only in accordance with the terms of the license agreement
-/// you entered into with Samsung.
+ /*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 
 using System;
 using System.Collections.Generic;
@@ -50,6 +59,9 @@ namespace Tizen.Network.IoTConnectivity
         /// <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>
+        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
+        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory</exception>
+        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
         public RemoteResource(string hostAddress, string uriPath, ResourcePolicy policy, ResourceTypes resourceTypes, ResourceInterfaces resourceInterfaces)
         {
             if (hostAddress == null || uriPath == null || resourceTypes == null || resourceInterfaces == null)
@@ -153,6 +165,8 @@ namespace Tizen.Network.IoTConnectivity
         /// <summary>
         /// The header options of the resource
         /// </summary>
+        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
+        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
         public ResourceOptions Options
         {
             get
@@ -180,6 +194,11 @@ namespace Tizen.Network.IoTConnectivity
         /// <remarks>
         /// Client can start caching only when this is set true. Set it to false to stop caching the resource attributes.
         /// </remarks>
+        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
+        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when app does not have privilege to access</exception>
+        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory</exception>
         public bool CacheEnabled
         {
             get
@@ -203,12 +222,14 @@ namespace Tizen.Network.IoTConnectivity
         /// Default time interval is 10 seconds.\n
         /// Seconds for time interval (must be in range from 1 to 3600)
         /// </remarks>
+        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
+        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
         public int TimeInterval
         {
             get
             {
                 int interval;
-                int ret = Interop.IoTConnectivity.Client.RemoteResource.GetTimeInterval(out interval);
+                int ret = Interop.IoTConnectivity.Client.RemoteResource.GetTimeInterval(_remoteResourceHandle, out interval);
                 if (ret != (int)IoTConnectivityError.None)
                 {
                     Log.Warn(IoTConnectivityErrorFactory.LogTag, "Failed to get time interval");
@@ -221,7 +242,7 @@ namespace Tizen.Network.IoTConnectivity
                 int ret = (int)IoTConnectivityError.InvalidParameter;
                 if (value <= TimeOutMax && value > 0)
                 {
-                    ret = Interop.IoTConnectivity.Client.RemoteResource.SetTimeInterval(value);
+                    ret = Interop.IoTConnectivity.Client.RemoteResource.SetTimeInterval(_remoteResourceHandle, value);
                 }
                 if (ret != (int)IoTConnectivityError.None)
                 {
@@ -264,6 +285,11 @@ namespace Tizen.Network.IoTConnectivity
         /// </privilege>
         /// <param name="policy">The type to specify how client wants to observe</param>
         /// <param name="query">The query to send to server</param>
+        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
+        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when app does not have privilege to access</exception>
+        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory</exception>
         public void StartObserving(ObservePolicy policy, ResourceQuery query = null)
         {
             _observeCallback = (IntPtr resource, int err, int sequenceNumber, IntPtr response, IntPtr userData) =>
@@ -300,7 +326,7 @@ namespace Tizen.Network.IoTConnectivity
                     Representation = repr,
                     Result = (ResponseCode)result
                 };
-                ObserverNotified?.Invoke(null, e);
+                ObserverNotified?.Invoke(this, e);
             };
 
             IntPtr queryHandle = IntPtr.Zero;
@@ -323,6 +349,10 @@ namespace Tizen.Network.IoTConnectivity
         /// <privilege>
         /// http://tizen.org/privilege/internet
         /// </privilege>
+        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
+        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when app does not have privilege to access</exception>
         public void StopObserving()
         {
             int ret = Interop.IoTConnectivity.Client.RemoteResource.DeregisterObserve(_remoteResourceHandle);
@@ -567,6 +597,8 @@ namespace Tizen.Network.IoTConnectivity
         {
             Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType type = Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType.None;
 
+            Log.Info(IoTConnectivityErrorFactory.LogTag, hostAddress);
+
             if (hostAddress == IoTConnectivityClientManager.MulticastAddress)
             {
                 type = Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType.Ipv4;
@@ -583,6 +615,23 @@ namespace Tizen.Network.IoTConnectivity
                         hostName = hostParts[0];
                     }
                 }
+                if (hostAddress.Contains("%"))
+                {
+                    string[] hostParts = hostAddress.Split('%');
+                    if (hostParts.Length == 2)
+                    {
+                        hostName = hostParts[0];
+                    }
+                }
+                if (hostName.Contains("["))
+                {
+                    string[] hostParts = hostName.Split('[');
+                    if (hostParts.Length == 2)
+                    {
+                        hostName = hostParts[1];
+                    }
+                }
+                Log.Info(IoTConnectivityErrorFactory.LogTag, hostName);
                 if (IPAddress.TryParse(hostName, out address))
                 {
                     switch (address.AddressFamily)
@@ -598,6 +647,10 @@ namespace Tizen.Network.IoTConnectivity
                             break;
                     }
                 }
+                else
+                {
+                    Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to parse hostname " + hostName);
+                }
             }
             return type;
         }
@@ -643,7 +696,7 @@ namespace Tizen.Network.IoTConnectivity
                         {
                             Representation = repr
                         };
-                        CacheUpdated?.Invoke(null, e);
+                        CacheUpdated?.Invoke(this, e);
                     }
                 };