Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

VirtualBoxBaseProto::AutoInitSpan Class Reference

#include <VirtualBoxBase.h>

List of all members.

Detailed Description

Smart class to enclose the state transition NotReady->InInit->Ready.

The purpose of this span is to protect object initialization.

Instances must be created as a stack-based variable taking |this| pointer as the argument at the beginning of init() methods of VirtualBoxBase subclasses. When this variable is created it automatically places the object to the InInit state.

When the created variable goes out of scope (i.e. gets destroyed) then, depending on the result status of this initialization span, it either places the object to Ready or Limited state or calls the object's VirtualBoxBase::uninit() method which is supposed to place the object back to the NotReady state using the AutoUninitSpan class.

The initial result status of the initialization span is determined by the aResult argument of the AutoInitSpan constructor (Result::Failed by default). Inside the initialization span, the success status can be set to Result::Succeeded using setSucceeded(), to to Result::Limited using setLimited() or to Result::Failed using setFailed(). Please don't forget to set the correct success status before getting the AutoInitSpan variable destroyed (for example, by performing an early return from the init() method)!

Note that if an instance of this class gets constructed when the object is in the state other than NotReady, isOk() returns |false| and methods of this class do nothing: the state transition is not performed.

A typical usage pattern is: HRESULT Component::init() { AutoInitSpan autoInitSpan (this); AssertReturn (autoInitSpan.isOk(), E_FAIL); ... if (FAILED (rc)) return rc; ... if (SUCCEEDED (rc)) autoInitSpan.setSucceeded(); return rc; }

Never create instances of this class outside init() methods of VirtualBoxBase subclasses and never pass anything other than |this| as the argument to the constructor!

Definition at line 893 of file VirtualBoxBase.h.

Public Types

enum  Result { Failed = 0x0, Succeeded = 0x1, Limited = 0x2 }

Public Member Functions

 AutoInitSpan (VirtualBoxBaseProto *aObj, Result aResult=Failed)
bool isOk () const
Result result ()
void setFailed ()
void setLimited ()
void setSucceeded ()
 ~AutoInitSpan ()

Private Attributes

bool mOk: 1
Result mResult: 3

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index