Merge "[Multimedia] Updated the doc-comments to fix the grammar errors."
[platform/core/csapi/tizenfx.git] / src / Tizen.Sensor / Tizen.Sensor / Plugins / WalkingActivityDetector.cs
old mode 100644 (file)
new mode 100755 (executable)
index d82fc78..d2b7906
@@ -1,30 +1,42 @@
-// 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;
 
 namespace Tizen.Sensor
 {
     /// <summary>
-    /// WalkingActivityDetector Class. Used for registering callbacks for walking activity detector and getting the walking state
+    /// The WalkingActivityDetector class is used for registering callbacks for the walking activity detector and getting the walking state.
     /// </summary>
-    public class WalkingActivityDetector : ActivityDetector
+    public sealed class WalkingActivityDetector : ActivityDetector
     {
         private static string ActivityDetectorKey = "http://tizen.org/feature/sensor.activity_recognition";
 
         /// <summary>
-        /// Gets the state of walking activity detector
+        /// Gets the state of the walking activity detector.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value> The walking state. </value>
         public DetectorState Walking { get; private set; } = DetectorState.Unknown;
 
         /// <summary>
-        /// Returns true or false based on whether walking activity detector is supported by device.
+        /// Returns true or false based on whether the walking activity detector is supported by the device.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value><c>true</c> if supported; otherwise <c>false</c>.</value>
         public static bool IsSupported
         {
             get
@@ -35,8 +47,10 @@ namespace Tizen.Sensor
         }
 
         /// <summary>
-        /// Returns the number of walking activity detector available on the device.
+        /// Returns the number of walking activity detectors available on the device.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value> The count of walking activity detectors. </value>
         public static int Count
         {
             get
@@ -47,11 +61,13 @@ namespace Tizen.Sensor
         }
 
         /// <summary>
-        /// Initializes a new instance of the <see cref="Tizen.Sensor.walkingActivityDetector"/> class.
+        /// Initializes a new instance of the <see cref="Tizen.Sensor.WalkingActivityDetector"/> class.
         /// </summary>
-        /// <exception cref="ArgumentException">Thrown when an invalid argument is used</exception>
-        /// <exception cref="NotSupportedException">Thrown when the sensor is not supported</exception>
-        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid for the current state</exception>
+        /// <since_tizen> 3 </since_tizen>
+        /// <feature>http://tizen.org/feature/sensor.activity_recognition</feature>
+        /// <exception cref="ArgumentException">Thrown when an invalid argument is used.</exception>
+        /// <exception cref="NotSupportedException">Thrown when the sensor is not supported.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid for the current state.</exception>
         /// <param name='index'>
         /// Index. Default value for this is 0. Index refers to a particular walking activity detector in case of multiple sensors.
         /// </param>
@@ -77,18 +93,41 @@ namespace Tizen.Sensor
         }
 
         /// <summary>
-        /// Event Handler for storing the callback functions for event corresponding to change in walking activity gesture detector data.
+        /// An event handler for storing the callback functions for the event corresponding to the change in the walking activity gesture detector data.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
         public event EventHandler<WalkingActivityDetectorDataUpdatedEventArgs> DataUpdated;
 
-        protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
+        internal static Interop.SensorListener.SensorEventCallback _callback;
+
+        internal override void EventListenStart()
         {
-            Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
-            TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
-            Walking = (DetectorState)sensorData.values[0];
-            ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy;
+            _callback = (IntPtr sensorHandle, IntPtr eventPtr, IntPtr data) => {
+                Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(eventPtr);
+
+                TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
+                Walking = (DetectorState)sensorData.values[0];
+                ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy;
+
+                DataUpdated?.Invoke(this, new WalkingActivityDetectorDataUpdatedEventArgs(sensorData.values[0]));
+            };
+
+            int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, _callback, IntPtr.Zero);
+            if (error != (int)SensorError.None)
+            {
+                Log.Error(Globals.LogTag, "Error setting event callback for walking activity detector");
+                throw SensorErrorFactory.CheckAndThrowException(error, "Unable to set event callback for walking activity detector");
+            }
+        }
 
-            DataUpdated?.Invoke(this, new WalkingActivityDetectorDataUpdatedEventArgs(sensorData.values[0]));
+        internal override void EventListenStop()
+        {
+            int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
+            if (error != (int)SensorError.None)
+            {
+                Log.Error(Globals.LogTag, "Error unsetting event callback for walking activity detector");
+                throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for walking activity detector");
+            }
         }
 
         internal override SensorType GetSensorType()