]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/resource.h
tableprinter: add of table_col_is_printed
[libucw.git] / ucw / resource.h
index d2a415c3fca9de02e181057388f2db60abce5dd1..a2783a75f9687c5bb7162fdc68794c6d1727147d 100644 (file)
 #ifndef _UCW_RESPOOL_H
 #define _UCW_RESPOOL_H
 
 #ifndef _UCW_RESPOOL_H
 #define _UCW_RESPOOL_H
 
-#include "ucw/clists.h"
-#include "ucw/threads.h"
+#include <ucw/clists.h>
+#include <ucw/threads.h>
+
+#ifdef CONFIG_UCW_CLEAN_ABI
+#define res_add ucw_res_add
+#define res_alloc ucw_res_alloc
+#define res_detach ucw_res_detach
+#define res_drop ucw_res_drop
+#define res_dump ucw_res_dump
+#define res_eltpool ucw_res_eltpool
+#define res_for_fd ucw_res_for_fd
+#define res_free ucw_res_free
+#define res_malloc ucw_res_malloc
+#define res_malloc_zero ucw_res_malloc_zero
+#define res_mempool ucw_res_mempool
+#define res_realloc ucw_res_realloc
+#define res_subpool ucw_res_subpool
+#define rp_commit ucw_rp_commit
+#define rp_delete ucw_rp_delete
+#define rp_detach ucw_rp_detach
+#define rp_dump ucw_rp_dump
+#define rp_new ucw_rp_new
+#endif
 
 /**
  * A resource pool. It contains a name of the pool (which is printed
 
 /**
  * A resource pool. It contains a name of the pool (which is printed
@@ -23,7 +44,7 @@ struct respool {
   const char *name;
   struct mempool *mpool;                               // If set, resources are allocated from the mempool, otherwise by xmalloc()
   struct resource *subpool_of;
   const char *name;
   struct mempool *mpool;                               // If set, resources are allocated from the mempool, otherwise by xmalloc()
   struct resource *subpool_of;
-  uns default_res_flags;                               // RES_FLAG_xxx for newly allocated resources
+  uint default_res_flags;                              // RES_FLAG_xxx for newly allocated resources
 };
 
 /**
 };
 
 /**
@@ -34,7 +55,7 @@ struct respool {
 struct resource {
   cnode n;
   struct respool *rpool;
 struct resource {
   cnode n;
   struct respool *rpool;
-  uns flags;                                           // RES_FLAG_xxx
+  uint flags;                                          // RES_FLAG_xxx
   const struct res_class *rclass;
   void *priv;                                          // Private to the class
   // More data specific for the particular class can follow
   const struct res_class *rclass;
   void *priv;                                          // Private to the class
   // More data specific for the particular class can follow
@@ -43,6 +64,7 @@ struct resource {
 /** Resource flags **/
 enum resource_flags {
   RES_FLAG_TEMP = 1,                                   // Resource is temporary
 /** Resource flags **/
 enum resource_flags {
   RES_FLAG_TEMP = 1,                                   // Resource is temporary
+  RES_FLAG_XFREE = 2,                                  // Resource structure needs to be deallocated by xfree()
 };
 
 /**
 };
 
 /**
@@ -54,7 +76,7 @@ struct respool *rp_new(const char *name, struct mempool *mp);
 void rp_delete(struct respool *rp);                    /** Deletes a resource pool, freeing all resources. **/
 void rp_detach(struct respool *rp);                    /** Deletes a resource pool, detaching all resources. **/
 void rp_commit(struct respool *rp);                    /** Deletes a resource pool. Temporary resources are freed, stable resources are detached. **/
 void rp_delete(struct respool *rp);                    /** Deletes a resource pool, freeing all resources. **/
 void rp_detach(struct respool *rp);                    /** Deletes a resource pool, detaching all resources. **/
 void rp_commit(struct respool *rp);                    /** Deletes a resource pool. Temporary resources are freed, stable resources are detached. **/
-void rp_dump(struct respool *rp, uns indent);          /** Prints out a debugging dump of a pool to stdout. **/
+void rp_dump(struct respool *rp, uint indent);         /** Prints out a debugging dump of a pool to stdout. **/
 
 /** Returns a pointer to the currently active resource pool or NULL, if none exists. **/
 static inline struct respool *rp_current(void)
 
 /** Returns a pointer to the currently active resource pool or NULL, if none exists. **/
 static inline struct respool *rp_current(void)
@@ -74,9 +96,9 @@ static inline struct respool *rp_switch(struct respool *rp)
   return orp;
 }
 
   return orp;
 }
 
-struct resource *res_alloc(const struct res_class *rc) LIKE_MALLOC;    // Returns NULL if there is no pool active
+struct resource *res_alloc(const struct res_class *rc) LIKE_MALLOC;    // Dies if there is no pool active
 
 
-void res_dump(struct resource *r, uns indent);         /** Prints out a debugging dump of the resource to stdout. **/
+void res_dump(struct resource *r, uint indent);                /** Prints out a debugging dump of the resource to stdout. **/
 
 /**
  * Frees a resource, unlinking it from its pool.
 
 /**
  * Frees a resource, unlinking it from its pool.
@@ -126,10 +148,27 @@ struct res_class {
   const char *name;                                    // The name of the class (included in debugging dumps)
   void (*detach)(struct resource *r);                  // The callbacks
   void (*free)(struct resource *r);
   const char *name;                                    // The name of the class (included in debugging dumps)
   void (*detach)(struct resource *r);                  // The callbacks
   void (*free)(struct resource *r);
-  void (*dump)(struct resource *r, uns indent);
-  uns res_size;                                                // Size of the resource structure (0=default)
+  void (*dump)(struct resource *r, uint indent);
+  uint res_size;                                               // Size of the resource structure (0=default)
 };
 
 };
 
+/**
+ * Initialize a pre-allocated buffer to the specific class of resource, setting its private data to @priv.
+ * This resource can be added to the current pool by @res_add().
+ **/
+static inline struct resource *res_init(struct resource *r, const struct res_class *rc, void *priv)
+{
+  r->flags = 0;
+  r->rclass = rc;
+  r->priv = priv;
+  return r;
+}
+
+/**
+ * Links a pre-initialized resource to the active pool.
+ **/
+void res_add(struct resource *r);
+
 /**
  * Unlinks a resource from a pool and releases its meta-data. Unlike @res_detach(),
  * it does not invoke any callbacks. The caller must make sure that no references to
 /**
  * Unlinks a resource from a pool and releases its meta-data. Unlike @res_detach(),
  * it does not invoke any callbacks. The caller must make sure that no references to