http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/Logger.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Logger.h b/lib/atscppapi/src/include/atscppapi/Logger.h index f5227d0..9b1265f 100644 --- a/lib/atscppapi/src/include/atscppapi/Logger.h +++ b/lib/atscppapi/src/include/atscppapi/Logger.h @@ -57,27 +57,27 @@ * // Outputs [file.cc:125, function()] [DEBUG] This is a test DEBUG message: hello. * \endcode */ -#define LOG_DEBUG(log, fmt, ...) \ - do { \ - (log).logDebug("[%s:%d, %s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__); \ +#define LOG_DEBUG(log, fmt, ...) \ + do { \ + (log).logDebug("[%s:%d, %s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \ } while (false) /** * A helper macro for Logger objects that allows you to easily add a info level message * which will include file, line, and function name with the message. See example in LOG_DEBUG */ -#define LOG_INFO(log, fmt, ...) \ - do { \ - (log).logInfo("[%s:%d, %s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__); \ +#define LOG_INFO(log, fmt, ...) \ + do { \ + (log).logInfo("[%s:%d, %s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \ } while (false) /** * A helper macro for Logger objects that allows you to easily add a error level message * which will include file, line, and function name with the message. See example in LOG_DEBUG */ -#define LOG_ERROR(log, fmt, ...) \ - do { \ - (log).logError("[%s:%d, %s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__); \ +#define LOG_ERROR(log, fmt, ...) \ + do { \ + (log).logError("[%s:%d, %s()] " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \ } while (false) /** @@ -87,7 +87,7 @@ * * @private */ -extern "C" void TSDebug(const char *tag, const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(2,3); +extern "C" void TSDebug(const char *tag, const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(2, 3); /** * We forward declare this because if we didn't we end up writing our @@ -96,7 +96,7 @@ extern "C" void TSDebug(const char *tag, const char *fmt, ...) ATSCPPAPI_PRINTFL * * @private */ -extern "C" void TSError(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(1,2); +extern "C" void TSError(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(1, 2); // This is weird, but see the following: // http://stackoverflow.com/questions/5641427/how-to-make-preprocessor-generate-a-string-for-line-keyword @@ -109,9 +109,9 @@ extern "C" void TSError(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(1,2); * via traffic_server -T "tag.*" or since this macro includes the file can you further refine to an * individual file or even a particular line! This can also be enabled via records.config. */ -#define TS_DEBUG(tag, fmt, ...) \ - do { \ - TSDebug(tag "." __FILE__ ":" LINE_NO , "[%s()] " fmt, __FUNCTION__, ## __VA_ARGS__); \ +#define TS_DEBUG(tag, fmt, ...) \ + do { \ + TSDebug(tag "." __FILE__ ":" LINE_NO, "[%s()] " fmt, __FUNCTION__, ##__VA_ARGS__); \ } while (false) /** @@ -119,14 +119,14 @@ extern "C" void TSError(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(1,2); * will also output a DEBUG message visible via traffic_server -T "tag.*", or by enabling the * tag in records.config. */ -#define TS_ERROR(tag, fmt, ...) \ - do { \ - TS_DEBUG(tag, "[ERROR] " fmt, ## __VA_ARGS__); \ - TSError("[%s] [%s:%d, %s()] " fmt, tag, __FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__); \ +#define TS_ERROR(tag, fmt, ...) \ + do { \ + TS_DEBUG(tag, "[ERROR] " fmt, ##__VA_ARGS__); \ + TSError("[%s] [%s:%d, %s()] " fmt, tag, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \ } while (false) -namespace atscppapi { - +namespace atscppapi +{ struct LoggerState; /** @@ -155,17 +155,17 @@ struct LoggerState; * Apply the patch in TS-1813 to correct log rolling in 3.2.x * */ -class Logger : noncopyable { +class Logger : noncopyable +{ public: - /** * The available log levels */ enum LogLevel { LOG_LEVEL_NO_LOG = 128, /**< This log level is used to disable all logging */ - LOG_LEVEL_DEBUG = 1, /**< This log level is used for DEBUG level logging (DEBUG + INFO + ERROR) */ - LOG_LEVEL_INFO = 2, /**< This log level is used for INFO level logging (INFO + ERROR) */ - LOG_LEVEL_ERROR = 4 /**< This log level is used for ERROR level logging (ERROR ONLY) */ + LOG_LEVEL_DEBUG = 1, /**< This log level is used for DEBUG level logging (DEBUG + INFO + ERROR) */ + LOG_LEVEL_INFO = 2, /**< This log level is used for INFO level logging (INFO + ERROR) */ + LOG_LEVEL_ERROR = 4 /**< This log level is used for ERROR level logging (ERROR ONLY) */ }; Logger(); @@ -177,7 +177,8 @@ public: * * @param file The name of the file to create in the logging directory, if you do not specify an extension .log will be used. * @param add_timestamp Prepend a timestamp to the log lines, the default value is true. - * @param rename_file If a file already exists by the same name it will attempt to rename using a scheme that appends .1, .2, and so on, + * @param rename_file If a file already exists by the same name it will attempt to rename using a scheme that appends .1, .2, and + *so on, * the default value for this argument is true. * @param level the default log level to use when creating the logger, this is set to LOG_LEVEL_INFO by default. * @param rolling_enabled if set to true this will enable log rolling on a periodic basis, this is enabled by default. @@ -185,8 +186,8 @@ public: * @return returns true if the logger was successfully created and initialized. * @see LogLevel */ - bool init(const std::string &file, bool add_timestamp = true, bool rename_file = true, - LogLevel level = LOG_LEVEL_INFO, bool rolling_enabled = true, int rolling_interval_seconds = 3600); + bool init(const std::string &file, bool add_timestamp = true, bool rename_file = true, LogLevel level = LOG_LEVEL_INFO, + bool rolling_enabled = true, int rolling_interval_seconds = 3600); /** * Allows you to change the rolling interval in seconds @@ -241,21 +242,22 @@ public: * log.logDebug("Hello you are %d years old", 27); * \endcode */ - void logDebug(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(2,3); + void logDebug(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(2, 3); /** * This method writes an INFO level message to the log file, the LOG_INFO * macro in Logger.h should be used in favor of these when possible because it * will produce a much more rich info message. */ - void logInfo(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(2,3); + void logInfo(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(2, 3); /** * This method writes an ERROR level message to the log file, the LOG_ERROR * macro in Logger.h should be used in favor of these when possible because it * will produce a much more rich error message. */ - void logError(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(2,3); + void logError(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(2, 3); + private: LoggerState *state_; /**< Internal state for the Logger */ }; @@ -263,6 +265,4 @@ private: } /* atscppapi */ - - #endif /* ATSCPPAPI_LOGGER_H_ */
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/Mutex.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Mutex.h b/lib/atscppapi/src/include/atscppapi/Mutex.h index 6044477..5e5f941 100644 --- a/lib/atscppapi/src/include/atscppapi/Mutex.h +++ b/lib/atscppapi/src/include/atscppapi/Mutex.h @@ -29,8 +29,8 @@ #include <atscppapi/noncopyable.h> #include <atscppapi/shared_ptr.h> -namespace atscppapi { - +namespace atscppapi +{ /** * @brief A mutex is mutual exclusion: a blocking lock. * @@ -41,16 +41,18 @@ namespace atscppapi { * @see ScopedSharedMutexLock * @see ScopedSharedMutexTryLock */ -class Mutex: noncopyable { +class Mutex : noncopyable +{ public: - /** * The available types of Mutexes. */ enum Type { TYPE_NORMAL = 0, /**< This type of Mutex will deadlock if locked by a thread already holding the lock */ - TYPE_RECURSIVE, /**< This type of Mutex will allow a thread holding the lock to lock it again; however, it must be unlocked the same number of times */ - TYPE_ERROR_CHECK /**< This type of Mutex will return errno = EDEADLCK if a thread would deadlock by taking the lock after it already holds it */ + TYPE_RECURSIVE, /**< This type of Mutex will allow a thread holding the lock to lock it again; however, it must be unlocked the + same number of times */ + TYPE_ERROR_CHECK /**< This type of Mutex will return errno = EDEADLCK if a thread would deadlock by taking the lock after it + already holds it */ }; /** @@ -59,51 +61,57 @@ public: * @param type The Type of Mutex to create, the default is TYPE_NORMAL. * @see Type */ - Mutex(Type type = TYPE_NORMAL) { + Mutex(Type type = TYPE_NORMAL) + { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); - switch(type) { + switch (type) { case TYPE_RECURSIVE: - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - break; + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + break; case TYPE_ERROR_CHECK: - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); - break; + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); + break; case TYPE_NORMAL: default: - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); - break; + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); + break; } pthread_mutex_init(&mutex, &attr); } - ~Mutex() { - pthread_mutex_destroy(&mutex); - } + ~Mutex() { pthread_mutex_destroy(&mutex); } /** * Try to take the lock, this call will NOT block if the mutex cannot be taken. * @return Returns true if the lock was taken, false if it was not. This call obviously will not block. */ - bool tryLock() { + bool + tryLock() + { return !pthread_mutex_trylock(&mutex); } /** * Block until the lock is taken, when this call returns the thread will be holding the lock. */ - void lock() { + void + lock() + { pthread_mutex_lock(&mutex); } /** * Unlock the lock, this call is nonblocking. */ - void unlock() { + void + unlock() + { pthread_mutex_unlock(&mutex); } + private: pthread_mutex_t mutex; /**< Internal mutex identifier */ }; @@ -116,23 +124,20 @@ private: * * @see Mutex */ -class ScopedMutexLock: noncopyable { +class ScopedMutexLock : noncopyable +{ public: /** * Create the scoped mutex lock, once this object is constructed the lock will be held by the thread. * @param mutex a reference to a Mutex. */ - explicit ScopedMutexLock(Mutex &mutex) : - mutex_(mutex) { - mutex_.lock(); - } + explicit ScopedMutexLock(Mutex &mutex) : mutex_(mutex) { mutex_.lock(); } /** * Unlock the mutex. */ - ~ScopedMutexLock() { - mutex_.unlock(); - } + ~ScopedMutexLock() { mutex_.unlock(); } + private: Mutex &mutex_; }; @@ -145,23 +150,20 @@ private: * * @see Mutex */ -class ScopedSharedMutexLock: noncopyable { +class ScopedSharedMutexLock : noncopyable +{ public: /** * Create the scoped mutex lock, once this object is constructed the lock will be held by the thread. * @param mutex a shared pointer to a Mutex. */ - explicit ScopedSharedMutexLock(shared_ptr<Mutex> mutex) : - mutex_(mutex) { - mutex_->lock(); - } + explicit ScopedSharedMutexLock(shared_ptr<Mutex> mutex) : mutex_(mutex) { mutex_->lock(); } /** * Unlock the mutex. */ - ~ScopedSharedMutexLock() { - mutex_->unlock(); - } + ~ScopedSharedMutexLock() { mutex_->unlock(); } + private: shared_ptr<Mutex> mutex_; }; @@ -174,21 +176,21 @@ private: * * @see Mutex */ -class ScopedMutexTryLock: noncopyable { +class ScopedMutexTryLock : noncopyable +{ public: /** - * Try to create the scoped mutex lock, if you should check hasLock() to determine if this object was successfully able to take the lock. + * Try to create the scoped mutex lock, if you should check hasLock() to determine if this object was successfully able to take + * the lock. * @param mutex a shared pointer to a Mutex. */ - explicit ScopedMutexTryLock(Mutex &mutex) : - mutex_(mutex), has_lock_(false) { - has_lock_ = mutex_.tryLock(); - } + explicit ScopedMutexTryLock(Mutex &mutex) : mutex_(mutex), has_lock_(false) { has_lock_ = mutex_.tryLock(); } /** * Unlock the mutex (if we hold the lock) */ - ~ScopedMutexTryLock() { + ~ScopedMutexTryLock() + { if (has_lock_) { mutex_.unlock(); } @@ -197,9 +199,12 @@ public: /** * @return True if the lock was taken, False if it was not taken. */ - bool hasLock() { + bool + hasLock() + { return has_lock_; } + private: Mutex &mutex_; bool has_lock_; @@ -213,21 +218,21 @@ private: * * @see Mutex */ -class ScopedSharedMutexTryLock: noncopyable { +class ScopedSharedMutexTryLock : noncopyable +{ public: /** - * Try to create the scoped mutex lock, if you should check hasLock() to determine if this object was successfully able to take the lock. + * Try to create the scoped mutex lock, if you should check hasLock() to determine if this object was successfully able to take + * the lock. * @param mutex a shared pointer to a Mutex. */ - explicit ScopedSharedMutexTryLock(shared_ptr<Mutex> mutex) : - mutex_(mutex), has_lock_(false) { - has_lock_ = mutex_->tryLock(); - } + explicit ScopedSharedMutexTryLock(shared_ptr<Mutex> mutex) : mutex_(mutex), has_lock_(false) { has_lock_ = mutex_->tryLock(); } /** * Unlock the mutex (if we hold the lock) */ - ~ScopedSharedMutexTryLock() { + ~ScopedSharedMutexTryLock() + { if (has_lock_) { mutex_->unlock(); } @@ -236,9 +241,12 @@ public: /** * @return True if the lock was taken, False if it was not taken. */ - bool hasLock() { + bool + hasLock() + { return has_lock_; } + private: shared_ptr<Mutex> mutex_; bool has_lock_; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/Plugin.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Plugin.h b/lib/atscppapi/src/include/atscppapi/Plugin.h index ce1d943..1800ea5 100644 --- a/lib/atscppapi/src/include/atscppapi/Plugin.h +++ b/lib/atscppapi/src/include/atscppapi/Plugin.h @@ -30,8 +30,8 @@ #include <atscppapi/Transaction.h> #include <atscppapi/noncopyable.h> -namespace atscppapi { - +namespace atscppapi +{ /** * @brief The base interface used when creating a Plugin. * @@ -42,7 +42,8 @@ namespace atscppapi { * @see GlobalPlugin * @see TransformationPlugin */ -class Plugin: noncopyable { +class Plugin : noncopyable +{ public: /** * A enumeration of the available types of Hooks. These are used with GlobalPlugin::registerHook() @@ -50,68 +51,109 @@ public: */ enum HookType { HOOK_READ_REQUEST_HEADERS_PRE_REMAP = 0, /**< This hook will be fired before remap has occured. */ - HOOK_READ_REQUEST_HEADERS_POST_REMAP, /**< This hook will be fired directly after remap has occured. */ - HOOK_SEND_REQUEST_HEADERS, /**< This hook will be fired right before request headers are sent to the origin */ + HOOK_READ_REQUEST_HEADERS_POST_REMAP, /**< This hook will be fired directly after remap has occured. */ + HOOK_SEND_REQUEST_HEADERS, /**< This hook will be fired right before request headers are sent to the origin */ HOOK_READ_RESPONSE_HEADERS, /**< This hook will be fired right after response headers have been read from the origin */ HOOK_SEND_RESPONSE_HEADERS, /**< This hook will be fired right before the response headers are sent to the client */ - HOOK_OS_DNS, /**< This hook will be fired right after the OS DNS lookup */ - HOOK_READ_REQUEST_HEADERS, /**< This hook will be fired after the request is read. */ - HOOK_READ_CACHE_HEADERS, /**< This hook will be fired after the CACHE hdrs. */ + HOOK_OS_DNS, /**< This hook will be fired right after the OS DNS lookup */ + HOOK_READ_REQUEST_HEADERS, /**< This hook will be fired after the request is read. */ + HOOK_READ_CACHE_HEADERS, /**< This hook will be fired after the CACHE hdrs. */ HOOK_CACHE_LOOKUP_COMPLETE, /**< This hook will be fired after caceh lookup complete. */ - HOOK_SELECT_ALT /**< This hook will be fired after select alt. */ + HOOK_SELECT_ALT /**< This hook will be fired after select alt. */ }; /** * This method must be implemented when you hook HOOK_READ_REQUEST_HEADERS_PRE_REMAP */ - virtual void handleReadRequestHeadersPreRemap(Transaction &transaction) { transaction.resume(); }; + virtual void + handleReadRequestHeadersPreRemap(Transaction &transaction) + { + transaction.resume(); + }; /** * This method must be implemented when you hook HOOK_READ_REQUEST_HEADERS_POST_REMAP */ - virtual void handleReadRequestHeadersPostRemap(Transaction &transaction) { transaction.resume(); }; + virtual void + handleReadRequestHeadersPostRemap(Transaction &transaction) + { + transaction.resume(); + }; /** * This method must be implemented when you hook HOOK_SEND_REQUEST_HEADERS */ - virtual void handleSendRequestHeaders(Transaction &transaction) { transaction.resume(); }; + virtual void + handleSendRequestHeaders(Transaction &transaction) + { + transaction.resume(); + }; /** * This method must be implemented when you hook HOOK_READ_RESPONSE_HEADERS */ - virtual void handleReadResponseHeaders(Transaction &transaction) { transaction.resume(); }; + virtual void + handleReadResponseHeaders(Transaction &transaction) + { + transaction.resume(); + }; /** * This method must be implemented when you hook HOOK_SEND_RESPONSE_HEADERS */ - virtual void handleSendResponseHeaders(Transaction &transaction) { transaction.resume(); }; + virtual void + handleSendResponseHeaders(Transaction &transaction) + { + transaction.resume(); + }; /** * This method must be implemented when you hook HOOK_OS_DNS */ - virtual void handleOsDns(Transaction &transaction) { transaction.resume(); }; + virtual void + handleOsDns(Transaction &transaction) + { + transaction.resume(); + }; /** * This method must be implemented when you hook HOOK_READ_REQUEST_HEADERS */ - virtual void handleReadRequestHeaders(Transaction &transaction) { transaction.resume(); }; + virtual void + handleReadRequestHeaders(Transaction &transaction) + { + transaction.resume(); + }; /** * This method must be implemented when you hook HOOK_READ_CACHE_HEADERS */ - virtual void handleReadCacheHeaders(Transaction &transaction) { transaction.resume(); }; + virtual void + handleReadCacheHeaders(Transaction &transaction) + { + transaction.resume(); + }; /** * This method must be implemented when you hook HOOK_CACHE_LOOKUP_COMPLETE */ - virtual void handleReadCacheLookupComplete(Transaction &transaction) { transaction.resume(); }; + virtual void + handleReadCacheLookupComplete(Transaction &transaction) + { + transaction.resume(); + }; /** * This method must be implemented when you hook HOOK_SELECT_ALT */ - virtual void handleSelectAlt(Transaction &transaction) { transaction.resume(); }; + virtual void + handleSelectAlt(Transaction &transaction) + { + transaction.resume(); + }; + + virtual ~Plugin(){}; - virtual ~Plugin() { }; protected: /** * \note This interface can never be implemented directly, it should be implemented @@ -119,7 +161,7 @@ protected: * * @private */ - Plugin() { }; + Plugin(){}; }; /**< Human readable strings for each HookType, you can access them as HOOK_TYPE_STRINGS[HOOK_OS_DNS] for example. */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/PluginInit.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/PluginInit.h b/lib/atscppapi/src/include/atscppapi/PluginInit.h index 5a4ffb3..a1249b8 100644 --- a/lib/atscppapi/src/include/atscppapi/PluginInit.h +++ b/lib/atscppapi/src/include/atscppapi/PluginInit.h @@ -37,7 +37,10 @@ extern "C" { */ void TSPluginInit(int argc, const char *argv[]); -enum TsReturnCode { TS_ERROR = -1, TS_SUCCESS = 0 }; +enum TsReturnCode { + TS_ERROR = -1, + TS_SUCCESS = 0, +}; /** * Invoked for remap plugins - listed in remap.config. The arguments provided as @pparam @@ -50,7 +53,6 @@ enum TsReturnCode { TS_ERROR = -1, TS_SUCCESS = 0 }; * @param errbuf_size Not used */ TsReturnCode TSRemapNewInstance(int argc, char *argv[], void **instance_handle, char *errbuf, int errbuf_size); - } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/RemapPlugin.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/RemapPlugin.h b/lib/atscppapi/src/include/atscppapi/RemapPlugin.h index 3f44f78..5edf8ab 100644 --- a/lib/atscppapi/src/include/atscppapi/RemapPlugin.h +++ b/lib/atscppapi/src/include/atscppapi/RemapPlugin.h @@ -28,12 +28,13 @@ #include "atscppapi/Url.h" #include "atscppapi/utils.h" -namespace atscppapi { - +namespace atscppapi +{ /** * @brief Base class that remap plugins should extend. */ -class RemapPlugin { +class RemapPlugin +{ public: /** * Constructor @@ -42,8 +43,13 @@ public: */ RemapPlugin(void **instance_handle); - enum Result { RESULT_ERROR = 0, RESULT_NO_REMAP, RESULT_DID_REMAP, RESULT_NO_REMAP_STOP, - RESULT_DID_REMAP_STOP }; + enum Result { + RESULT_ERROR = 0, + RESULT_NO_REMAP, + RESULT_DID_REMAP, + RESULT_NO_REMAP_STOP, + RESULT_DID_REMAP_STOP, + }; /** * Invoked when a request matches the remap.config line - implementation should perform the @@ -57,14 +63,15 @@ public: * * @return Result of the remap - will dictate futher processing by the system. */ - virtual Result doRemap(const Url &map_from_url ATSCPPAPI_UNUSED, const Url &map_to_url ATSCPPAPI_UNUSED, Transaction &transaction ATSCPPAPI_UNUSED, - bool &redirect ATSCPPAPI_UNUSED) { + virtual Result + doRemap(const Url &map_from_url ATSCPPAPI_UNUSED, const Url &map_to_url ATSCPPAPI_UNUSED, + Transaction &transaction ATSCPPAPI_UNUSED, bool &redirect ATSCPPAPI_UNUSED) + { return RESULT_NO_REMAP; } - virtual ~RemapPlugin() { } + virtual ~RemapPlugin() {} }; - } #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/Request.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Request.h b/lib/atscppapi/src/include/atscppapi/Request.h index f2aa1bb..bfe1b0a 100644 --- a/lib/atscppapi/src/include/atscppapi/Request.h +++ b/lib/atscppapi/src/include/atscppapi/Request.h @@ -29,15 +29,16 @@ #include <atscppapi/Url.h> #include <atscppapi/noncopyable.h> -namespace atscppapi { - +namespace atscppapi +{ class Transaction; struct RequestState; /** * @brief Encapsulates a request. */ -class Request: noncopyable { +class Request : noncopyable +{ public: Request(); @@ -59,6 +60,7 @@ public: Headers &getHeaders() const; ~Request(); + private: Request(void *hdr_buf, void *hdr_loc); RequestState *state_; @@ -66,7 +68,6 @@ private: friend class Transaction; friend class ClientRequest; }; - } #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/Response.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Response.h b/lib/atscppapi/src/include/atscppapi/Response.h index c6c68f8..5b8582d 100644 --- a/lib/atscppapi/src/include/atscppapi/Response.h +++ b/lib/atscppapi/src/include/atscppapi/Response.h @@ -27,16 +27,20 @@ #include <atscppapi/HttpVersion.h> #include <atscppapi/HttpStatus.h> -namespace atscppapi { - +namespace atscppapi +{ // forward declarations struct ResponseState; -namespace utils { class internal; } +namespace utils +{ + class internal; +} /** * @brief Encapsulates a response. */ -class Response: noncopyable { +class Response : noncopyable +{ public: Response(); @@ -59,13 +63,13 @@ public: Headers &getHeaders() const; ~Response(); + private: ResponseState *state_; void init(void *hdr_buf, void *hdr_loc); friend class Transaction; friend class utils::internal; }; - } #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/Stat.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Stat.h b/lib/atscppapi/src/include/atscppapi/Stat.h index d665d1a..9789173 100644 --- a/lib/atscppapi/src/include/atscppapi/Stat.h +++ b/lib/atscppapi/src/include/atscppapi/Stat.h @@ -27,8 +27,8 @@ #include <stdint.h> #include <string> -namespace atscppapi { - +namespace atscppapi +{ /** * @brief A Stat is an atomic variable that can be used to store counters, averages, time averages, or summations. * @@ -46,16 +46,17 @@ namespace atscppapi { * * A full example is available in examples/stat_example/. */ -class Stat : noncopyable { +class Stat : noncopyable +{ public: /** * The available Stat types. */ enum SyncType { SYNC_SUM = 0, /**< The stat will sum all values from a stat.inc(VAL) */ - SYNC_COUNT, /**< The stat will count all calls to stat.inc(VAL) */ - SYNC_AVG, /**< The stat will keep an average after call calls to stat.inc(VAL) */ - SYNC_TIMEAVG /**< The stat will keep a time average of all calls to stat.inc(VAL) */ + SYNC_COUNT, /**< The stat will count all calls to stat.inc(VAL) */ + SYNC_AVG, /**< The stat will keep an average after call calls to stat.inc(VAL) */ + SYNC_TIMEAVG /**< The stat will keep a time average of all calls to stat.inc(VAL) */ }; Stat(); @@ -96,6 +97,7 @@ public: * @param value the value to set the stat to. */ void set(int64_t value); + private: int stat_id_; /**< The internal stat ID */ }; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/Transaction.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Transaction.h b/lib/atscppapi/src/include/atscppapi/Transaction.h index dbf18b8..a0d7bf7 100644 --- a/lib/atscppapi/src/include/atscppapi/Transaction.h +++ b/lib/atscppapi/src/include/atscppapi/Transaction.h @@ -31,12 +31,15 @@ #include "atscppapi/ClientRequest.h" #include "atscppapi/Response.h" -namespace atscppapi { - +namespace atscppapi +{ // forward declarations class TransactionPlugin; struct TransactionState; -namespace utils { class internal; } +namespace utils +{ + class internal; +} /** * @brief Transactions are the object containing all the state related to a HTTP Transaction @@ -45,7 +48,8 @@ namespace utils { class internal; } * created and destroyed as they are needed. Transactions should never be saved beyond the * scope of the function in which they are delivered otherwise undefined behaviour will result. */ -class Transaction: noncopyable { +class Transaction : noncopyable +{ public: /** * @brief ContextValues are a mechanism to share data between plugins using the atscppapi. @@ -71,9 +75,10 @@ public: * take shared pointers you dont have to worry about the cleanup as that will happen automatically so long * as you dont have shared_ptrs that cannot go out of scope. */ - class ContextValue { + class ContextValue + { public: - virtual ~ContextValue() { } + virtual ~ContextValue() {} }; ~Transaction(); @@ -234,10 +239,10 @@ public: * The available types of timeouts you can set on a Transaction. */ enum TimeoutType { - TIMEOUT_DNS = 0, /**< Timeout on DNS */ - TIMEOUT_CONNECT, /**< Timeout on Connect */ + TIMEOUT_DNS = 0, /**< Timeout on DNS */ + TIMEOUT_CONNECT, /**< Timeout on Connect */ TIMEOUT_NO_ACTIVITY, /**< Timeout on No Activity */ - TIMEOUT_ACTIVE /**< Timeout with Activity */ + TIMEOUT_ACTIVE /**< Timeout with Activity */ }; /** @@ -301,11 +306,11 @@ public: /** * Redirect the transaction a different @a url. */ - void redirectTo(std::string const& url); + void redirectTo(std::string const &url); private: - TransactionState *state_; //!< The internal TransactionState object tied to the current Transaction - friend class TransactionPlugin; //!< TransactionPlugin is a friend so it can call addPlugin() + TransactionState *state_; //!< The internal TransactionState object tied to the current Transaction + friend class TransactionPlugin; //!< TransactionPlugin is a friend so it can call addPlugin() friend class TransformationPlugin; //!< TransformationPlugin is a friend so it can call addPlugin() /** http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/TransactionPlugin.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/TransactionPlugin.h b/lib/atscppapi/src/include/atscppapi/TransactionPlugin.h index 3987927..e2ee048 100644 --- a/lib/atscppapi/src/include/atscppapi/TransactionPlugin.h +++ b/lib/atscppapi/src/include/atscppapi/TransactionPlugin.h @@ -29,10 +29,11 @@ #include <atscppapi/shared_ptr.h> #include <atscppapi/Mutex.h> -namespace atscppapi { - -namespace utils { - class internal; +namespace atscppapi +{ +namespace utils +{ + class internal; } /* utils */ /** @@ -76,7 +77,8 @@ struct TransactionPluginState; * @see Plugin * @see HookType */ -class TransactionPlugin : public Plugin { +class TransactionPlugin : public Plugin +{ public: /** * registerHook is the mechanism used to attach a transaction hook. @@ -91,6 +93,7 @@ public: */ void registerHook(Plugin::HookType hook_type); virtual ~TransactionPlugin(); + protected: TransactionPlugin(Transaction &transaction); @@ -102,6 +105,7 @@ protected: * TransactionPlugin. */ shared_ptr<Mutex> getMutex(); + private: TransactionPluginState *state_; /**< The internal state for a TransactionPlugin */ friend class utils::internal; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/TransformationPlugin.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/TransformationPlugin.h b/lib/atscppapi/src/include/atscppapi/TransformationPlugin.h index 4c617f7..9295053 100644 --- a/lib/atscppapi/src/include/atscppapi/TransformationPlugin.h +++ b/lib/atscppapi/src/include/atscppapi/TransformationPlugin.h @@ -28,8 +28,8 @@ #include <atscppapi/Transaction.h> #include <atscppapi/TransactionPlugin.h> -namespace atscppapi { - +namespace atscppapi +{ struct TransformationPluginState; /** @@ -78,14 +78,15 @@ struct TransformationPluginState; * @see Type * @see HookType */ -class TransformationPlugin : public TransactionPlugin { +class TransformationPlugin : public TransactionPlugin +{ public: /** * The available types of Transformations. */ enum Type { REQUEST_TRANSFORMATION = 0, /**< Transform the Request body content */ - RESPONSE_TRANSFORMATION /**< Transform the Response body content */ + RESPONSE_TRANSFORMATION /**< Transform the Response body content */ }; /** @@ -102,7 +103,6 @@ public: virtual ~TransformationPlugin(); /**< Destructor for a TransformationPlugin */ protected: - /** * This method is how a TransformationPlugin will produce output for the downstream * transformation plugin, if you need to produce binary data this can still be @@ -119,6 +119,7 @@ protected: /** a TransformationPlugin must implement this interface, it cannot be constructed directly */ TransformationPlugin(Transaction &transaction, Type type); + private: TransformationPluginState *state_; /** Internal state for a TransformationPlugin */ size_t doProduce(const std::string &); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/Url.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Url.h b/lib/atscppapi/src/include/atscppapi/Url.h index 1feadf8..502b80d 100644 --- a/lib/atscppapi/src/include/atscppapi/Url.h +++ b/lib/atscppapi/src/include/atscppapi/Url.h @@ -27,8 +27,8 @@ #include <stdint.h> #include <atscppapi/noncopyable.h> -namespace atscppapi { - +namespace atscppapi +{ struct UrlState; /** @@ -42,7 +42,8 @@ struct UrlState; * and it can be retrieved via Request::getUrl(). A full example of this * is available in examples/detachedrequest/. */ -class Url: noncopyable { +class Url : noncopyable +{ public: /** * @warning Url objects should never be constructed by the user. @@ -135,6 +136,7 @@ public: * \note This method should rarely be used. */ void reset(); + private: bool isInitialized() const; void init(void *hdr_buf, void *url_loc); @@ -143,7 +145,6 @@ private: friend class ClientRequest; friend class RemapPlugin; }; - } #endif /* ATSCPPAPI_URL_H_ */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/noncopyable.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/noncopyable.h b/lib/atscppapi/src/include/atscppapi/noncopyable.h index 6c1c5f4..620bd25 100644 --- a/lib/atscppapi/src/include/atscppapi/noncopyable.h +++ b/lib/atscppapi/src/include/atscppapi/noncopyable.h @@ -26,8 +26,8 @@ #ifndef ATSCPPAPI_NONCOPYABLE_H_ #define ATSCPPAPI_NONCOPYABLE_H_ -namespace atscppapi { - +namespace atscppapi +{ /** * @brief noncopyable is a base class that will prevent derived classes from being copied. * @@ -53,9 +53,10 @@ class noncopyable protected: noncopyable() {} ~noncopyable() {} + private: - noncopyable(const noncopyable&); - const noncopyable& operator=(const noncopyable&); + noncopyable(const noncopyable &); + const noncopyable &operator=(const noncopyable &); }; } /* atscppapi */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/shared_ptr.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/shared_ptr.h b/lib/atscppapi/src/include/atscppapi/shared_ptr.h index 6fa9571..9d17a87 100644 --- a/lib/atscppapi/src/include/atscppapi/shared_ptr.h +++ b/lib/atscppapi/src/include/atscppapi/shared_ptr.h @@ -28,22 +28,22 @@ #include "ink_autoconf.h" #if HAVE_STD_SHARED_PTR -# include <memory> +#include <memory> #else -# include <tr1/memory> +#include <tr1/memory> #endif -namespace atscppapi { - +namespace atscppapi +{ /** * Force the use of std::tr1::shared_ptr * \todo Consider adding a simple macro to check if c++0x/11 is enabled * and if so change it to std::shared_ptr and #include <memory>s */ #if HAVE_STD_SHARED_PTR - using std::shared_ptr; +using std::shared_ptr; #else - using std::tr1::shared_ptr; +using std::tr1::shared_ptr; #endif } /* atscppapi */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/atscppapi/utils.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/utils.h b/lib/atscppapi/src/include/atscppapi/utils.h index 8c91c1d..b1e44f3 100644 --- a/lib/atscppapi/src/include/atscppapi/utils.h +++ b/lib/atscppapi/src/include/atscppapi/utils.h @@ -33,39 +33,39 @@ #ifndef ATSCPPAPI_UNUSED #ifdef __GNUC__ -#define ATSCPPAPI_UNUSED __attribute__ ((unused)) +#define ATSCPPAPI_UNUSED __attribute__((unused)) #else #define ATSCPPAPI_UNUSED #endif #endif -namespace atscppapi { -namespace utils { +namespace atscppapi +{ +namespace utils +{ + /** + * @brief Returns a pretty printed string of a sockaddr * + * + * @param sockaddr* A pointer to a sockaddr * + * @return a string which is the pretty printed address + */ + std::string getIpString(const sockaddr *); -/** - * @brief Returns a pretty printed string of a sockaddr * - * - * @param sockaddr* A pointer to a sockaddr * - * @return a string which is the pretty printed address - */ -std::string getIpString(const sockaddr *); - -/** - * @brief Returns just the port portion of the sockaddr * - * - * @param sockaddr* A pointer to a sockaddr * - * @return a uint16_t which is the port from the sockaddr * - */ -uint16_t getPort(const sockaddr *); - -/** - * @brief Returns a pretty printed string of a sockaddr * including port - * - * @param sockaddr* A pointer to a sockaddr * - * @return a string which is the pretty printed address including port - */ -std::string getIpPortString(const sockaddr *); + /** + * @brief Returns just the port portion of the sockaddr * + * + * @param sockaddr* A pointer to a sockaddr * + * @return a uint16_t which is the port from the sockaddr * + */ + uint16_t getPort(const sockaddr *); + /** + * @brief Returns a pretty printed string of a sockaddr * including port + * + * @param sockaddr* A pointer to a sockaddr * + * @return a string which is the pretty printed address including port + */ + std::string getIpPortString(const sockaddr *); } } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/logging_internal.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/logging_internal.h b/lib/atscppapi/src/include/logging_internal.h index 7a6ac27..3b1dd72 100644 --- a/lib/atscppapi/src/include/logging_internal.h +++ b/lib/atscppapi/src/include/logging_internal.h @@ -38,7 +38,7 @@ #undef LOG_ERROR #endif -#define LOG_DEBUG(fmt, ...) TS_DEBUG("atscppapi", fmt, ## __VA_ARGS__) -#define LOG_ERROR(fmt, ...) TS_ERROR("atscppapi", fmt, ## __VA_ARGS__) +#define LOG_DEBUG(fmt, ...) TS_DEBUG("atscppapi", fmt, ##__VA_ARGS__) +#define LOG_ERROR(fmt, ...) TS_ERROR("atscppapi", fmt, ##__VA_ARGS__) #endif /* ATSCPPAPI_LOGGING_INTERNAL_H_ */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/include/utils_internal.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/utils_internal.h b/lib/atscppapi/src/include/utils_internal.h index 7cef956..c08636e 100644 --- a/lib/atscppapi/src/include/utils_internal.h +++ b/lib/atscppapi/src/include/utils_internal.h @@ -39,61 +39,77 @@ #include "atscppapi/Transaction.h" #include "atscppapi/InterceptPlugin.h" -namespace atscppapi { - -namespace utils { - -/** - * @private - */ -class internal { -public: - static TSHttpHookID convertInternalHookToTsHook(Plugin::HookType); - static TSHttpHookID convertInternalTransformationTypeToTsHook(TransformationPlugin::Type type); - static void invokePluginForEvent(TransactionPlugin *, TSHttpTxn, TSEvent); - static void invokePluginForEvent(GlobalPlugin *, TSHttpTxn, TSEvent); - static HttpVersion getHttpVersion(TSMBuffer hdr_buf, TSMLoc hdr_loc); - static void initTransactionManagement(); - static std::string consumeFromTSIOBufferReader(TSIOBufferReader); - static shared_ptr<Mutex> getTransactionPluginMutex(TransactionPlugin &); - static Transaction &getTransaction(TSHttpTxn); - - static AsyncHttpFetchState *getAsyncHttpFetchState(AsyncHttpFetch &async_http_fetch) { - return async_http_fetch.state_; - } - - static void initResponse(Response &response, TSMBuffer hdr_buf, TSMLoc hdr_loc) { - response.init(hdr_buf, hdr_loc); - } - - static void initTransactionServerRequest(Transaction &transaction) { - transaction.initServerRequest(); - } - - static void initTransactionServerResponse(Transaction &transaction) { - transaction.initServerResponse(); - } - - static void initTransactionClientResponse(Transaction &transaction) { - transaction.initClientResponse(); - } - - static const std::list<TransactionPlugin *> &getTransactionPlugins(const Transaction &transaction) { - return transaction.getPlugins(); - } - - static void dispatchInterceptEvent(InterceptPlugin *plugin, TSEvent event, void *edata) { - plugin->handleEvent(static_cast<int>(event), edata); - } - - static void deleteAsyncHttpFetch(AsyncHttpFetch *fetch) { - delete fetch; - } - -}; /* internal */ +namespace atscppapi +{ +namespace utils +{ + /** + * @private + */ + class internal + { + public: + static TSHttpHookID convertInternalHookToTsHook(Plugin::HookType); + static TSHttpHookID convertInternalTransformationTypeToTsHook(TransformationPlugin::Type type); + static void invokePluginForEvent(TransactionPlugin *, TSHttpTxn, TSEvent); + static void invokePluginForEvent(GlobalPlugin *, TSHttpTxn, TSEvent); + static HttpVersion getHttpVersion(TSMBuffer hdr_buf, TSMLoc hdr_loc); + static void initTransactionManagement(); + static std::string consumeFromTSIOBufferReader(TSIOBufferReader); + static shared_ptr<Mutex> getTransactionPluginMutex(TransactionPlugin &); + static Transaction &getTransaction(TSHttpTxn); + + static AsyncHttpFetchState * + getAsyncHttpFetchState(AsyncHttpFetch &async_http_fetch) + { + return async_http_fetch.state_; + } + + static void + initResponse(Response &response, TSMBuffer hdr_buf, TSMLoc hdr_loc) + { + response.init(hdr_buf, hdr_loc); + } + + static void + initTransactionServerRequest(Transaction &transaction) + { + transaction.initServerRequest(); + } + + static void + initTransactionServerResponse(Transaction &transaction) + { + transaction.initServerResponse(); + } + + static void + initTransactionClientResponse(Transaction &transaction) + { + transaction.initClientResponse(); + } + + static const std::list<TransactionPlugin *> & + getTransactionPlugins(const Transaction &transaction) + { + return transaction.getPlugins(); + } + + static void + dispatchInterceptEvent(InterceptPlugin *plugin, TSEvent event, void *edata) + { + plugin->handleEvent(static_cast<int>(event), edata); + } + + static void + deleteAsyncHttpFetch(AsyncHttpFetch *fetch) + { + delete fetch; + } + + }; /* internal */ } /* utils */ - } #endif /* ATSCPPAPI_ATSUTILS_H_ */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/utils.cc ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/utils.cc b/lib/atscppapi/src/utils.cc index 7608281..8ccd5ec 100644 --- a/lib/atscppapi/src/utils.cc +++ b/lib/atscppapi/src/utils.cc @@ -26,20 +26,22 @@ #include <ts/ts.h> #include "logging_internal.h" -std::string atscppapi::utils::getIpString(const sockaddr *sockaddress) { +std::string +atscppapi::utils::getIpString(const sockaddr *sockaddress) +{ if (sockaddress == NULL) { LOG_ERROR("Cannot work on NULL sockaddress"); - return std::string(); + return std::string(); } char buf[INET6_ADDRSTRLEN]; switch (sockaddress->sa_family) { case AF_INET: - inet_ntop(AF_INET, &(((struct sockaddr_in *) sockaddress)->sin_addr), buf, INET_ADDRSTRLEN); + inet_ntop(AF_INET, &(((struct sockaddr_in *)sockaddress)->sin_addr), buf, INET_ADDRSTRLEN); return std::string(buf); case AF_INET6: - inet_ntop(AF_INET6, &(((struct sockaddr_in6 *) sockaddress)->sin6_addr), buf, INET6_ADDRSTRLEN); + inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sockaddress)->sin6_addr), buf, INET6_ADDRSTRLEN); return std::string(buf); default: LOG_ERROR("Unknown Address Family %d", static_cast<int>(sockaddress->sa_family)); @@ -47,23 +49,27 @@ std::string atscppapi::utils::getIpString(const sockaddr *sockaddress) { } } -uint16_t atscppapi::utils::getPort(const sockaddr *sockaddress) { +uint16_t +atscppapi::utils::getPort(const sockaddr *sockaddress) +{ if (sockaddress == NULL) { LOG_ERROR("Cannot work on NULL sockaddress"); return 0; } if (sockaddress->sa_family == AF_INET) { - return ntohs((((struct sockaddr_in*) sockaddress)->sin_port)); + return ntohs((((struct sockaddr_in *)sockaddress)->sin_port)); } else if (sockaddress->sa_family == AF_INET6) { - return ntohs((((struct sockaddr_in6*) sockaddress)->sin6_port)); + return ntohs((((struct sockaddr_in6 *)sockaddress)->sin6_port)); } else { LOG_ERROR("Unknown Address Family %d", static_cast<int>(sockaddress->sa_family)); return 0; } } -std::string atscppapi::utils::getIpPortString(const sockaddr *sockaddress) { +std::string +atscppapi::utils::getIpPortString(const sockaddr *sockaddress) +{ if (sockaddress == NULL) { LOG_ERROR("Cannot work on NULL sockaddress"); return std::string(); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/atscppapi/src/utils_internal.cc ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/utils_internal.cc b/lib/atscppapi/src/utils_internal.cc index 12538c7..a62e1b8 100644 --- a/lib/atscppapi/src/utils_internal.cc +++ b/lib/atscppapi/src/utils_internal.cc @@ -36,19 +36,21 @@ using namespace atscppapi; -namespace { - +namespace +{ // This is the highest txn arg that can be used, we choose this // value to minimize the likelihood of it causing any problems. const int MAX_TXN_ARG = 15; const int TRANSACTION_STORAGE_INDEX = MAX_TXN_ARG; -int handleTransactionEvents(TSCont cont, TSEvent event, void *edata) { +int +handleTransactionEvents(TSCont cont, TSEvent event, void *edata) +{ // This function is only here to clean up Transaction objects TSHttpTxn ats_txn_handle = static_cast<TSHttpTxn>(edata); Transaction &transaction = utils::internal::getTransaction(ats_txn_handle); - LOG_DEBUG("Got event %d on continuation %p for transaction (ats pointer %p, object %p)", event, cont, - ats_txn_handle, &transaction); + LOG_DEBUG("Got event %d on continuation %p for transaction (ats pointer %p, object %p)", event, cont, ats_txn_handle, + &transaction); switch (event) { case TS_EVENT_HTTP_POST_REMAP: @@ -56,7 +58,7 @@ int handleTransactionEvents(TSCont cont, TSEvent event, void *edata) { // This is here to force a refresh of the cached client request url TSMBuffer hdr_buf; TSMLoc hdr_loc; - (void) TSHttpTxnClientReqGet(static_cast<TSHttpTxn>(transaction.getAtsHandle()), &hdr_buf, &hdr_loc); + (void)TSHttpTxnClientReqGet(static_cast<TSHttpTxn>(transaction.getAtsHandle()), &hdr_buf, &hdr_loc); break; case TS_EVENT_HTTP_SEND_REQUEST_HDR: utils::internal::initTransactionServerRequest(transaction); @@ -67,21 +69,18 @@ int handleTransactionEvents(TSCont cont, TSEvent event, void *edata) { case TS_EVENT_HTTP_SEND_RESPONSE_HDR: utils::internal::initTransactionClientResponse(transaction); break; - case TS_EVENT_HTTP_TXN_CLOSE: - { // opening scope to declare plugins variable below - const std::list<TransactionPlugin *> &plugins = utils::internal::getTransactionPlugins(transaction); - for (std::list<TransactionPlugin *>::const_iterator iter = plugins.begin(), end = plugins.end(); - iter != end; ++iter) { - shared_ptr<Mutex> trans_mutex = utils::internal::getTransactionPluginMutex(**iter); - LOG_DEBUG("Locking TransacitonPlugin mutex to delete transaction plugin at %p", *iter); - trans_mutex->lock(); - LOG_DEBUG("Locked Mutex...Deleting transaction plugin at %p", *iter); - delete *iter; - trans_mutex->unlock(); - } - delete &transaction; + case TS_EVENT_HTTP_TXN_CLOSE: { // opening scope to declare plugins variable below + const std::list<TransactionPlugin *> &plugins = utils::internal::getTransactionPlugins(transaction); + for (std::list<TransactionPlugin *>::const_iterator iter = plugins.begin(), end = plugins.end(); iter != end; ++iter) { + shared_ptr<Mutex> trans_mutex = utils::internal::getTransactionPluginMutex(**iter); + LOG_DEBUG("Locking TransacitonPlugin mutex to delete transaction plugin at %p", *iter); + trans_mutex->lock(); + LOG_DEBUG("Locked Mutex...Deleting transaction plugin at %p", *iter); + delete *iter; + trans_mutex->unlock(); } - break; + delete &transaction; + } break; default: assert(false); /* we should never get here */ break; @@ -90,7 +89,9 @@ int handleTransactionEvents(TSCont cont, TSEvent event, void *edata) { return 0; } -void setupTransactionManagement() { +void +setupTransactionManagement() +{ // We must always have a cleanup handler available TSMutex mutex = NULL; TSCont cont = TSContCreate(handleTransactionEvents, mutex); @@ -101,7 +102,8 @@ void setupTransactionManagement() { TSHttpHookAdd(TS_HTTP_TXN_CLOSE_HOOK, cont); } -void inline invokePluginForEvent(Plugin *plugin, TSHttpTxn ats_txn_handle, TSEvent event) { +void inline invokePluginForEvent(Plugin *plugin, TSHttpTxn ats_txn_handle, TSEvent event) +{ Transaction &transaction = utils::internal::getTransaction(ats_txn_handle); switch (event) { case TS_EVENT_HTTP_PRE_REMAP: @@ -143,7 +145,9 @@ void inline invokePluginForEvent(Plugin *plugin, TSHttpTxn ats_txn_handle, TSEve } /* anonymous namespace */ -Transaction &utils::internal::getTransaction(TSHttpTxn ats_txn_handle) { +Transaction & +utils::internal::getTransaction(TSHttpTxn ats_txn_handle) +{ Transaction *transaction = static_cast<Transaction *>(TSHttpTxnArgGet(ats_txn_handle, TRANSACTION_STORAGE_INDEX)); if (!transaction) { transaction = new Transaction(static_cast<void *>(ats_txn_handle)); @@ -153,11 +157,15 @@ Transaction &utils::internal::getTransaction(TSHttpTxn ats_txn_handle) { return *transaction; } -shared_ptr<Mutex> utils::internal::getTransactionPluginMutex(TransactionPlugin &transaction_plugin) { +shared_ptr<Mutex> +utils::internal::getTransactionPluginMutex(TransactionPlugin &transaction_plugin) +{ return transaction_plugin.getMutex(); } -TSHttpHookID utils::internal::convertInternalHookToTsHook(Plugin::HookType hooktype) { +TSHttpHookID +utils::internal::convertInternalHookToTsHook(Plugin::HookType hooktype) +{ switch (hooktype) { case Plugin::HOOK_READ_REQUEST_HEADERS_POST_REMAP: return TS_HTTP_POST_REMAP_HOOK; @@ -186,29 +194,37 @@ TSHttpHookID utils::internal::convertInternalHookToTsHook(Plugin::HookType hookt return static_cast<TSHttpHookID>(-1); } -TSHttpHookID utils::internal::convertInternalTransformationTypeToTsHook(TransformationPlugin::Type type) { +TSHttpHookID +utils::internal::convertInternalTransformationTypeToTsHook(TransformationPlugin::Type type) +{ switch (type) { - case TransformationPlugin::RESPONSE_TRANSFORMATION: - return TS_HTTP_RESPONSE_TRANSFORM_HOOK; - case TransformationPlugin::REQUEST_TRANSFORMATION: - return TS_HTTP_REQUEST_TRANSFORM_HOOK; - default: - assert(false); // shouldn't happen, let's catch it early - break; + case TransformationPlugin::RESPONSE_TRANSFORMATION: + return TS_HTTP_RESPONSE_TRANSFORM_HOOK; + case TransformationPlugin::REQUEST_TRANSFORMATION: + return TS_HTTP_REQUEST_TRANSFORM_HOOK; + default: + assert(false); // shouldn't happen, let's catch it early + break; } return static_cast<TSHttpHookID>(-1); } -void utils::internal::invokePluginForEvent(TransactionPlugin *plugin, TSHttpTxn ats_txn_handle, TSEvent event) { +void +utils::internal::invokePluginForEvent(TransactionPlugin *plugin, TSHttpTxn ats_txn_handle, TSEvent event) +{ ScopedSharedMutexLock scopedLock(plugin->getMutex()); ::invokePluginForEvent(static_cast<Plugin *>(plugin), ats_txn_handle, event); } -void utils::internal::invokePluginForEvent(GlobalPlugin *plugin, TSHttpTxn ats_txn_handle, TSEvent event) { +void +utils::internal::invokePluginForEvent(GlobalPlugin *plugin, TSHttpTxn ats_txn_handle, TSEvent event) +{ ::invokePluginForEvent(static_cast<Plugin *>(plugin), ats_txn_handle, event); } -std::string utils::internal::consumeFromTSIOBufferReader(TSIOBufferReader reader) { +std::string +utils::internal::consumeFromTSIOBufferReader(TSIOBufferReader reader) +{ std::string str; int avail = TSIOBufferReaderAvail(reader); @@ -236,7 +252,9 @@ std::string utils::internal::consumeFromTSIOBufferReader(TSIOBufferReader reader } -HttpVersion utils::internal::getHttpVersion(TSMBuffer hdr_buf, TSMLoc hdr_loc) { +HttpVersion +utils::internal::getHttpVersion(TSMBuffer hdr_buf, TSMLoc hdr_loc) +{ int version = TSHttpHdrVersionGet(hdr_buf, hdr_loc); if (version != TS_ERROR) { if ((TS_HTTP_MAJOR(version) == 0) && (TS_HTTP_MINOR(version) == 0)) { @@ -256,7 +274,9 @@ HttpVersion utils::internal::getHttpVersion(TSMBuffer hdr_buf, TSMLoc hdr_loc) { return HTTP_VERSION_UNKNOWN; } -void utils::internal::initTransactionManagement() { +void +utils::internal::initTransactionManagement() +{ static pthread_once_t setup_pthread_once_control = PTHREAD_ONCE_INIT; pthread_once(&setup_pthread_once_control, setupTransactionManagement); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/records/I_RecAlarms.h ---------------------------------------------------------------------- diff --git a/lib/records/I_RecAlarms.h b/lib/records/I_RecAlarms.h index 25bebb9..21713c4 100644 --- a/lib/records/I_RecAlarms.h +++ b/lib/records/I_RecAlarms.h @@ -25,26 +25,26 @@ #define _I_REC_ALARMS_H_ // copy from mgmt/Alarms.h -#define REC_ALARM_PROXY_PROCESS_DIED 1 -#define REC_ALARM_PROXY_PROCESS_BORN 2 -#define REC_ALARM_PROXY_PEER_BORN 3 -#define REC_ALARM_PROXY_PEER_DIED 4 -#define REC_ALARM_PROXY_CONFIG_ERROR 5 -#define REC_ALARM_PROXY_SYSTEM_ERROR 6 -#define REC_ALARM_PROXY_LOG_SPACE_CRISIS 7 -#define REC_ALARM_PROXY_CACHE_ERROR 8 -#define REC_ALARM_PROXY_CACHE_WARNING 9 -#define REC_ALARM_PROXY_LOGGING_ERROR 10 -#define REC_ALARM_PROXY_LOGGING_WARNING 11 +#define REC_ALARM_PROXY_PROCESS_DIED 1 +#define REC_ALARM_PROXY_PROCESS_BORN 2 +#define REC_ALARM_PROXY_PEER_BORN 3 +#define REC_ALARM_PROXY_PEER_DIED 4 +#define REC_ALARM_PROXY_CONFIG_ERROR 5 +#define REC_ALARM_PROXY_SYSTEM_ERROR 6 +#define REC_ALARM_PROXY_LOG_SPACE_CRISIS 7 +#define REC_ALARM_PROXY_CACHE_ERROR 8 +#define REC_ALARM_PROXY_CACHE_WARNING 9 +#define REC_ALARM_PROXY_LOGGING_ERROR 10 +#define REC_ALARM_PROXY_LOGGING_WARNING 11 // Currently unused: 12 -#define REC_ALARM_REC_TEST 13 -#define REC_ALARM_CONFIG_UPDATE_FAILED 14 -#define REC_ALARM_WEB_ERROR 15 -#define REC_ALARM_PING_FAILURE 16 -#define REC_ALARM_REC_CONFIG_ERROR 17 -#define REC_ALARM_ADD_ALARM 18 -#define REC_ALARM_PROXY_LOG_SPACE_ROLLED 19 -#define REC_ALARM_PROXY_HTTP_CONGESTED_SERVER 20 -#define REC_ALARM_PROXY_HTTP_ALLEVIATED_SERVER 21 +#define REC_ALARM_REC_TEST 13 +#define REC_ALARM_CONFIG_UPDATE_FAILED 14 +#define REC_ALARM_WEB_ERROR 15 +#define REC_ALARM_PING_FAILURE 16 +#define REC_ALARM_REC_CONFIG_ERROR 17 +#define REC_ALARM_ADD_ALARM 18 +#define REC_ALARM_PROXY_LOG_SPACE_ROLLED 19 +#define REC_ALARM_PROXY_HTTP_CONGESTED_SERVER 20 +#define REC_ALARM_PROXY_HTTP_ALLEVIATED_SERVER 21 #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/records/I_RecCore.h ---------------------------------------------------------------------- diff --git a/lib/records/I_RecCore.h b/lib/records/I_RecCore.h index 5b5ffe0..9945cc0 100644 --- a/lib/records/I_RecCore.h +++ b/lib/records/I_RecCore.h @@ -36,102 +36,102 @@ struct RecRecord; //------------------------------------------------------------------------- // Diagnostic Output //------------------------------------------------------------------------- -int RecSetDiags(Diags * diags); +int RecSetDiags(Diags *diags); //------------------------------------------------------------------------- // Config File Parsing //------------------------------------------------------------------------- -typedef void (*RecConfigEntryCallback)(RecT rec_type, RecDataT data_type, const char * name, const char * value, bool inc_version); +typedef void (*RecConfigEntryCallback)(RecT rec_type, RecDataT data_type, const char *name, const char *value, bool inc_version); void RecConfigFileInit(void); -int RecConfigFileParse(const char * path, RecConfigEntryCallback handler, bool inc_version); +int RecConfigFileParse(const char *path, RecConfigEntryCallback handler, bool inc_version); // Return a copy of the system's configuration directory, taking proxy.config.config_dir into account. The // caller MUST release the result with ats_free(). -char * RecConfigReadConfigDir(); +char *RecConfigReadConfigDir(); // Return a copy of the system's local state directory, taking proxy.config.local_state_dir into account. The // caller MUST release the result with ats_free(). -char * RecConfigReadRuntimeDir(); +char *RecConfigReadRuntimeDir(); // Return a copy of the system's snapshot directory, taking proxy.config.snapshot_dir into account. The caller // MUST release the result with ats_free(). -char * RecConfigReadSnapshotDir(); +char *RecConfigReadSnapshotDir(); // Return a copy of the system's log directory, taking proxy.config.log.logfile_dir into account. The caller // MUST release the result with ats_free(). -char * RecConfigReadLogDir(); +char *RecConfigReadLogDir(); // Return a copy of the system's bin directory, taking proxy.config.bin_path into account. The caller MUST // release the result with ats_free(). -char * RecConfigReadBinDir(); +char *RecConfigReadBinDir(); // Return a copy of a configuration file that is relative to sysconfdir. The relative path to the configuration // file is specified in the configuration variable named by "file_variable". If the configuration variable has no // value, NULL is returned. The caller MUST release the result with ats_free(). -char * RecConfigReadConfigPath(const char * file_variable, const char * default_value = NULL); +char *RecConfigReadConfigPath(const char *file_variable, const char *default_value = NULL); // This is the same as RecConfigReadConfigPath, except it makes the paths relative to $PREFIX. -char * RecConfigReadPrefixPath(const char * file_variable, const char * default_value = NULL); +char *RecConfigReadPrefixPath(const char *file_variable, const char *default_value = NULL); // Return a copy of the persistent stats file. This is $RUNTIMEDIR/records.snap. // The caller MUST release the result with ats_free(). -char * RecConfigReadPersistentStatsPath(); +char *RecConfigReadPersistentStatsPath(); // Test whether the named configuration value is overridden by an environment variable. Return either // the overridden value, or the original value. Caller MUST NOT free the result. -const char * RecConfigOverrideFromEnvironment(const char * name, const char * value); +const char *RecConfigOverrideFromEnvironment(const char *name, const char *value); //------------------------------------------------------------------------- // Stat Registration //------------------------------------------------------------------------- int _RecRegisterStatInt(RecT rec_type, const char *name, RecInt data_default, RecPersistT persist_type); -#define RecRegisterStatInt(rec_type, name, data_default, persist_type) _RecRegisterStatInt((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type)) +#define RecRegisterStatInt(rec_type, name, data_default, persist_type) \ + _RecRegisterStatInt((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type)) int _RecRegisterStatFloat(RecT rec_type, const char *name, RecFloat data_default, RecPersistT persist_type); -#define RecRegisterStatFloat(rec_type, name, data_default, persist_type) _RecRegisterStatFloat((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type)) +#define RecRegisterStatFloat(rec_type, name, data_default, persist_type) \ + _RecRegisterStatFloat((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type)) int _RecRegisterStatString(RecT rec_type, const char *name, RecString data_default, RecPersistT persist_type); -#define RecRegisterStatString(rec_type, name, data_default, persist_type) _RecRegisterStatString((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type)) +#define RecRegisterStatString(rec_type, name, data_default, persist_type) \ + _RecRegisterStatString((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type)) int _RecRegisterStatCounter(RecT rec_type, const char *name, RecCounter data_default, RecPersistT persist_type); -#define RecRegisterStatCounter(rec_type, name, data_default, persist_type) _RecRegisterStatCounter((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type)) +#define RecRegisterStatCounter(rec_type, name, data_default, persist_type) \ + _RecRegisterStatCounter((rec_type), (name), (data_default), REC_PERSISTENCE_TYPE(persist_type)) //------------------------------------------------------------------------- // Config Registration //------------------------------------------------------------------------- -int RecRegisterConfigInt(RecT rec_type, const char *name, - RecInt data_default, RecUpdateT update_type, - RecCheckT check_type, const char *ccheck_regex, RecAccessT access_type = RECA_NULL); +int RecRegisterConfigInt(RecT rec_type, const char *name, RecInt data_default, RecUpdateT update_type, RecCheckT check_type, + const char *ccheck_regex, RecAccessT access_type = RECA_NULL); -int RecRegisterConfigFloat(RecT rec_type, const char *name, - RecFloat data_default, RecUpdateT update_type, - RecCheckT check_type, const char *check_regex, RecAccessT access_type = RECA_NULL); +int RecRegisterConfigFloat(RecT rec_type, const char *name, RecFloat data_default, RecUpdateT update_type, RecCheckT check_type, + const char *check_regex, RecAccessT access_type = RECA_NULL); -int RecRegisterConfigString(RecT rec_type, const char *name, - const char *data_default, RecUpdateT update_type, - RecCheckT check_type, const char *check_regex, RecAccessT access_type = RECA_NULL); +int RecRegisterConfigString(RecT rec_type, const char *name, const char *data_default, RecUpdateT update_type, RecCheckT check_type, + const char *check_regex, RecAccessT access_type = RECA_NULL); -int RecRegisterConfigCounter(RecT rec_type, const char *name, - RecCounter data_default, RecUpdateT update_type, - RecCheckT check_type, const char *check_regex, RecAccessT access_type = RECA_NULL); +int RecRegisterConfigCounter(RecT rec_type, const char *name, RecCounter data_default, RecUpdateT update_type, RecCheckT check_type, + const char *check_regex, RecAccessT access_type = RECA_NULL); //------------------------------------------------------------------------- // Config Change Notification //------------------------------------------------------------------------- -int RecLinkConfigInt(const char *name, RecInt * rec_int); -int RecLinkConfigInt32(const char *name, int32_t * p_int32); -int RecLinkConfigUInt32(const char *name, uint32_t * p_uint32); -int RecLinkConfigFloat(const char *name, RecFloat * rec_float); -int RecLinkConfigCounter(const char *name, RecCounter * rec_counter); -int RecLinkConfigString(const char *name, RecString * rec_string); -int RecLinkConfigByte(const char *name, RecByte * rec_byte); -int RecLinkConfigBool(const char *name, RecBool * rec_byte); +int RecLinkConfigInt(const char *name, RecInt *rec_int); +int RecLinkConfigInt32(const char *name, int32_t *p_int32); +int RecLinkConfigUInt32(const char *name, uint32_t *p_uint32); +int RecLinkConfigFloat(const char *name, RecFloat *rec_float); +int RecLinkConfigCounter(const char *name, RecCounter *rec_counter); +int RecLinkConfigString(const char *name, RecString *rec_string); +int RecLinkConfigByte(const char *name, RecByte *rec_byte); +int RecLinkConfigBool(const char *name, RecBool *rec_byte); int RecRegisterConfigUpdateCb(const char *name, RecConfigUpdateCb update_cb, void *cookie); -int RecRegisterRawStatUpdateFunc(const char *name, RecRawStatBlock * rsb, int id, RecStatUpdateFunc update_func, void *cookie); +int RecRegisterRawStatUpdateFunc(const char *name, RecRawStatBlock *rsb, int id, RecStatUpdateFunc update_func, void *cookie); //------------------------------------------------------------------------- @@ -151,33 +151,33 @@ int RecSetRecordFloat(const char *name, RecFloat rec_float, bool lock = true, bo int RecSetRecordString(const char *name, const RecString rec_string, bool lock = true, bool inc_version = true); int RecSetRecordCounter(const char *name, RecCounter rec_counter, bool lock = true, bool inc_version = true); -int RecGetRecordInt(const char *name, RecInt * rec_int, bool lock = true); -int RecGetRecordFloat(const char *name, RecFloat * rec_float, bool lock = true); +int RecGetRecordInt(const char *name, RecInt *rec_int, bool lock = true); +int RecGetRecordFloat(const char *name, RecFloat *rec_float, bool lock = true); int RecGetRecordString(const char *name, char *buf, int buf_len, bool lock = true); -int RecGetRecordString_Xmalloc(const char *name, RecString * rec_string, bool lock = true); -int RecGetRecordCounter(const char *name, RecCounter * rec_counter, bool lock = true); +int RecGetRecordString_Xmalloc(const char *name, RecString *rec_string, bool lock = true); +int RecGetRecordCounter(const char *name, RecCounter *rec_counter, bool lock = true); // Convenience to allow us to treat the RecInt as a single byte internally -int RecGetRecordByte(const char *name, RecByte * rec_byte, bool lock = true); +int RecGetRecordByte(const char *name, RecByte *rec_byte, bool lock = true); // Convenience to allow us to treat the RecInt as a bool internally -int RecGetRecordBool(const char *name, RecBool * rec_byte, bool lock = true); +int RecGetRecordBool(const char *name, RecBool *rec_byte, bool lock = true); //------------------------------------------------------------------------ // Record Attributes Reading //------------------------------------------------------------------------ -int RecLookupRecord(const char *name, void (*callback)(const RecRecord *, void *), void * data, bool lock = true); +int RecLookupRecord(const char *name, void (*callback)(const RecRecord *, void *), void *data, bool lock = true); -int RecGetRecordType(const char *name, RecT * rec_type, bool lock = true); -int RecGetRecordDataType(const char *name, RecDataT * data_type, bool lock = true); -int RecGetRecordPersistenceType(const char *name, RecPersistT * persist_type, bool lock = true); +int RecGetRecordType(const char *name, RecT *rec_type, bool lock = true); +int RecGetRecordDataType(const char *name, RecDataT *data_type, bool lock = true); +int RecGetRecordPersistenceType(const char *name, RecPersistT *persist_type, bool lock = true); int RecGetRecordOrderAndId(const char *name, int *order, int *id, bool lock = true); -int RecGetRecordUpdateType(const char *name, RecUpdateT * update_type, bool lock = true); -int RecGetRecordCheckType(const char *name, RecCheckT * check_type, bool lock = true); +int RecGetRecordUpdateType(const char *name, RecUpdateT *update_type, bool lock = true); +int RecGetRecordCheckType(const char *name, RecCheckT *check_type, bool lock = true); int RecGetRecordCheckExpr(const char *name, char **check_expr, bool lock = true); int RecGetRecordDefaultDataString_Xmalloc(char *name, char **buf, bool lock = true); -int RecGetRecordAccessType(const char *name, RecAccessT * secure, bool lock = true); +int RecGetRecordAccessType(const char *name, RecAccessT *secure, bool lock = true); int RecSetRecordAccessType(const char *name, RecAccessT secure, bool lock = true); int RecGetRecordPrefix_Xmalloc(char *prefix, char **result, int *result_len); @@ -188,61 +188,64 @@ int RecGetRecordPrefix_Xmalloc(char *prefix, char **result, int *result_len); //------------------------------------------------------------------------ // RecSignalManager always sends a management signal up to traffic_manager. -void RecSignalManager(int id, const char * , size_t); +void RecSignalManager(int id, const char *, size_t); static inline void -RecSignalManager(int id, const char * str) { +RecSignalManager(int id, const char *str) +{ RecSignalManager(id, str, strlen(str + 1)); } // Format a message, and send it to the manager and to the Warning diagnostic. -void RecSignalWarning(int sig, const char * fmt, ...) - TS_PRINTFLIKE(2, 3); +void RecSignalWarning(int sig, const char *fmt, ...) TS_PRINTFLIKE(2, 3); //------------------------------------------------------------------------- // Backwards Compatibility Items (REC_ prefix) //------------------------------------------------------------------------- -#define REC_ReadConfigInt32(_var,_config_var_name) do { \ - RecInt tmp = 0; \ - RecGetRecordInt(_config_var_name, (RecInt*) &tmp); \ - _var = (int32_t)tmp; \ -} while (0) - -#define REC_ReadConfigInteger(_var,_config_var_name) do { \ - RecInt tmp = 0; \ - RecGetRecordInt(_config_var_name, &tmp); \ - _var = tmp; \ -} while (0) - -#define REC_ReadConfigFloat(_var,_config_var_name) do { \ - RecFloat tmp = 0; \ - RecGetRecordFloat(_config_var_name, &tmp); \ - _var = tmp; \ -} while (0) - -#define REC_ReadConfigStringAlloc(_var,_config_var_name) \ - RecGetRecordString_Xmalloc(_config_var_name, (RecString*)&_var) - -#define REC_ReadConfigString(_var, _config_var_name, _len) \ - RecGetRecordString(_config_var_name, _var, _len) - -#define REC_RegisterConfigUpdateFunc(_config_var_name, func, flag) \ - RecRegisterConfigUpdateCb(_config_var_name, func, flag) - -#define REC_EstablishStaticConfigInteger(_var, _config_var_name) do { \ - RecLinkConfigInt(_config_var_name, &_var); \ - _var = (int64_t)REC_ConfigReadInteger(_config_var_name); \ -} while (0) - -#define REC_EstablishStaticConfigInt32(_var, _config_var_name) do { \ - RecLinkConfigInt32(_config_var_name, &_var); \ - _var = (int32_t)REC_ConfigReadInteger(_config_var_name); \ -} while (0) - -#define REC_EstablishStaticConfigInt32U(_var, _config_var_name) do { \ - RecLinkConfigUInt32(_config_var_name, &_var); \ - _var = (int32_t)REC_ConfigReadInteger(_config_var_name); \ -} while (0) +#define REC_ReadConfigInt32(_var, _config_var_name) \ + do { \ + RecInt tmp = 0; \ + RecGetRecordInt(_config_var_name, (RecInt *)&tmp); \ + _var = (int32_t)tmp; \ + } while (0) + +#define REC_ReadConfigInteger(_var, _config_var_name) \ + do { \ + RecInt tmp = 0; \ + RecGetRecordInt(_config_var_name, &tmp); \ + _var = tmp; \ + } while (0) + +#define REC_ReadConfigFloat(_var, _config_var_name) \ + do { \ + RecFloat tmp = 0; \ + RecGetRecordFloat(_config_var_name, &tmp); \ + _var = tmp; \ + } while (0) + +#define REC_ReadConfigStringAlloc(_var, _config_var_name) RecGetRecordString_Xmalloc(_config_var_name, (RecString *)&_var) + +#define REC_ReadConfigString(_var, _config_var_name, _len) RecGetRecordString(_config_var_name, _var, _len) + +#define REC_RegisterConfigUpdateFunc(_config_var_name, func, flag) RecRegisterConfigUpdateCb(_config_var_name, func, flag) + +#define REC_EstablishStaticConfigInteger(_var, _config_var_name) \ + do { \ + RecLinkConfigInt(_config_var_name, &_var); \ + _var = (int64_t)REC_ConfigReadInteger(_config_var_name); \ + } while (0) + +#define REC_EstablishStaticConfigInt32(_var, _config_var_name) \ + do { \ + RecLinkConfigInt32(_config_var_name, &_var); \ + _var = (int32_t)REC_ConfigReadInteger(_config_var_name); \ + } while (0) + +#define REC_EstablishStaticConfigInt32U(_var, _config_var_name) \ + do { \ + RecLinkConfigUInt32(_config_var_name, &_var); \ + _var = (int32_t)REC_ConfigReadInteger(_config_var_name); \ + } while (0) /* * RecLinkConfigString allocates the RecString and stores the ptr to it (&var). @@ -251,29 +254,33 @@ void RecSignalWarning(int sig, const char * fmt, ...) * For now, we're using the return value to indicate this, even though it's * not always the case. If we're wrong, we'll leak the RecString. */ -#define REC_EstablishStaticConfigStringAlloc(_var, _config_var_name) do { \ - if (RecLinkConfigString(_config_var_name, &_var) == REC_ERR_OKAY) \ - ats_free(_var); \ - _var = (RecString)REC_ConfigReadString(_config_var_name); \ -} while (0) +#define REC_EstablishStaticConfigStringAlloc(_var, _config_var_name) \ + do { \ + if (RecLinkConfigString(_config_var_name, &_var) == REC_ERR_OKAY) \ + ats_free(_var); \ + _var = (RecString)REC_ConfigReadString(_config_var_name); \ + } while (0) -#define REC_EstablishStaticConfigFloat(_var, _config_var_name) do { \ - RecLinkConfigFloat(_config_var_name, &_var); \ - _var = (RecFloat)REC_ConfigReadFloat(_config_var_name); \ -} while (0) +#define REC_EstablishStaticConfigFloat(_var, _config_var_name) \ + do { \ + RecLinkConfigFloat(_config_var_name, &_var); \ + _var = (RecFloat)REC_ConfigReadFloat(_config_var_name); \ + } while (0) // Allow to treat our "INT" configs as a byte type internally. Note // that the byte type is just a wrapper around RECD_INT. -#define REC_EstablishStaticConfigByte(_var, _config_var_name) do { \ - RecLinkConfigByte(_config_var_name, &_var); \ - _var = (RecByte)REC_ConfigReadInteger(_config_var_name); \ +#define REC_EstablishStaticConfigByte(_var, _config_var_name) \ + do { \ + RecLinkConfigByte(_config_var_name, &_var); \ + _var = (RecByte)REC_ConfigReadInteger(_config_var_name); \ } while (0) // Allow to treat our "INT" configs as a bool type internally. Note // that the bool type is just a wrapper around RECD_INT. -#define REC_EstablishStaticConfigBool(_var, _config_var_name) do { \ - RecLinkConfigBool(_config_var_name, &_var); \ - _var = 0 != REC_ConfigReadInteger(_config_var_name); \ +#define REC_EstablishStaticConfigBool(_var, _config_var_name) \ + do { \ + RecLinkConfigBool(_config_var_name, &_var); \ + _var = 0 != REC_ConfigReadInteger(_config_var_name); \ } while (0) RecInt REC_ConfigReadInteger(const char *name); @@ -282,10 +289,10 @@ RecFloat REC_ConfigReadFloat(const char *name); RecCounter REC_ConfigReadCounter(const char *name); // MGMT2 Marco's -- converting lmgmt->record_data->readXXX -RecInt REC_readInteger(const char *name, bool * found, bool lock = true); -RecFloat REC_readFloat(char *name, bool * found, bool lock = true); -RecCounter REC_readCounter(char *name, bool * found, bool lock = true); -RecString REC_readString(const char *name, bool * found, bool lock = true); +RecInt REC_readInteger(const char *name, bool *found, bool lock = true); +RecFloat REC_readFloat(char *name, bool *found, bool lock = true); +RecCounter REC_readCounter(char *name, bool *found, bool lock = true); +RecString REC_readString(const char *name, bool *found, bool lock = true); //------------------------------------------------------------------------ // Clear Statistics @@ -302,7 +309,7 @@ int RecSetSyncRequired(char *name, bool lock = true); //------------------------------------------------------------------------ // Manager Callback //------------------------------------------------------------------------ -typedef void *(*RecManagerCb) (void *opaque_cb_data, char *data_raw, int data_len); +typedef void *(*RecManagerCb)(void *opaque_cb_data, char *data_raw, int data_len); int RecRegisterManagerCb(int _signal, RecManagerCb _fn, void *_data = NULL); #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/records/I_RecDefs.h ---------------------------------------------------------------------- diff --git a/lib/records/I_RecDefs.h b/lib/records/I_RecDefs.h index fedf88f..114153e 100644 --- a/lib/records/I_RecDefs.h +++ b/lib/records/I_RecDefs.h @@ -34,10 +34,9 @@ //------------------------------------------------------------------------- // Error Values //------------------------------------------------------------------------- -enum RecErrT -{ +enum RecErrT { REC_ERR_FAIL = -1, - REC_ERR_OKAY = 0 + REC_ERR_OKAY = 0, }; @@ -54,20 +53,18 @@ typedef int64_t RecCounter; typedef int8_t RecByte; typedef bool RecBool; -enum RecT -{ - RECT_NULL = 0x00, - RECT_CONFIG = 0x01, - RECT_PROCESS = 0x02, - RECT_NODE = 0x04, - RECT_CLUSTER = 0x08, - RECT_LOCAL = 0x10, - RECT_PLUGIN = 0x20, - RECT_ALL = 0x3F +enum RecT { + RECT_NULL = 0x00, + RECT_CONFIG = 0x01, + RECT_PROCESS = 0x02, + RECT_NODE = 0x04, + RECT_CLUSTER = 0x08, + RECT_LOCAL = 0x10, + RECT_PLUGIN = 0x20, + RECT_ALL = 0x3F }; -enum RecDataT -{ +enum RecDataT { RECD_NULL = 0, RECD_INT, RECD_FLOAT, @@ -75,82 +72,73 @@ enum RecDataT RECD_COUNTER, #if defined(STAT_PROCESSOR) - RECD_CONST, // Added for the StatProcessor, store as RECD_FLOAT - RECD_FX, // Added for the StatProcessor, store as RECD_INT + RECD_CONST, // Added for the StatProcessor, store as RECD_FLOAT + RECD_FX, // Added for the StatProcessor, store as RECD_INT #endif RECD_MAX }; -enum RecPersistT -{ +enum RecPersistT { RECP_NULL, RECP_PERSISTENT, - RECP_NON_PERSISTENT + RECP_NON_PERSISTENT, }; // RECP_NULL should never be used by callers of RecRegisterStat*(). You have to decide // whether to persist stats or not. The template goop below make sure that passing RECP_NULL // is a very ugle compile-time error. -namespace rec { -namespace detail { -template <RecPersistT> -struct is_valid_persistence; - -template<> -struct is_valid_persistence<RECP_PERSISTENT> +namespace rec { - static const RecPersistT value = RECP_PERSISTENT; -}; - -template<> -struct is_valid_persistence<RECP_NON_PERSISTENT> +namespace detail { - static const RecPersistT value = RECP_NON_PERSISTENT; -}; + template <RecPersistT> struct is_valid_persistence; -}} + template <> struct is_valid_persistence<RECP_PERSISTENT> { + static const RecPersistT value = RECP_PERSISTENT; + }; + + template <> struct is_valid_persistence<RECP_NON_PERSISTENT> { + static const RecPersistT value = RECP_NON_PERSISTENT; + }; +} +} #define REC_PERSISTENCE_TYPE(P) rec::detail::is_valid_persistence<P>::value -enum RecUpdateT -{ - RECU_NULL, // default: don't know the behavior - RECU_DYNAMIC, // config can be updated dynamically w/ traffic_line -x - RECU_RESTART_TS, // config requires TS to be restarted to take effect - RECU_RESTART_TM, // config requires TM/TS to be restarted to take effect - RECU_RESTART_TC // config requires TC/TM/TS to be restarted to take effect +enum RecUpdateT { + RECU_NULL, // default: don't know the behavior + RECU_DYNAMIC, // config can be updated dynamically w/ traffic_line -x + RECU_RESTART_TS, // config requires TS to be restarted to take effect + RECU_RESTART_TM, // config requires TM/TS to be restarted to take effect + RECU_RESTART_TC // config requires TC/TM/TS to be restarted to take effect }; -enum RecCheckT -{ - RECC_NULL, // default: no check type defined - RECC_STR, // config is a string - RECC_INT, // config is an integer with a range - RECC_IP // config is an ip address +enum RecCheckT { + RECC_NULL, // default: no check type defined + RECC_STR, // config is a string + RECC_INT, // config is an integer with a range + RECC_IP // config is an ip address }; -enum RecModeT -{ +enum RecModeT { RECM_NULL, RECM_CLIENT, RECM_SERVER, - RECM_STAND_ALONE + RECM_STAND_ALONE, }; -enum RecAccessT -{ +enum RecAccessT { RECA_NULL, RECA_NO_ACCESS, - RECA_READ_ONLY + RECA_READ_ONLY, }; //------------------------------------------------------------------------- // Data Union //------------------------------------------------------------------------- -union RecData -{ +union RecData { RecInt rec_int; RecFloat rec_float; RecString rec_string; @@ -161,14 +149,13 @@ union RecData //------------------------------------------------------------------------- // RawStat Structures //------------------------------------------------------------------------- -struct RecRawStat -{ +struct RecRawStat { int64_t sum; int64_t count; // XXX - these will waist some space because they are only needed for the globals // this is a fix for bug TS-162, so I am trying to do as few code changes as // possible, this should be revisted -bcall - int64_t last_sum; // value from the last global sync + int64_t last_sum; // value from the last global sync int64_t last_count; // value from the last global sync uint32_t version; }; @@ -176,12 +163,11 @@ struct RecRawStat // WARNING! It's advised that developers do not modify the contents of // the RecRawStatBlock. ^_^ -struct RecRawStatBlock -{ - off_t ethr_stat_offset; // thread local raw-stat storage - RecRawStat **global; // global raw-stat storage (ptr to RecRecord) - int num_stats; // number of stats in this block - int max_stats; // maximum number of stats for this block +struct RecRawStatBlock { + off_t ethr_stat_offset; // thread local raw-stat storage + RecRawStat **global; // global raw-stat storage (ptr to RecRecord) + int num_stats; // number of stats in this block + int max_stats; // maximum number of stats for this block ink_mutex mutex; }; @@ -189,8 +175,8 @@ struct RecRawStatBlock //------------------------------------------------------------------------- // RecCore Callback Types //------------------------------------------------------------------------- -typedef int (*RecConfigUpdateCb) (const char *name, RecDataT data_type, RecData data, void *cookie); -typedef int (*RecStatUpdateFunc) (const char *name, RecDataT data_type, RecData * data, RecRawStatBlock * rsb, int id, void *cookie); -typedef int (*RecRawStatSyncCb) (const char *name, RecDataT data_type, RecData * data, RecRawStatBlock * rsb, int id); +typedef int (*RecConfigUpdateCb)(const char *name, RecDataT data_type, RecData data, void *cookie); +typedef int (*RecStatUpdateFunc)(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id, void *cookie); +typedef int (*RecRawStatSyncCb)(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id); #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/records/I_RecEvents.h ---------------------------------------------------------------------- diff --git a/lib/records/I_RecEvents.h b/lib/records/I_RecEvents.h index 7454b48..1dedd8b 100644 --- a/lib/records/I_RecEvents.h +++ b/lib/records/I_RecEvents.h @@ -25,18 +25,18 @@ #define _I_REC_EVENTS_H_ // copy from mgmt/BaseManager.h -#define REC_EVENT_SYNC_KEY 10000 -#define REC_EVENT_SHUTDOWN 10001 -#define REC_EVENT_RESTART 10002 -#define REC_EVENT_BOUNCE 10003 -#define REC_EVENT_CLEAR_STATS 10004 -#define REC_EVENT_CONFIG_FILE_UPDATE 10005 -#define REC_EVENT_PLUGIN_CONFIG_UPDATE 10006 -#define REC_EVENT_HTTP_CLUSTER_DELTA 10007 -#define REC_EVENT_ROLL_LOG_FILES 10008 -#define REC_EVENT_LIBRECORDS 10009 -#define REC_EVENT_CONFIG_FILE_UPDATE_NO_INC_VERSION 10010 - -#define REC_EVENT_CACHE_DISK_CONTROL 10011 +#define REC_EVENT_SYNC_KEY 10000 +#define REC_EVENT_SHUTDOWN 10001 +#define REC_EVENT_RESTART 10002 +#define REC_EVENT_BOUNCE 10003 +#define REC_EVENT_CLEAR_STATS 10004 +#define REC_EVENT_CONFIG_FILE_UPDATE 10005 +#define REC_EVENT_PLUGIN_CONFIG_UPDATE 10006 +#define REC_EVENT_HTTP_CLUSTER_DELTA 10007 +#define REC_EVENT_ROLL_LOG_FILES 10008 +#define REC_EVENT_LIBRECORDS 10009 +#define REC_EVENT_CONFIG_FILE_UPDATE_NO_INC_VERSION 10010 + +#define REC_EVENT_CACHE_DISK_CONTROL 10011 #endif
