Qt 4.8
Public Types | Public Slots | Public Functions | Private Slots | Private Functions | Properties | List of all members
QBBButtonEventNotifier Class Reference

#include <qbbbuttoneventnotifier.h>

Inheritance diagram for QBBButtonEventNotifier:
QObject

Public Types

enum  ButtonId {
  bid_minus = 0, bid_playpause, bid_plus, bid_power,
  ButtonCount
}
 
enum  ButtonState { ButtonUp, ButtonDown }
 

Public Slots

void start ()
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Public Functions

 QBBButtonEventNotifier (QObject *parent=0)
 
 ~QBBButtonEventNotifier ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Private Slots

void updateButtonStates ()
 

Private Functions

void close ()
 
bool parsePPS (const QByteArray &ppsData, QHash< QByteArray, QByteArray > *messageFields) const
 

Properties

QList< QByteArraymButtonKeys
 
int mFd
 
QSocketNotifiermReadNotifier
 
ButtonState mState [ButtonCount]
 

Additional Inherited Members

- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 52 of file qbbbuttoneventnotifier.h.

Enumerations

◆ ButtonId

◆ ButtonState

Enumerator
ButtonUp 
ButtonDown 

Definition at line 65 of file qbbbuttoneventnotifier.h.

Constructors and Destructors

◆ QBBButtonEventNotifier()

QBBButtonEventNotifier::QBBButtonEventNotifier ( QObject parent = 0)
explicit

Definition at line 65 of file qbbbuttoneventnotifier.cpp.

66  : QObject(parent),
67  mFd(-1),
68  mReadNotifier(0)
69 {
70  // Set initial state of buttons to ButtonUp and
71  // fetch the new button ids
72  int enumeratorIndex = QBBButtonEventNotifier::staticMetaObject.indexOfEnumerator("ButtonId");
74  for (int buttonId = bid_minus; buttonId < ButtonCount; ++buttonId) {
75  mButtonKeys.append(enumerator.valueToKey(buttonId));
76  mState[buttonId] = ButtonUp;
77  }
78 }
The QMetaEnum class provides meta-data about an enumerator.
Definition: qmetaobject.h:147
QSocketNotifier * mReadNotifier
const char * valueToKey(int value) const
Returns the string that is used as the name of the given enumeration value, or 0 if value is not defi...
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QByteArray > mButtonKeys
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QMetaEnum enumerator(int index) const
Returns the meta-data for the enumerator with the given index.
int indexOfEnumerator(const char *name) const
Finds enumerator name and returns its index; otherwise returns -1.
ButtonState mState[ButtonCount]

◆ ~QBBButtonEventNotifier()

QBBButtonEventNotifier::~QBBButtonEventNotifier ( )

Definition at line 80 of file qbbbuttoneventnotifier.cpp.

81 {
82  close();
83 }

Functions

◆ close()

void QBBButtonEventNotifier::close ( )
private

Definition at line 180 of file qbbbuttoneventnotifier.cpp.

Referenced by ~QBBButtonEventNotifier().

181 {
182  delete mReadNotifier;
183  mReadNotifier = 0;
184 
185  if (mFd != -1) {
187  mFd = -1;
188  }
189 }
QSocketNotifier * mReadNotifier
static int qt_safe_close(int fd)
Definition: qcore_unix_p.h:297

◆ parsePPS()

bool QBBButtonEventNotifier::parsePPS ( const QByteArray ppsData,
QHash< QByteArray, QByteArray > *  messageFields 
) const
private

Definition at line 191 of file qbbbuttoneventnotifier.cpp.

Referenced by updateButtonStates().

192 {
193  // tokenize pps data into lines
194  QList<QByteArray> lines = ppsData.split('\n');
195 
196  // validate pps object
197  if (lines.size() == 0 || !lines.at(0).contains(QByteArray("@status"))) {
198  qWarning("QQNX: unrecognized pps object, data=%s", ppsData.constData());
199  return false;
200  }
201 
202  // parse pps object attributes and extract values
203  for (int i = 1; i < lines.size(); i++) {
204 
205  // tokenize current attribute
206  const QByteArray &attr = lines.at(i);
207 
208  qButtonDebug() << Q_FUNC_INFO << "attr=" << attr;
209 
210  int doubleColon = attr.indexOf(QByteArray("::"));
211  if (doubleColon == -1) {
212  // abort - malformed attribute
213  continue;
214  }
215 
216  QByteArray key = attr.left(doubleColon);
217  QByteArray value = attr.mid(doubleColon + 2);
218  messageFields->insert(key, value);
219  }
220  return true;
221 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray mid(int index, int len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos...
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays...
#define qButtonDebug
int key
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.
Definition: qbytearray.h:525
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ start

void QBBButtonEventNotifier::start ( )
slot

Definition at line 85 of file qbbbuttoneventnotifier.cpp.

86 {
87  qButtonDebug() << Q_FUNC_INFO << "starting hardware button event processing";
88  if (mFd != -1)
89  return;
90 
91  // Open the pps interface
92  errno = 0;
94  if (mFd == -1) {
95  qWarning("QQNX: failed to open buttons pps, errno=%d", errno);
96  return;
97  }
98 
100  QObject::connect(mReadNotifier, SIGNAL(activated(int)), this, SLOT(updateButtonStates()));
101 
102  qButtonDebug() << Q_FUNC_INFO << "successfully connected to Navigator. fd =" << mFd;
103 }
QSocketNotifier * mReadNotifier
#define SLOT(a)
Definition: qobjectdefs.h:226
#define O_RDONLY
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static int qt_safe_open(const char *pathname, int flags, mode_t mode=0777)
Definition: qcore_unix_p.h:171
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
Q_CORE_EXPORT void qWarning(const char *,...)
#define qButtonDebug
static const char * ppsPath
int errno
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ updateButtonStates

void QBBButtonEventNotifier::updateButtonStates ( )
privateslot

Definition at line 105 of file qbbbuttoneventnotifier.cpp.

Referenced by start().

106 {
107  // Allocate buffer for pps data
108  char buffer[ppsBufferSize];
109 
110  // Attempt to read pps data
111  errno = 0;
112  int bytes = qt_safe_read(mFd, buffer, ppsBufferSize - 1);
113  qButtonDebug() << "Read" << bytes << "bytes of data";
114  if (bytes == -1) {
115  qWarning("QQNX: failed to read hardware buttons pps object, errno=%d", errno);
116  return;
117  }
118 
119  // We seem to get a spurious read notification after the real one. Ignore it
120  if (bytes == 0)
121  return;
122 
123  // Ensure data is null terminated
124  buffer[bytes] = '\0';
125 
126  qButtonDebug() << Q_FUNC_INFO << "received PPS message:\n" << buffer;
127 
128  // Process received message
129  QByteArray ppsData = QByteArray::fromRawData(buffer, bytes);
131  if (!parsePPS(ppsData, &fields))
132  return;
133 
134  // Update our state and inject key events as needed
135  for (int buttonId = bid_minus; buttonId < ButtonCount; ++buttonId) {
136  // Extract the new button state
137  QByteArray key = mButtonKeys.at(buttonId);
138  ButtonState newState = (fields.value(key) == QByteArray("b_up") ? ButtonUp : ButtonDown);
139 
140  // If state has changed, update our state and inject a keypress event
141  if (mState[buttonId] != newState) {
142  qButtonDebug() << "Hardware button event: button =" << key << "state =" << fields.value(key);
143  mState[buttonId] = newState;
144 
145  // Is it a key press or key release event?
147 
148  Qt::Key key;
149  switch (buttonId) {
150  case bid_minus:
151  key = Qt::Key_VolumeDown;
152  break;
153 
154  case bid_playpause:
155  key = Qt::Key_Play;
156  break;
157 
158  case bid_plus:
159  key = Qt::Key_VolumeUp;
160  break;
161 
162  case bid_power:
163  key = Qt::Key_PowerDown;
164  break;
165 
166  default:
167  qButtonDebug() << "Unknown hardware button";
168  continue;
169  }
170 
171  // No modifiers
172  Qt::KeyboardModifiers modifier = Qt::NoModifier;
173 
174  // Post the event
176  }
177  }
178 }
int type
Definition: qmetatype.cpp:239
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or 0 if no application wi...
static void handleKeyEvent(QWidget *w, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static QByteArray fromRawData(const char *, int size)
Constructs a QByteArray that uses the first size bytes of the data array.
Q_CORE_EXPORT void qWarning(const char *,...)
QList< QByteArray > mButtonKeys
#define qButtonDebug
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
static const int ppsBufferSize
int key
ButtonState mState[ButtonCount]
static qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
Definition: qcore_unix_p.h:273
int errno
bool parsePPS(const QByteArray &ppsData, QHash< QByteArray, QByteArray > *messageFields) const
#define Q_FUNC_INFO
Definition: qglobal.h:1871

Properties

◆ mButtonKeys

QList<QByteArray> QBBButtonEventNotifier::mButtonKeys
private

Definition at line 86 of file qbbbuttoneventnotifier.h.

Referenced by QBBButtonEventNotifier(), and updateButtonStates().

◆ mFd

int QBBButtonEventNotifier::mFd
private

Definition at line 83 of file qbbbuttoneventnotifier.h.

Referenced by close(), start(), and updateButtonStates().

◆ mReadNotifier

QSocketNotifier* QBBButtonEventNotifier::mReadNotifier
private

Definition at line 84 of file qbbbuttoneventnotifier.h.

Referenced by close(), and start().

◆ mState

ButtonState QBBButtonEventNotifier::mState[ButtonCount]
private

Definition at line 85 of file qbbbuttoneventnotifier.h.

Referenced by QBBButtonEventNotifier(), and updateButtonStates().


The documentation for this class was generated from the following files: