#ifndef X10MAP_H_
#define X10MAP_H_

#include <queue>

#define XS_EXIST	(1 << 0)	// Module exists
#define XS_TWOWAY	(1 << 1)	// Module is two-way
#define XS_ALIVE	(1 << 2)	// Module is responding
#define XS_LIGHT	(1 << 3)	// Module is a light or is dimmable
#define XS_ON		(1 << 4)	// Module is on
#define XS_ME		(1 << 5)	// I am the module.  Use ifunc.
#define XS_UPONLY	(1 << 6)	// Module fades up only, not down.
#define XS_DOWNONLY	(1 << 7)	// Module fades down only, not up.

typedef void INTERNALFUNC (int housecode, int unitcode, int command);

struct x10state {
	int flags;	// State flags
	int level;	// Dim level
	INTERNALFUNC *ifunc;	// action function.  NULL==external prog
};

struct x10event {
	int house;
	int unit;
	int cmd;
};

extern const char *parameter [];

class X10map {
public:
	X10map(char *format, int event_timeout);
	~X10map();
	int Update (int housecode, int command, int received = 0);
	int GetActiveUnit (int housecode);
	int GetTimeout (void);
	void Timeout (void);
protected:
	void ExecuteCommand (int house, int unit, int cmd);
	void CheckTimeout (void);
	int mfd;
	char *run_format;
	struct x10state *xmap;
	int active_unit[16];

	std::queue<x10event> q;
	pid_t kidpid;
	int timeout;
	time_t timeout_pending;
};



#endif

