MetricManagerAdvancedCAPI.c

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.

#include <libusermetricsinput/usermetricsinput.h>
int main(int argc, char *argv[]) {
// We start with a manager object.
// This can be used as a long-lived object to reduce DBus traffic.
UserMetricsInputMetricManager metricManager =
usermetricsinput_metricmanager_new();
// Create a parameters object
UserMetricsInputMetricParameters parameters =
usermetricsinput_metricparameters_new("twitter");
// Set its attributes
usermetricsinput_metricparameters_set_format_string(parameters,
"<b>%1</b> tweets received today");
usermetricsinput_metricparameters_set_empty_data_string(parameters,
"No tweets today");
usermetricsinput_metricparameters_set_text_domain(parameters,
"myapptextdomain");
// You can hold onto this shared object for as long as you want.
// It will be destroyed when the manager is destroyed.
UserMetricsInputMetric metric = usermetricsinput_metricmanager_add(
metricManager, parameters);
// Remember to free the parameters object after use
usermetricsinput_metricparameters_delete(parameters);
// The update is sent when the update object is destroyed.
// Providing a blank username string will use the current
// user according to the USER environment variable.
UserMetricsInputMetricUpdate metricUpdate = usermetricsinput_metric_update(
metric, "username");
// The data is ordered starting from today, going backwards in time
usermetricsinput_metricupdate_add_data(metricUpdate, 1.0);
usermetricsinput_metricupdate_add_data(metricUpdate, 0.1);
usermetricsinput_metricupdate_add_data(metricUpdate, -5.0);
// Delete and dispatch the metri update
usermetricsinput_metricupdate_delete(metricUpdate);
// Free the manager when done with it
usermetricsinput_metricmanager_delete(metricManager);
return 0;
}
usermetricsinput.h
usermetricsinput_metricparameters_set_format_string
USERMETRICSINPUT_EXPORT void usermetricsinput_metricparameters_set_format_string(UserMetricsInputMetricParameters metricParameter, const char *formatString)
Set the string to print in the output API, e.g. "<b>%1</b> messages received today".
usermetricsinput_metricmanager_add
USERMETRICSINPUT_EXPORT UserMetricsInputMetric usermetricsinput_metricmanager_add(UserMetricsInputMetricManager metricManager, UserMetricsInputMetricParameters metricParameters)
Register a new UserMetricsInputMetric.
usermetricsinput_metricparameters_delete
USERMETRICSINPUT_EXPORT void usermetricsinput_metricparameters_delete(UserMetricsInputMetricParameters metricParameters)
Free a UserMetricsInputMetricParameters.
UserMetricsInputMetric
void * UserMetricsInputMetric
A single user metric, e.g. "number of e-mails today" or "photos taken today".
Definition usermetricsinput.h:57
UserMetricsInputMetricParameters
void * UserMetricsInputMetricParameters
Parameters for constructing a metric.
Definition usermetricsinput.h:52
usermetricsinput_metric_update
USERMETRICSINPUT_EXPORT UserMetricsInputMetricUpdate usermetricsinput_metric_update(UserMetricsInputMetric metric, const char *username)
Create an update to a particular metric.
usermetricsinput_metricmanager_delete
USERMETRICSINPUT_EXPORT void usermetricsinput_metricmanager_delete(UserMetricsInputMetricManager metricManager)
Free a UserMetricsInputMetricManager.
UserMetricsInputMetricManager
void * UserMetricsInputMetricManager
A central place for registering user metrics.
Definition usermetricsinput.h:47
usermetricsinput_metricupdate_add_data
USERMETRICSINPUT_EXPORT void usermetricsinput_metricupdate_add_data(UserMetricsInputMetricUpdate metricUpdate, double data)
Add data to a UserMetricsInputMetricUpdate.
UserMetricsInputMetricUpdate
void * UserMetricsInputMetricUpdate
A update to a user metric for a particular user.
Definition usermetricsinput.h:62
usermetricsinput_metricupdate_delete
USERMETRICSINPUT_EXPORT void usermetricsinput_metricupdate_delete(UserMetricsInputMetricUpdate metricUpdate)
Free a UserMetricsInputMetric.
usermetricsinput_metricparameters_set_text_domain
USERMETRICSINPUT_EXPORT void usermetricsinput_metricparameters_set_text_domain(UserMetricsInputMetricParameters metricParameter, const char *textDomain)
Set the translation domain.
usermetricsinput_metricparameters_set_empty_data_string
USERMETRICSINPUT_EXPORT void usermetricsinput_metricparameters_set_empty_data_string(UserMetricsInputMetricParameters metricParameter, const char *emptyDataString)
set the string to print in the case of no data, e.g. "No messages received today"
usermetricsinput_metricparameters_new
USERMETRICSINPUT_EXPORT UserMetricsInputMetricParameters usermetricsinput_metricparameters_new(const char *dataSourceId)
Construct a new UserMetricsInputMetricParameters.
usermetricsinput_metricmanager_new
USERMETRICSINPUT_EXPORT UserMetricsInputMetricManager usermetricsinput_metricmanager_new()
Construct a new UserMetricsInputMetricManager.