Revision 65
logic/trunk/src/startup/main.c | ||
---|---|---|
8 | 8 |
#include <stdlib.h> |
9 | 9 |
#include <pthread.h> |
10 | 10 |
#include <syslog.h> |
11 |
#include <unistd.h> |
|
11 | 12 |
#include "../hci_comm/hciChanged.h" |
12 | 13 |
#include "../hci_comm/hci_comm.h" |
13 | 14 |
#include "../init/scenariolist.h" |
... | ... | |
56 | 57 |
|
57 | 58 |
// Application entry point |
58 | 59 |
int main(int argc, char *argv[]) { |
59 |
/** //DAEMON |
|
60 |
//** //DAEMON
|
|
60 | 61 |
pid_t pid, sid; |
61 | 62 |
|
62 | 63 |
pid = fork(); |
... | ... | |
147 | 148 |
} |
148 | 149 |
|
149 | 150 |
/*start some sort of control over scenarios? - hmm morda ne...bom jutri :)*/ |
150 |
printf("Exiting main thread\n"); |
|
151 |
//printf("Exiting main thread\n");
|
|
151 | 152 |
pthread_exit(0); |
152 | 153 |
} |
153 | 154 |
|
... | ... | |
285 | 286 |
{ |
286 | 287 |
thread_id_holder *hold; |
287 | 288 |
hold = hThrIDhold_dev; |
288 |
//hThrIDhold_dev = NULL; |
|
289 | 289 |
|
290 | 290 |
//kill device threads |
291 |
printf("Attempting to cancel threads!\n"); |
|
292 | 291 |
while(hold) |
293 | 292 |
{ |
294 |
printf("Cancelling dev thread %ld with return state %d\n", hold->pthr_idx,pthread_cancel(hold->pthr_idx)); |
|
295 |
//TODO free thread_id_holder list too! |
|
293 |
pthread_cancel(hold->pthr_idx); |
|
296 | 294 |
hold=hold->nxt; |
297 | 295 |
} |
298 | 296 |
|
... | ... | |
301 | 299 |
//hThrIDhold_scn = NULL; |
302 | 300 |
while(hold) |
303 | 301 |
{ |
304 |
printf("Cancelling scn thread %ld with return state %d\n", hold->pthr_idx,pthread_cancel(hold->pthr_idx)); |
|
305 |
//TODO free thread_id_holder list too! |
|
302 |
pthread_cancel(hold->pthr_idx); |
|
306 | 303 |
hold=hold->nxt; |
307 | 304 |
} |
308 | 305 |
|
309 | 306 |
//free memory |
310 |
printf("Freeing memory!\n"); |
|
307 |
//printf("Freeing memory!\n");
|
|
311 | 308 |
freeDeviceList(hDevice); |
312 | 309 |
freeScenarioList(hScenario); |
313 | 310 |
freeThreadIDList(hThrIDhold_dev); |
314 | 311 |
freeThreadIDList(hThrIDhold_scn); |
315 | 312 |
|
316 | 313 |
//reinit devices |
317 |
printf("Reinitializing devices!\n"); |
|
314 |
//printf("Reinitializing devices!\n");
|
|
318 | 315 |
hDevice = setDeviceList(); |
319 | 316 |
|
320 | 317 |
//reinit scenarios |
321 |
printf("Reinitializing scenarios!\n"); |
|
318 |
//printf("Reinitializing scenarios!\n");
|
|
322 | 319 |
hScenario = setNewScenarioList(hDevice); |
323 | 320 |
|
324 | 321 |
//restart main thread |
325 |
printf("Restarting main thread!\n"); |
|
322 |
//printf("Restarting main thread!\n");
|
|
326 | 323 |
pthread_create(&decisionMakingThread,NULL,decisionMakingThread_routine,NULL); |
327 | 324 |
|
328 | 325 |
return 1; //sucess, TODO add fail conditions |
... | ... | |
332 | 329 |
{ |
333 | 330 |
thread_id_holder *hold; |
334 | 331 |
hold = hThrIDhold_dev; |
335 |
//hThrIDhold_dev = NULL; |
|
336 | 332 |
|
337 | 333 |
//kill device threads |
338 |
printf("Attempting to cancel threads!\n"); |
|
334 |
//printf("Attempting to cancel threads!\n");
|
|
339 | 335 |
while(hold) |
340 | 336 |
{ |
341 |
printf("Cancelling dev thread %ld with return state %d\n", hold->pthr_idx,pthread_cancel(hold->pthr_idx)); |
|
342 |
//TODO free thread_id_holder list too! |
|
337 |
pthread_cancel(hold->pthr_idx); |
|
343 | 338 |
hold=hold->nxt; |
344 | 339 |
} |
345 | 340 |
|
346 | 341 |
//kill scenario threads |
347 | 342 |
hold = hThrIDhold_scn; |
348 |
//hThrIDhold_scn = NULL; |
|
349 | 343 |
while(hold) |
350 | 344 |
{ |
351 |
printf("Cancelling scn thread %ld with return state %d\n", hold->pthr_idx,pthread_cancel(hold->pthr_idx));
|
|
345 |
pthread_cancel(hold->pthr_idx);
|
|
352 | 346 |
//TODO free thread_id_holder list too! |
353 | 347 |
hold=hold->nxt; |
354 | 348 |
} |
355 | 349 |
|
356 | 350 |
//free memory |
357 |
printf("Freeing memory!\n"); |
|
351 |
//printf("Freeing memory!\n");
|
|
358 | 352 |
freeDeviceList(hDevice); |
359 | 353 |
freeScenarioList(hScenario); |
360 | 354 |
freeThreadIDList(hThrIDhold_dev); |
Also available in: Unified diff