diff --git a/src/oatpp/core/base/memory/Allocator.cpp b/src/oatpp/core/base/memory/Allocator.cpp index 80757cc6..3dce0bc4 100644 --- a/src/oatpp/core/base/memory/Allocator.cpp +++ b/src/oatpp/core/base/memory/Allocator.cpp @@ -23,3 +23,12 @@ ***************************************************************************/ #include "Allocator.hpp" + +namespace oatpp { namespace base { namespace memory { + +AllocatorPoolInfo::AllocatorPoolInfo(const char* pPoolName, v_int32 pPoolChunkSize) + : poolName(pPoolName) + , poolChunkSize(pPoolChunkSize) +{} + +}}} \ No newline at end of file diff --git a/src/oatpp/core/base/memory/Allocator.hpp b/src/oatpp/core/base/memory/Allocator.hpp index a349d714..c7e7cb5d 100644 --- a/src/oatpp/core/base/memory/Allocator.hpp +++ b/src/oatpp/core/base/memory/Allocator.hpp @@ -29,16 +29,35 @@ namespace oatpp { namespace base { namespace memory { +/** + * Pool Information for Pool Allocators. + */ class AllocatorPoolInfo { public: - AllocatorPoolInfo(const char* pPoolName, v_int32 pPoolChunkSize) - : poolName(pPoolName) - , poolChunkSize(pPoolChunkSize) - {} + /** + * Constructor. + * @param pPoolName - memory pool name. + * @param pPoolChunkSize - memory pool chunk size. For more about chunk size see &id:oatpp::base::memory::MemoryPool::MemoryPool;. + */ + AllocatorPoolInfo(const char* pPoolName, v_int32 pPoolChunkSize); + + /** + * Memory pool name. + */ const char* const poolName; + + /** + * Memory pool chunk size. + * For more about chunk size see &id:oatpp::base::memory::MemoryPool::MemoryPool;. + */ const v_int32 poolChunkSize; }; - + +/** + * Allocator to allocate shared object on &id:oatpp::base::memory::MemoryPool; + * Used to allocate shared_ptr control block and an object in the same memory entry of the pool. + * @tparam T - type of the object to allocate. + */ template class PoolSharedObjectAllocator { public: @@ -79,7 +98,11 @@ template inline bool operator != (const PoolSharedObjectAllocator& a, const PoolSharedObjectAllocator& b) { return !(a == b); } - + +/** + * Same as &l:PoolSharedObjectAllocator; but uses `thread_local` &id:oatpp::base::memory::MemoryPool;. + * @tparam T - type of the object to allocate. + */ template class ThreadLocalPoolSharedObjectAllocator { public: @@ -120,17 +143,26 @@ template inline bool operator != (const ThreadLocalPoolSharedObjectAllocator& a, const ThreadLocalPoolSharedObjectAllocator& b) { return !(a == b); } - + +/** + * Extra information for, and about allocation. + * Used for variable-size objects allocations. (ex.: for strings). + */ class AllocationExtras { public: AllocationExtras(v_int32 pExtraWanted) - : extraWanted(pExtraWanted) + : extraWanted(pExtraWanted) {} const v_int32 extraWanted; void* extraPtr; v_int32 baseSize; }; - + +/** + * Allocator for shared objects. + * Used to allocate object and shared_ptr's control block in the same memory entry. + * @tparam T - type of the object to allocate. + */ template class SharedObjectAllocator { public: @@ -160,7 +192,12 @@ public: } }; - + +/** + * Allocator for shared objects. Allocates objects on the pool provided. + * @tparam T - type of object to allocate. + * @tparam P - type of memory pool to allocate object on. + */ template class CustomPoolSharedObjectAllocator { public: @@ -203,7 +240,7 @@ template inline bool operator != (const SharedObjectAllocator& a, const SharedObjectAllocator& b) { return !(a == b); } - + template static std::shared_ptr allocateSharedWithExtras(AllocationExtras& extras, Args... args){ typedef SharedObjectAllocator _Allocator; diff --git a/src/oatpp/core/base/memory/ObjectPool.hpp b/src/oatpp/core/base/memory/ObjectPool.hpp index dfbec57c..24635ac0 100644 --- a/src/oatpp/core/base/memory/ObjectPool.hpp +++ b/src/oatpp/core/base/memory/ObjectPool.hpp @@ -30,6 +30,12 @@ namespace oatpp { namespace base { namespace memory { +/** + * Macro to declare object pool class which uses &id:oatpp::base::memory::PoolSharedObjectAllocator; to allocate objects. + * @param NAME - name of the memory pool. + * @param TYPE - type of the object. + * @param CHUNK_SIZE - chunk size for &id:oatpp::base::memory::MemoryPool;. + */ #define SHARED_OBJECT_POOL(NAME, TYPE, CHUNK_SIZE) \ class NAME { \ public: \ @@ -54,7 +60,12 @@ public: \ \ }; - +/** + * Macro to declare object pool class which uses &id:oatpp::base::memory::ThreadLocalPoolSharedObjectAllocator; to allocate objects. + * @param NAME - name of the memory pool. + * @param TYPE - type of the object. + * @param CHUNK_SIZE - chunk size for &id:oatpp::base::memory::MemoryPool;. + */ #define SHARED_OBJECT_POOL_THREAD_LOCAL(NAME, TYPE, CHUNK_SIZE) \ class NAME { \ public: \ @@ -78,7 +89,15 @@ public: \ } \ \ }; - + +/** + * Macro to declare: &id:oatpp::base::memory::MemoryPool; for object, plus class-specific operators + * `static void* operator new(std::size_t sz)`, `static void operator delete(void* ptr, std::size_t sz)`, + * `static void* operator new(std::size_t sz, void* entry)`, `static void operator delete(void* ptr, void* entry)`. + * @param NAME - name of the memory pool. + * @param TYPE - type of the object. + * @param CHUNK_SIZE - chunk size for &id:oatpp::base::memory::MemoryPool;. + */ #define OBJECT_POOL(POOL_NAME, TYPE, CHUNK_SIZE) \ class POOL_NAME { \ public: \ @@ -115,6 +134,14 @@ static void* operator new(std::size_t sz, void* entry) { \ static void operator delete(void* ptr, void* entry) { \ } +/** + * Macro to declare: `thread_local` &id:oatpp::base::memory::MemoryPool; for object, plus class-specific operators + * `static void* operator new(std::size_t sz)`, `static void operator delete(void* ptr, std::size_t sz)`, + * `static void* operator new(std::size_t sz, void* entry)`, `static void operator delete(void* ptr, void* entry)`. + * @param NAME - name of the memory pool. + * @param TYPE - type of the object. + * @param CHUNK_SIZE - chunk size for &id:oatpp::base::memory::MemoryPool;. + */ #define OBJECT_POOL_THREAD_LOCAL(POOL_NAME, TYPE, CHUNK_SIZE) \ class POOL_NAME { \ public: \ diff --git a/src/oatpp/core/data/mapping/type/Object.hpp b/src/oatpp/core/data/mapping/type/Object.hpp index aeefa7e6..49d49957 100644 --- a/src/oatpp/core/data/mapping/type/Object.hpp +++ b/src/oatpp/core/data/mapping/type/Object.hpp @@ -37,16 +37,27 @@ namespace oatpp { namespace data { namespace mapping { namespace type { namespace __class { - + + /** + * AbstractObject class. + */ class AbstractObject { public: static const char* const CLASS_NAME; }; - + + /** + * Template for Object class of type T. + * @tparam T - object type. + */ template class Object : public AbstractObject { public: - + + /** + * Get type describing this class. + * @return - &id:oatpp::data::mapping::type::Type; + */ static Type* getType(){ static Type* type = static_cast(T::Z__CLASS_GET_TYPE()); return type; @@ -55,7 +66,11 @@ namespace __class { }; } - + +/** + * Base class for all DTO objects. + * For more info about Data Transfer Object (DTO) see [Data Transfer Object (DTO)](https://oatpp.io/docs/components/dto/). + */ class Object : public oatpp::base::Countable { public: typedef oatpp::data::mapping::type::String String; diff --git a/src/oatpp/core/data/share/MemoryLabel.hpp b/src/oatpp/core/data/share/MemoryLabel.hpp index c4d57526..3d4026a8 100644 --- a/src/oatpp/core/data/share/MemoryLabel.hpp +++ b/src/oatpp/core/data/share/MemoryLabel.hpp @@ -31,7 +31,9 @@ namespace oatpp { namespace data { namespace share { /** - * MemoryLabel represent a part of the whole memory buffer refered by handle + * MemoryLabel represent a part of the whole memory buffer refered by handle. + * Advantage of MemoryLabel use is that you may just "label" some data instead of allocating buffer for it's copy. + * You may allocate separate buffer for data copy later once you need it. */ class MemoryLabel { protected: @@ -39,32 +41,66 @@ protected: p_char8 m_data; v_int32 m_size; public: - + + /** + * Default constructor. Null MemoryLabel. + */ MemoryLabel() : m_memoryHandle(nullptr) , m_data(nullptr) , m_size(0) {} - + + /** + * Constructor. + * @param memHandle - memory handle. `std::shared_ptr` to buffer pointed by a memory label. + * @param data - pointer to data. + * @param size - size of the data in bytes. + */ MemoryLabel(const std::shared_ptr& memHandle, p_char8 data, v_int32 size); - + + /** + * Get pointer to labeled data. + * @return - pointer to data. + */ p_char8 getData() const { return m_data; } - + + /** + * Get data size. + * @return - size of the data. + */ v_int32 getSize() const { return m_size; } - + + /** + * Get memory handle which this memory label holds. + * @return - `std::shared_ptr` to &id:oatpp::base::StrBuffer;. + */ std::shared_ptr getMemoryHandle() const { return m_memoryHandle; } - + + /** + * Check if labeled data equals to data specified. + * Data is compared using &id:oatpp::base::StrBuffer::equals;. + * @param data - data to compare with labeled data. + * @return - `true` if equals. + */ bool equals(const char* data) const { v_int32 size = (v_int32) std::strlen(data); return m_size == size && base::StrBuffer::equals(m_data, data, m_size); } - + + /** + * Check if labeled data equals to data specified. + * Data is compared using &id:oatpp::base::StrBuffer::equals;. + * @param data - data to compare with labeled data. + * @param size - data size. + * @return - `true` if equals. + */ bool equals(const void* data, v_int32 size) const { return m_size == size && base::StrBuffer::equals(m_data, data, m_size); } diff --git a/src/oatpp/core/data/stream/ChunkedBuffer.cpp b/src/oatpp/core/data/stream/ChunkedBuffer.cpp index cfe991a8..6fb0e929 100644 --- a/src/oatpp/core/data/stream/ChunkedBuffer.cpp +++ b/src/oatpp/core/data/stream/ChunkedBuffer.cpp @@ -34,7 +34,18 @@ const data::v_io_size ChunkedBuffer::CHUNK_ENTRY_SIZE_INDEX_SHIFT = 11; const data::v_io_size ChunkedBuffer::CHUNK_ENTRY_SIZE = (1 << ChunkedBuffer::CHUNK_ENTRY_SIZE_INDEX_SHIFT); const data::v_io_size ChunkedBuffer::CHUNK_CHUNK_SIZE = 32; - + +ChunkedBuffer::ChunkedBuffer() + : m_size(0) + , m_chunkPos(0) + , m_firstEntry(nullptr) + , m_lastEntry(nullptr) +{} + +ChunkedBuffer::~ChunkedBuffer() { + clear(); +} + ChunkedBuffer::ChunkEntry* ChunkedBuffer::obtainNewEntry(){ auto result = new ChunkEntry(getSegemntPool().obtain(), nullptr); if(m_firstEntry == nullptr) { @@ -187,19 +198,22 @@ oatpp::String ChunkedBuffer::getSubstring(data::v_io_size pos, readSubstring(str->getData(), pos, count); return str; } - + +// TODO - refactor this. bool ChunkedBuffer::flushToStream(const std::shared_ptr& stream){ data::v_io_size pos = m_size; auto curr = m_firstEntry; while (pos > 0) { if(pos > CHUNK_ENTRY_SIZE) { auto res = stream->write(curr->chunk, CHUNK_ENTRY_SIZE); + // TODO handle I/O errors. if(res != CHUNK_ENTRY_SIZE) { return false; } pos -= res; } else { auto res = stream->write(curr->chunk, pos); + // TODO handle I/O errors. if(res != pos) { return false; } diff --git a/src/oatpp/core/data/stream/ChunkedBuffer.hpp b/src/oatpp/core/data/stream/ChunkedBuffer.hpp index 9d3c42ce..62f91643 100644 --- a/src/oatpp/core/data/stream/ChunkedBuffer.hpp +++ b/src/oatpp/core/data/stream/ChunkedBuffer.hpp @@ -31,7 +31,10 @@ #include "oatpp/core/async/Coroutine.hpp" namespace oatpp { namespace data{ namespace stream { - + +/** + * Buffer wich can grow by chunks and implements &id:oatpp::data::stream::OutputStream; interface. + */ class ChunkedBuffer : public oatpp::base::Countable, public OutputStream, public std::enable_shared_from_this { public: static const char* ERROR_ASYNC_FAILED_TO_WRITE_ALL_DATA; @@ -126,54 +129,102 @@ private: public: - ChunkedBuffer() - : m_size(0) - , m_chunkPos(0) - , m_firstEntry(nullptr) - , m_lastEntry(nullptr) - {} - - ~ChunkedBuffer() { - clear(); - } + /** + * Constructor. + */ + ChunkedBuffer(); + + /** + * Virtual Destructor. + */ + ~ChunkedBuffer(); public: + /** + * Deleted copy constructor. + */ ChunkedBuffer(const ChunkedBuffer&) = delete; + ChunkedBuffer& operator=(const ChunkedBuffer&) = delete; public: + /** + * Create shared ChunkedBuffer. + * @return `std::shared_ptr` to ChunkedBuffer. + */ static std::shared_ptr createShared(){ return Shared_ChunkedBuffer_Pool::allocateShared(); } + /** + * Write data to ChunkedBuffer. Implementation of &id:oatpp::data::stream::OutputStream::write; method. + * @param data - data to write. + * @param count - size of data in bytes. + * @return - actual number of bytes written. + */ data::v_io_size write(const void *data, data::v_io_size count) override; - data::v_io_size readSubstring(void *buffer, - data::v_io_size pos, - data::v_io_size count); + /** + * Read part of ChunkedBuffer to buffer. + * @param buffer - buffer to write data to. + * @param pos - starting position in ChunkedBuffer to read data from. + * @param count - number of bytes to read. + * @return - actual number of bytes read from ChunkedBuffer and written to buffer. + */ + data::v_io_size readSubstring(void *buffer, data::v_io_size pos, data::v_io_size count); /** - * return substring of the data written to stream; NOT NULL + * Create &id:oatpp::String; from part of ChunkedBuffer. + */ + + /** + * Create &id:oatpp::String; from part of ChunkedBuffer. + * @param pos - starting position in ChunkedBuffer. + * @param count - size of bytes to write to substring. + * @return - &id:oatpp::String; */ oatpp::String getSubstring(data::v_io_size pos, data::v_io_size count); /** - * return data written to stream as oatpp::String; NOT NULL + * Create &id:oatpp::String; from all data in ChunkedBuffer. + * @return - &id:oatpp::String; */ oatpp::String toString() { return getSubstring(0, m_size); } + /** + * Write all data from ChunkedBuffer to &id:oatpp::data::stream::OutputStream;. + * ChunkedBuffer will not be cleared during this call! + * @param stream - &id:oatpp::data::stream::OutputStream; stream to write all data to. + * @return - `true` if no errors occured. **will be refactored to return actual amount of bytes flushed**. + */ bool flushToStream(const std::shared_ptr& stream); + + /** + * Write all data from ChunkedBuffer to &id:oatpp::data::stream::OutputStream; in asynchronous manner. + * @param parentCoroutine - caller coroutine. &id:oatpp::async::AbstractCoroutine;. + * @param actionOnFinish - action to do once finished. &id:oatpp::async::Action;. + * @param stream - &id:oatpp::data::stream::OutputStream; stream to write all data to. + * @return - &id:oatpp::async::Action;. + */ oatpp::async::Action flushToStreamAsync(oatpp::async::AbstractCoroutine* parentCoroutine, const oatpp::async::Action& actionOnFinish, const std::shared_ptr& stream); std::shared_ptr getChunks(); + /** + * Get number of bytes written to ChunkedBuffer. + * @return - number of bytes written to ChunkedBuffer. + */ data::v_io_size getSize(); + + /** + * Clear data in ChunkedBuffer. + */ void clear(); }; diff --git a/src/oatpp/core/data/stream/Delegate.hpp b/src/oatpp/core/data/stream/Delegate.hpp index ced52e5f..6789dfae 100644 --- a/src/oatpp/core/data/stream/Delegate.hpp +++ b/src/oatpp/core/data/stream/Delegate.hpp @@ -28,14 +28,31 @@ #include "./Stream.hpp" namespace oatpp { namespace data{ namespace stream { - + +/** + * Stream writer delegate which can write data to stream provided. + */ class WriterDelegate { public: + + /** + * Write data to provided stream. + * @param stream - stream to write data to. + * @return - actual number of bytes written to stream. &id:oatpp::data::v_io_size;. + */ virtual data::v_io_size writeToStream(const std::shared_ptr& stream) = 0; }; - + +/** + * Stream reader delegate which can read data from stream provided. + */ class ReaderDelegate { public: + /** + * Read data from provided stream. + * @param stream - stream to read data from. + * @return - actual number of bytes read. &id:oatpp::data::v_io_size;. + */ virtual data::v_io_size readFromStream(const std::shared_ptr& stream) = 0; }; diff --git a/src/oatpp/core/macro/basic.hpp b/src/oatpp/core/macro/basic.hpp index c7c0e712..c08411d3 100644 --- a/src/oatpp/core/macro/basic.hpp +++ b/src/oatpp/core/macro/basic.hpp @@ -22,6 +22,10 @@ * ***************************************************************************/ +/**[info] + * This file contains source code for basic helper macros used for code-generator. + */ + #ifndef oatpp_macro_ForEach_hpp #define oatpp_macro_ForEach_hpp diff --git a/src/oatpp/core/macro/codegen.hpp b/src/oatpp/core/macro/codegen.hpp index 87b054eb..61c1ac9a 100644 --- a/src/oatpp/core/macro/codegen.hpp +++ b/src/oatpp/core/macro/codegen.hpp @@ -22,6 +22,19 @@ * ***************************************************************************/ +/**[info] + * This file contains source code for `OATPP_CODEGEN_BEGIN(NAME)` and `OATPP_CODEGEN_END(NAME)` macros.
+ *
+ * + * More about use of `OATPP_CODEGEN_BEGIN` and `OATPP_CODEGEN_BEGIN` see:
+ *
    + *
  • [ApiController component](https://oatpp.io/docs/components/api-controller/)
  • + *
  • [ApiClient component](https://oatpp.io/docs/components/api-client/)
  • + *
  • [Data Transfer Object(DTO) component](https://oatpp.io/docs/components/dto/)
  • + *
+ * + */ + #ifndef codegen_hpp #define codegen_hpp diff --git a/src/oatpp/core/macro/component.hpp b/src/oatpp/core/macro/component.hpp index fc1fe8eb..94b73e57 100644 --- a/src/oatpp/core/macro/component.hpp +++ b/src/oatpp/core/macro/component.hpp @@ -22,6 +22,18 @@ * ***************************************************************************/ +/**[info] + * This file contains source code for `OATPP_CREATE_COMPONENT` and `OATPP_COMPONENT` macros which are part of + * oatpp Dependency Injection (DI) framework.
+ *
+ * For usage examples see example-projects: + *
    + *
  • [CRUD - example](https://github.com/oatpp/example-crud)
  • + *
  • [HLS Media Stream - example](https://github.com/oatpp/example-hls-media-stream)
  • + *
  • [Async API - example](https://github.com/oatpp/example-async-api)
  • + *
+ */ + #ifndef oatpp_macro_component_hpp #define oatpp_macro_component_hpp @@ -62,10 +74,21 @@ OATPP_MACRO_COMPONENT_(X, TYPE, NAME, LIST) #define OATPP_MACRO_COMPONENT___(TYPE, NAME, LIST) \ OATPP_MACRO_COMPONENT__(OATPP_MACRO_HAS_ARGS LIST, TYPE, NAME, LIST) +/** + * Inject component. Create variable of type=TYPE and name=NAME and assign registered component to it. + * @param TYPE - type of the component. + * @param NAME - name of the variable. + * @param QUALIFIER_NAME - qualifier name is needed if there are multiple components registered of the same type. + * If there is one component registered only then TYPE info is enought to search for component. + */ #define OATPP_COMPONENT(TYPE, NAME, ...) \ OATPP_MACRO_COMPONENT___(TYPE, NAME, (__VA_ARGS__)) - +/** + * Create component that then can be injected in other application classes. + * @param TYPE - type of the component. + * @param NAME - name of the component field. + */ #define OATPP_CREATE_COMPONENT(TYPE, NAME) \ oatpp::base::Environment::Component NAME = oatpp::base::Environment::Component diff --git a/src/oatpp/core/parser/Caret.hpp b/src/oatpp/core/parser/Caret.hpp index b6f79115..e5f3083e 100644 --- a/src/oatpp/core/parser/Caret.hpp +++ b/src/oatpp/core/parser/Caret.hpp @@ -43,27 +43,70 @@ public: static const char* const ERROR_NAME_EXPECTED; public: + /** + * Class to label parsing data. + */ class Label { private: Caret* m_caret; v_int32 m_start; v_int32 m_end; public: - + + /** + * Constructor. + * @param caret. + */ Label(Caret* caret); - + + /** + * Set current caret position as a starting point for label. + */ void start(); + + /** + * Fix current caret position as an end point for label. + */ void end(); + + /** + * Get pointer to a labeled data. + * @return + */ p_char8 getData(); + + /** + * Get size of labeled data. + * @return + */ v_int32 getSize(); + + /** + * Create &id:oatpp::String; from labeled data. + * @param saveAsOwnData - `true` - allocate new memory block for string. `false` - string will point to the same data as label. + * @return - &id:oatpp::String;. + */ oatpp::String toString(bool saveAsOwnData); + + /** + * Same as`toString(true).` + * @return - &id:oatpp::String;. + */ oatpp::String toString(); + + /** + * Create `std::string` from labeled data. + * @return - `std::string`. + */ std::string std_str(); explicit operator bool() const; }; + /** + * Caret state saver guard. + */ class StateSaveGuard { private: Caret& m_caret; @@ -72,11 +115,33 @@ public: v_int32 m_savedErrorCode; public: + /** + * Constructor. + * @param caret. + */ StateSaveGuard(Caret& caret); + + /** + * Destructor. Restore saved state. + */ ~StateSaveGuard(); + /** + * Get caret saved position. + * @return + */ v_int32 getSavedPosition(); + + /** + * Get caret saved error message. + * @return + */ const char* getSavedErrorMessage(); + + /** + * Get caret saved error code. + * @return + */ v_int32 getSavedErrorCode(); }; diff --git a/src/oatpp/network/server/Server.cpp b/src/oatpp/network/server/Server.cpp index 709ee0dc..258b904d 100644 --- a/src/oatpp/network/server/Server.cpp +++ b/src/oatpp/network/server/Server.cpp @@ -34,6 +34,13 @@ const v_int32 Server::STATUS_RUNNING = 1; const v_int32 Server::STATUS_STOPPING = 2; const v_int32 Server::STATUS_DONE = 3; +Server::Server(const std::shared_ptr& connectionProvider, + const std::shared_ptr& connectionHandler) + : m_status(STATUS_CREATED) + , m_connectionProvider(connectionProvider) + , m_connectionHandler(connectionHandler) +{} + void Server::mainLoop(){ setStatus(STATUS_CREATED, STATUS_RUNNING); diff --git a/src/oatpp/network/server/Server.hpp b/src/oatpp/network/server/Server.hpp index 31ad6c09..088fcf26 100644 --- a/src/oatpp/network/server/Server.hpp +++ b/src/oatpp/network/server/Server.hpp @@ -40,6 +40,10 @@ namespace oatpp { namespace network { namespace server { +/** + * Server calls &id:oatpp::network::ConnectionProvider::getConnection; in the loop and passes obtained Connection + * to &id:oatpp::network::server::ConnectionHandler;. + */ class Server : public base::Countable, public concurrency::Runnable{ private: @@ -58,32 +62,70 @@ private: std::shared_ptr m_connectionHandler; public: - - Server( - const std::shared_ptr& connectionProvider, - const std::shared_ptr& connectionHandler - ) - : m_status(STATUS_CREATED) - , m_connectionProvider(connectionProvider) - , m_connectionHandler(connectionHandler) - {} + + /** + * Constructor. + * @param connectionProvider - &id:oatpp::network::ConnectionProvider;. + * @param connectionHandler - &id:oatpp::network::server::ConnectionHandler;. + */ + Server(const std::shared_ptr& connectionProvider, + const std::shared_ptr& connectionHandler); public: - + + /** + * Status constant. + */ static const v_int32 STATUS_CREATED; + + /** + * Status constant. + */ static const v_int32 STATUS_RUNNING; + + /** + * Status constant. + */ static const v_int32 STATUS_STOPPING; + + /** + * Status constant. + */ static const v_int32 STATUS_DONE; - + + /** + * Create shared Server. + * @param connectionProvider - &id:oatpp::network::ConnectionProvider;. + * @param connectionHandler - &id:oatpp::network::server::ConnectionHandler;. + * @return - `std::shared_ptr` to Server. + */ static std::shared_ptr createShared(const std::shared_ptr& connectionProvider, - const std::shared_ptr& connectionHandler){ + const std::shared_ptr& connectionHandler){ return std::make_shared(connectionProvider, connectionHandler); } - + + /** + * Call &id:oatpp::network::ConnectionProvider::getConnection; in the loop and passes obtained Connection + * to &id:oatpp::network::server::ConnectionHandler;. + */ void run() override; - + + /** + * Break server loop. + * Note: thread can still be blocked on the &l:Server::run (); call as it may be waiting for ConnectionProvider to provide connection. + */ void stop(); - + + /** + * Get server status. + * @return - one of:
+ *
    + *
  • &l:Server::STATUS_CREATED;
  • + *
  • &l:Server::STATUS_RUNNING;
  • + *
  • &l:Server::STATUS_STOPPING;
  • + *
  • &l:Server::STATUS_DONE;
  • + *
+ */ v_int32 getStatus(); }; diff --git a/src/oatpp/network/server/SimpleTCPConnectionProvider.hpp b/src/oatpp/network/server/SimpleTCPConnectionProvider.hpp index 87ec42a1..9aa7ab2b 100644 --- a/src/oatpp/network/server/SimpleTCPConnectionProvider.hpp +++ b/src/oatpp/network/server/SimpleTCPConnectionProvider.hpp @@ -31,7 +31,10 @@ #include "oatpp/core/Types.hpp" namespace oatpp { namespace network { namespace server { - + +/** + * Simple provider of TCP connections. + */ class SimpleTCPConnectionProvider : public base::Countable, public ServerConnectionProvider { private: v_word16 m_port; @@ -41,22 +44,52 @@ private: private: oatpp::data::v_io_handle instantiateServer(); public: + /** + * Constructor. + * @param port - port to listen for incoming connections. + * @param nonBlocking - set `true` to provide non-blocking &id:oatpp::data::stream::IOStream; for connection. + * `false` for blocking &id:oatpp::data::stream::IOStream;. Default `false`. + */ SimpleTCPConnectionProvider(v_word16 port, bool nonBlocking = false); public: - + + /** + * Create shared SimpleTCPConnectionProvider. + * @param port - port to listen for incoming connections. + * @param nonBlocking - set `true` to provide non-blocking &id:oatpp::data::stream::IOStream; for connection. + * `false` for blocking &id:oatpp::data::stream::IOStream;. Default `false`. + */ static std::shared_ptr createShared(v_word16 port, bool nonBlocking = false){ return std::make_shared(port, nonBlocking); } - + + /** + * Virtual destructor. + */ ~SimpleTCPConnectionProvider(); + /** + * Close accept-socket. + */ void close() override; - + + /** + * Get incoming connection. + * @return &id:oatpp::data::stream::IOStream;. + */ std::shared_ptr getConnection() override; - + + /** + * No need to implement this.
+ * For Asynchronous IO in oatpp it is considered to be a good practice + * to accept connections in a seperate thread with the blocking accept() + * and then process connections in Asynchronous manner with non-blocking read/write. + *
+ * *It may be implemented later* + */ Action getConnectionAsync(oatpp::async::AbstractCoroutine* parentCoroutine, AsyncCallback callback) override { - /** + /* * No need to implement this. * For Asynchronous IO in oatpp it is considered to be a good practice * to accept connections in a seperate thread with the blocking accept() @@ -66,7 +99,11 @@ public: */ throw std::runtime_error("[oatpp::network::server::SimpleTCPConnectionProvider::getConnectionAsync()]: Error. Not implemented."); } - + + /** + * Get port. + * @return + */ v_word16 getPort(){ return m_port; }