diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cutils/list.h | 24 | ||||
-rw-r--r-- | include/log/log.h | 23 | ||||
-rw-r--r-- | include/log/log_read.h | 79 | ||||
-rw-r--r-- | include/log/logger.h | 131 | ||||
-rw-r--r-- | include/log/uio.h | 6 | ||||
-rw-r--r-- | include/sysutils/SocketClient.h | 29 | ||||
-rw-r--r-- | include/sysutils/SocketClientCommand.h | 27 | ||||
-rw-r--r-- | include/sysutils/SocketListener.h | 8 |
8 files changed, 276 insertions, 51 deletions
diff --git a/include/cutils/list.h b/include/cutils/list.h index 72395f4..945729a 100644 --- a/include/cutils/list.h +++ b/include/cutils/list.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 The Android Open Source Project + * Copyright (C) 2008-2013 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,9 +49,25 @@ struct listnode node != (list); \ node = next, next = node->next) -void list_init(struct listnode *list); -void list_add_tail(struct listnode *list, struct listnode *item); -void list_remove(struct listnode *item); +static inline void list_init(struct listnode *node) +{ + node->next = node; + node->prev = node; +} + +static inline void list_add_tail(struct listnode *head, struct listnode *item) +{ + item->next = head; + item->prev = head->prev; + head->prev->next = item; + head->prev = item; +} + +static inline void list_remove(struct listnode *item) +{ + item->next->prev = item->prev; + item->prev->next = item->next; +} #define list_empty(list) ((list) == (list)->next) #define list_head(list) ((list)->next) diff --git a/include/log/log.h b/include/log/log.h index 7faddea..7f952ff 100644 --- a/include/log/log.h +++ b/include/log/log.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005 The Android Open Source Project + * Copyright (C) 2005-2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,17 +28,16 @@ #ifndef _LIBS_LOG_LOG_H #define _LIBS_LOG_LOG_H -#include <stdio.h> -#include <time.h> #include <sys/types.h> -#include <unistd.h> #ifdef HAVE_PTHREADS #include <pthread.h> #endif #include <stdarg.h> - -#include <log/uio.h> +#include <stdio.h> +#include <time.h> +#include <unistd.h> #include <log/logd.h> +#include <log/uio.h> #ifdef __cplusplus extern "C" { @@ -470,7 +469,8 @@ typedef enum { EVENT_TYPE_STRING = 2, EVENT_TYPE_LIST = 3, } AndroidEventLogType; - +#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType) +#define typeof_AndroidEventLogType unsigned char #ifndef LOG_EVENT_INT #define LOG_EVENT_INT(_tag, _value) { \ @@ -540,7 +540,9 @@ typedef enum { #define android_logToFile(tag, file) (0) #define android_logToFd(tag, fd) (0) -typedef enum { +typedef enum log_id { + LOG_ID_MIN = 0, + LOG_ID_MAIN = 0, LOG_ID_RADIO = 1, LOG_ID_EVENTS = 2, @@ -548,6 +550,8 @@ typedef enum { LOG_ID_MAX } log_id_t; +#define sizeof_log_id_t sizeof(typeof_log_id_t) +#define typeof_log_id_t unsigned char /* * Send a simple string to the log. @@ -555,9 +559,8 @@ typedef enum { int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text); int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...); - #ifdef __cplusplus } #endif -#endif // _LIBS_CUTILS_LOG_H +#endif /* _LIBS_LOG_LOG_H */ diff --git a/include/log/log_read.h b/include/log/log_read.h new file mode 100644 index 0000000..861c192 --- /dev/null +++ b/include/log/log_read.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2013-2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _LIBS_LOG_LOG_READ_H +#define _LIBS_LOG_LOG_READ_H + +#include <time.h> + +#define NS_PER_SEC 1000000000ULL +#ifdef __cplusplus +struct log_time : public timespec { +public: + log_time(timespec &T) + { + tv_sec = T.tv_sec; + tv_nsec = T.tv_nsec; + } + log_time(void) + { + } + log_time(clockid_t id) + { + clock_gettime(id, (timespec *) this); + } + log_time(const char *T) + { + const uint8_t *c = (const uint8_t *) T; + tv_sec = c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24); + tv_nsec = c[4] | (c[5] << 8) | (c[6] << 16) | (c[7] << 24); + } + bool operator== (const timespec &T) const + { + return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec); + } + bool operator!= (const timespec &T) const + { + return !(*this == T); + } + bool operator< (const timespec &T) const + { + return (tv_sec < T.tv_sec) + || ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec)); + } + bool operator>= (const timespec &T) const + { + return !(*this < T); + } + bool operator> (const timespec &T) const + { + return (tv_sec > T.tv_sec) + || ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec)); + } + bool operator<= (const timespec &T) const + { + return !(*this > T); + } + uint64_t nsec(void) const + { + return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec; + } +}; +#else +typedef struct timespec log_time; +#endif + +#endif /* define _LIBS_LOG_LOG_READ_H */ diff --git a/include/log/logger.h b/include/log/logger.h index 04f3fb0..966397a 100644 --- a/include/log/logger.h +++ b/include/log/logger.h @@ -1,16 +1,21 @@ -/* utils/logger.h -** -** Copyright 2007, The Android Open Source Project +/* +** +** Copyright 2007-2014, The Android Open Source Project ** ** This file is dual licensed. It may be redistributed and/or modified ** under the terms of the Apache 2.0 License OR version 2 of the GNU ** General Public License. */ -#ifndef _UTILS_LOGGER_H -#define _UTILS_LOGGER_H +#ifndef _LIBS_LOG_LOGGER_H +#define _LIBS_LOG_LOGGER_H #include <stdint.h> +#include <log/log.h> + +#ifdef __cplusplus +extern "C" { +#endif /* * The userspace structure for version 1 of the logger_entry ABI. @@ -43,11 +48,6 @@ struct logger_entry_v2 { char msg[0]; /* the entry's payload */ }; -#define LOGGER_LOG_MAIN "log/main" -#define LOGGER_LOG_RADIO "log/radio" -#define LOGGER_LOG_EVENTS "log/events" -#define LOGGER_LOG_SYSTEM "log/system" - /* * The maximum size of the log entry payload that can be * written to the kernel logger driver. An attempt to write @@ -63,19 +63,108 @@ struct logger_entry_v2 { */ #define LOGGER_ENTRY_MAX_LEN (5*1024) -#ifdef HAVE_IOCTL +#define NS_PER_SEC 1000000000ULL + +struct log_msg { + union { + unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1]; + struct logger_entry_v2 entry; + struct logger_entry_v2 entry_v2; + struct logger_entry entry_v1; + struct { + unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1]; + log_id_t id; + } extra; + } __attribute__((aligned(4))); +#ifdef __cplusplus + /* Matching log_time operators */ + bool operator== (const log_msg &T) const + { + return (entry.sec == T.entry.sec) && (entry.nsec == T.entry.nsec); + } + bool operator!= (const log_msg &T) const + { + return !(*this == T); + } + bool operator< (const log_msg &T) const + { + return (entry.sec < T.entry.sec) + || ((entry.sec == T.entry.sec) + && (entry.nsec < T.entry.nsec)); + } + bool operator>= (const log_msg &T) const + { + return !(*this < T); + } + bool operator> (const log_msg &T) const + { + return (entry.sec > T.entry.sec) + || ((entry.sec == T.entry.sec) + && (entry.nsec > T.entry.nsec)); + } + bool operator<= (const log_msg &T) const + { + return !(*this > T); + } + uint64_t nsec(void) const + { + return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec; + } + + /* packet methods */ + log_id_t id(void) + { + return extra.id; + } + char *msg(void) + { + return entry.hdr_size ? (char *) buf + entry.hdr_size : entry_v1.msg; + } + unsigned int len(void) + { + return (entry.hdr_size ? entry.hdr_size : sizeof(entry_v1)) + entry.len; + } +#endif +}; -#include <sys/ioctl.h> +struct logger; -#define __LOGGERIO 0xAE +log_id_t android_logger_get_id(struct logger *logger); -#define LOGGER_GET_LOG_BUF_SIZE _IO(__LOGGERIO, 1) /* size of log */ -#define LOGGER_GET_LOG_LEN _IO(__LOGGERIO, 2) /* used log len */ -#define LOGGER_GET_NEXT_ENTRY_LEN _IO(__LOGGERIO, 3) /* next entry len */ -#define LOGGER_FLUSH_LOG _IO(__LOGGERIO, 4) /* flush log */ -#define LOGGER_GET_VERSION _IO(__LOGGERIO, 5) /* abi version */ -#define LOGGER_SET_VERSION _IO(__LOGGERIO, 6) /* abi version */ +int android_logger_clear(struct logger *logger); +int android_logger_get_log_size(struct logger *logger); +int android_logger_get_log_readable_size(struct logger *logger); +int android_logger_get_log_version(struct logger *logger); + +struct logger_list; + +struct logger_list *android_logger_list_alloc(int mode, + unsigned int tail, + pid_t pid); +void android_logger_list_free(struct logger_list *logger_list); +/* In the purest sense, the following two are orthogonal interfaces */ +int android_logger_list_read(struct logger_list *logger_list, + struct log_msg *log_msg); + +/* Multiple log_id_t opens */ +struct logger *android_logger_open(struct logger_list *logger_list, + log_id_t id); +#define android_logger_close android_logger_free +/* Single log_id_t open */ +struct logger_list *android_logger_list_open(log_id_t id, + int mode, + unsigned int tail, + pid_t pid); +#define android_logger_list_close android_logger_list_free + +/* + * log_id_t helpers + */ +log_id_t android_name_to_log_id(const char *logName); +const char *android_log_id_to_name(log_id_t log_id); -#endif // HAVE_IOCTL +#ifdef __cplusplus +} +#endif -#endif /* _UTILS_LOGGER_H */ +#endif /* _LIBS_LOG_LOGGER_H */ diff --git a/include/log/uio.h b/include/log/uio.h index 01a74d2..a71f515 100644 --- a/include/log/uio.h +++ b/include/log/uio.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 The Android Open Source Project + * Copyright (C) 2007-2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,8 @@ extern "C" { #include <stddef.h> struct iovec { - const void* iov_base; - size_t iov_len; + void* iov_base; + size_t iov_len; }; extern int readv( int fd, struct iovec* vecs, int count ); diff --git a/include/sysutils/SocketClient.h b/include/sysutils/SocketClient.h index 85b58ef..1004f06 100644 --- a/include/sysutils/SocketClient.h +++ b/include/sysutils/SocketClient.h @@ -6,22 +6,23 @@ #include <pthread.h> #include <cutils/atomic.h> #include <sys/types.h> +#include <sys/uio.h> class SocketClient { int mSocket; bool mSocketOwned; pthread_mutex_t mWriteMutex; - /* Peer process ID */ + // Peer process ID pid_t mPid; - /* Peer user ID */ + // Peer user ID uid_t mUid; - /* Peer group ID */ + // Peer group ID gid_t mGid; - /* Reference count (starts at 1) */ + // Reference count (starts at 1) pthread_mutex_t mRefCountMutex; int mRefCount; @@ -38,12 +39,15 @@ public: pid_t getPid() const { return mPid; } uid_t getUid() const { return mUid; } gid_t getGid() const { return mGid; } - void setCmdNum(int cmdNum) { android_atomic_release_store(cmdNum, &mCmdNum); } + void setCmdNum(int cmdNum) { + android_atomic_release_store(cmdNum, &mCmdNum); + } int getCmdNum() { return mCmdNum; } // Send null-terminated C strings: int sendMsg(int code, const char *msg, bool addErrno); int sendMsg(int code, const char *msg, bool addErrno, bool useCmdNum); + int sendMsg(const char *msg); // Provides a mechanism to send a response code to the client. // Sends the code and a null character. @@ -56,6 +60,8 @@ public: // Sending binary data: int sendData(const void *data, int len); + // iovec contents not preserved through call + int sendDatav(struct iovec *iov, int iovcnt); // Optional reference counting. Reference count starts at 1. If // it's decremented to 0, it deletes itself. @@ -64,19 +70,18 @@ public: void incRef(); bool decRef(); // returns true at 0 (but note: SocketClient already deleted) - // return a new string in quotes with '\\' and '\"' escaped for "my arg" transmissions + // return a new string in quotes with '\\' and '\"' escaped for "my arg" + // transmissions static char *quoteArg(const char *arg); private: - // Send null-terminated C strings - int sendMsg(const char *msg); void init(int socket, bool owned, bool useCmdNum); - // Sending binary data. The caller should use make sure this is protected + // Sending binary data. The caller should make sure this is protected // from multiple threads entering simultaneously. - // returns 0 if successful, -1 if there is a 0 byte write and -2 if any other - // error occurred (use errno to get the error) - int sendDataLocked(const void *data, int len); + // returns 0 if successful, -1 if there is a 0 byte write or if any + // other error occurred (use errno to get the error) + int sendDataLockedv(struct iovec *iov, int iovcnt); }; typedef android::sysutils::List<SocketClient *> SocketClientCollection; diff --git a/include/sysutils/SocketClientCommand.h b/include/sysutils/SocketClientCommand.h new file mode 100644 index 0000000..746bc25 --- /dev/null +++ b/include/sysutils/SocketClientCommand.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _SOCKETCLIENTCOMMAND_H +#define _SOCKETCLIENTCOMMAND_H + +#include <sysutils/SocketClient.h> + +class SocketClientCommand { +public: + virtual ~SocketClientCommand() { } + virtual void runSocketCommand(SocketClient *client) = 0; +}; + +#endif diff --git a/include/sysutils/SocketListener.h b/include/sysutils/SocketListener.h index 8f56230..c204a0f 100644 --- a/include/sysutils/SocketListener.h +++ b/include/sysutils/SocketListener.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 2008-2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ #include <pthread.h> #include <sysutils/SocketClient.h> +#include "SocketClientCommand.h" class SocketListener { bool mListen; @@ -41,10 +42,15 @@ public: void sendBroadcast(int code, const char *msg, bool addErrno); + void runOnEachSocket(SocketClientCommand *command); + + bool release(SocketClient *c) { return release(c, true); } + protected: virtual bool onDataAvailable(SocketClient *c) = 0; private: + bool release(SocketClient *c, bool wakeup); static void *threadStart(void *obj); void runListener(); void init(const char *socketName, int socketFd, bool listen, bool useCmdNum); |