csleeptimer/actions.c

40 lines
780 B
C

#include <string.h>
#include <unistd.h>
#include "echo.h"
#include "stdio.h"
#include "suspend.h"
#include "actions.h"
const char *ACTION_ECHO = "echo";
const char *ACTION_SUSPEND = "suspend";
enum Action parseAction(const char *action) {
enum Action a = ActionSuspend;
if (strcmp(action, ACTION_ECHO) == 0) {
a = ActionEcho;
} else if (strcmp(action, ACTION_SUSPEND) == 0) {
a = ActionSuspend;
} else {
a = ActionUnknown;
}
return a;
}
actionCallback getActionCallback(enum Action action) {
actionCallback callback = suspend;
switch (action) {
case ActionSuspend:
callback = suspend;
break;
case ActionEcho:
callback = echo;
break;
default:
fprintf(stderr, "Unknown method\n");
return NULL;
}
return callback;
}