[svn-commits] russell: branch russell/event_performance r183906 - in /team/russell/event_pe...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Tue Mar 24 06:46:12 CDT 2009
Author: russell
Date: Tue Mar 24 06:46:07 2009
New Revision: 183906
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183906
Log:
Fill out hash and compare functions
Modified:
team/russell/event_performance/include/asterisk/strings.h
team/russell/event_performance/main/event.c
Modified: team/russell/event_performance/include/asterisk/strings.h
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/include/asterisk/strings.h?view=diff&rev=183906&r1=183905&r2=183906
==============================================================================
--- team/russell/event_performance/include/asterisk/strings.h (original)
+++ team/russell/event_performance/include/asterisk/strings.h Tue Mar 24 06:46:07 2009
@@ -717,6 +717,29 @@
}
/*!
+ * \brief Compute a hash value on a string
+ *
+ * \param[in] str The string to add to the hash
+ * \param[in] hash The hash value to add to
+ *
+ * \details
+ * This version of the function is for when you need to compute a
+ * string hash of more than one string.
+ *
+ * This famous hash algorithm was written by Dan Bernstein and is
+ * commonly used.
+ *
+ * \sa http://www.cse.yorku.ca/~oz/hash.html
+ */
+static force_inline int ast_str_hash_add(const char *str, int hash)
+{
+ while (*str)
+ hash = hash * 33 ^ *str++;
+
+ return abs(hash);
+}
+
+/*!
* \brief Compute a hash value on a case-insensitive string
*
* Uses the same hash algorithm as ast_str_hash, but converts
Modified: team/russell/event_performance/main/event.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/main/event.c?view=diff&rev=183906&r1=183905&r2=183906
==============================================================================
--- team/russell/event_performance/main/event.c (original)
+++ team/russell/event_performance/main/event.c Tue Mar 24 06:46:07 2009
@@ -368,7 +368,8 @@
return res;
}
-static int match_ie_val(struct ast_event *event, struct ast_event_ie_val *ie_val, struct ast_event *event2)
+static int match_ie_val(const struct ast_event *event,
+ const struct ast_event_ie_val *ie_val, const struct ast_event *event2)
{
if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT) {
uint32_t val = event2 ? ast_event_get_ie_uint(event2, ie_val->ie_type) : ie_val->payload.uint;
@@ -1046,7 +1047,6 @@
int ast_event_queue_and_cache(struct ast_event *event)
{
- struct ast_event_ref *event_ref;
ao2_callback_fn *cb_fn;
struct ao2_container *container;
struct ast_event_ref tmp_event_ref = {
@@ -1054,18 +1054,18 @@
};
if (!(container = ast_event_cache[ast_event_get_type(event)])) {
+ ast_log(LOG_WARNING, "cache requested for non-cached event type\n");
goto queue_event;
}
if (!(cb_fn = cached_event_types[ast_event_get_type(event)].cmp_fn)) {
+ ast_log(LOG_WARNING, "cache requested for non-cached event type\n");
goto queue_event;
}
/* Remove matches from the cache */
- while ((event_ref = ao2_callback(container, OBJ_POINTER | OBJ_UNLINK,
- cb_fn, &tmp_event_ref))) {
- ao2_ref(event_ref, -1);
- }
+ ao2_callback(container, OBJ_POINTER | OBJ_UNLINK | OBJ_MULTIPLE | OBJ_NODATA,
+ cb_fn, &tmp_event_ref);
queue_event:
return ast_event_queue(event);
@@ -1142,43 +1142,79 @@
const struct ast_event *event = obj;
const char *mailbox = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX);
const char *context = ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT);
- struct ast_str *str;
-
- str = ast_str_alloca(strlen(mailbox) + strlen(context) + 1);
-
- ast_str_set(&str, 0, "%s@%s", mailbox, context);
-
- return ast_str_hash(ast_str_buffer(str));
+
+ return ast_str_hash_add(context, ast_str_hash(mailbox));
}
static int ast_event_cmp_mwi(void *obj, void *arg, int flags)
{
- /* XXX */
- return 0;
+ const struct ast_event *event = obj;
+ const struct ast_event *event2 = arg;
+ struct ast_event_ie_val ie_val = {
+ .ie_type = AST_EVENT_IE_MAILBOX,
+ };
+
+ if (!match_ie_val(event, &ie_val, event2)) {
+ return 0;
+ }
+
+ ie_val.ie_type = AST_EVENT_IE_CONTEXT;
+
+ if (!match_ie_val(event, &ie_val, event2)) {
+ return 0;
+ }
+
+ return CMP_MATCH;
}
static int ast_event_hash_devstate(const void *obj, const int flags)
{
- /* XXX */
- return 0;
+ const struct ast_event *event = obj;
+
+ return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE));
}
static int ast_event_cmp_devstate(void *obj, void *arg, int flags)
{
- /* XXX */
- return 0;
+ const struct ast_event *event = obj;
+ const struct ast_event *event2 = arg;
+ struct ast_event_ie_val ie_val = {
+ .ie_type = AST_EVENT_IE_DEVICE,
+ };
+
+ if (!match_ie_val(event, &ie_val, event2)) {
+ return 0;
+ }
+
+ return CMP_MATCH;
}
static int ast_event_hash_devstate_change(const void *obj, const int flags)
{
- /* XXX */
- return 0;
+ const struct ast_event *event = obj;
+
+ return ast_str_hash(ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE));
}
static int ast_event_cmp_devstate_change(void *obj, void *arg, int flags)
{
- /* XXX */
- return 0;
+ const struct ast_event *event = obj;
+ const struct ast_event *event2 = arg;
+ struct ast_event_ie_val ie_val = {
+ .ie_type = AST_EVENT_IE_DEVICE,
+ };
+
+ if (!match_ie_val(event, &ie_val, event2)) {
+ return 0;
+ }
+
+ ie_val.ie_type = AST_EVENT_IE_EID;
+
+ if (!match_ie_val(event, &ie_val, event2)) {
+ return 0;
+ }
+
+ return CMP_MATCH;
}
static int ast_event_hash(const void *obj, const int flags)
More information about the svn-commits
mailing list