Ignore:
Timestamp:
Apr 26, 2006, 5:22:09 PM (19 years ago)
Author:
ansari
Message:

ajout methode ZThread::kill() pour envoi de signal a un thread + remplacement CancelThread par StopThread (par kill/SIGUSR1) dans Commander (commander.cc) + amelioration documentation , Reza 26/4/2006

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/SysTools/commander.cc

    r2914 r2943  
    66#include <ctype.h>
    77#include <math.h>
     8#include <signal.h>
    89
    910#include "strutil.h"
     
    341342  \ingroup SysTools
    342343  Class for internal use by class Commander for command execution in separate threads.
     344  The command execution is carried in method run() which has its own exception handling bloc.
    343345*/
    344346class CommandExeThr :  public ZThread  {
     
    377379void CommandExeThr::run()
    378380{
    379   int rc = _cmdex->Execute(_keyw, _args, _toks);
     381  int rc = 0;
     382  try {
     383    rc = _cmdex->Execute(_keyw, _args, _toks);
     384  }
     385  catch (PThrowable& exc) {
     386    cout << "CommandExeThr::run() Catched Exception Msg()= "
     387         << exc.Msg() << endl;
     388    rc = -77;
     389  }
     390  catch (std::exception& sex) {
     391    cout << "CommandExeThr::run() Catched std::exception what()= "
     392         << sex.what() << endl;
     393    rc = -78;
     394  }
     395  catch (...) {
     396    cout << "CommandExeThr::run() Catched unknown (...) exception " << endl;
     397    rc = -79;
     398  }
    380399  _fgdone = true;
    381400  setRC(rc);
     
    402421  - Simple and vector variables
    403422  - Script definition
     423  - Command execution in separate threads
    404424  - Dynamic Load
    405425
     
    492512usage += "  > thrlist       # List of command execution threads (& as the last character) \n";
    493513usage += "  > clearthrlist  # Removes finished threads from the list  \n";
    494 usage += "  > cancelthr Id  # Cancel a given thread (ThrId=id) \n";
     514usage += "  > stopthr Id    # Try to stop a given thread (ThrId=id) sending SIGUSR1 \n";
    495515usage += "  > waitthr       # Waits until all active threads have finished (join()) \n";
    496516usage += "  > exec filename # Execute commands from file \n";
     
    704724
    705725/* --Methode-- */
    706 //! Select an interpreter by its name. The corresponding Interpret method is then called
     726//! Select an interpreter by its name as the current interpreter.
    707727void Commander::SelInterpreter(string& name)
    708728{
     
    10811101}
    10821102
     1103//! Can be called asynchronously (from a separate thread) to break (halt) execution (in loops, scripts ...)
    10831104void  Commander::StopExecution()
    10841105{
     
    18571878  return(0);
    18581879}
    1859 else if (kw == "cancelthr") {
    1860   if (tokens.size() < 1) { cout << "Commander::Interpret() Usage: cancelthr thrid" << endl;  return(0); }
     1880else if (kw == "stopthr") {
     1881  if (tokens.size() < 1) { cout << "Commander::Interpret() Usage: stopthr thrid" << endl;  return(0); }
    18611882  uint_8  id = atol(tokens[0].c_str());
    1862   CancelThr(id);
     1883  StopThr(id);
    18631884  return (0);
    18641885}
     
    19381959        CmdThrExeList.push_back(thr);
    19391960        cout << " Commander::ExecuteCommand() : Thread execution of command " << keyw << endl;
    1940         thr->start();   
     1961        thr->start();
     1962        if (CmdThrExeList.size() > 5)  CleanThrList();
    19411963        rc = 0;
    19421964      }
    1943       else rc = (*it).second.cex->Execute(keyw, args, toks);
     1965      else  rc = (*it).second.cex->Execute(keyw, args, toks);
    19441966    }
    19451967    else cout << "Dont know how to execute " << keyw << " ? " << endl;
    1946     }
     1968  }
    19471969  return(rc);
    19481970}
     
    20152037}
    20162038/* --Methode-- */
    2017 void Commander::CancelThr(uint_8 id)
     2039void Commander::StopThr(uint_8 id)
    20182040{
    20192041  for(list<CommandExeThr *>::iterator tit = CmdThrExeList.begin();
    20202042      tit != CmdThrExeList.end(); tit++) {
    2021     if ((*tit)->Id() == id) {
    2022       (*tit)->cancel(); 
    2023       cout << "Commander::CancelThr()  Thread Id= " << id << " cancelled" << endl;
     2043    if ( ((*tit)->Id() == id) && !((*tit)->IfDone()) ) {
     2044      (*tit)->kill(SIGUSR1); 
     2045      cout << "Commander::StopThr()  Send signal SIGUSR1 to Thread Id= " << id << endl;
    20242046      return;
    20252047    }
    20262048  }
    2027   cout << "Commander::CancelThr()/Error: No thread with Id= " << id << endl;
     2049  cout << "Commander::StopThr()/Error: No active thread with Id= " << id << endl;
    20282050}
    20292051
     
    21432165
    21442166/* --Methode-- */
    2145 //! Produces a LaTeX file containing the registered command helps
     2167/*!
     2168  \brief Produces a LaTeX file containing the registered command helps
     2169  The file \b fname is created and can be inserted into a LaTeX document
     2170  in order to produce the list of registered commands and corresponding description
     2171  texts.
     2172  The LaTeX file should contain the following definitions:
     2173\verbatim
     2174  \newcommand{\piacommand}[1]{
     2175    \framebox{\bf \Large #1 } \index{#1} % (Command)
     2176  }
     2177
     2178  \newcommand{\piahelpitem}[1]{
     2179    \framebox{\bf \Large #1 } \index{#1} (Help item)
     2180  }
     2181
     2182  \newcommand{\myppageref}[1]{ (p. \pageref{#1} ) }
     2183
     2184\endverbatim
     2185*/
    21462186void Commander::HelptoLaTeX(string const & fname)
    21472187{
Note: See TracChangeset for help on using the changeset viewer.