Skip to main content

Crate chilen_ipc

Crate chilen_ipc 

Source
Expand description

§Chilen Inter-Process Communication library

§Warning

The project is under active development, so please be wary of any bugs you may find, and expect breaking API changes in the upcoming updates!

This library provides common data types and functions used to communicate with the chilen daemon. No additional crates are required to create a simple client.

Under the hood, chilen_ipc uses [interprocess] and [rmp_serde] to talk to the chilen daemon on a local socket. The type of socket used depends on your platform, and the startup configuration of the chilen daemon.

The daemon communicates by listening for commands, dispatching them, and sending back responses. It can also stream events to the client whenever there is an important state change, eg. the music library content changed, the player was paused, or the track queue changed.

§Examples

Note: all the examples provided require a running daemon instance to work.

Send a single command to a running daemon, get the response, and disconnect:

assert_eq!(
  send_command(
    Command::Ping,
    DEFAULT_SOCKET_NAME,
    &SocketType::default()
  ).unwrap(),
  Response::Pong
)

Connect to a running daemon, send a command and then disconnect:

  let conn = connect(
    // The socket the `daemon` listens on. Default socket address is provided in `chilen_ipc`, but
    // it shouldn't be used outside of testing
    DEFAULT_SOCKET_NAME,
    // The type of IPC socket `daemon` listens on
    &SocketType::default()
  ).unwrap();
  let mut conn = BufReader::new(conn);

  // Serialize and send the command to the `daemon`
  let cmd = chilen_ipc::serialize_command(&Command::Ping).unwrap();
  conn.get_mut().write_all(&cmd).unwrap();

  // The `daemon` will always respond to `Command::Ping` with `Response::Pong`
  assert_eq!(receive_response(&mut conn).unwrap(), Response::Pong);

  // Close the connection
  disconnect(&mut conn).unwrap();

Modules§

library
playback

Enums§

Command
Command that can be executed by a daemon instance.
Error
Error related to the daemon.
Event
Event from the daemon received in Response::Event.
Response
Response sent to a client from the daemon.
SocketType
Defines the socket type to use when attempting to connect to a daemon.
Stream
Local socket byte stream, obtained either from Listener or by connecting to an existing local socket.

Constants§

DEFAULT_SOCKET_NAME
The default name of the socket the daemon listens on.

Functions§

connect
Connects to the daemon via a local socket and returns the connection Stream.
disconnect
Disconnects from the daemon by sending the Command::Disconnect command.
get_socket
Attempts to get a socket address for daemon IPC.
receive_response
Receive a daemon response from a buffered stream connection.
send_command
Executes a single daemon command on a new connection and closes it.
serialize_command
Serialize a client command to a format that can be sent to the daemon.