blob: 3fdcb8d00a0ac23f0e73263e486415205e7a40df [file] [log] [blame]
library fuchsia.netemul.sync;
using zx;
/// Simple data structure passed on netemul bus.
table Event {
/// User-defined event code.
1: int32 code;
/// string message.
2: string message;
/// serialized arguments.
3: vector<uint8> arguments;
};
/// Represents a named bus:
/// a bus is a broadcast pub/sub network that distributes Events.
/// Events are not stored, only forwarded to attached clients.
protocol Bus {
/// Publishes event on the bus.
Publish(Event data);
/// Publishes data on bus and only returns when data has been dispatched.
/// Use this if you need guarantees that the data was broadcast before continuing.
/// Note that this ensures that the data will be *published* to all listening clients,
/// but it cannot guarantee that all clients will have observed the event before it returns.
EnsurePublish(Event data) -> ();
/// Notifies client of new event.
-> OnBusData(Event data);
/// Get list of named clients.
GetClients() -> (vector<string> clients);
/// Notifies a client is now attached.
-> OnClientAttached(string client);
/// Notifies a client was detached.
-> OnClientDetached(string client);
/// Waits for up to |timeout| (nsec) for all the clients in |clients|.
/// Returns true if all clients are present on the bus before timeout expired.
/// If |result| is false, |absent| will contain the entries in |clients| that still weren't
/// present on the bus when the timout expired.
/// Use |timeout| <= 0 for indefinite wait.
WaitForClients(vector<string> clients, zx.duration timeout) -> (bool result, vector<string>? absent);
/// Waits for up to |timeout| (nsec) for an event that matches |data|.
/// Event equality is performed by comparing *all* set fields in |data|.
/// Returns true if event was received before timeout expired.
/// Use |timeout| <= 0 for indefinite wait.
WaitForEvent(Event data, zx.duration timeout) -> (bool result);
};
/// The SyncManager is the entry point to attach a client to a bus or use other synchronization
/// primitives.
/// The client's 'ticket' to remain on the bus is the channel obtained through the 'BusSubscribe' call.
[Discoverable]
protocol SyncManager {
/// Subscribes to bus 'busName' with a given client name.
/// Duplicate client names are disallowed and will cause the request to return unfulfilled.
BusSubscribe(string busName, string clientName, request<Bus> bus);
/// Waits on a named counter barrier with name |barrierName|.
/// Functon will return true if the number of waits pending on the barrier matches or exceeds
/// |threshold| before |timeout| (nsec) expires.
/// Use |timeout| <= 0 for indefinite wait.
WaitForBarrierThreshold(string barrierName, uint32 threshold, zx.duration timeout) -> (bool result);
};