diff --git a/common/inc/pwrbuffer.h b/common/inc/pwrbuffer.h index 0dac160fcdc38576dfc6f08a3dffeecab2f8297b..64ec25bdb9be9ad49c67c8ec295ba2165ed7baef 100644 --- a/common/inc/pwrbuffer.h +++ b/common/inc/pwrbuffer.h @@ -14,9 +14,9 @@ * **************************************************************************** */ #ifndef __POWERAPI_UTILS_H__ #define __POWERAPI_UTILS_H__ -#include "pwrmsg.h" #include #include +#include "pwrmsg.h" #define PWR_BUFFER_SIZE 64 // Ring Queue, FIFO @@ -64,7 +64,7 @@ static inline int IsFullBuffer(const PwrMsgBuffer *smb) return t == smb->head; } -ResultWaitingMsgNode *CreateResultWaitingMsgNode(); +ResultWaitingMsgNode *CreateResultWaitingMsgNode(void); void ReleaseResultWaitingMsgNode(ResultWaitingMsgNode *node); void InitResultWaitingList(ResultWaitingMsgList *rwm); void ResetResultWaitingList(ResultWaitingMsgList *rwm); diff --git a/common/inc/pwrmsg.h b/common/inc/pwrmsg.h index 3fb39d6184d8e74328efacb5cdb3bfb400191c25..00c65ca3acdb720328e05c587733800ab2b24a03 100644 --- a/common/inc/pwrmsg.h +++ b/common/inc/pwrmsg.h @@ -95,8 +95,8 @@ static inline void ReleasePwrMsg(PwrMsg **msg) PwrMsg *ClonePwrMsg(PwrMsg *msg); PwrMsg *CreateReqMsg(enum OperationType optType, uint32_t taskNo, uint32_t dataLen, char *data); -int InitMsgFactory(); -void DestroyMsgFactory(); +int InitMsgFactory(void); +void DestroyMsgFactory(void); int GenerateRspMsg(PwrMsg *req, PwrMsg *rsp, int rspCode, char *data, int dataLen); diff --git a/common/src/pwrbuffer.c b/common/src/pwrbuffer.c index cf77c714fa9ca189776edef541d9e74ce62c3779..493a2dcba5375d7e92b24e4294f29fadae1b65d7 100644 --- a/common/src/pwrbuffer.c +++ b/common/src/pwrbuffer.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: @@ -112,7 +112,7 @@ static ResultWaitingMsgNode *MoveFromList(ResultWaitingMsgList *rwm, ResultWaiti // list public======================================================================= -ResultWaitingMsgNode *CreateResultWaitingMsgNode() +ResultWaitingMsgNode *CreateResultWaitingMsgNode(void) { ResultWaitingMsgNode *node = (ResultWaitingMsgNode *)malloc(sizeof(ResultWaitingMsgNode)); if (!node) { diff --git a/common/src/pwrmsg.c b/common/src/pwrmsg.c index 550201c07e5af200261d0b17d6c4f67f88ef87df..5a0629d4ad5e21462a7a54d9260b16c8c0f0b7aa 100644 --- a/common/src/pwrmsg.c +++ b/common/src/pwrmsg.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: @@ -94,13 +94,13 @@ PwrMsg *ClonePwrMsg(PwrMsg *msg) return c; } -int InitMsgFactory() +int InitMsgFactory(void) { g_pid = getpid(); pthread_mutex_init((pthread_mutex_t *)&g_seqLock, NULL); } -void DestroyMsgFactory() +void DestroyMsgFactory(void) { pthread_mutex_destroy((pthread_mutex_t *)&g_seqLock); } diff --git a/pwrapic/inc/powerapi.h b/pwrapic/inc/powerapi.h index ed80017f80e37474e56396e5b725c55b89d7d5cf..08bb7e32b9a3f3697bdee410cb60393c7c1d3683 100644 --- a/pwrapic/inc/powerapi.h +++ b/pwrapic/inc/powerapi.h @@ -29,8 +29,8 @@ extern "C" { // common PWR_API int PWR_SetLogCallback(void(LogCallback)(int level, const char *fmt, va_list vl)); -PWR_API int PWR_Register(); -PWR_API int PWR_UnRegister(); +PWR_API int PWR_Register(void); +PWR_API int PWR_UnRegister(void); // CPU PWR_API int PWR_CPU_GetInfo(PWR_CPU_Info *cpuInfo); diff --git a/pwrapic/inc/sockclient.h b/pwrapic/inc/sockclient.h index 87bc601cd4c45084b7ad330032e9749ec2013055..a6e1aa35d8d37059d416b7500e60b0fa488a6371 100644 --- a/pwrapic/inc/sockclient.h +++ b/pwrapic/inc/sockclient.h @@ -28,8 +28,8 @@ typedef struct RspOutputParam { char *rspData; } RspOutputParam; -int InitSockClient(); -int FiniSockClient(); +int InitSockClient(void); +int FiniSockClient(void); int SendReqAndWaitForRsp(ReqInputParam input, RspOutputParam output); #endif diff --git a/pwrapic/src/powerapi.c b/pwrapic/src/powerapi.c index e20a77a9fb5f6284cb6d64d1abf13a144e4d9ed8..8bcb1c68894b61d12cdb1c77623c3bf86cdb68e9 100644 --- a/pwrapic/src/powerapi.c +++ b/pwrapic/src/powerapi.c @@ -56,7 +56,7 @@ int PWR_SetLogCallback(void(LogCallback)(int, const char *, va_list)) return -1; } -int PWR_Register() +int PWR_Register(void) { // todo: 增加必要的其他初始化动作 if (InitSockClient() != SUCCESS) { @@ -66,7 +66,7 @@ int PWR_Register() return SUCCESS; } -int PWR_UnRegister() +int PWR_UnRegister(void) { int ret = FiniSockClient(); // todo: 增加必要的其他去初始化动作 diff --git a/pwrapic/src/pwrcpu.c b/pwrapic/src/pwrcpu.c index 753693975122ab76b29ed361f6f9103a8c1af42e..5e91051b910afd32388f3ae43d90be9aa1caf156 100644 --- a/pwrapic/src/pwrcpu.c +++ b/pwrapic/src/pwrcpu.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: diff --git a/pwrapic/src/pwrdisk.c b/pwrapic/src/pwrdisk.c index 83d272245ed601c20d3de4c3e688baa4a3626e03..b3bf2754e14d5b09358c415f8cd7da04a04fe1c0 100644 --- a/pwrapic/src/pwrdisk.c +++ b/pwrapic/src/pwrdisk.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: diff --git a/pwrapic/src/pwrnet.c b/pwrapic/src/pwrnet.c index 5153242d38513afb87a6458bb4dee1cd3803f533..1f75b019efefd6ecba88d34702d3fded32630abe 100644 --- a/pwrapic/src/pwrnet.c +++ b/pwrapic/src/pwrnet.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: diff --git a/pwrapic/src/pwrusb.c b/pwrapic/src/pwrusb.c index 8e4df13e96db646195c477ec73c703f763615aa1..69eb39298c7271f223718454eeff36cb85f931bf 100644 --- a/pwrapic/src/pwrusb.c +++ b/pwrapic/src/pwrusb.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: diff --git a/pwrapic/src/sockclient.c b/pwrapic/src/sockclient.c index 4a4297fa533e906c3903334877505e503f41efa4..b6678e03c54ab980a05a4cbea69ee4fc8c49f8d3 100644 --- a/pwrapic/src/sockclient.c +++ b/pwrapic/src/sockclient.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: @@ -30,7 +30,7 @@ #define CLIENT_ADDR "pwrclient.sock." #define SERVER_ADDR "pwrserver.sock" -#define INVALID_FD -1 +#define INVALID_FD (-1) #define SOCK_THREAD_LOOP_INTERVAL 2000 // us static int g_sockFd = INVALID_FD; @@ -113,7 +113,7 @@ static void ProcessOtherMsg(PwrMsg *msg) } } -static void RecvMsgFromSocket() +static void RecvMsgFromSocket(void) { PwrMsg *msg = (PwrMsg *)malloc(sizeof(PwrMsg)); if (!msg || ReadMsg(msg, sizeof(PwrMsg)) != SUCCESS) { @@ -135,7 +135,7 @@ static void RecvMsgFromSocket() } } -static void SendMsgToSocket() +static void SendMsgToSocket(void) { int count = 0; static char data[MAX_DATA_SIZE]; @@ -171,7 +171,7 @@ static void SendMsgToSocket() } -static int CreateConnection() +static int CreateConnection(void) { int clientFd; clientFd = socket(AF_UNIX, SOCK_STREAM, 0); @@ -213,7 +213,7 @@ static int CreateConnection() return SUCCESS; } -static void *RunSocketProcess() +static void *RunSocketProcess(void* none) { fd_set recvFdSet; struct timeval tv; @@ -298,7 +298,7 @@ static int SendReqMsgAndWaitForRsp(PwrMsg *req, PwrMsg **rsp) } // public****************************************************************************************/ -int InitSockClient() +int InitSockClient(void) { InitPwrMsgBuffer(&g_sendBuff); InitPwrMsgBuffer(&g_recvBuff); @@ -324,10 +324,11 @@ int InitSockClient() return ret; } -int FiniSockClient() +int FiniSockClient(void) { FiniThreadInfo(&g_sockThread); close(g_sockFd); + g_sockFd = INVALID_FD; ResetPwrMsgBuffer(&g_sendBuff); ResetPwrMsgBuffer(&g_recvBuff); ResetResultWaitingList(&g_waitList); diff --git a/pwrapic/test/demo_main.c b/pwrapic/test/demo_main.c index 84eb39a9dbdb9cb1c4ed9ac3166055989dde4d48..84652223678d26988ace3876369fa2677c5c473e 100644 --- a/pwrapic/test/demo_main.c +++ b/pwrapic/test/demo_main.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: @@ -19,6 +19,7 @@ #include #include "powerapi.h" +#define MAIN_LOOP_INTERVAL 5 static int g_run = 1; static const char *GetLevelName(int level) @@ -53,12 +54,12 @@ void LogCallback(int level, const char *fmt, va_list vl) printf("%s: %s\n", GetLevelName(level), message); } -static void SignalHandler() +static void SignalHandler(int none) { g_run = 0; } -static void SetupSignal() +static void SetupSignal(void) { // regist signal handler signal(SIGINT, SignalHandler); @@ -69,10 +70,13 @@ static void SetupSignal() } // PWR_CPU_GetUsage -static void TEST_PWR_CPU_GetInfo() +static void TEST_PWR_CPU_GetInfo(void) { int ret; PWR_CPU_Info *info = (PWR_CPU_Info *)malloc(sizeof(PWR_CPU_Info)); + if (!info) { + return; + } bzero(info, sizeof(PWR_CPU_Info)); ret = PWR_CPU_GetInfo(info); printf("PWR_CPU_GetInfo ret: %d\n arch:%s\n coreNum: %d\n maxFreq:%f\n minFreq:%d\n modelName: %s\n numaNum: %d\n " @@ -86,11 +90,14 @@ static void TEST_PWR_CPU_GetInfo() } // PWR_CPU_GetUsage -static void TEST_PWR_CPU_GetUsage() +static void TEST_PWR_CPU_GetUsage(void) { int ret; int buffSize = sizeof(PWR_CPU_Usage) + 128 * sizeof(PWR_CPU_CoreUsage); PWR_CPU_Usage *u = (PWR_CPU_Usage *)malloc(buffSize); + if (!u) { + return; + } bzero(u, buffSize); ret = PWR_CPU_GetUsage(u, buffSize); printf("PWR_CPU_GetUsage ret: %d, CPU avgUsage:%f, coreNum: %d \n", ret, u->avgUsage, u->coreNum); @@ -107,7 +114,7 @@ static void TEST_PWR_CPU_GetFreqAbility(void) int len = sizeof(PWR_CPU_FreqAbility) + 5 * 128; PWR_CPU_FreqAbility *freqAbi = (PWR_CPU_FreqAbility *)malloc(len); if(!freqAbi) { - return -1; + return; } bzero(freqAbi, len); ret = PWR_CPU_GetFreqAbility(freqAbi, len); @@ -125,7 +132,7 @@ static void TEST_PWR_CPU_GetFreqAbility(void) free(freqAbi); } -static void TEST_PWR_CPU_SetAndGetFreqGov() +static void TEST_PWR_CPU_SetAndGetFreqGov(void) { int ret = 0; char gov[MAX_ELEMENT_NAME_LEN] = {0}; @@ -141,7 +148,7 @@ static void TEST_PWR_CPU_SetAndGetFreqGov() // PWR_CPU_GetFreq PWR_CPU_SetFreq #define TEST_FREQ 2400; -static void TEST_PWR_CPU_SetAndGetCurFreq() +static void TEST_PWR_CPU_SetAndGetCurFreq(void) { int ret = 0; uint32_t len = 128; @@ -166,7 +173,7 @@ static void TEST_PWR_CPU_SetAndGetCurFreq() printf("Freq Policy %d curFreq:%d\n", curFreq[0].policyId, curFreq[0].curFreq); } -static void TEST_PWR_CPU_DmaSetAndGetLatency() +static void TEST_PWR_CPU_DmaSetAndGetLatency(void) { int ret = 0; int la = -1; @@ -183,7 +190,7 @@ int main(int argc, const char *args[]) { PWR_SetLogCallback(LogCallback); while (PWR_Register() != SUCCESS) { - sleep(3); + sleep(MAIN_LOOP_INTERVAL); printf("main registed failed!\n"); continue; } @@ -205,9 +212,8 @@ int main(int argc, const char *args[]) TEST_PWR_CPU_DmaSetAndGetLatency(); // todo: 其他接口测试 - while (g_run) { - sleep(5); + sleep(MAIN_LOOP_INTERVAL); } PWR_UnRegister(); return 0; diff --git a/pwrapis/inc/common.h b/pwrapis/inc/common.h index 5459c579caa5fdac1079b7447cb82f9cb204b0ef..edd36dbc6b6132448e5b94c6c1d79fa0970d3127 100644 --- a/pwrapis/inc/common.h +++ b/pwrapis/inc/common.h @@ -22,6 +22,7 @@ #define MAX_PEDDING_SOCKS 5 #define MS_TO_SEC 1000 #define ONE_HUNDRED 100 +#define ONE_THOUSAND 1000 // Status code defination #define INTERACT_SUCCEED 2003 @@ -259,13 +260,14 @@ enum RunStatus { }; -#define INVALID_FD -1 -#define INVALID_INDEX -1 +#define INVALID_FD (-1) +#define INVALID_INDEX (-1) #define MAX_LICENT_NUM 3 #define THREAD_LOOP_INTERVAL 2000 // us #define SERVER_ADDR "pwrserver.sock" #define CLIENT_ADDR "pwrclient.sock." #define MAX_SYSID_LEN 20 +#define MAX_PROC_NUM_ONE_LOOP 5 #endif diff --git a/pwrapis/inc/config.h b/pwrapis/inc/config.h index acc298f61a2c96276e3baae488549a639bafa4ee..d2381d873bff2821195433465c3b6f003a547d3c 100644 --- a/pwrapis/inc/config.h +++ b/pwrapis/inc/config.h @@ -50,8 +50,8 @@ typedef struct ServCfg { char sockFile[MAX_FILE_NAME]; } ServCfg; -int InitConfig(); -LogCfg *GetLogCfg(); -ServCfg *GetServCfg(); -int CheckAndUpdateConfig(); +int InitConfig(void); +LogCfg *GetLogCfg(void); +ServCfg *GetServCfg(void); +int CheckAndUpdateConfig(void); #endif diff --git a/pwrapis/inc/log.h b/pwrapis/inc/log.h index 80ca50b19046601b967f6788b91415f90b042e13..bcd5da8eb515abb2c29090583557e9065fad5e03 100644 --- a/pwrapis/inc/log.h +++ b/pwrapis/inc/log.h @@ -15,8 +15,6 @@ #ifndef __PAPIS_LOG_H__ #define __PAPIS_LOG_H__ -#include -#include "common.h" #include "config.h" /** @@ -25,7 +23,7 @@ * Note: Exit on error */ -int InitLogger(); +int InitLogger(void); /** * Logger - send messages to the system logger * @@ -33,5 +31,5 @@ int InitLogger(); */ void Logger(enum LogLevel level, const char *moduleName, const char *format, ...); -void ClearLogger(); +void ClearLogger(void); #endif diff --git a/pwrapis/inc/server.h b/pwrapis/inc/server.h index 972898138435a69b8479e402ea0bcaab0b366d7b..e9ed186cd5b57bd827f53778fff43df290d6411c 100644 --- a/pwrapis/inc/server.h +++ b/pwrapis/inc/server.h @@ -24,8 +24,8 @@ * Note: return connected socket fd if success; * return < 1 if failed */ -int StartServer(); -void StopServer(); +int StartServer(void); +void StopServer(void); int SendRspMsg(PwrMsg *rsp); #endif diff --git a/pwrapis/inc/utils.h b/pwrapis/inc/utils.h index ce9efdd99a69535b3ba23d9e8eb23a037a95234e..829861e0c55da7f553fa168b2c3e9aeb375299d7 100644 --- a/pwrapis/inc/utils.h +++ b/pwrapis/inc/utils.h @@ -37,7 +37,7 @@ struct FieldLocation { * GetCurSec - returns the current time as the number of seconds * since the Epoch, 1970 - 01 - 01 00:00:00 + 0000 (UTC). */ -time_t GetCurSec(); +time_t GetCurSec(void); /** * Return the current time string in the specified format @@ -69,7 +69,7 @@ time_t GetLastDaySec(const char *day); /* * GetLastDaySec - Get the last second of the current day */ -time_t GetLastCurDaySec(); +time_t GetLastCurDaySec(void); /** * LcmGetNthField - Find the @nth field separated by @sep in the string * diff --git a/pwrapis/src/config.c b/pwrapis/src/config.c index dc20296d43fd340fb43854ac86bd44a675c8beec..bb80d34d14f2b3ffb56b4fcc4632eb9925f5a89c 100644 --- a/pwrapis/src/config.c +++ b/pwrapis/src/config.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: @@ -19,18 +19,18 @@ #include "log.h" static struct LogCfg g_logCfg; -inline LogCfg *GetLogCfg() +inline LogCfg *GetLogCfg(void) { return (LogCfg *)&g_logCfg; } static struct ServCfg g_servCfg; -inline ServCfg *GetServCfg() +inline ServCfg *GetServCfg(void) { return (ServCfg *)&g_servCfg; } -static int InitLogCfg() +static int InitLogCfg(void) { bzero(&g_logCfg, sizeof(g_logCfg)); g_logCfg.logLevel = DEBUG; // todo 发布时修改为INFO @@ -47,11 +47,11 @@ static int InitLogCfg() return SUCCESS; } -static int LoadConfigFile() +static int LoadConfigFile(void) { // todo 打开读取文件,解析配置项,校验配置项,有效配置项替换 } -static int InitServCfg() +static int InitServCfg(void) { strncpy(g_servCfg.sockFile, DEFAULT_SERVER_ADDR, sizeof(g_servCfg.sockFile) - 1); g_servCfg.port = 0; @@ -59,7 +59,7 @@ static int InitServCfg() } -int InitConfig() +int InitConfig(void) { int ret = SUCCESS; // Init by default values @@ -84,7 +84,7 @@ int InitConfig() return SUCCESS; } -int CheckAndUpdateConfig() +int CheckAndUpdateConfig(void) { // todo 检查配置文件是否有更新,有更新则更新系统配置项 } @@ -96,7 +96,7 @@ int UpdateLogLevel(enum LogLevel logLevel) return SUCCESS; } -int GetLogLevel() +int GetLogLevel(void) { return g_logCfg.logLevel; } diff --git a/pwrapis/src/cpuservice.c b/pwrapis/src/cpuservice.c index ce55eb9488a20296ac54d15fadaa5fbd1aea5571..4f6b41c4ac1a1da92d6c9bec70636f6f75eba755 100644 --- a/pwrapis/src/cpuservice.c +++ b/pwrapis/src/cpuservice.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: diff --git a/pwrapis/src/log.c b/pwrapis/src/log.c index 478cb68e60f7407beb480d8127a1e8141d18a410..d50feb6e2be6291aa78a563353583c17d50f908e 100644 --- a/pwrapis/src/log.c +++ b/pwrapis/src/log.c @@ -37,7 +37,7 @@ static FILE *g_pFile = NULL; // todo 需要mutex保护 static uint32_t g_curSize = 0; static regex_t g_logCmpFlRgx; -static FILE *OpenLogFile() +static FILE *OpenLogFile(void) { struct stat st; char fullName[MAX_FULL_NAME] = {0}; @@ -66,7 +66,7 @@ static int LogCmpFileFilter(const struct dirent *item) } } // Release space by deleting the earlier compressed files -static void SpaceChkAndDel() +static void SpaceChkAndDel(void) { int cnt; int fileCnt; @@ -94,7 +94,7 @@ static void SpaceChkAndDel() free(fileList); } -static int RotateFile() +static int RotateFile(void) { int ret; char curTime[MAX_STD_TIME] = {0}; @@ -148,7 +148,7 @@ static const char *GetLevelName(enum LogLevel level) } } -int InitLogger() +int InitLogger(void) { regcomp(&g_logCmpFlRgx, "^", REG_EXTENDED | REG_NOSUB); @@ -171,7 +171,7 @@ int InitLogger() return SUCCESS; } -void ClearLogger() +void ClearLogger(void) { if (g_pFile != NULL) { fclose(g_pFile); diff --git a/pwrapis/src/main_frame.c b/pwrapis/src/main_frame.c index b5f83590f092f5341967f2a74e29759a248fe663..d3e062cab3f2ef2f00c3cff32bb92ad552c45d1a 100644 --- a/pwrapis/src/main_frame.c +++ b/pwrapis/src/main_frame.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: @@ -21,6 +21,7 @@ #include "log.h" #define ARGS_NUM 2 +#define MAIN_LOOP_INTERVAL 5 static int g_keepMainRunning; static void PrintUsage(const char *args[]) @@ -28,7 +29,7 @@ static void PrintUsage(const char *args[]) printf("Usage: %s < config_file_name > \n", args[0]); } -static int BaseInit() +static int BaseInit(void) { int ret = SUCCESS; ret = InitConfig(); @@ -45,18 +46,18 @@ static int BaseInit() return SUCCESS; } -static void ClearEnv() +static void ClearEnv(void) { // todo:必要的环境清理动作 ClearLogger(); } -static void SignalHandler() +static void SignalHandler(int none) { g_keepMainRunning = EXIT; } -static void SetupSignal() +static void SetupSignal(void) { // regist signal handler signal(SIGINT, SignalHandler); @@ -90,7 +91,7 @@ int main(int argc, const char *args[]) SetupSignal(); g_keepMainRunning = KEEP_RUN; while (g_keepMainRunning) { - sleep(5); + sleep(MAIN_LOOP_INTERVAL); CheckAndUpdateConfig(); // todo 系统定时任务(比如配置文件更新)触发 } diff --git a/pwrapis/src/pwrclient.c b/pwrapis/src/pwrclient.c index 897206a894a91683743b4286a627796f2afbd23d..35c9743285237af710e17ceb729c7169480eeeca 100644 --- a/pwrapis/src/pwrclient.c +++ b/pwrapis/src/pwrclient.c @@ -1,5 +1,5 @@ /* ***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022 All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022 All rights reserved. * PowerAPI licensed under the Mulan PSL v2. * You can use this software according to the terms and conditions of the Mulan PSL v2. * You may obtain a copy of Mulan PSL v2 at: @@ -12,9 +12,9 @@ * Create: 2022-06-23 * Description: pwrclient manager. pwrclient refers to the socket connection info. * **************************************************************************** */ +#include "pwrclient.h" #include #include -#include "pwrclient.h" #include "pwrerr.h" #include "common.h" #include "log.h" diff --git a/pwrapis/src/server.c b/pwrapis/src/server.c index 91861423c2206fc32aac4d9465db80caccfc45ea..41cef65f54896bb5c786014a2e62d4a92c169b82 100644 --- a/pwrapis/src/server.c +++ b/pwrapis/src/server.c @@ -87,7 +87,7 @@ static int StartUnxListen(const char *localFileName) return ListenStart(sockFd, (struct sockaddr *)&tSockaddr); } -static void StopListen() +static void StopListen(void) { pthread_mutex_lock(&g_listenFdLock); if (g_listenFd < 0) { @@ -99,7 +99,7 @@ static void StopListen() pthread_mutex_unlock(&g_listenFdLock); } -static void AcceptConnection() +static void AcceptConnection(void) { Logger(INFO, MD_NM_SVR, "Received connection request."); int newClientFd; @@ -208,12 +208,12 @@ static int WriteMsg(const void *pData, int len, int dstFd) return SUCCESS; } -static void ProcessSendMsgToClient() +static void ProcessSendMsgToClient(void) { // 从缓存中读取待发送消息,并发送出去 int count = 0; static char data[MAX_DATA_SIZE]; - while (!IsEmptyBuffer(&g_sendBuff) && count < 5) { + while (!IsEmptyBuffer(&g_sendBuff) && count < MAX_PROC_NUM_ONE_LOOP) { PwrMsg *msg = PopFromBufferHead(&g_sendBuff); count++; if (!msg) { @@ -256,7 +256,7 @@ static void ProcessSendMsgToClient() * 1. Accepting connection request * 2. Receiving msg from or send msg to client FDs */ -static void *RunServerSocketProcess() +static void *RunServerSocketProcess(void *none) { fd_set recvFdSet; int maxFd = INVALID_FD; @@ -299,14 +299,14 @@ static void *RunServerSocketProcess() CloseAllConnections(g_pwrClients); } -static void WaitForMsg() +static void WaitForMsg(void) { struct timeval now; struct timespec outTime; pthread_mutex_lock((pthread_mutex_t *)&g_waitMsgMutex); gettimeofday(&now, NULL); outTime.tv_sec = now.tv_sec; - outTime.tv_nsec = (now.tv_usec + THREAD_LOOP_INTERVAL) * 1000; + outTime.tv_nsec = (now.tv_usec + THREAD_LOOP_INTERVAL) * ONE_THOUSAND; pthread_cond_timedwait((pthread_cond_t *)&g_waitMsgCond, (pthread_mutex_t *)&g_waitMsgMutex, &outTime); pthread_mutex_unlock((pthread_mutex_t *)&g_waitMsgMutex); } @@ -337,7 +337,7 @@ static void ProcessReqMsg(PwrMsg *req) * RunServiceProcess - Run RunServiceProcess * Process the request msg in receiving buffer g_recvBuff */ -static void *RunServiceProcess() +static void *RunServiceProcess(void *none) { while (g_serviceThread.keepRunning) { if (IsEmptyBuffer(&g_recvBuff)) { @@ -352,7 +352,7 @@ static void *RunServiceProcess() } // public====================================================================================== // Init Socket. Start listening & accepting -int StartServer() +int StartServer(void) { InitMsgFactory(); InitPwrMsgBuffer(&g_sendBuff); @@ -382,7 +382,7 @@ int StartServer() return SUCCESS; } -void StopServer() +void StopServer(void) { FiniThreadInfo(&g_sockProcThread); FiniThreadInfo(&g_serviceThread); diff --git a/pwrapis/src/utils.c b/pwrapis/src/utils.c index ba6c4c209d19ae2ec1070485c4f7aedfc414bc4b..49f35cfc652fdb187037c7e6e9e793ff5d386f43 100644 --- a/pwrapis/src/utils.c +++ b/pwrapis/src/utils.c @@ -31,14 +31,14 @@ #define SUCCESS 0 -static struct timeval GetCurTv() +static struct timeval GetCurTv(void) { struct timeval curTime; gettimeofday(&curTime, NULL); return curTime; } // Check head file -time_t GetCurSec() +time_t GetCurSec(void) { struct timeval tv; tv = GetCurTv(); @@ -198,7 +198,7 @@ time_t GetLastDaySec(const char *day) } return StrTime2Sec(strSec); } -time_t GetLastCurDaySec() +time_t GetLastCurDaySec(void) { const char *pDay = NULL; char strCurTm[MAX_STD_TIME] = {0};