Hobrasoft httpd server
Embedded HTTP server for Qt and C++
controllerexample.cpp
Go to the documentation of this file.
1 
7 #include "controllerexample.h"
8 #include "application.h"
9 #include "list.h"
10 #include "item.h"
11 #include "main.h"
12 
13 #define LIST application->list()
14 
15 using namespace Example;
16 using namespace Example::Httpd;
17 
18 
19 void ControllerExample::serviceList (HobrasoftHttpd::HttpRequest *request, HobrasoftHttpd::HttpResponse *response) {
20  serviceOK(request, response, LIST->webStatus());
21 }
22 
23 
24 bool ControllerExample::exists (const QString& id) const {
25  return LIST->contains(id);
26 }
27 
28 
29 void ControllerExample::serviceEvents (HobrasoftHttpd::HttpRequest *request, HobrasoftHttpd::HttpResponse *response) {
30  Q_UNUSED(request);
31  Q_UNUSED(response);
32  connect (LIST, SIGNAL( statusChanged(const Item *)),
33  this, SLOT( sendUpdate(const Item *)));
34 }
35 
36 
37 void ControllerExample::serviceIdEvents (HobrasoftHttpd::HttpRequest *request, HobrasoftHttpd::HttpResponse *response, const QString& id) {
38  Q_UNUSED(request);
39  Q_UNUSED(response);
40 
41  Item *item = LIST->item(id);
42 
43  connect(item, SIGNAL(statusChanged(const Item *)),
44  this, SLOT( sendUpdate(const Item *)));
45 
46  sendUpdate(item);
47 }
48 
49 
50 void ControllerExample::serviceIdGet (HobrasoftHttpd::HttpRequest *request, HobrasoftHttpd::HttpResponse *response, const QString& id) {
51  serviceOK(request, response, LIST->item(id)->webStatus());
52 }
53 
54 
56  serviceEvent(NULL, NULL, item->webStatus());
57 }
58 
59 
60 
virtual void serviceOK(HobrasoftHttpd::HttpRequest *request, HobrasoftHttpd::HttpResponse *response, const QVariant &data=QVariant())
Sends 200 OK response.
virtual bool exists(const QString &id) const
Check existence of th ID.
HttpResponse * response()
Returns new instance of HttpResponse class.
Namespace for Example.
Definition: application.h:11
Name space for own application HTTP server.
Response to HTTP request - headers, cookies and body.
Definition: httpresponse.h:30
QVariantMap webStatus() const
Returns webStatus of the item.
Definition: item.cpp:42
One data item in the example.
Definition: item.h:20
Processes HTTP request, parses headers, body and files sent by HTTP protocol.
Definition: httprequest.h:23
void sendUpdate(const Item *)
Sends data of the item to the event stream.