Skip to content

Commit

Permalink
Merge pull request #655 from o-sdn-o/gui-bridge
Browse files Browse the repository at this point in the history
Fix deadlock while synching config access
  • Loading branch information
o-sdn-o authored Oct 19, 2024
2 parents 55ee737 + ae1035e commit 6768e50
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 49 deletions.
7 changes: 6 additions & 1 deletion CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@
"variables": [
{
"name": "CMAKE_CXX_FLAGS_RELEASE",
"value": "/MT /O2 /DNDEBUG /EHsc /bigobj /utf-8 /Zc:preprocessor /W4",
"value": "/MT /O2 /DNDEBUG /EHsc /bigobj /utf-8 /Zi /Zc:preprocessor /W4",
"type": "STRING"
},
{
"name": "DCMAKE_EXE_LINKER_FLAGS_RELEASE",
"value": "/DEBUG /OPT:REF /OPT:ICF",
"type": "STRING"
}
]
Expand Down
6 changes: 4 additions & 2 deletions src/netxs/desktopio/ansivt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,8 +1420,10 @@ namespace netxs::ansi
intro.execute(traits.control, utf8, client); // Make one iteration using firstcmd and return.
return utf8;
};
auto y = [&](auto const& cluster){ client->post(cluster); };

auto y = [&](auto const& cluster)
{
client->post(cluster);
};
utf::decode(s, y, utf8, client->decsg);
client->flush();
}
Expand Down
58 changes: 35 additions & 23 deletions src/netxs/desktopio/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace netxs::app

namespace netxs::app::shared
{
static const auto version = "v0.9.99.24";
static const auto version = "v0.9.99.25";
static const auto repository = "https://github.com/directvt/vtm";
static const auto usr_config = "~/.config/vtm/settings.xml"s;
static const auto sys_config = "/etc/vtm/settings.xml"s;
Expand Down Expand Up @@ -599,35 +599,46 @@ namespace netxs::app::shared
map[app_typename] = builder;
}
};
struct gui_config_t
{
si32 winstate{};
bool aliasing{};
span blinking{};
twod wincoord{};
twod gridsize{};
si32 cellsize{};
std::list<text> fontlist;
};

void splice(xipc client, xmls& config)
auto get_gui_config(xmls& config)
{
auto gui_config = gui_config_t{ .winstate = config.take("/config/gui/winstate", win::state::normal, app::shared::win::options),
.aliasing = config.take("/config/gui/antialiasing", faux),
.blinking = config.take("/config/gui/blinkrate", span{ 400ms }),
.wincoord = config.take("/config/gui/wincoor", dot_mx),
.gridsize = config.take("/config/gui/gridsize", dot_mx),
.cellsize = std::clamp(config.take("/config/gui/cellheight", si32{ 20 }), 0, 256) };
if (gui_config.cellsize == 0) gui_config.cellsize = 20;
if (gui_config.gridsize == dot_00) gui_config.gridsize = dot_mx;
auto recs = config.list("/config/gui/fonts/font");
for (auto& f : recs)
{
//todo implement 'fonts/font/file' - font file path/url
gui_config.fontlist.push_back(f->take_value());
}
return gui_config;
}
void splice(xipc client, gui_config_t& gc)
{
if (os::dtvt::active || !(os::dtvt::vtmode & ui::console::gui)) os::tty::splice(client);
else
{
os::dtvt::client = client;
auto config_lock = ui::tui_domain().unique_lock(); // Sync multithreaded access to config.
auto winstate = config.take("/config/gui/winstate", win::state::normal, app::shared::win::options);
auto aliasing = config.take("/config/gui/antialiasing", faux);
auto blinking = config.take("/config/gui/blinkrate", span{ 400ms });
auto wincoord = config.take("/config/gui/wincoor", dot_mx);
auto gridsize = config.take("/config/gui/gridsize", dot_mx);
auto cellsize = std::clamp(config.take("/config/gui/cellheight", si32{ 20 }), 0, 256);
if (cellsize == 0) cellsize = 20;
if (gridsize == dot_00) gridsize = dot_mx;
auto fontlist = std::list<text>{};
auto recs = config.list("/config/gui/fonts/font");
for (auto& f : recs)
{
//todo implement 'fonts/font/file' - font file path/url
fontlist.push_back(f->take_value());
}
config_lock.unlock();
auto connect = [&]
{
auto event_domain = netxs::events::auth{};
auto window = event_domain.create<gui::window>(event_domain, fontlist, cellsize, aliasing, blinking);
window->connect(winstate, wincoord, gridsize);
auto window = event_domain.create<gui::window>(event_domain, gc.fontlist, gc.cellsize, gc.aliasing, gc.blinking);
window->connect(gc.winstate, gc.wincoord, gc.gridsize);
};
if (os::stdout_fd != os::invalid_fd)
{
Expand All @@ -645,11 +656,12 @@ namespace netxs::app::shared
void start(text cmd, text aclass, xmls& config)
{
auto [client, server] = os::ipc::xlink();
auto config_lock = ui::tui_domain().unique_lock(); // Sync multithreaded access to config.
auto gui_config = app::shared::get_gui_config(config);
auto thread = std::thread{ [&, &client = client] //todo clang 15.0.0 still disallows capturing structured bindings (wait for clang 16.0.0)
{
app::shared::splice(client, config);
app::shared::splice(client, gui_config);
}};
auto config_lock = ui::tui_domain().unique_lock(); // Sync multithreaded access to config.
auto domain = ui::host::ctor(server, config)->plugin<scripting::host>();
auto appcfg = eccc{ .cmd = cmd, .cfg = os::dtvt::active ? ""s : "<config simple=1/>"s };
auto applet = app::shared::builder(aclass)(appcfg, config);
Expand Down
22 changes: 13 additions & 9 deletions src/netxs/desktopio/consrv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2311,8 +2311,8 @@ struct impl : consrv
{
if (handle_ptr->link == &uiterm.target)
{
if (uiterm.target == &uiterm.normal) uiterm.update([&]{ proc(uiterm.normal); return faux; });
else if (uiterm.target == &uiterm.altbuf) uiterm.update([&]{ proc(uiterm.altbuf); return faux; });
if (uiterm.target == &uiterm.normal) unsync |= proc(uiterm.normal);
else if (uiterm.target == &uiterm.altbuf) unsync |= proc(uiterm.altbuf);
return true;
}
else
Expand All @@ -2329,7 +2329,7 @@ struct impl : consrv
if (auto iter2 = std::find_if(client.alters.begin(), client.alters.end(), [&](auto& altbuf){ return link == &altbuf; });
iter2 != client.alters.end()) // Buffer exists.
{
uiterm.update([&]{ proc(*iter2); return faux; });
unsync |= proc(*iter2);
return true;
}
}
Expand Down Expand Up @@ -3118,15 +3118,15 @@ struct impl : consrv
if constexpr (isreal())
{
auto active = scroll_handle.link == &uiterm.target || scroll_handle.link == uiterm.target; // Target buffer can be changed during vt execution (eg: switch to altbuf).
if (!direct(packet.target, [&](auto& scrollback){ active ? uiterm.ondata(crop)
: uiterm.ondata(crop, &scrollback); }))
if (!direct(packet.target, [&](auto& scrollback){ return active ? uiterm.ondata_direct(crop)
: uiterm.ondata_direct(crop, &scrollback); }))
{
datasize = 0;
}
}
else
{
uiterm.ondata(crop);
unsync |= uiterm.ondata_direct(crop);
}
log("\t", show_page(packet.input.utf16, codec.codepage), ": ", ansi::hi(utf::debase<faux, faux>(crop)));
scroll_handle.toUTF8.erase(0, crop.size()); // Delete processed data.
Expand Down Expand Up @@ -3184,6 +3184,7 @@ struct impl : consrv
auto success = direct(packet.target, [&](auto& scrollback)
{
scrollback._data(count, filler.pick(), cell::shaders::meta);
return true;
});
if (!success)
{
Expand Down Expand Up @@ -3229,6 +3230,7 @@ struct impl : consrv
line.crop(maxsz);
}
scrollback._data<true>(count, line.pick(), cell::shaders::text);
return true;
});
if (!success)
{
Expand Down Expand Up @@ -3454,6 +3456,7 @@ struct impl : consrv
auto success = direct(packet.target, [&](auto& scrollback)
{
uiterm.write_block(scrollback, dest, crop.coor, rect{ dot_00, window_inst.panel }, cell::shaders::full); // cell::shaders::skipnuls for transparency?
return true;
});
if (!success) crop = {};
}
Expand Down Expand Up @@ -3482,7 +3485,7 @@ struct impl : consrv
auto& packet = payload::cast(upload);
if constexpr (isreal())
{
if (!direct(packet.target, [&](auto& scrollback){ scrollback.brush = attr_to_brush(packet.input.color); }))
if (!direct(packet.target, [&](auto& scrollback){ scrollback.brush = attr_to_brush(packet.input.color); return faux; }))
{
log("\tdirect()", os::unexpected);
}
Expand Down Expand Up @@ -3550,7 +3553,7 @@ struct impl : consrv
if (count > maxsz) count = std::max(0, maxsz);
filler.kill();
filler.size(count, c);
if (!direct(packet.target, [&](auto& scrollback){ scrollback._data(count, filler.pick(), cell::shaders::meta); }))
if (!direct(packet.target, [&](auto& scrollback){ scrollback._data(count, filler.pick(), cell::shaders::meta); return true; }))
{
count = 0;
}
Expand Down Expand Up @@ -3598,7 +3601,7 @@ struct impl : consrv
(head++)->wdt(utf::matrix::vs<21,21>);
}
}
if (!direct(packet.target, [&](auto& scrollback){ scrollback._data(count, filler.pick(), cell::shaders::text); }))
if (!direct(packet.target, [&](auto& scrollback){ scrollback._data(count, filler.pick(), cell::shaders::text); return true; }))
{
count = 0;
}
Expand Down Expand Up @@ -4393,6 +4396,7 @@ struct impl : consrv
{
uiterm.write_block(scrollback, filler, scrl.coor, clip, cell::shaders::full);
uiterm.write_block(scrollback, mirror, dest, clip, cell::shaders::full);
return true;
});
}
else
Expand Down
8 changes: 7 additions & 1 deletion src/netxs/desktopio/scripting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,15 @@ namespace netxs::scripting
vtty engine; // scripting::host: Scripting engine instance.

// scripting::host: Proceed input.
void ondata(view data)
auto ondata_direct(view data)
{
log<faux>(ansi::fgc(greenlt).add(data).nil());
return faux;
}
// scripting::host: Proceed input.
void ondata(view data)
{
ondata_direct(data);
}
// scripting::host: Cooked read input.
void data(rich& /*data*/)
Expand Down
30 changes: 18 additions & 12 deletions src/netxs/desktopio/terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6862,22 +6862,28 @@ namespace netxs::ui
}
// term: Proceed terminal input.
template<bool Forced = faux>
auto ondata_direct(view data = {}, bufferbase* target_buffer = {})
{
auto& console_ptr = target_buffer ? target_buffer : this->target;
if (data.size())
{
if (io_log) log(prompt::cout, "\n\t", utf::replace_all(ansi::hi(utf::debase(data)), "\n", ansi::pushsgr().nil().add("\n\t").popsgr()));
ansi::parse(data, console_ptr);
return true;
}
else
{
console_ptr->parser::flush(); // Update line style, etc.
return Forced;
}
}
// term: Proceed terminal input.
template<bool Forced = faux>
void ondata(view data = {}, bufferbase* target_buffer = {})
{
update([&]
{
auto& console_ptr = target_buffer ? target_buffer : this->target;
if (data.size())
{
if (io_log) log(prompt::cout, "\n\t", utf::replace_all(ansi::hi(utf::debase(data)), "\n", ansi::pushsgr().nil().add("\n\t").popsgr()));
ansi::parse(data, console_ptr);
return true;
}
else
{
console_ptr->parser::flush(); // Update line style, etc.
return Forced;
}
return ondata_direct<Forced>(data, target_buffer);
});
}
// term: Reset to defaults.
Expand Down
3 changes: 2 additions & 1 deletion src/vtm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,9 @@ int main(int argc, char* argv[])
auto cmd = script;
auto cfg = config.utf8();
auto win = os::dtvt::gridsz;
auto gui = app::shared::get_gui_config(config);
userinit.send(client, userid.first, os::dtvt::vtmode, env, cwd, cmd, cfg, win);
app::shared::splice(client, config);
app::shared::splice(client, gui);
return 0;
}
else return failed(denied ? code::noaccess : code::noserver);
Expand Down

0 comments on commit 6768e50

Please sign in to comment.