Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

MessageController Class Reference

Provides time-flow control and sends received message to statecontrol at the correct time. More...

#include <MessageController.h>

Collaboration diagram for MessageController:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 MessageController (Dispatcher *dp)
 ~MessageController ()
double getVisualisationTime ()
bool processMessageFromComm (shared_ptr< vector< shared_ptr< string > > > messagebody)
bool sendMessageToComm (shared_ptr< vector< shared_ptr< string > > > messagebody)
bool communicationMode (int cMode, string filename)
bool communicationMode (int cMode, string thisname, string thatname)
bool setTimeFlow (double ntimeflowfactor)
double getTimeFlow ()

Private Attributes

Commcomm
Dispatcherdisp
int cmode
shared_ptr< list< shared_ptr<
vector< shared_ptr< string > > > > > 
msgqueue
pthread_mutex_t mutex
pthread_cond_t cond
double currenttime
double timeflowfactor
pthread_t msgcontrollerthread
bool msgcontrollerthread_run

Friends

void * msgcontrollerThread (void *args)

Detailed Description

Provides time-flow control and sends received message to statecontrol at the correct time.

MessageController has a timestamp-ordered queue which contain the messages received from Traplas. It also controls the flow of time in the visualisation. The MessageController has a thread which sends the message from its queue to StateControl when the timestamp of the message indicates so.

Definition at line 49 of file MessageController.h.


Constructor & Destructor Documentation

MessageController::MessageController Dispatcher dp  ) 
 

Constructor.

Parameters:
dp A reference to the Dispatcher that called the constructor.

Definition at line 138 of file MessageController.cpp.

References comm, cond, currenttime, disp, msgcontrollerThread, msgcontrollerthread, msgcontrollerthread_run, msgqueue, mutex, and timeflowfactor.

MessageController::~MessageController  ) 
 

Definition at line 153 of file MessageController.cpp.

References comm, msgcontrollerthread, and msgcontrollerthread_run.


Member Function Documentation

bool MessageController::communicationMode int  cMode,
string  thisname,
string  thatname
 

Method used by the Dispatcher to create a subclass of Comm, in this case a DbusConnection.

Parameters:
cMode Mode of communication, At the moment the DbusConnection is the only option.
thisname The name of this application on the DBus ipc messaging bus.
thatname The name of Traplas on the Dbus messaging bus.
Returns:
true if sucessfull, false if there has been an error.

Definition at line 242 of file MessageController.cpp.

References cmode, and comm.

bool MessageController::communicationMode int  cMode,
string  filename
 

Method used by the Dispatcher to create a subclass of Comm, in this case a filereader.

Parameters:
cMode Mode of communication. At the moment the FileReader is the only option.
filename The name of the input file.
Returns:
true if sucessfull, false if there has been an error.

Definition at line 234 of file MessageController.cpp.

References cmode, and comm.

Referenced by Dispatcher::communicationMode().

double MessageController::getTimeFlow  )  [inline]
 

Returns:
The timeflowfactor of the visualisation.

Definition at line 114 of file MessageController.h.

References timeflowfactor.

Referenced by Dispatcher::getTimeFlow().

double MessageController::getVisualisationTime  )  [inline]
 

Returns:
The current time of the visualisation in seconds.

Definition at line 77 of file MessageController.h.

References currenttime.

Referenced by Dispatcher::getTime().

bool MessageController::processMessageFromComm shared_ptr< vector< shared_ptr< string > > >  messagebody  ) 
 

This method is invoked by the communication-class (FileReader or DbusConnection) and puts the message in the queue at the correct place (ordered by timestamp).

Parameters:
messagebody A reference to the message.
Returns:
true if sucessfull, false if there has been an error.

Definition at line 162 of file MessageController.cpp.

References cond, INITIAL_TIMESCALE, msgqueue, mutex, and timeflowfactor.

Referenced by readFile(), and send().

bool MessageController::sendMessageToComm shared_ptr< vector< shared_ptr< string > > >  messagebody  ) 
 

This method is invoked by the Dispatcher to send messages to Traplas. It adds a timestamp to the message and calls sendmessage in the communication-class.

Parameters:
messagebody A reference to the message.
Returns:
true if sucessfull, false if there has been an error.

Definition at line 213 of file MessageController.cpp.

References comm, currenttime, and Comm::sendMessage().

Referenced by Dispatcher::order(), and Dispatcher::setSpdInSim().

Here is the call graph for this function:

bool MessageController::setTimeFlow double  ntimeflowfactor  ) 
 

Sets the timeflowfactor in the MessageController.

Parameters:
ntimeflowfactor The new timeflowfactor relative to the real timeflow. 0 is pause, 2 is twice as fast as real-time, etc.
Returns:
true if sucessfull, false if there has been an error.

Definition at line 250 of file MessageController.cpp.

References timeflowfactor.

Referenced by Dispatcher::setTimeFlow().


Friends And Related Function Documentation

void* msgcontrollerThread void *  args  )  [friend]
 

In this function is the thread which is responsible for controlling the flow of time in de visualisation. Every time it gets cpu-time from the scheduler, it increments the currenttime variable according to the elapsed time and the timeflowfactor. It then looks at the queue and sends messages which can be sent. The messages are send to the Dispatcher.

Parameters:
args The arguments needed for the context of the tread.

Definition at line 79 of file MessageController.cpp.

Referenced by MessageController().


Member Data Documentation

int MessageController::cmode [private]
 

Definition at line 54 of file MessageController.h.

Referenced by communicationMode().

Comm* MessageController::comm [private]
 

Definition at line 51 of file MessageController.h.

Referenced by communicationMode(), MessageController(), sendMessageToComm(), and ~MessageController().

pthread_cond_t MessageController::cond [private]
 

Definition at line 58 of file MessageController.h.

Referenced by MessageController(), msgcontrollerThread(), and processMessageFromComm().

double MessageController::currenttime [private]
 

Definition at line 60 of file MessageController.h.

Referenced by getVisualisationTime(), MessageController(), msgcontrollerThread(), and sendMessageToComm().

Dispatcher* MessageController::disp [private]
 

Definition at line 52 of file MessageController.h.

Referenced by MessageController(), and msgcontrollerThread().

pthread_t MessageController::msgcontrollerthread [private]
 

Definition at line 63 of file MessageController.h.

Referenced by MessageController(), and ~MessageController().

bool MessageController::msgcontrollerthread_run [private]
 

Definition at line 64 of file MessageController.h.

Referenced by MessageController(), msgcontrollerThread(), and ~MessageController().

shared_ptr< list< shared_ptr< vector< shared_ptr< string > > > > > MessageController::msgqueue [private]
 

Definition at line 56 of file MessageController.h.

Referenced by MessageController(), msgcontrollerThread(), and processMessageFromComm().

pthread_mutex_t MessageController::mutex [private]
 

Definition at line 57 of file MessageController.h.

Referenced by MessageController(), msgcontrollerThread(), and processMessageFromComm().

double MessageController::timeflowfactor [private]
 

Definition at line 61 of file MessageController.h.

Referenced by getTimeFlow(), MessageController(), msgcontrollerThread(), processMessageFromComm(), and setTimeFlow().


The documentation for this class was generated from the following files:
Generated on Mon Jun 19 10:22:18 2006 for TraplasVisualisation by  doxygen 1.4.4