You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by hc...@apache.org on 2014/11/18 10:02:41 UTC
[13/37] thrift git commit: THRIFT-2729: C++ - .clang-format created
and applied
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/TDispatchProcessor.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/TDispatchProcessor.h b/lib/cpp/src/thrift/TDispatchProcessor.h
index 33ec22e..fd1dce7 100644
--- a/lib/cpp/src/thrift/TDispatchProcessor.h
+++ b/lib/cpp/src/thrift/TDispatchProcessor.h
@@ -21,7 +21,8 @@
#include <thrift/TProcessor.h>
-namespace apache { namespace thrift {
+namespace apache {
+namespace thrift {
/**
* TDispatchProcessor is a helper class to parse the message header then call
@@ -31,7 +32,7 @@ namespace apache { namespace thrift {
*/
template <class Protocol_>
class TDispatchProcessorT : public TProcessor {
- public:
+public:
virtual bool process(boost::shared_ptr<protocol::TProtocol> in,
boost::shared_ptr<protocol::TProtocol> out,
void* connectionContext) {
@@ -60,15 +61,14 @@ class TDispatchProcessorT : public TProcessor {
// (The old generated processor code used to try to skip a T_STRUCT and
// continue. However, that seems unsafe.)
if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
- GlobalOutput.printf("received invalid message type %d from client",
- mtype);
+ GlobalOutput.printf("received invalid message type %d from client", mtype);
return false;
}
return this->dispatchCall(inRaw, outRaw, fname, seqid, connectionContext);
}
- protected:
+protected:
bool processFast(Protocol_* in, Protocol_* out, void* connectionContext) {
std::string fname;
protocol::TMessageType mtype;
@@ -76,13 +76,11 @@ class TDispatchProcessorT : public TProcessor {
in->readMessageBegin(fname, mtype, seqid);
if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
- GlobalOutput.printf("received invalid message type %d from client",
- mtype);
+ GlobalOutput.printf("received invalid message type %d from client", mtype);
return false;
}
- return this->dispatchCallTemplated(in, out, fname,
- seqid, connectionContext);
+ return this->dispatchCallTemplated(in, out, fname, seqid, connectionContext);
}
/**
@@ -90,11 +88,14 @@ class TDispatchProcessorT : public TProcessor {
*/
virtual bool dispatchCall(apache::thrift::protocol::TProtocol* in,
apache::thrift::protocol::TProtocol* out,
- const std::string& fname, int32_t seqid,
+ const std::string& fname,
+ int32_t seqid,
void* callContext) = 0;
- virtual bool dispatchCallTemplated(Protocol_* in, Protocol_* out,
- const std::string& fname, int32_t seqid,
+ virtual bool dispatchCallTemplated(Protocol_* in,
+ Protocol_* out,
+ const std::string& fname,
+ int32_t seqid,
void* callContext) = 0;
};
@@ -103,7 +104,7 @@ class TDispatchProcessorT : public TProcessor {
* perform a dynamic_cast.
*/
class TDispatchProcessor : public TProcessor {
- public:
+public:
virtual bool process(boost::shared_ptr<protocol::TProtocol> in,
boost::shared_ptr<protocol::TProtocol> out,
void* connectionContext) {
@@ -113,30 +114,28 @@ class TDispatchProcessor : public TProcessor {
in->readMessageBegin(fname, mtype, seqid);
if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
- GlobalOutput.printf("received invalid message type %d from client",
- mtype);
+ GlobalOutput.printf("received invalid message type %d from client", mtype);
return false;
}
return dispatchCall(in.get(), out.get(), fname, seqid, connectionContext);
}
- protected:
+protected:
virtual bool dispatchCall(apache::thrift::protocol::TProtocol* in,
apache::thrift::protocol::TProtocol* out,
- const std::string& fname, int32_t seqid,
+ const std::string& fname,
+ int32_t seqid,
void* callContext) = 0;
};
// Specialize TDispatchProcessorT for TProtocol and TDummyProtocol just to use
// the generic TDispatchProcessor.
template <>
-class TDispatchProcessorT<protocol::TDummyProtocol> :
- public TDispatchProcessor {};
+class TDispatchProcessorT<protocol::TDummyProtocol> : public TDispatchProcessor {};
template <>
-class TDispatchProcessorT<protocol::TProtocol> :
- public TDispatchProcessor {};
-
-}} // apache::thrift
+class TDispatchProcessorT<protocol::TProtocol> : public TDispatchProcessor {};
+}
+} // apache::thrift
#endif // _THRIFT_TDISPATCHPROCESSOR_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/TLogging.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/TLogging.h b/lib/cpp/src/thrift/TLogging.h
index 4c8bddc..096054c 100644
--- a/lib/cpp/src/thrift/TLogging.h
+++ b/lib/cpp/src/thrift/TLogging.h
@@ -39,13 +39,11 @@
*/
#define T_GLOBAL_DEBUGGING_LEVEL 0
-
/**
* T_GLOBAL_LOGGING_LEVEL = 0: all logging turned off, logging macros undefined
* T_GLOBAL_LOGGING_LEVEL = 1: all logging turned on
*/
-#define T_GLOBAL_LOGGING_LEVEL 1
-
+#define T_GLOBAL_LOGGING_LEVEL 1
/**
* Standard wrapper around fprintf what will prefix the file name and line
@@ -55,37 +53,40 @@
* @param format_string
*/
#if T_GLOBAL_DEBUGGING_LEVEL > 0
- #define T_DEBUG(format_string,...) \
- if (T_GLOBAL_DEBUGGING_LEVEL > 0) { \
- fprintf(stderr,"[%s,%d] " format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \
+#define T_DEBUG(format_string, ...) \
+ if (T_GLOBAL_DEBUGGING_LEVEL > 0) { \
+ fprintf(stderr, "[%s,%d] " format_string " \n", __FILE__, __LINE__, ##__VA_ARGS__); \
}
#else
- #define T_DEBUG(format_string,...)
+#define T_DEBUG(format_string, ...)
#endif
-
/**
* analagous to T_DEBUG but also prints the time
*
* @param string format_string input: printf style format string
*/
#if T_GLOBAL_DEBUGGING_LEVEL > 0
- #define T_DEBUG_T(format_string,...) \
- { \
- if (T_GLOBAL_DEBUGGING_LEVEL > 0) { \
- time_t now; \
- char dbgtime[26] ; \
- time(&now); \
- THRIFT_CTIME_R(&now, dbgtime); \
- dbgtime[24] = '\0'; \
- fprintf(stderr,"[%s,%d] [%s] " format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \
- } \
- }
+#define T_DEBUG_T(format_string, ...) \
+ { \
+ if (T_GLOBAL_DEBUGGING_LEVEL > 0) { \
+ time_t now; \
+ char dbgtime[26]; \
+ time(&now); \
+ THRIFT_CTIME_R(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr, \
+ "[%s,%d] [%s] " format_string " \n", \
+ __FILE__, \
+ __LINE__, \
+ dbgtime, \
+ ##__VA_ARGS__); \
+ } \
+ }
#else
- #define T_DEBUG_T(format_string,...)
+#define T_DEBUG_T(format_string, ...)
#endif
-
/**
* analagous to T_DEBUG but uses input level to determine whether or not the string
* should be logged.
@@ -93,68 +94,74 @@
* @param int level: specified debug level
* @param string format_string input: format string
*/
-#define T_DEBUG_L(level, format_string,...) \
- if ((level) > 0) { \
- fprintf(stderr,"[%s,%d] " format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \
+#define T_DEBUG_L(level, format_string, ...) \
+ if ((level) > 0) { \
+ fprintf(stderr, "[%s,%d] " format_string " \n", __FILE__, __LINE__, ##__VA_ARGS__); \
}
-
/**
* Explicit error logging. Prints time, file name and line number
*
* @param string format_string input: printf style format string
*/
-#define T_ERROR(format_string,...) \
- { \
- time_t now; \
- char dbgtime[26] ; \
- time(&now); \
- THRIFT_CTIME_R(&now, dbgtime); \
- dbgtime[24] = '\0'; \
- fprintf(stderr,"[%s,%d] [%s] ERROR: " format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \
+#define T_ERROR(format_string, ...) \
+ { \
+ time_t now; \
+ char dbgtime[26]; \
+ time(&now); \
+ THRIFT_CTIME_R(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr, \
+ "[%s,%d] [%s] ERROR: " format_string " \n", \
+ __FILE__, \
+ __LINE__, \
+ dbgtime, \
+ ##__VA_ARGS__); \
}
-
/**
* Analagous to T_ERROR, additionally aborting the process.
* WARNING: macro calls abort(), ending program execution
*
* @param string format_string input: printf style format string
*/
-#define T_ERROR_ABORT(format_string,...) \
- { \
- time_t now; \
- char dbgtime[26] ; \
- time(&now); \
- THRIFT_CTIME_R(&now, dbgtime); \
- dbgtime[24] = '\0'; \
- fprintf(stderr,"[%s,%d] [%s] ERROR: Going to abort " format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \
- exit(1); \
+#define T_ERROR_ABORT(format_string, ...) \
+ { \
+ time_t now; \
+ char dbgtime[26]; \
+ time(&now); \
+ THRIFT_CTIME_R(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr, \
+ "[%s,%d] [%s] ERROR: Going to abort " format_string " \n", \
+ __FILE__, \
+ __LINE__, \
+ dbgtime, \
+ ##__VA_ARGS__); \
+ exit(1); \
}
-
/**
* Log input message
*
* @param string format_string input: printf style format string
*/
#if T_GLOBAL_LOGGING_LEVEL > 0
- #define T_LOG_OPER(format_string,...) \
- { \
- if (T_GLOBAL_LOGGING_LEVEL > 0) { \
- time_t now; \
- char dbgtime[26] ; \
- time(&now); \
- THRIFT_CTIME_R(&now, dbgtime); \
- dbgtime[24] = '\0'; \
- fprintf(stderr,"[%s] " format_string " \n", dbgtime,##__VA_ARGS__); \
- } \
- }
+#define T_LOG_OPER(format_string, ...) \
+ { \
+ if (T_GLOBAL_LOGGING_LEVEL > 0) { \
+ time_t now; \
+ char dbgtime[26]; \
+ time(&now); \
+ THRIFT_CTIME_R(&now, dbgtime); \
+ dbgtime[24] = '\0'; \
+ fprintf(stderr, "[%s] " format_string " \n", dbgtime, ##__VA_ARGS__); \
+ } \
+ }
#else
- #define T_LOG_OPER(format_string,...)
+#define T_LOG_OPER(format_string, ...)
#endif
-
/**
* T_GLOBAL_DEBUG_VIRTUAL = 0 or unset: normal operation,
* virtual call debug messages disabled
@@ -165,29 +172,24 @@
* apache::thrift::profile_print_info()
*/
#if T_GLOBAL_DEBUG_VIRTUAL > 1
- #define T_VIRTUAL_CALL() \
- ::apache::thrift::profile_virtual_call(typeid(*this))
- #define T_GENERIC_PROTOCOL(template_class, generic_prot, specific_prot) \
- do { \
- if (!(specific_prot)) { \
- ::apache::thrift::profile_generic_protocol( \
- typeid(*template_class), typeid(*generic_prot)); \
- } \
- } while (0)
+#define T_VIRTUAL_CALL() ::apache::thrift::profile_virtual_call(typeid(*this))
+#define T_GENERIC_PROTOCOL(template_class, generic_prot, specific_prot) \
+ do { \
+ if (!(specific_prot)) { \
+ ::apache::thrift::profile_generic_protocol(typeid(*template_class), typeid(*generic_prot)); \
+ } \
+ } while (0)
#elif T_GLOBAL_DEBUG_VIRTUAL == 1
- #define T_VIRTUAL_CALL() \
- fprintf(stderr,"[%s,%d] virtual call\n", __FILE__, __LINE__)
- #define T_GENERIC_PROTOCOL(template_class, generic_prot, specific_prot) \
- do { \
- if (!(specific_prot)) { \
- fprintf(stderr, \
- "[%s,%d] failed to cast to specific protocol type\n", \
- __FILE__, __LINE__); \
- } \
- } while (0)
+#define T_VIRTUAL_CALL() fprintf(stderr, "[%s,%d] virtual call\n", __FILE__, __LINE__)
+#define T_GENERIC_PROTOCOL(template_class, generic_prot, specific_prot) \
+ do { \
+ if (!(specific_prot)) { \
+ fprintf(stderr, "[%s,%d] failed to cast to specific protocol type\n", __FILE__, __LINE__); \
+ } \
+ } while (0)
#else
- #define T_VIRTUAL_CALL()
- #define T_GENERIC_PROTOCOL(template_class, generic_prot, specific_prot)
+#define T_VIRTUAL_CALL()
+#define T_GENERIC_PROTOCOL(template_class, generic_prot, specific_prot)
#endif
#endif // #ifndef _THRIFT_TLOGGING_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/TProcessor.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/TProcessor.h b/lib/cpp/src/thrift/TProcessor.h
index b4a4657..d8f86c4 100644
--- a/lib/cpp/src/thrift/TProcessor.h
+++ b/lib/cpp/src/thrift/TProcessor.h
@@ -24,7 +24,8 @@
#include <thrift/protocol/TProtocol.h>
#include <boost/shared_ptr.hpp>
-namespace apache { namespace thrift {
+namespace apache {
+namespace thrift {
/**
* Virtual interface class that can handle events from the processor. To
@@ -34,8 +35,7 @@ namespace apache { namespace thrift {
* instance's state).
*/
class TProcessorEventHandler {
- public:
-
+public:
virtual ~TProcessorEventHandler() {}
/**
@@ -45,8 +45,8 @@ class TProcessorEventHandler {
* for that function invocation.
*/
virtual void* getContext(const char* fn_name, void* serverContext) {
- (void) fn_name;
- (void) serverContext;
+ (void)fn_name;
+ (void)serverContext;
return NULL;
}
@@ -54,61 +54,61 @@ class TProcessorEventHandler {
* Expected to free resources associated with a context.
*/
virtual void freeContext(void* ctx, const char* fn_name) {
- (void) ctx;
- (void) fn_name;
+ (void)ctx;
+ (void)fn_name;
}
/**
* Called before reading arguments.
*/
virtual void preRead(void* ctx, const char* fn_name) {
- (void) ctx;
- (void) fn_name;
+ (void)ctx;
+ (void)fn_name;
}
/**
* Called between reading arguments and calling the handler.
*/
virtual void postRead(void* ctx, const char* fn_name, uint32_t bytes) {
- (void) ctx;
- (void) fn_name;
- (void) bytes;
+ (void)ctx;
+ (void)fn_name;
+ (void)bytes;
}
/**
* Called between calling the handler and writing the response.
*/
virtual void preWrite(void* ctx, const char* fn_name) {
- (void) ctx;
- (void) fn_name;
+ (void)ctx;
+ (void)fn_name;
}
/**
* Called after writing the response.
*/
virtual void postWrite(void* ctx, const char* fn_name, uint32_t bytes) {
- (void) ctx;
- (void) fn_name;
- (void) bytes;
+ (void)ctx;
+ (void)fn_name;
+ (void)bytes;
}
/**
* Called when an async function call completes successfully.
*/
virtual void asyncComplete(void* ctx, const char* fn_name) {
- (void) ctx;
- (void) fn_name;
+ (void)ctx;
+ (void)fn_name;
}
/**
* Called if the handler throws an undeclared exception.
*/
virtual void handlerError(void* ctx, const char* fn_name) {
- (void) ctx;
- (void) fn_name;
+ (void)ctx;
+ (void)fn_name;
}
- protected:
+protected:
TProcessorEventHandler() {}
};
@@ -116,12 +116,16 @@ class TProcessorEventHandler {
* A helper class used by the generated code to free each context.
*/
class TProcessorContextFreer {
- public:
- TProcessorContextFreer(TProcessorEventHandler* handler, void* context, const char* method) :
- handler_(handler), context_(context), method_(method) {}
- ~TProcessorContextFreer() { if (handler_ != NULL) handler_->freeContext(context_, method_); }
+public:
+ TProcessorContextFreer(TProcessorEventHandler* handler, void* context, const char* method)
+ : handler_(handler), context_(context), method_(method) {}
+ ~TProcessorContextFreer() {
+ if (handler_ != NULL)
+ handler_->freeContext(context_, method_);
+ }
void unregister() { handler_ = NULL; }
- private:
+
+private:
apache::thrift::TProcessorEventHandler* handler_;
void* context_;
const char* method_;
@@ -135,27 +139,24 @@ class TProcessorContextFreer {
*
*/
class TProcessor {
- public:
+public:
virtual ~TProcessor() {}
virtual bool process(boost::shared_ptr<protocol::TProtocol> in,
boost::shared_ptr<protocol::TProtocol> out,
void* connectionContext) = 0;
- bool process(boost::shared_ptr<apache::thrift::protocol::TProtocol> io,
- void* connectionContext) {
+ bool process(boost::shared_ptr<apache::thrift::protocol::TProtocol> io, void* connectionContext) {
return process(io, io, connectionContext);
}
- boost::shared_ptr<TProcessorEventHandler> getEventHandler() {
- return eventHandler_;
- }
+ boost::shared_ptr<TProcessorEventHandler> getEventHandler() { return eventHandler_; }
void setEventHandler(boost::shared_ptr<TProcessorEventHandler> eventHandler) {
eventHandler_ = eventHandler;
}
- protected:
+protected:
TProcessor() {}
boost::shared_ptr<TProcessorEventHandler> eventHandler_;
@@ -173,20 +174,20 @@ class TProcessor {
* parameter to a shared_ptr, so that factory->releaseHandler() will be called
* when the object is no longer needed, instead of deleting the pointer.
*/
-template<typename HandlerFactory_>
+template <typename HandlerFactory_>
class ReleaseHandler {
- public:
- ReleaseHandler(const boost::shared_ptr<HandlerFactory_>& handlerFactory) :
- handlerFactory_(handlerFactory) {}
-
- void operator()(typename HandlerFactory_::Handler* handler) {
- if (handler) {
- handlerFactory_->releaseHandler(handler);
- }
- }
-
- private:
- boost::shared_ptr<HandlerFactory_> handlerFactory_;
+public:
+ ReleaseHandler(const boost::shared_ptr<HandlerFactory_>& handlerFactory)
+ : handlerFactory_(handlerFactory) {}
+
+ void operator()(typename HandlerFactory_::Handler* handler) {
+ if (handler) {
+ handlerFactory_->releaseHandler(handler);
+ }
+ }
+
+private:
+ boost::shared_ptr<HandlerFactory_> handlerFactory_;
};
struct TConnectionInfo {
@@ -201,7 +202,7 @@ struct TConnectionInfo {
};
class TProcessorFactory {
- public:
+public:
virtual ~TProcessorFactory() {}
/**
@@ -211,23 +212,19 @@ class TProcessorFactory {
* accepted on. This generally means that this call does not need to be
* thread safe, as it will always be invoked from a single thread.
*/
- virtual boost::shared_ptr<TProcessor> getProcessor(
- const TConnectionInfo& connInfo) = 0;
+ virtual boost::shared_ptr<TProcessor> getProcessor(const TConnectionInfo& connInfo) = 0;
};
class TSingletonProcessorFactory : public TProcessorFactory {
- public:
- TSingletonProcessorFactory(boost::shared_ptr<TProcessor> processor) :
- processor_(processor) {}
+public:
+ TSingletonProcessorFactory(boost::shared_ptr<TProcessor> processor) : processor_(processor) {}
- boost::shared_ptr<TProcessor> getProcessor(const TConnectionInfo&) {
- return processor_;
- }
+ boost::shared_ptr<TProcessor> getProcessor(const TConnectionInfo&) { return processor_; }
- private:
+private:
boost::shared_ptr<TProcessor> processor_;
};
-
-}} // apache::thrift
+}
+} // apache::thrift
#endif // #ifndef _THRIFT_TPROCESSOR_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/TReflectionLocal.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/TReflectionLocal.h b/lib/cpp/src/thrift/TReflectionLocal.h
index 2ef7511..2fc53c8 100644
--- a/lib/cpp/src/thrift/TReflectionLocal.h
+++ b/lib/cpp/src/thrift/TReflectionLocal.h
@@ -31,7 +31,10 @@
*
*/
-namespace apache { namespace thrift { namespace reflection { namespace local {
+namespace apache {
+namespace thrift {
+namespace reflection {
+namespace local {
using apache::thrift::protocol::TType;
@@ -47,7 +50,7 @@ struct FieldMeta {
struct TypeSpec {
TType ttype;
- uint8_t fp_prefix[FP_PREFIX_LEN];
+ uint8_t fp_prefix[FP_PREFIX_LEN];
// Use an anonymous union here so we can fit two TypeSpecs in one cache line.
union {
@@ -57,8 +60,8 @@ struct TypeSpec {
TypeSpec** specs;
} tstruct;
struct {
- TypeSpec *subtype1;
- TypeSpec *subtype2;
+ TypeSpec* subtype1;
+ TypeSpec* subtype2;
} tcontainer;
};
@@ -66,31 +69,24 @@ struct TypeSpec {
// so take the plunge and use constructors.
// Hopefully they'll be evaluated at compile time.
- TypeSpec(TType ttype) : ttype(ttype) {
- std::memset(fp_prefix, 0, FP_PREFIX_LEN);
- }
+ TypeSpec(TType ttype) : ttype(ttype) { std::memset(fp_prefix, 0, FP_PREFIX_LEN); }
- TypeSpec(TType ttype,
- const uint8_t* fingerprint,
- FieldMeta* metas,
- TypeSpec** specs) :
- ttype(ttype)
- {
+ TypeSpec(TType ttype, const uint8_t* fingerprint, FieldMeta* metas, TypeSpec** specs)
+ : ttype(ttype) {
std::memcpy(fp_prefix, fingerprint, FP_PREFIX_LEN);
tstruct.metas = metas;
tstruct.specs = specs;
}
- TypeSpec(TType ttype, TypeSpec* subtype1, TypeSpec* subtype2) :
- ttype(ttype)
- {
+ TypeSpec(TType ttype, TypeSpec* subtype1, TypeSpec* subtype2) : ttype(ttype) {
std::memset(fp_prefix, 0, FP_PREFIX_LEN);
tcontainer.subtype1 = subtype1;
tcontainer.subtype2 = subtype2;
}
-
};
-
-}}}} // apache::thrift::reflection::local
+}
+}
+}
+} // apache::thrift::reflection::local
#endif // #ifndef _THRIFT_TREFLECTIONLOCAL_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/TToString.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/TToString.h b/lib/cpp/src/thrift/TToString.h
index c160e09..5023869 100644
--- a/lib/cpp/src/thrift/TToString.h
+++ b/lib/cpp/src/thrift/TToString.h
@@ -28,7 +28,8 @@
#include <string>
#include <sstream>
-namespace apache { namespace thrift {
+namespace apache {
+namespace thrift {
template <typename T>
std::string to_string(const T& t) {
@@ -52,8 +53,7 @@ std::string to_string(const typename std::pair<K, V>& v) {
}
template <typename T>
-std::string to_string(const T& beg, const T& end)
-{
+std::string to_string(const T& beg, const T& end) {
std::ostringstream o;
for (T it = beg; it != end; ++it) {
if (it != beg)
@@ -83,7 +83,7 @@ std::string to_string(const std::set<T>& s) {
o << "{" << to_string(s.begin(), s.end()) << "}";
return o.str();
}
-
-}} // apache::thrift
+}
+} // apache::thrift
#endif // _THRIFT_TOSTRING_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/Thrift.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/Thrift.cpp b/lib/cpp/src/thrift/Thrift.cpp
index b1e1386..5739d0f 100644
--- a/lib/cpp/src/thrift/Thrift.cpp
+++ b/lib/cpp/src/thrift/Thrift.cpp
@@ -24,11 +24,12 @@
#include <stdarg.h>
#include <stdio.h>
-namespace apache { namespace thrift {
+namespace apache {
+namespace thrift {
TOutput GlobalOutput;
-void TOutput::printf(const char *message, ...) {
+void TOutput::printf(const char* message, ...) {
#ifndef THRIFT_SQUELCH_CONSOLE_OUTPUT
// Try to reduce heap usage, even if printf is called rarely.
static const int STACK_BUF_SIZE = 256;
@@ -58,7 +59,7 @@ void TOutput::printf(const char *message, ...) {
}
#endif
- char *heap_buf = (char*)malloc((need+1) * sizeof(char));
+ char* heap_buf = (char*)malloc((need + 1) * sizeof(char));
if (heap_buf == NULL) {
#ifdef _MSC_VER
va_start(ap, message);
@@ -71,7 +72,7 @@ void TOutput::printf(const char *message, ...) {
}
va_start(ap, message);
- int rval = vsnprintf(heap_buf, need+1, message, ap);
+ int rval = vsnprintf(heap_buf, need + 1, message, ap);
va_end(ap);
// TODO(shigin): inform user
if (rval != -1) {
@@ -92,7 +93,7 @@ void TOutput::errorTimeWrapper(const char* msg) {
#endif
}
-void TOutput::perror(const char *message, int errno_copy) {
+void TOutput::perror(const char* message, int errno_copy) {
std::string out = message + strerror_s(errno_copy);
f_(out.c_str());
}
@@ -100,18 +101,18 @@ void TOutput::perror(const char *message, int errno_copy) {
std::string TOutput::strerror_s(int errno_copy) {
#ifndef HAVE_STRERROR_R
return "errno = " + boost::lexical_cast<std::string>(errno_copy);
-#else // HAVE_STRERROR_R
+#else // HAVE_STRERROR_R
- char b_errbuf[1024] = { '\0' };
+ char b_errbuf[1024] = {'\0'};
#ifdef STRERROR_R_CHAR_P
- char *b_error = strerror_r(errno_copy, b_errbuf, sizeof(b_errbuf));
+ char* b_error = strerror_r(errno_copy, b_errbuf, sizeof(b_errbuf));
#else
- char *b_error = b_errbuf;
+ char* b_error = b_errbuf;
int rv = strerror_r(errno_copy, b_errbuf, sizeof(b_errbuf));
if (rv == -1) {
// strerror_r failed. omgwtfbbq.
- return "XSI-compliant strerror_r() failed with errno = " +
- boost::lexical_cast<std::string>(errno_copy);
+ return "XSI-compliant strerror_r() failed with errno = "
+ + boost::lexical_cast<std::string>(errno_copy);
}
#endif
// Can anyone prove that explicit cast is probably not necessary
@@ -119,7 +120,7 @@ std::string TOutput::strerror_s(int errno_copy) {
// b_error becomes invalid?
return std::string(b_error);
-#endif // HAVE_STRERROR_R
+#endif // HAVE_STRERROR_R
}
-
-}} // apache::thrift
+}
+} // apache::thrift
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/Thrift.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/Thrift.h b/lib/cpp/src/thrift/Thrift.h
index 4d8d87c..9ddf946 100644
--- a/lib/cpp/src/thrift/Thrift.h
+++ b/lib/cpp/src/thrift/Thrift.h
@@ -62,40 +62,33 @@
* THRIFT_OVERLOAD_IF_DEFN should be used in the function definition, if it is
* defined separately from where it is declared.
*/
-#define THRIFT_OVERLOAD_IF_DEFN(T, Y) \
- typename ::boost::enable_if<typename ::boost::is_convertible<T*, Y*>::type, \
- void*>::type
+#define THRIFT_OVERLOAD_IF_DEFN(T, Y) \
+ typename ::boost::enable_if<typename ::boost::is_convertible<T*, Y*>::type, void*>::type
-#define THRIFT_OVERLOAD_IF(T, Y) \
- THRIFT_OVERLOAD_IF_DEFN(T, Y) = NULL
+#define THRIFT_OVERLOAD_IF(T, Y) THRIFT_OVERLOAD_IF_DEFN(T, Y) = NULL
#define THRIFT_UNUSED_VARIABLE(x) ((void)(x))
-namespace apache { namespace thrift {
+namespace apache {
+namespace thrift {
-class TEnumIterator : public std::iterator<std::forward_iterator_tag, std::pair<int, const char*> > {
- public:
- TEnumIterator(int n,
- int* enums,
- const char** names) :
- ii_(0), n_(n), enums_(enums), names_(names) {
- }
+class TEnumIterator
+ : public std::iterator<std::forward_iterator_tag, std::pair<int, const char*> > {
+public:
+ TEnumIterator(int n, int* enums, const char** names)
+ : ii_(0), n_(n), enums_(enums), names_(names) {}
- int operator ++() {
- return ++ii_;
- }
+ int operator++() { return ++ii_; }
- bool operator !=(const TEnumIterator& end) {
- (void)end; // avoid "unused" warning with NDEBUG
+ bool operator!=(const TEnumIterator& end) {
+ (void)end; // avoid "unused" warning with NDEBUG
assert(end.n_ == -1);
return (ii_ != n_);
}
- std::pair<int, const char*> operator*() const {
- return std::make_pair(enums_[ii_], names_[ii_]);
- }
+ std::pair<int, const char*> operator*() const { return std::make_pair(enums_[ii_], names_[ii_]); }
- private:
+private:
int ii_;
const int n_;
int* enums_;
@@ -103,46 +96,40 @@ class TEnumIterator : public std::iterator<std::forward_iterator_tag, std::pair<
};
class TOutput {
- public:
+public:
TOutput() : f_(&errorTimeWrapper) {}
- inline void setOutputFunction(void (*function)(const char *)){
- f_ = function;
- }
+ inline void setOutputFunction(void (*function)(const char*)) { f_ = function; }
- inline void operator()(const char *message){
- f_(message);
- }
+ inline void operator()(const char* message) { f_(message); }
// It is important to have a const char* overload here instead of
// just the string version, otherwise errno could be corrupted
// if there is some problem allocating memory when constructing
// the string.
- void perror(const char *message, int errno_copy);
- inline void perror(const std::string &message, int errno_copy) {
+ void perror(const char* message, int errno_copy);
+ inline void perror(const std::string& message, int errno_copy) {
perror(message.c_str(), errno_copy);
}
- void printf(const char *message, ...);
+ void printf(const char* message, ...);
static void errorTimeWrapper(const char* msg);
/** Just like strerror_r but returns a C++ string object. */
static std::string strerror_s(int errno_copy);
- private:
- void (*f_)(const char *);
+private:
+ void (*f_)(const char*);
};
extern TOutput GlobalOutput;
class TException : public std::exception {
- public:
- TException():
- message_() {}
+public:
+ TException() : message_() {}
- TException(const std::string& message) :
- message_(message) {}
+ TException(const std::string& message) : message_(message) {}
virtual ~TException() throw() {}
@@ -154,33 +141,36 @@ class TException : public std::exception {
}
}
- protected:
+protected:
std::string message_;
-
};
-
// Forward declare this structure used by TDenseProtocol
-namespace reflection { namespace local {
+namespace reflection {
+namespace local {
struct TypeSpec;
-}}
+}
+}
class TDelayedException {
- public:
- template <class E> static TDelayedException* delayException(const E& e);
+public:
+ template <class E>
+ static TDelayedException* delayException(const E& e);
virtual void throw_it() = 0;
- virtual ~TDelayedException() {};
+ virtual ~TDelayedException(){};
};
-template <class E> class TExceptionWrapper : public TDelayedException {
- public:
+template <class E>
+class TExceptionWrapper : public TDelayedException {
+public:
TExceptionWrapper(const E& e) : e_(e) {}
virtual void throw_it() {
E temp(e_);
delete this;
throw temp;
}
- private:
+
+private:
E e_;
};
@@ -191,13 +181,12 @@ TDelayedException* TDelayedException::delayException(const E& e) {
#if T_GLOBAL_DEBUG_VIRTUAL > 1
void profile_virtual_call(const std::type_info& info);
-void profile_generic_protocol(const std::type_info& template_type,
- const std::type_info& prot_type);
-void profile_print_info(FILE *f);
+void profile_generic_protocol(const std::type_info& template_type, const std::type_info& prot_type);
+void profile_print_info(FILE* f);
void profile_print_info();
void profile_write_pprof(FILE* gen_calls_f, FILE* virtual_calls_f);
#endif
-
-}} // apache::thrift
+}
+} // apache::thrift
#endif // #ifndef _THRIFT_THRIFT_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/VirtualProfiling.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/VirtualProfiling.cpp b/lib/cpp/src/thrift/VirtualProfiling.cpp
index 180cfb7..6ce346b 100644
--- a/lib/cpp/src/thrift/VirtualProfiling.cpp
+++ b/lib/cpp/src/thrift/VirtualProfiling.cpp
@@ -35,14 +35,14 @@
#error "Thrift virtual function profiling currently requires glibc"
#endif // !__GLIBC__
-
#include <thrift/concurrency/Mutex.h>
#include <ext/hash_map>
#include <execinfo.h>
#include <stdio.h>
-namespace apache { namespace thrift {
+namespace apache {
+namespace thrift {
using ::apache::thrift::concurrency::Mutex;
using ::apache::thrift::concurrency::Guard;
@@ -53,20 +53,18 @@ static const unsigned int MAX_STACK_DEPTH = 15;
* A stack trace
*/
class Backtrace {
- public:
+public:
Backtrace(int skip = 0);
- Backtrace(Backtrace const &bt);
+ Backtrace(Backtrace const& bt);
- void operator=(Backtrace const &bt) {
+ void operator=(Backtrace const& bt) {
numCallers_ = bt.numCallers_;
if (numCallers_ >= 0) {
memcpy(callers_, bt.callers_, numCallers_ * sizeof(void*));
}
}
- bool operator==(Backtrace const &bt) const {
- return (cmp(bt) == 0);
- }
+ bool operator==(Backtrace const& bt) const { return (cmp(bt) == 0); }
size_t hash() const {
intptr_t ret = 0;
@@ -83,8 +81,8 @@ class Backtrace {
}
for (int n = 0; n < numCallers_; ++n) {
- int diff = reinterpret_cast<intptr_t>(callers_[n]) -
- reinterpret_cast<intptr_t>(bt.callers_[n]);
+ int diff = reinterpret_cast<intptr_t>(callers_[n])
+ - reinterpret_cast<intptr_t>(bt.callers_[n]);
if (diff != 0) {
return diff;
}
@@ -93,8 +91,8 @@ class Backtrace {
return 0;
}
- void print(FILE *f, int indent=0, int start=0) const {
- char **strings = backtrace_symbols(callers_, numCallers_);
+ void print(FILE* f, int indent = 0, int start = 0) const {
+ char** strings = backtrace_symbols(callers_, numCallers_);
if (strings) {
start += skip_;
if (start < 0) {
@@ -109,11 +107,9 @@ class Backtrace {
}
}
- int getDepth() const {
- return numCallers_ - skip_;
- }
+ int getDepth() const { return numCallers_ - skip_; }
- void *getFrame(int index) const {
+ void* getFrame(int index) const {
int adjusted_index = index + skip_;
if (adjusted_index < 0 || adjusted_index >= numCallers_) {
return NULL;
@@ -121,8 +117,8 @@ class Backtrace {
return callers_[adjusted_index];
}
- private:
- void *callers_[MAX_STACK_DEPTH];
+private:
+ void* callers_[MAX_STACK_DEPTH];
int numCallers_;
int skip_;
};
@@ -138,9 +134,7 @@ Backtrace::Backtrace(int skip)
}
}
-Backtrace::Backtrace(Backtrace const &bt)
- : numCallers_(bt.numCallers_)
- , skip_(bt.skip_) {
+Backtrace::Backtrace(Backtrace const& bt) : numCallers_(bt.numCallers_), skip_(bt.skip_) {
if (numCallers_ >= 0) {
memcpy(callers_, bt.callers_, numCallers_ * sizeof(void*));
}
@@ -150,32 +144,20 @@ Backtrace::Backtrace(Backtrace const &bt)
* A backtrace, plus one or two type names
*/
class Key {
- public:
+public:
class Hash {
- public:
- size_t operator()(Key const& k) const {
- return k.hash();
- }
+ public:
+ size_t operator()(Key const& k) const { return k.hash(); }
};
Key(const Backtrace* bt, const std::type_info& type_info)
- : backtrace_(bt)
- , typeName1_(type_info.name())
- , typeName2_(NULL) {
- }
+ : backtrace_(bt), typeName1_(type_info.name()), typeName2_(NULL) {}
- Key(const Backtrace* bt, const std::type_info& type_info1,
- const std::type_info& type_info2)
- : backtrace_(bt)
- , typeName1_(type_info1.name())
- , typeName2_(type_info2.name()) {
- }
+ Key(const Backtrace* bt, const std::type_info& type_info1, const std::type_info& type_info2)
+ : backtrace_(bt), typeName1_(type_info1.name()), typeName2_(type_info2.name()) {}
Key(const Key& k)
- : backtrace_(k.backtrace_)
- , typeName1_(k.typeName1_)
- , typeName2_(k.typeName2_) {
- }
+ : backtrace_(k.backtrace_), typeName1_(k.typeName1_), typeName2_(k.typeName2_) {}
void operator=(const Key& k) {
backtrace_ = k.backtrace_;
@@ -183,17 +165,11 @@ class Key {
typeName2_ = k.typeName2_;
}
- const Backtrace* getBacktrace() const {
- return backtrace_;
- }
+ const Backtrace* getBacktrace() const { return backtrace_; }
- const char* getTypeName() const {
- return typeName1_;
- }
+ const char* getTypeName() const { return typeName1_; }
- const char* getTypeName2() const {
- return typeName2_;
- }
+ const char* getTypeName2() const { return typeName2_; }
void makePersistent() {
// Copy the Backtrace object
@@ -233,20 +209,17 @@ class Key {
return k.typeName2_ - typeName2_;
}
- bool operator==(const Key& k) const {
- return cmp(k) == 0;
- }
+ bool operator==(const Key& k) const { return cmp(k) == 0; }
size_t hash() const {
// NOTE: As above, we just use the name pointer value.
// Works with GNU libstdc++, but not guaranteed to be correct on all
// implementations.
- return backtrace_->hash() ^
- reinterpret_cast<size_t>(typeName1_) ^
- reinterpret_cast<size_t>(typeName2_);
+ return backtrace_->hash() ^ reinterpret_cast<size_t>(typeName1_)
+ ^ reinterpret_cast<size_t>(typeName2_);
}
- private:
+private:
const Backtrace* backtrace_;
const char* typeName1_;
const char* typeName2_;
@@ -257,9 +230,8 @@ class Key {
* has a higher count.
*/
class CountGreater {
- public:
- bool operator()(std::pair<Key, size_t> bt1,
- std::pair<Key, size_t> bt2) const {
+public:
+ bool operator()(std::pair<Key, size_t> bt1, std::pair<Key, size_t> bt2) const {
return bt1.second > bt2.second;
}
};
@@ -278,8 +250,7 @@ Mutex virtual_calls_mutex;
BacktraceMap generic_calls;
Mutex generic_calls_mutex;
-
-void _record_backtrace(BacktraceMap* map, const Mutex& mutex, Key *k) {
+void _record_backtrace(BacktraceMap* map, const Mutex& mutex, Key* k) {
Guard guard(mutex);
BacktraceMap::iterator it = map->find(*k);
@@ -324,7 +295,7 @@ void profile_generic_protocol(const std::type_info& template_type,
* Print the recorded profiling information to the specified file.
*/
void profile_print_info(FILE* f) {
- typedef std::vector< std::pair<Key, size_t> > BacktraceVector;
+ typedef std::vector<std::pair<Key, size_t> > BacktraceVector;
CountGreater is_greater;
@@ -342,13 +313,14 @@ void profile_print_info(FILE* f) {
BacktraceVector gp_sorted(generic_calls.begin(), generic_calls.end());
std::sort(gp_sorted.begin(), gp_sorted.end(), is_greater);
- for (BacktraceVector::const_iterator it = gp_sorted.begin();
- it != gp_sorted.end();
- ++it) {
- Key const &key = it->first;
+ for (BacktraceVector::const_iterator it = gp_sorted.begin(); it != gp_sorted.end(); ++it) {
+ Key const& key = it->first;
size_t const count = it->second;
- fprintf(f, "T_GENERIC_PROTOCOL: %zu calls to %s with a %s:\n",
- count, key.getTypeName(), key.getTypeName2());
+ fprintf(f,
+ "T_GENERIC_PROTOCOL: %zu calls to %s with a %s:\n",
+ count,
+ key.getTypeName(),
+ key.getTypeName2());
key.getBacktrace()->print(f, 2);
fprintf(f, "\n");
}
@@ -357,10 +329,8 @@ void profile_print_info(FILE* f) {
BacktraceVector vc_sorted(virtual_calls.begin(), virtual_calls.end());
std::sort(vc_sorted.begin(), vc_sorted.end(), is_greater);
- for (BacktraceVector::const_iterator it = vc_sorted.begin();
- it != vc_sorted.end();
- ++it) {
- Key const &key = it->first;
+ for (BacktraceVector::const_iterator it = vc_sorted.begin(); it != vc_sorted.end(); ++it) {
+ Key const& key = it->first;
size_t const count = it->second;
fprintf(f, "T_VIRTUAL_CALL: %zu calls on %s:\n", count, key.getTypeName());
key.getBacktrace()->print(f, 2);
@@ -380,7 +350,7 @@ void profile_print_info() {
*/
static void profile_write_pprof_file(FILE* f, BacktraceMap const& map) {
// Write the header
- uintptr_t header[5] = { 0, 3, 0, 0, 0 };
+ uintptr_t header[5] = {0, 3, 0, 0, 0};
fwrite(&header, sizeof(header), 1, f);
// Write the profile records
@@ -399,12 +369,12 @@ static void profile_write_pprof_file(FILE* f, BacktraceMap const& map) {
}
// Write the trailer
- uintptr_t trailer[3] = { 0, 1, 0 };
+ uintptr_t trailer[3] = {0, 1, 0};
fwrite(&trailer, sizeof(trailer), 1, f);
// Write /proc/self/maps
// TODO(simpkins): This only works on linux
- FILE *proc_maps = fopen("/proc/self/maps", "r");
+ FILE* proc_maps = fopen("/proc/self/maps", "r");
if (proc_maps) {
uint8_t buf[4096];
while (true) {
@@ -434,7 +404,7 @@ static void profile_write_pprof_file(FILE* f, BacktraceMap const& map) {
* profile_virtual_call() will be written to this file.
*/
void profile_write_pprof(FILE* gen_calls_f, FILE* virtual_calls_f) {
- typedef std::vector< std::pair<Key, size_t> > BacktraceVector;
+ typedef std::vector<std::pair<Key, size_t> > BacktraceVector;
CountGreater is_greater;
@@ -449,7 +419,7 @@ void profile_write_pprof(FILE* gen_calls_f, FILE* virtual_calls_f) {
// write the info from virtual_calls
profile_write_pprof_file(virtual_calls_f, virtual_calls);
}
-
-}} // apache::thrift
+}
+} // apache::thrift
#endif // T_GLOBAL_PROFILE_VIRTUAL > 0
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/async/TAsyncBufferProcessor.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/async/TAsyncBufferProcessor.h b/lib/cpp/src/thrift/async/TAsyncBufferProcessor.h
index ad7c639..3c957a6 100644
--- a/lib/cpp/src/thrift/async/TAsyncBufferProcessor.h
+++ b/lib/cpp/src/thrift/async/TAsyncBufferProcessor.h
@@ -25,22 +25,24 @@
#include <thrift/transport/TBufferTransports.h>
-namespace apache { namespace thrift { namespace async {
+namespace apache {
+namespace thrift {
+namespace async {
class TAsyncBufferProcessor {
- public:
+public:
// Process data in "in", putting the result in "out".
// Call _return(true) when done, or _return(false) to
// forcefully close the connection (if applicable).
// "in" and "out" should be TMemoryBuffer or similar,
// not a wrapper around a socket.
- virtual void process(
- apache::thrift::stdcxx::function<void(bool healthy)> _return,
- boost::shared_ptr<apache::thrift::transport::TBufferBase> ibuf,
- boost::shared_ptr<apache::thrift::transport::TBufferBase> obuf) = 0;
+ virtual void process(apache::thrift::stdcxx::function<void(bool healthy)> _return,
+ boost::shared_ptr<apache::thrift::transport::TBufferBase> ibuf,
+ boost::shared_ptr<apache::thrift::transport::TBufferBase> obuf) = 0;
virtual ~TAsyncBufferProcessor() {}
};
-
-}}} // apache::thrift::async
+}
+}
+} // apache::thrift::async
#endif // #ifndef _THRIFT_TASYNC_BUFFER_PROCESSOR_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/async/TAsyncChannel.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/async/TAsyncChannel.cpp b/lib/cpp/src/thrift/async/TAsyncChannel.cpp
index 64dfe5f..4716af2 100644
--- a/lib/cpp/src/thrift/async/TAsyncChannel.cpp
+++ b/lib/cpp/src/thrift/async/TAsyncChannel.cpp
@@ -20,15 +20,18 @@
#include <thrift/async/TAsyncChannel.h>
#include <thrift/cxxfunctional.h>
-namespace apache { namespace thrift { namespace async {
+namespace apache {
+namespace thrift {
+namespace async {
void TAsyncChannel::sendAndRecvMessage(const VoidCallback& cob,
TMemoryBuffer* sendBuf,
TMemoryBuffer* recvBuf) {
- apache::thrift::stdcxx::function<void()> send_done =
- apache::thrift::stdcxx::bind(&TAsyncChannel::recvMessage, this, cob, recvBuf);
+ apache::thrift::stdcxx::function<void()> send_done
+ = apache::thrift::stdcxx::bind(&TAsyncChannel::recvMessage, this, cob, recvBuf);
sendMessage(send_done, sendBuf);
}
-
-}}} // apache::thrift::async
+}
+}
+} // apache::thrift::async
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/async/TAsyncChannel.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/async/TAsyncChannel.h b/lib/cpp/src/thrift/async/TAsyncChannel.h
index 0f202fd..eb3ce2a 100644
--- a/lib/cpp/src/thrift/async/TAsyncChannel.h
+++ b/lib/cpp/src/thrift/async/TAsyncChannel.h
@@ -23,15 +23,21 @@
#include <thrift/cxxfunctional.h>
#include <thrift/Thrift.h>
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
class TMemoryBuffer;
-}}}
+}
+}
+}
-namespace apache { namespace thrift { namespace async {
+namespace apache {
+namespace thrift {
+namespace async {
using apache::thrift::transport::TMemoryBuffer;
class TAsyncChannel {
- public:
+public:
typedef apache::thrift::stdcxx::function<void()> VoidCallback;
virtual ~TAsyncChannel() {}
@@ -45,22 +51,23 @@ class TAsyncChannel {
* Send a message over the channel.
*/
virtual void sendMessage(const VoidCallback& cob,
- apache::thrift::transport::TMemoryBuffer* message) = 0;
+ apache::thrift::transport::TMemoryBuffer* message) = 0;
/**
* Receive a message from the channel.
*/
virtual void recvMessage(const VoidCallback& cob,
- apache::thrift::transport::TMemoryBuffer* message) = 0;
+ apache::thrift::transport::TMemoryBuffer* message) = 0;
/**
* Send a message over the channel and receive a response.
*/
virtual void sendAndRecvMessage(const VoidCallback& cob,
- apache::thrift::transport::TMemoryBuffer* sendBuf,
- apache::thrift::transport::TMemoryBuffer* recvBuf);
+ apache::thrift::transport::TMemoryBuffer* sendBuf,
+ apache::thrift::transport::TMemoryBuffer* recvBuf);
};
-
-}}} // apache::thrift::async
+}
+}
+} // apache::thrift::async
#endif // #ifndef _THRIFT_ASYNC_TASYNCCHANNEL_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/async/TAsyncDispatchProcessor.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/async/TAsyncDispatchProcessor.h b/lib/cpp/src/thrift/async/TAsyncDispatchProcessor.h
index 15b5bce..e79c57d 100644
--- a/lib/cpp/src/thrift/async/TAsyncDispatchProcessor.h
+++ b/lib/cpp/src/thrift/async/TAsyncDispatchProcessor.h
@@ -21,7 +21,9 @@
#include <thrift/async/TAsyncProcessor.h>
-namespace apache { namespace thrift { namespace async {
+namespace apache {
+namespace thrift {
+namespace async {
/**
* TAsyncDispatchProcessor is a helper class to parse the message header then
@@ -31,7 +33,7 @@ namespace apache { namespace thrift { namespace async {
*/
template <class Protocol_>
class TAsyncDispatchProcessorT : public TAsyncProcessor {
- public:
+public:
virtual void process(apache::thrift::stdcxx::function<void(bool success)> _return,
boost::shared_ptr<protocol::TProtocol> in,
boost::shared_ptr<protocol::TProtocol> out) {
@@ -60,8 +62,7 @@ class TAsyncDispatchProcessorT : public TAsyncProcessor {
// (The old generated processor code used to try to skip a T_STRUCT and
// continue. However, that seems unsafe.)
if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
- GlobalOutput.printf("received invalid message type %d from client",
- mtype);
+ GlobalOutput.printf("received invalid message type %d from client", mtype);
_return(false);
return;
}
@@ -70,15 +71,15 @@ class TAsyncDispatchProcessorT : public TAsyncProcessor {
}
void processFast(apache::thrift::stdcxx::function<void(bool success)> _return,
- Protocol_* in, Protocol_* out) {
+ Protocol_* in,
+ Protocol_* out) {
std::string fname;
protocol::TMessageType mtype;
int32_t seqid;
in->readMessageBegin(fname, mtype, seqid);
if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
- GlobalOutput.printf("received invalid message type %d from client",
- mtype);
+ GlobalOutput.printf("received invalid message type %d from client", mtype);
_return(false);
return;
}
@@ -89,10 +90,12 @@ class TAsyncDispatchProcessorT : public TAsyncProcessor {
virtual void dispatchCall(apache::thrift::stdcxx::function<void(bool ok)> _return,
apache::thrift::protocol::TProtocol* in,
apache::thrift::protocol::TProtocol* out,
- const std::string& fname, int32_t seqid) = 0;
+ const std::string& fname,
+ int32_t seqid) = 0;
virtual void dispatchCallTemplated(apache::thrift::stdcxx::function<void(bool ok)> _return,
- Protocol_* in, Protocol_* out,
+ Protocol_* in,
+ Protocol_* out,
const std::string& fname,
int32_t seqid) = 0;
};
@@ -102,7 +105,7 @@ class TAsyncDispatchProcessorT : public TAsyncProcessor {
* that doesn't bother trying to perform a dynamic_cast.
*/
class TAsyncDispatchProcessor : public TAsyncProcessor {
- public:
+public:
virtual void process(apache::thrift::stdcxx::function<void(bool success)> _return,
boost::shared_ptr<protocol::TProtocol> in,
boost::shared_ptr<protocol::TProtocol> out) {
@@ -120,8 +123,7 @@ class TAsyncDispatchProcessor : public TAsyncProcessor {
// (The old generated processor code used to try to skip a T_STRUCT and
// continue. However, that seems unsafe.)
if (mtype != protocol::T_CALL && mtype != protocol::T_ONEWAY) {
- GlobalOutput.printf("received invalid message type %d from client",
- mtype);
+ GlobalOutput.printf("received invalid message type %d from client", mtype);
_return(false);
return;
}
@@ -132,18 +134,18 @@ class TAsyncDispatchProcessor : public TAsyncProcessor {
virtual void dispatchCall(apache::thrift::stdcxx::function<void(bool ok)> _return,
apache::thrift::protocol::TProtocol* in,
apache::thrift::protocol::TProtocol* out,
- const std::string& fname, int32_t seqid) = 0;
+ const std::string& fname,
+ int32_t seqid) = 0;
};
// Specialize TAsyncDispatchProcessorT for TProtocol and TDummyProtocol just to
// use the generic TDispatchProcessor.
template <>
-class TAsyncDispatchProcessorT<protocol::TDummyProtocol> :
- public TAsyncDispatchProcessor {};
+class TAsyncDispatchProcessorT<protocol::TDummyProtocol> : public TAsyncDispatchProcessor {};
template <>
-class TAsyncDispatchProcessorT<protocol::TProtocol> :
- public TAsyncDispatchProcessor {};
-
-}}} // apache::thrift::async
+class TAsyncDispatchProcessorT<protocol::TProtocol> : public TAsyncDispatchProcessor {};
+}
+}
+} // apache::thrift::async
#endif // _THRIFT_ASYNC_TASYNCDISPATCHPROCESSOR_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/async/TAsyncProcessor.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/async/TAsyncProcessor.h b/lib/cpp/src/thrift/async/TAsyncProcessor.h
index a03d1dc..033f7d9 100644
--- a/lib/cpp/src/thrift/async/TAsyncProcessor.h
+++ b/lib/cpp/src/thrift/async/TAsyncProcessor.h
@@ -25,7 +25,9 @@
#include <thrift/protocol/TProtocol.h>
#include <thrift/TProcessor.h>
-namespace apache { namespace thrift { namespace async {
+namespace apache {
+namespace thrift {
+namespace async {
/**
* Async version of a TProcessor. It is not expected to complete by the time
@@ -35,7 +37,7 @@ namespace apache { namespace thrift { namespace async {
class TEventServer; // forward declaration
class TAsyncProcessor {
- public:
+public:
virtual ~TAsyncProcessor() {}
virtual void process(apache::thrift::stdcxx::function<void(bool success)> _return,
@@ -47,31 +49,27 @@ class TAsyncProcessor {
return process(_return, io, io);
}
- boost::shared_ptr<TProcessorEventHandler> getEventHandler() {
- return eventHandler_;
- }
+ boost::shared_ptr<TProcessorEventHandler> getEventHandler() { return eventHandler_; }
void setEventHandler(boost::shared_ptr<TProcessorEventHandler> eventHandler) {
eventHandler_ = eventHandler;
}
- const TEventServer* getAsyncServer() {
- return asyncServer_;
- }
- protected:
+ const TEventServer* getAsyncServer() { return asyncServer_; }
+
+protected:
TAsyncProcessor() {}
boost::shared_ptr<TProcessorEventHandler> eventHandler_;
const TEventServer* asyncServer_;
- private:
+
+private:
friend class TEventServer;
- void setAsyncServer(const TEventServer* server) {
- asyncServer_ = server;
- }
+ void setAsyncServer(const TEventServer* server) { asyncServer_ = server; }
};
class TAsyncProcessorFactory {
- public:
+public:
virtual ~TAsyncProcessorFactory() {}
/**
@@ -81,17 +79,17 @@ class TAsyncProcessorFactory {
* accepted on. This generally means that this call does not need to be
* thread safe, as it will always be invoked from a single thread.
*/
- virtual boost::shared_ptr<TAsyncProcessor> getProcessor(
- const TConnectionInfo& connInfo) = 0;
+ virtual boost::shared_ptr<TAsyncProcessor> getProcessor(const TConnectionInfo& connInfo) = 0;
};
-
-
-
-}}} // apache::thrift::async
+}
+}
+} // apache::thrift::async
// XXX I'm lazy for now
-namespace apache { namespace thrift {
+namespace apache {
+namespace thrift {
using apache::thrift::async::TAsyncProcessor;
-}}
+}
+}
#endif // #ifndef _THRIFT_TASYNCPROCESSOR_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/async/TAsyncProtocolProcessor.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/async/TAsyncProtocolProcessor.cpp b/lib/cpp/src/thrift/async/TAsyncProtocolProcessor.cpp
index 2096289..5a4f347 100644
--- a/lib/cpp/src/thrift/async/TAsyncProtocolProcessor.cpp
+++ b/lib/cpp/src/thrift/async/TAsyncProtocolProcessor.cpp
@@ -22,30 +22,32 @@
using apache::thrift::transport::TBufferBase;
using apache::thrift::protocol::TProtocol;
-namespace apache { namespace thrift { namespace async {
+namespace apache {
+namespace thrift {
+namespace async {
-void TAsyncProtocolProcessor::process(
- apache::thrift::stdcxx::function<void(bool healthy)> _return,
- boost::shared_ptr<TBufferBase> ibuf,
- boost::shared_ptr<TBufferBase> obuf) {
+void TAsyncProtocolProcessor::process(apache::thrift::stdcxx::function<void(bool healthy)> _return,
+ boost::shared_ptr<TBufferBase> ibuf,
+ boost::shared_ptr<TBufferBase> obuf) {
boost::shared_ptr<TProtocol> iprot(pfact_->getProtocol(ibuf));
boost::shared_ptr<TProtocol> oprot(pfact_->getProtocol(obuf));
- return underlying_->process(
- apache::thrift::stdcxx::bind(
- &TAsyncProtocolProcessor::finish,
- _return,
- oprot,
- apache::thrift::stdcxx::placeholders::_1),
- iprot, oprot);
+ return underlying_
+ ->process(apache::thrift::stdcxx::bind(&TAsyncProtocolProcessor::finish,
+ _return,
+ oprot,
+ apache::thrift::stdcxx::placeholders::_1),
+ iprot,
+ oprot);
}
/* static */ void TAsyncProtocolProcessor::finish(
apache::thrift::stdcxx::function<void(bool healthy)> _return,
boost::shared_ptr<TProtocol> oprot,
bool healthy) {
- (void) oprot;
+ (void)oprot;
// This is a stub function to hold a reference to oprot.
return _return(healthy);
}
-
-}}} // apache::thrift::async
+}
+}
+} // apache::thrift::async
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/async/TAsyncProtocolProcessor.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/async/TAsyncProtocolProcessor.h b/lib/cpp/src/thrift/async/TAsyncProtocolProcessor.h
index 840b4dd..3f2b394 100644
--- a/lib/cpp/src/thrift/async/TAsyncProtocolProcessor.h
+++ b/lib/cpp/src/thrift/async/TAsyncProtocolProcessor.h
@@ -24,34 +24,32 @@
#include <thrift/async/TAsyncBufferProcessor.h>
#include <thrift/protocol/TProtocol.h>
-namespace apache { namespace thrift { namespace async {
+namespace apache {
+namespace thrift {
+namespace async {
class TAsyncProtocolProcessor : public TAsyncBufferProcessor {
- public:
- TAsyncProtocolProcessor(
- boost::shared_ptr<TAsyncProcessor> underlying,
- boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> pfact)
- : underlying_(underlying)
- , pfact_(pfact)
- {}
-
- virtual void process(
- apache::thrift::stdcxx::function<void(bool healthy)> _return,
- boost::shared_ptr<apache::thrift::transport::TBufferBase> ibuf,
- boost::shared_ptr<apache::thrift::transport::TBufferBase> obuf);
+public:
+ TAsyncProtocolProcessor(boost::shared_ptr<TAsyncProcessor> underlying,
+ boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> pfact)
+ : underlying_(underlying), pfact_(pfact) {}
+
+ virtual void process(apache::thrift::stdcxx::function<void(bool healthy)> _return,
+ boost::shared_ptr<apache::thrift::transport::TBufferBase> ibuf,
+ boost::shared_ptr<apache::thrift::transport::TBufferBase> obuf);
virtual ~TAsyncProtocolProcessor() {}
- private:
- static void finish(
- apache::thrift::stdcxx::function<void(bool healthy)> _return,
- boost::shared_ptr<apache::thrift::protocol::TProtocol> oprot,
- bool healthy);
+private:
+ static void finish(apache::thrift::stdcxx::function<void(bool healthy)> _return,
+ boost::shared_ptr<apache::thrift::protocol::TProtocol> oprot,
+ bool healthy);
boost::shared_ptr<TAsyncProcessor> underlying_;
boost::shared_ptr<apache::thrift::protocol::TProtocolFactory> pfact_;
};
-
-}}} // apache::thrift::async
+}
+}
+} // apache::thrift::async
#endif // #ifndef _THRIFT_TNAME_ME_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/async/TEvhttpClientChannel.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/async/TEvhttpClientChannel.cpp b/lib/cpp/src/thrift/async/TEvhttpClientChannel.cpp
index 7ad7537..bcb87cd 100644
--- a/lib/cpp/src/thrift/async/TEvhttpClientChannel.cpp
+++ b/lib/cpp/src/thrift/async/TEvhttpClientChannel.cpp
@@ -28,20 +28,16 @@
using namespace apache::thrift::protocol;
using apache::thrift::transport::TTransportException;
-namespace apache { namespace thrift { namespace async {
-
-
-TEvhttpClientChannel::TEvhttpClientChannel(
- const std::string& host,
- const std::string& path,
- const char* address,
- int port,
- struct event_base* eb)
- : host_(host)
- , path_(path)
- , recvBuf_(NULL)
- , conn_(NULL)
-{
+namespace apache {
+namespace thrift {
+namespace async {
+
+TEvhttpClientChannel::TEvhttpClientChannel(const std::string& host,
+ const std::string& path,
+ const char* address,
+ int port,
+ struct event_base* eb)
+ : host_(host), path_(path), recvBuf_(NULL), conn_(NULL) {
conn_ = evhttp_connection_new(address, port);
if (conn_ == NULL) {
throw TException("evhttp_connection_new failed");
@@ -49,18 +45,15 @@ TEvhttpClientChannel::TEvhttpClientChannel(
evhttp_connection_set_base(conn_, eb);
}
-
TEvhttpClientChannel::~TEvhttpClientChannel() {
if (conn_ != NULL) {
evhttp_connection_free(conn_);
}
}
-
-void TEvhttpClientChannel::sendAndRecvMessage(
- const VoidCallback& cob,
- apache::thrift::transport::TMemoryBuffer* sendBuf,
- apache::thrift::transport::TMemoryBuffer* recvBuf) {
+void TEvhttpClientChannel::sendAndRecvMessage(const VoidCallback& cob,
+ apache::thrift::transport::TMemoryBuffer* sendBuf,
+ apache::thrift::transport::TMemoryBuffer* recvBuf) {
cob_ = cob;
recvBuf_ = recvBuf;
@@ -95,68 +88,64 @@ void TEvhttpClientChannel::sendAndRecvMessage(
}
}
-
-void TEvhttpClientChannel::sendMessage(
- const VoidCallback& cob, apache::thrift::transport::TMemoryBuffer* message) {
- (void) cob;
- (void) message;
+void TEvhttpClientChannel::sendMessage(const VoidCallback& cob,
+ apache::thrift::transport::TMemoryBuffer* message) {
+ (void)cob;
+ (void)message;
throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
- "Unexpected call to TEvhttpClientChannel::sendMessage");
+ "Unexpected call to TEvhttpClientChannel::sendMessage");
}
-
-void TEvhttpClientChannel::recvMessage(
- const VoidCallback& cob, apache::thrift::transport::TMemoryBuffer* message) {
- (void) cob;
- (void) message;
+void TEvhttpClientChannel::recvMessage(const VoidCallback& cob,
+ apache::thrift::transport::TMemoryBuffer* message) {
+ (void)cob;
+ (void)message;
throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
- "Unexpected call to TEvhttpClientChannel::recvMessage");
+ "Unexpected call to TEvhttpClientChannel::recvMessage");
}
-
void TEvhttpClientChannel::finish(struct evhttp_request* req) {
if (req == NULL) {
- try {
- cob_();
- } catch(const TTransportException& e) {
- if(e.getType() == TTransportException::END_OF_FILE)
- throw TException("connect failed");
- else
- throw;
- }
- return;
+ try {
+ cob_();
+ } catch (const TTransportException& e) {
+ if (e.getType() == TTransportException::END_OF_FILE)
+ throw TException("connect failed");
+ else
+ throw;
+ }
+ return;
} else if (req->response_code != 200) {
- try {
- cob_();
- } catch(const TTransportException& e) {
- std::stringstream ss;
- ss << "server returned code " << req->response_code;
- if(req->response_code_line)
- ss << ": " << req->response_code_line;
- if(e.getType() == TTransportException::END_OF_FILE)
- throw TException(ss.str());
- else
- throw;
- }
- return;
+ try {
+ cob_();
+ } catch (const TTransportException& e) {
+ std::stringstream ss;
+ ss << "server returned code " << req->response_code;
+ if (req->response_code_line)
+ ss << ": " << req->response_code_line;
+ if (e.getType() == TTransportException::END_OF_FILE)
+ throw TException(ss.str());
+ else
+ throw;
+ }
+ return;
}
- recvBuf_->resetBuffer(
- EVBUFFER_DATA(req->input_buffer),
- static_cast<uint32_t>(EVBUFFER_LENGTH(req->input_buffer)));
+ recvBuf_->resetBuffer(EVBUFFER_DATA(req->input_buffer),
+ static_cast<uint32_t>(EVBUFFER_LENGTH(req->input_buffer)));
cob_();
return;
}
-
/* static */ void TEvhttpClientChannel::response(struct evhttp_request* req, void* arg) {
TEvhttpClientChannel* self = (TEvhttpClientChannel*)arg;
try {
self->finish(req);
- } catch(std::exception& e) {
+ } catch (std::exception& e) {
// don't propagate a C++ exception in C code (e.g. libevent)
- std::cerr << "TEvhttpClientChannel::response exception thrown (ignored): " << e.what() << std::endl;
+ std::cerr << "TEvhttpClientChannel::response exception thrown (ignored): " << e.what()
+ << std::endl;
}
}
-
-
-}}} // apache::thrift::async
+}
+}
+} // apache::thrift::async
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/async/TEvhttpClientChannel.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/async/TEvhttpClientChannel.h b/lib/cpp/src/thrift/async/TEvhttpClientChannel.h
index a7229e9..72ed40f 100644
--- a/lib/cpp/src/thrift/async/TEvhttpClientChannel.h
+++ b/lib/cpp/src/thrift/async/TEvhttpClientChannel.h
@@ -28,39 +28,46 @@ struct event_base;
struct evhttp_connection;
struct evhttp_request;
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
class TMemoryBuffer;
-}}}
+}
+}
+}
-namespace apache { namespace thrift { namespace async {
+namespace apache {
+namespace thrift {
+namespace async {
class TEvhttpClientChannel : public TAsyncChannel {
- public:
+public:
using TAsyncChannel::VoidCallback;
- TEvhttpClientChannel(
- const std::string& host,
- const std::string& path,
- const char* address,
- int port,
- struct event_base* eb);
+ TEvhttpClientChannel(const std::string& host,
+ const std::string& path,
+ const char* address,
+ int port,
+ struct event_base* eb);
~TEvhttpClientChannel();
virtual void sendAndRecvMessage(const VoidCallback& cob,
apache::thrift::transport::TMemoryBuffer* sendBuf,
apache::thrift::transport::TMemoryBuffer* recvBuf);
- virtual void sendMessage(const VoidCallback& cob, apache::thrift::transport::TMemoryBuffer* message);
- virtual void recvMessage(const VoidCallback& cob, apache::thrift::transport::TMemoryBuffer* message);
+ virtual void sendMessage(const VoidCallback& cob,
+ apache::thrift::transport::TMemoryBuffer* message);
+ virtual void recvMessage(const VoidCallback& cob,
+ apache::thrift::transport::TMemoryBuffer* message);
void finish(struct evhttp_request* req);
- //XXX
+ // XXX
virtual bool good() const { return true; }
virtual bool error() const { return false; }
virtual bool timedOut() const { return false; }
- private:
+private:
static void response(struct evhttp_request* req, void* arg);
std::string host_;
@@ -68,9 +75,9 @@ class TEvhttpClientChannel : public TAsyncChannel {
VoidCallback cob_;
apache::thrift::transport::TMemoryBuffer* recvBuf_;
struct evhttp_connection* conn_;
-
};
-
-}}} // apache::thrift::async
+}
+}
+} // apache::thrift::async
#endif // #ifndef _THRIFT_TEVHTTP_CLIENT_CHANNEL_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/async/TEvhttpServer.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/async/TEvhttpServer.cpp b/lib/cpp/src/thrift/async/TEvhttpServer.cpp
index fa8d782..93fb479 100644
--- a/lib/cpp/src/thrift/async/TEvhttpServer.cpp
+++ b/lib/cpp/src/thrift/async/TEvhttpServer.cpp
@@ -30,8 +30,9 @@
using apache::thrift::transport::TMemoryBuffer;
-namespace apache { namespace thrift { namespace async {
-
+namespace apache {
+namespace thrift {
+namespace async {
struct TEvhttpServer::RequestContext {
struct evhttp_request* req;
@@ -41,19 +42,12 @@ struct TEvhttpServer::RequestContext {
RequestContext(struct evhttp_request* req);
};
-
TEvhttpServer::TEvhttpServer(boost::shared_ptr<TAsyncBufferProcessor> processor)
- : processor_(processor)
- , eb_(NULL)
- , eh_(NULL)
-{}
-
+ : processor_(processor), eb_(NULL), eh_(NULL) {
+}
TEvhttpServer::TEvhttpServer(boost::shared_ptr<TAsyncBufferProcessor> processor, int port)
- : processor_(processor)
- , eb_(NULL)
- , eh_(NULL)
-{
+ : processor_(processor), eb_(NULL), eh_(NULL) {
// Create event_base and evhttp.
eb_ = event_base_new();
if (eb_ == NULL) {
@@ -70,7 +64,7 @@ TEvhttpServer::TEvhttpServer(boost::shared_ptr<TAsyncBufferProcessor> processor,
if (ret < 0) {
evhttp_free(eh_);
event_base_free(eb_);
- throw TException("evhttp_bind_socket failed");
+ throw TException("evhttp_bind_socket failed");
}
// Register a handler. If you use the other constructor,
@@ -79,7 +73,6 @@ TEvhttpServer::TEvhttpServer(boost::shared_ptr<TAsyncBufferProcessor> processor,
evhttp_set_cb(eh_, "/", request, (void*)this);
}
-
TEvhttpServer::~TEvhttpServer() {
if (eh_ != NULL) {
evhttp_free(eh_);
@@ -89,7 +82,6 @@ TEvhttpServer::~TEvhttpServer() {
}
}
-
int TEvhttpServer::serve() {
if (eb_ == NULL) {
throw TException("Unexpected call to TEvhttpServer::serve");
@@ -97,37 +89,33 @@ int TEvhttpServer::serve() {
return event_base_dispatch(eb_);
}
-
-TEvhttpServer::RequestContext::RequestContext(struct evhttp_request* req) : req(req)
- , ibuf(new TMemoryBuffer(EVBUFFER_DATA(req->input_buffer), static_cast<uint32_t>(EVBUFFER_LENGTH(req->input_buffer))))
- , obuf(new TMemoryBuffer())
-{}
-
+TEvhttpServer::RequestContext::RequestContext(struct evhttp_request* req)
+ : req(req),
+ ibuf(new TMemoryBuffer(EVBUFFER_DATA(req->input_buffer),
+ static_cast<uint32_t>(EVBUFFER_LENGTH(req->input_buffer)))),
+ obuf(new TMemoryBuffer()) {
+}
void TEvhttpServer::request(struct evhttp_request* req, void* self) {
try {
static_cast<TEvhttpServer*>(self)->process(req);
- } catch(std::exception& e) {
+ } catch (std::exception& e) {
evhttp_send_reply(req, HTTP_INTERNAL, e.what(), 0);
}
}
-
void TEvhttpServer::process(struct evhttp_request* req) {
RequestContext* ctx = new RequestContext(req);
- return processor_->process(
- apache::thrift::stdcxx::bind(
- &TEvhttpServer::complete,
- this,
- ctx,
- apache::thrift::stdcxx::placeholders::_1),
- ctx->ibuf,
- ctx->obuf);
+ return processor_->process(apache::thrift::stdcxx::bind(&TEvhttpServer::complete,
+ this,
+ ctx,
+ apache::thrift::stdcxx::placeholders::_1),
+ ctx->ibuf,
+ ctx->obuf);
}
-
void TEvhttpServer::complete(RequestContext* ctx, bool success) {
- (void) success;
+ (void)success;
std::auto_ptr<RequestContext> ptr(ctx);
int code = success ? 200 : 400;
@@ -142,7 +130,7 @@ void TEvhttpServer::complete(RequestContext* ctx, bool success) {
struct evbuffer* buf = evbuffer_new();
if (buf == NULL) {
// TODO: Log an error.
- std::cerr << "evbuffer_new failed " << __FILE__ << ":" << __LINE__ << std::endl;
+ std::cerr << "evbuffer_new failed " << __FILE__ << ":" << __LINE__ << std::endl;
} else {
uint8_t* obuf;
uint32_t sz;
@@ -150,7 +138,8 @@ void TEvhttpServer::complete(RequestContext* ctx, bool success) {
int ret = evbuffer_add(buf, obuf, sz);
if (ret != 0) {
// TODO: Log an error.
- std::cerr << "evhttp_add failed with " << ret << " " << __FILE__ << ":" << __LINE__ << std::endl;
+ std::cerr << "evhttp_add failed with " << ret << " " << __FILE__ << ":" << __LINE__
+ << std::endl;
}
}
@@ -160,10 +149,9 @@ void TEvhttpServer::complete(RequestContext* ctx, bool success) {
}
}
-
struct event_base* TEvhttpServer::getEventBase() {
return eb_;
}
-
-
-}}} // apache::thrift::async
+}
+}
+} // apache::thrift::async
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/async/TEvhttpServer.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/async/TEvhttpServer.h b/lib/cpp/src/thrift/async/TEvhttpServer.h
index edc6ffb..89bf337 100644
--- a/lib/cpp/src/thrift/async/TEvhttpServer.h
+++ b/lib/cpp/src/thrift/async/TEvhttpServer.h
@@ -26,12 +26,14 @@ struct event_base;
struct evhttp;
struct evhttp_request;
-namespace apache { namespace thrift { namespace async {
+namespace apache {
+namespace thrift {
+namespace async {
class TAsyncBufferProcessor;
class TEvhttpServer {
- public:
+public:
/**
* Create a TEvhttpServer for use with an external evhttp instance.
* Must be manually installed with evhttp_set_cb, using
@@ -55,7 +57,7 @@ class TEvhttpServer {
struct event_base* getEventBase();
- private:
+private:
struct RequestContext;
void process(struct evhttp_request* req);
@@ -65,7 +67,8 @@ class TEvhttpServer {
struct event_base* eb_;
struct evhttp* eh_;
};
-
-}}} // apache::thrift::async
+}
+}
+} // apache::thrift::async
#endif // #ifndef _THRIFT_TEVHTTP_SERVER_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/concurrency/BoostMonitor.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/concurrency/BoostMonitor.cpp b/lib/cpp/src/thrift/concurrency/BoostMonitor.cpp
index 1027157..6c24d82 100644
--- a/lib/cpp/src/thrift/concurrency/BoostMonitor.cpp
+++ b/lib/cpp/src/thrift/concurrency/BoostMonitor.cpp
@@ -29,7 +29,9 @@
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
-namespace apache { namespace thrift { namespace concurrency {
+namespace apache {
+namespace thrift {
+namespace concurrency {
/**
* Monitor implementation using the boost thread library
@@ -38,23 +40,12 @@ namespace apache { namespace thrift { namespace concurrency {
*/
class Monitor::Impl : public boost::condition_variable_any {
- public:
+public:
+ Impl() : ownedMutex_(new Mutex()), mutex_(NULL) { init(ownedMutex_.get()); }
- Impl()
- : ownedMutex_(new Mutex()),
- mutex_(NULL) {
- init(ownedMutex_.get());
- }
-
- Impl(Mutex* mutex)
- : mutex_(NULL) {
- init(mutex);
- }
+ Impl(Mutex* mutex) : mutex_(NULL) { init(mutex); }
- Impl(Monitor* monitor)
- : mutex_(NULL) {
- init(&(monitor->mutex()));
- }
+ Impl(Monitor* monitor) : mutex_(NULL) { init(&(monitor->mutex())); }
Mutex& mutex() { return *mutex_; }
void lock() { mutex().lock(); }
@@ -72,8 +63,7 @@ class Monitor::Impl : public boost::condition_variable_any {
if (result == THRIFT_ETIMEDOUT) {
throw TimedOutException();
} else if (result != 0) {
- throw TException(
- "Monitor::wait() failed");
+ throw TException("Monitor::wait() failed");
}
}
@@ -89,14 +79,17 @@ class Monitor::Impl : public boost::condition_variable_any {
}
assert(mutex_);
- boost::timed_mutex* mutexImpl =
- reinterpret_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
+ boost::timed_mutex* mutexImpl
+ = reinterpret_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
assert(mutexImpl);
- boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
- int res = timed_wait(lock, boost::get_system_time()+boost::posix_time::milliseconds(timeout_ms)) ? 0 : THRIFT_ETIMEDOUT;
- lock.release();
- return res;
+ boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
+ int res
+ = timed_wait(lock, boost::get_system_time() + boost::posix_time::milliseconds(timeout_ms))
+ ? 0
+ : THRIFT_ETIMEDOUT;
+ lock.release();
+ return res;
}
/**
@@ -105,7 +98,7 @@ class Monitor::Impl : public boost::condition_variable_any {
*/
int waitForTime(const THRIFT_TIMESPEC* abstime) {
struct timeval temp;
- temp.tv_sec = static_cast<long>(abstime->tv_sec);
+ temp.tv_sec = static_cast<long>(abstime->tv_sec);
temp.tv_usec = static_cast<long>(abstime->tv_nsec) / 1000;
return waitForTime(&temp);
}
@@ -116,27 +109,27 @@ class Monitor::Impl : public boost::condition_variable_any {
*/
int waitForTime(const struct timeval* abstime) {
assert(mutex_);
- boost::timed_mutex* mutexImpl =
- static_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
+ boost::timed_mutex* mutexImpl = static_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
assert(mutexImpl);
struct timeval currenttime;
Util::toTimeval(currenttime, Util::currentTime());
- long tv_sec = static_cast<long>(abstime->tv_sec - currenttime.tv_sec);
- long tv_usec = static_cast<long>(abstime->tv_usec - currenttime.tv_usec);
- if(tv_sec < 0)
- tv_sec = 0;
- if(tv_usec < 0)
- tv_usec = 0;
-
- boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
- int res = timed_wait(lock, boost::get_system_time() +
- boost::posix_time::seconds(tv_sec) +
- boost::posix_time::microseconds(tv_usec)
- ) ? 0 : THRIFT_ETIMEDOUT;
- lock.release();
- return res;
+ long tv_sec = static_cast<long>(abstime->tv_sec - currenttime.tv_sec);
+ long tv_usec = static_cast<long>(abstime->tv_usec - currenttime.tv_usec);
+ if (tv_sec < 0)
+ tv_sec = 0;
+ if (tv_usec < 0)
+ tv_usec = 0;
+
+ boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
+ int res = timed_wait(lock,
+ boost::get_system_time() + boost::posix_time::seconds(tv_sec)
+ + boost::posix_time::microseconds(tv_usec))
+ ? 0
+ : THRIFT_ETIMEDOUT;
+ lock.release();
+ return res;
}
/**
@@ -145,48 +138,53 @@ class Monitor::Impl : public boost::condition_variable_any {
*/
int waitForever() {
assert(mutex_);
- boost::timed_mutex* mutexImpl =
- reinterpret_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
+ boost::timed_mutex* mutexImpl
+ = reinterpret_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
assert(mutexImpl);
- boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
- ((boost::condition_variable_any*)this)->wait(lock);
- lock.release();
+ boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
+ ((boost::condition_variable_any*)this)->wait(lock);
+ lock.release();
return 0;
}
+ void notify() { notify_one(); }
- void notify() {
- notify_one();
- }
+ void notifyAll() { notify_all(); }
- void notifyAll() {
- notify_all();
- }
-
- private:
-
- void init(Mutex* mutex) {
- mutex_ = mutex;
- }
+private:
+ void init(Mutex* mutex) { mutex_ = mutex; }
boost::scoped_ptr<Mutex> ownedMutex_;
Mutex* mutex_;
};
-Monitor::Monitor() : impl_(new Monitor::Impl()) {}
-Monitor::Monitor(Mutex* mutex) : impl_(new Monitor::Impl(mutex)) {}
-Monitor::Monitor(Monitor* monitor) : impl_(new Monitor::Impl(monitor)) {}
+Monitor::Monitor() : impl_(new Monitor::Impl()) {
+}
+Monitor::Monitor(Mutex* mutex) : impl_(new Monitor::Impl(mutex)) {
+}
+Monitor::Monitor(Monitor* monitor) : impl_(new Monitor::Impl(monitor)) {
+}
-Monitor::~Monitor() { delete impl_; }
+Monitor::~Monitor() {
+ delete impl_;
+}
-Mutex& Monitor::mutex() const { return const_cast<Monitor::Impl*>(impl_)->mutex(); }
+Mutex& Monitor::mutex() const {
+ return const_cast<Monitor::Impl*>(impl_)->mutex();
+}
-void Monitor::lock() const { const_cast<Monitor::Impl*>(impl_)->lock(); }
+void Monitor::lock() const {
+ const_cast<Monitor::Impl*>(impl_)->lock();
+}
-void Monitor::unlock() const { const_cast<Monitor::Impl*>(impl_)->unlock(); }
+void Monitor::unlock() const {
+ const_cast<Monitor::Impl*>(impl_)->unlock();
+}
-void Monitor::wait(int64_t timeout) const { const_cast<Monitor::Impl*>(impl_)->wait(timeout); }
+void Monitor::wait(int64_t timeout) const {
+ const_cast<Monitor::Impl*>(impl_)->wait(timeout);
+}
int Monitor::waitForTime(const THRIFT_TIMESPEC* abstime) const {
return const_cast<Monitor::Impl*>(impl_)->waitForTime(abstime);
@@ -204,8 +202,13 @@ int Monitor::waitForever() const {
return const_cast<Monitor::Impl*>(impl_)->waitForever();
}
-void Monitor::notify() const { const_cast<Monitor::Impl*>(impl_)->notify(); }
-
-void Monitor::notifyAll() const { const_cast<Monitor::Impl*>(impl_)->notifyAll(); }
+void Monitor::notify() const {
+ const_cast<Monitor::Impl*>(impl_)->notify();
+}
-}}} // apache::thrift::concurrency
+void Monitor::notifyAll() const {
+ const_cast<Monitor::Impl*>(impl_)->notifyAll();
+}
+}
+}
+} // apache::thrift::concurrency
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/concurrency/BoostMutex.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/concurrency/BoostMutex.cpp b/lib/cpp/src/thrift/concurrency/BoostMutex.cpp
index 59c3618..f7cadab 100644
--- a/lib/cpp/src/thrift/concurrency/BoostMutex.cpp
+++ b/lib/cpp/src/thrift/concurrency/BoostMutex.cpp
@@ -28,31 +28,44 @@
#include <boost/thread/mutex.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
-namespace apache { namespace thrift { namespace concurrency {
+namespace apache {
+namespace thrift {
+namespace concurrency {
/**
* Implementation of Mutex class using boost interprocess mutex
*
* @version $Id:$
*/
-class Mutex::impl : public boost::timed_mutex {
-};
+class Mutex::impl : public boost::timed_mutex {};
-Mutex::Mutex(Initializer init) : impl_(new Mutex::impl())
-{ THRIFT_UNUSED_VARIABLE(init); }
+Mutex::Mutex(Initializer init) : impl_(new Mutex::impl()) {
+ THRIFT_UNUSED_VARIABLE(init);
+}
-void* Mutex::getUnderlyingImpl() const { return impl_.get(); }
+void* Mutex::getUnderlyingImpl() const {
+ return impl_.get();
+}
-void Mutex::lock() const { impl_->lock(); }
+void Mutex::lock() const {
+ impl_->lock();
+}
-bool Mutex::trylock() const { return impl_->try_lock(); }
+bool Mutex::trylock() const {
+ return impl_->try_lock();
+}
-bool Mutex::timedlock(int64_t ms) const { return impl_->timed_lock(boost::get_system_time()+boost::posix_time::milliseconds(ms)); }
+bool Mutex::timedlock(int64_t ms) const {
+ return impl_->timed_lock(boost::get_system_time() + boost::posix_time::milliseconds(ms));
+}
-void Mutex::unlock() const { impl_->unlock(); }
+void Mutex::unlock() const {
+ impl_->unlock();
+}
void Mutex::DEFAULT_INITIALIZER(void* arg) {
THRIFT_UNUSED_VARIABLE(arg);
}
-
-}}} // apache::thrift::concurrency
+}
+}
+} // apache::thrift::concurrency