为提高性能,改用c替换原本的flask
This commit is contained in:
73
c/tools/log/log.c
Normal file
73
c/tools/log/log.c
Normal file
@ -0,0 +1,73 @@
|
||||
#include "log.h"
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int in_log(logs *log,log_manager *self)
|
||||
{
|
||||
sem_wait(&self->log_sem);//加锁
|
||||
logs *buf = self->rear;
|
||||
if(self->log == NULL){
|
||||
self->log = log;
|
||||
self->rear = log;
|
||||
return 0;
|
||||
}
|
||||
self->count++;
|
||||
buf->next = log;
|
||||
log->next = NULL;
|
||||
self->rear = log;
|
||||
sem_post(&self->log_sem);
|
||||
return self->count;
|
||||
}
|
||||
|
||||
logs *out_log(log_manager *self)
|
||||
{
|
||||
sem_wait(&self->log_sem);
|
||||
logs *buf = self->log;
|
||||
if(self->log->next ==NULL)
|
||||
self->log = self->rear = NULL;
|
||||
self->count--;
|
||||
sem_post(&self->log_sem);
|
||||
buf->next =NULL;
|
||||
return buf;
|
||||
}
|
||||
|
||||
//定期清理函数
|
||||
void *clear_log(void *self_p)
|
||||
{
|
||||
log_manager *self = (log_manager*)self_p;
|
||||
for(;;)
|
||||
{
|
||||
sleep(1000);
|
||||
sem_wait(&self->log_sem);
|
||||
if(self->count<256){
|
||||
sem_post(&self->log_sem);
|
||||
continue;
|
||||
}
|
||||
logs* buf = self->log;
|
||||
self->log = self->rear =NULL;
|
||||
sem_post(&self->log_sem);
|
||||
logs* tobeclear;
|
||||
while(buf->next !=NULL)
|
||||
{
|
||||
tobeclear = buf;
|
||||
buf = buf->next;
|
||||
free(tobeclear);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int init_loger(log_manager *self)
|
||||
{
|
||||
if(self == NULL)
|
||||
{
|
||||
perror("NULL\n");
|
||||
return -1;
|
||||
}
|
||||
sem_init(&self->log_sem, 0,1);
|
||||
self->in_log = in_log;
|
||||
self->out_log = out_log;
|
||||
self->clear_log = clear_log;
|
||||
self->log = NULL;
|
||||
}
|
27
c/tools/log/log.h
Normal file
27
c/tools/log/log.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef LOG
|
||||
#define LOG
|
||||
|
||||
#include <semaphore.h>
|
||||
|
||||
#define MAX_LOG 256
|
||||
|
||||
typedef struct logs
|
||||
{
|
||||
char log[1024];
|
||||
struct logs *next;
|
||||
}logs;
|
||||
|
||||
typedef struct log_manager
|
||||
{
|
||||
int (*in_log)(logs *,struct log_manager*);
|
||||
logs* (*out_log)(struct log_manager*);
|
||||
void *(*clear_log)(void*);
|
||||
sem_t log_sem;
|
||||
logs *log;
|
||||
logs *rear;
|
||||
int count;
|
||||
}log_manager;
|
||||
|
||||
int init_loger(log_manager *self);
|
||||
|
||||
#endif
|
40
c/tools/pkgmanager/pkginstall.c
Normal file
40
c/tools/pkgmanager/pkginstall.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "pkginstall.h"
|
||||
|
||||
int check_python(pkger *self)
|
||||
{
|
||||
//只需要检查pip是否存在,即可确定python是否存在
|
||||
int pip_ex = system("pip -V >/dev/null 2>&1");
|
||||
if(WIFEXITED(pip_ex) && WEXITSTATUS(pip_ex) == 0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//TO_DO 完成一下函数实现
|
||||
|
||||
int install_dependence(pkger *self)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int check_dir(pkger *self)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int packup(pkger *self)
|
||||
{
|
||||
|
||||
}//运行包安装器时执行此函数,注意所有函数通过结构体内部调用。
|
||||
|
||||
pkger *init_pkginstaller()
|
||||
{
|
||||
pkger *self = (pkger*)malloc(sizeof(pkger));
|
||||
self->check_dir = check_dir;
|
||||
self->check_python = check_python;
|
||||
self->install_dependence = install_dependence;
|
||||
self->packup = packup;
|
||||
}
|
21
c/tools/pkgmanager/pkginstall.h
Normal file
21
c/tools/pkgmanager/pkginstall.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef PKGINSTALL
|
||||
|
||||
#define PKGINSTALL
|
||||
|
||||
typedef struct pkger
|
||||
{
|
||||
//data
|
||||
int requirement;//存储requirement.txt的文件fd
|
||||
char dir[256];
|
||||
//method
|
||||
int (*check_python)(struct pkger*);
|
||||
int (*install_dependence)(struct pkger*);
|
||||
int (*check_dir)(struct pkger*);
|
||||
int (*packup)(struct pkger*);
|
||||
|
||||
}pkger;
|
||||
|
||||
pkger *init_pkginstaller();
|
||||
|
||||
|
||||
#endif
|
7
c/tools/quit/quit.c
Normal file
7
c/tools/quit/quit.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void *quit_all(void *self_d)
|
||||
{
|
||||
|
||||
}
|
6
c/tools/quit/quit.h
Normal file
6
c/tools/quit/quit.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef QUIT
|
||||
#define QUIT
|
||||
|
||||
void *quitall(int status,void *arg);
|
||||
|
||||
#endif
|
2392
c/tools/toml/toml.c
Normal file
2392
c/tools/toml/toml.c
Normal file
File diff suppressed because it is too large
Load Diff
175
c/tools/toml/toml.h
Normal file
175
c/tools/toml/toml.h
Normal file
@ -0,0 +1,175 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) CK Tan
|
||||
https://github.com/cktan/tomlc99
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#ifndef TOML_H
|
||||
#define TOML_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4996)
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define TOML_EXTERN extern "C"
|
||||
#else
|
||||
#define TOML_EXTERN extern
|
||||
#endif
|
||||
|
||||
typedef struct toml_timestamp_t toml_timestamp_t;
|
||||
typedef struct toml_table_t toml_table_t;
|
||||
typedef struct toml_array_t toml_array_t;
|
||||
typedef struct toml_datum_t toml_datum_t;
|
||||
|
||||
/* Parse a file. Return a table on success, or 0 otherwise.
|
||||
* Caller must toml_free(the-return-value) after use.
|
||||
*/
|
||||
TOML_EXTERN toml_table_t *toml_parse_file(FILE *fp, char *errbuf, int errbufsz);
|
||||
|
||||
/* Parse a string containing the full config.
|
||||
* Return a table on success, or 0 otherwise.
|
||||
* Caller must toml_free(the-return-value) after use.
|
||||
*/
|
||||
TOML_EXTERN toml_table_t *toml_parse(char *conf, /* NUL terminated, please. */
|
||||
char *errbuf, int errbufsz);
|
||||
|
||||
/* Free the table returned by toml_parse() or toml_parse_file(). Once
|
||||
* this function is called, any handles accessed through this tab
|
||||
* directly or indirectly are no longer valid.
|
||||
*/
|
||||
TOML_EXTERN void toml_free(toml_table_t *tab);
|
||||
|
||||
/* Timestamp types. The year, month, day, hour, minute, second, z
|
||||
* fields may be NULL if they are not relevant. e.g. In a DATE
|
||||
* type, the hour, minute, second and z fields will be NULLs.
|
||||
*/
|
||||
struct toml_timestamp_t {
|
||||
struct { /* internal. do not use. */
|
||||
int year, month, day;
|
||||
int hour, minute, second, millisec;
|
||||
char z[10];
|
||||
} __buffer;
|
||||
int *year, *month, *day;
|
||||
int *hour, *minute, *second, *millisec;
|
||||
char *z;
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
* Enhanced access methods
|
||||
*/
|
||||
struct toml_datum_t {
|
||||
int ok;
|
||||
union {
|
||||
toml_timestamp_t *ts; /* ts must be freed after use */
|
||||
char *s; /* string value. s must be freed after use */
|
||||
int b; /* bool value */
|
||||
int64_t i; /* int value */
|
||||
double d; /* double value */
|
||||
} u;
|
||||
};
|
||||
|
||||
/* on arrays: */
|
||||
/* ... retrieve size of array. */
|
||||
TOML_EXTERN int toml_array_nelem(const toml_array_t *arr);
|
||||
/* ... retrieve values using index. */
|
||||
TOML_EXTERN toml_datum_t toml_string_at(const toml_array_t *arr, int idx);
|
||||
TOML_EXTERN toml_datum_t toml_bool_at(const toml_array_t *arr, int idx);
|
||||
TOML_EXTERN toml_datum_t toml_int_at(const toml_array_t *arr, int idx);
|
||||
TOML_EXTERN toml_datum_t toml_double_at(const toml_array_t *arr, int idx);
|
||||
TOML_EXTERN toml_datum_t toml_timestamp_at(const toml_array_t *arr, int idx);
|
||||
/* ... retrieve array or table using index. */
|
||||
TOML_EXTERN toml_array_t *toml_array_at(const toml_array_t *arr, int idx);
|
||||
TOML_EXTERN toml_table_t *toml_table_at(const toml_array_t *arr, int idx);
|
||||
|
||||
/* on tables: */
|
||||
/* ... retrieve the key in table at keyidx. Return 0 if out of range. */
|
||||
TOML_EXTERN const char *toml_key_in(const toml_table_t *tab, int keyidx);
|
||||
/* ... returns 1 if key exists in tab, 0 otherwise */
|
||||
TOML_EXTERN int toml_key_exists(const toml_table_t *tab, const char *key);
|
||||
/* ... retrieve values using key. */
|
||||
TOML_EXTERN toml_datum_t toml_string_in(const toml_table_t *arr,
|
||||
const char *key);
|
||||
TOML_EXTERN toml_datum_t toml_bool_in(const toml_table_t *arr, const char *key);
|
||||
TOML_EXTERN toml_datum_t toml_int_in(const toml_table_t *arr, const char *key);
|
||||
TOML_EXTERN toml_datum_t toml_double_in(const toml_table_t *arr,
|
||||
const char *key);
|
||||
TOML_EXTERN toml_datum_t toml_timestamp_in(const toml_table_t *arr,
|
||||
const char *key);
|
||||
/* .. retrieve array or table using key. */
|
||||
TOML_EXTERN toml_array_t *toml_array_in(const toml_table_t *tab,
|
||||
const char *key);
|
||||
TOML_EXTERN toml_table_t *toml_table_in(const toml_table_t *tab,
|
||||
const char *key);
|
||||
|
||||
/*-----------------------------------------------------------------
|
||||
* lesser used
|
||||
*/
|
||||
/* Return the array kind: 't'able, 'a'rray, 'v'alue, 'm'ixed */
|
||||
TOML_EXTERN char toml_array_kind(const toml_array_t *arr);
|
||||
|
||||
/* For array kind 'v'alue, return the type of values
|
||||
i:int, d:double, b:bool, s:string, t:time, D:date, T:timestamp, 'm'ixed
|
||||
0 if unknown
|
||||
*/
|
||||
TOML_EXTERN char toml_array_type(const toml_array_t *arr);
|
||||
|
||||
/* Return the key of an array */
|
||||
TOML_EXTERN const char *toml_array_key(const toml_array_t *arr);
|
||||
|
||||
/* Return the number of key-values in a table */
|
||||
TOML_EXTERN int toml_table_nkval(const toml_table_t *tab);
|
||||
|
||||
/* Return the number of arrays in a table */
|
||||
TOML_EXTERN int toml_table_narr(const toml_table_t *tab);
|
||||
|
||||
/* Return the number of sub-tables in a table */
|
||||
TOML_EXTERN int toml_table_ntab(const toml_table_t *tab);
|
||||
|
||||
/* Return the key of a table*/
|
||||
TOML_EXTERN const char *toml_table_key(const toml_table_t *tab);
|
||||
|
||||
/*--------------------------------------------------------------
|
||||
* misc
|
||||
*/
|
||||
TOML_EXTERN int toml_utf8_to_ucs(const char *orig, int len, int64_t *ret);
|
||||
TOML_EXTERN int toml_ucs_to_utf8(int64_t code, char buf[6]);
|
||||
TOML_EXTERN void toml_set_memutil(void *(*xxmalloc)(size_t),
|
||||
void (*xxfree)(void *));
|
||||
|
||||
/*--------------------------------------------------------------
|
||||
* deprecated
|
||||
*/
|
||||
/* A raw value, must be processed by toml_rto* before using. */
|
||||
typedef const char *toml_raw_t;
|
||||
TOML_EXTERN toml_raw_t toml_raw_in(const toml_table_t *tab, const char *key);
|
||||
TOML_EXTERN toml_raw_t toml_raw_at(const toml_array_t *arr, int idx);
|
||||
TOML_EXTERN int toml_rtos(toml_raw_t s, char **ret);
|
||||
TOML_EXTERN int toml_rtob(toml_raw_t s, int *ret);
|
||||
TOML_EXTERN int toml_rtoi(toml_raw_t s, int64_t *ret);
|
||||
TOML_EXTERN int toml_rtod(toml_raw_t s, double *ret);
|
||||
TOML_EXTERN int toml_rtod_ex(toml_raw_t s, double *ret, char *buf, int buflen);
|
||||
TOML_EXTERN int toml_rtots(toml_raw_t s, toml_timestamp_t *ret);
|
||||
|
||||
#endif /* TOML_H */
|
Reference in New Issue
Block a user