Commit c2c15a1a authored by Asad Salman's avatar Asad Salman Committed by Adrien Béraud

Added Typemaps to handle Callbacks

Removed hacky sed calls for the same purpose

Change-Id: I8d2c475be5d6a076b4be7d2637b7f6345f5daac1
parent 5539b1ff
......@@ -3,11 +3,11 @@ include $(top_srcdir)/globals.mk
BUILT_SOURCES= \
ring_wrapper.cpp \
build/Makefile \
build/Release/dring.node \
build/Release/obj.target/dring.node
ring_wrapper.cpp: nodejs_interface.i configurationmanager.i managerimpl.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
node-gyp configure
......
......@@ -59,13 +59,13 @@ void setCallback(const std::string& signal, Local<Function>& func){
}
}
void parseCbMap(const Local<Value>& arg){
Local<Object> array = arg->ToObject();
Local<Array> props = array->GetOwnPropertyNames();
void parseCbMap(const Local<Value>& callbackMap){
Local<Object> cbAssocArray = callbackMap->ToObject();
Local<Array> props = cbAssocArray->GetOwnPropertyNames();
for (uint32_t i = 0; i < props->Length(); ++i) {
const Local<Value> key_local = props->Get(i);
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);
setCallback(key,func);
}
......
......@@ -106,13 +106,24 @@ namespace std {
#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 %{
/* some functions that need to be declared in *_wrap.cpp
* that are not declared elsewhere in the c++ code
*/
void init(const SwigV8Arguments& args){
parseCbMap(args[0]);
void init(const v8::Handle<v8::Value> &funcMap){
parseCbMap(funcMap);
using namespace std::placeholders;
using std::bind;
......@@ -143,8 +154,6 @@ void init(const SwigV8Arguments& args){
DRing::start();
}
%}
#ifndef SWIG
/* some bad declarations */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment