<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Soprano: Writing Soprano Plugins</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.1 --> <script type="text/javascript"> function hasClass(ele,cls) { return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)')); } function addClass(ele,cls) { if (!this.hasClass(ele,cls)) ele.className += " "+cls; } function removeClass(ele,cls) { if (hasClass(ele,cls)) { var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)'); ele.className=ele.className.replace(reg,' '); } } function toggleVisibility(linkObj) { var base = linkObj.getAttribute('id'); var summary = document.getElementById(base + '-summary'); var content = document.getElementById(base + '-content'); var trigger = document.getElementById(base + '-trigger'); if ( hasClass(linkObj,'closed') ) { summary.style.display = 'none'; content.style.display = 'block'; trigger.src = 'open.png'; removeClass(linkObj,'closed'); addClass(linkObj,'opened'); } else if ( hasClass(linkObj,'opened') ) { summary.style.display = 'block'; content.style.display = 'none'; trigger.src = 'closed.png'; removeClass(linkObj,'opened'); addClass(linkObj,'closed'); } return false; } </script> <div class="navigation" id="top"> <div class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li class="current"><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> </ul> </div> <div class="navpath"> <ul> <li><a class="el" href="index.html">Soprano (aka QRDF) - A modular RDF storage framework</a> </li> </ul> </div> </div> <div class="header"> <div class="headertitle"> <h1>Writing <a class="el" href="namespaceSoprano.html">Soprano</a> Plugins </h1> </div> </div> <div class="contents"> <p>Soprano has five kinds of plugins: <a class="el" href="classSoprano_1_1Backend.html" title="Soprano::Backend defines the interface for a Soprano backend plugin.">Soprano::Backend</a>, <a class="el" href="classSoprano_1_1Parser.html" title="Soprano::Parser defines the interface for a Soprano RDF parser plugin.">Soprano::Parser</a>, <a class="el" href="classSoprano_1_1Serializer.html" title="Soprano::Serializer defines the interface for a Soprano RDF serializer plugin.">Soprano::Serializer</a>, Soprano::Query::Parser, and Soprano::Query::Serializer.</p> <p>Creating a new plugin for Soprano is pretty easy. Imagine, for example, we want to write a new Backend plugin. We simply create a class that inherits from <a class="elRef" href="qobject.html">QObject</a> and the <a class="el" href="classSoprano_1_1Backend.html" title="Soprano::Backend defines the interface for a Soprano backend plugin.">Soprano::Backend</a> interface and use the Q_INTERFACES macro to tell Qt's meta-object system about the new plugin. We then export the plugin via the Q_EXPORT_PLUGIN2 macro in the source file.</p> <p>An example would look as follows:</p> <div class="fragment"><pre class="fragment"> <span class="keyword">class </span>MyBackend : <span class="keyword">public</span> <a class="codeRef" href="qobject.html">QObject</a>, <span class="keyword">public</span> Soprano::Backend { Q_OBJECT Q_INTERFACES(<a class="code" href="classSoprano_1_1Backend.html" title="Soprano::Backend defines the interface for a Soprano backend plugin.">Soprano::Backend</a>) public: StorageModel* <a class="code" href="namespaceSoprano.html#a66f765cf9fd9aae07f874fdb8867dd1c">createModel</a>( const <a class="codeRef" href="qstringlist.html">QStringList</a>& options = <a class="codeRef" href="qstringlist.html">QStringList</a>() ) const; <span class="keywordtype">bool</span> deleteModelData( const <a class="code" href="namespaceSoprano.html#a47246ff42973d5f78cb21ed7b1e07033">BackendSettings</a>& settings ) const; BackendFeatures supportedFeatures() const; }; </pre></div><p>In the implementation file, export the plugin so that it can be picked up by the plugin loading framework:</p> <div class="fragment"><pre class="fragment"> Q_EXPORT_PLUGIN2(soprano_mybackend, MyBackend) </pre></div><p>The plugin then needs to be linked as a library and installed into the lib/soprano target folder.</p> <p>Finally we need to create a desktop file describing the plugin. The minimal desktop file looks as follows (for details see <a class="el" href="soprano_plugin_desktop_file.html">Soprano Plugin Desktop Files</a>):</p> <div class="fragment"><pre class="fragment"> [Desktop Entry] Encoding=UTF-8 X-Soprano-Library=libsoprano_mybackend X-Soprano-Version=2.2 Type=Service ServiceTypes=Soprano/Backend Name=MyBackend Comment=My very cool and fast Soprano backend </pre></div><p>The desktop file should be installed into share/soprano/plugins so the <a class="el" href="classSoprano_1_1PluginManager.html" title="The PluginManager loads and maintains all Soprano plugins.">Soprano::PluginManager</a> will find it.</p> <p>All plugin interfaces inherit from <a class="el" href="classSoprano_1_1Error_1_1ErrorCache.html" title="Core class of Soprano's exception system.">Soprano::Error::ErrorCache</a> for error handling and subclasses should use <a class="el" href="classSoprano_1_1Error_1_1ErrorCache.html#a65f952db676de0a6a186ea872fca18b8">Soprano::Error::ErrorCache::clearError()</a> and <a class="el" href="classSoprano_1_1Error_1_1ErrorCache.html#afd1a1eccaa2af733601eab1f019a8553">Soprano::Error::ErrorCache::setError()</a> to report the status. </p> </div> <hr class="footer"/><address class="footer"><small>Generated on Thu Oct 21 2010 for Soprano by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address> </body> </html>