Print
Category: Zeus Framework
Hits: 5497

Index of Framework Extension


1. General

This example shows you how to use zeus framework from a programming point of view. We will show you how to extend the functionality of the Zeus-Framework, witch is our base at anytime. First we start with our main application and the minimum implementation used to run our application.

The example code is included by the Zeus-Framework package as "zeus". The zeus application is a simple platform to load code modules and build object hierachies using xml.

1.1 The main program

Our main application must include the libraries of zeus, the zeus-base and the zeus-dev.

Those libraries must also included when we create a new code module (See step 4).
Our main function must start the framework. First we initialize the logger for standard out logging.


TAutoPtr<ILogger> pStdLogger = new TStdLogger();
LoggerManager.setRootLogger(*pStdLogger);

To start the framework we must implement our own framework loader class (in this example TCCMFrameLoader). Using startup() the framework will load the xml-ressource file from the directory and build up the object tree (See Zeus-Framework specification for object tree informations).

To close the framework we must call shutdown(). All resources will be released and the code modules will be unloaded.


try
{
  TAutoPtr<TCCMFrameLoader> pLoader = new TCCMFrameLoader(argc, argv);
  pLoader->initialize();
  ...
  pLoader->startup();
  ...
  retval = pLoader->run();
  ...
  pLoader->shutdown();
  ...
  
}
catch(...)
{
  RootLogger.unindent();
  RootLogger.printfln(LOGMODE_INFO, 
                      "Exception received. Killing all life :-(");
}

1.2 Step 2. The frame loader

Now we must implement our own loader class (in this example TCCMFrameLoader). We use the abstract class TAbstractFrameLoader from the Zeus-Base package as a base class.


#include <zeusbase/AbstractFrameLoader.h>
...
BEGIN_NAMESPACE_Zeus
...

class TCCMFrameLoader : public TAbstractFrameLoader
{
  public:
    TCCMFrameLoader(int argc, char *argv[]);
    ...
    //Methods of TAbstractFrameLoader
    virtual Int run();
    virtual Retval startup();
    virtual Retval shutdown();

  protected:
    virtual ~TCCMFrameLoader();
    
  private:
    ...
};
...

Inside the overwritten methods you must call the methods of the base class. Before and after this call, you may insert your own code. The run() Method is defined abstract inside the class TAbstractFrameLoader.

The Object m_pApplication is used to control a console application. If you want to use QT or borland VCL use their application object. This TApplication class waits inside start() until CTRL+C is pressed or a signal has been sent.


Retval TCCMFrameLoader::startup()
{
  //insert your own code here
  ...  
  Retval retValue = TAbstractFrameLoader::startup();
  
  //insert your own code here
  ....
  return retValue;
}

Retval TCCMFrameLoader::shutdown()
{
  //insert your own code here
  ...  
  Retval retValue = TAbstractFrameLoader::shutdown();
  
  //insert your own code here
  ...  
  return retValue;
}

Int TCCMFrameLoader::run()
{
  m_pApplication->start();
  return 0; //Return error code (EXIT CODE)
}

1.3 Step 3: How to register custom classes

The base class TAbstractFrameLoader has a method registerClasses(), witch is called when an object of TAbstractFrameLoader has been created. This method registeres all customized XObject-Classes (See Zeus-Framework Specification for detailed description on XObjects). This method can be overwritten as well. In the following example we have a custom class TMyFrameLoader, witch has to register two XObject classes. TXMyRootObject is a root object class, witch can manage an entire xml file. TXMySubObject is also an XObject-class, but represents only a xml node.


//Custom class declaration
class TMyFrameLoader : public TAbstractFrameLoader
{
  ...
  proteced:
    virtual void registerClasses();
  ...
}

//Implementation
void TMyFrameLoader::registerClasses()
{
  //Call super class
  TAbstractFrameLoader::registerClasses();
  
  XOBJECTFACTORY_REGISTER_ROOT(TXMyRootObject);
  XOBJECTFACTORY_REGISTER_SUB(TXMySubObject);
  ...
}


2. Download the source

The examble is included in the Zeus-Framework. You find the code in the /src/zeus/ directory.
Go to the download page here