├── cmake ├── version.cmake ├── third_party_paths.cmake ├── install.cmake ├── options.cmake └── settings.cmake ├── CMakeLists.txt ├── examples ├── http │ ├── config │ │ ├── config.json │ │ └── config.xml │ ├── common │ │ └── include │ │ │ └── common │ │ │ ├── id │ │ │ └── service.h │ │ │ ├── interface │ │ │ └── iadmin.h │ │ │ ├── ps │ │ │ └── iadmin.h │ │ │ └── client.h │ ├── CMakeLists.txt │ ├── client │ │ └── src │ │ │ └── main.cpp │ └── server │ │ └── src │ │ └── main.cpp ├── visitor │ ├── config │ │ ├── config.json │ │ └── config.xml │ ├── common │ │ └── include │ │ │ └── common │ │ │ ├── id │ │ │ └── service.h │ │ │ ├── ps │ │ │ └── iface.h │ │ │ └── interface │ │ │ └── iface.h │ ├── server │ │ └── src │ │ │ ├── main.cpp │ │ │ └── service.cpp │ ├── CMakeLists.txt │ └── client │ │ └── src │ │ └── main.cpp ├── complex_type │ ├── config │ │ ├── config.json │ │ └── config.xml │ ├── common │ │ └── include │ │ │ └── common │ │ │ ├── id │ │ │ └── service.h │ │ │ ├── interface │ │ │ └── imy_company.h │ │ │ ├── ps │ │ │ └── imy_company.h │ │ │ ├── data │ │ │ └── data.h │ │ │ └── meta │ │ │ └── data.h │ ├── server │ │ └── src │ │ │ └── main.cpp │ └── CMakeLists.txt ├── hello_world │ ├── config │ │ ├── config.json │ │ └── config.xml │ ├── common │ │ └── include │ │ │ └── common │ │ │ ├── id │ │ │ └── service.h │ │ │ ├── interface │ │ │ └── ihello_world.h │ │ │ └── ps │ │ │ └── ihello_world.h │ ├── server │ │ └── src │ │ │ └── main.cpp │ ├── CMakeLists.txt │ └── client │ │ └── src │ │ └── main.cpp ├── inheritance │ ├── config │ │ ├── config.json │ │ └── config.xml │ ├── common │ │ └── include │ │ │ └── common │ │ │ ├── id │ │ │ └── service.h │ │ │ ├── interface │ │ │ └── iface.h │ │ │ └── ps │ │ │ └── iface.h │ ├── server │ │ └── src │ │ │ └── main.cpp │ ├── CMakeLists.txt │ └── client │ │ └── src │ │ └── main.cpp ├── http_crud │ ├── db │ │ └── schema.sql │ ├── config │ │ ├── config.json │ │ └── config.xml │ ├── CMakeLists.txt │ └── src │ │ ├── main.cpp │ │ ├── employee_service.h │ │ └── data │ │ └── data.h ├── microservices │ ├── storage │ │ ├── db │ │ │ └── schema.sql │ │ └── src │ │ │ └── main.cpp │ ├── config │ │ ├── service.json │ │ ├── storage.json │ │ ├── service.xml │ │ └── storage.xml │ ├── service │ │ └── src │ │ │ ├── id │ │ │ └── service.h │ │ │ ├── main.cpp │ │ │ └── data │ │ │ └── responses.h │ ├── common │ │ └── include │ │ │ └── common │ │ │ ├── id │ │ │ └── service.h │ │ │ ├── data │ │ │ ├── data.h │ │ │ └── meta │ │ │ │ └── data.h │ │ │ └── interface │ │ │ ├── ps │ │ │ └── iemployee_storage.h │ │ │ └── iemployee_storage.h │ └── CMakeLists.txt ├── reflection │ └── CMakeLists.txt ├── http_echo_server │ ├── CMakeLists.txt │ ├── config │ │ ├── config.json │ │ └── config.xml │ └── src │ │ └── main.cpp └── common │ └── cmake │ ├── settings.cmake │ └── mif.cmake ├── src └── mif │ ├── common │ ├── config.h.in │ ├── version.h.in │ └── uuid_generator.cpp │ ├── remote │ └── factory.cpp │ ├── service │ └── external.cpp │ ├── net │ ├── clients │ │ ├── frame_writer.cpp │ │ ├── gzip_compressor.cpp │ │ └── gzip_decompressor.cpp │ ├── tcp │ │ └── detail │ │ │ └── session.h │ └── http │ │ └── detail │ │ └── utility.h │ ├── db │ └── postgresql │ │ └── detail │ │ └── statement.h │ └── application │ └── tcp_service.cpp ├── download_third_party.sh ├── include └── mif │ ├── common │ ├── unused.h │ ├── types.h │ ├── hash_calc.h │ ├── log_init.h │ ├── uuid_generator.h │ ├── icollection.h │ ├── thread_pool.h │ ├── detail │ │ ├── hierarchy.h │ │ ├── type_logic_funcs.h │ │ └── method.h │ ├── index_sequence.h │ └── log.h │ ├── net │ ├── icontrol.h │ ├── ipublisher.h │ ├── ihandler.h │ ├── http │ │ ├── servlet.h │ │ ├── detail │ │ │ ├── content_tags.h │ │ │ ├── params.h │ │ │ └── content.h │ │ ├── codes.h │ │ ├── iweb_service.h │ │ ├── request_handler.h │ │ ├── methods.h │ │ ├── clients.h │ │ ├── ioutput_pack.h │ │ ├── serializer │ │ │ ├── json.h │ │ │ ├── plain_text.h │ │ │ └── xml.h │ │ ├── converter │ │ │ └── content │ │ │ │ ├── json.h │ │ │ │ ├── plain_text.h │ │ │ │ ├── raw.h │ │ │ │ └── xml.h │ │ ├── iinput_pack.h │ │ ├── server.h │ │ └── make_web_service.h │ ├── iconnection.h │ ├── tcp │ │ ├── server.h │ │ ├── clients.h │ │ └── connection.h │ ├── iclient_factory.h │ ├── clients │ │ ├── frame_writer.h │ │ ├── gzip_compressor.h │ │ ├── gzip_decompressor.h │ │ ├── frame_reader.h │ │ └── parallel_handler.h │ └── client.h │ ├── service │ ├── icheckable.h │ ├── id │ │ └── service.h │ ├── ipool.h │ ├── make.h │ ├── ifactory.h │ ├── create.h │ ├── external.h │ ├── ilocator.h │ └── root_locator.h │ ├── db │ ├── iconnection_pool.h │ ├── istatement.h │ ├── iconnection.h │ ├── id │ │ └── service.h │ ├── irecordset.h │ └── transaction.h │ ├── remote │ ├── meta │ │ ├── iservice.h │ │ └── service │ │ │ └── icheckable.h │ ├── serialization │ │ ├── serialization.h │ │ └── detail │ │ │ └── tag.h │ ├── predefined │ │ ├── serialization │ │ │ ├── xml.h │ │ │ ├── json.h │ │ │ └── boost │ │ │ │ ├── xml.h │ │ │ │ ├── text.h │ │ │ │ └── binary.h │ │ └── protocol │ │ │ ├── simple_frame.h │ │ │ └── archived_frame.h │ ├── factory.h │ └── detail │ │ ├── meta │ │ └── iobject_manager.h │ │ └── iobject_manager.h │ └── application │ ├── id │ └── config.h │ ├── iconfig.h │ ├── net_base_application.h │ ├── http_server.h │ ├── tcp_service.h │ └── tcp_service_client.h ├── template └── src │ └── main.cpp └── LICENSE /cmake/version.cmake: -------------------------------------------------------------------------------- 1 | set (MIF_VERSION_MAJOR 1) 2 | set (MIF_VERSION_MINOR 5) 3 | set (MIF_VERSION_PATCH 1) 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.27) 2 | 3 | project(Mif) 4 | 5 | include (cmake/settings.cmake) 6 | include (cmake/third_party.cmake) 7 | include (cmake/library.cmake) 8 | include (cmake/install.cmake) 9 | -------------------------------------------------------------------------------- /cmake/third_party_paths.cmake: -------------------------------------------------------------------------------- 1 | # zlib 2 | set (MIF_ZLIB_LOCAL_PATH "${THITD_PARTY_SOURCES_PATH}/zlib/") 3 | 4 | # boost 5 | set (MIF_BOOST_LOCAL_PATH "${THITD_PARTY_SOURCES_PATH}/boost/") 6 | 7 | # libpq 8 | set (MIF_LIBPQ_LOCAL_PATH "${THITD_PARTY_SOURCES_PATH}/libpq/") 9 | -------------------------------------------------------------------------------- /cmake/install.cmake: -------------------------------------------------------------------------------- 1 | if (MIF_STATIC_LIBS) 2 | install (TARGETS ${PROJECT_LC} EXPORT ${PROJECT_LC} 3 | ARCHIVE DESTINATION lib 4 | ) 5 | endif() 6 | 7 | if (MIF_SHARED_LIBS) 8 | install (TARGETS ${PROJECT_LC}${MIF_SHARED_LIB_SUFFIX} EXPORT ${PROJECT_LC}${MIF_SHARED_LIB_SUFFIX} 9 | LIBRARY DESTINATION lib 10 | ) 11 | endif() 12 | 13 | install(DIRECTORY include/${PROJECT_LC} DESTINATION include) 14 | -------------------------------------------------------------------------------- /examples/http/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "daemon": 0, 4 | "log": { 5 | "level": 4, 6 | "dir": ".", 7 | "pattern": "log_%5N.log" 8 | } 9 | }, 10 | "data": 11 | { 12 | "server": { 13 | "host": "0.0.0.0", 14 | "port": "55555", 15 | "workers": 8, 16 | "timeout": 10000000 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/visitor/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "daemon": 0, 4 | "log": { 5 | "level": 4, 6 | "dir": ".", 7 | "pattern": "log_%5N.log" 8 | } 9 | }, 10 | "data": 11 | { 12 | "server": { 13 | "host": "0.0.0.0", 14 | "port": "55555", 15 | "workers": 8, 16 | "timeout": 10000000 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/complex_type/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "daemon": 0, 4 | "log": { 5 | "level": 4, 6 | "dir": ".", 7 | "pattern": "log_%5N.log" 8 | } 9 | }, 10 | "data": 11 | { 12 | "server": { 13 | "host": "0.0.0.0", 14 | "port": "55555", 15 | "workers": 8, 16 | "timeout": 10000000 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/hello_world/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "daemon": 0, 4 | "log": { 5 | "level": 4, 6 | "dir": ".", 7 | "pattern": "log_%5N.log" 8 | } 9 | }, 10 | "data": 11 | { 12 | "server": { 13 | "host": "0.0.0.0", 14 | "port": "55555", 15 | "workers": 8, 16 | "timeout": 10000000 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/inheritance/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "daemon": 0, 4 | "log": { 5 | "level": 4, 6 | "dir": ".", 7 | "pattern": "log_%5N.log" 8 | } 9 | }, 10 | "data": 11 | { 12 | "server": { 13 | "host": "0.0.0.0", 14 | "port": "55555", 15 | "workers": 8, 16 | "timeout": 10000000 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/mif/common/config.h.in: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 10.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_CONFIG_H__ 9 | #define __MIF_COMMON_CONFIG_H__ 10 | 11 | ${MIF_COMPILER_DEFINES} 12 | 13 | #endif // !__MIF_COMMON_CONFIG_H__ 14 | -------------------------------------------------------------------------------- /cmake/options.cmake: -------------------------------------------------------------------------------- 1 | # Third-party projects options 2 | option (MIF_NEED_THIRD_PARTY_BUILD "[MIF] Need to build third-party libraries" ON) 3 | option (MIF_WITH_POSTGRESQL "[MIF] Support working with PostgreSQL library (libpq)" ON) 4 | 5 | # MIF library options 6 | option (MIF_STATIC_LIBS "[MIF] Create static libs" ON) 7 | option (MIF_SHARED_LIBS "[MIF] Create shared libs" OFF) 8 | 9 | # Json writer option 10 | option (MIF_PRETTY_JSON_WRITER "[MIF] Write pretty json" ON) 11 | -------------------------------------------------------------------------------- /examples/http_crud/db/schema.sql: -------------------------------------------------------------------------------- 1 | BEGIN; 2 | 3 | CREATE TYPE "Position" AS ENUM 4 | ( 5 | 'Unknown', 6 | 'Developer', 7 | 'Manager' 8 | ); 9 | 10 | CREATE TABLE employees 11 | ( 12 | employee_id bigserial not null primary key, 13 | name varchar not null, 14 | last_name varchar not null, 15 | age integer not null, 16 | email varchar not null, 17 | position "Position" not null default 'Unknown', 18 | rate numeric(10, 2) not null 19 | ); 20 | 21 | COMMIT; 22 | -------------------------------------------------------------------------------- /examples/microservices/storage/db/schema.sql: -------------------------------------------------------------------------------- 1 | BEGIN; 2 | 3 | CREATE TYPE "Position" AS ENUM 4 | ( 5 | 'Unknown', 6 | 'Developer', 7 | 'Manager' 8 | ); 9 | 10 | CREATE TABLE employees 11 | ( 12 | employee_id bigserial not null primary key, 13 | name varchar not null, 14 | last_name varchar not null, 15 | age integer not null, 16 | email varchar not null, 17 | position "Position" not null default 'Unknown', 18 | rate numeric(10, 2) not null 19 | ); 20 | 21 | COMMIT; 22 | -------------------------------------------------------------------------------- /examples/http/config/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | 4 7 | . 8 | log_%5N.log 9 | 10 | 11 | 12 | 13 | 0.0.0.0 14 | 55555 15 | 8 16 | 10000000 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/hello_world/config/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | 4 7 | . 8 | log_%5N.log 9 | 10 | 11 | 12 | 13 | 0.0.0.0 14 | 55555 15 | 8 16 | 10000000 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/http_crud/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "daemon": 0, 4 | "log": { 5 | "level": 4, 6 | "dir": "../build/", 7 | "pattern": "log_%5N.log" 8 | } 9 | }, 10 | "data": 11 | { 12 | "server": 13 | { 14 | "host": "0.0.0.0", 15 | "port": "55555", 16 | "workers": 8, 17 | "timeout": 10000000 18 | }, 19 | "database": 20 | { 21 | "host": "localhost", 22 | "port": 5432, 23 | "user": "postgres", 24 | "password": "postgres", 25 | "dbname": "crud_test", 26 | "connectiontimeout": 10 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/inheritance/config/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | 4 7 | . 8 | log_%5N.log 9 | 10 | 11 | 12 | 13 | 0.0.0.0 14 | 55555 15 | 8 16 | 10000000 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/reflection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.27) 2 | 3 | project(Reflection) 4 | set(PROJECT ${PROJECT_NAME}) 5 | string(TOLOWER "${PROJECT}" PROJECT_LC) 6 | 7 | include (../common/cmake/mif.cmake) 8 | 9 | set(COMMON_HEADERS 10 | ${COMMON_HEADERS} 11 | ) 12 | 13 | set(HEADERS 14 | ${HEADERS} 15 | ${COMMON_HEADERS} 16 | ) 17 | 18 | set(SOURCES 19 | ${SOURCES} 20 | ) 21 | 22 | add_executable(${PROJECT_LC} ${HEADERS} ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp) 23 | target_link_libraries(${PROJECT_LC} ${LIBRARIES}) 24 | -------------------------------------------------------------------------------- /examples/visitor/config/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | 4 7 | . 8 | log_%5N.log 9 | 10 | 11 | 12 | 13 | 0.0.0.0 14 | 55555 15 | 8 16 | 10000000 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/complex_type/config/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | 4 7 | . 8 | log_%5N.log 9 | 10 | 11 | 12 | 13 | 0.0.0.0 14 | 55555 15 | 8 16 | 10000000 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/http_echo_server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.27) 2 | 3 | project(http_echo_server) 4 | set(PROJECT ${PROJECT_NAME}) 5 | string(TOLOWER "${PROJECT}" PROJECT_LC) 6 | 7 | include (../common/cmake/mif.cmake) 8 | 9 | set(COMMON_HEADERS 10 | ${COMMON_HEADERS} 11 | ) 12 | 13 | set(HEADERS 14 | ${HEADERS} 15 | ${COMMON_HEADERS} 16 | ) 17 | 18 | set(SOURCES 19 | ${SOURCES} 20 | ) 21 | 22 | add_executable(${PROJECT_LC} ${HEADERS} ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp) 23 | target_link_libraries(${PROJECT_LC} ${LIBRARIES}) 24 | -------------------------------------------------------------------------------- /download_third_party.sh: -------------------------------------------------------------------------------- 1 | mkdir third_party_sources ||: 2 | cd third_party_sources 3 | git clone --branch v1.3 https://github.com/madler/zlib.git 4 | 5 | wget https://boostorg.jfrog.io/artifactory/main/release/1.85.0/source/boost_1_85_0.tar.gz 6 | tar zxvf boost_1_85_0.tar.gz 7 | mv boost_1_85_0 boost 8 | rm boost_1_85_0.tar.gz 9 | 10 | # In Ubuntu you might have to install some additional packages 11 | # - liblz4-dev 12 | # - pkgconf 13 | # - bison 14 | # - flex 15 | 16 | wget https://github.com/postgres/postgres/archive/REL_16_1.tar.gz 17 | tar zxvf REL_16_1.tar.gz 18 | mv postgres-REL_16_1 libpq 19 | rm REL_16_1.tar.gz 20 | -------------------------------------------------------------------------------- /examples/microservices/config/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "daemon": 0, 4 | "log": { 5 | "level": 4, 6 | "dir": ".", 7 | "pattern": "log_%5N.log" 8 | } 9 | }, 10 | "data": 11 | { 12 | "server": { 13 | "host": "0.0.0.0", 14 | "port": "55555", 15 | "workers": 8, 16 | "timeout": 10000000 17 | }, 18 | "storage": { 19 | "host": "localhost", 20 | "port": "55000", 21 | "workers": 8, 22 | "timeout": 10000000 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/http_echo_server/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "daemon": 0, 4 | "log": { 5 | "level": 4, 6 | "dir": ".", 7 | "pattern": "log_%5N.log" 8 | } 9 | }, 10 | "data": 11 | { 12 | "server": { 13 | "host": "0.0.0.0", 14 | "port": "55555", 15 | "workers": 8, 16 | "timeout": 10000000, 17 | "http": { 18 | "headerslimit": 512, 19 | "bodylimit": 1024, 20 | "chunksize": 1024, 21 | "pipelinelimit": 4 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /include/mif/common/unused.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 11.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_UNUSED_H__ 9 | #define __MIF_COMMON_UNUSED_H__ 10 | 11 | namespace Mif 12 | { 13 | namespace Common 14 | { 15 | 16 | template 17 | inline void Unused(T && ... ) 18 | { 19 | } 20 | 21 | } // namespace Common 22 | } // namespace Mif 23 | 24 | #endif // !__MIF_COMMON_UNUSED_H__ 25 | -------------------------------------------------------------------------------- /include/mif/net/icontrol.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_ICONTROL_H__ 9 | #define __MIF_NET_ICONTROL_H__ 10 | 11 | namespace Mif 12 | { 13 | namespace Net 14 | { 15 | 16 | struct IControl 17 | { 18 | virtual ~IControl() = default; 19 | virtual void CloseMe() = 0; 20 | }; 21 | 22 | } // namespace Net 23 | } // namespace Mif 24 | 25 | #endif // !__MIF_NET_ICONTROL_H__ 26 | -------------------------------------------------------------------------------- /include/mif/common/types.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_TYPES_H__ 9 | #define __MIF_COMMON_TYPES_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | namespace Mif 16 | { 17 | namespace Common 18 | { 19 | 20 | using Buffer = std::vector; 21 | using BufferPtr = std::shared_ptr; 22 | 23 | } // namespace Common 24 | } // namespace Mif 25 | 26 | #endif // !__MIF_COMMON_TYPES_H__ 27 | -------------------------------------------------------------------------------- /examples/microservices/config/storage.json: -------------------------------------------------------------------------------- 1 | { 2 | "common": { 3 | "daemon": 0, 4 | "log": { 5 | "level": 4, 6 | "dir": ".", 7 | "pattern": "log_%5N.log" 8 | } 9 | }, 10 | "data": 11 | { 12 | "server": { 13 | "host": "0.0.0.0", 14 | "port": "55000", 15 | "workers": 8, 16 | "timeout": 10000000 17 | }, 18 | "database": 19 | { 20 | "host": "localhost", 21 | "port": 5432, 22 | "user": "postgres", 23 | "password": "postgres", 24 | "dbname": "crud_test", 25 | "connectiontimeout": 10 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/http_crud/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.27) 2 | 3 | project(http_crud) 4 | set(PROJECT ${PROJECT_NAME}) 5 | string(TOLOWER "${PROJECT}" PROJECT_LC) 6 | 7 | include (../common/cmake/mif.cmake) 8 | 9 | include_directories(${CMAKE_SOURCE_DIR}/../common/include) 10 | 11 | set(COMMON_HEADERS 12 | ${COMMON_HEADERS} 13 | ) 14 | 15 | set(HEADERS 16 | ${HEADERS} 17 | ${COMMON_HEADERS} 18 | ) 19 | 20 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) 21 | 22 | set(SOURCES 23 | ${SOURCES} 24 | ${CMAKE_CURRENT_SOURCE_DIR}/src/employee_service.cpp 25 | ) 26 | 27 | add_executable(${PROJECT_LC} ${HEADERS} ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp) 28 | target_link_libraries(${PROJECT_LC} ${LIBRARIES}) 29 | -------------------------------------------------------------------------------- /examples/http/common/include/common/id/service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __HTTP_COMMON_ID_SERVICE_H__ 9 | #define __HTTP_COMMON_ID_SERVICE_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | namespace Service 15 | { 16 | namespace Id 17 | { 18 | 19 | enum 20 | { 21 | Service = Mif::Common::Crc32("WebService.Admin") 22 | }; 23 | 24 | } // namespace Id 25 | } // namespace Service 26 | 27 | #endif // !__HTTP_COMMON_ID_SERVICE_H__ 28 | -------------------------------------------------------------------------------- /examples/visitor/common/include/common/id/service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 02.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __VISITOR_COMMON_ID_SERVICE_H__ 9 | #define __VISITOR_COMMON_ID_SERVICE_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | namespace Service 15 | { 16 | namespace Id 17 | { 18 | 19 | enum 20 | { 21 | Service = Mif::Common::Crc32("Service") 22 | }; 23 | 24 | } // namespace Id 25 | } // namespace Service 26 | 27 | #endif // !__VISITOR_COMMON_ID_SERVICE_H__ 28 | -------------------------------------------------------------------------------- /examples/microservices/config/service.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | 4 7 | . 8 | log_%5N.log 9 | 10 | 11 | 12 | 13 | 0.0.0.0 14 | 55555 15 | 8 16 | 10000000 17 | 18 | 19 | localhost 20 | 55000 21 | 8 22 | 10000000 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/inheritance/common/include/common/id/service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __INHERITANCE_COMMON_ID_SERVICE_H__ 9 | #define __INHERITANCE_COMMON_ID_SERVICE_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | namespace Service 15 | { 16 | namespace Id 17 | { 18 | 19 | enum 20 | { 21 | Service = Mif::Common::Crc32("Service") 22 | }; 23 | 24 | } // namespace Id 25 | } // namespace Service 26 | 27 | #endif // !__INHERITANCE_COMMON_ID_SERVICE_H__ 28 | -------------------------------------------------------------------------------- /examples/complex_type/common/include/common/id/service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __COMPLEX_TYPE_COMMON_ID_SERVICE_H__ 9 | #define __COMPLEX_TYPE_COMMON_ID_SERVICE_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | namespace Service 15 | { 16 | namespace Id 17 | { 18 | 19 | enum 20 | { 21 | MyCompany = Mif::Common::Crc32("MyCompany") 22 | }; 23 | 24 | } // namespace Id 25 | } // namespace Service 26 | 27 | #endif // !__COMPLEX_TYPE_COMMON_ID_SERVICE_H__ 28 | -------------------------------------------------------------------------------- /examples/hello_world/common/include/common/id/service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __HELLO_WORLD_COMMON_ID_SERVICE_H__ 9 | #define __HELLO_WORLD_COMMON_ID_SERVICE_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | namespace Service 15 | { 16 | namespace Id 17 | { 18 | 19 | enum 20 | { 21 | HelloWorld = Mif::Common::Crc32("HelloWorld") 22 | }; 23 | 24 | } // namespace Id 25 | } // namespace Service 26 | 27 | #endif // !__HELLO_WORLD_COMMON_ID_SERVICE_H__ 28 | -------------------------------------------------------------------------------- /examples/microservices/service/src/id/service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 08.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MICROSERVICES_SERVICE_ID_SERVICE_H__ 9 | #define __MICROSERVICES_SERVICE_ID_SERVICE_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | namespace Service 15 | { 16 | namespace Id 17 | { 18 | 19 | enum 20 | { 21 | Employee = Mif::Common::Crc32("Employee.Http") 22 | }; 23 | 24 | } // namespace Id 25 | } // namespace Service 26 | 27 | #endif // !__MICROSERVICES_SERVICE_ID_SERVICE_H__ 28 | -------------------------------------------------------------------------------- /include/mif/net/ipublisher.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_IPUBLISHER_H__ 9 | #define __MIF_NET_IPUBLISHER_H__ 10 | 11 | // MIF 12 | #include "mif/common/types.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Net 17 | { 18 | 19 | struct IPublisher 20 | { 21 | virtual ~IPublisher() = default; 22 | virtual void Publish(Common::Buffer buffer) = 0; 23 | }; 24 | 25 | 26 | } // namespace Net 27 | } // namespace Mif 28 | 29 | #endif // !__MIF_NET_IPUBLISHER_H__ 30 | -------------------------------------------------------------------------------- /examples/http_crud/config/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | 4 7 | . 8 | log_%5N.log 9 | 10 | 11 | 12 | 13 | 0.0.0.0 14 | 55555 15 | 8 16 | 10000000 17 | 18 | 19 | localhost 20 | 5432 21 | postgres 22 | postgres 23 | crud_test 24 | 10 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /include/mif/net/ihandler.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_IHANDLER_H__ 9 | #define __MIF_NET_IHANDLER_H__ 10 | 11 | // MIF 12 | #include "mif/common/types.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Net 17 | { 18 | 19 | struct IHandler 20 | { 21 | virtual ~IHandler() = default; 22 | virtual void OnData(Common::Buffer buffer) = 0; 23 | virtual void OnClose() = 0; 24 | }; 25 | 26 | } // namespace Net 27 | } // namespace Mif 28 | 29 | #endif // !__MIF_NET_IHANDLER_H__ 30 | -------------------------------------------------------------------------------- /examples/http_echo_server/config/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | 4 7 | . 8 | log_%5N.log 9 | 10 | 11 | 12 | 13 | 0.0.0.0 14 | 55555 15 | 8 16 | 10000000 17 | 18 | 512 19 | 1024 20 | 1024 21 | 4 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /template/src/main.cpp: -------------------------------------------------------------------------------- 1 | // MIF 2 | #include 3 | #include 4 | 5 | class Application 6 | : public Mif::Application::Application 7 | { 8 | public: 9 | Application(int argc, char const **argv) 10 | : Mif::Application::Application{argc, argv} 11 | { 12 | MIF_LOG(Info) << "Application"; 13 | } 14 | 15 | ~Application() 16 | { 17 | MIF_LOG(Info) << "~Application"; 18 | } 19 | 20 | virtual void OnStart() override final 21 | { 22 | MIF_LOG(Info) << "OnStart"; 23 | } 24 | 25 | virtual void OnStop() override final 26 | { 27 | MIF_LOG(Info) << "OnStop"; 28 | } 29 | }; 30 | 31 | int main(int argc, char const **argv) 32 | { 33 | return Mif::Application::Run(argc, argv); 34 | } 35 | -------------------------------------------------------------------------------- /examples/microservices/config/storage.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 0 5 | 6 | 4 7 | . 8 | log_%5N.log 9 | 10 | 11 | 12 | 13 | 0.0.0.0 14 | 55000 15 | 8 16 | 10000000 17 | 18 | 19 | localhost 20 | 5432 21 | postgres 22 | postgres 23 | crud_test 24 | 10 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /include/mif/net/http/servlet.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_SERVLET_H__ 9 | #define __MIF_NET_HTTP_SERVLET_H__ 10 | 11 | // MIF 12 | #include "mif/net/iclient_factory.h" 13 | #include "mif/net/http/request_handler.h" 14 | 15 | namespace Mif 16 | { 17 | namespace Net 18 | { 19 | namespace Http 20 | { 21 | 22 | ServerHandler MakeServlet(std::shared_ptr factory, std::uint32_t sessionTimeout = 180 /*seconds*/); 23 | 24 | } // namespace Http 25 | } // namespace Net 26 | } // namespace Mif 27 | 28 | #endif // !__MIF_NET_HTTP_SERVLET_H__ 29 | -------------------------------------------------------------------------------- /include/mif/net/iconnection.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_ICONNECTION_H__ 9 | #define __MIF_NET_ICONNECTION_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/net/client.h" 16 | 17 | namespace Mif 18 | { 19 | namespace Net 20 | { 21 | 22 | struct IConnection 23 | { 24 | virtual ~IConnection() = default; 25 | 26 | using ClientPtr = std::shared_ptr; 27 | 28 | virtual ClientPtr GetClient() = 0; 29 | }; 30 | 31 | } // namespace Net 32 | } // namespace Mif 33 | 34 | #endif // !__MIF_NET_ICONNECTION_H__ 35 | -------------------------------------------------------------------------------- /include/mif/service/icheckable.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 05.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_SERVICE_ICHECKABLE_H__ 9 | #define __MIF_SERVICE_ICHECKABLE_H__ 10 | 11 | // MIF 12 | #include "mif/service/iservice.h" 13 | #include "mif/service/make.h" 14 | 15 | namespace Mif 16 | { 17 | namespace Service 18 | { 19 | 20 | struct ICheckable 21 | : public Inherit 22 | { 23 | virtual bool IsGood() const = 0; 24 | }; 25 | 26 | using ICheckablePtr = Service::TServicePtr; 27 | 28 | } // namespace Service 29 | } // namespace Mif 30 | 31 | #endif // !__MIF_SERVICE_ICHECKABLE_H__ 32 | -------------------------------------------------------------------------------- /include/mif/db/iconnection_pool.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 10.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_DB_ICONNECTION_POOL_H__ 9 | #define __MIF_DB_ICONNECTION_POOL_H__ 10 | 11 | // MIF 12 | #include "mif/db/iconnection.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Db 17 | { 18 | 19 | struct IConnectionPool 20 | : public Service::Inherit 21 | { 22 | virtual IConnectionPtr GetConnection() const = 0; 23 | }; 24 | 25 | using IConnectionPoolPtr = Service::TServicePtr; 26 | 27 | } // namespace Db 28 | } // namespace Mif 29 | 30 | #endif // !__MIF_DB_ICONNECTION_POOL_H__ 31 | -------------------------------------------------------------------------------- /examples/microservices/common/include/common/id/service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 08.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MICROSERVICES_COMMON_ID_SERVICE_H__ 9 | #define __MICROSERVICES_COMMON_ID_SERVICE_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | namespace Common 15 | { 16 | namespace Service 17 | { 18 | namespace Id 19 | { 20 | 21 | enum 22 | { 23 | PGEmployeeStorage = Mif::Common::Crc32("EmployeeStorage.PostgreSQL") 24 | }; 25 | 26 | } // namespace Id 27 | } // namespace Service 28 | } // namespace Common 29 | 30 | #endif // !__MICROSERVICES_COMMON_ID_SERVICE_H__ 31 | -------------------------------------------------------------------------------- /include/mif/common/hash_calc.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 04.2021 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_HASH_CALC_H__ 9 | #define __MIF_COMMON_HASH_CALC_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | namespace Mif 16 | { 17 | namespace Common 18 | { 19 | namespace Hash 20 | { 21 | 22 | std::string Crc32(void const *data, std::size_t size); 23 | std::string Md5(void const *data, std::size_t size); 24 | std::string Sha1(void const *data, std::size_t size); 25 | 26 | } // namespace Hash 27 | } // namespace Common 28 | } // namespace Mif 29 | 30 | #endif // !__MIF_COMMON_HASH_CALC_H__ 31 | -------------------------------------------------------------------------------- /examples/inheritance/server/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | 11 | // COMMON 12 | #include "common/id/service.h" 13 | #include "common/ps/iface.h" 14 | 15 | class Application 16 | : public Mif::Application::TcpService 17 | { 18 | public: 19 | using TcpService::TcpService; 20 | 21 | private: 22 | // Mif.Application.TcpService 23 | virtual void Init(Mif::Service::FactoryPtr factory) override final 24 | { 25 | factory->AddClass<::Service::Id::Service>(); 26 | } 27 | }; 28 | 29 | int main(int argc, char const **argv) 30 | { 31 | return Mif::Application::Run(argc, argv); 32 | } 33 | -------------------------------------------------------------------------------- /examples/visitor/server/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 02.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | 11 | // COMMON 12 | #include "common/id/service.h" 13 | #include "common/ps/iface.h" 14 | 15 | class Application 16 | : public Mif::Application::TcpService 17 | { 18 | public: 19 | using TcpService::TcpService; 20 | 21 | private: 22 | // Mif.Application.TcpService 23 | virtual void Init(Mif::Service::FactoryPtr factory) override final 24 | { 25 | factory->AddClass<::Service::Id::Service>(); 26 | } 27 | }; 28 | 29 | int main(int argc, char const **argv) 30 | { 31 | return Mif::Application::Run(argc, argv); 32 | } 33 | -------------------------------------------------------------------------------- /examples/complex_type/server/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 10.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | 11 | // COMMON 12 | #include "common/id/service.h" 13 | #include "common/ps/imy_company.h" 14 | 15 | class Application 16 | : public Mif::Application::TcpService 17 | { 18 | public: 19 | using TcpService::TcpService; 20 | 21 | private: 22 | // Mif.Application.Application 23 | virtual void Init(Mif::Service::FactoryPtr factory) override final 24 | { 25 | factory->AddClass<::Service::Id::MyCompany>(); 26 | } 27 | }; 28 | 29 | int main(int argc, char const **argv) 30 | { 31 | return Mif::Application::Run(argc, argv); 32 | } 33 | -------------------------------------------------------------------------------- /examples/hello_world/server/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | 11 | // COMMON 12 | #include "common/id/service.h" 13 | #include "common/ps/ihello_world.h" 14 | 15 | class Application 16 | : public Mif::Application::TcpService 17 | { 18 | public: 19 | using TcpService::TcpService; 20 | 21 | private: 22 | // Mif.Application.TcpService 23 | virtual void Init(Mif::Service::FactoryPtr factory) override final 24 | { 25 | factory->AddClass(); 26 | } 27 | }; 28 | 29 | int main(int argc, char const **argv) 30 | { 31 | return Mif::Application::Run(argc, argv); 32 | } 33 | -------------------------------------------------------------------------------- /examples/http/common/include/common/interface/iadmin.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __HTTP_COMMON_INTERFACE_IADMIN_H__ 9 | #define __HTTP_COMMON_INTERFACE_IADMIN_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include 16 | 17 | namespace Service 18 | { 19 | 20 | struct IAdmin 21 | : public Mif::Service::Inherit 22 | { 23 | virtual void SetTitle(std::string const &title) = 0; 24 | virtual void SetBody(std::string const &body) = 0; 25 | virtual std::string GetPage() const = 0; 26 | }; 27 | 28 | } // namespace Service 29 | 30 | #endif // !__HTTP_COMMON_INTERFACE_IADMIN_H__ 31 | -------------------------------------------------------------------------------- /include/mif/remote/meta/iservice.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 02.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_META_ISERVICE_H__ 9 | #define __MIF_REMOTE_META_ISERVICE_H__ 10 | 11 | // MIF 12 | #include "mif/remote/ps.h" 13 | #include "mif/service/iservice.h" 14 | 15 | namespace Mif 16 | { 17 | namespace Service 18 | { 19 | namespace Meta 20 | { 21 | 22 | using Service::IService; 23 | 24 | MIF_REMOTE_PS_BEGIN(IService) 25 | MIF_REMOTE_PS_END() 26 | 27 | } // namespace Meta 28 | } // namespace Service 29 | } // namespace Mif 30 | 31 | MIF_REMOTE_REGISTER_PS(Mif::Service::Meta::IService) 32 | 33 | #endif // !__MIF_REMOTE_META_ISERVICE_H__ 34 | -------------------------------------------------------------------------------- /include/mif/common/log_init.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 11.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_LOG_INIT_H__ 9 | #define __MIF_COMMON_LOG_INIT_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/common/log.h" 17 | 18 | namespace Mif 19 | { 20 | namespace Common 21 | { 22 | 23 | void InitConsoleLog(Log::Level const &level = Log::Level::Trace); 24 | 25 | void InitFileLog(Log::Level const &level, 26 | std::string const &logDir, std::string const &filePattern, 27 | std::size_t maxSize = 1, std::size_t maxCount = 10); 28 | 29 | } // namespace Common 30 | } // namespace Mif 31 | 32 | #endif // !__MIF_COMMON_LOG_INIT_H__ 33 | -------------------------------------------------------------------------------- /include/mif/common/uuid_generator.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_UUID_GENERATOR_H__ 9 | #define __MIF_COMMON_UUID_GENERATOR_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | namespace Mif 16 | { 17 | namespace Common 18 | { 19 | 20 | class UuidGenerator final 21 | { 22 | public: 23 | UuidGenerator(); 24 | ~UuidGenerator(); 25 | 26 | std::string Generate() const; 27 | 28 | private: 29 | class Impl; 30 | std::unique_ptr m_impl; 31 | }; 32 | 33 | } // namespace Common 34 | } // namespace Mif 35 | 36 | #endif // !__MIF_COMMON_UUID_GENERATOR_H__ 37 | -------------------------------------------------------------------------------- /examples/hello_world/common/include/common/interface/ihello_world.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __HELLO_WORLD_COMMON_INTERFACE_IHELLO_WORLD_H__ 9 | #define __HELLO_WORLD_COMMON_INTERFACE_IHELLO_WORLD_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include 16 | 17 | namespace Service 18 | { 19 | 20 | struct IHelloWorld 21 | : public Mif::Service::Inherit 22 | { 23 | virtual void AddWord(std::string const &word) = 0; 24 | virtual std::string GetText() const = 0; 25 | virtual void Clean() = 0; 26 | }; 27 | 28 | } // namespace Service 29 | 30 | #endif // !__HELLO_WORLD_COMMON_INTERFACE_IHELLO_WORLD_H__ 31 | -------------------------------------------------------------------------------- /include/mif/service/id/service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_SERVICE_ID_SERVICE_H__ 9 | #define __MIF_SERVICE_ID_SERVICE_H__ 10 | 11 | // MIF 12 | #include "mif/common/crc32.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Service 17 | { 18 | namespace Id 19 | { 20 | 21 | enum 22 | { 23 | 24 | Locator = Common::Crc32("Mif.Service.Locator"), 25 | Pool = Common::Crc32("Mif.Service.Pool"), 26 | PerThreadPool = Common::Crc32("Mif.Service.PerThreadPool") 27 | 28 | }; 29 | 30 | } // namespace Id 31 | } // namespace Service 32 | } // namespace Mif 33 | 34 | #endif // !__MIF_SERVICE_ID_SERVICE_H__ 35 | -------------------------------------------------------------------------------- /include/mif/net/http/detail/content_tags.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_DETAIL_CONTENT_TAGS_H__ 9 | #define __MIF_NET_HTTP_DETAIL_CONTENT_TAGS_H__ 10 | 11 | // MIF 12 | #include "mif/common/static_string.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Net 17 | { 18 | namespace Http 19 | { 20 | namespace Detail 21 | { 22 | namespace Tag 23 | { 24 | 25 | using Document = MIF_STATIC_STR("document"); 26 | 27 | } // namespace Tag 28 | } // namespace Detail 29 | } // namespace Http 30 | } // namespace Net 31 | } // namespace Mif 32 | 33 | 34 | #endif // !__MIF_NET_HTTP_DETAIL_CONTENT_TAGS_H__ 35 | -------------------------------------------------------------------------------- /include/mif/common/icollection.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_ICOLLECTION_H__ 9 | #define __MIF_COMMON_ICOLLECTION_H__ 10 | 11 | // MIF 12 | #include "mif/service/iservice.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Common 17 | { 18 | 19 | struct ICollection 20 | : public Service::Inherit 21 | { 22 | virtual bool IsEmpty() const = 0; 23 | virtual void Reset() = 0; 24 | virtual Service::IServicePtr Get() = 0; 25 | virtual bool Next() = 0; 26 | }; 27 | 28 | using ICollectionPtr = Service::TServicePtr; 29 | 30 | } // namespace Common 31 | } // namespace Mif 32 | 33 | #endif // !__MIF_COMMON_ICOLLECTION_H__ 34 | -------------------------------------------------------------------------------- /include/mif/remote/serialization/serialization.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_SERIALIZATION_SERIALIZATION_H__ 9 | #define __MIF_REMOTE_SERIALIZATION_SERIALIZATION_H__ 10 | 11 | namespace Mif 12 | { 13 | namespace Remote 14 | { 15 | namespace Serialization 16 | { 17 | 18 | template 19 | class SerializerTraits final 20 | { 21 | public: 22 | using Serializer = TSerializer; 23 | using Deserializer = TDeserializer; 24 | }; 25 | 26 | } // namespace Serialization 27 | } // namespace Remote 28 | } // namespace Mif 29 | 30 | 31 | #endif // !__MIF_REMOTE_SERIALIZATION_SERIALIZATION_H__ 32 | -------------------------------------------------------------------------------- /examples/complex_type/common/include/common/interface/imy_company.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 10.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __COMPLEX_TYPE_COMMON_INTERFACE_IMYCOMPANY_H__ 9 | #define __COMPLEX_TYPE_COMMON_INTERFACE_IMYCOMPANY_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | // THIS 15 | #include "common/data/data.h" 16 | 17 | namespace Service 18 | { 19 | 20 | struct IMyCompany 21 | : public Mif::Service::Inherit 22 | { 23 | virtual Data::ID AddEmployee(Data::Employee const &employee) = 0; 24 | virtual void RemoveAccount(Data::ID const &id) = 0; 25 | virtual Data::Employees GetEmployees() const = 0; 26 | }; 27 | 28 | } // namespace Service 29 | 30 | #endif // !__COMPLEX_TYPE_COMMON_INTERFACE_IMYCOMPANY_H__ 31 | -------------------------------------------------------------------------------- /include/mif/db/istatement.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_DB_ISTATEMENT_H__ 9 | #define __MIF_DB_ISTATEMENT_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/db/irecordset.h" 16 | #include "mif/service/iservice.h" 17 | 18 | namespace Mif 19 | { 20 | namespace Db 21 | { 22 | 23 | struct IStatement 24 | : public Service::Inherit 25 | { 26 | using Parameters = std::list; 27 | 28 | virtual IRecordsetPtr Execute(Parameters const ¶meters = {}) = 0; 29 | }; 30 | 31 | using IStatementPtr = Service::TServicePtr; 32 | 33 | } // namespace Db 34 | } // namespace Mif 35 | 36 | #endif // !__MIF_DB_ISTATEMENT_H__ 37 | -------------------------------------------------------------------------------- /include/mif/remote/meta/service/icheckable.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 05.2020 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_META_SERVICE_ICHECKABLE_H__ 9 | #define __MIF_REMOTE_META_SERVICE_ICHECKABLE_H__ 10 | 11 | // MIF 12 | #include "mif/remote/ps.h" 13 | #include "mif/service/icheckable.h" 14 | 15 | namespace Mif 16 | { 17 | namespace Service 18 | { 19 | namespace Meta 20 | { 21 | 22 | using Service::ICheckable; 23 | 24 | MIF_REMOTE_PS_BEGIN(ICheckable) 25 | MIF_REMOTE_METHOD(IsGood) 26 | MIF_REMOTE_PS_END() 27 | 28 | } // namespace Meta 29 | } // namespace Service 30 | } // namespace Mif 31 | 32 | MIF_REMOTE_REGISTER_PS(Mif::Service::Meta::ICheckable) 33 | 34 | #endif // !__MIF_REMOTE_META_SERVICE_ICHECKABLE_H__ 35 | -------------------------------------------------------------------------------- /include/mif/db/iconnection.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_DB_ICONNECTION_H__ 9 | #define __MIF_DB_ICONNECTION_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/db/istatement.h" 16 | #include "mif/service/iservice.h" 17 | 18 | namespace Mif 19 | { 20 | namespace Db 21 | { 22 | 23 | struct IConnection 24 | : public Service::Inherit 25 | { 26 | virtual void ExecuteDirect(std::string const &query) = 0; 27 | virtual IStatementPtr CreateStatement(std::string const &query) = 0; 28 | }; 29 | 30 | using IConnectionPtr = Service::TServicePtr; 31 | 32 | } // namespace Db 33 | } // namespace Mif 34 | 35 | #endif // !__MIF_DB_ICONNECTION_H__ 36 | -------------------------------------------------------------------------------- /examples/http/common/include/common/ps/iadmin.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __HTTP_COMMON_PS_IADMIN_H__ 9 | #define __HTTP_COMMON_PS_IADMIN_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include 16 | 17 | // THIS 18 | #include "common/interface/iadmin.h" 19 | 20 | namespace Service 21 | { 22 | namespace Meta 23 | { 24 | 25 | using namespace ::Service; 26 | 27 | MIF_REMOTE_PS_BEGIN(IAdmin) 28 | MIF_REMOTE_METHOD(SetTitle) 29 | MIF_REMOTE_METHOD(SetBody) 30 | MIF_REMOTE_METHOD(GetPage) 31 | MIF_REMOTE_PS_END() 32 | 33 | } // namespace Meta 34 | } // namespace Service 35 | 36 | MIF_REMOTE_REGISTER_PS(Service::Meta::IAdmin) 37 | 38 | #endif // !__HTTP_COMMON_PS_IADMIN_H__ 39 | -------------------------------------------------------------------------------- /include/mif/service/ipool.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 05.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_SERVICE_IPOOL_H__ 9 | #define __MIF_SERVICE_IPOOL_H__ 10 | 11 | // MIF 12 | #include "mif/service/iservice.h" 13 | #include "mif/service/make.h" 14 | 15 | namespace Mif 16 | { 17 | namespace Service 18 | { 19 | 20 | struct IPool 21 | : public Inherit 22 | { 23 | virtual IServicePtr GetService() const = 0; 24 | 25 | template 26 | TServicePtr GetService() const 27 | { 28 | return Service::Cast(GetService()); 29 | } 30 | }; 31 | 32 | using IPoolPtr = Service::TServicePtr; 33 | 34 | } // namespace Service 35 | } // namespace Mif 36 | 37 | #endif // !__MIF_SERVICE_IPOOL_H__ 38 | -------------------------------------------------------------------------------- /src/mif/remote/factory.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // STD 9 | #include 10 | 11 | // MIF 12 | #include "mif/remote/factory.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Remote 17 | { 18 | 19 | Factory::Factory(std::shared_ptr connection, ServiceCreator const &serviceCreator) 20 | : m_connection{connection} 21 | , m_serviceCreator{serviceCreator} 22 | { 23 | if (!m_connection) 24 | throw std::invalid_argument{"[Mif::Remote::Factory] Empty connection ptr."}; 25 | } 26 | 27 | Service::IServicePtr Factory::Create(Service::ServiceId id) 28 | { 29 | return m_serviceCreator(m_connection->GetClient(), id); 30 | } 31 | 32 | } // namespace Remote 33 | } // namespace Mif 34 | -------------------------------------------------------------------------------- /include/mif/net/http/codes.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_CODES_H__ 9 | #define __MIF_NET_HTTP_CODES_H__ 10 | 11 | namespace Mif 12 | { 13 | namespace Net 14 | { 15 | namespace Http 16 | { 17 | 18 | enum class Code 19 | { 20 | Ok, 21 | NoContent, 22 | MovePerm, 23 | MoveTemp, 24 | NotModified, 25 | BadRequest, 26 | NotFound, 27 | BadMethod, 28 | Unauthorized, 29 | Internal, 30 | NotImplemented, 31 | Unavaliable 32 | }; 33 | 34 | } // namespace Http 35 | } // namespace Net 36 | } // namespace Mif 37 | 38 | #endif // !__MIF_NET_HTTP_CODES_H__ 39 | -------------------------------------------------------------------------------- /examples/hello_world/common/include/common/ps/ihello_world.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __HELLO_WORLD_COMMON_PS_IHELLO_WORLD_H__ 9 | #define __HELLO_WORLD_COMMON_PS_IHELLO_WORLD_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include 16 | 17 | // THIS 18 | #include "common/interface/ihello_world.h" 19 | 20 | namespace Service 21 | { 22 | namespace Meta 23 | { 24 | 25 | using namespace ::Service; 26 | 27 | MIF_REMOTE_PS_BEGIN(IHelloWorld) 28 | MIF_REMOTE_METHOD(AddWord) 29 | MIF_REMOTE_METHOD(GetText) 30 | MIF_REMOTE_METHOD(Clean) 31 | MIF_REMOTE_PS_END() 32 | 33 | } // namespace Meta 34 | } // namespace Service 35 | 36 | MIF_REMOTE_REGISTER_PS(Service::Meta::IHelloWorld) 37 | 38 | #endif // !__HELLO_WORLD_COMMON_PS_IHELLO_WORLD_H__ 39 | -------------------------------------------------------------------------------- /examples/common/cmake/settings.cmake: -------------------------------------------------------------------------------- 1 | set (PROJECT_SERVER_NAME "${PROJECT_LC}_server") 2 | set (PROJECT_CLIENT_NAME "${PROJECT_LC}_client") 3 | 4 | set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/MyCMakeScripts) 5 | set (EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) 6 | set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) 7 | 8 | set (MIF_LIB_INSTALL_PATH, ${PROJECT_SOURCE_DIR}/MyCMakeScripts/lib/mif) 9 | 10 | set (MIF_STD_CXX "c++11") 11 | 12 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -std=${MIF_STD_CXX}") 13 | set (CMAKE_CXX_FLAGS_RELEASE "-O3 -g0 -DNDEBUG") 14 | #set (CMAKE_EXE_LINKER_FLAGS "-static-libstdc++") 15 | set (CMAKE_POSITION_INDEPENDENT_CODE ON) 16 | 17 | set(LIBRARIES 18 | ${LIBRARIES} 19 | mif 20 | boost_iostreams 21 | boost_json 22 | boost_date_time 23 | boost_serialization 24 | boost_program_options 25 | boost_log 26 | boost_filesystem 27 | boost_thread 28 | boost_system 29 | pthread 30 | z 31 | rt 32 | ) 33 | 34 | if (MIF_WITH_POSTGRESQL) 35 | set(LIBRARIES 36 | ${LIBRARIES} 37 | pq 38 | ) 39 | endif() 40 | -------------------------------------------------------------------------------- /examples/complex_type/common/include/common/ps/imy_company.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 10.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __COMPLEX_TYPE_COMMON_PS_IMYCOMPANY_H__ 9 | #define __COMPLEX_TYPE_COMMON_PS_IMYCOMPANY_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | // THIS 15 | #include "common/interface/imy_company.h" 16 | #include "common/meta/data.h" 17 | 18 | namespace Service 19 | { 20 | namespace Meta 21 | { 22 | 23 | using namespace ::Service; 24 | 25 | MIF_REMOTE_PS_BEGIN(IMyCompany) 26 | MIF_REMOTE_METHOD(AddEmployee) 27 | MIF_REMOTE_METHOD(RemoveAccount) 28 | MIF_REMOTE_METHOD(GetEmployees) 29 | MIF_REMOTE_PS_END() 30 | 31 | } // namespace Meta 32 | } // namespace Service 33 | 34 | MIF_REMOTE_REGISTER_PS(Service::Meta::IMyCompany) 35 | 36 | #endif // !__COMPLEX_TYPE_COMMON_PS_IMYCOMPANY_H__ 37 | -------------------------------------------------------------------------------- /include/mif/net/http/iweb_service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_IWEB_SERVICE_H__ 9 | #define __MIF_NET_HTTP_IWEB_SERVICE_H__ 10 | 11 | // MIF 12 | #include "mif/net/http/iinput_pack.h" 13 | #include "mif/net/http/ioutput_pack.h" 14 | #include "mif/service/iservice.h" 15 | 16 | namespace Mif 17 | { 18 | namespace Net 19 | { 20 | namespace Http 21 | { 22 | 23 | struct IWebService 24 | : public Service::Inherit 25 | { 26 | virtual void OnRequest(IInputPack const &request, IOutputPack &response) = 0; 27 | }; 28 | 29 | using IWebServicePtr = Service::TIntrusivePtr; 30 | 31 | } // namespace Http 32 | } // namespace Net 33 | } // namespace Mif 34 | 35 | #endif // !__MIF_NET_HTTP_IWEB_SERVICE_H__ 36 | -------------------------------------------------------------------------------- /include/mif/net/http/request_handler.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 11.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_REQUEST_HANDLER_H__ 9 | #define __MIF_NET_HTTP_REQUEST_HANDLER_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | // MIF 17 | #include "mif/net/http/iinput_pack.h" 18 | #include "mif/net/http/ioutput_pack.h" 19 | 20 | namespace Mif 21 | { 22 | namespace Net 23 | { 24 | namespace Http 25 | { 26 | 27 | using ServerHandler = std::function; 28 | using ServerHandlers = std::map; 29 | 30 | using ClientHandler = std::function; 31 | 32 | } // namespace Http 33 | } // namespace Net 34 | } // namespace Mif 35 | 36 | #endif // !__MIF_NET_HTTP_REQUEST_HANDLER_H__ 37 | -------------------------------------------------------------------------------- /include/mif/net/tcp/server.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_TCP_SERVER_H__ 9 | #define __MIF_NET_TCP_SERVER_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | // MIF 17 | #include "mif/net/iclient_factory.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Net 22 | { 23 | namespace Tcp 24 | { 25 | 26 | class Server final 27 | { 28 | public: 29 | Server(std::string const &host, std::string const &port, IClientFactoryPtr factory); 30 | 31 | ~Server(); 32 | 33 | private: 34 | class Impl; 35 | std::unique_ptr m_impl; 36 | }; 37 | 38 | } // namespace Tcp 39 | } // namespace Net 40 | } // namespace Mif 41 | 42 | #endif // !__MIF_NET_TCP_SERVER_H__ 43 | -------------------------------------------------------------------------------- /examples/visitor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.27) 2 | 3 | project(Visitor) 4 | set(PROJECT ${PROJECT_NAME}) 5 | string(TOLOWER "${PROJECT}" PROJECT_LC) 6 | 7 | include (../common/cmake/mif.cmake) 8 | 9 | include_directories(${CMAKE_SOURCE_DIR}/common/include) 10 | 11 | set(COMMON_HEADERS 12 | ${COMMON_HEADERS} 13 | ${CMAKE_SOURCE_DIR}/common/include 14 | ) 15 | 16 | set(SERVER_HEADERS 17 | ${SERVER_HEADERS} 18 | ${COMMON_HEADERS} 19 | ) 20 | 21 | set(SERVER_SOURCES 22 | ${SERVER_SOURCES} 23 | ${CMAKE_CURRENT_SOURCE_DIR}/server/src/service.cpp 24 | ) 25 | 26 | set(CLIENT_HEADERS 27 | ${SERVER_HEADERS} 28 | ${COMMON_HEADERS} 29 | ) 30 | 31 | set(CLIENT_SOURCES 32 | ${CLIENT_SOURCES} 33 | ) 34 | 35 | add_executable(${PROJECT_SERVER_NAME} ${SERVER_HEADERS} ${SERVER_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/server/src/main.cpp) 36 | target_link_libraries(${PROJECT_SERVER_NAME} ${LIBRARIES}) 37 | 38 | add_executable(${PROJECT_CLIENT_NAME} ${CLIENT_HEADERS} ${CLIENT_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/client/src/main.cpp) 39 | target_link_libraries(${PROJECT_CLIENT_NAME} ${LIBRARIES}) 40 | -------------------------------------------------------------------------------- /include/mif/db/id/service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_DB_ID_SERVICE_H__ 9 | #define __MIF_DB_ID_SERVICE_H__ 10 | 11 | // MIF 12 | #include "mif/common/config.h" 13 | #include "mif/common/crc32.h" 14 | 15 | namespace Mif 16 | { 17 | namespace Db 18 | { 19 | namespace Id 20 | { 21 | namespace Service 22 | { 23 | 24 | enum 25 | { 26 | #ifdef MIF_WITH_POSTGRESQL 27 | PostgreSQL = Common::Crc32("Mif.Db.Service.Connection.PostgreSQL"), 28 | PostgresConnectionPool = Common::Crc32("Mif.Db.Service.PostgresConnectionPool") 29 | #endif // !MIF_WITH_POSTGRESQL 30 | }; 31 | 32 | } // namespace Service 33 | } // namespace Id 34 | } // namespace Db 35 | } // namespace Mif 36 | 37 | #endif // !__MIF_DB_ID_SERVICE_H__ 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016-2024 tdv 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/inheritance/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.27) 2 | 3 | project(Inheritance) 4 | set(PROJECT ${PROJECT_NAME}) 5 | string(TOLOWER "${PROJECT}" PROJECT_LC) 6 | 7 | include (../common/cmake/mif.cmake) 8 | 9 | include_directories(${CMAKE_SOURCE_DIR}/common/include) 10 | 11 | set(COMMON_HEADERS 12 | ${COMMON_HEADERS} 13 | ${CMAKE_SOURCE_DIR}/common/include 14 | ) 15 | 16 | set(SERVER_HEADERS 17 | ${SERVER_HEADERS} 18 | ${COMMON_HEADERS} 19 | ) 20 | 21 | set(SERVER_SOURCES 22 | ${SERVER_SOURCES} 23 | ${CMAKE_CURRENT_SOURCE_DIR}/server/src/service.cpp 24 | ) 25 | 26 | set(CLIENT_HEADERS 27 | ${SERVER_HEADERS} 28 | ${COMMON_HEADERS} 29 | ) 30 | 31 | set(CLIENT_SOURCES 32 | ${CLIENT_SOURCES} 33 | ) 34 | 35 | add_executable(${PROJECT_SERVER_NAME} ${SERVER_HEADERS} ${SERVER_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/server/src/main.cpp) 36 | target_link_libraries(${PROJECT_SERVER_NAME} ${LIBRARIES}) 37 | 38 | add_executable(${PROJECT_CLIENT_NAME} ${CLIENT_HEADERS} ${CLIENT_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/client/src/main.cpp) 39 | target_link_libraries(${PROJECT_CLIENT_NAME} ${LIBRARIES}) 40 | -------------------------------------------------------------------------------- /include/mif/net/iclient_factory.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_ICLIENT_FACTORY_H__ 9 | #define __MIF_NET_ICLIENT_FACTORY_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/net/client.h" 16 | 17 | namespace Mif 18 | { 19 | namespace Net 20 | { 21 | 22 | struct IClientFactory 23 | { 24 | using ClientPtr = std::shared_ptr; 25 | using IControlPtr = std::weak_ptr; 26 | using IPublisherPtr = std::weak_ptr; 27 | 28 | virtual ~IClientFactory() = default; 29 | virtual ClientPtr Create(IControlPtr control, IPublisherPtr publisher) = 0; 30 | }; 31 | 32 | using IClientFactoryPtr = std::shared_ptr; 33 | 34 | } // namespace Net 35 | } // namespace Mif 36 | 37 | #endif // !__MIF_NET_ICLIENT_FACTORY_H__ 38 | -------------------------------------------------------------------------------- /examples/complex_type/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.27) 2 | 3 | project(ComplexType) 4 | set(PROJECT ${PROJECT_NAME}) 5 | string(TOLOWER "${PROJECT}" PROJECT_LC) 6 | 7 | include (../common/cmake/mif.cmake) 8 | 9 | include_directories(${CMAKE_SOURCE_DIR}/common/include) 10 | 11 | set(COMMON_HEADERS 12 | ${COMMON_HEADERS} 13 | ${CMAKE_SOURCE_DIR}/common/include 14 | ) 15 | 16 | set(SERVER_HEADERS 17 | ${SERVER_HEADERS} 18 | ${COMMON_HEADERS} 19 | ) 20 | 21 | set(SERVER_SOURCES 22 | ${SERVER_SOURCES} 23 | ${CMAKE_CURRENT_SOURCE_DIR}/server/src/my_company.cpp 24 | ) 25 | 26 | set(CLIENT_HEADERS 27 | ${SERVER_HEADERS} 28 | ${COMMON_HEADERS} 29 | ) 30 | 31 | set(CLIENT_SOURCES 32 | ${CLIENT_SOURCES} 33 | ) 34 | 35 | add_executable(${PROJECT_SERVER_NAME} ${SERVER_HEADERS} ${SERVER_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/server/src/main.cpp) 36 | target_link_libraries(${PROJECT_SERVER_NAME} ${LIBRARIES}) 37 | 38 | add_executable(${PROJECT_CLIENT_NAME} ${CLIENT_HEADERS} ${CLIENT_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/client/src/main.cpp) 39 | target_link_libraries(${PROJECT_CLIENT_NAME} ${LIBRARIES}) 40 | -------------------------------------------------------------------------------- /include/mif/net/clients/frame_writer.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_CLIENTS_FRAME_WRITER_H__ 9 | #define __MIF_NET_CLIENTS_FRAME_WRITER_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/net/client.h" 16 | 17 | namespace Mif 18 | { 19 | namespace Net 20 | { 21 | namespace Clients 22 | { 23 | 24 | class FrameWriter final 25 | : public Net::Client 26 | { 27 | public: 28 | FrameWriter(std::weak_ptr control, std::weak_ptr publisher); 29 | 30 | private: 31 | // Client 32 | virtual void ProcessData(Common::Buffer buffer) override final; 33 | }; 34 | 35 | } // namespace Clients 36 | } // namespace Net 37 | } // namespace Mif 38 | 39 | #endif // !__MIF_NET_CLIENTS_FRAME_WRITER_H__ 40 | -------------------------------------------------------------------------------- /examples/http/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.27) 2 | 3 | project(Http) 4 | set(PROJECT ${PROJECT_NAME}) 5 | string(TOLOWER "${PROJECT}" PROJECT_LC) 6 | 7 | include (../common/cmake/mif.cmake) 8 | 9 | include_directories(${CMAKE_SOURCE_DIR}/common/include) 10 | 11 | set(COMMON_HEADERS 12 | ${COMMON_HEADERS} 13 | ${CMAKE_SOURCE_DIR}/common/include 14 | ) 15 | 16 | set(SERVER_HEADERS 17 | ${SERVER_HEADERS} 18 | ${COMMON_HEADERS} 19 | ) 20 | 21 | set(SERVER_SOURCES 22 | ${SERVER_SOURCES} 23 | ${CMAKE_CURRENT_SOURCE_DIR}/server/src/service.cpp 24 | ) 25 | 26 | set(CLIENT_HEADERS 27 | ${SERVER_HEADERS} 28 | ${COMMON_HEADERS} 29 | ) 30 | 31 | set(CLIENT_SOURCES 32 | ${CLIENT_SOURCES} 33 | ) 34 | 35 | include_directories(common/include) 36 | 37 | add_executable(${PROJECT_SERVER_NAME} ${SERVER_HEADERS} ${SERVER_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/server/src/main.cpp) 38 | target_link_libraries(${PROJECT_SERVER_NAME} ${LIBRARIES}) 39 | 40 | add_executable(${PROJECT_CLIENT_NAME} ${CLIENT_HEADERS} ${CLIENT_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/client/src/main.cpp) 41 | target_link_libraries(${PROJECT_CLIENT_NAME} ${LIBRARIES}) 42 | -------------------------------------------------------------------------------- /examples/common/cmake/mif.cmake: -------------------------------------------------------------------------------- 1 | include (../../cmake/options.cmake) 2 | include (../common/cmake/settings.cmake) 3 | 4 | set (THITD_PARTY_PATH "${CMAKE_SOURCE_DIR}/../../third_party") 5 | set (MIF_LIB_PATH "${CMAKE_SOURCE_DIR}/../..") 6 | 7 | include_directories (SYSTEM ${THITD_PARTY_PATH}/zlib/include) 8 | link_directories (${THITD_PARTY_PATH}/zlib/lib) 9 | 10 | include_directories (SYSTEM ${THITD_PARTY_PATH}/boost/include) 11 | link_directories (${THITD_PARTY_PATH}/boost/lib) 12 | 13 | include_directories (SYSTEM ${THITD_PARTY_PATH}/event/include) 14 | link_directories (${THITD_PARTY_PATH}/event/lib) 15 | 16 | if (MIF_WITH_POSTGRESQL) 17 | include_directories (SYSTEM ${THITD_PARTY_PATH}/libpq/include) 18 | link_directories (${THITD_PARTY_PATH}/libpq/lib) 19 | endif() 20 | 21 | if (MIF_WITH_SQLITE) 22 | include_directories (SYSTEM ${THITD_PARTY_PATH}/sqlite/include) 23 | link_directories (${THITD_PARTY_PATH}/sqlite/lib) 24 | endif() 25 | 26 | include_directories (SYSTEM ${THITD_PARTY_PATH}/mif/include) 27 | link_directories (${THITD_PARTY_PATH}/mif/lib) 28 | 29 | include_directories (SYSTEM ${MIF_LIB_PATH}/include) 30 | link_directories (${MIF_LIB_PATH}/lib) 31 | -------------------------------------------------------------------------------- /include/mif/application/id/config.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_APPLICATION_ID_CONFIG_H__ 9 | #define __MIF_APPLICATION_ID_CONFIG_H__ 10 | 11 | // MIF 12 | #include "mif/common/crc32.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Application 17 | { 18 | namespace Id 19 | { 20 | namespace Service 21 | { 22 | namespace Config 23 | { 24 | 25 | enum 26 | { 27 | Json = Common::Crc32("Mif.Application.Service.Config.Json"), 28 | Xml = Common::Crc32("Mif.Application.Service.Config.Xml") 29 | }; 30 | 31 | } // namespace Config 32 | } // namespace Service 33 | } // namespace Id 34 | } // namespace Application 35 | } // namespace Mif 36 | 37 | #endif // !__MIF_APPLICATION_ID_CONFIG_H__ 38 | -------------------------------------------------------------------------------- /include/mif/net/clients/gzip_compressor.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_CLIENTS_GZIP_COMPRESSOR_H__ 9 | #define __MIF_NET_CLIENTS_GZIP_COMPRESSOR_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/net/client.h" 16 | 17 | namespace Mif 18 | { 19 | namespace Net 20 | { 21 | namespace Clients 22 | { 23 | 24 | class GZipCompressor final 25 | : public Net::Client 26 | { 27 | public: 28 | GZipCompressor(std::weak_ptr control, std::weak_ptr publisher); 29 | 30 | protected: 31 | // Client 32 | virtual void ProcessData(Common::Buffer buffer) override final; 33 | }; 34 | 35 | } // namespace Clients 36 | } // namespace Net 37 | } // namespace Mif 38 | 39 | #endif // !__MIF_NET_CLIENTS_GZIP_COMPRESSOR_H__ 40 | -------------------------------------------------------------------------------- /examples/hello_world/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.27) 2 | 3 | project(HelloWorld) 4 | set(PROJECT ${PROJECT_NAME}) 5 | string(TOLOWER "${PROJECT}" PROJECT_LC) 6 | 7 | include (../common/cmake/mif.cmake) 8 | 9 | include_directories(${CMAKE_SOURCE_DIR}/common/include) 10 | 11 | set(COMMON_HEADERS 12 | ${COMMON_HEADERS} 13 | ${CMAKE_SOURCE_DIR}/common/include 14 | ) 15 | 16 | set(SERVER_HEADERS 17 | ${SERVER_HEADERS} 18 | ${COMMON_HEADERS} 19 | ) 20 | 21 | set(SERVER_SOURCES 22 | ${SERVER_SOURCES} 23 | ${CMAKE_CURRENT_SOURCE_DIR}/server/src/hello_world.cpp 24 | ) 25 | 26 | set(CLIENT_HEADERS 27 | ${SERVER_HEADERS} 28 | ${COMMON_HEADERS} 29 | ) 30 | 31 | set(CLIENT_SOURCES 32 | ${CLIENT_SOURCES} 33 | ) 34 | 35 | include_directories(common/include) 36 | 37 | add_executable(${PROJECT_SERVER_NAME} ${SERVER_HEADERS} ${SERVER_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/server/src/main.cpp) 38 | target_link_libraries(${PROJECT_SERVER_NAME} ${LIBRARIES}) 39 | 40 | add_executable(${PROJECT_CLIENT_NAME} ${CLIENT_HEADERS} ${CLIENT_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/client/src/main.cpp) 41 | target_link_libraries(${PROJECT_CLIENT_NAME} ${LIBRARIES}) 42 | -------------------------------------------------------------------------------- /include/mif/net/clients/gzip_decompressor.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_CLIENTS_GZIP_DECOMPRESSOR_H__ 9 | #define __MIF_NET_CLIENTS_GZIP_DECOMPRESSOR_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/net/client.h" 16 | 17 | namespace Mif 18 | { 19 | namespace Net 20 | { 21 | namespace Clients 22 | { 23 | 24 | class GZipDecompressor final 25 | : public Net::Client 26 | { 27 | public: 28 | GZipDecompressor(std::weak_ptr control, std::weak_ptr publisher); 29 | 30 | protected: 31 | // Client 32 | virtual void ProcessData(Common::Buffer buffer) override final; 33 | }; 34 | 35 | } // namespace Clients 36 | } // namespace Net 37 | } // namespace Mif 38 | 39 | #endif // !__MIF_NET_CLIENTS_GZIP_DECOMPRESSOR_H__ 40 | -------------------------------------------------------------------------------- /include/mif/net/tcp/clients.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_TCP_CLIENTS_H__ 9 | #define __MIF_NET_TCP_CLIENTS_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | // MIF 17 | #include "mif/net/iclient_factory.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Net 22 | { 23 | namespace Tcp 24 | { 25 | 26 | class Clients final 27 | { 28 | public: 29 | Clients(IClientFactoryPtr factory); 30 | ~Clients(); 31 | 32 | IClientFactory::ClientPtr RunClient(std::string const &host, std::string const &port); 33 | 34 | private: 35 | class Impl; 36 | std::unique_ptr m_impl; 37 | }; 38 | 39 | } // namespace Tcp 40 | } // namespace Net 41 | } // namespace Mif 42 | 43 | #endif // !__MIF_NET_TCP_CLIENTS_H__ 44 | -------------------------------------------------------------------------------- /include/mif/net/http/methods.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_METHODS_H__ 9 | #define __MIF_NET_HTTP_METHODS_H__ 10 | 11 | // STD 12 | #include 13 | 14 | namespace Mif 15 | { 16 | namespace Net 17 | { 18 | namespace Http 19 | { 20 | namespace Method 21 | { 22 | 23 | enum class Type 24 | { 25 | Get, 26 | Post, 27 | Head, 28 | Put, 29 | Delete, 30 | Options, 31 | Trqce, 32 | Connect, 33 | Patch 34 | }; 35 | 36 | } // namespace Method 37 | 38 | using Methods = std::set; 39 | 40 | } // namespace Http 41 | } // namespace Net 42 | } // namespace Mif 43 | 44 | #endif // !__MIF_NET_HTTP_METHODS_H__ 45 | -------------------------------------------------------------------------------- /include/mif/common/thread_pool.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_THREAD_POOL_H__ 9 | #define __MIF_COMMON_THREAD_POOL_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | namespace Mif 17 | { 18 | namespace Common 19 | { 20 | 21 | struct IThreadPool 22 | : public std::enable_shared_from_this 23 | { 24 | using Task = std::function; 25 | 26 | virtual ~IThreadPool() = default; 27 | 28 | virtual void Post(Task task) = 0; 29 | virtual std::shared_ptr CreateOrderedPoster() = 0; 30 | }; 31 | 32 | using IThreadPoolPtr = std::shared_ptr; 33 | 34 | std::shared_ptr CreateThreadPool(std::uint16_t threadCount); 35 | 36 | } // namespace Common 37 | } // namespace Mif 38 | 39 | #endif // !__MIF_COMMON_THREAD_POOL_H__ 40 | -------------------------------------------------------------------------------- /src/mif/common/version.h.in: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_VERSION_H__ 9 | #define __MIF_COMMON_VERSION_H__ 10 | 11 | namespace Mif 12 | { 13 | namespace Common 14 | { 15 | 16 | struct Version final 17 | { 18 | static int Major() noexcept 19 | { 20 | return ${MIF_VERSION_MAJOR}; 21 | } 22 | 23 | static int Minor() noexcept 24 | { 25 | return ${MIF_VERSION_MINOR}; 26 | } 27 | 28 | static int Patch() noexcept 29 | { 30 | return ${MIF_VERSION_PATCH}; 31 | } 32 | 33 | static char const* GetAsString() noexcept 34 | { 35 | return "${MIF_VERSION_MAJOR}.${MIF_VERSION_MINOR}.${MIF_VERSION_PATCH}"; 36 | } 37 | }; 38 | 39 | } // namespace Common 40 | } // namespace Mif 41 | 42 | #endif // !__MIF_COMMON_VERSION_H__ 43 | -------------------------------------------------------------------------------- /include/mif/remote/predefined/serialization/xml.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_PREDEFINED_SERIALIZATION_XML_H__ 9 | #define __MIF_REMOTE_PREDEFINED_SERIALIZATION_XML_H__ 10 | 11 | // MIF 12 | #include "mif/remote/serialization/xml.h" 13 | #include "mif/remote/serialization/serialization.h" 14 | 15 | namespace Mif 16 | { 17 | namespace Remote 18 | { 19 | namespace Predefined 20 | { 21 | namespace Serialization 22 | { 23 | 24 | using Xml = Remote::Serialization::SerializerTraits 25 | < 26 | Remote::Serialization::Xml::Serializer, 27 | Remote::Serialization::Xml::Deserializer 28 | >; 29 | 30 | } // namespace Serialization 31 | } // namespace Predefined 32 | } // namespace Remote 33 | } // namespace Mif 34 | 35 | #endif // !__MIF_REMOTE_PREDEFINED_SERIALIZATION_XML_H__ 36 | -------------------------------------------------------------------------------- /include/mif/remote/predefined/serialization/json.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_PREDEFINED_SERIALIZATION_JSON_H__ 9 | #define __MIF_REMOTE_PREDEFINED_SERIALIZATION_JSON_H__ 10 | 11 | // MIF 12 | #include "mif/remote/serialization/json.h" 13 | #include "mif/remote/serialization/serialization.h" 14 | 15 | namespace Mif 16 | { 17 | namespace Remote 18 | { 19 | namespace Predefined 20 | { 21 | namespace Serialization 22 | { 23 | 24 | using Json = Remote::Serialization::SerializerTraits 25 | < 26 | Remote::Serialization::Json::Serializer, 27 | Remote::Serialization::Json::Deserializer 28 | >; 29 | 30 | } // namespace Serialization 31 | } // namespace Predefined 32 | } // namespace Remote 33 | } // namespace Mif 34 | 35 | #endif // !__MIF_REMOTE_PREDEFINED_SERIALIZATION_JSON_H__ 36 | -------------------------------------------------------------------------------- /include/mif/net/http/clients.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_CLIENTS_H__ 9 | #define __MIF_NET_HTTP_CLIENTS_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/net/iclient_factory.h" 17 | 18 | namespace Mif 19 | { 20 | namespace Net 21 | { 22 | namespace Http 23 | { 24 | 25 | class Clients final 26 | { 27 | public: 28 | Clients(std::shared_ptr factory); 29 | ~Clients(); 30 | 31 | IClientFactory::ClientPtr RunClient(std::string const &host, std::string const &port, 32 | std::string const &resource = ""); 33 | 34 | private: 35 | class Impl; 36 | std::unique_ptr m_impl; 37 | }; 38 | 39 | } // namespace Http 40 | } // namespace Net 41 | } // namespace Mif 42 | 43 | #endif // !__MIF_NET_HTTP_CLIENTS_H__ 44 | -------------------------------------------------------------------------------- /examples/microservices/common/include/common/data/data.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 10.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MICROSERVICES_COMMON_DATA_DATA_H__ 9 | #define __MICROSERVICES_COMMON_DATA_DATA_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | namespace Common 17 | { 18 | namespace Data 19 | { 20 | 21 | using ID = std::string; 22 | 23 | enum class Position 24 | { 25 | Unknown, 26 | Developer, 27 | Manager 28 | }; 29 | 30 | struct Employee 31 | { 32 | std::string name; 33 | std::string lastName; 34 | std::uint32_t age = 0; 35 | std::string email; 36 | Position position = Position::Unknown; 37 | double rate = 0.0; 38 | }; 39 | 40 | using Employees = std::map; 41 | 42 | } // namespace Data 43 | } // namespace Common 44 | 45 | #endif // !__MICROSERVICES_COMMON_DATA_DATA_H__ 46 | -------------------------------------------------------------------------------- /src/mif/service/external.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 06.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include "mif/service/external.h" 10 | 11 | namespace Mif 12 | { 13 | namespace Service 14 | { 15 | 16 | void External::Add(IServicePtr service) 17 | { 18 | LockGuard lock{m_lock}; 19 | m_services.emplace_back(service); 20 | } 21 | 22 | bool External::_Mif_Remote_QueryRemoteInterface(void **service, 23 | std::type_info const &typeInfo, std::string const &serviceId, 24 | IService **holder) 25 | { 26 | LockGuard lock{m_lock}; 27 | 28 | if (m_services.empty()) 29 | return false; 30 | 31 | for (auto &i : m_services) 32 | { 33 | bool res = i->Query(typeInfo, service, serviceId, holder); 34 | if (res) 35 | return true; 36 | } 37 | 38 | return false; 39 | } 40 | 41 | } // namespace Service 42 | } // namespace Mif 43 | -------------------------------------------------------------------------------- /examples/microservices/common/include/common/interface/ps/iemployee_storage.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 08.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MICROSERVICES_COMMON_INTERFACE_PS_IEMPPLOYEE_STORAGE_H__ 9 | #define __MICROSERVICES_COMMON_INTERFACE_PS_IEMPPLOYEE_STORAGE_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | // THIS 15 | #include "common/interface/iemployee_storage.h" 16 | #include "common/data/meta/data.h" 17 | 18 | namespace Common 19 | { 20 | namespace Meta 21 | { 22 | 23 | using namespace ::Common; 24 | 25 | MIF_REMOTE_PS_BEGIN(IEmployeeStorage) 26 | MIF_REMOTE_METHOD(Create) 27 | MIF_REMOTE_METHOD(Read) 28 | MIF_REMOTE_METHOD(Update) 29 | MIF_REMOTE_METHOD(Delete) 30 | MIF_REMOTE_METHOD(List) 31 | MIF_REMOTE_PS_END() 32 | 33 | } // namespace Meta 34 | } // namespace Common 35 | 36 | MIF_REMOTE_REGISTER_PS(Common::Meta::IEmployeeStorage) 37 | 38 | #endif // !__MICROSERVICES_COMMON_INTERFACE_PS_IEMPPLOYEE_STORAGE_H__ 39 | -------------------------------------------------------------------------------- /include/mif/service/make.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_SERVICE_MAKE_H__ 9 | #define __MIF_SERVICE_MAKE_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/service/iservice.h" 16 | #include "mif/service/detail/service.h" 17 | 18 | namespace Mif 19 | { 20 | namespace Service 21 | { 22 | 23 | template 24 | inline TServicePtr Make(TArgs && ... args) 25 | { 26 | TServicePtr service{new Detail::Service_Impl__(std::forward(args) ... )}; 27 | return Cast(service); 28 | } 29 | 30 | template 31 | inline IServicePtr Make(TArgs && ... args) 32 | { 33 | return Make(std::forward(args) ... ); 34 | } 35 | 36 | } // namespace Service 37 | } // namespace Mif 38 | 39 | #endif // !__MIF_SERVICE_MAKE_H__ 40 | -------------------------------------------------------------------------------- /examples/complex_type/common/include/common/data/data.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 10.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __COMPLEX_TYPE_COMMON_DATA_DATA_H__ 9 | #define __COMPLEX_TYPE_COMMON_DATA_DATA_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | namespace Service 17 | { 18 | namespace Data 19 | { 20 | 21 | using ID = std::string; 22 | 23 | struct Human 24 | { 25 | std::string name; 26 | std::string lastName; 27 | std::uint32_t age = 0; 28 | }; 29 | 30 | enum class Position 31 | { 32 | Unknown, 33 | Developer, 34 | Manager 35 | }; 36 | 37 | struct Employee 38 | : public Human 39 | { 40 | Position position = Position::Unknown; 41 | }; 42 | 43 | using Employees = std::map; 44 | 45 | } // namespace Data 46 | } // namespace Service 47 | 48 | #endif // !__COMPLEX_TYPE_COMMON_DATA_DATA_H__ 49 | -------------------------------------------------------------------------------- /examples/http_echo_server/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 08.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | #include 11 | #include 12 | 13 | class Application 14 | : public Mif::Application::HttpServer 15 | { 16 | public: 17 | using HttpServer::HttpServer; 18 | 19 | private: 20 | // Mif.Application.HttpServer 21 | virtual void Init(Mif::Net::Http::ServerHandlers &handlers) override final 22 | { 23 | handlers["/"] = [] (Mif::Net::Http::IInputPack const &request, 24 | Mif::Net::Http::IOutputPack &response) 25 | { 26 | auto const data = request.GetData(); 27 | 28 | MIF_LOG(Info) << "Received bytes: " << data.size(); 29 | 30 | response.SetCode(Mif::Net::Http::Code::Ok); 31 | 32 | response.SetData(std::move(data)); 33 | }; 34 | } 35 | }; 36 | 37 | int main(int argc, char const **argv) 38 | { 39 | return Mif::Application::Run(argc, argv); 40 | } 41 | -------------------------------------------------------------------------------- /include/mif/net/clients/frame_reader.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_CLIENTS_FRAME_READER_H__ 9 | #define __MIF_NET_CLIENTS_FRAME_READER_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/net/client.h" 16 | 17 | namespace Mif 18 | { 19 | namespace Net 20 | { 21 | namespace Clients 22 | { 23 | 24 | class FrameReader final 25 | : public Net::Client 26 | { 27 | public: 28 | FrameReader(std::weak_ptr control, std::weak_ptr publisher); 29 | ~FrameReader(); 30 | 31 | private: 32 | class Impl; 33 | std::unique_ptr m_impl; 34 | 35 | // Client 36 | virtual void ProcessData(Common::Buffer buffer) override final; 37 | }; 38 | 39 | } // namespace Clients 40 | } // namespace Net 41 | } // namespace Mif 42 | 43 | #endif // !__MIF_NET_CLIENTS_FRAME_READER_H__ 44 | -------------------------------------------------------------------------------- /examples/visitor/common/include/common/ps/iface.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 02.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __VISITOR_COMMON_PS_IFACE_H__ 9 | #define __VISITOR_COMMON_PS_IFACE_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | // THIS 15 | #include "common/interface/iface.h" 16 | 17 | namespace Service 18 | { 19 | namespace Meta 20 | { 21 | 22 | using namespace ::Service; 23 | 24 | MIF_REMOTE_PS_BEGIN(IMessage) 25 | MIF_REMOTE_METHOD(GetText) 26 | MIF_REMOTE_PS_END() 27 | 28 | MIF_REMOTE_PS_BEGIN(IMessageVisitor) 29 | MIF_REMOTE_METHOD(Visit) 30 | MIF_REMOTE_PS_END() 31 | 32 | MIF_REMOTE_PS_BEGIN(IViewer) 33 | MIF_REMOTE_METHOD(Accept) 34 | MIF_REMOTE_PS_END() 35 | 36 | } // namespace Meta 37 | } // namespace Service 38 | 39 | MIF_REMOTE_REGISTER_PS(Service::Meta::IMessage) 40 | MIF_REMOTE_REGISTER_PS(Service::Meta::IMessageVisitor) 41 | MIF_REMOTE_REGISTER_PS(Service::Meta::IViewer) 42 | 43 | #endif // !__VISITOR_COMMON_PS_IFACE_H__ 44 | -------------------------------------------------------------------------------- /include/mif/common/detail/hierarchy.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_DETAIL_HIERARCHY_H__ 9 | #define __MIF_COMMON_DETAIL_HIERARCHY_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | namespace Mif 16 | { 17 | namespace Common 18 | { 19 | namespace Detail 20 | { 21 | 22 | template 23 | struct Hierarchy 24 | : public Hierarchy 25 | { 26 | }; 27 | 28 | template <> 29 | struct Hierarchy<0> 30 | { 31 | }; 32 | 33 | template 34 | using MakeHierarchy = Hierarchy; 35 | 36 | using FakeHierarchyLength = std::integral_constant; 37 | using FakeHierarchy = MakeHierarchy; 38 | 39 | } // namespace Detail 40 | 41 | } // namespace Common 42 | } // namespace Mif 43 | 44 | #endif // !__MIF_COMMON_DETAIL_HIERARCHY_H__ 45 | -------------------------------------------------------------------------------- /include/mif/common/detail/type_logic_funcs.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 10.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_DETAIL_TYPE_LOGIC_FUNCS_H__ 9 | #define __MIF_COMMON_DETAIL_TYPE_LOGIC_FUNCS_H__ 10 | 11 | // STD 12 | #include 13 | 14 | namespace Mif 15 | { 16 | namespace Common 17 | { 18 | namespace Detail 19 | { 20 | 21 | template 22 | struct Disjunction 23 | : public std::false_type 24 | { 25 | }; 26 | 27 | template 28 | struct Disjunction 29 | : public B1 30 | { 31 | }; 32 | 33 | template 34 | struct Disjunction 35 | : public std::conditional>::type 36 | { 37 | }; 38 | 39 | } // namespace Detail 40 | } // namespace Common 41 | } // namespace Mif 42 | 43 | #endif // !__MIF_COMMON_DETAIL_TYPE_LOGIC_FUNCS_H__ 44 | -------------------------------------------------------------------------------- /include/mif/service/ifactory.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_SERVICE_IFACTORY_H__ 9 | #define __MIF_SERVICE_IFACTORY_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/common/crc32.h" 16 | #include "mif/service/iservice.h" 17 | 18 | namespace Mif 19 | { 20 | namespace Service 21 | { 22 | 23 | struct IFactory 24 | : public Inherit 25 | { 26 | virtual IServicePtr Create(ServiceId id) = 0; 27 | 28 | template 29 | TServicePtr Create(ServiceId id) 30 | { 31 | return Service::Cast(Create(id)); 32 | } 33 | 34 | template 35 | TServicePtr Create(std::string const &id) 36 | { 37 | return Create(Common::Crc32str(id)); 38 | } 39 | 40 | }; 41 | 42 | using IFactoryPtr = TServicePtr; 43 | 44 | } // namespace Service 45 | } // namespace Mif 46 | 47 | #endif // !__MIF_SERVICE_IFACTORY_H__ 48 | -------------------------------------------------------------------------------- /include/mif/net/tcp/connection.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_TCP_CONNECTION_H__ 9 | #define __MIF_NET_TCP_CONNECTION_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/net/iclient_factory.h" 17 | #include "mif/net/iconnection.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Net 22 | { 23 | namespace Tcp 24 | { 25 | 26 | class Connection final 27 | : public IConnection 28 | { 29 | public: 30 | Connection(std::string const &host, std::string const &port, 31 | IClientFactoryPtr factory); 32 | 33 | ~Connection(); 34 | 35 | // IConnection 36 | virtual ClientPtr GetClient() override final; 37 | 38 | private: 39 | class Impl; 40 | std::unique_ptr m_impl; 41 | }; 42 | 43 | } // namespace Tcp 44 | } // namespace Net 45 | } // namespace Mif 46 | 47 | #endif // !__MIF_NET_TCP_CLIENTS_H__ 48 | -------------------------------------------------------------------------------- /examples/microservices/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.27) 2 | 3 | project(ComplexType) 4 | set(PROJECT ${PROJECT_NAME}) 5 | string(TOLOWER "${PROJECT}" PROJECT_LC) 6 | 7 | set(SERVICE_PROJECT "service") 8 | set(STORAGE_PROJECT "storage") 9 | 10 | include (../common/cmake/mif.cmake) 11 | 12 | include_directories(${CMAKE_SOURCE_DIR}/common/include) 13 | 14 | set(COMMON_HEADERS 15 | ${COMMON_HEADERS} 16 | ${CMAKE_SOURCE_DIR}/common/include 17 | ) 18 | 19 | set(SERVICE_SOURCES 20 | ${SERVICE_SOURCES} 21 | ${COMMON_HEADERS} 22 | ${CMAKE_CURRENT_SOURCE_DIR}/service/src 23 | ) 24 | 25 | set(SERVICE_SOURCES 26 | ${SERVICE_SOURCES} 27 | ${CMAKE_CURRENT_SOURCE_DIR}/service/src/employee_service.cpp 28 | ) 29 | 30 | set(STORAGE_HEADERS 31 | ${STORAGE_HEADERS} 32 | ${COMMON_HEADERS} 33 | ) 34 | 35 | set(STORAGE_SOURCES 36 | ${STORAGE_SOURCES} 37 | ${CMAKE_CURRENT_SOURCE_DIR}/storage/src/pg_employee_storage.cpp 38 | ) 39 | 40 | add_executable(${SERVICE_PROJECT} ${SERVICE_HEADERS} ${SERVICE_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/service/src/main.cpp) 41 | target_link_libraries(${SERVICE_PROJECT} ${LIBRARIES}) 42 | 43 | add_executable(${STORAGE_PROJECT} ${STORAGE_HEADERS} ${STORAGE_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/storage/src/main.cpp) 44 | target_link_libraries(${STORAGE_PROJECT} ${LIBRARIES}) 45 | -------------------------------------------------------------------------------- /examples/visitor/common/include/common/interface/iface.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 02.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __VISITOR_COMMON_INTERFACE_IFACE_H__ 9 | #define __VISITOR_COMMON_INTERFACE_IFACE_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include 16 | 17 | namespace Service 18 | { 19 | 20 | struct IMessage 21 | : public Mif::Service::Inherit 22 | { 23 | virtual std::string GetText() const = 0; 24 | }; 25 | 26 | using IMessagePtr = Mif::Service::TIntrusivePtr; 27 | 28 | struct IMessageVisitor 29 | : public Mif::Service::Inherit 30 | { 31 | virtual void Visit(IMessagePtr message) = 0 ; 32 | }; 33 | 34 | using IMessageVisitorPtr = Mif::Service::TIntrusivePtr; 35 | 36 | struct IViewer 37 | : public Mif::Service::Inherit 38 | { 39 | virtual void Accept(IMessageVisitorPtr visitor) = 0; 40 | }; 41 | 42 | } // namespace Service 43 | 44 | #endif // !__VISITOR_COMMON_INTERFACE_IFACE_H__ 45 | -------------------------------------------------------------------------------- /include/mif/net/http/ioutput_pack.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 11.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_IOUTPUT_PACK_H__ 9 | #define __MIF_NET_HTTP_IOUTPUT_PACK_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/common/types.h" 16 | #include "mif/net/http/codes.h" 17 | 18 | namespace Mif 19 | { 20 | namespace Net 21 | { 22 | namespace Http 23 | { 24 | 25 | struct IOutputPack 26 | { 27 | virtual ~IOutputPack() = default; 28 | 29 | virtual Code GetCode() const = 0; 30 | 31 | virtual void SetCode(Code code) = 0; 32 | virtual void SetReason(std::string const &reason) = 0; 33 | 34 | virtual void SetHeader(std::string const &key, std::string const &value) = 0; 35 | virtual void SetData(Common::Buffer buffer) = 0; 36 | virtual void SetData(Common::BufferPtr buffer) = 0; 37 | }; 38 | 39 | } // namespace Http 40 | } // namespace Net 41 | } // namespace Mif 42 | 43 | #endif // !__MIF_NET_HTTP_IOUTPUT_PACK_H__ 44 | -------------------------------------------------------------------------------- /examples/microservices/service/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | #include 11 | 12 | // THIS 13 | #include "id/service.h" 14 | 15 | class Application 16 | : public Mif::Application::HttpServer 17 | { 18 | public: 19 | using HttpServer::HttpServer; 20 | 21 | private: 22 | // Mif.Application.HttpService 23 | virtual void Init(Mif::Net::Http::ServerHandlers &handlers) override final 24 | { 25 | auto config = GetConfig(); 26 | if (!config) 27 | throw std::runtime_error{"[Service::Application::Init] No config."}; 28 | 29 | std::string const employeeLocation = "/employee"; 30 | auto employeeHandler = Mif::Net::Http::MakeWebService( 31 | employeeLocation, config->GetConfig("storage") 32 | ); 33 | 34 | handlers.emplace(employeeLocation, employeeHandler); 35 | } 36 | }; 37 | 38 | int main(int argc, char const **argv) 39 | { 40 | return Mif::Application::Run(argc, argv); 41 | } 42 | -------------------------------------------------------------------------------- /include/mif/net/http/serializer/json.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_SERIALIZER_JSON_H__ 9 | #define __MIF_NET_HTTP_SERIALIZER_JSON_H__ 10 | 11 | // MIF 12 | #include "mif/serialization/json.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Net 17 | { 18 | namespace Http 19 | { 20 | namespace Serializer 21 | { 22 | 23 | struct Json final 24 | { 25 | static constexpr char const* GetContentType() 26 | { 27 | return "application/json; charset=UTF-8"; 28 | } 29 | 30 | template 31 | static Common::Buffer Serialize(T const &data) 32 | { 33 | return Serialization::Json::Serialize(data); 34 | } 35 | }; 36 | 37 | } // namespace Serializer 38 | } // namespace Http 39 | } // namespace Net 40 | } // namespace Mif 41 | 42 | 43 | #endif // !__MIF_NET_HTTP_SERIALIZER_JSON_H__ 44 | -------------------------------------------------------------------------------- /include/mif/remote/factory.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_FACTORY_H__ 9 | #define __MIF_REMOTE_FACTORY_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/net/iconnection.h" 17 | #include "mif/service/ifactory.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Remote 22 | { 23 | 24 | class Factory 25 | : public Service::Inherit 26 | { 27 | public: 28 | using ServiceCreator = std::function; 29 | 30 | Factory(std::shared_ptr connection, ServiceCreator const &serviceCreator); 31 | 32 | private: 33 | std::shared_ptr m_connection; 34 | ServiceCreator m_serviceCreator; 35 | 36 | // IFactory 37 | virtual Service::IServicePtr Create(Service::ServiceId id) override final; 38 | }; 39 | 40 | } // namespace Remote 41 | } // namespace Mif 42 | 43 | #endif // !__MIF_REMOTE_FACTORY_H__ 44 | -------------------------------------------------------------------------------- /include/mif/remote/detail/meta/iobject_manager.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_DETAIL_META_IOBJECT_MANAGER_H__ 9 | #define __MIF_REMOTE_DETAIL_META_IOBJECT_MANAGER_H__ 10 | 11 | // MIF 12 | #include "mif/remote/ps.h" 13 | #include "mif/remote/detail/iobject_manager.h" 14 | 15 | namespace Mif 16 | { 17 | namespace Remote 18 | { 19 | namespace Detail 20 | { 21 | namespace Meta 22 | { 23 | 24 | using Detail::IObjectManager; 25 | 26 | MIF_REMOTE_PS_BEGIN(IObjectManager) 27 | MIF_REMOTE_METHOD(CreateObject) 28 | MIF_REMOTE_METHOD(DestroyObject) 29 | MIF_REMOTE_METHOD(QueryInterface) 30 | MIF_REMOTE_METHOD(CloneReference) 31 | MIF_REMOTE_PS_END() 32 | 33 | } // namespace Meta 34 | } // namespace Detail 35 | } // namespace Remote 36 | } // namespace Mif 37 | 38 | MIF_REMOTE_REGISTER_PS(Mif::Remote::Detail::Meta::IObjectManager) 39 | 40 | #endif // !__MIF_REMOTE_DETAIL_META_IOBJECT_MANAGER_H__ 41 | -------------------------------------------------------------------------------- /include/mif/common/index_sequence.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_INDEX_SEQUENCE_H__ 9 | #define __MIF_COMMON_INDEX_SEQUENCE_H__ 10 | 11 | // STD 12 | #include 13 | 14 | namespace Mif 15 | { 16 | namespace Common 17 | { 18 | 19 | template 20 | struct IndexSequence 21 | { 22 | }; 23 | 24 | namespace Detail 25 | { 26 | 27 | template 28 | struct IndexSequenceGenerator 29 | : IndexSequenceGenerator 30 | { 31 | }; 32 | 33 | template 34 | struct IndexSequenceGenerator<0u, Indexes ... > 35 | { 36 | using Type = IndexSequence; 37 | }; 38 | 39 | } // namespace Detail 40 | 41 | template 42 | using MakeIndexSequence = typename Detail::IndexSequenceGenerator::Type; 43 | 44 | } // namespace Common 45 | } // namespace Mif 46 | 47 | #endif // !__MIF_COMMON_INDEX_SEQUENCE_H__ 48 | -------------------------------------------------------------------------------- /include/mif/remote/predefined/protocol/simple_frame.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_PREDEFINED_PROTOCOL_SIMPLE_FRAME_H__ 9 | #define __MIF_REMOTE_PREDEFINED_PROTOCOL_SIMPLE_FRAME_H__ 10 | 11 | // MIF 12 | #include "mif/net/clients_chain.h" 13 | #include "mif/net/clients/parallel_handler.h" 14 | #include "mif/net/clients/frame_reader.h" 15 | #include "mif/net/clients/frame_writer.h" 16 | 17 | namespace Mif 18 | { 19 | namespace Remote 20 | { 21 | namespace Predefined 22 | { 23 | namespace Protocol 24 | { 25 | 26 | template 27 | using SimpleFrame = Net::ClientsChain 28 | < 29 | Net::Clients::FrameReader, 30 | Net::Clients::ParallelHandler, 31 | TClient, 32 | Net::Clients::FrameWriter 33 | >; 34 | 35 | } // namespace Protocol 36 | } // namespace Predefined 37 | } // namespace Remote 38 | } // namespace Mif 39 | 40 | #endif // !__MIF_REMOTE_PREDEFINED_PROTOCOL_SIMPLE_FRAME_H__ 41 | -------------------------------------------------------------------------------- /include/mif/service/create.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_SERVICE_CREATE_H__ 9 | #define __MIF_SERVICE_CREATE_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/service/iservice.h" 16 | 17 | namespace Mif 18 | { 19 | namespace Service 20 | { 21 | namespace Detail 22 | { 23 | namespace Creators 24 | { 25 | 26 | template 27 | IServicePtr Create(TArgs ... args); 28 | 29 | } // namespace Creators 30 | } // namespace Detail 31 | 32 | template 33 | TServicePtr Create(TArgs && ... args) 34 | { 35 | return Cast(Detail::Creators::Create(std::forward(args) ... )); 36 | } 37 | 38 | template 39 | IServicePtr Create(TArgs && ... args) 40 | { 41 | return Create(std::forward(args) ... ); 42 | } 43 | 44 | } // namespace Service 45 | } // namespace Mif 46 | 47 | #endif // !__MIF_SERVICE_CREATE_H__ 48 | -------------------------------------------------------------------------------- /examples/inheritance/client/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | #include 11 | 12 | // COMMON 13 | #include "common/id/service.h" 14 | #include "common/ps/iface.h" 15 | 16 | class Application 17 | : public Mif::Application::TcpServiceClient 18 | { 19 | public: 20 | using TcpServiceClient::TcpServiceClient; 21 | 22 | private: 23 | // Mif.Application.TcpServiceClient 24 | virtual void Init(Mif::Service::IFactoryPtr factory) override final 25 | { 26 | auto service = factory->Create(Service::Id::Service); 27 | 28 | auto human = service->Cast(); 29 | MIF_LOG(Info) << "Name: \"" << human->GetName() << "\""; 30 | MIF_LOG(Info) << "Age: \"" << human->GetAge() << "\""; 31 | 32 | service->Planning(); 33 | service->Development(); 34 | service->BugFixes(); 35 | service->Monitoring(); 36 | 37 | MIF_LOG(Info) << "Rate: \"" << service->GetRate() << "\""; 38 | } 39 | }; 40 | 41 | int main(int argc, char const **argv) 42 | { 43 | return Mif::Application::Run(argc, argv); 44 | } 45 | -------------------------------------------------------------------------------- /examples/inheritance/common/include/common/interface/iface.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __INHERITANCE_COMMON_INTERFACE_IFACE_H__ 9 | #define __INHERITANCE_COMMON_INTERFACE_IFACE_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include 17 | 18 | namespace Service 19 | { 20 | 21 | struct IHuman 22 | : public Mif::Service::Inherit 23 | { 24 | virtual std::string GetName() const = 0; 25 | virtual std::size_t GetAge() const = 0; 26 | }; 27 | 28 | struct IDeveloper 29 | : public Mif::Service::Inherit 30 | { 31 | virtual void Development() = 0; 32 | virtual void BugFixes() = 0; 33 | }; 34 | 35 | struct IManager 36 | : public Mif::Service::Inherit 37 | { 38 | virtual void Planning() = 0; 39 | virtual void Monitoring() = 0; 40 | }; 41 | 42 | struct IEmployee 43 | : public Mif::Service::Inherit 44 | { 45 | virtual double GetRate() = 0; 46 | }; 47 | 48 | } // namespace Service 49 | 50 | #endif // !__INHERITANCE_COMMON_INTERFACE_IFACE_H__ 51 | -------------------------------------------------------------------------------- /examples/microservices/common/include/common/interface/iemployee_storage.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 08.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MICROSERVICES_COMMON_INTERFACE_IEMPPLOYEE_STORAGE_H__ 9 | #define __MICROSERVICES_COMMON_INTERFACE_IEMPPLOYEE_STORAGE_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include 17 | 18 | // THIS 19 | #include "common/data/data.h" 20 | 21 | namespace Common 22 | { 23 | 24 | struct IEmployeeStorage 25 | : public Mif::Service::Inherit 26 | { 27 | virtual Data::ID Create(Data::Employee const &employee) = 0; 28 | virtual Data::Employee Read(Data::ID const &id) const = 0; 29 | virtual void Update(Data::ID const &id, Data::Employee const &employee) = 0; 30 | virtual void Delete(Data::ID const &id) = 0; 31 | 32 | // CRUD extension method 33 | virtual Data::Employees List(std::size_t offset = std::numeric_limits::max(), 34 | std::size_t limit = std::numeric_limits::max()) const = 0; 35 | }; 36 | 37 | } // namespace Common 38 | 39 | #endif // !__MICROSERVICES_COMMON_INTERFACE_IEMPPLOYEE_STORAGE_H__ 40 | -------------------------------------------------------------------------------- /include/mif/net/clients/parallel_handler.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 02.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_CLIENTS_PARALLEL_HANDLER_H__ 9 | #define __MIF_NET_CLIENTS_PARALLEL_HANDLER_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/common/thread_pool.h" 16 | #include "mif/net/iclient_factory.h" 17 | #include "mif/net/client.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Net 22 | { 23 | namespace Clients 24 | { 25 | 26 | class ParallelHandler final 27 | : public Net::Client 28 | { 29 | public: 30 | ParallelHandler(std::weak_ptr control, std::weak_ptr publisher, 31 | Common::IThreadPoolPtr workers); 32 | ~ParallelHandler(); 33 | 34 | private: 35 | class Impl; 36 | std::shared_ptr m_impl; 37 | 38 | // Client 39 | virtual void ProcessData(Common::Buffer buffer) override final; 40 | }; 41 | 42 | } // namespace Clients 43 | } // namespace Net 44 | } // namespace Mif 45 | 46 | #endif // !__MIF_NET_CLIENTS_PARALLEL_HANDLER_H__ 47 | -------------------------------------------------------------------------------- /examples/hello_world/client/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | #include 11 | 12 | // COMMON 13 | #include "common/id/service.h" 14 | #include "common/ps/ihello_world.h" 15 | 16 | class Application 17 | : public Mif::Application::TcpServiceClient 18 | { 19 | public: 20 | using TcpServiceClient::TcpServiceClient; 21 | 22 | private: 23 | // Mif.Application.TcpServiceClient 24 | virtual void Init(Mif::Service::IFactoryPtr factory) override final 25 | { 26 | auto service = factory->Create(Service::Id::HelloWorld); 27 | 28 | MIF_LOG(Info) << "Add words."; 29 | 30 | service->AddWord("Hello"); 31 | service->AddWord("World"); 32 | service->AddWord("!!!"); 33 | 34 | MIF_LOG(Info) << "Result from server: \"" << service->GetText() << "\""; 35 | 36 | MIF_LOG(Info) << "Clean."; 37 | service->Clean(); 38 | 39 | MIF_LOG(Info) << "Result from server: \"" << service->GetText() << "\""; 40 | } 41 | }; 42 | 43 | int main(int argc, char const **argv) 44 | { 45 | return Mif::Application::Run(argc, argv); 46 | } 47 | -------------------------------------------------------------------------------- /cmake/settings.cmake: -------------------------------------------------------------------------------- 1 | project (Mif) 2 | set (PROJECT ${PROJECT_NAME}) 3 | string (TOLOWER "${PROJECT}" PROJECT_LC) 4 | 5 | if (NOT MIF_STD_CXX) 6 | set (MIF_STD_CXX "c++11") 7 | endif(NOT MIF_STD_CXX) 8 | 9 | set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/MyCMakeScripts) 10 | 11 | if (NOT DEFINED THITD_PARTY_OUTPUT_PATH) 12 | set (THITD_PARTY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/third_party) 13 | endif() 14 | 15 | set (THITD_PARTY_SOURCES_PATH ${CMAKE_SOURCE_DIR}/third_party_sources) 16 | set (EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) 17 | set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) 18 | set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) 19 | set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) 20 | set (LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) 21 | 22 | set (MIF_SHARED_LIB_SUFFIX "_shared") 23 | 24 | if (NOT CMAKE_BUILD_TYPE) 25 | set (CMAKE_BUILD_TYPE "Release" CACHE INTERNAL "") 26 | endif(NOT CMAKE_BUILD_TYPE) 27 | 28 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") 29 | 30 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -fPIC -std=${MIF_STD_CXX}") 31 | set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -DDEBUG") 32 | set (CMAKE_CXX_FLAGS_RELEASE "-O3 -g0 -DNDEBUG") 33 | set (CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++") 34 | set (CMAKE_SHARED_LINKER_FLAGS "-static-libgcc -static-libstdc++") 35 | set (CMAKE_POSITION_INDEPENDENT_CODE ON) 36 | 37 | set(Boost_USE_STATIC_LIBS ON) 38 | set(Boost_USE_MULTITHREADED ON) -------------------------------------------------------------------------------- /include/mif/db/irecordset.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_DB_IRECORDSET_H__ 9 | #define __MIF_DB_IRECORDSET_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/service/iservice.h" 17 | 18 | namespace Mif 19 | { 20 | namespace Db 21 | { 22 | 23 | struct IRecordset 24 | : public Service::Inherit 25 | { 26 | virtual bool Read() = 0; 27 | virtual std::size_t GetFieldsCount() const = 0; 28 | virtual bool IsNull(std::size_t index) const = 0; 29 | virtual std::string GetFieldName(std::size_t index) const = 0; 30 | virtual std::size_t GetFieldIndex(std::string const &name) const = 0; 31 | virtual std::string GetAsString(std::size_t index) const = 0; 32 | virtual std::int32_t GetAsInt32(std::size_t index) const = 0; 33 | virtual std::int64_t GetAsInt64(std::size_t index) const = 0; 34 | virtual double GetAsDouble(std::size_t index) const = 0; 35 | }; 36 | 37 | using IRecordsetPtr = Service::TServicePtr; 38 | 39 | } // namespace Db 40 | } // namespace Mif 41 | 42 | #endif // !__MIF_DB_IRECORDSET_H__ 43 | -------------------------------------------------------------------------------- /examples/http_crud/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | #include 11 | 12 | // THIS 13 | #include "employee_service.h" 14 | 15 | class Application 16 | : public Mif::Application::HttpServer 17 | { 18 | public: 19 | using HttpServer::HttpServer; 20 | 21 | private: 22 | // Mif.Application.HttpService 23 | virtual void Init(Mif::Net::Http::ServerHandlers &handlers) override final 24 | { 25 | auto config = GetConfig(); 26 | if (!config) 27 | throw std::runtime_error{"[Application::Init] No config."}; 28 | auto dbConfig = config->GetConfig("database"); 29 | if (!dbConfig) 30 | throw std::runtime_error{"[Application::Init] No 'database' node in the config."}; 31 | std::string const employeeLocation = "/employee"; 32 | auto employeeService = Mif::Service::Make( 33 | employeeLocation, dbConfig); 34 | handlers.emplace(employeeLocation, Mif::Net::Http::MakeWebService(employeeService)); 35 | } 36 | }; 37 | 38 | int main(int argc, char const **argv) 39 | { 40 | return Mif::Application::Run(argc, argv); 41 | } 42 | -------------------------------------------------------------------------------- /include/mif/net/http/converter/content/json.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_CONVERTER_CONTENT_JSON_H__ 9 | #define __MIF_NET_HTTP_CONVERTER_CONTENT_JSON_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/serialization/json.h" 16 | 17 | namespace Mif 18 | { 19 | namespace Net 20 | { 21 | namespace Http 22 | { 23 | namespace Converter 24 | { 25 | namespace Content 26 | { 27 | 28 | struct Json final 29 | { 30 | template 31 | static T Convert(Common::Buffer const &buffer) 32 | { 33 | if (buffer.empty()) 34 | throw std::invalid_argument{"[Mif::Net::Http::Converter::Content::Json] No content."}; 35 | return Serialization::Json::Deserialize(buffer); 36 | } 37 | }; 38 | 39 | } // namespace Content 40 | } // namespace Converter 41 | } // namespace Http 42 | } // namespace Net 43 | } // namespace Mif 44 | 45 | #endif // !__MIF_NET_HTTP_CONVERTER_CONTENT_JSON_H__ 46 | -------------------------------------------------------------------------------- /include/mif/net/http/iinput_pack.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 11.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_IINPUT_PACK_H__ 9 | #define __MIF_NET_HTTP_IINPUT_PACK_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | // MIF 17 | #include "mif/common/types.h" 18 | #include "mif/net/http/codes.h" 19 | #include "mif/net/http/methods.h" 20 | 21 | namespace Mif 22 | { 23 | namespace Net 24 | { 25 | namespace Http 26 | { 27 | 28 | struct IInputPack 29 | { 30 | using Params = std::map; 31 | using Headers = std::map; 32 | 33 | virtual ~IInputPack() = default; 34 | 35 | virtual Method::Type GetType() const = 0; 36 | 37 | virtual std::string GetPath() const = 0; 38 | virtual std::string GetQuery() const = 0; 39 | 40 | virtual Params GetParams() const = 0; 41 | 42 | virtual Headers GetHeaders() const = 0; 43 | 44 | virtual Common::Buffer const& GetData() const = 0; 45 | }; 46 | 47 | } // namespace Http 48 | } // namespace Net 49 | } // namespace Mif 50 | 51 | #endif // !__MIF_NET_HTTP_IINPUT_PACK_H__ 52 | -------------------------------------------------------------------------------- /include/mif/db/transaction.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_DB_TRANSACTION_H__ 9 | #define __MIF_DB_TRANSACTION_H__ 10 | 11 | // MIF 12 | #include "mif/db/iconnection.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Db 17 | { 18 | 19 | class Transaction final 20 | { 21 | public: 22 | enum class State 23 | { 24 | Unknown, 25 | Init, 26 | Begin, 27 | Commit, 28 | Rollback 29 | }; 30 | 31 | Transaction(Transaction const &) = delete; 32 | Transaction& operator = (Transaction const &) = delete; 33 | 34 | Transaction(IConnectionPtr connection, bool open = true); 35 | Transaction(Transaction &&transaction); 36 | Transaction& operator = (Transaction &&transaction); 37 | 38 | ~Transaction(); 39 | 40 | void Begin(); 41 | void Commit(); 42 | void Rollback(); 43 | State GetState() const; 44 | 45 | private: 46 | IConnectionPtr m_connection; 47 | State m_state = State::Init; 48 | }; 49 | 50 | } // namespace Db 51 | } // namespace Mif 52 | 53 | #endif // !__MIF_DB_TRANSACTION_H__ 54 | -------------------------------------------------------------------------------- /examples/microservices/common/include/common/data/meta/data.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 08.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MICROSERVICES_COMMON_DATA_META_DATA_H__ 9 | #define __MICROSERVICES_COMMON_DATA_META_DATA_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | // THIS 15 | #include "common/data/data.h" 16 | 17 | namespace Common 18 | { 19 | namespace Data 20 | { 21 | namespace Meta 22 | { 23 | 24 | MIF_REFLECT_BEGIN(Position) 25 | MIF_REFLECT_FIELD(Unknown) 26 | MIF_REFLECT_FIELD(Developer) 27 | MIF_REFLECT_FIELD(Manager) 28 | MIF_REFLECT_END() 29 | 30 | MIF_REFLECT_BEGIN(Employee) 31 | MIF_REFLECT_FIELD(name) 32 | MIF_REFLECT_FIELD(lastName) 33 | MIF_REFLECT_FIELD(age) 34 | MIF_REFLECT_FIELD(email) 35 | MIF_REFLECT_FIELD(position) 36 | MIF_REFLECT_FIELD(rate) 37 | MIF_REFLECT_END() 38 | 39 | } // namespace Meta 40 | } // namespace Data 41 | } // namespace Common 42 | 43 | MIF_REGISTER_REFLECTED_TYPE(::Common::Data::Meta::Position) 44 | MIF_REGISTER_REFLECTED_TYPE(::Common::Data::Meta::Employee) 45 | 46 | #endif // !__MICROSERVICES_COMMON_DATA_META_DATA_H__ 47 | -------------------------------------------------------------------------------- /include/mif/remote/predefined/serialization/boost/xml.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_PREDEFINED_SERIALIZATION_BOOST_XML_H__ 9 | #define __MIF_REMOTE_PREDEFINED_SERIALIZATION_BOOST_XML_H__ 10 | 11 | // BOOST 12 | #include 13 | #include 14 | 15 | // MIF 16 | 17 | #include "mif/remote/serialization/serialization.h" 18 | #include "mif/remote/serialization/boost.h" 19 | 20 | namespace Mif 21 | { 22 | namespace Remote 23 | { 24 | namespace Predefined 25 | { 26 | namespace Serialization 27 | { 28 | namespace Boost 29 | { 30 | 31 | using Xml = Remote::Serialization::SerializerTraits 32 | < 33 | Remote::Serialization::Boost::Serializer, 34 | Remote::Serialization::Boost::Deserializer 35 | >; 36 | 37 | } // namespace Boost 38 | } // namespace Serialization 39 | } // namespace Predefined 40 | } // namespace Remote 41 | } // namespace Mif 42 | 43 | #endif // !__MIF_REMOTE_PREDEFINED_SERIALIZATION_BOOST_XML_H__ 44 | -------------------------------------------------------------------------------- /include/mif/common/detail/method.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_DETAIL_METHOD_H__ 9 | #define __MIF_COMMON_DETAIL_METHOD_H__ 10 | 11 | // STD 12 | #include 13 | 14 | namespace Mif 15 | { 16 | namespace Common 17 | { 18 | namespace Detail 19 | { 20 | 21 | template 22 | struct Method; 23 | 24 | template 25 | struct Method 26 | { 27 | using ClassType = TClass; 28 | using ResultType = TResult; 29 | using ParamTypeList = std::tuple; 30 | enum { IsConst = 0 }; 31 | }; 32 | 33 | template 34 | struct Method 35 | { 36 | using ClassType = TClass; 37 | using ResultType = TResult; 38 | using ParamTypeList = std::tuple; 39 | enum { IsConst = 1 }; 40 | }; 41 | 42 | } // namespace Detail 43 | } // namespace Common 44 | } // namespace Mif 45 | 46 | 47 | #endif // !__MIF_COMMON_DETAIL_METHOD_H__ 48 | -------------------------------------------------------------------------------- /include/mif/remote/predefined/serialization/boost/text.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_PREDEFINED_SERIALIZATION_BOOST_TEXT_H__ 9 | #define __MIF_REMOTE_PREDEFINED_SERIALIZATION_BOOST_TEXT_H__ 10 | 11 | // BOOST 12 | #include 13 | #include 14 | 15 | // MIF 16 | 17 | #include "mif/remote/serialization/serialization.h" 18 | #include "mif/remote/serialization/boost.h" 19 | 20 | namespace Mif 21 | { 22 | namespace Remote 23 | { 24 | namespace Predefined 25 | { 26 | namespace Serialization 27 | { 28 | namespace Boost 29 | { 30 | 31 | using Text = Remote::Serialization::SerializerTraits 32 | < 33 | Remote::Serialization::Boost::Serializer, 34 | Remote::Serialization::Boost::Deserializer 35 | >; 36 | 37 | } // namespace Boost 38 | } // namespace Serialization 39 | } // namespace Predefined 40 | } // namespace Remote 41 | } // namespace Mif 42 | 43 | #endif // !__MIF_REMOTE_PREDEFINED_SERIALIZATION_BOOST_TEXT_H__ 44 | -------------------------------------------------------------------------------- /include/mif/net/http/server.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 11.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_SERVER_H__ 9 | #define __MIF_NET_HTTP_SERVER_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | // MIF 17 | #include "mif/net/http/methods.h" 18 | #include "mif/net/http/request_handler.h" 19 | 20 | namespace Mif 21 | { 22 | namespace Net 23 | { 24 | namespace Http 25 | { 26 | 27 | class Server final 28 | { 29 | public: 30 | Server(std::string const &host, std::string const &port, 31 | std::uint16_t workers, 32 | Methods const &allowedMethods, 33 | ServerHandlers const &handlers, 34 | std::size_t headersSize = -1, 35 | std::size_t bodySize = -1, 36 | std::size_t chunkSize = -1, 37 | std::size_t requestTimeout = -1, 38 | std::size_t pipelineLimit = -1); 39 | 40 | ~Server(); 41 | 42 | private: 43 | class Impl; 44 | std::unique_ptr m_impl; 45 | }; 46 | 47 | } // namespace Http 48 | } // namespace Net 49 | } // namespace Mif 50 | 51 | #endif // !__MIF_NET_HTTP_SERVER_H__ 52 | -------------------------------------------------------------------------------- /include/mif/remote/detail/iobject_manager.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_DETAIL_IOBJECT_MANAGER_H__ 9 | #define __MIF_REMOTE_DETAIL_IOBJECT_MANAGER_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/service/iservice.h" 16 | 17 | namespace Mif 18 | { 19 | namespace Remote 20 | { 21 | namespace Detail 22 | { 23 | 24 | struct IObjectManager 25 | : public Service::Inherit 26 | { 27 | virtual ~IObjectManager() = default; 28 | virtual std::string CreateObject(Service::ServiceId serviceId, std::string const &interfaceId) = 0; 29 | virtual void DestroyObject(std::string const &instanceId) = 0; 30 | virtual std::string QueryInterface(std::string const &instanceId, std::string const &interfaceId, 31 | std::string const &serviceId) = 0; 32 | virtual std::string CloneReference(std::string const &instanceId, std::string const &interfaceId) = 0; 33 | }; 34 | 35 | using IObjectManagerPtr = Service::TServicePtr; 36 | 37 | } // namespace Detail 38 | } // namespace Remote 39 | } // namespace Mif 40 | 41 | #endif // !__MIF_REMOTE_DETAIL_IOBJECT_MANAGER_H__ 42 | -------------------------------------------------------------------------------- /include/mif/application/iconfig.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_APPLICATION_ICONFIG_H__ 9 | #define __MIF_APPLICATION_ICONFIG_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/common/icollection.h" 17 | #include "mif/service/iservice.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Application 22 | { 23 | struct IConfig 24 | : public Service::Inherit 25 | { 26 | virtual bool Exists(std::string const &path) const = 0; 27 | virtual std::string GetValue(std::string const &path) const = 0; 28 | virtual Service::TIntrusivePtr GetConfig(std::string const &path) const = 0; 29 | virtual Common::ICollectionPtr GetCollection(std::string const &path) const = 0; 30 | 31 | template 32 | T GetValue(std::string const &path) const 33 | { 34 | std::stringstream stream{GetValue(path)}; 35 | T value{}; 36 | stream >> value; 37 | return value; 38 | } 39 | }; 40 | 41 | using IConfigPtr = Service::TServicePtr; 42 | 43 | } // namespace Application 44 | } // namespace Mif 45 | 46 | #endif // !__MIF_APPLICATION_ICONFIG_H__ 47 | -------------------------------------------------------------------------------- /examples/complex_type/common/include/common/meta/data.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 10.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __COMPLEX_TYPE_COMMON_META_DATA_H__ 9 | #define __COMPLEX_TYPE_COMMON_META_DATA_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | // THIS 15 | #include "common/data/data.h" 16 | 17 | namespace Service 18 | { 19 | namespace Data 20 | { 21 | namespace Meta 22 | { 23 | 24 | MIF_REFLECT_BEGIN(Human) 25 | MIF_REFLECT_FIELD(name) 26 | MIF_REFLECT_FIELD(lastName) 27 | MIF_REFLECT_FIELD(age) 28 | MIF_REFLECT_END() 29 | 30 | MIF_REFLECT_BEGIN(Position) 31 | MIF_REFLECT_FIELD(Unknown) 32 | MIF_REFLECT_FIELD(Developer) 33 | MIF_REFLECT_FIELD(Manager) 34 | MIF_REFLECT_END() 35 | 36 | MIF_REFLECT_BEGIN(Employee, Human) 37 | MIF_REFLECT_FIELD(position) 38 | MIF_REFLECT_END() 39 | 40 | } // namespace Meta 41 | } // namespace Data 42 | } // namespace Service 43 | 44 | MIF_REGISTER_REFLECTED_TYPE(::Service::Data::Meta::Human) 45 | MIF_REGISTER_REFLECTED_TYPE(::Service::Data::Meta::Position) 46 | MIF_REGISTER_REFLECTED_TYPE(::Service::Data::Meta::Employee) 47 | 48 | #endif // !__COMPLEX_TYPE_COMMON_META_DATA_H__ 49 | -------------------------------------------------------------------------------- /examples/microservices/storage/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 08.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | 11 | // COMMON 12 | #include "common/id/service.h" 13 | #include "common/interface/ps/iemployee_storage.h" 14 | 15 | namespace Storage 16 | { 17 | 18 | class Application 19 | : public Mif::Application::TcpService 20 | { 21 | public: 22 | using TcpService::TcpService; 23 | 24 | private: 25 | // Mif.Application.Application 26 | virtual void Init(Mif::Service::FactoryPtr factory) override final 27 | { 28 | auto config = GetConfig(); 29 | if (!config) 30 | throw std::runtime_error{"[Storage::Application::Init] No config."}; 31 | 32 | auto dbConfig = config->GetConfig("database"); 33 | if (!dbConfig) 34 | throw std::runtime_error{"[Storage::Application::Init] No 'database' config node."}; 35 | 36 | auto storage = Mif::Service::Create(dbConfig); 37 | 38 | factory->AddInstance(Common::Service::Id::PGEmployeeStorage, storage); 39 | } 40 | }; 41 | 42 | } // namespace Storage 43 | 44 | int main(int argc, char const **argv) 45 | { 46 | return Mif::Application::Run(argc, argv); 47 | } 48 | -------------------------------------------------------------------------------- /include/mif/remote/predefined/serialization/boost/binary.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_PREDEFINED_SERIALIZATION_BOOST_BINARY_H__ 9 | #define __MIF_REMOTE_PREDEFINED_SERIALIZATION_BOOST_BINARY_H__ 10 | 11 | // BOOST 12 | #include 13 | #include 14 | 15 | // MIF 16 | 17 | #include "mif/remote/serialization/serialization.h" 18 | #include "mif/remote/serialization/boost.h" 19 | 20 | namespace Mif 21 | { 22 | namespace Remote 23 | { 24 | namespace Predefined 25 | { 26 | namespace Serialization 27 | { 28 | namespace Boost 29 | { 30 | 31 | using Binary = Remote::Serialization::SerializerTraits 32 | < 33 | Remote::Serialization::Boost::Serializer, 34 | Remote::Serialization::Boost::Deserializer 35 | >; 36 | 37 | } // namespace Boost 38 | } // namespace Serialization 39 | } // namespace Predefined 40 | } // namespace Remote 41 | } // namespace Mif 42 | 43 | #endif // !__MIF_REMOTE_PREDEFINED_SERIALIZATION_BOOST_BINARY_H__ 44 | -------------------------------------------------------------------------------- /include/mif/service/external.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 06.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_SERVICE_EXTERNAL_H__ 9 | #define __MIF_SERVICE_EXTERNAL_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/common/unused.h" 17 | #include "mif/service/iservice.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Service 22 | { 23 | 24 | class External 25 | : public Inherit 26 | , private Detail::IProxyBase_Mif_Remote_ 27 | { 28 | public: 29 | void Add(IServicePtr service); 30 | 31 | private: 32 | template 33 | friend class Detail::Service_Impl__; 34 | 35 | using LockType = std::mutex; 36 | using LockGuard = std::lock_guard; 37 | 38 | using Services = std::list; 39 | 40 | LockType m_lock; 41 | 42 | Services m_services; 43 | 44 | // IProxyBase_Mif_Remote_ 45 | virtual bool _Mif_Remote_QueryRemoteInterface(void **service, 46 | std::type_info const &typeInfo, std::string const &serviceId, 47 | IService **holder) override final; 48 | }; 49 | 50 | } // namespace Service 51 | } // namespace Mif 52 | 53 | #endif // !__MIF_SERVICE_EXTERNAL_H__ 54 | -------------------------------------------------------------------------------- /include/mif/service/ilocator.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_SERVICE_ILOCATOR_H__ 9 | #define __MIF_SERVICE_ILOCATOR_H__ 10 | 11 | // MIF 12 | #include "mif/service/create.h" 13 | #include "mif/service/iservice.h" 14 | 15 | namespace Mif 16 | { 17 | namespace Service 18 | { 19 | 20 | struct ILocator 21 | : public Inherit 22 | { 23 | MIF_SERVICE_ID("Mif.Service.ILocator") 24 | 25 | virtual IServicePtr Get(ServiceId id) const = 0; 26 | virtual bool Exists(ServiceId id) const = 0; 27 | virtual void Put(ServiceId id, IServicePtr service) = 0; 28 | virtual void Remove(ServiceId id) = 0; 29 | virtual void Clear() = 0; 30 | 31 | template 32 | TServicePtr Get(ServiceId id) const 33 | { 34 | return ::Mif::Service::Cast(Get(id)); 35 | } 36 | 37 | template 38 | void Put(TArgs && ... args) 39 | { 40 | Put(Id, Create(std::forward(args) ... )); 41 | } 42 | }; 43 | 44 | using ILocatorPtr = TServicePtr; 45 | 46 | } // namespace Service 47 | } // namespace Mif 48 | 49 | #endif // !__MIF_SERVICE_ILOCATOR_H__ 50 | -------------------------------------------------------------------------------- /examples/inheritance/common/include/common/ps/iface.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __INHERITANCE_COMMON_PS_IFACE_H__ 9 | #define __INHERITANCE_COMMON_PS_IFACE_H__ 10 | 11 | // MIF 12 | #include 13 | 14 | // THIS 15 | #include "common/interface/iface.h" 16 | 17 | namespace Service 18 | { 19 | namespace Meta 20 | { 21 | 22 | using namespace ::Service; 23 | 24 | MIF_REMOTE_PS_BEGIN(IHuman) 25 | MIF_REMOTE_METHOD(GetName) 26 | MIF_REMOTE_METHOD(GetAge) 27 | MIF_REMOTE_PS_END() 28 | 29 | MIF_REMOTE_PS_BEGIN(IDeveloper) 30 | MIF_REMOTE_METHOD(Development) 31 | MIF_REMOTE_METHOD(BugFixes) 32 | MIF_REMOTE_PS_END() 33 | 34 | MIF_REMOTE_PS_BEGIN(IManager) 35 | MIF_REMOTE_METHOD(Planning) 36 | MIF_REMOTE_METHOD(Monitoring) 37 | MIF_REMOTE_PS_END() 38 | 39 | MIF_REMOTE_PS_BEGIN(IEmployee) 40 | MIF_REMOTE_METHOD(GetRate) 41 | MIF_REMOTE_PS_END() 42 | 43 | } // namespace Meta 44 | } // namespace Service 45 | 46 | MIF_REMOTE_REGISTER_PS(Service::Meta::IHuman) 47 | MIF_REMOTE_REGISTER_PS(Service::Meta::IDeveloper) 48 | MIF_REMOTE_REGISTER_PS(Service::Meta::IManager) 49 | MIF_REMOTE_REGISTER_PS(Service::Meta::IEmployee) 50 | 51 | #endif // !__INHERITANCE_COMMON_PS_IFACE_H__ 52 | -------------------------------------------------------------------------------- /include/mif/net/client.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_CLIENT_H__ 9 | #define __MIF_NET_CLIENT_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/net/ihandler.h" 17 | #include "mif/net/icontrol.h" 18 | #include "mif/net/ipublisher.h" 19 | 20 | namespace Mif 21 | { 22 | namespace Net 23 | { 24 | 25 | class Client 26 | : public std::enable_shared_from_this 27 | , public IHandler 28 | { 29 | public: 30 | Client(std::weak_ptr control, std::weak_ptr publisher); 31 | 32 | bool IsClosed() const; 33 | 34 | // IHandler 35 | virtual void OnData(Common::Buffer buffer) override final; 36 | virtual void OnClose() override final; 37 | 38 | private: 39 | std::atomic m_makredAsClosed{false}; 40 | std::weak_ptr m_control; 41 | std::weak_ptr m_publisher; 42 | 43 | protected: 44 | bool CloseMe(); 45 | bool Post(Common::Buffer buffer); 46 | 47 | virtual void ProcessData(Common::Buffer /*buffer*/); 48 | virtual void Close(); 49 | }; 50 | 51 | } // namespace Net 52 | } // namespace Mif 53 | 54 | #endif // !__MIF_NET_CLIENT_H__ 55 | -------------------------------------------------------------------------------- /include/mif/net/http/detail/params.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2018 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_DETAIL_PARAMS_H__ 9 | #define __MIF_NET_HTTP_DETAIL_PARAMS_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | namespace Mif 16 | { 17 | namespace Net 18 | { 19 | namespace Http 20 | { 21 | namespace Detail 22 | { 23 | namespace Tag 24 | { 25 | 26 | struct Params; 27 | struct Headers; 28 | 29 | } // namespace Tag 30 | 31 | template 32 | class Params final 33 | { 34 | public: 35 | using Type = std::map; 36 | 37 | Params(Type const ¶ms) 38 | : m_params{params} 39 | { 40 | } 41 | 42 | Type const& Get() const 43 | { 44 | return m_params; 45 | } 46 | 47 | private: 48 | Type const &m_params; 49 | }; 50 | 51 | } // namespace Detail 52 | } // namespace Http 53 | } // namespace Net 54 | } // namespace Mif 55 | 56 | #endif // !__MIF_NET_HTTP_DETAIL_PARAMS_H__ 57 | -------------------------------------------------------------------------------- /include/mif/remote/serialization/detail/tag.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 11.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_SERIALIZATION_DETAIL_TAG_H__ 9 | #define __MIF_REMOTE_SERIALIZATION_DETAIL_TAG_H__ 10 | 11 | // MIF 12 | #include "mif/common/static_string.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Remote 17 | { 18 | namespace Serialization 19 | { 20 | namespace Detail 21 | { 22 | namespace Tag 23 | { 24 | 25 | using Pack = MIF_STATIC_STR("package"); 26 | using Uuid = MIF_STATIC_STR("uuid"); 27 | using Type = MIF_STATIC_STR("type"); 28 | using Request = MIF_STATIC_STR("request"); 29 | using Response = MIF_STATIC_STR("response"); 30 | using Instsnce = MIF_STATIC_STR("instance"); 31 | using Interface = MIF_STATIC_STR("interface"); 32 | using Method = MIF_STATIC_STR("method"); 33 | using Param = MIF_STATIC_STR("prm"); 34 | using Exception = MIF_STATIC_STR("exception"); 35 | 36 | } // namespace Tag 37 | } // namespace Detail 38 | } // namespace Serialization 39 | } // namespace Remote 40 | } // namespace Mif 41 | 42 | #endif // !__MIF_REMOTE_SERIALIZATION_DETAIL_TAG_H__ 43 | -------------------------------------------------------------------------------- /src/mif/common/uuid_generator.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // STD 9 | #include 10 | #include 11 | 12 | // BOOST 13 | #include 14 | #include 15 | #include 16 | 17 | // MIF 18 | #include "mif/common/uuid_generator.h" 19 | 20 | namespace Mif 21 | { 22 | namespace Common 23 | { 24 | 25 | class UuidGenerator::Impl final 26 | { 27 | public: 28 | std::string Generate() const 29 | { 30 | std::stringstream stream; 31 | { 32 | std::lock_guard lock(m_lock); 33 | auto const uuid = m_generator(); 34 | stream << uuid; 35 | } 36 | return stream.str(); 37 | } 38 | 39 | private: 40 | mutable std::mutex m_lock; 41 | mutable boost::uuids::random_generator m_generator; 42 | }; 43 | 44 | 45 | UuidGenerator::UuidGenerator() 46 | : m_impl{new Impl} 47 | { 48 | } 49 | 50 | UuidGenerator::~UuidGenerator() 51 | { 52 | } 53 | 54 | std::string UuidGenerator::Generate() const 55 | { 56 | return m_impl->Generate(); 57 | } 58 | 59 | } // namespace Common 60 | } // namespace Mif 61 | -------------------------------------------------------------------------------- /src/mif/net/clients/frame_writer.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // STD 9 | #include 10 | #include 11 | #include 12 | 13 | // BOOST 14 | #include 15 | 16 | // MIF 17 | #include "mif/net/clients/frame_writer.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Net 22 | { 23 | namespace Clients 24 | { 25 | 26 | FrameWriter::FrameWriter(std::weak_ptr control, std::weak_ptr publisher) 27 | : Client{control, publisher} 28 | { 29 | } 30 | 31 | void FrameWriter::ProcessData(Common::Buffer buffer) 32 | { 33 | auto frameBytes = static_cast(buffer.size()); 34 | boost::endian::native_to_big_inplace(frameBytes); 35 | Common::Buffer frame; 36 | frame.reserve(buffer.size() + sizeof(frameBytes)); 37 | std::copy(reinterpret_cast(&frameBytes), 38 | reinterpret_cast(&frameBytes) + sizeof(frameBytes), 39 | std::back_inserter(frame)); 40 | frame.insert(std::end(frame), std::begin(buffer), std::end(buffer)); 41 | Post(std::move(frame)); 42 | } 43 | 44 | } // namespace Clients 45 | } // namespace Net 46 | } // namespace Mif 47 | -------------------------------------------------------------------------------- /include/mif/remote/predefined/protocol/archived_frame.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_REMOTE_PREDEFINED_PROTOCOL_ARCHIVED_FRAME_H__ 9 | #define __MIF_REMOTE_PREDEFINED_PROTOCOL_ARCHIVED_FRAME_H__ 10 | 11 | // MIF 12 | #include "mif/net/clients_chain.h" 13 | #include "mif/net/clients/parallel_handler.h" 14 | #include "mif/net/clients/frame_reader.h" 15 | #include "mif/net/clients/frame_writer.h" 16 | #include "mif/net/clients/gzip_compressor.h" 17 | #include "mif/net/clients/gzip_decompressor.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Remote 22 | { 23 | namespace Predefined 24 | { 25 | namespace Protocol 26 | { 27 | 28 | template 29 | using ArchivedFrame = Net::ClientsChain 30 | < 31 | Net::Clients::FrameReader, 32 | Net::Clients::ParallelHandler, 33 | Net::Clients::GZipDecompressor, 34 | TClient, 35 | Net::Clients::GZipCompressor, 36 | Net::Clients::FrameWriter 37 | >; 38 | 39 | } // namespace Protocol 40 | } // namespace Predefined 41 | } // namespace Remote 42 | } // namespace Mif 43 | 44 | #endif // !__MIF_REMOTE_PREDEFINED_PROTOCOL_ARCHIVED_FRAME_H__ 45 | -------------------------------------------------------------------------------- /include/mif/application/net_base_application.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_APPLICATION_NET_BASE_APPLICATION_H__ 9 | #define __MIF_APPLICATION_NET_BASE_APPLICATION_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | // MIF 17 | #include "mif/application/application.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Application 22 | { 23 | 24 | class NetBaseApplication 25 | : public Application 26 | { 27 | public: 28 | NetBaseApplication(int argc, char const **argv); 29 | 30 | protected: 31 | virtual void OnInit(); 32 | virtual void OnDone(); 33 | 34 | std::string GetHost() const; 35 | std::string GetPort() const; 36 | std::uint16_t GetWorkers() const; 37 | std::chrono::microseconds GetTimeout() const; 38 | std::string GetConfigBranch() const; 39 | 40 | private: 41 | std::string m_host; 42 | std::string m_port; 43 | std::uint16_t m_workers = 0; 44 | std::uint64_t m_timeout = 0; 45 | 46 | // Application 47 | virtual void OnStart() override final; 48 | virtual void OnStop() override final; 49 | }; 50 | 51 | } // namespace Application 52 | } // namespace Mif 53 | 54 | #endif // !__MIF_APPLICATION_NET_BASE_APPLICATION_H__ 55 | -------------------------------------------------------------------------------- /include/mif/common/log.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 10.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_COMMON_LOG_H__ 9 | #define __MIF_COMMON_LOG_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | #define MIF_LOG(level_) Logger(::Mif::Common::Log::Level :: level_ ) 16 | 17 | namespace Mif 18 | { 19 | namespace Common 20 | { 21 | 22 | class Log final 23 | { 24 | public: 25 | enum Level 26 | { 27 | Fatal, 28 | Error, 29 | Warning, 30 | Info, 31 | Trace 32 | }; 33 | 34 | Log(Log &&) = default; 35 | Log& operator = (Log &&) = default; 36 | Log(Log const &) = delete; 37 | Log& operator = (Log const &) = delete; 38 | 39 | ~Log() noexcept; 40 | 41 | friend Log Logger(Level const &level); 42 | 43 | template 44 | Log& operator << (T && data) 45 | { 46 | m_stream << std::forward(data); 47 | return *this; 48 | } 49 | 50 | private: 51 | class Impl; 52 | Impl &m_impl; 53 | Level m_level; 54 | std::stringstream m_stream; 55 | 56 | Log(Level const &level); 57 | }; 58 | 59 | } // namespace Common 60 | } // namespace Mif 61 | 62 | #endif // !__MIF_COMMON_LOG_H__ 63 | -------------------------------------------------------------------------------- /include/mif/net/http/converter/content/plain_text.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_CONVERTER_CONTENT_PLAIN_TEXT_H__ 9 | #define __MIF_NET_HTTP_CONVERTER_CONTENT_PLAIN_TEXT_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/common/types.h" 17 | #include "mif/net/http/converter/url/param.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Net 22 | { 23 | namespace Http 24 | { 25 | namespace Converter 26 | { 27 | namespace Content 28 | { 29 | 30 | struct PlainText final 31 | { 32 | template 33 | static T Convert(Common::Buffer const &buffer) 34 | { 35 | if (buffer.empty()) 36 | throw std::invalid_argument{"[Mif::Net::Http::Converter::Content::PlainText] No content."}; 37 | return Converter::Url::Param::template Convert(std::string{std::begin(buffer), std::end(buffer)}); 38 | } 39 | }; 40 | 41 | } // namespace Content 42 | } // namespace Converter 43 | } // namespace Http 44 | } // namespace Net 45 | } // namespace Mif 46 | 47 | 48 | #endif // !__MIF_NET_HTTP_CONVERTER_CONTENT_PLAIN_TEXT_H__ 49 | -------------------------------------------------------------------------------- /examples/http/client/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | // THIS 15 | #include "common/client.h" 16 | #include "common/id/service.h" 17 | #include "common/ps/iadmin.h" 18 | 19 | class Application 20 | : public Mif::Application::NetBaseApplication 21 | { 22 | public: 23 | using NetBaseApplication::NetBaseApplication; 24 | 25 | private: 26 | // Mif.Application.Application 27 | virtual void OnInit() override final 28 | { 29 | auto clientFactory = Service::Ipc::MakeClientFactory(GetTimeout()); 30 | 31 | Mif::Net::Http::Clients clients(clientFactory); 32 | 33 | auto proxy = std::static_pointer_cast(clients.RunClient( 34 | GetHost(), GetPort(), "/admin")); 35 | 36 | auto client = proxy->GetClientItem(); 37 | 38 | auto service = client->CreateService(Service::Id::Service); 39 | 40 | MIF_LOG(Info) << "Set new document title and body."; 41 | 42 | service->SetTitle("Client title"); 43 | service->SetBody("Client body"); 44 | 45 | MIF_LOG(Info) << "Page preview: \n" << service->GetPage(); 46 | } 47 | }; 48 | 49 | int main(int argc, char const **argv) 50 | { 51 | return Mif::Application::Run(argc, argv); 52 | } 53 | -------------------------------------------------------------------------------- /src/mif/db/postgresql/detail/statement.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_DB_POSTGRESQL_DETAIL_STATEMENT_H__ 9 | #define __MIF_DB_POSTGRESQL_DETAIL_STATEMENT_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // LIBPR 16 | #include 17 | 18 | // MIF 19 | #include "mif/db/istatement.h" 20 | #include "mif/service/iservice.h" 21 | 22 | namespace Mif 23 | { 24 | namespace Db 25 | { 26 | namespace PostgreSql 27 | { 28 | namespace Detail 29 | { 30 | 31 | class Statement 32 | : public Service::Inherit 33 | { 34 | public: 35 | using ResultPtr = std::unique_ptr; 36 | 37 | Statement(PGconn *connection, Service::IService *holder, std::string const &query); 38 | 39 | virtual ~Statement(); 40 | 41 | private: 42 | PGconn *m_connection; 43 | Service::IServicePtr m_holder; 44 | std::string m_name; 45 | 46 | // IStatement 47 | virtual IRecordsetPtr Execute(Parameters const ¶meters) override final; 48 | }; 49 | 50 | } // namespace Detail 51 | } // namespace PostgreSql 52 | } // namespace Db 53 | } // namespace Mif 54 | 55 | #endif // !__MIF_DB_POSTGRESQL_DETAIL_STATEMENT_H__ 56 | -------------------------------------------------------------------------------- /include/mif/service/root_locator.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_SERVICE_ROOT_LOCATOR_H__ 9 | #define __MIF_SERVICE_ROOT_LOCATOR_H__ 10 | 11 | // MIF 12 | #include "mif/service/create.h" 13 | #include "mif/service/ilocator.h" 14 | #include "mif/service/id/service.h" 15 | 16 | namespace Mif 17 | { 18 | namespace Service 19 | { 20 | namespace Detail 21 | { 22 | 23 | template 24 | class RootLocator final 25 | { 26 | public: 27 | static ILocatorPtr Get() 28 | { 29 | return m_instance.m_locator; 30 | } 31 | 32 | private: 33 | static RootLocator m_instance; 34 | ILocatorPtr m_locator{Create()}; 35 | 36 | RootLocator() = default; 37 | 38 | RootLocator(RootLocator const &) = delete; 39 | RootLocator& operator = (RootLocator const &) = delete; 40 | RootLocator(RootLocator &&) = delete; 41 | RootLocator& operator = (RootLocator &&) = delete; 42 | }; 43 | 44 | template 45 | RootLocator RootLocator::m_instance; 46 | 47 | } // namespace Detail 48 | 49 | using RootLocator = Detail::RootLocator; 50 | 51 | } // namespace Service 52 | } // namespace Mif 53 | 54 | #endif // !__MIF_SERVICE_ROOT_LOCATOR_H__ 55 | -------------------------------------------------------------------------------- /examples/microservices/service/src/data/responses.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 08.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MICROSERVICES_SERVICE_DATA_RESPONSES_H__ 9 | #define __MICROSERVICES_SERVICE_DATA_RESPONSES_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | // COMMON 17 | #include "common/data/data.h" 18 | 19 | namespace Service 20 | { 21 | namespace Data 22 | { 23 | namespace Response 24 | { 25 | 26 | struct Status 27 | { 28 | std::uint32_t code = 0; 29 | std::string message; 30 | }; 31 | 32 | struct Info 33 | { 34 | std::string timestamp; 35 | std::string node; 36 | Status status; 37 | }; 38 | 39 | struct Void 40 | { 41 | Info meta; 42 | }; 43 | 44 | struct Id 45 | { 46 | Info meta; 47 | Common::Data::ID data; 48 | }; 49 | 50 | struct Employee 51 | { 52 | Info meta; 53 | Common::Data::Employee data; 54 | }; 55 | 56 | struct Employees 57 | { 58 | Info meta; 59 | Common::Data::Employees data; 60 | }; 61 | 62 | } // namespace Response 63 | } // namespace Data 64 | } // namespace Service 65 | 66 | #endif // !__MICROSERVICES_SERVICE_DATA_RESPONSES_H__ 67 | -------------------------------------------------------------------------------- /examples/http/server/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | #include 11 | #include 12 | 13 | // COMMON 14 | #include "common/client.h" 15 | #include "common/id/service.h" 16 | #include "common/ps/iadmin.h" 17 | 18 | class Application 19 | : public Mif::Application::HttpServer 20 | { 21 | public: 22 | using HttpServer::HttpServer; 23 | 24 | private: 25 | // Mif.Application.HttpService 26 | virtual void Init(Mif::Net::Http::ServerHandlers &handlers) override final 27 | { 28 | std::string const adminLocation = "/admin"; 29 | std::string const viewLocation = "/view"; 30 | 31 | auto service = Mif::Service::Create(viewLocation); 32 | auto webService = Mif::Service::Cast(service); 33 | 34 | auto factory = Mif::Service::Make(); 35 | factory->AddInstance(Service::Id::Service, service); 36 | 37 | std::chrono::microseconds const timeout{10 * 1000 * 1000}; 38 | 39 | auto clientFactory = Service::Ipc::MakeClientFactory(timeout, factory); 40 | 41 | handlers.emplace(adminLocation, Mif::Net::Http::MakeServlet(clientFactory)); 42 | handlers.emplace(viewLocation, Mif::Net::Http::MakeWebService(webService)); 43 | } 44 | }; 45 | 46 | int main(int argc, char const **argv) 47 | { 48 | return Mif::Application::Run(argc, argv); 49 | } 50 | -------------------------------------------------------------------------------- /include/mif/application/http_server.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_APPLICATION_HTTP_SERVER_H__ 9 | #define __MIF_APPLICATION_HTTP_SERVER_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/application/net_base_application.h" 17 | #include "mif/net/http/server.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Application 22 | { 23 | 24 | class HttpServer 25 | : public NetBaseApplication 26 | { 27 | public: 28 | HttpServer(int argc, char const **argv, 29 | Net::Http::Methods const &methods = { 30 | Net::Http::Method::Type::Get, 31 | Net::Http::Method::Type::Post 32 | } 33 | ); 34 | 35 | protected: 36 | virtual void Init(Net::Http::ServerHandlers &handlers); 37 | virtual void Done(); 38 | 39 | private: 40 | std::size_t m_headersLimit; 41 | std::size_t m_bodyLimit; 42 | std::size_t m_chunkSize; 43 | std::size_t m_pipelineLimit; 44 | 45 | Net::Http::Methods m_methods; 46 | std::unique_ptr m_server; 47 | 48 | // NetBaseApplication 49 | virtual void OnInit() override final; 50 | virtual void OnDone() override final; 51 | }; 52 | 53 | } // namespace Application 54 | } // namespace Mif 55 | 56 | #endif // !__MIF_APPLICATION_HTTP_SERVER_H__ 57 | -------------------------------------------------------------------------------- /examples/http/common/include/common/client.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 02.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __HTTP_COMMON_CLIENT_H__ 9 | #define __HTTP_COMMON_CLIENT_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | // MIF 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace Service 26 | { 27 | namespace Ipc 28 | { 29 | 30 | using PSClient = Mif::Remote::PSClient; 31 | 32 | namespace Detail 33 | { 34 | 35 | using ProtocolChain = Mif::Net::ClientsChain; 36 | using ClientFactory = Mif::Net::ClientFactory; 37 | 38 | } // namespace Detail 39 | 40 | using ClientsChain = Detail::ProtocolChain; 41 | 42 | inline Mif::Net::IClientFactoryPtr MakeClientFactory(std::chrono::microseconds const &timeout, 43 | Mif::Service::IFactoryPtr factory = Mif::Service::Make()) 44 | { 45 | return std::make_shared 46 | ( 47 | Mif::Common::MakeCreator(timeout, factory) 48 | ); 49 | } 50 | 51 | } // namespace Ipc 52 | } // namespace Service 53 | 54 | #endif // !__HTTP_COMMON_CLIENT_H__ 55 | -------------------------------------------------------------------------------- /include/mif/net/http/serializer/plain_text.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_SERIALIZER_PLAIN_TEXT_H__ 9 | #define __MIF_NET_HTTP_SERIALIZER_PLAIN_TEXT_H__ 10 | 11 | // BOOST 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace Mif 18 | { 19 | namespace Net 20 | { 21 | namespace Http 22 | { 23 | namespace Serializer 24 | { 25 | 26 | struct PlainText final 27 | { 28 | static constexpr char const* GetContentType() 29 | { 30 | return "text/html; charset=UTF-8"; 31 | } 32 | 33 | template 34 | static Common::Buffer Serialize(T const &data) 35 | { 36 | Common::Buffer buffer; 37 | 38 | { 39 | boost::iostreams::filtering_ostream stream{boost::iostreams::back_inserter(buffer)}; 40 | stream << data; 41 | stream.flush(); 42 | } 43 | 44 | return buffer; 45 | } 46 | }; 47 | 48 | } // namespace Serializer 49 | } // namespace Http 50 | } // namespace Net 51 | } // namespace Mif 52 | 53 | 54 | #endif // !__MIF_NET_HTTP_SERIALIZER_PLAIN_TEXT_H__ 55 | -------------------------------------------------------------------------------- /include/mif/net/http/serializer/xml.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_SERIALIZER_XML_H__ 9 | #define __MIF_NET_HTTP_SERIALIZER_XML_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // MIF 15 | #include "mif/net/http/detail/content_tags.h" 16 | #include "mif/reflection/reflection.h" 17 | #include "mif/serialization/xml.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Net 22 | { 23 | namespace Http 24 | { 25 | namespace Serializer 26 | { 27 | 28 | struct Xml final 29 | { 30 | static constexpr char const* GetContentType() 31 | { 32 | return "text/xml; charset=UTF-8"; 33 | } 34 | 35 | template 36 | static typename std::enable_if(), Common::Buffer>::type Serialize(T const &data) 37 | { 38 | return Serialization::Xml::Serialize(data); 39 | } 40 | 41 | template 42 | static typename std::enable_if(), Common::Buffer>::type Serialize(T const &data) 43 | { 44 | return Serialization::Xml::Serialize(data, Detail::Tag::Document::Value); 45 | } 46 | }; 47 | 48 | } // namespace Serializer 49 | } // namespace Http 50 | } // namespace Net 51 | } // namespace Mif 52 | 53 | 54 | #endif // !__MIF_NET_HTTP_SERIALIZER_XML_H__ 55 | -------------------------------------------------------------------------------- /include/mif/application/tcp_service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_APPLICATION_TCP_SERVICE_H__ 9 | #define __MIF_APPLICATION_TCP_SERVICE_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | // MIF 18 | #include "mif/application/net_base_application.h" 19 | #include "mif/service/factory.h" 20 | #include "mif/net/tcp/server.h" 21 | #include "mif/remote/predefined/utility.h" 22 | 23 | namespace Mif 24 | { 25 | namespace Application 26 | { 27 | 28 | class TcpService 29 | : public NetBaseApplication 30 | { 31 | public: 32 | using ClientFactory = std::function< 33 | Net::IClientFactoryPtr (std::uint16_t /*workers*/, 34 | std::chrono::microseconds const & /*timeout*/, 35 | Service::FactoryPtr /*factory*/) 36 | >; 37 | 38 | TcpService(int argc, char const **argv, 39 | ClientFactory const &clientFactory = Remote::Predefined::MakeClientFactory<>); 40 | 41 | protected: 42 | virtual void Init(Service::FactoryPtr factory); 43 | virtual void Done(); 44 | 45 | private: 46 | ClientFactory m_clientFactory; 47 | std::unique_ptr m_server; 48 | 49 | // NetBaseApplication 50 | virtual void OnInit() override final; 51 | virtual void OnDone() override final; 52 | }; 53 | 54 | } // namespace Application 55 | } // namespace Mif 56 | 57 | #endif // !__MIF_APPLICATION_TCP_SERVICE_H__ 58 | -------------------------------------------------------------------------------- /examples/visitor/client/src/main.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 02.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | #include 11 | 12 | // COMMON 13 | #include "common/id/service.h" 14 | #include "common/ps/iface.h" 15 | 16 | namespace Service 17 | { 18 | namespace Detail 19 | { 20 | namespace 21 | { 22 | 23 | class MessageVisitor 24 | : public Mif::Service::Inherit 25 | { 26 | private: 27 | // IMessageVisitor 28 | virtual void Visit(IMessagePtr message) override final 29 | { 30 | if (!message) 31 | throw std::invalid_argument{"Empty message pointer."}; 32 | 33 | MIF_LOG(Info) << "Message: " << message->GetText(); 34 | } 35 | }; 36 | 37 | } // namespace 38 | } // namespace Detail 39 | } // namespace Service 40 | 41 | class Application 42 | : public Mif::Application::TcpServiceClient 43 | { 44 | public: 45 | using TcpServiceClient::TcpServiceClient; 46 | 47 | private: 48 | // Mif.Application.TcpServiceClient 49 | virtual void Init(Mif::Service::IFactoryPtr factory) override final 50 | { 51 | auto service = factory->Create(Service::Id::Service); 52 | 53 | auto visitor = Mif::Service::Make(); 54 | service->Accept(visitor); 55 | } 56 | }; 57 | 58 | int main(int argc, char const **argv) 59 | { 60 | return Mif::Application::Run(argc, argv); 61 | } 62 | -------------------------------------------------------------------------------- /include/mif/net/http/converter/content/raw.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 02.2018 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_CONVERTER_CONTENT_RAW_H__ 9 | #define __MIF_NET_HTTP_CONVERTER_CONTENT_RAW_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/common/types.h" 17 | #include "mif/serialization/traits.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Net 22 | { 23 | namespace Http 24 | { 25 | namespace Converter 26 | { 27 | namespace Content 28 | { 29 | 30 | struct Raw final 31 | { 32 | template 33 | static typename std::enable_if 34 | < 35 | Serialization::Traits::IsIterable() || 36 | std::is_same::value, 37 | T 38 | >::type 39 | Convert(Common::Buffer const &buffer) 40 | { 41 | if (buffer.empty()) 42 | throw std::invalid_argument{"[Mif::Net::Http::Converter::Content::Raw] No content."}; 43 | return {std::begin(buffer), std::end(buffer)}; 44 | } 45 | }; 46 | 47 | } // namespace Content 48 | } // namespace Converter 49 | } // namespace Http 50 | } // namespace Net 51 | } // namespace Mif 52 | 53 | #endif // !__MIF_NET_HTTP_CONVERTER_CONTENT_RAW_H__ 54 | -------------------------------------------------------------------------------- /src/mif/net/clients/gzip_compressor.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // STD 9 | #include 10 | 11 | // BOOST 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | // MIF 20 | #include "mif/net/clients/gzip_compressor.h" 21 | 22 | namespace Mif 23 | { 24 | namespace Net 25 | { 26 | namespace Clients 27 | { 28 | 29 | GZipCompressor::GZipCompressor(std::weak_ptr control, std::weak_ptr publisher) 30 | : Client(control, publisher) 31 | { 32 | } 33 | 34 | void GZipCompressor::ProcessData(Common::Buffer buffer) 35 | { 36 | Common::Buffer result; 37 | 38 | { 39 | using SourceType = boost::iostreams::basic_array_source; 40 | SourceType source{buffer.data(), buffer.size()}; 41 | boost::iostreams::stream iStream{source}; 42 | 43 | boost::iostreams::filtering_ostream oStream; 44 | oStream.push(boost::iostreams::gzip_compressor{}); 45 | oStream.push(boost::iostreams::back_inserter(result)); 46 | 47 | boost::iostreams::copy(iStream, oStream); 48 | } 49 | 50 | Post(std::move(result)); 51 | } 52 | 53 | } // namespace Clients 54 | } // namespace Net 55 | } // namespace Mif 56 | -------------------------------------------------------------------------------- /src/mif/net/clients/gzip_decompressor.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // STD 9 | #include 10 | 11 | // BOOST 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | // MIF 20 | #include "mif/net/clients/gzip_decompressor.h" 21 | 22 | namespace Mif 23 | { 24 | namespace Net 25 | { 26 | namespace Clients 27 | { 28 | 29 | GZipDecompressor::GZipDecompressor(std::weak_ptr control, std::weak_ptr publisher) 30 | : Client(control, publisher) 31 | { 32 | } 33 | 34 | void GZipDecompressor::ProcessData(Common::Buffer buffer) 35 | { 36 | Common::Buffer result; 37 | 38 | { 39 | using SourceType = boost::iostreams::basic_array_source; 40 | SourceType source{buffer.data(), buffer.size()}; 41 | boost::iostreams::stream iStream{source}; 42 | 43 | boost::iostreams::filtering_ostream oStream; 44 | oStream.push(boost::iostreams::gzip_decompressor{}); 45 | oStream.push(boost::iostreams::back_inserter(result)); 46 | 47 | boost::iostreams::copy(iStream, oStream); 48 | } 49 | 50 | Post(std::move(result)); 51 | } 52 | 53 | } // namespace Clients 54 | } // namespace Net 55 | } // namespace Mif 56 | -------------------------------------------------------------------------------- /examples/http_crud/src/employee_service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __HTTP_CRUD_EMPLOYEE_SERVICE_H__ 9 | #define __HTTP_CRUD_EMPLOYEE_SERVICE_H__ 10 | 11 | // MIF 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "mif/net/http/serializer/json.h" 17 | #include 18 | 19 | // THIS 20 | #include "data/data.h" 21 | 22 | namespace Service 23 | { 24 | 25 | class EmployeeService 26 | : public Mif::Net::Http::WebService 27 | { 28 | public: 29 | EmployeeService(std::string const &pathPrefix, Mif::Application::IConfigPtr dbConfig); 30 | 31 | private: 32 | using ResultSerializer = Result; 33 | template 34 | using InputContent = Content; 35 | 36 | Mif::Db::IConnectionPoolPtr m_connections; 37 | 38 | Data::Response::Info CreateMeta(std::uint32_t code = 0, std::string const &message = {}) const; 39 | std::string FormatExceptionMessage(std::string const &message) const; 40 | 41 | // Web hadlers 42 | ResultSerializer Create(InputContent const &employee); 43 | ResultSerializer Read(Prm const &id); 44 | ResultSerializer Update(Prm const &id, InputContent const &employee); 45 | ResultSerializer Delete(Prm const &id); 46 | 47 | ResultSerializer List(Prm const &offset, 48 | Prm const &limit); 49 | }; 50 | 51 | } // namespace Service 52 | 53 | #endif // !__HTTP_CRUD_EMPLOYEE_SERVICE_H__ 54 | -------------------------------------------------------------------------------- /src/mif/net/tcp/detail/session.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 09.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_TCP_DETAIL_SESSION_H__ 9 | #define __MIF_NET_TCP_DETAIL_SESSION_H__ 10 | 11 | // STD 12 | #include 13 | 14 | // BOOST 15 | #include 16 | 17 | // MIF 18 | #include "mif/net/iclient_factory.h" 19 | 20 | namespace Mif 21 | { 22 | namespace Net 23 | { 24 | namespace Tcp 25 | { 26 | namespace Detail 27 | { 28 | 29 | class Session final 30 | : public std::enable_shared_from_this 31 | , public IPublisher 32 | , public IControl 33 | { 34 | public: 35 | Session(boost::asio::ip::tcp::socket socket, IClientFactory &factory); 36 | 37 | IClientFactory::ClientPtr Start(); 38 | 39 | private: 40 | boost::asio::ip::tcp::socket m_socket; 41 | IClientFactory &m_factory; 42 | IClientFactory::ClientPtr m_client; 43 | 44 | //---------------------------------------------------------------------------- 45 | // IPublisher 46 | virtual void Publish(Common::Buffer buffer) override; 47 | 48 | //---------------------------------------------------------------------------- 49 | // IControl 50 | virtual void CloseMe() override; 51 | 52 | //---------------------------------------------------------------------------- 53 | void DoRead(); 54 | }; 55 | 56 | } // namespace Detail 57 | } // namespace Tcp 58 | } // namespace Net 59 | } // namespace Mif 60 | 61 | #endif // !__MIF_NET_TCP_DETAIL_SESSION_H__ 62 | -------------------------------------------------------------------------------- /src/mif/net/http/detail/utility.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2016 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_DETAIL_UTILITY_H__ 9 | #define __MIF_NET_HTTP_DETAIL_UTILITY_H__ 10 | 11 | // BOOST 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/net/http/codes.h" 17 | #include "mif/net/http/methods.h" 18 | 19 | namespace Mif 20 | { 21 | namespace Net 22 | { 23 | namespace Http 24 | { 25 | namespace Detail 26 | { 27 | namespace Utility 28 | { 29 | 30 | Method::Type ConvertMethodType(boost::beast::http::verb verb); 31 | boost::beast::http::verb ConvertMethodType(Method::Type method); 32 | 33 | char const* GetReasonString(Code code); 34 | boost::beast::http::status ConvertCode(Code code); 35 | Code ConvertCode(boost::beast::http::status code); 36 | 37 | std::string CreateTimestamp(); 38 | 39 | std::string DecodeUrl(std::string const &url); 40 | std::string EncodeUrl(std::string const &url); 41 | 42 | class Target final 43 | { 44 | public: 45 | Target(std::string const &url); 46 | 47 | std::string const& GetPath() const noexcept; 48 | std::string const& GetQuery() const noexcept; 49 | 50 | private: 51 | std::string m_path; 52 | std::string m_query; 53 | }; 54 | 55 | } // namespace Utility 56 | 57 | } // namespace Detail 58 | } // namespace Http 59 | } // namespace Net 60 | } // namespace Mif 61 | 62 | #endif // !__MIF_NET_HTTP_DETAIL_UTILITY_H__ 63 | -------------------------------------------------------------------------------- /examples/http_crud/src/data/data.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __HTTP_CRUD_DATA_DATA_H__ 9 | #define __HTTP_CRUD_DATA_DATA_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | namespace Service 17 | { 18 | namespace Data 19 | { 20 | 21 | using ID = std::string; 22 | 23 | enum class Position 24 | { 25 | Unknown, 26 | Developer, 27 | Manager 28 | }; 29 | 30 | struct Employee 31 | { 32 | std::string name; 33 | std::string lastName; 34 | std::uint32_t age = 0; 35 | std::string email; 36 | Position position = Position::Unknown; 37 | double rate = 0.0; 38 | }; 39 | 40 | using Employees = std::map; 41 | 42 | namespace Response 43 | { 44 | 45 | struct Status 46 | { 47 | std::uint32_t code = 0; 48 | std::string message; 49 | }; 50 | 51 | struct Info 52 | { 53 | std::string timestamp; 54 | std::string node; 55 | Status status; 56 | }; 57 | 58 | struct Void 59 | { 60 | Info meta; 61 | }; 62 | 63 | struct Id 64 | { 65 | Info meta; 66 | ID data; 67 | }; 68 | 69 | struct Employee 70 | { 71 | Info meta; 72 | Data::Employee data; 73 | }; 74 | 75 | struct Employees 76 | { 77 | Info meta; 78 | Data::Employees data; 79 | }; 80 | 81 | } // namespace Response 82 | } // namespace Data 83 | } // namespace Service 84 | 85 | #endif // !__HTTP_CRUD_DATA_DATA_H__ 86 | -------------------------------------------------------------------------------- /include/mif/net/http/make_web_service.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 03.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_MAKE_WEB_SERVICE_H__ 9 | #define __MIF_NET_HTTP_MAKE_WEB_SERVICE_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | // MIF 17 | #include "mif/net/http/request_handler.h" 18 | #include "mif/net/http/iweb_service.h" 19 | #include "mif/service/create.h" 20 | #include "mif/service/make.h" 21 | 22 | namespace Mif 23 | { 24 | namespace Net 25 | { 26 | namespace Http 27 | { 28 | 29 | inline ServerHandler MakeWebService(IWebServicePtr service) 30 | { 31 | auto handler = std::bind(&IWebService::OnRequest, service, std::placeholders::_1, std::placeholders::_2); 32 | return handler; 33 | } 34 | 35 | template 36 | inline typename std::enable_if::value, ServerHandler>::type 37 | MakeWebService(TArgs && ... args) 38 | { 39 | auto service = Service::Make(std::forward(args) ... ); 40 | auto handler = std::bind(&IWebService::OnRequest, service, std::placeholders::_1, std::placeholders::_2); 41 | return handler; 42 | } 43 | 44 | template 45 | inline ServerHandler MakeWebService(TArgs && ... args) 46 | { 47 | auto service = Service::Create(std::forward(args) ... ); 48 | auto handler = std::bind(&IWebService::OnRequest, service, std::placeholders::_1, std::placeholders::_2); 49 | return handler; 50 | } 51 | 52 | } // namespace Http 53 | } // namespace Net 54 | } // namespace Mif 55 | 56 | 57 | #endif // !__MIF_NET_HTTP_MAKE_WEB_SERVICE_H__ 58 | -------------------------------------------------------------------------------- /include/mif/net/http/detail/content.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 01.2018 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_DETAIL_CONTENT_H__ 9 | #define __MIF_NET_HTTP_DETAIL_CONTENT_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/common/types.h" 17 | 18 | namespace Mif 19 | { 20 | namespace Net 21 | { 22 | namespace Http 23 | { 24 | namespace Detail 25 | { 26 | 27 | template 28 | class Content final 29 | { 30 | public: 31 | using ContentType = Content; 32 | using Type = T; 33 | using Converter = TConverter; 34 | 35 | Content() = default; 36 | Content(Content &&) = default; 37 | Content(Content const &) = delete; 38 | 39 | Content(Common::Buffer const &value) 40 | : m_value{value.empty() ? nullptr : 41 | new Type{Converter::template Convert(value)}} 42 | { 43 | } 44 | 45 | explicit operator bool() const noexcept 46 | { 47 | return !!m_value; 48 | } 49 | 50 | Type const& Get() const 51 | { 52 | if (!*this) 53 | throw std::runtime_error{"[Mif::Net::Http::WebService::Content] No content."}; 54 | return *m_value; 55 | } 56 | 57 | private: 58 | std::unique_ptr const m_value; 59 | }; 60 | 61 | } // namespace Detail 62 | } // namespace Http 63 | } // namespace Net 64 | } // namespace Mif 65 | 66 | #endif // !__MIF_NET_HTTP_DETAIL_CONTENT_H__ 67 | -------------------------------------------------------------------------------- /include/mif/application/tcp_service_client.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_APPLICATION_TCP_SERVICE_CLIENT_H__ 9 | #define __MIF_APPLICATION_TCP_SERVICE_CLIENT_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | #include 15 | 16 | // MIF 17 | #include "mif/application/net_base_application.h" 18 | #include "mif/service/ifactory.h" 19 | #include "mif/remote/predefined/utility.h" 20 | 21 | namespace Mif 22 | { 23 | namespace Application 24 | { 25 | 26 | class TcpServiceClient 27 | : public NetBaseApplication 28 | { 29 | public: 30 | using ClientFactory = std::function< 31 | Net::IClientFactoryPtr (std::uint16_t /*workers*/, 32 | std::chrono::microseconds const & /*timeout*/, 33 | Service::FactoryPtr /*factory*/) 34 | >; 35 | 36 | using ServiceCreator = std::function< 37 | Service::IServicePtr (Net::IClientFactory::ClientPtr /*client*/, 38 | Service::ServiceId /*service id*/) 39 | >; 40 | 41 | TcpServiceClient(int argc, char const **argv, 42 | ClientFactory const &clientFactory = Remote::Predefined::MakeClientFactory<>, 43 | ServiceCreator const &serviceCreator = Remote::Predefined::CreateService<>); 44 | 45 | protected: 46 | virtual void Init(Service::IFactoryPtr factory); 47 | virtual void Done(); 48 | 49 | private: 50 | ClientFactory m_clientFactory; 51 | ServiceCreator m_serviceCreator; 52 | 53 | // NetBaseApplication 54 | virtual void OnInit() override final; 55 | virtual void OnDone() override final; 56 | }; 57 | 58 | } // namespace Application 59 | } // namespace Mif 60 | 61 | #endif // !__MIF_APPLICATION_TCP_SERVICE_CLIENT_H__ 62 | -------------------------------------------------------------------------------- /include/mif/net/http/converter/content/xml.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 12.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | #ifndef __MIF_NET_HTTP_CONVERTER_CONTENT_XML_H__ 9 | #define __MIF_NET_HTTP_CONVERTER_CONTENT_XML_H__ 10 | 11 | // STD 12 | #include 13 | #include 14 | 15 | // MIF 16 | #include "mif/net/http/detail/content_tags.h" 17 | #include "mif/reflection/reflection.h" 18 | #include "mif/serialization/xml.h" 19 | 20 | namespace Mif 21 | { 22 | namespace Net 23 | { 24 | namespace Http 25 | { 26 | namespace Converter 27 | { 28 | namespace Content 29 | { 30 | 31 | struct Xml final 32 | { 33 | template 34 | static typename std::enable_if(), T>::type Convert(Common::Buffer const &buffer) 35 | { 36 | if (buffer.empty()) 37 | throw std::invalid_argument{"[Mif::Net::Http::Converter::Content::Xml] No content."}; 38 | return Serialization::Xml::Deserialize(buffer); 39 | } 40 | 41 | template 42 | static typename std::enable_if(), T>::type Convert(Common::Buffer const &buffer) 43 | { 44 | if (buffer.empty()) 45 | throw std::invalid_argument{"[Mif::Net::Http::XmlContentParamConverter] No content."}; 46 | return Serialization::Xml::Deserialize(buffer, Detail::Tag::Document::Value); 47 | } 48 | }; 49 | 50 | } // namespace Content 51 | } // namespace Converter 52 | } // namespace Http 53 | } // namespace Net 54 | } // namespace Mif 55 | 56 | #endif // !__MIF_NET_HTTP_CONVERTER_CONTENT_XML_H__ 57 | -------------------------------------------------------------------------------- /src/mif/application/tcp_service.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 07.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include "mif/application/tcp_service.h" 10 | #include "mif/common/log.h" 11 | #include "mif/common/unused.h" 12 | #include "mif/service/make.h" 13 | 14 | namespace Mif 15 | { 16 | namespace Application 17 | { 18 | 19 | TcpService::TcpService(int argc, char const **argv, ClientFactory const &clientFactory) 20 | : NetBaseApplication{argc, argv} 21 | , m_clientFactory{clientFactory} 22 | { 23 | } 24 | 25 | void TcpService::Init(Service::FactoryPtr factory) 26 | { 27 | Common::Unused(factory); 28 | } 29 | 30 | void TcpService::Done() 31 | { 32 | } 33 | 34 | void TcpService::OnInit() 35 | { 36 | auto const host = GetHost(); 37 | auto const port = GetPort(); 38 | auto const workers = GetWorkers(); 39 | auto const timeout = GetTimeout(); 40 | 41 | MIF_LOG(Info) << "Starting server on " << host << ":" << port; 42 | 43 | auto factory = Service::Make(); 44 | 45 | Init(factory); 46 | 47 | auto clientFactory = m_clientFactory(workers, timeout, factory); 48 | 49 | m_server.reset(new Net::Tcp::Server{host, port, clientFactory}); 50 | 51 | MIF_LOG(Info) << "Server is successfully started."; 52 | } 53 | 54 | void TcpService::OnDone() 55 | { 56 | MIF_LOG(Info) << "Stopping server ..."; 57 | 58 | m_server.reset(); 59 | 60 | try 61 | { 62 | Done(); 63 | } 64 | catch (std::exception const &e) 65 | { 66 | MIF_LOG(Warning) << "[Mif::Application::TcpService::OnDone] " 67 | << "Failed to call \"Done\". Error: " << e.what(); 68 | } 69 | 70 | MIF_LOG(Info) << "Server is successfully stopped."; 71 | } 72 | 73 | } // namespace Application 74 | } // namespace Mif 75 | -------------------------------------------------------------------------------- /examples/visitor/server/src/service.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------- 2 | // MetaInfo Framework (MIF) 3 | // https://github.com/tdv/mif 4 | // Created: 02.2017 5 | // Copyright (C) 2016-2024 tdv 6 | //------------------------------------------------------------------- 7 | 8 | // MIF 9 | #include 10 | #include 11 | #include 12 | 13 | // COMMON 14 | #include "common/id/service.h" 15 | #include "common/interface/iface.h" 16 | 17 | namespace Service 18 | { 19 | namespace Detail 20 | { 21 | namespace 22 | { 23 | 24 | class Message 25 | : public Mif::Service::Inherit 26 | { 27 | public: 28 | Message(std::string const &message) 29 | : m_message{message} 30 | { 31 | } 32 | 33 | private: 34 | std::string m_message; 35 | 36 | // IMessage 37 | virtual std::string GetText() const override final 38 | { 39 | return m_message; 40 | } 41 | }; 42 | 43 | class Service 44 | : public Mif::Service::Inherit 45 | { 46 | public: 47 | Service() 48 | { 49 | MIF_LOG(Info) << "Service"; 50 | } 51 | 52 | ~Service() 53 | { 54 | MIF_LOG(Info) << "~Service"; 55 | } 56 | 57 | private: 58 | // IViewer 59 | virtual void Accept(IMessageVisitorPtr visitor) override final 60 | { 61 | if (!visitor) 62 | throw std::invalid_argument{"Empty pointer on IMessageVisitor"}; 63 | 64 | MIF_LOG(Info) << "Accept"; 65 | 66 | auto message = Mif::Service::Make("Message from remote service."); 67 | 68 | visitor->Visit(message); 69 | } 70 | 71 | }; 72 | 73 | } // namespace 74 | } // namespace Detail 75 | } // namespace Service 76 | 77 | MIF_SERVICE_CREATOR 78 | ( 79 | ::Service::Id::Service, 80 | ::Service::Detail::Service 81 | ) 82 | --------------------------------------------------------------------------------