Skip to content

Commit

Permalink
Merge pull request #29 from PDXostc/swig_integration_part2
Browse files Browse the repository at this point in the history
Swig integration part2
  • Loading branch information
magnusfeuer authored Apr 1, 2019
2 parents 388920e + be34cb0 commit cf39295
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
6 changes: 3 additions & 3 deletions swig/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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__
13 changes: 8 additions & 5 deletions swig/dstc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -64,7 +67,7 @@ def dstc_process(*arg):

def activate():
global active
dstc_swig.setup()
dstc_swig.dstc_setup()
active = True
return True

Expand All @@ -74,7 +77,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):
Expand All @@ -88,7 +91,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:
Expand All @@ -107,9 +110,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
Expand Down
11 changes: 1 addition & 10 deletions swig/dstc_swig.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
%}
%{

extern "C" {
#include <dstc.h>
typedef long int usec_timestamp_t;

Expand All @@ -21,7 +20,7 @@ extern "C" {
char *func_name,
char* payload,
unsigned short payload_len));
}


static PyObject *cb_ptr = NULL;

Expand Down Expand Up @@ -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);
2 changes: 1 addition & 1 deletion swig/print_name_and_age_client.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

#!/usr/bin/python3
# Test python client to exercise DSTC.
import dstc

Expand Down
3 changes: 2 additions & 1 deletion swig/print_name_and_age_server.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
6 changes: 4 additions & 2 deletions swig/setup.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/python3

"""
setup.py file for DSTC SWIG
"""
Expand All @@ -8,8 +10,8 @@
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.cxx',],libraries=['dstc', 'rmc'])
Extension('_dstc_swig', sources=['dstc_swig_wrap.c',],libraries=['dstc', 'rmc'])
],
)

0 comments on commit cf39295

Please sign in to comment.