Ejemplo n.º 1
0
	static void doAll() { doDebug(); doInfo(); doWarn(); doError(); }
Ejemplo n.º 2
0
//0:exit,1:continue
int CwxBinlogOp::doCommand(char* szCmd) {
  string strCmd;
  list < string > value;
  CwxCommon::trim(szCmd);
  strCmd = szCmd;
  CwxCommon::split(strCmd, value, ' ');
  list<string>::iterator iter = value.begin();
  //remove the empty value
  while (iter != value.end()) {
    if ((*iter).length() == 0) {
      value.erase(iter);
      iter = value.begin();
      continue;
    }
    iter++;
  }
  if (value.size() == 0)
    return 1;

  iter = value.begin();
  CWX_UINT32 uiItemNum = value.size();
  if (0 == strcasecmp((*iter).c_str(), "help")) {
    doHelp();
  } else if (0 == strcasecmp((*iter).c_str(), "info")) {
    doInfo();
  } else if (0 == strcasecmp((*iter).c_str(), "next")) {
    CWX_UINT32 uiNum = 1;
    if (1 != uiItemNum) {
      iter++;
      uiNum = strtoul((*iter).c_str(), NULL, 0);
    }
    doNext(uiNum);
  } else if (0 == strcasecmp((*iter).c_str(), "prev")) {
    CWX_UINT32 uiNum = 1;
    if (1 != uiItemNum) {
      iter++;
      uiNum = strtoul((*iter).c_str(), NULL, 0);
    }
    doPrev(uiNum);
  } else if (0 == strcasecmp((*iter).c_str(), "sid")) {
    if (2 != uiItemNum) {
      printf("Invalid sid command, using: sid value.\n");
      return 1;
    }
    iter++;
    doSid(strtoull((*iter).c_str(), NULL, 0));
  } else if (0 == strcasecmp((*iter).c_str(), "rec")) {
    if (2 != uiItemNum) {
      printf("Invalid rec command, using: rec value.\n");
      return 1;
    }
    iter++;
    doRecord(strtoul((*iter).c_str(), NULL, 0));
  } else if (0 == strcasecmp((*iter).c_str(), "group")) {
    if (2 != uiItemNum) {
      printf("Invalid group command, using: group value.\n");
      return 1;
    }
    iter++;
    doGroup(strtoul((*iter).c_str(), NULL, 0));
  } else if (0 == strcasecmp((*iter).c_str(), "key")) {
    if (3 != uiItemNum) {
      printf("Invalid key command, using: key k v.\n");
      return 1;
    }
    iter++;
    string strKey = *iter;
    doKey(strKey.c_str(), (*iter).c_str());
  } else if (0 == strcasecmp((*iter).c_str(), "head")) {
    doHead();
  } else if (0 == strcasecmp((*iter).c_str(), "data")) {
    doData();
  } else if (0 == strcasecmp((*iter).c_str(), "save")) {
    if (1 == uiItemNum) {
      printf("Invalid save command, using: save file.\n");
      return 1;
    }
    iter++;
    doSave(*iter);
  } else if (0 == strcasecmp((*iter).c_str(), "exit")) {
    return 0;
  } else {
    printf("Invalid command %s\n", (*iter).c_str());
    doHelp();
  }
  return 1;
}
Ejemplo n.º 3
0
void Router::onMessage(Connection *conn)
{
	Buffer *pBuffer = conn->getBuffer();
	while(true)
	{
		if(pBuffer->size() < ROUTER_HEAD_SIZE){
			return ;
		}
		
		RouterMsg msg = unpackMsg(pBuffer->data());
		if(pBuffer->size() < ROUTER_HEAD_SIZE + msg.slen + msg.len){
			return ;
		}
		
		RouterMsg *pMsg = (RouterMsg*)pBuffer->data();
		pMsg->type = msg.type;
		pMsg->slen = msg.slen;
		pMsg->len = msg.len;
		LOG("on data, type=%d, slen=%d, len=%d", pMsg->type, pMsg->slen, pMsg->len);
		
		switch(pMsg->type){
			case ROUTER_MSG_AUTH:
				doAuth(conn, pMsg);
				break;
			case ROUTER_MSG_CONN:
				doConn(conn, pMsg);
				break;
			case ROUTER_MSG_CLOSE:
				doClose(conn, pMsg);
				break;
			case ROUTER_MSG_KICK:
				doKick(conn, pMsg);
				break;
			case ROUTER_MSG_SEND_MSG:
				doSendMsg(conn, pMsg);
				break;
			case ROUTER_MSG_SEND_ALL:
				doSendAllMsg(conn, pMsg);
				break;
			case ROUTER_MSG_CH_ADD:
				doChannelAdd(conn, pMsg);
				break;
			case ROUTER_MSG_CH_DEL:
				doChannelDel(conn, pMsg);
				break;
			case ROUTER_MSG_CH_PUB:
				doChannelPub(conn, pMsg);
				break;
			case ROUTER_MSG_CH_SUB:
				doChannelSub(conn, pMsg);
				break;
			case ROUTER_MSG_CH_UNSUB:
				doChannelUnSub(conn, pMsg);
				break;
			case ROUTER_MSG_INFO:
				doInfo(conn, pMsg);
				break;
			default:
				LOG("[router]error type");
				break;
		}
		
		pBuffer->seek(ROUTER_HEAD_SIZE + pMsg->slen + pMsg->len);
	}
}