# BasicMessage.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-libCERTI
    00006 //
    00007 // CERTI-libCERTI is free software ; you can redistribute it and/or
    00008 // modify it under the terms of the GNU Lesser General Public License
    00009 // as published by the Free Software Foundation ; either version 2 of
    00010 // the License, or (at your option) any later version.
    00011 //
    00012 // CERTI-libCERTI is distributed in the hope that it will be useful, but
    00013 // WITHOUT ANY WARRANTY ; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    00015 // Lesser General Public License for more details.
    00016 //
    00017 // You should have received a copy of the GNU Lesser General Public
    00018 // License along with this program ; if not, write to the Free Software
    00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
    00020 // USA
    00021 //
    00022 // $Id: BasicMessage.cc,v 3.12 2008/05/29 12:20:35 rousse Exp $
    00023 // ----------------------------------------------------------------------------
    00024
    00025
    00026 #include "BasicMessage.hh"
    00027 #include "PrettyDebug.hh"
    00028
    00029 #include <cassert>
    00030
    00031 using std::vector ;
    00032 using std::endl ;
    00033
    00034 static pdCDebug D("MESSAGE", __FILE__);
    00035
    00036 namespace certi {
    00037
    00038 BasicMessage::~BasicMessage() {
    00039
    00040 }
    00041
    00042 // ----------------------------------------------------------------------------
    00045 void
    00046 BasicMessage::setExtents(const std::vector<Extent> &e)
    00047 {
    00048     extents = e ;
    00049     assert(extents.size() == e.size());
    00050 }
    00051
    00052 // ----------------------------------------------------------------------------
    00055 const vector<Extent> &
    00056 BasicMessage::getExtents() const
    00057 {
    00058     return extents ;
    00059 }
    00060
    00061 void
    00062 BasicMessage::serialize(MessageBuffer& msgBuffer) {
    00063     /* Write Extent */
    00064     D[pdDebug] << "Serialize " << extents.size() << " extent(s)" << endl;
    00065     msgBuffer.write_int32(static_cast<int32_t>(extents.size()));
    00066     if (extents.size() > 0) {
    00067         int n = extents[0].size();
    00068         msgBuffer.write_int32(static_cast<int32_t>(n));
    00069         D[pdDebug] << "Extent with " << n << " range(s)" << endl;
    00070         for (unsigned int i = 0; i < extents.size(); ++i) {
    00071             const Extent &e = extents[i];
    00072
    00073             for (int h = 1; h <= n; ++h) {
    00074                 msgBuffer.write_int32(static_cast<int32_t>(e.getRangeLowerBound(h)));
    00075                 msgBuffer.write_int32(static_cast<int32_t>(e.getRangeUpperBound(h)));
    00076             }
    00077         }
    00078     }
    00079     /* Write Region */
    00080     int32_t n = regions.size();
    00081     msgBuffer.write_int32(n);
    00082     for (int i = 0; i < n; ++i) {
    00083         msgBuffer.write_int32(regions[i]);
    00084     }
    00085 } /* end of serialize */
    00086
    00087 void
    00088 BasicMessage::deserialize(MessageBuffer& msgBuffer) {
    00089     /* Deserialize Extents */
    00090     int32_t nb_extents;
    00091     int32_t temp;
    00092     msgBuffer.read_int32(&nb_extents);
    00093     D[pdDebug] << "Deserialize " << nb_extents << " extent(s)" << endl;
    00094
    00095     extents.clear();
    00096     if (nb_extents > 0) {
    00097         extents.reserve(nb_extents);
    00098         int32_t nb_dimensions;
    00099         msgBuffer.read_int32(&nb_dimensions);
    00100         D[pdDebug] << "Extent with " << nb_dimensions << " range(s)" << endl;
    00101         for (long i = 0; i < nb_extents; ++i) {
    00102             Extent e(nb_dimensions);
    00103
    00104             for (long h = 1; h <= nb_dimensions; ++h) {
    00105                 msgBuffer.read_int32(&temp);
    00106                 e.setRangeLowerBound(h, temp);
    00107                 msgBuffer.read_int32(&temp);
    00108                 e.setRangeUpperBound(h, temp);
    00109             }
    00110             extents.push_back(e);
    00111         }
    00112     }
    00113     /* Deserialize Regions */
    00114     int32_t n;
    00115     msgBuffer.read_int32(&n);
    00116     regions.clear();
    00117     regions.reserve(n);
    00118     for (int i = 0; i < n; ++i) {
    00119         msgBuffer.read_int32(&temp);
    00120         regions.push_back(temp);
    00121     }
    00122
    00123 } /* end of serialize */
    00124
    00125 // ----------------------------------------------------------------------------
    00130 void
    00131 BasicMessage::writeExtents(MessageBuffer& msgBuffer) const
    00132 {
    00133     D[pdDebug] << "Write " << extents.size() << " extent(s)" << endl ;
    00134
    00135     msgBuffer.write_int64(extents.size());
    00136     if (extents.size() > 0) {
    00137     int n = extents[0].size();
    00138     msgBuffer.write_int64(n);
    00139     D[pdDebug] << "Extent with " << n << " range(s)" << endl ;
    00140
    00141     for (unsigned int i = 0 ; i < extents.size(); ++i) {
    00142         const Extent &e = extents[i] ;
    00143
    00144         for (int h = 1 ; h <= n ; ++h) {
    00145         msgBuffer.write_int64(e.getRangeLowerBound(h));
    00146         msgBuffer.write_int64(e.getRangeUpperBound(h));
    00147         }
    00148     }
    00149     }
    00150 }
    00151
    00152 // ----------------------------------------------------------------------------
    00157 void
    00158 BasicMessage::readExtents(MessageBuffer& msgBuffer)
    00159 {
    00160     long nb_extents = msgBuffer.read_int64();
    00161     D[pdDebug] << "Read " << nb_extents << " extent(s)" << endl ;
    00162
    00163     extents.clear();
    00164     if (nb_extents > 0) {
    00165     extents.reserve(nb_extents);
    00166     long nb_dimensions = msgBuffer.read_int64();
    00167     D[pdDebug] << "Extent with " << nb_dimensions << " range(s)" << endl ;
    00168     for (long i = 0 ; i < nb_extents ; ++i) {
    00169         Extent e(nb_dimensions);
    00170         for (long h = 1 ; h <= nb_dimensions ; ++h) {
    00171         e.setRangeLowerBound(h, msgBuffer.read_int64());
    00172         e.setRangeUpperBound(h, msgBuffer.read_int64());
    00173         }
    00174         extents.push_back(e);
    00175     }
    00176     }
    00177 }
    00178
    00179 // ----------------------------------------------------------------------------
    00180 void
    00181 BasicMessage::writeRegions(MessageBuffer& msgBuffer)
    00182 {
    00183     long n = regions.size();
    00184     msgBuffer.write_int64(n);
    00185     for (int i = 0 ; i < n ; ++i) {
    00186     msgBuffer.write_int64(regions[i]);
    00187     }
    00188 }
    00189
    00190 // ----------------------------------------------------------------------------
    00191 void
    00192 BasicMessage::readRegions(MessageBuffer& msgBuffer)
    00193 {
    00194     long n = msgBuffer.read_int64();
    00195     regions.clear();
    00196     regions.reserve(n);
    00197     for (int i = 0; i < n; ++i) {
    00198     regions.push_back(msgBuffer.read_int64());
    00199     }
    00200 }
    00201
    00202 // ----------------------------------------------------------------------------
    00203 void
    00204 BasicMessage::setRegions(const BaseRegion *reg[], int size)
    00205 {
    00206     regions.resize(size);
    00207
    00208     for (int i = 0 ; i < size ; ++i) {
    00209         regions[i] = reg[i]->getHandle();
    00210     }
    00211 }
    00212
    00213 void
    00214 BasicMessage::setRegions(const std::vector<RegionHandle> &src)
    00215 {
    00216     regions = src ;
    00217 }
    00218
    00219 // ----------------------------------------------------------------------------
    00220 const std::vector<RegionHandle> &
    00221 BasicMessage::getRegions() const
    00222 {
    00223     return regions ;
    00224 }
    00225
    00226 } // namespace certi
    00227
    00228 // $Id: BasicMessage.cc,v 3.12 2008/05/29 12:20:35 rousse Exp $