<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.8.20" xml:lang="en-US">
  <compounddef id="MetricManagerAdvancedCAPI_8c-example" kind="example">
    <compoundname>MetricManagerAdvancedCAPI.c</compoundname>
    <briefdescription>
    </briefdescription>
    <detaileddescription>
<para>A more advanced metric that updates the history of a metric. Usually this would be a metric from an external data source, e.g. e-mail or Facebook messages. <programlisting filename="MetricManagerAdvancedCAPI.c"><codeline><highlight class="preprocessor">#include<sp/>&lt;<ref refid="usermetricsinput_8h" kindref="compound">libusermetricsinput/usermetricsinput.h</ref>&gt;</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"></highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>main(</highlight><highlight class="keywordtype">int</highlight><highlight class="normal"><sp/>argc,<sp/></highlight><highlight class="keywordtype">char</highlight><highlight class="normal"><sp/>*argv[])<sp/>{</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>We<sp/>start<sp/>with<sp/>a<sp/>manager<sp/>object.</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>This<sp/>can<sp/>be<sp/>used<sp/>as<sp/>a<sp/>long-lived<sp/>object<sp/>to<sp/>reduce<sp/>DBus<sp/>traffic.</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1a7352ed8164cb4dfee8f0ef9d27d3ebe1" kindref="member">UserMetricsInputMetricManager</ref><sp/>metricManager<sp/>=</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1af59e1f9c50dcc73755a7b4b07b1aba37" kindref="member">usermetricsinput_metricmanager_new</ref>();</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Create<sp/>a<sp/>parameters<sp/>object</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1a34ed483df591648eb3f3118609eae6df" kindref="member">UserMetricsInputMetricParameters</ref><sp/>parameters<sp/>=</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1af0f8d6a63b4dee377a84f47f21be7bd3" kindref="member">usermetricsinput_metricparameters_new</ref>(</highlight><highlight class="stringliteral">&quot;twitter&quot;</highlight><highlight class="normal">);</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Set<sp/>its<sp/>attributes</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1a07374ef2eef88fddd5bb1f5d6dcec28e" kindref="member">usermetricsinput_metricparameters_set_format_string</ref>(parameters,</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="stringliteral">&quot;&lt;b&gt;%1&lt;/b&gt;<sp/>tweets<sp/>received<sp/>today&quot;</highlight><highlight class="normal">);</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1aedf61b9f47b1de80db718059ffe86319" kindref="member">usermetricsinput_metricparameters_set_empty_data_string</ref>(parameters,</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="stringliteral">&quot;No<sp/>tweets<sp/>today&quot;</highlight><highlight class="normal">);</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1ae7fdf9c5fe35a32f58d81876d020c052" kindref="member">usermetricsinput_metricparameters_set_text_domain</ref>(parameters,</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/></highlight><highlight class="stringliteral">&quot;myapptextdomain&quot;</highlight><highlight class="normal">);</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>You<sp/>can<sp/>hold<sp/>onto<sp/>this<sp/>shared<sp/>object<sp/>for<sp/>as<sp/>long<sp/>as<sp/>you<sp/>want.</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>It<sp/>will<sp/>be<sp/>destroyed<sp/>when<sp/>the<sp/>manager<sp/>is<sp/>destroyed.</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1a1abb7e3afa51177792d0672b4e9769b9" kindref="member">UserMetricsInputMetric</ref><sp/>metric<sp/>=<sp/><ref refid="usermetricsinput_8h_1a1634de4e0e5490b465e8c544074cb0e8" kindref="member">usermetricsinput_metricmanager_add</ref>(</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>metricManager,<sp/>parameters);</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Remember<sp/>to<sp/>free<sp/>the<sp/>parameters<sp/>object<sp/>after<sp/>use</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1a1642acbf716986af38a30afbb0dbfb1a" kindref="member">usermetricsinput_metricparameters_delete</ref>(parameters);</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>The<sp/>update<sp/>is<sp/>sent<sp/>when<sp/>the<sp/>update<sp/>object<sp/>is<sp/>destroyed.</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Providing<sp/>a<sp/>blank<sp/>username<sp/>string<sp/>will<sp/>use<sp/>the<sp/>current</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>user<sp/>according<sp/>to<sp/>the<sp/>USER<sp/>environment<sp/>variable.</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1a83a29a00021c4e85a2bacd75ad9187e6" kindref="member">UserMetricsInputMetricUpdate</ref><sp/>metricUpdate<sp/>=<sp/><ref refid="usermetricsinput_8h_1a67be82f953e7fd0cbf12356a77c65cfd" kindref="member">usermetricsinput_metric_update</ref>(</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>metric,<sp/></highlight><highlight class="stringliteral">&quot;username&quot;</highlight><highlight class="normal">);</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>The<sp/>data<sp/>is<sp/>ordered<sp/>starting<sp/>from<sp/>today,<sp/>going<sp/>backwards<sp/>in<sp/>time</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1a74e2f80d61e621e4bd3a2b1a9df3c156" kindref="member">usermetricsinput_metricupdate_add_data</ref>(metricUpdate,<sp/>1.0);</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1a74e2f80d61e621e4bd3a2b1a9df3c156" kindref="member">usermetricsinput_metricupdate_add_data</ref>(metricUpdate,<sp/>0.1);</highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1a74e2f80d61e621e4bd3a2b1a9df3c156" kindref="member">usermetricsinput_metricupdate_add_data</ref>(metricUpdate,<sp/>-5.0);</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Delete<sp/>and<sp/>dispatch<sp/>the<sp/>metri<sp/>update</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1ada691afb67642066c997ceaff5f7273b" kindref="member">usermetricsinput_metricupdate_delete</ref>(metricUpdate);</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="comment">//<sp/>Free<sp/>the<sp/>manager<sp/>when<sp/>done<sp/>with<sp/>it</highlight><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/><ref refid="usermetricsinput_8h_1a72fdb8f86e2b0f69b17b68309d733642" kindref="member">usermetricsinput_metricmanager_delete</ref>(metricManager);</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
<codeline><highlight class="normal"><sp/><sp/><sp/><sp/></highlight><highlight class="keywordflow">return</highlight><highlight class="normal"><sp/>0;</highlight></codeline>
<codeline><highlight class="normal">}</highlight></codeline>
<codeline><highlight class="normal"></highlight></codeline>
</programlisting> </para>
    </detaileddescription>
  </compounddef>
</doxygen>
