Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ add_definitions(-D__NO_MATH_INLINES)

link_directories(${NODE_ROOT}/lib)
include_directories(${NODE_ROOT}/include/node)
include_directories(${NODE_ROOT}/src)
include_directories(${NODE_ROOT}/deps/v8/include)

include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}"
${PROJECT_SOURCE_DIR}/nwrfcsdk/include
${PROJECT_SOURCE_DIR}/node_modules/nan
)

link_directories(
Expand All @@ -25,7 +28,10 @@ link_directories(

set(Sources
src/binding.cc
src/current_function.hpp
src/Common.h
src/Loggable.h
src/Loggable.cc
src/Connection.h
src/Connection.cc
src/Function.h
Expand Down
4 changes: 4 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
'targets': [{
'sources': [
'src/binding.cc',
'src/current_function.hpp',
'src/Common.h',
'src/Loggable.h',
'src/Loggable.cc',
'src/Connection.h',
'src/Connection.cc',
'src/Function.h',
Expand Down Expand Up @@ -44,6 +47,7 @@
'_CRT_NON_CONFORMING_SWPRINTFS',
'_CRT_SECURE_NO_DEPRECATE',
'_CRT_NONSTDC_NO_DEPRECATE',
'NOMINMAX',
'SAPonNT',
'UNICODE',
'_UNICODE'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"bindings": ">=0.3.0",
"nan": "^2.1.0"
"nan": "^2.2.0"
},
"devDependencies": {
"gulp": "^3.9.0",
Expand Down
25 changes: 24 additions & 1 deletion sapnwrfc.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
var majMinVersion = process.versions.node.match(/^[0-9]+.[0-9]+/)[0] || '';
module.exports = require('bindings')({ bindings: 'sapnwrfc', version: majMinVersion });
var sapnwrfc = require('bindings')({bindings: 'sapnwrfc', version: majMinVersion});

var _logger;

sapnwrfc.configure = function(options) {
if(options) {
_logger = options.logger;
}
}

function _log(level, message, meta) {
if(_logger) {
if(meta) {
_logger.log(level, message, meta);
} else {
_logger.log(level, message);
}
}
};

sapnwrfc.Connection.prototype._log = _log;
sapnwrfc.Function.prototype._log = _log;

module.exports = sapnwrfc;
78 changes: 58 additions & 20 deletions src/Connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ NAN_METHOD(Connection::New)
Connection *self = new Connection();
self->Wrap(info.This());

self->log(Levels::SILLY, "Connection object created");

info.GetReturnValue().Set(info.This());
}

Expand Down Expand Up @@ -103,6 +105,8 @@ NAN_METHOD(Connection::Open)
{
Connection *self = node::ObjectWrap::Unwrap<Connection>(info.This());

self->log(Levels::VERBOSE, "opening new SAP connection");

if (info.Length() < 2) {
Nan::ThrowError("Function expects 2 arguments");
return;
Expand All @@ -124,6 +128,8 @@ NAN_METHOD(Connection::Open)
memset(self->loginParams, 0, self->loginParamsSize * sizeof(RFC_CONNECTION_PARAMETER));
memset(&self->errorInfo, 0, sizeof(RFC_ERROR_INFO));

self->log(Levels::DBG, "Connection params", optionsObj);

for (unsigned int i = 0; i < self->loginParamsSize; i++) {
v8::Local<v8::Value> name = props->Get(i);
v8::Local<v8::Value> value = optionsObj->Get(name->ToString());
Expand Down Expand Up @@ -153,55 +159,67 @@ void Connection::EIO_Open(uv_work_t *req)
Connection *self = static_cast<Connection*>(req->data);

self->connectionHandle = RfcOpenConnection(self->loginParams, self->loginParamsSize, &self->errorInfo);
DEFER_LOG_API(self, "RfcOpenConnection");
}

void Connection::EIO_AfterOpen(uv_work_t *req)
{
Nan::HandleScope scope;
RFC_ERROR_INFO errorInfo;
int isValid;
Connection *self = static_cast<Connection*>(req->data);

v8::Local<v8::Value> argv[1];
argv[0] = Nan::Null();

if (self->connectionHandle == nullptr) {
self->log(Levels::DBG, "Connection handle is NULL, connection failed");
argv[0] = RfcError(self->errorInfo);
} else {
RfcIsConnectionHandleValid(self->connectionHandle, &isValid, &errorInfo);
RfcIsConnectionHandleValid(self->connectionHandle, &isValid, &self->errorInfo);
LOG_API(self, "RfcIsConnectionHandleValid");
if (!isValid) {
argv[0] = RfcError(errorInfo);
self->log(Levels::SILLY, "Connection not valid");
argv[0] = RfcError(self->errorInfo);
} else {
self->log(Levels::SILLY, "Connection still valid");
}
}

Nan::TryCatch try_catch;

self->log(Levels::SILLY, "EIO_AfterOpen: About to call the callback");
assert(!self->cbOpen->IsEmpty());
self->cbOpen->Call(1, argv);
delete self->cbOpen;
self->cbOpen = nullptr;
self->Unref();
self->log(Levels::SILLY, "EIO_AfterOpen: Finished callback");

if (try_catch.HasCaught()) {
self->log(Levels::ERR, "EIO_AfterOpen: Exception thrown in callback. Abort.");
Nan::FatalException(try_catch);
}
}

NAN_METHOD(Connection::Close)
{
Connection *self = node::ObjectWrap::Unwrap<Connection>(info.This());
self->log(Levels::SILLY, "Connection::Close");
info.GetReturnValue().Set(self->CloseConnection());
}

v8::Local<v8::Value> Connection::CloseConnection(void)
{
Nan::EscapableHandleScope scope;
RFC_RC rc = RFC_OK;
RFC_ERROR_INFO errorInfo;

log(Levels::SILLY, "Connection::CloseConnection");

if (this->connectionHandle != nullptr) {
rc = RfcCloseConnection(this->connectionHandle, &errorInfo);
LOG_API(this, "RfcCloseConnection");
if (rc != RFC_OK) {
log(Levels::DBG, "Connection::CloseConnection: Error closing connection");
scope.Escape(RfcError(errorInfo));
}
}
Expand All @@ -228,11 +246,20 @@ NAN_METHOD(Connection::IsOpen)
{
Connection *self = node::ObjectWrap::Unwrap<Connection>(info.This());
RFC_RC rc = RFC_OK;
RFC_ERROR_INFO errorInfo;
int isValid;

rc = RfcIsConnectionHandleValid(self->connectionHandle, &isValid, &errorInfo);
info.GetReturnValue().Set(isValid ? Nan::True() : Nan::False());
self->log(Levels::SILLY, "Connection::IsOpen");

rc = RfcIsConnectionHandleValid(self->connectionHandle, &isValid, &self->errorInfo);
LOG_API(self, "RfcIsConnectionHandleValid");
if(!isValid) {
self->log(Levels::SILLY, "Connection::IsOpen: RfcIsConnectionHandleValid returned false");
info.GetReturnValue().Set(Nan::False());
} else {
self->log(Levels::SILLY, "Connection::IsOpen: RfcIsConnectionHandleValid returned true");
info.GetReturnValue().Set(Nan::True());
}

}

/**
Expand All @@ -243,16 +270,18 @@ NAN_METHOD(Connection::Ping)
{
Connection *self = node::ObjectWrap::Unwrap<Connection>(info.This());
RFC_RC rc = RFC_OK;
RFC_ERROR_INFO errorInfo;

self->log(Levels::SILLY, "Connection::IsOpen");

if (info.Length() > 0) {
Nan::ThrowError("No arguments expected");
return;
}

rc = RfcPing(self->connectionHandle, &errorInfo);
rc = RfcPing(self->connectionHandle, &self->errorInfo);
LOG_API(self, "RfcPing");
if (rc != RFC_OK) {
RETURN_RFC_ERROR(errorInfo);
RETURN_RFC_ERROR(self->errorInfo);
}

info.GetReturnValue().Set(Nan::True());
Expand All @@ -264,12 +293,12 @@ NAN_METHOD(Connection::Ping)
*/
NAN_METHOD(Connection::Lookup)
{
RFC_RC rc = RFC_OK;
RFC_ERROR_INFO errorInfo;
int isValid;

Connection *self = node::ObjectWrap::Unwrap<Connection>(info.This());

self->log(Levels::SILLY, "Connection::Lookup");

if (info.Length() != 1) {
Nan::ThrowError("Function expects 1 argument");
return;
Expand All @@ -279,13 +308,21 @@ NAN_METHOD(Connection::Lookup)
return;
}

rc = RfcIsConnectionHandleValid(self->connectionHandle, &isValid, &errorInfo);
RfcIsConnectionHandleValid(self->connectionHandle, &isValid, &self->errorInfo);
LOG_API(self, "RfcIsConnectionHandleValid");
if (!isValid) {
Nan::ThrowError(RfcError(errorInfo));
self->log(Levels::SILLY, "Connection::Lookup: RfcIsConnectionHandleValid returned false");
Nan::ThrowError(RfcError(self->errorInfo));
return;
} else {
self->log(Levels::SILLY, "Connection::Lookup: RfcIsConnectionHandleValid returned true");
}

self->log(Levels::SILLY, "Connection::Lookup: About to create function instance");
v8::Local<v8::Value> f = Function::NewInstance(*self, info);
if( IsException(f)) {
self->log(Levels::DBG, "Connection::Lookup: Unable to create function instance");
}
info.GetReturnValue().Set(f);
}

Expand All @@ -295,11 +332,10 @@ NAN_METHOD(Connection::Lookup)
*/
NAN_METHOD(Connection::SetIniPath)
{
RFC_RC rc = RFC_OK;
RFC_ERROR_INFO errorInfo;

Connection *self = node::ObjectWrap::Unwrap<Connection>(info.This());

self->log(Levels::SILLY, "Connection::SetIniPath");

if (info.Length() != 1) {
Nan::ThrowError("Function expects 1 argument");
return;
Expand All @@ -311,9 +347,11 @@ NAN_METHOD(Connection::SetIniPath)

v8::Local<v8::Value> iniPath = info[0]->ToString();

rc = RfcSetIniPath(convertToSAPUC(iniPath), &errorInfo);
if (rc) {
Nan::ThrowError(RfcError(errorInfo));
RfcSetIniPath(convertToSAPUC(iniPath), &self->errorInfo);
LOG_API(self, "RfcSetIniPath");
if (self->errorInfo.code) {
self->log(Levels::DBG, "Connection::SetIniPath: RfcSetIniPath failed");
Nan::ThrowError(RfcError(self->errorInfo));
return;
}

Expand Down
7 changes: 2 additions & 5 deletions src/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ SOFTWARE.
#ifndef CONNECTION_H_
#define CONNECTION_H_

#include "Common.h"
#include <v8.h>
#include <node.h>
#include <node_version.h>
#include "Loggable.h"
#include <uv.h>
#include <sapnwrfc.h>
#include <iostream>

class Connection : public node::ObjectWrap
class Connection : public Loggable
{
friend class Function;

Expand Down
Loading