diff --git a/conf/cert_store.ini b/conf/cert_store.ini index f79ed39..c61b5b6 100644 --- a/conf/cert_store.ini +++ b/conf/cert_store.ini @@ -4,9 +4,9 @@ DEBUG_SWITCH = 1 #10:DEBUG, 20:INFO, 30:FATAL RUN_LOG_LEVEL = 10 -RUN_LOG_PATH = ./logs/ +RUN_LOG_PATH = ./logs [CONFIG] -thread-nu = 2 +thread-nu = 1 ca-path = ../ca valid-days = 30 [LIBEVENT] diff --git a/make/application.mk b/make/application.mk index 57f6aa4..2b31ae8 100644 --- a/make/application.mk +++ b/make/application.mk @@ -2,7 +2,7 @@ $(OBJ_DIR): mkdir $(OBJ_DIR) - #mkdir $(OBJ_DIR_CPP) + mkdir $(OBJ_DIR_CPP) # applications object suffix rule @@ -12,21 +12,21 @@ $(OBJ_DIR)/%.o: %.c $(OBJ_DIR)/%.o: %.S $(ASSEMBLE) -#$(OBJ_DIR_CPP)/%.o: %.cpp -# $(CPPCOMPILE) +$(OBJ_DIR_CPP)/%.o: %.cpp + $(CPPCOMPILE) # application config check and rules -include $(OBJS:.o=.d) -#-include $(OBJS_CPP:.o=.d) +-include $(OBJS_CPP:.o=.d) application-target: $(TARGET) -#$(TARGET): $(OBJ_DIR) $(OBJS) $(LIBS_LIST) $(OBJ_DIR_CPP) $(OBJS_CPP) -# $(CC) -o $@ $(OBJS) $(OBJS_CPP) $(LDFLAGS_PATH) $(LIBS_LIST) $(LDFLAGS_GLOBAL) +$(TARGET): $(OBJ_DIR) $(OBJS) $(LIBS_LIST) $(OBJ_DIR_CPP) $(OBJS_CPP) + $(CC) -o $@ $(OBJS) $(OBJS_CPP) $(LDFLAGS_PATH) $(LIBS_LIST) $(LDFLAGS_GLOBAL) -$(TARGET): $(OBJ_DIR) $(OBJS) $(LIBS_LIST) - $(CC) -o $@ $(OBJS) $(LDFLAGS_PATH) $(LIBS_LIST) $(LDFLAGS_GLOBAL) +#$(TARGET): $(OBJ_DIR) $(OBJS) $(LIBS_LIST) +# $(CC) -o $@ $(OBJS) $(LDFLAGS_PATH) $(LIBS_LIST) $(LDFLAGS_GLOBAL) $(TARGET).stp: $(TARGET) $(STRIP) -o $(TARGET).stp $(TARGET) diff --git a/make/common.mk b/make/common.mk index 1c5c22d..f4e664e 100644 --- a/make/common.mk +++ b/make/common.mk @@ -32,13 +32,13 @@ STRIP = strip OBJDUMP = objdump NM = nm -#CPP = g++ +CPP = g++ # build object directory OBJ_DIR = obj$(PREFIX) -#OBJ_DIR_CPP = obj$(PREFIX)/cpp +OBJ_DIR_CPP = obj$(PREFIX)/cpp # standard compile line @@ -48,4 +48,4 @@ ASSEMBLE = $(CC) $(ASFLAGS_GLOBAL) $(ASFLAGS_LOCAL) -MD -c -o $@ $< MYARCHIVE = $(AR) -cr $@ $< -#CPPCOMPILE = $(CPP) $(CFLAGS_GLOBAL) $(CFLAGS_LOCAL) -MD -c -o $@ $< +CPPCOMPILE = $(CPP) $(CFLAGS_GLOBAL) $(CFLAGS_LOCAL) -MD -c -o $@ $< diff --git a/src/Makefile b/src/Makefile index 2404d2a..e902554 100644 --- a/src/Makefile +++ b/src/Makefile @@ -40,8 +40,12 @@ dir := ./rt include $(dir)/rt.mk OBJS += $(OBJS_$(dir)) +dir := ./inc +include $(dir)/inc.mk +OBJS += $(OBJS_$(dir)) + LDFLAGS_GLOBAL += -L ./lib -lapps -lcrypto -lssl -levent -lhiredis -lMESA_htable -LDFLAGS_GLOBAL += -L ./lib -lMESA_htable -lMESA_handle_logger -lMESA_prof_load +LDFLAGS_GLOBAL += -L ./lib -lMESA_htable -lMESA_field_stat2 -lMESA_handle_logger -lMESA_prof_load LDFLAGS_GLOBAL += \ -lpthread -lcrypt -lm -lz -ldl -lstdc++ diff --git a/src/cert_session.c b/src/cert_session.c index 4d06445..5b96c5b 100644 --- a/src/cert_session.c +++ b/src/cert_session.c @@ -36,6 +36,7 @@ #include "http.h" #include "buffer.h" #include "util-internal.h" +#include "moodycamel_field_stat2.h" #include "logging.h" #define SG_DATA_SIZE 2048 @@ -45,6 +46,16 @@ static libevent_thread *threads; +struct fs_stats_t{ + int line_ids[3]; + screen_stat_handle_t handle; +}; + +static struct fs_stats_t SGstats = { + .line_ids = {0}, + .handle = NULL, +}; + #define sizeof_seconds(x) (x * 24 * 60 * 60) void connectCallback(const struct redisAsyncContext *c, int status) { @@ -63,56 +74,6 @@ void disconnectCallback(const struct redisAsyncContext *c, int status) { printf("Redis server disconnected...\n"); } -static rt_mutex *mutex_buf = NULL; - -static unsigned long pthreads_thread_id(void) -{ - return ((unsigned long)pthread_self()); -} - -static void pthreads_locking_callback(int mode, int n, const char __attribute__((__unused__))*file, - int __attribute__((__unused__))line) -{ - if(mode & CRYPTO_LOCK) - rt_mutex_lock(&(mutex_buf[n])); - else - rt_mutex_unlock(&(mutex_buf[n])); -} - -int thread_setup(void) -{ - int i; - - mutex_buf = malloc(CRYPTO_num_locks() * sizeof(rt_mutex)); - if(!mutex_buf) - return 0; - - for(i = 0; i < CRYPTO_num_locks(); i++) - rt_mutex_init(&(mutex_buf[i]), NULL); - - CRYPTO_set_id_callback(pthreads_thread_id); - CRYPTO_set_locking_callback(pthreads_locking_callback); - return 1; -} - -int thread_cleanup(void) -{ - int i; - - if(!mutex_buf) - return 0; - - CRYPTO_set_id_callback(NULL); - CRYPTO_set_locking_callback(NULL); - - for(i = 0; i < CRYPTO_num_locks(); i++) - rt_mutex_destroy(&(mutex_buf[i])); - - free(mutex_buf); - mutex_buf = NULL; - return 1; -} - int ssl_rand(void *p, size_t sz) { @@ -607,7 +568,7 @@ int cert_redis_init(struct event_base *base, struct redisAsyncContext **cl_ctx) struct config_bucket_t *redis = cert_default_config(); *cl_ctx = redisAsyncConnect(redis->r_ip, redis->r_port); - if((*cl_ctx)->err) { + if((*cl_ctx)->err ) { mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Redis Connect error : %s", (*cl_ctx)->errstr); goto finish; } @@ -621,7 +582,7 @@ finish: } static void -setCallback(redisAsyncContext __attribute__((__unused__))*c, void *r, +rd_set_callback(redisAsyncContext __attribute__((__unused__))*c, void *r, void *privdata) { redisReply *reply = (redisReply*)r; @@ -672,7 +633,7 @@ release_resources(struct cert_trapper_t *certCtx, char *cert, char *pubkey, int } #endif -int x509_mkcert(char *host, EVP_PKEY *key, X509 *root, char *ca_s, char *pubkey) +int x509_online_append(char *host, EVP_PKEY *key, X509 *root, char *ca_s, char *pubkey) { int xret = -1; struct config_bucket_t *rte = cert_default_config(); @@ -682,7 +643,7 @@ int x509_mkcert(char *host, EVP_PKEY *key, X509 *root, char *ca_s, char *pubkey) goto finish; } X509* x509 = x509_modify_by_cert(root, key, ca, X509_get_pubkey(root), - rte->days, NULL, NULL); + rte->days, NULL, NULL); if (!x509){ goto err; } @@ -696,7 +657,8 @@ finish: return xret; } -int create_x509(struct request_t *request, redisAsyncContext *c, char *sendbuf) +static int +rd_decode_sendbuf(struct request_t *request, redisAsyncContext *c, char *sendbuf) { int xret = -1; @@ -705,27 +667,47 @@ int create_x509(struct request_t *request, redisAsyncContext *c, char *sendbuf) struct config_bucket_t *rte = cert_default_config(); char cert[SG_DATA_SIZE] = {0}, pubkey[SG_DATA_SIZE] = {0}; - x509_mkcert(request->host, thread->key, thread->root, cert, pubkey); + x509_online_append(request->host, thread->key, thread->root, cert, pubkey); if (cert[0] == '\0' && pubkey[0] == '\0'){ mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to issue certificate"); - evhttp_send_error(request->evh_req, HTTP_BADREQUEST, 0); + evhttp_send_error(request->evh_req, HTTP_NOTFOUND, 0); goto finish; } - CA_SIGN_ADD(1); + + FS_internal_operate(SGstats.handle,thread->column_ids,thread->field_ids,SGstats.line_ids[2], FS_OP_ADD, 1); + snprintf(sendbuf, SG_DATA_SIZE * 2, "%s%s", pubkey, cert); - xret = redisAsyncCommand(c, setCallback, request->host, "SETEX %s %d %s", + xret = redisAsyncCommand(c, rd_set_callback, request->host, "SETEX %s %d %s", request->host, sizeof_seconds(rte->days), sendbuf); if (xret < 0){ mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to set information to redis server"); goto finish; } - xret = 0; + + xret = 0; finish: return xret; } -void getCallback(redisAsyncContext *c, void *r, void *privdata) +static int +rd_encode_sendbuf(struct request_t *request, redisReply *reply, char *sendbuf) +{ + int xret = -1; + libevent_thread *thread = threads + request->thread_id; + + if (reply && reply->str){ + FS_internal_operate(SGstats.handle,thread->column_ids,thread->field_ids,SGstats.line_ids[1],FS_OP_ADD,1); + snprintf(sendbuf, SG_DATA_SIZE * 2, "%s", reply->str); + xret = 0; + } + else{ + evhttp_send_error(request->evh_req, HTTP_BADREQUEST, 0); + } + return xret; +} + +void rd_get_callback(redisAsyncContext *c, void *r, void *privdata) { int xret = -1; char sendbuf[SG_DATA_SIZE * 2] = {0}; @@ -737,18 +719,15 @@ void getCallback(redisAsyncContext *c, void *r, void *privdata) switch(reply->type){ case REDIS_REPLY_STRING: mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Sends the certificate information to the requestor"); - CA_STORE_ADD(1); - if (reply->str != NULL){ - snprintf(sendbuf, SG_DATA_SIZE * 2, "%s", reply->str); - xret = 0; - }else{ - evhttp_send_error(request->evh_req, HTTP_BADREQUEST, 0); - } + + xret = rd_encode_sendbuf(request, reply, sendbuf); break; + case REDIS_REPLY_NIL: /* Certificate information modification and Strategy to judge**/ mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Generating certificate information"); - xret = create_x509(request, c, sendbuf); + + xret = rd_decode_sendbuf(request, c, sendbuf); break; default: break; @@ -836,7 +815,7 @@ int cert_session_finish() #endif static int -sample_decode_uri(const char *uri, char *host, +rt_decode_uri(const char *uri, char *host, int *flag, int *valid) { const char *fg = NULL, *vl = NULL; @@ -865,6 +844,17 @@ finish: return 0; } +static void +evhttp_socket_close_cb(struct evhttp_connection *evcon, + void __attribute__((__unused__))*arg) +{ + if (NULL == evcon){ + goto finish; + } +finish: + return; +} + void pthread_work_proc(struct evhttp_request *evh_req, void *arg) { @@ -872,9 +862,11 @@ pthread_work_proc(struct evhttp_request *evh_req, void *arg) const char *cmdtype; struct request_t *request = NULL; struct evhttp_uri *decoded = NULL; - libevent_thread *thread_info = (libevent_thread *)arg; + /* we want to know if this connection closes on us */ + evhttp_connection_set_closecb(evhttp_request_get_connection(evh_req), evhttp_socket_close_cb, NULL); + const char *uri = evhttp_request_get_uri(evh_req); /* Decode the URI */ decoded = evhttp_uri_parse(uri); @@ -882,6 +874,7 @@ pthread_work_proc(struct evhttp_request *evh_req, void *arg) mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "It's not a good URI. Sending BADREQUEST\n"); goto error; } + request = (struct request_t *) kmalloc (sizeof(struct request_t), MPF_CLR, -1); if (request != NULL){ request->thread_id = thread_info->id; @@ -900,28 +893,30 @@ pthread_work_proc(struct evhttp_request *evh_req, void *arg) case EVHTTP_REQ_PATCH: cmdtype = "PATCH"; break; default: cmdtype = "unknown"; break; } + FS_internal_operate(SGstats.handle,thread_info->column_ids,-1,SGstats.line_ids[0], FS_OP_ADD, 1); - WEB_REQUEST_ADD(1); - sample_decode_uri(uri, request->host, &request->flag, &request->valid); + rt_decode_uri(uri, request->host, &request->flag, &request->valid); mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "[Thread %d]Received a %s request for %s, host:%s, flag:%d, valid:%d\nHeaders:", request->thread_id, cmdtype, uri, request->host, request->flag, request->valid); if (request->host[0] != '\0' && request->evh_req != NULL){ - xret = redisAsyncCommand(thread_info->cl_ctx, getCallback, request, "GET %s", request->host); - if (xret < 0){ + + xret = redisAsyncCommand(thread_info->cl_ctx, rd_get_callback, request, "GET %s", request->host); + if (xret < 0) mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Failed to get information from redis server"); - } - }else{ + } + else { kfree(request); evhttp_uri_free(decoded); goto error; } + evhttp_uri_free(decoded); goto finish; error: - evhttp_send_error(evh_req, HTTP_BADREQUEST, 0); + evhttp_send_error(evh_req, HTTP_NOTFOUND, 0); finish: return; } @@ -1032,30 +1027,22 @@ err: return fd; } -void * do_perform_monitor(void __attribute__((__unused__))*_thread_id) +static int +fs_screen_preview(libevent_thread *thread) { -#define EVAL_TM_STYLE_FULL "%Y-%m-%d %H:%M:%S" - char tm[64] = {0}; - int64_t web_req; - int64_t ca_store, ca_sign; + char buff[128] = {0}; - do{ - web_req = WEB_REQUEST_ADD(0); - ca_store = CA_STORE_ADD(0); - ca_sign = CA_SIGN_ADD(0); + snprintf(buff, sizeof(buff),"Thread_%02d", thread->id); + thread->field_ids = FS_internal_register(SGstats.handle, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); - rt_curr_tms2str(EVAL_TM_STYLE_FULL, tm, 63); - printf("%s Web Req=%ld, Ca Total=%ld\n", tm, web_req, ca_store + ca_sign); - printf("\tCa store=%ld, sign=%ld\n", - ca_store, ca_sign); + snprintf(buff, sizeof(buff),"Thread_%d", thread->id); + thread->column_ids = FS_internal_register(SGstats.handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); - sleep(5); - }while(1); - - return NULL; + return 0; } -int libevent_socket_init() +static int +libevent_socket_init() { struct sockaddr_in sin; evutil_socket_t accept_fd = -1; @@ -1077,15 +1064,12 @@ int libevent_socket_init() goto finish; } - /* one way to set the necessary OpenSSL locking callbacks if you want to do - multi-threaded transfers with HTTPS/FTPS built to use OpenSSL **/ - thread_setup(); - threads = calloc(thread_nu, sizeof(libevent_thread)); if (! threads) { mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Can't allocate thread descriptors"); goto finish; } + memset(threads, 0, thread_nu * sizeof(libevent_thread)); /* Create threads after we've done all the libevent setup. */ for (tid = 0; tid < thread_nu; tid++) { @@ -1095,6 +1079,8 @@ int libevent_socket_init() thread->accept_fd = accept_fd; thread->routine = pthread_worker_libevent; + fs_screen_preview(thread); + if (pthread_create(&thread->pid, thread->attr, thread->routine, &threads[tid])){ mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "%s", strerror(errno)); goto finish; @@ -1106,26 +1092,73 @@ int libevent_socket_init() } } - rt_pthread perform; - long thread_id = 5; - pthread_create(&perform, NULL, do_perform_monitor, (void *) thread_id); - - void * per_res; - pthread_join(perform, &per_res); - FOREVER{ sleep(1); } - - thread_cleanup(); finish: return xret; } +static void +rt_get_pname_by_pid(pid_t pid, char *task_name) +{ +#define BUF_SIZE 1024 + char proc_pid_path[BUF_SIZE]; + char buf[BUF_SIZE]; + sprintf(proc_pid_path, "/proc/%d/status", pid); + FILE* fp = fopen(proc_pid_path, "r"); + if(NULL != fp){ + if( fgets(buf, BUF_SIZE-1, fp)== NULL ){ + fclose(fp); + } + fclose(fp); + sscanf(buf, "%*s %s", task_name); + } +} + +static int +fs_screen_init() +{ + int value=0; + char stat_path[63] = {0}; + char pname[32]= {0}, buff[128] = {0}; + + SGstats.handle = FS_internal_create_handle(); + + rt_get_pname_by_pid(getpid(), &pname[0]); + FS_internal_set_para(SGstats.handle, APP_NAME, pname, strlen(pname)+1); + value=0; + FS_internal_set_para(SGstats.handle, FLUSH_BY_DATE, &value, sizeof(value)); + + snprintf(stat_path, 63, "%s/fs2_%s.status", logging_sc_lid.run_log_path, pname); + FS_internal_set_para(SGstats.handle, OUTPUT_DEVICE, stat_path, strlen(stat_path)+1); + value=1; + FS_internal_set_para(SGstats.handle, PRINT_MODE, &value, sizeof(value)); + value=1; + FS_internal_set_para(SGstats.handle, CREATE_THREAD, &value, sizeof(value)); + value=3; + FS_internal_set_para(SGstats.handle, STAT_CYCLE, &value, sizeof(value)); + + snprintf(buff,sizeof(buff),"%s", "req"); + SGstats.line_ids[0] = FS_internal_register(SGstats.handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); + + snprintf(buff,sizeof(buff),"%s", "store"); + SGstats.line_ids[1] = FS_internal_register(SGstats.handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); + + snprintf(buff,sizeof(buff),"%s", "sign"); + SGstats.line_ids[2] = FS_internal_register(SGstats.handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); + + FS_internal_start(SGstats.handle); + + return 0; +} + int cert_session_init() { int xret = 0; + fs_screen_init(); + libevent_socket_init(); return xret; diff --git a/src/cert_session.h b/src/cert_session.h index abdb7a4..2512707 100644 --- a/src/cert_session.h +++ b/src/cert_session.h @@ -44,22 +44,13 @@ typedef struct { struct redisAsyncContext *cl_ctx; void * (*routine)(void *); /** Executive entry */ + + int field_ids; /* dispaly */ + + int column_ids; } libevent_thread; -struct rt_ca_statis{ - atomic64_t req_url; - atomic64_t ca_store, ca_sign; -}; - -struct rt_ca_statis ca_writer; - -#define WEB_REQUEST_ADD(n) atomic64_add(&ca_writer.req_url, n); -#define CA_STORE_ADD(n) atomic64_add(&ca_writer.ca_store, n); -#define CA_SIGN_ADD(n) atomic64_add(&ca_writer.ca_sign, n); - extern int cert_session_init(); -extern int cert_session_finish(); - #endif diff --git a/src/cert_store.c b/src/cert_store.c index d2d6216..e4e2b3a 100644 --- a/src/cert_store.c +++ b/src/cert_store.c @@ -1,7 +1,7 @@ /************************************************************************* > File Name: cert_server.c > Author: fengweihao - > Mail: fengweihao158@163.com + > Mail: > Created Time: Tue 29 May 2018 06:45:23 PM PDT ************************************************************************/ diff --git a/src/components/syslogd/logging.c b/src/components/syslogd/logging.c index 9cfa2f0..68fc3fc 100644 --- a/src/components/syslogd/logging.c +++ b/src/components/syslogd/logging.c @@ -22,7 +22,7 @@ #include "MESA_prof_load.h" #include "MESA_handle_logger.h" -void rt_get_pname_by_pid(pid_t pid, char *task_name) +static void rt_get_pname_by_pid(pid_t pid, char *task_name) { #define BUF_SIZE 1024 char proc_pid_path[BUF_SIZE]; @@ -63,6 +63,8 @@ int mesa_logging_mkfile(char *file, size_t size) void cert_syslog_init(char *config) { + char run_log_path[256] = {0}; + MESA_load_profile_int_def(config, (const char *)"SYSTEM",(const char *)"DEBUG_SWITCH", &logging_sc_lid.debug_switch, 1); MESA_load_profile_int_def(config, (const char *)"SYSTEM",(const char *)"RUN_LOG_LEVEL", @@ -72,9 +74,10 @@ void cert_syslog_init(char *config) char file[64] = {0}; mesa_logging_mkfile(file, 63); - STRCAT(logging_sc_lid.run_log_path, file); + //STRCAT(logging_sc_lid.run_log_path, file); + snprintf(run_log_path, 255, "%s/%s", logging_sc_lid.run_log_path, file); - logging_sc_lid.run_log_handle = MESA_create_runtime_log_handle(logging_sc_lid.run_log_path, logging_sc_lid.run_log_level); + logging_sc_lid.run_log_handle = MESA_create_runtime_log_handle(run_log_path, logging_sc_lid.run_log_level); if(logging_sc_lid.run_log_handle == NULL){ printf("Create log runtime_log_handle error, init failed!"); goto finish; diff --git a/src/inc/field_stat2.h b/src/inc/field_stat2.h new file mode 100644 index 0000000..6b7ca4a --- /dev/null +++ b/src/inc/field_stat2.h @@ -0,0 +1,68 @@ +#ifndef H_SCREEN_STAT_H_INCLUDE +#define H_SCREEN_STAT_H_INCLUDE +#include + +#ifndef __cplusplus +#error("This file should be compiled with C++ compiler") +#endif + +enum field_dsp_style_t +{ + FS_STYLE_FIELD=0, + FS_STYLE_COLUMN, + FS_STYLE_LINE, + FS_STYLE_STATUS +}; +enum field_calc_algo +{ + FS_CALC_CURRENT=0, + FS_CALC_SPEED +}; +enum field_op +{ + FS_OP_ADD=1, + FS_OP_SET +}; + + +typedef void* screen_stat_handle_t; + +enum FS_option +{ + OUTPUT_DEVICE, //VALUE is a const char*, indicate a file path string, SIZE = strlen(string+'\0')+1.DEFAULT:output to stdout. + PRINT_MODE, //VALUE is an interger,1:Rewrite ,2: Append. SIZE=4,DEFALUT:REWRITE. + STAT_CYCLE, //VALUE is an interger idicate interval seconds of every output, SIZE=4 ,DEFUALT:2 seconds. + PRINT_TRIGGER, //VALUE is an interger,1:Do print,0: Don't print.SIZE=4.DEFAULT:1. + CREATE_THREAD, //VALUE is an interger,1: Create a print thread,0:not create,output by call passive_output function, + //and the STAT_CYCLE is meaningless.SIZE=4,DEFAULT:0. + ID_INVISBLE, //value is field_id/status_id/column_id, not output this string, SIZE=4,DEFAULT: shutdown NO one. + FLUSH_BY_DATE, //value is 1(ture) or 0(false),SIZE=4,DEFAULT: Do not flush by date. + APP_NAME, //VALUE is a const char*, MUST end with '\0', SIZE= strlen(string+'\0')+1. DEFAULT is "?". + STATS_SERVER_IP, //VALUE is a const char*, MUST end with '\0', SIZE= strlen(string+'\0')+1. No DEFAULT. + STATS_SERVER_PORT, //VALUE is a unsigned short or a signed int, host order, SIZE= sizeof(unsigned short) or sizeof(int). No DEFAULT. + MAX_STAT_FIELD_NUM //VALUE is an interger, SIZE=sizeof(int), DEFAULT:1024. +}; + +//Always success. +screen_stat_handle_t FS_create_handle(void); + +int FS_set_para(screen_stat_handle_t handle, enum FS_option type,const void* value,int size); +void FS_start(screen_stat_handle_t handle); +void FS_stop(screen_stat_handle_t* handle); + +//return field_id/line_id/column_id greater than zero if success,return an interger less than zero if failed. +//should NOT include "|:\n\r.\t<>[]#!@"or space in the parameter name. +//Runtime rregister column is NOT allowed. +int FS_register(screen_stat_handle_t handle,enum field_dsp_style_t style,enum field_calc_algo calc_type,const char* name); + +//numerator_id and denominator_id must be column/field/status style. +//scaling: negative value: zoom in; positive value: zoom out; +int FS_register_ratio(screen_stat_handle_t handle,int numerator_id,int denominator_id,int scaling,enum field_dsp_style_t style,enum field_calc_algo calc_type,const char* name); + +//id: when id's type is FIELD , column_id is ignore. +int FS_operate(screen_stat_handle_t handle,int id,int column_id,enum field_op op,long long value); + +void FS_passive_output(screen_stat_handle_t handle); + +#endif + diff --git a/src/inc/inc.mk b/src/inc/inc.mk new file mode 100644 index 0000000..43fbc58 --- /dev/null +++ b/src/inc/inc.mk @@ -0,0 +1,32 @@ + + +# standard component Makefile header +sp := $(sp).x +dirstack_$(sp) := $(d) +d := $(dir) + +# component specification + +OBJS_$(d) :=\ + $(OBJ_DIR_CPP)/moodycamel_field_stat2.o\ + + +CFLAGS_LOCAL += -I$(d) +$(OBJS_$(d)): CFLAGS_LOCAL := -std=c++11 -W -Wall -g -O3\ + -I$(d)\ + +# standard component Makefile rules + +DEPS_$(d) := $(OBJS_$(d):.o=.d) + +CLEAN_LIST := $(CLEAN_LIST) $(OBJS_$(d)) $(DEPS_$(d)) + +$(OBJ_DIR_CPP)/%.o: $(d)/%.cpp + $(CPPCOMPILE) + +-include $(DEPS_$(d)) + +# standard component Makefile footer + +d := $(dirstack_$(sp)) +sp := $(basename $(sp)) diff --git a/src/inc/moodycamel_field_stat2.cpp b/src/inc/moodycamel_field_stat2.cpp new file mode 100644 index 0000000..d872083 --- /dev/null +++ b/src/inc/moodycamel_field_stat2.cpp @@ -0,0 +1,56 @@ +/************************************************************************* + > File Name: moodycamel_field_stat2.cpp + > Author: + > Mail: + > Created Time: 2018年07月03日 星期二 16时48分52秒 + ************************************************************************/ + +#include +#include "field_stat2.h" + +using namespace std; + +extern "C" screen_stat_handle_t FS_internal_create_handle(void); +extern "C" int FS_internal_set_para(screen_stat_handle_t handle, enum FS_option type,const void* value,int size); +extern "C" void FS_internal_start(screen_stat_handle_t handle); +extern "C" int FS_internal_register(screen_stat_handle_t handle,enum field_dsp_style_t style, + enum field_calc_algo calc_type,const char* name); +extern "C" int FS_internal_operate(screen_stat_handle_t handle,int id,int id2,int column_id,enum field_op op,long long value); + +screen_stat_handle_t FS_internal_create_handle(void) +{ + return FS_create_handle(); +} + +int FS_internal_set_para(screen_stat_handle_t handle, enum FS_option type,const void* value,int size) +{ + return FS_set_para(handle, type, value, size); +} + +void FS_internal_start(screen_stat_handle_t handle) +{ + FS_start(handle); +} + +int FS_internal_register(screen_stat_handle_t handle,enum field_dsp_style_t style, + enum field_calc_algo calc_type,const char* name) +{ + return FS_register(handle, style, calc_type, name); +} + +int FS_internal_operate(screen_stat_handle_t handle,int id,int id2,int column_id,enum field_op op,long long value) +{ + int ret = -1; + + ret = FS_operate(handle, id, column_id, op, value); + if (ret < 0) + goto finish; + + if (id2 < 0) + goto finish; + + ret = FS_operate(handle, id2, 0, op, value); +finish: + return ret; +} + diff --git a/src/inc/moodycamel_field_stat2.h b/src/inc/moodycamel_field_stat2.h new file mode 100644 index 0000000..31b4a10 --- /dev/null +++ b/src/inc/moodycamel_field_stat2.h @@ -0,0 +1,58 @@ +/************************************************************************* + > File Name: moodycamel_field_stat2.h + > Author: + > Mail: + > Created Time: 2018年07月03日 星期二 16时51分41秒 + ************************************************************************/ + +#ifndef _MOODYCAMEL_FIELD_STAT2_H +#define _MOODYCAMEL_FIELD_STAT2_H + +enum field_dsp_style_t +{ + FS_STYLE_FIELD=0, + FS_STYLE_COLUMN, + FS_STYLE_LINE, + FS_STYLE_STATUS +}; +enum field_calc_algo +{ + FS_CALC_CURRENT=0, + FS_CALC_SPEED +}; +enum field_op +{ + FS_OP_ADD=1, + FS_OP_SET +}; + +typedef void* screen_stat_handle_t; + +enum FS_option +{ + OUTPUT_DEVICE, //VALUE is a const char*, indicate a file path string, SIZE = strlen(string+'\0')+1.DEFAULT:output to stdout. + PRINT_MODE, //VALUE is an interger,1:Rewrite ,2: Append. SIZE=4,DEFALUT:REWRITE. + STAT_CYCLE, //VALUE is an interger idicate interval seconds of every output, SIZE=4 ,DEFUALT:2 seconds. + PRINT_TRIGGER, //VALUE is an interger,1:Do print,0: Don't print.SIZE=4.DEFAULT:1. + CREATE_THREAD, //VALUE is an interger,1: Create a print thread,0:not create,output by call passive_output function, + //and the STAT_CYCLE is meaningless.SIZE=4,DEFAULT:0. + ID_INVISBLE, //value is field_id/status_id/column_id, not output this string, SIZE=4,DEFAULT: shutdown NO one. + FLUSH_BY_DATE, //value is 1(ture) or 0(false),SIZE=4,DEFAULT: Do not flush by date. + APP_NAME, //VALUE is a const char*, MUST end with '\0', SIZE= strlen(string+'\0')+1. DEFAULT is "?". + STATS_SERVER_IP, //VALUE is a const char*, MUST end with '\0', SIZE= strlen(string+'\0')+1. No DEFAULT. + STATS_SERVER_PORT, //VALUE is a unsigned short or a signed int, host order, SIZE= sizeof(unsigned short) or sizeof(int). No DEFAULT. + MAX_STAT_FIELD_NUM //VALUE is an interger, SIZE=sizeof(int), DEFAULT:1024. +}; + +screen_stat_handle_t FS_internal_create_handle(void); + +int FS_internal_set_para(screen_stat_handle_t handle, enum FS_option type,const void* value,int size); + +void FS_internal_start(screen_stat_handle_t handle); + +int FS_internal_register(screen_stat_handle_t handle,enum field_dsp_style_t style, + enum field_calc_algo calc_type,const char* name); + +int FS_internal_operate(screen_stat_handle_t handle,int id,int id2,int column_id,enum field_op op,long long value); + +#endif diff --git a/src/lib/libMESA_field_stat2.a b/src/lib/libMESA_field_stat2.a new file mode 100644 index 0000000..bc1b2c2 Binary files /dev/null and b/src/lib/libMESA_field_stat2.a differ diff --git a/src/rt/rt_string.h b/src/rt/rt_string.h index 2a3f3ca..f37b368 100644 --- a/src/rt/rt_string.h +++ b/src/rt/rt_string.h @@ -62,5 +62,4 @@ static inline void atomic_set(atomic_t *v, int32_t val) { v->counter = val; } - #endif