Debian Codegraph @

runtime/linkedlist.h

raw
1 /* Definition of the linkedlist object.
2 *
3 * Copyright 2007-2012 Rainer Gerhards and Adiscon GmbH.
4 *
5 * This file is part of the rsyslog runtime library.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * -or-
13 * see COPYING.ASL20 in the source distribution
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22 #ifndef LINKEDLIST_H_INCLUDED
23 #define LINKEDLIST_H_INCLUDED
24
25 /* this is a single entry for a parse routine. It describes exactly
26 * one entry point/handler.
27 * The short name is cslch (Configfile SysLine CommandHandler)
28 */
29 struct llElt_s { /* config file sysline parse entry */
30 struct llElt_s *pNext;
31 void *pKey; /* key for this element */
32 void *pData; /* user-supplied data pointer */
33 };
34 typedef struct llElt_s llElt_t;
35
36
37 /* this is the list of known configuration commands with pointers to
38 * their handlers.
39 * The short name is cslc (Configfile SysLine Command)
40 */
41 struct linkedList_s { /* config file sysline parse entry */
42 int iNumElts; /* number of elements in list */
43 rsRetVal (*pEltDestruct)(void *pData); /* destructor for user pointer in llElt_t's */
44 rsRetVal (*pKeyDestruct)(void *pKey); /* destructor for key pointer in llElt_t's */
45 int (*cmpOp)(void *, void *); /* pointer to key compare operation function, retval like strcmp */
46 void *pKey; /* the list key (searchable, if set) */
47 llElt_t *pRoot; /* list root */
48 llElt_t *pLast; /* list tail */
49 };
50 typedef struct linkedList_s linkedList_t;
51
52 typedef llElt_t *linkedListCookie_t; /* this type avoids exposing internals and keeps us flexible */
53
54 /* prototypes */
55 rsRetVal llInit(linkedList_t *pThis,
56 rsRetVal (*pEltDestructor)(void *),
57 rsRetVal (*pKeyDestructor)(void *),
58 int (*pCmpOp)(void *, void *));
59 rsRetVal llDestroy(linkedList_t *pThis);
60 rsRetVal llDestroyRootElt(linkedList_t *pThis);
61 rsRetVal llGetNextElt(linkedList_t *pThis, linkedListCookie_t *ppElt, void **ppUsr);
62 rsRetVal llAppend(linkedList_t *pThis, void *pKey, void *pData);
63 rsRetVal llFind(linkedList_t *pThis, void *pKey, void **ppData);
64 rsRetVal llGetKey(llElt_t *pThis, void *ppData);
65 rsRetVal llGetNumElts(linkedList_t *pThis, int *piCnt);
66 rsRetVal llExecFunc(linkedList_t *pThis, rsRetVal (*pFunc)(void *, void *), void *pParam);
67 rsRetVal llFindAndDelete(linkedList_t *pThis, void *pKey);
68 /* use the macro below to define a function that will be executed by
69 * llExecFunc()
70 */
71 #define DEFFUNC_llExecFunc(funcName) \
72 static rsRetVal funcName(void __attribute__((unused)) * pData, void __attribute__((unused)) * pParam)
73
74 #endif /* #ifndef LINKEDLIST_H_INCLUDED */