summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-11 14:34:53 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-11 14:34:53 +0000
commitdd575394dba4f1943a5185a5f40750a4293b7203 (patch)
tree360bdc8e0588c1330b80a4cab8c7ce61b1fd742b
parent8dad3997505f71e6e9962892f79d7b7dad0a89ce (diff)
downloadrsyslog-dd575394dba4f1943a5185a5f40750a4293b7203.tar.gz
rsyslog-dd575394dba4f1943a5185a5f40750a4293b7203.tar.xz
rsyslog-dd575394dba4f1943a5185a5f40750a4293b7203.zip
support for object property bags added
-rw-r--r--obj-types.h3
-rw-r--r--obj.c54
-rw-r--r--obj.h1
-rw-r--r--queue.c17
-rw-r--r--queue.h2
-rw-r--r--syslogd.c1
6 files changed, 63 insertions, 15 deletions
diff --git a/obj-types.h b/obj-types.h
index ca7e1c67..e712f5fd 100644
--- a/obj-types.h
+++ b/obj-types.h
@@ -57,7 +57,8 @@ typedef struct {
typedef enum { /* IDs of known object "types/classes" */
OBJNull = 0, /* no valid object (we do not start at zero so we can detect calloc()) */
OBJMsg = 1,
- OBJstrm = 2
+ OBJstrm = 2,
+ OBJqueue = 3
} objID_t;
#define OBJ_NUM_IDS 3
diff --git a/obj.c b/obj.c
index 97fb3373..c51dfbe9 100644
--- a/obj.c
+++ b/obj.c
@@ -119,17 +119,22 @@ rsRetVal objInfoSetMethod(objInfo_t *pThis, objMethod_t objMethod, rsRetVal (*pH
/* --------------- object serializiation / deserialization support --------------- */
-/* serialize the header of an object */
-static rsRetVal objSerializeHeader(strm_t *pStrm, obj_t *pObj)
+/* serialize the header of an object
+ * pszRecType must be either "Obj" (Object) or "OPB" (Object Property Bag)
+ */
+static rsRetVal objSerializeHeader(strm_t *pStrm, obj_t *pObj, uchar *pszRecType)
{
DEFiRet;
- assert(pStrm != NULL);
+ ISOBJ_TYPE_assert(pStrm, strm);
ISOBJ_assert(pObj);
+ assert(!strcmp((char*) pszRecType, "Obj") || !strcmp((char*) pszRecType, "OPB"));
/* object cookie and serializer version (so far always 1) */
CHKiRet(strmWriteChar(pStrm, COOKIE_OBJLINE));
- CHKiRet(strmWrite(pStrm, (uchar*) "Obj1", sizeof("Obj1") - 1));
+ CHKiRet(strmWrite(pStrm, (uchar*) pszRecType, 3)); /* record types are always 3 octets */
+ CHKiRet(strmWriteChar(pStrm, ':'));
+ CHKiRet(strmWriteChar(pStrm, '1'));
/* object type, version and string length */
CHKiRet(strmWriteChar(pStrm, ':'));
@@ -150,24 +155,44 @@ static rsRetVal objSerializeHeader(strm_t *pStrm, obj_t *pObj)
finalize_it:
return iRet;
}
-/* begin serialization of an object - this is a very simple hook. It once wrote the wrapper,
- * now it only constructs the string object. We still leave it in here so that we may utilize
- * it in the future (it is a nice abstraction). iExpcectedObjSize is an optimization setting.
- * It must contain the size (in characters) that the calling object expects the string
- * representation to grow to. Specifying a bit too large size doesn't hurt. A too-small size
- * does not cause any malfunction, but results in more often memory copies than necessary. So
- * the caller is advised to be conservative in guessing. Binary multiples are recommended.
+
+
+/* begin serialization of an object
* rgerhards, 2008-01-06
*/
rsRetVal objBeginSerialize(strm_t *pStrm, obj_t *pObj)
{
DEFiRet;
- assert(pStrm != NULL);
- assert(pObj != NULL);
+ ISOBJ_TYPE_assert(pStrm, strm);
+ ISOBJ_assert(pObj);
+
+ CHKiRet(strmRecordBegin(pStrm));
+ CHKiRet(objSerializeHeader(pStrm, pObj, (uchar*) "Obj"));
+
+finalize_it:
+ return iRet;
+}
+
+
+/* begin serialization of an object's property bag
+ * Note: a property bag is used to serialize some of an objects
+ * properties, but not necessarily all. A good example is the queue
+ * object, which at some stage needs to serialize a number of its
+ * properties, but not the queue data itself. From the object point
+ * of view, a property bag can not be used to re-instantiate an object.
+ * Otherwise, the serialization is exactly the same.
+ * rgerhards, 2008-01-11
+ */
+rsRetVal objBeginSerializePropBag(strm_t *pStrm, obj_t *pObj)
+{
+ DEFiRet;
+
+ ISOBJ_TYPE_assert(pStrm, strm);
+ ISOBJ_assert(pObj);
CHKiRet(strmRecordBegin(pStrm));
- CHKiRet(objSerializeHeader(pStrm, pObj));
+ CHKiRet(objSerializeHeader(pStrm, pObj, (uchar*) "OPB"));
finalize_it:
return iRet;
@@ -397,6 +422,7 @@ static rsRetVal objDeserializeHeader(objID_t *poID, int* poVers, strm_t *pStrm)
NEXTC; if(c != 'O') ABORT_FINALIZE(RS_RET_INVALID_HEADER);
NEXTC; if(c != 'b') ABORT_FINALIZE(RS_RET_INVALID_HEADER);
NEXTC; if(c != 'j') ABORT_FINALIZE(RS_RET_INVALID_HEADER);
+ NEXTC; if(c != ':') ABORT_FINALIZE(RS_RET_INVALID_HEADER);
NEXTC; if(c != '1') ABORT_FINALIZE(RS_RET_INVALID_HEADER_VERS);
NEXTC; if(c != ':') ABORT_FINALIZE(RS_RET_INVALID_HEADER_VERS);
diff --git a/obj.h b/obj.h
index ae395a53..0caf1306 100644
--- a/obj.h
+++ b/obj.h
@@ -86,6 +86,7 @@
/* prototypes */
rsRetVal objInfoConstruct(objInfo_t **ppThis, objID_t objID, uchar *pszName, int iObjVers, rsRetVal (*pConstruct)(void *), rsRetVal (*pDestruct)(void *));
rsRetVal objInfoSetMethod(objInfo_t *pThis, objMethod_t objMethod, rsRetVal (*pHandler)(void*));
+rsRetVal objBeginSerializePropBag(strm_t *pStrm, obj_t *pObj);
rsRetVal objBeginSerialize(strm_t *pStrm, obj_t *pObj);
rsRetVal objSerializeProp(strm_t *pStrm, uchar *pszPropName, propertyType_t propType, void *pUsr);
rsRetVal objEndSerialize(strm_t *pStrm);
diff --git a/queue.c b/queue.c
index 0d59a068..91d89b06 100644
--- a/queue.c
+++ b/queue.c
@@ -46,6 +46,7 @@
#include "obj.h"
/* static data */
+DEFobjStaticHelpers
/* methods */
@@ -498,6 +499,7 @@ rsRetVal queueConstruct(queue_t **ppThis, queueType_t qType, int iWorkerThreads,
}
/* we have an object, so let's fill the properties */
+ objConstructSetObjInfo(pThis);
if((pThis->pszSpoolDir = (uchar*) strdup((char*)glblGetWorkDir())) == NULL)
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
@@ -633,6 +635,10 @@ static rsRetVal queuePersist(queue_t *pThis)
CHKiRet(strmSetFName(psQIF, pszQIFNam, lenQIFNam));
CHKiRet(strmConstructFinalize(psQIF));
+ /* first, write the property bag for ourselfs */
+ CHKiRet(objBeginSerializePropBag(psQIF, (obj_t*) pThis));
+ CHKiRet(objEndSerialize(psQIF));
+
/* this is disk specific and must be moved to a function */
CHKiRet(strmSerialize(pThis->tVars.disk.pWrite, psQIF));
CHKiRet(strmSerialize(pThis->tVars.disk.pRead, psQIF));
@@ -799,6 +805,17 @@ finalize_it:
/* some simple object access methods */
DEFpropSetMeth(queue, bImmediateShutdown, int);
+
+/* Initialize the stream class. Must be called as the very first method
+ * before anything else is called inside this class.
+ * rgerhards, 2008-01-09
+ */
+BEGINObjClassInit(queue, 1)
+ //OBJSetMethodHandler(objMethod_SERIALIZE, strmSerialize);
+ //OBJSetMethodHandler(objMethod_SETPROPERTY, strmSetProperty);
+ //OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, strmConstructFinalize);
+ENDObjClassInit(strm)
+
/*
* vi:set ai:
*/
diff --git a/queue.h b/queue.h
index 56841faf..0fda1e50 100644
--- a/queue.h
+++ b/queue.h
@@ -74,6 +74,7 @@ typedef struct qWrkThrd_s {
/* the queue object */
typedef struct queue_s {
+ BEGINobjInstance;
queueType_t qType;
int iQueueSize; /* Current number of elements in the queue */
int iMaxQueueSize; /* how large can the queue grow? */
@@ -127,6 +128,7 @@ rsRetVal queueSetMaxFileSize(queue_t *pThis, size_t iMaxFileSize);
rsRetVal queueSetFilePrefix(queue_t *pThis, uchar *pszPrefix, size_t iLenPrefix);
rsRetVal queueConstruct(queue_t **ppThis, queueType_t qType, int iWorkerThreads,
int iMaxQueueSize, rsRetVal (*pConsumer)(void*));
+PROTOTYPEObjClassInit(queue);
PROTOTYPEpropSetMeth(queue, bImmediateShutdown, int);
#define queueGetID(pThis) ((unsigned long) pThis)
diff --git a/syslogd.c b/syslogd.c
index db31bf9a..25185efc 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -4696,6 +4696,7 @@ static rsRetVal InitGlobalClasses(void)
CHKiRet(objClassInit()); /* *THIS* *MUST* always be the first class initilizere called! */
CHKiRet(MsgClassInit());
CHKiRet(strmClassInit());
+ CHKiRet(queueClassInit());
finalize_it:
return iRet;