summaryrefslogtreecommitdiff
path: root/maximus/sci/src/SciServer.cpp
diff options
context:
space:
mode:
authorburet2007-09-05 17:40:25 +0000
committerburet2007-09-05 17:40:25 +0000
commit1b49d1b75981cbb1ee814bfbf0d840b4bf446edc (patch)
treea97e5d621c11686715584134be395b5561a97d2b /maximus/sci/src/SciServer.cpp
parentd759876fb0d38dec53ce050c186b05b5f789bd1e (diff)
Maximus simulator: fixes #8.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@667 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'maximus/sci/src/SciServer.cpp')
-rw-r--r--maximus/sci/src/SciServer.cpp197
1 files changed, 100 insertions, 97 deletions
diff --git a/maximus/sci/src/SciServer.cpp b/maximus/sci/src/SciServer.cpp
index 6db7de68ce..731a5f8136 100644
--- a/maximus/sci/src/SciServer.cpp
+++ b/maximus/sci/src/SciServer.cpp
@@ -185,6 +185,10 @@ bool SciServer::process ( )
if((len = read(fd_index, &header, sizeof(struct Sci_Msg_Header))) < header_len)
{
clog << logger(LOG_ERROR) << "header read error: len = " << dec << len << ", errno = " << errno << endl;
+ if (0 == len)
+ {
+ throw Error(__PRETTY_FUNCTION__, "Header read error: len = 0");
+ }
continue;
}
else
@@ -220,6 +224,10 @@ bool SciServer::process ( )
{
clog << logger(LOG_ERROR) << "data read error: len = " << dec << len << ", errno = " << errno << endl;
free(buffer);
+ if (0 == len)
+ {
+ throw Error(__PRETTY_FUNCTION__, "Data read error: len = 0");
+ }
continue;
}
receiveMsg(&header, header.length, buffer);
@@ -285,8 +293,10 @@ bool SciServer::log ( ) const
throw Error(__PRETTY_FUNCTION__, "A station pointer is NULL");
}
}
+
+ delete [] pBuffer;
}
-
+
stationLogFile.close();
return bLog;
@@ -369,78 +379,60 @@ bool SciServer::sendSciMsg ( const SciMsg & sci_msg_to_send ) const
{
logFunction();
bool bSend = false;
-
+
// Retrieve destination station
//
- Station * destination = NULL;
- if ( (NULL != mpListOfStations) && (!mpListOfStations->empty()) )
+ if (NULL != mpListOfStations)
{
+ // Skim through stations list
+ //
for (StationsList::const_iterator it = mpListOfStations->begin(); it != mpListOfStations->end(); ++it)
{
- if (NULL != *it)
+ // Before sending a SCI msg, check that station status is 'IDLE'
+ //
+ if ( (NULL != *it)
+ && ((*it)->getStationId() == sci_msg_to_send.getSciMsgStationId())
+ && (MAXIMUS_STATION_STATUS_IDLE == (*it)->getStationStatus()) )
{
- if ( ((*it)->getStationId()) == sci_msg_to_send.getSciMsgStationId() )
+ bSend = true;
+
+ // Write data into output pipe
+ //
+ int length = 0;
+ int totalLength = 0;
+ while(totalLength < (int)sci_msg_to_send.getSciMsgDataLength())
{
- destination = (*it);
-
- // Before sending a SCI msg, check that station status is 'IDLE'
- // Then, station status is set to 'BUSY'
- // Station status will stay 'BUSY' until a system 'IDLE' msg will be received
- //
- if (MAXIMUS_STATION_STATUS_IDLE != destination->getStationStatus())
+ length = write((*it)->getOutputFileDescriptor(), sci_msg_to_send.getSciMsgData() + totalLength, sci_msg_to_send.getSciMsgDataLength()-totalLength);
+ if(length < 0)
{
- clog << logger(LOG_ERROR) << "cannot send message because station status is not IDLE!" << endl;
+ clog << logger(LOG_ERROR) << "write data failed!" << endl;
+ bSend = false;
}
- else
- {
- bSend = true;
- }
-
- it = mpListOfStations->end();
- --it;
+ totalLength += length;
}
- }
- else
- {
- throw Error(__PRETTY_FUNCTION__, "Station pointer is NULL");
- }
- }
- }
- if (bSend)
- {
- if (NULL != destination)
- {
- // Write data into output pipe
- //
- int length=0;
- int totalLength=0;
- while(totalLength < (int)sci_msg_to_send.getSciMsgDataLength())
- {
- length = write(destination->getOutputFileDescriptor(), sci_msg_to_send.getSciMsgData() + totalLength, sci_msg_to_send.getSciMsgDataLength()-totalLength);
- if(length < 0)
+ if (bSend)
{
- clog << logger(LOG_ERROR) << "write data failed!" << endl;
- bSend = false;
+ // Station status is set to 'BUSY'
+ // Station status will stay 'BUSY' until all system 'IDLE' msgs will be received
+ //
+ (*it)->setStationStatus(MAXIMUS_STATION_STATUS_BUSY);
+ (*it)->incrementStationIdleCounter();
+ clog << logger(LOG_COM) << "<--- send " << displaySciMsgType(sci_msg_to_send.getSciMsgHeader()->type) \
+ << " SCI message to station " << dec << (*it)->getStationId() \
+ << " (0x" << setfill('0') << setw(4) << uppercase << hex << (*it)->getStationId() << ")" << dec << endl;
}
- totalLength += length;
+
+ it = mpListOfStations->end();
+ --it;
}
}
- else
- {
- clog << logger(LOG_ERROR) << "destination station not found!" << endl;
- bSend = false;
- }
}
-
- if (bSend)
+ else
{
- destination->setStationStatus(MAXIMUS_STATION_STATUS_BUSY);
- destination->incrementStationIdleCounter();
- clog << logger(LOG_COM) << "<--- send " << displaySciMsgType(sci_msg_to_send.getSciMsgHeader()->type) << " SCI message to station " << dec << destination->getStationId() << " (0x" << setfill('0') << setw(4) << uppercase << hex << destination->getStationId() << ")" << dec << endl;
+ throw Error(__PRETTY_FUNCTION__, "Stations list pointer is NULL");
}
- destination = NULL;
-
+
return bSend;
}
@@ -449,62 +441,73 @@ bool SciServer::sendSciMsgToAllActiveStations ( SciMsg & sci_msg_to_send ) const
{
logFunction();
bool bSend = false;
-
- // Skim through stations list
- //
- if ( (NULL != mpListOfStations) && (!mpListOfStations->empty()) )
+
+ if (NULL != mpListOfStations)
{
+ const Sci_Msg_Station_Id txStationId = sci_msg_to_send.getSciMsgStationId(); // get id of the transmitting station
int length;
int totalLength;
-
+ bool bWrite;
+
+ // Skim through stations list
+ //
for (StationsList::const_iterator it = mpListOfStations->begin(); it != mpListOfStations->end(); ++it)
{
- if (NULL != *it)
+ // Send message to all active stations except the sender
+ // Before filling in the message, set station id to the destination station
+ //
+ if ( (NULL != *it)
+ && (txStationId != (*it)->getStationId())
+ && (MAXIMUS_STATION_STATUS_DEACTIVATED != (*it)->getStationStatus())
+ && sci_msg_to_send.setSciMsgStationId((*it)->getStationId())
+ && fillSciMsg(sci_msg_to_send) )
{
- // Send to all stations except the sender
+ bSend = true;
+
+ // Write data into output pipe
//
- if ( (*it)->getStationId() != sci_msg_to_send.getSciMsgStationId() )
+ length = 0;
+ totalLength = 0;
+ bWrite = true;
+ while(totalLength < (int)sci_msg_to_send.getSciMsgDataLength())
{
- // Before filling in the message, set station id to the destination station
- //
- bSend = sci_msg_to_send.setSciMsgStationId((*it)->getStationId());
- bSend &= fillSciMsg(sci_msg_to_send);
-
- // Before sending a SCI msg, check that station status is not 'DEACTIVATED'
- // Then, station status is set to 'BUSY'
- // Station status will stay 'BUSY' until a system 'IDLE' msg will be received
- //
- if (MAXIMUS_STATION_STATUS_DEACTIVATED != (*it)->getStationStatus())
+ length = write((*it)->getOutputFileDescriptor(), sci_msg_to_send.getSciMsgData() + totalLength, sci_msg_to_send.getSciMsgDataLength()-totalLength);
+ if(length < 0)
{
- (*it)->setStationStatus(MAXIMUS_STATION_STATUS_BUSY);
- (*it)->incrementStationIdleCounter();
-
- // Write data into output pipe
- //
- length = 0;
- totalLength = 0;
- while(totalLength < (int)sci_msg_to_send.getSciMsgDataLength())
- {
- length = write((*it)->getOutputFileDescriptor(), sci_msg_to_send.getSciMsgData() + totalLength, sci_msg_to_send.getSciMsgDataLength()-totalLength);
- if(length < 0)
- {
- clog << logger(LOG_ERROR) << "write data failed!" << endl;
- }
- totalLength += length;
- }
-
- clog << logger(LOG_COM) << "<--- send " << displaySciMsgType(sci_msg_to_send.getSciMsgHeader()->type) << " SCI message to all stations" << endl;
- bSend = true;
+ clog << logger(LOG_ERROR) << "write data failed!" << endl;
+ bWrite = false;
+ bSend = false;
}
+ totalLength += length;
+ }
+
+ if (bWrite)
+ {
+ // Station status is set to 'BUSY'
+ // Station status will stay 'BUSY' until all system 'IDLE' msgs will be received
+ //
+ (*it)->setStationStatus(MAXIMUS_STATION_STATUS_BUSY);
+ (*it)->incrementStationIdleCounter();
}
- }
- else
- {
- throw Error(__PRETTY_FUNCTION__, "A station pointer is NULL");
}
}
}
-
+ else
+ {
+ throw Error(__PRETTY_FUNCTION__, "Stations list pointer is NULL");
+ }
+
+ if (bSend)
+ {
+ clog << logger(LOG_COM) << "<--- send " << displaySciMsgType(sci_msg_to_send.getSciMsgHeader()->type) \
+ << " SCI message to all stations" << endl;
+ }
+ else
+ {
+ clog << logger(LOG_ERROR) << "did not send " << displaySciMsgType(sci_msg_to_send.getSciMsgHeader()->type) \
+ << " SCI message to all stations!" << endl;
+ }
+
return bSend;
}