feature: stellar dev API support stellar_new()/stellar_run()/stellar_free()/stellar_loopbreak()

This commit is contained in:
luwenpeng
2024-08-19 17:28:45 +08:00
parent 28f50b922b
commit 520eb085b8
7 changed files with 197 additions and 83 deletions

View File

@@ -1,6 +1,58 @@
#include "stellar/stellar.h"
#include <stdio.h>
#include <stddef.h>
#include <signal.h>
int main(int argc, char **argv)
#include "stellar/stellar.h"
#include "stellar_core.h"
struct stellar *st = NULL;
static void signal_handler(int signo)
{
return stellar_run(argc, argv);
if (signo == SIGINT)
{
printf("SIGINT received, notify threads to exit");
stellar_loopbreak(st);
}
if (signo == SIGQUIT)
{
printf("SIGQUIT received, notify threads to exit");
stellar_loopbreak(st);
}
if (signo == SIGTERM)
{
printf("SIGTERM received, notify threads to exit");
stellar_loopbreak(st);
}
if (signo == SIGHUP)
{
printf("SIGHUP received, reload log level !!!");
stellar_reload_log_level(st);
}
}
int main(int argc __attribute__((__unused__)), char **argv __attribute__((__unused__)))
{
const char *stellar_cfg_file = "./conf/stellar.toml";
const char *plugin_cfg_file = "./plugin/spec.toml";
const char *log_cfg_file = "./conf/log.toml";
signal(SIGINT, signal_handler);
signal(SIGQUIT, signal_handler);
signal(SIGTERM, signal_handler);
signal(SIGHUP, signal_handler);
st = stellar_new(stellar_cfg_file, plugin_cfg_file, log_cfg_file);
if (st == NULL)
{
return 0;
}
stellar_run(st);
stellar_free(st);
return 0;
}