VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxCredProv/VBoxCredProvPoller.cpp@ 40388

Last change on this file since 40388 was 40271, checked in by vboxsync, 13 years ago

VBoxCredProv: fixed svn properties

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* $Id: VBoxCredProvPoller.cpp 40271 2012-02-28 11:22:04Z vboxsync $ */
2/** @file
3 * VBoxCredPoller - Thread for querying / retrieving user credentials.
4 */
5
6/*
7 * Copyright (C) 2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include <windows.h>
19
20#include <VBox/VBoxGuest.h>
21#include <VBox/VBoxGuestLib.h>
22#include <VBox/VMMDev.h>
23#include <iprt/string.h>
24
25#include "VBoxCredProvProvider.h"
26
27#include "VBoxCredProvCredential.h"
28#include "VBoxCredProvPoller.h"
29#include "VBoxCredProvUtils.h"
30
31
32VBoxCredProvPoller::VBoxCredProvPoller(void) :
33 m_hThreadPoller(NIL_RTTHREAD),
34 m_pProv(NULL)
35{
36}
37
38
39VBoxCredProvPoller::~VBoxCredProvPoller(void)
40{
41 Shutdown();
42}
43
44
45int VBoxCredProvPoller::Initialize(VBoxCredProvProvider *pProvider)
46{
47 AssertPtrReturn(pProvider, VERR_INVALID_POINTER);
48
49 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Initializing\n");
50
51 /* Don't create more than one of them. */
52 if (m_hThreadPoller != NIL_RTTHREAD)
53 {
54 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Thread already running, returning!\n");
55 return VINF_SUCCESS;
56 }
57
58 if (m_pProv != NULL)
59 m_pProv->Release();
60 m_pProv = pProvider;
61 AssertPtr(m_pProv);
62
63 /* Create the poller thread. */
64 int rc = RTThreadCreate(&m_hThreadPoller, VBoxCredProvPoller::threadPoller, this, 0, RTTHREADTYPE_INFREQUENT_POLLER,
65 RTTHREADFLAGS_WAITABLE, "credpoll");
66 if (RT_FAILURE(rc))
67 VBoxCredProvVerbose(0, "VBoxCredProvPoller::Initialize: Failed to create thread, rc=%Rrc\n", rc);
68
69 return rc;
70}
71
72
73int VBoxCredProvPoller::Shutdown(void)
74{
75 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Shutdown\n");
76
77 if (m_hThreadPoller == NIL_RTTHREAD)
78 return VINF_SUCCESS;
79
80 /* Post termination event semaphore. */
81 int rc = RTThreadUserSignal(m_hThreadPoller);
82 if (RT_SUCCESS(rc))
83 {
84 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Waiting for thread to terminate\n");
85 /* Wait until the thread has terminated. */
86 rc = RTThreadWait(m_hThreadPoller, RT_INDEFINITE_WAIT, NULL);
87 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Thread has (probably) terminated (rc=%Rrc)\n", rc);
88 }
89 else
90 {
91 /* Failed to signal the thread - very unlikely - so no point in waiting long. */
92 VBoxCredProvVerbose(0, "VBoxCredProvPoller::Shutdown: Failed to signal semaphore, rc=%Rrc\n", rc);
93 rc = RTThreadWait(m_hThreadPoller, 100, NULL);
94 VBoxCredProvVerbose(0, "VBoxCredProvPoller::Shutdown: Thread has terminated? Wait rc=%Rrc\n", rc);
95 }
96
97 m_hThreadPoller = NIL_RTTHREAD;
98 return rc;
99}
100
101
102DECLCALLBACK(int) VBoxCredProvPoller::threadPoller(RTTHREAD ThreadSelf, void *pvUser)
103{
104 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Starting, pvUser=0x%p\n", pvUser);
105
106 VBoxCredProvPoller *pThis = (VBoxCredProvPoller*)pvUser;
107 AssertPtr(pThis);
108
109 for (;;)
110 {
111 int rc;
112 rc = VbglR3CredentialsQueryAvailability();
113 if (RT_FAILURE(rc))
114 {
115 if (rc != VERR_NOT_FOUND)
116 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Could not retrieve credentials! rc=%Rc\n", rc);
117 }
118 else
119 {
120 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Credentials available, notifying provider\n");
121
122 if (pThis->m_pProv)
123 pThis->m_pProv->OnCredentialsProvided();
124 }
125
126 /* Wait a bit. */
127 if (RTThreadUserWait(ThreadSelf, 500) == VINF_SUCCESS)
128 {
129 VBoxCredProvVerbose(0, "VBoxCredProvPoller: Terminating\n");
130 break;
131 }
132 }
133
134 return VINF_SUCCESS;
135}
136
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette