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
Makefile
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
Makefile
The Makefile will build on Windows or Linux. A Windows VS 6.0
project file is also supplied.
Typical output from the Makefile build is listed below. This
is the output on a Windows system:
cl -o simpleModule.dll simpleModule.cpp -Zi -Od -D_NDEBUG -W3 -nologo -MDd -FD -DWIN -D_DLL -D_MT \
-D_WINDOWS -DWIN32 -D_WIN32_WINNT=0x500 -D_X86_=1 -D_CRT_SECURE_NO_DEPRECATE -D_USRDLL \
-I../../../include -LD ../../../bin/libappwebStatic.lib ws2_32.lib advapi32.lib user32.lib
Source Code
The sample includes two source
files:
simpleModule.h
///
/// @file simpleModule.h
/// @brief Header for the simpleModule
///
// Copyright (c) Embedthis Software LLC, 2003-2009. All Rights Reserved.
//
////////////////////////////// Includes ////////////////////////////////
#ifndef _h_SIMPLE_MODULE
#define _h_SIMPLE_MODULE 1
#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
///
/// @file simpleModule.cpp
/// @brief Create a simple Appweb dynamically loadable module
//
// Copyright (c) Embedthis Software LLC, 2003-2009. All Rights Reserved.
//
////////////////////////////// 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()
{
//
// Put cleanup code here for when Appweb is exiting
//
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
//
}
////////////////////////////////////////////////////////////////////////