Setting since_tizen 3/4 on Tizen.NET API
[platform/core/csapi/tizenfx.git] / src / Tizen.Sensor / Tizen.Sensor / Plugins / OrientationSensor.cs
old mode 100644 (file)
new mode 100755 (executable)
index 465c358..866b29f
@@ -19,31 +19,40 @@ using System;
 namespace Tizen.Sensor
 {
     /// <summary>
-    /// OrientationSensor Class. Used for registering callbacks for orientation sensor and getting orientation data
-    /// /// </summary>
+    /// The OrientationSensor class is used for registering callbacks for the orientation sensor and getting the orientation data.
+    /// </summary>
+    /// <since_tizen> 3 </since_tizen>
     public sealed class OrientationSensor : Sensor
     {
         private static string OrientationSensorKey = "http://tizen.org/feature/sensor.tiltmeter";
 
         private event EventHandler<SensorAccuracyChangedEventArgs> _accuracyChanged;
         /// <summary>
-        /// Gets the Azimuth component of the orientation.
+        /// Gets the azimuth component of the orientation.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value> Azimuth </value>
         public float Azimuth { get; private set; } = float.MinValue;
 
         /// <summary>
-        /// Gets the Pitch component of the orientation.
+        /// Gets the pitch component of the orientation.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value> Pitch </value>
         public float Pitch { get; private set; } = float.MinValue;
 
         /// <summary>
-        /// Gets the Roll component of the orientation.
+        /// Gets the roll component of the orientation.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value> Roll </value>
         public float Roll { get; private set; } = float.MinValue;
 
         /// <summary>
-        /// Returns true or false based on whether orientation sensor is supported by device.
+        /// Returns true or false based on whether the orientation 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
@@ -56,6 +65,8 @@ namespace Tizen.Sensor
         /// <summary>
         /// Returns the number of orientation sensors available on the device.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value> The count of orientation sensors. </value>
         public static int Count
         {
             get
@@ -68,11 +79,13 @@ namespace Tizen.Sensor
         /// <summary>
         /// Initializes a new instance of the <see cref="Tizen.Sensor.OrientationSensor"/> 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.tiltmeter</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 orientation sensor in case of multiple sensors
+        /// Index. Default value for this is 0. Index refers to a particular orientation sensor in case of multiple sensors.
         /// </param>
         public OrientationSensor(uint index = 0) : base(index)
         {
@@ -85,14 +98,16 @@ namespace Tizen.Sensor
         }
 
         /// <summary>
-        /// Event Handler for storing the callback functions for event corresponding to change in orientation sensor data.
+        /// An event handler for storing the callback functions for the event corresponding to the change in the orientation sensor data.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
 
         public event EventHandler<OrientationSensorDataUpdatedEventArgs> DataUpdated;
 
         /// <summary>
-        /// Event handler for accuracy changed events.
+        /// An event handler for accuracy changed events.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
         public event EventHandler<SensorAccuracyChangedEventArgs> AccuracyChanged
         {
             add
@@ -128,9 +143,22 @@ namespace Tizen.Sensor
             return count;
         }
 
-        protected internal 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);
+                Azimuth = sensorData.values[0];
+                Pitch = sensorData.values[1];
+                Roll = sensorData.values[2];
+
+                DataUpdated?.Invoke(this, new OrientationSensorDataUpdatedEventArgs(sensorData.values));
+            };
+
+            int error = Interop.SensorListener.SetEventCallback(ListenerHandle, Interval, _callback, IntPtr.Zero);
             if (error != (int)SensorError.None)
             {
                 Log.Error(Globals.LogTag, "Error setting event callback for orientation sensor");
@@ -138,7 +166,7 @@ namespace Tizen.Sensor
             }
         }
 
-        protected internal override void EventListenStop()
+        internal override void EventListenStop()
         {
             int error = Interop.SensorListener.UnsetEventCallback(ListenerHandle);
             if (error != (int)SensorError.None)
@@ -148,9 +176,16 @@ namespace Tizen.Sensor
             }
         }
 
+        private static Interop.SensorListener.SensorAccuracyCallback _accuracyCallback;
+
         private void AccuracyListenStart()
         {
-            int error = Interop.SensorListener.SetAccuracyCallback(ListenerHandle, AccuracyEventCallback, IntPtr.Zero);
+            _accuracyCallback = (IntPtr sensorHandle, UInt64 timestamp, SensorDataAccuracy accuracy, IntPtr data) => {
+                TimeSpan = new TimeSpan((Int64)timestamp);
+                _accuracyChanged?.Invoke(this, new SensorAccuracyChangedEventArgs(new TimeSpan((Int64)timestamp), accuracy));
+            };
+
+            int error = Interop.SensorListener.SetAccuracyCallback(ListenerHandle, _accuracyCallback, IntPtr.Zero);
             if (error != (int)SensorError.None)
             {
                 Log.Error(Globals.LogTag, "Error setting accuracy event callback for orientation sensor");
@@ -167,22 +202,5 @@ namespace Tizen.Sensor
                 throw SensorErrorFactory.CheckAndThrowException(error, "Unable to unset accuracy event callback for orientation");
             }
         }
-
-        private void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
-        {
-            Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
-            TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
-            Azimuth = sensorData.values[0];
-            Pitch = sensorData.values[1];
-            Roll = sensorData.values[2];
-
-            DataUpdated?.Invoke(this, new OrientationSensorDataUpdatedEventArgs(sensorData.values));
-        }
-
-        private void AccuracyEventCallback(IntPtr sensorHandle, UInt64 timestamp, SensorDataAccuracy accuracy, IntPtr data)
-        {
-            TimeSpan = new TimeSpan((Int64)timestamp);
-            _accuracyChanged?.Invoke(this, new SensorAccuracyChangedEventArgs(new TimeSpan((Int64)timestamp), accuracy));
-        }
     }
 }