|
#include "test1.h" |
|
|
|
#include <thrift/protocol/TBinaryProtocol.h> |
|
#include <thrift/async/TAsyncProtocolProcessor.h> |
|
#include <thrift/async/TEvhtpServer.h> |
|
|
|
using namespace ::apache::thrift; |
|
using namespace ::apache::thrift::protocol; |
|
using namespace ::apache::thrift::transport; |
|
using namespace ::apache::thrift::async; |
|
|
|
using boost::shared_ptr; |
|
|
|
using namespace ::test1; |
|
|
|
class test1Handler : virtual public test1If { |
|
public: |
|
test1Handler() { |
|
printf("test1Handler()\n"); |
|
} |
|
|
|
int32_t |
|
add_val(const std::string& key, const std::string& val) { |
|
printf("add_val %s %s\n", key.c_str(), val.c_str()); |
|
return 0; |
|
} |
|
|
|
void |
|
find_val(std::string& _return, const std::string& key) { |
|
printf("find_val\n"); |
|
} |
|
|
|
void |
|
find_val_struct(Test1& _return, const std::string& key) { |
|
printf("find_val_struct\n"); |
|
} |
|
}; |
|
|
|
class test1AsyncHandler : public test1CobSvIf { |
|
public: |
|
test1AsyncHandler() { |
|
syncHandler_ = std::auto_ptr<test1Handler>(new test1Handler); |
|
printf("test1AsyncHandler()\n"); |
|
} |
|
|
|
|
|
void |
|
add_val(tcxx::function <void(int32_t const& _ret)>cob, |
|
const std::string& key, |
|
const std::string& val) { |
|
int32_t _ret = 0; |
|
|
|
_ret = syncHandler_->add_val(key, val); |
|
|
|
return cob(_ret); |
|
} |
|
|
|
void |
|
find_val(tcxx::function <void(std::string const & _ret)>cob, |
|
const std::string & key) { |
|
std::string _ret; |
|
|
|
syncHandler_->find_val(_ret, key); |
|
|
|
return cob(_ret); |
|
} |
|
|
|
void |
|
find_val_struct(tcxx::function<void(Test1 const& _ret)>cob, |
|
const std::string& key) { |
|
Test1 _ret; |
|
|
|
syncHandler_->find_val_struct(_ret, key); |
|
|
|
return cob(_ret); |
|
} |
|
|
|
protected: |
|
std::auto_ptr<test1Handler> syncHandler_; |
|
}; |
|
|
|
|
|
int |
|
main(int argc, char ** argv) { |
|
shared_ptr<test1AsyncHandler> handler(new test1AsyncHandler()); |
|
shared_ptr<TAsyncProcessor> proc(new test1AsyncProcessor(handler)); |
|
shared_ptr<TProtocolFactory> pfact(new TBinaryProtocolFactory()); |
|
shared_ptr<TAsyncBufferProcessor> bufproc(new TAsyncProtocolProcessor(proc, pfact)); |
|
shared_ptr<TEvhtpServer> server(new TEvhtpServer(bufproc, 9090)); |
|
|
|
server->serve(); |
|
|
|
return 0; |
|
} |