From a2afd56222ff1be94be5d52404796498ebb3a43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=80=99=E9=B9=8F=E9=A3=9E?= <2597457485@qq.com> Date: Wed, 11 Nov 2020 10:41:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A8=B3=E5=AE=9A=E6=80=A7?= =?UTF-8?q?=E5=92=8C=E4=BF=AE=E6=94=B9BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/CMakeLists.txt.user | 2 +- Server/inc/common.h | 3 +-- Server/inc/mock/VirtualScreen.h | 1 - Server/main.cpp | 3 ++- Server/src/jsapp/JsApp.cpp | 6 +++--- Server/src/mock/VirtualScreen.cpp | 7 ------- Server/src/server.cpp | 30 +++++++++++++++++++----------- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Server/CMakeLists.txt.user b/Server/CMakeLists.txt.user index 83664e7..49e4bda 100644 --- a/Server/CMakeLists.txt.user +++ b/Server/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/Server/inc/common.h b/Server/inc/common.h index ef519d2..38290cb 100644 --- a/Server/inc/common.h +++ b/Server/inc/common.h @@ -22,10 +22,8 @@ #endif #ifdef WIN32 -#define ACCESS _access #define MKDIR(a) _mkdir((a)) #elif __linux__ -#define ACCESS access #define MKDIR(a) mkdir((a),0755) #endif @@ -37,6 +35,7 @@ extern bool m_send; extern bool isChanged; extern ProtocolMessage protocalMsg; extern CliParam cliParam; +extern bool isAppRunning; /** * ide发给管理服务的消息封装类 diff --git a/Server/inc/mock/VirtualScreen.h b/Server/inc/mock/VirtualScreen.h index 0c1b066..38b2fd5 100644 --- a/Server/inc/mock/VirtualScreen.h +++ b/Server/inc/mock/VirtualScreen.h @@ -20,5 +20,4 @@ public: private: VirtualScreen(); ~VirtualScreen(); - bool IsRectValid(int32_t x1, int32_t y1, int32_t x2, int32_t y2); }; diff --git a/Server/main.cpp b/Server/main.cpp index 6f5391a..9429e68 100644 --- a/Server/main.cpp +++ b/Server/main.cpp @@ -16,6 +16,7 @@ bool m_send = false; bool isChanged = false; ProtocolMessage protocalMsg; CliParam cliParam; +bool isAppRunning = true; int main(int argc, char *argv[]) { @@ -24,7 +25,7 @@ int main(int argc, char *argv[]) { //判断jsBundle路径是否存在 if(!cliParam.jsBundle.empty()) { - if(ACCESS(cliParam.jsBundle.c_str(),0) == -1) { + if(access(cliParam.jsBundle.c_str(),0) == -1) { std::cout << "[Error]:Error jsBundle path!" << std::endl; return 0; } diff --git a/Server/src/jsapp/JsApp.cpp b/Server/src/jsapp/JsApp.cpp index ee78a48..7129f54 100644 --- a/Server/src/jsapp/JsApp.cpp +++ b/Server/src/jsapp/JsApp.cpp @@ -30,7 +30,6 @@ bool JsApp::Start() { JsAppthread = std::thread(JsApp::Run); if(JsAppthread.joinable()) { JsAppthread.detach(); - return true; } else { return false; } @@ -40,7 +39,8 @@ bool JsApp::Start() { bool JsApp::Stop() { std::cout << "[INFO]:JsApp Stop" << std::endl; jsAbility->TransferToDestroy(); - JsAppthread.~thread(); + //JsAppthread.~thread(); + isAppRunning = false; return true; } @@ -57,7 +57,7 @@ void JsApp::Run() { const_cast((ApplicationPath()+"\\font\\").c_str()), const_cast(FONT_NAME)); VirtualScreen::GetInstance().Init(protocalMsg.devices[0].screen.width, protocalMsg.devices[0].screen.height); JsApp::GetInstance().StartJsApp(); - for(;;) { + while(isAppRunning) { OHOS::RenderManager::GetInstance().Callback(); if(m_send == true) { if(VirtualScreen::GetInstance().screenBuffer == nullptr) { diff --git a/Server/src/mock/VirtualScreen.cpp b/Server/src/mock/VirtualScreen.cpp index a8436e4..67e7333 100644 --- a/Server/src/mock/VirtualScreen.cpp +++ b/Server/src/mock/VirtualScreen.cpp @@ -31,13 +31,6 @@ void VirtualScreen::Flush(int16_t x1, int16_t y1, int16_t x2, int16_t y2, const OHOS::ScreenDeviceProxy::GetInstance()->OnFlushReady(); } -bool VirtualScreen::IsRectValid(int32_t x1, int32_t y1, int32_t x2, int32_t y2) { - if (x1 < x2 || x1 < 0 || x2 < 0 || y1 < 0 || y2 < 0 || y1 < y2) { - return false; - } - return true; -} - uint16_t VirtualScreen::GetWidth() const { return OHOS::ScreenDeviceProxy::GetInstance()->GetScreenWidth(); } diff --git a/Server/src/server.cpp b/Server/src/server.cpp index a57f4a9..f865e14 100644 --- a/Server/src/server.cpp +++ b/Server/src/server.cpp @@ -165,7 +165,7 @@ void on_http(server* s, websocketpp::connection_hdl hdl) { void on_fail(server* s, websocketpp::connection_hdl hdl) { server::connection_ptr con = s->get_con_from_hdl(hdl); - //std::cout << "Fail handler: " << con->get_ec() << " " << con->get_ec().message() << std::endl; + std::cout << "Fail handler: " << con->get_ec() << " " << con->get_ec().message() << std::endl; } void on_open(server* s, websocketpp::connection_hdl hdl) { @@ -220,14 +220,22 @@ void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { // restart engine std::cout << "[INFO]:restart engine" << std::endl; m_send = false; - JsApp::GetInstance().Stop(); - if(ACCESS(cMessage.args["jsBundle"].c_str(),0) == -1) { - std::cout << "[Error]:jsBundle path does not exist!" << std::endl; - sendMsg(s, hdl, failMsg, msg->get_opcode()); - on_stop(s); + try { + JsApp::GetInstance().Stop(); + if(access(cMessage.args["jsBundle"].c_str(),0) == -1) { + std::cout << "[Error]:jsBundle path does not exist!" << std::endl; + sendMsg(s, hdl, failMsg, msg->get_opcode()); + on_stop(s); + } + JsApp::GetInstance().SetJsAppPath(cMessage.args["jsBundle"]); + if(JsApp::GetInstance().Start() == false) { + std::cout << "[Error]:App start err!" << std::endl; + sendMsg(s, hdl, failMsg, msg->get_opcode()); + on_stop(s); + } + } catch (const std::exception& e) { + std::cout << e.what() << std::endl; } - JsApp::GetInstance().SetJsAppPath(cMessage.args["jsBundle"]); - JsApp::GetInstance().Start(); m_send = true; isChanged = true; sendMsg(s, hdl, successMsg, msg->get_opcode()); @@ -249,9 +257,9 @@ void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) { OHOS::InputDeviceManager::GetInstance()->Callback(); //sendMsg(s, hdl, successMsg, msg->get_opcode()); }else if (pMessage.command == "MouseMove") { - MouseInput::GetInstance().SetMousePosition(pMessage.args["x"],pMessage.args["y"]); - MouseInput::GetInstance().SetMouseStatus(MouseInput::MouseStatus::INDEV_STATE_MOVE); - OHOS::InputDeviceManager::GetInstance()->Callback(); + //MouseInput::GetInstance().SetMousePosition(pMessage.args["x"],pMessage.args["y"]); + //MouseInput::GetInstance().SetMouseStatus(MouseInput::MouseStatus::INDEV_STATE_MOVE); + //OHOS::InputDeviceManager::GetInstance()->Callback(); //sendMsg(s, hdl, successMsg, msg->get_opcode()); }else if (pMessage.command == "MouseRelease") { MouseInput::GetInstance().SetMousePosition(pMessage.args["x"],pMessage.args["y"]); -- Gitee