Skip to content
Snippets Groups Projects
Commit c2c15a1a authored by Asad Salman's avatar Asad Salman Committed by Adrien Béraud
Browse files

Added Typemaps to handle Callbacks

Removed hacky sed calls for the same purpose

Change-Id: I8d2c475be5d6a076b4be7d2637b7f6345f5daac1
parent 5539b1ff
No related branches found
No related tags found
No related merge requests found
...@@ -3,11 +3,11 @@ include $(top_srcdir)/globals.mk ...@@ -3,11 +3,11 @@ include $(top_srcdir)/globals.mk
BUILT_SOURCES= \ BUILT_SOURCES= \
ring_wrapper.cpp \ ring_wrapper.cpp \
build/Makefile \ build/Makefile \
build/Release/dring.node \
build/Release/obj.target/dring.node build/Release/obj.target/dring.node
ring_wrapper.cpp: nodejs_interface.i configurationmanager.i managerimpl.i ring_wrapper.cpp: nodejs_interface.i configurationmanager.i managerimpl.i
$(SWIG) -v -c++ -javascript -node -o ring_wrapper.cpp nodejs_interface.i $(SWIG) -v -c++ -javascript -node -o ring_wrapper.cpp nodejs_interface.i
sed -i 's/_wrap_init)/init)/g' ring_wrapper.cpp
build/Makefile: ring_wrapper.cpp binding.gyp build/Makefile: ring_wrapper.cpp binding.gyp
node-gyp configure node-gyp configure
......
...@@ -59,13 +59,13 @@ void setCallback(const std::string& signal, Local<Function>& func){ ...@@ -59,13 +59,13 @@ void setCallback(const std::string& signal, Local<Function>& func){
} }
} }
void parseCbMap(const Local<Value>& arg){ void parseCbMap(const Local<Value>& callbackMap){
Local<Object> array = arg->ToObject(); Local<Object> cbAssocArray = callbackMap->ToObject();
Local<Array> props = array->GetOwnPropertyNames(); Local<Array> props = cbAssocArray->GetOwnPropertyNames();
for (uint32_t i = 0; i < props->Length(); ++i) { for (uint32_t i = 0; i < props->Length(); ++i) {
const Local<Value> key_local = props->Get(i); const Local<Value> key_local = props->Get(i);
std::string key = *String::Utf8Value(key_local); std::string key = *String::Utf8Value(key_local);
Handle<Object> buffer = array->Get(V8_STRING_NEW(key))->ToObject(); Handle<Object> buffer = cbAssocArray->Get(V8_STRING_NEW(key))->ToObject();
Local<Function> func = Local<Function>::Cast(buffer); Local<Function> func = Local<Function>::Cast(buffer);
setCallback(key,func); setCallback(key,func);
} }
......
...@@ -106,13 +106,24 @@ namespace std { ...@@ -106,13 +106,24 @@ namespace std {
#include "callback.h" #include "callback.h"
%} %}
//typemap for passing Callbacks
%typemap(in) v8::Local<v8::Function> {
$1 = v8::Local<v8::Function>::Cast($input);
}
//typemap for handling map of functions
%typemap(in) const v8::Handle<v8::Value> {
$1 = $input;
}
%inline %{ %inline %{
/* some functions that need to be declared in *_wrap.cpp /* some functions that need to be declared in *_wrap.cpp
* that are not declared elsewhere in the c++ code * that are not declared elsewhere in the c++ code
*/ */
void init(const SwigV8Arguments& args){ void init(const v8::Handle<v8::Value> &funcMap){
parseCbMap(args[0]); parseCbMap(funcMap);
using namespace std::placeholders; using namespace std::placeholders;
using std::bind; using std::bind;
...@@ -143,8 +154,6 @@ void init(const SwigV8Arguments& args){ ...@@ -143,8 +154,6 @@ void init(const SwigV8Arguments& args){
DRing::start(); DRing::start();
} }
%} %}
#ifndef SWIG #ifndef SWIG
/* some bad declarations */ /* some bad declarations */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment