commit 49af441d48753514dde50d45817dc1429709c3d6 Author: King_DuckZ Date: Sat Jun 20 00:08:04 2020 +0200 Proof of concept invoking remote ping call diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c9082c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.clangd +tags +compile_commands.json diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1846834 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "subprojects/restc-cpp"] + path = subprojects/restc-cpp/restc-cpp + url = https://github.com/jgaa/restc-cpp.git +[submodule "subprojects/date"] + path = subprojects/date + url = https://github.com/HowardHinnant/date.git diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..9833917 --- /dev/null +++ b/main.cpp @@ -0,0 +1,66 @@ +#define HAS_UNCAUGHT_EXCEPTIONS 1 + +#include +#include +#include +#include +//#include +#include +#include +#include "date/date.h" + +namespace rc = restc_cpp; +namespace lt = boost::local_time; + +namespace oro { + typedef date::sys_time timestamp_t; + + struct Timestamp { + Timestamp& operator= (const std::string& str) { + std::istringstream iss(str); + date::from_stream(iss, "%FT%T%Ez", ts); + return *this; + } + + timestamp_t ts; + }; + + struct Ping { + Timestamp generation_timestamp; + std::string message; + int version; + }; +} //namespace oro + +BOOST_FUSION_ADAPT_STRUCT( + oro::Ping, + (oro::Timestamp, generation_timestamp) + (std::string, message) + (int, version) +) + +int main() { + using date::operator<<; + + auto rest_client = rc::RestClient::Create(); + oro::Ping ping = rest_client->ProcessWithPromiseT([&](rc::Context& ctx) { + oro::Ping ping; + std::unique_ptr reply = rc::RequestBuilder(ctx) + .Get("https://api.originsro.org/api/v1/ping") + .Header("X-Client", "RESTC_CPP") + .Header("X-Client-Purpose", "Testing") + .Execute(); + + std::cout << "I got X-RateLimit-Limit: " << *reply->GetHeader("X-RateLimit-Limit") << '\n'; + + rc::SerializeFromJson(ping, std::move(reply)); + return ping; + }).get(); + + std::cout << "Response received:\n\ttimestamp: " << ping.generation_timestamp.ts; + std::cout << "\n\tmessage: " << ping.message; + std::cout << "\n\tversion: " << ping.version; + + std::cout << std::endl; + return 0; +} diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..4a510ff --- /dev/null +++ b/meson.build @@ -0,0 +1,23 @@ +project('orotool', 'cpp', + version: '0.1.0', + meson_version: '>=0.49.2', + default_options: ['buildtype=debug', 'cpp_std=gnu++17'], + license: 'GPL3+', +) + +restc_cpp_dep = dependency('restc-cpp', version: '>=0.1.1', + fallback: ['restc-cpp', 'restc_cpp_dep'], + default_options: [ + 'restc_cpp_with_unit_tests=false', + ], +) +boost_dep = dependency('Boost', modules: ['date_time']) + +date_incdir = include_directories('subprojects/date/include') + +executable(meson.project_name(), + 'main.cpp', + install: true, + dependencies: [restc_cpp_dep, boost_dep], + include_directories: date_incdir, +) diff --git a/subprojects/date b/subprojects/date new file mode 160000 index 0000000..a55f1a1 --- /dev/null +++ b/subprojects/date @@ -0,0 +1 @@ +Subproject commit a55f1a103b9d21a0440fde0fb9ea5cf547826af6 diff --git a/subprojects/restc-cpp/include/restc-cpp/meson.build b/subprojects/restc-cpp/include/restc-cpp/meson.build new file mode 100644 index 0000000..263f6df --- /dev/null +++ b/subprojects/restc-cpp/include/restc-cpp/meson.build @@ -0,0 +1,23 @@ +conf = configuration_data() + +cpp = meson.get_compiler('cpp') + +conf.set('RESTC_CPP_WITH_UNIT_TESTS', get_option('restc_cpp_with_unit_tests') ? 1 : false) +conf.set('RESTC_CPP_WITH_TLS', get_option('restc_cpp_with_tls') ? 1 : false) +conf.set('RESTC_CPP_LOG_WITH_BOOST_LOG', get_option('restc_cpp_log_with_boost_log') ? 1 : false) +conf.set('RESTC_CPP_WITH_ZLIB', get_option('restc_cpp_with_zlib') ? 1 : false) +conf.set('RESTC_CPP_HAVE_BOOST_TYPEINDEX', cpp.has_header('boost/type_index.hpp') ? 1 : false) +conf.set('RESTC_CPP_LOG_JSON_SERIALIZATION', get_option('restc_cpp_log_json_serialization') ? 1 : false) +if get_option('cpp_std') == 'gnu++17' or get_option('cpp_std') == 'c++17' + conf.set('RESTC_CPP_USE_CPP17', 1) +else + conf.set('RESTC_CPP_USE_CPP17', false) +endif +conf.set('RESTC_CPP_MAX_INPUT_BUFFER_LENGTH', get_option('restc_cpp_max_input_buffer_length')) + +project_config_file = configure_file( + input: config_template, + output: 'config.h', + configuration: conf, + format: 'cmake', +) diff --git a/subprojects/restc-cpp/meson.build b/subprojects/restc-cpp/meson.build new file mode 100644 index 0000000..adde014 --- /dev/null +++ b/subprojects/restc-cpp/meson.build @@ -0,0 +1,68 @@ +project('restc-cpp', 'cpp', + version: '0.9.2', + meson_version: '>=0.49.2', + default_options: ['cpp_std=gnu++17'], +) + +config_template = files('restc-cpp/config.h.template') +if get_option('restc_cpp_with_zlib') + zipreaderimpl = files('restc-cpp/src/ZipReaderImpl.cpp') +endif +compiler_opts = ['-DBOOST_COROUTINE_NO_DEPRECATION_WARNING=1'] + +thread_dep = dependency('threads') +boost_dep = dependency('boost', + modules: [ + 'system', 'program_options', 'filesystem', 'date_time', + 'context', 'coroutine', 'chrono', 'log' + ] +) + +if not get_option('embedded_restc_cpp') + if get_option('restc_cpp_with_zlib') + zlib_dep = dependency('zlib') + endif + if get_option('restc_cpp_with_tls') + tls_dep = dependency('OpenSSL') + endif +endif + +pvt_incdir = include_directories('restc-cpp/src') +pub_incdir = include_directories('restc-cpp/include', 'include') + +subdir('include/restc-cpp') + +restc_cpp_target = library(meson.project_name(), + 'restc-cpp/src/ChunkedReaderImpl.cpp', + 'restc-cpp/src/ChunkedWriterImpl.cpp', + 'restc-cpp/src/IoReaderImpl.cpp', + 'restc-cpp/src/IoWriterImpl.cpp', + 'restc-cpp/src/PlainReaderImpl.cpp', + 'restc-cpp/src/PlainWriterImpl.cpp', + 'restc-cpp/src/NoBodyReaderImpl.cpp', + 'restc-cpp/src/DataReaderStream.cpp', + 'restc-cpp/src/RestClientImpl.cpp', + 'restc-cpp/src/RequestImpl.cpp', + 'restc-cpp/src/ReplyImpl.cpp', + 'restc-cpp/src/ConnectionPoolImpl.cpp', + 'restc-cpp/src/Url.cpp', + 'restc-cpp/src/RequestBodyStringImpl.cpp', + 'restc-cpp/src/RequestBodyFileImpl.cpp', + 'restc-cpp/src/url_encode.cpp', + zipreaderimpl, + install: true, + include_directories: [pvt_incdir, pub_incdir], + dependencies: [zlib_dep, tls_dep, thread_dep, boost_dep], + cpp_args: compiler_opts, +) + +restc_cpp_dep = declare_dependency( + link_with: restc_cpp_target, + include_directories: pub_incdir, + compile_args: compiler_opts, + dependencies: [tls_dep, thread_dep, boost_dep], +) + +if get_option('restc_cpp_with_unit_tests') + #subdir('tests') +endif diff --git a/subprojects/restc-cpp/meson_options.txt b/subprojects/restc-cpp/meson_options.txt new file mode 100644 index 0000000..2b2a50e --- /dev/null +++ b/subprojects/restc-cpp/meson_options.txt @@ -0,0 +1,7 @@ +option('restc_cpp_max_input_buffer_length', type: 'integer', value: 0x7fffffff) +option('embedded_restc_cpp', type: 'boolean', value: false) +option('restc_cpp_with_unit_tests', type: 'boolean', value: false) +option('restc_cpp_with_tls', type: 'boolean', value: true) +option('restc_cpp_log_with_boost_log', type: 'boolean', value: true) +option('restc_cpp_with_zlib', type: 'boolean', value: true) +option('restc_cpp_log_json_serialization', type: 'boolean', value: false) diff --git a/subprojects/restc-cpp/restc-cpp b/subprojects/restc-cpp/restc-cpp new file mode 160000 index 0000000..c2b893a --- /dev/null +++ b/subprojects/restc-cpp/restc-cpp @@ -0,0 +1 @@ +Subproject commit c2b893a3979c92ab94137203294badc1c26513cd