From 13fbcf993034e9c85e304440871b39affd173921 Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Sun, 26 May 2019 16:45:02 +0300 Subject: [PATCH 1/5] Better Logging system --- src/oatpp-test/UnitTest.cpp | 10 +- .../core/async/worker/IOEventWorker_epoll.cpp | 20 ++-- .../async/worker/IOEventWorker_kqueue.cpp | 4 +- src/oatpp/core/base/Config.hpp | 6 +- src/oatpp/core/base/Environment.cpp | 85 +++++++++++++- src/oatpp/core/base/Environment.hpp | 104 ++++++++++++++++-- test/oatpp/AllTestsMain.cpp | 4 - .../oatpp/core/base/memory/MemoryPoolTest.cpp | 2 +- .../oatpp/core/data/mapping/type/TypeTest.cpp | 32 +++--- .../core/data/stream/ChunkedBufferTest.cpp | 2 +- test/oatpp/encoding/Base64Test.cpp | 4 +- test/oatpp/encoding/UnicodeTest.cpp | 2 +- test/oatpp/network/UrlTest.cpp | 24 ++-- test/oatpp/network/virtual_/InterfaceTest.cpp | 2 +- test/oatpp/network/virtual_/PipeTest.cpp | 6 +- .../parser/json/mapping/DTOMapperTest.cpp | 10 +- test/oatpp/web/FullAsyncClientTest.cpp | 14 +-- test/oatpp/web/FullAsyncTest.cpp | 4 +- test/oatpp/web/FullTest.cpp | 2 +- test/oatpp/web/app/Controller.hpp | 10 +- test/oatpp/web/app/ControllerAsync.hpp | 14 +-- 21 files changed, 258 insertions(+), 103 deletions(-) diff --git a/src/oatpp-test/UnitTest.cpp b/src/oatpp-test/UnitTest.cpp index dad63bbb..11f7b371 100644 --- a/src/oatpp-test/UnitTest.cpp +++ b/src/oatpp-test/UnitTest.cpp @@ -32,7 +32,7 @@ namespace oatpp { namespace test { void UnitTest::run(v_int32 times) { - OATPP_LOGD(TAG, "\033[1mSTART\033[0m..."); + OATPP_LOGI(TAG, "\033[1mSTART\033[0m..."); v_counter objectsCount = base::Environment::getObjectsCount(); v_counter objectsCreated = base::Environment::getObjectsCreated(); @@ -49,18 +49,18 @@ void UnitTest::run(v_int32 times) { v_counter objectsCreatedPerTest = base::Environment::getObjectsCreated() - objectsCreated; if(leakingObjects == 0){ - OATPP_LOGD(TAG, "\033[1mFINISHED\033[0m - \033[1;32msuccess!\033[0m"); - OATPP_LOGD(TAG, "\033[33m%d(micro), %d(objs)\033[0m\n", millis, objectsCreatedPerTest); + OATPP_LOGI(TAG, "\033[1mFINISHED\033[0m - \033[1;32msuccess!\033[0m"); + OATPP_LOGI(TAG, "\033[33m%d(micro), %d(objs)\033[0m\n", millis, objectsCreatedPerTest); }else{ - OATPP_LOGD(TAG, "\033[1mFINISHED\033[0m - \033[1;31mfailed\033[0m, leakingObjects = %d", leakingObjects); + OATPP_LOGE(TAG, "\033[1mFINISHED\033[0m - \033[1;31mfailed\033[0m, leakingObjects = %d", leakingObjects); auto POOLS = oatpp::base::memory::MemoryPool::POOLS; auto it = POOLS.begin(); while (it != POOLS.end()) { auto pool = it->second; if(pool->getObjectsCount() != 0) { - OATPP_LOGD("Pool", "name: '%s' [%d(objs)]", pool->getName().c_str(), pool->getObjectsCount()); + OATPP_LOGV("Pool", "name: '%s' [%d(objs)]", pool->getName().c_str(), pool->getObjectsCount()); } it ++; } diff --git a/src/oatpp/core/async/worker/IOEventWorker_epoll.cpp b/src/oatpp/core/async/worker/IOEventWorker_epoll.cpp index c992418a..e0c24092 100644 --- a/src/oatpp/core/async/worker/IOEventWorker_epoll.cpp +++ b/src/oatpp/core/async/worker/IOEventWorker_epoll.cpp @@ -42,14 +42,14 @@ void IOEventWorker::initEventQueue() { m_eventQueueHandle = ::epoll_create1(0); if(m_eventQueueHandle == -1) { - OATPP_LOGD("[oatpp::async::worker::IOEventWorker::initEventQueue()]", "Error. Call to ::epoll_create1() failed. errno=%d", errno); + OATPP_LOGE("[oatpp::async::worker::IOEventWorker::initEventQueue()]", "Error. Call to ::epoll_create1() failed. errno=%d", errno); throw std::runtime_error("[oatpp::async::worker::IOEventWorker::initEventQueue()]: Error. Call to ::epoll_create1() failed."); } m_outEvents = std::unique_ptr(new (std::nothrow) v_char8[MAX_EVENTS * sizeof(struct epoll_event)]); if(!m_outEvents) { - OATPP_LOGD("[oatpp::async::worker::IOEventWorker::initEventQueue()]", + OATPP_LOGE("[oatpp::async::worker::IOEventWorker::initEventQueue()]", "Error. Unable to allocate %d bytes for events.", MAX_EVENTS * sizeof(struct epoll_event)); throw std::runtime_error("[oatpp::async::worker::IOEventWorker::initEventQueue()]: Error. Unable to allocate memory for events."); } @@ -57,7 +57,7 @@ void IOEventWorker::initEventQueue() { m_wakeupTrigger = ::eventfd(0, EFD_NONBLOCK); if(m_wakeupTrigger == -1) { - OATPP_LOGD("[oatpp::async::worker::IOEventWorker::initEventQueue()]", "Error. Call to ::eventfd() failed. errno=%d", errno); + OATPP_LOGE("[oatpp::async::worker::IOEventWorker::initEventQueue()]", "Error. Call to ::eventfd() failed. errno=%d", errno); throw std::runtime_error("[oatpp::async::worker::IOEventWorker::initEventQueue()]: Error. Call to ::eventfd() failed."); } @@ -74,7 +74,7 @@ void IOEventWorker::initEventQueue() { auto res = ::epoll_ctl(m_eventQueueHandle, EPOLL_CTL_ADD, m_wakeupTrigger, &event); if(res == -1) { - OATPP_LOGD("[oatpp::async::worker::IOEventWorker::initEventQueue()]", "Error. Call to ::epoll_ctl failed. errno=%d", errno); + OATPP_LOGE("[oatpp::async::worker::IOEventWorker::initEventQueue()]", "Error. Call to ::epoll_ctl failed. errno=%d", errno); throw std::runtime_error("[oatpp::async::worker::IOEventWorker::initEventQueue()]: Error. Call to ::epoll_ctl() failed."); } @@ -98,7 +98,7 @@ void IOEventWorker::setCoroutineEvent(AbstractCoroutine* coroutine, int operatio case Action::TYPE_IO_REPEAT: break; default: - OATPP_LOGD("[oatpp::async::worker::IOEventWorker::pushCoroutineToQueue()]", "Error. Unknown Action. action.getType()==%d", action.getType()); + OATPP_LOGE("[oatpp::async::worker::IOEventWorker::pushCoroutineToQueue()]", "Error. Unknown Action. action.getType()==%d", action.getType()); throw std::runtime_error("[oatpp::async::worker::IOEventWorker::pushCoroutineToQueue()]: Error. Unknown Action."); } @@ -125,7 +125,7 @@ void IOEventWorker::setCoroutineEvent(AbstractCoroutine* coroutine, int operatio auto res = epoll_ctl(m_eventQueueHandle, operation, action.getIOHandle(), &event); if(res == -1) { - OATPP_LOGD("[oatpp::async::worker::IOEventWorker::setEpollEvent()]", "Error. Call to epoll_ctl failed. operation=%d, errno=%d", operation, errno); + OATPP_LOGE("[oatpp::async::worker::IOEventWorker::setEpollEvent()]", "Error. Call to epoll_ctl failed. operation=%d, errno=%d", operation, errno); throw std::runtime_error("[oatpp::async::worker::IOEventWorker::setEpollEvent()]: Error. Call to epoll_ctl failed."); } @@ -153,7 +153,7 @@ void IOEventWorker::waitEvents() { auto eventsCount = epoll_wait(m_eventQueueHandle, outEvents, MAX_EVENTS, -1); if(eventsCount < 0) { - OATPP_LOGD("[oatpp::async::worker::IOEventWorker::waitEvents()]", "Error. errno=%d", errno); + OATPP_LOGE("[oatpp::async::worker::IOEventWorker::waitEvents()]", "Error. errno=%d", errno); throw std::runtime_error("[oatpp::async::worker::IOEventWorker::waitEvents()]: Error. Event loop failed."); } @@ -204,7 +204,7 @@ void IOEventWorker::waitEvents() { res = epoll_ctl(m_eventQueueHandle, EPOLL_CTL_DEL, action.getIOHandle(), nullptr); if(res == -1) { - OATPP_LOGD( + OATPP_LOGE( "[oatpp::async::worker::IOEventWorker::waitEvents()]", "Error. Call to epoll_ctl failed. operation=%d, errno=%d. action_code=%d, worker_specialization=%d", EPOLL_CTL_DEL, errno, action.getIOEventCode(), m_specialization @@ -221,7 +221,7 @@ void IOEventWorker::waitEvents() { res = epoll_ctl(m_eventQueueHandle, EPOLL_CTL_DEL, action.getIOHandle(), nullptr); if(res == -1) { - OATPP_LOGD( + OATPP_LOGE( "[oatpp::async::worker::IOEventWorker::waitEvents()]", "Error. Call to epoll_ctl failed. operation=%d, errno=%d. action_code=%d, worker_specialization=%d", EPOLL_CTL_DEL, errno, action.getIOEventCode(), m_specialization @@ -241,7 +241,7 @@ void IOEventWorker::waitEvents() { res = epoll_ctl(m_eventQueueHandle, EPOLL_CTL_DEL, prevAction.getIOHandle(), nullptr); if(res == -1) { - OATPP_LOGD("[oatpp::async::worker::IOEventWorker::waitEvents()]", "Error. Call to epoll_ctl failed. operation=%d, errno=%d", EPOLL_CTL_DEL, errno); + OATPP_LOGE("[oatpp::async::worker::IOEventWorker::waitEvents()]", "Error. Call to epoll_ctl failed. operation=%d, errno=%d", EPOLL_CTL_DEL, errno); throw std::runtime_error("[oatpp::async::worker::IOEventWorker::waitEvents()]: Error. Call to epoll_ctl failed."); } diff --git a/src/oatpp/core/async/worker/IOEventWorker_kqueue.cpp b/src/oatpp/core/async/worker/IOEventWorker_kqueue.cpp index a9d116af..24845a54 100644 --- a/src/oatpp/core/async/worker/IOEventWorker_kqueue.cpp +++ b/src/oatpp/core/async/worker/IOEventWorker_kqueue.cpp @@ -45,7 +45,7 @@ void IOEventWorker::initEventQueue() { m_outEvents = std::unique_ptr(new (std::nothrow) v_char8[MAX_EVENTS * sizeof(struct kevent)]); if(!m_outEvents) { - OATPP_LOGD("[oatpp::async::worker::IOEventWorker::initEventQueue()]", + OATPP_LOGE("[oatpp::async::worker::IOEventWorker::initEventQueue()]", "Error. Unable to allocate %d bytes for events.", MAX_EVENTS * sizeof(struct kevent)); throw std::runtime_error("[oatpp::async::worker::IOEventWorker::initEventQueue()]: Error. Unable to allocate memory for events."); } @@ -130,7 +130,7 @@ void IOEventWorker::consumeBacklog() { m_inEvents = std::unique_ptr(new (std::nothrow) v_char8[m_inEventsCapacity * sizeof(struct kevent)]); if(!m_inEvents) { - OATPP_LOGD("[oatpp::async::worker::IOEventWorker::consumeBacklog()]", + OATPP_LOGE("[oatpp::async::worker::IOEventWorker::consumeBacklog()]", "Error. Unable to allocate %d bytes for events.", m_inEventsCapacity * sizeof(struct kevent)); throw std::runtime_error("[oatpp::async::worker::IOEventWorker::consumeBacklog()]: Error. Unable to allocate memory for events."); } diff --git a/src/oatpp/core/base/Config.hpp b/src/oatpp/core/base/Config.hpp index e3bd77b7..4d30eb35 100644 --- a/src/oatpp/core/base/Config.hpp +++ b/src/oatpp/core/base/Config.hpp @@ -64,17 +64,17 @@ #endif /** - * DISABLE logs level V + * DISABLE logs priority V */ //#define OATPP_DISABLE_LOGV /** - * DISABLE logs level D + * DISABLE logs priority D */ //#define OATPP_DISABLE_LOGD /** - * DISABLE logs level E + * DISABLE logs priority E */ //#define OATPP_DISABLE_LOGE diff --git a/src/oatpp/core/base/Environment.cpp b/src/oatpp/core/base/Environment.cpp index 9965f695..1d0e0b4b 100644 --- a/src/oatpp/core/base/Environment.cpp +++ b/src/oatpp/core/base/Environment.cpp @@ -23,13 +23,17 @@ ***************************************************************************/ #include "Environment.hpp" + +#include +#include #include #include +#include #include namespace oatpp { namespace base { -Logger* Environment::m_logger = nullptr; +std::shared_ptr Environment::m_logger; std::unordered_map> Environment::m_components; v_atomicCounter Environment::m_objectsCount(0); @@ -37,7 +41,77 @@ v_atomicCounter Environment::m_objectsCreated(0); thread_local v_counter Environment::m_threadLocalObjectsCount = 0; thread_local v_counter Environment::m_threadLocalObjectsCreated = 0; -void Environment::init(){ + +DefaultLogger::DefaultLogger(const Config& config) + : m_config(config) +{} + +void DefaultLogger::log(v_int32 priority, const std::string& tag, const std::string& message) { + + bool indent = false; + + auto ticks = Environment::getMicroTickCount(); + std::time_t time = std::time(nullptr); + + std::lock_guard lock(m_lock); + + switch (priority) { + case PRIORITY_V: + std::cout << "\033[0;0m V \033[0m|"; + break; + + case PRIORITY_D: + std::cout << "\033[34;0m D \033[0m|"; + break; + + case PRIORITY_I: + std::cout << "\033[32;0m I \033[0m|"; + break; + + case PRIORITY_W: + std::cout << "\033[45;0m W \033[0m|"; + break; + + case PRIORITY_E: + std::cout << "\033[41;0m E \033[0m|"; + break; + + default: + std::cout << " " << priority << " |"; + } + + if(m_config.printTime) { + const char* time_fmt = "%Y-%m-%d %H:%M:%S"; + std::tm tm = *std::localtime(&time); + std::cout << std::put_time(&tm, time_fmt); + indent = true; + } + + if(m_config.printTicks) { + if(indent) { + std::cout << " " << ticks; + } else { + std::cout << ticks; + indent = true; + } + } + + if(indent) { + std::cout << "|"; + } + std::cout << " " << tag << ":" << message << "\n"; + +} + + +void Environment::init() { + init(std::make_shared()); +} + +void Environment::init(const std::shared_ptr& logger) { + + m_logger = logger; + checkTypes(); m_objectsCount = 0; @@ -48,12 +122,14 @@ void Environment::init(){ if(m_components.size() > 0) { throw std::runtime_error("[oatpp::base::Environment]: Invalid state. Components were created before call to Environment::init()"); } + } void Environment::destroy(){ if(m_components.size() > 0) { throw std::runtime_error("[oatpp::base::Environment]: Invalid state. Leaking components"); } + m_logger.reset(); } void Environment::checkTypes(){ @@ -107,13 +183,14 @@ v_counter Environment::getThreadLocalObjectsCreated(){ return m_threadLocalObjectsCreated; } -void Environment::setLogger(Logger* logger){ - delete m_logger; +void Environment::setLogger(const std::shared_ptr& logger){ m_logger = logger; } void Environment::printCompilationConfig() { + OATPP_LOGD("oatpp-version", OATPP_VERSION); + #ifdef OATPP_DISABLE_ENV_OBJECT_COUNTERS OATPP_LOGD("oatpp/Config", "OATPP_DISABLE_ENV_OBJECT_COUNTERS"); #endif diff --git a/src/oatpp/core/base/Environment.hpp b/src/oatpp/core/base/Environment.hpp index 903014eb..916e9d1f 100644 --- a/src/oatpp/core/base/Environment.hpp +++ b/src/oatpp/core/base/Environment.hpp @@ -32,8 +32,8 @@ #include #include #include +#include #include - #include #define OATPP_VERSION "0.19.4" @@ -74,9 +74,34 @@ namespace oatpp { namespace base{ /** * Interface for system-wide Logger.
- * All calls to `OATPP_DISABLE_LOGV`, `OATPP_DISABLE_LOGE`, `OATPP_DISABLE_LOGD` should come here. + * All calls to `OATPP_DISABLE_LOGV`, `OATPP_DISABLE_LOGE`, `OATPP_DISABLE_LOGD` will come here. */ class Logger { +public: + /** + * Log priority V-verbouse. + */ + static constexpr v_int32 PRIORITY_V = 0; + + /** + * Log priority D-debug. + */ + static constexpr v_int32 PRIORITY_D = 1; + + /** + * Log priority I-Info. + */ + static constexpr v_int32 PRIORITY_I = 2; + + /** + * Log priority W-Warning. + */ + static constexpr v_int32 PRIORITY_W = 3; + + /** + * Log priority E-error. + */ + static constexpr v_int32 PRIORITY_E = 4; public: /** * Virtual Destructor. @@ -92,6 +117,45 @@ public: virtual void log(v_int32 priority, const std::string& tag, const std::string& message) = 0; }; +/** + * Default Logger implementation. + */ +class DefaultLogger : public Logger { +public: + /** + * Default Logger Config. + */ + struct Config { + /** + * Print time of the log message. + */ + bool printTime; + + /** + * Print micro-ticks in the log message. + */ + bool printTicks; + }; +private: + Config m_config; + std::mutex m_lock; +public: + + /** + * Constructor. + * @param config - Logger config. + */ + DefaultLogger(const Config& config = {true, false}); + + /** + * Log message with priority, tag, message. + * @param priority - log-priority channel of the message. + * @param tag - tag of the log message. + * @param message - message. + */ + void log(v_int32 priority, const std::string& tag, const std::string& message) override; +}; + /** * Class to manage application environment.
* Manage object counters, manage components, and do system health-checks. @@ -103,7 +167,7 @@ private: static thread_local v_counter m_threadLocalObjectsCount; static thread_local v_counter m_threadLocalObjectsCreated; private: - static Logger* m_logger; + static std::shared_ptr m_logger; static void checkTypes(); private: static std::unordered_map> m_components; @@ -169,6 +233,12 @@ public: */ static void init(); + /** + * Initialize environment and do basic health-checks. + * @param logger - system-wide logger. + */ + static void init(const std::shared_ptr& logger); + /** * De-initialize environment and do basic health-checks. * Check for memory leaks. @@ -211,9 +281,9 @@ public: /** * Set environment logger. - * @param logger - pointer to logger. + * @param logger - system-wide logger. */ - static void setLogger(Logger* logger); + static void setLogger(const std::shared_ptr& logger); /** * Print debug information of compilation config.
@@ -228,7 +298,7 @@ public: /** * Call `Logger::log()` - * @param priority - priority channel of the message. + * @param priority - log-priority channel of the message. * @param tag - tag of the log message. * @param message - message. */ @@ -237,7 +307,7 @@ public: /** * Format message and call `Logger::log()`
* Message is formatted using `vsnprintf` method. - * @param priority - priority channel of the message. + * @param priority - log-priority channel of the message. * @param tag - tag of the log message. * @param message - message. * @param ... - format arguments. @@ -274,19 +344,31 @@ if(!(EXP)) { \ } #ifndef OATPP_DISABLE_LOGV - #define OATPP_LOGV(TAG, ...) oatpp::base::Environment::logFormatted(0, TAG, __VA_ARGS__); + #define OATPP_LOGV(TAG, ...) oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_V, TAG, __VA_ARGS__); #else #define OATPP_LOGV(TAG, ...) #endif #ifndef OATPP_DISABLE_LOGD - #define OATPP_LOGD(TAG, ...) oatpp::base::Environment::logFormatted(1, TAG, __VA_ARGS__); + #define OATPP_LOGD(TAG, ...) oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_D, TAG, __VA_ARGS__); #else #define OATPP_LOGD(TAG, ...) #endif - + +#ifndef OATPP_DISABLE_LOGI + #define OATPP_LOGI(TAG, ...) oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_I, TAG, __VA_ARGS__); +#else + #define OATPP_LOGI(TAG, ...) +#endif + +#ifndef OATPP_DISABLE_LOGW + #define OATPP_LOGW(TAG, ...) oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_W, TAG, __VA_ARGS__); +#else + #define OATPP_LOGW(TAG, ...) +#endif + #ifndef OATPP_DISABLE_LOGE - #define OATPP_LOGE(TAG, ...) oatpp::base::Environment::logFormatted(2, TAG, __VA_ARGS__); + #define OATPP_LOGE(TAG, ...) oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_E, TAG, __VA_ARGS__); #else #define OATPP_LOGE(TAG, ...) #endif diff --git a/test/oatpp/AllTestsMain.cpp b/test/oatpp/AllTestsMain.cpp index 0aed9e05..3ad9c02b 100644 --- a/test/oatpp/AllTestsMain.cpp +++ b/test/oatpp/AllTestsMain.cpp @@ -120,13 +120,9 @@ void runTests() { int main() { oatpp::base::Environment::init(); - oatpp::base::Environment::setLogger(new Logger()); runTests(); - oatpp::base::Environment::setLogger(nullptr); - oatpp::base::Environment::destroy(); - /* Print how much objects were created during app running, and what have left-probably leaked */ /* Disable object counting for release builds using '-D OATPP_DISABLE_ENV_OBJECT_COUNTERS' flag for better performance */ std::cout << "\nEnvironment:\n"; diff --git a/test/oatpp/core/base/memory/MemoryPoolTest.cpp b/test/oatpp/core/base/memory/MemoryPoolTest.cpp index 533f7a96..c17ce871 100644 --- a/test/oatpp/core/base/memory/MemoryPoolTest.cpp +++ b/test/oatpp/core/base/memory/MemoryPoolTest.cpp @@ -127,7 +127,7 @@ void testPool(v_int32 objectsNumber, v_int32 garbageNumber, v_int32 chunkSize){ OATPP_ASSERT(objects[i]->a == -100); } #else - OATPP_LOGV("TEST[base::memory::MemoryPoolTest]", "\033[35mWARNING. 'OATPP_DISABLE_POOL_ALLOCATIONS' flag is ON. Assertions disabled.\033[0m"); + OATPP_LOGI("TEST[base::memory::MemoryPoolTest]", "WARNING. 'OATPP_DISABLE_POOL_ALLOCATIONS' flag is ON. Assertions disabled."); #endif delete [] objects; diff --git a/test/oatpp/core/data/mapping/type/TypeTest.cpp b/test/oatpp/core/data/mapping/type/TypeTest.cpp index 8095f7e9..21960056 100644 --- a/test/oatpp/core/data/mapping/type/TypeTest.cpp +++ b/test/oatpp/core/data/mapping/type/TypeTest.cpp @@ -69,52 +69,52 @@ void TypeTest::onRun() { auto obj = TestDto::createShared(); - OATPP_LOGD(TAG, "type: '%s'", obj->_string.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_string.valueType->name); OATPP_ASSERT(obj->_string.valueType->name == oatpp::data::mapping::type::__class::String::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_int8.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_int8.valueType->name); OATPP_ASSERT(obj->_int8.valueType->name == oatpp::data::mapping::type::__class::Int8::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_int16.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_int16.valueType->name); OATPP_ASSERT(obj->_int16.valueType->name == oatpp::data::mapping::type::__class::Int16::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_int32.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_int32.valueType->name); OATPP_ASSERT(obj->_int32.valueType->name == oatpp::data::mapping::type::__class::Int32::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_int64.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_int64.valueType->name); OATPP_ASSERT(obj->_int64.valueType->name == oatpp::data::mapping::type::__class::Int64::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_float32.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_float32.valueType->name); OATPP_ASSERT(obj->_float32.valueType->name == oatpp::data::mapping::type::__class::Float32::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_float64.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_float64.valueType->name); OATPP_ASSERT(obj->_float64.valueType->name == oatpp::data::mapping::type::__class::Float64::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_boolean.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_boolean.valueType->name); OATPP_ASSERT(obj->_boolean.valueType->name == oatpp::data::mapping::type::__class::Boolean::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_list_string.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_list_string.valueType->name); OATPP_ASSERT(obj->_list_string.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_list_int32.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_list_int32.valueType->name); OATPP_ASSERT(obj->_list_int32.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_list_int64.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_list_int64.valueType->name); OATPP_ASSERT(obj->_list_int64.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_list_float32.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_list_float32.valueType->name); OATPP_ASSERT(obj->_list_float32.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_list_float64.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_list_float64.valueType->name); OATPP_ASSERT(obj->_list_float64.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_list_boolean.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_list_boolean.valueType->name); OATPP_ASSERT(obj->_list_boolean.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->_map_string_string.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->_map_string_string.valueType->name); OATPP_ASSERT(obj->_map_string_string.valueType->name == oatpp::data::mapping::type::__class::AbstractListMap::CLASS_NAME); - OATPP_LOGD(TAG, "type: '%s'", obj->obj1.valueType->name); + OATPP_LOGV(TAG, "type: '%s'", obj->obj1.valueType->name); OATPP_ASSERT(obj->obj1.valueType->name == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME); } diff --git a/test/oatpp/core/data/stream/ChunkedBufferTest.cpp b/test/oatpp/core/data/stream/ChunkedBufferTest.cpp index a039db46..fd0fdf1a 100644 --- a/test/oatpp/core/data/stream/ChunkedBufferTest.cpp +++ b/test/oatpp/core/data/stream/ChunkedBufferTest.cpp @@ -39,7 +39,7 @@ void ChunkedBufferTest::onRun() { stream << "int=" << 1 << ", float=" << 1.1 << ", " << "bool=" << true << " or " << false; - OATPP_LOGD(TAG, "str='%s'", stream.toString()->c_str()); + OATPP_LOGV(TAG, "str='%s'", stream.toString()->c_str()); stream.clear(); stream << 101; diff --git a/test/oatpp/encoding/Base64Test.cpp b/test/oatpp/encoding/Base64Test.cpp index 868a1586..f42109af 100644 --- a/test/oatpp/encoding/Base64Test.cpp +++ b/test/oatpp/encoding/Base64Test.cpp @@ -35,7 +35,7 @@ void Base64Test::onRun() { { oatpp::String encoded = oatpp::encoding::Base64::encode(message); - OATPP_LOGD(TAG, "encoded='%s'", encoded->c_str()); + OATPP_LOGV(TAG, "encoded='%s'", encoded->c_str()); OATPP_ASSERT(encoded->equals(messageEncoded.get())); oatpp::String decoded = oatpp::encoding::Base64::decode(encoded); OATPP_ASSERT(message->equals(decoded.get())); @@ -43,7 +43,7 @@ void Base64Test::onRun() { { oatpp::String encoded = oatpp::encoding::Base64::encode(message, oatpp::encoding::Base64::ALPHABET_BASE64_URL_SAFE); - OATPP_LOGD(TAG, "encoded='%s'", encoded->c_str()); + OATPP_LOGV(TAG, "encoded='%s'", encoded->c_str()); oatpp::String decoded = oatpp::encoding::Base64::decode(encoded, oatpp::encoding::Base64::ALPHABET_BASE64_URL_SAFE_AUXILIARY_CHARS); OATPP_ASSERT(message->equals(decoded.get())); } diff --git a/test/oatpp/encoding/UnicodeTest.cpp b/test/oatpp/encoding/UnicodeTest.cpp index 6a58ac84..53445f4d 100644 --- a/test/oatpp/encoding/UnicodeTest.cpp +++ b/test/oatpp/encoding/UnicodeTest.cpp @@ -50,7 +50,7 @@ void writeBinaryInt(v_int32 value){ } } - OATPP_LOGD("bin", "value='%s'", (const char*) &buff); + OATPP_LOGV("bin", "value='%s'", (const char*) &buff); } diff --git a/test/oatpp/network/UrlTest.cpp b/test/oatpp/network/UrlTest.cpp index 8641d541..5b4fe985 100644 --- a/test/oatpp/network/UrlTest.cpp +++ b/test/oatpp/network/UrlTest.cpp @@ -36,7 +36,7 @@ void UrlTest::onRun() { { const char* urlText = "http://root@127.0.0.1:8000/path/to/resource/?q1=1&q2=2"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto url = Url::Parser::parseUrl(urlText); OATPP_ASSERT(url.scheme && url.scheme == "http"); @@ -51,7 +51,7 @@ void UrlTest::onRun() { { const char* urlText = "ftp://root@oatpp.io:8000/path/to/resource?q1=1&q2=2"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto url = Url::Parser::parseUrl(urlText); OATPP_ASSERT(url.scheme && url.scheme == "ftp"); @@ -66,7 +66,7 @@ void UrlTest::onRun() { { const char* urlText = "https://oatpp.io/?q1=1&q2=2"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto url = Url::Parser::parseUrl(urlText); OATPP_ASSERT(url.scheme && url.scheme == "https"); @@ -81,7 +81,7 @@ void UrlTest::onRun() { { const char* urlText = "https://oatpp.io/"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto url = Url::Parser::parseUrl(urlText); OATPP_ASSERT(url.scheme && url.scheme == "https"); @@ -94,7 +94,7 @@ void UrlTest::onRun() { { const char* urlText = "https://oatpp.io"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto url = Url::Parser::parseUrl(urlText); OATPP_ASSERT(url.scheme && url.scheme == "https"); @@ -107,7 +107,7 @@ void UrlTest::onRun() { { const char* urlText = "oatpp.io"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto url = Url::Parser::parseUrl(urlText); OATPP_ASSERT(url.scheme == nullptr); @@ -120,7 +120,7 @@ void UrlTest::onRun() { { const char* urlText = "?key1=value1&key2=value2&key3=value3"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto params = Url::Parser::parseQueryParams(urlText); OATPP_ASSERT(params.size() == 3); OATPP_ASSERT(params["key1"] == "value1"); @@ -130,7 +130,7 @@ void UrlTest::onRun() { { const char *urlText = "?key1=value1&key2&key3=value3"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto params = Url::Parser::parseQueryParams(urlText); OATPP_ASSERT(params.size() == 3); OATPP_ASSERT(params["key1"] == "value1"); @@ -140,7 +140,7 @@ void UrlTest::onRun() { { const char *urlText = "?key1=value1&key2&key3"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto params = Url::Parser::parseQueryParams(urlText); OATPP_ASSERT(params.size() == 3); OATPP_ASSERT(params["key1"] == "value1"); @@ -150,7 +150,7 @@ void UrlTest::onRun() { { const char *urlText = "label?key1=value1&key2=value2&key3=value3"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto params = Url::Parser::labelQueryParams(urlText); OATPP_ASSERT(params.size() == 3); OATPP_ASSERT(params["key1"] == "value1"); @@ -160,7 +160,7 @@ void UrlTest::onRun() { { const char* urlText = "label?key1=value1&key2&key3=value3"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto params = Url::Parser::labelQueryParams(urlText); OATPP_ASSERT(params.size() == 3); OATPP_ASSERT(params["key1"] == "value1"); @@ -170,7 +170,7 @@ void UrlTest::onRun() { { const char* urlText = "label?key1=value1&key2&key3"; - OATPP_LOGD(TAG, "urlText='%s'", urlText); + OATPP_LOGV(TAG, "urlText='%s'", urlText); auto params = Url::Parser::labelQueryParams(urlText); OATPP_ASSERT(params.size() == 3); OATPP_ASSERT(params["key1"] == "value1"); diff --git a/test/oatpp/network/virtual_/InterfaceTest.cpp b/test/oatpp/network/virtual_/InterfaceTest.cpp index 4b6fccc5..ff0aec1c 100644 --- a/test/oatpp/network/virtual_/InterfaceTest.cpp +++ b/test/oatpp/network/virtual_/InterfaceTest.cpp @@ -66,7 +66,7 @@ namespace { OATPP_ASSERT(stream->getSize() == res); OATPP_ASSERT(stream->toString() == "OK"); - //OATPP_LOGD("client", "finished - OK"); + //OATPP_LOGV("client", "finished - OK"); } diff --git a/test/oatpp/network/virtual_/PipeTest.cpp b/test/oatpp/network/virtual_/PipeTest.cpp index 16bba088..291a14a3 100644 --- a/test/oatpp/network/virtual_/PipeTest.cpp +++ b/test/oatpp/network/virtual_/PipeTest.cpp @@ -66,7 +66,7 @@ namespace { } } } - OATPP_LOGD("WriterTask", "sent %d bytes", m_transferedBytes); + OATPP_LOGV("WriterTask", "sent %d bytes", m_transferedBytes); } }; @@ -94,14 +94,14 @@ namespace { m_buffer->write(readBuffer, res); } } - OATPP_LOGD("ReaderTask", "sent %d bytes", m_buffer->getSize()); + OATPP_LOGV("ReaderTask", "sent %d bytes", m_buffer->getSize()); } }; void runTransfer(const std::shared_ptr& pipe, v_int32 chunksToTransfer, bool writeNonBlock, bool readerNonBlock) { - OATPP_LOGD("transfer", "writer-nb: %d, reader-nb: %d", writeNonBlock, readerNonBlock); + OATPP_LOGV("transfer", "writer-nb: %d, reader-nb: %d", writeNonBlock, readerNonBlock); auto buffer = oatpp::data::stream::ChunkedBuffer::createShared(); diff --git a/test/oatpp/parser/json/mapping/DTOMapperTest.cpp b/test/oatpp/parser/json/mapping/DTOMapperTest.cpp index f8df03f8..e0d7218f 100644 --- a/test/oatpp/parser/json/mapping/DTOMapperTest.cpp +++ b/test/oatpp/parser/json/mapping/DTOMapperTest.cpp @@ -159,11 +159,11 @@ void DTOMapperTest::onRun(){ auto result = mapper->writeToString(test1); - OATPP_LOGD(TAG, "json='%s'", (const char*) result->getData()); + OATPP_LOGV(TAG, "json='%s'", (const char*) result->getData()); - OATPP_LOGD(TAG, "..."); - OATPP_LOGD(TAG, "..."); - OATPP_LOGD(TAG, "..."); + OATPP_LOGV(TAG, "..."); + OATPP_LOGV(TAG, "..."); + OATPP_LOGV(TAG, "..."); oatpp::parser::Caret caret(result); auto obj = mapper->readFromCaret(caret); @@ -188,7 +188,7 @@ void DTOMapperTest::onRun(){ result = mapper->writeToString(obj); - OATPP_LOGD(TAG, "json='%s'", (const char*) result->getData()); + OATPP_LOGV(TAG, "json='%s'", (const char*) result->getData()); } diff --git a/test/oatpp/web/FullAsyncClientTest.cpp b/test/oatpp/web/FullAsyncClientTest.cpp index 9935ced9..11ec901b 100644 --- a/test/oatpp/web/FullAsyncClientTest.cpp +++ b/test/oatpp/web/FullAsyncClientTest.cpp @@ -150,9 +150,9 @@ public: Action handleError(const std::shared_ptr& error) override { if(error->is()) { auto e = static_cast(error.get()); - OATPP_LOGD("[FullAsyncClientTest::ClientCoroutine_echoBodyAsync::handleError()]", "AsyncIOError. %s, %d", e->what(), e->getCode()); + OATPP_LOGE("[FullAsyncClientTest::ClientCoroutine_echoBodyAsync::handleError()]", "AsyncIOError. %s, %d", e->what(), e->getCode()); } else { - OATPP_LOGD("[FullAsyncClientTest::ClientCoroutine_echoBodyAsync::handleError()]", "Error. %s", error->what()); + OATPP_LOGE("[FullAsyncClientTest::ClientCoroutine_echoBodyAsync::handleError()]", "Error. %s", error->what()); } return propagateError(); } @@ -196,9 +196,9 @@ public: if(error) { if(error->is()) { auto e = static_cast(error.get()); - OATPP_LOGD("[FullAsyncClientTest::ClientCoroutine_echoBodyAsync::handleError()]", "AsyncIOError. %s, %d", e->what(), e->getCode()); + OATPP_LOGE("[FullAsyncClientTest::ClientCoroutine_echoBodyAsync::handleError()]", "AsyncIOError. %s, %d", e->what(), e->getCode()); } else { - OATPP_LOGD("[FullAsyncClientTest::ClientCoroutine_echoBodyAsync::handleError()]", "Error. %s", error->what()); + OATPP_LOGE("[FullAsyncClientTest::ClientCoroutine_echoBodyAsync::handleError()]", "Error. %s", error->what()); } } return propagateError(); @@ -237,7 +237,7 @@ void FullAsyncClientTest::onRun() { ClientCoroutine_echoBodyAsync::SUCCESS_COUNTER != -1 ) { - OATPP_LOGD("Client", "Root=%d, Body=%d", + OATPP_LOGV("Client", "Root=%d, Body=%d", ClientCoroutine_getRootAsync::SUCCESS_COUNTER.load(), ClientCoroutine_echoBodyAsync::SUCCESS_COUNTER.load() ); @@ -245,11 +245,11 @@ void FullAsyncClientTest::onRun() { std::this_thread::sleep_for(std::chrono::milliseconds(100)); if(ClientCoroutine_getRootAsync::SUCCESS_COUNTER == iterations){ ClientCoroutine_getRootAsync::SUCCESS_COUNTER = -1; - OATPP_LOGD("Client", "getRootAsync - DONE!"); + OATPP_LOGV("Client", "getRootAsync - DONE!"); } if(ClientCoroutine_echoBodyAsync::SUCCESS_COUNTER == iterations){ ClientCoroutine_echoBodyAsync::SUCCESS_COUNTER = -1; - OATPP_LOGD("Client", "echoBodyAsync - DONE!"); + OATPP_LOGV("Client", "echoBodyAsync - DONE!"); } } diff --git a/test/oatpp/web/FullAsyncTest.cpp b/test/oatpp/web/FullAsyncTest.cpp index 20c7ece2..8d19bedc 100644 --- a/test/oatpp/web/FullAsyncTest.cpp +++ b/test/oatpp/web/FullAsyncTest.cpp @@ -140,7 +140,7 @@ void FullAsyncTest::onRun() { for(v_int32 i = 0; i < iterationsStep * 10; i ++) { - //OATPP_LOGD("i", "%d", i); + //OATPP_LOGV("i", "%d", i); { // test simple GET auto response = client->getRoot(connection); @@ -191,7 +191,7 @@ void FullAsyncTest::onRun() { if((i + 1) % iterationsStep == 0) { auto ticks = oatpp::base::Environment::getMicroTickCount() - lastTick; lastTick = oatpp::base::Environment::getMicroTickCount(); - OATPP_LOGD("i", "%d, tick=%d", i + 1, ticks); + OATPP_LOGV("i", "%d, tick=%d", i + 1, ticks); } } diff --git a/test/oatpp/web/FullTest.cpp b/test/oatpp/web/FullTest.cpp index 9ea7c038..7fdc4e38 100644 --- a/test/oatpp/web/FullTest.cpp +++ b/test/oatpp/web/FullTest.cpp @@ -207,7 +207,7 @@ void FullTest::onRun() { if((i + 1) % iterationsStep == 0) { auto ticks = oatpp::base::Environment::getMicroTickCount() - lastTick; lastTick = oatpp::base::Environment::getMicroTickCount(); - OATPP_LOGD("i", "%d, tick=%d", i + 1, ticks); + OATPP_LOGV("i", "%d, tick=%d", i + 1, ticks); } } diff --git a/test/oatpp/web/app/Controller.hpp b/test/oatpp/web/app/Controller.hpp index 2ee991d8..1f0edabf 100644 --- a/test/oatpp/web/app/Controller.hpp +++ b/test/oatpp/web/app/Controller.hpp @@ -52,13 +52,13 @@ public: #include OATPP_CODEGEN_BEGIN(ApiController) ENDPOINT("GET", "/", root) { - //OATPP_LOGD(TAG, "GET '/'"); + //OATPP_LOGV(TAG, "GET '/'"); return createResponse(Status::CODE_200, "Hello World!!!"); } ENDPOINT("GET", "params/{param}", getWithParams, PATH(String, param)) { - //OATPP_LOGD(TAG, "GET params/%s", param->c_str()); + //OATPP_LOGV(TAG, "GET params/%s", param->c_str()); auto dto = TestDto::createShared(); dto->testValue = param; return createDtoResponse(Status::CODE_200, dto); @@ -83,7 +83,7 @@ public: ENDPOINT("GET", "headers", getWithHeaders, HEADER(String, param, "X-TEST-HEADER")) { - //OATPP_LOGD(TAG, "GET headers {X-TEST-HEADER: %s}", param->c_str()); + //OATPP_LOGV(TAG, "GET headers {X-TEST-HEADER: %s}", param->c_str()); auto dto = TestDto::createShared(); dto->testValue = param; return createDtoResponse(Status::CODE_200, dto); @@ -91,7 +91,7 @@ public: ENDPOINT("POST", "body", postBody, BODY_STRING(String, body)) { - //OATPP_LOGD(TAG, "POST body %s", body->c_str()); + //OATPP_LOGV(TAG, "POST body %s", body->c_str()); auto dto = TestDto::createShared(); dto->testValue = body; return createDtoResponse(Status::CODE_200, dto); @@ -99,7 +99,7 @@ public: ENDPOINT("POST", "echo", echo, BODY_STRING(String, body)) { - //OATPP_LOGD(TAG, "POST body(echo) size=%d", body->getSize()); + //OATPP_LOGV(TAG, "POST body(echo) size=%d", body->getSize()); return createResponse(Status::CODE_200, body); } diff --git a/test/oatpp/web/app/ControllerAsync.hpp b/test/oatpp/web/app/ControllerAsync.hpp index b6c88216..8867369f 100644 --- a/test/oatpp/web/app/ControllerAsync.hpp +++ b/test/oatpp/web/app/ControllerAsync.hpp @@ -54,7 +54,7 @@ public: ENDPOINT_ASYNC_INIT(Root) Action act() { - //OATPP_LOGD(TAG, "GET '/'"); + //OATPP_LOGV(TAG, "GET '/'"); return _return(controller->createResponse(Status::CODE_200, "Hello World Async!!!")); } @@ -66,7 +66,7 @@ public: Action act() { auto param = request->getPathVariable("param"); - //OATPP_LOGD(TAG, "GET params/%s", param->c_str()); + //OATPP_LOGV(TAG, "GET params/%s", param->c_str()); auto dto = TestDto::createShared(); dto->testValue = param; return _return(controller->createDtoResponse(Status::CODE_200, dto)); @@ -80,7 +80,7 @@ public: Action act() { auto param = request->getHeader("X-TEST-HEADER"); - //OATPP_LOGD(TAG, "GET headers {X-TEST-HEADER: %s}", param->c_str()); + //OATPP_LOGV(TAG, "GET headers {X-TEST-HEADER: %s}", param->c_str()); auto dto = TestDto::createShared(); dto->testValue = param; return _return(controller->createDtoResponse(Status::CODE_200, dto)); @@ -93,12 +93,12 @@ public: ENDPOINT_ASYNC_INIT(PostBody) Action act() { - //OATPP_LOGD(TAG, "POST body. Reading body..."); + //OATPP_LOGV(TAG, "POST body. Reading body..."); return request->readBodyToStringAsync().callbackTo(&PostBody::onBodyRead); } Action onBodyRead(const String& body) { - //OATPP_LOGD(TAG, "POST body %s", body->c_str()); + //OATPP_LOGV(TAG, "POST body %s", body->c_str()); auto dto = TestDto::createShared(); dto->testValue = body; return _return(controller->createDtoResponse(Status::CODE_200, dto)); @@ -111,12 +111,12 @@ public: ENDPOINT_ASYNC_INIT(Echo) Action act() { - //OATPP_LOGD(TAG, "POST body(echo). Reading body..."); + //OATPP_LOGV(TAG, "POST body(echo). Reading body..."); return request->readBodyToStringAsync().callbackTo(&Echo::onBodyRead); } Action onBodyRead(const String& body) { - //OATPP_LOGD(TAG, "POST echo size=%d", body->getSize()); + //OATPP_LOGV(TAG, "POST echo size=%d", body->getSize()); return _return(controller->createResponse(Status::CODE_200, body)); } From 7bc8fe2d7938b5b105a6e8740cfddcd73ccf8747 Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Sun, 26 May 2019 16:55:44 +0300 Subject: [PATCH 2/5] show micro-ticks in the logs by default --- src/oatpp/core/base/Environment.hpp | 2 +- test/oatpp/core/base/memory/MemoryPoolTest.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/oatpp/core/base/Environment.hpp b/src/oatpp/core/base/Environment.hpp index 916e9d1f..7d6ca28c 100644 --- a/src/oatpp/core/base/Environment.hpp +++ b/src/oatpp/core/base/Environment.hpp @@ -145,7 +145,7 @@ public: * Constructor. * @param config - Logger config. */ - DefaultLogger(const Config& config = {true, false}); + DefaultLogger(const Config& config = {true, true}); /** * Log message with priority, tag, message. diff --git a/test/oatpp/core/base/memory/MemoryPoolTest.cpp b/test/oatpp/core/base/memory/MemoryPoolTest.cpp index c17ce871..ac9eb682 100644 --- a/test/oatpp/core/base/memory/MemoryPoolTest.cpp +++ b/test/oatpp/core/base/memory/MemoryPoolTest.cpp @@ -127,7 +127,7 @@ void testPool(v_int32 objectsNumber, v_int32 garbageNumber, v_int32 chunkSize){ OATPP_ASSERT(objects[i]->a == -100); } #else - OATPP_LOGI("TEST[base::memory::MemoryPoolTest]", "WARNING. 'OATPP_DISABLE_POOL_ALLOCATIONS' flag is ON. Assertions disabled."); + OATPP_LOGW("TEST[base::memory::MemoryPoolTest]", "WARNING. 'OATPP_DISABLE_POOL_ALLOCATIONS' flag is ON. Assertions disabled."); #endif delete [] objects; From 041eaa5e3a486dcd7c9fe05ddb2577dff72575bc Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Sun, 26 May 2019 20:46:02 +0300 Subject: [PATCH 3/5] fix lgtm Alert --- src/oatpp/core/base/Environment.cpp | 21 ++++++++++----------- src/oatpp/core/base/Environment.hpp | 8 +++++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/oatpp/core/base/Environment.cpp b/src/oatpp/core/base/Environment.cpp index 1d0e0b4b..c3e6adfa 100644 --- a/src/oatpp/core/base/Environment.cpp +++ b/src/oatpp/core/base/Environment.cpp @@ -49,9 +49,7 @@ DefaultLogger::DefaultLogger(const Config& config) void DefaultLogger::log(v_int32 priority, const std::string& tag, const std::string& message) { bool indent = false; - - auto ticks = Environment::getMicroTickCount(); - std::time_t time = std::time(nullptr); + auto time = std::chrono::system_clock::now().time_since_epoch(); std::lock_guard lock(m_lock); @@ -80,20 +78,21 @@ void DefaultLogger::log(v_int32 priority, const std::string& tag, const std::str std::cout << " " << priority << " |"; } - if(m_config.printTime) { - const char* time_fmt = "%Y-%m-%d %H:%M:%S"; - std::tm tm = *std::localtime(&time); - std::cout << std::put_time(&tm, time_fmt); + if(m_config.timeFormat) { + time_t seconds = std::chrono::duration_cast(time).count(); + struct tm now; + localtime_r(&seconds, &now); + std::cout << std::put_time(&now, m_config.timeFormat); indent = true; } if(m_config.printTicks) { + auto ticks = std::chrono::duration_cast(time).count(); if(indent) { - std::cout << " " << ticks; - } else { - std::cout << ticks; - indent = true; + std::cout << " "; } + std::cout << ticks; + indent = true; } if(indent) { diff --git a/src/oatpp/core/base/Environment.hpp b/src/oatpp/core/base/Environment.hpp index 7d6ca28c..b689b427 100644 --- a/src/oatpp/core/base/Environment.hpp +++ b/src/oatpp/core/base/Environment.hpp @@ -127,9 +127,11 @@ public: */ struct Config { /** - * Print time of the log message. + * Time format of the log message. + * If nullptr then do not print time. + * Default value - `%Y-%m-%d %H:%M:%S`. */ - bool printTime; + const char* timeFormat; /** * Print micro-ticks in the log message. @@ -145,7 +147,7 @@ public: * Constructor. * @param config - Logger config. */ - DefaultLogger(const Config& config = {true, true}); + DefaultLogger(const Config& config = {"%Y-%m-%d %H:%M:%S", true}); /** * Log message with priority, tag, message. From e3120343313adb9100fac1b1e1abfc7e9f4cf1fe Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Mon, 27 May 2019 02:22:48 +0300 Subject: [PATCH 4/5] better API-docs --- src/oatpp/core/base/Environment.hpp | 81 ++++++++++++++++++++++++++--- test/oatpp/AllTestsMain.cpp | 14 ----- 2 files changed, 73 insertions(+), 22 deletions(-) diff --git a/src/oatpp/core/base/Environment.hpp b/src/oatpp/core/base/Environment.hpp index b689b427..44a5a4e1 100644 --- a/src/oatpp/core/base/Environment.hpp +++ b/src/oatpp/core/base/Environment.hpp @@ -74,7 +74,8 @@ namespace oatpp { namespace base{ /** * Interface for system-wide Logger.
- * All calls to `OATPP_DISABLE_LOGV`, `OATPP_DISABLE_LOGE`, `OATPP_DISABLE_LOGD` will come here. + * All calls to `OATPP_DISABLE_LOGV`, `OATPP_DISABLE_LOGD`, `OATPP_DISABLE_LOGI`, + * `OATPP_DISABLE_LOGW`, `OATPP_DISABLE_LOGE` will come here. */ class Logger { public: @@ -126,10 +127,20 @@ public: * Default Logger Config. */ struct Config { + + /** + * Constructor. + * @param tfmt - time format. + * @param printMicroTicks - show ticks in microseconds. + */ + Config(const char* tfmt, bool printMicroTicks) + : timeFormat(tfmt) + , printTicks(printMicroTicks) + {} + /** * Time format of the log message. * If nullptr then do not print time. - * Default value - `%Y-%m-%d %H:%M:%S`. */ const char* timeFormat; @@ -147,7 +158,7 @@ public: * Constructor. * @param config - Logger config. */ - DefaultLogger(const Config& config = {"%Y-%m-%d %H:%M:%S", true}); + DefaultLogger(const Config& config = Config("%Y-%m-%d %H:%M:%S", true)); /** * Log message with priority, tag, message. @@ -339,6 +350,10 @@ public: }; +/** + * Default oatpp assert method. + * @param EXP - expression that must be `true`. + */ #define OATPP_ASSERT(EXP) \ if(!(EXP)) { \ OATPP_LOGE("\033[1mASSERT\033[0m[\033[1;31mFAILED\033[0m]", #EXP); \ @@ -346,31 +361,81 @@ if(!(EXP)) { \ } #ifndef OATPP_DISABLE_LOGV - #define OATPP_LOGV(TAG, ...) oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_V, TAG, __VA_ARGS__); + + /** + * Log message with &l:Logger::PRIORITY_V;
+ * *To disable this log compile oatpp with `#define OATPP_DISABLE_LOGV`* + * @param TAG - message tag. + * @param ...(1) - message. + * @param ... - optional format parameter. + */ + #define OATPP_LOGV(TAG, ...) \ + oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_V, TAG, __VA_ARGS__); + #else #define OATPP_LOGV(TAG, ...) #endif #ifndef OATPP_DISABLE_LOGD - #define OATPP_LOGD(TAG, ...) oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_D, TAG, __VA_ARGS__); + + /** + * Log message with &l:Logger::PRIORITY_D;
+ * *To disable this log compile oatpp with `#define OATPP_DISABLE_LOGD`* + * @param TAG - message tag. + * @param ...(1) - message. + * @param ... - optional format parameter. + */ + #define OATPP_LOGD(TAG, ...) \ + oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_D, TAG, __VA_ARGS__); + #else #define OATPP_LOGD(TAG, ...) #endif #ifndef OATPP_DISABLE_LOGI - #define OATPP_LOGI(TAG, ...) oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_I, TAG, __VA_ARGS__); + + /** + * Log message with &l:Logger::PRIORITY_I;
+ * *To disable this log compile oatpp with `#define OATPP_DISABLE_LOGI`* + * @param TAG - message tag. + * @param ...(1) - message. + * @param ... - optional format parameter. + */ + #define OATPP_LOGI(TAG, ...) \ + oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_I, TAG, __VA_ARGS__); + #else #define OATPP_LOGI(TAG, ...) #endif #ifndef OATPP_DISABLE_LOGW - #define OATPP_LOGW(TAG, ...) oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_W, TAG, __VA_ARGS__); + + /** + * Log message with &l:Logger::PRIORITY_W;
+ * *To disable this log compile oatpp with `#define OATPP_DISABLE_LOGW`* + * @param TAG - message tag. + * @param ...(1) - message. + * @param ... - optional format parameter. + */ + #define OATPP_LOGW(TAG, ...) \ + oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_W, TAG, __VA_ARGS__); + #else #define OATPP_LOGW(TAG, ...) #endif #ifndef OATPP_DISABLE_LOGE - #define OATPP_LOGE(TAG, ...) oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_E, TAG, __VA_ARGS__); + + /** + * Log message with &l:Logger::PRIORITY_E;
+ * *To disable this log compile oatpp with `#define OATPP_DISABLE_LOGE`* + * @param TAG - message tag. + * @param ...(1) - message. + * @param ... - optional format parameter. + */ + #define OATPP_LOGE(TAG, ...) \ + oatpp::base::Environment::logFormatted(oatpp::base::Logger::PRIORITY_E, TAG, __VA_ARGS__); + #else #define OATPP_LOGE(TAG, ...) #endif diff --git a/test/oatpp/AllTestsMain.cpp b/test/oatpp/AllTestsMain.cpp index 3ad9c02b..61c9d39d 100644 --- a/test/oatpp/AllTestsMain.cpp +++ b/test/oatpp/AllTestsMain.cpp @@ -39,20 +39,6 @@ #ifdef OATPP_ENABLE_ALL_TESTS_MAIN namespace { -class Logger : public oatpp::base::Logger { -private: - oatpp::concurrency::SpinLock m_lock; -public: - - void log(v_int32 priority, const std::string& tag, const std::string& message) override { - std::lock_guard lock(m_lock); - std::cout << tag << ":" << message << "\n"; - } - -}; - - - void runTests() { oatpp::base::Environment::printCompilationConfig(); From 71630b62b1441cc7c785ea5b780e218b777c2aef Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Tue, 28 May 2019 03:44:08 +0300 Subject: [PATCH 5/5] Better Router API --- src/CMakeLists.txt | 5 +- .../web/server/HttpConnectionHandler.hpp | 2 +- src/oatpp/web/server/HttpProcessor.cpp | 4 +- src/oatpp/web/server/HttpRequestHandler.hpp | 62 +++++++++ src/oatpp/web/server/HttpRouter.cpp | 12 +- src/oatpp/web/server/HttpRouter.hpp | 29 ++-- src/oatpp/web/server/api/ApiController.cpp | 2 +- src/oatpp/web/server/api/ApiController.hpp | 6 +- src/oatpp/web/server/api/Endpoint.hpp | 14 +- src/oatpp/web/url/mapping/Router.cpp | 25 ---- src/oatpp/web/url/mapping/Router.hpp | 125 ++++++------------ src/oatpp/web/url/mapping/Subscriber.cpp | 25 ---- src/oatpp/web/url/mapping/Subscriber.hpp | 58 -------- 13 files changed, 131 insertions(+), 238 deletions(-) create mode 100644 src/oatpp/web/server/HttpRequestHandler.hpp delete mode 100644 src/oatpp/web/url/mapping/Router.cpp delete mode 100644 src/oatpp/web/url/mapping/Subscriber.cpp delete mode 100644 src/oatpp/web/url/mapping/Subscriber.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 826108cc..1113a77e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -187,13 +187,10 @@ add_library(oatpp oatpp/web/server/handler/Interceptor.hpp oatpp/web/url/mapping/Pattern.cpp oatpp/web/url/mapping/Pattern.hpp - oatpp/web/url/mapping/Router.cpp oatpp/web/url/mapping/Router.hpp - oatpp/web/url/mapping/Subscriber.cpp - oatpp/web/url/mapping/Subscriber.hpp oatpp/core/parser/ParsingError.cpp oatpp/core/parser/ParsingError.hpp -) + oatpp/web/server/HttpRequestHandler.hpp) set_target_properties(oatpp PROPERTIES CXX_STANDARD 11 diff --git a/src/oatpp/web/server/HttpConnectionHandler.hpp b/src/oatpp/web/server/HttpConnectionHandler.hpp index bc3ae45a..ef77a4e3 100644 --- a/src/oatpp/web/server/HttpConnectionHandler.hpp +++ b/src/oatpp/web/server/HttpConnectionHandler.hpp @@ -99,7 +99,7 @@ public: void setErrorHandler(const std::shared_ptr& errorHandler); /** - * Set request interceptor. Request intercepted after route is resolved but before corresponding route subscriber is called. + * Set request interceptor. Request intercepted after route is resolved but before corresponding route endpoint is called. * @param interceptor - &id:oatpp::web::server::handler::RequestInterceptor;. */ void addRequestInterceptor(const std::shared_ptr& interceptor); diff --git a/src/oatpp/web/server/HttpProcessor.cpp b/src/oatpp/web/server/HttpProcessor.cpp index e91dce48..e0bc3847 100644 --- a/src/oatpp/web/server/HttpProcessor.cpp +++ b/src/oatpp/web/server/HttpProcessor.cpp @@ -80,7 +80,7 @@ HttpProcessor::processRequest(HttpRouter* router, currInterceptor = currInterceptor->getNext(); } if(!response) { - response = route.processEvent(request); + response = route.getEndpoint()->handle(request); } } catch (oatpp::web::protocol::http::HttpError& error) { return errorHandler->handleError(error.getInfo().status, error.getMessage()); @@ -138,7 +138,7 @@ HttpProcessor::Coroutine::Action HttpProcessor::Coroutine::act() { } HttpProcessor::Coroutine::Action HttpProcessor::Coroutine::onRequestFormed() { - return m_currentRoute.processEventAsync(m_currentRequest).callbackTo(&HttpProcessor::Coroutine::onResponse); + return m_currentRoute.getEndpoint()->handleAsync(m_currentRequest).callbackTo(&HttpProcessor::Coroutine::onResponse); } HttpProcessor::Coroutine::Action HttpProcessor::Coroutine::onResponse(const std::shared_ptr& response) { diff --git a/src/oatpp/web/server/HttpRequestHandler.hpp b/src/oatpp/web/server/HttpRequestHandler.hpp new file mode 100644 index 00000000..0e6712e2 --- /dev/null +++ b/src/oatpp/web/server/HttpRequestHandler.hpp @@ -0,0 +1,62 @@ +/*************************************************************************** + * + * Project _____ __ ____ _ _ + * ( _ ) /__\ (_ _)_| |_ _| |_ + * )(_)( /(__)\ )( (_ _)(_ _) + * (_____)(__)(__)(__) |_| |_| + * + * + * Copyright 2018-present, Leonid Stryzhevskyi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ***************************************************************************/ + +#ifndef oatpp_web_server_HttpRequestHandler_hpp +#define oatpp_web_server_HttpRequestHandler_hpp + +#include "oatpp/web/protocol/http/outgoing/Response.hpp" +#include "oatpp/web/protocol/http/incoming/Request.hpp" + +namespace oatpp { namespace web { namespace server { + +/** + * HTTP request handler. + */ +class HttpRequestHandler { +public: + typedef oatpp::web::protocol::http::incoming::Request IncomingRequest; + typedef oatpp::web::protocol::http::outgoing::Response OutgoingResponse; +public: + + /** + * Handle incoming http request.
+ * *Implement this method.* + * @param request - incoming http request. &id:oatpp::web::protocol::http::incoming::Request;. + * @return - outgoing http response. &id:oatpp::web::protocol::http::outgoing::Response;. + */ + virtual std::shared_ptr handle(const std::shared_ptr& request) = 0; + + /** + * Handle incoming http request in Asynchronous manner.
+ * *Implement this method.* + * @param request - &id:oatpp::web::protocol::http::incoming::Request;. + * @return - &id:oatpp::async::CoroutineStarterForResult; of &id:oatpp::web::protocol::http::outgoing::Response;. + */ + virtual oatpp::async::CoroutineStarterForResult&> + handleAsync(const std::shared_ptr& request) = 0; +}; + +}}} + +#endif // oatpp_web_server_HttpRequestHandler_hpp diff --git a/src/oatpp/web/server/HttpRouter.cpp b/src/oatpp/web/server/HttpRouter.cpp index 7cc40c67..287c9c8c 100644 --- a/src/oatpp/web/server/HttpRouter.cpp +++ b/src/oatpp/web/server/HttpRouter.cpp @@ -41,16 +41,16 @@ std::shared_ptr HttpRouter::createShared() { return std::make_shared(); } -void HttpRouter::addSubscriber(const oatpp::String& method, - const oatpp::String& urlPattern, - const std::shared_ptr& subscriber) { - getBranch(method)->addSubscriber(urlPattern, subscriber); +void HttpRouter::route(const oatpp::String& method, + const oatpp::String& pathPattern, + const std::shared_ptr& handler) { + getBranch(method)->route(pathPattern, handler); } -HttpRouter::BranchRouter::Route HttpRouter::getRoute(const StringKeyLabel& method, const StringKeyLabel& url){ +HttpRouter::BranchRouter::Route HttpRouter::getRoute(const StringKeyLabel& method, const StringKeyLabel& path){ auto it = m_branchMap.find(method); if(it != m_branchMap.end()) { - return m_branchMap[method]->getRoute(url); + return m_branchMap[method]->getRoute(path); } return BranchRouter::Route(); } diff --git a/src/oatpp/web/server/HttpRouter.hpp b/src/oatpp/web/server/HttpRouter.hpp index eb27363e..c22a9885 100644 --- a/src/oatpp/web/server/HttpRouter.hpp +++ b/src/oatpp/web/server/HttpRouter.hpp @@ -25,9 +25,7 @@ #ifndef oatpp_web_server_HttpRouter_hpp #define oatpp_web_server_HttpRouter_hpp -#include "oatpp/web/protocol/http/outgoing/Response.hpp" -#include "oatpp/web/protocol/http/incoming/Request.hpp" - +#include "./HttpRequestHandler.hpp" #include "oatpp/web/url/mapping/Router.hpp" namespace oatpp { namespace web { namespace server { @@ -42,22 +40,11 @@ private: */ typedef oatpp::data::share::StringKeyLabel StringKeyLabel; public: - /** - * &id:oatpp::web::url::mapping::Router; of &id:oatpp::web::protocol::http::incoming::Request; and - * &id:oatpp::web::protocol::http::outgoing::Response;. Meaning router for Subscribers which accept - * incoming request as an input parameter and return outgoing request as an output parameter. - */ - typedef oatpp::web::url::mapping::Router< - std::shared_ptr, - std::shared_ptr - > BranchRouter; /** - * Subscriber which accept - * incoming request as an input parameter and return outgoing request as an output parameter. - * See &l:HttpRouter::BranchRouter;. + * &id:oatpp::web::url::mapping::Router; of &id:oatpp::web::server::HttpRequestHandler;. */ - typedef BranchRouter::UrlSubscriber Subscriber; + typedef oatpp::web::url::mapping::Router BranchRouter; /** * Http method to &l:HttpRouter::BranchRouter; map. @@ -84,12 +71,12 @@ public: static std::shared_ptr createShared(); /** - * Add url pattern Subscriber (handler for all requests resolved by specified url-pattern). + * Route URL to Handler by method, and pathPattern. * @param method - http method like ["GET", "POST", etc.]. - * @param urlPattern - url path pattern. ex.: `"/path/to/resource/with/{param1}/{param2}"`. - * @param subscriber - &l:HttpRouter::Subscriber;. + * @param pathPattern - url path pattern. ex.: `"/path/to/resource/with/{param1}/{param2}"`. + * @param handler - &id:oatpp::web::server::HttpRequestHandler;. */ - void addSubscriber(const oatpp::String& method, const oatpp::String& urlPattern, const std::shared_ptr& subscriber); + void route(const oatpp::String& method, const oatpp::String& pathPattern, const std::shared_ptr& handler); /** * Resolve http method and path to &id:oatpp::web::url::mapping::Router::Route; @@ -97,7 +84,7 @@ public: * @param url - url path. "Path" part of url only. * @return - &id:oatpp::web::url::mapping::Router::Route;. */ - BranchRouter::Route getRoute(const StringKeyLabel& method, const StringKeyLabel& url); + BranchRouter::Route getRoute(const StringKeyLabel& method, const StringKeyLabel& path); /** * Print out all router mapping. diff --git a/src/oatpp/web/server/api/ApiController.cpp b/src/oatpp/web/server/api/ApiController.cpp index 1582658d..31150899 100644 --- a/src/oatpp/web/server/api/ApiController.cpp +++ b/src/oatpp/web/server/api/ApiController.cpp @@ -30,7 +30,7 @@ void ApiController::addEndpointsToRouter(const std::shared_ptr& router){ auto node = m_endpoints->getFirstNode(); while (node != nullptr) { auto endpoint = node->getData(); - router->addSubscriber(endpoint->info->method, endpoint->info->path, endpoint->handler); + router->route(endpoint->info->method, endpoint->info->path, endpoint->handler); node = node->getNext(); } } diff --git a/src/oatpp/web/server/api/ApiController.hpp b/src/oatpp/web/server/api/ApiController.hpp index 51669554..01b9daa9 100644 --- a/src/oatpp/web/server/api/ApiController.hpp +++ b/src/oatpp/web/server/api/ApiController.hpp @@ -168,7 +168,7 @@ protected: * Handler which subscribes to specific URL in Router and delegates calls endpoints */ template - class Handler : public oatpp::web::url::mapping::Subscriber, std::shared_ptr> { + class Handler : public oatpp::web::server::HttpRequestHandler { public: typedef std::shared_ptr (T::*Method)(const std::shared_ptr&); typedef oatpp::async::CoroutineStarterForResult&> @@ -189,7 +189,7 @@ protected: return std::make_shared(controller, method, methodAsync); } - std::shared_ptr processEvent(const std::shared_ptr& request) override { + std::shared_ptr handle(const std::shared_ptr& request) override { if(m_method != nullptr) { return (m_controller->*m_method)(request); } else { @@ -198,7 +198,7 @@ protected: } oatpp::async::CoroutineStarterForResult&> - processEventAsync(const std::shared_ptr& request) override { + handleAsync(const std::shared_ptr& request) override { if(m_methodAsync != nullptr) { return (m_controller->*m_methodAsync)(request); } diff --git a/src/oatpp/web/server/api/Endpoint.hpp b/src/oatpp/web/server/api/Endpoint.hpp index d7f57b90..947cabb8 100644 --- a/src/oatpp/web/server/api/Endpoint.hpp +++ b/src/oatpp/web/server/api/Endpoint.hpp @@ -25,10 +25,7 @@ #ifndef oatpp_web_server_rest_Endpoint_hpp #define oatpp_web_server_rest_Endpoint_hpp -#include "oatpp/web/url/mapping/Router.hpp" - -#include "oatpp/web/protocol/http/incoming/Request.hpp" -#include "oatpp/web/protocol/http/outgoing/Response.hpp" +#include "oatpp/web/server/HttpRequestHandler.hpp" #include #include @@ -41,10 +38,11 @@ namespace oatpp { namespace web { namespace server { namespace api { */ class Endpoint : public oatpp::base::Countable { public: - typedef oatpp::web::url::mapping::Subscriber< - std::shared_ptr, - std::shared_ptr - > RequestHandler; + + /** + * Convenience typedef for &id:oatpp::web::server::HttpRequestHandler;. + */ + typedef oatpp::web::server::HttpRequestHandler RequestHandler; public: /** diff --git a/src/oatpp/web/url/mapping/Router.cpp b/src/oatpp/web/url/mapping/Router.cpp deleted file mode 100644 index 749fcdac..00000000 --- a/src/oatpp/web/url/mapping/Router.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/*************************************************************************** - * - * Project _____ __ ____ _ _ - * ( _ ) /__\ (_ _)_| |_ _| |_ - * )(_)( /(__)\ )( (_ _)(_ _) - * (_____)(__)(__)(__) |_| |_| - * - * - * Copyright 2018-present, Leonid Stryzhevskyi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ***************************************************************************/ - -#include "Router.hpp" diff --git a/src/oatpp/web/url/mapping/Router.hpp b/src/oatpp/web/url/mapping/Router.hpp index 9e58e996..98c1608c 100644 --- a/src/oatpp/web/url/mapping/Router.hpp +++ b/src/oatpp/web/url/mapping/Router.hpp @@ -25,33 +25,28 @@ #ifndef oatpp_web_url_mapping_Router_hpp #define oatpp_web_url_mapping_Router_hpp -#include "./Subscriber.hpp" #include "./Pattern.hpp" -#include "oatpp/core/collection/LinkedList.hpp" - #include "oatpp/core/Types.hpp" - -#include "oatpp/core/base/Countable.hpp" -#include "oatpp/core/base/Environment.hpp" +#include +#include namespace oatpp { namespace web { namespace url { namespace mapping { /** - * Class responsible to map "path-pattern" to "Subscriber". - * @tparam Param - input parameter for Subscriber. - * @tparam ReturnType - output parameter of Subscriber. + * Class responsible to map "Path" to "Route" by "Path-Pattern". + * @tparam Endpoint - endpoint of the route. */ -template -class Router : public base::Countable{ -public: - /** - * Convenience typedef for &id:oatpp::web::url::mapping::Subscriber;. - */ - typedef Subscriber UrlSubscriber; +template +class Router : public base::Countable { private: + /** + * Pair &id:oatpp::web::url::mapping::Pattern; to Endpoint. + */ + typedef std::pair, std::shared_ptr> Pair; + /** * Convenience typedef &id:oatpp::data::share::StringKeyLabel;. */ @@ -63,46 +58,31 @@ public: */ class Route { private: - UrlSubscriber* m_subscriber; + Endpoint* m_endpoint; public: /** * Default constructor. */ Route() - : m_subscriber(nullptr) + : m_endpoint(nullptr) {} /** * Constructor. - * @param subscriber - &id:Router::UrlSubscriber;. + * @param pEndpoint - route endpoint. * @param pMatchMap - Match map of resolved path containing resolved path variables. */ - Route(UrlSubscriber* subscriber, const Pattern::MatchMap& pMatchMap) - : m_subscriber(subscriber) + Route(Endpoint* endpoint, const Pattern::MatchMap& pMatchMap) + : m_endpoint(endpoint) , matchMap(pMatchMap) {} /** - * Call &id:oatpp::web::url::mapping::Subscriber::processEvent; with corresponding parameter. - * @param param - * @return - corresponding ReturnType. + * Get endpoint of the route. */ - ReturnType processEvent(const Param& param) const { - return m_subscriber->processEvent(param); - } - - /** - * Call &id:oatpp::web::url::mapping::Subscriber::processEventAsync; with corresponding parameter. - * @param param - * @return - &id:oatpp::async::CoroutineStarterForResult;. - */ - oatpp::async::CoroutineStarterForResult processEventAsync(const Param& param) const { - return m_subscriber->processEventAsync(param); - } - - explicit operator bool() const { - return m_subscriber != nullptr; + Endpoint* getEndpoint() { + return m_endpoint; } /** @@ -110,33 +90,14 @@ public: */ Pattern::MatchMap matchMap; - }; - -public: - - class Pair : public base::Countable{ - public: - Pair(const std::shared_ptr& pPattern, const std::shared_ptr& pSubscriber) - : pattern(pPattern) - , subscriber(pSubscriber) - {} - public: - - static std::shared_ptr createShared(const std::shared_ptr& pattern, const std::shared_ptr& subscriber){ - return std::make_shared(pattern, subscriber); + explicit operator bool() const { + return m_endpoint != nullptr; } - const std::shared_ptr pattern; - const std::shared_ptr subscriber; - }; private: - std::shared_ptr>> m_subscribers; -public: - Router() - : m_subscribers(oatpp::collection::LinkedList>::createShared()) - {} + std::list m_endpointsByPattern; public: static std::shared_ptr createShared(){ @@ -144,43 +105,39 @@ public: } /** - * Add path-pattern subscriber. - * @param urlPattern - * @param subscriber + * Add `path-pattern` to `endpoint` mapping. + * @param pathPattern - path pattern for endpoint. + * @param endpoint - route endpoint. */ - void addSubscriber(const oatpp::String& urlPattern, - const std::shared_ptr& subscriber){ - auto pattern = Pattern::parse(urlPattern); - auto pair = Pair::createShared(pattern, subscriber); - m_subscribers->pushBack(pair); + void route(const oatpp::String& pathPattern, const std::shared_ptr& endpoint) { + auto pattern = Pattern::parse(pathPattern); + m_endpointsByPattern.push_back({pattern, endpoint}); } /** - * Resolve path to corresponding subscriber. - * @param url + * Resolve path to corresponding endpoint. + * @param path * @return - &id:Router::Route;. */ - Route getRoute(const StringKeyLabel& url){ - auto curr = m_subscribers->getFirstNode(); - while(curr != nullptr) { - const std::shared_ptr& pair = curr->getData(); - curr = curr->getNext(); - Pattern::MatchMap match; - if(pair->pattern->match(url, match)) { - return Route(pair->subscriber.get(), match); + Route getRoute(const StringKeyLabel& path){ + + for(auto& pair : m_endpointsByPattern) { + Pattern::MatchMap matchMap; + if(pair.first->match(path, matchMap)) { + return Route(pair.second.get(), matchMap); } } + return Route(); } void logRouterMappings() { - auto curr = m_subscribers->getFirstNode(); - while(curr != nullptr){ - const std::shared_ptr& pair = curr->getData(); - curr = curr->getNext(); - auto mapping = pair->pattern->toString(); + + for(auto& pair : m_endpointsByPattern) { + auto mapping = pair.first->toString(); OATPP_LOGD("Router", "url '%s' -> mapped", (const char*) mapping->getData()); } + } }; diff --git a/src/oatpp/web/url/mapping/Subscriber.cpp b/src/oatpp/web/url/mapping/Subscriber.cpp deleted file mode 100644 index 3ab3b66b..00000000 --- a/src/oatpp/web/url/mapping/Subscriber.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/*************************************************************************** - * - * Project _____ __ ____ _ _ - * ( _ ) /__\ (_ _)_| |_ _| |_ - * )(_)( /(__)\ )( (_ _)(_ _) - * (_____)(__)(__)(__) |_| |_| - * - * - * Copyright 2018-present, Leonid Stryzhevskyi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ***************************************************************************/ - -#include "Subscriber.hpp" diff --git a/src/oatpp/web/url/mapping/Subscriber.hpp b/src/oatpp/web/url/mapping/Subscriber.hpp deleted file mode 100644 index cccbc577..00000000 --- a/src/oatpp/web/url/mapping/Subscriber.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * - * Project _____ __ ____ _ _ - * ( _ ) /__\ (_ _)_| |_ _| |_ - * )(_)( /(__)\ )( (_ _)(_ _) - * (_____)(__)(__)(__) |_| |_| - * - * - * Copyright 2018-present, Leonid Stryzhevskyi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ***************************************************************************/ - -#ifndef oatpp_web_mapping_url_Subscriber_hpp -#define oatpp_web_mapping_url_Subscriber_hpp - - -#include "oatpp/core/async/Coroutine.hpp" - -namespace oatpp { namespace web { namespace url { namespace mapping { - -/** - * Abstract subscriber which can subscribe to incoming events from &id:oatpp::web::url::mapping::Router; and process those events. - * @tparam Event - incoming event type. - * @tparam Result - result of event processing. - */ -template -class Subscriber { -public: - /** - * Process event. - * @param Event - some incoming data. - * @return - some outgoing data. - */ - virtual Result processEvent(const Event& event) = 0; - - /** - * Process event in asynchronous manner. - * @param event - some incoming data. - * @return - &id:oatpp::async::CoroutineStarterForResult;. - */ - virtual oatpp::async::CoroutineStarterForResult processEventAsync(const Event& event) = 0; -}; - -}}}} - -#endif /* oatpp_web_mapping_url_Subscriber_hpp */