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

#include <qbbnavigatoreventnotifier.h>

Inheritance diagram for QBBNavigatorEventNotifier:
QObject

Public Slots

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

Public Functions

 QBBNavigatorEventNotifier (QBBNavigatorEventHandler *eventHandler, QObject *parent=0)
 
 ~QBBNavigatorEventNotifier ()
 
- 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 readData ()
 

Private Functions

void handleMessage (const QByteArray &msg, const QByteArray &dat, const QByteArray &id)
 
void parsePPS (const QByteArray &ppsData, QByteArray &msg, QByteArray &dat, QByteArray &id)
 
void replyPPS (const QByteArray &res, const QByteArray &id, const QByteArray &dat)
 

Properties

QBBNavigatorEventHandlermEventHandler
 
int mFd
 
QSocketNotifiermReadNotifier
 

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 qbbnavigatoreventnotifier.h.

Constructors and Destructors

◆ QBBNavigatorEventNotifier()

QBBNavigatorEventNotifier::QBBNavigatorEventNotifier ( QBBNavigatorEventHandler eventHandler,
QObject parent = 0 
)
explicit

Definition at line 63 of file qbbnavigatoreventnotifier.cpp.

64  : QObject(parent),
65  mEventHandler(eventHandler),
66  mFd(-1),
67  mReadNotifier(0)
68 {
69 }
QBBNavigatorEventHandler * mEventHandler
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QBBNavigatorEventNotifier()

QBBNavigatorEventNotifier::~QBBNavigatorEventNotifier ( )

Definition at line 71 of file qbbnavigatoreventnotifier.cpp.

72 {
73  delete mReadNotifier;
74 
75  if (mFd != -1)
77 
78 #if defined(QBBNAVIGATOREVENTNOTIFIER_DEBUG)
79  qDebug() << "QBB: navigator event notifier stopped";
80 #endif
81 }
static int qt_safe_close(int fd)
Definition: qcore_unix_p.h:297
Q_CORE_EXPORT void qDebug(const char *,...)

Functions

◆ handleMessage()

void QBBNavigatorEventNotifier::handleMessage ( const QByteArray msg,
const QByteArray dat,
const QByteArray id 
)
private

Definition at line 180 of file qbbnavigatoreventnotifier.cpp.

Referenced by readData().

181 {
182 #if defined(QBBNAVIGATOREVENTNOTIFIER_DEBUG)
183  qDebug() << "PPS: msg=" << msg << ", dat=" << dat << ", id=" << id;
184 #endif
185 
186  // check message type
187  if (msg == "orientationCheck") {
188  const bool result = mEventHandler->handleOrientationCheck(dat.toInt());
189  replyPPS(msg, id, result ? "true": "false");
190  } else if (msg == "orientation") {
192  replyPPS(msg, id, "");
193  } else if (msg == "SWIPE_DOWN") {
195  } else if (msg == "exit") {
197  } else if (msg == "windowActive") {
199  } else if (msg == "windowInactive") {
201  }
202 }
void handleWindowGroupActivated(const QByteArray &id)
QBBNavigatorEventHandler * mEventHandler
void handleWindowGroupDeactivated(const QByteArray &id)
Q_CORE_EXPORT void qDebug(const char *,...)
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
void replyPPS(const QByteArray &res, const QByteArray &id, const QByteArray &dat)

◆ parsePPS()

void QBBNavigatorEventNotifier::parsePPS ( const QByteArray ppsData,
QByteArray msg,
QByteArray dat,
QByteArray id 
)
private

Definition at line 101 of file qbbnavigatoreventnotifier.cpp.

Referenced by readData().

102 {
103 #if defined(QBBNAVIGATOREVENTNOTIFIER_DEBUG)
104  qDebug() << "PPS: data=" << ppsData;
105 #endif
106 
107  // tokenize pps data into lines
108  QList<QByteArray> lines = ppsData.split('\n');
109 
110  // validate pps object
111  if (lines.size() == 0 || lines.at(0) != "@control")
112  qFatal("QBB: unrecognized pps object, data=%s", ppsData.constData());
113 
114  // parse pps object attributes and extract values
115  for (int i = 1; i < lines.size(); i++) {
116 
117  // tokenize current attribute
118  const QByteArray &attr = lines.at(i);
119 
120 #if defined(QBBNAVIGATOREVENTNOTIFIER_DEBUG)
121  qDebug() << "PPS: attr=" << attr;
122 #endif
123 
124  int firstColon = attr.indexOf(':');
125  if (firstColon == -1) {
126  // abort - malformed attribute
127  continue;
128  }
129 
130  int secondColon = attr.indexOf(':', firstColon + 1);
131  if (secondColon == -1) {
132  // abort - malformed attribute
133  continue;
134  }
135 
136  QByteArray key = attr.left(firstColon);
137  QByteArray value = attr.mid(secondColon + 1);
138 
139 #if defined(QBBNAVIGATOREVENTNOTIFIER_DEBUG)
140  qDebug() << "PPS: key=" << key;
141  qDebug() << "PPS: val=" << value;
142 #endif
143 
144  // save attribute value
145  if (key == "msg")
146  msg = value;
147  else if (key == "dat")
148  dat = value;
149  else if (key == "id")
150  id = value;
151  else
152  qFatal("QBB: unrecognized pps attribute, attr=%s", key.constData());
153  }
154 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Q_CORE_EXPORT void qDebug(const char *,...)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
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...
Q_CORE_EXPORT void qFatal(const char *,...)
int key
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ readData

void QBBNavigatorEventNotifier::readData ( )
privateslot

Definition at line 204 of file qbbnavigatoreventnotifier.cpp.

Referenced by start().

205 {
206 #if defined(QBBNAVIGATOREVENTNOTIFIER_DEBUG)
207  qDebug() << "QBB: reading navigator data";
208 #endif
209 
210  // allocate buffer for pps data
211  char buffer[PPS_BUFFER_SIZE];
212 
213  // attempt to read pps data
214  errno = 0;
215  int bytes = qt_safe_read(mFd, buffer, PPS_BUFFER_SIZE - 1);
216  if (bytes == -1)
217  qFatal("QBB: failed to read navigator pps, errno=%d", errno);
218 
219  // check if pps data was received
220  if (bytes > 0) {
221 
222  // ensure data is null terminated
223  buffer[bytes] = '\0';
224 
225  // process received message
226  QByteArray ppsData(buffer);
227  QByteArray msg;
228  QByteArray dat;
229  QByteArray id;
230  parsePPS(ppsData, msg, dat, id);
231  handleMessage(msg, dat, id);
232  }
233 
234 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void parsePPS(const QByteArray &ppsData, QByteArray &msg, QByteArray &dat, QByteArray &id)
Q_CORE_EXPORT void qDebug(const char *,...)
#define PPS_BUFFER_SIZE
Q_CORE_EXPORT void qFatal(const char *,...)
void handleMessage(const QByteArray &msg, const QByteArray &dat, const QByteArray &id)
static qint64 qt_safe_read(int fd, void *data, qint64 maxlen)
Definition: qcore_unix_p.h:273
int errno

◆ replyPPS()

void QBBNavigatorEventNotifier::replyPPS ( const QByteArray res,
const QByteArray id,
const QByteArray dat 
)
private

Definition at line 156 of file qbbnavigatoreventnotifier.cpp.

Referenced by handleMessage().

157 {
158  // construct pps message
159  QByteArray ppsData = "res::";
160  ppsData += res;
161  ppsData += "\nid::";
162  ppsData += id;
163  if (!dat.isEmpty()) {
164  ppsData += "\ndat::";
165  ppsData += dat;
166  }
167  ppsData += "\n";
168 
169 #if defined(QBBNAVIGATOREVENTNOTIFIER_DEBUG)
170  qDebug() << "PPS reply=" << ppsData;
171 #endif
172 
173  // send pps message to navigator
174  errno = 0;
175  int bytes = write(mFd, ppsData.constData(), ppsData.size());
176  if (bytes == -1)
177  qFatal("QBB: failed to write navigator pps, errno=%d", errno);
178 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Q_CORE_EXPORT void qDebug(const char *,...)
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
Q_CORE_EXPORT void qFatal(const char *,...)
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
int errno

◆ start

void QBBNavigatorEventNotifier::start ( )
slot

Definition at line 83 of file qbbnavigatoreventnotifier.cpp.

84 {
85 #if defined(QBBNAVIGATOREVENTNOTIFIER_DEBUG)
86  qDebug() << "QBB: navigator event notifier started";
87 #endif
88 
89  // open connection to navigator
90  errno = 0;
92  if (mFd == -1) {
93  qWarning("QBB: failed to open navigator pps, errno=%d", errno);
94  return;
95  }
96 
98  connect(mReadNotifier, SIGNAL(activated(int)), this, SLOT(readData()));
99 }
#define SLOT(a)
Definition: qobjectdefs.h:226
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
Q_CORE_EXPORT void qDebug(const char *,...)
#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 O_RDWR
#define NAV_CONTROL_PATH
int errno

Properties

◆ mEventHandler

QBBNavigatorEventHandler* QBBNavigatorEventNotifier::mEventHandler
private

Definition at line 66 of file qbbnavigatoreventnotifier.h.

Referenced by handleMessage().

◆ mFd

int QBBNavigatorEventNotifier::mFd
private

Definition at line 67 of file qbbnavigatoreventnotifier.h.

Referenced by readData(), replyPPS(), start(), and ~QBBNavigatorEventNotifier().

◆ mReadNotifier

QSocketNotifier* QBBNavigatorEventNotifier::mReadNotifier
private

Definition at line 68 of file qbbnavigatoreventnotifier.h.

Referenced by start(), and ~QBBNavigatorEventNotifier().


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