Revert "THRIFT-2729: C++ - .clang-format created and applied"
This reverts commit 74260aa9099c3bb209bc8e524b0e8ba603f62c41.
diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp
old mode 100644
new mode 100755
index 6d2a260..a343221
--- a/test/cpp/src/TestServer.cpp
+++ b/test/cpp/src/TestServer.cpp
@@ -50,7 +50,7 @@
#include <signal.h>
#if _WIN32
-#include <thrift/windows/TWinsockSingleton.h>
+ #include <thrift/windows/TWinsockSingleton.h>
#endif
using namespace std;
@@ -68,12 +68,14 @@
#define EXECUTABLE_FILE_NAME_LENGTH 19
class TestHandler : public ThriftTestIf {
-public:
+ public:
TestHandler() {}
- void testVoid() { printf("testVoid()\n"); }
+ void testVoid() {
+ printf("testVoid()\n");
+ }
- void testString(string& out, const string& thing) {
+ void testString(string& out, const string &thing) {
printf("testString(\"%s\")\n", thing.c_str());
out = thing;
}
@@ -98,28 +100,18 @@
return thing;
}
- void testStruct(Xtruct& out, const Xtruct& thing) {
- printf("testStruct({\"%s\", %d, %d, %" PRId64 "})\n",
- thing.string_thing.c_str(),
- (int)thing.byte_thing,
- thing.i32_thing,
- thing.i64_thing);
+ void testStruct(Xtruct& out, const Xtruct &thing) {
+ printf("testStruct({\"%s\", %d, %d, %" PRId64 "})\n", thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing);
out = thing;
}
void testNest(Xtruct2& out, const Xtruct2& nest) {
- const Xtruct& thing = nest.struct_thing;
- printf("testNest({%d, {\"%s\", %d, %d, %" PRId64 "}, %d})\n",
- (int)nest.byte_thing,
- thing.string_thing.c_str(),
- (int)thing.byte_thing,
- thing.i32_thing,
- thing.i64_thing,
- nest.i32_thing);
+ const Xtruct &thing = nest.struct_thing;
+ printf("testNest({%d, {\"%s\", %d, %d, %" PRId64 "}, %d})\n", (int)nest.byte_thing, thing.string_thing.c_str(), (int)thing.byte_thing, thing.i32_thing, thing.i64_thing, nest.i32_thing);
out = nest;
}
- void testMap(map<int32_t, int32_t>& out, const map<int32_t, int32_t>& thing) {
+ void testMap(map<int32_t, int32_t> &out, const map<int32_t, int32_t> &thing) {
printf("testMap({");
map<int32_t, int32_t>::const_iterator m_iter;
bool first = true;
@@ -135,8 +127,7 @@
out = thing;
}
- void testStringMap(map<std::string, std::string>& out,
- const map<std::string, std::string>& thing) {
+ void testStringMap(map<std::string, std::string> &out, const map<std::string, std::string> &thing) {
printf("testMap({");
map<std::string, std::string>::const_iterator m_iter;
bool first = true;
@@ -152,7 +143,7 @@
out = thing;
}
- void testSet(set<int32_t>& out, const set<int32_t>& thing) {
+ void testSet(set<int32_t> &out, const set<int32_t> &thing) {
printf("testSet({");
set<int32_t>::const_iterator s_iter;
bool first = true;
@@ -168,7 +159,7 @@
out = thing;
}
- void testList(vector<int32_t>& out, const vector<int32_t>& thing) {
+ void testList(vector<int32_t> &out, const vector<int32_t> &thing) {
printf("testList({");
vector<int32_t>::const_iterator l_iter;
bool first = true;
@@ -194,22 +185,23 @@
return thing;
}
- void testMapMap(map<int32_t, map<int32_t, int32_t> >& mapmap, const int32_t hello) {
+ void testMapMap(map<int32_t, map<int32_t,int32_t> > &mapmap, const int32_t hello) {
printf("testMapMap(%d)\n", hello);
- map<int32_t, int32_t> pos;
- map<int32_t, int32_t> neg;
+ map<int32_t,int32_t> pos;
+ map<int32_t,int32_t> neg;
for (int i = 1; i < 5; i++) {
- pos.insert(make_pair(i, i));
- neg.insert(make_pair(-i, -i));
+ pos.insert(make_pair(i,i));
+ neg.insert(make_pair(-i,-i));
}
mapmap.insert(make_pair(4, pos));
mapmap.insert(make_pair(-4, neg));
+
}
- void testInsanity(map<UserId, map<Numberz::type, Insanity> >& insane, const Insanity& argument) {
- (void)argument;
+ void testInsanity(map<UserId, map<Numberz::type,Insanity> > &insane, const Insanity &argument) {
+ (void) argument;
printf("testInsanity()\n");
Xtruct hello;
@@ -245,11 +237,13 @@
printf("return");
printf(" = {");
- map<UserId, map<Numberz::type, Insanity> >::const_iterator i_iter;
+ map<UserId, map<Numberz::type,Insanity> >::const_iterator i_iter;
for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
printf("%" PRId64 " => {", i_iter->first);
- map<Numberz::type, Insanity>::const_iterator i2_iter;
- for (i2_iter = i_iter->second.begin(); i2_iter != i_iter->second.end(); ++i2_iter) {
+ map<Numberz::type,Insanity>::const_iterator i2_iter;
+ for (i2_iter = i_iter->second.begin();
+ i2_iter != i_iter->second.end();
+ ++i2_iter) {
printf("%d => {", i2_iter->first);
map<Numberz::type, UserId> userMap = i2_iter->second.userMap;
map<Numberz::type, UserId>::const_iterator um;
@@ -263,11 +257,7 @@
vector<Xtruct>::const_iterator x;
printf("{");
for (x = xtructs.begin(); x != xtructs.end(); ++x) {
- printf("{\"%s\", %d, %d, %" PRId64 "}, ",
- x->string_thing.c_str(),
- (int)x->byte_thing,
- x->i32_thing,
- x->i64_thing);
+ printf("{\"%s\", %d, %d, %" PRId64 "}, ", x->string_thing.c_str(), (int)x->byte_thing, x->i32_thing, x->i64_thing);
}
printf("}");
@@ -276,18 +266,14 @@
printf("}, ");
}
printf("}\n");
+
+
}
- void testMulti(Xtruct& hello,
- const int8_t arg0,
- const int32_t arg1,
- const int64_t arg2,
- const std::map<int16_t, std::string>& arg3,
- const Numberz::type arg4,
- const UserId arg5) {
- (void)arg3;
- (void)arg4;
- (void)arg5;
+ void testMulti(Xtruct &hello, const int8_t arg0, const int32_t arg1, const int64_t arg2, const std::map<int16_t, std::string> &arg3, const Numberz::type arg4, const UserId arg5) {
+ (void) arg3;
+ (void) arg4;
+ (void) arg5;
printf("testMulti()\n");
@@ -297,7 +283,9 @@
hello.i64_thing = (int64_t)arg2;
}
- void testException(const std::string& arg) throw(Xception, apache::thrift::TException) {
+ void testException(const std::string &arg)
+ throw(Xception, apache::thrift::TException)
+ {
printf("testException(%s)\n", arg.c_str());
if (arg.compare("Xception") == 0) {
Xception e;
@@ -314,9 +302,7 @@
}
}
- void testMultiException(Xtruct& result,
- const std::string& arg0,
- const std::string& arg1) throw(Xception, Xception2) {
+ void testMultiException(Xtruct &result, const std::string &arg0, const std::string &arg1) throw(Xception, Xception2) {
printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str());
@@ -343,23 +329,28 @@
}
};
+
class TestProcessorEventHandler : public TProcessorEventHandler {
virtual void* getContext(const char* fn_name, void* serverContext) {
- (void)serverContext;
+ (void) serverContext;
return new std::string(fn_name);
}
virtual void freeContext(void* ctx, const char* fn_name) {
- (void)fn_name;
+ (void) fn_name;
delete static_cast<std::string*>(ctx);
}
- virtual void preRead(void* ctx, const char* fn_name) { communicate("preRead", ctx, fn_name); }
+ virtual void preRead(void* ctx, const char* fn_name) {
+ communicate("preRead", ctx, fn_name);
+ }
virtual void postRead(void* ctx, const char* fn_name, uint32_t bytes) {
- (void)bytes;
+ (void) bytes;
communicate("postRead", ctx, fn_name);
}
- virtual void preWrite(void* ctx, const char* fn_name) { communicate("preWrite", ctx, fn_name); }
+ virtual void preWrite(void* ctx, const char* fn_name) {
+ communicate("preWrite", ctx, fn_name);
+ }
virtual void postWrite(void* ctx, const char* fn_name, uint32_t bytes) {
- (void)bytes;
+ (void) bytes;
communicate("postWrite", ctx, fn_name);
}
virtual void asyncComplete(void* ctx, const char* fn_name) {
@@ -374,6 +365,7 @@
}
};
+
class TestHandlerAsync : public ThriftTestCobSvIf {
public:
TestHandlerAsync(boost::shared_ptr<TestHandler>& handler) : _delegate(handler) {}
@@ -384,8 +376,7 @@
cob();
}
- virtual void testString(tcxx::function<void(std::string const& _return)> cob,
- const std::string& thing) {
+ virtual void testString(tcxx::function<void(std::string const& _return)> cob, const std::string& thing) {
std::string res;
_delegate->testString(res, thing);
cob(res);
@@ -423,37 +414,31 @@
cob(res);
}
- virtual void testMap(tcxx::function<void(std::map<int32_t, int32_t> const& _return)> cob,
- const std::map<int32_t, int32_t>& thing) {
+ virtual void testMap(tcxx::function<void(std::map<int32_t, int32_t> const& _return)> cob, const std::map<int32_t, int32_t> & thing) {
std::map<int32_t, int32_t> res;
_delegate->testMap(res, thing);
cob(res);
}
- virtual void testStringMap(
- tcxx::function<void(std::map<std::string, std::string> const& _return)> cob,
- const std::map<std::string, std::string>& thing) {
+ virtual void testStringMap(tcxx::function<void(std::map<std::string, std::string> const& _return)> cob, const std::map<std::string, std::string> & thing) {
std::map<std::string, std::string> res;
_delegate->testStringMap(res, thing);
cob(res);
}
- virtual void testSet(tcxx::function<void(std::set<int32_t> const& _return)> cob,
- const std::set<int32_t>& thing) {
+ virtual void testSet(tcxx::function<void(std::set<int32_t> const& _return)> cob, const std::set<int32_t> & thing) {
std::set<int32_t> res;
_delegate->testSet(res, thing);
cob(res);
}
- virtual void testList(tcxx::function<void(std::vector<int32_t> const& _return)> cob,
- const std::vector<int32_t>& thing) {
+ virtual void testList(tcxx::function<void(std::vector<int32_t> const& _return)> cob, const std::vector<int32_t> & thing) {
std::vector<int32_t> res;
_delegate->testList(res, thing);
cob(res);
}
- virtual void testEnum(tcxx::function<void(Numberz::type const& _return)> cob,
- const Numberz::type thing) {
+ virtual void testEnum(tcxx::function<void(Numberz::type const& _return)> cob, const Numberz::type thing) {
Numberz::type res = _delegate->testEnum(thing);
cob(res);
}
@@ -463,56 +448,39 @@
cob(res);
}
- virtual void testMapMap(
- tcxx::function<void(std::map<int32_t, std::map<int32_t, int32_t> > const& _return)> cob,
- const int32_t hello) {
+ virtual void testMapMap(tcxx::function<void(std::map<int32_t, std::map<int32_t, int32_t> > const& _return)> cob, const int32_t hello) {
std::map<int32_t, std::map<int32_t, int32_t> > res;
_delegate->testMapMap(res, hello);
cob(res);
}
- virtual void testInsanity(
- tcxx::function<void(std::map<UserId, std::map<Numberz::type, Insanity> > const& _return)> cob,
- const Insanity& argument) {
+ virtual void testInsanity(tcxx::function<void(std::map<UserId, std::map<Numberz::type, Insanity> > const& _return)> cob, const Insanity& argument) {
std::map<UserId, std::map<Numberz::type, Insanity> > res;
_delegate->testInsanity(res, argument);
cob(res);
- }
+ }
- virtual void testMulti(tcxx::function<void(Xtruct const& _return)> cob,
- const int8_t arg0,
- const int32_t arg1,
- const int64_t arg2,
- const std::map<int16_t, std::string>& arg3,
- const Numberz::type arg4,
- const UserId arg5) {
+ virtual void testMulti(tcxx::function<void(Xtruct const& _return)> cob, const int8_t arg0, const int32_t arg1, const int64_t arg2, const std::map<int16_t, std::string> & arg3, const Numberz::type arg4, const UserId arg5) {
Xtruct res;
_delegate->testMulti(res, arg0, arg1, arg2, arg3, arg4, arg5);
cob(res);
}
- virtual void testException(
- tcxx::function<void()> cob,
- tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
- const std::string& arg) {
+ virtual void testException(tcxx::function<void()> cob, tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob, const std::string& arg) {
try {
_delegate->testException(arg);
- } catch (const apache::thrift::TException& e) {
+ } catch(const apache::thrift::TException& e) {
exn_cob(apache::thrift::TDelayedException::delayException(e));
return;
}
cob();
}
- virtual void testMultiException(
- tcxx::function<void(Xtruct const& _return)> cob,
- tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob,
- const std::string& arg0,
- const std::string& arg1) {
+ virtual void testMultiException(tcxx::function<void(Xtruct const& _return)> cob, tcxx::function<void(::apache::thrift::TDelayedException* _throw)> exn_cob, const std::string& arg0, const std::string& arg1) {
Xtruct res;
try {
_delegate->testMultiException(res, arg0, arg1);
- } catch (const apache::thrift::TException& e) {
+ } catch(const apache::thrift::TException& e) {
exn_cob(apache::thrift::TDelayedException::delayException(e));
return;
}
@@ -528,12 +496,13 @@
boost::shared_ptr<TestHandler> _delegate;
};
-int main(int argc, char** argv) {
+
+int main(int argc, char **argv) {
string file_path = boost::filesystem::system_complete(argv[0]).string();
- string dir_path = file_path.substr(0, file_path.size() - EXECUTABLE_FILE_NAME_LENGTH);
+ string dir_path = file_path.substr(0, file_path.size()-EXECUTABLE_FILE_NAME_LENGTH);
-#if _WIN32
+ #if _WIN32
transport::TWinsockSingleton::create();
#endif
int port = 9090;
@@ -544,35 +513,32 @@
string domain_socket = "";
size_t workers = 4;
+
boost::program_options::options_description desc("Allowed options");
- desc.add_options()("help,h", "produce help message")(
- "port",
- boost::program_options::value<int>(&port)->default_value(port),
- "Port number to listen")("domain-socket",
- boost::program_options::value<string>(&domain_socket)
- ->default_value(domain_socket),
- "Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)")(
- "server-type",
- boost::program_options::value<string>(&server_type)->default_value(server_type),
- "type of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\"")(
- "transport",
- boost::program_options::value<string>(&transport_type)->default_value(transport_type),
- "transport: buffered, framed, http")(
- "protocol",
- boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
- "protocol: binary, compact, json")("ssl", "Encrypted Transport using SSL")(
- "processor-events",
- "processor-events")("workers,n",
- boost::program_options::value<size_t>(&workers)->default_value(workers),
- "Number of thread pools workers. Only valid for thread-pool server type");
+ desc.add_options()
+ ("help,h", "produce help message")
+ ("port", boost::program_options::value<int>(&port)->default_value(port), "Port number to listen")
+ ("domain-socket", boost::program_options::value<string>(&domain_socket)->default_value(domain_socket),
+ "Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)")
+ ("server-type", boost::program_options::value<string>(&server_type)->default_value(server_type),
+ "type of server, \"simple\", \"thread-pool\", \"threaded\", or \"nonblocking\"")
+ ("transport", boost::program_options::value<string>(&transport_type)->default_value(transport_type),
+ "transport: buffered, framed, http")
+ ("protocol", boost::program_options::value<string>(&protocol_type)->default_value(protocol_type),
+ "protocol: binary, compact, json")
+ ("ssl", "Encrypted Transport using SSL")
+ ("processor-events", "processor-events")
+ ("workers,n", boost::program_options::value<size_t>(&workers)->default_value(workers),
+ "Number of thread pools workers. Only valid for thread-pool server type")
+ ;
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);
if (vm.count("help")) {
- cout << desc << "\n";
- return 1;
+ cout << desc << "\n";
+ return 1;
}
try {
@@ -582,7 +548,7 @@
} else if (server_type == "threaded") {
} else if (server_type == "nonblocking") {
} else {
- throw invalid_argument("Unknown server type " + server_type);
+ throw invalid_argument("Unknown server type "+server_type);
}
}
@@ -591,7 +557,7 @@
} else if (protocol_type == "compact") {
} else if (protocol_type == "json") {
} else {
- throw invalid_argument("Unknown protocol type " + protocol_type);
+ throw invalid_argument("Unknown protocol type "+protocol_type);
}
}
@@ -600,7 +566,7 @@
} else if (transport_type == "framed") {
} else if (transport_type == "http") {
} else {
- throw invalid_argument("Unknown transport type " + transport_type);
+ throw invalid_argument("Unknown transport type "+transport_type);
}
}
@@ -623,8 +589,7 @@
boost::shared_ptr<TProtocolFactory> compactProtocolFactory(new TCompactProtocolFactory());
protocolFactory = compactProtocolFactory;
} else {
- boost::shared_ptr<TProtocolFactory> binaryProtocolFactory(
- new TBinaryProtocolFactoryT<TBufferBase>());
+ boost::shared_ptr<TProtocolFactory> binaryProtocolFactory(new TBinaryProtocolFactoryT<TBufferBase>());
protocolFactory = binaryProtocolFactory;
}
@@ -633,8 +598,8 @@
boost::shared_ptr<ThriftTestProcessor> testProcessor(new ThriftTestProcessor(testHandler));
if (vm.count("processor-events")) {
- testProcessor->setEventHandler(
- boost::shared_ptr<TProcessorEventHandler>(new TestProcessorEventHandler()));
+ testProcessor->setEventHandler(boost::shared_ptr<TProcessorEventHandler>(
+ new TestProcessorEventHandler()));
}
// Transport
@@ -672,8 +637,8 @@
}
// Server Info
- cout << "Starting \"" << server_type << "\" server (" << transport_type << "/" << protocol_type
- << ") listen on: " << domain_socket;
+ cout << "Starting \"" << server_type << "\" server ("
+ << transport_type << "/" << protocol_type << ") listen on: " << domain_socket;
if (port != 0) {
cout << port;
}
@@ -683,13 +648,17 @@
boost::shared_ptr<apache::thrift::server::TServer> server;
if (server_type == "simple") {
- server.reset(new TSimpleServer(testProcessor, serverSocket, transportFactory, protocolFactory));
+ server.reset(new TSimpleServer(testProcessor,
+ serverSocket,
+ transportFactory,
+ protocolFactory));
} else if (server_type == "thread-pool") {
- boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workers);
+ boost::shared_ptr<ThreadManager> threadManager =
+ ThreadManager::newSimpleThreadManager(workers);
- boost::shared_ptr<PlatformThreadFactory> threadFactory
- = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
+ boost::shared_ptr<PlatformThreadFactory> threadFactory =
+ boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
threadManager->threadFactory(threadFactory);
@@ -702,15 +671,15 @@
threadManager));
} else if (server_type == "threaded") {
- server.reset(
- new TThreadedServer(testProcessor, serverSocket, transportFactory, protocolFactory));
+ server.reset(new TThreadedServer(testProcessor,
+ serverSocket,
+ transportFactory,
+ protocolFactory));
} else if (server_type == "nonblocking") {
- if (transport_type == "http") {
+ if(transport_type == "http") {
boost::shared_ptr<TestHandlerAsync> testHandlerAsync(new TestHandlerAsync(testHandler));
- boost::shared_ptr<TAsyncProcessor> testProcessorAsync(
- new ThriftTestAsyncProcessor(testHandlerAsync));
- boost::shared_ptr<TAsyncBufferProcessor> testBufferProcessor(
- new TAsyncProtocolProcessor(testProcessorAsync, protocolFactory));
+ boost::shared_ptr<TAsyncProcessor> testProcessorAsync(new ThriftTestAsyncProcessor(testHandlerAsync));
+ boost::shared_ptr<TAsyncBufferProcessor> testBufferProcessor(new TAsyncProtocolProcessor(testProcessorAsync, protocolFactory));
// not loading nonblockingServer into "server" because
// TEvhttpServer doesn't inherit from TServer, and doesn't
@@ -722,18 +691,17 @@
}
}
- if (server.get() != NULL) {
+ if(server.get() != NULL)
+ {
apache::thrift::concurrency::PlatformThreadFactory factory;
factory.setDetached(false);
boost::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server);
- boost::shared_ptr<apache::thrift::concurrency::Thread> thread
- = factory.newThread(serverThreadRunner);
+ boost::shared_ptr<apache::thrift::concurrency::Thread> thread = factory.newThread(serverThreadRunner);
thread->start();
// HACK: cross language test suite is unable to handle cin properly
// that's why we stay in a endless loop here
- while (1) {
- }
+ while(1){}
// FIXME: find another way to stop the server (e.g. a signal)
// cout<<"Press enter to stop the server."<<endl;
// cin.ignore(); //wait until a key is pressed