Thread: [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.
}
|
|
From: Artyom B. <art...@ya...> - 2013-04-27 07:51:16
|
In general there is no built in loadable module support of the applications, it is planned for next release: http://cppcms.com/wikipp/en/page/cppcms_1x_tasks#Provide.Plugin.Framework But many users had already implement such kind of support, there is class that allows to load modules easily http://cppcms.com/cppcms_ref/latest/classbooster_1_1shared__object.html And cppcms templates are fully pluggable, i.e. they are self registered so only thing you need to do is to link the templates to shared object that you are loading. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ >________________________________ > From: Saikumar Gandapodi <sai...@gm...> >To: cpp...@li... >Sent: Wednesday, April 24, 2013 4:54 PM >Subject: [Cppcms-users] Page handlers from configuration > > >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. >} > > > >------------------------------------------------------------------------------ >Try New Relic Now & We'll Send You this Cool Shirt >New Relic is the only SaaS-based application performance monitoring service >that delivers powerful full stack analytics. Optimize and monitor your >browser, app, & servers with just a few lines of code. Try New Relic >and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr >_______________________________________________ >Cppcms-users mailing list >Cpp...@li... >https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > |
|
From: Saikumar G. <sai...@gm...> - 2013-04-28 11:54:42
|
If there is a mapping like this
dispatcher().assign("/login", &Server::loginpage, this);
Is possible to know the assigned path ( "login") at runtime from inside
the loginpage() method ?
|
|
From: Artyom B. <art...@ya...> - 2013-04-29 06:33:21
|
What do you mean?
- You mean what parameter was given?
The obvious
void loginpage(std::string url)
dispatcher().assing("/login,&server::loginpage,this,0);
- What regular expression was used?
For "reverse" path generation you can use
URL mapping (the opposite of dispatching).
- What is the full mapping path? You can use CGI variables:
request().path_info() to get the full path.
Artyom Beilis
--------------
CppCMS - C++ Web Framework: http://cppcms.com/
CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/
----- Original Message -----
> From: Saikumar Gandapodi <sai...@gm...>
> To: cpp...@li...
> Cc:
> Sent: Sunday, April 28, 2013 2:54 PM
> Subject: Re: [Cppcms-users] Page handlers from configuration
>
> If there is a mapping like this
>
> dispatcher().assign("/login", &Server::loginpage, this);
>
> Is possible to know the assigned path ( "login") at runtime from
> inside
> the loginpage() method ?
>
>
>
>
> ------------------------------------------------------------------------------
> Try New Relic Now & We'll Send You this Cool Shirt
> New Relic is the only SaaS-based application performance monitoring service
> that delivers powerful full stack analytics. Optimize and monitor your
> browser, app, & servers with just a few lines of code. Try New Relic
> and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
> _______________________________________________
> Cppcms-users mailing list
> Cpp...@li...
> https://lists.sourceforge.net/lists/listinfo/cppcms-users
>
|
|
From: Saikumar G. <sai...@gm...> - 2013-04-30 04:24:47
|
Great. The argument "url" solves my issue.
void loginpage(std::string url)
dispatcher().assign("/login", &server::loginpage, this,0);
With this I can lookup the associated page handler through command pattern
and it can be set in the configuration file.
Thanks.
|