/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* ---
*
* file.h: Describes Empire tables (`files' for historical reasons)
- *
+ *
* Known contributors to this file:
* Markus Armbruster, 2005-2008
*/
/* User callbacks, may all be null */
/*
- * Called after read, with file type and element as arguments.
- * May modify the element. Modifications are visible to caller of
- * ef_read(), but have no effect on the file.
+ * Called after element initialization. ELT is the element.
+ */
+ void (*oninit)(void *elt);
+ /*
+ * Called after read. ID is the element id, and ELT is the
+ * element read. May modify the element. Modifications are
+ * visible to caller of ef_read(), but have no effect on the file.
+ */
+ void (*postread)(int id, void *elt);
+ /*
+ * Called before write. ID is the element id, OLD is the element
+ * being updated (null unless it is cached) and ELT is the element
+ * being written. May modify the element. Modifications will be
+ * visible to caller of ef_write() and are written to the file.
*/
- void (*postread)(int, void *);
+ void (*prewrite)(int id, void *old, void *elt);
/*
- * Called before write, with file type and element as arguments.
- * May modify the element. Modifications will be visible to
- * caller of ef_write() and are written to the file.
+ * Called after table size changed, with file type as argument.
+ * Return -1 and set errno to make the operation fail.
*/
- void (*prewrite)(int, void *);
+ int (*onresize)(int type);
};
struct emptypedstr {
- short ef_type;
- short uid;
- unsigned seqno;
+ signed ef_type: 8;
+ unsigned seqno: 12;
+ unsigned generation: 12;
+ int uid;
time_t timestamp;
};
*/
/* Immutable flags, fixed at compile-time */
/* Dereferencing entry address cast to struct emptypedstr * is safe */
-#define EFF_TYPED bit(0)
+#define EFF_TYPED bit(0)
/*
* EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
* group of such a table's entries can be safely obtained by
extern struct castr *ef_cadef(int);
extern int ef_read(int, int, void *);
+extern void ef_make_stale(void);
+extern void ef_mark_fresh(int, void *);
extern void *ef_ptr(int, int);
extern char *ef_nameof(int);
extern time_t ef_mtime(int);