]> git.pond.sub.org Git - empserver/blobdiff - include/file.h
Generation numbers to catch write back of stale copies
[empserver] / include / file.h
index 3d8587bd50b4a10afe84f311782f37a3b82f094c..58146d31cdb8e73106fb145a0cb6ae7b7fb82fae 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  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
@@ -26,7 +26,7 @@
  *  ---
  *
  *  file.h: Describes Empire tables (`files' for historical reasons)
- * 
+ *
  *  Known contributors to this file:
  *     Markus Armbruster, 2005-2008
  */
@@ -61,23 +61,34 @@ struct empfile {
 
     /* 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;
 };
 
@@ -88,7 +99,7 @@ struct emptypedstr {
  */
 /* 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
@@ -193,10 +204,13 @@ enum {
 
 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);
 extern int ef_open(int, int, int);
+extern int ef_open_view(int, int);
 extern int ef_close(int);
 extern int ef_flush(int);
 extern void ef_blank(int, int, void *);