Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2018 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 #ifndef ANDROID_MEDIA_MEDIAMETRICS_H
     18 #define ANDROID_MEDIA_MEDIAMETRICS_H
     19 
     20 //
     21 // define a C interface to the media metrics functionality
     22 //
     23 // All functions that return a char * or const char * also give responsibility
     24 // for that string to the caller. The caller is responsible for calling free()
     25 // on that pointer when done using the value.
     26 
     27 __BEGIN_DECLS
     28 
     29 // internally re-cast to the behind-the-scenes C++ class instance
     30 typedef int64_t mediametrics_handle_t;
     31 typedef const char *mediametricskey_t;
     32 typedef const char *attr_t;
     33 
     34 mediametrics_handle_t mediametrics_create(mediametricskey_t key);
     35 void mediametrics_delete(mediametrics_handle_t handle);
     36 
     37 mediametricskey_t mediametrics_getKey(mediametrics_handle_t handle);
     38 
     39 
     40 // set
     41 void mediametrics_setInt32(mediametrics_handle_t handle, attr_t attr,
     42                            int32_t value);
     43 void mediametrics_setInt64(mediametrics_handle_t handle, attr_t attr,
     44                            int64_t value);
     45 void mediametrics_setDouble(mediametrics_handle_t handle, attr_t attr,
     46                             double value);
     47 void mediametrics_setRate(mediametrics_handle_t handle, attr_t attr,
     48                           int64_t count, int64_t duration);
     49 void mediametrics_setCString(mediametrics_handle_t handle, attr_t attr,
     50                             const char * value);
     51 
     52 // fused get/add/set; if attr wasn't there, it's a simple set.
     53 // these do not provide atomicity or mutual exclusion, only simpler code sequences.
     54 void mediametrics_addInt32(mediametrics_handle_t handle, attr_t attr,
     55                            int32_t value);
     56 void mediametrics_addInt64(mediametrics_handle_t handle, attr_t attr,
     57                            int64_t value);
     58 void mediametrics_addDouble(mediametrics_handle_t handle, attr_t attr,
     59                             double value);
     60 void mediametrics_addRate(mediametrics_handle_t handle, attr_t attr,
     61                           int64_t count, int64_t duration);
     62 
     63 // find & extract values
     64 // return indicates whether attr exists (and thus whether value filled in)
     65 // NULL parameter value suppresses storage of value.
     66 bool mediametrics_getInt32(mediametrics_handle_t handle, attr_t attr,
     67                            int32_t * value);
     68 bool mediametrics_getInt64(mediametrics_handle_t handle, attr_t attr,
     69                            int64_t * value);
     70 bool mediametrics_getDouble(mediametrics_handle_t handle, attr_t attr,
     71                             double *value);
     72 bool mediametrics_getRate(mediametrics_handle_t handle, attr_t attr,
     73                           int64_t * count, int64_t * duration, double *rate);
     74 bool mediametrics_getCString(mediametrics_handle_t handle, attr_t attr,
     75                             char **value);
     76 // to release strings returned via getCString()
     77 void mediametrics_freeCString(char *value);
     78 
     79 // # of attributes set within this record.
     80 int32_t mediametrics_count(mediametrics_handle_t handle);
     81 
     82 bool mediametrics_selfRecord(mediametrics_handle_t handle);
     83 
     84 const char *mediametrics_readable(mediametrics_handle_t handle);
     85 void mediametrics_setUid(mediametrics_handle_t handle, uid_t uid);
     86 bool mediametrics_isEnabled();
     87 
     88 // serialized copy of the attributes/values, mostly for upstream getMetrics() calls
     89 // caller owns the buffer allocated as part of this call.
     90 bool mediametrics_getAttributes(mediametrics_handle_t handle, char **buffer, size_t *length);
     91 
     92 __END_DECLS
     93 
     94 #endif
     95