VirtualBox

Changeset 28353 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Apr 15, 2010 12:26:45 PM (15 years ago)
Author:
vboxsync
Message:

Main/MediumLock: header file update and implementation. Gets built and linked now even though it is not yet used.

Location:
trunk/src/VBox/Main
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/Makefile.kmk

    r27882 r28353  
    55
    66#
    7 # Copyright (C) 2006-2009 Sun Microsystems, Inc.
     7# Copyright (C) 2006-2010 Sun Microsystems, Inc.
    88#
    99# This file is part of VirtualBox Open Source Edition (OSE), as
     
    298298        SnapshotImpl.cpp \
    299299        MediumImpl.cpp \
     300        MediumLock.cpp \
    300301        MediumAttachmentImpl.cpp \
    301302        MediumFormatImpl.cpp \
  • trunk/src/VBox/Main/include/MediumLock.h

    r27120 r28353  
    2727/* interface definitions */
    2828#include "VBox/com/VirtualBox.h"
     29#include "VirtualBoxBase.h"
     30#include "AutoCaller.h"
    2931
    3032#include <iprt/types.h>
     33
     34#include <list>
     35#include <map>
     36
     37class Medium;
     38class MediumAttachment;
    3139
    3240/**
     
    5462     * @param aLockWrite    @c true means a write lock should be taken
    5563     */
    56     MediumLock(ComObjPtr<Medium> aMedium, bool aLockWrite);
     64    MediumLock(const ComObjPtr<Medium> &aMedium, bool aLockWrite);
     65
     66    /**
     67     * Copy constructor. Needed because we contain an AutoCaller
     68     * instance which is deliberately not copyable. The copy is not
     69     * marked as locked, so be careful.
     70     *
     71     * @param aMediumLock   Reference to source object.
     72     */
     73    MediumLock(const MediumLock &aMediumLock);
     74
     75    /**
     76     * Update a medium lock description
     77     *
     78     * @note May be only used in unlocked state.
     79     *
     80     * @return COM status code
     81     * @param aLockWrite    @c true means a write lock should be taken
     82     */
     83    HRESULT UpdateLock(bool aLockWrite);
     84
     85    /**
     86     * Get medium object reference.
     87     */
     88    const ComObjPtr<Medium> &GetMedium() const;
    5789
    5890    /**
    5991     * Acquire a medium lock.
    60      */
    61     int Lock();
     92     *
     93     * @return COM status code
     94     */
     95    HRESULT Lock();
    6296
    6397    /**
    6498     * Release a medium lock.
    65      */
    66     int Unlock();
     99     *
     100     * @return COM status code
     101     */
     102    HRESULT Unlock();
    67103
    68104private:
    69105    ComObjPtr<Medium> mMedium;
     106    AutoCaller mMediumCaller;
    70107    bool mLockWrite;
     108    bool mIsLocked;
     109    /** Flag whether the medium was skipped when taking the locks.
     110     * Only existing and accessible media objects need to be locked. */
     111    bool mLockSkipped;
    71112};
    72113
     
    80121public:
    81122
     123    /* Base list data type. */
     124    typedef std::list<MediumLock> Base;
     125
    82126    /**
    83127     * Default medium lock list constructor.
     
    91135
    92136    /**
     137     * Checks if medium lock declaration list is empty.
     138     *
     139     * @return true if list is empty.
     140     */
     141    bool IsEmpty();
     142
     143    /**
    93144     * Add a new medium lock declaration to the end of the list.
    94145     *
    95146     * @note May be only used in unlocked state.
    96147     *
    97      * @return VBox status code.
     148     * @return COM status code
    98149     * @param aMedium       Reference to medium object
    99150     * @param aLockWrite    @c true means a write lock should be taken
    100151     */
    101     int Append(ComObjPtr<Medium> aMedium, bool aLockWrite);
     152    HRESULT Append(const ComObjPtr<Medium> &aMedium, bool aLockWrite);
    102153
    103154    /**
     
    106157     * @note May be only used in unlocked state.
    107158     *
    108      * @return VBox status code.
     159     * @return COM status code
    109160     * @param aMedium       Reference to medium object
    110161     * @param aLockWrite    @c true means a write lock should be taken
    111162     */
    112     int Prepend(ComObjPtr<Medium> aMedium, bool aLockWrite);
     163    HRESULT Prepend(const ComObjPtr<Medium> &aMedium, bool aLockWrite);
    113164
    114165    /**
     
    117168     * @note May be only used in unlocked state.
    118169     *
    119      * @return VBox status code.
     170     * @return COM status code
    120171     * @param aMedium       Reference to medium object
    121172     * @param aLockWrite    @c true means a write lock should be taken
    122173     */
    123     int Update(ComObjPtr<Medium> aMedium, bool aLockWrite);
    124 
    125     /**
    126      * Remove a medium lock declaration.
    127      *
    128      * @note May be only used in unlocked state.
    129      *
    130      * @return VBox status code.
    131      * @param aMedium       Reference to medium object
    132      */
    133     int Remove(ComObjPtr<Medium> aMedium);
     174    HRESULT Update(const ComObjPtr<Medium> &aMedium, bool aLockWrite);
     175
     176    /**
     177     * Remove a medium lock declaration and return an updated iterator.
     178     *
     179     * @note May be used in locked state.
     180     *
     181     * @return COM status code
     182     * @param aIt           Iterator for the element to remove
     183     */
     184    HRESULT RemoveByIterator(Base::iterator &aIt);
     185
     186    /**
     187     * Clear all medium lock declaration.
     188     *
     189     * @note Implicitly unlocks all locks.
     190     *
     191     * @return COM status code
     192     */
     193    HRESULT Clear();
     194
     195    /**
     196     * Get iterator begin() for base list.
     197     */
     198    Base::iterator GetBegin();
     199
     200    /**
     201     * Get iterator end() for base list.
     202     */
     203    Base::iterator GetEnd();
    134204
    135205    /**
    136206     * Acquire all medium locks "atomically", i.e. all or nothing.
    137      */
    138     int Lock();
     207     *
     208     * @return COM status code
     209     */
     210    HRESULT Lock();
    139211
    140212    /**
    141213     * Release all medium locks.
    142      */
    143     int Unlock();
     214     *
     215     * @return COM status code
     216     */
     217    HRESULT Unlock();
    144218
    145219private:
    146     std::list<MediumLock> mMediumLocks;
     220    Base mMediumLocks;
    147221    bool mIsLocked;
    148 }
     222};
    149223
    150224/**
     
    163237
    164238    /**
    165      * Default medium lock list destructor.
     239     * Default medium lock list map destructor.
    166240     */
    167241    ~MediumLockListMap();
    168242
     243    /**
     244     * Checks if medium lock list map is empty.
     245     *
     246     * @return true if list is empty.
     247     */
     248    bool IsEmpty();
     249
     250    /**
     251     * Insert a new medium lock list into the map.
     252     *
     253     * @note May be only used in unlocked state.
     254     *
     255     * @return COM status code
     256     * @param aMediumAttachment Reference to medium attachment object, the key.
     257     * @param aMediumLockList   Reference to medium lock list object
     258     */
     259    HRESULT Insert(const ComObjPtr<MediumAttachment> &aMediumAttachment, MediumLockList *aMediumLockList);
     260
     261    /**
     262     * Replace the medium lock list key by a different one.
     263     *
     264     * @note May be used in locked state.
     265     *
     266     * @return COM status code
     267     * @param aMediumAttachmentOld  Reference to medium attachment object.
     268     * @param aMediumAttachmentNew  Reference to medium attachment object.
     269     */
     270    HRESULT ReplaceKey(const ComObjPtr<MediumAttachment> &aMediumAttachmentOld, const ComObjPtr<MediumAttachment> &aMediumAttachmentNew);
     271
     272    /**
     273     * Remove a medium lock list from the map. The list will get deleted.
     274     *
     275     * @note May be only used in unlocked state.
     276     *
     277     * @return COM status code
     278     * @param aMediumAttachment Reference to medium attachment object, the key.
     279     */
     280    HRESULT Remove(const ComObjPtr<MediumAttachment> &aMediumAttachment);
     281
     282    /**
     283     * Clear all medium lock declarations in this map.
     284     *
     285     * @note Implicitly unlocks all locks.
     286     *
     287     * @return COM status code
     288     */
     289    HRESULT Clear();
     290
     291    /**
     292     * Get the medium lock list identified by the given key.
     293     *
     294     * @note May be used in locked state.
     295     *
     296     * @return COM status code
     297     * @param aMediumAttachment     Key for medium attachment object.
     298     * @param aMediumLockList       Out: medium attachment object reference.
     299     */
     300    HRESULT Get(const ComObjPtr<MediumAttachment> &aMediumAttachment, MediumLockList * &aMediumLockList);
     301
     302    /**
     303     * Acquire all medium locks "atomically", i.e. all or nothing.
     304     *
     305     * @return COM status code
     306     */
     307    HRESULT Lock();
     308
     309    /**
     310     * Release all medium locks.
     311     *
     312     * @return COM status code
     313     */
     314    HRESULT Unlock();
     315
    169316private:
    170     std::map<ComObjPtr<Medium>, MediumLockList *> mMediumLocks;
    171 }
     317    typedef std::map<ComObjPtr<MediumAttachment>, MediumLockList *> Base;
     318    Base mMediumLocks;
     319    bool mIsLocked;
     320};
    172321
    173322#endif /* !____H_MEDIUMLOCK */
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