home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Module.h
-
- The module class allows us to have independent pieces of code which are initialized
- automatically at system startup. Unlike the C++ static constructor method, this
- is guaranteed to happen at a safe time
-
- */
-
- #ifndef __MODULE__
- #define __MODULE__
- #pragma once
-
- #include "Object.h"
- #include "OTList.h"
-
- #define qCWoffsetofBug 1
-
- //--------------------------------------------------------------------------------
- class TModule : public virtual TObject
- {
- DeclareClassSingleAbstract(TModule, TObject);
-
- private:
- OTLink fNextModule;
-
- protected:
- TModule(bool early = false);
- virtual ~TModule();
-
- virtual bool Validate(void); // Check against system, possibly re-order
-
- virtual bool Available(void); // Return true if you have been initialized
- virtual bool Initialized(void); // Return true if you have been initialized
- virtual bool InitializeCalled(void); // Return true if you have been initialized
- virtual bool InitializeAfter(TModule& mod); // May be called during Initialize() to make
- // sure another module has been inti
- virtual bool IsRequired();
- virtual bool InitializeWhenUsed();
-
- static bool TestBit(long flags, int bit) { return flags & (1 << bit); }
-
- public:
- static bool InitializeModules(void); // Initialize all modules in system
- static void FinalizeModules(void); // Reverse initialization
-
- static inline void UseModule(TModule& /*module*/) {}
-
- static OTList gUninitList; // list of uninitialized modules
- static OTList gInitedList; // list of initialized modules
- static OTList gFailedList; // list of modules which failed to initialize
-
- #if !qCWoffsetofBug
- typedef EmbeddedLinkPtr(TModule, fNextModule) ModuleLinkPtr;
- typedef EmbeddedLIFO(TModule, fNextModule) ModuleLIFO;
- typedef EmbeddedList(TModule, fNextModule) ModuleList;
-
- static inline ModuleList& GetUninitList() { return *(ModuleList*) &TModule::gUninitList; }
- static inline ModuleList& GetInitedList() { return *(ModuleList*) &TModule::gInitedList; }
- static inline ModuleList& GetFailedList() { return *(ModuleList*) &TModule::gFailedList; }
- #endif
-
- };
-
-
- #if qCWoffsetofBug
-
- typedef OTLinkPtr<TModule, 8> ModuleLinkPtr;
- typedef OTLIFOOf <TModule, 8> ModuleLIFO;
- typedef OTListOf <TModule, 8> ModuleList;
-
- inline ModuleList& GetUninitList() { return *(ModuleList*) &TModule::gUninitList; }
- inline ModuleList& GetInitedList() { return *(ModuleList*) &TModule::gInitedList; }
- inline ModuleList& GetFailedList() { return *(ModuleList*) &TModule::gFailedList; }
-
- #endif
-
- #endif // __MODULE__
-