Beispiel #1
0
bool UPower::connectInterfaces() {
    if(m_interface==0 || !m_interface->isValid()) {
        m_interface = new QDBusInterface("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower",
                                         QDBusConnection::systemBus());
        if(!m_interface->isValid()) {
	    m_interface->deleteLater();
            m_interface = 0;
	    if (m_interfaceProps)
                m_interfaceProps->deleteLater();
            m_interfaceProps = 0;
            return false;
        }

        connect(m_interface, SIGNAL(DeviceAdded(QString)), this, SLOT(deviceAdded(QString)));
        connect(m_interface, SIGNAL(DeviceRemoved(QString)), this, SIGNAL(batteryDisconnected(QString)));
        connect(m_interface, SIGNAL(Changed()), this, SLOT(changed()));
    }

    if(m_interfaceProps==0 || !m_interfaceProps->isValid()) {
        m_interfaceProps = new QDBusInterface("org.freedesktop.UPower", "/org/freedesktop/UPower",
                                              "org.freedesktop.DBus.Properties", QDBusConnection::systemBus());
        if(!m_interfaceProps->isValid()) {
	    if (m_interface)
	        m_interface->deleteLater();
            m_interface = 0;
	    m_interfaceProps->deleteLater();
            m_interfaceProps = 0;
            return false;
        }
    }

    emit upowerAvailable();

    return true;
}
bool CDeviceKitDisksProvider::PumpDriveChangeEvents(IStorageEventsCallback *callback)
{
  bool result = false;
  if (m_connection)
  {
    dbus_connection_read_write(m_connection, 0);
    DBusMessage *msg = dbus_connection_pop_message(m_connection);

    if (msg)
    {
      char *object;
      if (dbus_message_get_args (msg, NULL, DBUS_TYPE_OBJECT_PATH, &object, DBUS_TYPE_INVALID))
      {
        result = true;
        if (dbus_message_is_signal(msg, "org.freedesktop.DeviceKit.Disks", "DeviceAdded"))
          DeviceAdded(object, callback);
        else if (dbus_message_is_signal(msg, "org.freedesktop.DeviceKit.Disks", "DeviceRemoved"))
          DeviceRemoved(object, callback);
        else if (dbus_message_is_signal(msg, "org.freedesktop.DeviceKit.Disks", "DeviceChanged"))
          DeviceChanged(object, callback);
      }
      dbus_message_unref(msg);
    }
  }
  return result;
}
void Udisks2Lister::UnmountDevice(const QString& id) {
  QReadLocker locker(&device_data_lock_);
  if (!device_data_.contains(id)) return;

  OrgFreedesktopUDisks2FilesystemInterface filesystem(
      udisks2_service_, device_data_[id].dbus_path,
      QDBusConnection::systemBus());

  if (filesystem.isValid()) {
    auto unmount_result = filesystem.Unmount(QVariantMap());
    unmount_result.waitForFinished();

    if (unmount_result.isError()) {
      qLog(Warning) << "Failed to unmount " << id << ": "
                    << unmount_result.error();
      return;
    }

    OrgFreedesktopUDisks2DriveInterface drive(udisks2_service_,
                                              device_data_[id].dbus_drive_path,
                                              QDBusConnection::systemBus());

    if (drive.isValid()) {
      auto eject_result = drive.Eject(QVariantMap());
      eject_result.waitForFinished();

      if (eject_result.isError())
        qLog(Warning) << "Failed to eject " << id << ": "
                      << eject_result.error();
    }

    device_data_.remove(id);
    DeviceRemoved(id);
  }
}
Beispiel #4
0
void DeviceKitLister::DBusDeviceRemoved(const QDBusObjectPath& path) {
  QString id;
  {
    QMutexLocker l(&mutex_);
    id = FindUniqueIdByPath(path);
    if (id.isNull()) return;

    device_data_.remove(id);
  }

  emit DeviceRemoved(id);
}
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	// UpdateDeviceStates()
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	void PlugIn::UpdateDeviceStates() 
	{
		// Get the current state of all the devices plugged in from the SampleAssistant
		DPA::Sample::AutoFreeUnboundedArray<DPA::Sample::DeviceState> deviceStates;
		DPA::Sample::GetDeviceStates(mAssistantPort, mDeviceEventPort->GetMachPort(), deviceStates);
		
		// Determine how many devices have been removed (if any).
		// This will be done by iterating over all the devices the PlugIn knows about and making sure they are present in the deviceStates array
		{
			std::vector<Device*> removedDevices;

			for (UInt32 i = 0 ; i < GetNumberDevices() ; ++i)
			{
				Device* device = static_cast<Device*>(GetDeviceByIndex(i));
				bool found = false;
				
				// See if it can be located in the deviceStates array
				for (UInt32 ii = 0; ii < deviceStates.GetLength() ; ++ii)
				{
					if (deviceStates[ii].mGUID == device->GetDeviceGUID())
					{
						found = true;
						break;
					}
				}
				
				// If the device was not found, stick into the vector of unplugged devices
				if (not found)
					removedDevices.push_back(device);
			}
			
			// Remove all the unplugged devices
			for (std::vector<Device*>::iterator i = removedDevices.begin() ; i != removedDevices.end() ; ++i)
				DeviceRemoved(**i);
		}

		// Determine how many new devices are present
		{
			for (UInt32 i = 0; i < deviceStates.GetLength() ; ++i)
			{
				try
				{
					// This will throw an exception if the device is not found
					(void) GetDeviceByGUID(deviceStates[i].mGUID);
				}
				catch (...)
				{
					// No device was found with the indicated GUID, so it is a new device
					DeviceArrived(deviceStates[i].mGUID, deviceStates[i].mRegistryPath);
				}
			}
		}
	}
void iLister::DeviceRemovedCallback(const char* uuid) {
  QString id = UniqueId(uuid);
  {
    QMutexLocker l(&mutex_);
    if (!devices_.contains(id))
      return;

    devices_.remove(id);
  }

  emit DeviceRemoved(id);
}
LRESULT CInterfacePlugInWnd::OnMyDeviceChange(WPARAM wParam, LPARAM lParam)
{
  PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam;

  switch (wParam)
  {
    case DBT_DEVICEARRIVAL: DeviceAdded(pHdr); break;
    case DBT_DEVICEREMOVECOMPLETE: DeviceRemoved(pHdr); break;
	default: break;
  }

  return 0;
}
Beispiel #8
0
void GioLister::MountRemoved(GMount *mount) {
  QString id;
  {
    QMutexLocker l(&mutex_);
    id = FindUniqueIdByMount(mount);
    if (id.isNull())
      return;

    devices_.remove(id);
  }

  emit DeviceRemoved(id);
}
Beispiel #9
0
void GioLister::VolumeRemoved(GVolume* volume) {
  QString id;
  {
    QMutexLocker l(&mutex_);
    id = FindUniqueIdByVolume(volume);
    if (id.isNull())
      return;

    devices_.remove(id);
  }

  emit DeviceRemoved(id);
}
Beispiel #10
0
void WmdmLister::WMDMDeviceRemoved(const QString& canonical_name) {
  QString id = CanonicalNameToId(canonical_name);
  {
    QMutexLocker l(&mutex_);
    if (!devices_.contains(id))
      return;

    devices_[id].device_->Release();
    devices_[id].storage_->Release();

    devices_.remove(id);
  }

  emit DeviceRemoved(id);
}
void Udisks2Lister::RemoveDevice(const QDBusObjectPath& device_path) {
  QWriteLocker locker(&device_data_lock_);
  QString id;
  for (const auto& data : device_data_) {
    if (data.dbus_path == device_path.path()) {
      id = data.unique_id();
      break;
    }
  }

  if (id.isEmpty()) return;

  qLog(Debug) << "UDisks2 device removed: " << device_path.path();
  device_data_.remove(id);
  DeviceRemoved(id);
}
Beispiel #12
0
 void LinuxDeviceManager::processDeviceRemoval(struct udev_device *dev)
 {
   log->debug("Processing device removal");
   const char *syspath_cstr = udev_device_get_syspath(dev);
   if (!syspath_cstr) {
     return;
   }
   const String syspath(syspath_cstr);
   try {
     Pointer<Device> device = removeDevice(syspath);
     DeviceRemoved(device);
   } catch(...) {
     /* Ignore for now */
     log->debug("Removal of an unknown device ignored.");
     return;
   }
   return;
 }
Beispiel #13
0
void GioLister::MountAdded(GMount* mount) {
  g_object_ref(mount);

  DeviceInfo info;
  info.ReadVolumeInfo(g_mount_get_volume(mount));
#ifdef HAVE_AUDIOCD
  if (info.volume_root_uri.startsWith("cdda"))
    // Audio CD devices are already handled by CDDA lister
    return;
#endif
  info.ReadMountInfo(mount);
  info.ReadDriveInfo(g_mount_get_drive(mount));
  if (!info.is_suitable())
    return;

  QString old_id;
  {
    QMutexLocker l(&mutex_);

    // The volume might already exist - either mounted or unmounted.
    foreach (const QString& id, devices_.keys()) {
      if (devices_[id].volume == info.volume) {
        old_id = id;
        break;
      }
    }

    if (!old_id.isEmpty() && old_id != info.unique_id()) {
      // If the ID has changed (for example, after it's been mounted), we need
      // to remove the old device.
      devices_.remove(old_id);
      emit DeviceRemoved(old_id);

      old_id = QString();
    }
    devices_[info.unique_id()] = info;
  }

  if (!old_id.isEmpty())
    emit DeviceChanged(old_id);
  else {
    emit DeviceAdded(info.unique_id());
  }
}
Beispiel #14
0
void DeviceKitLister::Init() {
  interface_.reset(new OrgFreedesktopUDisksInterface(
      OrgFreedesktopUDisksInterface::staticInterfaceName(),
      "/org/freedesktop/UDisks", QDBusConnection::systemBus()));

  // Get all the devices currently attached
  QDBusPendingReply<QList<QDBusObjectPath> > reply =
      interface_->EnumerateDevices();
  reply.waitForFinished();

  if (!reply.isValid()) {
    qLog(Warning) << "Error enumerating DeviceKit-disks devices:"
                  << reply.error().name() << reply.error().message();
    interface_.reset();
    return;
  }

  // Listen for changes
  connect(interface_.get(), SIGNAL(DeviceAdded(QDBusObjectPath)),
          SLOT(DBusDeviceAdded(QDBusObjectPath)));
  connect(interface_.get(), SIGNAL(DeviceRemoved(QDBusObjectPath)),
          SLOT(DBusDeviceRemoved(QDBusObjectPath)));
  connect(interface_.get(), SIGNAL(DeviceChanged(QDBusObjectPath)),
          SLOT(DBusDeviceChanged(QDBusObjectPath)));

  // Get information about each one
  QMap<QString, DeviceData> device_data;
  for (const QDBusObjectPath& path : reply.value()) {
    DeviceData data = ReadDeviceData(path);
    if (data.suitable) device_data[data.unique_id()] = data;
  }

  // Update the internal cache
  {
    QMutexLocker l(&mutex_);
    device_data_ = device_data;
  }

  // Notify about the changes
  for (const QString& id : device_data.keys()) {
    emit DeviceAdded(id);
  }
}
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	// Teardown()
	//	This is invoked when the DAL is torn down by CMIOHardwareUnload().  If the process quits or crashes, the DAL just vanishes.
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	void PlugIn::Teardown()
	{
		// Grab the muxtex for the plugIn's state
		CAMutex::Locker locker(GetStateMutex());
		
		// Cancel the dispatch source for the device event notifications
		if (NULL != mDeviceEventDispatchSource)
		{
			dispatch_source_cancel(mDeviceEventDispatchSource);
			dispatch_release(mDeviceEventDispatchSource);
			mDeviceEventDispatchSource = NULL;
		}

		// Do the full teardown if this is outside of the process being torn down or this is the master process
		if (not DALA::System::IsInitingOrExiting() or DALA::System::IsMaster())
		{
			// Teardown all the devices currently being managed
			while (0 != GetNumberDevices())
				DeviceRemoved(*static_cast<Device*>(GetDeviceByIndex(0)));
			
			// Teardown the super class
			DP::PlugIn::Teardown();
		}
		else
		{
			// Iterate over the devices and suspend and finalize them
			for (UInt32 i = 0 ; i < GetNumberDevices() ; ++i)
			{
				Device* device = static_cast<Device*>(GetDeviceByIndex(i));
				
				// Suspend the device
				device->Unplug();
				
				// Finalize (rather than teardown) the device
				device->Finalize();
			}
			
			// Teardown the super class
			DP::PlugIn::Teardown();
			
			// And leave the rest to die with the process...
		}
	}
Beispiel #16
0
void ColordEngine::init()
{
    // Creates a ColorD interface, it must be created with new
    // otherwise the object will be deleted when this block ends
    QDBusInterface *interface;
    interface = new QDBusInterface(QLatin1String("org.freedesktop.ColorManager"),
                                   QLatin1String("/org/freedesktop/ColorManager"),
                                   QLatin1String("org.freedesktop.ColorManager"),
                                   QDBusConnection::systemBus(),
                                   this);
    // listen to colord for device events
    connect(interface, SIGNAL(DeviceAdded(QDBusObjectPath)),
            this, SLOT(deviceAdded(QDBusObjectPath)));
    connect(interface, SIGNAL(DeviceRemoved(QDBusObjectPath)),
            this, SLOT(deviceRemoved(QDBusObjectPath)));
    connect(interface, SIGNAL(DeviceChanged(QDBusObjectPath)),
            this, SLOT(deviceChanged(QDBusObjectPath)));

    // listen to colord for profile events
    connect(interface, SIGNAL(ProfileAdded(QDBusObjectPath)),
            this, SLOT(profileAdded(QDBusObjectPath)));
    connect(interface, SIGNAL(ProfileRemoved(QDBusObjectPath)),
            this, SLOT(profileRemoved(QDBusObjectPath)));
    connect(interface, SIGNAL(ProfileChanged(QDBusObjectPath)),
            this, SLOT(profileChanged(QDBusObjectPath)));

    // Ask for profiles
    QDBusMessage msg;
    msg = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.ColorManager"),
                                         QLatin1String("/org/freedesktop/ColorManager"),
                                         QLatin1String("org.freedesktop.ColorManager"),
                                         QLatin1String("GetProfiles"));
    QDBusConnection::systemBus().callWithCallback(msg, this, SLOT(gotProfiles(QDBusMessage)));

    // Ask for devices
    QDBusMessage message;
    message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.ColorManager"),
                                             QLatin1String("/org/freedesktop/ColorManager"),
                                             QLatin1String("org.freedesktop.ColorManager"),
                                             QLatin1String("GetDevices"));
    QDBusConnection::systemBus().callWithCallback(message, this, SLOT(gotDevices(QDBusMessage)));
}
devicemodel::devicemodel(QObject* parent)
    :QAbstractListModel(parent)
{

    QHash<int, QByteArray> roles;
    roles.insert( devicemodel::DeviceName, "deviceName");
    roles.insert( devicemodel::DeviceLabel, "deviceLabel");
    setRoleNames(roles);


    m_deviceInterface = new org::freedesktop::UDisks( QString("org.freedesktop.UDisks"),
                                                      QString("/org/freedesktop/UDisks"),
                                                      QDBusConnection::systemBus(), this);

    connect(m_deviceInterface,SIGNAL(DeviceAdded(QDBusObjectPath)),this,
            SLOT(addDevice(QDBusObjectPath)));


    connect(m_deviceInterface,SIGNAL(DeviceRemoved(QDBusObjectPath)),this,
            SLOT(removeDevice(QDBusObjectPath)));

    listDevices();
}
void Udisks2Lister::HandleFinishedUnmountJob(
    const Udisks2Lister::PartitionData& partition_data,
    const QDBusObjectPath& mounted_object) {
  QWriteLocker locker(&device_data_lock_);
  QString id;
  for (auto& data : device_data_) {
    if (data.mount_paths.contains(mounted_object.path())) {
      qLog(Debug)
          << "UDisks2 umount job finished, found corresponding device: Drive = "
          << data.dbus_drive_path << " | Partition = " << data.dbus_path;
      data.mount_paths.removeOne(mounted_object.path());
      if (data.mount_paths.empty()) id = data.unique_id();
      break;
    }
  }

  if (!id.isEmpty()) {
    qLog(Debug) << "Partition " << partition_data.dbus_path
                << " has no more mount points, removing it from device list";
    device_data_.remove(id);
    DeviceRemoved(id);
  }
}