SUMO - Simulation of Urban MObility

OutputDevice_Network Class Reference

An output device for TCP/IP network connections. More...

#include <OutputDevice_Network.h>

Inheritance diagram for OutputDevice_Network:
OutputDevice

Public Member Functions

 OutputDevice_Network (const std::string &host, const int port) throw (IOError)
 Constructor.
 ~OutputDevice_Network () throw ()
 Destructor.
OutputDevice member methods
virtual bool ok () throw ()
 returns the information whether one can write into the device
void close () throw ()
 Closes the device and removes it from the dictionary.
void setPrecision (unsigned int precision=OUTPUT_ACCURACY) throw ()
 Sets the precison or resets it to default.
bool writeXMLHeader (const std::string &rootElement, const std::string xmlParams="", const std::string &attrs="", const std::string &comment="") throw ()
 Writes an XML header with optional configuration.
OutputDevice & indent () throw ()
 Adds indentation.
OutputDevice & openTag (const std::string &xmlElement) throw ()
 Opens an XML tag.
OutputDevice & openTag (const SumoXMLTag &xmlElement) throw ()
 Opens an XML tag.
bool closeTag (bool abbreviated=false) throw ()
 Closes the most recently opened tag.
OutputDevice & writeAttr (std::string attr, std::string val)
 writes an arbitrary attribute
template<class T >
OutputDevice & writeAttr (const SumoXMLAttr attr, const T &val)
 writes an named attribute
void inform (const std::string &msg)
 Retrieves a message to this device.
template<class T >
OutputDevice & operator<< (const T &t)
 Abstract output operator.

Static Public Member Functions

static std::string realString (const SUMOReal v, const int precision=OUTPUT_ACCURACY)
 Abstract output operator.
static access methods to OutputDevices
static OutputDevice & getDevice (const std::string &name, const std::string &base="") throw (IOError)
 Returns the described OutputDevice.
static bool createDeviceByOption (const std::string &optionName, const std::string &rootElement="") throw (IOError)
 Creates the device using the output definition stored in the named option.
static OutputDevice & getDeviceByOption (const std::string &name) throw (IOError, InvalidArgument)
 Returns the device described by the option.
static void closeAll () throw ()

Protected Member Functions

Methods that override/implement OutputDevice-methods
std::ostream & getOStream () throw ()
 Returns the associated ostream.
virtual void postWriteHook () throw ()
 Sends the data which was written to the string stream over the socket.

Private Attributes

std::ostringstream myMessage
 packet buffer
tcpip::Socket * mySocket
 the socket to transfer the data

Detailed Description

An output device for TCP/IP network connections.

The implementation uses a portable socket implementation from the Shawn project (shawn.sf.net) located in src/foreign/tcpip/socket.h. It uses an internal storage for the messages, which is sent via the socket when "postWriteHook" is called.

See also:
postWriteHook

Definition at line 54 of file OutputDevice_Network.h.


Constructor & Destructor Documentation

OutputDevice_Network::OutputDevice_Network ( const std::string &  host,
const int  port 
) throw (IOError)

Constructor.

Parameters:
[in]hostThe host to connect
[in]portThe port to connect
Exceptions:
IOErrorIf the connection could not been established

Definition at line 43 of file OutputDevice_Network.cpp.

References toString(), and tcpip::SocketException::what().

OutputDevice_Network::~OutputDevice_Network ( ) throw ()

Destructor.

Definition at line 54 of file OutputDevice_Network.cpp.

References tcpip::Socket::close(), and mySocket.


Member Function Documentation

void OutputDevice::closeAll ( ) throw () [static, inherited]

Closes all registered devices

Definition at line 116 of file OutputDevice.cpp.

References OutputDevice::myOutputDevices.

Referenced by GUIRunThread::deleteSim(), and main().

bool OutputDevice::closeTag ( bool  abbreviated = false) throw () [inherited]
bool OutputDevice::createDeviceByOption ( const std::string &  optionName,
const std::string &  rootElement = "" 
) throw (IOError) [static, inherited]

Creates the device using the output definition stored in the named option.

Creates and returns the device named by the option. Asks whether the option and retrieves the name from the option if so. Optionally the XML header gets written as well. Returns whether a device was created (option was set).

Please note, that we do not have to consider the "application base" herein, because this call is only used to get file names of files referenced within XML-declarations of structures which paths already is aware of the cwd.

Parameters:
[in]optionNameThe name of the option to use for retrieving the output definition
[in]rootElementThe root element to use (XML-output)
Returns:
Whether a device was built (the option was set)
Exceptions:
IOErrorIf the output could not be built for any reason (error message is supplied)

Definition at line 92 of file OutputDevice.cpp.

References OutputDevice::getDevice(), OptionsCont::getOptions(), and OutputDevice::writeXMLHeader().

Referenced by MSFrame::buildStreams(), MSDevice_Vehroutes::init(), and main().

OutputDevice & OutputDevice::getDevice ( const std::string &  name,
const std::string &  base = "" 
) throw (IOError) [static, inherited]

Returns the described OutputDevice.

Creates and returns the named device. "stdout" and "-" refer to standard out, "hostname:port" initiates socket connection. Otherwise a filename is assumed and the second parameter may be used to give a base directory. If there already is a device with the same name this one is returned.

Parameters:
[in]nameThe description of the output name/port/whatever
[in]baseThe base path the application is run within
Returns:
The corresponding (built or existing) device
Exceptions:
IOErrorIf the output could not be built for any reason (error message is supplied)

Definition at line 61 of file OutputDevice.cpp.

References TplConvert< E >::_2int(), FileHelpers::checkForRelativity(), OutputDevice::getOStream(), FileHelpers::isSocket(), and OutputDevice::setPrecision().

Referenced by NLHandler::addE1Detector(), NLHandler::addE2Detector(), NLHandler::addEdgeLaneMeanData(), NLHandler::addInstantE1Detector(), NLHandler::addRouteProbeDetector(), NLHandler::addVTypeProbeDetector(), NLHandler::beginE3Detector(), NLDiscreteEventBuilder::buildSaveTLStateCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchesCommand(), NLDiscreteEventBuilder::buildSaveTLSwitchStatesCommand(), OutputDevice::createDeviceByOption(), OutputDevice::getDeviceByOption(), MsgHandler::initOutputOptions(), GUIDialog_ViewSettings::onCmdExportSetting(), GUIParameterTracker::onCmdSave(), GUIDialog_EditViewport::onCmdSave(), GUIDialog_Breakpoints::onCmdSave(), RONet::openOutput(), RODFDetectorCon::save(), PCPolyContainer::save(), GUISelectedStorage::save(), RODFDetectorCon::saveAsPOIs(), GUIDialog_ViewSettings::saveDecals(), RODFDetectorCon::saveRoutes(), NWWriter_XML::writeEdgesAndConnections(), RODFDetector::writeEmitterDefinition(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), NWWriter_SUMO::writeNetwork(), NWWriter_OpenDrive::writeNetwork(), NWWriter_MATSim::writeNetwork(), NWFrame::writeNetwork(), NWWriter_XML::writeNodes(), RODFDetector::writeSingleSpeedTrigger(), RODFDetectorCon::writeSpeedTrigger(), NWWriter_XML::writeTrafficLights(), and RODFDetectorCon::writeValidationDetectors().

OutputDevice & OutputDevice::getDeviceByOption ( const std::string &  name) throw (IOError, InvalidArgument) [static, inherited]

Returns the device described by the option.

Returns the device named by the option. If the option is unknown, unset or the device was not created before, InvalidArgument is thrown.

Please note, that we do not have to consider the "application base" herein.

Parameters:
[in]nameThe name of the option to use for retrieving the output definition
Returns:
The corresponding (built or existing) device
Exceptions:
IOErrorIf the output could not be built for any reason (error message is supplied)
InvalidArgumentIf the option with the given name does not exist

Definition at line 106 of file OutputDevice.cpp.

References OutputDevice::getDevice(), OptionsCont::getOptions(), and OptionsCont::getString().

Referenced by MSPersonControl::erase(), MSDevice_Vehroutes::generateOutput(), MSDevice_Tripinfo::generateOutput(), MSDevice_HBEFA::generateOutput(), main(), MSVehicleControl::scheduleVehicleRemoval(), and MSNet::writeOutput().

std::ostream & OutputDevice_Network::getOStream ( ) throw () [protected, virtual]

Returns the associated ostream.

The stream is an ostringstream, actually, into which the message is written. It is sent when postWriteHook is called.

Returns:
The used stream
See also:
postWriteHook

Implements OutputDevice.

Definition at line 61 of file OutputDevice_Network.cpp.

References myMessage.

OutputDevice & OutputDevice::indent ( ) throw () [inherited]

Adds indentation.

An intendation, depending on the current xml-element-stack size, is written.

Returns:
The OutputDevice for further processing

Definition at line 195 of file OutputDevice.cpp.

References OutputDevice::getOStream(), OutputDevice::myDefaultIndentation, OutputDevice::myXMLStack, and OutputDevice::postWriteHook().

void OutputDevice::inform ( const std::string &  msg) [inherited]

Retrieves a message to this device.

Implementation of the MessageRetriever interface. Writes the given message to the output device.

Parameters:
[in]msgThe msg to write to the device

Definition at line 239 of file OutputDevice.cpp.

References OutputDevice::getOStream(), and OutputDevice::postWriteHook().

bool OutputDevice::ok ( ) throw () [virtual, inherited]

returns the information whether one can write into the device

Returns:
Whether the device can be used (stream is good)

Definition at line 151 of file OutputDevice.cpp.

References OutputDevice::getOStream().

OutputDevice & OutputDevice::openTag ( const SumoXMLTag &  xmlElement) throw () [inherited]

Opens an XML tag.

Helper method which finds the correct string before calling openTag.

Parameters:
[in]xmlElementId of the element to open
Returns:
The OutputDevice for further processing

Definition at line 212 of file OutputDevice.cpp.

References toString().

template<class T >
OutputDevice& OutputDevice::operator<< ( const T &  t) [inline, inherited]

Abstract output operator.

Returns:
The OutputDevice for further processing

Definition at line 260 of file OutputDevice.h.

References OutputDevice::getOStream(), and OutputDevice::postWriteHook().

void OutputDevice_Network::postWriteHook ( ) throw () [protected, virtual]

Sends the data which was written to the string stream over the socket.

Converts the stored message into a vector of chars and sends them via to the socket implementation. Resets the message, afterwards.

Reimplemented from OutputDevice.

Definition at line 67 of file OutputDevice_Network.cpp.

References myMessage, mySocket, and tcpip::Socket::send().

std::string OutputDevice::realString ( const SUMOReal  v,
const int  precision = OUTPUT_ACCURACY 
) [static, inherited]

Abstract output operator.

Returns:
The OutputDevice for further processing

Definition at line 125 of file OutputDevice.cpp.

Referenced by MSDevice_HBEFA::generateOutput(), and MSMeanData_HBEFA::MSLaneMeanDataValues::write().

void OutputDevice::setPrecision ( unsigned int  precision = OUTPUT_ACCURACY) throw () [inherited]

Sets the precison or resets it to default.

Parameters:
[in]precisionThe accuracy (number of digits behind '.') to set

Definition at line 170 of file OutputDevice.cpp.

Referenced by MSVTypeProbe::execute(), OutputDevice::getDevice(), NWWriter_XML::writeEdgesAndConnections(), NWWriter_SUMO::writeLocation(), NWWriter_XML::writeNodes(), RORouteDef_Alternatives::writeXMLDefinition(), and RORoute::writeXMLDefinition().

template<class T >
OutputDevice& OutputDevice::writeAttr ( const SumoXMLAttr  attr,
const T &  val 
) [inline, inherited]

writes an named attribute

Parameters:
[in]attrThe attribute (name)
[in]valThe attribute value

Definition at line 242 of file OutputDevice.h.

References toString(), and OutputDevice::writeAttr().

bool OutputDevice::writeXMLHeader ( const std::string &  rootElement,
const std::string  xmlParams = "",
const std::string &  attrs = "",
const std::string &  comment = "" 
) throw () [inherited]

Writes an XML header with optional configuration.

If something has been written (myXMLStack is not empty), nothing is written and false returned.

Parameters:
[in]rootElementThe root element to use
[in]xmlParamsAdditional parameters (such as encoding) to include in the <?xml> declaration
[in]attrsAdditional attributes to save within the rootElement
[in]commentAdditional comment (saved in front the rootElement)
Todo:

Check which parameter is used herein

Describe what is saved

Definition at line 176 of file OutputDevice.cpp.

References OptionsCont::getOptions(), and OptionsCont::writeXMLHeader().

Referenced by Command_SaveTLSState::Command_SaveTLSState(), Command_SaveTLSSwitches::Command_SaveTLSSwitches(), Command_SaveTLSSwitchStates::Command_SaveTLSSwitchStates(), OutputDevice::createDeviceByOption(), MSVTypeProbe::MSVTypeProbe(), RODFDetectorCon::save(), PCPolyContainer::save(), RODFDetectorCon::saveAsPOIs(), RODFDetectorCon::saveRoutes(), NWWriter_XML::writeEdgesAndConnections(), RODFDetector::writeEmitterDefinition(), RODFDetectorCon::writeEmitterPOIs(), RODFDetectorCon::writeEmitters(), RODFDetectorCon::writeEndRerouterDetectors(), NWWriter_SUMO::writeNetwork(), NWWriter_XML::writeNodes(), RODFDetector::writeSingleSpeedTrigger(), RODFDetectorCon::writeSpeedTrigger(), NWWriter_XML::writeTrafficLights(), and RODFDetectorCon::writeValidationDetectors().


Field Documentation

std::ostringstream OutputDevice_Network::myMessage [private]

packet buffer

Definition at line 95 of file OutputDevice_Network.h.

Referenced by getOStream(), and postWriteHook().

the socket to transfer the data

Definition at line 98 of file OutputDevice_Network.h.

Referenced by postWriteHook(), and ~OutputDevice_Network().


The documentation for this class was generated from the following files:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines