Skip to content

Commit

Permalink
karm-sys: Renamed IPC to RPC.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Nov 13, 2024
1 parent 45c5f76 commit 793448a
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/impls/impl-skift/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <karm-base/panic.h>
#include <karm-logger/logger.h>
#include <karm-sys/context.h>
#include <karm-sys/ipc.h>
#include <karm-sys/rpc.h>

#include "fd.h"

Expand Down
26 changes: 13 additions & 13 deletions src/libs/karm-sys/ipc.h → src/libs/karm-sys/rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,42 +148,42 @@ struct Message {
// MARK: Primitive Operations --------------------------------------------------

template <typename T, typename... Args>
Res<> ipcSend(Sys::IpcConnection &con, Port to, u64 seq, Args &&...args) {
Res<> rpcSend(Sys::IpcConnection &con, Port to, u64 seq, Args &&...args) {
Message msg = Message::packReq<T>(to, seq, std::forward<Args>(args)...).take();

logDebug("ipcSend : {}, len: {}", msg.header(), msg.len());
logDebug("rpcSend : {}, len: {}", msg.header(), msg.len());
try$(con.send(msg.bytes(), msg.handles()));
return Ok();
}

static inline Async::Task<Message> ipcRecvAsync(Sys::IpcConnection &con) {
static inline Async::Task<Message> rpcRecvAsync(Sys::IpcConnection &con) {
Message msg;
auto [bufLen, hndsLen] = co_trya$(con.recvAsync(msg._buf, msg._hnds));
if (bufLen < sizeof(Header))
co_return Error::invalidData("invalid message");
msg._len = bufLen;
msg._hndsLen = hndsLen;

logDebug("ipcRecv: {}, len: {}", msg.header(), msg.len());
logDebug("rpcRecv: {}, len: {}", msg.header(), msg.len());
co_return msg;
}

// MARK: Ipc -------------------------------------------------------------------
// MARK: Rpc -------------------------------------------------------------------

struct Ipc {
struct Rpc {
Sys::IpcConnection _con;
bool _receiving = false;
Map<u64, Async::_Promise<Message>> _pending{};
u64 _seq = 1;

static Ipc create(Sys::Context &ctx) {
static Rpc create(Sys::Context &ctx) {
auto &channel = useChannel(ctx);
return Ipc{std::move(channel.con)};
return Rpc{std::move(channel.con)};
}

template <typename T, typename... Args>
Res<> send(Port port, Args &&...args) {
return ipcSend<T>(_con, port, _seq++, std::forward<Args>(args)...);
return rpcSend<T>(_con, port, _seq++, std::forward<Args>(args)...);
}

Async::Task<Message> recvAsync() {
Expand All @@ -196,7 +196,7 @@ struct Ipc {
}};

while (true) {
Message msg = co_trya$(ipcRecvAsync(_con));
Message msg = co_trya$(rpcRecvAsync(_con));

auto header = msg._header;

Expand All @@ -214,8 +214,8 @@ struct Ipc {
Res<> resp(Message &msg, Res<typename T::Response> message) {
auto header = msg._header;
if (not message)
return ipcSend<Error>(_con, header.from, header.seq, message.none());
return ipcSend<typename T::Response>(_con, header.from, header.seq, message.take());
return rpcSend<Error>(_con, header.from, header.seq, message.none());
return rpcSend<typename T::Response>(_con, header.from, header.seq, message.take());
}

template <typename T, typename... Args>
Expand All @@ -226,7 +226,7 @@ struct Ipc {

_pending.put(seq, std::move(promise));

co_try$(ipcSend<T>(_con, port, seq, std::forward<Args>(args)...));
co_try$(rpcSend<T>(_con, port, seq, std::forward<Args>(args)...));

Message msg = co_await future;

Expand Down
6 changes: 3 additions & 3 deletions src/srvs/grund-av/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <karm-sys/entry.h>
#include <karm-sys/ipc.h>
#include <karm-sys/rpc.h>

namespace Grund::Av {

Async::Task<> serv(Sys::Context &ctx) {
Sys::Ipc ipc = Sys::Ipc::create(ctx);
Sys::Rpc rpc = Sys::Rpc::create(ctx);

logInfo("service started");
while (true) {
co_trya$(ipc.recvAsync());
co_trya$(rpc.recvAsync());
logDebug("received message from system");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/srvs/grund-bus/api.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <karm-base/string.h>
#include <karm-sys/ipc.h>
#include <karm-sys/rpc.h>

namespace Grund::Bus {

Expand Down
4 changes: 2 additions & 2 deletions src/srvs/grund-bus/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ Res<> Service::activate(Sys::Context &ctx) {

Async::Task<> Service::runAsync() {
while (true) {
auto msg = co_trya$(Sys::ipcRecvAsync(_con));
auto msg = co_trya$(Sys::rpcRecvAsync(_con));

logDebug("Received message on service '{}' {}", _id, msg.header());

auto res = dispatch(msg);
if (not res)
co_try$(Sys::ipcSend<Error>(_con, port(), msg.header().seq, res.none()));
co_try$(Sys::rpcSend<Error>(_con, port(), msg.header().seq, res.none()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/srvs/grund-bus/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <karm-logger/logger.h>
#include <karm-mime/url.h>
#include <karm-sys/context.h>
#include <karm-sys/ipc.h>
#include <karm-sys/rpc.h>

namespace Grund::Bus {

Expand Down
6 changes: 3 additions & 3 deletions src/srvs/grund-conf/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <karm-sys/entry.h>
#include <karm-sys/ipc.h>
#include <karm-sys/rpc.h>

namespace Grund::Conf {

Async::Task<> serv(Sys::Context &ctx) {
Sys::Ipc ipc = Sys::Ipc::create(ctx);
auto rpc = Sys::Rpc::create(ctx);

logInfo("service started");
while (true) {
co_trya$(ipc.recvAsync());
co_trya$(rpc.recvAsync());
logDebug("received message from system");
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/srvs/grund-dhcp/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <karm-sys/entry.h>
#include <karm-sys/ipc.h>
#include <karm-sys/rpc.h>

namespace Grund::Dhcp {

Async::Task<> serv(Sys::Context &ctx) {
Sys::Ipc ipc = Sys::Ipc::create(ctx);
auto rpc = Sys::Rpc::create(ctx);

logInfo("service started");
while (true) {
co_trya$(ipc.recvAsync());
co_trya$(rpc.recvAsync());
logDebug("received message from system");
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/srvs/grund-dns/main.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#include <karm-sys/entry.h>
#include <karm-sys/ipc.h>
#include <karm-sys/rpc.h>

#include "../grund-bus/api.h"
#include "../grund-echo/api.h"

namespace Grund::Dns {

Async::Task<> serv(Sys::Context &ctx) {
Sys::Ipc ipc = Sys::Ipc::create(ctx);
auto rpc = Sys::Rpc::create(ctx);

logDebug("sending nonsens to system");

auto echoPort = co_trya$(ipc.callAsync<Bus::Locate>(Sys::Port::BUS, "grund-echo"s));
auto echoPort = co_trya$(rpc.callAsync<Bus::Locate>(Sys::Port::BUS, "grund-echo"s));
logDebug("located echo service at port: {}", echoPort);

auto res = co_trya$(ipc.callAsync<Echo::Request>(echoPort, "nonsens"s));
auto res = co_trya$(rpc.callAsync<Echo::Request>(echoPort, "nonsens"s));
logDebug("received response from system: {}", res);

logInfo("service started");
while (true) {
co_trya$(ipc.recvAsync());
co_trya$(rpc.recvAsync());
logDebug("received message from system");
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/srvs/grund-echo/main.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include <karm-sys/entry.h>
#include <karm-sys/ipc.h>
#include <karm-sys/rpc.h>

#include "api.h"

namespace Grund::Echo {

Async::Task<> serv(Sys::Context &ctx) {
Sys::Ipc ipc = Sys::Ipc::create(ctx);
auto rpc = Sys::Rpc::create(ctx);
while (true) {
auto msg = co_trya$(ipc.recvAsync());
auto msg = co_trya$(rpc.recvAsync());
if (msg.is<Echo::Request>()) {
auto req = co_try$(msg.unpack<Echo::Request>());
co_try$(ipc.resp<Echo::Request>(msg, Ok(req.msg)));
co_try$(rpc.resp<Echo::Request>(msg, Ok(req.msg)));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/srvs/grund-fs/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <karm-sys/entry.h>
#include <karm-sys/ipc.h>
#include <karm-sys/rpc.h>

namespace Grund::Fs {

Async::Task<> serv(Sys::Context &ctx) {
Sys::Ipc ipc = Sys::Ipc::create(ctx);
auto rpc = Sys::Rpc::create(ctx);

logInfo("service started");
while (true) {
co_trya$(ipc.recvAsync());
co_trya$(rpc.recvAsync());
logDebug("received message from system");
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/srvs/grund-net/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <karm-sys/entry.h>
#include <karm-sys/ipc.h>
#include <karm-sys/rpc.h>

namespace Grund::Net {

Async::Task<> serv(Sys::Context &ctx) {
Sys::Ipc ipc = Sys::Ipc::create(ctx);
auto rpc = Sys::Rpc::create(ctx);

logInfo("service started");
while (true) {
co_trya$(ipc.recvAsync());
co_trya$(rpc.recvAsync());
logDebug("received message from system");
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/srvs/grund-seat/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include <karm-sys/entry.h>
#include <karm-sys/ipc.h>
#include <karm-sys/rpc.h>

namespace Grund::Seat {

Async::Task<> serv(Sys::Context &ctx) {
Sys::Ipc ipc = Sys::Ipc::create(ctx);
auto rpc = Sys::Rpc::create(ctx);

logInfo("service started");
while (true) {
co_trya$(ipc.recvAsync());
co_trya$(rpc.recvAsync());
logDebug("received message from system");
}
}
Expand Down

0 comments on commit 793448a

Please sign in to comment.