event.h 3.58 KB
#ifndef SCOT_EVENT_H
#define SCOT_EVENT_H

#include <stddef.h>

#include <scot/scot_int.h>
#include <scot/scot_types.h>

#define SCOT_EVENT_NO		uint16_t

/*
 * basis event struktur. Ein Typ und die wirkliche größe.
 */
struct scot_event
{
	SCOT_EVENT_NO event;
	uint32_t      size;       /* is used with serialization. If an event
										  was serialized and send over a datalink,
										  it is possible that not all data is read
										  at once. So i can first read 
										  sizeof (struct scot_event) and then i
										  know exactly how much has to be read for
										  the whole event. */
	uint32_t      ed_size;    /* This reflects the size of the extra_data
										  buffer...when serializing is done it is
										  neccessary to know where extra_data ends,
										  and as it could be any arbitrary data this
										  could not be guessed by the code. */
	void *        extra_data; /* maybe this should hold the object that
										  an callback function to this event belongs
										  to. */
};


struct scot_event * scot_event_new         (struct scot_event *, 
		                                      SCOT_EVENT_NO , void *, SIZE_T);
SIZE_T              scot_event_serialize   (struct scot_event *, char **);
struct scot_event * scot_event_deserialize (struct scot_event *, const char *);
void                scot_event_free        (struct scot_event *);

/*
 * event definitionen für stream pool events
 * Die stream pool event gruppe hat nur eine erweiterte event struktur,
 * es ist aber auch denkbar das eine event gruppe mehrere solche strukturen
 * einschließt. (Alle events die ein stream pool erzeugt  sind read
 * write oder exception auf einem stream und fuer alle diese events
 * reicht es den stream handle im event mitzugeben).
 */
struct scot_stream_pool_event
{
	struct scot_event         event;
	struct scot_stream *      st;
};

struct scot_stream_pool_event * scot_stream_pool_event_new (
		struct scot_stream_pool_event *,
		SCOT_EVENT_NO, void *, SIZE_T, struct scot_stream * );

/*
 * event definitionen für filesystem watcher events
 */
struct scot_fs_watcher_event
{
	struct scot_event event;
	char *            path;
	char *            name;
	char *            oldname; /* used by rename events */
};

struct scot_fs_watcher_event * scot_fs_watcher_event_new (
		struct scot_fs_watcher_event *,
		SCOT_EVENT_NO, void *, SIZE_T, 
		const char *, const char *, const char *);

#define GEN_SCOT_EVENT_NO (group, mask, no) ((group<<24)&(mask<<18)&no)
#define SCOT_EVENT_GEN_MASK(exp)            1<<(exp)

#define SCOT_EVENT_CHK_GROUP(e, g) (((e)&((SCOT_EVENT_NO)(g)<<8)) == ((g)<<8))

/* EG := EVENT_GROUP */
#define SCOT_EG_INTERNAL          ((SCOT_EVENT_NO)0)
#define SCOT_EG_STREAM_POOL       ((SCOT_EVENT_NO)1)
#define SCOT_EG_FS_WATCHER        ((SCOT_EVENT_NO)2)

#define SCOT_EVENT_STREAM_POOL_READ   \
	((SCOT_EVENT_NO)(SCOT_EG_STREAM_POOL << 8) | 0)
#define SCOT_EVENT_STREAM_POOL_WRITE  \
	((SCOT_EVENT_NO)(SCOT_EG_STREAM_POOL << 8) | 1)
#define SCOT_EVENT_STREAM_POOL_EXCEP  \
	((SCOT_EVENT_NO)(SCOT_EG_STREAM_POOL << 8) | 2)

#define SCOT_EVENT_FS_WATCHER_CREATE \
	((SCOT_EVENT_NO)(SCOT_EG_FS_WATCHER << 8) | 0)
#define SCOT_EVENT_FS_WATCHER_DELETE \
	((SCOT_EVENT_NO)(SCOT_EG_FS_WATCHER << 8) | 1)
#define SCOT_EVENT_FS_WATCHER_RENAME \
	((SCOT_EVENT_NO)(SCOT_EG_FS_WATCHER << 8) | 2)
#define SCOT_EVENT_FS_WATCHER_WRITTEN \
	((SCOT_EVENT_NO)(SCOT_EG_FS_WATCHER << 8) | 3)
#define SCOT_EVENT_FS_WATCHER_ATTRCHG \
	((SCOT_EVENT_NO)(SCOT_EG_FS_WATCHER << 8) | 4)
#define SCOT_EVENT_FS_WATCHER_SIZECHG \
	((SCOT_EVENT_NO)(SCOT_EG_FS_WATCHER << 8) | 5)


#endif /* SCOT_EVENT_H */