<commit_before>//------------------------------------------------------------------------
//
// CASROS: Component-based Architecture for Safe Robotic Systems
//
// Copyright (C) 2012-2014 <NAME> and <NAME>
//
//------------------------------------------------------------------------
//
// Created on   : Jul 31, 2012
// Last revision: May 8, 2014
// Author       : <NAME> (<EMAIL>)
// Github       : https://github.com/minyang/casros
//
#include "subscriber.h"
#include "config.h"
#include "dict.h"

#include <Ice/Application.h>

using namespace SF;

// Subscriber id (unique within a process)
unsigned int Subscriber::Id = 0;

#define SUBSCRIBER_INFO "Subscriber " << Id << " (\"" << this->TopicName << "\"): "

class DataI: public Data {
protected:
    SFCallback * CallbackInstance;
public:
    DataI(SFCallback * callbackInstance): CallbackInstance(callbackInstance) {}
    // FIXME: how do I know which command json came from?
    void Monitor(const std::string & json, const Ice::Current &) {
        CallbackInstance->Callback(json);
    }
    void Event(const std::string & json, const Ice::Current &) {
        CallbackInstance->Callback(json);
    }
    void Log(const std::string & json, const Ice::Current &) {
        CallbackInstance->Callback(json);
    }
};

class ControlI: public Control {
protected:
    SFCallback * CallbackInstance;
public:
    ControlI(SFCallback * callbackInstance): CallbackInstance(callbackInstance) {}
    void Command(const std::string & json, const Ice::Current &) {
        CallbackInstance->Callback(json);
    }
};

Subscriber::Subscriber(void): BaseIce(NONAME, NONAME), CallbackInstance(0)
{
    // Default constructor should not be used
    SFASSERT(false);
}

Subscriber::Subscriber(const std::string & topicName, SFCallback * callbackInstance)
    : BaseIce(topicName, GetDefaultConfigFilePath()), 
      CallbackInstance(callbackInstance)
{
    Init();
}

Subscriber::Subscriber(const std::string & topicName, const std::string & propertyFileName)
    : BaseIce(topicName, propertyFileName), 
      CallbackInstance(0)
{
    Init();
}

Subscriber::~Subscriber()
{
}

void Subscriber::Init(void)
{
    ++Id;

    SFLOG_INFO << SUBSCRIBER_INFO << "Created with config file: " << this->IcePropertyFileName << std::endl;
    SFLOG_INFO << SUBSCRIBER_INFO << "Created with topic name: " << this->TopicName << std::endl;
}

bool Subscriber::Startup(void)
{
    this->IceInitialize();

    IceStorm::TopicManagerPrx manager;
    try {<commit_msg>added missing deallocation of callback instance<commit_after>//------------------------------------------------------------------------
//
// CASROS: Component-based Architecture for Safe Robotic Systems
//
// Copyright (C) 2012-2014 <NAME> and <NAME>
//
//------------------------------------------------------------------------
//
// Created on   : Jul 31, 2012
// Last revision: May 8, 2014
// Author       : <NAME> (<EMAIL>)
// Github       : https://github.com/minyang/casros
//
#include "subscriber.h"
#include "config.h"
#include "dict.h"

#include <Ice/Application.h>

using namespace SF;

// Subscriber id (unique within a process)
unsigned int Subscriber::Id = 0;

#define SUBSCRIBER_INFO "Subscriber " << Id << " (\"" << this->TopicName << "\"): "

class DataI: public Data {
protected:
    SFCallback * CallbackInstance;
public:
    DataI(SFCallback * callbackInstance): CallbackInstance(callbackInstance) {}
    // FIXME: how do I know which command json came from?
    void Monitor(const std::string & json, const Ice::Current &) {
        CallbackInstance->Callback(json);
    }
    void Event(const std::string & json, const Ice::Current &) {
        CallbackInstance->Callback(json);
    }
    void Log(const std::string & json, const Ice::Current &) {
        CallbackInstance->Callback(json);
    }
};

class ControlI: public Control {
protected:
    SFCallback * CallbackInstance;
public:
    ControlI(SFCallback * callbackInstance): CallbackInstance(callbackInstance) {}
    void Command(const std::string & json, const Ice::Current &) {
        CallbackInstance->Callback(json);
    }
};

Subscriber::Subscriber(void): BaseIce(NONAME, NONAME), CallbackInstance(0)
{
    // Default constructor should not be used
    SFASSERT(false);
}

Subscriber::Subscriber(const std::string & topicName, SFCallback * callbackInstance)
    : BaseIce(topicName, GetDefaultConfigFilePath()), 
      CallbackInstance(callbackInstance)
{
    Init();
}

Subscriber::Subscriber(const std::string & topicName, const std::string & propertyFileName)
    : BaseIce(topicName, propertyFileName), 
      CallbackInstance(0)
{
    Init();
}

Subscriber::~Subscriber()
{
    if (CallbackInstance)
        delete CallbackInstance;
}

void Subscriber::Init(void)
{
    ++Id;

    SFLOG_INFO << SUBSCRIBER_INFO << "Created with config file: " << this->IcePropertyFileName << std::endl;
    SFLOG_INFO << SUBSCRIBER_INFO << "Created with topic name: " << this->TopicName << std::endl;
}

bool Subscriber::Startup(void)
{
    this->IceInitialize();

    IceStorm::TopicManagerPrx manager;
    try {
{'fraction_non_alphanumeric': 0.18802913959440834, 'fraction_numerical': 0.008663122661941327, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '7127886', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1461, 'n_words': 351}