Wexus2 0.20
|
This tutorial will quickly outline how to make a Wexus app. This tutorial was made while building the wexus::UptimeApp application, so you can open the source files for that and follow along.
An application object represents the persistent state your application needs between controller calls. Many applications don't need to put any additional logic in their application objects, but they provide a handy service when they are needed.
Create your application class by deriving from wexus::Application You don't need to to implement any of the methods, but you should probably provide a constructor:
class wexus::UptimeApp : public wexus::Application { public: /// default constructor UptimeApp(void); };
You must also register your application. You do this in your .cpp file by instantiating a small static class, providing your class type and a unique string describing the string. You can embed your organizations domain name (in reverse order) to help make your name unique.
For example:
static wexus::RegisterApp<wexus::UptimeApp> r1("ca.demko.uptime");
Note that the instance name of this object ("r1" in this case) is not used anywhere, so we typically give them short, arbitrary names.
Now you will need one or more controller objects. Typically, you register one or more methods of your controller objects as "actions" for URLs. When a web user accesses one of those URLs, the appropriate controller object is instantiated and the desired method is then called.
Controller objects are not persistent - they are instantiated and destroyed per call.
Here is an example of a declaration of a Controller and one method:
class wexus::UptimeController : public wexus::Controller { public: void index(void); };
And the implementation of the method:
void UptimeController::index(void) { htmlOutput() << "Hello, world"; }
Finally, we need to register the controller, and bind it to the application type. We also need to register each action method. Again, the instance names of these objects are arbitrary:
static wexus::RegisterController<wexus::UptimeApp, wexus::UptimeController> r2("home"); static wexus::RegisterAction<wexus::UptimeController, &wexus::UptimeController::index> r100("index");
We can now compile and run the application. Simply:
Here is the app.ini
[myappinstance] app = ca.demko.uptime
(yet to be written)