//
// Copyright (C) 2018-2019 Dominik S. Buse <buse@ccs-labs.org>
//
// Documentation for these modules is at http://veins.car2x.org/
//
// SPDX-License-Identifier: GPL-2.0-or-later
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//

%description
Ensure CallbackListeners are called.

%file: test.ned

simple Module {
    @signal[mySignal](type=string);
}

network Test
{
    submodules:
        node: Module;
}


%file: test.cc
#include "veins/veins.h"
#include "veins/modules/utility/SignalManager.h"

namespace @TESTNAME@ {

using payloadType = const char*;

void staticCallback(veins::SignalPayload<payloadType> signalPayload)
{
    EV << "Static callback that does not use the payload\n";
}

struct functorCallback {
    void operator()(veins::SignalPayload<payloadType> signalPayload)
    {
        EV << "Functor callback that does not use the payload\n";
    }
};

auto lambdaCallback = [](veins::SignalPayload<payloadType> signalPayload) {
    EV << "Lambda that does not use the payload\n";
};

class Module : public cSimpleModule {
public:
    static const simsignal_t mySignal;
    Module()
        : cSimpleModule() {};
    void initialize(int stage) override;
protected:
    veins::SignalManager signalManager;
};

const simsignal_t Module::mySignal = registerSignal("mySignal");

Define_Module(Module);

void Module::initialize(int stage)
{
    auto localLambdaCallback = [this](veins::SignalPayload<payloadType> signalPayload) {
        EV << "Local lambda that does not use the payload\n";
    };
    // setup callback with signal manager
    signalManager.subscribeCallback(getSystemModule(), Module::mySignal, lambdaCallback);
    signalManager.subscribeCallback(getSystemModule(), Module::mySignal, localLambdaCallback);
    signalManager.subscribeCallback(getSystemModule(), Module::mySignal, staticCallback);
    signalManager.subscribeCallback(getSystemModule(), Module::mySignal, functorCallback());

    // emit message to all callbacks
    emit(Module::mySignal, "Hello World");
}

} // namespace @TESTNAME@

%contains: stdout
Lambda that does not use the payload
Local lambda that does not use the payload
Static callback that does not use the payload
Functor callback that does not use the payload
