Download this file

log.js    117 lines (98 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var fs = require("fs");
let moduleConfiguration = JSON.parse(fs.readFileSync('moduleConfiguration.json', 'utf8'));
// code for connecting to pubsub
let vfosMessagingPubsub = require("../pubsub/index.js");
// this parameters are read from some external json
let broker = moduleConfiguration.broker;
let userName = moduleConfiguration.userName;
let platformDomain = moduleConfiguration.platformDomain;
let routingKeys = moduleConfiguration.routingKeys;
let pubsub = moduleConfiguration.activation;
let communications;
if (pubsub){
communications = new vfosMessagingPubsub(broker, userName, platformDomain, routingKeys);
}
module.exports = function (log) {
/**
* Log listing (Subscribe)
* @param {subscriptionData} subscriptionData device object to subscribe the platform to the log
* @callback {Function} callback Callback function
* @param {Error|string} err Error object
* @param {referenceResult} result Result object
*/
log.subscribe = function (subscriptionData, callback) {
let prefixMessagingPrivateDestination1 = platformDomain;
let componentMessagingPrivateDestination1 = "platform";
callback(null, "{msg: \"registered logger on platform with" + platformDomain + ":" + componentMessagingPrivateDestination1 + "\"}");
// communications.sendPrivateMessage(prefixMessagingPrivateDestination1, componentMessagingPrivateDestination1, privateMessage1);
}
/**
* Log UnSubscribe
* @param {string} reference reference to unsubscribe a component as listener of logs
* @callback {Function} callback Callback function
* @param {Error|string} err Error object
* @param {any} result Result object
*/
log.unsubscribe = function (reference, callback) {
// Replace the code below with your implementation.
// Please make sure the callback is invoked.
process.nextTick(function () {
var err = new Error('Not implemented');
callback(err);
});
/*
var err0 = new Error('Invalid ID supplied');
err0.statusCode = 400;
return cb(err0);
*/
/*
var err1 = new Error('device not found');
err1.statusCode = 404;
return cb(err1);
*/
}
log.remoteMethod('subscribe', {
isStatic: true,
consumes: ['application/json'],
produces: ['application/json'],
accepts: [{
arg: 'subscriptionData',
type: 'subscriptionData',
description: 'device object to subscribe the platform to the log',
required: true,
http: {
source: 'body'
}
}],
returns: [{
description: 'id of the device created',
type: 'referenceResult',
arg: 'data',
root: true
}],
http: {
verb: 'post',
path: '/logs'
},
description: 'Log listing (Subscribe)'
});
log.remoteMethod('unsubscribe', {
isStatic: true,
produces: ['application/json'],
accepts: [{
arg: 'reference',
type: 'string',
description: 'reference to unsubscribe a component as listener of logs',
required: true,
http: {
source: 'path'
}
}],
returns: [],
http: {
verb: 'delete',
path: '/logs/:reference'
},
description: 'Log UnSubscribe'
});
}