[Cppcms-users] Page handlers from configuration
Brought to you by:
artyom-beilis
|
From: Saikumar G. <sai...@gm...> - 2013-04-24 13:54:45
|
Before I reinvent the wheel, I wanted to check with you first to see if there
is an easier method to accomplish this.
Goal: I want to specify the dispatch handler method through means of a class
whose instance is created through a class factory using a service name.
Why: So that we can specify the page handlers through the configuration file and
not touch the main module for adding/updating/deleting a page.
You can notice that the service module is created using a class factory and used
for the assign method in dispatcher.
I know the below code is wrong and will not work, but wanted to show you the
concept what I would like to accomplish.
Any ideas ?
void CPPCMSServer::initmapping( cppcms::service &srv ) {
string page = "/login"; // Read from the configuration
// Creates an instance of LoginServiceModule
ServiceModule *sm = CreateServiceModuleFactory(page);
dispatcher().assign(page, &ServiceModule::processRequest, sm);
}
class ServiceModule
{
public:
virtual void processRequest(cppcms::application &app) = 0;
};
class LoginServiceModule : public ServiceModule {
public:
LoginServiceModule() {}
void processRequest(cppcms::application &app);
};
void LoginServiceModule::processRequest(cppcms::application &app) {
// Process page request for "/main/login" page.
}
|