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.
18 * @author Qi Xiangguo (xiangguo.qi@samsung.com)
23 #ifndef WRTDEVICEAPIS_ORIENTATION_ORIENTATION_H_
24 #define WRTDEVICEAPIS_ORIENTATION_ORIENTATION_H_
27 #include <dpl/shared_ptr.h>
28 #include <dpl/noncopyable.h>
30 #include <sensor_accel.h>
31 #include <Orientation/IOrientation.h>
32 #include <Orientation/OrientationFactory.h>
33 #include <Orientation/EventOrientationChanged.h>
34 #include <Commons/Emitters.h>
36 namespace WrtDeviceApis {
37 namespace Orientation {
39 class Orientation : public Api::IOrientation
44 * @See: Api::Orientation.
46 friend class Api::OrientationFactory;
53 Api::EventOrientationChangedEmitterPtr m_emitter;
58 const Api::EventOrientationChangedEmitterPtr&
70 Api::EventOrientationChangedEmitterPtr getEmitter()
75 void emit(const Api::EventOrientationChangedPtr& event)
77 m_emitter->emit(event);
79 void getCurrentOrientationForWatch();
80 void orientationHasChanged(sensor_event_data_t *sensorEvent);
82 typedef DPL::SharedPtr<Watcher> WatcherPtr;
85 virtual ~Orientation();
88 * @See: IOrientation::getCurrentOrientation
90 virtual void getCurrentOrientation(
91 const Api::EventGetCurrentOrientationPtr& event);
94 * @See: IOrientation::watchOrientation
96 virtual long watchOrientation(
97 const Api::EventOrientationChangedEmitterPtr&
99 long minNotificationInterval);
102 * @See: IOrientation::clearWatch
104 virtual void clearWatch(
105 Api::EventOrientationChangedEmitter::IdType id);
108 * Method to run from platform's callback function
110 void OrientationHasChanged(sensor_event_data_t *sensorEvent);
113 * Method to get current orientation for watch function
115 void getCurrentOrientationForWatch();
119 virtual void OnRequestReceived(
120 const Api::EventGetCurrentOrientationPtr& event);
123 typedef Commons::Emitters<Api::EventOrientationChangedEmitter>
124 OrientationChangedEmitters;
127 * Initialize orientation sensor. This method returns when platform error occurs.
132 * Start orientation sensor. This method sends a start command to sensor server.
134 void start(int handle);
137 * Stop orientation sensor. This method sends a stop command to sensor server.
139 void stop(int& handle,
140 bool isWatcherHandle = false);
143 * Method to restart orientation sensor server.
145 void restart(int& handle);
147 OrientationChangedEmitters m_OrientationEmitters;
148 DPL::Mutex m_initializationMutex;
151 std::vector<WatcherPtr> m_watchers;
157 #endif // WRTDEVICEAPIS_ORIENTATION_ORIENTATION_H_