libtasks Documentation  1.6
thrift_server/uwsgi_handler.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #include <tasks/dispatcher.h>
9 #include <tasks/net/acceptor.h>
13 
14 #include <iostream>
15 #include <arpa/inet.h>
16 #include <thrift/protocol/TBinaryProtocol.h>
17 
18 #ifdef PROFILER
19 #include <google/profiler.h>
20 #endif
21 
22 #include "uwsgi_handler.h"
23 #include "stats.h"
24 
26  // Do something with the url for example
27  // const std::string& url = request().var("REQUEST_URI");
28  // Or print all incoming variables
29  // request().print_vars();
30 
32  typedef apache::thrift::protocol::TBinaryProtocol protocol_type;
33 
34  boost::shared_ptr<transport_type> transport(new transport_type(response_p()));
35  boost::shared_ptr<protocol_type> protocol(new protocol_type(transport));
37 
38  id_name m;
39  m.id = 33;
40  m.name = "testtest";
41  writer.write(m);
42 
43  // Now send back a response
44  response().set_status("200 OK");
45  response().set_header("Content-Type", "application/x-thrift");
46  send_response();
47 
49 
50  return true;
51 }
52 
53 int main(int argc, char** argv) {
54 #ifdef PROFILER
55  ProfilerStart("uwsgi_server.prof");
56 #endif
57  stats s;
59  auto tasks = std::vector<tasks::task*>{&srv, &s};
60  tasks::dispatcher::instance()->run(tasks);
61 #ifdef PROFILER
62  ProfilerStop();
63 #endif
64  return 0;
65 }
static std::shared_ptr< dispatcher > instance()
Definition: dispatcher.h:75
http_response & response()
Definition: uwsgi_task.h:55
int main(int argc, char **argv)
void set_status(std::string status)
Definition: http_response.h:23
void set_header(std::string header, std::string value)
Definition: http_base.h:46
void send_response()
Send the resonse back.
Definition: uwsgi_task.h:67
http_response * response_p()
Definition: uwsgi_task.h:61
static void inc_req()
Definition: echoserver.h:25