svcmain.cpp revision c12e254c1838a1b167dd65cf40b90067f136d8ca
/** @file
*
* SVCMAIN - COM out-of-proc server main entry
*/
/*
* Copyright (C) 2006-2011 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 <stdio.h>
#include "VBox/com/VirtualBox.h"
#include "VirtualBoxImpl.h"
#include "Logging.h"
#include "svchlp.h"
#include <iprt/initterm.h>
#include <atlbase.h>
#include <atlcom.h>
#define _ATL_FREE_THREADED
class CExeModule : public CComModule
{
public:
void MonitorShutdown();
bool StartMonitor();
bool bActivity;
};
/* Passed to CreateThread to monitor the shutdown event */
{
p->MonitorShutdown();
return 0;
}
{
if (l == 0)
{
bActivity = true;
}
return l;
}
/* Monitors the shutdown event */
void CExeModule::MonitorShutdown()
{
while (1)
{
do
{
bActivity = false;
} while (dwWait == WAIT_OBJECT_0);
/* timed out */
{
if (!bActivity && m_nLockCnt == 0)
#endif
break;
}
}
}
bool CExeModule::StartMonitor()
{
if (hEventShutdown == NULL)
return false;
return (h != NULL);
}
{
{
{
if (*p1 == *p)
p = CharNext(p);
}
}
return NULL;
}
{
{
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////
//
{
/* Need to parse the command line before initializing the VBox runtime. */
{
{
/* %HOMEDRIVE%%HOMEPATH% */
wchar_t wszHome[RTPATH_MAX];
{
{
/* If this fails there is nothing we can do. Ignore. */
}
}
}
}
/*
* Initialize the VBox runtime without loading
* the support driver.
*/
RTR3Init();
* approximate case insensitive matching, which RTGetOpt doesn't offer. */
static const RTGETOPTDEF s_aOptions[] =
{
};
bool fRun = true;
bool fRegister = false;
bool fUnregister = false;
const char *pszPipeName = NULL;
const char *pszLogFile = NULL;
int vrc = RTGetOptInit(&GetOptState, argc, argv, &s_aOptions[0], RT_ELEMENTS(s_aOptions), 1, 0 /*fFlags*/);
{
switch (vrc)
{
case 'e':
/* already handled above */
break;
case 'u':
fUnregister = true;
fRun = false;
break;
case 'r':
fRegister = true;
break;
case 'f':
fUnregister = true;
fRegister = true;
fRun = false;
break;
case 'H':
if (!pszPipeName)
pszPipeName = "";
fRun = false;
break;
case 'F':
break;
case 'R':
break;
case 'S':
break;
case 'I':
break;
case 'h':
L"/RegServer:\tregister COM out-of-proc server\n"
L"/UnregServer:\tunregister COM out-of-proc server\n"
L"/ReregServer:\tunregister and register COM server\n"
L"no options:\trun the server";
fRun = false;
break;
case 'V':
fRun = false;
break;
default:
/** @todo this assumes that stderr is visible, which is not
* true for standard Windows applications. */
}
}
if (!pszLogFile)
{
char szLogFile[RTPATH_MAX];
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
}
/* Only create the log file when running VBoxSVC normally, but not when
* registering/unregistering or calling the helper functionality. */
if (fRun)
int nRet = 0;
if (!fRun)
{
if (fUnregister)
{
}
if (fRegister)
{
}
if (!pszPipeName)
{
if (!*pipeName)
if (RT_SUCCESS(vrc))
{
/* do the helper job */
if (RT_SUCCESS(vrc))
}
if (RT_FAILURE(vrc))
{
nRet = 1;
}
}
}
else
{
hRes = CoResumeClassObjects();
#else
#endif
while (GetMessage(&msg, 0, 0, 0))
}
Log(("SVCMAIN: Returning, COM server process ends.\n"));
return nRet;
}