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:


  
    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.
    
  


To create the thread, the derived class just has to call the Create()
 method. To stop the thread, just call Stop().




Modules


Whenever a class is optional, it should be implemented as a module. A module
can be:

  
    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.
  


Here are the differents steps required to add a new module:


  
    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_ClassType 
{
 public:
  C_ClassType(C_Module *pModule, argType val)
  // Class declaration
};
    
DECLARE_VIRTUAL_MODULE(ClassType, "strType", argType);
    
    
    The virtual module constructor must have two arguments: C_Module *pModule 
    and argType val, where argType can
    be anything (defined in the DECLARE_VIRTUAL_MODULE macro). The virtual
    module destructor have to call pModule->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_ClassNameClassType : public ClassType
{
 public:
  C_ClassNameClassType(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_ClassNameClassTypeModule, handle);
#endif


//------------------------------------------------------------------------------
// Builtin declaration
//------------------------------------------------------------------------------
#ifdef __BUILTIN__
C_Module* NewBuiltin_classnameclasstype(handle hLog)
{
  return new C_ClassNameClassTypeModule(hLog);
}
#endif
    
  
  
  
  
  Add 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.