VirtualBox

Changeset 2929 in vbox


Ignore:
Timestamp:
May 30, 2007 1:31:16 PM (18 years ago)
Author:
vboxsync
Message:

Main: Removed devNode from the host DVD drive description (it's up to UI to decide how to visually represent things); switched HostDVDDrive and HostFloppyDrive objects to the new locking scheme.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/HostDVDDriveImpl.cpp

    r2917 r2929  
    2525/////////////////////////////////////////////////////////////////////////////
    2626
    27 HostDVDDrive::HostDVDDrive()
     27DEFINE_EMPTY_CTOR_DTOR (HostDVDDrive)
     28
     29HRESULT HostDVDDrive::FinalConstruct()
    2830{
     31    return S_OK;
    2932}
    3033
    31 HostDVDDrive::~HostDVDDrive()
     34void HostDVDDrive::FinalRelease()
    3235{
     36    uninit();
    3337}
    3438
     
    3741
    3842/**
    39  * Initializes the host object.
     43 * Initializes the host DVD drive object.
    4044 *
    41  * @returns COM result indicator
    42  * @param driveName name of the drive
     45 * @param aName         Name of the drive.
     46 * @param aDescription  Human-readable drive description (may be NULL).
     47 *
     48 * @return COM result indicator.
    4349 */
    44 HRESULT HostDVDDrive::init (INPTR BSTR driveName)
     50HRESULT HostDVDDrive::init (INPTR BSTR aName,
     51                            INPTR BSTR aDescription /* = NULL */)
    4552{
    46     ComAssertRet (driveName, E_INVALIDARG);
     53    ComAssertRet (aName, E_INVALIDARG);
    4754
    48     AutoLock lock(this);
    49     mDriveName = driveName;
    50     setReady(true);
     55    /* Enclose the state transition NotReady->InInit->Ready */
     56    AutoInitSpan autoInitSpan (this);
     57    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED);
     58
     59    unconst (mName) = aName;
     60    unconst (mDescription) = aDescription;
     61
     62    /* Confirm the successful initialization */
     63    autoInitSpan.setSucceeded();
     64
    5165    return S_OK;
    5266}
    5367
    5468/**
    55  * Initializes the host object.
    56  *
    57  * @returns COM result indicator
    58  * @param driveName        name of the drive
    59  * @param driveDescription human readable description of the drive
     69 *  Uninitializes the instance and sets the ready flag to FALSE.
     70 *  Called either from FinalRelease() or by the parent when it gets destroyed.
    6071 */
    61 HRESULT HostDVDDrive::init (INPTR BSTR driveName, INPTR BSTR driveDescription)
     72void HostDVDDrive::uninit()
    6273{
    63     ComAssertRet (driveName, E_INVALIDARG);
    64     ComAssertRet (driveDescription, E_INVALIDARG);
     74    /* Enclose the state transition Ready->InUninit->NotReady */
     75    AutoUninitSpan autoUninitSpan (this);
     76    if (autoUninitSpan.uninitDone())
     77        return;
    6578
    66     AutoLock lock(this);
    67     mDriveName = driveName;
    68     mDriveDescription = driveDescription;
    69     setReady(true);
    70     return S_OK;
     79    unconst (mDescription).setNull();
     80    unconst (mName).setNull();
    7181}
    7282
     
    7484/////////////////////////////////////////////////////////////////////////////
    7585
    76 /**
    77  * Returns the name of the host drive
    78  *
    79  * @returns COM status code
    80  * @param driveName address of result pointer
    81  */
    82 STDMETHODIMP HostDVDDrive::COMGETTER(Name) (BSTR *driveName)
     86STDMETHODIMP HostDVDDrive::COMGETTER(Name) (BSTR *aName)
    8387{
    84     if (!driveName)
     88    if (!aName)
    8589        return E_POINTER;
    86     AutoLock lock(this);
    87     CHECK_READY();
    88     mDriveName.cloneTo(driveName);
     90
     91    AutoCaller autoCaller (this);
     92    CheckComRCReturnRC (autoCaller.rc());
     93
     94    /* mName is constant during life time, no need to lock */
     95
     96    mName.cloneTo (aName);
     97
    8998    return S_OK;
    9099}
    91100
    92 /**
    93  * Returns the description of the host drive
    94  *
    95  * @returns COM status code
    96  * @param driveDescription address of result pointer
    97  */
    98 STDMETHODIMP HostDVDDrive::COMGETTER(Description) (BSTR *driveDescription)
     101STDMETHODIMP HostDVDDrive::COMGETTER(Description) (BSTR *aDescription)
    99102{
    100     if (!driveDescription)
     103    if (!aDescription)
    101104        return E_POINTER;
    102     AutoLock lock(this);
    103     CHECK_READY();
    104     mDriveDescription.cloneTo(driveDescription);
     105
     106    AutoCaller autoCaller (this);
     107    CheckComRCReturnRC (autoCaller.rc());
     108
     109    /* mDescription is constant during life time, no need to lock */
     110
     111    mDescription.cloneTo (aDescription);
     112
    105113    return S_OK;
    106114}
  • trunk/src/VBox/Main/HostFloppyDriveImpl.cpp

    r1 r2929  
    2525/////////////////////////////////////////////////////////////////////////////
    2626
    27 HostFloppyDrive::HostFloppyDrive()
     27DEFINE_EMPTY_CTOR_DTOR (HostFloppyDrive)
     28
     29HRESULT HostFloppyDrive::FinalConstruct()
    2830{
     31    return S_OK;
    2932}
    3033
    31 HostFloppyDrive::~HostFloppyDrive()
     34void HostFloppyDrive::FinalRelease()
    3235{
     36    uninit();
    3337}
    3438
     
    3943 * Initializes the host floppy drive object.
    4044 *
    41  * @returns COM result indicator
    42  * @param driveName name of the drive
     45 * @param aName         Name of the drive.
     46 *
     47 * @return COM result indicator.
    4348 */
    44 HRESULT HostFloppyDrive::init (INPTR BSTR driveName)
     49HRESULT HostFloppyDrive::init (INPTR BSTR aName)
    4550{
    46     ComAssertRet (driveName, E_INVALIDARG);
     51    ComAssertRet (aName, E_INVALIDARG);
    4752
    48     AutoLock lock(this);
    49     mDriveName = driveName;
    50     setReady(true);
     53    /* Enclose the state transition NotReady->InInit->Ready */
     54    AutoInitSpan autoInitSpan (this);
     55    AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED);
     56
     57    unconst (mName) = aName;
     58
     59    /* Confirm the successful initialization */
     60    autoInitSpan.setSucceeded();
     61
    5162    return S_OK;
     63}
     64
     65/**
     66 *  Uninitializes the instance and sets the ready flag to FALSE.
     67 *  Called either from FinalRelease() or by the parent when it gets destroyed.
     68 */
     69void HostFloppyDrive::uninit()
     70{
     71    /* Enclose the state transition Ready->InUninit->NotReady */
     72    AutoUninitSpan autoUninitSpan (this);
     73    if (autoUninitSpan.uninitDone())
     74        return;
     75
     76    unconst (mName).setNull();
    5277}
    5378
     
    5580/////////////////////////////////////////////////////////////////////////////
    5681
    57 /**
    58  * Returns the name of the host drive
    59  *
    60  * @returns COM status code
    61  * @param driveName address of result pointer
    62  */
    63 STDMETHODIMP HostFloppyDrive::COMGETTER(Name) (BSTR *driveName)
     82STDMETHODIMP HostFloppyDrive::COMGETTER(Name) (BSTR *aName)
    6483{
    65     if (!driveName)
     84    if (!aName)
    6685        return E_POINTER;
    67     AutoLock lock(this);
    68     CHECK_READY();
    69     mDriveName.cloneTo(driveName);
     86
     87    AutoCaller autoCaller (this);
     88    CheckComRCReturnRC (autoCaller.rc());
     89
     90    /* mName is constant during life time, no need to lock */
     91
     92    mName.cloneTo (aName);
     93
    7094    return S_OK;
    7195}
  • trunk/src/VBox/Main/HostImpl.cpp

    r2917 r2929  
    14261426                                if (validateDevice(devNode, true))
    14271427                                {
    1428                                     char description[256];
     1428                                    Utf8Str description;
    14291429                                    char *vendor, *product;
    14301430                                    /* We have at least one hit, so operation successful :) */
     
    14341434                                    product = libhal_device_get_property_string(halContext,
    14351435                                                    halDevices[i], "info.product", &dbusError);
    1436                                     if ((product != 0))
     1436                                    if ((product != 0 && product[0] != 0))
    14371437                                    {
    14381438                                        if (vendor != 0 && vendor[0] != 0)
    14391439                                        {
    1440                                             RTStrPrintf(description, sizeof(description),
    1441                                                         "%s %s (%s)", vendor, product, devNode);
     1440                                            description = Utf8StrFmt ("%s %s",
     1441                                                                      vendor, product);
    14421442                                        }
    14431443                                        else
    14441444                                        {
    1445                                             RTStrPrintf(description, sizeof(description),
    1446                                                         "%s (%s)", product, devNode);
     1445                                            description = product;
    14471446                                        }
    14481447                                        ComObjPtr <HostDVDDrive> hostDVDDriveObj;
  • trunk/src/VBox/Main/include/HostDVDDriveImpl.h

    r2917 r2929  
    2727
    2828class ATL_NO_VTABLE HostDVDDrive :
     29    public VirtualBoxBaseNEXT,
    2930    public VirtualBoxSupportErrorInfoImpl <HostDVDDrive, IHostDVDDrive>,
    3031    public VirtualBoxSupportTranslation <HostDVDDrive>,
    31     public VirtualBoxBase,
    3232    public IHostDVDDrive
    3333{
    3434public:
    3535
    36     HostDVDDrive();
    37     virtual ~HostDVDDrive();
     36    VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (HostDVDDrive)
    3837
    39     DECLARE_NOT_AGGREGATABLE(HostDVDDrive)
     38    DECLARE_NOT_AGGREGATABLE (HostDVDDrive)
    4039
    4140    DECLARE_PROTECT_FINAL_CONSTRUCT()
     
    4847    NS_DECL_ISUPPORTS
    4948
     49    DECLARE_EMPTY_CTOR_DTOR (HostDVDDrive)
     50
     51    HRESULT FinalConstruct();
     52    void FinalRelease();
     53
    5054    // public initializer/uninitializer for internal purposes only
    51     HRESULT init (INPTR BSTR driveName);
    52     HRESULT init (INPTR BSTR driveName, INPTR BSTR driveDescription);
     55    HRESULT init (INPTR BSTR aName, INPTR BSTR aDescription = NULL);
     56    void uninit();
    5357
    5458    // IHostDVDDrive properties
    55     STDMETHOD(COMGETTER(Name)) (BSTR *driveName);
    56     STDMETHOD(COMGETTER(Description)) (BSTR *driveDescription);
     59    STDMETHOD(COMGETTER(Name)) (BSTR *aName);
     60    STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
    5761
    5862    // public methods for internal purposes only
    5963
    60     const Bstr &driveName() const { return mDriveName; }
     64    /* @note Must be called from under the object read lock. */
     65    const Bstr &name() const { return mName; }
    6166
    6267    // for VirtualBoxSupportErrorInfoImpl
     
    6570private:
    6671
    67     Bstr mDriveName;
    68     Bstr mDriveDescription;
     72    const Bstr mName;
     73    const Bstr mDescription;
    6974};
    7075
    7176COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (HostDVDDrive)
    7277
    73     STDMETHOD(FindByName) (INPTR BSTR name, IHostDVDDrive **drive)
     78    STDMETHOD(FindByName) (INPTR BSTR aName, IHostDVDDrive **aDrive)
    7479    {
    75         if (!name)
     80        if (!aName)
    7681            return E_INVALIDARG;
    77         if (!drive)
     82        if (!aDrive)
    7883            return E_POINTER;
    7984
    80         *drive = NULL;
     85        *aDrive = NULL;
    8186        Vector::value_type found;
    8287        Vector::iterator it = vec.begin();
     
    8590            Bstr n;
    8691            (*it)->COMGETTER(Name) (n.asOutParam());
    87             if (n == name)
     92            if (n == aName)
    8893                found = *it;
    8994            ++ it;
     
    9297        if (!found)
    9398            return setError (E_INVALIDARG, HostDVDDriveCollection::tr (
    94                 "The host DVD drive named '%ls' could not be found"), name);
     99                "The host DVD drive named '%ls' could not be found"), aName);
    95100
    96         return found.queryInterfaceTo (drive);
     101        return found.queryInterfaceTo (aDrive);
    97102    }
    98103
  • trunk/src/VBox/Main/include/HostFloppyDriveImpl.h

    r1 r2929  
    2727
    2828class ATL_NO_VTABLE HostFloppyDrive :
     29    public VirtualBoxBaseNEXT,
    2930    public VirtualBoxSupportErrorInfoImpl <HostFloppyDrive, IHostFloppyDrive>,
    3031    public VirtualBoxSupportTranslation <HostFloppyDrive>,
    31     public VirtualBoxBase,
    3232    public IHostFloppyDrive
    3333{
    3434public:
    3535
    36     HostFloppyDrive();
    37     virtual ~HostFloppyDrive();
     36    VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (HostFloppyDrive)
    3837
    39     DECLARE_NOT_AGGREGATABLE(HostFloppyDrive)
     38    DECLARE_NOT_AGGREGATABLE (HostFloppyDrive)
    4039
    4140    DECLARE_PROTECT_FINAL_CONSTRUCT()
     
    4847    NS_DECL_ISUPPORTS
    4948
     49    DECLARE_EMPTY_CTOR_DTOR (HostFloppyDrive)
     50
     51    HRESULT FinalConstruct();
     52    void FinalRelease();
     53
    5054    // public initializer/uninitializer for internal purposes only
    51     HRESULT init (INPTR BSTR driveName);
     55    HRESULT init (INPTR BSTR aName);
     56    void uninit();
    5257
    5358    // IHostDVDDrive properties
    54     STDMETHOD(COMGETTER(Name)) (BSTR *driveName);
     59    STDMETHOD(COMGETTER(Name)) (BSTR *aName);
    5560
    5661    // public methods for internal purposes only
    5762
    58     const Bstr &driveName() const { return mDriveName; }
     63    /* @note Must be called from under the object read lock. */
     64    const Bstr &name() const { return mName; }
    5965
    6066    // for VirtualBoxSupportErrorInfoImpl
     
    6369private:
    6470
    65     Bstr mDriveName;
     71    const Bstr mName;
    6672};
    6773
    6874COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (HostFloppyDrive)
    6975
    70     STDMETHOD(FindByName) (INPTR BSTR name, IHostFloppyDrive **drive)
     76    STDMETHOD(FindByName) (INPTR BSTR aName, IHostFloppyDrive **aDrive)
    7177    {
    72         if (!name)
     78        if (!aName)
    7379            return E_INVALIDARG;
    74         if (!drive)
     80        if (!aDrive)
    7581            return E_POINTER;
    7682
    77         *drive = NULL;
     83        *aDrive = NULL;
    7884        Vector::value_type found;
    7985        Vector::iterator it = vec.begin();
     
    8288            Bstr n;
    8389            (*it)->COMGETTER(Name) (n.asOutParam());
    84             if (n == name)
     90            if (n == aName)
    8591                found = *it;
    8692            ++ it;
     
    8995        if (!found)
    9096            return setError (E_INVALIDARG, HostFloppyDriveCollection::tr (
    91                 "The host floppy drive named '%ls' could not be found"), name);
     97                "The host floppy drive named '%ls' could not be found"), aName);
    9298
    93         return found.queryInterfaceTo (drive);
     99        return found.queryInterfaceTo (aDrive);
    94100    }
    95101
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