summaryrefslogtreecommitdiffstats
path: root/libk3bdevice
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-03-30 20:24:24 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-03-30 20:24:24 -0500
commit983ade75ae2f488477bbb796f52ce2135c202dfe (patch)
tree32fd2ad28d871b6f5f636ae5659391eac56665b5 /libk3bdevice
parent39728f666128bb7d8ab24c1e3835cf0ac3c1f092 (diff)
downloadk3b-983ade75ae2f488477bbb796f52ce2135c202dfe.tar.gz
k3b-983ade75ae2f488477bbb796f52ce2135c202dfe.zip
Use TDE hardware library instead of HAL when HAL is not available
Clean up spurious build files
Diffstat (limited to 'libk3bdevice')
-rw-r--r--libk3bdevice/Makefile.am10
-rw-r--r--libk3bdevice/k3bhalconnection.cpp303
-rw-r--r--libk3bdevice/k3bhalconnection.h27
3 files changed, 328 insertions, 12 deletions
diff --git a/libk3bdevice/Makefile.am b/libk3bdevice/Makefile.am
index 71b1b76..4489660 100644
--- a/libk3bdevice/Makefile.am
+++ b/libk3bdevice/Makefile.am
@@ -11,7 +11,6 @@ libk3bdevice_la_LIBADD = $(LIB_KIO) $(RESMGR_LIB) $(CAM_LIB) $(HAL_DBUS_LIBS) $(
# lib version 5 for K3b 1.0
libk3bdevice_la_LDFLAGS = $(all_libraries) -version-info 5:0:0 -no-undefined
-if include_HAL
libk3bdevice_la_SOURCES = k3bdevice.cpp k3bdevice_mmc.cpp k3bscsicommand.cpp \
k3btrack.cpp k3btoc.cpp k3bdevicemanager.cpp k3bmsf.cpp k3bdiskinfo.cpp \
k3bdeviceglobals.cpp k3bcrc.cpp k3bcdtext.cpp k3bhalconnection.cpp \
@@ -20,15 +19,6 @@ k3bdebug.cpp
include_HEADERS = k3bdevicemanager.h k3bdevice.h k3btoc.h k3btrack.h \
k3bdeviceglobals.h k3bdiskinfo.h k3bcdtext.h k3bmsf.h k3bdevicetypes.h \
k3bdevice_export.h k3bhalconnection.h k3bdebug.h
-else
-libk3bdevice_la_SOURCES = k3bdevice.cpp k3bdevice_mmc.cpp k3bscsicommand.cpp \
-k3btrack.cpp k3btoc.cpp k3bdevicemanager.cpp k3bmsf.cpp k3bdiskinfo.cpp \
-k3bdeviceglobals.cpp k3bcrc.cpp k3bcdtext.cpp k3bdebug.cpp
-
-include_HEADERS = k3bdevicemanager.h k3bdevice.h k3btoc.h k3btrack.h \
-k3bdeviceglobals.h k3bdiskinfo.h k3bcdtext.h k3bmsf.h k3bdevicetypes.h \
-k3bdevice_export.h k3bdebug.h
-endif
messages: rc.cpp
$(XGETTEXT) `find -name "*.cpp" -or -name "*.h"` -o $(podir)/libk3bdevice.pot
diff --git a/libk3bdevice/k3bhalconnection.cpp b/libk3bdevice/k3bhalconnection.cpp
index ca12457..1877d78 100644
--- a/libk3bdevice/k3bhalconnection.cpp
+++ b/libk3bdevice/k3bhalconnection.cpp
@@ -2,9 +2,11 @@
*
* $Id: sourceheader,v 1.3 2005/01/19 13:03:46 trueg Exp $
* Copyright (C) 2005-2007 Sebastian Trueg <trueg@k3b.org>
+ * Copyright (C) 2013 Timothy Pearson <kb9vqf@pearsoncomputing.net>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
+ * Copyright (C) 2013 Timothy Pearson <kb9vqf@pearsoncomputing.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,13 +23,17 @@
#include <tqtimer.h>
+#ifdef HAVE_HAL
// We acknowledge the the dbus API is unstable
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/connection.h>
#include <dbus/dbus.h>
#include <hal/libhal.h>
+#else // HAVE_HAL
+#include <tdehardwaredevices.h>
+#endif // HAVE_HAL
-
+#ifdef HAVE_HAL
static char** qstringListToArray( const TQStringList& s )
{
char** a = new char*[s.count()];
@@ -607,4 +613,299 @@ void K3bDevice::HalConnection::setupDBusTQtConnection( DBusConnection* dbusConne
d->dBusTQtConnection->dbus_connection_setup_with_qt_main( dbusConnection );
}
+#else // HAVE_HAL
+
+K3bDevice::HalConnection* K3bDevice::HalConnection::s_instance = 0;
+
+
+class K3bDevice::HalConnection::Private
+{
+ public:
+ Private()
+ : bOpen(false),
+ m_hwdevices(NULL) {
+ //
+ }
+
+ bool bOpen;
+ TDEHardwareDevices *m_hwdevices;
+
+ TQMap<TQString, TQString> udiDeviceMap;
+ TQMap<TQString, TQString> deviceUdiMap;
+
+ TQMap<TQString, bool> deviceMediumUdiMap;
+};
+
+
+K3bDevice::HalConnection* K3bDevice::HalConnection::instance()
+{
+ if (s_instance == 0) {
+ s_instance = new HalConnection(0);
+ }
+
+ if ((!s_instance->isConnected()) && (!s_instance->open())) {
+ k3bDebug() << "(K3bDevice::HalConnection) failed to initialize the TDE hardware backend." << endl;
+ }
+
+ return s_instance;
+}
+
+
+K3bDevice::HalConnection::HalConnection( TQObject* parent, const char* name )
+ : TQObject( parent, name )
+{
+ d = new Private();
+}
+
+
+K3bDevice::HalConnection::~HalConnection()
+{
+ s_instance = 0;
+ close();
+ delete d;
+}
+
+
+bool K3bDevice::HalConnection::isConnected() const
+{
+ return d->bOpen;
+}
+
+
+bool K3bDevice::HalConnection::open()
+{
+ // Initialize the TDE device manager
+ d->m_hwdevices = TDEGlobal::hardwareDevices();
+
+ // Connect device monitoring signals/slots
+ connect(d->m_hwdevices, TQT_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, TQT_SLOT(AddDeviceHandler(TDEGenericDevice*)));
+ connect(d->m_hwdevices, TQT_SIGNAL(hardwareRemoved(TDEGenericDevice*)), this, TQT_SLOT(RemoveDeviceHandler(TDEGenericDevice*)));
+ connect(d->m_hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(ModifyDeviceHandler(TDEGenericDevice*)));
+
+ d->bOpen = true;
+
+ //
+ // Report all devices
+ //
+ TDEGenericHardwareList hwlist = d->m_hwdevices->listAllPhysicalDevices();
+ TDEGenericDevice *hwdevice;
+ for (hwdevice = hwlist.first(); hwdevice; hwdevice = hwlist.next()) {
+ AddDeviceHandler(hwdevice);
+ }
+
+ return true;
+}
+
+
+void K3bDevice::HalConnection::close()
+{
+ d->bOpen = false;
+}
+
+
+TQStringList K3bDevice::HalConnection::devices() const
+{
+ return TQStringList(d->udiDeviceMap.values());
+}
+
+void K3bDevice::HalConnection::AddDeviceHandler(TDEGenericDevice* hwdevice)
+{
+ if (hwdevice->type() != TDEGenericDeviceType::Disk) {
+ return;
+ }
+ TQString udi = hwdevice->uniqueID();
+ TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
+
+ if (sdevice->diskType() & TDEDiskDeviceType::Optical) {
+ TQString blockDevice = sdevice->deviceNode();
+ if (!blockDevice.isEmpty()) {
+ k3bDebug() << "Mapping udi " << udi << " to device " << blockDevice << endl;
+ d->udiDeviceMap[udi] = blockDevice;
+ d->deviceUdiMap[blockDevice] = udi;
+ emit deviceAdded(blockDevice);
+ // Check for medium
+ if (sdevice->mediaInserted()) {
+ d->deviceMediumUdiMap[blockDevice] = true;
+ emit mediumChanged(blockDevice);
+ }
+ }
+ }
+}
+
+void K3bDevice::HalConnection::RemoveDeviceHandler(TDEGenericDevice* hwdevice)
+{
+ if (hwdevice->type() != TDEGenericDeviceType::Disk) {
+ return;
+ }
+ TQString udi = hwdevice->uniqueID();
+ TQString blockDevice = hwdevice->deviceNode();
+
+ TQMapIterator<TQString, TQString> it = d->udiDeviceMap.find(udi);
+ if (it != d->udiDeviceMap.end()) {
+ k3bDebug() << "Unmapping udi " << udi << " from device " << it.data() << endl;
+ emit deviceRemoved(it.data());
+ d->udiDeviceMap.erase(it);
+ d->deviceUdiMap.erase(it.data());
+
+ if (d->deviceMediumUdiMap[blockDevice]) {
+ d->deviceMediumUdiMap[blockDevice] = false;
+ emit mediumChanged(blockDevice);
+ }
+ }
+}
+
+void K3bDevice::HalConnection::ModifyDeviceHandler(TDEGenericDevice* hwdevice)
+{
+ if (hwdevice->type() != TDEGenericDeviceType::Disk) {
+ return;
+ }
+ TQString udi = hwdevice->uniqueID();
+ TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
+ TQString blockDevice = hwdevice->deviceNode();
+
+ if (d->deviceMediumUdiMap[blockDevice] != sdevice->mediaInserted()) {
+ d->deviceMediumUdiMap[blockDevice] = sdevice->mediaInserted();
+ emit mediumChanged(blockDevice);
+ }
+}
+
+
+int K3bDevice::HalConnection::lock(Device* dev)
+{
+ if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+ TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
+ TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
+ if (!hwdevice) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+
+ if (hwdevice->type() != TDEGenericDeviceType::Disk) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+ TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
+
+ if (sdevice->lockDriveMedia(true)) {
+ return org_freedesktop_Hal_Success;
+ }
+ else {
+ return org_freedesktop_Hal_Device_Volume_InvalidEjectOption;
+ }
+}
+
+
+int K3bDevice::HalConnection::unlock(Device* dev)
+{
+ if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+ TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
+ TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
+ if (!hwdevice) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+
+ if (hwdevice->type() != TDEGenericDeviceType::Disk) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+ TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
+
+ if (sdevice->lockDriveMedia(false)) {
+ return org_freedesktop_Hal_Success;
+ }
+ else {
+ return org_freedesktop_Hal_Device_Volume_InvalidEjectOption;
+ }
+}
+
+
+int K3bDevice::HalConnection::mount( K3bDevice::Device* dev,
+ const TQString& mountPoint,
+ const TQString& fstype,
+ const TQStringList& options )
+{
+ if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+ TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
+ TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
+ if (!hwdevice) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+
+ if (hwdevice->type() != TDEGenericDeviceType::Disk) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+ TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
+
+ // FIXME
+ // Options from 'options' are not currently loaded into 'optionString'
+ TQString optionString;
+ TQString mountedPath = sdevice->mountDevice(mountPoint, optionString);
+ if (mountedPath.isNull()) {
+ return org_freedesktop_Hal_CommunicationError;
+ }
+ else {
+ return org_freedesktop_Hal_Success;
+ }
+}
+
+
+int K3bDevice::HalConnection::unmount(K3bDevice::Device* dev, const TQStringList& options)
+{
+ if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+ TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
+ TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
+ if (!hwdevice) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+
+ if (hwdevice->type() != TDEGenericDeviceType::Disk) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+ TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
+
+ // FIXME
+ // Options from 'options' are not currently loaded into 'optionString'
+ TQString optionString;
+
+ if (!sdevice->unmountDevice(NULL)) {
+ // Unmount failed!
+ return org_freedesktop_Hal_CommunicationError;
+ }
+ else {
+ return org_freedesktop_Hal_Success;
+ }
+}
+
+
+int K3bDevice::HalConnection::eject(K3bDevice::Device* dev, const TQStringList& options)
+{
+ if (!d->deviceUdiMap.contains(dev->blockDeviceName())) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+ TQString udi = d->deviceUdiMap[dev->blockDeviceName()];
+ TDEGenericDevice *hwdevice = d->m_hwdevices->findByUniqueID(udi);
+ if (!hwdevice) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+
+ if (hwdevice->type() != TDEGenericDeviceType::Disk) {
+ return org_freedesktop_Hal_Device_Volume_NoSuchDevice;
+ }
+ TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
+
+ if (sdevice->ejectDriveMedia()) {
+ return org_freedesktop_Hal_Success;
+ }
+ else {
+ return org_freedesktop_Hal_Device_Volume_InvalidEjectOption;
+ }
+}
+
+#endif // HAVE_HAL
+
#include "k3bhalconnection.moc"
diff --git a/libk3bdevice/k3bhalconnection.h b/libk3bdevice/k3bhalconnection.h
index a57093f..232669e 100644
--- a/libk3bdevice/k3bhalconnection.h
+++ b/libk3bdevice/k3bhalconnection.h
@@ -26,8 +26,11 @@
#include <tqmap.h>
#include <tqstringlist.h>
+#ifdef HAVE_HAL
class DBusConnection;
-
+#else // HAVE_HAL
+class TDEGenericDevice;
+#endif // HAVE_HAL
namespace K3bDevice {
@@ -74,6 +77,7 @@ namespace K3bDevice {
*/
TQStringList devices() const;
+#ifdef HAVE_HAL
/**
* \internal
*/
@@ -83,6 +87,7 @@ namespace K3bDevice {
* \internal
*/
void removeDevice( const char* udi );
+#endif // HAVE_HAL
/**
* Error codes named as the HAL deamon raises them
@@ -176,6 +181,24 @@ namespace K3bDevice {
int eject( Device*,
const TQStringList& options = TQStringList() );
+#ifndef HAVE_HAL
+private slots:
+ /**
+ * \internal
+ */
+ void AddDeviceHandler(TDEGenericDevice*);
+
+ /**
+ * \internal
+ */
+ void RemoveDeviceHandler(TDEGenericDevice*);
+
+ /**
+ * \internal
+ */
+ void ModifyDeviceHandler(TDEGenericDevice*);
+#endif // HAVE_HAL
+
signals:
/**
* This signal gets emitted whenever HAL finds a new optical drive.
@@ -217,7 +240,9 @@ namespace K3bDevice {
class Private;
Private* d;
+#ifdef HAVE_HAL
void setupDBusTQtConnection( DBusConnection* dbusConnection );
+#endif // HAVE_HAL
};
}