Ignore:
Timestamp:
Mar 11, 2010, 11:40:22 AM (17 years ago)
Author:
Liván Ramírez Dorta <livanr68@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
2ef94a4
Parents:
a4e3c41
Message:

refs#873: Improve TolServer process structure

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@2052 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tolsh/tolsh.vfs/lib/app-tolsh/tolsh.tcl

    ra4e3c41 r542c12b  
    157157          exit
    158158        }
     159      } elseif {$opt eq "slave"} {
     160        # the next argument is the port number
     161        set options(server,port) [lindex $cmdline [expr {$i+1}]]
     162        incr i
     163        if {$options(runmode) ne "" && $options(runmode) ne "slave"} {
     164          puts "Replacing previous run mode '$options(runmode)' with 'slave'"
     165        }
     166        set options(runmode) "slave"
     167      } elseif {$opt eq "shared"} {
     168        if {$options(runmode) ne "" && $options(runmode) ne "shared"} {
     169          puts "Replacing previous run mode '$options(runmode)' with 'shared'"
     170        }
     171        set options(runmode) "shared"
    159172      } else {
    160173        append delayed_msg "\nignoring unknown option: '$item'"
    … …  
    302315  setup_pkg tolcomm
    303316  setup_pkg tlogger
     317  setup_pkg tequila
     318  setup_pkg tequilas
    304319
    305320  logtmp "auto_path = $::auto_path"
    306321  logtmp "leaving ::tolsh::setup_autopath" 
     322}
     323
     324proc GetHomeDir { } {
     325  global env
     326  # Check if we're using windows
     327  if { $::tcl_platform(platform) eq "windows" } {
     328    package require registry 1.0
     329    set key1 {HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders}
     330    set key2 {Personal}
     331    set env_home [ registry get $key1 $key2 ]
     332    if {[string match %USERPROFILE%* $env_home]} {
     333      set env_home [string replace $env_home 0 12 $env(USERPROFILE)]
     334    }
     335  } else {
     336    set env_home $env(HOME)
     337  }
     338  return $env_home
    307339}
    308340
    … …  
    333365  setup_autopath
    334366
    335   # Load Toltcl (+tol)
    336   #
    337   package require -exact Toltcl 2.0.1
    338   tol::initkernel $options(lang) $options(vmode)
    339 
    340   # Load initLibrary if required
    341   #
    342   if {$options(initlib)} {
    343     tol::initlibrary
    344   }
    345 
    346   set appdata [string trim \
     367  # Load Toltcl (+tol) and initLibrary if required
     368  #
     369  if {$options(runmode) != "server" && $options(runmode) != "shared"} {
     370    package require -exact Toltcl 2.0.1
     371    tol::initkernel $options(lang) $options(vmode)
     372
     373    if {$options(initlib)} {
     374      tol::initlibrary
     375    }
     376
     377    set appdata [string trim \
    347378               [lindex [::tol::info var [list Text TolAppDataPath]] 2] \"]
    348 
    349   logtmp "appdata = $appdata"
    350 
    351   set tolcomm_dir [file join $appdata tolcomm]
     379    logtmp "appdata = $appdata"
     380  }
     381
     382  set tolcomm_dir [file join [GetHomeDir] tolcomm]
    352383  file mkdir $tolcomm_dir
    353384
    354   # load rmtps_client
    355   #
    356   if {[catch {package require rmtps_client} msg]} {
    357     std "could not load rmtps_client: $msg"
    358   } else {
    359     ::rmtps_client::init [file join $tolcomm_dir "rmtps_client.log"]
    360     if {[catch rmtps_client::define_TOLAPI msg]} {
    361       std "could not load tol code for rmtps_client: $msg"
     385  # load rmtps_client and tolclient if required
     386  #
     387  if {$options(runmode) != "server" && $options(runmode) != "shared"} {
     388 
     389    if {[catch {package require rmtps_client} msg]} {
     390      std "could not load rmtps_client: $msg"
     391    } else {
     392      ::rmtps_client::init [file join $tolcomm_dir "rmtps_client.log"]
     393      if {[catch rmtps_client::define_TOLAPI msg]} {
     394        std "could not load tol code for rmtps_client: $msg"
     395      }
    362396    }
    363   }
    364397 
    365   # load tolclient
    366   #
    367   if {[catch {package require tolclient} msg]} {
    368     std "could not load tolclient: $msg"
    369   } else {
    370     ::tolclient::init [file join $tolcomm_dir "tolclient.log"]
    371     if {[catch ::tolclient::define_TOLAPI msg]} {
    372       std "could not load tol code for rmtps_client: $msg"
     398    if {[catch {package require tolclient} msg]} {
     399      std "could not load tolclient: $msg"
     400    } else {
     401      ::tolclient::init [file join $tolcomm_dir "tolclient.log"]
     402      if {[catch ::tolclient::define_TOLAPI msg]} {
     403        std "could not load tol code for rmtps_client: $msg"
     404      }
    373405    }
    374   }
    375 
    376   # Compile expression and tol file provided in the command line
    377   #
    378   foreach item $options(compile) {
    379     if {[lindex $item 0] eq "expr"} {
    380       tol::console eval [lindex $item 1]
    381     } elseif {[lindex $item 0] eq "file"} {
    382       tol::include [lindex $item 1]
     406   
     407  }
     408
     409  # Compile expression and tol file provided in the command line if required
     410  #
     411  if {$options(runmode) != "server" && $options(runmode) != "shared" \
     412                                    && $options(runmode) != "slave" } {
     413
     414    foreach item $options(compile) {
     415      if {[lindex $item 0] eq "expr"} {
     416        tol::console eval [lindex $item 1]
     417      } elseif {[lindex $item 0] eq "file"} {
     418        tol::include [lindex $item 1]
     419      }
    383420    }
     421
    384422  }
    385423 
    … …  
    392430    # enter the tcl event loop
    393431    vwait __forever__
     432   
    394433  } elseif {$options(runmode) eq "server"} {
    395     package require tolserver
    396     tolserver::start -port $options(server,port) \
    397         -logfile [file join $tolcomm_dir "tolserver.log"]
    398     vwait __forever__
    399   }
    400 }
     434    puts "runmode=server"
     435    run_as_server $tolcomm_dir
     436   
     437  } elseif {$options(runmode) eq "shared"} {
     438    puts "runmode=shared"
     439    run_as_shared   
     440 
     441  } elseif {$options(runmode) eq "slave"} {
     442    puts "runmode=slave"
     443    run_as_slave $tolcomm_dir   
     444  }
     445}
     446
     447proc ::tolsh::run_as_server {tolcomm_dir} {
     448  variable options
     449  package require tolserver
     450
     451  clone
     452  tolserver::start -port $options(server,port) \
     453    -logfile [file join $tolcomm_dir "tolserver.log"] \
     454    -compile $options(compile)
     455  vwait __forever__
     456}   
     457
     458proc ::tolsh::clone {} {
     459  variable options
     460
     461  puts "::tolsh::clone"
     462  set tolsh [info nameofexecutable]
     463  puts "exec shared"
     464  exec $tolsh -shared &
     465  after 5000            ;# wait for data sharing are created by 'shared'
     466  puts "exec slave"
     467  exec $tolsh -slave $options(server,port) &
     468}
     469
     470proc ::tolsh::run_as_shared {} {
     471  package require tolshared
     472
     473  tolshared::start
     474}   
     475
     476proc ::tolsh::run_as_slave {tolcomm_dir} {
     477  variable options
     478  package require tolslave
     479
     480  tolslave::start -port $options(server,port) \
     481    -logfile [file join $tolcomm_dir "tolslave.log"]
     482  vwait __forever__
     483}   
    401484
    402485proc ::tolsh::console_cmd { cmd } {
Note: See TracChangeset for help on using the changeset viewer.