| Yao Chen | b3be9ea | 2018-05-07 16:57:13 -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 | /** | 
|  | 25 | * Internal lock should not be exposed. This is bad design. | 
|  | 26 | * TODO: rewrite it in c++ code and encapsulate the functionality in a | 
|  | 27 | * StatsdWriter class. | 
|  | 28 | */ | 
|  | 29 | void statsd_writer_init_lock(); | 
|  | 30 | int statsd_writer_init_trylock(); | 
|  | 31 | void statsd_writer_init_unlock(); | 
|  | 32 |  | 
|  | 33 | struct android_log_transport_write { | 
|  | 34 | const char* name; /* human name to describe the transport */ | 
|  | 35 | atomic_int sock; | 
|  | 36 | int (*available)(); /* Does not cause resources to be taken */ | 
|  | 37 | int (*open)();      /* can be called multiple times, reusing current resources */ | 
|  | 38 | void (*close)();    /* free up resources */ | 
|  | 39 | /* write log to transport, returns number of bytes propagated, or -errno */ | 
|  | 40 | int (*write)(struct timespec* ts, struct iovec* vec, size_t nr); | 
|  | 41 | }; | 
|  | 42 |  | 
|  | 43 | #endif  // ANDROID_STATS_LOG_STATS_WRITER_H |