/***************************************************************************
 *   Copyright (C) 2005 by Raphael Langerhorst                             *
 *   raphael-langerhorst@gmx.at                                            *
 *                                                                         *
 *   Permission is hereby granted, free of charge, to any person obtaining *
 *   a copy of this software and associated documentation files (the       *
 *   "Software"), to deal in the Software without restriction, including   *
 *   without limitation the rights to use, copy, modify, merge, publish,   *
 *   distribute, sublicense, and/or sell copies of the Software, and to    *
 *   permit persons to whom the Software is furnished to do so, subject to *
 *   the following conditions:                                             *
 *                                                                         *
 *   The above copyright notice and this permission notice shall be        *
 *   included in all copies or substantial portions of the Software.       *
 *                                                                         *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
 *   OTHER DEALINGS IN THE SOFTWARE.                                       *
 ***************************************************************************/

#ifndef GWEGWORLDENGINEFACTORY_H
#define GWEGWORLDENGINEFACTORY_H

#include <GweFactoryOption.h>
#include <GweController.h>

#include <qobject.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qptrlist.h>
#include <qvaluelist.h>
#include <qmutex.h>
#include <qmap.h>
#include <qdom.h>

namespace GWE
{

/**
  \class GWorldEngineFactory GWorldEngineFactory.h
  \brief Construct and initialize a GWE Server.
  @author Raphael Langerhorst
*/

class GWorldEngineFactory : public QObject, protected QMutex
{
  Q_OBJECT

  protected:

    QPtrList<GweController> GweControllers;
    
    /**
     * Before initializing the GWE various options can be set.
     * The factory holds one root options which expands to an
     * options tree.
     * 
     * @see GweFactoryOption, init, initDefault
     */
    GweFactoryOption* RootOption;
  
  public:
  
    /**
     * Constructor.
     */
    GWorldEngineFactory(QObject *parent = 0, const char *name = 0);

    /**
     * Virtual Destructor.
     */
    virtual ~GWorldEngineFactory();
    
    /**
     * @param delete_in_destructor whether to delete controllers in the destructor.
     */
    void setDeleteControllersInDestructor(bool delete_in_destructor);
    
    /**
     * @return true when all controllers are deleted in the destructor.
     */
    bool getDeleteControllersInDestructor() const;
    
    /**
     * @Returns a list of all initialized GWE Controllers.
     */
    QPtrList<GWE::GweController> getInitializedControllers();
    
    /**
     * @Returns the root of the options tree.
     * @see RootOption
     */
    GweFactoryOption* getRootOption();
    
    /**
     * @Returns the root of the options tree.
     * @see RootOption
     */
    const GweFactoryOption* getRootOption() const;
  
  public slots:
  
    /**
     * Initializes the GWE according to the defined Options.
     * @see Options
     * @return the initialized GWE Controller (or NULL if failed)
     */
    GweController* init();
    
    /**
     * Initializes the GWE with predefined values, all options
     * are set to default values.
     * @see Options
     * @return the initialized GWE Controller (or NULL if failed)
     */
    GweController* initDefault();
    
  signals:
  
    /**
     * In case Initialization succeeds this signal is emitted.
     * It is made sure that either this signal or initFailed()
     * is emitted.
     * @param controller is a valid pointer to the initialized GWE Controller
     */
    void initSucceeded(GweController* controller);
    
    /**
     * In case Initialization fails this signal is emitted.
     * It is made sure that either this signal or initSucceeded()
     * is emitted.
     * @param error_description contains information about the failure.
     */
    void initFailed(QString error_description);
};

}

#endif


syntax highlighted by Code2HTML, v. 0.9.1