<commit_before>/*
 * #%L
 * %%
 * Copyright (C) 2011 - 2013 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%
 */

#include <QFileInfo>

#include "MyRadioHelper.h"
#include "joynr/vehicle/RadioProxy.h"
#include "joynr/vehicle/RadioNewStationDiscoveredBroadcastFilterParameters.h"
#include "joynr/JoynrRuntime.h"
#include "joynr/RequestStatus.h"
#include "joynr/ISubscriptionListener.h"
#include "joynr/SubscriptionListener.h"
#include "joynr/OnChangeWithKeepAliveSubscriptionQos.h"
#include <cassert>
#include <limits>
#include "joynr/JsonSerializer.h"

using namespace joynr;
using joynr_logging::Logger;
using joynr_logging::Logging;

// A class that listens to messages generated by subscriptions
class RadioStationListener : public SubscriptionListener<vehicle::RadioStation>
{
public:
    RadioStationListener()
            : logger(Logging::getInstance()->getLogger(
                      "DEMO",
                      "MyRadioConsumerApplication::RadioStationListener"))
    {
    }

    ~RadioStationListener()
    {
        if (logger)
            delete logger;
    }

    void onReceive(vehicle::RadioStation value)
    {
        MyRadioHelper::prettyLog(
                logger,
                QString("ATTRIBUTE SUBSCRIPTION current station: %1").arg(value.toString()));
    }

    void onError()
    {
        MyRadioHelper::prettyLog(logger, QString("ATTRIBUTE SUBSCRIPTION Publication Missed"));
    }

private:
    Logger* logger;
};

// A class that listens to messages generated by subscriptions
class WeakSignalBroadcastListener : public SubscriptionListener<vehicle::RadioStation>
{
public:
    WeakSignalBroadcastListener()
            : logger(Logging::getInstance()->getLogger(
                      "DEMO",
                      "MyRadioConsumerApplication::WeakSignalBroadcastListener"))
    {
    }

    ~WeakSignalBroadcastListener()
    {
        if (logger)
            delete logger;
    }

    void onReceive(vehicle::RadioStation value)
    {
        MyRadioHelper::prettyLog(
                logger, QString("BROADCAST SUBSCRIPTION weak signal: %1").arg(value.toString()));
    }

private:
    Logger* logger;
};

// A class that listens to messages generated by subscriptions
class NewStationDiscoveredBroadcastListener
        : public SubscriptionListener<vehicle::RadioStation, vehicle::GeoPosition>
{
public:
    NewStationDiscoveredBroadcastListener()
            : logger(Logging::getInstance()->getLogger(
                      "DEMO",
                      "MyRadioConsumerApplication::NewStationDiscoveredBroadcastListener"))
    {
    }

    ~NewStationDiscoveredBroadcastListener()
    {
        if (logger)
            delete logger;
    }

    void onReceive(vehicle::RadioStation discoveredStation, vehicle::GeoPosition geoPosition)
    {
        MyRadioHelper::prettyLog(logger,
                                 QString("BROADCAST SUBSCRIPTION new station discovered: %1 at %2")
                                         .arg(discoveredStation.toString())
                                         .arg(geoPosition.toString()));
    }

private:
    Logger* logger;
};

// Run a subscription
QString runSubscription(vehicle::RadioProxy* proxy)
{
    Logger* logger = Logging::getInstance()->getLogger(
            "DEMO", "MyRadioConsumerApplication::runSubscription");

    // Set the Quality of Service parameters for the subscription

    // The provider will send a notification whenever the value changes. The number of sent
    // notifications
    // may be limited by the min interval QoS.
    // NOTE: The provider must support on-change notifications in order to use this feature by
    // calling
    //       the <attribute>Changed method of the <interface>AbstractProvider class whenever the
    //       <attribute>
    //       value changes.
    QSharedPointer<OnChangeWithKeepAliveSubscriptionQos> subscriptionQos(
            new OnChangeWithKeepAliveSubscriptionQos());
    // The provider will maintain at least a minimum interval idle time in milliseconds between
    // successive notifications, even if on-change notifications are enabled and the value changes
    // more
    // often. This prevents the consumer from being flooded by updated values. The filtering happens
    // on
    // the provider's side, thus also preventing excessive network traffic.
    subscriptionQos->setMinInterval(5 * 1000);
    // The provider will send notifications every maximum interval in milliseconds, even if the
    // value didn't
    // change. It will send notifications more often if on-change notifications are enabled,
    // the value changes more often, and the minimum interval QoS does not prevent it. The maximum
    // interval
    // can thus be seen as a sort of heart beat.
    subscriptionQos->setMaxInterval(8 * 1000);
    // The provider will send notifications until the end date is reached. The consumer will not
    // receive any
    // notifications (neither value notifications nor missed publication notifications) after
    // this date.
    // setValidity_ms will set the end date to current time millis + validity_ms
    subscriptionQos->setValidity(60 * 1000);
    // Notification messages will be sent with this time-to-live. If a notification message can not
    // be
    // delivered within its TTL, it will be deleted from the system.
    // NOTE: If a notification message is not delivered due to an expired TTL, it might raise a
    //       missed publication notification (depending on the value of the alert interval QoS).
    subscriptionQos->setAlertAfterInterval(10 * 1000);

    // Subscriptions go to a listener object
    QSharedPointer<ISubscriptionListener<vehicle::RadioStation>> listener(
            new RadioStationListener());

    // Subscribe to the radio station.
    QString subscriptionId = proxy->subscribeToCurrentStation(listener, subscriptionQos);

    return subscriptionId;
}

//------- Main entry point -------------------------------------------------------

int main(int argc, char* argv[])
{
    // Get a logger
    Logger* logger = Logging::getInstance()->getLogger("DEMO", "MyRadioConsumerApplication");

    // Check the usage
    QString programName(argv[0]);
    if (argc != 2) {
        LOG_ERROR(logger, QString("USAGE: %1 <provider-domain>").arg(programName));
        return 1;
    }

    // Get the provider domain
    QString providerDomain(argv[1]);
    LOG_INFO(logger, QString("Creating proxy for provider on domain \"%1\"").arg(providerDomain));

    // Get the current program directory
    QString dir(QFileInfo(programName).absolutePath());
<commit_msg>[C++] Radio-App, removed unused code<commit_after>/*
 * #%L
 * %%
 * Copyright (C) 2011 - 2013 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%
 */

#include <QFileInfo>

#include "MyRadioHelper.h"
#include "joynr/vehicle/RadioProxy.h"
#include "joynr/vehicle/RadioNewStationDiscoveredBroadcastFilterParameters.h"
#include "joynr/JoynrRuntime.h"
#include "joynr/RequestStatus.h"
#include "joynr/ISubscriptionListener.h"
#include "joynr/SubscriptionListener.h"
#include "joynr/OnChangeWithKeepAliveSubscriptionQos.h"
#include <cassert>
#include <limits>
#include "joynr/JsonSerializer.h"

using namespace joynr;
using joynr_logging::Logger;
using joynr_logging::Logging;

// A class that listens to messages generated by subscriptions
class RadioStationListener : public SubscriptionListener<vehicle::RadioStation>
{
public:
    RadioStationListener()
            : logger(Logging::getInstance()->getLogger(
                      "DEMO",
                      "MyRadioConsumerApplication::RadioStationListener"))
    {
    }

    ~RadioStationListener()
    {
        if (logger)
            delete logger;
    }

    void onReceive(vehicle::RadioStation value)
    {
        MyRadioHelper::prettyLog(
                logger,
                QString("ATTRIBUTE SUBSCRIPTION current station: %1").arg(value.toString()));
    }

    void onError()
    {
        MyRadioHelper::prettyLog(logger, QString("ATTRIBUTE SUBSCRIPTION Publication Missed"));
    }

private:
    Logger* logger;
};

// A class that listens to messages generated by subscriptions
class WeakSignalBroadcastListener : public SubscriptionListener<vehicle::RadioStation>
{
public:
    WeakSignalBroadcastListener()
            : logger(Logging::getInstance()->getLogger(
                      "DEMO",
                      "MyRadioConsumerApplication::WeakSignalBroadcastListener"))
    {
    }

    ~WeakSignalBroadcastListener()
    {
        if (logger)
            delete logger;
    }

    void onReceive(vehicle::RadioStation value)
    {
        MyRadioHelper::prettyLog(
                logger, QString("BROADCAST SUBSCRIPTION weak signal: %1").arg(value.toString()));
    }

private:
    Logger* logger;
};

// A class that listens to messages generated by subscriptions
class NewStationDiscoveredBroadcastListener
        : public SubscriptionListener<vehicle::RadioStation, vehicle::GeoPosition>
{
public:
    NewStationDiscoveredBroadcastListener()
            : logger(Logging::getInstance()->getLogger(
                      "DEMO",
                      "MyRadioConsumerApplication::NewStationDiscoveredBroadcastListener"))
    {
    }

    ~NewStationDiscoveredBroadcastListener()
    {
        if (logger)
            delete logger;
    }

    void onReceive(vehicle::RadioStation discoveredStation, vehicle::GeoPosition geoPosition)
    {
        MyRadioHelper::prettyLog(logger,
                                 QString("BROADCAST SUBSCRIPTION new station discovered: %1 at %2")
                                         .arg(discoveredStation.toString())
                                         .arg(geoPosition.toString()));
    }

private:
    Logger* logger;
};

//------- Main entry point -------------------------------------------------------

int main(int argc, char* argv[])
{
    // Get a logger
    Logger* logger = Logging::getInstance()->getLogger("DEMO", "MyRadioConsumerApplication");

    // Check the usage
    QString programName(argv[0]);
    if (argc != 2) {
        LOG_ERROR(logger, QString("USAGE: %1 <provider-domain>").arg(programName));
        return 1;
    }

    // Get the provider domain
    QString providerDomain(argv[1]);
    LOG_INFO(logger, QString("Creating proxy for provider on domain \"%1\"").arg(providerDomain));

    // Get the current program directory
    QString dir(QFileInfo(programName).absolutePath());

{'fraction_non_alphanumeric': 0.10396942586641188, 'fraction_numerical': 0.005732650047772084, 'mean_word_length': 2.8495486459378134, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5406093', 'n_tokens_mistral': 3044, 'n_tokens_neox': 2893, 'n_words': 890}