VirtualBox

Changeset 35755 in vbox


Ignore:
Timestamp:
Jan 28, 2011 11:36:42 AM (14 years ago)
Author:
vboxsync
Message:

Main: convert SharedFolder to utf-8

Location:
trunk/src/VBox/Main
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r35722 r35755  
    406406    {
    407407    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
    413420        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;
    420429    };
    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;
    423433
    424434private:
     
    449459    }
    450460
    451     HRESULT findSharedFolder(CBSTR aName,
     461    HRESULT findSharedFolder(const Utf8Str &strName,
    452462                             ComObjPtr<SharedFolder> &aSharedFolder,
    453463                             bool aSetError = false);
    454464
    455465    HRESULT fetchSharedFolders(BOOL aGlobal);
    456     bool findOtherSharedFolder(IN_BSTR aName,
     466    bool findOtherSharedFolder(const Utf8Str &straName,
    457467                               SharedFolderDataMap::const_iterator &aIt);
    458468
    459     HRESULT createSharedFolder(CBSTR aName, SharedFolderData aData);
    460     HRESULT removeSharedFolder(CBSTR aName);
     469    HRESULT createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData);
     470    HRESULT removeSharedFolder(const Utf8Str &strName);
    461471
    462472    static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
     
    631641    RemoteUSBDeviceList mRemoteUSBDevices;
    632642
    633     SharedFolderMap mSharedFolders;
    634     SharedFolderDataMap mMachineSharedFolders;
    635     SharedFolderDataMap mGlobalSharedFolders;
     643    SharedFolderDataMap m_mapGlobalSharedFolders;
     644    SharedFolderDataMap m_mapMachineSharedFolders;
     645    SharedFolderMap m_mapSharedFolders;             // the console instances
    636646
    637647    /** The VM instance handle. */
  • trunk/src/VBox/Main/include/MachineImpl.h

    r35676 r35755  
    726726    virtual HRESULT setMachineState(MachineState_T aMachineState);
    727727
    728     HRESULT findSharedFolder(CBSTR aName,
     728    HRESULT findSharedFolder(const Utf8Str &aName,
    729729                             ComObjPtr<SharedFolder> &aSharedFolder,
    730730                             bool aSetError = false);
  • trunk/src/VBox/Main/include/SharedFolderImpl.h

    r35638 r35755  
    3030public:
    3131
    32     struct Data
    33     {
    34         Data() {}
    35 
    36         const Bstr name;
    37         const Bstr hostPath;
    38         BOOL       writable;
    39         BOOL       autoMount;
    40         Bstr       lastAccessError;
    41     };
    42 
    4332    VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SharedFolder, ISharedFolder)
    4433
     
    5746
    5847    // public initializer/uninitializer for internal purposes only
    59     HRESULT init(Machine *aMachine, CBSTR aName, CBSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
     48    HRESULT init(Machine *aMachine, const Utf8Str &aName, const Utf8Str &aHostPath, bool aWritable, bool aAutoMount);
    6049    HRESULT initCopy(Machine *aMachine, SharedFolder *aThat);
    61     HRESULT init(Console *aConsole, CBSTR aName, CBSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
    62     HRESULT init(VirtualBox *aVirtualBox, CBSTR aName, CBSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
     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);
    6352    void uninit();
    6453
     
    7463    // (ensure there is a caller and a read lock before calling them!)
    7564
    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;
    7870
    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;
    8388
    8489protected:
    8590
    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);
    8992private:
    9093
     
    9699    VirtualBox * const      mVirtualBox;
    97100
    98     Data m;
     101    struct Data;            // opaque data struct, defined in SharedFolderImpl.cpp
     102    Data *m;
    99103};
    100104
  • trunk/src/VBox/Main/src-all/SharedFolderImpl.cpp

    r35638 r35755  
    2828#include <iprt/path.h>
    2929
     30/////////////////////////////////////////////////////////////////////////////
     31// SharedFolder::Data structure
     32/////////////////////////////////////////////////////////////////////////////
     33
     34struct 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
    3048// constructor / destructor
    3149/////////////////////////////////////////////////////////////////////////////
     
    3755      mVirtualBox(NULL)
    3856{
     57    m = new Data;
    3958}
    4059
    4160SharedFolder::~SharedFolder()
    4261{
     62    delete m;
     63    m = NULL;
    4364}
    4465
     
    6889 *  @return          COM result indicator
    6990 */
    70 HRESULT SharedFolder::init (Machine *aMachine,
    71                             CBSTR aName, CBSTR aHostPath, BOOL aWritable, BOOL aAutoMount)
     91HRESULT SharedFolder::init(Machine *aMachine,
     92                           const Utf8Str &aName,
     93                           const Utf8Str &aHostPath,
     94                           bool aWritable,
     95                           bool aAutoMount)
    7296{
    7397    /* Enclose the state transition NotReady->InInit->Ready */
     
    96120 *  @return          COM result indicator
    97121 */
    98 HRESULT SharedFolder::initCopy (Machine *aMachine, SharedFolder *aThat)
     122HRESULT SharedFolder::initCopy(Machine *aMachine, SharedFolder *aThat)
    99123{
    100124    ComAssertRet(aThat, E_INVALIDARG);
     
    106130    unconst(mMachine) = aMachine;
    107131
    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);
    111137
    112138    /* Confirm a successful initialization when it's the case */
     
    118144
    119145/**
    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.
    121148 *
    122149 *  @param aConsole     Console parent object
     
    128155 */
    129156HRESULT 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)
    131161{
    132162    /* Enclose the state transition NotReady->InInit->Ready */
     
    146176
    147177/**
    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.
    149180 *
    150181 *  @param aVirtualBox  VirtualBox parent object
     
    155186 *  @return          COM result indicator
    156187 */
    157 HRESULT SharedFolder::init (VirtualBox *aVirtualBox,
    158                             CBSTR aName, CBSTR aHostPath, BOOL aWritable, BOOL aAutoMount)
     188HRESULT SharedFolder::init(VirtualBox *aVirtualBox,
     189                           const Utf8Str &aName,
     190                           const Utf8Str &aHostPath,
     191                           bool aWritable,
     192                           bool aAutoMount)
    159193{
    160194    /* Enclose the state transition NotReady->InInit->Ready */
     
    174208
    175209/**
    176  *  Helper for init() methods.
     210 *  Shared initialization code. Called from the other constructors.
    177211 *
    178212 *  @note
     
    180214 */
    181215HRESULT SharedFolder::protectedInit(VirtualBoxBase *aParent,
    182                                     CBSTR           aName,
    183                                     CBSTR           aHostPath,
    184                                     BOOL            aWritable,
    185                                     BOOL            aAutoMount)
    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;
    193227    size_t hostPathLen = hostPath.length();
    194228
     
    229263    unconst(mParent) = aParent;
    230264
    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;
    235269
    236270    return S_OK;
     
    268302
    269303    /* mName is constant during life time, no need to lock */
    270     m.name.cloneTo(aName);
     304    m->strName.cloneTo(aName);
    271305
    272306    return S_OK;
     
    281315
    282316    /* mHostPath is constant during life time, no need to lock */
    283     m.hostPath.cloneTo(aHostPath);
     317    m->strHostPath.cloneTo(aHostPath);
    284318
    285319    return S_OK;
     
    296330
    297331    /* check whether the host path exists */
    298     Utf8Str hostPath = Utf8Str(m.hostPath);
     332    Utf8Str hostPath = m->strHostPath;
    299333    char hostPathFull[RTPATH_MAX];
    300334    int vrc = RTPathExists(hostPath.c_str()) ? RTPathReal(hostPath.c_str(),
     
    310344    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    311345
    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()));
    316351
    317352    *aAccessible = FALSE;
     
    328363    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    329364
    330     *aWritable = m.writable;
     365    *aWritable = !!m->fWritable;
    331366
    332367    return S_OK;
     
    342377    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    343378
    344     *aAutoMount = m.autoMount;
     379    *aAutoMount = !!m->fAutoMount;
    345380
    346381    return S_OK;
     
    356391    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    357392
    358     m.lastAccessError.cloneTo(aLastAccessError);
    359 
    360     return S_OK;
     393    m->strLastAccessError.cloneTo(aLastAccessError);
     394
     395    return S_OK;
     396}
     397
     398const Utf8Str& SharedFolder::getName() const
     399{
     400    return m->strName;
     401}
     402
     403const Utf8Str& SharedFolder::getHostPath() const
     404{
     405    return m->strHostPath;
     406}
     407
     408bool SharedFolder::isWritable() const
     409{
     410    return m->fWritable;
     411}
     412
     413bool SharedFolder::isAutoMounted() const
     414{
     415    return m->fAutoMount;
    361416}
    362417
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r35722 r35755  
    604604    }
    605605
    606     mGlobalSharedFolders.clear();
    607     mMachineSharedFolders.clear();
    608 
    609     mSharedFolders.clear();
     606    m_mapGlobalSharedFolders.clear();
     607    m_mapMachineSharedFolders.clear();
     608    m_mapSharedFolders.clear();             // console instances
     609
    610610    mRemoteUSBDevices.clear();
    611611    mUSBDevices.clear();
     
    12611261    AutoReadLock alock(that COMMA_LOCKVAL_SRC_POS);
    12621262
    1263     int vrc = SSMR3PutU32(pSSM, (uint32_t)that->mSharedFolders.size());
     1263    int vrc = SSMR3PutU32(pSSM, (uint32_t)that->m_mapSharedFolders.size());
    12641264    AssertRC(vrc);
    12651265
    1266     for (SharedFolderMap::const_iterator it = that->mSharedFolders.begin();
    1267          it != that->mSharedFolders.end();
     1266    for (SharedFolderMap::const_iterator it = that->m_mapSharedFolders.begin();
     1267         it != that->m_mapSharedFolders.end();
    12681268         ++ it)
    12691269    {
    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();
    12741275        vrc = SSMR3PutU32(pSSM, (uint32_t)name.length() + 1 /* term. 0 */);
    12751276        AssertRC(vrc);
     
    12771278        AssertRC(vrc);
    12781279
    1279         Utf8Str hostPath = pSharedFolder->getHostPath();
     1280        Utf8Str hostPath = pSF->getHostPath();
    12801281        vrc = SSMR3PutU32(pSSM, (uint32_t)hostPath.length() + 1 /* term. 0 */);
    12811282        AssertRC(vrc);
     
    12831284        AssertRC(vrc);
    12841285
    1285         vrc = SSMR3PutBool(pSSM, !!pSharedFolder->isWritable());
     1286        vrc = SSMR3PutBool(pSSM, !!pSF->isWritable());
    12861287        AssertRC(vrc);
    12871288
    1288         vrc = SSMR3PutBool(pSSM, !!pSharedFolder->isAutoMounted());
     1289        vrc = SSMR3PutBool(pSSM, !!pSF->isAutoMounted());
    12891290        AssertRC(vrc);
    12901291    }
     
    13391340    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    13401341
    1341     AssertReturn(mSharedFolders.size() == 0, VERR_INTERNAL_ERROR);
     1342    AssertReturn(m_mapSharedFolders.size() == 0, VERR_INTERNAL_ERROR);
    13421343
    13431344    uint32_t size = 0;
     
    13471348    for (uint32_t i = 0; i < size; ++ i)
    13481349    {
    1349         Bstr name;
    1350         Bstr hostPath;
     1350        Utf8Str strName;
     1351        Utf8Str strHostPath;
    13511352        bool writable = true;
    13521353        bool autoMount = false;
     
    13601361        vrc = SSMR3GetStrZ(pSSM, buf, szBuf);
    13611362        AssertRC(vrc);
    1362         name = buf;
     1363        strName = buf;
    13631364        delete[] buf;
    13641365
     
    13681369        vrc = SSMR3GetStrZ(pSSM, buf, szBuf);
    13691370        AssertRC(vrc);
    1370         hostPath = buf;
     1371        strHostPath = buf;
    13711372        delete[] buf;
    13721373
     
    13791380        ComObjPtr<SharedFolder> pSharedFolder;
    13801381        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);
    13831387        AssertComRCReturn(rc, VERR_INTERNAL_ERROR);
    13841388
    1385         mSharedFolders.insert(std::make_pair(name, pSharedFolder));
     1389        m_mapSharedFolders.insert(std::make_pair(strName, pSharedFolder));
    13861390    }
    13871391
     
    17001704    if (FAILED(rc)) return rc;
    17011705
    1702     SafeIfaceArray<ISharedFolder> sf(mSharedFolders);
     1706    SafeIfaceArray<ISharedFolder> sf(m_mapSharedFolders);
    17031707    sf.detachTo(ComSafeArrayOutArg(aSharedFolders));
    17041708
     
    28502854    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    28512855
     2856    Utf8Str strName(aName);
     2857    Utf8Str strHostPath(aHostPath);
     2858
    28522859    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    28532860
     
    28672874
    28682875    ComObjPtr<SharedFolder> pSharedFolder;
    2869     HRESULT rc = findSharedFolder(aName, pSharedFolder, false /* aSetError */);
     2876    HRESULT rc = findSharedFolder(strName, pSharedFolder, false /* aSetError */);
    28702877    if (SUCCEEDED(rc))
    28712878        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());
    28742881
    28752882    pSharedFolder.createObject();
    2876     rc = pSharedFolder->init(this, aName, aHostPath, aWritable, aAutoMount);
     2883    rc = pSharedFolder->init(this, strName, strHostPath, aWritable, aAutoMount);
    28772884    if (FAILED(rc)) return rc;
    28782885
     
    29022909    }
    29032910
    2904     mSharedFolders.insert(std::make_pair(aName, pSharedFolder));
     2911    m_mapSharedFolders.insert(std::make_pair(aName, pSharedFolder));
    29052912
    29062913    /* notify console callbacks after the folder is added to the list */
     
    29162923    AutoCaller autoCaller(this);
    29172924    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     2925
     2926    Utf8Str strName(aName);
    29182927
    29192928    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    29502959
    29512960        /* first, remove the given folder */
    2952         rc = removeSharedFolder(aName);
     2961        rc = removeSharedFolder(strName);
    29532962        if (FAILED(rc)) return rc;
    29542963
    29552964        /* first, remove the machine or the global folder if there is any */
    29562965        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);
    29602969            /* don't check rc here because we need to remove the console
    29612970             * folder from the collection even on failure */
     
    29632972    }
    29642973
    2965     mSharedFolders.erase(aName);
     2974    m_mapSharedFolders.erase(strName);
    29662975
    29672976    /* notify console callbacks after the folder is removed to the list */
     
    55275536        SharedFolderDataMap sharedFolders;
    55285537        {
     5538            // @todo umoeller
     5539
    55295540            /* 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            }
    55335548
    55345549            /* 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            }
    55385557
    55395558            /* 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            }
    55455570        }
    55465571
     
    61356160 * @note The caller must lock this object for writing.
    61366161 */
    6137 HRESULT Console::findSharedFolder(CBSTR aName,
     6162HRESULT Console::findSharedFolder(const Utf8Str &strName,
    61386163                                  ComObjPtr<SharedFolder> &aSharedFolder,
    61396164                                  bool aSetError /* = false */)
     
    61426167    AssertReturn(isWriteLockOnCurrentThread(), E_FAIL);
    61436168
    6144     SharedFolderMap::const_iterator it = mSharedFolders.find(aName);
    6145     if (it != mSharedFolders.end())
     6169    SharedFolderMap::const_iterator it = m_mapSharedFolders.find(strName);
     6170    if (it != m_mapSharedFolders.end())
    61466171    {
    61476172        aSharedFolder = it->second;
     
    61516176    if (aSetError)
    61526177        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());
    61556180
    61566181    return VBOX_E_FILE_ERROR;
     
    61886213        SharedFolderDataMap oldFolders;
    61896214        if (online)
    6190             oldFolders = mMachineSharedFolders;
    6191 
    6192         mMachineSharedFolders.clear();
     6215            oldFolders = m_mapMachineSharedFolders;
     6216
     6217        m_mapMachineSharedFolders.clear();
    61936218
    61946219        SafeIfaceArray<ISharedFolder> folders;
     
    62006225            ComPtr<ISharedFolder> pSharedFolder = folders[i];
    62016226
    6202             Bstr name;
    6203             Bstr hostPath;
     6227            Bstr bstrName;
     6228            Bstr bstrHostPath;
    62046229            BOOL writable;
    62056230            BOOL autoMount;
    62066231
    6207             rc = pSharedFolder->COMGETTER(Name)(name.asOutParam());
     6232            rc = pSharedFolder->COMGETTER(Name)(bstrName.asOutParam());
    62086233            if (FAILED(rc)) break;
    6209             rc = pSharedFolder->COMGETTER(HostPath)(hostPath.asOutParam());
     6234            Utf8Str strName(bstrName);
     6235
     6236            rc = pSharedFolder->COMGETTER(HostPath)(bstrHostPath.asOutParam());
    62106237            if (FAILED(rc)) break;
     6238            Utf8Str strHostPath(bstrHostPath);
     6239
    62116240            rc = pSharedFolder->COMGETTER(Writable)(&writable);
    62126241            if (FAILED(rc)) break;
     6242
    62136243            rc = pSharedFolder->COMGETTER(AutoMount)(&autoMount);
    62146244            if (FAILED(rc)) break;
    62156245
    6216             mMachineSharedFolders.insert(std::make_pair(name, SharedFolderData(hostPath, writable, autoMount)));
     6246            m_mapMachineSharedFolders.insert(std::make_pair(strName,
     6247                                                            SharedFolderData(strHostPath, writable, autoMount)));
    62176248
    62186249            /* send changes to HGCM if the VM is running */
    6219             /// @todo report errors as runtime warnings through VMSetError
     6250            /// @todo umoeller report errors as runtime warnings through VMSetError
    62206251            if (online)
    62216252            {
    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)
    62246256                {
    62256257                    /* a new machine folder is added or
    62266258                     * the existing machine folder is changed */
    6227                     if (mSharedFolders.find(name) != mSharedFolders.end())
     6259                    if (m_mapSharedFolders.find(strName) != m_mapSharedFolders.end())
    62286260                        ; /* the console folder exists, nothing to do */
    62296261                    else
     
    62316263                        /* remove the old machine folder (when changed)
    62326264                         * 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);
    62376269                        /* create the new machine folder */
    6238                         rc = createSharedFolder(name.raw(),
    6239                                                 SharedFolderData(hostPath,
     6270                        rc = createSharedFolder(strName,
     6271                                                SharedFolderData(strHostPath,
    62406272                                                                 writable,
    62416273                                                                 autoMount));
     
    62596291                 it != oldFolders.end(); ++ it)
    62606292            {
    6261                 if (mSharedFolders.find(it->first) != mSharedFolders.end())
     6293                if (m_mapSharedFolders.find(it->first) != m_mapSharedFolders.end())
    62626294                    ; /* the console folder exists, nothing to do */
    62636295                else
    62646296                {
    62656297                    /* remove the outdated machine folder */
    6266                     rc = removeSharedFolder(it->first.raw());
     6298                    rc = removeSharedFolder(it->first);
    62676299                    /* create the global folder if there is any */
    62686300                    SharedFolderDataMap::const_iterator git =
    6269                         mGlobalSharedFolders.find(it->first);
    6270                     if (git != mGlobalSharedFolders.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);
    62726304                }
    62736305            }
     
    62906322 * @note The caller must lock this object for reading.
    62916323 */
    6292 bool Console::findOtherSharedFolder(IN_BSTR aName,
     6324bool Console::findOtherSharedFolder(const Utf8Str &strName,
    62936325                                    SharedFolderDataMap::const_iterator &aIt)
    62946326{
     
    62976329
    62986330    /* first, search machine folders */
    6299     aIt = mMachineSharedFolders.find(aName);
    6300     if (aIt != mMachineSharedFolders.end())
     6331    aIt = m_mapMachineSharedFolders.find(strName);
     6332    if (aIt != m_mapMachineSharedFolders.end())
    63016333        return true;
    63026334
    63036335    /* second, search machine folders */
    6304     aIt = mGlobalSharedFolders.find(aName);
    6305     if (aIt != mGlobalSharedFolders.end())
     6336    aIt = m_mapGlobalSharedFolders.find(strName);
     6337    if (aIt != m_mapGlobalSharedFolders.end())
    63066338        return true;
    63076339
     
    63186350 * @note Doesn't lock anything.
    63196351 */
    6320 HRESULT Console::createSharedFolder(CBSTR aName, SharedFolderData aData)
    6321 {
    6322     ComAssertRet(aName && *aName, E_FAIL);
    6323     ComAssertRet(!aData.mHostPath.isEmpty(), E_FAIL);
     6352HRESULT Console::createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData)
     6353{
     6354    ComAssertRet(strName.isNotEmpty(), E_FAIL);
     6355    ComAssertRet(aData.m_strHostPath.isNotEmpty(), E_FAIL);
    63246356
    63256357    /* sanity checks */
     
    63316363    size_t cbString;
    63326364
    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);
    63366371    if (cbString >= UINT16_MAX)
    63376372        return setError(E_INVALIDARG, tr("The name is too long"));
    6338     pFolderName = (SHFLSTRING *) RTMemAllocZ(sizeof(SHFLSTRING) + cbString);
     6373    pFolderName = (SHFLSTRING*)RTMemAllocZ(sizeof(SHFLSTRING) + cbString);
    63396374    Assert(pFolderName);
    6340     memcpy(pFolderName->String.ucs2, aData.mHostPath.raw(), cbString);
     6375    memcpy(pFolderName->String.ucs2, bstrHostPath.raw(), cbString);
    63416376
    63426377    pFolderName->u16Size   = (uint16_t)cbString;
     
    63476382    parms[0].u.pointer.size = sizeof(SHFLSTRING) + (uint16_t)cbString;
    63486383
    6349     cbString = (RTUtf16Len(aName) + 1) * sizeof(RTUTF16);
     6384    cbString = (bstrName.length() + 1) * sizeof(RTUTF16);
    63506385    if (cbString >= UINT16_MAX)
    63516386    {
     
    63536388        return setError(E_INVALIDARG, tr("The host path is too long"));
    63546389    }
    6355     pMapName = (SHFLSTRING *) RTMemAllocZ(sizeof(SHFLSTRING) + cbString);
     6390    pMapName = (SHFLSTRING*)RTMemAllocZ(sizeof(SHFLSTRING) + cbString);
    63566391    Assert(pMapName);
    6357     memcpy(pMapName->String.ucs2, aName, cbString);
     6392    memcpy(pMapName->String.ucs2, bstrName.raw(), cbString);
    63586393
    63596394    pMapName->u16Size   = (uint16_t)cbString;
     
    63656400
    63666401    parms[2].type = VBOX_HGCM_SVC_PARM_32BIT;
    6367     parms[2].u.uint32 = aData.mWritable;
     6402    parms[2].u.uint32 = aData.m_fWritable;
    63686403
    63696404    /*
     
    63746409     */
    63756410    parms[3].type = VBOX_HGCM_SVC_PARM_32BIT;
    6376     parms[3].u.uint32 = aData.mAutoMount;
     6411    parms[3].u.uint32 = aData.m_fAutoMount;
    63776412
    63786413    int vrc = m_pVMMDev->hgcmHostCall("VBoxSharedFolders",
     
    63846419    if (RT_FAILURE(vrc))
    63856420        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);
    63886423
    63896424    return S_OK;
     
    63986433 * @note Doesn't lock anything.
    63996434 */
    6400 HRESULT Console::removeSharedFolder(CBSTR aName)
    6401 {
    6402     ComAssertRet(aName && *aName, E_FAIL);
     6435HRESULT Console::removeSharedFolder(const Utf8Str &strName)
     6436{
     6437    ComAssertRet(strName.isNotEmpty(), E_FAIL);
    64036438
    64046439    /* sanity checks */
     
    64106445    size_t cbString;
    64116446
    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);
    64156451    if (cbString >= UINT16_MAX)
    64166452        return setError(E_INVALIDARG, tr("The name is too long"));
    64176453    pMapName = (SHFLSTRING *) RTMemAllocZ(sizeof(SHFLSTRING) + cbString);
    64186454    Assert(pMapName);
    6419     memcpy(pMapName->String.ucs2, aName, cbString);
     6455    memcpy(pMapName->String.ucs2, bstrName.raw(), cbString);
    64206456
    64216457    pMapName->u16Size   = (uint16_t)cbString;
     
    64326468    if (RT_FAILURE(vrc))
    64336469        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);
    64366472
    64376473    return S_OK;
     
    77937829                         ++it)
    77947830                    {
    7795                         rc = pConsole->createSharedFolder((*it).first.raw(),
    7796                                                          (*it).second);
     7831                        const SharedFolderData &d = it->second;
     7832                        rc = pConsole->createSharedFolder(it->first,
     7833                                                          d);
    77977834                        if (FAILED(rc)) break;
    77987835                    }
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r35676 r35755  
    70327032 *      must be called from under the object's lock!
    70337033 */
    7034 HRESULT Machine::findSharedFolder(CBSTR aName,
     7034HRESULT Machine::findSharedFolder(const Utf8Str &aName,
    70357035                                  ComObjPtr<SharedFolder> &aSharedFolder,
    70367036                                  bool aSetError /* = false */)
    70377037{
    7038     bool found = false;
     7038    HRESULT rc = VBOX_E_OBJECT_NOT_FOUND;
    70397039    for (HWData::SharedFolderList::const_iterator it = mHWData->mSharedFolders.begin();
    7040         !found && it != mHWData->mSharedFolders.end();
     7040        it != mHWData->mSharedFolders.end();
    70417041        ++it)
    70427042    {
    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());
    70537055
    70547056    return rc;
     
    85028504            ++it)
    85038505        {
    8504             ComObjPtr<SharedFolder> pFolder = *it;
     8506            SharedFolder *pSF = *it;
     8507            AutoCaller sfCaller(pSF);
     8508            AutoReadLock sfLock(pSF COMMA_LOCKVAL_SRC_POS);
    85058509            settings::SharedFolder sf;
    8506             sf.strName = pFolder->getName();
    8507             sf.strHostPath = pFolder->getHostPath();
    8508             sf.fWritable = !!pFolder->isWritable();
    8509             sf.fAutoMount = !!pFolder->isAutoMounted();
     8510            sf.strName = pSF->getName();
     8511            sf.strHostPath = pSF->getHostPath();
     8512            sf.fWritable = !!pSF->isWritable();
     8513            sf.fAutoMount = !!pSF->isAutoMounted();
    85108514
    85118515            data.llSharedFolders.push_back(sf);
Note: See TracChangeset for help on using the changeset viewer.

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