Chapter 2. VLS framework

Table of Contents
Overview
Threads
Modules

Overview

The VLS framework is a set of low-level classes used by every other classes. Currently, it can handle:

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:

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

  1. 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.

  2. 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);
        

  3. Add some declarations for libraries and built-in modules:

    
// in classname.cpp
    
    //------------------------------------------------------------------------------
    // Library declaration
    //------------------------------------------------------------------------------
    #ifdef PIC
    GENERATE_LIB_ARGS(C_ClassNameClassTypeModule, handle);
    #endif
    
    
    //------------------------------------------------------------------------------
    // Builtin declaration
    //------------------------------------------------------------------------------
    #ifndef PIC
    C_Module* NewBuiltin_classnameclasstype(handle hLog)
    {
      return new C_ClassNameClassTypeModule(hLog);
    }
    #endif
        

  4. 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.