Webtoolkit

From campisano.org
Jump to navigation Jump to search

Environment

# cat /etc/debian_version 
6.0.6
# gcc -v
gcc version 4.4.5 (Debian 4.4.5-8) 
# uname -r
3.2.0-0.bpo.3-amd64


Depends

apt-get install libwt-dev libwtfcgi-dev libapache2-mod-fastcgi
a2enmod fastcgi


Apache config

from http://whocares.de/fastcgiexternalserver-demystified/all/1/

<IfModule mod_fastcgi.c>
    FastCGIExternalServer /tmp/my_app.fastcgi -host 127.0.0.1:9000
    Alias /my_app /tmp/my_app.fastcgi
</IfModule>


First Wt app

#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WLineEdit>
#include <Wt/WPushButton>
#include <Wt/WText>

class HelloApplication : public Wt::WApplication
{
public:
    HelloApplication(const Wt::WEnvironment& env);

private:
    Wt::WLineEdit *nameEdit_;
    Wt::WText *greeting_;

    void greet();
};

HelloApplication::HelloApplication(const Wt::WEnvironment& env)
    : Wt::WApplication(env)
{
    setTitle("Hello world");

    root()->addWidget(new Wt::WText("Your name, please ? "));
    nameEdit_ = new Wt::WLineEdit(root());
    Wt::WPushButton *button = new Wt::WPushButton("Greet me.", root());
    root()->addWidget(new Wt::WBreak());
    greeting_ = new Wt::WText(root());
    button->clicked().connect(this, &HelloApplication::greet);
}

void HelloApplication::greet()
{
    greeting_->setText("Hello there, " + nameEdit_->text());
}

Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
    return new HelloApplication(env);
}

int main(int argc, char **argv)
{
    return Wt::WRun(argc, argv, &createApplication);
}


Compile

g++ -lwtfcgi -lwt my_app.cpp -o myapp


Create config file

nano wt_config.xml

<server>
    <application-settings location="*">
        <connector-fcgi>
            <run-directory>/tmp</run-directory>
        </connector-fcgi>
        <debug>true</debug>
        <log-file>/tmp/wt.log</log-file>
    </application-settings>
</server>


Running spawned process

WT_CONFIG_XML=wt_config.xml spawn-fcgi -n -p 9000 ./myapp

See the result on http://localhost/my_app


Set-up an Eclipse CDT project =

Create an Eclipse project, maybe like there


Configure to Run and Debug

Run -> Debug Configurations
select 'C/C++ Application'
click on 'New launch configuration'
Name: "TestWt Spawned"
C/C++ Application: "/usr/bin/spawn-fcgi"
switch to tab 'Arguments'
Program arguments: "-n -p 9000 build/debug/TestWt"
Working directory: "${workspace_loc:TestWt/TestWt}"
switch to tab 'Environment'
click New...
Name: "WT_CONFIG_XML"
Value: "wt_config.xml"
click Ok
switch to tab 'Debugger'
check 'Non-stop mode'
check 'Automatically debug forked processes'
click on Close


Now you can see the debug working, and run the page on http://localhost/my_app