[asterisk-commits] russell: branch russell/bindings r103759 - in /team/russell/bindings: binding...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 18 08:11:04 CST 2008


Author: russell
Date: Mon Feb 18 08:11:04 2008
New Revision: 103759

URL: http://svn.digium.com/view/asterisk?view=rev&rev=103759
Log:
 - add wait_for_digits() which will play a prompt and read a string of digits
 - expose ast_log and ast_verbose

Added:
    team/russell/bindings/bindings/asterisk.i   (with props)
Modified:
    team/russell/bindings/bindings/Makefile
    team/russell/bindings/bindings/ast_channel.i
    team/russell/bindings/bindings/examples/ast_channel_test.py
    team/russell/bindings/res/Makefile
    team/russell/bindings/res/python/res_python.h
    team/russell/bindings/res/res_python.c

Modified: team/russell/bindings/bindings/Makefile
URL: http://svn.digium.com/view/asterisk/team/russell/bindings/bindings/Makefile?view=diff&rev=103759&r1=103758&r2=103759
==============================================================================
--- team/russell/bindings/bindings/Makefile (original)
+++ team/russell/bindings/bindings/Makefile Mon Feb 18 08:11:04 2008
@@ -11,9 +11,9 @@
 # the GNU General Public License
 #
 
-PYTHON_MODS:=ast_cdr.py ast_channel.py
+PYTHON_MODS:=ast_cdr.py ast_channel.py asterisk.py
 
-all: ast_channel_wrap.c ast_cdr_wrap.c swigpyrun.h
+all: asterisk_wrap.c ast_channel_wrap.c ast_cdr_wrap.c swigpyrun.h
 
 ast_channel.i: $(ASTTOPDIR)/include/asterisk/channel.h
 
@@ -29,6 +29,11 @@
 ast_channel_wrap.c: ast_channel.i
 ifneq ($(SWIG),:)
 	$(SWIG) -I$(ASTTOPDIR)/include -python ast_channel.i
+endif
+
+asterisk_wrap.c: asterisk.i
+ifneq ($(SWIG),:)
+	$(SWIG) -I$(ASTTOPDIR)/include -python asterisk.i
 endif
 
 swigpyrun.h:

Modified: team/russell/bindings/bindings/ast_channel.i
URL: http://svn.digium.com/view/asterisk/team/russell/bindings/bindings/ast_channel.i?view=diff&rev=103759&r1=103758&r2=103759
==============================================================================
--- team/russell/bindings/bindings/ast_channel.i (original)
+++ team/russell/bindings/bindings/ast_channel.i Mon Feb 18 08:11:04 2008
@@ -12,11 +12,14 @@
 AST_THREADSTORAGE(ast_channel_get_var_buf);
 #define GET_VAR_BUF_LEN 1024
 
+AST_THREADSTORAGE(ast_channel_eval_buf);
+#define EVAL_BUF_LEN 4096
+
 AST_THREADSTORAGE(ast_channel_read_digit_buf);
 #define READ_DIGIT_BUF_LEN 2
 
-AST_THREADSTORAGE(ast_channel_eval_buf);
-#define EVAL_BUF_LEN 4096
+AST_THREADSTORAGE(ast_channel_read_digits_buf);
+#define READ_DIGITS_BUF_LEN 1024
 %}
 
 struct ast_channel {
@@ -143,7 +146,7 @@
         return buf;
     }
 
-    const char *wait_for_digit(int timeout = 3000)
+    const char *wait_for_digit(unsigned int timeout = 3000)
     {
         char *buf;
 
@@ -157,4 +160,25 @@
 
         return buf;
     }
+
+    const char *wait_for_digits(const char *prompt, unsigned int max_digits, 
+        unsigned int timeout)
+    {
+        char *buf;
+
+        if (!(buf = ast_threadstorage_get(&ast_channel_read_digits_buf, READ_DIGITS_BUF_LEN)))
+            return "";
+
+        buf[0] = '\0';
+
+        if (max_digits > READ_DIGITS_BUF_LEN - 1) {
+            ast_log(LOG_ERROR, "Requested maximum digits %d too big.  Only %d allowed.\n",
+                max_digits, READ_DIGITS_BUF_LEN - 1);
+            max_digits = READ_DIGITS_BUF_LEN - 1;
+        }
+
+        ast_app_getdata($self, prompt, buf, max_digits, timeout);
+
+        return buf;
+    }
 };

Added: team/russell/bindings/bindings/asterisk.i
URL: http://svn.digium.com/view/asterisk/team/russell/bindings/bindings/asterisk.i?view=auto&rev=103759
==============================================================================
--- team/russell/bindings/bindings/asterisk.i (added)
+++ team/russell/bindings/bindings/asterisk.i Mon Feb 18 08:11:04 2008
@@ -1,0 +1,16 @@
+%module asterisk
+
+%{
+#include <stdarg.h>
+
+#include "asterisk.h"
+#include "asterisk/logger.h"
+
+#include "python/res_python.h"
+%}
+
+void ast_log_error(const char *msg);
+void ast_log_warning(const char *msg);
+void ast_log_notice(const char *msg);
+void ast_log_debug(unsigned int level, const char *msg);
+void ast_log_verbose(unsigned int level, const char *msg);

Propchange: team/russell/bindings/bindings/asterisk.i
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/russell/bindings/bindings/asterisk.i
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/russell/bindings/bindings/asterisk.i
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/russell/bindings/bindings/examples/ast_channel_test.py
URL: http://svn.digium.com/view/asterisk/team/russell/bindings/bindings/examples/ast_channel_test.py?view=diff&rev=103759&r1=103758&r2=103759
==============================================================================
--- team/russell/bindings/bindings/examples/ast_channel_test.py (original)
+++ team/russell/bindings/bindings/examples/ast_channel_test.py Mon Feb 18 08:11:04 2008
@@ -1,6 +1,13 @@
+import asterisk
 import ast_channel
 
 def ast_app(chan):
+	asterisk.ast_log_verbose(1, 'Verbose message test')
+	asterisk.ast_log_debug(1, 'Debug message test')
+	asterisk.ast_log_notice('Notice message test')
+	asterisk.ast_log_warning('Warning message test')
+	asterisk.ast_log_error('Error message test')
+
 	print '(ast_channel test) Channel is ' + chan.get_name() + ', currently executing ' \
 		+ chan.get_context() + ',' + chan.get_exten() + ',' + repr(chan.get_priority()) + '.'
 
@@ -12,19 +19,26 @@
 	print 'Executing Playback of tt-weasels ...'
 	chan.exec_app('Playback', 'tt-weasels')
 
-	print 'setting FOO to BAR ...'
+	print 'Setting FOO to BAR ...'
 	chan.set_var('FOO', 'BAR')
 
-	print 'variable FOO is: ' + chan.get_var('FOO')
+	print 'Variable FOO is: ' + chan.get_var('FOO')
 
-	print 'evaluating literal variable string ${FOO} - ' + chan.eval('${FOO}')
+	print 'Evaluating literal variable string ${FOO} - ' + chan.eval('${FOO}')
 
-	print 'playing a beep and then waiting 3 seconds for a digit ...'
+	print 'Waiting 3 seconds for a digit ...'
 	digit = chan.wait_for_digit(3000)
 	if len(digit) != 0:
 		print 'Got digit ' + digit
 	else:
 		print 'Did not read a digit'
+
+	print 'Playing a beep, reading a string of digits (maximum 8), with a timeout of 5 seconds ...'
+	digits = chan.wait_for_digits("beep", 8, 5000)
+	if len(digits) != 0:
+		print 'Read a string of digits: ' + digits
+	else:
+		print 'Did not read any string of digits'
 
 	print 'Hanging up ...'
 	chan.hangup()

Modified: team/russell/bindings/res/Makefile
URL: http://svn.digium.com/view/asterisk/team/russell/bindings/res/Makefile?view=diff&rev=103759&r1=103758&r2=103759
==============================================================================
--- team/russell/bindings/res/Makefile (original)
+++ team/russell/bindings/res/Makefile Mon Feb 18 08:11:04 2008
@@ -48,7 +48,7 @@
 
 ael/pval.o: ael/pval.c
 
-PYTHON_WRAPPERS:=python_ast_cdr_wrap.o python_ast_channel_wrap.o
+PYTHON_WRAPPERS:=python_ast_cdr_wrap.o python_ast_channel_wrap.o python_asterisk_wrap.o
 RES_PYTHON_OBJS:=res_python.o python/cdr.o python/channel.o
 
 res_python.so: $(RES_PYTHON_OBJS) $(PYTHON_WRAPPERS)
@@ -57,6 +57,11 @@
 
 python/cdr.o: ASTCFLAGS+=$(PYTHON_INCLUDE)
 
+python_asterisk_wrap.o: ASTCFLAGS+=$(PYTHON_INCLUDE)
+	
+python_asterisk_wrap.c: ../bindings/asterisk_wrap.c
+	@cp $< $@
+	
 python_ast_channel_wrap.o: ASTCFLAGS+=$(PYTHON_INCLUDE)
 	
 python_ast_channel_wrap.c: ../bindings/ast_channel_wrap.c

Modified: team/russell/bindings/res/python/res_python.h
URL: http://svn.digium.com/view/asterisk/team/russell/bindings/res/python/res_python.h?view=diff&rev=103759&r1=103758&r2=103759
==============================================================================
--- team/russell/bindings/res/python/res_python.h (original)
+++ team/russell/bindings/res/python/res_python.h Mon Feb 18 08:11:04 2008
@@ -26,6 +26,15 @@
 extern PyThreadState *main_thread_state;
 extern struct ast_module_info *python_module_info;
 
+/*! defined by python_asterisk_wrap.c */
+void init_asterisk(void);
+
+void ast_log_error(const char *msg);
+void ast_log_warning(const char *msg);
+void ast_log_notice(const char *msg);
+void ast_log_debug(unsigned int level, const char *msg);
+void ast_log_verbose(unsigned int level, const char *msg);
+
 /*! defined by python_ast_cdr_wrap.c */
 void init_ast_cdr(void);
 

Modified: team/russell/bindings/res/res_python.c
URL: http://svn.digium.com/view/asterisk/team/russell/bindings/res/res_python.c?view=diff&rev=103759&r1=103758&r2=103759
==============================================================================
--- team/russell/bindings/res/res_python.c (original)
+++ team/russell/bindings/res/res_python.c Mon Feb 18 08:11:04 2008
@@ -45,6 +45,31 @@
 
 /*! \brief Don't let python register signal handlers */
 #define INIT_SIGS 0
+
+void ast_log_error(const char *msg)
+{
+	ast_log(LOG_ERROR, "%s\n", msg);
+}
+
+void ast_log_warning(const char *msg)
+{
+	ast_log(LOG_WARNING, "%s\n", msg);
+}
+
+void ast_log_notice(const char *msg)
+{
+	ast_log(LOG_NOTICE, "%s\n", msg);
+}
+
+void ast_log_debug(unsigned int level, const char *msg)
+{
+	ast_debug(level, "%s\n", msg);
+}
+
+void ast_log_verbose(unsigned int level, const char *msg)
+{
+	ast_verb(level, "%s\n", msg);
+}
 
 static char *cli_python_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
@@ -127,6 +152,8 @@
 
 	PyEval_InitThreads();
 
+	init_asterisk();
+
 	python_cdr_load();
 	python_channel_load();
 




More information about the asterisk-commits mailing list