/* 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_IController_HPP
#define NMM_IController_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/Interface.hpp"
#include "nmm/comm/messaging/Event.hpp"
#include "nmm/comm/messaging/IllegalStateException.hpp"
#include <memory>

/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *
 * See file LICENCE for terms and conditions of usage
 *
 */

#include "nmm/utils/time/Time.hpp"
#include "nmm/comm/messaging/Timestamp.hpp"

#include "visibility.hpp"

namespace NMM
{
  /** Method Call Delay Measurement.
   */

  class DLLEXPORT IPing : virtual public NMM::Interface { 
  public:
    IPing() : NMM::Interface(IPing::IPing_type, "NMM") { };

    IPing(NMM::NMMObject& parent) : NMM::Interface (parent, IPing::IPing_type, "NMM") { };

    virtual ~IPing() {};

    static const char* IPing_type;

    virtual  string getInterfaceType() const { return IPing_type; }

    NMM::Interface* copy() const { return new IPing(*this); }
    static void used(); 
    static const char* ping_event;
    /** Measure the delay of a method call.
     * This method can be used to estimate the delay between method call and execution.
     * The clocks on the host which calls the method and the host which executes the method
     * must be synchronized.
     * @return the system time when the method call was executed
     */

    virtual Time ping()
      throw(const NMM::SerializedException&);


  };

  typedef auto_ptr<IPing> IPing_var;


  /** Interface of a synchronization controller.
   * This is the interface of a synchronization controller. A controllers is attached to a synchronized source
   * or sink and adds synchronization functionality. The controller performs all interface communication with
   * the synchronizer.
   */

  class DLLEXPORT IController : virtual public IPing { 
  public:    /** Controller mode.
     */

  enum Mode { 
    ONLINE = 0 , ///< Online mode. Used for playback graphs

    OFFLINE = 1 ///< Offline mode. Used for non-realtime graphs, such as grabbing and transcoding
 };

    IController() : NMM::Interface(IController::IController_type, "NMM") { };

    IController(NMM::NMMObject& parent) : NMM::Interface (parent, IController::IController_type, "NMM") { };

    virtual ~IController() {};

    static const char* IController_type;

    virtual  string getInterfaceType() const { return IController_type; }

    NMM::Interface* copy() const { return new IController(*this); }
    static void used(); 
    static const char* setMode_event;
    static const char* permitDiscardBuffers_event;
    static const char* pause_event;
    static const char* wakeup_event;
    static const char* reset_event;
    static const char* setBuffersInvalid_event;
    static const char* setBuffersInvalidTimed_event;
    /** Set the controller mode.
     *
     * @param mode The controller mode
     */

    virtual Result setMode(const IController::Mode& mode)
      throw(const NMM::SerializedException&);
    /** Enable or disable discarding of buffers.
     * If the controller is in @c ONLINE mode, this method controls whether the controller may discard buffers
     * which can not be presented in time. Enabled by default.
     *
     * @param enable @c true to enable, @c false to disable discarding of buffers
     */

    virtual Result permitDiscardBuffers(const nmm_bool& enable)
      throw(const NMM::SerializedException&);
    /** Pause this controller.
     *
     * @return @c SUCCESS if the operation succeeded, @c FAILURE otherwise
     */

    virtual Result pause()
      throw(const NMM::SerializedException&);
    /** Wake up this controller after pause.
     *
     * @return @c SUCCESS if the operation succeeded, @c FAILURE otherwise
     */

    virtual Result wakeup()
      throw(const NMM::SerializedException&);
    /** Reset this controller.
     *
     * @return @c SUCCESS if the operation succeeded, @c FAILURE otherwise
     */

    virtual Result reset()
      throw(const NMM::SerializedException&);
    /** Enable or disable invalidation of all buffers.
     * If invalidation of all buffers is enabled, then all buffers are flagged as invalid and are not presented.
     * Disabled by default.
     *
     * @param enable @c true to enable, @c false to disable invalidation of all buffers
     */

    virtual void setBuffersInvalid(const nmm_bool& enable)
      throw(const NMM::SerializedException&);
    /** Enable or disable invalidation of all buffers after a specific timestamp.
     * If invalidation of all buffers is enabled, then all buffers are flagged as invalid and are not presented.
     * Disabled by default.
     * This method enables or disables invalidation of all buffers after a specific buffer timestamp.
     *
     * @param enable @c true to enable, @c false to disable invalidation of all buffers
     * @param timestamp Buffer timestamp which provides the @c sync_time after which the change becomes active
     */

    virtual void setBuffersInvalidTimed(const nmm_bool& enable, const Timestamp& timestamp)
      throw(const NMM::SerializedException&);


  };

  typedef auto_ptr<IController> IController_var;

  DLLEXPORT NMM::OValueStream& operator<<(NMM::OValueStream& ov, const IController::Mode& t);
  DLLEXPORT NMM::IValueStream& operator>>(NMM::IValueStream& iv, IController::Mode& t);



}

#include "nmm/nmm_suffix.hpp"

#endif
