• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <sys/cdefs.h>
28 #include <sys/types.h>
29 
30 __BEGIN_DECLS
31 
32 // internally re-cast to the behind-the-scenes C++ class instance
33 typedef int64_t mediametrics_handle_t;
34 typedef const char *mediametricskey_t;
35 typedef const char *attr_t;
36 
37 mediametrics_handle_t mediametrics_create(mediametricskey_t key);
38 void mediametrics_delete(mediametrics_handle_t handle);
39 
40 mediametricskey_t mediametrics_getKey(mediametrics_handle_t handle);
41 
42 
43 // set
44 void mediametrics_setInt32(mediametrics_handle_t handle, attr_t attr,
45                            int32_t value);
46 void mediametrics_setInt64(mediametrics_handle_t handle, attr_t attr,
47                            int64_t value);
48 void mediametrics_setDouble(mediametrics_handle_t handle, attr_t attr,
49                             double value);
50 void mediametrics_setRate(mediametrics_handle_t handle, attr_t attr,
51                           int64_t count, int64_t duration);
52 void mediametrics_setCString(mediametrics_handle_t handle, attr_t attr,
53                              const char * value);
54 
55 // fused get/add/set; if attr wasn't there, it's a simple set.
56 // these do not provide atomicity or mutual exclusion, only simpler code sequences.
57 void mediametrics_addInt32(mediametrics_handle_t handle, attr_t attr,
58                            int32_t value);
59 void mediametrics_addInt64(mediametrics_handle_t handle, attr_t attr,
60                            int64_t value);
61 void mediametrics_addDouble(mediametrics_handle_t handle, attr_t attr,
62                             double value);
63 void mediametrics_addRate(mediametrics_handle_t handle, attr_t attr,
64                           int64_t count, int64_t duration);
65 
66 // find & extract values
67 // return indicates whether attr exists (and thus whether value filled in)
68 // NULL parameter value suppresses storage of value.
69 bool mediametrics_getInt32(mediametrics_handle_t handle, attr_t attr,
70                            int32_t * value);
71 bool mediametrics_getInt64(mediametrics_handle_t handle, attr_t attr,
72                            int64_t * value);
73 bool mediametrics_getDouble(mediametrics_handle_t handle, attr_t attr,
74                             double *value);
75 bool mediametrics_getRate(mediametrics_handle_t handle, attr_t attr,
76                           int64_t * count, int64_t * duration, double *rate);
77 bool mediametrics_getCString(mediametrics_handle_t handle, attr_t attr,
78                             char **value);
79 // to release strings returned via getCString()
80 void mediametrics_freeCString(char *value);
81 
82 // # of attributes set within this record.
83 int32_t mediametrics_count(mediametrics_handle_t handle);
84 
85 mediametrics_handle_t mediametrics_dup(mediametrics_handle_t handle);
86 bool mediametrics_selfRecord(mediametrics_handle_t handle);
87 
88 const char *mediametrics_readable(mediametrics_handle_t handle);
89 void mediametrics_setUid(mediametrics_handle_t handle, uid_t uid);
90 bool mediametrics_isEnabled();
91 
92 // serialized copy of the attributes/values, mostly for upstream getMetrics() calls
93 // caller owns the buffer allocated as part of this call.
94 bool mediametrics_getAttributes(mediametrics_handle_t handle, char **buffer, size_t *length);
95 
96 __END_DECLS
97 
98 #ifdef __cplusplus
99 #include <string>
100 void mediametrics_setString(mediametrics_handle_t handle, attr_t attr,
101                             const std::string &value);
102 bool mediametrics_getString(mediametrics_handle_t handle, attr_t attr, std::string *value);
103 #endif // __cplusplus
104 
105 #endif
106