csapi-sensor: add descriptions for activity/gesture sensor class
[platform/core/csapi/sensor.git] / Tizen.System.Sensor / Tizen.System.Sensor / Plugins / InVehicleActivityDetector.cs
1 // Copyright 2016 by Samsung Electronics, Inc.,
2 //
3 // This software is the confidential and proprietary information
4 // of Samsung Electronics, Inc. ("Confidential Information"). You
5 // shall not disclose such Confidential Information and shall use
6 // it only in accordance with the terms of the license agreement
7 // you entered into with Samsung.
8
9 using System;
10
11 namespace Tizen.System.Sensor
12 {
13     /// <summary>
14     /// InVehicleActivityDetector Class. Used for registering callbacks for in vehicle activity detector and getting the in vehicle state
15     /// </summary>
16     public class InVehicleActivityDetector : ActivityDetector
17     {
18         /// <summary>
19         /// Gets the state of in-vehicle activity detector
20         /// </summary>
21         public DetectorState InVehicle { get; private set; }
22
23         /// <summary>
24         /// Returns true or false based on whether in-vehicle activity detector is supported by device.
25         /// </summary>
26         public static bool IsSupported
27         {
28             get
29             {
30                 Log.Info(Globals.LogTag, "Checking if the in-vehicle activity detector is supported");
31                 return CheckIfSupported();
32             }
33         }
34
35         /// <summary>
36         /// Returns the number of in-vehicle activity detector available on the device.
37         /// </summary>
38         public static int Count
39         {
40             get
41             {
42                 Log.Info(Globals.LogTag, "Getting the count of in-vehicle activity detectors");
43                 return GetCount();
44             }
45         }
46
47         /// <summary>
48         /// Initializes a new instance of the <see cref="Tizen.System.Sensor.InVehicleActivityDetector"/> class.
49         /// </summary>
50         /// <param name='index'>
51         /// Index. Default value for this is 0. Index refers to a particular in-vehicle activity detector in case of multiple sensors.
52         /// </param>
53         public InVehicleActivityDetector(int index = 0) : base(index)
54         {
55             SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.InVehicle);
56             Log.Info(Globals.LogTag, "Creating in-vehicle activity detector object");
57         }
58
59         private static bool CheckIfSupported()
60         {
61             bool isSupported;
62             int error = Interop.SensorManager.SensorIsSupported(SensorType.InVehicleActivityDetector, out isSupported);
63             if (error != (int)SensorError.None)
64             {
65                 Log.Error(Globals.LogTag, "Error checking if in-vehicle activity detector is supported");
66                 isSupported = false;
67             }
68             return isSupported;
69         }
70
71         private static int GetCount()
72         {
73             IntPtr list;
74             int count;
75             int error = Interop.SensorManager.GetSensorList(SensorType.InVehicleActivityDetector, out list, out count);
76             if (error != (int)SensorError.None)
77             {
78                 Log.Error(Globals.LogTag, "Error getting sensor list for in-vehicle activity detector");
79                 count = 0;
80             }
81             else
82                 Interop.Libc.Free(list);
83             return count;
84         }
85
86         /// <summary>
87         /// Event Handler for storing the callback functions for event corresponding to change in in-vehicle activity detector data.
88         /// </summary>
89         public event EventHandler<InVehicleActivityDetectorDataUpdatedEventArgs> DataUpdated;
90
91         protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
92         {
93             Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
94             TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
95             InVehicle = (DetectorState)sensorData.values[0];
96             ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy;
97
98             DataUpdated?.Invoke(this, new InVehicleActivityDetectorDataUpdatedEventArgs(sensorData.values[0]));
99         }
100
101         internal override SensorType GetSensorType()
102         {
103             return SensorType.InVehicleActivityDetector;
104         }
105     }
106 }