2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file Accelerometer.h
18 * @author Qi Xiangguo (xiangguo.qi@samsung.com)
23 #ifndef WRTDEVICEAPIS_ACCELEROMETER_ACCELEROMETER_H_
24 #define WRTDEVICEAPIS_ACCELEROMETER_ACCELEROMETER_H_
27 #include <dpl/shared_ptr.h>
28 #include <dpl/noncopyable.h>
30 #include <sensor_accel.h>
31 #include <Accelerometer/IAccelerometer.h>
32 #include <Accelerometer/AccelerometerFactory.h>
33 #include <Accelerometer/EventAccelerationChanged.h>
34 #include <Commons/Emitters.h>
36 namespace WrtDeviceApis {
37 namespace Accelerometer {
39 class Accelerometer : public Api::IAccelerometer
45 * @See: IgetCurrentAcceleration
47 friend class Api::AccelerometerFactory;
54 Api::EventAccelerationChangedEmitterPtr m_emitter;
59 const Api::EventAccelerationChangedEmitterPtr&
71 Api::EventAccelerationChangedEmitterPtr getEmitter()
76 void emit(const Api::EventAccelerationChangedPtr& event)
78 m_emitter->emit(event);
80 void getCurrentAccelerationForWatch();
81 void accelerationHasChanged(sensor_event_data_t *sensorEvent);
83 typedef DPL::SharedPtr<Watcher> WatcherPtr;
86 virtual ~Accelerometer();
89 * @See: IgetCurrentAcceleration
91 virtual void getCurrentAcceleration(
92 const Api::EventGetCurrentAccelerationPtr& event);
95 * @See: IwatchAcceleration
97 virtual long watchAcceleration(
98 const Api::EventAccelerationChangedEmitterPtr&
100 long minNotificationInterval);
105 virtual void clearWatch(
106 Api::EventAccelerationChangedEmitter::IdType id);
109 * Method to run from platform's callback function
111 void accelerationHasChanged(sensor_event_data_t *sensorEvent);
114 * Method to run currentAcceleration for watch function
117 void getCurrentAccelerationForWatch();
121 virtual void OnRequestReceived(
122 const Api::EventGetCurrentAccelerationPtr& event);
125 typedef Commons::Emitters<Api::EventAccelerationChangedEmitter>
126 AccelerationChangedEmitters;
129 * Initialize accelerometer sensor. This method returns when platform error occurs.
134 * Start accelerometer sensor. This method sends a start command to sensor server.
136 void start(int handle);
139 * Stop accelerometer sensor. This method sends a stop command to sensor server.
141 void stop(int& handle, bool isWatcherHandle = false);
144 * Method to restart accelerometer sensor server.
146 void restart(int& handle);
148 AccelerationChangedEmitters m_AccelerationEmitters;
149 DPL::Mutex m_initializationMutex;
153 std::vector<WatcherPtr> m_watchers;
159 #endif // WRTDEVICEAPIS_ACCELEROMETER_ACCELEROMETER_H_