Sam Leffler | 10b301d | 2010-06-17 14:22:43 -0700 | [diff] [blame] | 1 | // 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 Deymo | 7845a57 | 2014-11-10 19:55:35 -0800 | [diff] [blame^] | 9 | #include "metrics/c_metrics_library.h" |
| 10 | |
Bertrand SIMONNET | e6cfd64 | 2014-07-09 16:35:23 -0700 | [diff] [blame] | 11 | #include <string> |
| 12 | |
Bertrand SIMONNET | e6cfd64 | 2014-07-09 16:35:23 -0700 | [diff] [blame] | 13 | #include "metrics/metrics_library.h" |
Sam Leffler | 10b301d | 2010-06-17 14:22:43 -0700 | [diff] [blame] | 14 | |
| 15 | extern "C" CMetricsLibrary CMetricsLibraryNew(void) { |
| 16 | MetricsLibrary* lib = new MetricsLibrary; |
| 17 | return reinterpret_cast<CMetricsLibrary>(lib); |
| 18 | } |
| 19 | |
| 20 | extern "C" void CMetricsLibraryDelete(CMetricsLibrary handle) { |
| 21 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 22 | delete lib; |
| 23 | } |
| 24 | |
| 25 | extern "C" void CMetricsLibraryInit(CMetricsLibrary handle) { |
| 26 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 27 | if (lib != NULL) |
| 28 | lib->Init(); |
| 29 | } |
| 30 | |
| 31 | extern "C" int CMetricsLibrarySendToUMA(CMetricsLibrary handle, |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 32 | const char* name, int sample, |
| 33 | int min, int max, int nbuckets) { |
Sam Leffler | 10b301d | 2010-06-17 14:22:43 -0700 | [diff] [blame] | 34 | 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 | |
| 40 | extern "C" int CMetricsLibrarySendEnumToUMA(CMetricsLibrary handle, |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 41 | const char* name, int sample, |
| 42 | int max) { |
Sam Leffler | 10b301d | 2010-06-17 14:22:43 -0700 | [diff] [blame] | 43 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 44 | if (lib == NULL) |
| 45 | return 0; |
| 46 | return lib->SendEnumToUMA(std::string(name), sample, max); |
| 47 | } |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 48 | |
Luigi Semenzato | a7ebeb3 | 2013-03-19 15:02:42 -0700 | [diff] [blame] | 49 | extern "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 Petkov | ed82485 | 2011-01-06 10:51:47 -0800 | [diff] [blame] | 57 | extern "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 Mixter | be2e13b | 2011-01-22 06:15:56 -0800 | [diff] [blame] | 65 | extern "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 Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 73 | extern "C" int CMetricsLibraryAreMetricsEnabled(CMetricsLibrary handle) { |
| 74 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 75 | if (lib == NULL) |
| 76 | return 0; |
| 77 | return lib->AreMetricsEnabled(); |
| 78 | } |