Tizen 2.0 Release
[framework/osp/locations.git] / src / FLoc_LocationMonitor.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        FLoc_LocationMonitor.cpp
20  * @brief       This is the implementation file for the %_LocationMonitor class.
21  *
22  * This implementation file contains the definitions of the %_LocationMonitor class methods.
23  */
24
25 #include <FBaseSysLog.h>
26 #include "FLoc_LocationMonitor.h"
27
28 using namespace Tizen::Base::Runtime;
29 using namespace std;
30
31 namespace Tizen { namespace Locations
32 {
33
34 _LocationMonitor::_LocationMonitor(void)
35         : __pMonitor(null)
36         , __pLocation(null)
37 {
38 }
39
40 _LocationMonitor::~_LocationMonitor(void)
41 {
42         delete __pLocation;
43 }
44
45 result
46 _LocationMonitor::Construct(int timeout, LocationAccuracy accuracy)
47 {
48         unique_ptr< Tizen::Base::Runtime::Monitor > pMonitor(new (std::nothrow) Monitor());
49         SysTryReturn(NID_LOC, pMonitor, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
50
51         result r = pMonitor->Construct();
52         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Error from Monitor::Construct(). Propagating.", GetErrorMessage(r));
53
54         __pMonitor = std::move(pMonitor);
55
56         __timeout = timeout;
57         __accuracy = accuracy;
58
59         return r;
60 }
61
62 result
63 _LocationMonitor::Enter(void)
64 {
65         return __pMonitor->Enter();
66 }
67
68 result
69 _LocationMonitor::Wait(void)
70 {
71         return __pMonitor->Wait();
72 }
73
74 result
75 _LocationMonitor::Notify(void)
76 {
77         return __pMonitor->Notify();
78 }
79
80 result
81 _LocationMonitor::Exit(void)
82 {
83         return __pMonitor->Exit();
84 }
85
86 Location*
87 _LocationMonitor::GetLocationN(void)
88 {
89         Location* pLocation = __pLocation;
90         __pLocation = null;
91         return pLocation;
92 }
93
94 void
95 _LocationMonitor::SetLocation(Tizen::Locations::Location* pLocation)
96 {
97         if (__pLocation != null)
98         {
99                 delete __pLocation;
100         }
101         __pLocation = pLocation;
102 }
103
104 int
105 _LocationMonitor::GetTimeout(void) const
106 {
107         return __timeout;
108 }
109
110 LocationAccuracy
111 _LocationMonitor::GetAccuracy(void) const
112 {
113         return __accuracy;
114 }
115
116 }}