Simple Module Sample in C++

The simple module sample demonstrates how to embed your application into the AppWeb server by creating a simple AppWeb loadable module. The sample uses the AppWeb MaModule class and creates a loadable DLL or shared library.

The sample will run inside the AppWeb server when configured to load via the appWeb configuration file. 

Files

simpleModule.h
simpleModule.cpp

Configuration File

To load the module once built, you need to add the following line to your AppWeb configuration file. Add this after the existing LoadModule directives.


LoadModule simpleModule ../../../lib/libsimpleModule

Source Code

The sample includes four files:

simpleModule.h

//
// Copyright (c) Mbedthis Software LLC, 2003-2004. All Rights Reserved.
//
/// @file simpleModule.h
/// @brief Header for the simpleModule
///

#ifndef _h_SIMPLE_MODULE
#define _h_SIMPLE_MODULE 1
////////////////////////////// Includes ////////////////////////////////

#include "appWeb/appWeb.h"

////////////////////////// Forward Definitions /////////////////////////

class SimpleModule;

extern "C" {
extern int mprSimpleModuleInit(void *handle);
};

////////////////////////////////////////////////////////////////////////
///////////////////////////// SimpleModule /////////////////////////////
////////////////////////////////////////////////////////////////////////

class SimpleModule : public MaModule {
public:
SimpleModule(void *handle);
~SimpleModule();
int parseConfig(char *key, char *value, MaServer *server,
MaHost *host, MaAuth *auth, MaDir* dir,
MaLocation *location);
int start();
void stop();
};

////////////////////////////////////////////////////////////////////////
#endif // _h_SIMPLE_MODULE

simpleModule.cpp

//
// Copyright (c) Mbedthis Software LLC, 2003-2004. All Rights Reserved.
//
/// @file simpleModule.cpp
/// @brief Create a simple AppWeb dynamically loadable module
///

////////////////////////////// Includes ////////////////////////////////

#include "simpleModule.h"

////////////////////////////////////////////////////////////////////////
///////////////////////////// SimpleModule /////////////////////////////
////////////////////////////////////////////////////////////////////////

///
/// This function is called when the module is dynamically loaded
///

int mprSimpleModuleInit(void *handle)
{
mprLog(0, "In mprSimpleModuleInit()\n");
new SimpleModule(handle);
return 0;
}

////////////////////////////////////////////////////////////////////////

///
/// The constructor is called by either the DLL load entry point
/// above, or if not using DLLs, it should be called directly from
/// your application at initialization time.
///


SimpleModule::SimpleModule(void *handle) : MaModule("simpleModule",
handle)
{
mprLog(0, "In SimpleModule()\n");
}

////////////////////////////////////////////////////////////////////////

SimpleModule::~SimpleModule()
{
mprLog(0, "In ~SimpleModule()\n");
}

////////////////////////////////////////////////////////////////////////

int SimpleModule::parseConfig(char *key, char *value, MaServer *server,
MaHost *host, MaAuth *auth, MaDir* dir, MaLocation *location)
{
if (mprStrCmpAnyCase(key, "simpleDirective") == 0) {
//
// Put code here to parse the "value". Return 1 to indicate
// we have processed this directive.
//
return 1;
}
return 0;
}

////////////////////////////////////////////////////////////////////////
//
// AppWeb is starting up
//

int SimpleModule::start()
{
//
// Put startup code here
//
return 0;
}

////////////////////////////////////////////////////////////////////////
//
// AppWeb is shutting down
//

void SimpleModule::stop()
{
//
// Put shutdown code here
//
}

////////////////////////////////////////////////////////////////////////


© Mbedthis Software LLC, 2003-2204. All rights reserved. Mbedthis is a trademark of Mbedthis Software LLC.