• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ cmdRequest函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中cmdRequest函数的典型用法代码示例。如果您正苦于以下问题:C++ cmdRequest函数的具体用法?C++ cmdRequest怎么用?C++ cmdRequest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了cmdRequest函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: RPCExecutor

void RPCConsole::startExecutor()
{
    QThread* thread = new QThread;
    RPCExecutor *executor = new RPCExecutor();
    executor->moveToThread(thread);

    // Notify executor when thread started (in executor thread)
    connect(thread, SIGNAL(started()), executor, SLOT(start()));
    // Replies from executor object must go to this object
    connect(executor, SIGNAL(reply(int,QString)), this, SLOT(message(int,QString)));
    // Requests from this object must go to executor
    connect(this, SIGNAL(cmdRequest(QString)), executor, SLOT(request(QString)));
    // On stopExecutor signal
    // - queue executor for deletion (in execution thread)
    // - quit the Qt event loop in the execution thread
    connect(this, SIGNAL(stopExecutor()), executor, SLOT(deleteLater()));
    connect(this, SIGNAL(stopExecutor()), thread, SLOT(quit()));
    // Queue the thread for deletion (in this thread) when it is finished
    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));

    // Default implementation of QThread::run() simply spins up an event loop in the thread,
    // which is what we want.
    thread->start();
}
开发者ID:Putin-Coin,项目名称:putincoin,代码行数:24,代码来源:rpcconsole.cpp


示例2: MQTTCMD_Setup

void ICACHE_FLASH_ATTR
MQTTCMD_Setup(CmdPacket *cmd) {
  CmdRequest req;
  cmdRequest(&req, cmd);

  MQTT_Client* client = &mqttClient;

  if (cmdGetArgc(&req) != 4) return;

#if 0
// This section is commented-out because we're using the same client as esp-link is using itself,
// i.e. the one set-up in the Web UI. This code was here when we used a separate client for the
// attached uC, which just makes life more complicated...

  if (cmdGetArgc(&req) != 9)
    return 0;

  // create mqtt client
  uint8_t clientLen = sizeof(MQTT_Client);
  MQTT_Client* client = (MQTT_Client*)os_zalloc(clientLen);
  if (client == NULL) return 0;
  os_memset(client, 0, clientLen);

  uint16_t len;
  uint8_t *client_id, *user_data, *pass_data;
  uint32_t keepalive, clean_session;

  // get client id
  len = cmdArgLen(&req);
  if (len > 32) return 0; // safety check
  client_id = (uint8_t*)os_zalloc(len + 1);
  cmdPopArg(&req, client_id, len);
  client_id[len] = 0;

  // get username
  len = cmdArgLen(&req);
  if (len > 32) return 0; // safety check
  user_data = (uint8_t*)os_zalloc(len + 1);
  cmdPopArg(&req, user_data, len);
  user_data[len] = 0;

  // get password
  len = cmdArgLen(&req);
  if (len > 32) return 0; // safety check
  pass_data = (uint8_t*)os_zalloc(len + 1);
  cmdPopArg(&req, pass_data, len);
  pass_data[len] = 0;

  // get keepalive
  cmdPopArg(&req, (uint8_t*)&keepalive, 4);

  // get clean session
  cmdPopArg(&req, (uint8_t*)&clean_session, 4);
#ifdef MQTTCMD_DBG
  DBG("MQTT: MQTTCMD_Setup clientid=%s, user=%s, pw=%s, keepalive=%ld, clean_session=%ld\n", client_id, user_data, pass_data, keepalive, clean_session);
#endif

  // init client
  // TODO: why malloc these all here, pass to MQTT_InitClient to be malloc'd again?
  MQTT_InitClient(client, (char*)client_id, (char*)user_data, (char*)pass_data, keepalive, clean_session);

  os_free(client_id);
  os_free(user_data);
  os_free(pass_data);
#endif

  // create callback
  MqttCmdCb* callback = (MqttCmdCb*)os_zalloc(sizeof(MqttCmdCb));
  cmdPopArg(&req, &callback->connectedCb, 4);
  cmdPopArg(&req, &callback->disconnectedCb, 4);
  cmdPopArg(&req, &callback->publishedCb, 4);
  cmdPopArg(&req, &callback->dataCb, 4);
  client->user_data = callback;

  DBG("MQTT connectedCb=%x\n", callback->connectedCb);

  client->cmdConnectedCb = cmdMqttConnectedCb;
  client->cmdDisconnectedCb = cmdMqttDisconnectedCb;
  client->cmdPublishedCb = cmdMqttPublishedCb;
  client->cmdDataCb = cmdMqttDataCb;

  if (client->connState == MQTT_CONNECTED) {
    if (callback->connectedCb)
      cmdMqttConnectedCb(client);
  } else if (callback->disconnectedCb) {
    cmdMqttDisconnectedCb(client);
  }
}
开发者ID:InSoonPark,项目名称:esp-link,代码行数:88,代码来源:mqtt_cmd.c


示例3: message

void ConsolePage::on_lineEdit_returnPressed()
{
    QString cmd = ui->lineEdit->text();
    ui->lineEdit->clear();

    if(!cmd.isEmpty())
    {
        if(cmd.toStdString() == "clear")
    {
        message(CMD_REQUEST, cmd);
        clear();
        // Remove command, if already in history
            history.removeOne(cmd);
            // Append command to history
            history.append(cmd);
            // Enforce maximum history size
            while(history.size() > CONSOLE_HISTORY)
                history.removeFirst();
            // Set pointer to end of history
            historyPtr = history.size();
            // Scroll console view to end
            scrollToEnd();
    }
    else if(cmd.toStdString() == "markethistory")
    {
        message(CMD_REQUEST, cmd);
        dumpmarkethistory();
        // Remove command, if already in history
            history.removeOne(cmd);
            // Append command to history
            history.append(cmd);
            // Enforce maximum history size
            while(history.size() > CONSOLE_HISTORY)
                history.removeFirst();
            // Set pointer to end of history
            historyPtr = history.size();
            // Scroll console view to end
            scrollToEnd();
    }
    else if(cmd.toStdString() == "marketdata")
    {
        message(CMD_REQUEST, cmd);
        marketdata();
        // Remove command, if already in history
            history.removeOne(cmd);
            // Append command to history
            history.append(cmd);
            // Enforce maximum history size
            while(history.size() > CONSOLE_HISTORY)
                history.removeFirst();
            // Set pointer to end of history
            historyPtr = history.size();
            // Scroll console view to end
            scrollToEnd();
    }
    else
    {
            message(CMD_REQUEST, cmd);
            emit cmdRequest(cmd);
            // Remove command, if already in history
            history.removeOne(cmd);
            // Append command to history
            history.append(cmd);
            // Enforce maximum history size
            while(history.size() > CONSOLE_HISTORY)
                history.removeFirst();
            // Set pointer to end of history
            historyPtr = history.size();
            // Scroll console view to end
            scrollToEnd();
    }
    }
}
开发者ID:BluntCoin,项目名称:bluntcoin,代码行数:73,代码来源:consolepage.cpp


示例4: REST_Request

void ICACHE_FLASH_ATTR
REST_Request(CmdPacket *cmd) {
  CmdRequest req;
  cmdRequest(&req, cmd);
  DBG("REST: request");
  if (cmd->argc != 2 && cmd->argc != 3) return;

  // Get client
  uint32_t clientNum = cmd->value;
  RestClient *client = restClient + (clientNum % MAX_REST);
  DBG(" #%ld", clientNum);

  // Get HTTP method
  uint16_t len = cmdArgLen(&req);
  if (len > 15) goto fail;
  char method[16];
  cmdPopArg(&req, method, len);
  method[len] = 0;
  DBG(" method=%s", method);

  // Get HTTP path
  len = cmdArgLen(&req);
  if (len > 1023) goto fail;
  char path[1024];
  cmdPopArg(&req, path, len);
  path[len] = 0;
  DBG(" path=%s", path);

  // Get HTTP body
  uint32_t realLen = 0;
  if (cmdGetArgc(&req) == 2) {
    realLen = 0;
  } else {
    realLen = cmdArgLen(&req);
    if (realLen > 2048) goto fail;
  }
  DBG(" bodyLen=%ld", realLen);

  // we need to allocate memory for the header plus the body. First we count the length of the
  // header (including some extra counted "%s" and then we add the body length. We allocate the
  // whole shebang and copy everything into it.
  // BTW, use http/1.0 to avoid responses with transfer-encoding: chunked
  char *headerFmt = "%s %s HTTP/1.0\r\n"
                    "Host: %s\r\n"
                    "%s"
                    "Content-Length: %d\r\n"
                    "Connection: close\r\n"
                    "Content-Type: %s\r\n"
                    "User-Agent: %s\r\n\r\n";
  uint16_t headerLen = strlen(headerFmt) + strlen(method) + strlen(path) + strlen(client->host) +
      strlen(client->header) + strlen(client->content_type) + strlen(client->user_agent);
  DBG(" hdrLen=%d", headerLen);
  if (client->data) os_free(client->data);
  client->data = (char*)os_zalloc(headerLen + realLen);
  if (client->data == NULL) goto fail;
  DBG(" totLen=%ld data=%p", headerLen + realLen, client->data);
  client->data_len = os_sprintf((char*)client->data, headerFmt, method, path, client->host,
      client->header, realLen, client->content_type, client->user_agent);
  DBG(" hdrLen=%d", client->data_len);

  if (realLen > 0) {
    cmdPopArg(&req, client->data + client->data_len, realLen);
    client->data_len += realLen;
  }
  DBG("\n");

  //DBG("REST request: %s", (char*)client->data);

  //DBG("REST: pCon state=%d\n", client->pCon->state);
  client->pCon->state = ESPCONN_NONE;
  espconn_regist_connectcb(client->pCon, tcpclient_connect_cb);
  espconn_regist_reconcb(client->pCon, tcpclient_recon_cb);

  if(UTILS_StrToIP((char *)client->host, &client->pCon->proto.tcp->remote_ip)) {
    DBG("REST: Connect to ip %s:%ld\n",client->host, client->port);
    //if(client->security){
    //  espconn_secure_connect(client->pCon);
    //}
    //else {
      espconn_connect(client->pCon);
    //}
  } else {
    DBG("REST: Connect to host %s:%ld\n", client->host, client->port);
    espconn_gethostbyname(client->pCon, (char *)client->host, &client->ip, rest_dns_found);
  }

  return;

fail:
  DBG("\n");
}
开发者ID:susisstrolch,项目名称:ems-esp-link,代码行数:91,代码来源:rest.c


示例5: REST_Setup

void ICACHE_FLASH_ATTR
REST_Setup(CmdPacket *cmd) {
  CmdRequest req;
  uint32_t port, security;
  int32_t err = -1; // error code in case of failure

  // start parsing the command
  cmdRequest(&req, cmd);
  if(cmdGetArgc(&req) != 3) goto fail;
  err--;

  // get the hostname
  uint16_t len = cmdArgLen(&req);
  if (len > 128) goto fail; // safety check
  err--;
  uint8_t *rest_host = (uint8_t*)os_zalloc(len + 1);
  if (cmdPopArg(&req, rest_host, len)) goto fail;
  err--;
  rest_host[len] = 0;

  // get the port
  if (cmdPopArg(&req, (uint8_t*)&port, 2)) {
    os_free(rest_host);
    goto fail;
  }
  err--;

  // get the security mode
  if (cmdPopArg(&req, (uint8_t*)&security, 1)) {
    os_free(rest_host);
    goto fail;
  }
  err--;

  // clear connection structures the first time
  if (restNum == 0xff) {
    os_memset(restClient, 0, MAX_REST * sizeof(RestClient));
    restNum = 0;
  }

  // allocate a connection structure
  RestClient *client = restClient + restNum;
  uint8_t clientNum = restNum;
  restNum = (restNum+1)%MAX_REST;

  // free any data structure that may be left from a previous connection
  if (client->header) os_free(client->header);
  if (client->content_type) os_free(client->content_type);
  if (client->user_agent) os_free(client->user_agent);
  if (client->data) os_free(client->data);
  if (client->pCon) {
    if (client->pCon->proto.tcp) os_free(client->pCon->proto.tcp);
    os_free(client->pCon);
  }
  os_memset(client, 0, sizeof(RestClient));
  DBG("REST: setup #%d host=%s port=%ld security=%ld\n", clientNum, rest_host, port, security);

  client->resp_cb = cmd->value;

  client->host = (char *)rest_host;
  client->port = port;
  client->security = security;

  client->header = (char*)os_zalloc(4);
  client->header[0] = 0;

  client->content_type = (char*)os_zalloc(22);
  os_sprintf((char *)client->content_type, "x-www-form-urlencoded");

  client->user_agent = (char*)os_zalloc(9);
  os_sprintf((char *)client->user_agent, "esp-link");

  client->pCon = (struct espconn *)os_zalloc(sizeof(struct espconn));
  client->pCon->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));

  client->pCon->type = ESPCONN_TCP;
  client->pCon->state = ESPCONN_NONE;
  client->pCon->proto.tcp->local_port = espconn_port();
  client->pCon->proto.tcp->remote_port = client->port;

  client->pCon->reverse = client;

  cmdResponseStart(CMD_RESP_V, clientNum, 0);
  cmdResponseEnd();
  return;

fail:
  cmdResponseStart(CMD_RESP_V, err, 0);
  cmdResponseEnd();
  return;
}
开发者ID:susisstrolch,项目名称:ems-esp-link,代码行数:91,代码来源:rest.c


示例6: SetCloseAndDelete


//.........这里部分代码省略.........
					SetCloseAndDelete();
				}
			}
			break;
		case STATE_GET_INTEGERS:
			if (l < 4)
			{static_cast<PeerHandler&>(Handler()).SetNotPaused();return;}
			uint32_t ll;
			ibuf.Read( (char *)&ll, 4);
			m_int[m_ptr++] = ntohl(ll);
			if (m_ptr >= m_integers)
			{
				switch (m_cmd)
				{
				case 4:
					if (m_int[0] < sess -> GetNumberOfPieces())
					{
						cmdHave(m_int[0]);
						m_state = STATE_COMMAND;
					}
					else
					{
					
						SetCloseAndDelete();
					}
					break;
				case 6:
					if (m_int[0] < sess -> GetNumberOfPieces() &&
						m_int[1] < sess -> GetPieceLength() &&
						m_int[2] < 131072 &&
						m_int[1] + m_int[2] <= sess -> GetPieceLength() &&
						m_int[2] > 0)
					{
						cmdRequest(m_int[0], m_int[1], m_int[2]);
						m_state = STATE_COMMAND;
					}
					else
					{
					
						SetCloseAndDelete();
					}
					break;
				case 7:
					m_ptr = 0;
					m_state = STATE_GET_PIECE;
					break;
				case 8:
					if (m_int[0] < sess -> GetNumberOfPieces() &&
						m_int[1] < sess -> GetPieceLength() &&
						m_int[2] < 131072 &&
						m_int[1] + m_int[2] <= sess -> GetPieceLength() &&
						m_int[2] > 0)
					{
						cmdCancel(m_int[0], m_int[1], m_int[2]);
						m_state = STATE_COMMAND;
					}
					else
					{
						if(ACTIVATE_LOG)
							this->pSocket_log->add_line(string("cmdCancel Error."),true);
						bRecoverFromError=true;
						SetCloseAndDelete();
					}
					break;
				}
			}
开发者ID:amirkrifa,项目名称:BitHoc,代码行数:67,代码来源:pSocket.cpp



注:本文中的cmdRequest函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ cmd_account函数代码示例发布时间:2022-05-30
下一篇:
C++ cmdQueue_SendCommand函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap