[asterisk-commits] rizzo: branch rizzo/video_v2 r82497 - /team/rizzo/video_v2/channels/chan_oss.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Sep 16 10:34:07 CDT 2007


Author: rizzo
Date: Sun Sep 16 10:34:06 2007
New Revision: 82497

URL: http://svn.digium.com/view/asterisk?view=rev&rev=82497
Log:
TRUNK CANDIDATE (not done here):
move the core of 'store_config()' to a separate function, as i just realised
that many of the parameters in oss.conf are suitable for a CLI command,
and there is no reason to replicate the parsing routines.

On passing, change variable name and values to "const char *" as they
are not supposed to be modified anyways.

In order to make it cleanly, the same change should be applied to
ast_jb_read_conf(). In the meantime, i just cast the arguments.


Modified:
    team/rizzo/video_v2/channels/chan_oss.c

Modified: team/rizzo/video_v2/channels/chan_oss.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_v2/channels/chan_oss.c?view=diff&rev=82497&r1=82496&r2=82497
==============================================================================
--- team/rizzo/video_v2/channels/chan_oss.c (original)
+++ team/rizzo/video_v2/channels/chan_oss.c Sun Sep 16 10:34:06 2007
@@ -212,7 +212,7 @@
  * Likely we will come up with a better way of doing config file parsing.
  */
 #define M_START(var, val) \
-        char *__s = var; char *__val = val;
+        const char *__s = var; const char *__val = val;
 #define M_END(x)   x;
 #define M_F(tag, f)			if (!strcasecmp((__s), tag)) { f; } else
 #define M_BOOL(tag, dst)	M_F(tag, (dst) = ast_true(__val) )
@@ -1111,6 +1111,47 @@
 	return c;
 }
 
+static void store_config_core(struct chan_oss_pvt *o, const char *var, const char *value);
+
+/*! generic console command handler */
+static char *console_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct chan_oss_pvt *o = find_desc(oss_active);
+	const char *var, *value;
+
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "console [videodevice|fps|bitrate]";
+		e->usage =
+			"Usage: console ...\n"
+			"       Generic handler for console commands.\n";
+		return NULL;
+
+	case CLI_GENERATE:
+		return NULL;
+	}
+
+	if (a->argc < e->args)
+		return CLI_SHOWUSAGE;
+	if (o == NULL) {
+		ast_log(LOG_WARNING, "Cannot find device %s (should not happen!)\n",
+		    oss_active);
+		return CLI_FAILURE;
+	}
+	var = a->argv[e->args-1];
+	value = a->argc > e->args ? a->argv[e->args] : NULL;
+	if (value)	/* handle setting */
+		store_config_core(o, var, value);
+	if (!strcasecmp(var, "videodevice")) {
+		ast_cli(a->fd, "videodevice is [%s]\n", o->env.videodevice);
+	} else if (!strcasecmp(var, "bitrate")) {
+		ast_cli(a->fd, "bitrate is [%d]\n", o->env.bitrate);
+	} else if (!strcasecmp(var, "fps")) {
+		ast_cli(a->fd, "fps is [%d]\n", o->env.fps);
+	}
+	return CLI_SUCCESS;
+
+}
 static char *console_autoanswer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct chan_oss_pvt *o = find_desc(oss_active);
@@ -1419,7 +1460,7 @@
 /*!
  * \brief store the boost factor
  */
-static void store_boost(struct chan_oss_pvt *o, char *s)
+static void store_boost(struct chan_oss_pvt *o, const char *s)
 {
 	double boost = 0;
 	if (sscanf(s, "%lf", &boost) != 1) {
@@ -1455,6 +1496,7 @@
 	NEW_CLI(console_flash, "Flash a call on the console"),
 	NEW_CLI(console_dial, "Dial an extension on the console"),
 	NEW_CLI(console_mute, "Disable/Enable mic input"),
+	NEW_CLI(console_cmd, "Generic console command"),
 	{ { "console", "transfer", NULL },
 	console_transfer, "Transfer a call to a different extension",
 	transfer_usage },
@@ -1476,7 +1518,7 @@
  * invalid or dangerous values (the string is used as argument for
  * system("mixer %s")
  */
-static void store_mixer(struct chan_oss_pvt *o, char *s)
+static void store_mixer(struct chan_oss_pvt *o, const char *s)
 {
 	int i;
 
@@ -1495,9 +1537,40 @@
 /*!
  * store the callerid components
  */
-static void store_callerid(struct chan_oss_pvt *o, char *s)
+static void store_callerid(struct chan_oss_pvt *o, const char *s)
 {
 	ast_callerid_split(s, o->cid_name, sizeof(o->cid_name), o->cid_num, sizeof(o->cid_num));
+}
+
+static void store_config_core(struct chan_oss_pvt *o, const char *var, const char *value)
+{
+	M_START(var, value);
+
+	/* handle jb conf */
+	if (!ast_jb_read_conf(&global_jbconf, (char *)var,(char *) value))
+		return;
+
+	M_BOOL("autoanswer", o->autoanswer)
+	M_BOOL("autohangup", o->autohangup)
+	M_BOOL("overridecontext", o->overridecontext)
+	M_STR("device", o->device)
+	M_UINT("frags", o->frags)
+	M_UINT("debug", oss_debug)
+	M_UINT("queuesize", o->queuesize)
+	M_STR("context", o->ctx)
+	M_STR("language", o->language)
+	M_STR("mohinterpret", o->mohinterpret)
+	M_STR("extension", o->ext)
+	M_F("mixer", store_mixer(o, value))
+	M_F("callerid", store_callerid(o, value))
+	M_F("boost", store_boost(o, value))
+	M_STR("videodevice", o->env.videodevice)
+	M_UINT("videowidth", o->env.w)
+	M_UINT("videoheight", o->env.h)
+	M_UINT("fps", o->env.fps)
+	M_UINT("bitrate", o->env.bitrate)
+
+	M_END(/* */);
 }
 
 /*!
@@ -1529,33 +1602,7 @@
 	o->lastopen = ast_tvnow();	/* don't leave it 0 or tvdiff may wrap */
 	/* fill other fields from configuration */
 	for (v = ast_variable_browse(cfg, ctg); v; v = v->next) {
-		M_START(v->name, v->value);
-
-		/* handle jb conf */
-		if (!ast_jb_read_conf(&global_jbconf, v->name, v->value))
-			continue;
-
-		M_BOOL("autoanswer", o->autoanswer)
-		M_BOOL("autohangup", o->autohangup)
-		M_BOOL("overridecontext", o->overridecontext)
-		M_STR("device", o->device)
-		M_UINT("frags", o->frags)
-		M_UINT("debug", oss_debug)
-		M_UINT("queuesize", o->queuesize)
-		M_STR("context", o->ctx)
-		M_STR("language", o->language)
-		M_STR("mohinterpret", o->mohinterpret)
-		M_STR("extension", o->ext)
-		M_F("mixer", store_mixer(o, v->value))
-		M_F("callerid", store_callerid(o, v->value))
-		M_F("boost", store_boost(o, v->value))
-		M_STR("videodevice", o->env.videodevice)
-		M_UINT("videowidth", o->env.w)
-		M_UINT("videoheight", o->env.h)
-		M_UINT("fps", o->env.fps)
-		M_UINT("bitrate", o->env.bitrate)
-
-		M_END(/* */);
+		store_config_core(o, v->name, v->value);
 	}
 	if (ast_strlen_zero(o->device))
 		ast_copy_string(o->device, DEV_DSP, sizeof(o->device));




More information about the asterisk-commits mailing list