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 | |
| 9 | #include "c_metrics_library.h" |
| 10 | #include "metrics_library.h" |
| 11 | |
| 12 | extern "C" CMetricsLibrary CMetricsLibraryNew(void) { |
| 13 | MetricsLibrary* lib = new MetricsLibrary; |
| 14 | return reinterpret_cast<CMetricsLibrary>(lib); |
| 15 | } |
| 16 | |
| 17 | extern "C" void CMetricsLibraryDelete(CMetricsLibrary handle) { |
| 18 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 19 | delete lib; |
| 20 | } |
| 21 | |
| 22 | extern "C" void CMetricsLibraryInit(CMetricsLibrary handle) { |
| 23 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 24 | if (lib != NULL) |
| 25 | lib->Init(); |
| 26 | } |
| 27 | |
| 28 | extern "C" int CMetricsLibrarySendToUMA(CMetricsLibrary handle, |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 29 | const char* name, int sample, |
| 30 | int min, int max, int nbuckets) { |
Sam Leffler | 10b301d | 2010-06-17 14:22:43 -0700 | [diff] [blame] | 31 | 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 | |
| 37 | extern "C" int CMetricsLibrarySendEnumToUMA(CMetricsLibrary handle, |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 38 | const char* name, int sample, |
| 39 | int max) { |
Sam Leffler | 10b301d | 2010-06-17 14:22:43 -0700 | [diff] [blame] | 40 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 41 | if (lib == NULL) |
| 42 | return 0; |
| 43 | return lib->SendEnumToUMA(std::string(name), sample, max); |
| 44 | } |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 45 | |
Luigi Semenzato | a7ebeb3 | 2013-03-19 15:02:42 -0700 | [diff] [blame^] | 46 | extern "C" int CMetricsLibrarySendSparseToUMA(CMetricsLibrary handle, |
| 47 | const char* name, int sample) { |
| 48 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 49 | if (lib == NULL) |
| 50 | return 0; |
| 51 | return lib->SendSparseToUMA(std::string(name), sample); |
| 52 | } |
| 53 | |
Darin Petkov | ed82485 | 2011-01-06 10:51:47 -0800 | [diff] [blame] | 54 | extern "C" int CMetricsLibrarySendUserActionToUMA(CMetricsLibrary handle, |
| 55 | const char* action) { |
| 56 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 57 | if (lib == NULL) |
| 58 | return 0; |
| 59 | return lib->SendUserActionToUMA(std::string(action)); |
| 60 | } |
| 61 | |
Ken Mixter | be2e13b | 2011-01-22 06:15:56 -0800 | [diff] [blame] | 62 | extern "C" int CMetricsLibrarySendCrashToUMA(CMetricsLibrary handle, |
| 63 | const char* crash_kind) { |
| 64 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 65 | if (lib == NULL) |
| 66 | return 0; |
| 67 | return lib->SendCrashToUMA(crash_kind); |
| 68 | } |
| 69 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 70 | extern "C" int CMetricsLibraryAreMetricsEnabled(CMetricsLibrary handle) { |
| 71 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 72 | if (lib == NULL) |
| 73 | return 0; |
| 74 | return lib->AreMetricsEnabled(); |
| 75 | } |