#ifndef _MONITOR_H
#define _MONITOR_H 1

#include <stddef.h>

#include "..\Runtime\Runtime.h"

#define MONITOR_ALL_INDEX -1

#define MONITORS \
   MONITOR_TIME_ENTRY, \
   MONITOR_PROCESS_ENTRY, \
   MONITOR_CONNECTION_ENTRY, \
   MONITOR_SCREENSAVER_ENTRY, \
   MONITOR_IDLE_ENTRY, \
   MONITOR_WINDOW_ENTRY, \
   MONITOR_QUOTA_ENTRY,

#define MONITOR_TIME_INDEX 0
#define MONITOR_TIME monitorv[MONITOR_TIME_INDEX]
#define MONITOR_TIME_ENTRY { NULL, NULL }
#define MONITOR_TIME_REGISTER(f1, f2) monitor_register(MONITOR_TIME_INDEX, f1, f2)

#define MONITOR_PROCESS_INDEX 1
#define MONITOR_PROCESS monitorv[MONITOR_PROCESS_INDEX]
#define MONITOR_PROCESS_ENTRY { NULL, NULL }
#define MONITOR_PROCESS_REGISTER(f1, f2) monitor_register(MONITOR_PROCESS_INDEX, f1, f2)

#define MONITOR_CONNECTION_INDEX 2
#define MONITOR_CONNECTION monitorv[MONITOR_CONNECTION_INDEX]
#define MONITOR_CONNECTION_ENTRY { NULL, NULL }
#define MONITOR_CONNECTION_REGISTER(f1, f2) monitor_register(MONITOR_CONNECTION_INDEX, f1, f2)

#define MONITOR_SCREENSAVER_INDEX 3
#define MONITOR_SCREENSAVER monitorv[MONITOR_SCREENSAVER_INDEX]
#define MONITOR_SCREENSAVER_ENTRY { NULL, NULL }
#define MONITOR_SCREENSAVER_REGISTER(f1, f2) monitor_register(MONITOR_SCREENSAVER_INDEX, f1, f2)

#define MONITOR_IDLE_INDEX 4
#define MONITOR_IDLE monitorv[MONITOR_IDLE_INDEX]
#define MONITOR_IDLE_ENTRY { NULL, NULL }
#define MONITOR_IDLE_REGISTER(f1, f2) monitor_register(MONITOR_IDLE_INDEX, f1, f2)

#define MONITOR_WINDOW_INDEX 5
#define MONITOR_WINDOW monitorv[MONITOR_WINDOW_INDEX]
#define MONITOR_WINDOW_ENTRY { NULL, NULL }
#define MONITOR_WINDOW_REGISTER(f1, f2) monitor_register(MONITOR_WINDOW_INDEX, f1, f2)

#define MONITOR_QUOTA_INDEX 6
#define MONITOR_QUOTA monitorv[MONITOR_QUOTA_INDEX]
#define MONITOR_QUOTA_ENTRY { NULL, NULL }
#define MONITOR_QUOTA_REGISTER(f1, f2) monitor_register(MONITOR_QUOTA_INDEX, f1, f2)


typedef void* (*monitor_addwatch)(PRUNTIME pRuntime, void *(*)(void*), void *args, int flags, ...);
typedef void* (*monitor_delwatch)(PRUNTIME pRuntime, void *);


typedef struct {
	monitor_addwatch addwatch;
	monitor_delwatch delwatch;
} monitor_t;

#define MONITOR_FLAG_NONE 0x00
#define MONITOR_FLAG_PERM 0x01
#define MONITOR_FLAG_NEG  0x02


int monitor_register( int id, monitor_addwatch fp_monitor_addwatch, monitor_delwatch fp_monitor_delwatch);
void monitor_flush(PRUNTIME pRuntime, int id);

extern monitor_t monitorv[];

#endif /* _MONITOR_H */
