Changeset 35755 in vbox
- Timestamp:
- Jan 28, 2011 11:36:42 AM (14 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/ConsoleImpl.h
r35722 r35755 406 406 { 407 407 public: 408 SharedFolderData() {} 409 SharedFolderData(Bstr aHostPath, BOOL aWritable, BOOL aAutoMount) 410 : mHostPath(aHostPath) 411 , mWritable(aWritable) 412 , mAutoMount(aAutoMount) {} 408 SharedFolderData() 409 { } 410 411 SharedFolderData(const Utf8Str &aHostPath, 412 bool aWritable, 413 bool aAutoMount) 414 : m_strHostPath(aHostPath), 415 m_fWritable(aWritable), 416 m_fAutoMount(aAutoMount) 417 { } 418 419 // copy constructor 413 420 SharedFolderData(const SharedFolderData& aThat) 414 : mHostPath(aThat.mHostPath) 415 , mWritable(aThat.mWritable) 416 , mAutoMount(aThat.mAutoMount) {} 417 Bstr mHostPath; 418 BOOL mWritable; 419 BOOL mAutoMount; 421 : m_strHostPath(aThat.m_strHostPath), 422 m_fWritable(aThat.m_fWritable), 423 m_fAutoMount(aThat.m_fAutoMount) 424 { } 425 426 Utf8Str m_strHostPath; 427 bool m_fWritable; 428 bool m_fAutoMount; 420 429 }; 421 typedef std::map <Bstr, ComObjPtr<SharedFolder> > SharedFolderMap; 422 typedef std::map <Bstr, SharedFolderData> SharedFolderDataMap; 430 431 typedef std::map<Utf8Str, ComObjPtr<SharedFolder> > SharedFolderMap; 432 typedef std::map<Utf8Str, SharedFolderData> SharedFolderDataMap; 423 433 424 434 private: … … 449 459 } 450 460 451 HRESULT findSharedFolder( CBSTR aName,461 HRESULT findSharedFolder(const Utf8Str &strName, 452 462 ComObjPtr<SharedFolder> &aSharedFolder, 453 463 bool aSetError = false); 454 464 455 465 HRESULT fetchSharedFolders(BOOL aGlobal); 456 bool findOtherSharedFolder( IN_BSTRaName,466 bool findOtherSharedFolder(const Utf8Str &straName, 457 467 SharedFolderDataMap::const_iterator &aIt); 458 468 459 HRESULT createSharedFolder( CBSTR aName, SharedFolderDataaData);460 HRESULT removeSharedFolder( CBSTR aName);469 HRESULT createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData); 470 HRESULT removeSharedFolder(const Utf8Str &strName); 461 471 462 472 static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole); … … 631 641 RemoteUSBDeviceList mRemoteUSBDevices; 632 642 633 SharedFolder Map mSharedFolders;634 SharedFolderDataMap m MachineSharedFolders;635 SharedFolder DataMap mGlobalSharedFolders;643 SharedFolderDataMap m_mapGlobalSharedFolders; 644 SharedFolderDataMap m_mapMachineSharedFolders; 645 SharedFolderMap m_mapSharedFolders; // the console instances 636 646 637 647 /** The VM instance handle. */ -
trunk/src/VBox/Main/include/MachineImpl.h
r35676 r35755 726 726 virtual HRESULT setMachineState(MachineState_T aMachineState); 727 727 728 HRESULT findSharedFolder( CBSTRaName,728 HRESULT findSharedFolder(const Utf8Str &aName, 729 729 ComObjPtr<SharedFolder> &aSharedFolder, 730 730 bool aSetError = false); -
trunk/src/VBox/Main/include/SharedFolderImpl.h
r35638 r35755 30 30 public: 31 31 32 struct Data33 {34 Data() {}35 36 const Bstr name;37 const Bstr hostPath;38 BOOL writable;39 BOOL autoMount;40 Bstr lastAccessError;41 };42 43 32 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SharedFolder, ISharedFolder) 44 33 … … 57 46 58 47 // public initializer/uninitializer for internal purposes only 59 HRESULT init(Machine *aMachine, CBSTR aName, CBSTR aHostPath, BOOL aWritable, BOOLaAutoMount);48 HRESULT init(Machine *aMachine, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount); 60 49 HRESULT initCopy(Machine *aMachine, SharedFolder *aThat); 61 HRESULT init(Console *aConsole, CBSTR aName, CBSTR aHostPath, BOOL aWritable, BOOLaAutoMount);62 HRESULT init(VirtualBox *aVirtualBox, CBSTR aName, CBSTR aHostPath, BOOL aWritable, BOOLaAutoMount);50 HRESULT init(Console *aConsole, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount); 51 HRESULT init(VirtualBox *aVirtualBox, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount); 63 52 void uninit(); 64 53 … … 74 63 // (ensure there is a caller and a read lock before calling them!) 75 64 76 // public methods that don't need a lock (because access constant data) 77 // (ensure there is a caller added before calling them!) 65 /** 66 * Public internal method. Returns the shared folder's name. Needs caller! Locking not necessary. 67 * @return 68 */ 69 const Utf8Str& getName() const; 78 70 79 const Bstr& getName() const { return m.name; } 80 const Bstr& getHostPath() const { return m.hostPath; } 81 BOOL isWritable() const { return m.writable; } 82 BOOL isAutoMounted() const { return m.autoMount; } 71 /** 72 * Public internal method. Returns the shared folder's host path. Needs caller! Locking not necessary. 73 * @return 74 */ 75 const Utf8Str& getHostPath() const; 76 77 /** 78 * Public internal method. Returns true if the shared folder is writable. Needs caller and locking! 79 * @return 80 */ 81 bool isWritable() const; 82 83 /** 84 * Public internal method. Returns true if the shared folder is auto-mounted. Needs caller and locking! 85 * @return 86 */ 87 bool isAutoMounted() const; 83 88 84 89 protected: 85 90 86 HRESULT protectedInit(VirtualBoxBase *aParent, 87 CBSTR aName, CBSTR aHostPath, 88 BOOL aWritable, BOOL aAutoMount); 91 HRESULT protectedInit(VirtualBoxBase *aParent, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount); 89 92 private: 90 93 … … 96 99 VirtualBox * const mVirtualBox; 97 100 98 Data m; 101 struct Data; // opaque data struct, defined in SharedFolderImpl.cpp 102 Data *m; 99 103 }; 100 104 -
trunk/src/VBox/Main/src-all/SharedFolderImpl.cpp
r35638 r35755 28 28 #include <iprt/path.h> 29 29 30 ///////////////////////////////////////////////////////////////////////////// 31 // SharedFolder::Data structure 32 ///////////////////////////////////////////////////////////////////////////// 33 34 struct SharedFolder::Data 35 { 36 Data() 37 : fWritable(false), 38 fAutoMount(false) 39 { } 40 41 const Utf8Str strName; 42 const Utf8Str strHostPath; 43 bool fWritable; 44 bool fAutoMount; 45 Utf8Str strLastAccessError; 46 }; 47 30 48 // constructor / destructor 31 49 ///////////////////////////////////////////////////////////////////////////// … … 37 55 mVirtualBox(NULL) 38 56 { 57 m = new Data; 39 58 } 40 59 41 60 SharedFolder::~SharedFolder() 42 61 { 62 delete m; 63 m = NULL; 43 64 } 44 65 … … 68 89 * @return COM result indicator 69 90 */ 70 HRESULT SharedFolder::init (Machine *aMachine, 71 CBSTR aName, CBSTR aHostPath, BOOL aWritable, BOOL aAutoMount) 91 HRESULT SharedFolder::init(Machine *aMachine, 92 const Utf8Str &aName, 93 const Utf8Str &aHostPath, 94 bool aWritable, 95 bool aAutoMount) 72 96 { 73 97 /* Enclose the state transition NotReady->InInit->Ready */ … … 96 120 * @return COM result indicator 97 121 */ 98 HRESULT SharedFolder::initCopy 122 HRESULT SharedFolder::initCopy(Machine *aMachine, SharedFolder *aThat) 99 123 { 100 124 ComAssertRet(aThat, E_INVALIDARG); … … 106 130 unconst(mMachine) = aMachine; 107 131 108 HRESULT rc = protectedInit(aMachine, aThat->m.name.raw(), 109 aThat->m.hostPath.raw(), aThat->m.writable, 110 aThat->m.autoMount); 132 HRESULT rc = protectedInit(aMachine, 133 aThat->m->strName, 134 aThat->m->strHostPath, 135 aThat->m->fWritable, 136 aThat->m->fAutoMount); 111 137 112 138 /* Confirm a successful initialization when it's the case */ … … 118 144 119 145 /** 120 * Initializes the shared folder object. 146 * Initializes the shared folder object. This variant gets called when 147 * the shared folder lives in the Console address space. 121 148 * 122 149 * @param aConsole Console parent object … … 128 155 */ 129 156 HRESULT SharedFolder::init(Console *aConsole, 130 CBSTR aName, CBSTR aHostPath, BOOL aWritable, BOOL aAutoMount) 157 const Utf8Str &aName, 158 const Utf8Str &aHostPath, 159 bool aWritable, 160 bool aAutoMount) 131 161 { 132 162 /* Enclose the state transition NotReady->InInit->Ready */ … … 146 176 147 177 /** 148 * Initializes the shared folder object. 178 * Initializes the shared folder object. This variant gets called when 179 * the shared folder lives in the VirtualBox (server) address space. 149 180 * 150 181 * @param aVirtualBox VirtualBox parent object … … 155 186 * @return COM result indicator 156 187 */ 157 HRESULT SharedFolder::init (VirtualBox *aVirtualBox, 158 CBSTR aName, CBSTR aHostPath, BOOL aWritable, BOOL aAutoMount) 188 HRESULT SharedFolder::init(VirtualBox *aVirtualBox, 189 const Utf8Str &aName, 190 const Utf8Str &aHostPath, 191 bool aWritable, 192 bool aAutoMount) 159 193 { 160 194 /* Enclose the state transition NotReady->InInit->Ready */ … … 174 208 175 209 /** 176 * Helper for init() methods.210 * Shared initialization code. Called from the other constructors. 177 211 * 178 212 * @note … … 180 214 */ 181 215 HRESULT SharedFolder::protectedInit(VirtualBoxBase *aParent, 182 CBSTRaName,183 CBSTRaHostPath,184 BOOLaWritable,185 BOOLaAutoMount)186 { 187 LogFlowThisFunc(("aName={% ls}, aHostPath={%ls}, aWritable={%d}, aAutoMount={%d}\n",188 aName , aHostPath, aWritable, aAutoMount));189 190 ComAssertRet(aParent && aName && aHostPath, E_INVALIDARG);191 192 Utf8Str hostPath = Utf8Str (aHostPath);216 const Utf8Str &aName, 217 const Utf8Str &aHostPath, 218 bool aWritable, 219 bool aAutoMount) 220 { 221 LogFlowThisFunc(("aName={%s}, aHostPath={%s}, aWritable={%d}, aAutoMount={%d}\n", 222 aName.c_str(), aHostPath.c_str(), aWritable, aAutoMount)); 223 224 ComAssertRet(aParent && aName.isNotEmpty() && aHostPath.isNotEmpty(), E_INVALIDARG); 225 226 Utf8Str hostPath = aHostPath; 193 227 size_t hostPathLen = hostPath.length(); 194 228 … … 229 263 unconst(mParent) = aParent; 230 264 231 unconst(m .name) = aName;232 unconst(m .hostPath) = hostPath;233 m .writable = aWritable;234 m .autoMount = aAutoMount;265 unconst(m->strName) = aName; 266 unconst(m->strHostPath) = hostPath; 267 m->fWritable = aWritable; 268 m->fAutoMount = aAutoMount; 235 269 236 270 return S_OK; … … 268 302 269 303 /* mName is constant during life time, no need to lock */ 270 m .name.cloneTo(aName);304 m->strName.cloneTo(aName); 271 305 272 306 return S_OK; … … 281 315 282 316 /* mHostPath is constant during life time, no need to lock */ 283 m .hostPath.cloneTo(aHostPath);317 m->strHostPath.cloneTo(aHostPath); 284 318 285 319 return S_OK; … … 296 330 297 331 /* check whether the host path exists */ 298 Utf8Str hostPath = Utf8Str(m.hostPath);332 Utf8Str hostPath = m->strHostPath; 299 333 char hostPathFull[RTPATH_MAX]; 300 334 int vrc = RTPathExists(hostPath.c_str()) ? RTPathReal(hostPath.c_str(), … … 310 344 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 311 345 312 m.lastAccessError = BstrFmt ( 313 tr ("'%s' is not accessible (%Rrc)"), hostPath.c_str(), vrc); 314 315 LogWarningThisFunc(("m.lastAccessError=\"%ls\"\n", m.lastAccessError.raw())); 346 m->strLastAccessError = Utf8StrFmt(tr("'%s' is not accessible (%Rrc)"), 347 m->strHostPath.c_str(), 348 vrc); 349 350 LogWarningThisFunc(("m.lastAccessError=\"%s\"\n", m->strLastAccessError.c_str())); 316 351 317 352 *aAccessible = FALSE; … … 328 363 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 329 364 330 *aWritable = m.writable;365 *aWritable = !!m->fWritable; 331 366 332 367 return S_OK; … … 342 377 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 343 378 344 *aAutoMount = m.autoMount;379 *aAutoMount = !!m->fAutoMount; 345 380 346 381 return S_OK; … … 356 391 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 357 392 358 m.lastAccessError.cloneTo(aLastAccessError); 359 360 return S_OK; 393 m->strLastAccessError.cloneTo(aLastAccessError); 394 395 return S_OK; 396 } 397 398 const Utf8Str& SharedFolder::getName() const 399 { 400 return m->strName; 401 } 402 403 const Utf8Str& SharedFolder::getHostPath() const 404 { 405 return m->strHostPath; 406 } 407 408 bool SharedFolder::isWritable() const 409 { 410 return m->fWritable; 411 } 412 413 bool SharedFolder::isAutoMounted() const 414 { 415 return m->fAutoMount; 361 416 } 362 417 -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r35722 r35755 604 604 } 605 605 606 m GlobalSharedFolders.clear();607 m MachineSharedFolders.clear();608 609 mSharedFolders.clear(); 606 m_mapGlobalSharedFolders.clear(); 607 m_mapMachineSharedFolders.clear(); 608 m_mapSharedFolders.clear(); // console instances 609 610 610 mRemoteUSBDevices.clear(); 611 611 mUSBDevices.clear(); … … 1261 1261 AutoReadLock alock(that COMMA_LOCKVAL_SRC_POS); 1262 1262 1263 int vrc = SSMR3PutU32(pSSM, (uint32_t)that->m SharedFolders.size());1263 int vrc = SSMR3PutU32(pSSM, (uint32_t)that->m_mapSharedFolders.size()); 1264 1264 AssertRC(vrc); 1265 1265 1266 for (SharedFolderMap::const_iterator it = that->m SharedFolders.begin();1267 it != that->m SharedFolders.end();1266 for (SharedFolderMap::const_iterator it = that->m_mapSharedFolders.begin(); 1267 it != that->m_mapSharedFolders.end(); 1268 1268 ++ it) 1269 1269 { 1270 ComObjPtr<SharedFolder> pSharedFolder = (*it).second; 1271 // don't lock the folder because methods we access are const 1272 1273 Utf8Str name = pSharedFolder->getName(); 1270 SharedFolder *pSF = (*it).second; 1271 AutoCaller sfCaller(pSF); 1272 AutoReadLock sfLock(pSF COMMA_LOCKVAL_SRC_POS); 1273 1274 Utf8Str name = pSF->getName(); 1274 1275 vrc = SSMR3PutU32(pSSM, (uint32_t)name.length() + 1 /* term. 0 */); 1275 1276 AssertRC(vrc); … … 1277 1278 AssertRC(vrc); 1278 1279 1279 Utf8Str hostPath = pS haredFolder->getHostPath();1280 Utf8Str hostPath = pSF->getHostPath(); 1280 1281 vrc = SSMR3PutU32(pSSM, (uint32_t)hostPath.length() + 1 /* term. 0 */); 1281 1282 AssertRC(vrc); … … 1283 1284 AssertRC(vrc); 1284 1285 1285 vrc = SSMR3PutBool(pSSM, !!pS haredFolder->isWritable());1286 vrc = SSMR3PutBool(pSSM, !!pSF->isWritable()); 1286 1287 AssertRC(vrc); 1287 1288 1288 vrc = SSMR3PutBool(pSSM, !!pS haredFolder->isAutoMounted());1289 vrc = SSMR3PutBool(pSSM, !!pSF->isAutoMounted()); 1289 1290 AssertRC(vrc); 1290 1291 } … … 1339 1340 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 1340 1341 1341 AssertReturn(m SharedFolders.size() == 0, VERR_INTERNAL_ERROR);1342 AssertReturn(m_mapSharedFolders.size() == 0, VERR_INTERNAL_ERROR); 1342 1343 1343 1344 uint32_t size = 0; … … 1347 1348 for (uint32_t i = 0; i < size; ++ i) 1348 1349 { 1349 Bstr name;1350 Bstr hostPath;1350 Utf8Str strName; 1351 Utf8Str strHostPath; 1351 1352 bool writable = true; 1352 1353 bool autoMount = false; … … 1360 1361 vrc = SSMR3GetStrZ(pSSM, buf, szBuf); 1361 1362 AssertRC(vrc); 1362 name = buf;1363 strName = buf; 1363 1364 delete[] buf; 1364 1365 … … 1368 1369 vrc = SSMR3GetStrZ(pSSM, buf, szBuf); 1369 1370 AssertRC(vrc); 1370 hostPath = buf;1371 strHostPath = buf; 1371 1372 delete[] buf; 1372 1373 … … 1379 1380 ComObjPtr<SharedFolder> pSharedFolder; 1380 1381 pSharedFolder.createObject(); 1381 HRESULT rc = pSharedFolder->init(this, name.raw(), hostPath.raw(), 1382 writable, autoMount); 1382 HRESULT rc = pSharedFolder->init(this, 1383 strName, 1384 strHostPath, 1385 writable, 1386 autoMount); 1383 1387 AssertComRCReturn(rc, VERR_INTERNAL_ERROR); 1384 1388 1385 m SharedFolders.insert(std::make_pair(name, pSharedFolder));1389 m_mapSharedFolders.insert(std::make_pair(strName, pSharedFolder)); 1386 1390 } 1387 1391 … … 1700 1704 if (FAILED(rc)) return rc; 1701 1705 1702 SafeIfaceArray<ISharedFolder> sf(m SharedFolders);1706 SafeIfaceArray<ISharedFolder> sf(m_mapSharedFolders); 1703 1707 sf.detachTo(ComSafeArrayOutArg(aSharedFolders)); 1704 1708 … … 2850 2854 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2851 2855 2856 Utf8Str strName(aName); 2857 Utf8Str strHostPath(aHostPath); 2858 2852 2859 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 2853 2860 … … 2867 2874 2868 2875 ComObjPtr<SharedFolder> pSharedFolder; 2869 HRESULT rc = findSharedFolder( aName, pSharedFolder, false /* aSetError */);2876 HRESULT rc = findSharedFolder(strName, pSharedFolder, false /* aSetError */); 2870 2877 if (SUCCEEDED(rc)) 2871 2878 return setError(VBOX_E_FILE_ERROR, 2872 tr("Shared folder named '% ls' already exists"),2873 aName);2879 tr("Shared folder named '%s' already exists"), 2880 strName.c_str()); 2874 2881 2875 2882 pSharedFolder.createObject(); 2876 rc = pSharedFolder->init(this, aName, aHostPath, aWritable, aAutoMount);2883 rc = pSharedFolder->init(this, strName, strHostPath, aWritable, aAutoMount); 2877 2884 if (FAILED(rc)) return rc; 2878 2885 … … 2902 2909 } 2903 2910 2904 m SharedFolders.insert(std::make_pair(aName, pSharedFolder));2911 m_mapSharedFolders.insert(std::make_pair(aName, pSharedFolder)); 2905 2912 2906 2913 /* notify console callbacks after the folder is added to the list */ … … 2916 2923 AutoCaller autoCaller(this); 2917 2924 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 2925 2926 Utf8Str strName(aName); 2918 2927 2919 2928 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); … … 2950 2959 2951 2960 /* first, remove the given folder */ 2952 rc = removeSharedFolder( aName);2961 rc = removeSharedFolder(strName); 2953 2962 if (FAILED(rc)) return rc; 2954 2963 2955 2964 /* first, remove the machine or the global folder if there is any */ 2956 2965 SharedFolderDataMap::const_iterator it; 2957 if (findOtherSharedFolder( aName, it))2958 { 2959 rc = createSharedFolder( aName, it->second);2966 if (findOtherSharedFolder(strName, it)) 2967 { 2968 rc = createSharedFolder(strName, it->second); 2960 2969 /* don't check rc here because we need to remove the console 2961 2970 * folder from the collection even on failure */ … … 2963 2972 } 2964 2973 2965 m SharedFolders.erase(aName);2974 m_mapSharedFolders.erase(strName); 2966 2975 2967 2976 /* notify console callbacks after the folder is removed to the list */ … … 5527 5536 SharedFolderDataMap sharedFolders; 5528 5537 { 5538 // @todo umoeller 5539 5529 5540 /* first, insert global folders */ 5530 for (SharedFolderDataMap::const_iterator it = mGlobalSharedFolders.begin(); 5531 it != mGlobalSharedFolders.end(); ++ it) 5532 sharedFolders[it->first] = it->second; 5541 for (SharedFolderDataMap::const_iterator it = m_mapGlobalSharedFolders.begin(); 5542 it != m_mapGlobalSharedFolders.end(); 5543 ++it) 5544 { 5545 const SharedFolderData &d = it->second; 5546 sharedFolders[it->first] = d; 5547 } 5533 5548 5534 5549 /* second, insert machine folders */ 5535 for (SharedFolderDataMap::const_iterator it = mMachineSharedFolders.begin(); 5536 it != mMachineSharedFolders.end(); ++ it) 5537 sharedFolders[it->first] = it->second; 5550 for (SharedFolderDataMap::const_iterator it = m_mapMachineSharedFolders.begin(); 5551 it != m_mapMachineSharedFolders.end(); 5552 ++it) 5553 { 5554 const SharedFolderData &d = it->second; 5555 sharedFolders[it->first] = d; 5556 } 5538 5557 5539 5558 /* third, insert console folders */ 5540 for (SharedFolderMap::const_iterator it = mSharedFolders.begin(); 5541 it != mSharedFolders.end(); ++ it) 5542 sharedFolders[it->first] = SharedFolderData(it->second->getHostPath(), 5543 it->second->isWritable(), 5544 it->second->isAutoMounted()); 5559 for (SharedFolderMap::const_iterator it = m_mapSharedFolders.begin(); 5560 it != m_mapSharedFolders.end(); 5561 ++it) 5562 { 5563 SharedFolder *pSF = it->second; 5564 AutoCaller sfCaller(pSF); 5565 AutoReadLock sfLock(pSF COMMA_LOCKVAL_SRC_POS); 5566 sharedFolders[it->first] = SharedFolderData(pSF->getHostPath(), 5567 pSF->isWritable(), 5568 pSF->isAutoMounted()); 5569 } 5545 5570 } 5546 5571 … … 6135 6160 * @note The caller must lock this object for writing. 6136 6161 */ 6137 HRESULT Console::findSharedFolder( CBSTR aName,6162 HRESULT Console::findSharedFolder(const Utf8Str &strName, 6138 6163 ComObjPtr<SharedFolder> &aSharedFolder, 6139 6164 bool aSetError /* = false */) … … 6142 6167 AssertReturn(isWriteLockOnCurrentThread(), E_FAIL); 6143 6168 6144 SharedFolderMap::const_iterator it = m SharedFolders.find(aName);6145 if (it != m SharedFolders.end())6169 SharedFolderMap::const_iterator it = m_mapSharedFolders.find(strName); 6170 if (it != m_mapSharedFolders.end()) 6146 6171 { 6147 6172 aSharedFolder = it->second; … … 6151 6176 if (aSetError) 6152 6177 setError(VBOX_E_FILE_ERROR, 6153 tr("Could not find a shared folder named '% ls'."),6154 aName);6178 tr("Could not find a shared folder named '%s'."), 6179 strName.c_str()); 6155 6180 6156 6181 return VBOX_E_FILE_ERROR; … … 6188 6213 SharedFolderDataMap oldFolders; 6189 6214 if (online) 6190 oldFolders = m MachineSharedFolders;6191 6192 m MachineSharedFolders.clear();6215 oldFolders = m_mapMachineSharedFolders; 6216 6217 m_mapMachineSharedFolders.clear(); 6193 6218 6194 6219 SafeIfaceArray<ISharedFolder> folders; … … 6200 6225 ComPtr<ISharedFolder> pSharedFolder = folders[i]; 6201 6226 6202 Bstr name;6203 Bstr hostPath;6227 Bstr bstrName; 6228 Bstr bstrHostPath; 6204 6229 BOOL writable; 6205 6230 BOOL autoMount; 6206 6231 6207 rc = pSharedFolder->COMGETTER(Name)( name.asOutParam());6232 rc = pSharedFolder->COMGETTER(Name)(bstrName.asOutParam()); 6208 6233 if (FAILED(rc)) break; 6209 rc = pSharedFolder->COMGETTER(HostPath)(hostPath.asOutParam()); 6234 Utf8Str strName(bstrName); 6235 6236 rc = pSharedFolder->COMGETTER(HostPath)(bstrHostPath.asOutParam()); 6210 6237 if (FAILED(rc)) break; 6238 Utf8Str strHostPath(bstrHostPath); 6239 6211 6240 rc = pSharedFolder->COMGETTER(Writable)(&writable); 6212 6241 if (FAILED(rc)) break; 6242 6213 6243 rc = pSharedFolder->COMGETTER(AutoMount)(&autoMount); 6214 6244 if (FAILED(rc)) break; 6215 6245 6216 mMachineSharedFolders.insert(std::make_pair(name, SharedFolderData(hostPath, writable, autoMount))); 6246 m_mapMachineSharedFolders.insert(std::make_pair(strName, 6247 SharedFolderData(strHostPath, writable, autoMount))); 6217 6248 6218 6249 /* send changes to HGCM if the VM is running */ 6219 /// @todo report errors as runtime warnings through VMSetError6250 /// @todo umoeller report errors as runtime warnings through VMSetError 6220 6251 if (online) 6221 6252 { 6222 SharedFolderDataMap::iterator it = oldFolders.find(name); 6223 if (it == oldFolders.end() || it->second.mHostPath != hostPath) 6253 SharedFolderDataMap::iterator it = oldFolders.find(strName); 6254 if ( it == oldFolders.end() 6255 || it->second.m_strHostPath != strHostPath) 6224 6256 { 6225 6257 /* a new machine folder is added or 6226 6258 * the existing machine folder is changed */ 6227 if (m SharedFolders.find(name) != mSharedFolders.end())6259 if (m_mapSharedFolders.find(strName) != m_mapSharedFolders.end()) 6228 6260 ; /* the console folder exists, nothing to do */ 6229 6261 else … … 6231 6263 /* remove the old machine folder (when changed) 6232 6264 * or the global folder if any (when new) */ 6233 if ( it != oldFolders.end() ||6234 mGlobalSharedFolders.find(name) !=6235 mGlobalSharedFolders.end())6236 rc = removeSharedFolder( name.raw());6265 if ( it != oldFolders.end() 6266 || m_mapGlobalSharedFolders.find(strName) != m_mapGlobalSharedFolders.end() 6267 ) 6268 rc = removeSharedFolder(strName); 6237 6269 /* create the new machine folder */ 6238 rc = createSharedFolder( name.raw(),6239 SharedFolderData( hostPath,6270 rc = createSharedFolder(strName, 6271 SharedFolderData(strHostPath, 6240 6272 writable, 6241 6273 autoMount)); … … 6259 6291 it != oldFolders.end(); ++ it) 6260 6292 { 6261 if (m SharedFolders.find(it->first) != mSharedFolders.end())6293 if (m_mapSharedFolders.find(it->first) != m_mapSharedFolders.end()) 6262 6294 ; /* the console folder exists, nothing to do */ 6263 6295 else 6264 6296 { 6265 6297 /* remove the outdated machine folder */ 6266 rc = removeSharedFolder(it->first .raw());6298 rc = removeSharedFolder(it->first); 6267 6299 /* create the global folder if there is any */ 6268 6300 SharedFolderDataMap::const_iterator git = 6269 m GlobalSharedFolders.find(it->first);6270 if (git != m GlobalSharedFolders.end())6271 rc = createSharedFolder(git->first .raw(), git->second);6301 m_mapGlobalSharedFolders.find(it->first); 6302 if (git != m_mapGlobalSharedFolders.end()) 6303 rc = createSharedFolder(git->first, git->second); 6272 6304 } 6273 6305 } … … 6290 6322 * @note The caller must lock this object for reading. 6291 6323 */ 6292 bool Console::findOtherSharedFolder( IN_BSTR aName,6324 bool Console::findOtherSharedFolder(const Utf8Str &strName, 6293 6325 SharedFolderDataMap::const_iterator &aIt) 6294 6326 { … … 6297 6329 6298 6330 /* first, search machine folders */ 6299 aIt = m MachineSharedFolders.find(aName);6300 if (aIt != m MachineSharedFolders.end())6331 aIt = m_mapMachineSharedFolders.find(strName); 6332 if (aIt != m_mapMachineSharedFolders.end()) 6301 6333 return true; 6302 6334 6303 6335 /* second, search machine folders */ 6304 aIt = m GlobalSharedFolders.find(aName);6305 if (aIt != m GlobalSharedFolders.end())6336 aIt = m_mapGlobalSharedFolders.find(strName); 6337 if (aIt != m_mapGlobalSharedFolders.end()) 6306 6338 return true; 6307 6339 … … 6318 6350 * @note Doesn't lock anything. 6319 6351 */ 6320 HRESULT Console::createSharedFolder( CBSTR aName, SharedFolderDataaData)6321 { 6322 ComAssertRet( aName && *aName, E_FAIL);6323 ComAssertRet( !aData.mHostPath.isEmpty(), E_FAIL);6352 HRESULT Console::createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData) 6353 { 6354 ComAssertRet(strName.isNotEmpty(), E_FAIL); 6355 ComAssertRet(aData.m_strHostPath.isNotEmpty(), E_FAIL); 6324 6356 6325 6357 /* sanity checks */ … … 6331 6363 size_t cbString; 6332 6364 6333 Log(("Adding shared folder '%ls' -> '%ls'\n", aName, aData.mHostPath.raw())); 6334 6335 cbString = (RTUtf16Len(aData.mHostPath.raw()) + 1) * sizeof(RTUTF16); 6365 Log(("Adding shared folder '%s' -> '%s'\n", strName.c_str(), aData.m_strHostPath.c_str())); 6366 6367 Bstr bstrName(strName); 6368 Bstr bstrHostPath(aData.m_strHostPath); 6369 6370 cbString = (bstrHostPath.length() + 1) * sizeof(RTUTF16); 6336 6371 if (cbString >= UINT16_MAX) 6337 6372 return setError(E_INVALIDARG, tr("The name is too long")); 6338 pFolderName = (SHFLSTRING *)RTMemAllocZ(sizeof(SHFLSTRING) + cbString);6373 pFolderName = (SHFLSTRING*)RTMemAllocZ(sizeof(SHFLSTRING) + cbString); 6339 6374 Assert(pFolderName); 6340 memcpy(pFolderName->String.ucs2, aData.mHostPath.raw(), cbString);6375 memcpy(pFolderName->String.ucs2, bstrHostPath.raw(), cbString); 6341 6376 6342 6377 pFolderName->u16Size = (uint16_t)cbString; … … 6347 6382 parms[0].u.pointer.size = sizeof(SHFLSTRING) + (uint16_t)cbString; 6348 6383 6349 cbString = ( RTUtf16Len(aName) + 1) * sizeof(RTUTF16);6384 cbString = (bstrName.length() + 1) * sizeof(RTUTF16); 6350 6385 if (cbString >= UINT16_MAX) 6351 6386 { … … 6353 6388 return setError(E_INVALIDARG, tr("The host path is too long")); 6354 6389 } 6355 pMapName = (SHFLSTRING *)RTMemAllocZ(sizeof(SHFLSTRING) + cbString);6390 pMapName = (SHFLSTRING*)RTMemAllocZ(sizeof(SHFLSTRING) + cbString); 6356 6391 Assert(pMapName); 6357 memcpy(pMapName->String.ucs2, aName, cbString);6392 memcpy(pMapName->String.ucs2, bstrName.raw(), cbString); 6358 6393 6359 6394 pMapName->u16Size = (uint16_t)cbString; … … 6365 6400 6366 6401 parms[2].type = VBOX_HGCM_SVC_PARM_32BIT; 6367 parms[2].u.uint32 = aData.m Writable;6402 parms[2].u.uint32 = aData.m_fWritable; 6368 6403 6369 6404 /* … … 6374 6409 */ 6375 6410 parms[3].type = VBOX_HGCM_SVC_PARM_32BIT; 6376 parms[3].u.uint32 = aData.m AutoMount;6411 parms[3].u.uint32 = aData.m_fAutoMount; 6377 6412 6378 6413 int vrc = m_pVMMDev->hgcmHostCall("VBoxSharedFolders", … … 6384 6419 if (RT_FAILURE(vrc)) 6385 6420 return setError(E_FAIL, 6386 tr("Could not create a shared folder '% ls' mapped to '%ls' (%Rrc)"),6387 aName, aData.mHostPath.raw(), vrc);6421 tr("Could not create a shared folder '%s' mapped to '%s' (%Rrc)"), 6422 strName.c_str(), aData.m_strHostPath.c_str(), vrc); 6388 6423 6389 6424 return S_OK; … … 6398 6433 * @note Doesn't lock anything. 6399 6434 */ 6400 HRESULT Console::removeSharedFolder( CBSTR aName)6401 { 6402 ComAssertRet( aName && *aName, E_FAIL);6435 HRESULT Console::removeSharedFolder(const Utf8Str &strName) 6436 { 6437 ComAssertRet(strName.isNotEmpty(), E_FAIL); 6403 6438 6404 6439 /* sanity checks */ … … 6410 6445 size_t cbString; 6411 6446 6412 Log(("Removing shared folder '%ls'\n", aName)); 6413 6414 cbString = (RTUtf16Len(aName) + 1) * sizeof(RTUTF16); 6447 Log(("Removing shared folder '%s'\n", strName.c_str())); 6448 6449 Bstr bstrName(strName); 6450 cbString = (bstrName.length() + 1) * sizeof(RTUTF16); 6415 6451 if (cbString >= UINT16_MAX) 6416 6452 return setError(E_INVALIDARG, tr("The name is too long")); 6417 6453 pMapName = (SHFLSTRING *) RTMemAllocZ(sizeof(SHFLSTRING) + cbString); 6418 6454 Assert(pMapName); 6419 memcpy(pMapName->String.ucs2, aName, cbString);6455 memcpy(pMapName->String.ucs2, bstrName.raw(), cbString); 6420 6456 6421 6457 pMapName->u16Size = (uint16_t)cbString; … … 6432 6468 if (RT_FAILURE(vrc)) 6433 6469 return setError(E_FAIL, 6434 tr("Could not remove the shared folder '% ls' (%Rrc)"),6435 aName, vrc);6470 tr("Could not remove the shared folder '%s' (%Rrc)"), 6471 strName.c_str(), vrc); 6436 6472 6437 6473 return S_OK; … … 7793 7829 ++it) 7794 7830 { 7795 rc = pConsole->createSharedFolder((*it).first.raw(), 7796 (*it).second); 7831 const SharedFolderData &d = it->second; 7832 rc = pConsole->createSharedFolder(it->first, 7833 d); 7797 7834 if (FAILED(rc)) break; 7798 7835 } -
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r35676 r35755 7032 7032 * must be called from under the object's lock! 7033 7033 */ 7034 HRESULT Machine::findSharedFolder( CBSTRaName,7034 HRESULT Machine::findSharedFolder(const Utf8Str &aName, 7035 7035 ComObjPtr<SharedFolder> &aSharedFolder, 7036 7036 bool aSetError /* = false */) 7037 7037 { 7038 bool found = false;7038 HRESULT rc = VBOX_E_OBJECT_NOT_FOUND; 7039 7039 for (HWData::SharedFolderList::const_iterator it = mHWData->mSharedFolders.begin(); 7040 !found &&it != mHWData->mSharedFolders.end();7040 it != mHWData->mSharedFolders.end(); 7041 7041 ++it) 7042 7042 { 7043 AutoWriteLock alock(*it COMMA_LOCKVAL_SRC_POS); 7044 found = (*it)->getName() == aName; 7045 if (found) 7046 aSharedFolder = *it; 7047 } 7048 7049 HRESULT rc = found ? S_OK : VBOX_E_OBJECT_NOT_FOUND; 7050 7051 if (aSetError && !found) 7052 setError(rc, tr("Could not find a shared folder named '%ls'"), aName); 7043 SharedFolder *pSF = *it; 7044 AutoCaller autoCaller(pSF); 7045 if (pSF->getName() == aName) 7046 { 7047 aSharedFolder = pSF; 7048 rc = S_OK; 7049 break; 7050 } 7051 } 7052 7053 if (aSetError && FAILED(rc)) 7054 setError(rc, tr("Could not find a shared folder named '%s'"), aName.c_str()); 7053 7055 7054 7056 return rc; … … 8502 8504 ++it) 8503 8505 { 8504 ComObjPtr<SharedFolder> pFolder = *it; 8506 SharedFolder *pSF = *it; 8507 AutoCaller sfCaller(pSF); 8508 AutoReadLock sfLock(pSF COMMA_LOCKVAL_SRC_POS); 8505 8509 settings::SharedFolder sf; 8506 sf.strName = p Folder->getName();8507 sf.strHostPath = p Folder->getHostPath();8508 sf.fWritable = !!p Folder->isWritable();8509 sf.fAutoMount = !!p Folder->isAutoMounted();8510 sf.strName = pSF->getName(); 8511 sf.strHostPath = pSF->getHostPath(); 8512 sf.fWritable = !!pSF->isWritable(); 8513 sf.fAutoMount = !!pSF->isAutoMounted(); 8510 8514 8511 8515 data.llSharedFolders.push_back(sf);
Note:
See TracChangeset
for help on using the changeset viewer.