Project

General

Profile

Bug #4878 ยป restest.cpp

Henry Morgan, 04/28/2016 10:04 PM

 
#include <Wt/WServer>
#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <Wt/WContainerWidget>
#include <Wt/WResource>
#include <Wt/Http/Response>
#include <Wt/WBootstrapTheme>
#include <Wt/WText>
#include <Wt/WTimer>

class CTestResource: public Wt::WResource
{
public:
CTestResource(): Wt::WResource()
{
m_pTimer = new Wt::WTimer();
m_pTimer->setInterval(10000);
m_pTimer->setSingleShot(true);
m_pTimer->timeout().connect(this, &CTestResource::OnTimer);
m_pTimer->start();
}
void OnTimer(void)
{
std::cerr << "expired" << std::endl;
}
void handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response)
{
std::cerr << "Call dummy" << std::endl;
Dummy();
response.setMimeType("application/javascript");
response.out() << "This is a test.";
}
void Dummy(void)
{
if(m_pTimer->isActive())
{
m_pTimer->stop();
}
m_pTimer->start();
std::cerr << "do nothing?" << std::endl;
}

CTestResource *m_pSelf = this;
Wt::WTimer *m_pTimer;
};

class CTestApplication: public Wt::WApplication
{
public:
CTestApplication(const Wt::WEnvironment& oEnv): Wt::WApplication(oEnv)
{
std::string strLoadingObjectManagerResource = "/test";// + instance()->environment().sessionId(); //<-enable for multisession
root()->addWidget(new Wt::WText("Use:" + strLoadingObjectManagerResource));
instance()->environment().server()->addResource(&m_oTestResource, strLoadingObjectManagerResource);
}
CTestResource m_oTestResource;
};




Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
Wt::WApplication *oApplication = new CTestApplication(env);
Wt::WBootstrapTheme *oBootstrapTheme = new Wt::WBootstrapTheme(oApplication);
oBootstrapTheme->setVersion(Wt::WBootstrapTheme::Version3);
oBootstrapTheme->setResponsive(true);
oApplication->setTheme(oBootstrapTheme);
return oApplication;
}

int main(int argc, char **argv)
{
try
{
Wt::WServer oServer(argc, argv, WTHTTP_CONFIGURATION);
oServer.addEntryPoint(Wt::Application, createApplication);
oServer.run();
}
catch (Wt::WServer::Exception& e)
{
std::cerr << e.what() << std::endl;
}
catch (std::exception &e)
{
std::cerr << "exception: " << e.what() << std::endl;
}
}
    (1-1/1)