/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM is free software; you can redistribute it and/or modify it    
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; only version 2 of the License.      
 * 
 * NMM is distributed in the hope that it will be useful, but WITHOUT 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 
 * License for more details.  
 * 
 * You should have received a copy of the GNU General Public License 
 * along with NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef NMM_TIMESTAMP_HPP
#define NMM_TIMESTAMP_HPP NMM_TIMESTAMP_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/utils/time/Time.hpp"

#include "visibility.hpp"

namespace NMM {
  
  class IValueStream;
  class OValueStream;
  
   
  /** The Timestamp contains time information about one message.
   *
   * With timestamps it is possible to send time information for each 
   * data buffer within the stream. 
   */
  struct Timestamp {
    Timestamp() : sync_time(0), stream_counter(0), is_valid(false), is_set(false) {}
    Time sync_time;          //! This time is used for synchronization.
    nmm_int64 stream_counter;    //! The number of the buffer in the stream.
    nmm_bool is_valid;           //! True if the timestamp has been set correctly.
    nmm_bool is_set;             //! True if the timestamp was set (also true for invalid timestamps)
  };

  /** Returns true if a is less than b.
   *
   * @param a first timestamp
   * @param b second timestamp
   * @return true if a < b, false otherwise
   */
  inline bool operator<(const Timestamp& a, const Timestamp& b) {
    return (a.sync_time < b.sync_time);
  };

  /** Returns true if a is biffer than b.
   *
   * @param a first timestamp
   * @param b second timestamp
   * @return true if a > b, false otherwise
   */
  inline bool operator>(const Timestamp& a, const Timestamp& b) {
    return (a.sync_time > b.sync_time);
  };

  /** Returns true if a is less or equal than b.
   *
   * @param a first timestamp
   * @param b second timestamp
   * @return true if a <= b, false otherwise
   */
  inline bool operator<=(const Timestamp& a, const Timestamp& b) {
    return (a.sync_time <= b.sync_time);
  };

  /** Returns true if a is greater or equal than b.
   *
   * @param a first timestamp
   * @param b second timestamp
   * @return true if a >= b, false otherwise
   */
  inline bool operator>=(const Timestamp& a, const Timestamp& b) {
    return (a.sync_time >= b.sync_time);
  };
  
  /** The output operator of Timestamp.
   *
   * Writes Timestamp to ostream.
   *
   * @param stream ostream to write to
   * @param ts Timestamp to write
   * @return reference to stream
   */
  DLLEXPORT std::ostream& operator<< (std::ostream& stream, const Timestamp& ts);
  
  /** The output operator of Timestamp.
   *
   * Writes Timestamp to OValueStream.
   *
   * @param ov OValueStream to write to
   * @param ts Timestamp to write
   * @return reference to ov
   */
  DLLEXPORT OValueStream& operator<<(OValueStream& ov, const Timestamp& ts);


  /** The input operator of Timestamp.
   *
   * Reads Timestamp from IValueStream.
   *
   * @param iv IValueStream to read from
   * @param ts Timestamp variable to read to
   * @return reference to iv
   */
  DLLEXPORT IValueStream& operator>>(IValueStream& iv, Timestamp& ts);
}

#include "nmm/nmm_suffix.hpp"

#endif
