58 using namespace COMMUNICATIONLIB;
75 QString t_sCommand = QString(
"%1\n").arg(p_sCommand);
78 if (this->state() == QAbstractSocket::ConnectedState)
80 this->write(t_sCommand.toUtf8().constData(), t_sCommand.size());
81 this->waitForBytesWritten();
84 this->waitForReadyRead(1000);
85 QByteArray t_qByteArrayRaw;
88 while (this->bytesAvailable() > 0 && this->canReadLine())
89 t_qByteArrayRaw += this->readAll();
91 p_sReply = QString(t_qByteArrayRaw);
100 const QString t_sCommand = QString(
"{\"commands\":{%1}}\n").arg(p_command.
toStringReadySend());
104 if (this->state() == QAbstractSocket::ConnectedState)
109 QDataStream out(&block, QIODevice::WriteOnly);
110 out.setVersion(QDataStream::Qt_5_1);
112 out << static_cast<quint16>(0);
114 out.device()->seek(0);
115 out << static_cast<quint16>(
static_cast<unsigned long>(block.size()) -
sizeof(quint16));
118 this->waitForBytesWritten();
121 QDataStream in(
this);
122 in.setVersion(QDataStream::Qt_5_1);
124 quint16 blockSize = 0;
126 bool respComplete =
false;
130 this->waitForReadyRead(100);
134 if (this->bytesAvailable() >= (
int)
sizeof(quint16))
137 else if(this->bytesAvailable() >= blockSize)
142 }
while (!respComplete && blockSize < 65000);
144 this->write(t_sCommand.toUtf8().constData(), t_sCommand.size());
145 this->waitForBytesWritten();
148 bool respComplete =
false;
149 QByteArray t_qByteArrayRaw;
152 if (this->waitForReadyRead(100))
154 t_qByteArrayRaw += this->readAll();
157 respComplete = t_qByteArrayRaw.count(
'{')
158 == t_qByteArrayRaw.count(
'}');
160 qDebug() <<
"Response: " << t_qByteArrayRaw.size() <<
" bytes";
161 }
while (!respComplete);
162 t_sReply = QString(t_qByteArrayRaw);
167 qWarning() <<
"Request was not send, because client is not connected!";
172 m_sAvailableData = t_sReply;
183 m_commandManager[
"getbufsize"].send();
187 QByteArray t_sJsonCommands = m_sAvailableData.toUtf8();
191 QJsonParseError error;
192 QJsonDocument t_jsonDocumentOrigin = QJsonDocument::fromJson(t_sJsonCommands, &error);
194 if (error.error == QJsonParseError::NoError)
199 if(t_jsonDocumentOrigin.isObject() && t_jsonDocumentOrigin.object().value(QString(
"bufsize")) != QJsonValue::Undefined)
201 qint32 size = (qint32)t_jsonDocumentOrigin.object().value(QString(
"bufsize")).toDouble();
206 qCritical() <<
"Unable to parse JSON response: " << error.errorString();
215 const QString help(
"help");
216 const QString description(
"");
217 const Command cmdHelp(help, description);
221 m_commandManager.
clear();
225 QByteArray t_sJsonCommands = m_sAvailableData.toUtf8();
229 QJsonParseError error;
230 QJsonDocument t_jsonDocumentOrigin = QJsonDocument::fromJson(
231 t_sJsonCommands, &error);
233 if (error.error == QJsonParseError::NoError)
234 m_commandManager.
insert(t_jsonDocumentOrigin);
236 qCritical() <<
"Unable to parse JSON response: " << error.errorString();
244 m_commandManager[
"conlist"].send();
248 QByteArray t_sJsonConnectors = m_sAvailableData.toUtf8();
252 QJsonParseError error;
253 QJsonDocument t_jsonDocumentOrigin = QJsonDocument::fromJson(
254 t_sJsonConnectors, &error);
256 QJsonObject t_jsonObjectConnectors;
259 if(t_jsonDocumentOrigin.isObject() && t_jsonDocumentOrigin.object().value(QString(
"connectors")) != QJsonValue::Undefined)
260 t_jsonObjectConnectors = t_jsonDocumentOrigin.object().value(QString(
"connectors")).toObject();
263 qint32 p_iActiveId = -1;
264 p_qMapConnectors.clear();
267 QJsonObject::Iterator it;
268 for(it = t_jsonObjectConnectors.begin(); it != t_jsonObjectConnectors.end(); ++it)
270 QString t_qConnectorName = it.key();
272 qint32
id = it.value().toObject().value(QString(
"id")).toDouble();
274 if(!p_qMapConnectors.contains(
id))
275 p_qMapConnectors.insert(
id, t_qConnectorName);
277 qWarning(
"Warning: CommandMap contains command %s already. Insertion skipped.\n", it.key().toUtf8().constData());
280 if(it.value().toObject().value(QString(
"active")).toBool())
331 if (m_sAvailableData.size() > 0)
334 qint64 t_msecsStart = QDateTime::currentMSecsSinceEpoch();
338 < QDateTime::currentMSecsSinceEpoch() - t_msecsStart)
341 if (m_sAvailableData.size() > 0)
351 return m_commandManager[key];
358 return m_commandManager[key];