Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPC #58

Open
Vild opened this issue Sep 14, 2016 · 2 comments
Open

IPC #58

Vild opened this issue Sep 14, 2016 · 2 comments
Labels
effort: high The issue will probably take a single contributor several days of work to resolve. priority: medium The issue makes it more difficult for people to use the software.
Milestone

Comments

@Vild
Copy link
Member

Vild commented Sep 14, 2016

A IPC similar to how dbus works would be cool

@Vild Vild added this to the Version 0.2 milestone Sep 14, 2016
@WebFreak001
Copy link
Member

also something like unix domain sockets pls

@WebFreak001
Copy link
Member

Suggestion for a (slow-ish, but convenient) dbus-like IPC system, but better integrated into the system:

interfaces live as a node in the filesystem (for example in /bus/...)

interfaces can have methods (callable), events (subscribable) and properties (get/set)

The low level API would be like this (implemented using filesystem APIs):

enum IPCType : ubyte {
  response,
  call,
  get,
  set
}

// server:

auto mail = ipc.create("/bus/org/webfreak/mail"); // creates a kind of connectionless IPC server (lite in-memory socket file, needs kernel API)

auto calls = ipc.read(mail); // basically just calls some file/socket read function so one can `select` or peek on IPC objects to implement event based non blocking servers
// ipc.read just converts the read lines into an array of IPC calls

auto call = calls[0];
ipc.respond(call.origin, call.id, Variant("bar")); // writes a special response call to origin
// origin is a FD translated to this program
// id is a specified request ID or 0 for none
// must always respond something to every request

ipc.emit(mail, "onNewMessage", ["argname": Variant("argvalue")]); // basically just calls onNewMessage on all subscribed ipc objects, needs some kernel API for broadcasting on the IPC object

// client:

auto mail = ipc.open("/bus/org/webfreak/mail"); // opens the IPC server for read/write

auto fooobj = ipc.call(mail, /* request ID */ 2, /* method */ "foo", ["argname": Variant("argvalue")]);
// basically just sends a call into the socket, returns an object which can be waited on for a return value
// serializes to some yet-to-be-specified format, for example {"method": "foo", "arguments": { "argname": "argvalue" }}
auto fooval = fooobj.value;

ipc.get(mail, /* request ID */ 3, "prop1"); // writes a special get call into the file (prioritized)
auto setobj = ipc.set(mail, /* request ID */ 4, "prop1", Variant("foo")); // sends a special set call into the socket (prioritized) for setting a property

// ipc.read would be used like in the server code to handle get for example & error responses

auto obj = ipc.subscribe(mail); // returns socket/file which receives events from mail
auto events = ipc.read(obj); // server just sends calls to subscribed

basically it would be entirely implemented in userspace using the filesystem APIs then. The filesystem API would need be extended to be able to create a IPC file which only lives in RAM which also removes itself and closes all listeners when the process closes, some API for prepending should be added.

The advantage here is also that permissions could be added to the file to restrict programs from opening it. A permission which restricts sending events to only the owner should also be added here.

The low level API is used for the protocol and cross program function calls and manual process handling.

The high level API could look like this:

// server api

IPCServer server = IPCServer.create("/bus/org/webfreak/mail");
server.register!MyClass; // auto register methods & properties
server.methods.foo = (string s) {}; // inserts metadata with compile time magic
server.props.bar = 5; // opDispatch

server.process(); // while (true) server.tick();
// or:
select(1, &server.handle, null, null, null); // optional
server.tick(); // reads blocking

// caller api

IPCObject obj = IPCObject.open("/bus/org/webfreak/mail");
// waits for a response on all calls & verifies for errors
obj.call.checkMail(); // call is a wrapper object with opDispatch
obj.event.onNewMessage ~= (string title, string body_) {}; // event is a wrapper object with opDispatch which also verifies the call with compile time reflection
Variant accounts = obj.get.mailAccounts;

For introspection a program would try calling introspect on the IPC object. This method would return some yet to be specified array of methods & properties which would be implemented by the high level API. If it doesn't respond or error responds then it should be treated as non introspectable interface.

@Vild Vild modified the milestones: Version 0.3, Version 0.4 Feb 27, 2018
@Vild Vild added effort: high The issue will probably take a single contributor several days of work to resolve. priority: medium The issue makes it more difficult for people to use the software. and removed enhancement labels Mar 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: high The issue will probably take a single contributor several days of work to resolve. priority: medium The issue makes it more difficult for people to use the software.
Projects
None yet
Development

No branches or pull requests

2 participants