<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://techbase.kde.org/skins/common/feed.css?0.2"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://techbase.kde.org/index.php?title=Development/Tutorials/Solid/Device_Discovery&amp;feed=atom&amp;action=history</id>
		<title>Development/Tutorials/Solid/Device Discovery - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://techbase.kde.org/index.php?title=Development/Tutorials/Solid/Device_Discovery&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Development/Tutorials/Solid/Device_Discovery&amp;action=history"/>
		<updated>2013-05-23T02:42:35Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.2</generator>

	<entry>
		<id>http://techbase.kde.org/index.php?title=Development/Tutorials/Solid/Device_Discovery&amp;diff=66400&amp;oldid=prev</id>
		<title>Ervin: Created page with &quot;== Prerequisites == * A working KDE4 development environment. Documentation on setting up a KDE environment can be found here.  == Listing Devices == Our firs...&quot;</title>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Development/Tutorials/Solid/Device_Discovery&amp;diff=66400&amp;oldid=prev"/>
				<updated>2011-09-30T14:39:58Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Prerequisites == * A working KDE4 development environment. Documentation on setting up a KDE environment can be found &lt;a href=&quot;/Getting_Started&quot; title=&quot;Getting Started&quot;&gt;here&lt;/a&gt;.  == Listing Devices == Our firs...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Prerequisites ==&lt;br /&gt;
* A working KDE4 development environment. Documentation on setting up a KDE environment can be found [[Getting_Started|here]].&lt;br /&gt;
&lt;br /&gt;
== Listing Devices ==&lt;br /&gt;
Our first program will be a simple console based app that gets a list of all the hardware devices and prints them out to the screen.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
    Solid::DeviceNotifier *notifier = Solid::DeviceNotifier::instance();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This gets us the device manager.  All the devices are queried through and returned from the device manager.  Once we have the list of devices we can interact with them as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;foreach( Solid::Device device, Solid::Device::allDevices() )&lt;br /&gt;
{&lt;br /&gt;
    //print the name of device&lt;br /&gt;
    kDebug() &amp;lt;&amp;lt; device.udi();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
device.udi() returns the Unique Device Identifier for the device as a QString. Even if you have more than one identical device, the UDI is guaranteed to be unique.  For example if you have a MythTV box with two PVR-250 T.V. capture cards in it, you will be able to refer to card #1 and #2 by their respective UDI.&lt;br /&gt;
&lt;br /&gt;
The complete program along with the CMake files necessary to build it can be found under &amp;quot;[http://websvn.kde.org/trunk/KDE/kdeexamples/solid/tutorial1/ kdeexamples/solid/tutorial1/]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Searching for specific devices ==&lt;br /&gt;
This second program makes uses of filters built into the solid framework.  Using these filters you can list only devices according to supported capabilities, sub-devices of a given parent, and various predicates.  In our example we'll be limiting our list to only audio hardware.  A full list of capabilities can be viewed under the Solid::Capability namespace.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
Solid::DeviceNotifier *notifier = Solid::DeviceNotifier::instance();&lt;br /&gt;
    &lt;br /&gt;
//get a list of all devices that are AudioHw&lt;br /&gt;
foreach (Solid::Device device, Solid::Device::listFromType(Solid::DeviceInterface::AudioInterface, QString()))&lt;br /&gt;
{&lt;br /&gt;
   kDebug() &amp;lt;&amp;lt; device.udi().toLatin1().constData();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example Solid::DeviceManager::findDevicesFromQuery looks for a device with any parent and the Solid::Capability::AudioHw capability.  If we had wanted to specify an AudioHw device with the parent &amp;quot;real_specific_parent&amp;quot; it would look like this:&lt;br /&gt;
    &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;Solid::Device::listFromType(Solid::Capability::AudioHw,&amp;quot;real_specific_parent&amp;quot; )&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The complete program along with the CMake files required to build it can be found under &amp;quot;[http://websvn.kde.org/trunk/KDE/kdeexamples/solid/tutorial2/ kdeexamples/solid/tutorial2/]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== What do we do with a device once we get it? ==&lt;br /&gt;
Now that we got a device, what do we do with it?  First let's look at the relationship between the Solid::Device and Solid::Capability. A Solid::Device can contain many Solid::Capability.  A device can be tested to have a capability in the following way:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
Solid::DeviceNotifier *notifier = Solid::DeviceNotifier::instance();&lt;br /&gt;
&lt;br /&gt;
//get a Processor&lt;br /&gt;
QList&amp;lt;Solid::Device&amp;gt; list = Solid::Device::listFromType(Solid::DeviceInterface::Processor, QString());&lt;br /&gt;
&lt;br /&gt;
//take the first processor&lt;br /&gt;
Solid::Device device = list[0];&lt;br /&gt;
if(device.is&amp;lt;Solid::Processor&amp;gt;() ) kDebug() &amp;lt;&amp;lt; &amp;quot;We've got a processor!&amp;quot;;&lt;br /&gt;
else kDebug() &amp;lt;&amp;lt; &amp;quot;Device is not a processor.&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Solid::Processor *processor = device.as&amp;lt;Solid::Processor&amp;gt;();&lt;br /&gt;
kDebug() &amp;lt;&amp;lt; &amp;quot;This processors maximum speed is:&amp;quot; &amp;lt;&amp;lt; processor-&amp;gt;maxSpeed();&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To actually use this device as a processor we need to do the following:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
    Solid::Processor *processor = device.as&amp;lt;Solid::Processor&amp;gt;();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The complete program along with the CMake files required to build it can be found under &amp;quot;[http://websvn.kde.org/trunk/KDE/kdeexamples/solid/tutorial3/ kdeexamples/solid/tutorial3/]&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== solid-hardware tool ==&lt;br /&gt;
&lt;br /&gt;
kdebase-runtime provides solid-hardware, a command line tool to investigate available devices.&lt;br /&gt;
&lt;br /&gt;
Listing udi for all installed devices:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
solid-hardware list&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Listing full details for all installed devices:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
solid-hardware list details&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Listing all audio hardware devices:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
solid-hardware query 'IS AudioInterface'&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorial]]&lt;br /&gt;
[[Category:C++]]&lt;br /&gt;
[[Category:KDE4]]&lt;br /&gt;
[[Category:Solid]]&lt;/div&gt;</summary>
		<author><name>Ervin</name></author>	</entry>

	</feed>