Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1269


Ignore:
Timestamp:
May 14, 2008, 12:46:00 AM (17 years ago)
Author:
landauf
Message:

added some control commands to TclThreadManager (status, dump, flush) and changed some small details.
calls to a TclThread are no longer hidden from the main-interpreter. if you want to pass expressions with variables to a thread, put them into {curly braces} - the expression will then be transfered untouched to the sub-interpreter. without braces, the variables will be replaced by the main-interpreter.
the advantage is: you can use a variable to pass the ID of a thread to TclThreadManager, which wasn't possible with the old solution. an example is remote.tcl that creates a thread, saves it's ID in a variable and executes a command on this thread.

oh, and if you didn't understood a word - no problem, this is only important for people using Tcl in Orxonox ;)

Location:
code/branches/console
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/bin/remote.tcl

    r1267 r1269  
    1 TclThreadManager create
    2 TclThreadManager execute 1 source telnet_server.tcl
     1set telnetserverthreadid [TclThreadManager create]
     2TclThreadManager execute $telnetserverthreadid source telnet_server.tcl
  • code/branches/console/src/core/CommandExecutor.cc

    r1255 r1269  
    394394        if (useTcl)
    395395        {
    396             std::string temp = getLowercase(removeTrailingWhitespaces(command));
    397             if (!(temp.find("tclthread") == 0 || temp.find("tclthreadmanager") == 0))
     396//            std::string temp = getLowercase(removeTrailingWhitespaces(command));
     397//            if (!(temp.substr(0, 16) == "tclthreadmanager" || temp.substr(0, 10) == "tclexecute" || temp.substr(0, 8) == "tclquery"))
    398398                return TclBind::eval(command);
    399399        }
  • code/branches/console/src/core/InputBuffer.cc

    r1230 r1269  
    3939    {
    4040        //this->bActivated_ = false;
    41         this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^~";
     41        this->allowedChars_ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZäöüÄÖÜ0123456789 \\\"(){}[]<>.:,;_-+*/=!?|$&%^~#";
    4242        this->keyboard_ = InputManager::getSingleton().getKeyboard();
    4343        this->buffer_ = "";
  • code/branches/console/src/core/TclThreadManager.cc

    r1267 r1269  
    4848namespace orxonox
    4949{
    50 //    ConsoleCommand(TclThreadManager, tclthread, AccessLevel::None, true);
     50    ConsoleCommandShortcutGeneric(tclexecute, createExecutor(createFunctor(&TclThreadManager::execute), "tclexecute", AccessLevel::None));
     51    ConsoleCommandShortcutGeneric(tclquery,   createExecutor(createFunctor(&TclThreadManager::query),   "tclquery",   AccessLevel::None));
    5152    ConsoleCommand(TclThreadManager, create,    AccessLevel::None, false);
    5253    ConsoleCommand(TclThreadManager, destroy,   AccessLevel::None, false);
    5354    ConsoleCommand(TclThreadManager, execute,   AccessLevel::None, false);
    5455    ConsoleCommand(TclThreadManager, query,     AccessLevel::None, false);
    55 //    ConsoleCommand(TclThreadManager, status,    AccessLevel::None, false);
    56 //    ConsoleCommand(TclThreadManager, dump,      AccessLevel::None, false);
     56    ConsoleCommand(TclThreadManager, status,    AccessLevel::None, false);
     57    ConsoleCommand(TclThreadManager, dump,      AccessLevel::None, false);
     58    ConsoleCommand(TclThreadManager, flush,     AccessLevel::None, false);
    5759
    5860    TclThreadManager* instance = &TclThreadManager::getInstance();
     
    132134    }
    133135
    134     void TclThreadManager::execute(unsigned int threadID, const std::string& command)
    135     {
    136         TclThreadManager::getInstance().pushCommandToQueue(threadID, command);
     136    void TclThreadManager::execute(unsigned int threadID, const std::string& _command)
     137    {
     138        std::string command = _command;
     139        while (command.size() >= 2 && command[0] == '{' && command[command.size() - 1] == '}')
     140            command = command.substr(1, command.size() - 2);
     141
     142
     143        if (threadID == 0)
     144            TclThreadManager::getInstance().pushCommandToQueue(command);
     145        else
     146            TclThreadManager::getInstance().pushCommandToQueue(threadID, command);
    137147    }
    138148
     
    140150    {
    141151        return TclThreadManager::getInstance().evalQuery(TclThreadManager::getInstance().orxonoxInterpreterBundle_.id_, threadID, command);
     152    }
     153
     154    void TclThreadManager::status()
     155    {
     156        COUT(0) << "Thread ID" << '\t' << "Queue size" << '\t' << "State" << std::endl;
     157
     158        std::string output = "Orxonox";
     159        output += "\t\t";
     160        {
     161            boost::mutex::scoped_lock queue_lock(TclThreadManager::getInstance().orxonoxInterpreterBundle_.queueMutex_);
     162            output += getConvertedValue<unsigned int, std::string>(TclThreadManager::getInstance().orxonoxInterpreterBundle_.queue_.size());
     163        }
     164        output += "\t\t";
     165        output += "busy";
     166        COUT(0) << output << std::endl;
     167
     168        boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
     169        for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = TclThreadManager::getInstance().interpreterBundles_.begin(); it != TclThreadManager::getInstance().interpreterBundles_.end(); ++it)
     170        {
     171            std::string output = getConvertedValue<unsigned int, std::string>((*it).first);
     172            output += "\t\t";
     173            {
     174                boost::mutex::scoped_lock queue_lock((*it).second->queueMutex_);
     175                output += getConvertedValue<unsigned int, std::string>((*it).second->queue_.size());
     176            }
     177            output += "\t\t";
     178            {
     179                boost::mutex::scoped_lock interpreter_lock((*it).second->interpreterMutex_, boost::defer_lock_t());
     180                if (interpreter_lock.try_lock())
     181                    output += "ready";
     182                else
     183                    output += "busy";
     184            }
     185            COUT(0) << output << std::endl;
     186        }
     187    }
     188
     189    void TclThreadManager::dump(unsigned int threadID)
     190    {
     191        TclInterpreterBundle* bundle = 0;
     192        if (threadID == 0)
     193        {
     194            bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
     195            COUT(0) << "Queue dump of Orxonox:" << std::endl;
     196        }
     197        else
     198        {
     199            if (bundle = TclThreadManager::getInstance().getInterpreterBundle(threadID))
     200            {
     201                COUT(0) << "Queue dump of Tcl-thread " << threadID << ":" << std::endl;
     202            }
     203            else
     204                return;
     205        }
     206
     207        boost::mutex::scoped_lock queue_lock(bundle->queueMutex_);
     208        unsigned int index = 0;
     209        for (std::list<std::string>::const_iterator it = bundle->queue_.begin(); it != bundle->queue_.end(); ++it)
     210        {
     211            index++;
     212            COUT(0) << index << ": " << (*it) << std::endl;
     213        }
     214    }
     215
     216    void TclThreadManager::flush(unsigned int threadID)
     217    {
     218        TclInterpreterBundle* bundle = 0;
     219        if (threadID == 0)
     220            bundle = &TclThreadManager::getInstance().orxonoxInterpreterBundle_;
     221        else
     222            if (!(bundle = TclThreadManager::getInstance().getInterpreterBundle(threadID)))
     223                return;
     224
     225        boost::mutex::scoped_lock queue_lock(bundle->queueMutex_);
     226        bundle->queue_.clear();
     227        if (threadID == 0)
     228        {
     229            COUT(0) << "Flushed queue of Orxonox Tcl-interpreter." << std::endl;
     230        }
     231        else
     232        {
     233            COUT(0) << "Flushed queue of Tcl-interpreter " << threadID << "." << std::endl;
     234        }
    142235    }
    143236
     
    473566    void tclThread(TclInterpreterBundle* interpreterBundle, std::string command)
    474567    {
     568std::cout << "tclthreadm executes " << command << std::endl;
    475569        boost::mutex::scoped_lock interpreter_lock(interpreterBundle->interpreterMutex_);
    476570        try
  • code/branches/console/src/core/TclThreadManager.h

    r1257 r1269  
    7676            static void execute(unsigned int threadID, const std::string& command);
    7777            static std::string query(unsigned int threadID, const std::string& command);
     78            static void status();
     79            static void dump(unsigned int threadID);
     80            static void flush(unsigned int threadID);
    7881
    7982            static void tcl_execute(Tcl::object const &args);
Note: See TracChangeset for help on using the changeset viewer.