/* 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_PROXYAPPLICATION_HPP
#define NMM_PROXYAPPLICATION_HPP

#include "nmm/nmm_prefix.hpp"

#include "NMMApplication.hpp"
#include "visibility.hpp"

namespace NMM {
  class TCPStrategy;
  class TCPAcceptor;

  /** The ProxyApplication tries to connect to the Server-Registry that runs on this system.
   * If no Server-Registry is available, an exception is thrown in the construtor.
   */
  class DLLEXPORT ProxyApplication : public NMMApplication {
  public:
    /** @name Constructor & Destructor
     */
    //@{
    /** Constructor.
     *
     * @param argc number of commandline arguments
     * @param argv array of commandline arguments 
     * @param host host to connect to serverregistry 
     * @param port port to connect to serverregistry
     * @param enable_acceptor if true NMMApplication accepts incoming connections
     */
    ProxyApplication(int argc, char** argv, string host="", int port = ClientRegistry::default_port, bool enable_acceptor = true);

    /** Destructor.
     */
    virtual ~ProxyApplication();
    //@}

    /** @name ClientRegistry & PluginManager
     */
    //@{
    /** Returns the ClientRegistry.
     *
     * This method returns the ClientRegistry, which can be used to search and request Nodes.
     *
     * @return reference to ClientRegistry
     */
    virtual       ClientRegistry& getRegistry();

    /** Returns the ClientRegistry.
     *
     * This method returns the ClientRegistry, which can be used to search and request Nodes.
     *
     * @return reference to ClientRegistry
     */
    virtual const ClientRegistry& getRegistry() const;

    /** Returns the PluginManager.
     *
     * This method returns the PluginManager, which can be used to load plugins.
     *
     * @return reference to PluginManager.
     */
    virtual       IPluginManager& getPluginManager();

    /** Returns the PluginManager.
     *
     * This method returns the PluginManager, which can be used to load plugins.
     *
     * @return reference to PluginManager.
     */
    virtual const IPluginManager& getPluginManager() const;
    //@}

    /** @name Helper methods
     */
    //@{
    /** Returns ProxyApplication or, if instantiation fails, returns NMMAPPlication.
     *
     * This method can be used to detect automatically whether an NMMApplication or a ProxyApplication can be used.
     * Since this mehtod instantiates a NMMApplication or ProxyApplication each time it is called, it must only be called 
     * once (e.g. at the beginning of the application) because only one NMMApplcation or ProxyApplication can be instantiated 
     * within an application. The caller of this method is responsible to delete the NMMApplcation or ProxyApplication at the end
     * of the application.
     *
     * @param argc number of commandline arguments
     * @param argv array of commandline arguments 
     * @param host host to connect to serverregistry 
     * @param port port to connect to serverregistry
     * @param enable_acceptor if true NMMApplication accepts incoming connections
     */
    static NMMApplication* getApplication(int argc, char** argv, string host = "", int port = ClientRegistry::default_port, bool enable_acceptor = true);
    //@}
  private:
    auto_ptr<ClientRegistry>        __client_registry;        ///< pointer to the ClientRegistry
    IPluginManager_var              __i_plugin_manager;       ///< pointer to the IPluginManager
    string                          __default_host;           ///< uses this host to connect to the ServerRegistry
    int                             __default_port;           ///< uses this port to connect to the ServerRegistry
  };


}

#include "nmm/nmm_suffix.hpp"

#endif

