[asterisk-commits] file: trunk r81334 - in /trunk: include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Aug 29 10:19:12 CDT 2007
Author: file
Date: Wed Aug 29 10:19:11 2007
New Revision: 81334
URL: http://svn.digium.com/view/asterisk?view=rev&rev=81334
Log:
Add API calls for iterating through an event. This should allow events to have multiple information elements (while there was nothing preventing it before you could not actually access any except the first one).
Modified:
trunk/include/asterisk/event.h
trunk/include/asterisk/event_defs.h
trunk/main/event.c
Modified: trunk/include/asterisk/event.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/event.h?view=diff&rev=81334&r1=81333&r2=81334
==============================================================================
--- trunk/include/asterisk/event.h (original)
+++ trunk/include/asterisk/event.h Wed Aug 29 10:19:11 2007
@@ -413,4 +413,61 @@
*/
enum ast_event_type ast_event_get_type(const struct ast_event *event);
+/*!
+ * \brief Initialize an event iterator instance
+ *
+ * \param iterator The iterator instance to initialize
+ * \param event The event that will be iterated through
+ *
+ * \return Nothing
+ */
+void ast_event_iterator_init(struct ast_event_iterator *iterator, const struct ast_event *event);
+
+/*!
+ * \brief Move iterator instance to next IE
+ *
+ * \param iterator The iterator instance
+ *
+ * \retval 0 on success
+ * \retval -1 if end is reached
+ */
+int ast_event_iterator_next(struct ast_event_iterator *iterator);
+
+/*!
+ * \brief Get the type of the current IE in the iterator instance
+ *
+ * \param iterator The iterator instance
+ *
+ * \return the ie type as represented by one of the value sin the
+ * ast_event_ie_type enum
+ */
+enum ast_event_ie_type ast_event_iterator_get_ie_type(struct ast_event_iterator *iterator);
+
+/*!
+ * \brief Get the value of the current IE in the ierator as an integer payload
+ *
+ * \param iterator The iterator instance
+ *
+ * \return This returns the payload of the information element as a uint.
+ */
+uint32_t ast_event_iteragor_get_ie_uint(struct ast_event_iterator *iterator);
+
+/*!
+ * \brief Get the value of the current IE in the iterator as a string payload
+ *
+ * \param iterator The iterator instance
+ *
+ * \return This returns the payload of the information element as a string.
+ */
+const char *ast_event_iterator_get_ie_str(struct ast_event_iterator *iterator);
+
+/*!
+ * \brief Get the value of the current IE in the iterator instance that has a raw payload
+ *
+ * \param iterator The iterator instance
+ *
+ * \return This returns the payload of the information element as type raw.
+ */
+void *ast_event_iterator_get_ie_raw(struct ast_event_iterator *iterator);
+
#endif /* AST_EVENT_H */
Modified: trunk/include/asterisk/event_defs.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/event_defs.h?view=diff&rev=81334&r1=81333&r2=81334
==============================================================================
--- trunk/include/asterisk/event_defs.h (original)
+++ trunk/include/asterisk/event_defs.h Wed Aug 29 10:19:11 2007
@@ -138,5 +138,6 @@
struct ast_event;
struct ast_event_ie;
struct ast_event_sub;
+struct ast_event_iterator;
#endif /* AST_EVENT_DEFS_H */
Modified: trunk/main/event.c
URL: http://svn.digium.com/view/asterisk/trunk/main/event.c?view=diff&rev=81334&r1=81333&r2=81334
==============================================================================
--- trunk/main/event.c (original)
+++ trunk/main/event.c Wed Aug 29 10:19:11 2007
@@ -66,6 +66,12 @@
AST_LIST_ENTRY(ast_event_ref) entry;
};
+struct ast_event_iterator {
+ uint16_t event_len;
+ const struct ast_event *event;
+ struct ast_event_ie *ie;
+};
+
/*! \brief data shared between event dispatching threads */
static struct {
ast_cond_t cond;
@@ -355,6 +361,40 @@
ast_event_sub_destroy(sub);
}
+void ast_event_iterator_init(struct ast_event_iterator *iterator, const struct ast_event *event)
+{
+ iterator->event_len = ntohs(event->event_len);
+ iterator->event = event;
+ iterator->ie = ((void *) event) + sizeof(*event);
+ return;
+}
+
+int ast_event_iterator_next(struct ast_event_iterator *iterator)
+{
+ iterator->ie = ((void *) iterator->ie) + sizeof(*iterator->ie) + ntohs(iterator->ie->ie_payload_len);
+ return ((iterator->event_len > (((void *) iterator->ie) - ((void *) iterator->event))) ? -1 : 0);
+}
+
+enum ast_event_ie_type ast_event_iterator_get_ie_type(struct ast_event_iterator *iterator)
+{
+ return iterator->ie->ie_type;
+}
+
+uint32_t ast_event_iteragor_get_ie_uint(struct ast_event_iterator *iterator)
+{
+ return ntohl(*iterator->ie->ie_payload);
+}
+
+const char *ast_event_iterator_get_ie_str(struct ast_event_iterator *iterator)
+{
+ return (const char*)iterator->ie->ie_payload;
+}
+
+void *ast_event_iterator_get_ie_raw(struct ast_event_iterator *iterator)
+{
+ return iterator->ie->ie_payload;
+}
+
enum ast_event_type ast_event_get_type(const struct ast_event *event)
{
return ntohs(event->type);
@@ -376,18 +416,11 @@
const void *ast_event_get_ie_raw(const struct ast_event *event, enum ast_event_ie_type ie_type)
{
- struct ast_event_ie *ie;
- uint16_t event_len;
-
- ie_type = ntohs(ie_type);
- event_len = ntohs(event->event_len);
-
- ie = ((void *) event) + sizeof(*event);
-
- while ((((void *) ie) - ((void *) event)) < event_len) {
- if (ie->ie_type == ie_type)
- return ie->ie_payload;
- ie = ((void *) ie) + sizeof(*ie) + ntohs(ie->ie_payload_len);
+ struct ast_event_iterator iterator;
+
+ for (ast_event_iterator_init(&iterator, event); !ast_event_iterator_next(&iterator); ) {
+ if (ast_event_iterator_get_ie_type(&iterator) == ie_type)
+ return ast_event_iterator_get_ie_raw(&iterator);
}
return NULL;
More information about the asterisk-commits
mailing list