Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified host/bins/cfc-0.1.0-x64.deb
Binary file not shown.
1 change: 0 additions & 1 deletion host/src/pack/dpkg/opt/cfc/mwc/bin/killapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Binary file modified host/src/pack/dpkg/opt/cfc/mwc/bin/mwc_hostdaemon
Binary file not shown.
2 changes: 1 addition & 1 deletion host/src/pghost/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
107 changes: 107 additions & 0 deletions host/src/pghost/lgslot.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

SPDX-License-Identifier: GPL-3.0-or-later
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>

#include <sys/types.h>
#include <pthread.h>

#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; i<NUM_LG_SLOTS; i++) {
if (LGSLOT_IDLE == m_lg_slots[i]->slot_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;
}
45 changes: 45 additions & 0 deletions host/src/pghost/lgslot.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

SPDX-License-Identifier: GPL-3.0-or-later
*/

#ifndef __LGSLOT_H__
#define __LGSLOT_H__
#include <pthread.h>
using namespace std;

#include <stdio.h>
#include <stdlib.h>

#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
26 changes: 18 additions & 8 deletions host/src/pghost/vatclidaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
49 changes: 21 additions & 28 deletions host/src/pghost/vatclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -388,18 +395,10 @@ int VatClient::HandleEvent(Event* event)
}
break;
case EVENT_REQ_GET_IDLE_LG_SLOT:
idle_slot = -1;
for (int i=0; i<NUM_LG_SLOTS; i++) {
if (LGSLOT_IDLE == m_lg_slots[i]->slot_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);
Expand Down Expand Up @@ -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; i<NUM_LG_SLOTS; i++) {
printf("slot:%d, status:%d, appname:%s, activity:%s\n", i, m_lg_slots[i]->slot_status, m_lg_slots[i]->appname, m_lg_slots[i]->activity);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions host/src/pghost/vatclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class EventQueue;
class PipeMgr;
class Event;
class Connmgr;
class LGSlot;

#include "common.h"

Expand All @@ -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();
Expand All @@ -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;
};
Expand Down