use immediate initialization in nf7core_any
This commit is contained in:
parent
53e13f5c50
commit
623e783899
@ -8,5 +8,8 @@ target_link_libraries(nf7core_any
|
|||||||
PRIVATE
|
PRIVATE
|
||||||
nf7if
|
nf7if
|
||||||
nf7util
|
nf7util
|
||||||
|
|
||||||
|
PUBLIC
|
||||||
|
nf7core_exec
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -60,11 +60,13 @@ void send_(struct nf7core_exec_entity* entity, struct nf7util_buffer* buf) {
|
|||||||
(void) this;
|
(void) this;
|
||||||
(void) buf;
|
(void) buf;
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
|
nf7util_buffer_unref(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const struct nf7core_exec_idea nf7core_any_idea = {
|
const struct nf7core_exec_idea nf7core_any_idea = {
|
||||||
.name = (const uint8_t*) "nf7core_exec",
|
.name = (const uint8_t*) "nf7core_any",
|
||||||
.details = (const uint8_t*) "creates and wraps other entity of an idea chosen at runtime",
|
.details = (const uint8_t*) "creates and wraps other entity of an idea chosen at runtime",
|
||||||
.mod = &nf7core_any,
|
.mod = &nf7core_any,
|
||||||
|
|
||||||
|
@ -4,22 +4,26 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <uv.h>
|
|
||||||
|
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
|
||||||
#include "core/any/idea.h"
|
#include "core/any/idea.h"
|
||||||
|
#include "core/exec/idea.h"
|
||||||
|
|
||||||
|
|
||||||
static void del_(struct nf7_mod*);
|
static void del_(struct nf7_mod*);
|
||||||
|
|
||||||
static void idle_handle_(uv_idle_t*);
|
|
||||||
static void idle_close_(uv_handle_t*);
|
|
||||||
|
|
||||||
|
|
||||||
struct nf7_mod* nf7core_any_new(struct nf7* nf7) {
|
struct nf7_mod* nf7core_any_new(struct nf7* nf7) {
|
||||||
assert(nullptr != nf7);
|
assert(nullptr != nf7);
|
||||||
|
|
||||||
|
// find nf7core_exec
|
||||||
|
struct nf7core_exec* exec = (void*) nf7_get_mod_by_meta(nf7, &nf7core_exec);
|
||||||
|
if (nullptr == exec) {
|
||||||
|
nf7util_log_error("not found nf7core_exec, nf7core_any is disabled");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// create module data
|
||||||
struct nf7core_any* this = nf7util_malloc_alloc(nf7->malloc, sizeof(*this));
|
struct nf7core_any* this = nf7util_malloc_alloc(nf7->malloc, sizeof(*this));
|
||||||
if (nullptr == this) {
|
if (nullptr == this) {
|
||||||
nf7util_log_error("failed to allocate module context");
|
nf7util_log_error("failed to allocate module context");
|
||||||
@ -31,18 +35,13 @@ struct nf7_mod* nf7core_any_new(struct nf7* nf7) {
|
|||||||
.meta = &nf7core_any,
|
.meta = &nf7core_any,
|
||||||
},
|
},
|
||||||
.malloc = nf7->malloc,
|
.malloc = nf7->malloc,
|
||||||
.uv = nf7->uv,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
uv_idle_t* idle = nf7util_malloc_alloc(this->malloc, sizeof(*idle));
|
// register idea
|
||||||
if (nullptr == idle) {
|
if (!nf7core_exec_idea_register(exec, &nf7core_any_idea)) {
|
||||||
nf7util_log_error("failed to allocate an initializer");
|
nf7util_log_error("failed to register an idea, nf7core_any");
|
||||||
goto ABORT;
|
goto ABORT;
|
||||||
}
|
}
|
||||||
uv_idle_init(this->uv, idle);
|
|
||||||
idle->data = nf7;
|
|
||||||
uv_idle_start(idle, idle_handle_);
|
|
||||||
|
|
||||||
return &this->super;
|
return &this->super;
|
||||||
|
|
||||||
ABORT:
|
ABORT:
|
||||||
@ -57,38 +56,6 @@ static void del_(struct nf7_mod* mod) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void idle_handle_(uv_idle_t* idle) {
|
|
||||||
assert(nullptr != idle);
|
|
||||||
|
|
||||||
struct nf7* nf7 = idle->data;
|
|
||||||
assert(nullptr != nf7);
|
|
||||||
|
|
||||||
// Register an idea, nf7core_any
|
|
||||||
struct nf7core_exec* exec = (void*) nf7_get_mod_by_meta(nf7, &nf7core_exec);
|
|
||||||
if (nullptr == exec) {
|
|
||||||
nf7util_log_error("not found nf7core_exec, nf7core_any is disabled");
|
|
||||||
goto EXIT;
|
|
||||||
}
|
|
||||||
if (!nf7core_exec_idea_register(exec, &nf7core_any_idea)) {
|
|
||||||
nf7util_log_error("failed to register an idea, nf7core_any");
|
|
||||||
goto EXIT;
|
|
||||||
}
|
|
||||||
nf7util_log_debug("lazy initialization succeeded");
|
|
||||||
|
|
||||||
EXIT:
|
|
||||||
uv_idle_stop(idle);
|
|
||||||
uv_close((uv_handle_t*) idle, idle_close_);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void idle_close_(uv_handle_t* handle) {
|
|
||||||
assert(nullptr != handle);
|
|
||||||
|
|
||||||
struct nf7* nf7 = handle->data;
|
|
||||||
assert(nullptr != nf7);
|
|
||||||
|
|
||||||
nf7util_malloc_free(nf7->malloc, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct nf7_mod_meta nf7core_any = {
|
const struct nf7_mod_meta nf7core_any = {
|
||||||
.name = (const uint8_t*) "nf7core_any",
|
.name = (const uint8_t*) "nf7core_any",
|
||||||
.desc = (const uint8_t*) "executes any things",
|
.desc = (const uint8_t*) "executes any things",
|
||||||
|
@ -6,15 +6,10 @@
|
|||||||
|
|
||||||
#include "nf7.h"
|
#include "nf7.h"
|
||||||
|
|
||||||
#include <uv.h>
|
|
||||||
|
|
||||||
#include "core/exec/idea.h"
|
|
||||||
|
|
||||||
|
|
||||||
struct nf7core_any {
|
struct nf7core_any {
|
||||||
struct nf7_mod super;
|
struct nf7_mod super;
|
||||||
|
|
||||||
struct nf7util_malloc* malloc;
|
struct nf7util_malloc* malloc;
|
||||||
uv_loop_t* uv;
|
|
||||||
};
|
};
|
||||||
extern const struct nf7_mod_meta nf7core_any;
|
extern const struct nf7_mod_meta nf7core_any;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "util/buffer.h"
|
#include "util/buffer.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user