/* 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_IServerRegistryImpl_HPP
#define NMM_IServerRegistryImpl_HPP

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/NMMObject.hpp"
#include "IServerRegistry.hpp"

#include "IRegistryImpl.hpp"
#include "ISessionImpl.hpp"

#include "visibility.hpp"

namespace NMM
{
/** @class IServerRegistry
  * Base class for all Registry Interfaces.
  */

  class DLLEXPORT IServerRegistryImpl  : virtual public IRegistryImpl { 
  public:
    IServerRegistryImpl() { addInterface(new IServerRegistry(*this)); registerEvents(); };

    virtual ~IServerRegistryImpl() {};

  protected:
    /** This method returns the current system time  */

    virtual Time getSystemTime() = 0;
    /** This method returns the timout for access control.
     *
     * @return timout for access control
     */

    virtual nmm_uint32 getTransactionTimeout() = 0;
    /** This method sets the timout for access control.
     *
     * @param time_out The new timeout for the access control
     */

    virtual void setTransactionTimeout(const nmm_uint32& time_out) = 0;
    /** This method returns the leasing time_out for nodes.
     *
     * @return new timeout for the access control
     */

    virtual nmm_uint32 getNodeLeasingTime() = 0;
    /** This method sets the leasing time_out for nodes.
     *
     * @param time_out The new timeout for nodes.
     */

    virtual void setNodeLeasingTime(const nmm_uint32& time_out) = 0;
    /** This method refreshes the reservation of a leased nodes.
     * 
     * @param reg_id RegistryID of registry node is reserved at
     * @param node_id ObjectID of node
     * @param user_info UserInfo of node
     * @return new reservation time of node
     */

    virtual nmm_uint32 refreshNodeLeasing(const RegistryID& reg_id, const ObjectID& node_id, const UserInfo& user_info) = 0;
    /** This method refreshes the enabled access control.
     * 
     * @param user_info UserInfo specifying user which locked registry
     * @return new transaction time if successful, 0 otherwise 
     */

    virtual nmm_uint32 refreshTransaction(const UserInfo& user_info) = 0;
    /** Requests NMMObject specified by given ObjectDescription.
     *
     * Currently can only return MultiAudioVideoSynchronizer.
     *
     * @param od ObjectDescription specifying NMMObject to request
     */

    virtual Interface* requestNMMObject(const ObjectDescription& od) = 0;
    /** Release NMMObject specified by given Interface.
     *
     * @param i_face Interface specifying NMMObject 
     */

    virtual void releaseNMMObject(const Interface& i_face) = 0;
    /** Sets sharing type on nodes and return session for shared graph.
     *
     * @param gd GraphDescription for shared graph
     * @param user_info UserInfo specifying user requesting graph
     */

    virtual ISession* requestSharedGraph(GraphDescription& gd, const UserInfo& user_info) 
      throw(const RegistryException&) = 0;
    /** Releases given session.
     *
     * @param session session to release
     * @param user_info UserInfo which tries to release session
     */

    virtual void releaseSession(const ISession& session, const UserInfo& user_info) = 0;
    /** Releases a requested Node.
     *
     * @param node INode interface for Node to be released
     */

    virtual void releaseSharedNode(const INode& node) = 0;
    /* initialize a new session */
    /** Initializes new session with synchronizer.
     *
     * @param gd GraphDescription of graph to create session for
     * @param u_info UserInfo describing user initializing session
     * @param given_session Interface to master session or NULL, if this is the master session
     * @return ISession interface to created session
     */

    virtual ISession* initSession(GraphDescription& gd, const UserInfo& u_info, const ISession* given_session) = 0;
    /** Requests nodes contained in given GraphDescription.
     *
     * @param gd GraphDescription with Nodes to request
     * @param user_info UserInfo specifying user requesting graph
     */

    virtual void requestGraph(GraphDescription& gd, const UserInfo& user_info) = 0;

    virtual void sendIServerRegistry() = 0;


  private:
    void registerEvents();
  };

}

#include "nmm/nmm_suffix.hpp"

#endif
