Changeset 4040 in vbox for trunk/src/VBox/Main
- Timestamp:
- Aug 6, 2007 12:40:31 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 23475
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/SharedFolderImpl.cpp
r3668 r4040 34 34 ///////////////////////////////////////////////////////////////////////////// 35 35 36 SharedFolder::SharedFolder() 37 : mParent (NULL) 38 { 39 } 40 41 SharedFolder::~SharedFolder() 42 { 43 } 44 36 45 HRESULT SharedFolder::FinalConstruct() 37 46 { … … 59 68 const BSTR aName, const BSTR aHostPath) 60 69 { 61 AutoLock alock (this); 62 ComAssertRet (!isReady(), E_UNEXPECTED); 63 64 mMachine = aMachine; 65 return protectedInit (aMachine, aName, aHostPath); 70 /* Enclose the state transition NotReady->InInit->Ready */ 71 AutoInitSpan autoInitSpan (this); 72 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 73 74 unconst (mMachine) = aMachine; 75 76 HRESULT rc = protectedInit (aMachine, aName, aHostPath); 77 78 /* Confirm a successful initialization when it's the case */ 79 if (SUCCEEDED (rc)) 80 autoInitSpan.setSucceeded(); 81 82 return rc; 66 83 } 67 84 … … 80 97 ComAssertRet (aThat, E_INVALIDARG); 81 98 82 AutoLock alock (this); 83 ComAssertRet (!isReady(), E_UNEXPECTED); 84 85 mMachine = aMachine; 86 return protectedInit (aMachine, aThat->mName, aThat->mHostPath); 99 /* Enclose the state transition NotReady->InInit->Ready */ 100 AutoInitSpan autoInitSpan (this); 101 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 102 103 unconst (mMachine) = aMachine; 104 105 HRESULT rc = protectedInit (aMachine, aThat->mData.mName, 106 aThat->mData.mHostPath); 107 108 /* Confirm a successful initialization when it's the case */ 109 if (SUCCEEDED (rc)) 110 autoInitSpan.setSucceeded(); 111 112 return rc; 87 113 } 88 114 … … 99 125 const BSTR aName, const BSTR aHostPath) 100 126 { 101 AutoLock alock (this); 102 ComAssertRet (!isReady(), E_UNEXPECTED); 103 104 mConsole = aConsole; 105 return protectedInit (aConsole, aName, aHostPath); 127 /* Enclose the state transition NotReady->InInit->Ready */ 128 AutoInitSpan autoInitSpan (this); 129 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 130 131 unconst (mConsole) = aConsole; 132 133 HRESULT rc = protectedInit (aConsole, aName, aHostPath); 134 135 /* Confirm a successful initialization when it's the case */ 136 if (SUCCEEDED (rc)) 137 autoInitSpan.setSucceeded(); 138 139 return rc; 106 140 } 107 141 … … 118 152 const BSTR aName, const BSTR aHostPath) 119 153 { 120 AutoLock alock (this); 121 ComAssertRet (!isReady(), E_UNEXPECTED); 122 123 mVirtualBox = aVirtualBox; 124 return protectedInit (aVirtualBox, aName, aHostPath); 154 /* Enclose the state transition NotReady->InInit->Ready */ 155 AutoInitSpan autoInitSpan (this); 156 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 157 158 unconst (mVirtualBox) = aVirtualBox; 159 160 HRESULT rc = protectedInit (aVirtualBox, aName, aHostPath); 161 162 /* Confirm a successful initialization when it's the case */ 163 if (SUCCEEDED (rc)) 164 autoInitSpan.setSucceeded(); 165 166 return rc; 125 167 } 126 168 … … 131 173 * Must be called from under the object's lock! 132 174 */ 133 HRESULT SharedFolder::protectedInit (VirtualBoxBaseWithChildren *aParent,175 HRESULT SharedFolder::protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent, 134 176 const BSTR aName, const BSTR aHostPath) 135 177 { … … 171 213 tr ("Shared folder path '%s' is not absolute"), hostPath.raw()); 172 214 173 mParent = aParent; 174 unconst (mName) = aName; 175 unconst (mHostPath) = hostPath; 176 215 unconst (mParent) = aParent; 216 217 /* register with parent */ 177 218 mParent->addDependentChild (this); 178 219 179 setReady (true); 220 unconst (mData.mName) = aName; 221 unconst (mData.mHostPath) = hostPath; 222 180 223 return S_OK; 181 224 } … … 187 230 void SharedFolder::uninit() 188 231 { 189 LogFlowMember (("SharedFolder::uninit()\n")); 190 191 AutoLock alock (this); 192 193 LogFlowMember (("SharedFolder::uninit(): isReady=%d\n", isReady())); 194 if (!isReady()) 232 LogFlowThisFunc (("\n")); 233 234 /* Enclose the state transition Ready->InUninit->NotReady */ 235 AutoUninitSpan autoUninitSpan (this); 236 if (autoUninitSpan.uninitDone()) 195 237 return; 196 238 197 setReady (false); 198 199 alock.leave(); 200 mParent->removeDependentChild (this); 239 if (mParent) 240 mParent->removeDependentChild (this); 241 242 unconst (mParent) = NULL; 243 244 unconst (mMachine).setNull(); 245 unconst (mConsole).setNull(); 246 unconst (mVirtualBox).setNull(); 201 247 } 202 248 … … 209 255 return E_POINTER; 210 256 211 AutoLock alock (this); 212 CHECK_READY(); 213 214 mName.cloneTo (aName); 257 AutoCaller autoCaller (this); 258 CheckComRCReturnRC (autoCaller.rc()); 259 260 /* mName is constant during life time, no need to lock */ 261 mData.mName.cloneTo (aName); 262 215 263 return S_OK; 216 264 } … … 221 269 return E_POINTER; 222 270 223 AutoLock alock (this); 224 CHECK_READY(); 225 226 mHostPath.cloneTo (aHostPath); 271 AutoCaller autoCaller (this); 272 CheckComRCReturnRC (autoCaller.rc()); 273 274 /* mHostPath is constant during life time, no need to lock */ 275 mData.mHostPath.cloneTo (aHostPath); 276 227 277 return S_OK; 228 278 } … … 233 283 return E_POINTER; 234 284 235 AutoLock alock (this); 236 CHECK_READY(); 237 238 // check whether the host path exists 239 Utf8Str hostPath = Utf8Str (mHostPath); 285 AutoCaller autoCaller (this); 286 CheckComRCReturnRC (autoCaller.rc()); 287 288 /* mName and mHostPath are constant during life time, no need to lock */ 289 290 /* check whether the host path exists */ 291 Utf8Str hostPath = Utf8Str (mData.mHostPath); 240 292 char hostPathFull [RTPATH_MAX]; 241 int vrc = RTPathExists(hostPath) ? RTPathReal (hostPath, hostPathFull, sizeof (hostPathFull)) 293 int vrc = RTPathExists(hostPath) ? RTPathReal (hostPath, hostPathFull, 294 sizeof (hostPathFull)) 242 295 : VERR_PATH_NOT_FOUND; 243 296 if (VBOX_SUCCESS (vrc)) … … 252 305 tr ("Invalid shared folder path: '%s' (%Vrc)"), hostPath.raw(), vrc); 253 306 254 Log (("SharedFolder::COMGETTER(Accessible): WARNING: '%s' " 255 "is not accessible (%Vrc)\n", hostPath.raw(), vrc)); 307 LogWarningThisFunc (("'%s' is not accessible (%Vrc)\n", hostPath.raw(), vrc)); 256 308 257 309 *aAccessible = FALSE; -
trunk/src/VBox/Main/include/SharedFolderImpl.h
r2981 r4040 32 32 33 33 class ATL_NO_VTABLE SharedFolder : 34 public VirtualBoxBaseNEXT, 34 35 public VirtualBoxSupportErrorInfoImpl <SharedFolder, ISharedFolder>, 35 36 public VirtualBoxSupportTranslation <SharedFolder>, 36 public VirtualBoxBase,37 37 public ISharedFolder 38 38 { 39 39 public: 40 40 41 // to satisfy the ComObjPtr template (we have const members) 42 SharedFolder() {} 41 struct Data 42 { 43 Data() {} 44 45 const Bstr mName; 46 const Bstr mHostPath; 47 }; 48 49 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (SharedFolder) 43 50 44 51 DECLARE_NOT_AGGREGATABLE(SharedFolder) … … 52 59 53 60 NS_DECL_ISUPPORTS 61 62 DECLARE_EMPTY_CTOR_DTOR (SharedFolder) 54 63 55 64 HRESULT FinalConstruct(); … … 69 78 70 79 // public methods for internal purposes only 80 // (ensure there is a caller and a read lock before calling them!) 71 81 72 const Bstr &name() const { return mName; } 73 const Bstr &hostPath() const { return mHostPath; } 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; } 74 87 75 88 // for VirtualBoxSupportErrorInfoImpl … … 78 91 protected: 79 92 80 HRESULT protectedInit (VirtualBoxBaseWithChildren *aParent,93 HRESULT protectedInit (VirtualBoxBaseWithChildrenNEXT *aParent, 81 94 const BSTR aName, const BSTR aHostPath); 82 95 83 96 private: 84 97 85 VirtualBoxBaseWithChildren *mParent;98 VirtualBoxBaseWithChildrenNEXT *const mParent; 86 99 87 100 /* weak parents (only one of them is not null) */ 88 ComObjPtr <Machine, ComWeakRef> mMachine;89 ComObjPtr <Console, ComWeakRef> mConsole;90 ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;101 const ComObjPtr <Machine, ComWeakRef> mMachine; 102 const ComObjPtr <Console, ComWeakRef> mConsole; 103 const ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox; 91 104 92 const Bstr mName; 93 const Bstr mHostPath; 105 Data mData; 94 106 }; 95 107 … … 117 129 if (!found) 118 130 return setError (E_INVALIDARG, SharedFolderCollection::tr ( 119 " Shared folder named '%ls' could not be found"), aName);131 "Could not find the shared folder '%ls'"), aName); 120 132 121 133 return found.queryInterfaceTo (aSharedFolder);
Note:
See TracChangeset
for help on using the changeset viewer.