www.pudn.com > vls-0.5.6.rar > framework.sgml
VLS framework Overview The VLS framework is a set of low-level classes used by every other classes. Currently, it can handle: Buffers ( src/core/buffers.* )Configuration files ( src/core/settings.* )Exceptions ( src/core/exception.* )Files ( src/core/file.* )Hash tables ( src/core/hashtable.* )Dynamic libraries ( src/core/library.* )IO streams ( src/core/stream.* )Lists ( src/core/list.* )Logging ( src/core/log.* )Modules ( src/core/module.* )Parsing ( src/core/parsers.* )Session handling ( src/core/network.* )Serialization ( src/core/serialization.* )Sockets ( src/core/socket.* )Stacks ( src/core/stack.* )Threads ( src/core/thread.* )Vectors ( src/core/vector.* )Threads A class that must be run in a new thread has to extend the C_Thread abstract class. Pure virtual functions that must be implemented by such a class are: To create the thread, the derived class just has to call the void InitWork() This method is called before the thread is created. void DoWork() It is called just after the thread is created. The main loop of the class should be put here. void StopWork() This method is called when the thread is to be stopped or canceled. void CleanWork() This method is called after the shutdown of the thread. Create() method. To stop the thread, just callStop() .Modules Whenever a class is optional, it should be implemented as a module. A module can be: Here are the differents steps required to add a new module: a built-in module: it means the module is linked statically, though classes are of course instanciated dynamically. a plug-in module: in this case, the classes are linked in a shared library, and loaded dynamically at runtime. Declare a new module type. Indeed, modules of the same type are derived from the same class, called a "virtual module". For instance, DvdMpegReader and FileMpegReader are both derived from the module type "MpegReader". To declare a class as a virtual module, use the DECLARE_VIRTUAL_MODULE macro: // in classtype.h C_ The virtual module constructor must have two arguments: C_Module *pModule andClassType { public: C_ClassType (C_Module *pModule,argType val) // Class declaration }; DECLARE_VIRTUAL_MODULE(ClassType , "strType ",argType );argType val, whereargType can be anything (defined in the DECLARE_VIRTUAL_MODULE macro). The virtual module destructor have to callpModule->Unref() .strType is the name given to the module type.Declare the module itself. Like virtual modules, use the DECLARE_MODULE macro after the class declaration: // in classname.h C_ ClassName ClassType : publicClassType { public: C_ClassName ClassType (C_Module *pModule,argType val) // Class declaration }; DECLARE_MODULE(ClassName ,ClassType , "strType ",argType );Add some declarations for libraries and built-in modules: // in classname.cpp //------------------------------------------------------------------------------ // Library declaration //------------------------------------------------------------------------------ #ifdef __PLUGIN__ GENERATE_LIB_ARGS(C_ ClassName ClassType Module, handle); #endif //------------------------------------------------------------------------------ // Builtin declaration //------------------------------------------------------------------------------ #ifdef __BUILTIN__ C_Module* NewBuiltin_classname classtype (handle hLog) { return new C_ClassName ClassType Module(hLog); } #endifAdd the module in configure.in . For a built-in module, add the file name in the line BUILTINS=... For a plug-in module, it is more complicated; look what is done for existing plug-ins.