This repository has been archived by the owner on Dec 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): Refactor configuration variables
Refactor configuration variables for future cli and file config feature. This also enable logger helper to record initializations and destroys.
- Loading branch information
Yu Wei Wu
committed
Mar 21, 2019
1 parent
0668526
commit d04fdb6
Showing
5 changed files
with
148 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "config.h" | ||
#include "utils/logger_helper.h" | ||
|
||
#define CONFIG_LOGGER_ID "config" | ||
|
||
static logger_id_t logger_id; | ||
|
||
status_t ta_config_init(ta_config_t* const info, iota_config_t* const config, | ||
iota_client_service_t* const service) { | ||
status_t ret = SC_OK; | ||
if (info == NULL || config == NULL || service == NULL) { | ||
return SC_TA_NULL; | ||
} | ||
|
||
logger_id = logger_helper_enable(CONFIG_LOGGER_ID, LOGGER_DEBUG, true); | ||
log_info(logger_id, "[%s:%d] enable logger %s.\n", __func__, __LINE__, | ||
CONFIG_LOGGER_ID); | ||
|
||
log_info(logger_id, "Initializing TA information\n"); | ||
info->version = TA_VERSION; | ||
info->host = TA_HOST; | ||
info->port = TA_PORT; | ||
info->thread_count = TA_THREAD_COUNT; | ||
|
||
log_info(logger_id, "Initializing IRI configuration\n"); | ||
config->depth = DEPTH; | ||
config->mwm = MWM; | ||
config->seed = SEED; | ||
|
||
log_info(logger_id, "Initializing IRI connection\n"); | ||
service->http.path = "/"; | ||
service->http.content_type = "application/json"; | ||
service->http.accept = "application/json"; | ||
service->http.host = IRI_HOST; | ||
service->http.port = IRI_PORT; | ||
service->http.api_version = 1; | ||
service->serializer_type = SR_JSON; | ||
if (iota_client_core_init(service)) { | ||
log_critical(logger_id, "Initializing IRI connection failed!\n"); | ||
ret = SC_TA_OOM; | ||
} | ||
iota_client_extended_init(); | ||
|
||
return ret; | ||
} | ||
|
||
void ta_config_destroy(iota_client_service_t* const service) { | ||
log_info(logger_id, "Destroying IRI connection\n"); | ||
iota_client_extended_destroy(); | ||
iota_client_core_destroy(service); | ||
logger_helper_release(logger_id); | ||
} |
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