[svn-commits] mmichelson: branch group/CCSS r231733 - in /team/group/CCSS: channels/ includ...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Nov 30 16:45:24 CST 2009
Author: mmichelson
Date: Mon Nov 30 16:45:22 2009
New Revision: 231733
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=231733
Log:
Add method to search for an agent given a piece of data.
While trying to write code to handle an incoming PUBLISH, it became
clear that the way I would need to find the appropriate CC agent was
based on the request URI of the PUBLISH. I needed to match the URI
to the stored URI in the agent's private_data. Unfortunately, I can't
search the container of cc_core_instances in chan_sip because the container
and the cc_core_instance struct are both private to ccss.c. However, it
was not too difficult to create a public API call which could use ao2_callback
within ccss.c. This is very Matryoshka-esque code.
Modified:
team/group/CCSS/channels/chan_sip.c
team/group/CCSS/include/asterisk/ccss.h
team/group/CCSS/main/ccss.c
Modified: team/group/CCSS/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/channels/chan_sip.c?view=diff&rev=231733&r1=231732&r2=231733
==============================================================================
--- team/group/CCSS/channels/chan_sip.c (original)
+++ team/group/CCSS/channels/chan_sip.c Mon Nov 30 16:45:22 2009
@@ -3366,6 +3366,21 @@
char is_available;
};
+static int find_by_uri_helper(void *obj, void *arg, int flags)
+{
+ struct ast_cc_agent *agent = obj;
+ struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
+ const char *uri = arg;
+
+ return !strcmp(agent_pvt->notify_uri, uri) ? CMP_MATCH | CMP_STOP : 0;
+}
+
+static struct ast_cc_agent *find_sip_cc_agent_by_uri(const char * const uri)
+{
+ struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_uri_helper, (char *)uri, "SIP");
+ return agent;
+}
+
static int sip_cc_agent_init(struct ast_cc_agent *agent, struct ast_channel *chan)
{
struct sip_cc_agent_pvt *agent_pvt = ast_calloc(1, sizeof(*agent_pvt));
Modified: team/group/CCSS/include/asterisk/ccss.h
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/include/asterisk/ccss.h?view=diff&rev=231733&r1=231732&r2=231733
==============================================================================
--- team/group/CCSS/include/asterisk/ccss.h (original)
+++ team/group/CCSS/include/asterisk/ccss.h Mon Nov 30 16:45:22 2009
@@ -861,6 +861,24 @@
void (*destructor)(struct ast_cc_agent *agent);
};
+/*!
+ * \brief Call a callback on all agents of a specific type
+ *
+ * Since the container of CC core instances is private, and so
+ * are the items which the container contains, we have to provide
+ * an ao2_callback-like method so that a specific agent may be
+ * found or so that an operation can be made on all agents of
+ * a particular type. The first three arguments should be familiar
+ * to anyone who has used ao2_callback. The final argument is the
+ * type of agent you wish to have the callback called on.
+ *
+ * \param flags astobj2 search flags
+ * \param function an ao2 callback function to call
+ * \param arg the argument to the callback function
+ * \param type The type of agents to call the callback on
+ */
+void *ast_cc_agent_callback(int flags, ao2_callback_fn function, void *arg, const char * const type);
+
/* END STRUCTURES FOR AGENTS */
/* BEGIN STATE CHANGE API */
Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=231733&r1=231732&r2=231733
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Mon Nov 30 16:45:22 2009
@@ -241,6 +241,30 @@
struct cc_core_instance finder = {.core_id = core_id,};
return ao2_t_find(cc_core_instances, &finder, OBJ_POINTER, "Finding a core_instance");
+}
+
+struct cc_callback_helper {
+ ao2_callback_fn function;
+ void *args;
+ const char *type;
+};
+
+static int cc_agent_callback_helper(void *obj, void *args, int flags)
+{
+ struct cc_core_instance *core_instance = obj;
+ struct cc_callback_helper *helper = args;
+
+ if (strcmp(core_instance->agent->callbacks->type, helper->type)) {
+ return 0;
+ }
+
+ return helper->function(core_instance->agent, helper->args, flags);
+}
+
+void *ast_cc_agent_callback(int flags, ao2_callback_fn function, void *args, const char * const type)
+{
+ struct cc_callback_helper helper = {.function = function, .args = args, .type = type};
+ return ao2_callback(cc_core_instances, flags, cc_agent_callback_helper, &helper);
}
enum match_flags {
More information about the svn-commits
mailing list