VirtualBox

source: vbox/trunk/src/VBox/Main/include/SharedFolderImpl.h@ 4040

Last change on this file since 4040 was 4040, checked in by vboxsync, 18 years ago

Main: Converted SharedFolder class to the new locking scheme.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef ____H_SHAREDFOLDERIMPL
23#define ____H_SHAREDFOLDERIMPL
24
25#include "VirtualBoxBase.h"
26#include "Collection.h"
27#include <VBox/shflsvc.h>
28
29class Machine;
30class Console;
31class VirtualBox;
32
33class ATL_NO_VTABLE SharedFolder :
34 public VirtualBoxBaseNEXT,
35 public VirtualBoxSupportErrorInfoImpl <SharedFolder, ISharedFolder>,
36 public VirtualBoxSupportTranslation <SharedFolder>,
37 public ISharedFolder
38{
39public:
40
41 struct Data
42 {
43 Data() {}
44
45 const Bstr mName;
46 const Bstr mHostPath;
47 };
48
49 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (SharedFolder)
50
51 DECLARE_NOT_AGGREGATABLE(SharedFolder)
52
53 DECLARE_PROTECT_FINAL_CONSTRUCT()
54
55 BEGIN_COM_MAP(SharedFolder)
56 COM_INTERFACE_ENTRY(ISupportErrorInfo)
57 COM_INTERFACE_ENTRY(ISharedFolder)
58 END_COM_MAP()
59
60 NS_DECL_ISUPPORTS
61
62 DECLARE_EMPTY_CTOR_DTOR (SharedFolder)
63
64 HRESULT FinalConstruct();
65 void FinalRelease();
66
67 // public initializer/uninitializer for internal purposes only
68 HRESULT init (Machine *aMachine, const BSTR aName, const BSTR aHostPath);
69 HRESULT initCopy (Machine *aMachine, SharedFolder *aThat);
70 HRESULT init (Console *aConsole, const BSTR aName, const BSTR aHostPath);
71 HRESULT init (VirtualBox *aVirtualBox, const BSTR aName, const BSTR aHostPath);
72 void uninit();
73
74 // ISharedFolder properties
75 STDMETHOD(COMGETTER(Name)) (BSTR *aName);
76 STDMETHOD(COMGETTER(HostPath)) (BSTR *aHostPath);
77 STDMETHOD(COMGETTER(Accessible)) (BOOL *aAccessible);
78
79 // public methods for internal purposes only
80 // (ensure there is a caller and a read lock before calling them!)
81
82 // public methods that don't need a lock (because access constant data)
83 // (ensure there is a caller added before calling them!)
84
85 const Bstr &name() const { return mData.mName; }
86 const Bstr &hostPath() const { return mData.mHostPath; }
87
88 // for VirtualBoxSupportErrorInfoImpl
89 static const wchar_t *getComponentName() { return L"SharedFolder"; }
90
91protected:
92
93 HRESULT protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent,
94 const BSTR aName, const BSTR aHostPath);
95
96private:
97
98 VirtualBoxBaseWithChildrenNEXT *const mParent;
99
100 /* weak parents (only one of them is not null) */
101 const ComObjPtr <Machine, ComWeakRef> mMachine;
102 const ComObjPtr <Console, ComWeakRef> mConsole;
103 const ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
104
105 Data mData;
106};
107
108COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (SharedFolder)
109
110 STDMETHOD(FindByName) (INPTR BSTR aName, ISharedFolder **aSharedFolder)
111 {
112 if (!aName)
113 return E_INVALIDARG;
114 if (!aSharedFolder)
115 return E_POINTER;
116
117 *aSharedFolder = NULL;
118 Vector::value_type found;
119 Vector::iterator it = vec.begin();
120 while (it != vec.end() && !found)
121 {
122 Bstr name;
123 (*it)->COMGETTER(Name) (name.asOutParam());
124 if (name == aName)
125 found = *it;
126 ++ it;
127 }
128
129 if (!found)
130 return setError (E_INVALIDARG, SharedFolderCollection::tr (
131 "Could not find the shared folder '%ls'"), aName);
132
133 return found.queryInterfaceTo (aSharedFolder);
134 }
135
136COM_DECL_READONLY_ENUM_AND_COLLECTION_END (SharedFolder)
137
138#endif // ____H_SHAREDFOLDERIMPL
Note: See TracBrowser for help on using the repository browser.

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