From 163a6a9fbcb50ca55f405a900b762288ebda69ca Mon Sep 17 00:00:00 2001 From: Magnus Feuer Date: Mon, 25 Mar 2019 16:13:46 -0700 Subject: [PATCH 1/3] Switched from obsolete C++ to C. Cleaned up naming. Chmod 755 on test scripts --- swig/Makefile | 6 +++--- swig/dstc.py | 10 +++++----- swig/dstc_swig.i | 11 +---------- swig/print_name_and_age_client.py | 2 +- swig/print_name_and_age_server.py | 3 ++- swig/setup.py | 2 +- 6 files changed, 13 insertions(+), 21 deletions(-) mode change 100644 => 100755 swig/print_name_and_age_client.py mode change 100644 => 100755 swig/print_name_and_age_server.py diff --git a/swig/Makefile b/swig/Makefile index 800455e..7dc92dd 100644 --- a/swig/Makefile +++ b/swig/Makefile @@ -4,11 +4,11 @@ CFLAGS += -ggdb -dstc_swig_wrap.o: dstc_swig_wrap.cxx +dstc_swig_wrap.o: dstc_swig_wrap.c python3 setup.py build_ext --inplace -dstc_swig_wrap.cxx: dstc_swig.i ../dstc.h - swig -I/usr/include -python -c++ -includeall dstc_swig.i +dstc_swig_wrap.c: dstc_swig.i ../dstc.h + swig -I/usr/include -python -includeall dstc_swig.i clean: rm -rf _dstc*.so build dstc_swig.py dstc_swig_wrap.* __pycache__ diff --git a/swig/dstc.py b/swig/dstc.py index bcf5313..8132277 100644 --- a/swig/dstc.py +++ b/swig/dstc.py @@ -64,7 +64,7 @@ def dstc_process(*arg): def activate(): global active - dstc_swig.setup() + dstc_swig.dstc_setup() active = True return True @@ -74,7 +74,7 @@ def process_events(timeout): print("Please call activate() before processing events") return False - dstc_swig.process_events(timeout) + dstc_swig.dstc_process_events(timeout) return True def remote_function_available(lambda_func): @@ -88,7 +88,7 @@ def remote_function_available(lambda_func): return False func_name = client_lambda[lambda_func] - return dstc_swig.remote_function_available(func_name.encode("utf-8")) + return dstc_swig.dstc_remote_function_available_by_name(func_name.encode("utf-8")) def client_call(func_name, *args): if func_name not in client_func: @@ -107,9 +107,9 @@ def client_call(func_name, *args): cnvt_args += (arg, ) arg = struct.pack("<" + param_format, *cnvt_args) - res = dstc_swig.queue_func(func_name.encode("utf-8"), arg, len(arg)) + res = dstc_swig.dstc_queue_func(func_name.encode("utf-8"), arg, len(arg)) if res != 0: - print("dstc_swig.queue_func failed: {}".format(res)) + print("dstc_swig.dstc_queue_func failed: {}".format(res)) return False return True diff --git a/swig/dstc_swig.i b/swig/dstc_swig.i index 9679857..bc3af66 100644 --- a/swig/dstc_swig.i +++ b/swig/dstc_swig.i @@ -4,7 +4,6 @@ %} %{ -extern "C" { #include typedef long int usec_timestamp_t; @@ -21,7 +20,7 @@ extern "C" { char *func_name, char* payload, unsigned short payload_len)); -} + static PyObject *cb_ptr = NULL; @@ -68,16 +67,8 @@ void register_client_function(char* name) %} %include "typemaps.i" -%rename(setup) dstc_setup; extern int dstc_setup(void); - typedef long int usec_timestamp_t; -%rename(process_events) dstc_process_events; extern int dstc_process_events(usec_timestamp_t); - -%rename(queue_func) dstc_queue_func; extern int dstc_queue_func(char* name, const char* arg, unsigned int arg_sz); - -%rename(remote_function_available) dstc_remote_function_available_by_name; - extern unsigned char dstc_remote_function_available_by_name(char* func_name); diff --git a/swig/print_name_and_age_client.py b/swig/print_name_and_age_client.py old mode 100644 new mode 100755 index b147409..0f67a8e --- a/swig/print_name_and_age_client.py +++ b/swig/print_name_and_age_client.py @@ -1,4 +1,4 @@ - +#!/usr/bin/python3 # Test python client to exercise DSTC. import dstc diff --git a/swig/print_name_and_age_server.py b/swig/print_name_and_age_server.py old mode 100644 new mode 100755 index a6efd01..8dc962b --- a/swig/print_name_and_age_server.py +++ b/swig/print_name_and_age_server.py @@ -1,4 +1,5 @@ -# Test python client to exercise DSTC. +#!/usr/bin/python3 +# Test python client to exercise import dstc def do_print_name_and_age(func, name, age): diff --git a/swig/setup.py b/swig/setup.py index 4f2abb4..84b3a51 100644 --- a/swig/setup.py +++ b/swig/setup.py @@ -10,6 +10,6 @@ description = """SWIG wrapper for DSTC.""", py_modules = [ 'dstc' ], ext_modules = [ - Extension('_dstc_swig', sources=['dstc_swig_wrap.cxx',],libraries=['dstc', 'rmc']) + Extension('_dstc_swig', sources=['dstc_swig_wrap.c',],libraries=['dstc', 'rmc']) ], ) From 4f7f88d7dcb9a34433e8ccfa5d0cd873421995b5 Mon Sep 17 00:00:00 2001 From: Magnus Feuer Date: Mon, 25 Mar 2019 16:14:59 -0700 Subject: [PATCH 2/3] Made setup.py executable --- swig/setup.py | 2 ++ 1 file changed, 2 insertions(+) mode change 100644 => 100755 swig/setup.py diff --git a/swig/setup.py b/swig/setup.py old mode 100644 new mode 100755 index 84b3a51..f8abd0f --- a/swig/setup.py +++ b/swig/setup.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3 + """ setup.py file for DSTC SWIG """ From be34cb0a722bcb9394ce2dacc375f526ea144faa Mon Sep 17 00:00:00 2001 From: Magnus Feuer Date: Fri, 29 Mar 2019 09:21:38 -0700 Subject: [PATCH 3/3] Setup added to dstc as syntactic sugar. dstc_swig.py added as a module to setup.py --- swig/dstc.py | 3 +++ swig/setup.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/swig/dstc.py b/swig/dstc.py index 8132277..ad5e446 100644 --- a/swig/dstc.py +++ b/swig/dstc.py @@ -21,6 +21,9 @@ def decode_string(fixed_width_string): return fixed_width_string[:fixed_width_string.index(b'\x00')].decode("utf8") +def setup(): + return dstc_swig.dstc_setup() + def register_server_function(name, func, param_format): global active diff --git a/swig/setup.py b/swig/setup.py index f8abd0f..3314ad3 100755 --- a/swig/setup.py +++ b/swig/setup.py @@ -10,7 +10,7 @@ version = '0.1', author = "SWIG Docs", description = """SWIG wrapper for DSTC.""", - py_modules = [ 'dstc' ], + py_modules = [ 'dstc', 'dstc_swig' ], ext_modules = [ Extension('_dstc_swig', sources=['dstc_swig_wrap.c',],libraries=['dstc', 'rmc']) ],