Yao Chen | f7bc6ab | 2018-04-18 13:45:48 -0700 | [diff] [blame] | 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_STATS_LOG_STATS_WRITER_H |
| 18 | #define ANDROID_STATS_LOG_STATS_WRITER_H |
| 19 | |
| 20 | #include <pthread.h> |
| 21 | #include <stdatomic.h> |
| 22 | #include <sys/socket.h> |
| 23 | |
| 24 | namespace android { |
| 25 | namespace util { |
| 26 | |
| 27 | /** |
| 28 | * Internal lock should not be exposed. This is bad design. |
| 29 | * TODO: rewrite it in c++ code and encapsulate the functionality in a |
| 30 | * StatsdWriter class. |
| 31 | */ |
| 32 | void statsd_writer_init_lock(); |
| 33 | int statsd_writer_init_trylock(); |
| 34 | void statsd_writer_init_unlock(); |
| 35 | |
| 36 | struct android_log_transport_write { |
| 37 | const char* name; /* human name to describe the transport */ |
| 38 | static std::atomic_int sock; |
| 39 | int (*available)(); /* Does not cause resources to be taken */ |
| 40 | int (*open)(); /* can be called multiple times, reusing current resources */ |
| 41 | void (*close)(); /* free up resources */ |
| 42 | /* write log to transport, returns number of bytes propagated, or -errno */ |
| 43 | int (*write)(struct timespec* ts, struct iovec* vec, size_t nr); |
| 44 | }; |
| 45 | |
| 46 | } // namespace util |
| 47 | } // namespace android |
| 48 | |
| 49 | #endif // ANDROID_STATS_LOG_STATS_WRITER_H |