mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-12-23 22:31:46 +00:00
[c-host] add app_quit for clean shutdown support
This commit is contained in:
parent
b29de8f370
commit
7285f9e9ad
4 changed files with 22 additions and 9 deletions
|
@ -127,7 +127,7 @@ static bool captureStart(struct CaptureInterface * iface)
|
||||||
return startThreads();
|
return startThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_main(bool * termSignal)
|
int app_main()
|
||||||
{
|
{
|
||||||
unsigned int shmemSize = os_shmemSize();
|
unsigned int shmemSize = os_shmemSize();
|
||||||
uint8_t * shmemMap = NULL;
|
uint8_t * shmemMap = NULL;
|
||||||
|
@ -191,7 +191,7 @@ int app_main(bool * termSignal)
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(!*termSignal)
|
while(app.running)
|
||||||
{
|
{
|
||||||
bool hasFrameUpdate = false;
|
bool hasFrameUpdate = false;
|
||||||
bool hasPointerUpdate = false;
|
bool hasPointerUpdate = false;
|
||||||
|
@ -241,3 +241,8 @@ fail:
|
||||||
os_shmemUnmap();
|
os_shmemUnmap();
|
||||||
return exitcode;
|
return exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void app_quit()
|
||||||
|
{
|
||||||
|
app.running = false;
|
||||||
|
}
|
|
@ -21,7 +21,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
int app_main(bool * termSignal);
|
int app_main();
|
||||||
|
void app_quit();
|
||||||
|
|
||||||
// these must be implemented for each OS
|
// these must be implemented for each OS
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
struct app
|
struct app
|
||||||
{
|
{
|
||||||
|
@ -57,6 +58,12 @@ struct osThreadHandle
|
||||||
int resultCode;
|
int resultCode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void sigHandler(int signo)
|
||||||
|
{
|
||||||
|
DEBUG_INFO("SIGINT");
|
||||||
|
app_quit();
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
static struct option longOptions[] =
|
static struct option longOptions[] =
|
||||||
|
@ -160,8 +167,9 @@ int main(int argc, char * argv[])
|
||||||
DEBUG_INFO("KVMFR Device : %s", file);
|
DEBUG_INFO("KVMFR Device : %s", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool termSig = false;
|
signal(SIGINT, sigHandler);
|
||||||
int result = app_main(&termSig);
|
|
||||||
|
int result = app_main();
|
||||||
os_shmemUnmap();
|
os_shmemUnmap();
|
||||||
close(app.shmFD);
|
close(app.shmFD);
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
static HANDLE shmemHandle = INVALID_HANDLE_VALUE;
|
static HANDLE shmemHandle = INVALID_HANDLE_VALUE;
|
||||||
static bool shmemOwned = false;
|
static bool shmemOwned = false;
|
||||||
static IVSHMEM_MMAP shmemMap = {0};
|
static IVSHMEM_MMAP shmemMap = {0};
|
||||||
static bool termSignal = false;
|
|
||||||
static HWND messageWnd;
|
static HWND messageWnd;
|
||||||
|
|
||||||
struct osThreadHandle
|
struct osThreadHandle
|
||||||
|
@ -61,7 +60,7 @@ LRESULT CALLBACK DummyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
|
|
||||||
static int appThread(void * opaque)
|
static int appThread(void * opaque)
|
||||||
{
|
{
|
||||||
int result = app_main(&termSignal);
|
int result = app_main();
|
||||||
SendMessage(messageWnd, WM_CLOSE, 0, 0);
|
SendMessage(messageWnd, WM_CLOSE, 0, 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +161,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||||
goto finish_shmem;
|
goto finish_shmem;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(!termSignal)
|
while(true)
|
||||||
{
|
{
|
||||||
MSG msg;
|
MSG msg;
|
||||||
BOOL bRet = GetMessage(&msg, NULL, 0, 0);
|
BOOL bRet = GetMessage(&msg, NULL, 0, 0);
|
||||||
|
@ -183,7 +182,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown:
|
shutdown:
|
||||||
termSignal = true;
|
app_quit();
|
||||||
if (!os_joinThread(thread, &result))
|
if (!os_joinThread(thread, &result))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to join the main application thread");
|
DEBUG_ERROR("Failed to join the main application thread");
|
||||||
|
|
Loading…
Reference in a new issue