From b0e45371a0985433472b08026fa7d2406c876260 Mon Sep 17 00:00:00 2001 From: aleteoryx Date: Thu, 7 Nov 2024 10:43:04 -0500 Subject: [PATCH] rpcbind who --- db/main.tcl | 5 +++++ main.tcl | 18 ++++++++++++++++++ state.tcl | 46 ++++++++++++++++++++++++++++++++++++++++++++++ ui/main.tcl | 2 -- 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 db/main.tcl create mode 100644 state.tcl diff --git a/db/main.tcl b/db/main.tcl new file mode 100644 index 0000000..ddd1a0d --- /dev/null +++ b/db/main.tcl @@ -0,0 +1,5 @@ +package require sqlite3 +package require logger + +set log [logger::init tclircc::db] + diff --git a/main.tcl b/main.tcl index 6ba70c1..7d9b664 100755 --- a/main.tcl +++ b/main.tcl @@ -10,8 +10,21 @@ set log [logger::init tclircc::main] ${log}::info "tclircc $version " ${log}::info "running from $path" +source state.tcl + +${log}::debug "starting db thread..." +set db_thread [thread::create -preserved] +state::manage_thread $db_thread tclircc::db +thread::send $db_thread [list variable path $path version $version] +if {[thread::send $db_thread [list source "$path[file separator]db[file separator]main.tcl"] result] == 1} { + ${log}::critical "couldn't start db thread: $result" + exit -1 +} +${log}::debug "started db thread." + ${log}::debug "starting ui thread..." set ui_thread [thread::create -preserved] +state::manage_thread $ui_thread tclircc::ui thread::send $ui_thread [list variable path $path version $version] if {[thread::send $ui_thread [list source "$path[file separator]ui[file separator]main.tcl"] result] == 1} { ${log}::critical "couldn't start ui thread: $result" @@ -19,6 +32,11 @@ if {[thread::send $ui_thread [list source "$path[file separator]ui[file separato } ${log}::debug "started ui thread." +update +foreach key [array names state::ns] { + ${log}::debug "thread \"$key\" has id [set state::ns($key)]" +} + ${log}::debug "opening main window..." thread::send $ui_thread {mk_toplevel name; return $name} mainwin ${log}::debug "main window opened: $mainwin" diff --git a/state.tcl b/state.tcl new file mode 100644 index 0000000..5141118 --- /dev/null +++ b/state.tcl @@ -0,0 +1,46 @@ +namespace eval state { + variable threads [list main [thread::id]] + variable log [logger::init tclircc::state] + variable logt [logger::init tclircc::state::threads] + + variable ns + + proc manage_thread {tid name} { + variable threads + variable logt + dict set threads $name $tid + ${logt}::debug "managing thread $tid as \"$name\"" + + thread::send -head $tid { + namespace eval state { + variable ns + proc update {} { + variable ns + thread::send -head [set ns(main)] state::update + } + } + } + + ::state::update + } + proc unmanage_thread {name} { + variable threads + variable logt + dict unset threads $name + ${logt}::debug "unmanaging thread $tid (\"$name\")" + ::state::update + } + proc update {} { + variable threads + dict for {name tid} $threads { + if ![thread::exists $tid] {dict unset $threads $name} + } + dict for {name tid} $threads { + set payload {array unset state::ns; } + dict for {n t} $threads { + append payload {set state::ns(} $n {) } $t {; } + } + thread::send -head $tid $payload + } + } +} diff --git a/ui/main.tcl b/ui/main.tcl index 6ffd943..5fd30da 100644 --- a/ui/main.tcl +++ b/ui/main.tcl @@ -1,5 +1,3 @@ -#!/bin/env tclsh - variable toplevel_count 0 variable toplevel_tabs variable toplevel_classes -- 2.45.2