/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* ---
*
* file.h: Describes Empire tables (`files' for historical reasons)
- *
+ *
* Known contributors to this file:
- * Markus Armbruster, 2005-2008
+ * Markus Armbruster, 2005-2010
*/
#ifndef FILE_H
/* flags bit EFF_CUSTOM also varies */
/* User callbacks, may all be null */
+ /*
+ * 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
*/
void (*postread)(int id, void *elt);
/*
- * Called before write. ID is the element id, 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.
+ * 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 (*prewrite)(int id, void *old, void *elt);
+ /*
+ * Called after table size changed, with file type as argument.
+ * Return -1 and set errno to make the operation fail.
*/
- void (*prewrite)(int id, void *elt);
+ 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);