#ifndef _ACTIONMANAGER_H
#define _ACTIONMANAGER_H 1

#include "json.h"

#define ACTION_NONE -1

#define ACTION_EVENT 0
typedef struct {
	int event;
	int status;
} action_event_t;
int(*am_event)(PRUNTIME pRuntime, action_event_t *a);
#define ACTION_EVENT_P(x) ((action_event_t *)((x)->param))
#define ACTION_EVENT_INIT(x) am_event = x

#define ACTION_MODULE 1
typedef struct {
	int module;
	int status;
} action_module_t;
int(*am_module)(PRUNTIME pRuntime, action_module_t *a);
#define ACTION_MODULE_P(x) ((action_module_t *)((x)->param))
#define ACTION_MODULE_INIT(x) am_module = x

#define ACTION_UNINSTALL 2
typedef void action_uninstall_t;
int(*am_uninstall)(PRUNTIME pRuntime, action_uninstall_t *a);
#define ACTION_UNINSTALL_P(x) ((action_uninstall_t *)((x)->param))
#define ACTION_UNINSTALL_INIT(x) am_uninstall = x

#define ACTION_EXECUTE 3
typedef struct {
	char command[512];
} action_execute_t;
int(*am_execute)(PRUNTIME pRuntime, action_execute_t *a);
#define ACTION_EXECUTE_P(x) ((action_execute_t *)((x)->param))
#define ACTION_EXECUTE_INIT(x) am_execute = x

#define ACTION_LOG 4
typedef struct {
	char text[512];
} action_log_t;
int(*am_log)(PRUNTIME pRuntime, action_log_t *a);
#define ACTION_LOG_P(x) ((action_log_t *)((x)->param))
#define ACTION_LOG_INIT(x) am_log = x

#define ACTION_SYNCHRONIZE 5
typedef struct {
	char host[512];
	int bandwidth;
	int mindelay;
	int maxdelay;
	int stop;
} action_synchronize_t;
int(*am_synchronize)(PRUNTIME pRuntime, action_synchronize_t *a);
#define ACTION_SYNCHRONIZE_P(x) ((action_synchronize_t *)((x)->param))
#define ACTION_SYNCHRONIZE_INIT(x) am_synchronize = x

#define ACTION_DESTROY 6
typedef struct {
	int permanent;
} action_destroy_t;
int(*am_destroy)(PRUNTIME pRuntime, action_destroy_t *a);
#define ACTION_DESTROY_P(x) ((action_destroy_t *)((x)->param))
#define ACTION_DESTROY_INIT(x) am_destroy = x

typedef struct {
	int type;
	void *param;
} action_t;

typedef struct {
	int queue;
	int sched;
	int actionc;
	action_t *actionv;
} actiongroup_t;

#define QUEUE_SLOW 0
#define QUEUE_FAST 1

#define QSTATUS_STARTING 0
#define QSTATUS_STARTED  1
#define QSTATUS_STOPPING 2
#define QSTATUS_STOPPED  3

void am_init(PRUNTIME pRuntime);
void am_parseconfig(PRUNTIME pRuntime, json_object *config);
void am_createqueues(PRUNTIME pRuntime);
void am_queueaction(int actionid);
void am_startqueue(PRUNTIME pRuntime, int q);
void am_stopqueue(PRUNTIME pRuntime, int q);

#endif /* _ACTIONMANAGER_H */
