Bertrand SIMONNET | 52e5b99 | 2015-08-10 15:18:00 -0700 | [diff] [blame] | 1 | /* |
| 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 Leffler | 10b301d | 2010-06-17 14:22:43 -0700 | [diff] [blame] | 16 | |
| 17 | // |
| 18 | // C wrapper to libmetrics |
| 19 | // |
| 20 | |
Alex Deymo | 7845a57 | 2014-11-10 19:55:35 -0800 | [diff] [blame] | 21 | #include "metrics/c_metrics_library.h" |
| 22 | |
Bertrand SIMONNET | e6cfd64 | 2014-07-09 16:35:23 -0700 | [diff] [blame] | 23 | #include <string> |
| 24 | |
Bertrand SIMONNET | e6cfd64 | 2014-07-09 16:35:23 -0700 | [diff] [blame] | 25 | #include "metrics/metrics_library.h" |
Sam Leffler | 10b301d | 2010-06-17 14:22:43 -0700 | [diff] [blame] | 26 | |
| 27 | extern "C" CMetricsLibrary CMetricsLibraryNew(void) { |
| 28 | MetricsLibrary* lib = new MetricsLibrary; |
| 29 | return reinterpret_cast<CMetricsLibrary>(lib); |
| 30 | } |
| 31 | |
| 32 | extern "C" void CMetricsLibraryDelete(CMetricsLibrary handle) { |
| 33 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 34 | delete lib; |
| 35 | } |
| 36 | |
| 37 | extern "C" void CMetricsLibraryInit(CMetricsLibrary handle) { |
| 38 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 39 | if (lib != NULL) |
| 40 | lib->Init(); |
| 41 | } |
| 42 | |
| 43 | extern "C" int CMetricsLibrarySendToUMA(CMetricsLibrary handle, |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 44 | const char* name, int sample, |
| 45 | int min, int max, int nbuckets) { |
Sam Leffler | 10b301d | 2010-06-17 14:22:43 -0700 | [diff] [blame] | 46 | 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 | |
| 52 | extern "C" int CMetricsLibrarySendEnumToUMA(CMetricsLibrary handle, |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 53 | const char* name, int sample, |
| 54 | int max) { |
Sam Leffler | 10b301d | 2010-06-17 14:22:43 -0700 | [diff] [blame] | 55 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 56 | if (lib == NULL) |
| 57 | return 0; |
| 58 | return lib->SendEnumToUMA(std::string(name), sample, max); |
| 59 | } |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 60 | |
Luigi Semenzato | a7ebeb3 | 2013-03-19 15:02:42 -0700 | [diff] [blame] | 61 | extern "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 Mixter | be2e13b | 2011-01-22 06:15:56 -0800 | [diff] [blame] | 69 | extern "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 Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 77 | extern "C" int CMetricsLibraryAreMetricsEnabled(CMetricsLibrary handle) { |
| 78 | MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle); |
| 79 | if (lib == NULL) |
| 80 | return 0; |
| 81 | return lib->AreMetricsEnabled(); |
| 82 | } |