VBoxIPC.cpp revision cdf44790f2126d0f093dbe7647a5cebbdb33f63b
/* $Id$ */
/** @file
* VBoxIPC - IPC thread, acts as a (purely) local IPC server.
* Multiple sessions are supported, whereas every session
* has its own thread for processing requests.
*/
/*
* Copyright (C) 2010-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <windows.h>
#include "VBoxTray.h"
#include "VBoxTrayMsg.h"
#include "VBoxHelpers.h"
#include "VBoxIPC.h"
#include <iprt/critsect.h>
#include <iprt/localipc.h>
#include <VBoxGuestInternal.h>
/**
* IPC context data.
*/
typedef struct VBOXIPCCONTEXT
{
/** Pointer to the service environment. */
const VBOXSERVICEENV *pEnv;
/** Handle for the local IPC server. */
/** Critical section serializing access to the session list, the state,
* the response event, the session event, and the thread event. */
/** List of all active IPC sessions. */
static VBOXIPCCONTEXT gCtx = {0};
/**
* IPC per-session thread data.
*/
typedef struct VBOXIPCSESSION
{
/** The list node required to be part of the
* IPC session list. */
/** Pointer to the IPC context data. */
PVBOXIPCCONTEXT volatile pCtx;
/** The local ipc client handle. */
RTLOCALIPCSESSION volatile hSession;
/** Indicate that the thread should terminate ASAP. */
bool volatile fTerminate;
/** The thread handle. */
/**
* Initializes the IPC communication.
*
* @return IPRT status code.
* @param pEnv The IPC service's environment.
* @param ppInstance The instance pointer which refer to this object.
* @param pfStartThread Pointer to flag whether the IPC service can be started or not.
*/
{
/** ppInstance not used here. */
*pfStartThread = false;
if (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
{
return rc;
}
*pfStartThread = true;
}
return rc;
}
{
{
if (RT_FAILURE(rc2))
}
}
{
if (RT_SUCCESS(rc))
{
{
if (RT_FAILURE(rc2))
{
LogFunc(("Destroying IPC session %p failed with rc=%Rrc\n",
/* Keep going. */
}
}
}
LogFunc(("Destroyed pInstance=%p, rc=%Rrc\n",
}
/**
* Services a client session.
*
* @returns VINF_SUCCESS.
* @param hThread The thread handle.
* @param pvSession Pointer to the session instance data.
*/
{
/*
* Process client requests until it quits or we're cancelled on termination.
*/
{
if (RT_FAILURE(rc))
{
if (rc == VERR_CANCELLED)
{
LogFunc(("Waiting for data cancelled\n"));
rc = VINF_SUCCESS;
break;
}
else if (rc != VERR_TIMEOUT)
{
break;
}
}
/** @todo Implement handler. */
}
/*
* Clean up the session.
*/
if (pCtx)
else
if (hSession != NIL_RTLOCALIPCSESSION)
else
if (pCtx)
{
//RTSemEventSignal(pCtx->hSessionEvent);
}
return VINF_SUCCESS;
}
{
if (RT_SUCCESS(rc))
{
if (pSession)
{
pSession->fTerminate = false;
/* Start IPC session thread. */
if (RT_SUCCESS(rc))
{
/* Add session thread to session IPC list. */
}
else
{
if (RT_FAILURE(rc2))
}
}
else
rc = VERR_NO_MEMORY;
}
return rc;
}
{
if (hSession != NIL_RTLOCALIPCSESSION)
return VINF_SUCCESS;
}
/**
* Thread function to wait for and process seamless mode change
* requests
*/
{
bool fShutdown = false;
for (;;)
{
if (RT_FAILURE(rc))
{
if (rc == VERR_CANCELLED)
{
LogFlow(("Cancelled\n"));
fShutdown = true;
}
else
}
if (fShutdown)
break;
if (RT_FAILURE(rc))
{
/* Keep going. */
}
break;
}
return 0;
}