Lines Matching refs:hChannel

51     HChannel hChannel = nullptr;
52 uint32_t uid = thisClass->MallocChannel(&hChannel);
53 if (!hChannel) {
54 WRITE_LOG(LOG_FATAL, "AcceptClient hChannel is nullptr");
57 int rc = uv_accept(server, (uv_stream_t *)&hChannel->hWorkTCP);
66 uv_recv_buffer_size((uv_handle_t *)&hChannel->hWorkTCP, &bufMaxSize);
78 uv_read_start((uv_stream_t *)&hChannel->hWorkTCP, funcChannelHeaderAlloc, ReadStream);
83 handShake.channelId = htonl(hChannel->channelId);
91 thisClass->Send(hChannel->channelId, (uint8_t *)&handShake, sizeof(struct ChannelHandShake));
94 thisClass->Send(hChannel->channelId, reinterpret_cast<uint8_t *>(&handShake),
167 void HdcServerForClient::EchoClient(HChannel hChannel, MessageLevel level, const char *msg, ...)
187 SendChannel(hChannel, const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(log.c_str())), log.size());
190 void HdcServerForClient::EchoClientRaw(const HChannel hChannel, uint8_t *payload, const int payloadSize)
192 SendChannel(hChannel, payload, payloadSize);
196 void HdcServerForClient::SendCommandToClient(const HChannel hChannel, const uint16_t commandFlag,
199 SendChannelWithCmd(hChannel, commandFlag, payload, payloadSize);
202 bool HdcServerForClient::SendToDaemon(HChannel hChannel, const uint16_t commandFlag, uint8_t *bufPtr, const int bufSize)
208 ptrServer->AdminDaemonMap(OP_QUERY, hChannel->connectKey, hdi);
221 if (ptrServer->Send(hdi->hSession->sessionId, hChannel->channelId, commandFlag, bufPtr, bufSize) < 0) {
222 WRITE_LOG(LOG_FATAL, "SendToDaemon Send failed channelId:%u", hChannel->channelId);
231 void HdcServerForClient::OrderFindTargets(HChannel hChannel)
234 EchoClient(hChannel, MSG_INFO, "Please add HDC server's firewall ruler to allow udp incoming, udpport:%d",
251 EchoClient(hChannel, MSG_INFO, "Broadcast find daemon, total:%d", count);
261 HChannel hChannel = (HChannel)req->data;
262 HdcServerForClient *thisClass = (HdcServerForClient *)hChannel->clsChannel;
268 string target = std::string(hChannel->bufStd + 2);
280 if (hChannel->isCheck) {
281 WRITE_LOG(LOG_INFO, "%s check device success and remove %s", __FUNCTION__, hChannel->key.c_str());
282 thisClass->CommandRemoveSession(hChannel, hChannel->key.c_str());
283 thisClass->EchoClient(hChannel, MSG_OK, const_cast<char *>(hdi->version.c_str()));
286 thisClass->EchoClient(hChannel, MSG_OK, const_cast<char *>(sRet.c_str()));
290 uint16_t *bRetryCount = reinterpret_cast<uint16_t *>(hChannel->bufStd);
293 (hChannel->connectLocalDevice && *bRetryCount > MAX_CONNECT_DEVICE_RETRY_COUNT)) {
297 thisClass->EchoClient(hChannel, MSG_FAIL, const_cast<char *>(sRet.c_str()));
304 thisClass->FreeChannel(hChannel->channelId);
309 bool HdcServerForClient::NewConnectTry(void *ptrServer, HChannel hChannel, const string &connectKey, bool isCheck)
320 EchoClient(hChannel, MSG_INFO, "Target is connected, repeat operation");
322 EchoClient(hChannel, MSG_FAIL, "CreateConnect failed");
329 hChannel->connectLocalDevice = true;
332 Base::ZeroBuf(hChannel->bufStd, bufOffsetTwo);
333 childRet = snprintf_s(hChannel->bufStd + bufOffsetTwo, sizeof(hChannel->bufStd) - bufOffsetTwo,
334 sizeof(hChannel->bufStd) - bufOffsetThree, "%s",
337 Base::TimerUvTask(loopMain, hChannel, OrderConnecTargetResult, UV_START_REPEAT);
344 bool HdcServerForClient::CommandRemoveSession(HChannel hChannel, const char *connectKey)
350 EchoClient(hChannel, MSG_FAIL, "No target available");
386 void HdcServerForClient::GetTargetList(HChannel hChannel, void *formatCommandInput)
399 EchoClient(hChannel, MSG_OK, const_cast<char *>(sRet.c_str()));
406 bool HdcServerForClient::GetAnyTarget(HChannel hChannel)
412 EchoClient(hChannel, MSG_FAIL, "No target available");
417 bool ret = NewConnectTry(ptrServer, hChannel, connectKey);
425 bool HdcServerForClient::WaitForAny(HChannel hChannel)
429 if (!hChannel->connectKey.empty()) {
430 ptrServer->AdminDaemonMap(OP_WAIT_FOR_ANY, hChannel->connectKey, hdi);
435 EchoClient(hChannel, MSG_FAIL, "No any connected target");
439 EchoClient(hChannel, MSG_OK, "Wait for connected target is %s", key.c_str());
443 bool HdcServerForClient::RemoveForward(HChannel hChannel, const char *parameterString)
456 EchoClient(hChannel, MSG_OK, "Remove forward ruler success, ruler:%s", s.c_str());
458 EchoClient(hChannel, MSG_FAIL, "Remove forward ruler failed, ruler is not exist %s", s.c_str());
463 EchoClient(hChannel, MSG_OK, "Remove forward ruler success, ruler:%s", parameterString);
465 EchoClient(hChannel, MSG_FAIL, "Remove forward ruler failed, ruler is not exist %s", parameterString);
471 bool HdcServerForClient::DoCommandLocal(HChannel hChannel, void *formatCommandInput)
479 OrderFindTargets(hChannel);
484 GetTargetList(hChannel, formatCommandInput);
490 ReportServerVersion(hChannel);
496 ret = !WaitForAny(hChannel);
503 ret = GetAnyTarget(hChannel);
510 ret = NewConnectTry(ptrServer, hChannel, formatCommand->parameters.c_str());
515 hChannel->isCheck = true;
516 hChannel->key = formatCommand->parameters.c_str();
517 ret = NewConnectTry(ptrServer, hChannel, formatCommand->parameters.c_str(), true);
521 CommandRemoveSession(hChannel, formatCommand->parameters.c_str());
531 EchoClient(hChannel, MSG_OK, const_cast<char *>(echo.c_str()));
535 RemoveForward(hChannel, formatCommand->parameters.c_str());
540 hChannel->keepAlive = true;
545 EchoClient(hChannel, MSG_FAIL, "ExecuteCommand need connect-key? please confirm a device by help info");
552 bool HdcServerForClient::TaskCommand(HChannel hChannel, void *formatCommandInput)
561 HandleRemote(hChannel, formatCommand->parameters, RemoteType::REMOTE_FILE);
568 HandleRemote(hChannel, formatCommand->parameters, RemoteType::REMOTE_APP);
587 HSession hSession = FindAliveSession(hChannel->targetSessionId);
592 hChannel->fromClient) {
594 WRITE_LOG(LOG_DEBUG, "command send back to remote client channelId:%u", hChannel->channelId);
595 SendChannelWithCmd(hChannel, formatCommand->cmdFlag,
600 ptrServer->DispatchTaskData(hSession, hChannel->channelId, formatCommand->cmdFlag,
604 SendToDaemon(hChannel, formatCommand->cmdFlag,
611 void HdcServerForClient::HandleRemote(HChannel hChannel, string &parameters, RemoteType flag)
613 hChannel->remote = flag;
618 hChannel->fromClient = true;
619 WRITE_LOG(LOG_DEBUG, "remote client mode channelId:%u", hChannel->channelId);
623 if (hChannel->fromClient) {
632 bool HdcServerForClient::DoCommandRemote(HChannel hChannel, void *formatCommandInput)
650 if (!SendToDaemon(hChannel, formatCommand->cmdFlag,
657 hChannel->interactiveShellMode = true;
671 TaskCommand(hChannel, formatCommandInput);
679 EchoClient(hChannel, MSG_FAIL, "Failed to communicate with daemon");
684 bool HdcServerForClient::DoCommand(HChannel hChannel, void *formatCommandInput)
688 if (!hChannel->hChildWorkTCP.loop || formatCommand->cmdFlag == CMD_FORWARD_REMOVE) {
690 ret = DoCommandLocal(hChannel, formatCommandInput);
692 ret = DoCommandRemote(hChannel, formatCommandInput);
698 HSession HdcServerForClient::FindAliveSessionFromDaemonMap(const HChannel hChannel)
703 ptrServer->AdminDaemonMap(OP_QUERY, hChannel->connectKey, hdi);
705 EchoClient(hChannel, MSG_FAIL, "Not match target founded, check connect-key please");
709 EchoClient(hChannel, MSG_FAIL, "Device not founded or connected");
713 EchoClient(hChannel, MSG_FAIL, "Bind tartget session is dead");
718 hdi->hSession->sessionId, hChannel->channelId);
721 EchoClient(hChannel, MSG_FAIL, errMsg.c_str());
728 int HdcServerForClient::BindChannelToSession(HChannel hChannel, uint8_t *bufPtr, const int bytesIO)
730 if (FindAliveSessionFromDaemonMap(hChannel) == nullptr) {
731 WRITE_LOG(LOG_FATAL, "Find no alive session channelId:%u", hChannel->channelId);
734 bool isClosing = uv_is_closing((const uv_handle_t *)&hChannel->hWorkTCP);
735 if (!isClosing && (hChannel->fdChildWorkTCP = Base::DuplicateUvSocket(&hChannel->hWorkTCP)) < 0) {
736 WRITE_LOG(LOG_FATAL, "Duplicate socket failed channelId:%u", hChannel->channelId);
740 HChannel hChannel = (HChannel)handle->data;
741 --hChannel->ref;
743 ++hChannel->ref;
745 uv_close((uv_handle_t *)&hChannel->hWorkTCP, funcWorkTcpClose);
747 Base::DoNextLoop(loopMain, hChannel, [](const uint8_t flag, string &msg, const void *data) {
750 HChannel hChannel = (HChannel)data;
751 auto thisClass = (HdcServerForClient *)hChannel->clsChannel;
753 if ((hSession = thisClass->FindAliveSessionFromDaemonMap(hChannel)) == nullptr) {
754 WRITE_LOG(LOG_FATAL, "hSession nullptr channelId:%u", hChannel->channelId);
757 auto ctrl = HdcSessionBase::BuildCtrlString(SP_ATTACH_CHANNEL, hChannel->channelId, nullptr, 0);
763 bool HdcServerForClient::CheckAutoFillTarget(HChannel hChannel)
766 if (!hChannel->connectKey.size()) {
767 WRITE_LOG(LOG_FATAL, "connectKey.size 0 channelId:%u", hChannel->channelId);
770 if (hChannel->connectKey == CMDSTR_CONNECT_ANY) {
774 WRITE_LOG(LOG_WARN, "No any key found channelId:%u", hChannel->channelId);
778 WRITE_LOG(LOG_WARN, "hSession is null. channelId:%u", hChannel->channelId);
785 hChannel->connectKey = hdiOld->connectKey;
791 int HdcServerForClient::ChannelHandShake(HChannel hChannel, uint8_t *bufPtr, const int bytesIO)
798 hChannel->availTailIndex = 0;
803 hChannel->availTailIndex = 0;
809 hChannel->channelId, hChannel->targetSessionId);
810 hChannel->connectKey = handShake->connectKey;
811 hChannel->handshakeOK = true;
812 if (handShake->banner[WAIT_TAG_OFFSET] == WAIT_DEVICE_TAG || !CheckAutoFillTarget(hChannel)) {
813 WRITE_LOG(LOG_WARN, "No target channelId:%u", hChannel->channelId);
817 if (BindChannelToSession(hChannel, nullptr, 0)) {
818 hChannel->availTailIndex = 0;
820 hChannel->channelId, hChannel->targetSessionId);
826 void HdcServerForClient::ReportServerVersion(HChannel hChannel)
829 SendChannelWithCmd(hChannel, CMD_CHECK_SERVER,
835 int HdcServerForClient::ReadChannel(HChannel hChannel, uint8_t *bufPtr, const int bytesIO)
838 if (!hChannel->handshakeOK) {
839 return ChannelHandShake(hChannel, bufPtr, bytesIO);
843 ptrServer->AdminDaemonMap(OP_QUERY, hChannel->connectKey, hdi);
845 EchoClient(hChannel, MSG_FAIL, hdi->emgmsg.c_str());
849 if (command != 0 && (hChannel->remote > RemoteType::REMOTE_NONE)) {
851 if (!SendToDaemon(hChannel, command, bufPtr + sizeof(uint16_t), bytesIO - sizeof(uint16_t))) {
857 if (!hChannel->interactiveShellMode) {
864 EchoClient(hChannel, MSG_OK, retEcho.c_str());
866 EchoClient(hChannel, MSG_FAIL, retEcho.c_str());
870 hChannel->channelId, hChannel->targetSessionId, Hdc::MaskString(hChannel->connectKey).c_str(), bufPtr);
880 if (!DoCommand(hChannel, &formatCommand)) {