Qt 4.8
qmlostplugin.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative 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 #include "qmlostplugin.h"
43 #include "qostdevice.h"
44 
45 #include <private/qdeclarativedebugserver_p.h>
46 #include <private/qpacketprotocol_p.h>
47 
49 
50 static const TInt KQmlOstProtocolId = 0x94;
51 
53 public:
55 
59 };
60 
62  ost(0),
63  protocol(0),
64  debugServer(0)
65 {
66 }
67 
69  d_ptr(new QmlOstPluginPrivate)
70 {
71 }
72 
74 {
75  delete d_ptr;
76 }
77 
79 {
81  d->debugServer = server;
82 }
83 
85 {
86  Q_D(const QmlOstPlugin);
87  return d->ost && d->ost->isOpen();
88 }
89 
90 void QmlOstPlugin::send(const QByteArray &message)
91 {
93 
94  if (!isConnected())
95  return;
96 
97  QPacket pack;
98  pack.writeRawData(message.data(), message.length());
99 
100  d->protocol->send(pack);
101  //d->socket->flush();
102 }
103 
105 {
106  Q_D(QmlOstPlugin);
107 
108  delete d->protocol;
109  d->protocol = 0;
110 }
111 
113 {
114  Q_D(QmlOstPlugin);
115  return d->protocol->waitForReadyRead(-1);
116 }
117 
118 void QmlOstPlugin::setPort(int port, bool block)
119 {
120  Q_UNUSED(port);
121  Q_UNUSED(block);
122 
123  Q_D(QmlOstPlugin);
124 
125  d->ost = new QOstDevice(this);
126  bool ok = d->ost->open(KQmlOstProtocolId);
127  if (!ok) {
128  if (d->ost->errorString().length())
129  qDebug("Error from QOstDevice: %s", qPrintable(d->ost->errorString()));
130  qWarning("QDeclarativeDebugServer: Unable to listen on OST"); // This message is part of the signalling - do not change the format!
131  return;
132  }
133  d->protocol = new QPacketProtocol(d->ost, this);
134  QObject::connect(d->protocol, SIGNAL(readyRead()), this, SLOT(readyRead()));
135  qWarning("QDeclarativeDebugServer: Waiting for connection via OST"); // This message is part of the signalling - do not change the format!
136 }
137 
139 {
140  Q_D(QmlOstPlugin);
141  QPacket packet = d->protocol->read();
142 
143  QByteArray content = packet.data();
144  d->debugServer->receiveMessage(content);
145 }
146 
147 Q_EXPORT_PLUGIN2(qmlostplugin, QmlOstPlugin)
148 
double d
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static const TInt KQmlOstProtocolId
QPacketProtocol * protocol
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void setPort(int port, bool bock)
#define SLOT(a)
Definition: qobjectdefs.h:226
The QPacketProtocol class encapsulates communicating discrete packets across fragmented IO channels...
bool waitForMessage()
#define Q_D(Class)
Definition: qglobal.h:2482
The QPacket class encapsulates an unfragmentable packet of data to be transmitted by QPacketProtocol...
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
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 *,...)
QByteArray data() const
Returns raw packet data.
QDeclarativeDebugServer * debugServer
void setServer(QDeclarativeDebugServer *server)
bool isConnected() const
int length() const
Same as size().
Definition: qbytearray.h:356
static QAuServer & server()
Definition: qsound.cpp:79
QmlOstPluginPrivate * d_ptr
Definition: qmlostplugin.h:77
void send(const QByteArray &message)
#define qPrintable(string)
Definition: qglobal.h:1750
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
int writeRawData(const char *, int len)
Writes len bytes from s to the stream.
#define Q_EXPORT_PLUGIN2(PLUGIN, PLUGINCLASS)
Definition: qplugin.h:136