blob: e97f9ac264059040213a319c8005da45842ea1b8 [file] [log] [blame]
Sam Leffler10b301d2010-06-17 14:22:43 -07001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//
6// C wrapper to libmetrics
7//
8
9#include "c_metrics_library.h"
10#include "metrics_library.h"
11
12extern "C" CMetricsLibrary CMetricsLibraryNew(void) {
13 MetricsLibrary* lib = new MetricsLibrary;
14 return reinterpret_cast<CMetricsLibrary>(lib);
15}
16
17extern "C" void CMetricsLibraryDelete(CMetricsLibrary handle) {
18 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
19 delete lib;
20}
21
22extern "C" void CMetricsLibraryInit(CMetricsLibrary handle) {
23 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
24 if (lib != NULL)
25 lib->Init();
26}
27
28extern "C" int CMetricsLibrarySendToUMA(CMetricsLibrary handle,
Ken Mixter4c5daa42010-08-26 18:35:06 -070029 const char* name, int sample,
30 int min, int max, int nbuckets) {
Sam Leffler10b301d2010-06-17 14:22:43 -070031 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
32 if (lib == NULL)
33 return 0;
34 return lib->SendToUMA(std::string(name), sample, min, max, nbuckets);
35}
36
37extern "C" int CMetricsLibrarySendEnumToUMA(CMetricsLibrary handle,
Ken Mixter4c5daa42010-08-26 18:35:06 -070038 const char* name, int sample,
39 int max) {
Sam Leffler10b301d2010-06-17 14:22:43 -070040 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
41 if (lib == NULL)
42 return 0;
43 return lib->SendEnumToUMA(std::string(name), sample, max);
44}
Ken Mixter4c5daa42010-08-26 18:35:06 -070045
46extern "C" int CMetricsLibraryAreMetricsEnabled(CMetricsLibrary handle) {
47 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
48 if (lib == NULL)
49 return 0;
50 return lib->AreMetricsEnabled();
51}