aboutsummaryrefslogtreecommitdiff
path: root/libcontextprovider/doc/html/index.html
blob: 33b8aef0b3a4d6378a453821d5c43bd50882dbd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>libcontextprovider: Providing values for Context properties</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.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li class="current"><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;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>
<div class="contents">
<h1>Providing values for Context properties</h1>
<p>
This library implements the provider side of the ContextKit's D-Bus protocol. It has both a C++ and a C interface, so you can choose which you prefer. For the documentation of the C API, see <a class="el" href="capi.html">CApi</a>.<p>
The C++ interface consists mainly of the three classes <a class="el" href="class_context_provider_1_1_service.html" title="A Service object is a proxy representing a service on D-Bus that implements the ContextKit...">Service</a>, <a class="el" href="class_context_provider_1_1_property.html" title="A Property object represents a context property, i.e., a key-value pair.">Property</a>, and <a class="el" href="class_context_provider_1_1_group.html" title="Groups the firstSubscriberAppeared and lastSubscriberDisappeared from multiple Property...">Group</a> in the namespace <a class="el" href="namespace_context_provider.html">ContextProvider</a>. They are declared in the <a class="el" href="namespace_context_provider.html">ContextProvider</a> header file.<p>
Thus, you would typically gain access to the classes like this<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">  #include &lt;<a class="code" href="_context_provider.html">ContextProvider</a>&gt;</span>

  <span class="keyword">using namespace </span>ContextProvider;

  Service my_service (...);
</pre></div><p>
If you prefer not to have generic names like "Service" in your code, you can of course skip the "using" declaration and refer to the classes as "ContextProvider::Service", etc. If that is too long, consider a namespace alias like this:<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">  #include &lt;<a class="code" href="_context_provider.html">ContextProvider</a>&gt;</span>

  <span class="keyword">namespace </span>CP = ContextProvider;

  CP::Service my_service (...);
</pre></div><p>
The basic pattern to use this library is to create a <a class="el" href="class_context_provider_1_1_service.html" title="A Service object is a proxy representing a service on D-Bus that implements the ContextKit...">Service</a> instance to represent you on D-Bus and then to add <a class="el" href="class_context_provider_1_1_property.html" title="A Property object represents a context property, i.e., a key-value pair.">Property</a> instances to it for the keys that you want to provide. Once this is done, you can call Property::set() at any time to change the value of the property.<p>
Communication with clients happens asynchronously and this library needs a running event loop for that.<p>
Thus, a simple provider might look like this:<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">  #include &lt;<a class="code" href="_context_provider.html">ContextProvider</a>&gt;</span>

  <span class="keyword">using namespace </span>ContextProvider;

  <span class="keywordtype">void</span> main(<span class="keywordtype">int</span> <a class="code" href="contextc_8cpp.html#d1447518f4372828b8435ae82e48499e">argc</a>, <span class="keywordtype">char</span> **<a class="code" href="contextc_8cpp.html#34d7542664850bdf79197020d3e9532f">argv</a>)
  {
      QApplication <a class="code" href="contextc_8cpp.html#b751c4ea835b01f1db167e4fbc8f042d">app</a>(argc, argv);

      Service my_service(QDBusConnection::SessionBus, <span class="stringliteral">"com.example.simple"</span>);
      Property my_property(my_service, <span class="stringliteral">"Example.Simple"</span>);

      <span class="comment">// set initial value of property</span>
      my_property.set(100);

      <a class="code" href="contextc_8cpp.html#b751c4ea835b01f1db167e4fbc8f042d">app</a>.exec();
  }
</pre></div><p>
If you need to know when someone actually subscribes to one of your values, you can connect to the firstSubscriberAppeared and lastSubscriberDisappeared signals of the <a class="el" href="class_context_provider_1_1_property.html" title="A Property object represents a context property, i.e., a key-value pair.">Property</a> instances. You can also use a <a class="el" href="class_context_provider_1_1_group.html" title="Groups the firstSubscriberAppeared and lastSubscriberDisappeared from multiple Property...">Group</a> if you are only interested in whether at least one of a set of <a class="el" href="class_context_provider_1_1_property.html" title="A Property object represents a context property, i.e., a key-value pair.">Property</a> objects is subscribed to. </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Oct 23 08:58:39 2009 for libcontextprovider by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>