[asterisk-commits] mmichelson: branch group/CCSS r217443 - /team/group/CCSS/main/ccss.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Sep 9 12:25:01 CDT 2009
Author: mmichelson
Date: Wed Sep 9 12:24:58 2009
New Revision: 217443
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=217443
Log:
Start enacting the change to ao2_callback_data for match_agent.
There's still one more XXX comment to address in these changes. In
order to address it, I need to concoct the agent backend registration
process. It's necessary anyway, and I can pretty much copy the existing
monitor registration code.
Modified:
team/group/CCSS/main/ccss.c
Modified: team/group/CCSS/main/ccss.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=217443&r1=217442&r2=217443
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Wed Sep 9 12:24:58 2009
@@ -488,52 +488,39 @@
struct ast_cc_monitor *monitor;
};
-/* XXX I need to modify this to be an ao2_callback_data
- * callback instead. This way I'll know the context in which
- * it is being used, because the circumstances strongly dictate
- * what data should be ignored and what should not be.
- *
- * Let's be a bit more specific about this, shall we? There are
- * three places where this is used, so let's consider each.
- *
- * 1) When the time comes to create an instance of the core,
- * kill_duplicate_offers is used to destroy any core_instances
- * which have the same agent interface. The key here is that
- * we must only examine core_instances which have a NULL
- * monitor pointer. Those are the ones for which CC has been
- * offered, but for which the offer has not been accepted.
- *
- * Now, when a generic agent is in use, the search may be
- * expanded to include core_instances with non-NULL monitor
- * pointers. This doesn't mean that we will kill the pre-
- * existing request, but it does mean that we will cease
- * creation of the core_instance.
- *
- * 2) When CallCompletionRequest is called, we need to search
- * through the agents for a specific caller. This application
- * only applies to core_instances with a NULL monitor pointer,
- * so this is similar.
- *
- * 3) When CallCompletionCancel is called, we once again have
- * to search the container for a specific caller. In this situation,
- * though, we only care about core_instances with a non-NULL
- * monitor pointer.
- *
- * A bitfield should do the job nicely.
- */
-static int match_agent(void *obj, void *arg, int flags)
-{
- struct cc_core_instance *core_instance1 = obj;
+enum match_flags {
+ MATCH_NO_MONITOR,
+ MATCH_MONITOR,
+};
+
+static int match_agent(void *obj, void *arg, void *data, int flags)
+{
+ struct cc_core_instance *core_instance = obj;
const char *name = arg;
-
- if (!strcmp(core_instance1->agent->interface, name)) {
+ unsigned long match_flags = *(unsigned long *)data;
+ int possible_match = 0;
+
+ if ((match_flags & MATCH_NO_MONITOR) && !core_instance->monitor) {
+ possible_match = 1;
+ }
+
+ if ((match_flags & MATCH_MONITOR) && core_instance->monitor) {
+ possible_match = 1;
+ }
+
+ if (!possible_match) {
+ return 0;
+ }
+
+ if (!strcmp(core_instance->agent->interface, name)) {
return CMP_MATCH | CMP_STOP;
}
return 0;
}
static void kill_duplicate_offers(char *caller) {
- ao2_callback(cc_core_instances, OBJ_UNLINK | OBJ_NODATA, match_agent, caller);
+ unsigned long match_flags = MATCH_NO_MONITOR;
+ ao2_callback_data(cc_core_instances, OBJ_UNLINK | OBJ_NODATA, match_agent, caller, &match_flags);
}
static void check_callback_sanity(const struct ast_cc_agent_callbacks *callbacks)
@@ -616,6 +603,14 @@
* to request a CC service, it may only be for the latest call he made.
*/
kill_duplicate_offers(caller);
+
+ /* XXX At this point, I should do an ao2_callback_data to match_agent if the agent being
+ * used will be generic. This way, I can detect early if the caller already has an outstanding
+ * request and stop at this point.
+ *
+ * Actually, modifying kill_duplicate_offers would probably be better so that there is only
+ * one traversal of the container instead of two.
+ */
/* Next, we need to create the core instance for this call */
if (!(core_instance = ao2_alloc(sizeof(*core_instance), cc_core_instance_destructor))) {
@@ -1229,13 +1224,15 @@
char interface[AST_CHANNEL_NAME];
struct cc_generic_agent_pvt *generic_pvt;
char *dash;
+ unsigned long match_flags;
ast_copy_string(interface, chan->name, sizeof(interface));
if ((dash = strrchr(interface, '-'))) {
*dash = '\0';
}
- if (!(core_instance = ao2_callback(cc_core_instances, 0, match_agent, interface))) {
+ match_flags = MATCH_NO_MONITOR;
+ if (!(core_instance = ao2_callback_data(cc_core_instances, 0, match_agent, interface, &match_flags))) {
ast_log(LOG_NOTICE, "Couldn't find a core instance for caller %s\n", interface);
return -1;
}
@@ -1258,13 +1255,15 @@
struct cc_core_instance *core_instance;
char interface[AST_CHANNEL_NAME];
char *dash;
+ unsigned long match_flags;
ast_copy_string(interface, chan->name, sizeof(interface));
if ((dash = strrchr(interface, '-'))) {
*dash = '\0';
}
- if (!(core_instance = ao2_callback(cc_core_instances, 0, match_agent, interface))) {
+ match_flags = MATCH_MONITOR;
+ if (!(core_instance = ao2_callback_data(cc_core_instances, 0, match_agent, interface, &match_flags))) {
ast_log(LOG_WARNING, "Cannot fid CC transaction to cancel for caller %s\n", interface);
return -1;
}
More information about the asterisk-commits
mailing list