mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-31 10:41:08 +00:00
a4f929696490 Merge bitcoin-core/libmultiprocess#224: doc: fix typos f4344ae87da0 Merge bitcoin-core/libmultiprocess#222: test, ci: Fix threadsanitizer errors in mptest 1434642b3804 doc: fix typos 73d22ba2e930 test: Fix tsan race in thread busy test b74e1bba014d ci: Use tsan-instrumented cap'n proto in sanitizers job c332774409ad test: Fix failing exception check in new thread busy test ca3c05d56709 test: Use KJ_LOG instead of std::cout for logging 7eb1da120ab6 ci: Use tsan-instrumented libcxx in sanitizers job ec86e4336e98 Merge bitcoin-core/libmultiprocess#220: Add log levels and advertise them to users via logging callback 515ce93ad349 Logging: Pass LogData struct to logging callback 213574ccc43d Logging: reclassify remaining log messages e4de0412b430 Logging: Break out expensive log messages and classify them as Trace 408874a78fdc Logging: Use new logging macros 67b092d835cd Logging: Disable logging if messsage level is less than the requested level d0a1ba7ebf21 Logging: add log levels to mirror Core's 463a8296d188 Logging: Disable moving or copying Logger 83a2e10c0b03 Logging: Add an EventLoop constructor to allow for user-specified log options 58cf47a7fc8c Merge bitcoin-core/libmultiprocess#221: test default PassField impl handles output parameters db03a663f514 Merge bitcoin-core/libmultiprocess#214: Fix crash on simultaneous IPC calls using the same thread afcc40b0f1e8 Merge bitcoin-core/libmultiprocess#213: util+doc: Clearer errors when attempting to run examples + polished docs 6db669628387 test In|Out parameter 29cf2ada75ea test default PassField impl handles output parameters 1238170f68e8 test: simultaneous IPC calls using same thread eb069ab75d83 Fix crash on simultaneous IPC calls using the same thread ec03a9639ab5 doc: Precision and typos 2b4348193551 doc: Where possible, remove links to ryanofsky/bitcoin/ 286fe469c9c9 util: Add helpful error message when failing to execute file git-subtree-dir: src/ipc/libmultiprocess git-subtree-split: a4f92969649018ca70f949a09148bccfeaecd99a
65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
// Copyright (c) The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <calculator.h>
|
|
#include <init.capnp.h>
|
|
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner) // IWYU pragma: keep
|
|
|
|
#include <charconv>
|
|
#include <cstring>
|
|
#include <fstream>
|
|
#include <functional>
|
|
#include <iostream>
|
|
#include <kj/async.h>
|
|
#include <kj/common.h>
|
|
#include <kj/memory.h>
|
|
#include <memory>
|
|
#include <mp/proxy-io.h>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <system_error>
|
|
#include <utility>
|
|
|
|
class CalculatorImpl : public Calculator
|
|
{
|
|
public:
|
|
CalculatorImpl(std::unique_ptr<Printer> printer) : m_printer(std::move(printer)) {}
|
|
void solveEquation(const std::string& eqn) override { m_printer->print("Wow " + eqn + ", that's a tough one.\n"); }
|
|
std::unique_ptr<Printer> m_printer;
|
|
};
|
|
|
|
class InitImpl : public Init
|
|
{
|
|
public:
|
|
std::unique_ptr<Calculator> makeCalculator(std::unique_ptr<Printer> printer) override
|
|
{
|
|
return std::make_unique<CalculatorImpl>(std::move(printer));
|
|
}
|
|
};
|
|
|
|
// Exercises deprecated log callback signature
|
|
static void LogPrint(bool raise, const std::string& message)
|
|
{
|
|
if (raise) throw std::runtime_error(message);
|
|
std::ofstream("debug.log", std::ios_base::app) << message << std::endl;
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
if (argc != 2) {
|
|
std::cout << "Usage: mpcalculator <fd>\n";
|
|
return 1;
|
|
}
|
|
int fd;
|
|
if (std::from_chars(argv[1], argv[1] + strlen(argv[1]), fd).ec != std::errc{}) {
|
|
std::cerr << argv[1] << " is not a number or is larger than an int\n";
|
|
return 1;
|
|
}
|
|
mp::EventLoop loop("mpcalculator", LogPrint);
|
|
std::unique_ptr<Init> init = std::make_unique<InitImpl>();
|
|
mp::ServeStream<InitInterface>(loop, fd, *init);
|
|
loop.loop();
|
|
return 0;
|
|
}
|