Lines Matching refs:hChannel
51 HChannel hChannel = nullptr; in AcceptClient() local
52 uint32_t uid = thisClass->MallocChannel(&hChannel); in AcceptClient()
53 if (!hChannel) { in AcceptClient()
56 if (uv_accept(server, (uv_stream_t *)&hChannel->hWorkTCP) < 0) { in AcceptClient()
63 uv_recv_buffer_size((uv_handle_t *)&hChannel->hWorkTCP, &bufMaxSize); in AcceptClient()
75 uv_read_start((uv_stream_t *)&hChannel->hWorkTCP, funcChannelHeaderAlloc, ReadStream); in AcceptClient()
79 handShake.channelId = htonl(hChannel->channelId); in AcceptClient()
87 thisClass->Send(hChannel->channelId, (uint8_t *)&handShake, sizeof(struct ChannelHandShake)); in AcceptClient()
90 thisClass->Send(hChannel->channelId, reinterpret_cast<uint8_t *>(&handShake), in AcceptClient()
163 void HdcServerForClient::EchoClient(HChannel hChannel, MessageLevel level, const char *msg, ...) in EchoClient() argument
183 …SendChannel(hChannel, const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(log.c_str())), log.s… in EchoClient()
186 void HdcServerForClient::EchoClientRaw(const HChannel hChannel, uint8_t *payload, const int payload… in EchoClientRaw() argument
188 SendChannel(hChannel, payload, payloadSize); in EchoClientRaw()
192 void HdcServerForClient::SendCommandToClient(const HChannel hChannel, const uint16_t commandFlag, in SendCommandToClient() argument
195 SendChannelWithCmd(hChannel, commandFlag, payload, payloadSize); in SendCommandToClient()
198 bool HdcServerForClient::SendToDaemon(HChannel hChannel, const uint16_t commandFlag, uint8_t *bufPt… in SendToDaemon() argument
204 ptrServer->AdminDaemonMap(OP_QUERY, hChannel->connectKey, hdi); in SendToDaemon()
214 …if (ptrServer->Send(hdi->hSession->sessionId, hChannel->channelId, commandFlag, bufPtr, bufSize) <… in SendToDaemon()
223 void HdcServerForClient::OrderFindTargets(HChannel hChannel) in OrderFindTargets() argument
226 …EchoClient(hChannel, MSG_INFO, "Please add HDC server's firewall ruler to allow udp incoming, udpp… in OrderFindTargets()
243 EchoClient(hChannel, MSG_INFO, "Broadcast find daemon, total:%d", count); in OrderFindTargets()
253 HChannel hChannel = (HChannel)req->data; in OrderConnecTargetResult() local
254 HdcServerForClient *thisClass = (HdcServerForClient *)hChannel->clsChannel; in OrderConnecTargetResult()
260 string target = std::string(hChannel->bufStd + 2); in OrderConnecTargetResult()
272 if (hChannel->isCheck) { in OrderConnecTargetResult()
273 … WRITE_LOG(LOG_INFO, "%s check device success and remove %s", __FUNCTION__, hChannel->key.c_str()); in OrderConnecTargetResult()
274 thisClass->CommandRemoveSession(hChannel, hChannel->key.c_str()); in OrderConnecTargetResult()
275 thisClass->EchoClient(hChannel, MSG_OK, const_cast<char *>(hdi->version.c_str())); in OrderConnecTargetResult()
278 thisClass->EchoClient(hChannel, MSG_OK, const_cast<char *>(sRet.c_str())); in OrderConnecTargetResult()
282 uint16_t *bRetryCount = reinterpret_cast<uint16_t *>(hChannel->bufStd); in OrderConnecTargetResult()
285 (hChannel->connectLocalDevice && *bRetryCount > MAX_CONNECT_DEVICE_RETRY_COUNT)) { in OrderConnecTargetResult()
289 thisClass->EchoClient(hChannel, MSG_FAIL, const_cast<char *>(sRet.c_str())); in OrderConnecTargetResult()
296 thisClass->FreeChannel(hChannel->channelId); in OrderConnecTargetResult()
301 bool HdcServerForClient::NewConnectTry(void *ptrServer, HChannel hChannel, const string &connectKey… in NewConnectTry() argument
310 EchoClient(hChannel, MSG_INFO, "Target is connected, repeat operation"); in NewConnectTry()
312 EchoClient(hChannel, MSG_FAIL, "CreateConnect failed"); in NewConnectTry()
319 hChannel->connectLocalDevice = true; in NewConnectTry()
322 Base::ZeroBuf(hChannel->bufStd, 2); in NewConnectTry()
323 …childRet = snprintf_s(hChannel->bufStd + 2, sizeof(hChannel->bufStd) - 2, sizeof(hChannel->bufStd)… in NewConnectTry()
326 Base::TimerUvTask(loopMain, hChannel, OrderConnecTargetResult, 10); in NewConnectTry()
333 bool HdcServerForClient::CommandRemoveSession(HChannel hChannel, const char *connectKey) in CommandRemoveSession() argument
339 EchoClient(hChannel, MSG_FAIL, "No target available"); in CommandRemoveSession()
366 void HdcServerForClient::GetTargetList(HChannel hChannel, void *formatCommandInput) in GetTargetList() argument
379 EchoClient(hChannel, MSG_OK, const_cast<char *>(sRet.c_str())); in GetTargetList()
386 bool HdcServerForClient::GetAnyTarget(HChannel hChannel) in GetAnyTarget() argument
392 EchoClient(hChannel, MSG_FAIL, "No target available"); in GetAnyTarget()
397 bool ret = NewConnectTry(ptrServer, hChannel, connectKey); in GetAnyTarget()
405 bool HdcServerForClient::WaitForAny(HChannel hChannel) in WaitForAny() argument
411 EchoClient(hChannel, MSG_FAIL, "No any connected target"); in WaitForAny()
415 EchoClient(hChannel, MSG_OK, "Wait for connected target is %s", key.c_str()); in WaitForAny()
419 bool HdcServerForClient::RemoveForward(HChannel hChannel, const char *parameterString) in RemoveForward() argument
432 EchoClient(hChannel, MSG_OK, "Remove forward ruler success, ruler:%s", s.c_str()); in RemoveForward()
434 … EchoClient(hChannel, MSG_FAIL, "Remove forward ruler failed, ruler is not exist %s", s.c_str()); in RemoveForward()
439 EchoClient(hChannel, MSG_OK, "Remove forward ruler success, ruler:%s", parameterString); in RemoveForward()
441 …EchoClient(hChannel, MSG_FAIL, "Remove forward ruler failed, ruler is not exist %s", parameterStri… in RemoveForward()
447 bool HdcServerForClient::DoCommandLocal(HChannel hChannel, void *formatCommandInput) in DoCommandLocal() argument
455 OrderFindTargets(hChannel); in DoCommandLocal()
460 GetTargetList(hChannel, formatCommandInput); in DoCommandLocal()
466 ReportServerVersion(hChannel); in DoCommandLocal()
472 ret = !WaitForAny(hChannel); in DoCommandLocal()
479 ret = GetAnyTarget(hChannel); in DoCommandLocal()
486 ret = NewConnectTry(ptrServer, hChannel, formatCommand->parameters.c_str()); in DoCommandLocal()
491 hChannel->isCheck = true; in DoCommandLocal()
492 hChannel->key = formatCommand->parameters.c_str(); in DoCommandLocal()
493 ret = NewConnectTry(ptrServer, hChannel, formatCommand->parameters.c_str(), true); in DoCommandLocal()
497 CommandRemoveSession(hChannel, formatCommand->parameters.c_str()); in DoCommandLocal()
513 EchoClient(hChannel, MSG_OK, const_cast<char *>(echo.c_str())); in DoCommandLocal()
517 RemoveForward(hChannel, formatCommand->parameters.c_str()); in DoCommandLocal()
522 hChannel->keepAlive = true; in DoCommandLocal()
527 EchoClient(hChannel, MSG_FAIL, "ExecuteCommand need connect-key?"); in DoCommandLocal()
534 bool HdcServerForClient::TaskCommand(HChannel hChannel, void *formatCommandInput) in TaskCommand() argument
543 HandleRemote(hChannel, formatCommand->parameters, RemoteType::REMOTE_FILE); in TaskCommand()
550 HandleRemote(hChannel, formatCommand->parameters, RemoteType::REMOTE_APP); in TaskCommand()
569 HSession hSession = FindAliveSession(hChannel->targetSessionId); in TaskCommand()
574 hChannel->fromClient) { in TaskCommand()
576 … WRITE_LOG(LOG_DEBUG, "command send back to remote client channelId:%u", hChannel->channelId); in TaskCommand()
577 SendChannelWithCmd(hChannel, formatCommand->cmdFlag, in TaskCommand()
582 ptrServer->DispatchTaskData(hSession, hChannel->channelId, formatCommand->cmdFlag, in TaskCommand()
587 SendToDaemon(hChannel, formatCommand->cmdFlag, in TaskCommand()
594 void HdcServerForClient::HandleRemote(HChannel hChannel, string ¶meters, RemoteType flag) in HandleRemote() argument
596 hChannel->remote = flag; in HandleRemote()
601 hChannel->fromClient = true; in HandleRemote()
602 WRITE_LOG(LOG_DEBUG, "remote client mode channelId:%u", hChannel->channelId); in HandleRemote()
606 if (hChannel->fromClient) { in HandleRemote()
615 bool HdcServerForClient::DoCommandRemote(HChannel hChannel, void *formatCommandInput) in DoCommandRemote() argument
634 if (!SendToDaemon(hChannel, formatCommand->cmdFlag, in DoCommandRemote()
641 hChannel->interactiveShellMode = true; in DoCommandRemote()
655 TaskCommand(hChannel, formatCommandInput); in DoCommandRemote()
663 EchoClient(hChannel, MSG_FAIL, "Failed to communicate with daemon"); in DoCommandRemote()
668 bool HdcServerForClient::DoCommand(HChannel hChannel, void *formatCommandInput) in DoCommand() argument
672 if (!hChannel->hChildWorkTCP.loop || formatCommand->cmdFlag == CMD_FORWARD_REMOVE) { in DoCommand()
674 ret = DoCommandLocal(hChannel, formatCommandInput); in DoCommand()
676 ret = DoCommandRemote(hChannel, formatCommandInput); in DoCommand()
682 HSession HdcServerForClient::FindAliveSessionFromDaemonMap(const HChannel hChannel) in FindAliveSessionFromDaemonMap() argument
687 ptrServer->AdminDaemonMap(OP_QUERY, hChannel->connectKey, hdi); in FindAliveSessionFromDaemonMap()
689 EchoClient(hChannel, MSG_FAIL, "Not match target founded, check connect-key please"); in FindAliveSessionFromDaemonMap()
693 EchoClient(hChannel, MSG_FAIL, "Device not founded or connected"); in FindAliveSessionFromDaemonMap()
697 EchoClient(hChannel, MSG_FAIL, "Bind tartget session is dead"); in FindAliveSessionFromDaemonMap()
704 int HdcServerForClient::BindChannelToSession(HChannel hChannel, uint8_t *bufPtr, const int bytesIO) in BindChannelToSession() argument
706 if (FindAliveSessionFromDaemonMap(hChannel) == nullptr) { in BindChannelToSession()
709 bool isClosing = uv_is_closing((const uv_handle_t *)&hChannel->hWorkTCP); in BindChannelToSession()
710 … if (!isClosing && (hChannel->fdChildWorkTCP = Base::DuplicateUvSocket(&hChannel->hWorkTCP)) < 0) { in BindChannelToSession()
711 WRITE_LOG(LOG_FATAL, "Duplicate socket failed, cid:%d", hChannel->channelId); in BindChannelToSession()
715 HChannel hChannel = (HChannel)handle->data; in BindChannelToSession() local
716 --hChannel->ref; in BindChannelToSession()
718 ++hChannel->ref; in BindChannelToSession()
720 uv_close((uv_handle_t *)&hChannel->hWorkTCP, funcWorkTcpClose); in BindChannelToSession()
722 Base::DoNextLoop(loopMain, hChannel, [](const uint8_t flag, string &msg, const void *data) { in BindChannelToSession()
725 HChannel hChannel = (HChannel)data; in BindChannelToSession() local
726 auto thisClass = (HdcServerForClient *)hChannel->clsChannel; in BindChannelToSession()
728 if ((hSession = thisClass->FindAliveSessionFromDaemonMap(hChannel)) == nullptr) { in BindChannelToSession()
731 … auto ctrl = HdcSessionBase::BuildCtrlString(SP_ATTACH_CHANNEL, hChannel->channelId, nullptr, 0); in BindChannelToSession()
737 bool HdcServerForClient::CheckAutoFillTarget(HChannel hChannel) in CheckAutoFillTarget() argument
740 if (!hChannel->connectKey.size()) { in CheckAutoFillTarget()
743 if (hChannel->connectKey == CMDSTR_CONNECT_ANY) { in CheckAutoFillTarget()
749 hChannel->connectKey = hdiOld->connectKey; in CheckAutoFillTarget()
755 int HdcServerForClient::ChannelHandShake(HChannel hChannel, uint8_t *bufPtr, const int bytesIO) in ChannelHandShake() argument
762 hChannel->availTailIndex = 0; in ChannelHandShake()
767 hChannel->availTailIndex = 0; in ChannelHandShake()
773 hChannel->connectKey = handShake->connectKey; in ChannelHandShake()
774 hChannel->handshakeOK = true; in ChannelHandShake()
775 if (!CheckAutoFillTarget(hChannel)) { in ChannelHandShake()
779 if (BindChannelToSession(hChannel, nullptr, 0)) { in ChannelHandShake()
780 hChannel->availTailIndex = 0; in ChannelHandShake()
787 void HdcServerForClient::ReportServerVersion(HChannel hChannel) in ReportServerVersion() argument
790 SendChannelWithCmd(hChannel, CMD_CHECK_SERVER, in ReportServerVersion()
796 int HdcServerForClient::ReadChannel(HChannel hChannel, uint8_t *bufPtr, const int bytesIO) in ReadChannel() argument
799 if (!hChannel->handshakeOK) { in ReadChannel()
800 return ChannelHandShake(hChannel, bufPtr, bytesIO); in ReadChannel()
804 if (command != 0 && (hChannel->remote > RemoteType::REMOTE_NONE)) { in ReadChannel()
806 … if (!SendToDaemon(hChannel, command, bufPtr + sizeof(uint16_t), bytesIO - sizeof(uint16_t))) { in ReadChannel()
812 if (!hChannel->interactiveShellMode) { in ReadChannel()
819 EchoClient(hChannel, MSG_OK, retEcho.c_str()); in ReadChannel()
821 EchoClient(hChannel, MSG_FAIL, retEcho.c_str()); in ReadChannel()
834 if (!DoCommand(hChannel, &formatCommand)) { in ReadChannel()