/* 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_ITVGuide_HPP
#define NMM_ITVGuide_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 "ChannelDescription.hpp"
#include "ProgramDescription.hpp"
#include "ProgramFilter.hpp"
#include "nmm/utils/time/LocalTime.hpp"
#include "nmm/comm/serialize/SerializeLocalTime.hpp"
#include "nmm/comm/serialize/StdValue.hpp"
#include "nmm/plugins/video/tv/interfaces/tvguide/ITVGuidePlugin.hpp"
#include "nmm/plugins/video/tv/interfaces/tvguide/ITVGuidePeerObject.hpp"

#include "visibility.hpp"

namespace NMM
{
  /**
   * Interface to access EPG. 
   */

  class DLLEXPORT ITVGuide : virtual public NMM::Interface { 
  public:
    ITVGuide() : NMM::Interface(ITVGuide::ITVGuide_type, "NMM") { };

    ITVGuide(NMM::NMMObject& parent) : NMM::Interface (parent, ITVGuide::ITVGuide_type, "NMM") { };

    virtual ~ITVGuide() {};

    static const char* ITVGuide_type;

    virtual  string getInterfaceType() const { return ITVGuide_type; }

    NMM::Interface* copy() const { return new ITVGuide(*this); }
    static void used(); 
    static const char* insertChannel_event;
    static const char* insertChannelDescription_event;
    static const char* insertEvent_event;
    static const char* getDirectory_event;
    static const char* getChannelsList_event;
    static const char* getChannelById_event;
    static const char* getChannelByName_event;
    static const char* getEvent_event;
    static const char* getEventsOnDayOnChannel_event;
    static const char* search_event;
    static const char* getCurrentEventOnChannel_event;
    static const char* getFollowingEventOnChannel_event;
    static const char* getCategories_event;
    static const char* getPluginInterface_event;
    static const char* cleanDatabase_event;
    /**
     * Adds a channel to the channel-list
     *\param id ID of the channel wich is used to find show of this channel
     *\param name Name of the channel
     */

    virtual Result insertChannel(const string& id = "", const string& name = "")
      throw(const NMM::SerializedException&);
    /**
     * Adds a channel to the channel-list
     *\param cd ChannelDescription to be added
     */

    virtual Result insertChannelDescription(const ChannelDescription& cd)
      throw(const NMM::SerializedException&);
   /**
     * Adds an Event to the database
     *\param pd PrgoramDescription, containing the inrformation about the event
     */

    virtual Result insertEvent(const ProgramDescription& pd)
      throw(const NMM::SerializedException&);
    /**
     * returns the path, where the XML-Files are stored
     *\return Path to XML-Files
     */

    virtual string getDirectory()
      throw(const NMM::SerializedException&);
    /**
     * Returns the Channels, for wich informaion is available
     *\return Channel-list
     */

    virtual list<ChannelDescription >  getChannelsList()
      throw(const NMM::SerializedException&);
    /**
     * Returns the channel with the given ID
     *\param id ID of the channel
     *\return name of the channel, if available, empty string otherwise
     */

    virtual string getChannelById(const string& id)
      throw(const NMM::SerializedException&);
    /**
     *Return the ID of the Channel with the given name
     *\param name name o the channel
     *\return ID of the requested channel, empty string if not found
     */

    virtual string getChannelByName(const string& name)
      throw(const NMM::SerializedException&);
    /**
     *Returns the Event with the given starttime, endtime and channel
     *\param start StartTime of the Event
     *\param end EndTime of the Event
     *\param channel channel of the event
     *\return ProgramDescription containg the information about the event
     */

    virtual ProgramDescription getEvent(const LocalTime& start, const LocalTime& end, const ChannelDescription& channel)
      throw(const NMM::SerializedException&);
    /**
     *Returns all show on the specified day and channel
     *\param day date of the day
     *\param channel channel
     *\return List of ProgramDescripytions containing the information of the shows
     */

    virtual list<ProgramDescription >  getEventsOnDayOnChannel(const LocalTime& day, const ChannelDescription& channel)
      throw(const NMM::SerializedException&);
    /**
     * Returns a List with Events containing the given search-phrase
     *\param phrase Phrase to search for
     *\param peer Interface to the application the it is notified of new events
     *\return Event-Hitlist
     */

    virtual list<ProgramDescription >  search(const ProgramFilter& pf, const ITVGuidePeerObject* peer = NULL)
      throw(const NMM::SerializedException&);
    /**
     * returns the current event on the specified channel
     *\param channel channel_ID
     *@return current event in the specified channel
     */

    virtual ProgramDescription getCurrentEventOnChannel(const ChannelDescription& channel)
      throw(const NMM::SerializedException&);
    /**
     * returns the next to current event on the specified channel
     *\param channel channel_ID
     *@return next event in the specified channel
     */

    virtual ProgramDescription getFollowingEventOnChannel(const ChannelDescription& channel)
      throw(const NMM::SerializedException&);
    /** 
     * returns a list with all categories, stored in the DB
     *@return strin-list with categories
     */

    virtual list<string >  getCategories()
      throw(const NMM::SerializedException&);
    /**
     * requests the TVGuide-Plugin-Interface specified in type
     *@return ITVGuideUpdatePlugin* interface of the requested grabber
     *@param type Type of TVGuidePlugin, wich is its plugin-name, eg IXMLTVPlugin
     */

    virtual ITVGuidePlugin* getPluginInterface(const string& type)
      throw(const NMM::SerializedException&);
    /**
       clean up the database. specify the amount of days from today wich data should be kept. older data will be erased
    */

    virtual void cleanDatabase(const nmm_int32& days)
      throw(const NMM::SerializedException&);


  };

  typedef auto_ptr<ITVGuide> ITVGuide_var;




}

#include "nmm/nmm_suffix.hpp"

#endif
