VirtualBox

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

Last change on this file since 16560 was 16215, checked in by vboxsync, 15 years ago

Reapplied r41613.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
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 name;
46 const Bstr hostPath;
47 BOOL writable;
48 Bstr lastAccessError;
49 };
50
51 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (SharedFolder)
52
53 DECLARE_NOT_AGGREGATABLE(SharedFolder)
54
55 DECLARE_PROTECT_FINAL_CONSTRUCT()
56
57 BEGIN_COM_MAP(SharedFolder)
58 COM_INTERFACE_ENTRY(ISupportErrorInfo)
59 COM_INTERFACE_ENTRY(ISharedFolder)
60 END_COM_MAP()
61
62 NS_DECL_ISUPPORTS
63
64 DECLARE_EMPTY_CTOR_DTOR (SharedFolder)
65
66 HRESULT FinalConstruct();
67 void FinalRelease();
68
69 // public initializer/uninitializer for internal purposes only
70 HRESULT init (Machine *aMachine, CBSTR aName, CBSTR aHostPath, BOOL aWritable);
71 HRESULT initCopy (Machine *aMachine, SharedFolder *aThat);
72 HRESULT init (Console *aConsole, CBSTR aName, CBSTR aHostPath, BOOL aWritable);
73 HRESULT init (VirtualBox *aVirtualBox, CBSTR aName, CBSTR aHostPath, BOOL aWritable);
74 void uninit();
75
76 // ISharedFolder properties
77 STDMETHOD(COMGETTER(Name)) (BSTR *aName);
78 STDMETHOD(COMGETTER(HostPath)) (BSTR *aHostPath);
79 STDMETHOD(COMGETTER(Accessible)) (BOOL *aAccessible);
80 STDMETHOD(COMGETTER(Writable)) (BOOL *aWritable);
81 STDMETHOD(COMGETTER(LastAccessError)) (BSTR *aLastAccessError);
82
83 // public methods for internal purposes only
84 // (ensure there is a caller and a read lock before calling them!)
85
86 // public methods that don't need a lock (because access constant data)
87 // (ensure there is a caller added before calling them!)
88
89 const Bstr &name() const { return m.name; }
90 const Bstr &hostPath() const { return m.hostPath; }
91 BOOL writable() const { return m.writable; }
92
93 // for VirtualBoxSupportErrorInfoImpl
94 static const wchar_t *getComponentName() { return L"SharedFolder"; }
95
96protected:
97
98 HRESULT protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent,
99 CBSTR aName, CBSTR aHostPath, BOOL aWritable);
100
101private:
102
103 VirtualBoxBaseWithChildrenNEXT *const mParent;
104
105 /* weak parents (only one of them is not null) */
106 const ComObjPtr <Machine, ComWeakRef> mMachine;
107 const ComObjPtr <Console, ComWeakRef> mConsole;
108 const ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
109
110 Data m;
111};
112
113COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (SharedFolder)
114
115 STDMETHOD(FindByName) (IN_BSTR aName, ISharedFolder **aSharedFolder)
116 {
117 if (!aName)
118 return E_INVALIDARG;
119 if (!aSharedFolder)
120 return E_POINTER;
121
122 *aSharedFolder = NULL;
123 Vector::value_type found;
124 Vector::iterator it = vec.begin();
125 while (it != vec.end() && !found)
126 {
127 Bstr name;
128 (*it)->COMGETTER(Name) (name.asOutParam());
129 if (name == aName)
130 found = *it;
131 ++ it;
132 }
133
134 if (!found)
135 return setError (E_INVALIDARG, SharedFolderCollection::tr (
136 "Could not find the shared folder '%ls'"), aName);
137
138 return found.queryInterfaceTo (aSharedFolder);
139 }
140
141COM_DECL_READONLY_ENUM_AND_COLLECTION_END (SharedFolder)
142
143#endif // ____H_SHAREDFOLDERIMPL
144/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use