HALFRED
0.4.0
|
Overview.
The IOVirtual is an IODevice used mainly for unit testing.
It allows to emulate the behavior of connected IODevices. Each IOVirtual device has a number of gates, that allow it to be connected to other IOVirtual devices. When two or more IOVirtual devices are connected, writing to one of them will cause the data to be received by all the others.
Creating and destroying IOVirtual devices.
All IOVirtual device objects are created at runtime, by a call to IOVIRTUAL_Create function. This call allocates memory for a new IOVIRTUAL device descriptor (plus additional memory for data buffer). Such IOVirtual device is then ready to operate as a regular IODevice object. When done using, all IOVirtual devices should be destroyed to free allocated memory, by a call to IOVIRTUAL_Destroy function.
Using IOVirtual devices.
Once created, the IOVirtual devices are usually being connected to each other. This is done by a call to IOVIRTUAL_Connect. A complementary IOVIRTUAL_Disconnect function is also provided, allowing to disconnect the devices.
A typical usage scenario is presented below:
Functions | |
IODevice | IOVIRTUAL_Create (size_t buf_size, int number_of_gates) |
void | IOVIRTUAL_Destroy (IODevice iodevice) |
HALRESULT | IOVIRTUAL_Connect (IODevice iodev1, IODevice iodev2) |
HALRESULT | IOVIRTUAL_Disconnect (IODevice iodev1, IODevice iodev2) |
IODevice IOVIRTUAL_Create | ( | size_t | buf_size, |
int | number_of_gates | ||
) |
Creates a new virtual IODevice.
buf_size | size of the data buffer (in bytes) |
number_of_gates | number of gates to connect other IOVirtual devices |
void IOVIRTUAL_Destroy | ( | IODevice | iodevice | ) |
Destroys a virtual IODevice and frees all memory allocated for it. Note, that this function should NOT be used to free other types of IODevices.
iodevice | virtual IODevice |
Connects IOVirtual devices together.
iodev1 | first IOVirtual device |
iodev2 | second IOVirtual device |
HALRESULT_OK | if the devices were connected |
HALRESULT_NOT_ENOUGH_GATES | if one (or both) of the devices has no more free gates for connecting |