Welcome to libclay project

The Clay library (libclay) is a simple framework for multi-module integration.

It also supports dynamic plugins with DLL files (in Win32) or SO files (in Linux).


Find project details

please see http://sourceforge.net/projects/libclay


Download source files

please see http://sourceforge.net/projects/libclay/files


Get user guide

please see Quick Start and Document





Quick start for clay library

 

1.What is clay library ?

The Clay library (libclay) is a simple framework for multi-module integration.

It also supports dynamic plugins with DLL files (in Win32) or SO files (in Linux).

 

2.What can libclay do?

 

Before use libclay:

 

#include "ModuleA.h"

#include "ModuleB.h"

#include "ModuleC.h"

 

int main()

{

Function1InModuleA();

Function2InModuleB();

Function3InModuleC();

return 0;

}

 

After use libclay:

 

// #include "ModuleA.h"

// #include "ModuleB.h"

// #include "ModuleC.h"

 

#include "clay.h"

 

int main()

{

// Function1InModuleA();

// Function2InModuleB();

// Function3InModuleC();

 

clay::lib::CallService("ModuleA", "Function1");

clay::lib::CallService("ModuleB", "Function2");

clay::lib::CallService("ModuleC", "Function3");

 

return 0;

}

 

3.How to use libclay to do module integration?

StepA:

First, you have to create a new class as an interface class to wrap the module you want to integrate.

The interface class must inherit from the class clay::core::ClayServiceProvider.

Here is a sample

(HelloModule is wrapped, the function SayFunctionInHelloModule() is defined in HelloModule.h file):

 

Hello.h

 

class HelloServiceProvider: public clay::core::ClayServiceProvider

{

private:

protected:

    virtual void SetupServices();

    int SayHello(void* pParam);

public:

    explicit HelloServiceProvider(const std::string& sName);

    virtual ~HelloServiceProvider();

};

 

Hello.cpp

 

#include "Hello.h"

#include "HelloModule.h"  // the module you need to wrap

 

static HelloServiceProvider* g_pHelloServiceProvider = new HelloServiceProvider("Hello");

 

HelloServiceProvider::HelloServiceProvider(const std::string& sName)

: clay::core::ClayServiceProvider(sName)

{

      // Register the interface functions of the provider

SetupServices();


// Register current provider

clay::lib::RegisterSp(this);


// After the register, the framework will own the life of the provider's pointer,

// So from now on, developers should not try to delete it themselves.

}

 

HelloServiceProvider::~HelloServiceProvider() { return; }

 

void HelloServiceProvider::SetupServices()

{

    RegisterService("SayHello", CLAY_SVC_FUNC(HelloServiceProvider::SayHello));

}

 

int HelloServiceProvider::SayHello(void* pParam)

{

    return SayFunctionInHelloModule(pParam);  // the function you want to wrap

}

 

StepB:

Then, use clay::lib::CallService(sModuleName, sFunctionName, pParam); to replace the original function called in main.cpp.

 

main.cpp

 

// #include "HelloModule.h"

#include "clay.h"

 

int main()

{

char* sSomebody = "Somebody";

 

// SayFunctionInHelloModule(sSomebody);

clay::lib::CallService("Hello", "SayHello", (void*)sSomebody);

 

return 0;

}

 

 

4.How to use libclay to implement the plug-in function?

 

For example, we assume we are going to plug-in a DLL(Hello.dll) into a Win32 program,

we need to do :


(StepA and StepB are implemented in DLL project)


StepA: First, we still need to create an inteface class, please refer to the StepA in point 3.

StepB:

In main.h and main.cpp files of the DLL project, we need to write two interface functions:

 

main.h

 

#include <windows.h>


int DLL_EXPORT InitAgent(void* pParam);
int DLL_EXPORT InitModule(void* pParam);


 

main.cpp

 

#include "main.h"

#include "Hello.h"


int DLL_EXPORT InitAgent(void* pParam)
{
    clay::lib::SetAgent(pParam);
    return 0;
}

int DLL_EXPORT InitModule(void* pParam)
{
    std::string sProviderName((char*)pParam);
    return (int) new HelloServiceProvider(sProviderName);
}



(StepC is implemented in the main project which will call some functions of the DLL project)


StepC:

In main.cpp of the main program, which the DLL would attached to, we need to use the function

clay::lib::Plugin(sModuleName, sModuleFile); to plug in the external module from the DLL file,

and then we would still be able to use the function

clay::lib::CallService(sModuleName, sFunctionName, pParam);

to call the functions in the external module:

 

main.cpp

 

#include "clay.h"

#include "clay_plugin.h"

int main()

{

char* sSomebody = "Somebody";

 

clay::lib::Plugin("Hello", "Hello.dll");

 

clay::lib::CallService("Hello", "SayHello", (void*)sSomebody);

return 0;

}

 

 

5.Is libclay a cross-platform library?

Yes. Currently, libclay can work with/without SDL & wxWidgets.

If you are going to use libclay with SDL or wxWidgets, libclay will support all the platforms SDL/wxWidgets supports.

If you want libclay to work without SDL & wxWidgets, please note that: in current version, the plug-in function of libclay only supports the raw API of Windows & Linux.

You should define the right switch to build the proper version you want:

Use define "__WIN32__" to compile the library in Windows.
Use define "__LINUX__" to compile the library in Linux.
Use define "__CLAY_SDL__" to compile the library with SDL.
Use define "__CLAY_WX__" to compile the library with wxWidgets.

 

 

6.Is libclay an open source library? What is the license of libclay?

Yes. The Clay library (libclay) is licensed under the terms of the MIT license.

 

 

7.How can I get more help about libclay?

Please see http://libclay.sourceforge.net .