{"size": 2328, "ext": "js", "max_stars_repo_path": "services/index.js", "max_stars_repo_name": "cjoyau/intel-iot-alarm", "max_stars_repo_stars_event_min_datetime": "2021-02-11T17:20:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-11T17:20:18.000Z", "max_issues_repo_path": "services/index.js", "max_issues_repo_name": "cjoyau/intel-iot-alarm", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "services/index.js", "max_forks_repo_name": "cjoyau/intel-iot-alarm", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.7142857143, "max_line_length": 80, "alphanum_fraction": 0.6585051546}
/*
* Copyright (c) 2015 - 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

'use strict';

let services = null;

function servicesInit(config) {

    let transports = []

    if (config.services) {

        if (config.services.m2x) {
            const m2x = require('./transports/m2x');
            transports.push(m2x);
        }

        if (config.services.predix) {
            const predix = require('./transports/predix');
            transports.push(predix);
        }

        if (config.services.sap) {
            const sap = require('./transports/sap');
            transports.push(sap);
        }

        if (config.services.mqtt) {
            const mqtt = require('./transports/mqtt');
            transports.push(mqtt);
        }

        if (config.services.sms) {
            const sms = require('./transports/sms');
            transports.push(sms);
        }

    }

    return transports;

}

function publish(config, payload) {

    if (!services) {
        services = servicesInit(config);
    }

    services.forEach((service, index, obj) => service.publish(config, payload));

}

function increment(config) {
    const payload = { counter: new Date().toISOString() };
    publish(config, payload);
}

module.exports = {
    log: publish,
    increment: increment
};
