aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2016-07-20 16:40:00 +0300
committerGabriel Schulhof <gabriel.schulhof@intel.com>2016-08-08 11:44:08 +0000
commit74f0782652da0b089885000cedb5dac7fda76446 (patch)
treed2d34ec4b3ae6c4befcbad61b5cff6da11f5a7c4
parent7223f684f71fc04dac5c8d8da7a498b933ea9309 (diff)
All: Move up to iotivity 1.1.11.1.1-0
Bindings: * Use JS handles instead of arrays OicClient: * Create device.url from OCDevAddr Build: * Switch away from jshint/jscs to eslint * Add node 6 to Travis suite * Build iotivity logger to appease OSX Tests: * OicDevice.dataModels is supposed to be an array Examples: * Complete device information Fixes gh-52 Closes gh-67 Change-Id: I4ede50f12444b8b9772ae996fed5b868b828cbb5 Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-on: https://gerrit.iotivity.org/gerrit/10145
-rw-r--r--.eslintrc.json10
-rw-r--r--.jscsrc3
-rw-r--r--.travis.yml4
-rw-r--r--README.md12
-rw-r--r--binding.gyp1
-rwxr-xr-xbuild-csdk.sh11
-rw-r--r--grunt-build/js-example-files.js (renamed from grunt-build/js-example-and-test-files.js)5
-rw-r--r--grunt-build/js-files.js18
-rw-r--r--grunt-build/js-test-files.js (renamed from grunt-build/tasks/options/jscs.js)6
-rw-r--r--grunt-build/jshint-options.json25
-rw-r--r--grunt-build/tasks/alias.js2
-rw-r--r--grunt-build/tasks/options/esformatter.js6
-rw-r--r--grunt-build/tasks/options/eslint.js (renamed from grunt-build/tasks/options/jshint.js)33
-rw-r--r--js/client.delete.js97
-rw-r--r--js/high-level-resource-creation-server.js2
-rw-r--r--js/high-level-server-example.js2
-rw-r--r--js/server.delete.js91
-rw-r--r--js/server.discoverable.js6
-rw-r--r--lib/OicClient.js38
-rw-r--r--lib/OicDevice.js7
-rw-r--r--lib/OicServer.js38
-rw-r--r--octbstack.pc.in2
-rw-r--r--package.json6
-rw-r--r--src/common.h33
-rw-r--r--src/functions/oc-cancel.cc4
-rw-r--r--src/functions/oc-create-delete-resource.cc30
-rw-r--r--src/functions/oc-do-resource.cc13
-rw-r--r--src/functions/oc-notify.cc8
-rw-r--r--src/functions/simple.cc46
-rw-r--r--src/structures.cc8
-rw-r--r--src/structures/handles.cc110
-rw-r--r--src/structures/handles.h13
-rw-r--r--src/structures/oc-device-info.cc97
-rw-r--r--src/structures/oc-entity-handler-response.cc17
-rw-r--r--src/structures/oc-payload.cc8
-rw-r--r--tests/assert-to-console.js8
-rw-r--r--tests/tests/API Complex Payload/server.js3
-rw-r--r--tests/tests/API Device Information/client.js14
-rw-r--r--tests/tests/Complex Payload/server.js4
-rw-r--r--tests/tests/Device Entity Handler/server.js4
-rw-r--r--tests/tests/Discovery/server.js4
-rw-r--r--tests/tests/Get Request/server.js4
-rw-r--r--tests/tests/Multiple Observers/server.js4
-rw-r--r--tests/tests/Observation/server.js4
-rw-r--r--tests/tests/Presence/server.js4
-rw-r--r--tests/tests/Resource Operations.js7
-rw-r--r--tests/utils.js3
47 files changed, 608 insertions, 267 deletions
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..4e27087
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,10 @@
+{
+ "extends": "eslint-config-jquery",
+ "root": true,
+ "globals": {
+ "Promise": false
+ },
+ "env": {
+ "node": true
+ }
+}
diff --git a/.jscsrc b/.jscsrc
deleted file mode 100644
index 8729368..0000000
--- a/.jscsrc
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "preset": "jquery"
-} \ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 34fe176..1a80899 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -29,6 +29,10 @@ matrix:
os: linux
addons: *buildpackages
+ - env: NODE_VERSION=6 TEST_SCRIPT=ci
+ os: linux
+ addons: *buildpackages
+
- env: NODE_VERSION=4.0 TEST_SCRIPT=ci-lint
os: linux
diff --git a/README.md b/README.md
index 44b6fde..6dc60d2 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ This project provides a Javascript API for [OCF][] functionality. The API follow
### For the impatient:
0. Make sure [node][] is up and running
0. Install the following packages, which your distribution should provide:
- 0. unzip, scons, wget, git, and make
+ 0. unzip, scons, wget, git, patch, tar, and make
0. Development headers for boost, libuuid, glib2, and libcurl
boost and libcurl are needed during the build process, but iotivity-node does not ultimately depend on either.
@@ -35,7 +35,7 @@ var device = require( "iotivity-node" )();
will give you an instance of OicDevice as described in the JS API spec.
### In more detail:
-iotivity-node depends on [iotivity][] proper. It has been tested against [1.1.0][] on Linux. iotivity depends on development headers for libuuid and boost.
+iotivity-node depends on [iotivity][] proper. It has been tested against [1.1.1][] on Linux. iotivity depends on development headers for libuuid and boost.
iotivity-node requires a compiler that implements the C++11 standard.
@@ -107,11 +107,11 @@ Make sure no firewall is running (or one is properly configured to allow iotivit
[iotivity]: http://iotivity.org/
[node]: https://nodejs.org/
-[1.1.0]: https://gerrit.iotivity.org/gerrit/gitweb?p=iotivity.git;a=tree;hb=1.1.0
-[snapshot]: https://gerrit.iotivity.org/gerrit/gitweb?p=iotivity.git;a=snapshot;h=1.1.0;sf=tgz
+[1.1.1]: https://gerrit.iotivity.org/gerrit/gitweb?p=iotivity.git;a=tree;hb=1.1.1
+[snapshot]: https://gerrit.iotivity.org/gerrit/gitweb?p=iotivity.git;a=snapshot;h=1.1.1;sf=tgz
[scons]: http://www.scons.org/
-[install.sh]: https://raw.githubusercontent.com/otcshare/iotivity-node/1.1.0-5/install.sh
-[octbstack.pc.in]: https://raw.githubusercontent.com/otcshare/iotivity-node/1.1.0-5/octbstack.pc.in
+[install.sh]: https://raw.githubusercontent.com/otcshare/iotivity-node/1.1.1-0/install.sh
+[octbstack.pc.in]: https://raw.githubusercontent.com/otcshare/iotivity-node/1.1.1-0/octbstack.pc.in
[iotivity wiki]: https://wiki.iotivity.org/faq_s
[video]: https://www.youtube.com/watch?v=95VTB_qgYfw
[specification]: https://github.com/01org/iot-js-api-test-suite/blob/master/api/oic.md
diff --git a/binding.gyp b/binding.gyp
index fb8862b..4311a42 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -63,6 +63,7 @@
"-lcoap",
"-lc_common",
"-lroutingmanager",
+ "-llogger",
"-locsrm"
]
} ],
diff --git a/build-csdk.sh b/build-csdk.sh
index 470a404..e169157 100755
--- a/build-csdk.sh
+++ b/build-csdk.sh
@@ -18,11 +18,14 @@
# assumes the package version is of the form major.minor.patch[-dev-commitid]. It grabs whatever
# follows a zero-or-more-length-series of tokens that end in a dash.
if test "x${CSDK_REVISION}x" = "xx"; then
- CSDK_REVISION="$(node -e '
- console.log( require( "./package.json" ).version
+ CSDK_REVISION="$(node -p '
+ require( "./package.json" ).version
.replace( /-[0-9]*$/, "" )
- .replace( /^([^-]*-)*/, "" ) );
+ .replace( /^([^-]*-)pre-(.*$)/, "$2" )
')"
+
+ # The second .replace() will not match anything if it's not a commitid-version, so we will be
+ # left with the exact upstream version
fi
DO_BUILD=true
@@ -80,7 +83,7 @@ if test "x${DO_BUILD}x" = "xtruex"; then
cd extlibs/tinycbor/tinycbor
git checkout dbc0129400f22087d4be3396cc44ea922d2f07f8
cd -
- scons $SCONS_FLAGS liboctbstack libconnectivity_abstraction libcoap c_common libocsrm routingmanager || { cat config.log; exit 1; }
+ scons $SCONS_FLAGS logger liboctbstack libconnectivity_abstraction libcoap c_common libocsrm routingmanager || { cat config.log; exit 1; }
cd ../../ || exit 1
else
diff --git a/grunt-build/js-example-and-test-files.js b/grunt-build/js-example-files.js
index 03eaf88..bbdc2ba 100644
--- a/grunt-build/js-example-and-test-files.js
+++ b/grunt-build/js-example-files.js
@@ -12,7 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-module.exports = [
- "js/*.js",
- "tests/**/*.js"
-];
+module.exports = [ "js/*.js" ];
diff --git a/grunt-build/js-files.js b/grunt-build/js-files.js
deleted file mode 100644
index fa6e6b1..0000000
--- a/grunt-build/js-files.js
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2016 Intel Corporation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-module.exports = []
- .concat( require( "./js-example-and-test-files" ) )
- .concat( require( "./js-lib-files" ) )
- .concat( require( "./js-build-files" ) );
diff --git a/grunt-build/tasks/options/jscs.js b/grunt-build/js-test-files.js
index 932c547..2cac315 100644
--- a/grunt-build/tasks/options/jscs.js
+++ b/grunt-build/js-test-files.js
@@ -12,8 +12,4 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-module.exports = {
- js: {
- src: require( "../../js-files" )
- }
-};
+module.exports = [ "tests/**/*.js" ];
diff --git a/grunt-build/jshint-options.json b/grunt-build/jshint-options.json
deleted file mode 100644
index fc1da8b..0000000
--- a/grunt-build/jshint-options.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "boss": true,
- "curly": true,
- "eqeqeq": true,
- "eqnull": true,
- "expr": true,
- "immed": true,
- "jquery": true,
- "noarg": true,
- "quotmark": "double",
- "trailing": true,
- "undef": true,
- "unused": true,
- "esnext": true,
- "latedef": true,
- "newcap": true,
- "sub": true,
- "browser": true,
- "globals": {
- "define": false,
- "require": false,
- "requirejs": false
- },
- "node": true
-}
diff --git a/grunt-build/tasks/alias.js b/grunt-build/tasks/alias.js
index ab2be20..ff08d97 100644
--- a/grunt-build/tasks/alias.js
+++ b/grunt-build/tasks/alias.js
@@ -14,7 +14,7 @@
module.exports = function( grunt ) {
-grunt.registerTask( "lint", [ "jshint", "jscs" ] );
+grunt.registerTask( "lint", [ "eslint" ] );
grunt.registerTask( "default", [ "test" ] );
diff --git a/grunt-build/tasks/options/esformatter.js b/grunt-build/tasks/options/esformatter.js
index 3c1ad23..46c0524 100644
--- a/grunt-build/tasks/options/esformatter.js
+++ b/grunt-build/tasks/options/esformatter.js
@@ -17,5 +17,9 @@ module.exports = {
preset: "jquery",
plugins: [ "esformatter-jquery-chain" ]
},
- src: require( "../../js-files" )
+ src: []
+ .concat( require( "../../js-build-files" ) )
+ .concat( require( "../../js-example-files" ) )
+ .concat( require( "../../js-lib-files" ) )
+ .concat( require( "../../js-test-files" ) )
};
diff --git a/grunt-build/tasks/options/jshint.js b/grunt-build/tasks/options/eslint.js
index 7d80c06..84ee4fe 100644
--- a/grunt-build/tasks/options/jshint.js
+++ b/grunt-build/tasks/options/eslint.js
@@ -12,22 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-var _ = require( "lodash" ),
- commonJSHintOptions = require( "../../jshint-options.json" );
-
module.exports = {
- nonlib: {
- options: commonJSHintOptions,
- files: {
- src: []
- .concat( require( "../../js-example-and-test-files" ) )
- .concat( require( "../../js-build-files" ) )
- }
- },
+ examples: { src: require( "../../js-example-files" ) },
+ tests: { src: require( "../../js-test-files" ) },
+
+ // The library and the build files must not use the global "console"
lib: {
- options: _.extend( {}, commonJSHintOptions, { predef: [ "-console" ] } ),
- files: {
- src: require( "../../js-lib-files" )
- }
+ options: {
+ rules: {
+ "no-restricted-globals": [ 2, "console" ]
+ }
+ },
+ src: require( "../../js-lib-files" )
+ },
+ build: {
+ options: {
+ rules: {
+ "no-restricted-globals": [ 2, "console" ]
+ }
+ },
+ src: require( "../../js-build-files" )
}
};
diff --git a/js/client.delete.js b/js/client.delete.js
new file mode 100644
index 0000000..9ee835e
--- /dev/null
+++ b/js/client.delete.js
@@ -0,0 +1,97 @@
+// Copyright 2016 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+var intervalId,
+ handleReceptacle = {},
+
+ // This is the same value as server.get.js
+ sampleUri = "/a/iotivity-node-delete-sample",
+ iotivity = require( "iotivity-node/lowlevel" );
+
+console.log( "Starting OCF stack in client mode" );
+
+// Start iotivity and set up the processing loop
+iotivity.OCInit( null, 0, iotivity.OCMode.OC_CLIENT );
+
+intervalId = setInterval( function() {
+ iotivity.OCProcess();
+}, 1000 );
+
+console.log( "Issuing discovery request" );
+
+// Discover resources and list them
+iotivity.OCDoResource(
+
+ // The bindings fill in this object
+ handleReceptacle,
+
+ iotivity.OCMethod.OC_REST_DISCOVER,
+
+ // Standard path for discovering resources
+ iotivity.OC_MULTICAST_DISCOVERY_URI,
+
+ // There is no destination
+ null,
+
+ // There is no payload
+ null,
+ iotivity.OCConnectivityType.CT_DEFAULT,
+ iotivity.OCQualityOfService.OC_HIGH_QOS,
+ function( handle, response ) {
+ console.log( "Received response to DISCOVER request:" );
+ console.log( JSON.stringify( response, null, 4 ) );
+ var index,
+ destination = response.addr,
+ getHandleReceptacle = {},
+ resources = response && response.payload && response.payload.resources,
+ resourceCount = resources ? resources.length : 0,
+ deleteResponseHandler = function( handle, response ) {
+ console.log( "Received response to DELETE request:" );
+ console.log( JSON.stringify( response, null, 4 ) );
+ return iotivity.OCStackApplicationResult.OC_STACK_DELETE_TRANSACTION;
+ };
+
+ // If the sample URI is among the resources, issue the GET request to it
+ for ( index = 0; index < resourceCount; index++ ) {
+ if ( resources[ index ].uri === sampleUri ) {
+ iotivity.OCDoResource(
+ getHandleReceptacle,
+ iotivity.OCMethod.OC_REST_DELETE,
+ sampleUri,
+ destination,
+ null,
+ iotivity.OCConnectivityType.CT_DEFAULT,
+ iotivity.OCQualityOfService.OC_HIGH_QOS,
+ deleteResponseHandler,
+ null );
+ }
+ }
+
+ return iotivity.OCStackApplicationResult.OC_STACK_KEEP_TRANSACTION;
+ },
+
+ // There are no header options
+ null );
+
+// Exit gracefully when interrupted
+process.on( "SIGINT", function() {
+ console.log( "SIGINT: Quitting..." );
+
+ // Tear down the processing loop and stop iotivity
+ clearInterval( intervalId );
+ iotivity.OCStop();
+
+ // Exit
+ process.exit( 0 );
+} );
diff --git a/js/high-level-resource-creation-server.js b/js/high-level-resource-creation-server.js
index 7934d09..9a668c4 100644
--- a/js/high-level-resource-creation-server.js
+++ b/js/high-level-resource-creation-server.js
@@ -22,7 +22,7 @@ device.device = _.extend( device.device, {
device.platform = _.extend( device.platform, {
manufacturerName: "Intel",
manunfactureDate: new Date( "Wed Sep 23 10:04:17 EEST 2015" ),
- platformVersion: "1.0.1",
+ platformVersion: "1.1.1",
firmwareVersion: "0.0.1",
supportUrl: "http://example.com/"
} );
diff --git a/js/high-level-server-example.js b/js/high-level-server-example.js
index c1f0fff..4ff581b 100644
--- a/js/high-level-server-example.js
+++ b/js/high-level-server-example.js
@@ -26,7 +26,7 @@ device.device = _.extend( device.device, {
device.platform = _.extend( device.platform, {
manufacturerName: "Intel",
manufactureDate: new Date( "Wed Sep 23 10:04:17 EEST 2015" ),
- platformVersion: "1.0.1",
+ platformVersion: "1.1.1",
firmwareVersion: "0.0.1",
supportUrl: "http://example.com/"
} );
diff --git a/js/server.delete.js b/js/server.delete.js
new file mode 100644
index 0000000..1f95cb6
--- /dev/null
+++ b/js/server.delete.js
@@ -0,0 +1,91 @@
+// Copyright 2016 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+var intervalId,
+ handleReceptacle = {},
+
+ // This is the same value as server.get.js
+ sampleUri = "/a/iotivity-node-delete-sample",
+ iotivity = require( "iotivity-node/lowlevel" );
+
+console.log( "Starting OCF stack in server mode" );
+
+// Start iotivity and set up the processing loop
+iotivity.OCInit( null, 0, iotivity.OCMode.OC_SERVER );
+
+iotivity.OCSetDeviceInfo( { deviceName: "server.get", types: [] } );
+iotivity.OCSetPlatformInfo( {
+ platformID: "server.get.sample",
+ manufacturerName: "iotivity-node"
+} );
+
+intervalId = setInterval( function() {
+ iotivity.OCProcess();
+}, 1000 );
+
+console.log( "Registering resource" );
+
+// Create a new resource
+iotivity.OCCreateResource(
+
+ // The bindings fill in this object
+ handleReceptacle,
+
+ "core.fan",
+ iotivity.OC_RSRVD_INTERFACE_DEFAULT,
+ sampleUri,
+ function( flag, request ) {
+ console.log( "Entity handler called with flag = " + flag + " and the following request:" );
+ console.log( JSON.stringify( request, null, 4 ) );
+
+ // If we find the magic question in the request, we return the magic answer
+ if ( request && request.method === iotivity.OCMethod.OC_REST_DELETE ) {
+
+ var result = iotivity.OCDeleteResource( handleReceptacle.handle );
+
+ console.log( "OCDeleteResource() has resulted in " + result );
+
+ iotivity.OCDoResponse( {
+ requestHandle: request.requestHandle,
+ resourceHandle: request.resource,
+ ehResult: result ?
+ iotivity.OCEntityHandlerResult.OC_EH_ERROR :
+ iotivity.OCEntityHandlerResult.OC_EH_RESOURCE_DELETED,
+ payload: null,
+ resourceUri: sampleUri,
+ sendVendorSpecificHeaderOptions: []
+ } );
+
+ return iotivity.OCEntityHandlerResult.OC_EH_OK;
+ }
+
+ // By default we error out
+ return iotivity.OCEntityHandlerResult.OC_EH_ERROR;
+ },
+ iotivity.OCResourceProperty.OC_DISCOVERABLE );
+
+console.log( "Server ready" );
+
+// Exit gracefully when interrupted
+process.on( "SIGINT", function() {
+ console.log( "SIGINT: Quitting..." );
+
+ // Tear down the processing loop and stop iotivity
+ clearInterval( intervalId );
+ iotivity.OCDeleteResource( handleReceptacle.handle );
+ iotivity.OCStop();
+
+ // Exit
+ process.exit( 0 );
+} );
diff --git a/js/server.discoverable.js b/js/server.discoverable.js
index 66ac83f..df10325 100644
--- a/js/server.discoverable.js
+++ b/js/server.discoverable.js
@@ -25,7 +25,11 @@ intervalId = setInterval( function() {
iotivity.OCProcess();
}, 1000 );
-iotivity.OCSetDeviceInfo( { deviceName: "server.discoverable", types: [] } );
+iotivity.OCSetDeviceInfo( {
+ dataModelVersions: [ "test.0.0.1" ],
+ deviceName: "server.discoverable",
+ types: []
+} );
iotivity.OCSetPlatformInfo( {
platformID: "server.discoverable.sample",
manufacturerName: "iotivity-node"
diff --git a/lib/OicClient.js b/lib/OicClient.js
index 8e88368..f117e2a 100644
--- a/lib/OicClient.js
+++ b/lib/OicClient.js
@@ -24,6 +24,29 @@ var iotivity = require( "bindings" )( "iotivity" ),
OicResource = require( "./OicResource" );
+function ocAddressToUrl( ocAddress ) {
+ var theBuffer, theResult = "";
+
+ try {
+ theBuffer = Buffer.from( ocAddress.addr );
+ } catch ( anError ) {}
+ if ( !theBuffer ) {
+ try {
+ theBuffer = new Buffer( ocAddress.addr );
+ } catch ( anError ) {}
+ }
+
+ if ( theBuffer ) {
+ theResult = theBuffer.toString( "utf8" );
+ }
+
+ if ( ocAddress.port ) {
+ theResult += ":" + ocAddress.port;
+ }
+
+ return theResult;
+}
+
module.exports = function( devicePrototype ) {
_.extend( devicePrototype, {
@@ -259,7 +282,8 @@ _.extend( devicePrototype, {
function oneShotRequestHandler( handle, response ) {
var answer;
- if ( response.result === ocStackOk ) {
+ if ( response.result === ocStackOk ||
+ response.result === options.expectedResponse ) {
// In case of success, @createAnswer() is responsible for
// providing the value we pass to fulfill()
@@ -407,8 +431,11 @@ _.extend( devicePrototype, {
}, ( deviceId ? { deviceId: deviceId } : {} ) ) );
} else if ( response.payload ) {
this._addDevice( deviceId, {
+ url: ocAddressToUrl( response.addr ),
+ role: "server",
uuid: deviceId,
name: response.payload.deviceName,
+ dataModels: response.payload.dataModelVersions,
coreSpecVersion: response.payload.specVersion
}, response.devAddr );
}
@@ -517,7 +544,13 @@ _.extend( devicePrototype, {
this._devices[ id ] = _.extend( this._devices[ id ] || {}, {
info: {
uuid: id,
+
+ // FIXME: We assume it's a server here because the stack does not tell us
+ // one way or the other
+ role: "server",
+ url: ocAddressToUrl( response.addr ),
name: response.payload.deviceName,
+ dataModels: response.payload.dataModelVersions,
coreSpecVersion: response.payload.specVersion
}
} );
@@ -597,6 +630,7 @@ _.extend( devicePrototype, {
Array.isArray( resource.interfaces ) && resource.interfaces.length >= 1 &&
Object.keys( resource.properties ).length >= 1 ) ?
this._oneShotRequest( {
+ expectedResponse: iotivity.OCStackResult.OC_STACK_RESOURCE_CHANGED,
prefix: "create",
resourceId: resource.id,
method: "OC_REST_POST",
@@ -646,6 +680,7 @@ _.extend( devicePrototype, {
update: function( resource ) {
return this._oneShotRequest( {
+ expectedResponse: iotivity.OCStackResult.OC_STACK_RESOURCE_CHANGED,
prefix: "update",
resourceId: resource.id,
method: "OC_REST_PUT",
@@ -655,6 +690,7 @@ _.extend( devicePrototype, {
delete: function( id ) {
return this._oneShotRequest( {
+ expectedResponse: iotivity.OCStackResult.OC_STACK_RESOURCE_DELETED,
prefix: "delete",
resourceId: id,
method: "OC_REST_DELETE",
diff --git a/lib/OicDevice.js b/lib/OicDevice.js
index 2f150cb..97fb05f 100644
--- a/lib/OicDevice.js
+++ b/lib/OicDevice.js
@@ -77,7 +77,12 @@ _.extend( utils.makeEventEmitter( OicDevice ).prototype, {
},
_setDeviceInfo: function( info ) {
- var result = iotivity.OCSetDeviceInfo( { deviceName: info.name, types: [] } );
+ var result = iotivity.OCSetDeviceInfo( {
+ specVersion: info.coreSpecVersion,
+ deviceName: info.name,
+ dataModelVersions: info.dataModels,
+ types: []
+ } );
if ( result !== iotivity.OCStackResult.OC_STACK_OK ) {
throw _.extend( new Error( "Set device info failed" ), {
result: result
diff --git a/lib/OicServer.js b/lib/OicServer.js
index c255373..a788e5c 100644
--- a/lib/OicServer.js
+++ b/lib/OicServer.js
@@ -46,9 +46,11 @@ _.extend( OicRequestEvent.prototype, {
resourceHandle: this._resourceHandle,
payload: ( payloadObject ? myUtils.objectToPayload( payloadObject ) : null ),
sendVendorSpecificHeaderOptions: headerOptions,
- resourceUri: ( iotivity.OCGetResourceUri( this._resourceHandle ) || "" ),
+ resourceUri: ( this._resourceHandle ?
+ iotivity.OCGetResourceUri( this._resourceHandle ) || "" : "" ),
ehResult: entityHandlerResult
} );
+
if ( result !== iotivity.OCStackResult.OC_STACK_OK ) {
reject( _.extend( new Error( "OCDoResponse Error" ), {
result: result
@@ -60,7 +62,9 @@ _.extend( OicRequestEvent.prototype, {
},
sendResponse: function( resource ) {
- return this._constructResponse( iotivity.OCEntityHandlerResult.OC_EH_OK,
+ return this._constructResponse( this.type === "deleterequest" ?
+ iotivity.OCEntityHandlerResult.OC_EH_RESOURCE_DELETED :
+ iotivity.OCEntityHandlerResult.OC_EH_OK,
resource ? resource.properties : null );
},
@@ -125,16 +129,18 @@ _.extend( devicePrototype, {
// Handle the request and raise events accordingly
var i,
deviceId = iotivity.OCGetServerInstanceIDString(),
- url = iotivity.OCGetResourceUri( request.resource ) || requestedUrl,
+ url = request.resource ?
+ ( iotivity.OCGetResourceUri( request.resource ) || "" ) :
+ requestedUrl,
oicReq = new OicRequestEvent();
oicReq._resourceHandle = request.resource;
oicReq.requestId = request.requestHandle;
oicReq.target = resource || this._resources[ deviceId + ":" + url ] || {
- id: {
- deviceId: deviceId,
- path: url
- }
+ id: {
+ deviceId: deviceId,
+ path: url
+ }
};
if ( flag & iotivity.OCEntityHandlerFlag.OC_REQUEST_FLAG ) {
@@ -164,10 +170,10 @@ _.extend( devicePrototype, {
// Make sure we have everything we need for creating a new resource
if ( !( request.payload &&
- Array.isArray( request.payload.interfaces ) &&
- request.payload.interfaces.length >= 1 &&
- Array.isArray( request.payload.types ) &&
- request.payload.types.length >= 1 ) ) {
+ Array.isArray( request.payload.interfaces ) &&
+ request.payload.interfaces.length >= 1 &&
+ Array.isArray( request.payload.types ) &&
+ request.payload.types.length >= 1 ) ) {
return iotivity.OCEntityHandlerResult.OC_EH_ERROR;
}
@@ -241,11 +247,11 @@ _.extend( devicePrototype, {
var resource;
var result = 0;
var flag = 0 |
- ( init.discoverable ? iotivity.OCResourceProperty.OC_DISCOVERABLE : 0 ) |
- ( init.observable ? iotivity.OCResourceProperty.OC_OBSERVABLE : 0 ) |
- ( init.slow ? iotivity.OCResourceProperty.OC_SLOW : 0 ) |
- ( init.active ? iotivity.OCResourceProperty.OC_ACTIVE : 0 ) |
- ( init.secure ? iotivity.OCResourceProperty.OC_SECURE : 0 );
+ ( init.discoverable ? iotivity.OCResourceProperty.OC_DISCOVERABLE : 0 ) |
+ ( init.observable ? iotivity.OCResourceProperty.OC_OBSERVABLE : 0 ) |
+ ( init.slow ? iotivity.OCResourceProperty.OC_SLOW : 0 ) |
+ ( init.active ? iotivity.OCResourceProperty.OC_ACTIVE : 0 ) |
+ ( init.secure ? iotivity.OCResourceProperty.OC_SECURE : 0 );
var handleReceptacle = {};
if ( !init.id.deviceId ) {
diff --git a/octbstack.pc.in b/octbstack.pc.in
index 32334c8..58e9144 100644
--- a/octbstack.pc.in
+++ b/octbstack.pc.in
@@ -4,6 +4,6 @@ includedir=@INCLUDEDIR@
Name: liboctbstack
Description: iotivity CSDK
-Version: 1.1.0
+Version: 1.1.1-RC2
Libs: -L${libdir} -Wl,-rpath ${libdir} -loctbstack @PLATFORM_LIBS@
Cflags: -I${includedir}/@OCTB_STACK_INCLUDEDIR@ -I${includedir}/@OCTB_RANDOM_INCLUDEDIR@ -I${includedir}/@OCTB_CCOMMON_INCLUDEDIR@ -DTCP_ADAPTER -DROUTING_EP
diff --git a/package.json b/package.json
index 1312d02..f9792ed 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "iotivity-node",
- "version": "1.1.0-5",
+ "version": "1.1.1-0",
"description": "IoTivity bindings",
"repository": "https://github.com/otcshare/iotivity-node/",
"license": "Apache-2.0",
@@ -27,11 +27,11 @@
"async": "^0.9.0",
"commitplease": "^2.2.1",
"esformatter-jquery-chain": "^1.1.0",
+ "eslint-config-jquery": "0.1.2",
"glob": "^5.0.14",
"grunt": "^0.4.5",
- "grunt-contrib-jshint": "^0.11.3",
"grunt-esformatter": "^1.0.1",
- "grunt-jscs": "^2.1.0",
+ "grunt-eslint": "18.1.0",
"iot-js-api-test-suite": "https://github.com/01org/iot-js-api-test-suite.git",
"load-grunt-config": "^0.17.2",
"load-grunt-tasks": "^3.2.0",
diff --git a/src/common.h b/src/common.h
index 5e26547..f6a5677 100644
--- a/src/common.h
+++ b/src/common.h
@@ -17,13 +17,16 @@
#ifndef __IOTIVITY_NODE_FUNCTIONS_INTERNAL_H__
#define __IOTIVITY_NODE_FUNCTIONS_INTERNAL_H__
+#include <string>
#include <v8.h>
#include <nan.h>
-#define VALIDATE_CALLBACK_RETURN_VALUE_TYPE(value, typecheck, message) \
- if (!value->typecheck()) { \
- Nan::ThrowTypeError( \
- message " callback return value type must satisfy " #typecheck "()"); \
+#define VALIDATE_CALLBACK_RETURN_VALUE_TYPE(value, typecheck, message) \
+ if (!value->typecheck()) { \
+ Nan::ThrowTypeError( \
+ (std::string(message) + \
+ " callback return value type must satisfy " #typecheck "()") \
+ .c_str()); \
}
#define VALIDATE_ARGUMENT_COUNT(args, length) \
@@ -37,18 +40,20 @@
"()"); \
}
-#define VALIDATE_VALUE_TYPE(value, typecheck, message, failReturn) \
- if (!(value)->typecheck()) { \
- Nan::ThrowTypeError(message " must satisfy " #typecheck "()"); \
- return failReturn; \
+#define VALIDATE_VALUE_TYPE(value, typecheck, message, failReturn) \
+ if (!(value)->typecheck()) { \
+ Nan::ThrowTypeError( \
+ (std::string(message) + " must satisfy " #typecheck "()").c_str()); \
+ return failReturn; \
}
-#define VALIDATE_VALUE_TYPE_OR_FREE(value, typecheck, message, failReturn, \
- pointer_to_free, free_function) \
- if (!(value)->typecheck()) { \
- Nan::ThrowTypeError(message " must satisfy " #typecheck "()"); \
- free_function((pointer_to_free)); \
- return failReturn; \
+#define VALIDATE_VALUE_TYPE_OR_FREE(value, typecheck, message, failReturn, \
+ pointer_to_free, free_function) \
+ if (!(value)->typecheck()) { \
+ Nan::ThrowTypeError( \
+ (std::string(message) + " must satisfy " #typecheck "()").c_str()); \
+ free_function((pointer_to_free)); \
+ return failReturn; \
}
#define VALIDATE_ARGUMENT_TYPE_OR_NULL(args, index, typecheck) \
diff --git a/src/functions/oc-cancel.cc b/src/functions/oc-cancel.cc
index 3d0aef2..8a1de79 100644
--- a/src/functions/oc-cancel.cc
+++ b/src/functions/oc-cancel.cc
@@ -31,7 +31,7 @@ using namespace node;
NAN_METHOD(bind_OCCancel) {
VALIDATE_ARGUMENT_COUNT(info, 3);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
VALIDATE_ARGUMENT_TYPE(info, 1, IsUint32);
VALIDATE_ARGUMENT_TYPE_OR_NULL(info, 2, IsArray);
@@ -40,7 +40,7 @@ NAN_METHOD(bind_OCCancel) {
{OC_INVALID_ID, 0, 0, {0}}};
uint8_t numberOfOptions = 0;
- if (!c_OCDoHandle(Local<Array>::Cast(info[0]), &handle)) {
+ if (!c_OCDoHandle(Nan::To<Object>(info[0]).ToLocalChecked(), &handle)) {
return;
}
diff --git a/src/functions/oc-create-delete-resource.cc b/src/functions/oc-create-delete-resource.cc
index 4ab778c..d0c5016 100644
--- a/src/functions/oc-create-delete-resource.cc
+++ b/src/functions/oc-create-delete-resource.cc
@@ -73,13 +73,13 @@ NAN_METHOD(bind_OCCreateResource) {
NAN_METHOD(bind_OCDeleteResource) {
VALIDATE_ARGUMENT_COUNT(info, 1);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
OCStackResult returnValue;
OCResourceHandle handle = 0;
// Retrieve OCResourceHandle from JS object
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &handle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(), &handle)) {
return;
}
@@ -100,13 +100,13 @@ NAN_METHOD(bind_OCDeleteResource) {
NAN_METHOD(bind_OCBindResourceHandler) {
VALIDATE_ARGUMENT_COUNT(info, 2);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
VALIDATE_ARGUMENT_TYPE(info, 1, IsFunction);
OCResourceHandle handle = 0;
// Retrieve OCResourceHandle from JS object
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &handle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(), &handle)) {
return;
}
@@ -135,15 +135,17 @@ NAN_METHOD(bind_OCBindResourceHandler) {
NAN_METHOD(bind_OCBindResource) {
VALIDATE_ARGUMENT_COUNT(info, 2);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
- VALIDATE_ARGUMENT_TYPE(info, 1, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
+ VALIDATE_ARGUMENT_TYPE(info, 1, IsObject);
OCResourceHandle collectionHandle = 0, resourceHandle = 0;
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &collectionHandle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(),
+ &collectionHandle)) {
return;
}
- if (!c_OCResourceHandle(Local<Array>::Cast(info[1]), &resourceHandle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[1]).ToLocalChecked(),
+ &resourceHandle)) {
return;
}
@@ -153,12 +155,12 @@ NAN_METHOD(bind_OCBindResource) {
NAN_METHOD(bind_OCBindResourceInterfaceToResource) {
VALIDATE_ARGUMENT_COUNT(info, 2);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
VALIDATE_ARGUMENT_TYPE(info, 1, IsString);
OCResourceHandle handle = 0;
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &handle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(), &handle)) {
return;
}
@@ -168,12 +170,12 @@ NAN_METHOD(bind_OCBindResourceInterfaceToResource) {
NAN_METHOD(bind_OCBindResourceTypeToResource) {
VALIDATE_ARGUMENT_COUNT(info, 2);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
VALIDATE_ARGUMENT_TYPE(info, 1, IsString);
OCResourceHandle handle = 0;
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &handle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(), &handle)) {
return;
}
@@ -185,11 +187,11 @@ NAN_METHOD(bind_OCBindResourceTypeToResource) {
// annotation.
NAN_METHOD(bind_OCGetResourceHandler) {
VALIDATE_ARGUMENT_COUNT(info, 1);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
OCResourceHandle handle = 0;
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &handle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(), &handle)) {
return;
}
diff --git a/src/functions/oc-do-resource.cc b/src/functions/oc-do-resource.cc
index 9da6fa9..f85e9f7 100644
--- a/src/functions/oc-do-resource.cc
+++ b/src/functions/oc-do-resource.cc
@@ -33,7 +33,7 @@ using namespace node;
typedef struct CallbackInfo {
Nan::Callback *callback;
- Nan::Persistent<Array> *handle;
+ Nan::Persistent<Object> *handle;
} CallbackInfo;
static void deleteNanCallback(CallbackInfo *callback) {
@@ -43,7 +43,7 @@ static void deleteNanCallback(CallbackInfo *callback) {
if (callback->handle) {
// Mark the handle as stale
- Local<Array> handle = Nan::New(*(callback->handle));
+ Local<Object> handle = Nan::New(*(callback->handle));
Nan::Set(handle, Nan::New("stale").ToLocalChecked(), Nan::True());
delete callback->handle;
@@ -57,8 +57,9 @@ static void deleteNanCallback(CallbackInfo *callback) {
static OCStackApplicationResult defaultOCClientResponseHandler(
void *context, OCDoHandle handle, OCClientResponse *clientResponse) {
// Call the JS Callback
- Local<Value> jsCallbackArguments[2] = {js_OCDoHandle(handle),
- js_OCClientResponse(clientResponse)};
+ Local<Value> jsCallbackArguments[2] = {
+ Nan::New<Object>(*((CallbackInfo *)context)->handle),
+ js_OCClientResponse(clientResponse)};
Local<Value> returnValue =
(((CallbackInfo *)context)->callback)->Call(2, jsCallbackArguments);
@@ -155,9 +156,9 @@ NAN_METHOD(bind_OCDoResource) {
// the data on our behalf.
if (handle) {
- Local<Array> handleArray = js_OCDoHandle(handle);
+ Local<Object> handleArray = js_OCDoHandle(handle);
- callbackInfo->handle = new Nan::Persistent<Array>(handleArray);
+ callbackInfo->handle = new Nan::Persistent<Object>(handleArray);
info[0]->ToObject()->Set(Nan::New("handle").ToLocalChecked(), handleArray);
}
diff --git a/src/functions/oc-notify.cc b/src/functions/oc-notify.cc
index b0608cf..f4c2b08 100644
--- a/src/functions/oc-notify.cc
+++ b/src/functions/oc-notify.cc
@@ -31,11 +31,11 @@ using namespace node;
NAN_METHOD(bind_OCNotifyAllObservers) {
VALIDATE_ARGUMENT_COUNT(info, 2);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
VALIDATE_ARGUMENT_TYPE(info, 1, IsUint32);
OCResourceHandle handle;
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &handle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(), &handle)) {
return;
}
@@ -45,13 +45,13 @@ NAN_METHOD(bind_OCNotifyAllObservers) {
NAN_METHOD(bind_OCNotifyListOfObservers) {
VALIDATE_ARGUMENT_COUNT(info, 4);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
VALIDATE_ARGUMENT_TYPE(info, 1, IsArray);
VALIDATE_ARGUMENT_TYPE(info, 2, IsObject);
VALIDATE_ARGUMENT_TYPE(info, 3, IsUint32);
OCResourceHandle handle;
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &handle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(), &handle)) {
return;
}
diff --git a/src/functions/simple.cc b/src/functions/simple.cc
index f4d57b4..b096bad 100644
--- a/src/functions/simple.cc
+++ b/src/functions/simple.cc
@@ -90,14 +90,14 @@ NAN_METHOD(bind_OCSetPlatformInfo) {
NAN_METHOD(bind_OCGetNumberOfResourceInterfaces) {
VALIDATE_ARGUMENT_COUNT(info, 2);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
VALIDATE_ARGUMENT_TYPE(info, 1, IsObject);
OCResourceHandle handle = 0;
uint8_t interfaceCount = 0;
OCStackResult result;
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &handle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(), &handle)) {
return;
}
@@ -111,14 +111,14 @@ NAN_METHOD(bind_OCGetNumberOfResourceInterfaces) {
NAN_METHOD(bind_OCGetNumberOfResourceTypes) {
VALIDATE_ARGUMENT_COUNT(info, 2);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
VALIDATE_ARGUMENT_TYPE(info, 1, IsObject);
OCResourceHandle handle = 0;
uint8_t typeCount = 0;
OCStackResult result;
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &handle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(), &handle)) {
return;
}
@@ -160,13 +160,14 @@ NAN_METHOD(bind_OCGetResourceHandle) {
}
}
-#define RESOURCE_BY_INDEX_ACCESSOR_BOILERPLATE() \
- OCResourceHandle handle = 0; \
- VALIDATE_ARGUMENT_COUNT(info, 2); \
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray); \
- VALIDATE_ARGUMENT_TYPE(info, 1, IsUint32); \
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &handle)) { \
- return; \
+#define RESOURCE_BY_INDEX_ACCESSOR_BOILERPLATE() \
+ OCResourceHandle handle = 0; \
+ VALIDATE_ARGUMENT_COUNT(info, 2); \
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject); \
+ VALIDATE_ARGUMENT_TYPE(info, 1, IsUint32); \
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(), \
+ &handle)) { \
+ return; \
}
NAN_METHOD(bind_OCGetResourceHandleFromCollection) {
@@ -201,12 +202,13 @@ NAN_METHOD(bind_OCGetResourceTypeName) {
GET_STRING_FROM_RESOURCE_BY_INDEX_BOILERPLATE(OCGetResourceTypeName);
}
-#define LONE_ARGUMENT_IS_RESOURCE_HANDLE_BOILERPLATE() \
- VALIDATE_ARGUMENT_COUNT(info, 1); \
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray); \
- OCResourceHandle handle = 0; \
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &handle)) { \
- return; \
+#define LONE_ARGUMENT_IS_RESOURCE_HANDLE_BOILERPLATE() \
+ VALIDATE_ARGUMENT_COUNT(info, 1); \
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject); \
+ OCResourceHandle handle = 0; \
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(), \
+ &handle)) { \
+ return; \
}
NAN_METHOD(bind_OCGetResourceProperties) {
@@ -229,16 +231,18 @@ NAN_METHOD(bind_OCGetResourceUri) {
NAN_METHOD(bind_OCUnBindResource) {
VALIDATE_ARGUMENT_COUNT(info, 2);
- VALIDATE_ARGUMENT_TYPE(info, 0, IsArray);
- VALIDATE_ARGUMENT_TYPE(info, 1, IsArray);
+ VALIDATE_ARGUMENT_TYPE(info, 0, IsObject);
+ VALIDATE_ARGUMENT_TYPE(info, 1, IsObject);
OCResourceHandle collectionHandle = 0, resourceHandle = 0;
- if (!c_OCResourceHandle(Local<Array>::Cast(info[0]), &collectionHandle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[0]).ToLocalChecked(),
+ &collectionHandle)) {
return;
}
- if (!c_OCResourceHandle(Local<Array>::Cast(info[1]), &resourceHandle)) {
+ if (!c_OCResourceHandle(Nan::To<Object>(info[1]).ToLocalChecked(),
+ &resourceHandle)) {
return;
}
diff --git a/src/structures.cc b/src/structures.cc
index 9d83eb2..1ebb196 100644
--- a/src/structures.cc
+++ b/src/structures.cc
@@ -33,8 +33,12 @@ using namespace node;
Local<Object> js_OCEntityHandlerRequest(OCEntityHandlerRequest *request) {
Local<Object> jsRequest = Nan::New<Object>();
- Nan::Set(jsRequest, Nan::New("resource").ToLocalChecked(),
- js_OCResourceHandle(request->resource));
+ // The resource may be null if the request refers to a non-existing resource
+ // and is being passed to the default device entity handler
+ if (request->resource) {
+ Nan::Set(jsRequest, Nan::New("resource").ToLocalChecked(),
+ js_OCResourceHandle(request->resource));
+ }
Nan::Set(jsRequest, Nan::New("requestHandle").ToLocalChecked(),
js_OCRequestHandle(request->requestHandle));
diff --git a/src/structures/handles.cc b/src/structures/handles.cc
index 81b19d9..ff0921b 100644
--- a/src/structures/handles.cc
+++ b/src/structures/handles.cc
@@ -20,6 +20,49 @@
using namespace v8;
+template <class T>
+class JSHandle {
+ static Nan::Persistent<FunctionTemplate> &theTemplate() {
+ static Nan::Persistent<FunctionTemplate> returnValue;
+
+ if (returnValue.IsEmpty()) {
+ Local<FunctionTemplate> theTemplate = Nan::New<FunctionTemplate>();
+ theTemplate->SetClassName(Nan::New(T::jsClassName()).ToLocalChecked());
+ theTemplate->InstanceTemplate()->SetInternalFieldCount(1);
+ Nan::Set(Nan::GetFunction(theTemplate).ToLocalChecked(),
+ Nan::New("displayName").ToLocalChecked(),
+ Nan::New(T::jsClassName()).ToLocalChecked());
+ returnValue.Reset(theTemplate);
+ }
+ return returnValue;
+ }
+
+ public:
+ static Local<Object> New(void *data) {
+ Local<Object> returnValue = Nan::GetFunction(Nan::New(theTemplate()))
+ .ToLocalChecked()
+ ->NewInstance();
+ Nan::SetInternalFieldPointer(returnValue, 0, data);
+
+ return returnValue;
+ }
+
+ // If the object is not of the expected type, or if the pointer inside the
+ // object has already been removed, then we must throw an error
+ static void *Resolve(Local<Object> jsObject) {
+ void *returnValue = 0;
+
+ if (Nan::New(theTemplate())->HasInstance(jsObject)) {
+ returnValue = Nan::GetInternalFieldPointer(jsObject, 0);
+ }
+ if (!returnValue) {
+ Nan::ThrowTypeError(
+ (std::string("Object is not of type ") + T::jsClassName()).c_str());
+ }
+ return returnValue;
+ }
+};
+
Local<Array> jsArrayFromBytes(unsigned char *bytes, size_t length) {
size_t index;
Local<Array> returnValue = Nan::New<Array>(length);
@@ -49,36 +92,57 @@ bool fillCArrayFromJSArray(unsigned char *bytes, size_t length,
return true;
}
-Local<Array> js_OCResourceHandle(OCResourceHandle handle) {
- return jsArrayFromBytes(((unsigned char *)(&handle)),
- sizeof(OCResourceHandle));
-}
+class JSOCResourceHandle : public JSHandle<JSOCResourceHandle> {
+ public:
+ static const char *jsClassName() { return "OCResourceHandle"; }
+};
-#define C_HANDLE(jsHandle, cType, destination) \
- cType local; \
- if (!fillCArrayFromJSArray(((unsigned char *)&local), sizeof(cType), \
- jsHandle)) { \
- return false; \
- } \
- *destination = local; \
- return true;
+class JSOCRequestHandle : public JSHandle<JSOCRequestHandle> {
+ public:
+ static const char *jsClassName() { return "OCRequestHandle"; }
+};
+
+class JSOCDoHandle : public JSHandle<JSOCDoHandle> {
+ public:
+ static const char *jsClassName() { return "OCDoHandle"; }
+};
-bool c_OCResourceHandle(Local<Array> handle, OCResourceHandle *p_cHandle) {
- C_HANDLE(handle, OCResourceHandle, p_cHandle);
+bool c_OCResourceHandle(Local<Object> handle, OCResourceHandle *p_cHandle) {
+ OCResourceHandle local =
+ (OCResourceHandle)JSOCResourceHandle::Resolve(handle);
+ if (local) {
+ *p_cHandle = local;
+ return true;
+ }
+ return false;
}
-bool c_OCRequestHandle(Local<Array> handle, OCRequestHandle *p_cHandle) {
- C_HANDLE(handle, OCRequestHandle, p_cHandle);
+bool c_OCRequestHandle(Local<Object> handle, OCRequestHandle *p_cHandle) {
+ OCRequestHandle local = (OCRequestHandle)JSOCRequestHandle::Resolve(handle);
+ if (local) {
+ *p_cHandle = local;
+ return true;
+ }
+ return false;
}
-bool c_OCDoHandle(Local<Array> handle, OCDoHandle *p_cHandle) {
- C_HANDLE(handle, OCDoHandle, p_cHandle);
+bool c_OCDoHandle(Local<Object> handle, OCDoHandle *p_cHandle) {
+ OCDoHandle local = (OCDoHandle)JSOCDoHandle::Resolve(handle);
+ if (local) {
+ *p_cHandle = local;
+ return true;
+ }
+ return false;
+}
+
+Local<Object> js_OCResourceHandle(OCResourceHandle handle) {
+ return JSOCResourceHandle::New(handle);
}
-Local<Array> js_OCRequestHandle(OCRequestHandle handle) {
- return jsArrayFromBytes(((unsigned char *)(&handle)),
- sizeof(OCRequestHandle));
+
+Local<Object> js_OCRequestHandle(OCRequestHandle handle) {
+ return JSOCRequestHandle::New(handle);
}
-Local<Array> js_OCDoHandle(OCDoHandle handle) {
- return jsArrayFromBytes(((unsigned char *)(&handle)), sizeof(OCDoHandle));
+Local<Object> js_OCDoHandle(OCDoHandle handle) {
+ return JSOCDoHandle::New(handle);
}
diff --git a/src/structures/handles.h b/src/structures/handles.h
index 3907be4..f581f54 100644
--- a/src/structures/handles.h
+++ b/src/structures/handles.h
@@ -22,15 +22,16 @@ extern "C" {
#include <ocstack.h>
}
-v8::Local<v8::Array> js_OCResourceHandle(OCResourceHandle handle);
-bool c_OCResourceHandle(v8::Local<v8::Array> handle,
+v8::Local<v8::Object> js_OCResourceHandle(OCResourceHandle handle);
+bool c_OCResourceHandle(v8::Local<v8::Object> handle,
OCResourceHandle *p_cHandle);
-v8::Local<v8::Array> js_OCRequestHandle(OCRequestHandle handle);
-bool c_OCRequestHandle(v8::Local<v8::Array> handle, OCRequestHandle *p_cHandle);
+v8::Local<v8::Object> js_OCRequestHandle(OCRequestHandle handle);
+bool c_OCRequestHandle(v8::Local<v8::Object> handle,
+ OCRequestHandle *p_cHandle);
-v8::Local<v8::Array> js_OCDoHandle(OCDoHandle handle);
-bool c_OCDoHandle(v8::Local<v8::Array> handle, OCDoHandle *p_cHandle);
+v8::Local<v8::Object> js_OCDoHandle(OCDoHandle handle);
+bool c_OCDoHandle(v8::Local<v8::Object> handle, OCDoHandle *p_cHandle);
v8::Local<v8::Array> jsArrayFromBytes(unsigned char *bytes, size_t length);
diff --git a/src/structures/oc-device-info.cc b/src/structures/oc-device-info.cc
index 222b5aa..4b06a33 100644
--- a/src/structures/oc-device-info.cc
+++ b/src/structures/oc-device-info.cc
@@ -29,16 +29,16 @@ v8::Local<v8::Object> js_OCDeviceInfo(OCDeviceInfo *info) {
Local<Object> returnValue = Nan::New<Object>();
SET_STRING_IF_NOT_NULL(returnValue, info, deviceName);
+ SET_STRING_IF_NOT_NULL(returnValue, info, specVersion);
ADD_STRING_ARRAY(returnValue, info, types);
+ ADD_STRING_ARRAY(returnValue, info, dataModelVersions);
return returnValue;
}
-void c_OCDeviceInfoFreeMembers(OCDeviceInfo *info) {
+void c_freeLinkedList(OCStringLL *list) {
OCStringLL *item, *nextItem;
-
- free(info->deviceName);
- for (item = info->types; item;) {
+ for (item = list; item;) {
nextItem = item->next;
free(item->value);
free(item);
@@ -46,42 +46,71 @@ void c_OCDeviceInfoFreeMembers(OCDeviceInfo *info) {
}
}
+void c_OCDeviceInfoFreeMembers(OCDeviceInfo *info) {
+ free(info->deviceName);
+ free(info->specVersion);
+ c_freeLinkedList(info->types);
+ c_freeLinkedList(info->dataModelVersions);
+}
+
+bool c_StringArrayFromProperty(Local<Object> source, const char *propertyName,
+ OCStringLL **destination) {
+ Local<Value> sourceValue =
+ Nan::Get(source, Nan::New(propertyName).ToLocalChecked())
+ .ToLocalChecked();
+ VALIDATE_VALUE_TYPE(sourceValue, IsArray,
+ (std::string("device info ") + propertyName).c_str(),
+ false);
+ Local<Array> jsArray = Local<Array>::Cast(sourceValue);
+
+ size_t index, length = jsArray->Length();
+ OCStringLL *local = 0, **previous = &local;
+
+ for (index = 0; index < length; index++, previous = &((*previous)->next)) {
+ Local<Value> itemValue = Nan::Get(jsArray, index).ToLocalChecked();
+ VALIDATE_VALUE_TYPE_OR_FREE(
+ itemValue, IsString,
+ (std::string("device info ") + propertyName + " list item").c_str(),
+ false, local, c_freeLinkedList);
+
+ (*previous) = new OCStringLL;
+ if (!(*previous)) {
+ goto freeAndQuit;
+ }
+ (*previous)->next = 0;
+ (*previous)->value = strdup((const char *)*(String::Utf8Value(itemValue)));
+ if (!(*previous)->value) {
+ goto freeAndQuit;
+ }
+ }
+
+ *destination = local;
+ return true;
+freeAndQuit:
+ c_freeLinkedList(local);
+ return false;
+}
+
bool c_OCDeviceInfo(Local<Object> deviceInfo, OCDeviceInfo *info) {
- OCDeviceInfo local = {0, 0};
- OCStringLL *newType = 0;
+ OCDeviceInfo local = {
+ .deviceName = 0, .types = 0, .specVersion = 0, .dataModelVersions = 0};
VALIDATE_AND_ASSIGN_STRING(&local, deviceName, deviceInfo,
c_OCDeviceInfoFreeMembers, false);
- // Make sure the "types" property is an array
- Local<Value> typesValue =
- Nan::Get(deviceInfo, Nan::New("types").ToLocalChecked()).ToLocalChecked();
- VALIDATE_VALUE_TYPE_OR_FREE(typesValue, IsArray, "device info types list",
- false, &local, c_OCDeviceInfoFreeMembers);
- Local<Array> jsTypes = Local<Array>::Cast(typesValue);
- size_t index, length = jsTypes->Length();
-
- for (index = 0; index < length; index++) {
- // Make sure an individual type is a string
- Local<Value> itemValue = Nan::Get(jsTypes, index).ToLocalChecked();
- VALIDATE_VALUE_TYPE_OR_FREE(itemValue, IsString,
- "device info types list item", false, &local,
- c_OCDeviceInfoFreeMembers);
-
- // Copy the string to the C linked list
- newType = new OCStringLL;
- if (newType) {
- newType->next = local.types;
- local.types = newType;
- newType->value = strdup((const char *)*(String::Utf8Value(itemValue)));
- if (newType->value) {
- // If copying succeeds we move on to the next type in the list
- continue;
- }
- }
+ VALIDATE_AND_ASSIGN_STRING(&local, specVersion, deviceInfo,
+ c_OCDeviceInfoFreeMembers, false);
+
+ // Make sure the "types" property is an array and copy it to the C structure
+ if (!c_StringArrayFromProperty(deviceInfo, "types", &(local.types))) {
+ c_OCDeviceInfoFreeMembers(&local);
+ return false;
+ }
- // If copying fails we bail
- Nan::ThrowError("Failed to allocate device info types list item");
+ // Make sure the "dataModelVersion" property is an array and copy it to the C
+ // structure
+ if (!c_StringArrayFromProperty(deviceInfo, "dataModelVersions",
+ &(local.dataModelVersions))) {
c_OCDeviceInfoFreeMembers(&local);
return false;
}
diff --git a/src/structures/oc-entity-handler-response.cc b/src/structures/oc-entity-handler-response.cc
index 6b10a24..26fcf56 100644
--- a/src/structures/oc-entity-handler-response.cc
+++ b/src/structures/oc-entity-handler-response.cc
@@ -38,22 +38,25 @@ bool c_OCEntityHandlerResponse(Local<Object> jsResponse,
Local<Value> requestHandle =
Nan::Get(jsResponse, Nan::New("requestHandle").ToLocalChecked())
.ToLocalChecked();
- VALIDATE_VALUE_TYPE(requestHandle, IsArray,
+ VALIDATE_VALUE_TYPE(requestHandle, IsObject,
"entitiy handler response request handle", false);
- if (!c_OCRequestHandle(Local<Array>::Cast(requestHandle),
+ if (!c_OCRequestHandle(Nan::To<Object>(requestHandle).ToLocalChecked(),
&(response.requestHandle))) {
return false;
}
// resourceHandle
+ response.resourceHandle = 0;
Local<Value> resourceHandle =
Nan::Get(jsResponse, Nan::New("resourceHandle").ToLocalChecked())
.ToLocalChecked();
- VALIDATE_VALUE_TYPE(requestHandle, IsArray,
- "entitiy handler response resource handle", false);
- if (!c_OCRequestHandle(Local<Array>::Cast(resourceHandle),
- &(response.resourceHandle))) {
- return false;
+ if (!(resourceHandle->IsUndefined() || resourceHandle->IsNull())) {
+ VALIDATE_VALUE_TYPE(resourceHandle, IsObject,
+ "entitiy handler response resource handle", false);
+ if (!c_OCResourceHandle(Nan::To<Object>(resourceHandle).ToLocalChecked(),
+ &(response.resourceHandle))) {
+ return false;
+ }
}
// ehResult
diff --git a/src/structures/oc-payload.cc b/src/structures/oc-payload.cc
index f587ebb..688a935 100644
--- a/src/structures/oc-payload.cc
+++ b/src/structures/oc-payload.cc
@@ -284,9 +284,6 @@ static Local<Object> js_OCDiscoveryPayload(OCDiscoveryPayload *payload) {
static Local<Object> js_OCDevicePayload(OCDevicePayload *payload) {
Local<Object> returnValue = Nan::New<Object>();
- Nan::Set(returnValue, Nan::New("type").ToLocalChecked(),
- Nan::New(payload->base.type));
-
if (payload->sid) {
Nan::Set(returnValue, Nan::New("sid").ToLocalChecked(),
js_SID(payload->sid));
@@ -294,7 +291,10 @@ static Local<Object> js_OCDevicePayload(OCDevicePayload *payload) {
SET_STRING_IF_NOT_NULL(returnValue, payload, deviceName);
SET_STRING_IF_NOT_NULL(returnValue, payload, specVersion);
- SET_STRING_IF_NOT_NULL(returnValue, payload, dataModelVersion);
+
+ ADD_STRING_ARRAY(returnValue, payload, dataModelVersions);
+ ADD_STRING_ARRAY(returnValue, payload, interfaces);
+ ADD_STRING_ARRAY(returnValue, payload, types);
return returnValue;
}
diff --git a/tests/assert-to-console.js b/tests/assert-to-console.js
index f46cb35..6452e7e 100644
--- a/tests/assert-to-console.js
+++ b/tests/assert-to-console.js
@@ -57,9 +57,13 @@ module.exports = {
this.assert( "ok", properties[ index ].name in object,
objectName + " has " + properties[ index ].name );
if ( properties[ index ].type ) {
- this.assert( "strictEqual", typeof object[ properties[ index ].name ],
+ this.assert( "strictEqual",
+ properties[ index ].type === "array" ?
+ ( Array.isArray( object[ properties[ index ].name ] ) ?
+ "array" : "non-array" ) :
+ typeof object[ properties[ index ].name ],
properties[ index ].type,
- objectName + "." + properties[ index ].name + " is a " +
+ objectName + "." + properties[ index ].name + " is of type " +
properties[ index ].type );
}
diff --git a/tests/tests/API Complex Payload/server.js b/tests/tests/API Complex Payload/server.js
index 325bf23..8753965 100644
--- a/tests/tests/API Complex Payload/server.js
+++ b/tests/tests/API Complex Payload/server.js
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-var requestPromise, resource,
+var requestPromise,
_ = require( "lodash" ),
async = require( "async" ),
uuid = process.argv[ 2 ],
@@ -71,7 +71,6 @@ async.series( [
} ) ).then( cleanup, cleanup );
} );
- resource = theResource;
device.addEventListener( "retrieverequest", handler );
requestPromise = handler.promise;
diff --git a/tests/tests/API Device Information/client.js b/tests/tests/API Device Information/client.js
index 4a91dbb..3a21425 100644
--- a/tests/tests/API Device Information/client.js
+++ b/tests/tests/API Device Information/client.js
@@ -21,7 +21,9 @@ var expectedDeviceInfo = {
// The uuid field will be set to the deviceId when we know the deviceId
name: "API Device Info Server " + uuid,
- coreSpecVersion: "core.1.0.0"
+ coreSpecVersion: "test.0.0.1",
+ role: "server",
+ dataModels: [ "blah.1.1.1" ]
};
var expectedPlatformInfo = {
id: "platform " + uuid,
@@ -61,10 +63,14 @@ new Promise( function findTheDeviceId( fulfill, reject ) {
{ name: "uuid", type: "string" },
{ name: "url", type: "string" },
{ name: "name", type: "string" },
- { name: "dataModels", type: "string" },
+ { name: "dataModels", type: "array" },
{ name: "coreSpecVersion", type: "string" },
{ name: "role", type: "string" }
] );
+
+ // deviceInfo.url contains the host/port of the server, which changes from instance to
+ // instance, so we can't really asser it. Thus, we must remove it from the expectation
+ delete deviceInfo.url;
utils.assert( "deepEqual", deviceInfo, expectedDeviceInfo,
"Client: The retrieved device information is as expected" );
return deviceId;
@@ -107,6 +113,10 @@ new Promise( function findTheDeviceId( fulfill, reject ) {
oic.addEventListener( "devicefound", devicefound );
oic.findDevices().catch( teardown );
} ).then( function assertDiscoveredDeviceInfo( deviceInfo ) {
+
+ // deviceInfo.url contains the host/port of the server, which changes from instance to
+ // instance, so we can't really asser it. Thus, we must remove it from the expectation
+ delete deviceInfo.url;
utils.assert( "deepEqual", deviceInfo, expectedDeviceInfo,
"Client: The discovered device information is as expected" );
} );
diff --git a/tests/tests/Complex Payload/server.js b/tests/tests/Complex Payload/server.js
index ad89234..6444ac8 100644
--- a/tests/tests/Complex Payload/server.js
+++ b/tests/tests/Complex Payload/server.js
@@ -31,10 +31,10 @@ function cleanup() {
testUtils.assert( "ok", true, "Server: OCProcess succeeded " + processCallCount + " times" );
cleanupResult = iotivity.OCDeleteResource( resourceHandleReceptacle.handle );
- testUtils.stackOKOrDie( "Server", "OCDeleteResource", result );
+ testUtils.stackOKOrDie( "Server", "OCDeleteResource", cleanupResult );
cleanupResult = iotivity.OCStop();
- if ( testUtils.stackOKOrDie( "Server", "OCStop", result ) ) {
+ if ( testUtils.stackOKOrDie( "Server", "OCStop", cleanupResult ) ) {
console.log( JSON.stringify( { killPeer: true } ) );
process.exit( 0 );
}
diff --git a/tests/tests/Device Entity Handler/server.js b/tests/tests/Device Entity Handler/server.js
index bd1a99b..439f3f4 100644
--- a/tests/tests/Device Entity Handler/server.js
+++ b/tests/tests/Device Entity Handler/server.js
@@ -112,10 +112,10 @@ function cleanup() {
testUtils.assert( "ok", true, "Server: OCProcess succeeded " + processCallCount + " times" );
cleanupResult = iotivity.OCDeleteResource( resourceHandleReceptacle.handle );
- testUtils.stackOKOrDie( "Server", "OCDeleteResource", result );
+ testUtils.stackOKOrDie( "Server", "OCDeleteResource", cleanupResult );
cleanupResult = iotivity.OCStop();
- if ( testUtils.stackOKOrDie( "Server", "OCStop", result ) ) {
+ if ( testUtils.stackOKOrDie( "Server", "OCStop", cleanupResult ) ) {
process.exit( 0 );
}
}
diff --git a/tests/tests/Discovery/server.js b/tests/tests/Discovery/server.js
index 941299f..f11eb6a 100644
--- a/tests/tests/Discovery/server.js
+++ b/tests/tests/Discovery/server.js
@@ -31,10 +31,10 @@ function cleanup() {
testUtils.assert( "ok", true, "Server: OCProcess succeeded " + processCallCount + " times" );
cleanupResult = iotivity.OCDeleteResource( resourceHandleReceptacle.handle );
- testUtils.stackOKOrDie( "Server", "OCDeleteResource", result );
+ testUtils.stackOKOrDie( "Server", "OCDeleteResource", cleanupResult );
cleanupResult = iotivity.OCStop();
- if ( testUtils.stackOKOrDie( "Server", "OCStop", result ) ) {
+ if ( testUtils.stackOKOrDie( "Server", "OCStop", cleanupResult ) ) {
process.exit( 0 );
}
}
diff --git a/tests/tests/Get Request/server.js b/tests/tests/Get Request/server.js
index c5980ee..8aca958 100644
--- a/tests/tests/Get Request/server.js
+++ b/tests/tests/Get Request/server.js
@@ -104,10 +104,10 @@ function cleanup() {
testUtils.assert( "ok", true, "Server: OCProcess succeeded " + processCallCount + " times" );
cleanupResult = iotivity.OCDeleteResource( resourceHandleReceptacle.handle );
- testUtils.stackOKOrDie( "Server", "OCDeleteResource", result );
+ testUtils.stackOKOrDie( "Server", "OCDeleteResource", cleanupResult );
cleanupResult = iotivity.OCStop();
- if ( testUtils.stackOKOrDie( "Server", "OCStop", result ) ) {
+ if ( testUtils.stackOKOrDie( "Server", "OCStop", cleanupResult ) ) {
process.exit( 0 );
}
}
diff --git a/tests/tests/Multiple Observers/server.js b/tests/tests/Multiple Observers/server.js
index 5371d93..480cb7d 100644
--- a/tests/tests/Multiple Observers/server.js
+++ b/tests/tests/Multiple Observers/server.js
@@ -44,10 +44,10 @@ function cleanup() {
"Server: OCNotifyListOfObservers succeeded " + notificationCount + " times" );
cleanupResult = iotivity.OCDeleteResource( resourceHandleReceptacle.handle );
- testUtils.stackOKOrDie( "Server", "OCDeleteResource", result );
+ testUtils.stackOKOrDie( "Server", "OCDeleteResource", cleanupResult );
cleanupResult = iotivity.OCStop();
- if ( testUtils.stackOKOrDie( "Server", "OCStop", result ) ) {
+ if ( testUtils.stackOKOrDie( "Server", "OCStop", cleanupResult ) ) {
console.log( JSON.stringify( { killPeer: true } ) );
process.exit( 0 );
}
diff --git a/tests/tests/Observation/server.js b/tests/tests/Observation/server.js
index 97a9b81..ea28551 100644
--- a/tests/tests/Observation/server.js
+++ b/tests/tests/Observation/server.js
@@ -41,10 +41,10 @@ function cleanup() {
"Server: OCNotifyAllObservers succeeded " + notificationCount + " times" );
cleanupResult = iotivity.OCDeleteResource( resourceHandleReceptacle.handle );
- testUtils.stackOKOrDie( "Server", "OCDeleteResource", result );
+ testUtils.stackOKOrDie( "Server", "OCDeleteResource", cleanupResult );
cleanupResult = iotivity.OCStop();
- if ( testUtils.stackOKOrDie( "Server", "OCStop", result ) ) {
+ if ( testUtils.stackOKOrDie( "Server", "OCStop", cleanupResult ) ) {
console.log( JSON.stringify( { killPeer: true } ) );
process.exit( 0 );
}
diff --git a/tests/tests/Presence/server.js b/tests/tests/Presence/server.js
index a935756..a8abcd7 100644
--- a/tests/tests/Presence/server.js
+++ b/tests/tests/Presence/server.js
@@ -120,10 +120,10 @@ function cleanup() {
testUtils.assert( "ok", true, "Server: OCProcess succeeded " + processCallCount + " times" );
cleanupResult = iotivity.OCDeleteResource( resourceHandleReceptacle.handle );
- testUtils.stackOKOrDie( "Server", "OCDeleteResource", result );
+ testUtils.stackOKOrDie( "Server", "OCDeleteResource", cleanupResult );
cleanupResult = iotivity.OCStop();
- if ( testUtils.stackOKOrDie( "Server", "OCStop", result ) ) {
+ if ( testUtils.stackOKOrDie( "Server", "OCStop", cleanupResult ) ) {
process.exit( 0 );
}
}
diff --git a/tests/tests/Resource Operations.js b/tests/tests/Resource Operations.js
index 34d5ea5..ecdfa9c 100644
--- a/tests/tests/Resource Operations.js
+++ b/tests/tests/Resource Operations.js
@@ -33,7 +33,12 @@ result = iotivity.OCInit( null, 0, iotivity.OCMode.OC_SERVER );
testUtils.stackOKOrDie( "OCInit", result );
// Set device info
-result = iotivity.OCSetDeviceInfo( { deviceName: "resource-operations-" + uuid, types: [] } );
+result = iotivity.OCSetDeviceInfo( {
+ deviceName: "resource-operations-" + uuid,
+ specVersion: "blah.1.1.1",
+ dataModelVersions: [ "test.1.1.1" ],
+ types: []
+} );
testUtils.stackOKOrDie( "OCSetDeviceInfo", result );
// Set platform info
diff --git a/tests/utils.js b/tests/utils.js
index f5c960b..c8ae586 100644
--- a/tests/utils.js
+++ b/tests/utils.js
@@ -72,8 +72,7 @@ _.extend( TestUtils.prototype, require( "./assert-to-console" ), {
}
},
findResource: function( response, uuid ) {
- var index,
- resources,
+ var index, resources,
returnValue = false;
if ( response &&