tizen beta release
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Haptics / Motor.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #ifndef WRTDEVICEAPIS_HAPTICS_MOTOR_H_
17 #define WRTDEVICEAPIS_HAPTICS_MOTOR_H_
18
19 #include <cstddef>
20 #include <devman_haptic.h>
21 #include <dpl/mutex.h>
22 #include <dpl/shared_ptr.h>
23 #include <Commons/IEvent.h>
24 #include <Haptics/IMotor.h>
25
26 namespace WrtDeviceApis {
27 namespace Haptics {
28 // Dummy event for asynchronous haptic motor schedule
29 class EventHapticAction : public Commons::IEvent<EventHapticAction>
30 {
31 };
32 typedef DPL::SharedPtr<EventHapticAction> EventHapticActionPtr;
33 typedef Commons::EventRequestReceiver<EventHapticAction> EventHapticActionReqReceiver;
34 typedef Commons::EventRequestReceiver<Api::EventStartMotor> EventStartMotorReqReceiver;
35 typedef Commons::EventRequestReceiver<Api::EventPlayBeep> EventPlayBeepReqReceiver;
36
37 class Motor :
38     public Api::IMotor,
39     public EventHapticActionReqReceiver,
40     public EventStartMotorReqReceiver,
41     public EventPlayBeepReqReceiver
42 {
43   public:
44     explicit Motor(haptic_dev_idx index);
45     virtual ~Motor();
46
47     /**
48      * Run vibrate for duration.
49      * @param duration is unsigned long and value in milliseconds..
50      * @return none
51      */
52     void run(unsigned long duration);
53
54     /**
55      * Run vibrate for given  pattern .
56      * @param The pattern argument is a DOMString composed by '.' and '_' chars.
57      * @return none
58      */
59     void run(const Api::HapticPatternPtr& pattern);
60
61     /**
62      * Run vibrate for given  event .
63      * @param The event argument is event included duration & pattern.
64      * @return none
65      */
66     void run(const Api::EventStartMotorPtr& event);
67
68     /**
69      * stop motor for vibrating device
70      * @param none
71      * @return none
72      */
73     void stopMotor();
74
75     /**
76      * stop vibration. (pattern and motor)
77      * @param none
78      * @return none
79      */
80     void stopVibration();
81
82     /**
83      * Run notify  for given  duration and volume.if volume!=0 beep device,volume=0&vibrate open vibrate device
84      * @param duration value is unsigned long in millsecond.
85      * @param volume value is 0~7
86      * @return none
87      */
88     int playBeep(unsigned long duration,
89             int volume);
90
91     /**
92      * Run notify  for given  duration and volume.if volume!=0 beep device,volume=0&vibrate open vibrate device
93      * @param duration value is unsigned long in millsecond.
94      * @param volume value is 0~7
95      * @return none
96      */
97     void playBeep(const Api::EventPlayBeepPtr& event);
98
99     /**
100      * stop  beep/vibrate/light-on  device
101      * @param none
102      * @return none
103      */
104     void stopBeep();
105
106   protected:
107     void OnRequestReceived(const EventHapticActionPtr& event);
108     void OnRequestReceived(const Api::EventStartMotorPtr& event);
109     void OnRequestReceived(const Api::EventPlayBeepPtr& event);
110
111   private:
112     void runNextPattern();
113     void arragePattern(Api::HapticPatternPtr& patternPtr,
114             const unsigned long duration);
115
116   private:
117     int m_device; ///< Platform haptic device handle.
118     int m_beepHandle; ///< Platform beep handle.
119     Api::HapticPatternPtr m_pattern;    // haptic action pattern
120     EventHapticActionPtr m_event;        // haptic action scheduling event
121     size_t m_current;        // current haptic action pattern interval
122     DPL::Mutex m_patternMutex;
123 };
124 } // Haptics
125 } // WrtDeviceApis
126
127 #endif /* WRTDEVICEAPIS_HAPTICS_MOTOR_H_ */