ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
opts.h File Reference

Go to the source code of this file.

Functions

 EMSCRIPTEN_DECLARE_VAL_TYPE (OptionsPatch)
int patch_options (OptionsPatch patch, double expected_revision)
int initial_options (OptionsPatch patch)

Function Documentation

◆ EMSCRIPTEN_DECLARE_VAL_TYPE()

EMSCRIPTEN_DECLARE_VAL_TYPE ( OptionsPatch )

◆ initial_options()

int initial_options ( OptionsPatch patch)

Definition at line 25 of file opts.cpp.

25 {
26 emscripten::val object = patch;
27 if (!object.isNull() && !object.isUndefined() && object.typeOf().as<std::string>() == "object" && !emscripten::val::global("Array").call<bool>("isArray", object) &&
28 emscripten::val::global("Object").call<emscripten::val>("keys", object)["length"].as<unsigned>() == 0)
29 return ASCIICHAT_OK;
30 int result = patch_options(patch, -1);
31 if (result == ASCIICHAT_OK) {
32 options_snapshot_t *snapshot = SAFE_MALLOC(sizeof(*snapshot), options_snapshot_t *);
33 if (options_read_snapshot(snapshot) == ASCIICHAT_OK)
35 SAFE_FREE(snapshot);
36 }
37 return result;
38}
#define SAFE_FREE(ptr)
#define SAFE_MALLOC(size, cast)
@ ASCIICHAT_OK
Definition error_codes.h:50
void log_set_level(log_level_t level)
Set the minimum log level.
Definition log/log.c:809
int patch_options(OptionsPatch patch, double expected_revision)
Definition opts.cpp:15
asciichat_error_t options_read_snapshot(options_snapshot_t *snapshot)
Definition rcu.c:934
log_level_t log_level
Log level threshold.
Definition options.h:1160

References ASCIICHAT_OK, options_state::log_level, log_set_level(), options_read_snapshot(), patch_options(), SAFE_FREE, SAFE_MALLOC, and options_snapshot_t::values.

Referenced by ClientSessionBinding::ClientSessionBinding(), and MirrorSessionBinding::MirrorSessionBinding().

◆ patch_options()

int patch_options ( OptionsPatch patch,
double expected_revision )

Definition at line 15 of file opts.cpp.

15 {
16 emscripten::val object = patch;
17 if (object.isNull() || object.isUndefined() || object.typeOf().as<std::string>() != "object" || emscripten::val::global("Array").call<bool>("isArray", object))
18 return SET_ERRNO(ERROR_INVALID_PARAM, "Options patch must be an object");
19 emscripten::val json = emscripten::val::global("JSON").call<emscripten::val>("stringify", object);
20 if (json.isUndefined())
21 return SET_ERRNO(ERROR_INVALID_PARAM, "Options patch cannot be serialized");
22 std::string text = json.as<std::string>();
23 return options_apply_json(text.c_str(), text.size(), expected_revision < 0 ? OPTIONS_REVISION_ANY : static_cast<uint64_t>(expected_revision), OPTIONS_ORIGIN_LOCAL, nullptr);
24}
#define SET_ERRNO(code,...)
unsigned long long uint64_t
@ ERROR_INVALID_PARAM
@ OPTIONS_ORIGIN_LOCAL
#define OPTIONS_REVISION_ANY
asciichat_error_t options_apply_json(const char *json, size_t length, uint64_t expected_revision, options_origin_t origin, options_patch_result_t *result)
Definition rcu.c:1092

References ERROR_INVALID_PARAM, options_apply_json(), OPTIONS_ORIGIN_LOCAL, OPTIONS_REVISION_ANY, and SET_ERRNO.

Referenced by initial_options(), and OptionsBinding::patch().