[Sensor] Review sensor API cs files
[platform/core/csapi/tizenfx.git] / src / Tizen.Sensor / Tizen.Sensor / Plugins / UltravioletSensor.cs
old mode 100644 (file)
new mode 100755 (executable)
index 4aeba27..491716a
@@ -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>
-    /// UltravioletSensor Class. Used for registering callbacks for ultraviolet sensor and getting ultraviolet data
-    /// /// </summary>
-    public class UltravioletSensor : Sensor
+    /// The UltravioletSensor class is used for registering callbacks for the ultraviolet sensor and getting the ultraviolet data.
+    /// </summary>
+    public sealed class UltravioletSensor : Sensor
     {
         private static string UltravioletSensorKey = "http://tizen.org/feature/sensor.ultraviolet";
 
         /// <summary>
         /// Gets the value of the ultraviolet sensor.
         /// </summary>
-        public float UltravioletIndex { get; private set; }
+        /// <since_tizen> 3 </since_tizen>
+        /// <value> The ultraviolet index. </value>
+        public float UltravioletIndex { get; private set; } = float.MinValue;
 
         /// <summary>
-        /// Returns true or false based on whether ultraviolet sensor is supported by device.
+        /// Returns true or false based on whether the ultraviolet sensor 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
@@ -37,6 +49,8 @@ namespace Tizen.Sensor
         /// <summary>
         /// Returns the number of ultraviolet sensors available on the device.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value> The count of ultraviolet sensors. </value>
         public static int Count
         {
             get
@@ -49,11 +63,13 @@ namespace Tizen.Sensor
         /// <summary>
         /// Initializes a new instance of the <see cref="Tizen.Sensor.UltravioletSensor"/> 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.ultraviolet</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 ultraviolet sensor in case of multiple sensors
+        /// Index. Default value for this is 0. Index refers to a particular ultraviolet sensor in case of multiple sensors.
         /// </param>
         public UltravioletSensor(uint index = 0) : base(index)
         {
@@ -66,8 +82,9 @@ namespace Tizen.Sensor
         }
 
         /// <summary>
-        /// Event Handler for storing the callback functions for event corresponding to change in ultraviolet sensor data.
+        /// An event handler for storing the callback functions for the event corresponding to the change in the ultraviolet sensor data.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
 
         public event EventHandler<UltravioletSensorDataUpdatedEventArgs> DataUpdated;
 
@@ -87,9 +104,20 @@ namespace Tizen.Sensor
             return count;
         }
 
-        protected override void EventListenStart()
+        private static Interop.SensorListener.SensorEventCallback _callback;
+
+        internal override void EventListenStart()
         {
-            int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, SensorEventCallback, IntPtr.Zero);
+            _callback = (IntPtr sensorHandle, IntPtr eventPtr, IntPtr data) => {
+                Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(eventPtr);
+
+                TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
+                UltravioletIndex = sensorData.values[0];
+
+                DataUpdated?.Invoke(this, new UltravioletSensorDataUpdatedEventArgs(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 ultraviolet sensor");
@@ -97,7 +125,7 @@ namespace Tizen.Sensor
             }
         }
 
-        protected override void EventListenStop()
+        internal override void EventListenStop()
         {
             int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
             if (error != (int)SensorError.None)
@@ -106,14 +134,5 @@ namespace Tizen.Sensor
                 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset event callback for ultraviolet");
             }
         }
-
-        private void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
-        {
-            Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
-            TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
-            UltravioletIndex = sensorData.values[0];
-
-            DataUpdated?.Invoke(this, new UltravioletSensorDataUpdatedEventArgs(sensorData.values[0]));
-        }
     }
 }