Home Libraries Author Links

binmsg.hpp

Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the SysToMath C++ Libraries package (LibStmCpp).
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Tom Michaelis, SysToMath.
00018  * Portions created by the Initial Developer are Copyright (C) 2003-2006
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /******************************************************************************
00038  *                            First Release 2003-03-15
00039  ******************************************************************************/
00040 
00041 
00078 #ifndef STM_TOOLAIDS_BINMSG_HPP
00079 #define STM_TOOLAIDS_BINMSG_HPP
00080 
00081 
00082 // Include header files for implementation.
00083 #include <stm/toolaids/impl/xbinmsg.hpp>
00084 
00085 
00086 // Include BaseMessage base class template implementation.
00087 #include <stm/toolaids/impl/xbinmsg.hpp>
00088 
00089 
00090 namespace stm
00091 {
00092 
00093 
00094 namespace tools
00095 {
00096 
00097 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 template <class DataT, class InputRangeT, class ContextT>
00110 class BaseMessageContext :
00111     private local::xBaseMessageContext<DataT, InputRangeT, ContextT>
00112 {
00114     typedef local::xBaseMessageContext
00115     <
00116         DataT,
00117         InputRangeT,
00118         ContextT
00119     > BaseMessageContextImpl;
00120 
00121 public:
00123     typedef DataT data_type;
00124 
00127     typedef InputRangeT inputrange_type;
00128 
00130     typedef ContextT context_type;
00131     
00133     typedef MsgTimestamp Timestamp;
00134 
00138     BaseMessageContext (data_type &data, inputrange_type &input);
00139 
00144     const std::string &type () const;
00145 
00148     void setType (const std::string &type);
00149 
00154     const Timestamp &timestamp () const;
00155 
00158     void setTimestamp (const Timestamp &timestamp);
00159 
00162     data_type &data ();
00163 
00166     inputrange_type &input ();
00167 };
00168 
00169 
00181 template <class ContextT>
00182 class BaseMessage :
00183     public byte_iterator_range,
00184     private local::xBaseMessage<ContextT>
00185 {
00187     typedef local::xBaseMessage<ContextT> BaseMessageImpl;
00188 
00189 public:
00191     typedef ContextT context_type;
00192 
00194     typedef BaseMessage<ContextT> basemessage_type;
00195 
00197     typedef typename context_type::Timestamp Timestamp;
00198 
00200     enum
00201     {
00202         WordSize         = 4
00203     };
00204 
00206     enum
00207     {
00208         NoFlags          = 0x00000000,
00209         ThrowOnError     = 0x00000001
00210     };
00211 
00213     enum
00214     {
00215         NoError          = 0x00000000,
00216         OutOfSync        = 0x00000001,
00217         ConsistencyError = 0x00000002
00218     };
00219 
00222     virtual ~BaseMessage ();
00223 
00226     virtual const std::string &type () const = 0;
00227 
00230     dword flags () const;
00231 
00234     dword status () const;
00235 
00238     const Timestamp &timestamp () const;
00239 
00242     context_type &context ();
00243 
00247     const byte_iterator_range &body () const;
00248 
00249 protected:
00253     BaseMessage
00254     (
00255         const byte *first,
00256         const byte *last,
00257         context_type &context,
00258         dword flags = NoFlags,
00259         dword status = NoError
00260     );
00261 
00264     void setStatus (dword val);
00265 
00269     void setBody (const byte_iterator_range &body);
00270 
00276     void setUdpTimestamp
00277     (
00278         word bfn,
00279         dword bordTimeSec,
00280         word boardTimeMs,
00281         dword seqNo
00282     );
00283 
00289     void setFpgaTimestamp
00290     (
00291         word bfn,
00292         byte slot,
00293         word chip
00294     );
00295 };
00296 
00297 
00301 }  // namespace tools.
00302 
00303 
00304 }  // namespace stm.
00305 
00306 
00307 // Include BinMessageContext base class template implementation.
00308 #include <stm/toolaids/impl/xbinmsg.hpp>
00309 
00310 
00311 namespace stm
00312 {
00313 
00314 
00315 namespace tools
00316 {
00317 
00318 
00323 
00324 
00325 
00326 
00327 
00328 
00329 
00330 
00331 template <class DataT, class InputRangeT, class ContextT>
00332 class BinMessageContext :
00333     public BaseMessageContext <DataT, InputRangeT, ContextT>,
00334     private local::xBinMessageContext<ContextT>
00335 {
00337     typedef local::xBinMessageContext<ContextT> BinMessageContextImpl;
00338 
00340     friend class local::xBinMessage<ContextT>;
00341 
00342 public:
00344     typedef DataT data_type;
00345 
00350     typedef InputRangeT inputrange_type;
00351 
00353     typedef ContextT context_type;
00354 
00356     typedef BaseMessage<ContextT> basemessage_type;
00357 
00361     class Gap : private local::xBinMessageGap
00362     {
00363         friend class BinMessageContext<DataT, InputRangeT, ContextT>;
00364 
00365     public:
00367         Gap ();
00368 
00370         operator bool () const;
00371 
00373         long long offset () const;
00374 
00376         long long length () const;
00377     };
00378 
00381     BinMessageContext (data_type &data, inputrange_type &input);
00382 
00386     const Gap &gap () const;
00387 
00392     template <template <class> class Message> bool registerMessageType ();
00393 };
00394 
00395 
00403 template <class ContextT>
00404 class BinMessage :
00405     public byte_iterator_range,
00406     private local::xBinMessage<ContextT>
00407 {
00409     typedef local::xBinMessage<ContextT> BinMessageImpl;
00410 
00411 public:
00413     typedef ContextT context_type;
00414 
00416     typedef BaseMessage<ContextT> basemessage_type;
00417 
00419     typedef typename basemessage_type::Timestamp Timestamp;
00420 
00422     enum
00423     {
00424         NoFlags          = 0x00000000,
00425         ThrowOnError     = basemessage_type::ThrowOnError
00426     };
00427 
00429     enum
00430     {
00431         NoError          = 0x00000000,
00432         OutOfSync        = basemessage_type::OutOfSync,
00433         ConsistencyError = basemessage_type::ConsistencyError
00434     };
00435 
00459     BinMessage
00460     (
00461         const byte *first,
00462         const byte *last,
00463         context_type &context,
00464         dword flags = NoFlags
00465     ) throw (std::exception);
00466 
00469     virtual ~BinMessage ();
00470 
00473     const std::string &type () const;
00474 
00477     dword flags () const;
00478 
00481     dword status () const;
00482 
00485     const Timestamp &timestamp () const;
00486 
00490     const byte_iterator_range &body () const;
00491 
00494     context_type &context ();
00495 };
00496 
00497 
00501 }  // namespace tools.
00502 
00503 
00504 }  // namespace stm.
00505 
00506 
00507 // Include inline and template implementation.
00508 #include <stm/toolaids/impl/xbinmsg.hpp>
00509 
00510 
00511 #endif  // STM_TOOLAIDS_BINMSG_HPP

© Copyright Tom Michaelis 2002-2007

Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).