<commit_before>/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Copyright Projet JRL-Japan, 2007
 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * File:      DistantShell.h
 * Project:   SOT
 * Author:    <NAME>
 *
 * Version control
 * ===============
 *
 *  $Id$
 *
 * Description
 * ============
 *
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/



#ifndef __SOT_DISTANTSHELL_HH__
#define __SOT_DISTANTSHELL_HH__

/* --------------------------------------------------------------------- */
/* --- INCLUDE --------------------------------------------------------- */
/* --------------------------------------------------------------------- */


#include <dynamic-graph/interpreter.h>
#include <sot-core/contiifstream.h>
#include <dynamic-graph/entity.h>

//#include <pthread.h>

#ifdef HAVE_LIBBOOST_THREAD
#include <boost/thread.hpp>
#endif

/* --------------------------------------------------------------------- */
/* --- API ------------------------------------------------------------- */
/* --------------------------------------------------------------------- */

#if defined (WIN32) 
#  if defined (distant_shell_EXPORTS)
#    define SOTDISTANTSHELL_EXPORT __declspec(dllexport)
#  else  
#    define SOTDISTANTSHELL_EXPORT __declspec(dllimport)
#  endif 
#else
#  define SOTDISTANTSHELL_EXPORT
#endif


namespace sot {
namespace dg = dynamicgraph;

/* --------------------------------------------------------------------- */
/* --- CLASS ----------------------------------------------------------- */
/* --------------------------------------------------------------------- */

class SOTDISTANTSHELL_EXPORT DistantShell
{
 public:
  std::ofstream osOwn;
 protected:
  Contiifstream filein;
  dynamicgraph::Interpreter& shell;
  std::ostream & os;
/*   pthread_t loopThread; */
/*   pthread_attr_t loopThreadAttr; */

#ifdef HAVE_LIBBOOST_THREAD
  boost::thread* threadLoop;
#else
  int* threadLoop;
#endif 

  bool endLoop;
  
  unsigned int latency;
  static const unsigned int LATENCY_DEFAULT = 10;

 public:
  DistantShell(dynamicgraph::Interpreter& shell_,const std::string& fn  )
    :osOwn(fn.c_str()),shell(shell_),os(osOwn)
    ,endLoop(false),latency(LATENCY_DEFAULT){ }

  DistantShell( const std::string& filename
		   ,dynamicgraph::Interpreter& shell_
		   ,std::ostream& os_ )
    : filein( filename ),shell(shell_),os(os_)
    ,endLoop(false),latency(LATENCY_DEFAULT)
    {}

  DistantShell( const std::string& filename
		   ,dynamicgraph::Interpreter& shell_
		   ,const std::string& fn )
    : osOwn(fn.c_str()),filein( filename ),shell(shell_),os(osOwn)
    ,endLoop(false),latency(LATENCY_DEFAULT)
    {}

  ~DistantShell( void );

  void inputFile( const std::string& filename ) { filein = filename; }

  void loop( const int latency = LATENCY_DEFAULT ); // in ms
  void loopInThread( void );
  void terminate( void ) { endLoop = true; }
  void setLatency( const unsigned int& l ) { latency = l; }
};


class SOTDISTANTSHELL_EXPORT DistantShellPlugin
: public dynamicgraph::Entity
{
 protected:
  DistantShell dshell;

 public:<commit_msg>Distant-shell must use the API of sot-core<commit_after>/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Copyright Projet JRL-Japan, 2007
 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * File:      DistantShell.h
 * Project:   SOT
 * Author:    <NAME>
 *
 * Version control
 * ===============
 *
 *  $Id$
 *
 * Description
 * ============
 *
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/



#ifndef __SOT_DISTANTSHELL_HH__
#define __SOT_DISTANTSHELL_HH__

/* --------------------------------------------------------------------- */
/* --- INCLUDE --------------------------------------------------------- */
/* --------------------------------------------------------------------- */


#include <dynamic-graph/interpreter.h>
#include <sot-core/contiifstream.h>
#include <dynamic-graph/entity.h>
#include <sot-core/sot-core-api.h>

//#include <pthread.h>

#ifdef HAVE_LIBBOOST_THREAD
#include <boost/thread.hpp>
#endif

namespace sot {
namespace dg = dynamicgraph;

/* --------------------------------------------------------------------- */
/* --- CLASS ----------------------------------------------------------- */
/* --------------------------------------------------------------------- */

class SOT_CORE_EXPORT DistantShell
{
 public:
  std::ofstream osOwn;
 protected:
  Contiifstream filein;
  dynamicgraph::Interpreter& shell;
  std::ostream & os;
/*   pthread_t loopThread; */
/*   pthread_attr_t loopThreadAttr; */

#ifdef HAVE_LIBBOOST_THREAD
  boost::thread* threadLoop;
#else
  int* threadLoop;
#endif 

  bool endLoop;
  
  unsigned int latency;
  static const unsigned int LATENCY_DEFAULT = 10;

 public:
  DistantShell(dynamicgraph::Interpreter& shell_,const std::string& fn  )
    :osOwn(fn.c_str()),shell(shell_),os(osOwn)
    ,endLoop(false),latency(LATENCY_DEFAULT){ }

  DistantShell( const std::string& filename
		   ,dynamicgraph::Interpreter& shell_
		   ,std::ostream& os_ )
    : filein( filename ),shell(shell_),os(os_)
    ,endLoop(false),latency(LATENCY_DEFAULT)
    {}

  DistantShell( const std::string& filename
		   ,dynamicgraph::Interpreter& shell_
		   ,const std::string& fn )
    : osOwn(fn.c_str()),filein( filename ),shell(shell_),os(osOwn)
    ,endLoop(false),latency(LATENCY_DEFAULT)
    {}

  ~DistantShell( void );

  void inputFile( const std::string& filename ) { filein = filename; }

  void loop( const int latency = LATENCY_DEFAULT ); // in ms
  void loopInThread( void );
  void terminate( void ) { endLoop = true; }
  void setLatency( const unsigned int& l ) { latency = l; }
};


class SOT_CORE_EXPORT DistantShellPlugin
: public dynamicgraph::Entity
{
 protected:
  DistantShell dshell;

 public:
{'fraction_non_alphanumeric': 0.34576098059244126, 'fraction_numerical': 0.002383384405856316, 'mean_word_length': 2.082371458551941, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '7566891', 'n_tokens_mistral': 1797, 'n_tokens_neox': 1660, 'n_words': 324}