Tizen 2.0 Release
[framework/osp/locations.git] / src / FLoc_SyncLocationRequestInfo.h
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        FLoc_SyncLocationRequestInfo.h
20  * @brief       This is the header file for the %_SyncLocationRequestInfo class.
21  *
22  * This header file contains the declarations of the %_SyncLocationRequestInfo class member variables.
23  */
24
25 #ifndef _FLOC_INTERNAL_SYNC_LOCATION_REQUEST_INFO_H_
26 #define _FLOC_INTERNAL_SYNC_LOCATION_REQUEST_INFO_H_
27
28 #include <new>
29 #include <unique_ptr.h>
30 #include <FBaseObject.h>
31 #include <FBaseRtTimer.h>
32 #include <FBaseRtITimerEventListener.h>
33 #include <FLocTypes.h>
34 #include <FSysSystemTime.h>
35
36 namespace Tizen { namespace Locations
37 {
38 class _LocationMonitor;
39 class _LocationManager;
40
41 class _SyncLocationRequestInfo
42         : public Tizen::Base::Object
43 {
44 public:
45         _SyncLocationRequestInfo(_LocationMonitor* pLocMonitor, RequestId reqId)
46                 : Tizen::Base::Object()
47                 , __pLocMonitor(pLocMonitor)
48                 , __pTimer(null)
49                 , __reqId(reqId)
50                 , __tickCount(0)
51         {
52                 Tizen::System::SystemTime::GetCurrentTime(__requestTime);
53         }
54
55         ~_SyncLocationRequestInfo(void) {}
56
57         _LocationMonitor* GetLocationMonitor(void) const {return __pLocMonitor;}
58
59         result StartTimer(Tizen::Base::Runtime::ITimerEventListener& listener)
60         {
61                 result r = E_SUCCESS;
62
63                 if (__pTimer == null)
64                 {
65                         std::unique_ptr< Tizen::Base::Runtime::Timer > pTimer(new (std::nothrow) Tizen::Base::Runtime::Timer());
66                         SysTryReturn(NID_LOC, pTimer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
67                                                  "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
68                         r = pTimer->Construct(listener);
69                         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to construct the timer.", GetErrorMessage(r));
70
71                         __pTimer = std::move(pTimer);
72                 }
73
74                 const int DEFAULT_TIME_OUT = 1000;
75                 r = __pTimer->Start(DEFAULT_TIME_OUT);
76                 SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the timer.", GetErrorMessage(r));
77                 __tickCount++;
78                 return E_SUCCESS;
79         }
80
81         bool Equals(const Tizen::Base::Runtime::Timer& timer) {return __pTimer->Equals(timer);}
82
83         RequestId GetRequestId(void) const {return __reqId;}
84
85         int GetTickCount(void) const {return __tickCount;}
86
87         bool IsInTime(const Tizen::Base::DateTime& timestamp)
88         {
89                 return (timestamp > __requestTime) ? true : false;
90         }
91
92         bool IsAccuracySatisfying(LocationAccuracy accuracy)
93         {
94                 if (accuracy == LOC_ACCURACY_INVALID)
95                 {
96                         return false;
97                 }
98                 else
99                 {
100                         return (accuracy <= __pLocMonitor->GetAccuracy()) ? true : false;
101                 }
102         }
103
104 private:
105         _SyncLocationRequestInfo(void);
106
107         _SyncLocationRequestInfo& operator =(const _SyncLocationRequestInfo& rhs);
108
109 private:
110         Tizen::Base::DateTime __requestTime;
111         _LocationMonitor* __pLocMonitor;
112         std::unique_ptr< Tizen::Base::Runtime::Timer > __pTimer;
113         RequestId __reqId;
114         int __tickCount;
115 }; //_SyncLocationRequestInfo
116 }} //Tizen::Locations
117 #endif // _FLOC_INTERNAL_SYNC_LOCATION_REQUEST_INFO_H_