-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtemplate.c
73 lines (57 loc) · 1.01 KB
/
template.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include "utils.h"
#include "mcp.h"
static void loop() {
if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL)) {
xlog("Error setting pthread_setcancelstate");
return;
}
while (1) {
sleep(1);
// do some fancy stuff in a loop
xlog("template loop");
}
}
static int init() {
// initialize this module
return 0;
}
static void stop() {
// stop and destroy this module
}
static int test() {
xlog("module test code");
return 0;
}
int template_main(int argc, char **argv) {
set_xlog(XLOG_STDOUT);
set_debug(1);
// no arguments - main loop
if (argc == 1) {
init();
loop();
pause();
stop();
return 0;
}
// with arguments
int c;
while ((c = getopt(argc, argv, "t")) != -1) {
switch (c) {
case 't':
return test();
}
}
return 0;
}
#ifdef TEMPLATE_MAIN
int main(int argc, char **argv) {
return template_main(argc, argv);
}
#else
MCP_REGISTER(template, 99, &init, &stop, &loop);
#endif