Skip to content

Commit 60916b7

Browse files
committed
Now passes checkpatch.sh
1 parent 00266e3 commit 60916b7

File tree

1 file changed

+66
-25
lines changed

1 file changed

+66
-25
lines changed

examples/xedge/xedge_main.c

Lines changed: 66 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,54 @@
6060
#include <BaServerLib.h>
6161
#include "BAS/examples/xedge/src/xedge.h"
6262

63+
/***************************************************************************
64+
* Pre-processor Definitions
65+
***************************************************************************/
66+
67+
/* The following is a horrible hack to make the code pass the NuttX
68+
* checkpatch.sh tool. The Barracuda App Server uses a type of
69+
* camelCase encoding as explained here:
70+
* https://realtimelogic.com/ba/doc/en/C/introduction.html#oo_c
71+
*/
72+
73+
#define ltmgr ltMgr
74+
#define lthreadmgr LThreadMgr
75+
#define lthreadmgr_run LThreadMgr_run
76+
#define platforminitdiskio platformInitDiskIo
77+
#define diskio DiskIo
78+
#define diskio_setrootdir DiskIo_setRootDir
79+
#define threadjob ThreadJob
80+
#define threadjob_lcreate ThreadJob_lcreate
81+
#define lt Lt
82+
#define threadmutex ThreadMutex
83+
#define threadmutex_set ThreadMutex_set
84+
#define httpserver_getmutex HttpServer_getMutex
85+
#define threadmutex_release ThreadMutex_release
86+
#define xedgeinitdiskio xedgeInitDiskIo
87+
#define batime BaTime
88+
#define baparsedate baParseDate
89+
#define bagetunixtime baGetUnixTime
90+
#define thread_sleep Thread_sleep
91+
#define bafatalerrorcodes BaFatalErrorCodes
92+
#define setdispexit setDispExit
93+
#define xedgeopenaux xedgeOpenAUX
94+
#define xedgeopenauxt XedgeOpenAUX
95+
#define httptrace_setflushcallback HttpTrace_setFLushCallback
96+
#define httpserver_seterrhnd HttpServer_setErrHnd
97+
6398
/***************************************************************************
6499
* Private Data
65100
***************************************************************************/
66101

67-
static int running; /* Server running mode */
102+
static int running = FALSE; /* Running mode: 2 running, 1 exiting, 0 stopped */
68103

69104
/* BAS is configured to use dlmalloc for NuttX. This is the pool.
70105
* 2M : recommended minimum
71106
*/
72107

73108
static char poolbuf[2 * 1024 * 1024];
74109

75-
extern LThreadMgr ltMgr; /* The LThreadMgr configured in xedge.c */
110+
extern lthreadmgr ltmgr; /* The LThreadMgr configured in xedge.c */
76111

77112
/***************************************************************************
78113
* External Function Prototypes
@@ -82,7 +117,7 @@ extern LThreadMgr ltMgr; /* The LThreadMgr configured in xedge.c */
82117

83118
extern void barracuda(void);
84119
extern void init_dlmalloc(char *heapstart, char *heapend); /* dlmalloc.c */
85-
extern int (*platformInitDiskIo)(DiskIo *io); /* xedge.c */
120+
extern int (*platforminitdiskio)(diskio *io); /* xedge.c */
86121

87122
/***************************************************************************
88123
* Private Functions
@@ -100,9 +135,9 @@ extern int (*platformInitDiskIo)(DiskIo *io); /* xedge.c */
100135
* function is found, it will be executed as follows: _XedgeEvent("sntp")
101136
*/
102137

103-
static void execevent(ThreadJob *job, int msgh, LThreadMgr *mgr)
138+
static void execevent(threadjob *job, int msgh, lthreadmgr *mgr)
104139
{
105-
lua_State *L = job->Lt;
140+
lua_State *L = job->lt;
106141
lua_pushglobaltable(L);
107142
lua_getfield(L, -1, "_XedgeEvent");
108143

@@ -115,9 +150,9 @@ static void execevent(ThreadJob *job, int msgh, LThreadMgr *mgr)
115150

116151
/* Thread started by xedgeOpenAUX() */
117152

118-
static void *checkTimeThread(void *arg)
153+
static void *checktimethread(void *arg)
119154
{
120-
ThreadMutex *dm = HttpServer_getMutex(ltMgr.server);
155+
threadmutex *dm = httpserver_getmutex(ltmgr.server);
121156
const char *d = __DATE__;
122157
char buf[50];
123158

@@ -126,26 +161,26 @@ static void *checkTimeThread(void *arg)
126161
if (!(basnprintf(buf, sizeof(buf), "Mon, %c%c %c%c%c %s %s",
127162
d[4], d[5], d[0], d[1], d[2], d + 7, __TIME__) < 0))
128163
{
129-
BaTime t = baParseDate(buf);
164+
batime t = baparsedate(buf);
130165
if (t)
131166
{
132167
t -= 24 * 60 * 60;
133-
while (baGetUnixTime() < t)
168+
while (bagetunixtime() < t)
134169
{
135-
Thread_sleep(500);
170+
thread_sleep(500);
136171
}
137172

138-
ThreadJob *job = ThreadJob_lcreate(sizeof(ThreadJob), execevent);
139-
ThreadMutex_set(dm);
140-
LThreadMgr_run(&ltMgr, job);
141-
ThreadMutex_release(dm);
173+
threadjob *job = threadjob_lcreate(sizeof(threadjob), execevent);
174+
threadmutex_set(dm);
175+
lthreadmgr_run(&ltmgr, job);
176+
threadmutex_release(dm);
142177
}
143178
}
144179

145180
return NULL;
146181
}
147182

148-
static void panic(BaFatalErrorCodes ecode1,
183+
static void panic(bafatalerrorcodes ecode1,
149184
unsigned int ecode2,
150185
const char *file,
151186
int line)
@@ -159,9 +194,9 @@ static void panic(BaFatalErrorCodes ecode1,
159194
* https://realtimelogic.com/ba/doc/en/C/reference/html/structHttpTrace.html
160195
*/
161196

162-
static void flushtrace(char *buf, int bufLen)
197+
static void flushtrace(char *buf, int buflen)
163198
{
164-
buf[bufLen] = 0;
199+
buf[buflen] = 0;
165200
syslog(LOG_INFO, "%s", buf);
166201
}
167202

@@ -170,11 +205,11 @@ static void sighandler(int signo)
170205
if (running)
171206
{
172207
printf("\nGot SIGTERM; exiting...\n");
173-
setDispExit();
208+
setdispexit();
174209

175210
/* NuttX feature: Must wait for socket select() to return */
176211

177-
Thread_sleep(2000);
212+
thread_sleep(2000);
178213
}
179214
}
180215

@@ -186,9 +221,9 @@ static void sighandler(int signo)
186221
* Change "/mnt/lfs" to your preference.
187222
*/
188223

189-
int xedgeInitDiskIo(DiskIo *io)
224+
int xedgeinitdiskio(diskio *io)
190225
{
191-
if (DiskIo_setRootDir(io, "/mnt/lfs"))
226+
if (diskio_setrootdir(io, "/mnt/lfs"))
192227
{
193228
syslog(LOG_ERR, "Error: cannot set root to /mnt/lfs\n");
194229
return -1;
@@ -201,7 +236,7 @@ int xedgeInitDiskIo(DiskIo *io)
201236
* Tutorial: https://tutorial.realtimelogic.com/Lua-Bindings.lsp
202237
*/
203238

204-
int xedgeOpenAUX(XedgeOpenAUX *aux)
239+
int xedgeopenaux(xedgeopenauxt *aux)
205240
{
206241
pthread_t thread;
207242
pthread_attr_t attr;
@@ -213,20 +248,26 @@ int xedgeOpenAUX(XedgeOpenAUX *aux)
213248
pthread_attr_setstacksize(&attr, 4096);
214249
param.sched_priority = SCHED_PRIORITY_DEFAULT;
215250
pthread_attr_setschedparam(&attr, &param);
216-
pthread_create(&thread, &attr, checkTimeThread, NULL);
251+
pthread_create(&thread, &attr, checktimethread, NULL);
217252

218253
return 0;
219254
}
220255

221256
int main(int argc, FAR char *argv[])
222257
{
258+
if (running)
259+
{
260+
printf("Already running!\n");
261+
return 1;
262+
}
263+
223264
signal(SIGINT, sighandler);
224265
signal(SIGTERM, sighandler);
225266

226267
ntpc_start();
227268
init_dlmalloc(poolbuf, poolbuf + sizeof(poolbuf));
228-
HttpTrace_setFLushCallback(flushtrace);
229-
HttpServer_setErrHnd(panic);
269+
httptrace_setflushcallback(flushtrace);
270+
httpserver_seterrhnd(panic);
230271

231272
running = TRUE;
232273
barracuda();

0 commit comments

Comments
 (0)