svcmain.cpp revision df03c5ed15c9b5bf6d75fedcdf5057d3ffce8577
/** @file
*
* SVCMAIN - COM out-of-proc server main entry
*/
/*
* Copyright (C) 2004-2012 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 <stdio.h>
#include <stdlib.h>
#include "VBox/com/VirtualBox.h"
#include "VirtualBoxImpl.h"
#include "Logging.h"
#include "svchlp.h"
#include <iprt/buildconfig.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;
}
/////////////////////////////////////////////////////////////////////////////
//
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/)
{
/*
* 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.
*/
* 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;
fRun = false;
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;
return 0;
}
case 'V':
{
fRun = false;
return 0;
}
default:
/** @todo this assumes that stderr is visible, which is not
* true for standard Windows applications. */
/* continue on command line errors... */
}
}
/* Only create the log file when running VBoxSVC normally, but not when
* registering/unregistering or calling the helper functionality. */
if (fRun)
{
if (!pszLogFile)
{
char szLogFile[RTPATH_MAX];
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
}
"all", "VBOXSVC_RELEASE_LOG",
if (RT_FAILURE(vrc))
}
int nRet = 0;
if (!fRun)
{
if (fUnregister)
{
}
if (fRegister)
{
}
if (pszPipeName)
{
if (!*pszPipeName)
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;
}