summaryrefslogtreecommitdiffstats
path: root/collection
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2009-02-24 17:49:02 -0500
committerDmitri Pal <dpal@redhat.com>2009-02-24 17:49:02 -0500
commit78c5ff376dd37462fad9a2194e4ee4931dcbc473 (patch)
treecc99f4c16be76362f0b934cea688fd5a21d0a6de /collection
parent27d15caafe401160fcc62829a3460a52cd45d429 (diff)
downloadelapi_draft-78c5ff376dd37462fad9a2194e4ee4931dcbc473.tar.gz
elapi_draft-78c5ff376dd37462fad9a2194e4ee4931dcbc473.tar.xz
elapi_draft-78c5ff376dd37462fad9a2194e4ee4931dcbc473.zip
Fixing unittest. Fininshing with submit to syslog.
Diffstat (limited to 'collection')
-rw-r--r--collection/elapi_collection.c25
-rw-r--r--collection/elapi_collection.h12
-rw-r--r--collection/elapi_debug.h9
3 files changed, 45 insertions, 1 deletions
diff --git a/collection/elapi_collection.c b/collection/elapi_collection.c
index 2654edd..f2614a6 100644
--- a/collection/elapi_collection.c
+++ b/collection/elapi_collection.c
@@ -12,6 +12,7 @@
#define ELAPI_ACTION_FIND 1
#define ELAPI_ACTION_DEL 2
#define ELAPI_ACTION_UPDATE 3
+#define ELAPI_ACTION_GET 4
/* Special internal error code to indicate that collection search was interrupted */
@@ -862,6 +863,10 @@ static int act_traverse_handler(struct collection_item *head,
}
break;
+ case ELAPI_ACTION_GET:
+ DEBUG_STRING("It is a get action.","");
+ if(custom_data != NULL) *((struct collection_item **)(custom_data)) = current;
+ break;
case ELAPI_ACTION_DEL:
DEBUG_STRING("It is a delete action.","");
/* Make sure we tell the caller we found a match */
@@ -1237,7 +1242,6 @@ int get_collection_reference(struct collection_item *ci, /* High level
}
-
/* ADDITION */
/* Add collection to collection */
@@ -1430,6 +1434,25 @@ int get_item_and_do(struct collection_item *ci, /* Collection to find thin
return error;
}
+
+/* Get raw item */
+int get_item(struct collection_item *ci, /* Collection to find things in */
+ char *property_to_find, /* Name to match */
+ int type, /* Type filter */
+ int mode_flags, /* How to traverse the collection */
+ struct collection_item **item) /* Found item */
+{
+
+ int error = EOK;
+
+ DEBUG_STRING("get_item","Entry.");
+
+ error = find_item_and_do(ci,property_to_find,type,mode_flags,NULL,(void *)(item),ELAPI_ACTION_GET);
+
+ DEBUG_NUMBER("get_item returning",error);
+ return error;
+}
+
/* DELETE */
/* Delete property from the collection */
int delete_property(struct collection_item *ci, /* Collection to find things in */
diff --git a/collection/elapi_collection.h b/collection/elapi_collection.h
index 129b83a..9b9e8c3 100644
--- a/collection/elapi_collection.h
+++ b/collection/elapi_collection.h
@@ -172,6 +172,18 @@ int get_item_and_do(struct collection_item *ci, /* Collection to find thin
item_fn item_handler, /* Function to call when the item is found */
void *custom_data); /* Custom data passed around */
+/* Convenience function to get individual item */
+/* Caller should be aware that this is not a copy of the item
+ * but the pointer to actual item stored in the collection.
+ * The retuned pointer should never be altered or freed by caller of the function.
+ * The caller should be sure that the collection does not go out of scope
+ * while the pointer to its data is in use. */
+int get_item(struct collection_item *ci, /* Collection to find things in */
+ char *property_to_find, /* Name to match */
+ int type, /* Type filter */
+ int mode_flags, /* How to traverse the collection */
+ struct collection_item **item); /* Found item */
+
/* Delete property from the collection */
int delete_property(struct collection_item *ci, /* Collection to find things in */
char *property_to_find, /* Name to match */
diff --git a/collection/elapi_debug.h b/collection/elapi_debug.h
index 3da0685..5f2c174 100644
--- a/collection/elapi_debug.h
+++ b/collection/elapi_debug.h
@@ -31,5 +31,14 @@
#define DEBUG_ASSERT(expression) ;
#endif
+#ifdef ELAPI_LOG_DEBUG
+#ifdef ELAPI_TOOLS_H
+#define DEBUG_COLLECTION(collection) debug_collection(collection,ELAPI_TRAVERSE_DEFAULT);
+#else
+#define DEBUG_COLLECTION(collection) ;
+#endif
+#else
+#define DEBUG_COLLECTION(collection) ;
+#endif
#endif