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