diff --git a/host/bins/cfc-0.1.0-x64.deb b/host/bins/cfc-0.1.0-x64.deb index 09fa3d4..13b70f0 100644 Binary files a/host/bins/cfc-0.1.0-x64.deb and b/host/bins/cfc-0.1.0-x64.deb differ diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/killapp.sh b/host/src/pack/dpkg/opt/cfc/mwc/bin/killapp.sh index ccb3f6c..ca100dc 100755 --- a/host/src/pack/dpkg/opt/cfc/mwc/bin/killapp.sh +++ b/host/src/pack/dpkg/opt/cfc/mwc/bin/killapp.sh @@ -9,7 +9,6 @@ then fi adb -s vsock:3:5555 shell am force-stop $1 -adb -s vsock:3:5555 shell am force-stop com.android.packageinstaller exit 0 diff --git a/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_hostdaemon b/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_hostdaemon index e29758c..0df5605 100755 Binary files a/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_hostdaemon and b/host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_hostdaemon differ diff --git a/host/src/pghost/Makefile b/host/src/pghost/Makefile index bc920f6..26c47d4 100644 --- a/host/src/pghost/Makefile +++ b/host/src/pghost/Makefile @@ -22,7 +22,7 @@ all: mwc_launcher mwc_hostdaemon mwc libkydroid.so api_test msg_agent comm_host_ MWCHOSTDAEMONSRCS = vatclidaemon.cpp connsock.cpp connfactory.cpp connmgr.cpp \ - eventqueue.cpp utils.cpp vatclient.cpp + eventqueue.cpp utils.cpp vatclient.cpp lgslot.cpp MWCLAUNCHERSRCS = vatlauncher.cpp lgclient.cpp connfactory.cpp connmgr.cpp eventqueue.cpp \ connsock.cpp utils.cpp ShortcutMgrLg.cpp Log.cpp AdbProxy.cpp diff --git a/host/src/pghost/lgslot.cpp b/host/src/pghost/lgslot.cpp new file mode 100644 index 0000000..99ba313 --- /dev/null +++ b/host/src/pghost/lgslot.cpp @@ -0,0 +1,107 @@ +/* +Copyright (C) 2021 Intel Corporation +  +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License, as published +by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. +  +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +GNU General Public License for more details. +  +You should have received a copy of the GNU General Public License +along with this program; if not, see . +  +SPDX-License-Identifier: GPL-3.0-or-later +*/ + +#include +#include +#include +#include + +#include +#include + +#include "lgslot.h" +#include "common.h" + +LGSlot::LGSlot () +{ + if (pthread_mutex_init (&m_slots_lock, 0)) { + printf("LGSlot, error to init slots lock!\n"); + } +} + +LGSlot::~LGSlot() +{ + if (pthread_mutex_destroy(&m_slots_lock)) { + printf("~LGSlot, error to destroy slots lock!\n"); + } +} +void LGSlot::SetLGSlots(lgslot_t** slots) +{ + m_lg_slots = slots; +} + +int LGSlot::SetLGSlotIdle(int lgslot_id) +{ + if (NULL == m_lg_slots) { + return -1; + } + + if (lgslot_id >=0 && lgslot_id < NUM_LG_SLOTS) { + pthread_mutex_lock(&m_slots_lock); + m_lg_slots[lgslot_id]->slot_status = LGSLOT_IDLE; + memset(m_lg_slots[lgslot_id]->appname, 0, sizeof(m_lg_slots[lgslot_id]->appname)); + memset(m_lg_slots[lgslot_id]->activity, 0, sizeof(m_lg_slots[lgslot_id]->activity)); + pthread_mutex_unlock(&m_slots_lock); + } + else { + return -1; + } + + return lgslot_id; +} + +int LGSlot::BundleLGSlotApp(int lgslot_id, char* appname, char* activity) +{ + if (NULL == m_lg_slots) { + return -1; + } + + if (lgslot_id >= 0 && lgslot_id < NUM_LG_SLOTS) { + pthread_mutex_lock(&m_slots_lock); + m_lg_slots[lgslot_id]->slot_status = LGSLOT_USED; + snprintf(m_lg_slots[lgslot_id]->appname, sizeof(m_lg_slots[lgslot_id]->appname), "%s", appname); + snprintf(m_lg_slots[lgslot_id]->activity, sizeof(m_lg_slots[lgslot_id]->activity), "%s", activity); + pthread_mutex_unlock(&m_slots_lock); + } + else { + return -1; + } + + return lgslot_id; +} + +int LGSlot::ReserveOneLGSlot() +{ + if (NULL == m_lg_slots) { + return -1; + } + + int idle_slot = -1; + pthread_mutex_lock(&m_slots_lock); + for (int i=0; islot_status) { + printf("found one idle slot:%d and set the slot as reserved\n", i); + idle_slot = i; + m_lg_slots[i]->slot_status = LGSLOT_RESERVED; + break; + } + } + pthread_mutex_unlock(&m_slots_lock); + return idle_slot; +} diff --git a/host/src/pghost/lgslot.h b/host/src/pghost/lgslot.h new file mode 100644 index 0000000..3d92e7a --- /dev/null +++ b/host/src/pghost/lgslot.h @@ -0,0 +1,45 @@ +/* +Copyright (C) 2021 Intel Corporation +  +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License, as published +by the Free Software Foundation; either version 3 of the License, +or (at your option) any later version. +  +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +GNU General Public License for more details. +  +You should have received a copy of the GNU General Public License +along with this program; if not, see . +  +SPDX-License-Identifier: GPL-3.0-or-later +*/ + +#ifndef __LGSLOT_H__ +#define __LGSLOT_H__ +#include +using namespace std; + +#include +#include + +#include "common.h" + +class LGSlot { + public: + LGSlot (); + void SetLGSlots(lgslot_t** slots); + int SetLGSlotIdle(int lgslot_id); + int BundleLGSlotApp(int lgslot_id, char* appname, char* activity); + int ReserveOneLGSlot(); + ~LGSlot(); + private: + //Slot array lock protection; + pthread_mutex_t m_slots_lock; + lgslot_t** m_lg_slots = NULL; + +}; + +#endif diff --git a/host/src/pghost/vatclidaemon.cpp b/host/src/pghost/vatclidaemon.cpp index ef81772..7bccb67 100644 --- a/host/src/pghost/vatclidaemon.cpp +++ b/host/src/pghost/vatclidaemon.cpp @@ -41,6 +41,8 @@ Date: 2021.04.27 #include "eventqueue.h" #include "vatclient.h" +#include "lgslot.h" + #define LISTENPORT 3001 #define LISTENQ 8 using namespace std; @@ -63,6 +65,8 @@ lgslot_t* g_lg_slots[1]; lgslot_t* g_lg_slots[4]; #endif +LGSlot* g_lgslot_inst = NULL; + extern int get_key_value (char* src, char* key, char* ret_buf, char* kv_separtor, char* key_separator); #ifdef LG_SINGLE_MODE static int HandleEvent(global_data_t* gdata, Event* event) { @@ -129,14 +133,12 @@ static int HandleEvent(global_data_t* gdata, Event* event) { } it++; } - if (lg_slot >=0 && lg_slot < NUM_LG_SLOTS) { - if (strstr(g_lg_slots[lg_slot]->appname, appname) && g_lg_slots[lg_slot]->slot_status != LGSLOT_IDLE) { - g_lg_slots[lg_slot]->slot_status = LGSLOT_IDLE; - memset(g_lg_slots[lg_slot]->appname, 0, sizeof(g_lg_slots[lg_slot]->appname)); - memset(g_lg_slots[lg_slot]->activity,0, sizeof(g_lg_slots[lg_slot]->activity)); - } - } - } + if (lg_slot >=0 && lg_slot < NUM_LG_SLOTS) { + if (strstr(g_lg_slots[lg_slot]->appname, appname) && g_lg_slots[lg_slot]->slot_status != LGSLOT_IDLE) { + g_lgslot_inst->SetLGSlotIdle(lg_slot); + } + } + } break; default: break; @@ -204,6 +206,13 @@ int main (int argc, char **argv) g_lg_slots[i] = p_lgslot; } } + g_lgslot_inst = new LGSlot(); + if (NULL == g_lgslot_inst) { + perror("Failed to create Looking Glass slot state management instance. Probably low memory situation, exit!"); + exit(1); + } + g_lgslot_inst->SetLGSlots(g_lg_slots); + g_data.eventqueue = new EventQueue(); g_data.clients = &clients; g_data.running = 1; @@ -350,6 +359,7 @@ int main (int argc, char **argv) vatclient->setLauncherCommSock(fd_req); vatclient->setGlobalEvtQueue (g_data.eventqueue); vatclient->set_lg_slots(g_lg_slots); + vatclient->set_lgslot_inst(g_lgslot_inst); vatclient->Run(); clients.emplace (fd_req, vatclient); } diff --git a/host/src/pghost/vatclient.cpp b/host/src/pghost/vatclient.cpp index 3ab3bc7..368f399 100644 --- a/host/src/pghost/vatclient.cpp +++ b/host/src/pghost/vatclient.cpp @@ -39,12 +39,13 @@ Date: 2021.04.27 #include "common.h" #include "connmgr.h" - +#include "lgslot.h" using namespace std; VatClient::VatClient() { + slot_id = -1; } VatClient::~VatClient() @@ -101,6 +102,11 @@ void VatClient::set_lg_slots(lgslot_t** slots) m_lg_slots = slots; } +void VatClient::set_lgslot_inst(LGSlot* lgslot) +{ + m_lgslot = lgslot; +} + extern int get_event_id_by_name (char* evt_name); extern int get_key_value (char* src, char* key, char* ret_buf, char* kv_separtor, char* key_separator); void VatClient::EnQueueGlobalEvt (char* buf) @@ -359,8 +365,9 @@ int VatClient::HandleEvent(Event* event) } printf("slot_found: %d, idle_slot: %d\n", slot_found, idle_slot); if (slot_found > -1) { - slot_id = slot_found; - // Send the slot of the launched app to client + // Don't set slot_id in EVENT_REQ_CHECK_IF_APP_LAUNCHED, otherwise it may cause exisitng launched app state messed. + //slot_id = slot_found; + // Send the slot of the launched app to client snprintf (lgslot_body, sizeof(lgslot_body), "{lg_instance_id=%d;}", slot_found); char msg_body[512]; compose_msg_body(msg_body, sizeof(msg_body), EVENT_RES_CHECK_IF_APP_LAUNCHED, lgslot_body); @@ -388,18 +395,10 @@ int VatClient::HandleEvent(Event* event) } break; case EVENT_REQ_GET_IDLE_LG_SLOT: - idle_slot = -1; - for (int i=0; islot_status) { - printf("found one idle slot:%d and set the slot as reserved\n", i); - idle_slot = i; - slot_id = idle_slot; - m_lg_slots[i]->slot_status = LGSLOT_RESERVED; - break; - } - } + idle_slot = m_lgslot->ReserveOneLGSlot(); printf("idle_slot:%d\n", idle_slot); - if (idle_slot > -1) { + if (idle_slot >=0 && idle_slot < NUM_LG_SLOTS) { + slot_id = idle_slot; snprintf (lgslot_body, sizeof(lgslot_body), "{lg_instance_id=%d,};", idle_slot); char msg_body[512]; compose_msg_body(msg_body, sizeof(msg_body), EVENT_RES_IDEL_LG_SLOT, lgslot_body); @@ -429,11 +428,11 @@ int VatClient::HandleEvent(Event* event) (char*) "=", (char*) ","); lg_slot = atoi(lg_instance_id); - if (lg_slot < NUM_LG_SLOTS) { - m_lg_slots[lg_slot]->slot_status = LGSLOT_USED; - slot_id = lg_slot; - snprintf(m_lg_slots[lg_slot]->appname, sizeof(m_lg_slots[lg_slot]->appname), "%s", appname); - snprintf(m_lg_slots[lg_slot]->activity, sizeof(m_lg_slots[lg_slot]->activity), "%s", activity); + if (lg_slot < NUM_LG_SLOTS && lg_slot >=0) { + int ret = m_lgslot->BundleLGSlotApp(lg_slot, appname, activity); + if (ret >=0) { + slot_id = lg_slot; + } } for (int i=0; islot_status, m_lg_slots[i]->appname, m_lg_slots[i]->activity); @@ -450,9 +449,7 @@ int VatClient::HandleEvent(Event* event) if (LGSLOT_USED == m_lg_slots[i]->slot_status) { char* launched_appname = m_lg_slots[i]->appname; if (strstr(launched_appname, appname)) { - m_lg_slots[i]->slot_status = LGSLOT_IDLE; - memset(m_lg_slots[i]->appname, 0, sizeof(m_lg_slots[i]->appname)); - memset(m_lg_slots[i]->activity, 0, sizeof(m_lg_slots[i]->activity)); + m_lgslot->SetLGSlotIdle(i); kill_lg_process = 1; slot_found = i; break; @@ -535,9 +532,7 @@ int VatClient::HandleEvent(Event* event) (char*) ";"); lg_slot = atoi(lg_instance_id); if (lg_slot >=0 && lg_slot < NUM_LG_SLOTS) { - m_lg_slots[lg_slot]->slot_status = LGSLOT_IDLE; - memset(m_lg_slots[lg_slot]->appname, 0, sizeof(m_lg_slots[lg_slot]->appname)); - memset(m_lg_slots[lg_slot]->activity, 0, sizeof(m_lg_slots[lg_slot]->activity)); + m_lgslot->SetLGSlotIdle(lg_slot); } running = 0; break; @@ -600,9 +595,7 @@ void VatClient::CleanUp() if (slot_id >=0 && slot_id < NUM_LG_SLOTS) { if (LGSLOT_USED == m_lg_slots[slot_id]->slot_status) { - m_lg_slots[slot_id]->slot_status = LGSLOT_IDLE; - memset(m_lg_slots[slot_id]->appname, 0, sizeof(m_lg_slots[slot_id]->appname)); - memset(m_lg_slots[slot_id]->activity, 0, sizeof(m_lg_slots[slot_id]->activity)); + m_lgslot->SetLGSlotIdle(slot_id); } } } diff --git a/host/src/pghost/vatclient.h b/host/src/pghost/vatclient.h index 435f84b..a55eb19 100644 --- a/host/src/pghost/vatclient.h +++ b/host/src/pghost/vatclient.h @@ -28,6 +28,7 @@ class EventQueue; class PipeMgr; class Event; class Connmgr; +class LGSlot; #include "common.h" @@ -42,6 +43,7 @@ class VatClient void readAndParseEvt(); bool needRelease(); void set_lg_slots(lgslot_t** slots); + void set_lgslot_inst(LGSlot* lgslot); int getLGSlotID(); void Close(); char* getAppname(); @@ -65,6 +67,7 @@ class VatClient pthread_t m_client_loop = 0; volatile int slot_id = -1; lgslot_t** m_lg_slots = NULL; + LGSlot* m_lgslot = NULL; std::string m_appname; std::string m_activity; };