• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

rpmobject.h

Go to the documentation of this file.
00001 #ifndef _RPMOBJECT_H
00002 #define _RPMOBJECT_H
00003 
00004 #ifdef __cplusplus
00005 extern "C" {
00006 #endif
00007 
00008 /*
00009  * Rpm common object model, loosely based on Python's C-level objects.
00010  * For now, this only covers reference counting in rpm-style fooLink()
00011  * and fooUnlink().
00012  */
00013 
00014 typedef struct rpmTypeObject_s rpmTypeObject;
00015 
00016 /* Must be at the head of all rpm object structures */
00017 #define rpmObject_HEAD          \
00018         size_t ob_refcnt;       \
00019         rpmTypeObject * ob_type;
00020 
00021 #define rpmObject_HEAD_INIT(type)       \
00022         1, type,
00023 
00024 /* For now this is just so we have something to cast to */
00025 typedef struct rpmObject_s {
00026     rpmObject_HEAD
00027 } rpmObject;
00028 
00029 typedef enum rpmObjTypeFlags_e {
00030     RPMOBJ_NONE         = 0,
00031     RPMOBJ_NOREFCNT     = (1 << 0),
00032 } rpmObjTypeFlags;
00033 
00034 typedef void (*rpmobj_initfunc)(rpmObject *);
00035 typedef void (*rpmobj_destructor)(rpmObject *);
00036 
00037 /* Describes a type object */
00038 struct rpmTypeObject_s {
00039     rpmObject_HEAD
00040     const char *tp_name;                /* type name */
00041     size_t tp_basicsize;                /* allocation size of base struct */
00042     rpmObjTypeFlags tp_flags;           /* flags to control behavior */
00043 
00044     rpmobj_initfunc tp_init;            /* type initialization (optional) */
00045     rpmobj_destructor tp_destruct;      /* destructor (optional) */
00046 };
00047 
00048 /* Helper macros for creating type-specific wrappers */
00049 #define rpmObjLink(_type, _obj) (_type)rpmObjRef((rpmObject *)(_obj))
00050 #define rpmObjUnlink(_type, _obj) (_type)rpmObjDel((rpmObject *)(_obj))
00051 
00052 void * rpmObjRef(rpmObject * obj);
00053 #define rpmObjUnref(obj) rpmObjFree((obj))
00054 
00055 /* Create a new object instance of given type with refcount of 1. */
00056 void * rpmObjNew(rpmTypeObject * type);
00057 
00058 /* Free object when refcount reaches zero. Always return NULL. */
00059 void * rpmObjFree(rpmObject * obj);
00060 
00061 #ifdef __cplusplus
00062 }
00063 #endif
00064 
00065 #endif /* _RPMOBJECT_H */

Generated on Tue Sep 14 2010 for rpm by  doxygen 1.7.1