Skip to content

Commit a0a047c

Browse files
committed
Inline wrappers, tidy up, code format
1 parent a03adc9 commit a0a047c

File tree

10 files changed

+147
-360
lines changed

10 files changed

+147
-360
lines changed

processWatchdog.pro

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,7 @@ CONFIG -= app_bundle
88
CONFIG -= qt
99

1010
SOURCES += \
11-
src/filecmd.c \
12-
src/ini.c \
13-
src/apps.c \
14-
src/log.c \
15-
src/main.c \
16-
src/server.c \
17-
src/stats.c \
18-
src/test.c \
19-
src/utils.c
11+
src/*.c
2012

2113
HEADERS += \
22-
src/ini.h \
23-
src/filecmd.h \
24-
src/apps.h \
25-
src/log.h \
26-
src/server.h \
27-
src/stats.h \
28-
src/test.h \
29-
src/utils.h
14+
src/*.h

src/apps.c

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
#include "apps.h"
2222
#include "config.h"
23-
#include "process.h"
24-
#include "heartbeat.h"
2523
#include "log.h"
2624
#include "utils.h"
2725

@@ -37,8 +35,6 @@
3735
#include <sys/wait.h>
3836
#include <errno.h>
3937

40-
41-
4238
static Application_t apps[MAX_APPS]; /**< Array of Application_t structures representing applications defined in the ini file. */
4339
static AppState_t app_state = {0};
4440

@@ -60,32 +56,6 @@ void print_app(int i)
6056

6157
//------------------------------------------------------------------
6258

63-
// Wrapper functions for backward compatibility - delegate to heartbeat module
64-
void update_heartbeat_time(int i)
65-
{
66-
heartbeat_update_time(i);
67-
}
68-
69-
time_t get_heartbeat_time(int i)
70-
{
71-
return heartbeat_get_elapsed_time(i);
72-
}
73-
74-
bool is_timeup(int i)
75-
{
76-
return heartbeat_is_timeout(i);
77-
}
78-
79-
void set_first_heartbeat(int i)
80-
{
81-
heartbeat_set_first_received(i);
82-
}
83-
84-
bool get_first_heartbeat(int i)
85-
{
86-
return heartbeat_get_first_received(i);
87-
}
88-
8959
int find_pid(int pid)
9060
{
9161
for(int i = 0; i < app_state.app_count; i++)
@@ -99,8 +69,6 @@ int find_pid(int pid)
9969
return -1;
10070
}
10171

102-
//------------------------------------------------------------------
103-
10472
int read_ini_file()
10573
{
10674
// Use default ini file if not already set
@@ -132,40 +100,6 @@ int set_ini_file(char *path)
132100
return 0;
133101
}
134102

135-
//------------------------------------------------------------------
136-
137-
// Wrapper functions for backward compatibility - delegate to process module
138-
// TODO : inline wrapper functions
139-
bool is_application_running(int i)
140-
{
141-
return process_is_running(i);
142-
}
143-
144-
bool is_application_started(int i)
145-
{
146-
return process_is_started(i);
147-
}
148-
149-
bool is_application_start_time(int i)
150-
{
151-
return process_is_start_time(i);
152-
}
153-
154-
void start_application(int i)
155-
{
156-
process_start(i);
157-
}
158-
159-
void kill_application(int i)
160-
{
161-
process_kill(i);
162-
}
163-
164-
void restart_application(int i)
165-
{
166-
process_restart(i);
167-
}
168-
169103
int get_app_count(void)
170104
{
171105
return app_state.app_count;
@@ -181,16 +115,12 @@ int get_udp_port(void)
181115
return app_state.udp_port;
182116
}
183117

184-
//------------------------------------------------------------------
185-
// External access functions for other modules
186-
//------------------------------------------------------------------
187-
188-
Application_t* apps_get_array(void)
118+
Application_t *apps_get_array(void)
189119
{
190120
return apps;
191121
}
192122

193-
AppState_t* apps_get_state(void)
123+
AppState_t *apps_get_state(void)
194124
{
195125
return &app_state;
196126
}

src/apps.h

Lines changed: 20 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,6 @@ typedef struct
7575
*/
7676
void print_app(int i);
7777

78-
/**
79-
@brief Updates the last heartbeat time for the specified application.
80-
81-
@param i Index of the application.
82-
*/
83-
void update_heartbeat_time(int i);
84-
8578
/**
8679
@brief Finds the index of an application with the specified process ID.
8780
@@ -91,35 +84,40 @@ void update_heartbeat_time(int i);
9184
int find_pid(int pid);
9285

9386
/**
94-
@brief Gets the elapsed time since the last heartbeat received from the specified application.
87+
@brief Gets direct access to the applications array for other modules.
9588
96-
@param i Index of the application.
97-
@return Elapsed time in seconds.
89+
@return Pointer to the applications array.
9890
*/
99-
time_t get_heartbeat_time(int i);
91+
Application_t *apps_get_array(void);
10092

10193
/**
102-
@brief Checks if it is time to expect a heartbeat from the specified application.
94+
@brief Gets direct access to the application state for other modules.
10395
104-
@param i Index of the application.
105-
@return true if it is time to expect a heartbeat, false otherwise.
96+
@return Pointer to the application state structure.
10697
*/
107-
bool is_timeup(int i);
98+
AppState_t *apps_get_state(void);
10899

109100
/**
110-
@brief Sets the flag indicating that the specified application has sent its first heartbeat.
101+
@brief Gets the total number of applications found in the ini file.
111102
112-
@param i Index of the application.
103+
@return Total number of applications.
113104
*/
114-
void set_first_heartbeat(int i);
105+
int get_app_count();
115106

116107
/**
117-
@brief Gets the flag indicating whether the specified application has sent its first heartbeat.
108+
@brief Gets the name of the application at the specified index.
118109
119110
@param i Index of the application.
120-
@return true if the application has sent its first heartbeat, false otherwise.
111+
@return Name of the application.
121112
*/
122-
bool get_first_heartbeat(int i);
113+
char *get_app_name(int i);
114+
115+
/**
116+
@brief Gets the UDP port number specified in the ini file.
117+
118+
@return UDP port number.
119+
*/
120+
int get_udp_port();
123121

124122
/**
125123
@brief Sets the path to the ini file.
@@ -143,85 +141,4 @@ bool is_ini_updated();
143141
*/
144142
int read_ini_file();
145143

146-
/**
147-
@brief Checks if the specified application is currently running.
148-
149-
@param i Index of the application.
150-
@return true if the application is running, false otherwise.
151-
*/
152-
bool is_application_running(int i);
153-
154-
/**
155-
@brief Checks if the specified application has been started.
156-
157-
@param i Index of the application.
158-
@return true if the application has been started, false otherwise.
159-
*/
160-
bool is_application_started(int i);
161-
162-
/**
163-
@brief Checks if it is time to start the specified application based on the start delay.
164-
165-
@param i Index of the application.
166-
@return true if it is time to start the application, false otherwise.
167-
*/
168-
bool is_application_start_time(int i);
169-
170-
/**
171-
@brief Starts the specified application.
172-
173-
@param i Index of the application.
174-
*/
175-
void start_application(int i);
176-
177-
/**
178-
@brief Stops the specified application by killing its process.
179-
180-
@param i Index of the application.
181-
*/
182-
void kill_application(int i);
183-
184-
/**
185-
@brief Restarts the specified application.
186-
187-
@param i Index of the application.
188-
*/
189-
void restart_application(int i);
190-
191-
/**
192-
@brief Gets the total number of applications found in the ini file.
193-
194-
@return Total number of applications.
195-
*/
196-
int get_app_count();
197-
198-
/**
199-
@brief Gets the name of the application at the specified index.
200-
201-
@param i Index of the application.
202-
@return Name of the application.
203-
*/
204-
char *get_app_name(int i);
205-
206-
/**
207-
@brief Gets the UDP port number specified in the ini file.
208-
209-
@return UDP port number.
210-
*/
211-
int get_udp_port();
212-
213-
/**
214-
@brief Gets direct access to the applications array for other modules.
215-
216-
@return Pointer to the applications array.
217-
*/
218-
Application_t* apps_get_array(void);
219-
220-
/**
221-
@brief Gets direct access to the application state for other modules.
222-
223-
@return Pointer to the application state structure.
224-
*/
225-
AppState_t* apps_get_state(void);
226-
227-
#endif // APPS_H
144+
#endif // APPS_H

src/cmd.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@
2323
#include <string.h>
2424
#include <limits.h>
2525

26-
//------------------------------------------------------------------
27-
// Public interface functions
28-
//------------------------------------------------------------------
29-
30-
net_command_t cmd_parse_network(const char* data, int length)
26+
net_command_t cmd_parse_network(const char *data, int length)
3127
{
3228
net_command_t cmd = {0};
3329
cmd.type = NET_CMD_UNKNOWN;
3430
cmd.pid = 0;
3531
cmd.app_name[0] = '\0';
3632

37-
if (!data || length <= 0) {
33+
if(!data || length <= 0)
34+
{
3835
return cmd;
3936
}
4037

@@ -91,19 +88,23 @@ net_command_t cmd_parse_network(const char* data, int length)
9188
const int max_length = max_bytes * 3;
9289
char hexStr[max_length];
9390
memset(hexStr, 0, sizeof(hexStr));
94-
9591
int safe_length = length;
96-
if (safe_length > max_bytes) {
92+
93+
if(safe_length > max_bytes)
94+
{
9795
safe_length = max_bytes;
9896
}
9997

100-
for (int i = 0; i < safe_length; i++) {
98+
for(int i = 0; i < safe_length; i++)
99+
{
101100
snprintf(&hexStr[i * 3], sizeof(hexStr) - (i * 3), "%02X ", data[i]);
102101
}
103102

104103
char printableStr[max_bytes + 1];
105104
memset(printableStr, 0, sizeof(printableStr));
106-
for (int i = 0; i < safe_length; i++) {
105+
106+
for(int i = 0; i < safe_length; i++)
107+
{
107108
printableStr[i] = (data[i] >= 32 && data[i] < 127) ? data[i] : '.';
108109
}
109110

@@ -114,4 +115,4 @@ net_command_t cmd_parse_network(const char* data, int length)
114115
}
115116

116117
return cmd;
117-
}
118+
}

src/cmd.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
#ifndef CMD_H
1717
#define CMD_H
1818

19-
#include <stdbool.h>
20-
21-
// Include apps.h for MAX_APP_NAME_LENGTH constant
2219
#include "apps.h"
2320

21+
#include <stdbool.h>
22+
2423
/**
2524
@enum net_command_type_t
2625
@brief Enumeration of network command types.
2726
*/
28-
typedef enum {
27+
typedef enum
28+
{
2929
NET_CMD_HEARTBEAT, /**< Heartbeat command: p<pid> */
3030
NET_CMD_START, /**< Start command: a<name> (future) */
3131
NET_CMD_STOP, /**< Stop command: o<name> (future) */
@@ -37,7 +37,8 @@ typedef enum {
3737
@struct net_command_t
3838
@brief Structure representing a parsed network command.
3939
*/
40-
typedef struct {
40+
typedef struct
41+
{
4142
net_command_type_t type; /**< Type of the command */
4243
int pid; /**< Process ID for heartbeat commands */
4344
char app_name[MAX_APP_NAME_LENGTH]; /**< Application name for control commands */
@@ -53,6 +54,6 @@ typedef struct {
5354
@param length Length of the command data.
5455
@return Parsed network command structure.
5556
*/
56-
net_command_t cmd_parse_network(const char* data, int length);
57+
net_command_t cmd_parse_network(const char *data, int length);
5758

58-
#endif // CMD_H
59+
#endif // CMD_H

0 commit comments

Comments
 (0)