<commit_before>/*jslint node: true */

/*
 * #%L
 * %%
 * Copyright (C) 2011 - 2017 BMW Car IT GmbH
 * %%
 * 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.
 * #L%
 */
var JoynrMessage = require("../JoynrMessage");
var Typing = require("../../util/Typing");
var LoggerFactory = require("../../system/LoggerFactory");

/**
 * @constructor WebSocketMessagingSkeleton
 * @param {Object}
 *            settings
 * @param {SharedWebSocket}
 *            settings.sharedWebSocket
 */
var WebSocketMessagingSkeleton = function WebSocketMessagingSkeleton(settings) {
    Typing.checkProperty(settings, "Object", "settings");
    Typing.checkProperty(settings.sharedWebSocket, "SharedWebSocket", "sharedWebSocket");
    Typing.checkProperty(settings.mainTransport, "Boolean", "settings.mainTransport");

    var sharedWebSocket = settings.sharedWebSocket;
    var listener;

    settings.sharedWebSocket.onmessage = function(joynrMessage) {
        if (listener !== undefined) {
            if (joynrMessage.type === JoynrMessage.JOYNRMESSAGE_TYPE_MULTICAST && settings.mainTransport) {
                joynrMessage.setReceivedFromGlobal(true);
            }
            listener(joynrMessage);
        }
    };

    /**
     * Registers the listener function
     * @function WebSocketMessagingSkeleton#registerListener
     *
     * @param {Function}
     *            listener a listener function that should be added and should receive messages
     */
    this.registerListener = function registerListener(listenerToAdd) {
        Typing.checkProperty(listenerToAdd, "Function", "listenerToAdd");

        listener = listenerToAdd;
    };

    /**
     * Unregisters the listener function
     * @function WebSocketMessagingSkeleton#unregisterListener
     *
     * @param {Function}
     *            listener the listener function that should re removed and shouldn't receive
     *            messages any more
     */
    this.unregisterListener = function unregisterListener(listenerToRemove) {
        Typing.checkProperty(listenerToRemove, "Function", "listenerToRemove");

        listener = undefined;
    };

    /**
     * @function WebSocketMessagingSkeleton#shutdown
     */
    this.shutdown = function shutdown() {
        sharedWebSocket.close();
    };
};

module.exports = WebSocketMessagingSkeleton;
<commit_msg>[JS] log id of incoming messages in WebSocketMessagingSkeleton<commit_after>/*jslint node: true */

/*
 * #%L
 * %%
 * Copyright (C) 2011 - 2017 BMW Car IT GmbH
 * %%
 * 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.
 * #L%
 */
var JoynrMessage = require("../JoynrMessage");
var Typing = require("../../util/Typing");
var LoggerFactory = require("../../system/LoggerFactory");
var log = LoggerFactory.getLogger("joynr.messaging.websocket.WebSocketMessagingSkeleton");

/**
 * @constructor WebSocketMessagingSkeleton
 * @param {Object}
 *            settings
 * @param {SharedWebSocket}
 *            settings.sharedWebSocket
 */
var WebSocketMessagingSkeleton = function WebSocketMessagingSkeleton(settings) {
    Typing.checkProperty(settings, "Object", "settings");
    Typing.checkProperty(settings.sharedWebSocket, "SharedWebSocket", "sharedWebSocket");
    Typing.checkProperty(settings.mainTransport, "Boolean", "settings.mainTransport");

    var sharedWebSocket = settings.sharedWebSocket;
    var listener;

    settings.sharedWebSocket.onmessage = function(joynrMessage) {
        log.debug("<<< INCOMING <<< message with ID " + joynrMessage.msgId);
        if (listener !== undefined) {
            if (joynrMessage.type === JoynrMessage.JOYNRMESSAGE_TYPE_MULTICAST && settings.mainTransport) {
                joynrMessage.setReceivedFromGlobal(true);
            }
            listener(joynrMessage);
        }
    };

    /**
     * Registers the listener function
     * @function WebSocketMessagingSkeleton#registerListener
     *
     * @param {Function}
     *            listener a listener function that should be added and should receive messages
     */
    this.registerListener = function registerListener(listenerToAdd) {
        Typing.checkProperty(listenerToAdd, "Function", "listenerToAdd");

        listener = listenerToAdd;
    };

    /**
     * Unregisters the listener function
     * @function WebSocketMessagingSkeleton#unregisterListener
     *
     * @param {Function}
     *            listener the listener function that should re removed and shouldn't receive
     *            messages any more
     */
    this.unregisterListener = function unregisterListener(listenerToRemove) {
        Typing.checkProperty(listenerToRemove, "Function", "listenerToRemove");

        listener = undefined;
    };

    /**
     * @function WebSocketMessagingSkeleton#shutdown
     */
    this.shutdown = function shutdown() {
        sharedWebSocket.close();
    };
};

module.exports = WebSocketMessagingSkeleton;

{'fraction_non_alphanumeric': 0.10127442650807136, 'fraction_numerical': 0.0040781648258283775, 'mean_word_length': 3.1952957947255882, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4234885', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1504, 'n_words': 422}