summaryrefslogtreecommitdiffstats
path: root/lib/kross/main/manager.h
blob: fe815e7c58cea39373cc142444f955abadef179d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/***************************************************************************
 * manager.h
 * This file is part of the KDE project
 * copyright (C)2004-2005 by Sebastian Sauer ([email protected])
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * This program 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
 * Library General Public License for more details.
 * You should have received a copy of the GNU Library General Public License
 * along with this program; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 ***************************************************************************/

#ifndef KROSS_API_MANAGER_H
#define KROSS_API_MANAGER_H

#include <tqstring.h>
#include <tqstringlist.h>
#include <tqmap.h>
//#include <tqvariant.h>
#include <ksharedptr.h>

class TQObject;

#include "../api/object.h"
#include "mainmodule.h"

namespace Kross { namespace Api {

    // Forward declarations.
    class Interpreter;
    class Object;
    class EventSlot;
    class EventSignal;
    class ScriptContainer;
    class ManagerPrivate;
    class InterpreterInfo;

    /**
     * The Manager class is the main entry point to work with
     * Kross. It spends an abstraction layer between what is
     * under the hood of Kross and the functionality you need
     * to access.
     * Use \a Interpreter to just work with some implementated
     * interpreter like python. While \a Script spends a more
     * flexible container.
     */
    class KDE_EXPORT Manager : public MainModule
    {
        protected:

            /**
             * Constructor. Use \a scriptManager() to access
             * the Manager singleton instance.
             */
            Manager();

        public:

            /**
             * Destructor.
             */
            ~Manager();

            /**
             * Return the Manager instance. Always use this
             * function to access the Manager singleton.
             */
            static Manager* scriptManager();

            /**
             * \return a map with \a InterpreterInfo* instances
             * used to describe interpreters.
             */
            TQMap<TQString, InterpreterInfo*> getInterpreterInfos();

            /**
             * \return true if there exists an interpreter with the
             * name \p interpretername else false.
             */
            bool hasInterpreterInfo(const TQString& interpretername) const;

            /**
             * \return the \a InterpreterInfo* matching to the defined
             * \p interpretername or NULL if there does not exists such
             * a interpreter.
             */
            InterpreterInfo* getInterpreterInfo(const TQString& interpretername);

            /**
             * \return the name of the \a Interpreter that feels responsible
             * for the defined \p file .
             *
             * \param file The filename we should try to determinate the
             *        interpretername for.
             * \return The name of the \a Interpreter which will be used
             *        to execute the file or TQString() if we failed
             *        to determinate a matching interpreter for the file.
             */
            const TQString getInterpreternameForFile(const TQString& file);

            /**
             * Return the existing \a ScriptContainer with scriptname
             * or create a new \a ScriptContainer instance and associate
             * the passed scriptname with it.
             *
             * \param scriptname The name of the script. This
             *        should be unique for each \a Script and
             *        could be something like the filename.
             * \return The \a ScriptContainer instance matching to
             *         scriptname.
             */
            KSharedPtr<ScriptContainer> getScriptContainer(const TQString& scriptname);

            /**
             * Return the \a Interpreter instance defined by
             * the interpretername.
             *
             * \param interpretername The name of the interpreter.
             *        e.g. "python" or "kjs".
             * \return The Interpreter instance or NULL if there
             *         does not exists an interpreter with such
             *         an interpretername.
             */
            Interpreter* getInterpreter(const TQString& interpretername);

            /**
             * \return a list of names of the at the backend
             * supported interpreters.
             */
            const TQStringList getInterpreters();

            /**
             * Add the an external module to the global shared list of 
             * loaded modules.
             * 
             * @param module The @a Module instace to add.
             * @return true if the module was added successfully else
             *         false.
             */
            bool addModule(Module::Ptr module);

            /**
             * Load an external module and return it.
             *
             * \param modulename The name of the library we should try to 
             *        load. Those library needs to be a valid kross module.
             * \return The loaded \a Object or NULL if loading
             *        failed. The loaded Module isn't added to the global
             *        shared list of modules.
             */
            Module::Ptr loadModule(const TQString& modulename);

        private:
            /// Private d-pointer class.
            ManagerPrivate* d;
    };

}}

#endif