Files.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // CERTI - HLA RunTime Infrastructure
00003 // Copyright (C) 2002-2005  ONERA
00004 //
00005 // This file is part of CERTI
00006 //
00007 // CERTI is free software ; you can redistribute it and/or modify
00008 // it under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation ; either version 2 of the License, or
00010 // (at your option) any later version.
00011 //
00012 // CERTI is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY ; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program ; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00020 //
00021 // $Id: Files.cc,v 3.10 2008/05/07 15:37:38 erk Exp $
00022 // ----------------------------------------------------------------------------
00023 
00024 #include <config.h>
00025 #include "Files.hh"
00026 
00027 using std::list ;
00028 
00029 namespace certi {
00030 namespace rtia {
00031 
00032 // ----------------------------------------------------------------------------
00034 void
00035 Queues::nextTsoDate(bool &found, FederationTime &time)
00036 {
00037     NetworkMessage *msg_buffer ;
00038 
00039     if (tsos.empty()) {
00040         found = false ;
00041         time = -1.0 ;
00042     }
00043     else {
00044         msg_buffer = tsos.front();
00045         found = true ;
00046         time = msg_buffer->getDate();
00047     }
00048 }
00049 
00050 // ----------------------------------------------------------------------------
00054 NetworkMessage *
00055 Queues::giveCommandMessage(bool &msg_donne, bool &msg_restant)
00056 {
00057     NetworkMessage *msg ;
00058 
00059     msg_donne = false ;
00060     msg_restant = false ;
00061 
00062     if (!commands.empty()) {
00063         // remove from list but keep pointer to execute ExecuterServiceFedere.
00064         msg = commands.front();
00065         commands.pop_front();
00066         msg_donne = true ;
00067 
00068         if (!commands.empty())
00069             msg_restant = true ;
00070 
00071         return msg ;
00072     }
00073     else return 0 ;
00074 }
00075 
00076 // ----------------------------------------------------------------------------
00078 NetworkMessage *
00079 Queues::giveFifoMessage(bool &msg_donne, bool &msg_restant)
00080 {
00081     NetworkMessage *msg_tampon ;
00082 
00083     msg_donne = false ;
00084     msg_restant = false ;
00085 
00086     if (!fifos.empty()) {
00087         // remove from list but keep pointer to execute ExecuterServiceFedere.
00088         msg_tampon = fifos.front();
00089         fifos.pop_front();
00090         msg_donne = true ;
00091 
00092         if (!fifos.empty())
00093             msg_restant = true ;
00094 
00095         return msg_tampon ;
00096     }
00097     else return 0 ;
00098 }
00099 
00100 // ----------------------------------------------------------------------------
00104 NetworkMessage *
00105 Queues::giveTsoMessage(FederationTime heure_logique,
00106                        bool &msg_donne,
00107                        bool &msg_restant)
00108 {
00109     NetworkMessage *buffer_msg = NULL ;
00110 
00111     msg_donne = false ;
00112     msg_restant = false ;
00113 
00114     if (!tsos.empty()) {
00115         buffer_msg = tsos.front();
00116         if (buffer_msg->getDate() <= heure_logique) {
00117             // remove from list but keep pointer to execute
00118             // ExecuterServiceFedere.
00119             tsos.pop_front();
00120             msg_donne = true ;
00121 
00122             // Test if next TSO message can be sent.
00123             if (!tsos.empty()) {
00124                 NetworkMessage *buffer_msg2 ;
00125                 buffer_msg2 = tsos.front();
00126 
00127                 if (buffer_msg2->getDate() <= heure_logique)
00128                     msg_restant = true ;
00129             }
00130             return buffer_msg ;
00131         }
00132         else return NULL;
00133     }
00134     else return NULL;
00135 }
00136 
00137 // ----------------------------------------------------------------------------
00141 void
00142 Queues::insertBeginCommand(NetworkMessage *msg)
00143 {
00144     commands.push_front(msg);
00145 }
00146 
00147 // ----------------------------------------------------------------------------
00149 void
00150 Queues::insertLastCommand(NetworkMessage *msg)
00151 {
00152     commands.push_back(msg);
00153 }
00154 
00155 // ----------------------------------------------------------------------------
00157 void
00158 Queues::insertFifoMessage(NetworkMessage *msg)
00159 {
00160     fifos.push_back(msg);
00161 }
00162 
00163 // ----------------------------------------------------------------------------
00165 void
00166 Queues::insertTsoMessage(NetworkMessage *msg)
00167 {
00168     if (tsos.empty()) {
00169         tsos.push_front(msg);
00170         return ;
00171     }
00172     else {
00173         list<NetworkMessage *>::iterator i ;
00174         for (i = tsos.begin(); i != tsos.end(); i++) {
00175             // stricly greater because we want to place new message behind
00176             // older ones with same logical time and thus keep receive order
00177             // in list.
00178             if ((*i)->getDate() > msg->getDate()) {
00179                 tsos.insert(i, msg);
00180                 return ;
00181             }
00182         }
00183     }
00184     tsos.push_back(msg);
00185 }
00186 
00187 }} // namespaces
00188 
00189 // $Id: Files.cc,v 3.10 2008/05/07 15:37:38 erk Exp $

Generated on Thu Apr 30 15:53:49 2009 for CERTIDeveloperDocumentation by doxygen 1.5.5