LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
InputManager.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
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 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef INPUTMANAGER_H
23 #define INPUTMANAGER_H
24 
25 #include "Common.h"
26 
27 #include <string>
28 #include <map>
29 
30 #include <lunaservice.h>
31 
32 #include <Qt>
33 #include <QEvent>
34 
35 #include "Timer.h"
36 
37 QT_BEGIN_NAMESPACE
38 class QKeyEvent;
39 QT_END_NAMESPACE
40 
41 struct json_object;
42 
44 {
45 
46 public:
47  InputManager();
48  virtual ~InputManager();
49 
50  virtual bool handleEvent(QEvent* event);
51 
52  static bool audioKeyServiceCallback(LSHandle* handle, LSMessage* msg, void* userData);
53  static bool mediaKeyServiceCallback(LSHandle* handle, LSMessage* msg, void* userData);
54  static bool switchesStatusCallback(LSHandle* handle, LSMessage* msg, void* userData);
55 #if 0
56  static bool switchesRingerCallback(LSHandle* handle, LSMessage* msg, void* userData);
57  static bool switchesSliderCallback(LSHandle* handle, LSMessage* msg, void* userData);
58 #endif
59  static bool headsetStatusCallback(LSHandle* handle, LSMessage* msg, void* userData);
60 
61 private:
62  void startService();
63  void stopService();
64 
65  bool isSwitch(Qt::Key key);
66  bool isHeadsetKey(Qt::Key key);
67  bool isAudioKey(Qt::Key key);
68  bool isMediaKey(Qt::Key key);
69  bool isBluetoothKey(Qt::Key key);
70  bool isPublicCategory(const char* category);
71 
72  static bool activityStartCallback(LSHandle* handle, LSMessage* msg, void* userData);
73 
74  json_object* createKeyJson(const char* key, const char* value);
75  json_object* createKeyJson(const char* key, QEvent::Type type);
76 
77  void postKeyToSubscribers(QKeyEvent* event, const char* category, const char* keyString, const char* keyValue = NULL);
78  static bool processSubscription(LSHandle* handle, LSMessage* msg, void* userData);
79  bool processKeyState(LSHandle* handle, LSMessage* msg, void* userData);
80 
81  void handleBluetoothKey(const QKeyEvent* event);
82 
83  QEvent::Type getKeyState(Qt::Key key);
84  bool setKeyState(Qt::Key key, QEvent::Type state);
85  bool keyToString(Qt::Key key, const char** string);
86  qint32 stringToKey(const char* string);
87 
88  LSPalmService* m_palmService;
89  LSHandle* m_service; // private bus
90  LSHandle* m_publicService; // public bus
91 
92  // Switches
93  QEvent::Type m_ringerState;
94  QEvent::Type m_sliderState;
95 
96  enum HeadsetType {
97  HeadsetInvalid = -1,
98  Headset,
99  HeadsetMic
100  };
101 
102  // Headset and headset with mic states
103  QEvent::Type m_headsetState;
104  HeadsetType m_headsetType;
105 
106  enum HeadsetButtonState {
107  Start,
108  SinglePressOrHold,
109  Hold,
110  PotentialDoublePress,
111  DoublePressOrHold,
112  };
113 
114  void headsetStateMachine(QEvent* e);
115  bool headsetBtnTimerCallback(void);
116  HeadsetButtonState m_headsetBtnState;
117  Timer<InputManager> m_headsetBtnTimer;
118 
119  class CategoryMapEntry {
120  public:
121  CategoryMapEntry()
122  {
123  m_isPublic = false;
124  }
125 
126  CategoryMapEntry(const std::string& category, bool isPublic)
127  {
128  m_category = category;
129  m_isPublic = isPublic;
130  }
131 
132  bool isPublic(void)
133  {
134  return m_isPublic;
135  }
136 
137  private:
138  std::string m_category;
139  bool m_isPublic;
140  };
141 
142  std::map<std::string, CategoryMapEntry*> m_categoryMap;
143 };
144 
145 #endif /* INPUTMANAGER_H */