<commit_before>/*
 * FrameProcessorController.cpp
 *
 *  Created on: 27 May 2016
 *      Author: gnx91527
 */

#include <stdio.h>
#include "FrameProcessorController.h"

namespace FrameProcessor
{
  const std::string FrameProcessorController::META_RX_INTERFACE        = "inproc://meta_rx";

  const std::string FrameProcessorController::CONFIG_SHUTDOWN          = "shutdown";

  const std::string FrameProcessorController::CONFIG_STATUS            = "status";

  const std::string FrameProcessorController::CONFIG_FR_SHARED_MEMORY  = "fr_shared_mem";
  const std::string FrameProcessorController::CONFIG_FR_RELEASE        = "fr_release_cnxn";
  const std::string FrameProcessorController::CONFIG_FR_READY          = "fr_ready_cnxn";
  const std::string FrameProcessorController::CONFIG_FR_SETUP          = "fr_setup";

  const std::string FrameProcessorController::CONFIG_CTRL_ENDPOINT     = "ctrl_endpoint";
  const std::string FrameProcessorController::CONFIG_META_ENDPOINT     = "meta_endpoint";

  const std::string FrameProcessorController::CONFIG_PLUGIN            = "plugin";
  const std::string FrameProcessorController::CONFIG_PLUGIN_LIST       = "list";
  const std::string FrameProcessorController::CONFIG_PLUGIN_LOAD       = "load";
  const std::string FrameProcessorController::CONFIG_PLUGIN_CONNECT    = "connect";
  const std::string FrameProcessorController::CONFIG_PLUGIN_DISCONNECT = "disconnect";
  const std::string FrameProcessorController::CONFIG_PLUGIN_NAME       = "name";
  const std::string FrameProcessorController::CONFIG_PLUGIN_INDEX      = "index";
  const std::string FrameProcessorController::CONFIG_PLUGIN_LIBRARY    = "library";
  const std::string FrameProcessorController::CONFIG_PLUGIN_CONNECTION = "connection";

  /** Construct a new FrameProcessorController class.
   *
   * The constructor sets up logging used within the class, and starts the
   * IpcReactor thread.
   */
  FrameProcessorController::FrameProcessorController() :
    logger_(log4cxx::Logger::getLogger("FW.FrameProcessorController")),
    runThread_(true),
    threadRunning_(false),
    threadInitError_(false),
    pluginShutdownSent(false),
    ctrlThread_(boost::bind(&FrameProcessorController::runIpcService, this)),
    ctrlChannel_(ZMQ_REP),
	metaRxChannel_(ZMQ_PULL),
	metaTxChannel_(ZMQ_PUB)
  {
    LOG4CXX_DEBUG(logger_, "Constructing FrameProcessorController");
    
    totalFrames = 0;

    // Wait for the thread service to initialise and be running properly, so that
    // this constructor only returns once the object is fully initialised (RAII).
    // Monitor the thread error flag and throw an exception if initialisation fails
    while (!threadRunning_)
    {
        if (threadInitError_) {
            ctrlThread_.join();
            throw std::runtime_error(threadInitMsg_);
            break;
        }
    }

    this->setupMetaRxInterface();
 }

  /**
   * Destructor.
   */
  FrameProcessorController::~FrameProcessorController()
  {
    // TODO Auto-generated destructor stub
  }

  /** Handle an incoming configuration message.
   *
   * This method is called by the IpcReactor when a configuration IpcMessage
   * has been received.  The raw message is read and parsed into an IpcMessage
   * for further processing.  The configure method is called, and once
   * configuration has completed a response IpcMessage is sent back on the
   * control channel.
   */
  void FrameProcessorController::handleCtrlChannel()
  {
    // Receive a message from the main thread channel<commit_msg>Added comment regarding setting up the meta RX interface.<commit_after>/*
 * FrameProcessorController.cpp
 *
 *  Created on: 27 May 2016
 *      Author: gnx91527
 */

#include <stdio.h>
#include "FrameProcessorController.h"

namespace FrameProcessor
{
  const std::string FrameProcessorController::META_RX_INTERFACE        = "inproc://meta_rx";

  const std::string FrameProcessorController::CONFIG_SHUTDOWN          = "shutdown";

  const std::string FrameProcessorController::CONFIG_STATUS            = "status";

  const std::string FrameProcessorController::CONFIG_FR_SHARED_MEMORY  = "fr_shared_mem";
  const std::string FrameProcessorController::CONFIG_FR_RELEASE        = "fr_release_cnxn";
  const std::string FrameProcessorController::CONFIG_FR_READY          = "fr_ready_cnxn";
  const std::string FrameProcessorController::CONFIG_FR_SETUP          = "fr_setup";

  const std::string FrameProcessorController::CONFIG_CTRL_ENDPOINT     = "ctrl_endpoint";
  const std::string FrameProcessorController::CONFIG_META_ENDPOINT     = "meta_endpoint";

  const std::string FrameProcessorController::CONFIG_PLUGIN            = "plugin";
  const std::string FrameProcessorController::CONFIG_PLUGIN_LIST       = "list";
  const std::string FrameProcessorController::CONFIG_PLUGIN_LOAD       = "load";
  const std::string FrameProcessorController::CONFIG_PLUGIN_CONNECT    = "connect";
  const std::string FrameProcessorController::CONFIG_PLUGIN_DISCONNECT = "disconnect";
  const std::string FrameProcessorController::CONFIG_PLUGIN_NAME       = "name";
  const std::string FrameProcessorController::CONFIG_PLUGIN_INDEX      = "index";
  const std::string FrameProcessorController::CONFIG_PLUGIN_LIBRARY    = "library";
  const std::string FrameProcessorController::CONFIG_PLUGIN_CONNECTION = "connection";

  /** Construct a new FrameProcessorController class.
   *
   * The constructor sets up logging used within the class, and starts the
   * IpcReactor thread.
   */
  FrameProcessorController::FrameProcessorController() :
    logger_(log4cxx::Logger::getLogger("FW.FrameProcessorController")),
    runThread_(true),
    threadRunning_(false),
    threadInitError_(false),
    pluginShutdownSent(false),
    ctrlThread_(boost::bind(&FrameProcessorController::runIpcService, this)),
    ctrlChannel_(ZMQ_REP),
	metaRxChannel_(ZMQ_PULL),
	metaTxChannel_(ZMQ_PUB)
  {
    LOG4CXX_DEBUG(logger_, "Constructing FrameProcessorController");
    
    totalFrames = 0;

    // Wait for the thread service to initialise and be running properly, so that
    // this constructor only returns once the object is fully initialised (RAII).
    // Monitor the thread error flag and throw an exception if initialisation fails
    while (!threadRunning_)
    {
        if (threadInitError_) {
            ctrlThread_.join();
            throw std::runtime_error(threadInitMsg_);
            break;
        }
    }

    // The meta interface should only be setup once confirmation of the thread startup
    // has been recevied.  The reactor is created within the thread startup method.
    this->setupMetaRxInterface();
 }

  /**
   * Destructor.
   */
  FrameProcessorController::~FrameProcessorController()
  {
    // TODO Auto-generated destructor stub
  }

  /** Handle an incoming configuration message.
   *
   * This method is called by the IpcReactor when a configuration IpcMessage
   * has been received.  The raw message is read and parsed into an IpcMessage
   * for further processing.  The configure method is called, and once
   * configuration has completed a response IpcMessage is sent back on the
   * control channel.
   */
  void FrameProcessorController::handleCtrlChannel()
  {
    // Receive a message from the main thread channel
{'fraction_non_alphanumeric': 0.08713007570543703, 'fraction_numerical': 0.0038540949759119066, 'mean_word_length': 4.160511363636363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '5443234', 'n_tokens_mistral': 1979, 'n_tokens_neox': 1926, 'n_words': 502}