merge with master
[platform/framework/native/uix.git] / src / FUixSensorProximitySensorData.cpp
1 // 
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd. 
4 // 
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file     FUixSensorProximitySensorData.cpp
20  * @brief    This is the implementation file for the %ProximitySensorData class.
21  *
22  * This files contains implementation of the %ProximitySensorData class.
23  */
24
25 // Includes
26 #include <FBaseErrors.h>
27 #include <FBaseSysLog.h>
28 #include <FBaseFloat.h>
29 #include <FBaseLongLong.h>
30
31 #include <FUixSensorProximitySensorData.h>
32 #include "FUixSensor_SensorUtil.h"
33
34 using namespace Tizen::Base;
35
36 namespace Tizen { namespace Uix { namespace Sensor
37 {
38 namespace
39 {
40 static const wchar_t W_MSG_INVALID_SENSOR_DATA_KEY[] = L"A data matching the specified key and data type cannot be found.";
41 } // Anonymous
42
43 ProximitySensorData::ProximitySensorData(void)
44         : distance(0.0F)
45 {
46
47 }
48
49 ProximitySensorData::~ProximitySensorData(void)
50 {
51
52 }
53
54
55 ProximitySensorData::ProximitySensorData(const ProximitySensorData& rhs)
56         :distance(rhs.distance)
57 {
58
59 }
60
61 ProximitySensorData&
62 ProximitySensorData::operator =(const ProximitySensorData& rhs)
63 {
64         // check for self-assignment
65         if (this != &rhs)
66         {
67                 timestamp = rhs.timestamp;
68                 distance = rhs.distance;
69         }
70
71         return *this;
72 }
73
74 int
75 ProximitySensorData::GetHashCode(void) const
76 {
77         int hash = 0;
78
79                 hash += LongLong::GetHashCode(this->timestamp);
80                 hash += Float::GetHashCode(this->distance);
81
82                 return hash;
83 }
84
85 bool
86 ProximitySensorData::Equals(const Object& rhs) const
87 {
88         const ProximitySensorData* pRhs = dynamic_cast <const ProximitySensorData*>(&rhs);
89         if (pRhs == null)
90         {
91                 return false;
92         }
93
94         if (this->timestamp != pRhs->timestamp)
95         {
96                 return false;
97         }
98
99         if (this->distance != pRhs->distance)
100         {
101                 return false;
102         }
103
104         return true;
105 }
106
107 result
108 ProximitySensorData::GetValue(SensorDataKey dataKey, long& value) const
109 {
110         switch (static_cast<ProximityDataKey>(dataKey))
111         {
112         case PROXIMITY_DATA_KEY_TIMESTAMP:
113                 value = _SensorUtil::CutTimestamp(timestamp);
114                 break;
115         default:
116                 SysLogException(NID_UIX, E_INVALID_ARG, "[%s] %ls", GetErrorMessage(E_INVALID_ARG), W_MSG_INVALID_SENSOR_DATA_KEY);
117                 return E_INVALID_ARG;
118         }
119
120         return E_SUCCESS;
121 }
122
123 result
124 ProximitySensorData::GetValue(SensorDataKey dataKey, float& value) const
125 {
126         SysLogException(NID_UIX, E_INVALID_ARG, "[%s] %ls", GetErrorMessage(E_INVALID_ARG), W_MSG_INVALID_SENSOR_DATA_KEY);
127         return E_INVALID_ARG;
128 }
129
130 result
131 ProximitySensorData::GetValue(SensorDataKey dataKey, bool& value) const
132 {
133         switch (static_cast<ProximityDataKey>(dataKey))
134         {
135         case PROXIMITY_DATA_KEY_ONOFF:
136                 value = _SensorUtil::IsObjectDetected(distance);
137                 break;
138         default:
139                 SysLogException(NID_UIX, E_INVALID_ARG, "[%s] %ls", GetErrorMessage(E_INVALID_ARG), W_MSG_INVALID_SENSOR_DATA_KEY);
140                 return E_INVALID_ARG;
141         }
142
143         return E_SUCCESS;
144 }
145
146 bool
147 ProximitySensorData::IsObjectDetected(void) const
148 {
149         return _SensorUtil::IsObjectDetected(distance);
150 }
151 } } }// Tizen::Uix::Sensor