diff options
author | Ziyan <jaraidaniel@gmail.com> | 2015-04-11 23:15:11 +0200 |
---|---|---|
committer | Ziyan <jaraidaniel@gmail.com> | 2015-04-11 23:15:11 +0200 |
commit | 86666cc6ef99fa0a2761dc0c56e30df7cbb8e52c (patch) | |
tree | 8e38fe26d331e175fa4183fc16ea391145c12cd2 /libtiutils | |
parent | 05555c23e049a7ef25d7436fdad4e8cde5754642 (diff) | |
download | device_samsung_tuna-86666cc6ef99fa0a2761dc0c56e30df7cbb8e52c.zip device_samsung_tuna-86666cc6ef99fa0a2761dc0c56e30df7cbb8e52c.tar.gz device_samsung_tuna-86666cc6ef99fa0a2761dc0c56e30df7cbb8e52c.tar.bz2 |
Remove common omap4 modules
domx: remove for move to omap4-next
edid/hwc: remove for move to omap4-next
include / kernel-headers: remove for move to omap4-next
libcorkscrew: remove for move to omap4-next
libion_ti: remove for move to omap4-next
libtiutils: remove for move to omap4-next
pvr-source / pvrsrvinit: remove for move to omap4-next
remove gralloc symlink for move to omap4-next
Change-Id: I1ade011fd5e0adedbcb19cbf941fdde5ef4f96b6
symlinks: remove for move to omap4-next
Diffstat (limited to 'libtiutils')
-rw-r--r-- | libtiutils/Android.mk | 46 | ||||
-rw-r--r-- | libtiutils/DebugUtils.cpp | 96 | ||||
-rw-r--r-- | libtiutils/DebugUtils.h | 398 | ||||
-rw-r--r-- | libtiutils/ErrorUtils.cpp | 140 | ||||
-rw-r--r-- | libtiutils/ErrorUtils.h | 56 | ||||
-rw-r--r-- | libtiutils/MessageQueue.cpp | 419 | ||||
-rw-r--r-- | libtiutils/MessageQueue.h | 98 | ||||
-rw-r--r-- | libtiutils/Semaphore.cpp | 232 | ||||
-rw-r--r-- | libtiutils/Semaphore.h | 63 | ||||
-rw-r--r-- | libtiutils/Status.h | 67 | ||||
-rw-r--r-- | libtiutils/UtilsCommon.h | 99 |
11 files changed, 0 insertions, 1714 deletions
diff --git a/libtiutils/Android.mk b/libtiutils/Android.mk deleted file mode 100644 index c34c833..0000000 --- a/libtiutils/Android.mk +++ /dev/null @@ -1,46 +0,0 @@ -################################################ - -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= \ - DebugUtils.cpp \ - MessageQueue.cpp \ - Semaphore.cpp \ - ErrorUtils.cpp - -LOCAL_SHARED_LIBRARIES:= \ - libdl \ - libui \ - libbinder \ - libutils \ - libcutils - -LOCAL_C_INCLUDES += \ - frameworks/native/include \ - frameworks/native/include/media/openmax - -LOCAL_C_INCLUDES += \ - bionic/libc/include - -LOCAL_C_INCLUDES += \ - $(DOMX_PATH)/omx_core/inc \ - $(DOMX_PATH)/mm_osal/inc - -LOCAL_CFLAGS += -fno-short-enums $(ANDROID_API_CFLAGS) - -ifdef TI_UTILS_MESSAGE_QUEUE_DEBUG_ENABLED - # Enable debug logs - LOCAL_CFLAGS += -DMSGQ_DEBUG -endif - -ifdef TI_UTILS_MESSAGE_QUEUE_DEBUG_FUNCTION_NAMES - # Enable function enter/exit logging - LOCAL_CFLAGS += -DTI_UTILS_FUNCTION_LOGGER_ENABLE -endif - -LOCAL_MODULE:= libtiutils_$(TARGET_BOOTLOADER_BOARD_NAME) -LOCAL_MODULE_TAGS:= optional - -include $(BUILD_SHARED_LIBRARY) diff --git a/libtiutils/DebugUtils.cpp b/libtiutils/DebugUtils.cpp deleted file mode 100644 index 60ad0c8..0000000 --- a/libtiutils/DebugUtils.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * 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. - */ - -#include "DebugUtils.h" - -#include "utils/Debug.h" - - - - -namespace Ti { - - - - -// shared const buffer with spaces for indentation string -extern const char sIndentStringBuffer[] = - " " - " "; -template class android::CompileTimeAssert<sizeof(sIndentStringBuffer) - 1 == kIndentStringMaxLength>; - - - - -static const int kDebugThreadInfoGrowSize = 16; - - - - -Debug Debug::sInstance; - - - - -Debug::Debug() -{ - grow(); -} - - -void Debug::grow() -{ - android::AutoMutex locker(mMutex); - (void)locker; - - const int size = kDebugThreadInfoGrowSize; - - const int newSize = (mData.get() ? mData->threads.size() : 0) + size; - - Data * const newData = new Data; - newData->threads.setCapacity(newSize); - - // insert previous thread info pointers - if ( mData.get() ) - newData->threads.insertVectorAt(mData->threads, 0); - - // populate data with new thread infos - for ( int i = 0; i < size; ++i ) - newData->threads.add(new ThreadInfo); - - // replace old data with new one - mData = newData; -} - - -Debug::ThreadInfo * Debug::registerThread(Data * const data, const int32_t threadId) -{ - const int size = data->threads.size(); - for ( int i = 0; i < size; ++i ) - { - ThreadInfo * const threadInfo = data->threads.itemAt(i); - if ( android_atomic_acquire_cas(0, threadId, &threadInfo->threadId) == 0 ) - return threadInfo; - } - - // failed to find empty slot for thread - return 0; -} - - - - -} // namespace Ti diff --git a/libtiutils/DebugUtils.h b/libtiutils/DebugUtils.h deleted file mode 100644 index 958bae5..0000000 --- a/libtiutils/DebugUtils.h +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * 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 DEBUG_UTILS_H -#define DEBUG_UTILS_H - -#include <android/log.h> -#include <utils/threads.h> -#include <utils/Vector.h> - - - - -namespace Ti { - - - - -// use 2 space characters for call stack indent -static const int kFunctionLoggerIndentSize = 2; - - - - -template <int Size = kFunctionLoggerIndentSize> -class IndentString -{ -public: - IndentString(int length); - - const char * string() const; - -private: - int calculateOffset(int length) const; - -private: - const int mOffset; -}; - - - - -class Debug -{ -public: - static Debug * instance(); - - int offsetForCurrentThread(); - void log(int priority, const char * format, ...); - -private: - class ThreadInfo - { - public: - ThreadInfo() : - threadId(0), callOffset(0) - {} - - volatile int32_t threadId; - int callOffset; - }; - - class Data : public android::RefBase - { - public: - android::Vector<ThreadInfo*> threads; - }; - -private: - // called from FunctionLogger - void increaseOffsetForCurrentThread(); - void decreaseOffsetForCurrentThread(); - -private: - Debug(); - - void grow(); - ThreadInfo * registerThread(Data * data, int32_t threadId); - ThreadInfo * findCurrentThreadInfo(); - void addOffsetForCurrentThread(int offset); - -private: - static Debug sInstance; - - mutable android::Mutex mMutex; - android::sp<Data> mData; - - friend class FunctionLogger; -}; - - - - -class FunctionLogger -{ -public: - FunctionLogger(const char * file, int line, const char * function); - ~FunctionLogger(); - - void setExitLine(int line); - -private: - const char * const mFile; - const int mLine; - const char * const mFunction; - const void * const mThreadId; - int mExitLine; -}; - - - - -#ifdef TI_UTILS_FUNCTION_LOGGER_ENABLE -# define LOG_FUNCTION_NAME Ti::FunctionLogger __function_logger_instance(__FILE__, __LINE__, __FUNCTION__); -# define LOG_FUNCTION_NAME_EXIT __function_logger_instance.setExitLine(__LINE__); -#else -# define LOG_FUNCTION_NAME int __function_logger_instance; -# define LOG_FUNCTION_NAME_EXIT -/*(void*)__function_logger_instance;*/ -#endif - -#ifdef TI_UTILS_DEBUG_USE_TIMESTAMPS - // truncate timestamp to 1000 seconds to fit into 6 characters -# define TI_UTILS_DEBUG_TIMESTAMP_TOKEN "[%06d] " -# define TI_UTILS_DEBUG_TIMESTAMP_VARIABLE static_cast<int>(nanoseconds_to_milliseconds(systemTime()) % 1000000), -#else -# define TI_UTILS_DEBUG_TIMESTAMP_TOKEN -# define TI_UTILS_DEBUG_TIMESTAMP_VARIABLE -#endif - - - - -#define DBGUTILS_LOGV_FULL(priority, file, line, function, format, ...) \ - do \ - { \ - Ti::Debug * const debug = Ti::Debug::instance(); \ - debug->log(priority, format, \ - TI_UTILS_DEBUG_TIMESTAMP_VARIABLE \ - reinterpret_cast<int>(androidGetThreadId()), \ - Ti::IndentString<>(debug->offsetForCurrentThread()).string(), \ - file, line, function, __VA_ARGS__); \ - } while (0) - -#define DBGUTILS_LOGV(...) DBGUTILS_LOGV_FULL(ANDROID_LOG_VERBOSE, __FILE__, __LINE__, __FUNCTION__, TI_UTILS_DEBUG_TIMESTAMP_TOKEN "(%x) %s %s:%d %s - " __VA_ARGS__, "") -#define DBGUTILS_LOGD(...) DBGUTILS_LOGV_FULL(ANDROID_LOG_DEBUG, __FILE__, __LINE__, __FUNCTION__, TI_UTILS_DEBUG_TIMESTAMP_TOKEN "(%x) %s %s:%d %s - " __VA_ARGS__, "") -#define DBGUTILS_LOGI(...) DBGUTILS_LOGV_FULL(ANDROID_LOG_INFO, __FILE__, __LINE__, __FUNCTION__, TI_UTILS_DEBUG_TIMESTAMP_TOKEN "(%x) %s %s:%d %s - " __VA_ARGS__, "") -#define DBGUTILS_LOGW(...) DBGUTILS_LOGV_FULL(ANDROID_LOG_WARN, __FILE__, __LINE__, __FUNCTION__, TI_UTILS_DEBUG_TIMESTAMP_TOKEN "(%x) %s %s:%d %s - " __VA_ARGS__, "") -#define DBGUTILS_LOGE(...) DBGUTILS_LOGV_FULL(ANDROID_LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, TI_UTILS_DEBUG_TIMESTAMP_TOKEN "(%x) %s %s:%d %s - " __VA_ARGS__, "") -#define DBGUTILS_LOGF(...) DBGUTILS_LOGV_FULL(ANDROID_LOG_FATAL, __FILE__, __LINE__, __FUNCTION__, TI_UTILS_DEBUG_TIMESTAMP_TOKEN "(%x) %s %s:%d %s - " __VA_ARGS__, "") - -#define DBGUTILS_LOGVA DBGUTILS_LOGV -#define DBGUTILS_LOGVB DBGUTILS_LOGV - -#define DBGUTILS_LOGDA DBGUTILS_LOGD -#define DBGUTILS_LOGDB DBGUTILS_LOGD - -#define DBGUTILS_LOGEA DBGUTILS_LOGE -#define DBGUTILS_LOGEB DBGUTILS_LOGE - -// asserts -#define _DBGUTILS_PLAIN_ASSERT(condition) \ - do \ - { \ - if ( !(condition) ) \ - { \ - __android_log_print(ANDROID_LOG_FATAL, "Ti::Debug", \ - "Condition failed: " #condition); \ - __android_log_print(ANDROID_LOG_FATAL, "Ti::Debug", \ - "Aborting process..."); \ - abort(); \ - } \ - } while (0) - -#define _DBGUTILS_PLAIN_ASSERT_X(condition, ...) \ - do \ - { \ - if ( !(condition) ) \ - { \ - __android_log_print(ANDROID_LOG_FATAL, "Ti::Debug", \ - "Condition failed: " #condition ": " __VA_ARGS__); \ - __android_log_print(ANDROID_LOG_FATAL, "Ti::Debug", \ - "Aborting process..."); \ - abort(); \ - } \ - } while (0) - -#define DBGUTILS_ASSERT(condition) \ - do \ - { \ - if ( !(condition) ) \ - { \ - DBGUTILS_LOGF("Condition failed: " #condition); \ - DBGUTILS_LOGF("Aborting process..."); \ - abort(); \ - } \ - } while (0) - -#define DBGUTILS_ASSERT_X(condition, ...) \ - do \ - { \ - if ( !(condition) ) \ - { \ - DBGUTILS_LOGF("Condition failed: " #condition ": " __VA_ARGS__); \ - DBGUTILS_LOGF("Aborting process..."); \ - abort(); \ - } \ - } while (0) - - - - -static const int kIndentStringMaxLength = 128; - -template <int Size> -inline int IndentString<Size>::calculateOffset(const int length) const -{ - const int offset = kIndentStringMaxLength - length*Size; - return offset < 0 ? 0 : offset; -} - -template <int Size> -inline IndentString<Size>::IndentString(const int length) : - mOffset(calculateOffset(length)) -{} - -template <int Size> -inline const char * IndentString<Size>::string() const -{ - extern const char sIndentStringBuffer[]; - return sIndentStringBuffer + mOffset; -} - - - - -inline Debug * Debug::instance() -{ return &sInstance; } - - -inline Debug::ThreadInfo * Debug::findCurrentThreadInfo() -{ - // retain reference to threads data - android::sp<Data> data = mData; - - // iterate over threads to locate thread id, - // this is safe from race conditions because each thread - // is able to modify only his own ThreadInfo structure - const int32_t threadId = reinterpret_cast<int32_t>(androidGetThreadId()); - const int size = int(data->threads.size()); - for ( int i = 0; i < size; ++i ) - { - ThreadInfo * const threadInfo = data->threads.itemAt(i); - if ( threadInfo->threadId == threadId ) - return threadInfo; - } - - // this thread has not been registered yet, - // try to fing empty thread info slot - while ( true ) - { - ThreadInfo * const threadInfo = registerThread(data.get(), threadId); - if ( threadInfo ) - return threadInfo; - - // failed registering thread, because all slots are occupied - // grow the data and try again - grow(); - - data = mData; - } - - // should never reach here - _DBGUTILS_PLAIN_ASSERT(false); - return 0; -} - - -inline void Debug::addOffsetForCurrentThread(const int offset) -{ - if ( offset == 0 ) - return; - - ThreadInfo * const threadInfo = findCurrentThreadInfo(); - _DBGUTILS_PLAIN_ASSERT(threadInfo); - - threadInfo->callOffset += offset; - - if ( threadInfo->callOffset == 0 ) - { - // thread call stack has dropped to zero, unregister it - android_atomic_acquire_store(0, &threadInfo->threadId); - } -} - - -inline int Debug::offsetForCurrentThread() -{ -#ifdef TI_UTILS_FUNCTION_LOGGER_ENABLE - ThreadInfo * const threadInfo = findCurrentThreadInfo(); - _DBGUTILS_PLAIN_ASSERT(threadInfo); - - return threadInfo->callOffset; -#else - return 0; -#endif -} - - -inline void Debug::increaseOffsetForCurrentThread() -{ -#ifdef TI_UTILS_FUNCTION_LOGGER_ENABLE - addOffsetForCurrentThread(1); -#endif -} - - -inline void Debug::decreaseOffsetForCurrentThread() -{ -#ifdef TI_UTILS_FUNCTION_LOGGER_ENABLE - addOffsetForCurrentThread(-1); -#endif -} - - -inline void Debug::log(const int priority, const char * const format, ...) -{ - va_list args; - va_start(args, format); - __android_log_vprint(priority, LOG_TAG, format, args); - va_end(args); -} - - - - -inline FunctionLogger::FunctionLogger(const char * const file, const int line, const char * const function) : - mFile(file), mLine(line), mFunction(function), mThreadId(androidGetThreadId()), mExitLine(-1) -{ - Debug * const debug = Debug::instance(); - debug->increaseOffsetForCurrentThread(); - android_printLog(ANDROID_LOG_DEBUG, LOG_TAG, - TI_UTILS_DEBUG_TIMESTAMP_TOKEN "(%x) %s+ %s:%d %s - ENTER", - TI_UTILS_DEBUG_TIMESTAMP_VARIABLE - (int)mThreadId, IndentString<>(debug->offsetForCurrentThread()).string(), - mFile, mLine, mFunction); -} - - -inline FunctionLogger::~FunctionLogger() -{ - Debug * const debug = Debug::instance(); - android_printLog(ANDROID_LOG_DEBUG, LOG_TAG, - TI_UTILS_DEBUG_TIMESTAMP_TOKEN "(%x) %s- %s:%d %s - EXIT", - TI_UTILS_DEBUG_TIMESTAMP_VARIABLE - (int)mThreadId, IndentString<>(debug->offsetForCurrentThread()).string(), - mFile, mExitLine == -1 ? mLine : mExitLine, mFunction); - debug->decreaseOffsetForCurrentThread(); -} - - -inline void FunctionLogger::setExitLine(const int line) -{ - if ( mExitLine != -1 ) - { - Debug * const debug = Debug::instance(); - android_printLog(ANDROID_LOG_DEBUG, LOG_TAG, - TI_UTILS_DEBUG_TIMESTAMP_TOKEN "(%x) %s %s:%d %s - Double function exit trace detected. Previous: %d", - TI_UTILS_DEBUG_TIMESTAMP_VARIABLE - (int)mThreadId, IndentString<>(debug->offsetForCurrentThread()).string(), - mFile, line, mFunction, mExitLine); - } - - mExitLine = line; -} - - - - -} // namespace Ti - - - - -#endif //DEBUG_UTILS_H diff --git a/libtiutils/ErrorUtils.cpp b/libtiutils/ErrorUtils.cpp deleted file mode 100644 index e30fcfd..0000000 --- a/libtiutils/ErrorUtils.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * 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. - */ - - -#include "ErrorUtils.h" - -namespace Ti { -namespace Utils { - -/** - @brief Method to convert from POSIX to Android errors - - @param error Any of the standard POSIX error codes (defined in bionic/libc/kernel/common/asm-generic/errno.h) - @return Any of the standard Android error code (defined in frameworks/base/include/utils/Errors.h) - */ -status_t ErrorUtils::posixToAndroidError(int error) -{ - switch(error) - { - case 0: - return NO_ERROR; - case EINVAL: - case EFBIG: - case EMSGSIZE: - case E2BIG: - case EFAULT: - case EILSEQ: - return BAD_VALUE; - case ENOSYS: - return INVALID_OPERATION; - case EACCES: - case EPERM: - return PERMISSION_DENIED; - case EADDRINUSE: - case EAGAIN: - case EALREADY: - case EBUSY: - case EEXIST: - case EINPROGRESS: - return ALREADY_EXISTS; - case ENOMEM: - return NO_MEMORY; - default: - return UNKNOWN_ERROR; - }; - - return NO_ERROR; -} - - -/** - @brief Method to convert from TI OSAL to Android errors - - @param error Any of the standard TI OSAL error codes (defined in - hardware/ti/omx/ducati/domx/system/mm_osal/inc/timm_osal_error.h) - @return Any of the standard Android error code (defined in frameworks/base/include/utils/Errors.h) - */ -status_t ErrorUtils::osalToAndroidError(TIMM_OSAL_ERRORTYPE error) -{ - switch(error) - { - case TIMM_OSAL_ERR_NONE: - return NO_ERROR; - case TIMM_OSAL_ERR_ALLOC: - return NO_MEMORY; - default: - return UNKNOWN_ERROR; - } - - return NO_ERROR; -} - -/** - @brief Method to convert from OMX to Android errors - - @param error Any of the standard OMX error codes (defined in hardware/ti/omx/ducati/domx/system/omx_core/inc/OMX_Core.h) - @return Any of the standard Android error code (defined in frameworks/base/include/utils/Errors.h) - */ -status_t ErrorUtils::omxToAndroidError(OMX_ERRORTYPE error) -{ - switch(error) - { - case OMX_ErrorNone: - return NO_ERROR; - case OMX_ErrorBadParameter: - case OMX_ErrorInvalidComponentName: - case OMX_ErrorUndefined: - case OMX_ErrorInvalidState: - case OMX_ErrorStreamCorrupt: - case OMX_ErrorPortsNotCompatible: - case OMX_ErrorVersionMismatch: - case OMX_ErrorMbErrorsInFrame: - return BAD_VALUE; - case OMX_ErrorInsufficientResources: - return NO_MEMORY; - case OMX_ErrorComponentNotFound: - case OMX_ErrorNotImplemented: - case OMX_ErrorFormatNotDetected: - case OMX_ErrorUnsupportedSetting: - return NAME_NOT_FOUND; - case OMX_ErrorUnderflow: - case OMX_ErrorOverflow: - case OMX_ErrorUnsupportedIndex: - case OMX_ErrorBadPortIndex: - return BAD_INDEX; - case OMX_ErrorHardware: - case OMX_ErrorContentPipeCreationFailed: - case OMX_ErrorContentPipeOpenFailed: - return FAILED_TRANSACTION; - case OMX_ErrorTimeout: - return TIMED_OUT; - case OMX_ErrorSameState: - case OMX_ErrorIncorrectStateTransition: - case OMX_ErrorIncorrectStateOperation: - return PERMISSION_DENIED; - case OMX_ErrorTunnelingUnsupported: - return INVALID_OPERATION; - default: - return UNKNOWN_ERROR; - } - - return NO_ERROR; -} - - -} // namespace Utils -} // namespace Ti diff --git a/libtiutils/ErrorUtils.h b/libtiutils/ErrorUtils.h deleted file mode 100644 index c6c23a2..0000000 --- a/libtiutils/ErrorUtils.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * 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 ERROR_UTILS_H -#define ERROR_UTILS_H - -///Header file where all the android error codes are defined -#include <utils/Errors.h> - -///Header file where all the OMX error codes are defined -#include "OMX_Core.h" - -#include "Status.h" - - -extern "C" -{ -///Header file where all the TI OSAL error codes are defined -#include "timm_osal_error.h" -}; - -namespace Ti { -namespace Utils { - -///Generic class with static methods to convert any standard error type to Android error type -class ErrorUtils -{ -public: - ///Method to convert from POSIX to Android errors - static status_t posixToAndroidError(int error); - - ///Method to convert from TI OSAL to Android errors - static status_t osalToAndroidError(TIMM_OSAL_ERRORTYPE error); - - ///Method to convert from OMX to Android errors - static status_t omxToAndroidError(OMX_ERRORTYPE error); - -}; - -} // namespace Utils -} // namespace Ti - -#endif /// ERROR_UTILS_H diff --git a/libtiutils/MessageQueue.cpp b/libtiutils/MessageQueue.cpp deleted file mode 100644 index 13b1d53..0000000 --- a/libtiutils/MessageQueue.cpp +++ /dev/null @@ -1,419 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * 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. - */ - - -#include <errno.h> -#include <string.h> -#include <sys/types.h> -#include <sys/poll.h> -#include <unistd.h> -#include <utils/Errors.h> - - - -#define LOG_TAG "MessageQueue" -#include <utils/Log.h> - -#include "MessageQueue.h" - -namespace Ti { -namespace Utils { - -/** - @brief Constructor for the message queue class - - @param none - @return none - */ -MessageQueue::MessageQueue() -{ - LOG_FUNCTION_NAME; - - int fds[2] = {-1,-1}; - android::status_t stat; - - stat = pipe(fds); - - if ( 0 > stat ) - { - MSGQ_LOGEB("Error while openning pipe: %s", strerror(stat) ); - this->fd_read = 0; - this->fd_write = 0; - mHasMsg = false; - } - else - { - this->fd_read = fds[0]; - this->fd_write = fds[1]; - - mHasMsg = false; - } - - LOG_FUNCTION_NAME_EXIT; -} - -/** - @brief Destructor for the semaphore class - - @param none - @return none - */ -MessageQueue::~MessageQueue() -{ - LOG_FUNCTION_NAME; - - if(this->fd_read >= 0) - { - close(this->fd_read); - } - - if(this->fd_write >= 0) - { - close(this->fd_write); - } - - LOG_FUNCTION_NAME_EXIT; -} - -/** - @brief Get a message from the queue - - @param msg Message structure to hold the message to be retrieved - @return android::NO_ERROR On success - @return android::BAD_VALUE if the message pointer is NULL - @return android::NO_INIT If the file read descriptor is not set - @return android::UNKNOWN_ERROR if the read operation fromthe file read descriptor fails - */ -android::status_t MessageQueue::get(Message* msg) -{ - LOG_FUNCTION_NAME; - - if(!msg) - { - MSGQ_LOGEA("msg is NULL"); - LOG_FUNCTION_NAME_EXIT; - return android::BAD_VALUE; - } - - if(!this->fd_read) - { - MSGQ_LOGEA("read descriptor not initialized for message queue"); - LOG_FUNCTION_NAME_EXIT; - return android::NO_INIT; - } - - char* p = (char*) msg; - size_t read_bytes = 0; - - while( read_bytes < sizeof(*msg) ) - { - int err = read(this->fd_read, p, sizeof(*msg) - read_bytes); - - if( err < 0 ) - { - MSGQ_LOGEB("read() error: %s", strerror(errno)); - return android::UNKNOWN_ERROR; - } - else - { - read_bytes += err; - } - } - - MSGQ_LOGDB("MQ.get(%d,%p,%p,%p,%p)", msg->command, msg->arg1,msg->arg2,msg->arg3,msg->arg4); - - mHasMsg = false; - - LOG_FUNCTION_NAME_EXIT; - - return 0; -} - -/** - @brief Get the input file descriptor of the message queue - - @param none - @return file read descriptor - */ - -int MessageQueue::getInFd() -{ - return this->fd_read; -} - -/** - @brief Constructor for the message queue class - - @param fd file read descriptor - @return none - */ - -void MessageQueue::setInFd(int fd) -{ - LOG_FUNCTION_NAME; - - if ( -1 != this->fd_read ) - { - close(this->fd_read); - } - - this->fd_read = fd; - - LOG_FUNCTION_NAME_EXIT; -} - -/** - @brief Queue a message - - @param msg Message structure to hold the message to be retrieved - @return android::NO_ERROR On success - @return android::BAD_VALUE if the message pointer is NULL - @return android::NO_INIT If the file write descriptor is not set - @return android::UNKNOWN_ERROR if the write operation fromthe file write descriptor fails - */ - -android::status_t MessageQueue::put(Message* msg) -{ - LOG_FUNCTION_NAME; - - char* p = (char*) msg; - size_t bytes = 0; - - if(!msg) - { - MSGQ_LOGEA("msg is NULL"); - LOG_FUNCTION_NAME_EXIT; - return android::BAD_VALUE; - } - - if(!this->fd_write) - { - MSGQ_LOGEA("write descriptor not initialized for message queue"); - LOG_FUNCTION_NAME_EXIT; - return android::NO_INIT; - } - - - MSGQ_LOGDB("MQ.put(%d,%p,%p,%p,%p)", msg->command, msg->arg1,msg->arg2,msg->arg3,msg->arg4); - - while( bytes < sizeof(msg) ) - { - int err = write(this->fd_write, p, sizeof(*msg) - bytes); - - if( err < 0 ) - { - MSGQ_LOGEB("write() error: %s", strerror(errno)); - LOG_FUNCTION_NAME_EXIT; - return android::UNKNOWN_ERROR; - } - else - { - bytes += err; - } - } - - MSGQ_LOGDA("MessageQueue::put EXIT"); - - LOG_FUNCTION_NAME_EXIT; - return 0; -} - - -/** - @brief Returns if the message queue is empty or not - - @param none - @return true If the queue is empty - @return false If the queue has at least one message - */ -bool MessageQueue::isEmpty() -{ - LOG_FUNCTION_NAME; - - struct pollfd pfd; - - pfd.fd = this->fd_read; - pfd.events = POLLIN; - pfd.revents = 0; - - if(!this->fd_read) - { - MSGQ_LOGEA("read descriptor not initialized for message queue"); - LOG_FUNCTION_NAME_EXIT; - return android::NO_INIT; - } - - - if( -1 == poll(&pfd,1,0) ) - { - MSGQ_LOGEB("poll() error: %s", strerror(errno)); - LOG_FUNCTION_NAME_EXIT; - return false; - } - - if(pfd.revents & POLLIN) - { - mHasMsg = true; - } - else - { - mHasMsg = false; - } - - LOG_FUNCTION_NAME_EXIT; - return !mHasMsg; -} - -void MessageQueue::clear() -{ - LOG_FUNCTION_NAME; - - if(!this->fd_read) - { - MSGQ_LOGEA("read descriptor not initialized for message queue"); - LOG_FUNCTION_NAME_EXIT; - return; - } - - Message msg; - while(!isEmpty()) - { - get(&msg); - } - -} - - -/** - @brief Force whether the message queue has message or not - - @param hasMsg Whether the queue has a message or not - @return none - */ -void MessageQueue::setMsg(bool hasMsg) - { - mHasMsg = hasMsg; - } - - -/** - @briefWait for message in maximum three different queues with a timeout - - @param queue1 First queue. At least this should be set to a valid queue pointer - @param queue2 Second queue. Optional. - @param queue3 Third queue. Optional. - @param timeout The timeout value (in micro secs) to wait for a message in any of the queues - @return android::NO_ERROR On success - @return android::BAD_VALUE If queue1 is NULL - @return android::NO_INIT If the file read descriptor of any of the provided queues is not set - */ -android::status_t MessageQueue::waitForMsg(MessageQueue *queue1, MessageQueue *queue2, MessageQueue *queue3, int timeout) - { - LOG_FUNCTION_NAME; - - int n =1; - struct pollfd pfd[3]; - - if(!queue1) - { - MSGQ_LOGEA("queue1 pointer is NULL"); - LOG_FUNCTION_NAME_EXIT; - return android::BAD_VALUE; - } - - pfd[0].fd = queue1->getInFd(); - if(!pfd[0].fd) - { - MSGQ_LOGEA("read descriptor not initialized for message queue1"); - LOG_FUNCTION_NAME_EXIT; - return android::NO_INIT; - } - pfd[0].events = POLLIN; - pfd[0].revents = 0; - if(queue2) - { - MSGQ_LOGDA("queue2 not-null"); - pfd[1].fd = queue2->getInFd(); - if(!pfd[1].fd) - { - MSGQ_LOGEA("read descriptor not initialized for message queue2"); - LOG_FUNCTION_NAME_EXIT; - return android::NO_INIT; - } - - pfd[1].events = POLLIN; - pfd[1].revents = 0; - n++; - } - - if(queue3) - { - MSGQ_LOGDA("queue3 not-null"); - pfd[2].fd = queue3->getInFd(); - if(!pfd[2].fd) - { - MSGQ_LOGEA("read descriptor not initialized for message queue3"); - LOG_FUNCTION_NAME_EXIT; - return android::NO_INIT; - } - - pfd[2].events = POLLIN; - pfd[2].revents = 0; - n++; - } - - - int ret = poll(pfd, n, timeout); - if(ret==0) - { - LOG_FUNCTION_NAME_EXIT; - return ret; - } - - if(ret<android::NO_ERROR) - { - MSGQ_LOGEB("Message queue returned error %d", ret); - LOG_FUNCTION_NAME_EXIT; - return ret; - } - - if (pfd[0].revents & POLLIN) - { - queue1->setMsg(true); - } - - if(queue2) - { - if (pfd[1].revents & POLLIN) - { - queue2->setMsg(true); - } - } - - if(queue3) - { - if (pfd[2].revents & POLLIN) - { - queue3->setMsg(true); - } - } - - LOG_FUNCTION_NAME_EXIT; - return ret; - } - -} // namespace Utils -} // namespace Ti diff --git a/libtiutils/MessageQueue.h b/libtiutils/MessageQueue.h deleted file mode 100644 index 68943b7..0000000 --- a/libtiutils/MessageQueue.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * 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 __MESSAGEQUEUE_H__ -#define __MESSAGEQUEUE_H__ - -#include "DebugUtils.h" -#include <stdint.h> - -#ifdef MSGQ_DEBUG -# define MSGQ_LOGDA DBGUTILS_LOGDA -# define MSGQ_LOGDB DBGUTILS_LOGDB -#else -# define MSGQ_LOGDA(str) -# define MSGQ_LOGDB(str, ...) -#endif - -#define MSGQ_LOGEA DBGUTILS_LOGEA -#define MSGQ_LOGEB DBGUTILS_LOGEB - -namespace Ti { -namespace Utils { - -///Message type -struct Message -{ - unsigned int command; - void* arg1; - void* arg2; - void* arg3; - void* arg4; - int64_t id; -}; - -///Message queue implementation -class MessageQueue -{ -public: - - MessageQueue(); - ~MessageQueue(); - - ///Get a message from the queue - android::status_t get(Message*); - - ///Get the input file descriptor of the message queue - int getInFd(); - - ///Set the input file descriptor for the message queue - void setInFd(int fd); - - ///Queue a message - android::status_t put(Message*); - - ///Returns if the message queue is empty or not - bool isEmpty(); - - void clear(); - - ///Force whether the message queue has message or not - void setMsg(bool hasMsg=false); - - ///Wait for message in maximum three different queues with a timeout - static int waitForMsg(MessageQueue *queue1, MessageQueue *queue2=0, MessageQueue *queue3=0, int timeout = 0); - - bool hasMsg() - { - return mHasMsg; - } - -private: - int fd_read; - int fd_write; - bool mHasMsg; -}; - -} // namespace Utils -} // namespace Ti - - - - -#endif diff --git a/libtiutils/Semaphore.cpp b/libtiutils/Semaphore.cpp deleted file mode 100644 index 512eee3..0000000 --- a/libtiutils/Semaphore.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * 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. - */ - - - -#include "Semaphore.h" -#include "ErrorUtils.h" -#include <utils/Log.h> -#include <time.h> - -namespace Ti { -namespace Utils { - -/** - @brief Constructor for the semaphore class - - @param none - @return none - */ -Semaphore::Semaphore() -{ - ///Initialize the semaphore to NULL - mSemaphore = NULL; -} - -/** - @brief Destructor of the semaphore class - - @param none - @return none - - */ -Semaphore::~Semaphore() -{ - Release(); -} - -/** - @brief: Releases semaphore - - @param count >=0 - @return NO_ERROR On Success - @return One of the android error codes based on semaphore de-initialization - */ - -status_t Semaphore::Release() -{ - int status = 0; - - ///Destroy only if the semaphore has been created - if(mSemaphore) - { - status = sem_destroy(mSemaphore); - - free(mSemaphore); - - mSemaphore = NULL; - } - - ///Initialize the semaphore and return the status - return ErrorUtils::posixToAndroidError(status); - -} - -/** - @brief Create the semaphore with initial count value - - @param count >=0 - @return NO_ERROR On Success - @return NO_MEMORY If unable to allocate memory for the semaphore - @return BAD_VALUE If an invalid count value is passed (<0) - @return One of the android error codes based on semaphore initialization - */ - -status_t Semaphore::Create(int count) -{ - status_t ret = NO_ERROR; - - ///count cannot be less than zero - if(count<0) - { - return BAD_VALUE; - } - - ret = Release(); - if ( NO_ERROR != ret ) - { - return ret; - } - - ///allocate memory for the semaphore - mSemaphore = (sem_t*)malloc(sizeof(sem_t)) ; - - ///if memory is unavailable, return error - if(!mSemaphore) - { - return NO_MEMORY; - } - - ///Initialize the semaphore and return the status - return ErrorUtils::posixToAndroidError(sem_init(mSemaphore, 0x00, count)); - -} - -/** - @brief Wait operation - - @param none - @return BAD_VALUE if the semaphore is not initialized - @return NO_ERROR On success - @return One of the android error codes based on semaphore wait operation - */ -status_t Semaphore::Wait() -{ - ///semaphore should have been created first - if(!mSemaphore) - { - return BAD_VALUE; - } - - ///Wait and return the status after signalling - return ErrorUtils::posixToAndroidError(sem_wait(mSemaphore)); - - -} - - -/** - @brief Signal operation - - @param none - @return BAD_VALUE if the semaphore is not initialized - @return NO_ERROR On success - @return One of the android error codes based on semaphore signal operation - */ - -status_t Semaphore::Signal() -{ - ///semaphore should have been created first - if(!mSemaphore) - { - return BAD_VALUE; - } - - ///Post to the semaphore - return ErrorUtils::posixToAndroidError(sem_post(mSemaphore)); - -} - -/** - @brief Current semaphore count - - @param none - @return Current count value of the semaphore - */ -int Semaphore::Count() -{ - int val; - - ///semaphore should have been created first - if(!mSemaphore) - { - return BAD_VALUE; - } - - ///get the value of the semaphore - sem_getvalue(mSemaphore, &val); - - return val; -} - -/** - @brief Wait operation with a timeout - - @param timeoutMicroSecs The timeout period in micro seconds - @return BAD_VALUE if the semaphore is not initialized - @return NO_ERROR On success - @return One of the android error codes based on semaphore wait operation - */ - -status_t Semaphore::WaitTimeout(int timeoutMicroSecs) -{ - status_t ret = NO_ERROR; - - struct timespec timeSpec; - struct timeval currentTime; - - ///semaphore should have been created first - if( NULL == mSemaphore) - { - ret = BAD_VALUE; - } - - if ( NO_ERROR == ret ) - { - - ///setup the timeout values - timeout is specified in seconds and nanoseconds - gettimeofday(¤tTime, NULL); - timeSpec.tv_sec = currentTime.tv_sec; - timeSpec.tv_nsec = currentTime.tv_usec * 1000; - timeSpec.tv_sec += ( timeoutMicroSecs / 1000000 ); - timeSpec.tv_nsec += ( timeoutMicroSecs % 1000000) * 1000; - - ///Wait for the timeout or signal and return the result based on whichever event occurred first - ret = sem_timedwait(mSemaphore, &timeSpec); - } - - if ( NO_ERROR != ret ) - { - Signal(); - Create(0); - } - - return ret; -} - - -} // namespace Utils -} // namespace Ti diff --git a/libtiutils/Semaphore.h b/libtiutils/Semaphore.h deleted file mode 100644 index 8d64f3f..0000000 --- a/libtiutils/Semaphore.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * 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. - */ - - - -#include <utils/Errors.h> -#include <semaphore.h> -#include <stdio.h> -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "Status.h" - -namespace Ti { -namespace Utils { - -class Semaphore -{ -public: - - Semaphore(); - ~Semaphore(); - - //Release semaphore - status_t Release(); - - ///Create the semaphore with initial count value - status_t Create(int count=0); - - ///Wait operation - status_t Wait(); - - ///Signal operation - status_t Signal(); - - ///Current semaphore count - int Count(); - - ///Wait operation with a timeout - status_t WaitTimeout(int timeoutMicroSecs); - -private: - sem_t *mSemaphore; - -}; - -} // namespace Utils -} // namespace Ti diff --git a/libtiutils/Status.h b/libtiutils/Status.h deleted file mode 100644 index ded2cec..0000000 --- a/libtiutils/Status.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * 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 TI_UTILS_STATUS_H -#define TI_UTILS_STATUS_H - -#include <utils/Errors.h> - -#include "UtilsCommon.h" - - - - -namespace Ti { - - - - -typedef int status_t; - -#define TI_CAMERA_DEFINE_STATUS_CODE(x) x = android::x, -enum { - TI_CAMERA_DEFINE_STATUS_CODE(OK) - TI_CAMERA_DEFINE_STATUS_CODE(NO_ERROR) - TI_CAMERA_DEFINE_STATUS_CODE(UNKNOWN_ERROR) - TI_CAMERA_DEFINE_STATUS_CODE(NO_MEMORY) - TI_CAMERA_DEFINE_STATUS_CODE(INVALID_OPERATION) - TI_CAMERA_DEFINE_STATUS_CODE(BAD_VALUE) - TI_CAMERA_DEFINE_STATUS_CODE(BAD_TYPE) - TI_CAMERA_DEFINE_STATUS_CODE(NAME_NOT_FOUND) - TI_CAMERA_DEFINE_STATUS_CODE(PERMISSION_DENIED) - TI_CAMERA_DEFINE_STATUS_CODE(NO_INIT) - TI_CAMERA_DEFINE_STATUS_CODE(ALREADY_EXISTS) - TI_CAMERA_DEFINE_STATUS_CODE(DEAD_OBJECT) - TI_CAMERA_DEFINE_STATUS_CODE(FAILED_TRANSACTION) - TI_CAMERA_DEFINE_STATUS_CODE(JPARKS_BROKE_IT) - TI_CAMERA_DEFINE_STATUS_CODE(BAD_INDEX) - TI_CAMERA_DEFINE_STATUS_CODE(NOT_ENOUGH_DATA) - TI_CAMERA_DEFINE_STATUS_CODE(WOULD_BLOCK) - TI_CAMERA_DEFINE_STATUS_CODE(TIMED_OUT) - TI_CAMERA_DEFINE_STATUS_CODE(UNKNOWN_TRANSACTION) - TI_CAMERA_DEFINE_STATUS_CODE(FDS_NOT_ALLOWED) -}; -#undef TI_CAMERA_DEFINE_STATUS_CODE - - - - -} // namespace Ti - - - - -#endif // TI_UTILS_STATUS_H diff --git a/libtiutils/UtilsCommon.h b/libtiutils/UtilsCommon.h deleted file mode 100644 index 8aaeee7..0000000 --- a/libtiutils/UtilsCommon.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) Texas Instruments - http://www.ti.com/ - * - * 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 TI_UTILS_COMMON_H -#define TI_UTILS_COMMON_H - -#include <android/api-level.h> -#include <android/log.h> - - - -namespace Ti { - - - - -// default float point type -typedef float real; - - - - -template <typename T> -int floor(T x); - -template <typename T> -int round(T x); - -template <typename T> -const T & min(const T & a, const T & b); - -template <typename T> -const T & max(const T & a, const T & b); - -template <typename T> -const T & bound(const T & min, const T & x, const T & max); - -template <typename T> -T abs(const T & x); - - - - -template <typename T> -inline int floor(const T x) { - return static_cast<int>(x); -} - -template <typename T> -inline int round(const T x) { - if ( x >= 0 ) { - return floor(x + T(0.5)); - } else { - return floor(x - floor(x - T(1)) + T(0.5)) + floor(x - T(1)); - } -} - -template <typename T> -inline const T & min(const T & a, const T & b) { - return a < b ? a : b; -} - -template <typename T> -inline const T & max(const T & a, const T & b) { - return a < b ? b : a; -} - -template <typename T> -inline const T & bound(const T & min, const T & x, const T & max) { - return x < min ? min : x > max ? max : x; -} - -template <typename T> -inline T abs(const T & x) { - return x >= 0 ? x : -x; -} - - - - -} // namespace Ti - - - - -#endif // TI_UTILS_COMMON_H |