Alex Lin 14a75508a3 Cleaning up once include variables and copyright cleanup.
Changed all header file once include variables to follow the same naming
convention and not start with any underscores.  Also deleted old
incorrect copyright notices.  Also removed $Id: tags from all files.

Fixes #14.  Fixes #22.
2015-03-23 16:03:14 -05:00

121 lines
3.3 KiB
C++

#ifndef MESSAGETCDEVICE_HH
#define MESSAGETCDEVICE_HH
#include <pthread.h>
#include <vector>
#include "sim_services/Message/include/MessageSubscriber.hh"
#include "sim_services/ThreadBase/include/ThreadBase.hh"
#include "trick_utils/comm/include/tc.h"
namespace Trick {
class MessageTCDevice ;
class MessageTCDeviceListenThread : public Trick::ThreadBase {
public:
MessageTCDeviceListenThread(MessageTCDevice * in_mtcd) ;
virtual ~MessageTCDeviceListenThread() ;
int get_port() ;
int init_listen_device() ;
int restart() ;
virtual void * thread_body() ;
virtual void dump( std::ostream & oss = std::cout ) ;
protected:
/** Pointer back to MessageTCDevice\n */
MessageTCDevice * mtcd ; /**< trick_io(**) */
/** No handshake message server listen device.\n */
TCDevice listen_dev ; /**< trick_io(**) trick_units(--) */
} ;
/**
* This MessageTCDevice is a class that inherits from MessageSubscriber.
* It defines a type of MessageSubscriber that sends the messages to a receiver
* through TCDevice when a proper socket connection is established.
* Basically, it has a message server listen TCDevice that receives all the message
* updates from a message publisher which it subscribes to and then writes the message
* updates to all the connections it has if possible.
*/
class MessageTCDevice : public MessageSubscriber {
public:
/**
@brief The constructor.
*/
MessageTCDevice();
/**
@brief The destructor.
*/
~MessageTCDevice();
/**
@brief Gets the listen thread.
*/
Trick::MessageTCDeviceListenThread & get_listen_thread() ;
/**
@brief Adds a new connection. Called from MessageTCDeviceListenThread
*/
void add_connection( TCDevice * new_conn ) ;
/**
@brief Send the header & message to all open connections.
*/
virtual void update( unsigned int level , std::string header, std::string message );
/**
@brief Initializes this subscriber.
@return always 0
*/
int default_data() ;
/**
@brief Initializes this subscriber.
@return always 0
*/
int init() ;
/**
@brief Restarts this subscriber.
@return always 0
*/
int restart() ;
/**
@brief Shuts down this subscriber.
@return always 0
*/
int shutdown() ;
/** The port number for message socket connection. Copied out from listen_thread.\n */
int port ; /**< trick_units(--) */
private:
/** Thread to start listen device\n */
MessageTCDeviceListenThread listen_thread ;
/** Message buffer.\n */
char * combined_message ; /**< trick_io(**) trick_units(--) */
/** List of open connections.\n */
std::vector< TCDevice *> connections ; /**< trick_io(**) trick_units(--) */
} ;
}
#endif