spBase
Loading...
Searching...
No Matches
command_thread.c
#include <stdio.h>
#include <stdlib.h>
#include <sp/spBase.h>
#include <sp/spThread.h>
static volatile spBool flag = SP_FALSE;
void command_func(spCommandThreadStatus status, long data, void *user_data)
{
char *path = (char *)user_data;
switch (status) {
fprintf(stdout, "thread started\n");
break;
fprintf(stdout, "thread finished\n");
flag = SP_TRUE;
break;
fprintf(stdout, "command \"%s\" finished: %d\n", path, data);
break;
fprintf(stdout, "command \"%s\" failed: %d\n", path, data);
break;
default:
break;
}
return;
}
int main(int argc, char *argv[])
{
int i;
if (argc != 2) {
fprintf(stderr, "usage: command_thread <command>\n");
exit(1);
}
spCreateCommandThread(argv[1], command_func, argv[1]);
for (i = 0;; i++) {
if (flag == SP_TRUE) {
break;
}
printf("i = %d\n", i);
}
return 0;
}
int spBool
Definition spDefs.h:248
#define SP_TRUE
Definition spDefs.h:250
#define SP_FALSE
Definition spDefs.h:251
spCommandThreadStatus
Definition spThread.h:109
spBool spCreateCommandThread(const char *command, spCommandThreadCallback func, void *data)
@ SP_COMMAND_THREAD_COMMAND_FINISHED
Definition spThread.h:112
@ SP_COMMAND_THREAD_STARTED
Definition spThread.h:110
@ SP_COMMAND_THREAD_FINISHED
Definition spThread.h:111
@ SP_COMMAND_THREAD_COMMAND_FAILED
Definition spThread.h:113