New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtual device #41

merged 122 commits into from Oct 2, 2017
Jump to file or symbol
Failed to load files and symbols.
+47 −1
Diff settings


Just for now

Viewing a subset of changes. View all

ctlra: add device by vendor api to show devices

This commit adds an API to get a list of devices supported by a
vendor. The vendor and device APIs can be easily used to build a
simple user-interface for selecting or showing users what devices
are supported by Ctlra.

Signed-off-by: Harry van Haaren <>
  • Loading branch information...
harryhaaren committed Sep 24, 2017
commit 7742f9d86c660c5a063c0f4b628a646eaed5bc69
@@ -77,6 +77,30 @@ struct ctlra_dev_t *ctlra_dev_connect(struct ctlra_t *ctlra,
return 0;
ctlra_get_devices_by_vendor(const char *vendor, const char *devices[],
int32_t size)
memset(devices, 0, sizeof(char *) * size);
int device_idx = 0;
int i;
for(i = 0; i < __ctlra_device_count; i++) {
if(__ctlra_devices[i].info) {
const char *v = __ctlra_devices[i].info->vendor;
const char *d = __ctlra_devices[i].info->device;
/* check this device is by vendor */
if(strcmp(vendor, v) == 0) {
if(device_idx >= size)
devices[device_idx++] = d;
return device_idx;
ctlra_get_vendors(const char *vendors[], int32_t size)
@@ -308,6 +308,23 @@ int32_t ctlra_dev_disconnect(struct ctlra_dev_t *dev);
int32_t ctlra_get_vendors(const char *vendors[], int32_t size);
/** Retrieve a list of devices by a specific vendor. The returned strings
* are human-readable names of devices. These names could be presented to
* the user in eg: a drop down box allowing the user to select a specific
* device. One use case could be virtualizing a specific hardware device
* @param vendor The vendor from which to find all supported devices. See
* the *ctlra_get_vendors* function to retrieve vendors.
* @param devices An array of at least *size* to be filled in with null
* terminated strings, with each string representing a device.
* @param size Size of the devices array passed in.
* @return The number of devices populated in the array
int32_t ctlra_get_devices_by_vendor(const char *vendor,
const char *devices[],
int32_t size);
/** Add a virtualized device. This function adds a "virtual" device, which
* provides the controls of the physical device by displaying a user
* interface. In order for this function to operate, the device being
@@ -142,9 +142,14 @@ int main(int argc, char **argv)
const char *vendors[32];
int ret = ctlra_get_vendors(vendors, 32);
printf("get vendors ret = %d\n", ret);
for(int i = 0; i < ret; i++) {
printf("%d: %s\n", i, vendors[i]);
const char *devices[32];
int devs = ctlra_get_devices_by_vendor(vendors[i],
devices, 32);
for(int j = 0; j < devs; j++) {
printf(" - %d: %s\n", j, devices[j]);
struct ctlra_t *ctlra = ctlra_create(NULL);
ProTip! Use n and p to navigate between commits in a pull request.