Skip to content

Commit 74eadac

Browse files
committed
Identifying builds with Git revisions, streamlining function names in
modules
1 parent 8792819 commit 74eadac

18 files changed

Lines changed: 140 additions & 135 deletions

src/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
SRC = $(shell find ./ -name '*.c')
22
OBJ = ../divinus
3+
GIT_REV := $(shell git rev-parse --short HEAD)$(shell git diff --quiet HEAD || echo "-mod")
34

45
.PHONY: clean divinus
56
divinus: $(OBJ)
67

78
$(OBJ): $(SRC:%.c=%.o)
8-
$(CC) $^ -rdynamic $(OPT) -o $@
9+
$(CC) $^ -rdynamic $(OPT) -DGIT_REV=\"$(GIT_REV)\" -o $@
910

1011
%.o: %.c Makefile
11-
$(CC) -c $< $(OPT) -o $@
12+
$(CC) -c $< $(OPT) -DGIT_REV=\"$(GIT_REV)\" -o $@
1213

1314
clean:
1415
rm -rf $(SRC:%.c=%.o) $(OBJ)

src/app_config.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const char *appconf_paths[] = {"./divinus.yaml", "/etc/divinus.yaml"};
44

55
struct AppConfig app_config;
66

7-
static inline void open_app_config(FILE **file, const char *flags) {
7+
static inline void app_config_open(FILE **file, const char *flags) {
88
const char **path = appconf_paths;
99
char conf_path[PATH_MAX], exe_path[PATH_MAX];
1010
*file = NULL;
@@ -39,7 +39,7 @@ static inline void open_app_config(FILE **file, const char *flags) {
3939
}
4040
}
4141

42-
void restore_app_config(void) {
42+
void app_config_restore(void) {
4343
char conf_path[PATH_MAX], exe_path[PATH_MAX];
4444

4545
ssize_t exe_len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
@@ -67,10 +67,10 @@ void restore_app_config(void) {
6767
}
6868
}
6969

70-
int save_app_config(void) {
70+
int app_config_save(void) {
7171
FILE *file;
7272

73-
open_app_config(&file, "w");
73+
app_config_open(&file, "w");
7474
if (!file)
7575
HAL_ERROR("app_config", "Can't open config file for writing\n");
7676

@@ -213,7 +213,7 @@ int save_app_config(void) {
213213
return EXIT_SUCCESS;
214214
}
215215

216-
enum ConfigError parse_app_config(void) {
216+
enum ConfigError app_config_parse(void) {
217217
memset(&app_config, 0, sizeof(struct AppConfig));
218218

219219
app_config.web_port = 8080;
@@ -284,7 +284,7 @@ enum ConfigError parse_app_config(void) {
284284
memset(&ini, 0, sizeof(struct IniConfig));
285285

286286
FILE *file;
287-
open_app_config(&file, "r");
287+
app_config_open(&file, "r");
288288
if (!open_config(&ini, &file)) {
289289
printf("Can't find config divinus.yaml in:\n"
290290
" ./divinus.yaml\n /etc/divinus.yaml\n");

src/app_config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,6 @@ struct AppConfig {
119119
};
120120

121121
extern struct AppConfig app_config;
122-
enum ConfigError parse_app_config(void);
123-
void restore_app_config(void);
124-
int save_app_config(void);
122+
enum ConfigError app_config_parse(void);
123+
void app_config_restore(void);
124+
int app_config_save(void);

src/hal/globals.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
#include "types.h"
44

5+
#ifndef GIT_REV
6+
#define GIT_REV "unknown"
7+
#endif
8+
59
extern char graceful, keepRunning;
610
extern char audioOn, recordOn;
711

src/hal/macros.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,28 @@
2727

2828
#define HAL_DANGER(mod, x, ...) \
2929
do { \
30-
fprintf(stderr, "[%s] \033[31m", (mod)); \
30+
fprintf(stderr, "\033[0m[%s] \033[31m", (mod)); \
3131
fprintf(stderr, (x), ##__VA_ARGS__); \
3232
fprintf(stderr, "\033[0m"); \
3333
} while (0)
3434

3535
#define HAL_ERROR(mod, x, ...) \
3636
do { \
37-
fprintf(stderr, "[%s] \033[31m", (mod)); \
37+
fprintf(stderr, "\033[0m[%s] \033[31m", (mod)); \
3838
fprintf(stderr, (x), ##__VA_ARGS__); \
3939
fprintf(stderr, "\033[0m"); \
4040
return EXIT_FAILURE; \
4141
} while (0)
4242

4343
#define HAL_INFO(mod, x, ...) \
4444
do { \
45-
fprintf(stderr, "[%s] ", (mod)); \
45+
fprintf(stderr, "\033[0m[%s] ", (mod)); \
4646
fprintf(stderr, (x), ##__VA_ARGS__); \
4747
} while (0)
4848

4949
#define HAL_WARNING(mod, x, ...) \
5050
do { \
51-
fprintf(stderr, "[%s] \033[33m", (mod)); \
51+
fprintf(stderr, "\033[0m[%s] \033[33m", (mod)); \
5252
fprintf(stderr, (x), ##__VA_ARGS__); \
5353
fprintf(stderr, "\033[0m"); \
5454
} while (0)

src/http_post.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void *http_post_thread(void) {
104104
return NULL;
105105
}
106106

107-
void start_http_post_send() {
107+
void http_post_start() {
108108
pthread_attr_t thread_attr;
109109
pthread_attr_init(&thread_attr);
110110
size_t stacksize;
@@ -120,6 +120,6 @@ void start_http_post_send() {
120120
pthread_attr_destroy(&thread_attr);
121121
}
122122

123-
void stop_http_post_send() {
123+
void http_post_stop() {
124124
pthread_join(httpPostPid, NULL);
125125
}

src/http_post.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
#include "hal/macros.h"
1515
#include "jpeg.h"
1616

17-
void start_http_post_send();
18-
void stop_http_post_send();
17+
void http_post_start();
18+
void http_post_stop();

src/main.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,24 @@ int main(int argc, char *argv[]) {
5858
if (!*family)
5959
HAL_ERROR("hal", "Unsupported chip family! Quitting...\n");
6060

61-
fprintf(stderr, "\033[7m Divinus for %s \033[0m\n", family);
61+
fprintf(stderr, "\033[0m\033[7m Divinus (rev %s) for %s \033[0m\n", GIT_REV, family);
6262
fprintf(stderr, "Chip ID: %s\n", chip);
6363

64-
if (parse_app_config() != CONFIG_OK)
64+
if (app_config_parse() != CONFIG_OK)
6565
HAL_ERROR("hal", "Can't load app config 'divinus.yaml'\n");
6666

6767
if (app_config.watchdog)
6868
watchdog_start(app_config.watchdog);
6969

70-
start_network();
70+
network_start();
7171

72-
start_server();
72+
server_start();
7373

7474
if (app_config.rtsp_enable) {
7575
rtspHandle = rtsp_create(RTSP_MAXIMUM_CONNECTIONS, app_config.rtsp_port, 1);
7676
HAL_INFO("rtsp", "Started listening for clients...\n");
7777
if (app_config.rtsp_enable_auth) {
78-
if (!app_config.rtsp_auth_user || !app_config.rtsp_auth_pass)
78+
if (EMPTY(app_config.rtsp_auth_user) || EMPTY(app_config.rtsp_auth_pass))
7979
HAL_ERROR("rtsp", "One or both credential fields have been left empty!\n");
8080
else {
8181
rtsp_configure_auth(rtspHandle, app_config.rtsp_auth_user, app_config.rtsp_auth_pass);
@@ -85,19 +85,19 @@ int main(int argc, char *argv[]) {
8585
}
8686

8787
if (app_config.stream_enable)
88-
start_streaming();
88+
media_start();
8989

90-
if (start_sdk())
90+
if (sdk_start())
9191
HAL_ERROR("hal", "Failed to start SDK!\n");
9292

9393
if (app_config.night_mode_enable)
94-
enable_night();
94+
night_enable();
9595

9696
if (app_config.http_post_enable)
97-
start_http_post_send();
97+
http_post_start();
9898

9999
if (app_config.osd_enable)
100-
start_region_handler();
100+
region_start();
101101

102102
if (app_config.record_enable && app_config.record_continuous)
103103
record_start();
@@ -117,28 +117,28 @@ int main(int argc, char *argv[]) {
117117
}
118118

119119
if (app_config.http_post_enable)
120-
stop_http_post_send();
120+
http_post_start();
121121

122122
if (app_config.osd_enable)
123-
stop_region_handler();
123+
region_stop();
124124

125125
if (app_config.night_mode_enable)
126-
disable_night();
126+
night_disable();
127127

128-
stop_sdk();
128+
sdk_stop();
129129

130130
if (app_config.stream_enable)
131-
stop_streaming();
131+
media_stop();
132132

133-
stop_server();
133+
server_stop();
134134

135-
stop_network();
135+
network_stop();
136136

137137
if (app_config.watchdog)
138138
watchdog_stop();
139139

140140
if (!graceful)
141-
restore_app_config();
141+
app_config_restore();
142142

143143
if (graceful) {
144144
fprintf(stderr, "Restarting...\n");

0 commit comments

Comments
 (0)