1 /*
2  * Copyright 2017 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 #include <audio_utils/ErrorLog.h>
18 
19 using namespace android;
20 
error_log_create(size_t entries,int64_t aggregate_ns)21 error_log_t *error_log_create(size_t entries, int64_t aggregate_ns)
22 {
23     return reinterpret_cast<error_log_t *>
24             (new(std::nothrow) ErrorLog<int32_t>(entries, aggregate_ns));
25 }
26 
error_log_log(error_log_t * error_log,int32_t code,int64_t now_ns)27 void error_log_log(error_log_t *error_log, int32_t code, int64_t now_ns)
28 {
29     if (error_log == nullptr) {
30         return;
31     }
32     reinterpret_cast<ErrorLog<int32_t> *>(error_log)->log(code, now_ns);
33 }
34 
error_log_dump(error_log_t * error_log,int fd,const char * prefix,size_t lines,int64_t limit_ns)35 int error_log_dump(
36         error_log_t *error_log, int fd, const char *prefix, size_t lines, int64_t limit_ns)
37 {
38     if (error_log == nullptr) {
39         return BAD_VALUE;
40     }
41     return reinterpret_cast<ErrorLog<int32_t> *>(error_log)->dump(fd, prefix, lines, limit_ns);
42 }
43 
error_log_destroy(error_log_t * error_log)44 void error_log_destroy(error_log_t *error_log)
45 {
46     delete reinterpret_cast<ErrorLog<int32_t> *>(error_log);
47 }
48