Skip to content

Commit

Permalink
ADD Device registry context
Browse files Browse the repository at this point in the history
  • Loading branch information
janantala committed May 11, 2015
1 parent f7126bd commit 1ed12ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/lwm2m-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function start(config, startCallback) {

async.waterfall([
apply(validateTypes, config),
apply(registry.init, config, context, logger),
apply(registry.init, config),
apply(coapRouter.start, config),
loadDefaults
], function (error, results) {
Expand Down
17 changes: 9 additions & 8 deletions lib/services/server/inMemoryDeviceRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ var registry = {},
idCounter = 1,
errors = require('../../errors'),
_ = require('underscore'),
context,
logger,
logger = require('logops'),
context = {
op: 'LWM2MLib.MemoryDeviceRegistry'
},
checkLifetimeInterval;

/**
Expand Down Expand Up @@ -195,13 +197,12 @@ function stopLifetimeCheck() {
* Initializes the device registry based on the parameter found in the configuration. For this in memory registry this
* function doesn't do anything.
*
* @param {Object} newConfig Configuration object.
* @param {Object} newContext Context object.
* @param {Object} newLogger Logger object.
* @param {Object} config Configuration object.
*/
function init(newConfig, newContext, newLogger, callback) {
context = newContext;
logger = newLogger;
function init(config, callback) {
if (config.logLevel) {
logger.setLevel(config.logLevel);
}
callback(null);
}

Expand Down
19 changes: 10 additions & 9 deletions lib/services/server/mongodbDeviceRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
var errors = require('../../errors'),
dbService = require('../model/dbConn'),
Device = require('../model/Device'),
context,
logger,
logger = require('logops'),
context = {
op: 'LWM2MLib.MomgodbDeviceRegistry'
},
checkLifetimeInterval;

/**
Expand Down Expand Up @@ -244,14 +246,13 @@ function stopLifetimeCheck() {
* The configuration object to use should be the one corresponding to the general server configuration, although all
* the Mongo specific information should be stored under the 'deviceRegistry' section.
*
* @param {Object} newConfig Configuration object containing a deviceRegistry attribute with the info.
* @param {Object} newContext Context object.
* @param {Object} newLogger Logger object.
* @param {Object} config Configuration object containing a deviceRegistry attribute with the info.
*/
function init(newConfig, newContext, newLogger, callback) {
context = newContext;
logger = newLogger;
dbService.init(newConfig.deviceRegistry.host, newConfig.deviceRegistry.db, callback);
function init(config, callback) {
if (config.logLevel) {
logger.setLevel(config.logLevel);
}
dbService.init(config.deviceRegistry.host, config.deviceRegistry.db, callback);
}

exports.register = register;
Expand Down

0 comments on commit 1ed12ef

Please sign in to comment.