diff --git a/dist/main.js b/dist/main.js index b8e1f2a..b64e72a 100644 --- a/dist/main.js +++ b/dist/main.js @@ -2,28 +2,22 @@ Object.defineProperty(exports, "__esModule", { value: true }); const log = require("./log"); const mqtt = require("./mqttdispatcher"); -class Dispatcher { - constructor() { - this._mqttDispatcher = new mqtt.MqttDispatcher(); - this._mqttDispatcher.register('IoT/test', 'print1', (message) => { - log.info("Callback for IoT/test"); - log.info(`message is ${message}`); - return `<<${message}>>`; - }); - this._mqttDispatcher.register('IoT/test', 'print2', (message) => { - log.info("Callback for IoT/test"); - log.info(`message is ${message}`); - return `<<${message}>>`; - }); - this._mqttDispatcher.register('IoT/test', 'null1', mqtt.passThrough); - this._mqttDispatcher.register('IoT/test', 'null2', mqtt.passThrough); - } - exec() { - log.info("Dispatcher starting"); - this._mqttDispatcher.exec(); - log.info("Dispatcher running"); - } -} -const dispatcher = new Dispatcher(); -dispatcher.exec(); +const plugintest1 = require("./plugintest1"); +log.info("Dispatcher starting"); +exports.dispatcher = new mqtt.MqttDispatcher(); +exports.dispatcher.register('IoT/test', 'print1', (message) => { + log.info("Callback for IoT/test"); + log.info(`message is ${message}`); + return `<<${message}>>`; +}); +exports.dispatcher.register('IoT/test', 'print2', (message) => { + log.info("Callback for IoT/test"); + log.info(`message is ${message}`); + return `<<${message}>>`; +}); +exports.dispatcher.register('IoT/test', 'null1', mqtt.passThrough); +exports.dispatcher.register('IoT/test', 'null2', mqtt.passThrough); +plugintest1.pluginTest1Start(exports.dispatcher); +exports.dispatcher.exec(); +log.info("Dispatcher running"); //# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/dist/plugintest1.js b/dist/plugintest1.js new file mode 100644 index 0000000..79a335a --- /dev/null +++ b/dist/plugintest1.js @@ -0,0 +1,15 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const log = require("./log"); +const processor = require("./processor"); +var exRoute = new processor.ExProc1('label1'); +function pluginTest1Start(dispatcher) { + log.info("starting plugintest1"); + dispatcher.register('IoT/test', "plugintest1", (message) => { + log.info(`plugintest1 runs: ${message}`); + exRoute.in(message); + return message; + }); +} +exports.pluginTest1Start = pluginTest1Start; +//# sourceMappingURL=plugintest1.js.map \ No newline at end of file diff --git a/dist/processor.js b/dist/processor.js new file mode 100644 index 0000000..47ed41c --- /dev/null +++ b/dist/processor.js @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const log = require("./log"); +const events = require("events"); +class AProcessor extends events.EventEmitter { + constructor(label) { + super(); + this._label = label; + this.addListener('input', this.process); + log.info(`Processor object instanciated: ${this.constructor.name}, ${this._label}`); + } + in(message) { + log.info(`Routing ${message} to Processor class ${this.constructor.name}, ${this._label}`); + this.emit('input', message); + } +} +exports.AProcessor = AProcessor; +class ExProc1 extends AProcessor { + process(message) { + log.info(`ExRoute1.process: ${this._label}, ${message}`); + } +} +exports.ExProc1 = ExProc1; +//# sourceMappingURL=processor.js.map \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 08251dd..03082a5 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,41 +1,28 @@ import * as log from './log' import * as mqtt from './mqttdispatcher' import * as callchain from './callchain' +import * as plugintest1 from './plugintest1' -class Dispatcher { - private _mqttDispatcher: mqtt.MqttDispatcher +log.info("Dispatcher starting") +export const dispatcher = new mqtt.MqttDispatcher() +dispatcher.register('IoT/test', 'print1', (message: any) : any => { + log.info("Callback for IoT/test") + log.info(`message is ${message}`) + return `<<${message}>>` +}) +dispatcher.register('IoT/test', 'print2', (message: any) : any => { + log.info("Callback for IoT/test") + log.info(`message is ${message}`) + return `<<${message}>>` +}) +dispatcher.register('IoT/test', 'null1', mqtt.passThrough) +dispatcher.register('IoT/test', 'null2', mqtt.passThrough) - constructor() { - this._mqttDispatcher = new mqtt.MqttDispatcher() +plugintest1.pluginTest1Start(dispatcher) - this._mqttDispatcher.register('IoT/test', 'print1', (message: any) : any => { - log.info("Callback for IoT/test") - log.info(`message is ${message}`) - return `<<${message}>>` - }) - this._mqttDispatcher.register('IoT/test', 'print2', (message: any) : any => { - log.info("Callback for IoT/test") - log.info(`message is ${message}`) - return `<<${message}>>` - }) - this._mqttDispatcher.register('IoT/test', 'null1', mqtt.passThrough) - this._mqttDispatcher.register('IoT/test', 'null2', mqtt.passThrough) - } - - exec() : void { - log.info("Dispatcher starting") - - this._mqttDispatcher.exec() - - log.info("Dispatcher running") - } -} - - - -const dispatcher = new Dispatcher() dispatcher.exec() +log.info("Dispatcher running") diff --git a/src/mqttdispatcher.ts b/src/mqttdispatcher.ts index 7d7e944..c393167 100644 --- a/src/mqttdispatcher.ts +++ b/src/mqttdispatcher.ts @@ -17,7 +17,12 @@ interface TopicHandler { last: callchain.AChainItem | undefined } -export class MqttDispatcher { +export interface IDispatcher { + register(topic: string, label: string, + newChainItemOrCallbackFunc: callchain.AChainItem | callchain.ChainItemFunc) : void +} + +export class MqttDispatcher implements IDispatcher { private _mqttClient: Mqtt.Client private _mqttBrokerUrl: string private _topicHandlers: TopicHandler[] diff --git a/src/plugintest1.ts b/src/plugintest1.ts new file mode 100644 index 0000000..0e3625b --- /dev/null +++ b/src/plugintest1.ts @@ -0,0 +1,16 @@ +import * as log from './log' +import { IDispatcher } from './mqttdispatcher' +import * as processor from './processor' + + +var exRoute : processor.AProcessor = new processor.ExProc1('label1') + +export function pluginTest1Start(dispatcher : IDispatcher) : void { + log.info("starting plugintest1") + + dispatcher.register('IoT/test', "plugintest1", (message : any) : any => { + log.info(`plugintest1 runs: ${message}`) + exRoute.in(message) + return message + }) +} \ No newline at end of file diff --git a/src/processor.ts b/src/processor.ts new file mode 100644 index 0000000..b61ee15 --- /dev/null +++ b/src/processor.ts @@ -0,0 +1,28 @@ +import * as log from './log' +import * as events from 'events' + + +export abstract class AProcessor extends events.EventEmitter { + protected _label : string + + constructor(label : string) { + super() + this._label = label + this.addListener('input', this.process) + log.info(`Processor object instanciated: ${this.constructor.name}, ${this._label}`) + } + + public in(message : any) : void { + log.info(`Routing ${message} to Processor class ${this.constructor.name}, ${this._label}`) + this.emit('input', message) + } + + protected abstract process(message : any) : void +} + + +export class ExProc1 extends AProcessor { + protected process(message : any) : void { + log.info(`ExRoute1.process: ${this._label}, ${message}`) + } +} \ No newline at end of file