Home | History | Annotate | Download | only in metricsd
      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  */
     16 
     17 //
     18 // C wrapper to libmetrics
     19 //
     20 
     21 #include "metrics/c_metrics_library.h"
     22 
     23 #include <string>
     24 
     25 #include "metrics/metrics_library.h"
     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,
     44                                         const char* name, int sample,
     45                                         int min, int max, int nbuckets) {
     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,
     53                                             const char* name, int sample,
     54                                             int max) {
     55   MetricsLibrary* lib = reinterpret_cast<MetricsLibrary*>(handle);
     56   if (lib == NULL)
     57     return 0;
     58   return lib->SendEnumToUMA(std::string(name), sample, max);
     59 }
     60 
     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 
     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 
     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 }
     83