safer API with ObjectPath, InterfaceName, BusName
the busName and interfacePath types transparently cast down to a string, (but not the other way around) so they are a perfect upgrade to type-safety. The only downside to them is that templates can often get them wrong. std.conv.to will return with a cast(T) prefix, which could slightly break existing code. I think the type-safety advantages are outweighing this corner case though. The current API has been fully upgraded and examples still run and work.
This commit is contained in:
parent
c4de569809
commit
db86451c7f
9 changed files with 206 additions and 76 deletions
|
@ -4,12 +4,12 @@ import ddbus;
|
|||
|
||||
void testCall(Connection conn) {
|
||||
for(int i = 0; i < 50; i++) {
|
||||
Message msg = Message("ca.thume.transience","/ca/thume/transience/screensurface",
|
||||
"ca.thume.transience.screensurface","testDot");
|
||||
Message msg = Message(busName("ca.thume.transience"), ObjectPath("/ca/thume/transience/screensurface"),
|
||||
interfaceName("ca.thume.transience.screensurface"), "testDot");
|
||||
conn.sendBlocking(msg);
|
||||
}
|
||||
Message msg2 = Message("ca.thume.transience","/ca/thume/transience/screensurface",
|
||||
"ca.thume.transience.screensurface","testPing");
|
||||
Message msg2 = Message(busName("ca.thume.transience"), ObjectPath("/ca/thume/transience/screensurface"),
|
||||
interfaceName("ca.thume.transience.screensurface"), "testPing");
|
||||
Message res = conn.sendWithReplyBlocking(msg2, 3.seconds);
|
||||
int result = res.read!int();
|
||||
writeln(result);
|
||||
|
|
|
@ -3,18 +3,18 @@ import ddbus;
|
|||
|
||||
void testServe(Connection conn) {
|
||||
auto router = new MessageRouter();
|
||||
MessagePattern patt = MessagePattern("/root","ca.thume.test","test");
|
||||
MessagePattern patt = MessagePattern(ObjectPath("/root"), interfaceName("ca.thume.test"), "test");
|
||||
router.setHandler!(int,int)(patt,(int par) {
|
||||
writeln("Called with ", par);
|
||||
return par;
|
||||
});
|
||||
patt = MessagePattern("/signaler","ca.thume.test","signal",true);
|
||||
patt = MessagePattern(ObjectPath("/signaler"), interfaceName("ca.thume.test"), "signal",true);
|
||||
router.setHandler!(void,int)(patt,(int par) {
|
||||
writeln("Signalled with ", par);
|
||||
});
|
||||
registerRouter(conn, router);
|
||||
writeln("Getting name...");
|
||||
bool gotem = requestName(conn, "ca.thume.ddbus.test");
|
||||
bool gotem = requestName(conn, busName("ca.thume.ddbus.test"));
|
||||
writeln("Got name: ",gotem);
|
||||
simpleMainLoop(conn);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue