|
|
|
@ -42,9 +42,7 @@ dbusHAL::dbusHAL(){
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
dbus_is_connected = false;
|
|
|
|
|
hal_is_connected = false;
|
|
|
|
|
aquiredPolicyPower = false;
|
|
|
|
|
hal_ctx = NULL;
|
|
|
|
|
|
|
|
|
|
// add pointer to this for filter_function()
|
|
|
|
|
myInstance=this;
|
|
|
|
@ -53,8 +51,6 @@ dbusHAL::dbusHAL(){
|
|
|
|
|
kdError() << "Can't connect to D-Bus" << endl;
|
|
|
|
|
m_dBusQtConnection = NULL;
|
|
|
|
|
}
|
|
|
|
|
if(!initHAL())
|
|
|
|
|
kdError() << "Can't connect to HAL" << endl;
|
|
|
|
|
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
}
|
|
|
|
@ -79,16 +75,6 @@ bool dbusHAL::isConnectedToDBUS() {
|
|
|
|
|
return dbus_is_connected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function return information about connection status to the HAL daemon.
|
|
|
|
|
* \return boolean with the state of the connection to HAL
|
|
|
|
|
* \retval true if connected
|
|
|
|
|
* \retval false if disconnected
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::isConnectedToHAL() {
|
|
|
|
|
return hal_is_connected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function return information if the org.freedesktop.Policy.Power
|
|
|
|
|
* interface was claimed.
|
|
|
|
@ -107,12 +93,10 @@ bool dbusHAL::aquiredPolicyPowerInterface() {
|
|
|
|
|
* \retval false if unsuccessful
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::reconnect() {
|
|
|
|
|
// free HAL context
|
|
|
|
|
freeHAL();
|
|
|
|
|
// close D-Bus connection
|
|
|
|
|
close();
|
|
|
|
|
// init D-Bus conntection and HAL context
|
|
|
|
|
return (initDBUS() && initHAL());
|
|
|
|
|
return (initDBUS());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@ -176,20 +160,6 @@ bool dbusHAL::initDBUS(){
|
|
|
|
|
"interface='org.freedesktop.DBus',"
|
|
|
|
|
"member='NameOwnerChanged'", NULL);
|
|
|
|
|
|
|
|
|
|
/* add a match rule to catch all signals going through the bus with HAL interface */
|
|
|
|
|
dbus_bus_add_match( dbus_connection, "type='signal',"
|
|
|
|
|
"interface='org.freedesktop.Hal.Manager',"
|
|
|
|
|
"member='DeviceAdded'", NULL);
|
|
|
|
|
dbus_bus_add_match( dbus_connection, "type='signal',"
|
|
|
|
|
"interface='org.freedesktop.Hal.Manager',"
|
|
|
|
|
"member='DeviceRemoved'", NULL);
|
|
|
|
|
dbus_bus_add_match( dbus_connection, "type='signal',"
|
|
|
|
|
"interface='org.freedesktop.Hal.Device',"
|
|
|
|
|
"member='PropertyModified'", NULL);
|
|
|
|
|
dbus_bus_add_match( dbus_connection, "type='signal',"
|
|
|
|
|
"interface='org.freedesktop.Hal.Device',"
|
|
|
|
|
"member='Condition'", NULL);
|
|
|
|
|
|
|
|
|
|
/* add a match rule to catch all signals going through the bus with ConsoleKit Interface */
|
|
|
|
|
dbus_bus_add_match( dbus_connection, "type='signal',"
|
|
|
|
|
"interface='org.freedesktop.ConsoleKit.Session',"
|
|
|
|
@ -318,418 +288,7 @@ bool dbusHAL::isPolicyPowerIfaceOwned(){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----> DBUS section :: END <---- */
|
|
|
|
|
/* ----> HAL section :: START <---- */
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function initialise the connection to HAL over the D-Bus daemon.
|
|
|
|
|
* \return boolean with the result of the operation
|
|
|
|
|
* \retval true if successful initialised HAL connection and context
|
|
|
|
|
* \retval false if unsuccessful
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::initHAL(){
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
if ( !dbus_is_connected ) {
|
|
|
|
|
freeHAL();
|
|
|
|
|
return false;
|
|
|
|
|
} else if ( hal_is_connected && (hal_ctx != NULL)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// could not connect to HAL, reset all and try again
|
|
|
|
|
freeHAL();
|
|
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
|
|
|
|
|
if (dbus_connection == NULL || dbus_error_is_set(&error)) {
|
|
|
|
|
kdError() << "could not open connection to system bus: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool hal_is_ready = dbus_bus_name_has_owner(dbus_connection, "org.freedesktop.Hal", &error);
|
|
|
|
|
|
|
|
|
|
if (!hal_is_ready) {
|
|
|
|
|
kdWarning() << "HAL is not ready. We will try later... " << endl;
|
|
|
|
|
|
|
|
|
|
if ( dbus_error_is_set( &error ) ) {
|
|
|
|
|
kdError() << "Error checking if hal service exists: " << error.message << endl;
|
|
|
|
|
dbus_error_free( &error );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
freeHAL();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if((hal_ctx = libhal_ctx_new()) == NULL) {
|
|
|
|
|
kdError() << "Could not init HAL context" << endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* setup dbus connection for hal */
|
|
|
|
|
if (!libhal_ctx_set_dbus_connection(hal_ctx, dbus_connection)) {
|
|
|
|
|
kdError() << "Could not set up connection to dbus for hal" << endl;
|
|
|
|
|
freeHAL();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* init the hal library */
|
|
|
|
|
if (!libhal_ctx_init(hal_ctx, &error)) {
|
|
|
|
|
kdError() << "Could not init hal library: " << error.message << endl;
|
|
|
|
|
freeHAL();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hal_is_connected = true;
|
|
|
|
|
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return hal_is_connected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function free the hal connection/context.
|
|
|
|
|
*/
|
|
|
|
|
void dbusHAL::freeHAL(){
|
|
|
|
|
|
|
|
|
|
if ( hal_ctx != NULL ) {
|
|
|
|
|
libhal_ctx_free( hal_ctx );
|
|
|
|
|
hal_ctx = NULL;
|
|
|
|
|
}
|
|
|
|
|
hal_is_connected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function try a reconnect to the HAL daemon only.
|
|
|
|
|
* \return boolean with the result of the operation
|
|
|
|
|
* \retval true if successful reconnected to HAL
|
|
|
|
|
* \retval false if unsuccessful
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::reconnectHAL() {
|
|
|
|
|
// free HAL context
|
|
|
|
|
freeHAL();
|
|
|
|
|
// init HAL context
|
|
|
|
|
return (initHAL());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function query a integer property from HAL for a given device
|
|
|
|
|
* \param udi TQString with the UDI of the device
|
|
|
|
|
* \param property TQString with the property
|
|
|
|
|
* \param returnval pointer to the return value
|
|
|
|
|
* \return If the query was successful or not
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::halGetPropertyInt(TQString udi, TQString property, int *returnval){
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
if (!initHAL() || udi.isEmpty() || property.isEmpty())
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
if (!libhal_device_property_exists(hal_ctx, udi.ascii(), property.ascii(), &error)) {
|
|
|
|
|
kdWarning() << "Property: " << property << " for: " << udi << " doesn't exist." << endl;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*returnval = libhal_device_get_property_int(hal_ctx, udi.ascii(), property.ascii(), &error);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
|
kdError() << "Fetching property: " << property << " for: " << udi
|
|
|
|
|
<< " failed with: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
goto out;
|
|
|
|
|
} else {
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function query a boolean property from HAL for a given device
|
|
|
|
|
* \param udi TQString with the UDI of the device
|
|
|
|
|
* \param property TQString with the property
|
|
|
|
|
* \param returnval pointer to the return value
|
|
|
|
|
* \return If the query was successful or not
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::halGetPropertyBool(TQString udi, TQString property, bool *returnval){
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
if (!initHAL() || udi.isEmpty() || property.isEmpty())
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
if (!libhal_device_property_exists(hal_ctx, udi.ascii(), property.ascii(), &error)) {
|
|
|
|
|
kdWarning() << "Property: " << property << " for: " << udi << " doesn't exist." << endl;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*returnval = libhal_device_get_property_bool(hal_ctx, udi.ascii(), property.ascii(), &error);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
|
kdError() << "Fetching property: " << property << " for: " << udi
|
|
|
|
|
<< " failed with: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
goto out;
|
|
|
|
|
} else {
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function query a Sting property from HAL for a given device
|
|
|
|
|
* \param udi TQString with the UDI of the device
|
|
|
|
|
* \param property TQString with the property
|
|
|
|
|
* \param returnval pointer to the return value
|
|
|
|
|
* \return If the query was successful or not
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::halGetPropertyString(TQString udi, TQString property, TQString *returnval){
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
if (!initHAL() || udi.isEmpty() || property.isEmpty())
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
if (!libhal_device_property_exists(hal_ctx, udi.ascii(), property.ascii(), &error)) {
|
|
|
|
|
kdWarning() << "Property: " << property << " for: " << udi << " doesn't exist." << endl;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*returnval = libhal_device_get_property_string(hal_ctx, udi.ascii(), property.ascii(), &error);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
|
kdError() << "Fetching property: " << property << " for: " << udi
|
|
|
|
|
<< " failed with: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
goto out;
|
|
|
|
|
} else {
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function query a String List property from HAL for a given device
|
|
|
|
|
* \param udi TQString with the udi of the device
|
|
|
|
|
* \param property TQString with the property to query
|
|
|
|
|
* \param devices TQStringList to return the values
|
|
|
|
|
* \return If the query was successful or not
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::halGetPropertyStringList (TQString udi, TQString property, TQStringList *devices) {
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
if (!initHAL() || udi.isEmpty() || property.isEmpty())
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
char ** found;
|
|
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
if (!libhal_device_property_exists(hal_ctx, udi.ascii(), property.ascii(), &error)) {
|
|
|
|
|
kdWarning() << "Property: " << property << " for: " << udi << " doesn't exist." << endl;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
found = libhal_device_get_property_strlist (hal_ctx, udi.ascii(), property.ascii(), &error);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
|
kdWarning() << "Error while query existing strlist Property: " << property
|
|
|
|
|
<< " for: " << udi << " error: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
libhal_free_string_array(found);
|
|
|
|
|
goto out;
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; found[i] != NULL ; ++i) {
|
|
|
|
|
TQString _to_add = found[i];
|
|
|
|
|
if (!_to_add.isEmpty()) *devices += _to_add;
|
|
|
|
|
}
|
|
|
|
|
libhal_free_string_array(found);
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* This function query a capability from HAL for a given device
|
|
|
|
|
* \param udi TQString with the UDI of the device
|
|
|
|
|
* \param capability TQString with the capability to query
|
|
|
|
|
* \param returnval pointer to the return value as boolean
|
|
|
|
|
* \return If the query was successful or not
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::halQueryCapability(TQString udi, TQString capability, bool *returnval) {
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
if (!initHAL() || udi.isEmpty() || capability.isEmpty())
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
*returnval = libhal_device_query_capability(hal_ctx, udi.ascii(), capability.ascii(), &error);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
|
kdError() << "Fetching capability: " << capability << " for: " << udi
|
|
|
|
|
<< " failed with: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
goto out;
|
|
|
|
|
} else {
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* Use this function to check if a device has a specia property/key.
|
|
|
|
|
* \param udi TQString with the UDI of the device
|
|
|
|
|
* \param property TQString with the property
|
|
|
|
|
* \return If the query was successful or not
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::halDevicePropertyExist(TQString udi, TQString property ) {
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
if (!initHAL() || udi.isEmpty() || property.isEmpty())
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
if (! libhal_device_property_exists (hal_ctx, udi.ascii(), property.ascii(), &error)) {
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
|
kdError() << "Fetching existing property: " << property << " for: " << udi
|
|
|
|
|
<< " failed with: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
}
|
|
|
|
|
goto out;
|
|
|
|
|
} else {
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* Use this function to search find devices with a give capability
|
|
|
|
|
* \param capability TQString with the capability to query
|
|
|
|
|
* \param devices TQStringList to return the found devices
|
|
|
|
|
* \return If the query was successful or not
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::halFindDeviceByCapability (TQString capability, TQStringList *devices) {
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
char ** found;
|
|
|
|
|
int num = 0;
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
if (!initHAL() || capability.isEmpty())
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
found = libhal_find_device_by_capability (hal_ctx, capability.ascii(), &num, &error);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
|
kdError() << "Could not get list of devices with capability: " << capability
|
|
|
|
|
<< " error: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
libhal_free_string_array(found);
|
|
|
|
|
goto out;
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < num; ++i) {
|
|
|
|
|
TQString _to_add = found[i];
|
|
|
|
|
if (!_to_add.isEmpty()) *devices += _to_add;
|
|
|
|
|
}
|
|
|
|
|
libhal_free_string_array(found);
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* Use this function to search find devices with a special string property
|
|
|
|
|
* \param property TQString with the name of the property
|
|
|
|
|
* \param keyval TQString with value of the string property
|
|
|
|
|
* \param devices TQStringList to return the found devices
|
|
|
|
|
* \return If the query was successful or not
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::halFindDeviceByString (TQString property, TQString keyval, TQStringList *devices) {
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
DBusError error;
|
|
|
|
|
char ** found;
|
|
|
|
|
int num = 0;
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
if (!initHAL() || property.isEmpty() || keyval.isEmpty())
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
found = libhal_manager_find_device_string_match (hal_ctx, property.ascii(), keyval.ascii(), &num, &error);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
|
kdError() << "Could not get list of devices with key: " << property
|
|
|
|
|
<< "and string value: " << keyval << " error: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
libhal_free_string_array(found);
|
|
|
|
|
goto out;
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < num; ++i) {
|
|
|
|
|
TQString _to_add = found[i];
|
|
|
|
|
if (!_to_add.isEmpty()) *devices += _to_add;
|
|
|
|
|
}
|
|
|
|
|
libhal_free_string_array(found);
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ----> HAL section :: END <---- */
|
|
|
|
|
/* ----> D-Bus methode calls functions :: START <---- */
|
|
|
|
|
/*!
|
|
|
|
|
* This function call a D-Bus method
|
|
|
|
@ -868,102 +427,6 @@ out:
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* Function to call a suspend and call if resumed \ref callBackSuspend()
|
|
|
|
|
* to emit a resume signal.
|
|
|
|
|
* \param suspend a char pointer with the name of the suspend interface
|
|
|
|
|
* \return If the query was successful or not
|
|
|
|
|
*/
|
|
|
|
|
bool dbusHAL::dbusMethodCallSuspend ( const char *suspend ) {
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
DBusMessage *message;
|
|
|
|
|
DBusError error;
|
|
|
|
|
DBusPendingCall* pcall = NULL;
|
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
|
kdError() << "Could not get dbus connection: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
message = dbus_message_new_method_call( HAL_SERVICE, HAL_COMPUTER_UDI, HAL_PM_IFACE, suspend);
|
|
|
|
|
if (strcmp( suspend, "Suspend") == 0) {
|
|
|
|
|
int wake_up = 0;
|
|
|
|
|
dbus_message_append_args (message, DBUS_TYPE_INT32, &wake_up, DBUS_TYPE_INVALID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (message) {
|
|
|
|
|
// need to set INT_MAX as default and not -1
|
|
|
|
|
dbus_connection_send_with_reply (dbus_connection, message, &pcall, INT_MAX);
|
|
|
|
|
if (pcall) {
|
|
|
|
|
dbus_pending_call_ref (pcall); // really needed?
|
|
|
|
|
dbus_pending_call_set_notify (pcall, dbusHAL::callBackSuspend, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
dbus_message_unref (message);
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* Slot called by D-Bus as set in \ref dbusMethodCallSuspend()
|
|
|
|
|
* Here we emit the resume signal.
|
|
|
|
|
*/
|
|
|
|
|
void dbusHAL::callBackSuspend (DBusPendingCall* pcall, void* /*data*/) {
|
|
|
|
|
kdDebugFuncIn(trace);
|
|
|
|
|
|
|
|
|
|
DBusMessage* reply = NULL;
|
|
|
|
|
DBusError error;
|
|
|
|
|
int result;
|
|
|
|
|
bool failed = false;
|
|
|
|
|
|
|
|
|
|
if (!pcall) {
|
|
|
|
|
kdError() << "dbusHAL::callBackSuspend - DBusPendingCall not set, return" << endl;
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reply = dbus_pending_call_steal_reply (pcall);
|
|
|
|
|
if (reply == NULL) {
|
|
|
|
|
kdError() << "dbusHAL::callBackSuspend - Got no reply, return" << endl;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID)) {
|
|
|
|
|
if (dbus_error_is_set(&error)) {
|
|
|
|
|
kdError() << "Could not get argument from reply: " << error.message << endl;
|
|
|
|
|
dbus_error_free(&error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kdWarning() << "dbusHAL::callBackSuspend dbus_message_get_args failed, maybe timouted" << endl;
|
|
|
|
|
failed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
dbus_pending_call_unref (pcall);
|
|
|
|
|
|
|
|
|
|
if (failed)
|
|
|
|
|
emit ((dbusHAL*) myInstance)->backFromSuspend( -1 );
|
|
|
|
|
else
|
|
|
|
|
emit ((dbusHAL*) myInstance)->backFromSuspend( result );
|
|
|
|
|
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ----> D-Bus methode calls functions :: END <---- */
|
|
|
|
|
/* ---> PolicyKit method call section :: START <--- */
|
|
|
|
|
|
|
|
|
@ -998,38 +461,6 @@ int dbusHAL::isUserPrivileged(TQString privilege, TQString udi, TQString ressour
|
|
|
|
|
_unique_name = dbus_bus_get_unique_name(dbus_connection);
|
|
|
|
|
_privilege = privilege.latin1();
|
|
|
|
|
|
|
|
|
|
#ifdef USE_LIBHAL_POLICYCHECK
|
|
|
|
|
DBusError error;
|
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
|
|
if (udi.isEmpty()) {
|
|
|
|
|
kdError() << "No UDI given ... could not lookup privileges" << endl;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
if (!hal_is_connected) {
|
|
|
|
|
kdError() << "HAL not running, could not call libhal for lookup privileges" << endl;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
result = libhal_device_is_caller_privileged ( hal_ctx, udi.latin1(), _privilege, _unique_name, &error);
|
|
|
|
|
|
|
|
|
|
if ( dbus_error_is_set( &error ) ) {
|
|
|
|
|
kdWarning() << "Error while lookup privileges: " << error.message << endl;
|
|
|
|
|
dbus_error_free( &error );
|
|
|
|
|
retval = -1;
|
|
|
|
|
} else {
|
|
|
|
|
if (!strcmp(result, "yes")) {
|
|
|
|
|
retval = 1;
|
|
|
|
|
} else if (!strcmp(result, "no")) {
|
|
|
|
|
retval = 0;
|
|
|
|
|
} else {
|
|
|
|
|
retval = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libhal_free_string(result);
|
|
|
|
|
#else
|
|
|
|
|
// not sure if we need this, but to avoid problems
|
|
|
|
|
dbus_bool_t _retval;
|
|
|
|
|
const char *_ressource;
|
|
|
|
@ -1049,7 +480,6 @@ int dbusHAL::isUserPrivileged(TQString privilege, TQString udi, TQString ressour
|
|
|
|
|
} else {
|
|
|
|
|
retval = (int) _retval;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
@ -1157,22 +587,7 @@ filterFunction (DBusConnection *connection, DBusMessage *message, void */*data*/
|
|
|
|
|
if (dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &service,
|
|
|
|
|
DBUS_TYPE_STRING, &old_owner,
|
|
|
|
|
DBUS_TYPE_STRING, &new_owner, DBUS_TYPE_INVALID)) {
|
|
|
|
|
if (!strcmp(service, "org.freedesktop.Hal")) {
|
|
|
|
|
if (!strcmp(new_owner, "") && strcmp(old_owner, "")) {
|
|
|
|
|
// Hal service stopped.
|
|
|
|
|
kdDebug() << "=== org.freedesktop.Hal terminated ===" << endl;
|
|
|
|
|
((dbusHAL*) myInstance)->emitMsgReceived( DBUS_EVENT,
|
|
|
|
|
"hal.terminate",
|
|
|
|
|
NULL );
|
|
|
|
|
}
|
|
|
|
|
else if (!strcmp(old_owner, "") && strcmp(new_owner, "")) {
|
|
|
|
|
// Hal service started.
|
|
|
|
|
kdDebug() << "=== org.freedesktop.Hal started ===" << endl;
|
|
|
|
|
((dbusHAL*) myInstance)->emitMsgReceived( DBUS_EVENT,
|
|
|
|
|
"hal.started",
|
|
|
|
|
NULL );
|
|
|
|
|
}
|
|
|
|
|
} else if (!strcmp(service, "org.freedesktop.Policy.Power")) {
|
|
|
|
|
if (!strcmp(service, "org.freedesktop.Policy.Power")) {
|
|
|
|
|
const char *own_name;
|
|
|
|
|
|
|
|
|
|
own_name = dbus_bus_get_unique_name(((dbusHAL*) myInstance)->get_DBUS_connection());
|
|
|
|
@ -1195,88 +610,6 @@ filterFunction (DBusConnection *connection, DBusMessage *message, void */*data*/
|
|
|
|
|
}
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
} else if (ifaceType.startsWith("org.freedesktop.Hal.Manager")) {
|
|
|
|
|
kdDebug() << "Received from org.freedesktop.Hal.Manager" << endl;
|
|
|
|
|
char *udi;
|
|
|
|
|
|
|
|
|
|
const char *signal = dbus_message_get_member( message );
|
|
|
|
|
/* get the first argument. This must be a string at the moment */
|
|
|
|
|
dbus_message_get_args( message, &error, DBUS_TYPE_STRING, &value, DBUS_TYPE_INVALID );
|
|
|
|
|
|
|
|
|
|
if ( dbus_error_is_set( &error ) ) {
|
|
|
|
|
kdWarning() << "Received signal, but no string argument: " << error.message << endl;
|
|
|
|
|
dbus_error_free( &error );
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dbus_message_get_args( message, &error, DBUS_TYPE_STRING, &udi, DBUS_TYPE_INVALID )) {
|
|
|
|
|
if (! strcmp(signal, "DeviceRemoved") || ! strcmp(signal, "DeviceAdded")) {
|
|
|
|
|
((dbusHAL*) myInstance)->emitMsgReceived( HAL_DEVICE, signal, udi );
|
|
|
|
|
kdDebug() << "org.freedesktop.Hal.Manager: uid: " << udi
|
|
|
|
|
<< " signal: " << signal << endl;
|
|
|
|
|
} else {
|
|
|
|
|
kdWarning() << "Received unknown signal from org.freedesktop.Hal.Manager: "
|
|
|
|
|
<< signal << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
|
|
|
|
|
} else if (ifaceType.startsWith("org.freedesktop.Hal.Device")) {
|
|
|
|
|
const char *udi = dbus_message_get_path (message);
|
|
|
|
|
const char *signal = dbus_message_get_member( message );
|
|
|
|
|
|
|
|
|
|
/* Code taken from libhal */
|
|
|
|
|
if (! strcmp(signal, "PropertyModified")) {
|
|
|
|
|
if (trace) kdDebug() << "-------- PropertyModified ------" << endl;
|
|
|
|
|
int i, num_modifications;
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
DBusMessageIter iter_array;
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_init (message, &iter);
|
|
|
|
|
dbus_message_iter_get_basic (&iter, &num_modifications);
|
|
|
|
|
dbus_message_iter_next (&iter);
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_recurse (&iter, &iter_array);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < num_modifications; i++) {
|
|
|
|
|
dbus_bool_t removed, added;
|
|
|
|
|
char *key;
|
|
|
|
|
DBusMessageIter iter_struct;
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_recurse (&iter_array, &iter_struct);
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic (&iter_struct, &key);
|
|
|
|
|
dbus_message_iter_next (&iter_struct);
|
|
|
|
|
dbus_message_iter_get_basic (&iter_struct, &removed);
|
|
|
|
|
dbus_message_iter_next (&iter_struct);
|
|
|
|
|
dbus_message_iter_get_basic (&iter_struct, &added);
|
|
|
|
|
|
|
|
|
|
/* don't check if we really need this device, check this in an other class */
|
|
|
|
|
((dbusHAL*) myInstance)->emitMsgReceived( HAL_PROPERTY_CHANGED, udi, key);
|
|
|
|
|
kdDebug() << "PropertyModified: uid: " << udi << " key: " << key << endl;
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_next (&iter_array);
|
|
|
|
|
}
|
|
|
|
|
} else if (! strcmp(signal, "Condition")) {
|
|
|
|
|
if (trace) kdDebug() << "-------- Condition ------" << endl;
|
|
|
|
|
char *name, *detail;
|
|
|
|
|
|
|
|
|
|
dbus_message_get_args( message, &error, DBUS_TYPE_STRING, &value, DBUS_TYPE_INVALID );
|
|
|
|
|
|
|
|
|
|
if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &name,
|
|
|
|
|
DBUS_TYPE_STRING, &detail, DBUS_TYPE_INVALID)) {
|
|
|
|
|
((dbusHAL*) myInstance)->emitMsgReceived( HAL_CONDITION, name, detail );
|
|
|
|
|
} else {
|
|
|
|
|
if (dbus_error_is_set( &error )) dbus_error_free( &error );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
kdDebug() << "Received unknown signal from org.freedesktop.Hal.Device: "
|
|
|
|
|
<< signal << endl;
|
|
|
|
|
}
|
|
|
|
|
kdDebugFuncOut(trace);
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
} else if (ifaceType.startsWith("org.freedesktop.ConsoleKit.Session")) {
|
|
|
|
|
kdDebug() << "Received from org.freedesktop.ConsoleKit.Session" << endl;
|
|
|
|
|
|
|
|
|
|