dash/src/ipc/protocol.h
MarcoFalke 9d9d97d4fd
Merge bitcoin/bitcoin#22218: multiprocess: Add ipc::Context and ipc::capnp::Context structs
3e33d170cc0a8f386791777f3cc597e2bd0bf2ee Add ipc::Context and ipc::capnp::Context structs (Russell Yanofsky)

Pull request description:

  These are currently empty structs but they will be used to pass some function and object pointers from bitcoin application code to IPC hooks that run, for example, when a remote object is created or destroyed, or a new process is created.

  ---

  This PR is part of the [process separation project](https://github.com/bitcoin/bitcoin/projects/10). The commit was first part of larger PR #10102.

ACKs for top commit:
  ariard:
    Code Review ACK 3e33d170

Tree-SHA512: fd949fae5f1a973d39cb97f2745821ab2f62b98e166e53bc2801f97dcde988e18faaaaa0ffc2a82c170938b3a18078b6162fa35460e6e7c635e681b3c9e5b0a6
2024-08-14 12:12:50 +07:00

45 lines
1.5 KiB
C++

// Copyright (c) 2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_IPC_PROTOCOL_H
#define BITCOIN_IPC_PROTOCOL_H
#include <interfaces/init.h>
#include <functional>
#include <memory>
#include <typeindex>
namespace ipc {
struct Context;
//! IPC protocol interface for calling IPC methods over sockets.
//!
//! There may be different implementations of this interface for different IPC
//! protocols (e.g. Cap'n Proto, gRPC, JSON-RPC, or custom protocols).
class Protocol
{
public:
virtual ~Protocol() = default;
//! Return Init interface that forwards requests over given socket descriptor.
//! Socket communication is handled on a background thread.
virtual std::unique_ptr<interfaces::Init> connect(int fd, const char* exe_name) = 0;
//! Handle requests on provided socket descriptor, forwarding them to the
//! provided Init interface. Socket communication is handled on the
//! current thread, and this call blocks until the socket is closed.
virtual void serve(int fd, const char* exe_name, interfaces::Init& init) = 0;
//! Add cleanup callback to interface that will run when the interface is
//! deleted.
virtual void addCleanup(std::type_index type, void* iface, std::function<void()> cleanup) = 0;
//! Context accessor.
virtual Context& context() = 0;
};
} // namespace ipc
#endif // BITCOIN_IPC_PROTOCOL_H