blob: 47a543e45c2cdf143643459a64cb3faad6ad8832 [file] [log] [blame]
Bertrand SIMONNET52e5b992015-08-10 15:18:00 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Sam Leffler10b301d2010-06-17 14:22:43 -070016
17//
18// C wrapper to libmetrics
19//
20
Alex Deymo7845a572014-11-10 19:55:35 -080021#include "metrics/c_metrics_library.h"
22
Bertrand SIMONNETe6cfd642014-07-09 16:35:23 -070023#include <string>
24
Bertrand SIMONNETe6cfd642014-07-09 16:35:23 -070025#include "metrics/metrics_library.h"
Sam Leffler10b301d2010-06-17 14:22:43 -070026
27extern "C" CMetricsLibrary CMetricsLibraryNew(void) {
28 MetricsLibrary* lib = new MetricsLibrary;
29 return reinterpret_cast<CMetricsLibrary>(lib);
30}
31
32extern "C" void CMetricsLibraryDelete(CMetricsLibrary handle) {
33 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
34 delete lib;
35}
36
37extern "C" void CMetricsLibraryInit(CMetricsLibrary handle) {
38 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
39 if (lib != NULL)
40 lib->Init();
41}
42
43extern "C" int CMetricsLibrarySendToUMA(CMetricsLibrary handle,
Ken Mixter4c5daa42010-08-26 18:35:06 -070044 const char* name, int sample,
45 int min, int max, int nbuckets) {
Sam Leffler10b301d2010-06-17 14:22:43 -070046 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
47 if (lib == NULL)
48 return 0;
49 return lib->SendToUMA(std::string(name), sample, min, max, nbuckets);
50}
51
52extern "C" int CMetricsLibrarySendEnumToUMA(CMetricsLibrary handle,
Ken Mixter4c5daa42010-08-26 18:35:06 -070053 const char* name, int sample,
54 int max) {
Sam Leffler10b301d2010-06-17 14:22:43 -070055 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
56 if (lib == NULL)
57 return 0;
58 return lib->SendEnumToUMA(std::string(name), sample, max);
59}
Ken Mixter4c5daa42010-08-26 18:35:06 -070060
Luigi Semenzatoa7ebeb32013-03-19 15:02:42 -070061extern "C" int CMetricsLibrarySendSparseToUMA(CMetricsLibrary handle,
62 const char* name, int sample) {
63 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
64 if (lib == NULL)
65 return 0;
66 return lib->SendSparseToUMA(std::string(name), sample);
67}
68
Ken Mixterbe2e13b2011-01-22 06:15:56 -080069extern "C" int CMetricsLibrarySendCrashToUMA(CMetricsLibrary handle,
70 const char* crash_kind) {
71 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
72 if (lib == NULL)
73 return 0;
74 return lib->SendCrashToUMA(crash_kind);
75}
76
Ken Mixter4c5daa42010-08-26 18:35:06 -070077extern "C" int CMetricsLibraryAreMetricsEnabled(CMetricsLibrary handle) {
78 MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
79 if (lib == NULL)
80 return 0;
81 return lib->AreMetricsEnabled();
82}