summaryrefslogtreecommitdiff
path: root/libtiutils
diff options
context:
space:
mode:
authorJason Simmons <jsimmons@google.com>2012-10-17 15:06:16 -0700
committerJason Simmons <jsimmons@google.com>2012-10-23 15:10:22 -0700
commitf7a4d11e9f710e2cd0592310ac1baecccb85f1d1 (patch)
tree55b575622a421530ab6f86fa43ff3e15c2b82771 /libtiutils
parentc4e8e253c404231b74eb318bdb21d7898766f1af (diff)
downloadomap4-aah-f7a4d11e9f710e2cd0592310ac1baecccb85f1d1.tar.gz
Snapshot of TI's camera HAL development with adjustments to build in our tree
The head of TI's hardware/ti/omap4xxx/camera repository at the time of the snapshot was: commit 4447eaef6dc757aecab869054460ae87848e575e Author: Vladimir Petrov <vppetrov@mm-sol.com> Date: Thu Aug 16 19:13:03 2012 +0300 CameraHal: Add support to release tap in/outs Change-Id: Ia6bfefb427fe171067eddcab6d896683ff2d149f
Diffstat (limited to 'libtiutils')
-rw-r--r--libtiutils/Android.mk28
-rw-r--r--libtiutils/DebugUtils.cpp96
-rw-r--r--libtiutils/DebugUtils.h385
-rw-r--r--libtiutils/ErrorUtils.cpp9
-rw-r--r--libtiutils/ErrorUtils.h8
-rw-r--r--libtiutils/MessageQueue.cpp8
-rw-r--r--libtiutils/MessageQueue.h33
-rw-r--r--libtiutils/Semaphore.cpp8
-rw-r--r--libtiutils/Semaphore.h8
-rw-r--r--libtiutils/Status.h67
-rw-r--r--libtiutils/UtilsCommon.h99
11 files changed, 694 insertions, 55 deletions
diff --git a/libtiutils/Android.mk b/libtiutils/Android.mk
index e15eba9..ba6aab1 100644
--- a/libtiutils/Android.mk
+++ b/libtiutils/Android.mk
@@ -7,10 +7,11 @@ include $(CLEAR_VARS)
LOCAL_PRELINK_MODULE := false
LOCAL_SRC_FILES:= \
+ DebugUtils.cpp \
MessageQueue.cpp \
Semaphore.cpp \
ErrorUtils.cpp
-
+
LOCAL_SHARED_LIBRARIES:= \
libdl \
libui \
@@ -19,13 +20,26 @@ LOCAL_SHARED_LIBRARIES:= \
libcutils
LOCAL_C_INCLUDES += \
- bionic/libc/include \
- hardware/ti/omap4xxx/domx/omx_core/inc \
- hardware/ti/omap4xxx/domx/mm_osal/inc
-
-LOCAL_CFLAGS += -fno-short-enums
+ frameworks/native/include
+
+LOCAL_C_INCLUDES += \
+ bionic/libc/include
+
+LOCAL_C_INCLUDES += \
+ $(HARDWARE_TI_OMAP4_BASE)/domx/omx_core/inc \
+ $(HARDWARE_TI_OMAP4_BASE)/domx/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
-# LOCAL_CFLAGS +=
+ifdef TI_UTILS_MESSAGE_QUEUE_DEBUG_FUNCTION_NAMES
+ # Enable function enter/exit logging
+ LOCAL_CFLAGS += -DTI_UTILS_FUNCTION_LOGGER_ENABLE
+endif
LOCAL_MODULE:= libtiutils
LOCAL_MODULE_TAGS:= optional
diff --git a/libtiutils/DebugUtils.cpp b/libtiutils/DebugUtils.cpp
new file mode 100644
index 0000000..60ad0c8
--- /dev/null
+++ b/libtiutils/DebugUtils.cpp
@@ -0,0 +1,96 @@
+/*
+ * 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
index f421252..a05ba8d 100644
--- a/libtiutils/DebugUtils.h
+++ b/libtiutils/DebugUtils.h
@@ -14,23 +14,384 @@
* limitations under the License.
*/
-
-
#ifndef DEBUG_UTILS_H
#define DEBUG_UTILS_H
-///Defines for debug statements - Macro LOG_TAG needs to be defined in the respective files
-#define DBGUTILS_LOGVA(str) ALOGV("%s:%d %s - " str,__FILE__, __LINE__,__FUNCTION__);
-#define DBGUTILS_LOGVB(str,...) ALOGV("%s:%d %s - " str,__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__);
-#define DBGUTILS_LOGDA(str) ALOGD("%s:%d %s - " str,__FILE__, __LINE__,__FUNCTION__);
-#define DBGUTILS_LOGDB(str, ...) ALOGD("%s:%d %s - " str,__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__);
-#define DBGUTILS_LOGEA(str) ALOGE("%s:%d %s - " str,__FILE__, __LINE__, __FUNCTION__);
-#define DBGUTILS_LOGEB(str, ...) ALOGE("%s:%d %s - " str,__FILE__, __LINE__,__FUNCTION__, __VA_ARGS__);
-#define LOG_FUNCTION_NAME ALOGV("%d: %s() ENTER", __LINE__, __FUNCTION__);
-#define LOG_FUNCTION_NAME_EXIT ALOGV("%d: %s() EXIT", __LINE__, __FUNCTION__);
+#include <android/log.h>
+#include <utils/threads.h>
+#include <utils/Vector.h>
-#endif //DEBUG_UTILS_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
index df0e51c..e30fcfd 100644
--- a/libtiutils/ErrorUtils.cpp
+++ b/libtiutils/ErrorUtils.cpp
@@ -17,7 +17,8 @@
#include "ErrorUtils.h"
-namespace android {
+namespace Ti {
+namespace Utils {
/**
@brief Method to convert from POSIX to Android errors
@@ -135,7 +136,5 @@ status_t ErrorUtils::omxToAndroidError(OMX_ERRORTYPE error)
}
-};
-
-
-
+} // namespace Utils
+} // namespace Ti
diff --git a/libtiutils/ErrorUtils.h b/libtiutils/ErrorUtils.h
index 204ec97..c6c23a2 100644
--- a/libtiutils/ErrorUtils.h
+++ b/libtiutils/ErrorUtils.h
@@ -23,6 +23,8 @@
///Header file where all the OMX error codes are defined
#include "OMX_Core.h"
+#include "Status.h"
+
extern "C"
{
@@ -30,7 +32,8 @@ extern "C"
#include "timm_osal_error.h"
};
-namespace android {
+namespace Ti {
+namespace Utils {
///Generic class with static methods to convert any standard error type to Android error type
class ErrorUtils
@@ -47,6 +50,7 @@ public:
};
-};
+} // namespace Utils
+} // namespace Ti
#endif /// ERROR_UTILS_H
diff --git a/libtiutils/MessageQueue.cpp b/libtiutils/MessageQueue.cpp
index e3647d4..13b1d53 100644
--- a/libtiutils/MessageQueue.cpp
+++ b/libtiutils/MessageQueue.cpp
@@ -29,7 +29,8 @@
#include "MessageQueue.h"
-namespace TIUTILS {
+namespace Ti {
+namespace Utils {
/**
@brief Constructor for the message queue class
@@ -278,6 +279,8 @@ bool MessageQueue::isEmpty()
void MessageQueue::clear()
{
+ LOG_FUNCTION_NAME;
+
if(!this->fd_read)
{
MSGQ_LOGEA("read descriptor not initialized for message queue");
@@ -412,4 +415,5 @@ android::status_t MessageQueue::waitForMsg(MessageQueue *queue1, MessageQueue *q
return ret;
}
-};
+} // namespace Utils
+} // namespace Ti
diff --git a/libtiutils/MessageQueue.h b/libtiutils/MessageQueue.h
index 6d05201..68943b7 100644
--- a/libtiutils/MessageQueue.h
+++ b/libtiutils/MessageQueue.h
@@ -22,32 +22,19 @@
#include "DebugUtils.h"
#include <stdint.h>
-///Uncomment this macro to debug the message queue implementation
-//#define DEBUG_LOG
-
-///Camera HAL Logging Functions
-#ifndef DEBUG_LOG
-
-#define MSGQ_LOGDA(str)
-#define MSGQ_LOGDB(str, ...)
-
-#undef LOG_FUNCTION_NAME
-#undef LOG_FUNCTION_NAME_EXIT
-#define LOG_FUNCTION_NAME
-#define LOG_FUNCTION_NAME_EXIT
-
+#ifdef MSGQ_DEBUG
+# define MSGQ_LOGDA DBGUTILS_LOGDA
+# define MSGQ_LOGDB DBGUTILS_LOGDB
#else
-
-#define MSGQ_LOGDA DBGUTILS_LOGDA
-#define MSGQ_LOGDB DBGUTILS_LOGDB
-
+# define MSGQ_LOGDA(str)
+# define MSGQ_LOGDB(str, ...)
#endif
#define MSGQ_LOGEA DBGUTILS_LOGEA
#define MSGQ_LOGEB DBGUTILS_LOGEB
-
-namespace TIUTILS {
+namespace Ti {
+namespace Utils {
///Message type
struct Message
@@ -102,6 +89,10 @@ private:
bool mHasMsg;
};
-};
+} // namespace Utils
+} // namespace Ti
+
+
+
#endif
diff --git a/libtiutils/Semaphore.cpp b/libtiutils/Semaphore.cpp
index 37f3a89..512eee3 100644
--- a/libtiutils/Semaphore.cpp
+++ b/libtiutils/Semaphore.cpp
@@ -21,7 +21,8 @@
#include <utils/Log.h>
#include <time.h>
-namespace android {
+namespace Ti {
+namespace Utils {
/**
@brief Constructor for the semaphore class
@@ -227,6 +228,5 @@ status_t Semaphore::WaitTimeout(int timeoutMicroSecs)
}
-};
-
-
+} // namespace Utils
+} // namespace Ti
diff --git a/libtiutils/Semaphore.h b/libtiutils/Semaphore.h
index 6990848..8d64f3f 100644
--- a/libtiutils/Semaphore.h
+++ b/libtiutils/Semaphore.h
@@ -24,7 +24,10 @@
#include <string.h>
#include <unistd.h>
-namespace android {
+#include "Status.h"
+
+namespace Ti {
+namespace Utils {
class Semaphore
{
@@ -56,4 +59,5 @@ private:
};
-};
+} // namespace Utils
+} // namespace Ti
diff --git a/libtiutils/Status.h b/libtiutils/Status.h
new file mode 100644
index 0000000..ded2cec
--- /dev/null
+++ b/libtiutils/Status.h
@@ -0,0 +1,67 @@
+/*
+ * 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
new file mode 100644
index 0000000..8aaeee7
--- /dev/null
+++ b/libtiutils/UtilsCommon.h
@@ -0,0 +1,99 @@
+/*
+ * 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