Merge pull request #2 from oatpp/master

Get latest changes from oatpp
This commit is contained in:
Doug Camens 2019-05-31 14:31:30 -04:00 committed by GitHub
commit da44f34798
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 455 additions and 355 deletions

View File

@ -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

View File

@ -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 ++;
}

View File

@ -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<v_char8[]>(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.");
}

View File

@ -45,7 +45,7 @@ void IOEventWorker::initEventQueue() {
m_outEvents = std::unique_ptr<v_char8[]>(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<v_char8[]>(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.");
}

View File

@ -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

View File

@ -23,13 +23,17 @@
***************************************************************************/
#include "Environment.hpp"
#include <iomanip>
#include <chrono>
#include <iostream>
#include <cstring>
#include <ctime>
#include <stdarg.h>
namespace oatpp { namespace base {
Logger* Environment::m_logger = nullptr;
std::shared_ptr<Logger> Environment::m_logger;
std::unordered_map<std::string, std::unordered_map<std::string, void*>> Environment::m_components;
v_atomicCounter Environment::m_objectsCount(0);
@ -37,7 +41,76 @@ 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 time = std::chrono::system_clock::now().time_since_epoch();
std::lock_guard<std::mutex> 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.timeFormat) {
time_t seconds = std::chrono::duration_cast<std::chrono::seconds>(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<std::chrono::microseconds>(time).count();
if(indent) {
std::cout << " ";
}
std::cout << ticks;
indent = true;
}
if(indent) {
std::cout << "|";
}
std::cout << " " << tag << ":" << message << "\n";
}
void Environment::init() {
init(std::make_shared<DefaultLogger>());
}
void Environment::init(const std::shared_ptr<Logger>& logger) {
m_logger = logger;
checkTypes();
m_objectsCount = 0;
@ -48,12 +121,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 +182,14 @@ v_counter Environment::getThreadLocalObjectsCreated(){
return m_threadLocalObjectsCreated;
}
void Environment::setLogger(Logger* logger){
delete m_logger;
void Environment::setLogger(const std::shared_ptr<Logger>& 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

View File

@ -32,8 +32,8 @@
#include <mutex>
#include <string>
#include <unordered_map>
#include <memory>
#include <stdexcept>
#include <stdlib.h>
#define OATPP_VERSION "0.19.4"
@ -74,9 +74,35 @@ namespace oatpp { namespace base{
/**
* Interface for system-wide Logger.<br>
* All calls to `OATPP_DISABLE_LOGV`, `OATPP_DISABLE_LOGE`, `OATPP_DISABLE_LOGD` should 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:
/**
* 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 +118,57 @@ 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 {
/**
* 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.
*/
const char* timeFormat;
/**
* 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 = Config("%Y-%m-%d %H:%M:%S", true));
/**
* 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.<br>
* Manage object counters, manage components, and do system health-checks.
@ -103,7 +180,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<Logger> m_logger;
static void checkTypes();
private:
static std::unordered_map<std::string, std::unordered_map<std::string, void*>> m_components;
@ -169,6 +246,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>& logger);
/**
* De-initialize environment and do basic health-checks.
* Check for memory leaks.
@ -211,9 +294,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>& logger);
/**
* Print debug information of compilation config.<br>
@ -228,7 +311,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 +320,7 @@ public:
/**
* Format message and call `Logger::log()`<br>
* 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.
@ -267,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); \
@ -274,19 +361,81 @@ if(!(EXP)) { \
}
#ifndef OATPP_DISABLE_LOGV
#define OATPP_LOGV(TAG, ...) oatpp::base::Environment::logFormatted(0, TAG, __VA_ARGS__);
/**
* Log message with &l:Logger::PRIORITY_V; <br>
* *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(1, TAG, __VA_ARGS__);
/**
* Log message with &l:Logger::PRIORITY_D; <br>
* *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
/**
* Log message with &l:Logger::PRIORITY_I; <br>
* *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
/**
* Log message with &l:Logger::PRIORITY_W; <br>
* *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(2, TAG, __VA_ARGS__);
/**
* Log message with &l:Logger::PRIORITY_E; <br>
* *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

View File

@ -99,7 +99,7 @@ public:
void setErrorHandler(const std::shared_ptr<handler::ErrorHandler>& 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<handler::RequestInterceptor>& interceptor);

View File

@ -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<protocol::http::outgoing::Response>& response) {

View File

@ -0,0 +1,62 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* 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. <br>
* *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<OutgoingResponse> handle(const std::shared_ptr<IncomingRequest>& request) = 0;
/**
* Handle incoming http request in Asynchronous manner. <br>
* *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<const std::shared_ptr<OutgoingResponse>&>
handleAsync(const std::shared_ptr<IncomingRequest>& request) = 0;
};
}}}
#endif // oatpp_web_server_HttpRequestHandler_hpp

View File

@ -41,16 +41,16 @@ std::shared_ptr<HttpRouter> HttpRouter::createShared() {
return std::make_shared<HttpRouter>();
}
void HttpRouter::addSubscriber(const oatpp::String& method,
const oatpp::String& urlPattern,
const std::shared_ptr<Subscriber>& subscriber) {
getBranch(method)->addSubscriber(urlPattern, subscriber);
void HttpRouter::route(const oatpp::String& method,
const oatpp::String& pathPattern,
const std::shared_ptr<HttpRequestHandler>& 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();
}

View File

@ -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<oatpp::web::protocol::http::incoming::Request>,
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response>
> 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<HttpRequestHandler> BranchRouter;
/**
* Http method to &l:HttpRouter::BranchRouter; map.
@ -84,12 +71,12 @@ public:
static std::shared_ptr<HttpRouter> 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>& subscriber);
void route(const oatpp::String& method, const oatpp::String& pathPattern, const std::shared_ptr<HttpRequestHandler>& 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.

View File

@ -30,7 +30,7 @@ void ApiController::addEndpointsToRouter(const std::shared_ptr<Router>& 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();
}
}

View File

@ -168,7 +168,7 @@ protected:
* Handler which subscribes to specific URL in Router and delegates calls endpoints
*/
template<class T>
class Handler : public oatpp::web::url::mapping::Subscriber<std::shared_ptr<IncomingRequest>, std::shared_ptr<OutgoingResponse>> {
class Handler : public oatpp::web::server::HttpRequestHandler {
public:
typedef std::shared_ptr<OutgoingResponse> (T::*Method)(const std::shared_ptr<protocol::http::incoming::Request>&);
typedef oatpp::async::CoroutineStarterForResult<const std::shared_ptr<OutgoingResponse>&>
@ -189,7 +189,7 @@ protected:
return std::make_shared<Handler>(controller, method, methodAsync);
}
std::shared_ptr<OutgoingResponse> processEvent(const std::shared_ptr<protocol::http::incoming::Request>& request) override {
std::shared_ptr<OutgoingResponse> handle(const std::shared_ptr<protocol::http::incoming::Request>& request) override {
if(m_method != nullptr) {
return (m_controller->*m_method)(request);
} else {
@ -198,7 +198,7 @@ protected:
}
oatpp::async::CoroutineStarterForResult<const std::shared_ptr<OutgoingResponse>&>
processEventAsync(const std::shared_ptr<protocol::http::incoming::Request>& request) override {
handleAsync(const std::shared_ptr<protocol::http::incoming::Request>& request) override {
if(m_methodAsync != nullptr) {
return (m_controller->*m_methodAsync)(request);
}

View File

@ -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 <list>
#include <unordered_map>
@ -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<protocol::http::incoming::Request>,
std::shared_ptr<protocol::http::outgoing::Response>
> RequestHandler;
/**
* Convenience typedef for &id:oatpp::web::server::HttpRequestHandler;.
*/
typedef oatpp::web::server::HttpRequestHandler RequestHandler;
public:
/**

View File

@ -1,25 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* 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"

View File

@ -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 <utility>
#include <list>
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 Param, class ReturnType>
class Router : public base::Countable{
public:
/**
* Convenience typedef for &id:oatpp::web::url::mapping::Subscriber;.
*/
typedef Subscriber<Param, ReturnType> UrlSubscriber;
template<class Endpoint>
class Router : public base::Countable {
private:
/**
* Pair &id:oatpp::web::url::mapping::Pattern; to Endpoint.
*/
typedef std::pair<std::shared_ptr<Pattern>, std::shared_ptr<Endpoint>> 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<const ReturnType&> 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<Pattern>& pPattern, const std::shared_ptr<UrlSubscriber>& pSubscriber)
: pattern(pPattern)
, subscriber(pSubscriber)
{}
public:
static std::shared_ptr<Pair> createShared(const std::shared_ptr<Pattern>& pattern, const std::shared_ptr<UrlSubscriber>& subscriber){
return std::make_shared<Pair>(pattern, subscriber);
explicit operator bool() const {
return m_endpoint != nullptr;
}
const std::shared_ptr<Pattern> pattern;
const std::shared_ptr<UrlSubscriber> subscriber;
};
private:
std::shared_ptr<oatpp::collection::LinkedList<std::shared_ptr<Pair>>> m_subscribers;
public:
Router()
: m_subscribers(oatpp::collection::LinkedList<std::shared_ptr<Pair>>::createShared())
{}
std::list<Pair> m_endpointsByPattern;
public:
static std::shared_ptr<Router> 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<UrlSubscriber>& 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>& 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>& 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>& 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());
}
}
};

View File

@ -1,25 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* 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"

View File

@ -1,58 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>
*
* 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 Event, class Result>
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<const Result&> processEventAsync(const Event& event) = 0;
};
}}}}
#endif /* oatpp_web_mapping_url_Subscriber_hpp */

View File

@ -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<oatpp::concurrency::SpinLock> lock(m_lock);
std::cout << tag << ":" << message << "\n";
}
};
void runTests() {
oatpp::base::Environment::printCompilationConfig();
@ -120,13 +106,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";

View File

@ -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_LOGW("TEST[base::memory::MemoryPoolTest]", "WARNING. 'OATPP_DISABLE_POOL_ALLOCATIONS' flag is ON. Assertions disabled.");
#endif
delete [] objects;

View File

@ -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);
}

View File

@ -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;

View File

@ -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()));
}

View File

@ -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);
}

View File

@ -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");

View File

@ -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");
}

View File

@ -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>& 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();

View File

@ -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<Test>(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());
}

View File

@ -150,9 +150,9 @@ public:
Action handleError(const std::shared_ptr<const Error>& error) override {
if(error->is<oatpp::data::AsyncIOError>()) {
auto e = static_cast<const oatpp::data::AsyncIOError*>(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<oatpp::data::AsyncIOError>()) {
auto e = static_cast<const oatpp::data::AsyncIOError*>(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!");
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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));
}