Zig: Cross-mod: bus, services and lanes¶
Declarations¶
lane.protocol¶
| Zig | |
|---|---|
The lane protocol version this binding speaks.
lane.LaneInfo.json_keys¶
| Zig | |
|---|---|
Functions¶
busSubscribe¶
| Zig | |
|---|---|
Calls handler(topic, payload) for every message on topic, from mods of any language, on the publisher's thread. It returns a veto: true refuses a vetoable publish and false has no opinion, and a plain publish ignores it. Namespace topics, as "plot:enter".
- Parameters:
- topic :
[]const u8 - handler :
comptime fn ([]const u8, []const u8) bool
- topic :
- Return type:
Error!Subscription - Slots:
bus_subscribe
busPublish¶
| Zig | |
|---|---|
Sends payload to every subscriber of topic and returns how many ran; 0 means nobody is listening, which is not an error.
- Parameters:
- topic :
[]const u8 - payload :
[]const u8
- topic :
- Return type:
Error!u32 - Slots:
bus_publish
busPublishVetoable¶
| Zig | |
|---|---|
Sends payload and collects the subscribers' vetoes.
- Parameters:
- topic :
[]const u8 - payload :
[]const u8
- topic :
- Return type:
Error!Vetoable - Slots:
bus_publish_vetoable
busSubscriberCount¶
| Zig | |
|---|---|
How many subscribers topic has now.
- Parameters:
- topic :
[]const u8
- topic :
- Return type:
Error!u32 - Slots:
bus_subscriber_count
registerService¶
| Zig | |
|---|---|
Answers calls to name from mods of any language, and from native plugins through the bridge. provider(request, reply) runs on the caller's thread, also while this mod is disabled but loaded, since consumers resolve services in their own on_load.
- Parameters:
- name :
[]const u8 - provider :
comptime fn ([]const u8, *const Reply) bool
- name :
- Return type:
Error!ServiceRegistration - Slots:
service_register
callService¶
| Zig | |
|---|---|
Calls another mod's service, whatever language it is written in.
- Parameters:
- allocator :
std.mem.Allocator - name :
[]const u8 - request :
[]const u8
- allocator :
- Return type:
Error!CallOutcome - Slots:
service_call
listServicesJson¶
| Zig | |
|---|---|
Every registered service as the host's JSON array of {"name","mod"}, owned by the caller.
- Parameters:
- allocator :
std.mem.Allocator
- allocator :
- Return type:
Error![]u8 - Slots:
service_list
serviceCaller¶
| Zig | |
|---|---|
Inside a provider, the mod whose call is running; null outside one and for a caller with no mod, such as a native plugin through the bridge.
- Parameters:
- allocator :
std.mem.Allocator
- allocator :
- Return type:
Error!?[]u8 - Slots:
service_caller
lane.publish¶
| Zig | |
|---|---|
Publishes a lane, exclusively under name. fingerprint is the value of the contract and must not be 0, which means anyone may connect and which the host refuses. table is the provider's table of function pointers, data the pointer each of them receives; retain and release count leases on data. The lane is withdrawn automatically at unload. A name that is taken is Refused, and the host log names the holder.
- Parameters:
- name :
[]const u8 - fingerprint :
u64 - data :
?*anyopaque - table :
*const anyopaque - retain :
c.PierLaneRefFn - release :
c.PierLaneRefFn
- name :
- Return type:
core.Error!Publication - Slots:
lane_publish
lane.acquire¶
| Zig | |
|---|---|
Acquires a lane. fingerprint must be the value the consumer computed itself from the contract; 0 is not valid and always yields fingerprint.
- Parameters:
- name :
[]const u8 - fingerprint :
u64
- name :
- Return type:
core.Error!Outcome - Slots:
lane_acquire
lane.list¶
| Zig | |
|---|---|
Every lane. It passes no pointer at all, so it suits looking at what exists first.
- Parameters:
- allocator :
Allocator
- allocator :
- Return type:
core.Error!types.Owned(LaneInfo) - Slots:
lane_list
lane.listJson¶
| Zig | |
|---|---|
The raw JSON of the lane listing, unparsed, owned by the caller.
- Parameters:
- allocator :
Allocator
- allocator :
- Return type:
core.Error![]u8 - Slots:
lane_list
lane.Lease¶
| Zig | |
|---|---|
A lease on a published lane, kept to return it.
lane.Lease.isAlive¶
| Zig | |
|---|---|
Whether the provider is still there.
- Return type:
bool
lane.Lease.enter¶
| Zig | |
|---|---|
Enters the provider for one call. Null when the provider is gone. The caller makes its calls through the guard and then leaves, so the provider cannot unload underneath a call that is running:
| Text Only | |
|---|---|
- Return type:
?Guard
lane.Lease.release¶
| Zig | |
|---|---|
Returns the lease. Only a lease this mod holds. False when the provider is already gone, since the loader has released it by then and releasing again would be a double free.
- Return type:
core.Error!bool - Slots:
lane_release
lane.Guard¶
One call inside a provider. leave ends it.
lane.Guard.table¶
| Zig | |
|---|---|
The provider's table, which the contract names the type of.
- Parameters:
- Table :
comptime type
- Table :
- Return type:
*const Table
lane.Guard.data¶
| Zig | |
|---|---|
The pointer each function of the table receives.
- Return type:
?*anyopaque
lane.Guard.leave¶
| Zig | |
|---|---|
- Return type:
void
Subscription¶
One bus subscription, kept to end it.
Subscription.unsubscribe¶
| Zig | |
|---|---|
Ends the subscription; calling it twice is harmless.
- Return type:
Error!void - Slots:
bus_unsubscribe
Reply¶
The way a service provider answers: send the reply and return true, or send the reason and return false, which the caller receives unchanged as the provider's message.
Reply.send¶
| Zig | |
|---|---|
- Parameters:
- text :
[]const u8
- text :
- Return type:
void
ServiceRegistration¶
One service this mod provides, kept to withdraw it.
ServiceRegistration.unregister¶
| Zig | |
|---|---|
Withdraws the service; calling it twice is harmless.
- Return type:
Error!void - Slots:
service_unregister
lane.Publication¶
One publication. withdraw takes the lane back.
lane.Publication.withdraw¶
| Zig | |
|---|---|
Withdraws the lane; calling it twice is harmless. Every outstanding lease is released and a consumer's next liveness check sees the lane gone.
- Return type:
core.Error!void - Slots:
lane_unpublish
Vetoable¶
The result of one vetoable publish. There is no short circuit: after a veto the later subscribers still receive the message.
CallCode¶
How a service call ended, matching the PIER_SERVICE_* results.
CallOutcome¶
One service call's outcome. body is the reply for ok and the provider's message for provider_error, owned by the caller.
lane.Outcome¶
| Zig | |
|---|---|
How acquiring a lane ended.
lane.LaneInfo¶
| Zig | |
|---|---|
The registration record of a published lane.