Initial Release
This commit is contained in:
commit
5a00e06cb9
81 changed files with 12670 additions and 0 deletions
13
include/thespian/backtrace.h
Normal file
13
include/thespian/backtrace.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void install_debugger();
|
||||
void install_backtrace();
|
||||
void install_jitdebugger();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
39
include/thespian/c/context.h
Normal file
39
include/thespian/c/context.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
|
||||
#include <thespian/c/env.h>
|
||||
#include <thespian/c/handle.h>
|
||||
|
||||
// NOLINTBEGIN(modernize-use-trailing-return-type, modernize-use-using)
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*thespian_last_exit_handler)();
|
||||
typedef void (*thespian_context_destroy)(void *);
|
||||
|
||||
typedef void *thespian_behaviour_state;
|
||||
typedef void *thespian_exit_handler_state;
|
||||
typedef thespian_result (*thespian_behaviour)(thespian_behaviour_state);
|
||||
typedef void (*thespian_exit_handler)(thespian_exit_handler_state,
|
||||
const char *msg, size_t len);
|
||||
|
||||
struct thespian_context_t;
|
||||
typedef struct thespian_context_t *thespian_context;
|
||||
|
||||
thespian_context thespian_context_create(thespian_context_destroy *);
|
||||
void thespian_context_run(thespian_context);
|
||||
void thespian_context_on_last_exit(thespian_context,
|
||||
thespian_last_exit_handler);
|
||||
|
||||
int thespian_context_spawn_link(thespian_context, thespian_behaviour,
|
||||
thespian_behaviour_state, thespian_exit_handler,
|
||||
thespian_exit_handler_state, const char *name,
|
||||
thespian_env, thespian_handle *);
|
||||
|
||||
const char *thespian_get_last_error();
|
||||
void thespian_set_last_error(const char *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// NOLINTEND(modernize-use-trailing-return-type, modernize-use-using)
|
43
include/thespian/c/env.h
Normal file
43
include/thespian/c/env.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <thespian/c/handle.h>
|
||||
#include <thespian/c/string_view.h>
|
||||
#include <thespian/c/trace.h>
|
||||
|
||||
// NOLINTBEGIN(modernize-use-trailing-return-type, modernize-use-using)
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct thespian_env_t;
|
||||
typedef struct
|
||||
thespian_env_t *thespian_env;
|
||||
|
||||
void thespian_env_enable_all_channels(thespian_env);
|
||||
void thespian_env_disable_all_channels(thespian_env);
|
||||
void thespian_env_enable(thespian_env, thespian_trace_channel);
|
||||
void thespian_env_disable(thespian_env, thespian_trace_channel);
|
||||
bool thespian_env_enabled(thespian_env, thespian_trace_channel);
|
||||
void thespian_env_on_trace(thespian_env, thespian_trace_handler);
|
||||
void thespian_env_trace(thespian_env, cbor_buffer);
|
||||
|
||||
bool thespian_env_is(thespian_env, c_string_view key);
|
||||
void thespian_env_set(thespian_env, c_string_view key, bool);
|
||||
int64_t thespian_env_num(thespian_env, c_string_view key);
|
||||
void thespian_env_num_set(thespian_env, c_string_view key, int64_t);
|
||||
c_string_view thespian_env_str(thespian_env, c_string_view key);
|
||||
void thespian_env_str_set(thespian_env, c_string_view key,
|
||||
c_string_view);
|
||||
thespian_handle thespian_env_proc(thespian_env, c_string_view key);
|
||||
void thespian_env_proc_set(thespian_env, c_string_view key,
|
||||
thespian_handle);
|
||||
|
||||
thespian_env thespian_env_get();
|
||||
thespian_env thespian_env_new();
|
||||
thespian_env thespian_env_clone(thespian_env);
|
||||
void thespian_env_destroy(thespian_env);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// NOLINTEND(modernize-use-trailing-return-type, modernize-use-using)
|
19
include/thespian/c/file_descriptor.h
Normal file
19
include/thespian/c/file_descriptor.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
// NOLINTBEGIN(modernize-use-trailing-return-type)
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct thespian_file_descriptor_handle;
|
||||
struct thespian_file_descriptor_handle *
|
||||
thespian_file_descriptor_create(const char* tag, int fd);
|
||||
int thespian_file_descriptor_wait_write(struct thespian_file_descriptor_handle *);
|
||||
int thespian_file_descriptor_wait_read(struct thespian_file_descriptor_handle *);
|
||||
int thespian_file_descriptor_cancel(struct thespian_file_descriptor_handle *);
|
||||
void thespian_file_descriptor_destroy(struct thespian_file_descriptor_handle *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// NOLINTEND(modernize-use-trailing-return-type)
|
29
include/thespian/c/handle.h
Normal file
29
include/thespian/c/handle.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include "thespian/c/string_view.h"
|
||||
#include <cbor/c/cbor.h>
|
||||
|
||||
// NOLINTBEGIN(modernize-*, hicpp-*)
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef cbor_buffer thespian_error;
|
||||
typedef thespian_error *thespian_result;
|
||||
|
||||
struct thespian_handle_t;
|
||||
typedef struct thespian_handle_t *thespian_handle;
|
||||
|
||||
thespian_handle thespian_handle_clone(thespian_handle);
|
||||
void thespian_handle_destroy(thespian_handle);
|
||||
|
||||
thespian_result thespian_handle_send_raw(thespian_handle, cbor_buffer);
|
||||
thespian_result thespian_handle_send_exit(thespian_handle, c_string_view);
|
||||
bool thespian_handle_is_expired(thespian_handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// NOLINTEND(modernize-*, hicpp-*)
|
29
include/thespian/c/instance.h
Normal file
29
include/thespian/c/instance.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include "context.h"
|
||||
#include "env.h"
|
||||
#include "handle.h"
|
||||
|
||||
// NOLINTBEGIN(modernize-use-trailing-return-type, modernize-use-using)
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef thespian_result (*thespian_receiver)(thespian_behaviour_state,
|
||||
thespian_handle from, cbor_buffer);
|
||||
|
||||
void thespian_receive(thespian_receiver, thespian_behaviour_state);
|
||||
|
||||
bool thespian_get_trap();
|
||||
bool thespian_set_trap(bool);
|
||||
void thespian_link(thespian_handle);
|
||||
|
||||
thespian_handle thespian_self();
|
||||
|
||||
int thespian_spawn_link(thespian_behaviour, thespian_behaviour_state,
|
||||
const char *name, thespian_env, thespian_handle *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// NOLINTEND(modernize-use-trailing-return-type, modernize-use-using)
|
20
include/thespian/c/metronome.h
Normal file
20
include/thespian/c/metronome.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
// NOLINTBEGIN(modernize-use-trailing-return-type)
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct thespian_metronome_handle;
|
||||
struct thespian_metronome_handle *
|
||||
thespian_metronome_create_ms(unsigned long ms);
|
||||
struct thespian_metronome_handle *
|
||||
thespian_metronome_create_us(unsigned long us);
|
||||
int thespian_metronome_start(struct thespian_metronome_handle *);
|
||||
int thespian_metronome_stop(struct thespian_metronome_handle *);
|
||||
void thespian_metronome_destroy(struct thespian_metronome_handle *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// NOLINTEND(modernize-use-trailing-return-type)
|
19
include/thespian/c/signal.h
Normal file
19
include/thespian/c/signal.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <cbor/c/cbor.h>
|
||||
|
||||
// NOLINTBEGIN(modernize-use-trailing-return-type)
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct thespian_signal_handle;
|
||||
struct thespian_signal_handle *
|
||||
thespian_signal_create(int signum, cbor_buffer m);
|
||||
int thespian_signal_cancel(struct thespian_signal_handle *);
|
||||
void thespian_signal_destroy(struct thespian_signal_handle *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// NOLINTEND(modernize-use-trailing-return-type)
|
19
include/thespian/c/string_view.h
Normal file
19
include/thespian/c/string_view.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
// NOLINTBEGIN(modernize-*, hicpp-*)
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct c_string_view_t {
|
||||
const char *base;
|
||||
size_t len;
|
||||
};
|
||||
typedef struct c_string_view_t c_string_view;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// NOLINTEND(modernize-*, hicpp-*)
|
21
include/thespian/c/timeout.h
Normal file
21
include/thespian/c/timeout.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <cbor/c/cbor.h>
|
||||
|
||||
// NOLINTBEGIN(modernize-use-trailing-return-type)
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct thespian_timeout_handle;
|
||||
struct thespian_timeout_handle *
|
||||
thespian_timeout_create_ms(unsigned long ms, cbor_buffer m);
|
||||
struct thespian_timeout_handle *
|
||||
thespian_timeout_create_us(unsigned long us, cbor_buffer m);
|
||||
int thespian_timeout_cancel(struct thespian_timeout_handle *);
|
||||
void thespian_timeout_destroy(struct thespian_timeout_handle *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// NOLINTEND(modernize-use-trailing-return-type)
|
40
include/thespian/c/trace.h
Normal file
40
include/thespian/c/trace.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include <cbor/c/cbor.h>
|
||||
|
||||
// NOLINTBEGIN(modernize-*, hicpp-*)
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int thespian_trace_channel_set;
|
||||
|
||||
typedef int thespian_trace_channel;
|
||||
|
||||
static const thespian_trace_channel thespian_trace_channel_send = 1;
|
||||
static const thespian_trace_channel thespian_trace_channel_receive = 2;
|
||||
static const thespian_trace_channel thespian_trace_channel_lifetime = 4;
|
||||
static const thespian_trace_channel thespian_trace_channel_link = 8;
|
||||
static const thespian_trace_channel thespian_trace_channel_execute = 16;
|
||||
static const thespian_trace_channel thespian_trace_channel_udp = 32;
|
||||
static const thespian_trace_channel thespian_trace_channel_tcp = 64;
|
||||
static const thespian_trace_channel thespian_trace_channel_timer = 128;
|
||||
static const thespian_trace_channel thespian_trace_channel_metronome = 256;
|
||||
static const thespian_trace_channel thespian_trace_channel_endpoint = 512;
|
||||
static const thespian_trace_channel thespian_trace_channel_signal = 1024;
|
||||
static const thespian_trace_channel thespian_trace_channel_all = INT_MAX;
|
||||
|
||||
typedef void (*thespian_trace_handler)(cbor_buffer);
|
||||
|
||||
void thespian_on_trace(thespian_trace_handler);
|
||||
void thespian_trace_to_json_file(const char *file_name);
|
||||
void thespian_trace_to_cbor_file(const char *file_name);
|
||||
void thespian_trace_to_mermaid_file(const char *file_name);
|
||||
void thespian_trace_to_trace(thespian_trace_channel default_channel);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// NOLINTEND(modernize-*, hicpp-*)
|
46
include/thespian/context.hpp
Normal file
46
include/thespian/context.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include "env.hpp"
|
||||
#include "handle.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace thespian {
|
||||
|
||||
using behaviour = std::function<auto()->result>;
|
||||
using exit_handler = std::function<void(std::string_view)>;
|
||||
|
||||
struct context {
|
||||
using dtor = void (*)(context *);
|
||||
using ref = std::unique_ptr<context, dtor>;
|
||||
using last_exit_handler = std::function<void()>;
|
||||
|
||||
[[nodiscard]] static auto create() -> ref;
|
||||
[[nodiscard]] static auto create(dtor *) -> context *;
|
||||
void run();
|
||||
void on_last_exit(last_exit_handler);
|
||||
|
||||
[[nodiscard]] auto spawn(behaviour b, std::string_view name)
|
||||
-> expected<handle, error>;
|
||||
[[nodiscard]] auto spawn(behaviour b, std::string_view name, env_t env)
|
||||
-> expected<handle, error>;
|
||||
[[nodiscard]] auto spawn_link(behaviour b, exit_handler eh,
|
||||
std::string_view name)
|
||||
-> expected<handle, error>;
|
||||
[[nodiscard]] auto spawn_link(behaviour b, exit_handler eh,
|
||||
std::string_view name, env_t env)
|
||||
-> expected<handle, error>;
|
||||
|
||||
protected:
|
||||
context() = default;
|
||||
~context() = default;
|
||||
|
||||
public:
|
||||
context(const context &) = delete;
|
||||
context(context &&) = delete;
|
||||
void operator=(const context &) = delete;
|
||||
void operator=(context &&) = delete;
|
||||
};
|
||||
|
||||
} // namespace thespian
|
22
include/thespian/debug.hpp
Normal file
22
include/thespian/debug.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "context.hpp"
|
||||
#include "handle.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
using port_t = unsigned short;
|
||||
|
||||
namespace thespian::debug {
|
||||
|
||||
auto enable(context &) -> void;
|
||||
auto disable(context &) -> void;
|
||||
auto isenabled(context &) -> bool;
|
||||
|
||||
namespace tcp {
|
||||
|
||||
auto create(context &, port_t port, const std::string &prompt)
|
||||
-> expected<handle, error>;
|
||||
|
||||
} // namespace tcp
|
||||
} // namespace thespian::debug
|
33
include/thespian/endpoint.hpp
Normal file
33
include/thespian/endpoint.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include "handle.hpp"
|
||||
#include "tcp.hpp"
|
||||
#include "unx.hpp"
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
|
||||
using port_t = unsigned short;
|
||||
|
||||
namespace thespian::endpoint {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace tcp {
|
||||
|
||||
auto listen(in6_addr, port_t) -> expected<handle, error>;
|
||||
auto connect(in6_addr, port_t, std::chrono::milliseconds retry_time = 50ms,
|
||||
size_t retry_count = 5) -> expected<handle, error>;
|
||||
|
||||
} // namespace tcp
|
||||
|
||||
namespace unx {
|
||||
using thespian::unx::mode;
|
||||
|
||||
auto listen(std::string_view, mode = mode::abstract) -> expected<handle, error>;
|
||||
auto connect(std::string_view, mode = mode::abstract,
|
||||
std::chrono::milliseconds retry_time = 50ms,
|
||||
size_t retry_count = 5) -> expected<handle, error>;
|
||||
|
||||
} // namespace unx
|
||||
|
||||
} // namespace thespian::endpoint
|
51
include/thespian/env.hpp
Normal file
51
include/thespian/env.hpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
|
||||
#include "handle.hpp"
|
||||
#include "trace.hpp"
|
||||
|
||||
#include <any>
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
|
||||
namespace thespian {
|
||||
|
||||
struct env_t {
|
||||
void enable_all_channels() {
|
||||
trace_channels = static_cast<channel_set>(channel::all);
|
||||
}
|
||||
void disable_all_channels() { trace_channels = 0; }
|
||||
void enable(channel c) { trace_channels |= static_cast<channel_set>(c); }
|
||||
void disable(channel c) { trace_channels ^= static_cast<channel_set>(c); }
|
||||
auto enabled(channel c) -> bool {
|
||||
return trace_channels & static_cast<channel_set>(c);
|
||||
}
|
||||
|
||||
auto on_trace(trace_handler h) {
|
||||
std::swap(h, trace_handler);
|
||||
return h;
|
||||
}
|
||||
|
||||
auto trace(const cbor::buffer &msg) const {
|
||||
if (trace_handler)
|
||||
trace_handler(msg);
|
||||
}
|
||||
|
||||
auto is(std::string_view k) -> bool & { return b[std::string(k)]; }
|
||||
auto num(std::string_view k) -> int64_t & { return i[std::string(k)]; }
|
||||
auto str(std::string_view k) -> std::string & { return s[std::string(k)]; }
|
||||
auto proc(std::string_view k) -> handle & { return h[std::string(k)]; }
|
||||
[[nodiscard]] auto proc(std::string_view k) const -> const handle & {
|
||||
return h.at(std::string(k));
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> s;
|
||||
std::map<std::string, bool> b;
|
||||
std::map<std::string, int64_t> i;
|
||||
std::map<std::string, handle> h;
|
||||
channel_set trace_channels{0};
|
||||
trace_handler trace_handler;
|
||||
};
|
||||
auto env() -> env_t &;
|
||||
|
||||
} // namespace thespian
|
1716
include/thespian/expected.hpp
Normal file
1716
include/thespian/expected.hpp
Normal file
File diff suppressed because it is too large
Load diff
32
include/thespian/file_descriptor.hpp
Normal file
32
include/thespian/file_descriptor.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace thespian {
|
||||
|
||||
struct file_descriptor_impl;
|
||||
using file_descriptor_dtor = void (*)(file_descriptor_impl *);
|
||||
using file_descriptor_ref =
|
||||
std::unique_ptr<file_descriptor_impl, file_descriptor_dtor>;
|
||||
|
||||
struct file_descriptor {
|
||||
static auto create(std::string_view tag, int fd) -> file_descriptor;
|
||||
auto wait_write() -> void;
|
||||
auto wait_read() -> void;
|
||||
auto cancel() -> void;
|
||||
static void wait_write(file_descriptor_impl *);
|
||||
static void wait_read(file_descriptor_impl *);
|
||||
static void cancel(file_descriptor_impl *);
|
||||
static void destroy(file_descriptor_impl *);
|
||||
|
||||
//->("fd", tag, "write_ready")
|
||||
//->("fd", tag, "write_error", int err, string message)
|
||||
//->("fd", tag, "read_ready")
|
||||
//->("fd", tag, "read_error", int err, string message)
|
||||
|
||||
file_descriptor_ref ref;
|
||||
};
|
||||
|
||||
} // namespace thespian
|
49
include/thespian/handle.hpp
Normal file
49
include/thespian/handle.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#pragma once
|
||||
|
||||
#include <cbor/cbor.hpp>
|
||||
|
||||
#include "expected.hpp"
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace thespian {
|
||||
|
||||
template <typename T, typename E>
|
||||
using expected = std::experimental::expected<T, E>;
|
||||
using error = cbor::buffer;
|
||||
|
||||
using result = expected<void, error>;
|
||||
using to_error = std::experimental::unexpected<error>;
|
||||
|
||||
[[nodiscard]] inline auto ok() -> result { return result{}; }
|
||||
template <typename T> [[nodiscard]] auto ok(T v) { return result{v}; }
|
||||
template <typename T> [[nodiscard]] auto to_result(T ret) -> result {
|
||||
if (ret)
|
||||
return ok();
|
||||
return to_error(ret.error());
|
||||
}
|
||||
|
||||
struct instance;
|
||||
using ref = std::weak_ptr<instance>;
|
||||
|
||||
struct handle {
|
||||
[[nodiscard]] auto send_raw(cbor::buffer) const -> result;
|
||||
template <typename... Ts> [[nodiscard]] auto send(Ts &&...parms) const {
|
||||
return send_raw(cbor::array(std::forward<Ts>(parms)...));
|
||||
}
|
||||
template <typename... Ts>
|
||||
auto exit(const std::string &error, Ts &&...details) const {
|
||||
return send_raw(cbor::array("exit", error, std::forward<Ts>(details)...));
|
||||
}
|
||||
[[nodiscard]] inline auto expired() const { return ref_.expired(); }
|
||||
|
||||
private:
|
||||
ref ref_;
|
||||
friend auto handle_ref(handle &) -> ref &;
|
||||
friend auto handle_ref(const handle &) -> const ref &;
|
||||
friend auto operator==(const handle &, const handle &) -> bool;
|
||||
};
|
||||
|
||||
auto operator==(const handle &, const handle &) -> bool;
|
||||
|
||||
} // namespace thespian
|
46
include/thespian/hub.hpp
Normal file
46
include/thespian/hub.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include "handle.hpp"
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace thespian {
|
||||
|
||||
struct hub : private handle {
|
||||
using filter = std::function<bool(const cbor::buffer &)>;
|
||||
|
||||
hub() = default;
|
||||
auto expired() -> bool { return handle::expired(); }
|
||||
|
||||
template <typename... Ts> auto broadcast(Ts &&...parms) const {
|
||||
return send("broadcast", cbor::array(std::forward<Ts>(parms)...));
|
||||
}
|
||||
[[nodiscard]] auto subscribe() const -> result;
|
||||
[[nodiscard]] auto subscribe(filter) const -> result;
|
||||
[[nodiscard]] auto listen(std::string_view unix_socket_descriptor) const
|
||||
-> result;
|
||||
[[nodiscard]] auto shutdown() const { return send("shutdown"); }
|
||||
|
||||
[[nodiscard]] static auto create(std::string_view name)
|
||||
-> expected<hub, error>;
|
||||
|
||||
struct pipe {
|
||||
pipe();
|
||||
pipe(const pipe &) = delete;
|
||||
pipe(pipe &&) = delete;
|
||||
auto operator=(const pipe &) -> pipe & = delete;
|
||||
auto operator=(pipe &&) -> pipe & = delete;
|
||||
virtual ~pipe();
|
||||
};
|
||||
|
||||
private:
|
||||
hub(const handle &, std::shared_ptr<pipe>);
|
||||
std::shared_ptr<pipe> pipe_;
|
||||
friend auto operator==(const handle &, const hub &) -> bool;
|
||||
friend auto operator==(const hub &, const handle &) -> bool;
|
||||
};
|
||||
|
||||
auto operator==(const handle &, const hub &) -> bool;
|
||||
auto operator==(const hub &, const handle &) -> bool;
|
||||
|
||||
} // namespace thespian
|
51
include/thespian/instance.hpp
Normal file
51
include/thespian/instance.hpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
|
||||
#include "context.hpp"
|
||||
#include "env.hpp"
|
||||
#include "handle.hpp"
|
||||
#include "trace.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace thespian {
|
||||
|
||||
using receiver = std::function<result(handle from, cbor::buffer)>;
|
||||
using sync_receiver = std::function<cbor::buffer(handle from, cbor::buffer)>;
|
||||
|
||||
[[nodiscard]] auto send_raw(cbor::buffer) -> result;
|
||||
template <typename... Ts> [[nodiscard]] auto send(Ts &&...parms) -> result {
|
||||
return send_raw(cbor::array(std::forward<Ts>(parms)...));
|
||||
}
|
||||
auto receive(receiver) -> void;
|
||||
auto receive_sync(sync_receiver) -> void;
|
||||
|
||||
auto trap() -> bool;
|
||||
auto trap(bool) -> bool;
|
||||
auto link(const handle &) -> void;
|
||||
|
||||
auto self() -> handle;
|
||||
auto self_ref() -> handle&;
|
||||
|
||||
[[nodiscard]] auto spawn(behaviour, std::string_view name)
|
||||
-> expected<handle, error>;
|
||||
[[nodiscard]] auto spawn_link(behaviour, std::string_view name)
|
||||
-> expected<handle, error>;
|
||||
|
||||
[[nodiscard]] auto spawn(behaviour, std::string_view name, env_t)
|
||||
-> expected<handle, error>;
|
||||
[[nodiscard]] auto spawn_link(behaviour, std::string_view name, env_t)
|
||||
-> expected<handle, error>;
|
||||
|
||||
[[nodiscard]] auto ok() -> result;
|
||||
[[nodiscard]] auto exit() -> result;
|
||||
[[nodiscard]] auto exit(std::string_view e) -> result;
|
||||
[[nodiscard]] auto exit(std::string_view e, std::string_view m) -> result;
|
||||
[[nodiscard]] auto exit(std::string_view e, int err) -> result;
|
||||
[[nodiscard]] auto exit(std::string_view e, size_t n) -> result;
|
||||
|
||||
[[nodiscard]] auto unexpected(const cbor::buffer & /*b*/) -> result;
|
||||
|
||||
} // namespace thespian
|
25
include/thespian/metronome.hpp
Normal file
25
include/thespian/metronome.hpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace thespian {
|
||||
|
||||
struct metronome_impl;
|
||||
using metronome_dtor = void (*)(metronome_impl *);
|
||||
using metronome_ref = std::unique_ptr<metronome_impl, metronome_dtor>;
|
||||
|
||||
struct metronome {
|
||||
auto start() -> void;
|
||||
auto stop() -> void;
|
||||
|
||||
metronome_ref ref;
|
||||
};
|
||||
|
||||
[[nodiscard]] auto create_metronome(std::chrono::microseconds us) -> metronome;
|
||||
void start_metronome(metronome_impl *);
|
||||
void stop_metronome(metronome_impl *);
|
||||
void destroy_metronome(metronome_impl *);
|
||||
|
||||
} // namespace thespian
|
25
include/thespian/signal.hpp
Normal file
25
include/thespian/signal.hpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <cbor/cbor.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace thespian {
|
||||
|
||||
struct signal_impl;
|
||||
using signal_dtor = void (*)(signal_impl *);
|
||||
using signal_ref = std::unique_ptr<signal_impl, signal_dtor>;
|
||||
|
||||
struct signal {
|
||||
auto cancel() -> void;
|
||||
|
||||
signal_ref ref;
|
||||
};
|
||||
|
||||
[[nodiscard]] auto create_signal(int signum, cbor::buffer m) -> signal;
|
||||
void cancel_signal(signal_impl *);
|
||||
void destroy_signal(signal_impl *);
|
||||
|
||||
} // namespace thespian
|
29
include/thespian/socket.hpp
Normal file
29
include/thespian/socket.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace thespian {
|
||||
|
||||
struct socket_impl;
|
||||
using socket_dtor = void (*)(socket_impl *);
|
||||
using socket_ref = std::unique_ptr<socket_impl, socket_dtor>;
|
||||
|
||||
struct socket {
|
||||
static auto create(std::string_view tag, int fd) -> socket;
|
||||
auto write(std::string_view) -> void;
|
||||
auto write(const std::vector<uint8_t> &) -> void;
|
||||
auto read() -> void;
|
||||
auto close() -> void;
|
||||
|
||||
//->("socket", tag, "write_complete", int written)
|
||||
//->("socket", tag, "write_error", int err, string message)
|
||||
//->("socket", tag, "read_complete", string buf)
|
||||
//->("socket", tag, "read_error", int err, string message)
|
||||
//->("socket", tag, "closed")
|
||||
|
||||
socket_ref ref;
|
||||
};
|
||||
|
||||
} // namespace thespian
|
47
include/thespian/tcp.hpp
Normal file
47
include/thespian/tcp.hpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <netinet/in.h>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
using port_t = unsigned short;
|
||||
|
||||
namespace thespian::tcp {
|
||||
|
||||
struct acceptor_impl;
|
||||
using acceptor_dtor = void (*)(acceptor_impl *);
|
||||
using acceptor_ref = std::unique_ptr<acceptor_impl, acceptor_dtor>;
|
||||
|
||||
struct acceptor {
|
||||
static auto create(std::string_view tag) -> acceptor;
|
||||
auto listen(in6_addr ip, port_t port) -> port_t;
|
||||
auto close() -> void;
|
||||
|
||||
//->("acceptor", tag, "accept", int fd, in6_addr ip, port_t port)
|
||||
//->("acceptor", tag, "error", int err, string message)
|
||||
//->("acceptor", tag, "closed")
|
||||
|
||||
acceptor_ref ref;
|
||||
};
|
||||
|
||||
struct connector_impl;
|
||||
using connector_dtor = void (*)(connector_impl *);
|
||||
using connector_ref = std::unique_ptr<connector_impl, connector_dtor>;
|
||||
|
||||
struct connector {
|
||||
static auto create(std::string_view tag) -> connector;
|
||||
auto connect(in6_addr ip, port_t port) -> void;
|
||||
auto connect(in6_addr ip, port_t port, in6_addr lip) -> void;
|
||||
auto connect(in6_addr ip, port_t port, port_t lport) -> void;
|
||||
auto connect(in6_addr ip, port_t port, in6_addr lip, port_t lport) -> void;
|
||||
auto cancel() -> void;
|
||||
|
||||
//->("connector", tag, "connected", int fd)
|
||||
//->("connector", tag, "error", int err, string message)
|
||||
//->("connector", tag, "cancelled")
|
||||
|
||||
connector_ref ref;
|
||||
};
|
||||
|
||||
} // namespace thespian::tcp
|
28
include/thespian/timeout.hpp
Normal file
28
include/thespian/timeout.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <cbor/cbor.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace thespian {
|
||||
|
||||
struct timeout_impl;
|
||||
using timeout_dtor = void (*)(timeout_impl *);
|
||||
using timeout_ref = std::unique_ptr<timeout_impl, timeout_dtor>;
|
||||
|
||||
struct timeout {
|
||||
auto cancel() -> void;
|
||||
|
||||
timeout_ref ref;
|
||||
};
|
||||
|
||||
[[nodiscard]] auto create_timeout(std::chrono::microseconds us, cbor::buffer m)
|
||||
-> timeout;
|
||||
|
||||
[[nodiscard]] auto never() -> timeout;
|
||||
void cancel_timeout(timeout_impl *);
|
||||
void destroy_timeout(timeout_impl *);
|
||||
|
||||
} // namespace thespian
|
37
include/thespian/trace.hpp
Normal file
37
include/thespian/trace.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include "thespian/handle.hpp"
|
||||
#include <cbor/cbor.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace thespian {
|
||||
|
||||
using channel_set = int;
|
||||
enum class channel {
|
||||
send = 1,
|
||||
receive = 2,
|
||||
lifetime = 4,
|
||||
link = 8,
|
||||
execute = 16,
|
||||
udp = 32,
|
||||
tcp = 64,
|
||||
timer = 128,
|
||||
metronome = 256,
|
||||
endpoint = 512,
|
||||
signal = 1024,
|
||||
all = std::numeric_limits<channel_set>::max(),
|
||||
};
|
||||
|
||||
using trace_handler = std::function<void(const cbor::buffer &)>;
|
||||
|
||||
auto on_trace(trace_handler) -> trace_handler;
|
||||
auto trace_to_json_file(const std::string &file_name) -> void;
|
||||
auto trace_to_cbor_file(const std::string &file_name) -> void;
|
||||
auto trace_to_mermaid_file(const std::string &file_name) -> void;
|
||||
auto trace_to_trace(int default_channel) -> void;
|
||||
|
||||
} // namespace thespian
|
33
include/thespian/udp.hpp
Normal file
33
include/thespian/udp.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include <cbor/cbor_in.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
using port_t = unsigned short;
|
||||
|
||||
namespace thespian {
|
||||
|
||||
struct udp_impl;
|
||||
using udp_dtor = void (*)(udp_impl *);
|
||||
using udp_ref = std::unique_ptr<udp_impl, udp_dtor>;
|
||||
|
||||
struct udp {
|
||||
static auto create(std::string tag) -> udp;
|
||||
|
||||
auto open(const in6_addr &, port_t port) -> port_t;
|
||||
[[nodiscard]] auto sendto(std::string_view, in6_addr ip, port_t port)
|
||||
-> size_t;
|
||||
auto close() -> void;
|
||||
|
||||
//->("udp", tag, "open_error", int err, string message);
|
||||
//->("udp", tag, "read_error", int err, string message);
|
||||
//->("udp", tag, "receive", string data, in6_addr remote_ip, int port);
|
||||
//->("udp", tag, "closed");
|
||||
|
||||
udp_ref ref;
|
||||
};
|
||||
|
||||
} // namespace thespian
|
43
include/thespian/unx.hpp
Normal file
43
include/thespian/unx.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace thespian::unx {
|
||||
|
||||
enum class mode { file, abstract };
|
||||
|
||||
struct acceptor_impl;
|
||||
using acceptor_dtor = void (*)(acceptor_impl *);
|
||||
using acceptor_ref = std::unique_ptr<acceptor_impl, acceptor_dtor>;
|
||||
|
||||
struct acceptor {
|
||||
static auto create(std::string_view tag) -> acceptor;
|
||||
auto listen(std::string_view, mode) -> void;
|
||||
auto close() -> void;
|
||||
|
||||
//->("acceptor", tag, "accept", int fd)
|
||||
//->("acceptor", tag, "error", int err, string message)
|
||||
//->("acceptor",tag, "closed")
|
||||
|
||||
acceptor_ref ref;
|
||||
};
|
||||
|
||||
struct connector_impl;
|
||||
using connector_dtor = void (*)(connector_impl *);
|
||||
using connector_ref = std::unique_ptr<connector_impl, connector_dtor>;
|
||||
|
||||
struct connector {
|
||||
static auto create(std::string_view tag) -> connector;
|
||||
auto connect(std::string_view, mode) -> void;
|
||||
auto cancel() -> void;
|
||||
|
||||
//->("connector", tag, "connected", int fd)
|
||||
//->("connector", tag, "error", int err, string message)
|
||||
//->("connector", tag, "cancelled")
|
||||
|
||||
connector_ref ref;
|
||||
};
|
||||
|
||||
} // namespace thespian::unx
|
Loading…
Add table
Add a link
Reference in a new issue