-
Notifications
You must be signed in to change notification settings - Fork 42
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
Comments
also something like unix domain sockets pls |
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 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 |
A IPC similar to how dbus works would be cool
The text was updated successfully, but these errors were encountered: