VBoxCredProvPoller.cpp revision 04c077e3c2bfacb8a42b4ee801ca025e94a9f0eb
/* $Id$ */
/** @file
* VBoxCredPoller - Thread for querying / retrieving user credentials.
*/
/*
* Copyright (C) 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 <VBox/VBoxGuest.h>
#include <VBox/VBoxGuestLib.h>
#include "VBoxCredProvProvider.h"
#include "VBoxCredProvCredential.h"
#include "VBoxCredProvPoller.h"
#include "VBoxCredProvUtils.h"
VBoxCredProvPoller::VBoxCredProvPoller(void) :
{
}
VBoxCredProvPoller::~VBoxCredProvPoller(void)
{
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Destroying ...\n");
Shutdown();
}
{
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Initializing\n");
/* Don't create more than one of them. */
if (m_hThreadPoller != NIL_RTTHREAD)
{
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Thread already running, returning\n");
return VINF_SUCCESS;
}
/*
* We must not add a reference via AddRef() here, otherwise
* the credential provider does not get destructed properly.
* In order to get this thread terminated normally the credential
* provider has to call Shutdown().
*/
/* Create the poller thread. */
int rc = RTThreadCreate(&m_hThreadPoller, VBoxCredProvPoller::threadPoller, this, 0, RTTHREADTYPE_INFREQUENT_POLLER,
RTTHREADFLAGS_WAITABLE, "credpoll");
if (RT_FAILURE(rc))
return rc;
}
int VBoxCredProvPoller::Shutdown(void)
{
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Shutdown\n");
if (m_hThreadPoller == NIL_RTTHREAD)
return VINF_SUCCESS;
/* Post termination event semaphore. */
if (RT_SUCCESS(rc))
{
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Waiting for thread to terminate\n");
/* Wait until the thread has terminated. */
if (RT_FAILURE(rc))
}
else
return rc;
}
{
for (;;)
{
int rc;
if (RT_FAILURE(rc))
{
if (rc != VERR_NOT_FOUND)
}
else
{
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Credentials available, notifying provider\n");
}
/* Wait a bit. */
{
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Terminating\n");
break;
}
}
return VINF_SUCCESS;
}