Qt 4.8
qbblocalethread.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 - 2012 Research In Motion <blackberry-qt@qnx.com>
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 //#define QBBLOCALETHREAD_DEBUG
43 
44 #ifdef QBBLOCALETHREAD_ENABLED
45 
46 #include "qbblocalethread.h"
47 
48 #include <QtGui/QApplication>
49 #include <QtGui/QWidget>
50 #include <QtGui/QWindowSystemInterface>
51 #include <QByteArray>
52 #include <QList>
53 #include <QDebug>
54 
55 #include <errno.h>
56 #include <fcntl.h>
57 #include <unistd.h>
58 #include <sys/types.h>
59 #include <sys/stat.h>
60 
61 #define NAV_CONTROL_PATH "/pps/services/confstr/_CS_LOCALE"
62 #define PPS_BUFFER_SIZE 4096
63 
64 QBBLocaleThread::QBBLocaleThread()
65  : mFd(-1),
66  mQuit(false)
67 {
68 }
69 
70 QBBLocaleThread::~QBBLocaleThread()
71 {
72  // block until thread terminates
73  shutdown();
74 }
75 
77 {
78 #if defined(QBBLOCALETHREAD_DEBUG)
79  qDebug() << "QBB: Locale thread started";
80 #endif
81 
82  // open connection to Locale
83  errno = 0;
85  if (mFd == -1) {
86  qWarning("QBB: failed to open Locale pps, errno=%d", errno);
87  return;
88  }
89 
90  // allocate buffer for pps data
91  char buffer[PPS_BUFFER_SIZE];
92 
93  // loop indefinitely
94  while (!mQuit) {
95 
96  // attempt to read pps data
97  errno = 0;
98  int bytes = read(mFd, buffer, PPS_BUFFER_SIZE - 1);
99  if (bytes == -1) {
100  qWarning("QBB: failed to read Locale pps, errno=%d", errno);
101  return;
102  }
103 
104  // check if pps data was received
105  if (bytes > 0) {
106  // Notify the world that the locale has changed.
108  }
109 
110  // yield
111  msleep(5);
112  }
113 
114  // close connection to Locale
115  close(mFd);
116 
117 #if defined(QBBLOCALETHREAD_DEBUG)
118  qDebug() << "QBB: Locale thread stopped";
119 #endif
120 }
121 
122 void QBBLocaleThread::shutdown()
123 {
124  // signal thread to terminate
125  mQuit = true;
126 
127 #if defined(QBBLOCALETHREAD_DEBUG)
128  qDebug() << "QBB: Locale thread shutdown begin";
129 #endif
130 
131  // block until thread terminates
132  wait();
133 
134 #if defined(QBBLOCALETHREAD_DEBUG)
135  qDebug() << "QBB: Locale thread shutdown end";
136 #endif
137 }
138 
139 #endif // QBBLOCALETHREAD_ENABLED
#define O_RDONLY
Q_CORE_EXPORT void qDebug(const char *,...)
#define PPS_BUFFER_SIZE
Q_CORE_EXPORT void qWarning(const char *,...)
QFuture< T > run(Function function,...)
int open(const char *, int,...)
#define NAV_CONTROL_PATH
int errno