csapi-sensor: add default value in constructors of activity detectors
[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     public class InVehicleActivityDetector : ActivityDetector
14     {
15         /// <summary>
16         /// Gets the state of in-vehicle activity detector
17         /// </summary>
18         public DetectorState InVehicle { get; private set; }
19
20         /// <summary>
21         /// Returns true or false based on whether in-vehicle activity detector is supported by device.
22         /// </summary>
23         public static bool IsSupported
24         {
25             get
26             {
27                 Log.Info(Globals.LogTag, "Checking if the in-vehicle activity detector is supported");
28                 return CheckIfSupported();
29             }
30         }
31
32         /// <summary>
33         /// Returns the number of in-vehicle activity detector available on the device.
34         /// </summary>
35         public static int Count
36         {
37             get
38             {
39                 Log.Info(Globals.LogTag, "Getting the count of in-vehicle activity detectors");
40                 return GetCount();
41             }
42         }
43
44         /// <summary>
45         /// Initializes a new instance of the <see cref="Tizen.System.Sensor.InVehicleActivityDetector"/> class.
46         /// </summary>
47         /// <param name='index'>
48         /// Index. Default value for this is 0. Index refers to a particular in-vehicle activity detector in case of multiple sensors.
49         /// </param>
50         public InVehicleActivityDetector(int index = 0) : base(index)
51         {
52             SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.InVehicle);
53             Log.Info(Globals.LogTag, "Creating in-vehicle activity detector object");
54         }
55
56         private static bool CheckIfSupported()
57         {
58             bool isSupported;
59             int error = Interop.SensorManager.SensorIsSupported(SensorType.InVehicleActivityDetector, out isSupported);
60             if (error != (int)SensorError.None)
61             {
62                 Log.Error(Globals.LogTag, "Error checking if in-vehicle activity detector is supported");
63                 isSupported = false;
64             }
65             return isSupported;
66         }
67
68         private static int GetCount()
69         {
70             IntPtr list;
71             int count;
72             int error = Interop.SensorManager.GetSensorList(SensorType.InVehicleActivityDetector, out list, out count);
73             if (error != (int)SensorError.None)
74             {
75                 Log.Error(Globals.LogTag, "Error getting sensor list for in-vehicle activity detector");
76                 count = 0;
77             }
78             else
79                 Interop.Libc.Free(list);
80             return count;
81         }
82
83         /// <summary>
84         /// Event Handler for storing the callback functions for event corresponding to change in in-vehicle activity detector data.
85         /// </summary>
86         public event EventHandler<InVehicleActivityDetectorDataUpdatedEventArgs> DataUpdated;
87
88         protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
89         {
90             Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
91             TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
92             InVehicle = (DetectorState)sensorData.values[0];
93             ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy;
94
95             DataUpdated?.Invoke(this, new InVehicleActivityDetectorDataUpdatedEventArgs(sensorData.values[0]));
96         }
97
98         internal override SensorType GetSensorType()
99         {
100             return SensorType.InVehicleActivityDetector;
101         }
102     }
103 }