1 | /* $Id: VBoxCredProvFactory.cpp 40271 2012-02-28 11:22:04Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxCredentialProvFactory - The VirtualBox Credential Provider factory.
|
---|
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 "VBoxCredentialProvider.h"
|
---|
19 |
|
---|
20 | #include "VBoxCredProvFactory.h"
|
---|
21 | #include "VBoxCredProvProvider.h"
|
---|
22 |
|
---|
23 | extern HRESULT VBoxCredProvProviderCreate(REFIID interfaceID, void **ppvInterface);
|
---|
24 |
|
---|
25 | VBoxCredProvFactory::VBoxCredProvFactory(void)
|
---|
26 | : m_cRefCount(1) /* Start with one instance. */
|
---|
27 | {
|
---|
28 | }
|
---|
29 |
|
---|
30 | VBoxCredProvFactory::~VBoxCredProvFactory(void)
|
---|
31 | {
|
---|
32 | }
|
---|
33 |
|
---|
34 | /** IUnknown overrides. */
|
---|
35 | ULONG VBoxCredProvFactory::AddRef(void)
|
---|
36 | {
|
---|
37 | VBoxCredProvVerbose(0, "VBoxCredProvFactory: Increasing reference from %ld to %ld\n",
|
---|
38 | m_cRefCount, m_cRefCount + 1);
|
---|
39 |
|
---|
40 | return m_cRefCount++;
|
---|
41 | }
|
---|
42 |
|
---|
43 | ULONG VBoxCredProvFactory::Release(void)
|
---|
44 | {
|
---|
45 | VBoxCredProvVerbose(0, "VBoxCredProvFactory: Decreasing reference from %ld to %ld\n",
|
---|
46 | m_cRefCount, m_cRefCount - 1);
|
---|
47 |
|
---|
48 | ULONG cRefCount = --m_cRefCount;
|
---|
49 | if (!cRefCount)
|
---|
50 | {
|
---|
51 | VBoxCredProvVerbose(0, "VBoxCredProvFactory: Calling destructor\n");
|
---|
52 | delete this;
|
---|
53 | }
|
---|
54 | return cRefCount;
|
---|
55 | }
|
---|
56 |
|
---|
57 | HRESULT VBoxCredProvFactory::QueryInterface(REFIID interfaceID, void **ppvInterface)
|
---|
58 | {
|
---|
59 | HRESULT hr = S_OK;
|
---|
60 | if (ppvInterface)
|
---|
61 | {
|
---|
62 | if ( IID_IClassFactory == interfaceID
|
---|
63 | || IID_IUnknown == interfaceID)
|
---|
64 | {
|
---|
65 | *ppvInterface = static_cast<IUnknown*>(this);
|
---|
66 | reinterpret_cast<IUnknown*>(*ppvInterface)->AddRef();
|
---|
67 | }
|
---|
68 | else
|
---|
69 | {
|
---|
70 | *ppvInterface = NULL;
|
---|
71 | hr = E_NOINTERFACE;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | else
|
---|
75 | hr = E_INVALIDARG;
|
---|
76 | return hr;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /** IClassFactory overrides. This creates our actual credential provider. */
|
---|
80 | HRESULT VBoxCredProvFactory::CreateInstance(IUnknown* pUnkOuter,
|
---|
81 | REFIID interfaceID, void **ppvInterface)
|
---|
82 | {
|
---|
83 | if (pUnkOuter)
|
---|
84 | return CLASS_E_NOAGGREGATION;
|
---|
85 |
|
---|
86 | return VBoxCredProvProviderCreate(interfaceID, ppvInterface);
|
---|
87 | }
|
---|
88 |
|
---|
89 | HRESULT VBoxCredProvFactory::LockServer(BOOL bLock)
|
---|
90 | {
|
---|
91 | bLock ? VBoxCredentialProviderAcquire() : VBoxCredentialProviderRelease();
|
---|
92 | return S_OK;
|
---|
93 | }
|
---|
94 |
|
---|