libtasks Documentation  1.6
ip_service.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>
11 
12 #include <IpService.h> // Thrift generated
13 #include "ip_service.h"
14 
15 void ip_service::lookup(response_type& result, const int32_t ipv4, const ipv6_type& ipv6) {
16  key_value_type kv;
17  id_name_type val;
18  kv.key.id = 1;
19  kv.key.name = "city";
20  val.id = 123456;
21  val.name = "Berlin";
22  kv.values.push_back(val);
23  result.key_values.push_back(kv);
24  kv.values.clear();
25 
26  kv.key.id = 2;
27  kv.key.name = "country";
28  val.id = 3345677;
29  val.name = "Germany";
30  kv.values.push_back(val);
31  result.key_values.push_back(kv);
32 }
33 
34 int main(int argc, char** argv) {
35  using namespace tasks;
36  using namespace tasks::net;
37 
38  acceptor<uwsgi_thrift_processor<IpServiceProcessor /* Thrift generated */, ip_service /* Service handler */
39  > > srv(12345);
40  dispatcher::instance()->start();
41  dispatcher::instance()->add_task(&srv);
42  dispatcher::instance()->join();
43 
44  return 0;
45 }
static std::shared_ptr< dispatcher > instance()
Definition: dispatcher.h:75
int main(int argc, char **argv)
Definition: ip_service.cpp:34
void lookup(response_type &result, const int32_t ipv4, const ipv6_type &ipv6)
Definition: ip_service.cpp:15