fix compile warning and add json

This commit is contained in:
fengzero
2021-08-05 17:43:00 +08:00
committed by Parker Liu
parent f30dc14e1a
commit dc693c2b84
8 changed files with 82 additions and 31 deletions
+6 -1
View File
@@ -15,6 +15,9 @@ set(CMAKE_C_FLAGS "$ENV{CFLAGS} -Wall -Wextra")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O2")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0 -fsanitize=address -fno-stack-protector -fno-omit-frame-pointer -fno-var-tracking")
if(NOT DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE INTERNAL "No dev warnings")
endif()
add_subdirectory(extern/vector)
add_subdirectory(extern/libcsptr)
@@ -22,6 +25,7 @@ configure_file(extern/vector/vector.h ${CMAKE_SOURCE_DIR}/include/vector.h
COPYONLY)
# Call this from your own project's makefile.
find_package(nng CONFIG REQUIRED)
find_package(Threads)
@@ -55,7 +59,8 @@ set(NEURON_BASE_SOURCES
src/utils/mem_alloc.c
src/utils/idhash.c
src/utils/panic.c
src/utils/log.c)
src/utils/log.c
src/utils/json.c)
set(NEURON_BASE_INCLUDE_DIRECTORIES include)
add_library(neuron-base SHARED)
+3
View File
@@ -253,6 +253,9 @@ static int adapter_event_notify(neu_adapter_t * adapter,
{
int rv = 0;
(void) adapter;
(void) event;
log_info("Get event notify from plugin");
return rv;
}
+20 -25
View File
@@ -169,8 +169,8 @@ static void rest_job_cb(void *arg)
job->msg = nng_aio_get_msg(aio);
// We got a reply, so give it back to the server.
rv = nng_http_res_copy_data(
job->http_res, nng_msg_body(job->msg), nng_msg_len(job->msg));
rv = nng_http_res_copy_data(job->http_res, nng_msg_body(job->msg),
nng_msg_len(job->msg));
if (rv != 0) {
rest_http_fatal(job, "nng_http_res_copy_data: %s", rv);
return;
@@ -195,11 +195,8 @@ static void rest_job_cb(void *arg)
void rest_handle(nng_aio *aio)
{
struct rest_job *job;
nng_http_req * req = nng_aio_get_input(aio, 0);
nng_http_conn * conn = nng_aio_get_input(aio, 2);
const char * clen;
nng_http_req * req = nng_aio_get_input(aio, 0);
size_t sz;
nng_iov iov;
int rv;
void * data;
@@ -214,17 +211,13 @@ void rest_handle(nng_aio *aio)
return;
}
const char *uri = nng_http_req_get_uri(req);
log_debug("get http uri: %s", uri);
const char *uri = nng_http_req_get_uri(req);
const char *method = nng_http_req_get_method(req);
log_debug("get http method: %s", method);
const char *header = nng_http_req_get_header(req, "Content-Type");
log_debug("get http header: Content-Type: %s", header);
const char *token = nng_http_req_get_header(req, "Authorization");
log_debug("get http header: Authorization: %s", token);
const char *token = nng_http_req_get_header(req, "Authorization");
log_debug(
"get http uri: %s, method: %s, Content-type: %s, Authorization: %s",
uri, method, header, token);
nng_http_req_get_data(req, &data, &sz);
job->http_aio = aio;
@@ -359,6 +352,8 @@ void web_server(void *arg)
int rv;
nng_msg * msg;
(void) arg;
if (((rv = nng_rep0_open(&s)) != 0) ||
((rv = nng_listen(s, INPROC_URL, NULL, 0)) != 0)) {
fatal("unable to set up inproc", rv);
@@ -440,7 +435,6 @@ void web_server(void *arg)
// adapter_callbacks_t cb_funs;
// };
// static uint32_t adapter_get_req_id(neu_adapter_t *adapter)
// {
// uint32_t req_id;
@@ -553,7 +547,6 @@ void web_server(void *arg)
// return;
// }
// static int adapter_response(neu_adapter_t *adapter, neu_response_t *resp)
// {
// int rv = 0;
@@ -579,8 +572,8 @@ void web_server(void *arg)
// message_t *pay_msg;
// pay_msg = (message_t *) nng_msg_body(msg);
// msg_external_data_init(pay_msg, MSG_DATA_NEURON_DATABUF, databuf);
// nng_sendmsg(adapter->sock, msg, 0);
// msg_external_data_init(pay_msg, MSG_DATA_NEURON_DATABUF,
// databuf); nng_sendmsg(adapter->sock, msg, 0);
// }
// core_databuf_put(databuf);
// break;
@@ -601,7 +594,8 @@ void web_server(void *arg)
// return rv;
// }
// static const adapter_callbacks_t callback_funs = { .response = adapter_response,
// static const adapter_callbacks_t callback_funs = { .response =
// adapter_response,
// .event_notify = adapter_event_notify };
// neu_adapter_t *neu_adapter_create(neu_adapter_info_t *info)
@@ -652,8 +646,8 @@ void web_server(void *arg)
// /** no need plugin
// void * handle;
// neu_plugin_module_t *plugin_module;
// handle = load_plugin_library(adapter->plugin_lib_name, &plugin_module);
// if (handle == NULL) {
// handle = load_plugin_library(adapter->plugin_lib_name,
// &plugin_module); if (handle == NULL) {
// neu_panic("Can't to load library(%s) for plugin(%s)",
// adapter->plugin_lib_name, adapter->name);
// }
@@ -662,9 +656,10 @@ void web_server(void *arg)
// adapter->plugin_module = plugin_module;
// neu_plugin_t *plugin;
// plugin_module = adapter->plugin_module;
// plugin = plugin_module->intf_funs->open(adapter, &callback_funs);
// if (plugin == NULL) {
// neu_panic("Can't to open plugin(%s)", plugin_module->module_name);
// plugin = plugin_module->intf_funs->open(adapter,
// &callback_funs); if (plugin == NULL) {
// neu_panic("Can't to open plugin(%s)",
// plugin_module->module_name);
// }
// */
+8 -2
View File
@@ -276,6 +276,8 @@ static int manager_add_config(neu_manager_t *manager)
{
int rv = 0;
(void) manager;
return rv;
}
@@ -286,6 +288,8 @@ static void manager_bind_adapter(nng_pipe p, nng_pipe_ev ev, void *arg)
neu_manager_t * manager;
adapter_reg_entity_t *reg_entity;
(void) ev;
adapter = (neu_adapter_t *) arg;
manager = neu_adapter_get_manager(adapter);
nng_mtx_lock(manager->adapters_mtx);
@@ -312,6 +316,8 @@ static void manager_unbind_adapter(nng_pipe p, nng_pipe_ev ev, void *arg)
neu_manager_t * manager;
adapter_reg_entity_t *reg_entity;
(void) ev;
adapter = (neu_adapter_t *) arg;
manager = neu_adapter_get_manager(adapter);
nng_mtx_lock(manager->adapters_mtx);
@@ -442,7 +448,7 @@ static int manager_stop_adapter(neu_manager_t *manager, neu_adapter_t *adapter)
static int register_default_plugins(neu_manager_t *manager)
{
int rv = 0;
int i, j;
uint i, j;
plugin_id_t plugin_id;
const plugin_reg_param_t *reg_param;
@@ -479,7 +485,7 @@ static void unregister_all_reg_plugins(neu_manager_t *manager)
// Call this function before start manager loop, so it don't need lock
static void add_and_start_default_adapters(neu_manager_t *manager)
{
int i;
uint i;
adapter_id_t id;
neu_adapter_t *p_adapter;
+1
View File
@@ -428,5 +428,6 @@ int plugin_manager_get_reg_info_by_name(plugin_manager_t * plugin_mng,
void plugin_manager_dump(plugin_manager_t *plugin_mng)
{
// TODO: dump system plugins and custom plugins
(void) plugin_mng;
return;
}
+1 -3
View File
@@ -32,7 +32,6 @@
#include "neu_log.h"
#include "neu_panic.h"
#include "utils/idhash.h"
#include "adapter/web_server.h"
static nng_thread *web_thread;
static nng_mtx * log_mtx;
@@ -62,7 +61,6 @@ static void init()
}
// log_set_quiet(true);
log_add_fp(g_logfile, LOG_DEBUG);
}
static void uninit()
@@ -125,7 +123,7 @@ int main(int argc, char *argv[])
rest_start(DEFAULT_PORT);
neu_manager_t *manager;
log_info("running neuron main process");
log_info("running neuron main process, daemon: %d", is_daemon);
manager = neu_manager_create();
if (manager == NULL) {
log_error("Failed to create neuron manager, exit!");
+20
View File
@@ -0,0 +1,20 @@
/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#include "json.h"
+23
View File
@@ -0,0 +1,23 @@
/**
* NEURON IIoT System for Industry 4.0
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#ifndef _NEU_JSON__H_
#define _NEU_JSON_H_
#endif