class::hal::Switchboard

class hal::Switchboard
  : public hal::Device

The Switchboard class is used to interface with /dev/switchboard0 and similar devices.

The switchboard can connect two devices together such that when data is received on one device, it will be written to another device.

A good application for using the switchboard is connecting streaming audio devices together.

#include <sapi/hal.hpp>
Switchboard switchboard;
SwitchboardTerminal input("mic"); //will refer to /dev/mic
SwitchboardTerminal output("speaker"); //refers to /dev/speaker
SwitchboardConnection connection = switchboard.create_persistent_connnection(input, output);

Summary

Switchboard()

int create_fixed_size_connection(

const SwitchboardTerminal & input,
const SwitchboardTerminal & output,
s32 nbyte
) const

int create_persistent_connection(

const SwitchboardTerminal & input,
const SwitchboardTerminal & output,
s32 nbyte,
u32 o_flags
) const

int destroy_connection(

u16 id
) const

int destroy_connection(

SwitchboardConnection & connection
)

int get_active_connection_count() const

int get_available_connection() const

SwitchboardConnection get_connection(

u16 id
) const

int get_connection(

SwitchboardConnection & connection
) const

int get_info(

switchboard_info_t & info
) const

SwitchboardInfo get_info() const

virtual int open(

const arg::SourceFilePath & name,
const fs::OpenFlags & flags
)

void print_connections() const

int set_attr(

switchboard_attr_t & attr
) const

enum switchboard_flags

Members

Switchboard()

Constructs a new object.


int create_fixed_size_connection(

const SwitchboardTerminal & input,
const SwitchboardTerminal & output,
s32 nbyte
) const

create_fixed_size_connection

Parameters

  • input The input terminal

  • output The output terminal

  • nbyte The number of bytes to transfer

Returns

Zero on success or less than zero for an error


int create_persistent_connection(

const SwitchboardTerminal & input,
const SwitchboardTerminal & output,
s32 nbyte,
u32 o_flags
) const

Creates a new persistent connection on the switchboard.

Parameters

  • input The input terminal

  • output The output terminal

  • nbyte The number of bytes to transfer per transaction (default is maximum)

  • o_flags Additional flags to apply while creating the connection

Returns

The id number of the new connection or less than zero for an error

The connection will persist until it is disconnected using destroy_connection() or it encounters a read or write error.


int destroy_connection(

u16 id
) const

Destroys the specified connection.

Parameters

  • id The connection to disconnect

Returns

Zero on success

After a connection is destroyed, it can be used again. The connection may take some time to stop.


int destroy_connection(

SwitchboardConnection & connection
)

Disconnects the specified connection.

Parameters

  • connection A reference to the connection

int get_active_connection_count() const

Returns the number of active connections.


int get_available_connection() const

Gets a free connection that can be used for a new connection.

Returns

Less than zero if no connection is available


SwitchboardConnection get_connection(

u16 id
) const

Gets the connection specified by id.


int get_connection(

SwitchboardConnection & connection
) const

Reloads the latest status on the connection.

Parameters

  • connection A reference to the connection to reload

Returns

Zero on success

The connection parameter must have a valid id() value.

Switchboard sb;
sb.open();
SwitchboardConnection connection = sb.get_connection(0); //assumes 0 is a valid connection
printf("connection input bytes transferred %d\n", connection.input().bytes_transferred());
sleep(1);
sb.get_connection(connection); //grab the latest status
printf("connection input bytes transferred %d\n", connection.input().bytes_transferred());

int get_info(

switchboard_info_t & info
) const

Gets information from the switchboard.


SwitchboardInfo get_info() const

Gets information from the switchboard.


virtual int open(

const arg::SourceFilePath & name,
const fs::OpenFlags & flags
)

Opens a switch board

Parameters

  • name The path to the switchboard (default is /dev/swithboard0)

Returns

Zero on success

To open a different switchboard, use

Switchboard sb1;
sb1.open("/dev/switchboard1");

void print_connections() const

int set_attr(

switchboard_attr_t & attr
) const

Sets the attributes of the switchboard.

Use connect() and disconnect() to manage basic connections. This method can do more advanced features.


enum switchboard_flags
  • CONNECT Connect Flag
  • DISCONNECT Disconnect Flag
  • IS_PERSISTENT Is Persistent Flag
  • IS_FIXED_SIZE Is Fixed Size Flag
  • IS_CONNECTED Connection is connected and running (otherwise IS_ERROR, IS_CANCELED, or IS_DESTROYED)
  • IS_ERROR Stopped because of an error
  • IS_CANCELED Stopped because an operation was canceled
  • IS_DESTROYED Stopped because the connection was destroyed
  • IS_FILL_ZERO Fill output with zeros if no input data is available
  • IS_INPUT_NON_BLOCKING Execute input transactions as non-blocking
  • IS_OUTPUT_NON_BLOCKING Execute input transactions as non-blocking
  • IS_FILL_LAST_8 Fill output with last byte of most recent packet
  • IS_FILL_LAST_16 Fill output with last 16-bit word of most recent packet
  • IS_FILL_LAST_32 Fill output with last 32-bit word of most recent packet
  • IS_FILL_LAST_64 Fill output with last 64-bit word of most recent packet

X

Thanks for Coming!

Subscribe to news and updates