Add meson options for user agent and script path

This commit is contained in:
King_DuckZ 2022-05-14 19:13:10 +02:00
parent 18e5317baf
commit 1090ea8295
6 changed files with 81 additions and 19 deletions

View File

@ -5,11 +5,19 @@ project('duckticker', 'cpp',
license: 'GPL3+',
)
full_config_dir = get_option('prefix') / get_option('sysconfdir')
compiler_opts = ['-DWRENPP_WITH_NAME_GUESSING']
global_config = configuration_data()
global_config.set_quoted('PROJECT_NAME', meson.project_name())
version_arr = meson.project_version().split('.')
global_config.set('PROJECT_VERSION_MAJOR', version_arr[0])
global_config.set('PROJECT_VERSION_MINOR', version_arr[1])
global_config.set('PROJECT_VERSION_PATCH', version_arr[2])
global_config.set_quoted('SCRIPT_PATH', get_option('prefix') / get_option('script_path') / '')
subdir('src')
#full_config_dir = get_option('prefix') / get_option('sysconfdir')
#if meson.source_root() != full_config_dir
# install_data(sources: meson.project_name() + '.conf', install_dir: full_config_dir)
#endif

3
meson_options.txt Normal file
View File

@ -0,0 +1,3 @@
option('user_agent', type: 'string', value: '')
option('use_default_user_agent', type: 'boolean', value: false)
option('script_path', type: 'string', value: 'duckticker/script')

View File

@ -17,6 +17,7 @@
#include "bitcoinity_ticker_price.hpp"
#include "bitcoinity_reader.hpp"
#include "configure.hpp"
#include <wrenpp/vm_fun.hpp>
#include <wrenpp/callback_manager.hpp>
@ -38,47 +39,46 @@ constexpr std::string_view g_dummy_currency {"EUR"};
constexpr std::string_view g_dummy_exchange {"kraken"};
void quick_ticker_price_bitcoinity_wren (wren::VM& vm) {
using duck::TickerPrice;
using duck::bitcoinity_ticker_price;
using duck::BitcoinityMatchType;
TickerPrice* const tp = wren::make_foreign_object<TickerPrice>(vm, "ticker_price");
*tp = bitcoinity_ticker_price(g_dummy_exchange, g_dummy_currency, BitcoinityMatchType::Any);
}
void ticker_price_bitcoinity_wren (wren::VM& vm) {
using duck::TickerPrice;
using duck::bitcoinity_ticker_price;
using duck::BitcoinityMatchType;
TickerPrice* const tp = wren::make_foreign_object<TickerPrice>(vm, "ticker_price");
*tp = bitcoinity_ticker_price(wren::get<const char*>(vm, 1), wren::get<const char*>(vm, 2), BitcoinityMatchType::Exact);
}
void currency_ticker_price_bitcoinity_wren (wren::VM& vm) {
using duck::TickerPrice;
using duck::bitcoinity_ticker_price;
using duck::BitcoinityMatchType;
TickerPrice* const tp = wren::make_foreign_object<TickerPrice>(vm, "ticker_price");
*tp = bitcoinity_ticker_price(g_dummy_exchange, wren::get<const char*>(vm, 1), BitcoinityMatchType::CurrencyOnly);
}
void exchange_ticker_price_bitcoinity_wren (wren::VM& vm) {
using duck::TickerPrice;
using duck::bitcoinity_ticker_price;
using duck::BitcoinityMatchType;
TickerPrice* const tp = wren::make_foreign_object<TickerPrice>(vm, "ticker_price");
*tp = bitcoinity_ticker_price(wren::get<const char*>(vm, 1), g_dummy_currency, BitcoinityMatchType::ExchangeOnly);
}
std::string make_user_agent_string() {
#if defined(DUCKTICKER_DEFAULT_USER_AGENT)
std::string retval {g_program_name};
retval += "/";
retval += g_full_version;
retval += " beast/";
retval += duck::WebsocketReader::BeastVersionString;
#else
std::string retval{g_user_agent};
#endif
return retval;
}
} //unnamed namespace
TickerPrice bitcoinity_ticker_price (std::string_view exchange, std::string_view currency, BitcoinityMatchType match_type) {
static const TickerPrice error_price {0.0, "", ""};
duck::BitcoinityReader bitcoinity{
std::string{duck::WebsocketReader::BeastVersionString} + " websocket-client-coro",
make_user_agent_string(),
exchange,
currency
};

33
src/configure.hpp.in Normal file
View File

@ -0,0 +1,33 @@
/* Copyright 2022, Michele Santullo
* This file is part of duckticker.
*
* Wrenpp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wrenpp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with duckticker. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string_view>
namespace duck {
constexpr std::string_view g_program_name {@PROJECT_NAME@};
constexpr std::string_view g_user_agent {@USER_AGENT@};
constexpr std::string_view g_full_version {"@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@"};
constexpr std::string_view g_script_path {@SCRIPT_PATH@};
constexpr const unsigned short int g_version_major = @PROJECT_VERSION_MAJOR@;
constexpr const unsigned short int g_version_minor = @PROJECT_VERSION_MINOR@;
constexpr const unsigned short int g_version_patch = @PROJECT_VERSION_PATCH@;
#mesondefine DUCKTICKER_DEFAULT_USER_AGENT
} //namespace duck

View File

@ -16,6 +16,7 @@
*/
#include "bitcoinity_ticker_price.hpp"
#include "configure.hpp"
#include <wrenpp/vm_fun.hpp>
#include <wrenpp/def_configuration.hpp>
#include <fstream>
@ -59,7 +60,7 @@ int main() {
duck::register_bitcoinity_to_wren(vm);
std::string main_script = load_string_from_file("script/main.wren");
std::string main_script = load_string_from_file(std::string{duck::g_script_path} + "main.wren");
vm.interpret("main", main_script.c_str());
wren::call<void>(vm, {"main", "the_app"}, "start");

View File

@ -18,6 +18,23 @@ beast_dep = dependency('beast', version: '>=1.79.0',
fallback: ['beast', 'beast_dep'],
)
config = configuration_data()
config.merge_from(global_config)
if get_option('user_agent') == ''
config.set_quoted('USER_AGENT', meson.project_name() + '/' + meson.project_version())
else
config.set_quoted('USER_AGENT', get_option('user_agent'))
endif
if get_option('use_default_user_agent')
config.set('DUCKTICKER_DEFAULT_USER_AGENT', true)
endif
config_file = configure_file(
input: 'configure.hpp.in',
output: 'configure.hpp',
configuration: config
)
executable(meson.project_name(),
'main.cpp',
'nap/http_header_parse.cpp',