-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2009 from gc87/scan-tags-v2.9
[v2.9]feat: add scan tags reqest & response
- Loading branch information
Showing
18 changed files
with
431 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* NEURON IIoT System for Industry 4.0 | ||
* Copyright (C) 2020-2022 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. | ||
**/ | ||
|
||
/* | ||
* DO NOT EDIT THIS FILE MANUALLY! | ||
* It was automatically generated by `json-autotype`. | ||
*/ | ||
|
||
#ifndef _NEU_JSON_API_NEU_JSON_SCAN_H_ | ||
#define _NEU_JSON_API_NEU_JSON_SCAN_H_ | ||
|
||
#include "json/json.h" | ||
|
||
#include "tag.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct { | ||
char *node; | ||
char *id; | ||
} neu_json_scan_tags_req_t; | ||
|
||
int neu_json_decode_scan_tags_req(char *buf, neu_json_scan_tags_req_t **result); | ||
|
||
void neu_json_decode_scan_tags_req_free(neu_json_scan_tags_req_t *req); | ||
|
||
int neu_json_encode_scan_tags_resp(void *json_object, void *param); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <stdlib.h> | ||
|
||
#include "plugin.h" | ||
#include "utils/log.h" | ||
#include "json/neu_json_fn.h" | ||
#include "json/neu_json_scan.h" | ||
|
||
#include "handle.h" | ||
#include "utils/http.h" | ||
|
||
#include "scan_handle.h" | ||
|
||
void handle_scan_tags(nng_aio *aio) | ||
{ | ||
neu_plugin_t *plugin = neu_rest_get_plugin(); | ||
|
||
NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT( | ||
aio, neu_json_scan_tags_req_t, neu_json_decode_scan_tags_req, { | ||
neu_reqresp_head_t header = { 0 }; | ||
neu_req_scan_tags_t cmd = { 0 }; | ||
int err_type; | ||
|
||
nng_http_req *nng_req = nng_aio_get_input(aio, 0); | ||
nlog_notice("<%p> req %s %s", aio, nng_http_req_get_method(nng_req), | ||
nng_http_req_get_uri(nng_req)); | ||
header.ctx = aio; | ||
header.type = NEU_REQ_SCAN_TAGS; | ||
|
||
if (NULL != req->node && NEU_NODE_NAME_LEN <= strlen(req->node)) { | ||
err_type = NEU_ERR_NODE_NAME_TOO_LONG; | ||
goto error; | ||
} | ||
|
||
if (NULL != req->id && NEU_TAG_ADDRESS_LEN <= strlen(req->id)) { | ||
err_type = NEU_ERR_NODE_NAME_TOO_LONG; | ||
goto error; | ||
} | ||
|
||
if (NULL != req->node) { | ||
strcpy(cmd.driver, req->node); | ||
} | ||
|
||
if (NULL != req->id) { | ||
strcpy(cmd.id, req->id); | ||
} | ||
|
||
if (0 != neu_plugin_op(plugin, header, &cmd)) { | ||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, { | ||
neu_http_response(aio, NEU_ERR_IS_BUSY, result_error); | ||
}); | ||
} | ||
goto success; | ||
|
||
error: | ||
NEU_JSON_RESPONSE_ERROR( | ||
err_type, { neu_http_response(aio, err_type, result_error); }); | ||
|
||
success:; | ||
}) | ||
} | ||
|
||
void handle_scan_tags_resp(nng_aio *aio, neu_resp_scan_tags_t *resp) | ||
{ | ||
char *result = NULL; | ||
neu_json_encode_by_fn(resp, neu_json_encode_scan_tags_resp, &result); | ||
neu_http_ok(aio, result); | ||
free(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* NEURON IIoT System for Industry 4.0 | ||
* Copyright (C) 2020-2022 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_SCAN_HANDLE_H_ | ||
#define _NEU_ACAN_HANDLE_H_ | ||
|
||
#include <nng/nng.h> | ||
|
||
void handle_scan_tags(nng_aio *aio); | ||
void handle_scan_tags_resp(nng_aio *aio, neu_resp_scan_tags_t *resp); | ||
void handle_scan_tag(nng_aio *aio); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.