[svn-commits] mattf: branch mattf/1.6.0-chan_ccs r270834 - /team/mattf/1.6.0-chan_ccs/chann...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 16 10:51:31 CDT 2010


Author: mattf
Date: Wed Jun 16 10:51:28 2010
New Revision: 270834

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=270834
Log:
First cut of huntgroups.  Very simple huntgroups.

Modified:
    team/mattf/1.6.0-chan_ccs/channels/chan_ccs.c

Modified: team/mattf/1.6.0-chan_ccs/channels/chan_ccs.c
URL: http://svnview.digium.com/svn/asterisk/team/mattf/1.6.0-chan_ccs/channels/chan_ccs.c?view=diff&rev=270834&r1=270833&r2=270834
==============================================================================
--- team/mattf/1.6.0-chan_ccs/channels/chan_ccs.c (original)
+++ team/mattf/1.6.0-chan_ccs/channels/chan_ccs.c Wed Jun 16 10:51:28 2010
@@ -175,6 +175,22 @@
 
 #define LINKSET_FLAG_EXPLICITACM (1 << 0)
 
+/* How are we going to hunt */
+/* Inititially, ascending only */
+
+struct ccs_huntgroup {
+	char name[CCS_MAX_NAME];
+	struct ao2_container *channels;
+};
+
+static struct ccs_huntgroup * ccs_huntgroup_find(char *name);
+static void ccs_huntgroup_add_channel(char *name, struct ccs_chan *chan);
+
+#define CCS_MAX_HUNTGROUPS 32
+
+struct ao2_container *huntgroups;
+
+
 struct ccs_ss7 {
 	pthread_t master;						/*!< Thread of master */
 	ast_mutex_t lock;
@@ -203,7 +219,6 @@
 };
 
 struct ccs_ss7 *linksets[CCS_MAX_LINKSETS];
-
 
 #if 0
 #define PVT_TO_CHANNEL(p) (((p)->prioffset) | ((p)->logicalspan << 8) | (p->pri->mastertrunkgroup ? 0x10000 : 0))
@@ -771,14 +786,14 @@
 
 static const struct ast_channel_tech ccs_tech;
 
-static struct ast_channel * ccs_ss7_new(struct ccs_chan *c, struct ccs_ss7 *ss7, int state, char *called_num)
+static struct ast_channel * ccs_channel_new(struct ccs_chan *c, struct ccs_huntgroup *hg, int state, char *called_num)
 {
 	struct ast_channel *ast;
 	if (!c) {
 		struct ao2_iterator i;
 		struct ccs_chan *p = NULL;
 
-		i = ao2_iterator_init(ss7->pvts, 0);
+		i = ao2_iterator_init(hg->channels, 0);
 
 		while ((p = ao2_iterator_next(&i))) {
 			ast_mutex_lock(&p->lock);
@@ -833,26 +848,20 @@
 	return ast;
 }
 
-static struct ast_channel *ss7_request(char *linkname, char *called_num, int format, int *cause)
+static struct ast_channel *ccs_real_request(char *linkname, char *called_num, int format, int *cause)
 {
 	struct ast_channel *ast;
-	struct ccs_ss7 *ss7 = NULL;
+	struct ccs_huntgroup *hg;
 	struct ccs_chan *c;
-	int i;
-
-	for (i = 0; (i < CCS_MAX_LINKSETS) && linksets[i]; i++) {
-		if (!strcasecmp(linksets[i]->name, linkname)) {
-			ss7 = linksets[i];
-			break;
-		}
-	}
-
-	if (!ss7) {
-		ast_log(LOG_ERROR, "Unable to find linkset by name of request name %s\n", linkname);
+
+	hg  = ccs_huntgroup_find(linkname);
+	
+	if (!hg) {
+		ast_log(LOG_ERROR, "Unable to find huntgroup by name of request name %s\n", linkname);
 		return NULL;
 	}
 
-	ast = ccs_ss7_new(NULL, ss7, AST_STATE_RESERVED, called_num);
+	ast = ccs_channel_new(NULL, hg, AST_STATE_RESERVED, called_num);
 
 	if (!ast) {
 		ast_log(LOG_ERROR, "Unable to request CCS channel!\n");
@@ -912,7 +921,7 @@
 		return NULL;
 	}
 
-	ast = ss7_request(linkname, exten, format, cause);
+	ast = ccs_real_request(linkname, exten, format, cause);
 	return ast;
 }
 
@@ -1100,7 +1109,7 @@
 		ast_log(LOG_WARNING, "Unable to set law on channel %d\n", p->channel);
 	
 #endif
-	c = ccs_ss7_new(p, NULL, AST_STATE_RING, p->exten);
+	c = ccs_channel_new(p, NULL, AST_STATE_RING, p->exten);
 
 	if (!c) {
 		ast_log(LOG_WARNING, "Unable to start PBX on CIC %d\n", p->sig.ss7.cic);
@@ -1776,7 +1785,74 @@
 	return 0;
 }
 
-static int ccs_add_ss7_channel(struct ccs_ss7 *ss7, int dpc, int cic, char *tech, char *dialstr, char *context)
+static struct ccs_huntgroup * ccs_huntgroup_find(char *name)
+{
+	struct ccs_huntgroup *p, *g = NULL;
+	struct ao2_iterator i;
+
+	i = ao2_iterator_init(huntgroups, 0);
+
+	while ((p = ao2_iterator_next(&i))) {
+		if (!strcasecmp(g->name, "name")) {
+			g = p;
+			ao2_ref(p, -1);
+			break;
+		}
+		ao2_ref(p, -1);
+	}
+
+	return g;
+}
+
+static struct ccs_huntgroup * ccs_huntgroup_find_or_create(char *name)
+{
+	struct ccs_huntgroup *g = NULL;
+
+	g = ccs_huntgroup_find(name);
+
+	if (g) {
+		return g;
+	}
+
+	g = ao2_alloc(sizeof(*g), NULL);
+	if (!g)
+		goto failed_out;
+
+	ast_copy_string(g->name, name, sizeof(g->name));
+
+	/* Setup the container here */
+	g->channels = ao2_container_alloc(1, NULL, NULL);
+	if (!g->channels)
+		goto failed_out;
+
+	/* Now put it in the list and return */
+	ao2_link(huntgroups, g);
+
+	return g;
+
+failed_out:
+	if (g)
+		ao2_ref(g, -1);
+
+
+	return NULL;
+}
+
+static void ccs_huntgroup_add_channel(char *name, struct ccs_chan *chan)
+{
+	struct ccs_huntgroup *g;
+
+	g = ccs_huntgroup_find_or_create(name);
+
+	if (!g) {
+		ast_log(LOG_ERROR, "Couldn't create huntgroup '%s'\n", name);
+		return;
+	}
+
+	ao2_link(g->channels, chan);
+}
+
+static int ccs_add_ss7_channel(struct ccs_ss7 *ss7, int dpc, int cic, char *tech, char *dialstr, char *context, char *group)
 {
 	struct ccs_chan *chan;
 
@@ -1807,12 +1883,18 @@
 
 	ao2_link(ss7->pvts, chan);
 
+	if (group && !ast_strlen_zero(group)) {
+		ccs_huntgroup_add_channel(group, chan);
+	}
+	
+	ccs_huntgroup_add_channel(ss7->name, chan);
+
 	ast_verb(3, "Added SS7 CIC %d:%d (%s %s) to linkset \'%s\'\n", cic, dpc, tech, dialstr, ss7->name);
 
 	return 0;
 }
 
-static int parse_ss7channelmap(struct ccs_ss7 *ss7, int defaultdpc, const char *str, char *context)
+static int parse_ss7channelmap(struct ccs_ss7 *ss7, int defaultdpc, const char *str, char *context, char *group)
 {
 	char chanmapstr[256];
 	char *cicstr;
@@ -1863,7 +1945,7 @@
 	}
 
 
-	return ccs_add_ss7_channel(ss7, defaultdpc, cic, techstr, dialstr, context);
+	return ccs_add_ss7_channel(ss7, defaultdpc, cic, techstr, dialstr, context, group);
 }
 
 static int linkset_pvts_hash_cb(const void *obj, const int flags)
@@ -1889,6 +1971,7 @@
 	int cur_pointcode = -1;
 	int cur_ss7type = -1;
 	char cur_context[AST_MAX_EXTENSION] = "";
+	char cur_group[CCS_MAX_NAME] = "";
 
 	ss7 = ast_calloc(1, sizeof(*ss7));
 
@@ -1978,12 +2061,14 @@
 				ss7->flags &= ~LINKSET_FLAG_EXPLICITACM;
 		} else if (!strcasecmp(v->name, "context")) {
 			ast_copy_string(cur_context, v->value, sizeof(cur_context));
+		} else if (!strcasecmp(v->name, "group")) {
+			ast_copy_string(cur_group, v->value, sizeof(cur_context));
 		} else if (!strcasecmp(v->name, "ss7channelmap")) {
 			if (cur_defaultdpc == -1) {
 				ast_log(LOG_ERROR, "Must specify defaultdpc before channels are declared\n");
 				goto failed_out;
 			}
-			if (parse_ss7channelmap(ss7, cur_defaultdpc, v->value, cur_context)) {
+			if (parse_ss7channelmap(ss7, cur_defaultdpc, v->value, cur_context, cur_group)) {
 				goto failed_out;
 			}
 		}
@@ -2129,6 +2214,7 @@
 				ast_log(LOG_VERBOSE, "Found PRI signalled group %s\n", cat);
 
 			} else {
+				/* Probably a group then */
 				ast_log(LOG_ERROR, "Unhandled or unspecified signalling type in signalling group %s\n", cat);
 
 			}
@@ -2217,6 +2303,9 @@
 
 static int load_module(void)
 {
+	huntgroups = ao2_container_alloc(1, NULL, NULL);
+	if (!huntgroups)
+		goto failed_out;
 	ss7_set_error(ccs_ss7_error);
 	ss7_set_message(ccs_ss7_message);
 
@@ -2235,6 +2324,9 @@
 	ast_rtp_proto_register(&ccs_rtp);
 
 	return AST_MODULE_LOAD_SUCCESS;
+
+failed_out:
+	return AST_MODULE_LOAD_FAILURE;
 }
 
 static int reload(void)




More information about the svn-commits mailing list