Guest User

Marco

a guest
Apr 28th, 2015
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1.  
  2. #include <Wt/WServer>
  3. #include <Wt/WResource>
  4. #include <Wt/WApplication>
  5. #include <Wt/WContainerWidget>
  6. #include <Wt/Http/Response>
  7.  
  8. #include <Wt/WVBoxLayout>
  9. #include <Wt/WText>
  10.  
  11.  
  12. using namespace Wt;
  13.  
  14.  
  15.  
  16.  
  17. class MyResource : public Wt::WResource
  18. {
  19.  
  20. public:
  21.   MyResource (Wt::WObject *parent = nullptr);
  22.   ~MyResource ();
  23.  
  24.   void handleRequest (const Wt::Http::Request& request, Wt::Http::Response& response);
  25. };
  26.  
  27. MyResource::MyResource (Wt::WObject *parent)
  28.    : Wt::WResource(parent)
  29. {
  30.    suggestFileName("data.txt");
  31. }
  32.  
  33. MyResource::~MyResource ()
  34. {
  35.    beingDeleted(); // see "Concurrency issues" below.
  36. }
  37.  
  38. void MyResource::handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response)
  39. {
  40.    response.setMimeType("plain/text");
  41.    response.out() << "I am a text file." << std::endl;
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50. class WtTest : public Wt::WApplication {
  51.  
  52. public:
  53.    WtTest (const Wt::WEnvironment &environment);
  54.    virtual ~WtTest ();
  55.  
  56.    static WtTest* CreateInstance (const Wt::WEnvironment &environment);
  57. };
  58.  
  59. WtTest::WtTest (const Wt::WEnvironment &environment)
  60.    : Wt::WApplication(environment)
  61. {
  62.    auto layout = new WVBoxLayout(root());
  63.    layout->addWidget(new WText("Hallo Welt"));
  64.    layout->addStretch(1);
  65. }
  66.  
  67. WtTest::~WtTest()
  68. {
  69. }
  70.  
  71. WtTest* WtTest::CreateInstance (const Wt::WEnvironment &environment)
  72. {
  73.    return new WtTest(environment);
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84. // --http-address=0.0.0.0 --http-port=80 --docroot=.
  85. int main (int argc, char** argv)
  86. {
  87.    WServer wserver(argc, argv);
  88.    wserver.addEntryPoint(Wt::Application, &WtTest::CreateInstance);
  89.  
  90.    // without this 2 lines its not crashing...
  91.    MyResource res1;
  92.    wserver.addResource(&res1, "/res1");
  93.  
  94.    wserver.start();
  95.    wserver.waitForShutdown();
  96.  
  97.    return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment