Esempio n. 1
0
UdisksManager::UdisksManager(QObject *parent)
    : QObject(parent)
{
    QDBusConnection system = QDBusConnection::systemBus();

    if (!system.isConnected())
    {
        emit error(tr("Cannot connect to Udisks daemon"));
    }

    system.connect("org.freedesktop.UDisks",
                    "/org/freedesktop/UDisks",
                    "org.freedesktop.UDisks",
                    "DeviceAdded",
                    this,
                    SLOT(onDeviceAdded(QDBusObjectPath)));
    system.connect("org.freedesktop.UDisks",
                    "/org/freedesktop/UDisks",
                    "org.freedesktop.UDisks",
                    "DeviceRemoved",
                    this,
                    SLOT(onDeviceRemoved(QDBusObjectPath)));
    system.connect("org.freedesktop.UDisks",
                    "/org/freedesktop/UDisks",
                    "org.freedesktop.UDisks",
                    "DeviceChanged",
                    this,
                    SLOT(onDeviceChanged(QDBusObjectPath)));

    QDBusInterface devEnum("org.freedesktop.UDisks",
                           "/org/freedesktop/UDisks",
                           "org.freedesktop.UDisks",
                           QDBusConnection::systemBus());

    QDBusMessage enumRes = devEnum.call("EnumerateDevices");
    // TODO/FIXME: error checking
//    if (enumRes.type() == QDBusMessage::ErrorMessage)
//    {
//        fprintf(stderr, "ERROR: Can't call EnumerateDevices\n");
//        fprintf(stderr, "       %s : %s\n", qPrintable(enumRes.errorName()), qPrintable(enumRes.errorMessage()));
//    }
//
//    if (enumRes.type() != QDBusMessage::ReplyMessage || !enumRes.arguments().at(0).canConvert<QDBusArgument>())
//    {
//        fprintf(stderr, "ERROR: Unexpected result type of EnumerateDevices call\n");
//    }
//
    const QDBusArgument enumArg = enumRes.arguments().at(0).value<QDBusArgument>();
//    if (enumArg.currentType() != QDBusArgument::ArrayType)
//    {
//        fprintf(stderr, "ERROR: Unexpected argument type of EnumerateDevices call\n");
//    }

    enumArg.beginArray();
    while (!enumArg.atEnd())
    {
        addDevice(qdbus_cast<QDBusObjectPath>(enumArg));
    }
    enumArg.endArray();
}
Esempio n. 2
0
NetworkManager::NetworkManager(QIODevice *serial, QObject *parent) :
    QObject(parent),
    serial(serial)
{
  QObject::connect(this, SIGNAL(deviceAdded(node_id,MacAddress)), this, SLOT(onDeviceAdded(node_id,MacAddress)));
  QObject::connect(this, SIGNAL(deviceRemoved(node_id)), this, SLOT(onDeviceRemoved(node_id)));
}
Esempio n. 3
0
/*
 Scans the USB system for boards and reports whether boards have been attached/removed.
*/
UsbMonitor::UsbMonitor(MainWindow* mw) : QThread()
{
  mainWindow = mw;
  qRegisterMetaType<BoardType::Type>("BoardType::Type"); // silly Qt thing to communicate via signal across a thread
  connect(this, SIGNAL(newBoards(QStringList, BoardType::Type)),
                       mainWindow, SLOT(onUsbDeviceArrived(QStringList, BoardType::Type)));
  connect(this, SIGNAL(boardsRemoved(QString)), mainWindow, SLOT(onDeviceRemoved(QString)));
  connect( &enumerator, SIGNAL(deviceDiscovered(QextPortInfo)), this, SLOT(onDeviceDiscovered(QextPortInfo)));
  connect( &enumerator, SIGNAL(deviceTerminated(QextPortInfo)), this, SLOT(onDeviceTerminated(QextPortInfo)));
  #ifdef Q_OS_MAC
  enumerator.setUpNotifications();
  #elif (defined Q_OS_WIN)
  QList<QextPortInfo> ports = enumerator.getPorts();
  if( ports.count())
  {
    QStringList boards;
    foreach( QextPortInfo port, ports )
      onDeviceDiscovered( port );
  }
  enumerator.setUpNotifications();
  #endif
}