// {{{ the iWear header 
/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 * In particular this file is part of the Framework Core Library
 *
 * The iWear Framework 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 as in version 2 of the License.

 * 
 * The iWear Framework 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
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
// }}}

#ifndef __APPLICATIONLAUNCHER_H
#define __APPLICATIONLAUNCHER_H

#ifndef __APPLICATION_H
#include <iwear_uiservices/application.h>
#endif

// Our namespaces
using namespace iwear;
using namespace std;

// Forward Declaration
class iwear::ServiceManager;

namespace iwear{
    namespace uiservices{

// Forward Declaration -- Same Namespace
class ApplicationService;
class ApplicationHandle;
class SimpleMenuFunctor;


class ApplicationLauncher : public Application
{
    friend class ApplicationService;

 public:

    /**
     * The constructor for the application launcher
     * @param application_service pointer to the application service
     */
    ApplicationLauncher(ApplicationService* application_service);

/*
    ApplicationLauncher( void )
	: Application()
    {
	// Nothing yet to do!
    }
*/
    
    /**
     * The destructor
     */
    virtual ~ApplicationLauncher(void);

    /**
     * This method is called when the application launcher
     * thread is started
     */
    virtual void Run(void);

 protected:

    void Init_Application(void);
       
    void Final_Application(void);

    virtual void set_default_configuration(void);

    /**
     * This method is used to scan an arbitrary directory
     * for dynamically loadable applications and parse them
     * into the internal structure
     */
    virtual void scan_dynamic_apps( void );

    /**
     * This method handle the automatic start of certain 
     * applications which have been set appropriatly in the
     * configuration file by the user
     */
    virtual void handle_application_autostart(void);

    /**
     * This method is a handle method which is called by the
     * Application Launcher menu functor, when the user chose
     * to start a new dynamic application.
     */
    virtual void handle_application_launch(const uint32_t button_id,
					   const bool to_foreground = true);

    /**
     * This method is called by the application service whenever
     * an application is stopped. If this is a dynamically launched
     * application which is managed by the application launcher
     * this means that the object should be destroyed ( the
     * application is already stopped).
     */
    virtual void handle_application_termination(const uid* app_id);

    /**
     * The functor which is called bu the application launcher menu
     * when either an application or the switch button is clicked
     * Note: Only clicking buttons triggers any action
     */
    SimpleMenuFunctor* menu_functor;

    /**
     * This is a vector of directory entries each of whom represents
     * an iWear application which has been made available for the
     * current session of the iWear framework.
     */
    set<string> blubb;
    
    map<string, uint32_t> application_name2button_id;


    /**
     * Mapping from button ID's to corresponding Application
     * Handle. This allows to load dynamic application instances
     * upon button press --> result of parsin method
     */
    map<const uint32_t , ApplicationHandle* >
	button_id2application_handle;

    /** 
     * Mapping from UID's of dynamically loaded applications to
     * an according pair of application pointer and application
     * handle which was used to create the application and which 
     * will be used again to delete it.
     */
    map<const uid*, pair<Application*, ApplicationHandle*>, deref_less<const uid*> > 
	managed_applications;

};

    } // namespace uiservices
} // namespace iwear

#endif // __APPLICATIONLAUNCHER_H

