bref
API 2014 of the Zia HTTP server.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Public Member Functions | Protected Member Functions | Protected Attributes
bref::AModule Class Reference

Class used to operate with dynamically loaded modules. More...

#include <AModule.h>

Inheritance diagram for bref::AModule:
bref::IDisposable

List of all members.

Public Member Functions

virtual const std::string & name () const
 Retrieve the module's name.
virtual const std::string & description () const
 Retrieve the module's description.
virtual const Version & version () const
 Retrieve the module's version.
virtual const Version & minimumApiVersion () const
 Retrieve the minimum API version the module is compatible with.
virtual void registerHooks (Pipeline &)
 Register the module hooks on the convenient hookpoints of the pipeline.
virtual IDisposable * registerSessionHooks (Pipeline &)
 Register the module hooks on the convenient hookpoints of the pipeline.

Protected Member Functions

 AModule (const std::string &name, const std::string &description, const Version &version, const Version &minimumApiVersion)
 AModule constructor, which defines module's informations.
virtual ~AModule ()
 Virtual destructor for the module.

Protected Attributes

std::string name_
 Contains module's name.
std::string description_
 Contains module's description.
Version version_
 Contains module version.
Version minimumApiVersion_
 Minimum API version.

Detailed Description

Class used to operate with dynamically loaded modules.

Each module must provide a function to allow its loading at runtime, matching the following prototype:

extern "C" bref::AModule *loadModule(bref::ILogger *,
                                     const bref::ServerConfig &,
                                     const bref::IConfHelper &);

Once the module is loaded, a version check should be performed as follows:


Constructor & Destructor Documentation

bref::AModule::AModule ( const std::string &  name,
const std::string &  description,
const Version &  version,
const Version &  minimumApiVersion 
) [protected]

AModule constructor, which defines module's informations.

Parameters:
nameContains module's name
descriptionContains module's description
versionContain's module's version
minimumApiVersionRequired API version to use the module
virtual bref::AModule::~AModule ( ) [inline, protected, virtual]

Virtual destructor for the module.

The delete() operator should not be called on the AModule instance. Please refer to the dispose() method.

Note:
The destructor is protected in order to disable the call to the delete() operator from the server code.
See also:
dispose()

Member Function Documentation

virtual const std::string& bref::AModule::description ( ) const [virtual]

Retrieve the module's description.

Returns:
The module's description.
virtual const Version& bref::AModule::minimumApiVersion ( ) const [virtual]

Retrieve the minimum API version the module is compatible with.

Returns:
The minimum API version supported by this module.
virtual const std::string& bref::AModule::name ( ) const [virtual]

Retrieve the module's name.

Returns:
The module's name.
virtual void bref::AModule::registerHooks ( Pipeline &  ) [inline, virtual]

Register the module hooks on the convenient hookpoints of the pipeline.

Example:

void registerHooks(Pipeline & pipeline)
{
  const float lowPriority = 0.5f;

  pipeline.connectionHooks.push_back(std::make_pair(&hook_function,
                                                    lowPriority));
}
Parameters:
[out]pipelineThe pipeline.
virtual IDisposable* bref::AModule::registerSessionHooks ( Pipeline &  ) [inline, virtual]

Register the module hooks on the convenient hookpoints of the pipeline.

This method should be called by the server each time a new connection is made. The server should call IDisposable::dispose() on the returned value (if not null) when the connection is closed.

Example:

using namespace bref;

class ModuleSession : public IDisposable
{
public:
  Pipeline::OnReceiveRequestHandler receive(const Environment &)
  {
    return Pipeline::OnReceiveRequestHandler();
  }

  virtual void dispose() { delete this; }
  virtual ~ModuleSession() { }
};

class Module
{
  virtual IDisposable *registerSessionHooks(Pipeline & pipeline)
  {
    ModuleSession           *ms = new ModuleSession();
    Pipeline::OnReceiveHook  hook(ms, &ModuleSession::receive);

    pipeline.onReceiveHooks.push_back(std::make_pair(hook, 0.5f));
    return ms;
  }

  virtual void dispose() { delete this; }
};
Parameters:
[out]pipelineThe pipeline.
Returns:
A disposable instance, or null instead.
virtual const Version& bref::AModule::version ( ) const [virtual]

Retrieve the module's version.

Returns:
The module's version.

Member Data Documentation

std::string bref::AModule::description_ [protected]

Contains module's description.

See also:
description()

Minimum API version.

See also:
minimumApiVersion()
std::string bref::AModule::name_ [protected]

Contains module's name.

See also:
name()

Contains module version.

See also:
version()

The documentation for this class was generated from the following file: