pregmatch
pregmatch

Reputation: 2657

cppcms - why is hello world with url mapping not working?

I am having trouble with cppcms hello world example with url mapping.

I am having trouble with understanding this part:

int main(int argc,char ** argv)
{  
    try {
        cppcms::service srv(argc,argv);


        srv.applications_pool().mount(
                cppcms::applications_factory<hello>() //i do not understand this part
        );

        srv.run();
    }
    catch(std::exception const &e) {
        std::cerr << e.what() << std::endl;
    }
}

In tutorial said /hello - welcome function would be called but that is not what is happening. This method is called instead:

void hello::main(std::string /*url*/)
{
    response().out() <<
        "<html>\n"
        "<body>\n"
        "  <h1>Hello World</h1>\n"
        "</body>\n"
        "</html>\n";
}

Welcome method look like this and it is defined in a scope of hello class:

void welcome()
{
    response().out() <<
        "<h1> Welcome To Page with links </h1>\n"
        "<a href='" << url("/number",1)  << "'>1</a><br>\n"
        "<a href='" << url("/number",15) << "'>15</a><br>\n"
        "<a href='" << url("/smile") << "' >:-)</a><br>\n";
}

I need some answers if you can help me. I am just trying to understand so if you could point me to right direction it would be great.

Upvotes: 2

Views: 487

Answers (2)

The Floating Brain
The Floating Brain

Reputation: 966

I do not personally know much about this library, however it looks like in the line:

cppcms::applications_factory<hello>()

Your assosating the server with, and instantaiteing some sort of hello class. However I

Upvotes: 0

Gerald
Gerald

Reputation: 23499

You need to setup the mapping in your hello constructor, as shown in both the hello world example and the link you posted in your answer.

In particular, this part:

dispatcher().assign("",&hello::welcome,this);  
mapper().assign("");  

mapper().root("/hello");  

This maps the default route of the hello application to the "welcome" method. If you don't set a mapping, it's going to default to main.

Upvotes: 3

Related Questions