Exemple #1
0
bool Client::connectToServer(const QString &serverName)
{
  if (!m_jsonRpcClient) {
    m_jsonRpcClient = new JsonRpcClient(this);
    connect(m_jsonRpcClient, SIGNAL(resultReceived(QJsonObject)),
            SLOT(processResult(QJsonObject)));
    connect(m_jsonRpcClient, SIGNAL(notificationReceived(QJsonObject)),
            SLOT(processNotification(QJsonObject)));
    connect(m_jsonRpcClient, SIGNAL(errorReceived(QJsonObject)),
            SLOT(processError(QJsonObject)));
    connect(m_jsonRpcClient, SIGNAL(connectionStateChanged()),
            SIGNAL(connectionStateChanged()));
  }

  return m_jsonRpcClient->connectToServer(serverName);
}
 void CMessageBrokerController::onMessageReceived(Json::Value message)
 {
    // Determine message type and process...
    Json::Value error;
    if (checkMessage(message, error))
    {
       if (isNotification(message))
       {
          DBG_MSG(("Message is notification!\n"));
          processNotification(message);
       } else if (isResponse(message))
       {
          std::string id = message["id"].asString();
          std::string method = findMethodById(id);
          DBG_MSG(("Message is response on: %s\n", method.c_str()));
          if ("" != method)
          {
             if ("MB.registerComponent" == method)
             { // initialize mControllersIdStart
                if (message.isMember("result") && message["result"].isInt())
                {
                   mControllersIdStart = message["result"].asInt();
                } else
                {
                   DBG_MSG_ERROR(("Not possible to initialize mControllersIdStart!\n"));
                }
             } else if ("MB.subscribeTo" == method || "MB.unregisterComponent" == method || "MB.unsubscribeFrom" == method)
             {
                //nothing to do for now
             } else
             {
                processResponse(method, message);
             }
          } else
          {
             DBG_MSG_ERROR(("Request with id %s has not been found!\n", id.c_str()));
          }
       } else
       {
          DBG_MSG(("Message is request!\n"));
          processRequest(message);
       }
    } else
    {
       DBG_MSG_ERROR(("Message contains wrong data!\n"));
    }
 }
void StratumClient::processData(const QJsonObject& _jsonObject) {
  if (!_jsonObject.contains(JSON_RPC_TAG_NAME_ID)) {
    processNotification(_jsonObject);
    return;
  } else {
    quint64 id = _jsonObject.value(JSON_RPC_TAG_NAME_ID).toString().toULongLong();
    if (!m_activeRequestMap.contains(id)) {
      qDebug() << "Unknown responce with id = " << id;
      return;
    }

    JsonRpcRequest request = m_activeRequestMap.take(id);
    if (request.method == STRATUM_METHOD_NAME_LOGIN) {
      processLoginResponce(_jsonObject, request);
    }
  }
}
void CoapNetworkAccessManager::processResponse(const CoapPdu &pdu, const QHostAddress &address, const quint16 &port)
{
    CoapTarget *target = findTarget(address);
    if (!target) {
        qCDebug(dcCoap) << "Got message without request or registered observe resource from" << address << endl << "<---" << pdu;
//        CoapPdu responsePdu;
//        responsePdu.setMessageType(CoapPdu::Reset);
//        responsePdu.setMessageId(pdu.messageId());
//        responsePdu.setToken(pdu.token());
//        qCDebug(dcCoap) << "--->" << responsePdu;
//        sendCoapPdu(address, port, responsePdu);
        return;
    }

    // Check if this is the current reply for this target
    if (target->currentReply()) {
        CoapReply *reply = target->currentReply();
        qCDebug(dcCoap) << "<---" << address << pdu;

        // Check if PDU is valid
        if (!pdu.isValid()) {
            qCWarning(dcCoap) << "Received invalid PDU.";
            reply->setError(CoapReply::InvalidPduError);
            reply->setFinished();
            return;
        }

        // Check if the message is a response to a reply (message id based check)
        if (reply->messageId() == pdu.messageId()) {
            processIdBasedResponse(target, reply, pdu);
            return;
        }

        // Check if this is a disable notifications Response
        if (reply->observation() && !reply->observationEnable()) {
            reply->setMessageType(pdu.messageType());
            reply->setStatusCode(pdu.statusCode());
            reply->setContentType(pdu.contentType());
            reply->appendPayloadData(pdu.payload());
            reply->setFinished();
            return;
        }
    }

    // Check if we know the message by token (async response)
    if (target->hasAsyncReply(pdu.token())) {
        qCDebug(dcCoap) << "<---" << address << pdu;

        CoapReply *reply = target->asyncReply(pdu.token());
        // Separate Response received
        CoapPdu responsePdu;
        responsePdu.setMessageType(CoapPdu::Acknowledgement);
        responsePdu.setStatusCode(CoapPdu::Empty);
        responsePdu.setMessageId(pdu.messageId());
        qCDebug(dcCoap) << "--->" << reply->hostAddress() << responsePdu;
        sendCoapPdu(reply->hostAddress(), reply->port(), responsePdu);

        reply->setStatusCode(pdu.statusCode());
        reply->setContentType(pdu.contentType());
        reply->appendPayloadData(pdu.payload());
        reply->setFinished();
        return;
    }

    // Check if this is a blocked notification reply
    if (target->hasRunningObservationReply()) {
        processBlock2Notification(target, pdu);
        return;
    }

    // check if this is a notification
    if (target->hasObservationResource(pdu.token())) {
        processNotification(target, pdu, address, port);
        return;
    }

}
 CommEventNotifier(DWORD mask, SerialPortPrivate *d, QObject *parent)
     : QThread(parent), dptr(d), running(true) {
     connect(this, SIGNAL(eventMask(quint32)), this, SLOT(processNotification(quint32)));
     ::SetCommMask(dptr->descriptor, mask);
 }