ListDevices.cpp

/**
 * ListDevices.cpp - for LibTiePie 0.5+
 *
 * This example prints all the available devices to the screen.
 *
 * Find more information on http://www.tiepie.com/LibTiePie .
 */

#include <iostream>
#include "libtiepie++.h"
#include "PrintInfo.h"

#if defined(__linux) || defined(__unix)
  #include <cstdlib>
#endif

using namespace std;
using namespace LibTiePie;

int main()
{
  int status = EXIT_SUCCESS;

  // Initialize library:
  Library::init();

  // Print library information:
  printLibraryInfo();

  // Update device list:
  DeviceList::update();

  // Get the number of connected devices:
  const uint32_t connectedDevices = DeviceList::count();

  if(connectedDevices != 0)
  {
    cout << "Available devices:" << endl;

    for(uint32_t index = 0; index < connectedDevices; index++)
    {
      DeviceListItem* item = 0;

      try
      {
        item = DeviceList::getItemByIndex(index);

        cout << "  Name: " << item->name() << endl;
        cout << "    Serial Number  : " << item->serialNumber() << endl;
        cout << "    Available types: " << deviceTypeToStr(item->types()) << endl;
      }
      catch(const exception& e)
      {
        cerr << "Exception: " << e.what() << endl;
        status = EXIT_FAILURE;
      }

      delete item;
    }
  }
  else
  {
    cerr << "No devices found!" << endl;
    status = EXIT_FAILURE;
  }

  // Exit library:
  Library::exit();

  return status;
}