60
60
#include <BaServerLib.h>
61
61
#include "BAS/examples/xedge/src/xedge.h"
62
62
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
+
63
98
/***************************************************************************
64
99
* Private Data
65
100
***************************************************************************/
66
101
67
- static int running ; /* Server running mode */
102
+ static int running = FALSE ; /* Running mode: 2 running, 1 exiting, 0 stopped */
68
103
69
104
/* BAS is configured to use dlmalloc for NuttX. This is the pool.
70
105
* 2M : recommended minimum
71
106
*/
72
107
73
108
static char poolbuf [2 * 1024 * 1024 ];
74
109
75
- extern LThreadMgr ltMgr ; /* The LThreadMgr configured in xedge.c */
110
+ extern lthreadmgr ltmgr ; /* The LThreadMgr configured in xedge.c */
76
111
77
112
/***************************************************************************
78
113
* External Function Prototypes
@@ -82,7 +117,7 @@ extern LThreadMgr ltMgr; /* The LThreadMgr configured in xedge.c */
82
117
83
118
extern void barracuda (void );
84
119
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 */
86
121
87
122
/***************************************************************************
88
123
* Private Functions
@@ -100,9 +135,9 @@ extern int (*platformInitDiskIo)(DiskIo *io); /* xedge.c */
100
135
* function is found, it will be executed as follows: _XedgeEvent("sntp")
101
136
*/
102
137
103
- static void execevent (ThreadJob * job , int msgh , LThreadMgr * mgr )
138
+ static void execevent (threadjob * job , int msgh , lthreadmgr * mgr )
104
139
{
105
- lua_State * L = job -> Lt ;
140
+ lua_State * L = job -> lt ;
106
141
lua_pushglobaltable (L );
107
142
lua_getfield (L , -1 , "_XedgeEvent" );
108
143
@@ -115,9 +150,9 @@ static void execevent(ThreadJob *job, int msgh, LThreadMgr *mgr)
115
150
116
151
/* Thread started by xedgeOpenAUX() */
117
152
118
- static void * checkTimeThread (void * arg )
153
+ static void * checktimethread (void * arg )
119
154
{
120
- ThreadMutex * dm = HttpServer_getMutex ( ltMgr .server );
155
+ threadmutex * dm = httpserver_getmutex ( ltmgr .server );
121
156
const char * d = __DATE__ ;
122
157
char buf [50 ];
123
158
@@ -126,26 +161,26 @@ static void *checkTimeThread(void *arg)
126
161
if (!(basnprintf (buf , sizeof (buf ), "Mon, %c%c %c%c%c %s %s" ,
127
162
d [4 ], d [5 ], d [0 ], d [1 ], d [2 ], d + 7 , __TIME__ ) < 0 ))
128
163
{
129
- BaTime t = baParseDate (buf );
164
+ batime t = baparsedate (buf );
130
165
if (t )
131
166
{
132
167
t -= 24 * 60 * 60 ;
133
- while (baGetUnixTime () < t )
168
+ while (bagetunixtime () < t )
134
169
{
135
- Thread_sleep (500 );
170
+ thread_sleep (500 );
136
171
}
137
172
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 );
142
177
}
143
178
}
144
179
145
180
return NULL ;
146
181
}
147
182
148
- static void panic (BaFatalErrorCodes ecode1 ,
183
+ static void panic (bafatalerrorcodes ecode1 ,
149
184
unsigned int ecode2 ,
150
185
const char * file ,
151
186
int line )
@@ -159,9 +194,9 @@ static void panic(BaFatalErrorCodes ecode1,
159
194
* https://realtimelogic.com/ba/doc/en/C/reference/html/structHttpTrace.html
160
195
*/
161
196
162
- static void flushtrace (char * buf , int bufLen )
197
+ static void flushtrace (char * buf , int buflen )
163
198
{
164
- buf [bufLen ] = 0 ;
199
+ buf [buflen ] = 0 ;
165
200
syslog (LOG_INFO , "%s" , buf );
166
201
}
167
202
@@ -170,11 +205,11 @@ static void sighandler(int signo)
170
205
if (running )
171
206
{
172
207
printf ("\nGot SIGTERM; exiting...\n" );
173
- setDispExit ();
208
+ setdispexit ();
174
209
175
210
/* NuttX feature: Must wait for socket select() to return */
176
211
177
- Thread_sleep (2000 );
212
+ thread_sleep (2000 );
178
213
}
179
214
}
180
215
@@ -186,9 +221,9 @@ static void sighandler(int signo)
186
221
* Change "/mnt/lfs" to your preference.
187
222
*/
188
223
189
- int xedgeInitDiskIo ( DiskIo * io )
224
+ int xedgeinitdiskio ( diskio * io )
190
225
{
191
- if (DiskIo_setRootDir (io , "/mnt/lfs" ))
226
+ if (diskio_setrootdir (io , "/mnt/lfs" ))
192
227
{
193
228
syslog (LOG_ERR , "Error: cannot set root to /mnt/lfs\n" );
194
229
return -1 ;
@@ -201,7 +236,7 @@ int xedgeInitDiskIo(DiskIo *io)
201
236
* Tutorial: https://tutorial.realtimelogic.com/Lua-Bindings.lsp
202
237
*/
203
238
204
- int xedgeOpenAUX ( XedgeOpenAUX * aux )
239
+ int xedgeopenaux ( xedgeopenauxt * aux )
205
240
{
206
241
pthread_t thread ;
207
242
pthread_attr_t attr ;
@@ -213,20 +248,26 @@ int xedgeOpenAUX(XedgeOpenAUX *aux)
213
248
pthread_attr_setstacksize (& attr , 4096 );
214
249
param .sched_priority = SCHED_PRIORITY_DEFAULT ;
215
250
pthread_attr_setschedparam (& attr , & param );
216
- pthread_create (& thread , & attr , checkTimeThread , NULL );
251
+ pthread_create (& thread , & attr , checktimethread , NULL );
217
252
218
253
return 0 ;
219
254
}
220
255
221
256
int main (int argc , FAR char * argv [])
222
257
{
258
+ if (running )
259
+ {
260
+ printf ("Already running!\n" );
261
+ return 1 ;
262
+ }
263
+
223
264
signal (SIGINT , sighandler );
224
265
signal (SIGTERM , sighandler );
225
266
226
267
ntpc_start ();
227
268
init_dlmalloc (poolbuf , poolbuf + sizeof (poolbuf ));
228
- HttpTrace_setFLushCallback (flushtrace );
229
- HttpServer_setErrHnd (panic );
269
+ httptrace_setflushcallback (flushtrace );
270
+ httpserver_seterrhnd (panic );
230
271
231
272
running = TRUE;
232
273
barracuda ();
0 commit comments