Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/command/TclThreadManager.h @ 7373

Last change on this file since 7373 was 7284, checked in by landauf, 14 years ago

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _TclThreadManager_H__
30#define _TclThreadManager_H__
31
32#include "core/CorePrereqs.h"
33
34#include <cassert>
35#include <list>
36#include <map>
37#include <string>
38
39#include "util/Singleton.h"
40
41struct Tcl_Interp;
42
43namespace orxonox
44{
45    class _CoreExport TclThreadManager : public Singleton<TclThreadManager>
46    {
47        friend class Singleton<TclThreadManager>;
48        friend class TclBind;
49        friend _CoreExport void tclThread(TclInterpreterBundle* bundle, const std::string& command);
50        friend _CoreExport void sourceThread(const std::string& file);
51        friend _CoreExport int Tcl_OrxonoxAppInit(Tcl_Interp* interp);
52
53        public:
54            TclThreadManager(Tcl::interpreter* interpreter);
55            virtual ~TclThreadManager();
56
57            static unsigned int      create();
58            static Tcl::interpreter* createWithId(unsigned int id);
59            static void              destroy(unsigned int id);
60            static void              execute(unsigned int target_id, const std::string& command);
61            static std::string       query(unsigned int target_id, const std::string& command);
62            static void              source(const std::string& file);
63
64            static void error(const std::string& error);
65            static void debug(const std::string& error);
66
67            void preUpdate(const Clock& time);
68
69            std::list<unsigned int> getThreadList() const;
70
71        private:
72            static void tcl_execute(const Tcl::object& args);
73            static void tcl_crossexecute(int target_id, const Tcl::object& args);
74            static std::string tcl_query(int source_id, const Tcl::object& args);
75            static std::string tcl_crossquery(int source_id, int target_id, const Tcl::object& args);
76            static bool tcl_running(int id);
77
78            void _execute(unsigned int target_id, const std::string& command);
79            std::string _query(unsigned int source_id, unsigned int target_id, const std::string& command, bool bUseCommandExecutor = false);
80
81            TclInterpreterBundle* getInterpreterBundle(unsigned int id);
82            std::string dumpList(const std::list<unsigned int>& list);
83
84            static void initialize(TclInterpreterBundle* bundle);
85            static std::string eval(TclInterpreterBundle* bundle, const std::string& command, const std::string& action);
86
87            static TclThreadManager* singletonPtr_s;                            ///< Singleton pointer
88
89            unsigned int numInterpreterBundles_;                                ///< Number of created Tcl-interpreters (only used for auto-numbered interpreters, not affected by @ref createWithId)
90            std::map<unsigned int, TclInterpreterBundle*> interpreterBundles_;  ///< A map containing all Tcl-interpreters
91            boost::shared_mutex* interpreterBundlesMutex_;                      ///< A mutex used to synchronize threads when accessing @ref interpreterBundles_
92            TclThreadList<std::string>* messageQueue_;                          ///< A queue to pass messages from Tcl-threads to the main thread
93            boost::mutex* mainInterpreterMutex_;                                ///< A mutex to synchronize queries to the main interpreter
94    };
95
96    _CoreExport void tclThread(TclInterpreterBundle* bundle, const std::string& command);
97    _CoreExport void sourceThread(const std::string& file);
98    _CoreExport int Tcl_OrxonoxAppInit(Tcl_Interp* interp);
99}
100
101#endif /* _TclThreadManager_H__ */
Note: See TracBrowser for help on using the repository browser.