blob: 90a2d59c9b8eb2ad097d9013273642d053689fae [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
Alex Deymo7845a572014-11-10 19:55:35 -08009#include "metrics/c_metrics_library.h"
10
Bertrand SIMONNETe6cfd642014-07-09 16:35:23 -070011#include <string>
12
Bertrand SIMONNETe6cfd642014-07-09 16:35:23 -070013#include "metrics/metrics_library.h"
Sam Leffler10b301d2010-06-17 14:22:43 -070014
15extern "C" CMetricsLibrary CMetricsLibraryNew(void) {
16 MetricsLibrary* lib = new MetricsLibrary;
17 return reinterpret_cast<CMetricsLibrary>(lib);
18}
19
20extern "C" void CMetricsLibraryDelete(CMetricsLibrary handle) {
21 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
22 delete lib;
23}
24
25extern "C" void CMetricsLibraryInit(CMetricsLibrary handle) {
26 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
27 if (lib != NULL)
28 lib->Init();
29}
30
31extern "C" int CMetricsLibrarySendToUMA(CMetricsLibrary handle,
Ken Mixter4c5daa42010-08-26 18:35:06 -070032 const char* name, int sample,
33 int min, int max, int nbuckets) {
Sam Leffler10b301d2010-06-17 14:22:43 -070034 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
35 if (lib == NULL)
36 return 0;
37 return lib->SendToUMA(std::string(name), sample, min, max, nbuckets);
38}
39
40extern "C" int CMetricsLibrarySendEnumToUMA(CMetricsLibrary handle,
Ken Mixter4c5daa42010-08-26 18:35:06 -070041 const char* name, int sample,
42 int max) {
Sam Leffler10b301d2010-06-17 14:22:43 -070043 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
44 if (lib == NULL)
45 return 0;
46 return lib->SendEnumToUMA(std::string(name), sample, max);
47}
Ken Mixter4c5daa42010-08-26 18:35:06 -070048
Luigi Semenzatoa7ebeb32013-03-19 15:02:42 -070049extern "C" int CMetricsLibrarySendSparseToUMA(CMetricsLibrary handle,
50 const char* name, int sample) {
51 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
52 if (lib == NULL)
53 return 0;
54 return lib->SendSparseToUMA(std::string(name), sample);
55}
56
Darin Petkoved824852011-01-06 10:51:47 -080057extern "C" int CMetricsLibrarySendUserActionToUMA(CMetricsLibrary handle,
58 const char* action) {
59 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
60 if (lib == NULL)
61 return 0;
62 return lib->SendUserActionToUMA(std::string(action));
63}
64
Ken Mixterbe2e13b2011-01-22 06:15:56 -080065extern "C" int CMetricsLibrarySendCrashToUMA(CMetricsLibrary handle,
66 const char* crash_kind) {
67 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
68 if (lib == NULL)
69 return 0;
70 return lib->SendCrashToUMA(crash_kind);
71}
72
Ken Mixter4c5daa42010-08-26 18:35:06 -070073extern "C" int CMetricsLibraryAreMetricsEnabled(CMetricsLibrary handle) {
74 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
75 if (lib == NULL)
76 return 0;
77 return lib->AreMetricsEnabled();
78}