[asterisk-commits] mmichelson: branch group/CCSS r214471 - /team/group/CCSS/main/ccss.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Aug 27 15:10:43 CDT 2009
Author: mmichelson
Date: Thu Aug 27 15:10:39 2009
New Revision: 214471
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=214471
Log:
Add core instances container and start with the timer logic for the generic agent.
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=214471&r1=214470&r2=214471
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Thu Aug 27 15:10:39 2009
@@ -391,8 +391,10 @@
static int core_id_counter;
struct ao2_container *pending_cc_offers;
-
-static const int CC_PENDING_OFFER_BUCKETS = 37;
+struct ao2_container *cc_core_instances;
+
+static const int CC_PENDING_OFFER_BUCKETS = 53;
+static const int CC_CORE_INSTANCES_BUCKETS = 17;
/*!
* \brief Struct for CC offers, before a monitor is created
@@ -460,17 +462,14 @@
static int pending_offer_hash_fn(const void *obj, const int flags)
{
const struct core_pending_cc_offer *pending_offer = obj;
- return (pending_offer->core_id % CC_PENDING_OFFER_BUCKETS);
+ return pending_offer->core_id;
}
static int pending_offer_cmp_fn(void *obj, void *arg, int flags)
{
struct core_pending_cc_offer *pending_offer1 = obj;
struct core_pending_cc_offer *pending_offer2 = arg;
- if (pending_offer1->core_id == pending_offer2->core_id) {
- return CMP_MATCH | CMP_STOP;
- }
- return 0;
+ return pending_offer1->core_id == pending_offer2->core_id ? CMP_MATCH | CMP_STOP : 0;
}
static int match_caller(void *obj, void *arg, int flags)
@@ -565,6 +564,20 @@
ast_free(core_instance->agent);
}
+static int cc_core_instance_hash_fn(const void *obj, const int flags)
+{
+ const struct cc_core_instance *core_instance = obj;
+ return core_instance->core_id;
+}
+
+static int cc_core_instance_cmp_fn(void *obj, void *arg, int flags)
+{
+ struct cc_core_instance *core_instance1 = obj;
+ struct cc_core_instance *core_instance2 = arg;
+
+ return core_instance1->core_id == core_instance2->core_id ? CMP_MATCH | CMP_STOP : 0;
+}
+
int ast_cc_core_init_instance(struct ast_channel *caller_chan,
struct ast_cc_interface_tree *called_tree)
{
@@ -600,6 +613,8 @@
return -1;
}
+ ao2_link(cc_core_instances, core_instance);
+
/* Finally, start the state machine! */
return 0;
@@ -615,10 +630,22 @@
return 0;
}
+static int offer_timer_expire(const void *data)
+{
+ const struct ast_cc_agent *agent = data;
+ ast_cc_request_state_change(CC_FAILED, agent->core_id, "Generic agent offer timer expired");
+ return 0;
+}
+
static int cc_generic_agent_start_offer_timer(struct ast_cc_agent *agent)
{
- /* STUB */
- return 0;
+ int when;
+
+ ast_assert(cc_sched != NULL);
+ ast_assert(agent->cc_params != NULL);
+
+ when = ast_get_cc_offer_timer(agent->cc_params) * 1000;
+ return ast_sched_add(cc_sched, when, offer_timer_expire, agent);
}
static void cc_generic_agent_ack(struct ast_cc_agent *agent)
@@ -667,15 +694,16 @@
{
/* STUB */
struct cc_state_change_args *args = datap;
- struct cc_core_instance;
+ struct cc_core_instance *core_instance;
+ struct cc_core_instance finder = { .core_id = args->core_id };
ast_log(LOG_NOTICE, "State change to %d requested. Reason: %s\n", args->state, args->debug);
- /* XXX First we need to Get the correct instance
- * of the core based on args->core_id. Since
- * I haven't yet set up the container of core
- * instances, I'm skipping this for now.
- */
+ if (!(core_instance = ao2_find(cc_core_instances, &finder, OBJ_POINTER))) {
+ ast_log(LOG_NOTICE, "Unable to find core instance %d\n", args->core_id);
+ return -1;
+ }
+
switch (args->state) {
case CC_AVAILABLE:
/* This should never happen... */
@@ -746,6 +774,10 @@
pending_offer_hash_fn, pending_offer_cmp_fn))) {
return -1;
}
+ if (!(cc_core_instances = ao2_container_alloc(CC_CORE_INSTANCES_BUCKETS,
+ cc_core_instance_hash_fn, cc_core_instance_cmp_fn))) {
+ return -1;
+ }
if (!(cc_core_taskprocessor = ast_taskprocessor_get("CCSS core", TPS_REF_DEFAULT))) {
return -1;
}
More information about the asterisk-commits
mailing list