Skip to content

Commit

Permalink
hideo-shell: Application can be started and create instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Jan 4, 2025
1 parent 9d424b7 commit e02e49b
Show file tree
Hide file tree
Showing 32 changed files with 174 additions and 33 deletions.
1 change: 1 addition & 0 deletions meta/image/efi/boot/loader.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"bundle://grund-seat/_bin",
"bundle://grund-shell/_bin",
"bundle://grund-bus/_bin",
"bundle://hideo-calculator.main/_bin",
"bundle://hideo-shell/wallpapers/winter.qoi",
"bundle://fonts-inter/fonts/Inter-Regular.ttf",
"bundle://fonts-inter/fonts/Inter-Medium.ttf",
Expand Down
4 changes: 4 additions & 0 deletions src/apps/hideo-calculator/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
#include "../app.h"

Async::Task<> entryPointAsync(Sys::Context &ctx) {
#ifdef __ck_sys_skift__
co_return co_await Ui::runAsync(ctx, Hideo::Calculator::app());
#else
co_return Ui::runApp(ctx, Hideo::Calculator::app());
#endif
}
3 changes: 3 additions & 0 deletions src/apps/hideo-shell/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ Ui::Child appStack(State const &state) {
apps.pushBack(
i->build() |
Ui::box({
.borderRadii = 6,
.borderWidth = 1,
.borderFill = Ui::GRAY800,
.shadowStyle = Gfx::BoxShadow::elevated(zindex ? 4 : 16),
}) |
Ui::placed(i->bound) |
Expand Down
1 change: 0 additions & 1 deletion src/apps/hideo-shell/mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ void MockLauncher::launch(State &s) {
name,
ramp
);
s.activePanel = Panel::NIL;
s.instances.emplaceFront(instance);
}

Expand Down
4 changes: 4 additions & 0 deletions src/apps/hideo-shell/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Ui::Task<Action> reduce(State &s, Action a) {
},
[&](StartInstance start) {
s.launchers[start.index]->launch(s);
s.activePanel = Panel::NIL;
},
[&](AddInstance add) {
s.instances.pushBack(add.instance);
},
[&](MoveInstance move) {
s.activePanel = Panel::NIL;
Expand Down
5 changes: 5 additions & 0 deletions src/apps/hideo-shell/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ struct StartInstance {
usize index;
};

struct AddInstance {
Strong<Instance> instance;
};

struct MoveInstance {
usize index;
Math::Vec2i off;
Expand Down Expand Up @@ -129,6 +133,7 @@ using Action = Union<
Unlock,
DimisNoti,
StartInstance,
AddInstance,
MoveInstance,
CloseInstance,
FocusInstance,
Expand Down
4 changes: 4 additions & 0 deletions src/impls/impl-efi/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ Res<Strong<Host>> makeHost(Child root) {
return Ok(makeStrong<EfiHost>(root, stip, front, back));
}

Async::Task<> runAsync(Sys::Context&,Child) {
notImplemented();
}

} // namespace Karm::Ui::_Embed
4 changes: 4 additions & 0 deletions src/impls/impl-sdl/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,8 @@ Res<Strong<Host>> makeHost(Child root) {
return Ok(host);
}

Async::Task<> runAsync(Sys::Context &, Child) {
notImplemented();
}

} // namespace Karm::Ui::_Embed
3 changes: 1 addition & 2 deletions src/impls/impl-skift/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"karm-logger-impl",
"karm-sys-impl",
"karm-pkg-impl",
"karm-sys-async-impl",
"karm-ui-impl"
"karm-sys-async-impl"
]
}
10 changes: 0 additions & 10 deletions src/impls/impl-skift/ui.cpp

This file was deleted.

34 changes: 34 additions & 0 deletions src/impls/impl-skift/ui/impl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <grund-bus/api.h>
#include <grund-shell/api.h>
#include <karm-ui/_embed.h>

namespace Karm::Ui::_Embed {

Res<Strong<Host>> makeHost(Child) {
notImplemented();
}

struct Host : public Ui::ProxyNode<Host> {
Rpc::Endpoint &_endpoint;
Rpc::Port _shell;
Grund::Shell::Api::Instance _instance;

Host(Child child, Rpc::Endpoint &endpoint, Rpc::Port shell, Grund::Shell::Api::Instance surface)
: Ui::ProxyNode<Host>(std::move(child)), _endpoint(endpoint), _shell(shell), _instance(surface) {}
};

Async::Task<> runAsync(Sys::Context &ctx, Child root) {
auto endpoint = Rpc::Endpoint::create(ctx);
auto shell = co_trya$(endpoint.callAsync<Grund::Bus::Api::Locate>(Rpc::Port::BUS, "grund-shell"s));
auto size = root->size({1024, 720}, Hint::MIN);
auto surface = co_trya$(endpoint.callAsync<Grund::Shell::Api::CreateInstance>(shell, size));

auto host = makeStrong<Host>(std::move(root), endpoint, shell, surface);

while (true) {
auto msg = co_trya$(endpoint.recvAsync());
logWarn("unsupported event: {}", msg.header());
}
}

} // namespace Karm::Ui::_Embed
19 changes: 19 additions & 0 deletions src/impls/impl-skift/ui/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "https://schemas.cute.engineering/stable/cutekit.manifest.component.v1",
"id": "impl-skift.ui",
"type": "lib",
"props": {
"cpp-excluded": true
},
"enableIf": {
"sys": [
"skift"
]
},
"requires": [
"karm-rpc"
],
"provides": [
"karm-ui-impl"
]
}
3 changes: 3 additions & 0 deletions src/libs/karm-ui/_embed.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#pragma once

#include <karm-sys/context.h>
#include <karm-ui/host.h>

namespace Karm::Ui::_Embed {

Res<Strong<Host>> makeHost(Child root);

Async::Task<> runAsync(Sys::Context &ctx, Child root);

} // namespace Karm::Ui::_Embed
4 changes: 4 additions & 0 deletions src/libs/karm-ui/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Res<> runApp(Sys::Context &, Child root) {
return try$(_Embed::makeHost(root))->run();
}

Async::Task<> runAsync(Sys::Context &ctx, Child root) {
return _Embed::runAsync(ctx, root);
}

void mountApp(Cli::Command &cmd, Slot rootSlot) {
Cli::Flag mobileArg = Cli::flag(NONE, "mobile"s, "Show mobile layout."s);

Expand Down
2 changes: 2 additions & 0 deletions src/libs/karm-ui/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Child inspector(Child child);

Res<> runApp(Sys::Context &ctx, Child root);

Async::Task<> runAsync(Sys::Context &ctx, Child root);

void mountApp(Cli::Command &cmd, Slot rootSlot);

} // namespace Karm::Ui
1 change: 1 addition & 0 deletions src/srvs/grund-av/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"requires": [
"grund-base",
"karm-rpc",
"karm-sys"
]
Expand Down
5 changes: 5 additions & 0 deletions src/srvs/grund-base/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://schemas.cute.engineering/stable/cutekit.manifest.component.v1",
"id": "grund-base",
"type": "lib"
}
22 changes: 16 additions & 6 deletions src/srvs/grund-bus/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ Res<> Service::activate(Sys::Context &ctx) {
auto &handover = useHandover(ctx);
auto urlStr = try$(Io::format("bundle://{}/_bin", _id));
auto *elf = handover.fileByName(urlStr.buf());
if (not elf)
if (not elf) {
logError("service not found: '{}'", _id);
return Error::invalidFilename("service not found");
}

logInfoIf(DEBUG_ELF, "mapping elf...");
auto elfVmo = try$(Hj::Vmo::create(Hj::ROOT, elf->start, elf->size, Hj::VmoFlags::DMA));
Expand Down Expand Up @@ -141,7 +143,7 @@ bool Service::accept(Rpc::Message const &msg) {
return contains(_listen, msg.header().mid);
}

// MARK: Locator ---------------------------------------------------------------
// MARK: System ----------------------------------------------------------------

System::System() {
_port = Rpc::Port::BUS;
Expand All @@ -165,26 +167,34 @@ Res<> System::send(Rpc::Message &msg) {
return Error::notFound("service not found");
} else if (msg.is<Api::Start>()) {
auto start = try$(msg.unpack<Api::Start>());
return _bus->startService(start.id);
logDebug("starting service '{}'", start.id);
return _bus->prepareActivateService(start.id);
}

return Ok();
}

// MARK: Bus -------------------------------------------------------------------

Karm::Res<Strong<Bus>> Bus::create(Sys::Context &ctx) {
Res<Strong<Bus>> Bus::create(Sys::Context &ctx) {
return Ok(makeStrong<Bus>(ctx));
}

Karm::Res<> Bus::startService(Str id) {
Res<> Bus::prepareService(Str id) {
auto service = try$(Service::prepare(_context, id));
try$(attach(service));
Async::detach(service->runAsync());
return Ok();
}

Karm::Res<> Bus::attach(Strong<Endpoint> endpoint) {
Res<> Bus::prepareActivateService(Str id) {
auto service = try$(Service::prepare(_context, id));
try$(attach(service));
Async::detach(service->runAsync());
return service->activate(_context);
}

Res<> Bus::attach(Strong<Endpoint> endpoint) {
endpoint->attach(*this);
_endpoints.pushBack(endpoint);
return Ok();
Expand Down
4 changes: 3 additions & 1 deletion src/srvs/grund-bus/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ struct Bus : public Meta::Pinned {

Res<> dispatch(Rpc::Message &msg);

Res<> startService(Str id);
Res<> prepareService(Str id);

Res<> prepareActivateService(Str id);
};

} // namespace Grund::Bus
20 changes: 10 additions & 10 deletions src/srvs/grund-bus/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ Async::Task<> entryPointAsync(Sys::Context &ctx) {
auto system = co_try$(Bus::create(ctx));

co_try$(system->attach(makeStrong<System>()));
co_try$(system->startService("grund-av"s));
co_try$(system->startService("grund-conf"s));
co_try$(system->startService("grund-device"s));
co_try$(system->startService("grund-dhcp"s));
co_try$(system->startService("grund-dns"s));
co_try$(system->startService("grund-echo"s));
co_try$(system->startService("grund-fs"s));
co_try$(system->startService("grund-net"s));
co_try$(system->startService("grund-seat"s));
co_try$(system->startService("grund-shell"s));
co_try$(system->prepareService("grund-av"s));
co_try$(system->prepareService("grund-conf"s));
co_try$(system->prepareService("grund-device"s));
co_try$(system->prepareService("grund-dhcp"s));
co_try$(system->prepareService("grund-dns"s));
co_try$(system->prepareService("grund-echo"s));
co_try$(system->prepareService("grund-fs"s));
co_try$(system->prepareService("grund-net"s));
co_try$(system->prepareService("grund-seat"s));
co_try$(system->prepareService("grund-shell"s));

for (auto &endpoint : system->_endpoints)
co_try$(endpoint->activate(ctx));
Expand Down
1 change: 1 addition & 0 deletions src/srvs/grund-bus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"requires": [
"grund-base",
"karm-rpc",
"karm-sys"
]
Expand Down
1 change: 1 addition & 0 deletions src/srvs/grund-conf/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"requires": [
"grund-base",
"karm-rpc",
"karm-sys"
]
Expand Down
1 change: 1 addition & 0 deletions src/srvs/grund-device/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"requires": [
"grund-base",
"karm-rpc",
"karm-sys",
"hal"
Expand Down
1 change: 1 addition & 0 deletions src/srvs/grund-dhcp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"requires": [
"grund-base",
"karm-rpc",
"karm-sys"
]
Expand Down
1 change: 1 addition & 0 deletions src/srvs/grund-dns/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"requires": [
"grund-base",
"karm-rpc",
"karm-sys"
]
Expand Down
1 change: 1 addition & 0 deletions src/srvs/grund-echo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"requires": [
"grund-base",
"karm-rpc",
"karm-sys"
]
Expand Down
1 change: 1 addition & 0 deletions src/srvs/grund-fs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"requires": [
"grund-base",
"karm-rpc",
"karm-sys"
]
Expand Down
1 change: 1 addition & 0 deletions src/srvs/grund-net/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"requires": [
"grund-base",
"karm-rpc",
"karm-sys"
]
Expand Down
1 change: 1 addition & 0 deletions src/srvs/grund-seat/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"requires": [
"grund-base",
"karm-rpc",
"karm-sys"
]
Expand Down
14 changes: 12 additions & 2 deletions src/srvs/grund-shell/api.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#pragma once

namespace Grund::Shell {
#include <karm-math/vec.h>
#include <karm-rpc/base.h>

} // namespace Grund::Shell
namespace Grund::Shell::Api {

using Instance = usize;

struct CreateInstance {
using Response = Instance;
Math::Vec2i size;
};

} // namespace Grund::Shell::Api
Loading

0 comments on commit e02e49b

Please sign in to comment.