summaryrefslogtreecommitdiffstats
path: root/include/utils
diff options
context:
space:
mode:
Diffstat (limited to 'include/utils')
-rw-r--r--include/utils/Flattenable.h72
-rw-r--r--include/utils/KeyedVector.h26
-rw-r--r--include/utils/Log.h38
-rw-r--r--include/utils/SortedVector.h21
-rw-r--r--include/utils/SystemClock.h1
-rw-r--r--include/utils/Timers.h5
-rw-r--r--include/utils/Trace.h3
-rw-r--r--include/utils/Vector.h25
-rw-r--r--include/utils/VectorImpl.h20
-rw-r--r--include/utils/misc.h40
10 files changed, 166 insertions, 85 deletions
diff --git a/include/utils/Flattenable.h b/include/utils/Flattenable.h
index 852be3b..e40d289 100644
--- a/include/utils/Flattenable.h
+++ b/include/utils/Flattenable.h
@@ -24,6 +24,11 @@
namespace android {
+/*
+ * The Flattenable interface allows an object to serialize itself out
+ * to a byte-buffer and an array of file descriptors.
+ */
+
class Flattenable
{
public:
@@ -56,6 +61,73 @@ protected:
};
+/*
+ * LightFlattenable is a protocol allowing object to serialize themselves out
+ * to a byte-buffer.
+ *
+ * LightFlattenable objects must implement this protocol.
+ *
+ * LightFlattenable doesn't require the object to be virtual.
+ */
+template <typename T>
+class LightFlattenable {
+public:
+ // returns whether this object always flatten into the same size.
+ // for efficiency, this should always be inline.
+ inline bool isFixedSize() const;
+
+ // returns size in bytes of the flattened object. must be a constant.
+ inline size_t getSize() const;
+
+ // flattens the object into buffer.
+ inline status_t flatten(void* buffer) const;
+
+ // unflattens the object from buffer of given size.
+ inline status_t unflatten(void const* buffer, size_t size);
+};
+
+template <typename T>
+inline bool LightFlattenable<T>::isFixedSize() const {
+ return static_cast<T const*>(this)->T::isFixedSize();
+}
+template <typename T>
+inline size_t LightFlattenable<T>::getSize() const {
+ return static_cast<T const*>(this)->T::getSize();
+}
+template <typename T>
+inline status_t LightFlattenable<T>::flatten(void* buffer) const {
+ return static_cast<T const*>(this)->T::flatten(buffer);
+}
+template <typename T>
+inline status_t LightFlattenable<T>::unflatten(void const* buffer, size_t size) {
+ return static_cast<T*>(this)->T::unflatten(buffer, size);
+}
+
+/*
+ * LightFlattenablePod is an implementation of the LightFlattenable protocol
+ * for POD (plain-old-data) objects.
+ */
+template <typename T>
+class LightFlattenablePod : public LightFlattenable<T> {
+public:
+ inline bool isFixedSize() const {
+ return true;
+ }
+
+ inline size_t getSize() const {
+ return sizeof(T);
+ }
+ inline status_t flatten(void* buffer) const {
+ *reinterpret_cast<T*>(buffer) = *static_cast<T const*>(this);
+ return NO_ERROR;
+ }
+ inline status_t unflatten(void const* buffer, size_t) {
+ *static_cast<T*>(this) = *reinterpret_cast<T const*>(buffer);
+ return NO_ERROR;
+ }
+};
+
+
}; // namespace android
diff --git a/include/utils/KeyedVector.h b/include/utils/KeyedVector.h
index 20575ee..c4faae0 100644
--- a/include/utils/KeyedVector.h
+++ b/include/utils/KeyedVector.h
@@ -21,6 +21,8 @@
#include <stdint.h>
#include <sys/types.h>
+#include <cutils/log.h>
+
#include <utils/SortedVector.h>
#include <utils/TypeHelpers.h>
#include <utils/Errors.h>
@@ -50,13 +52,16 @@ public:
//! returns number of items in the vector
inline size_t size() const { return mVector.size(); }
- //! returns wether or not the vector is empty
+ //! returns whether or not the vector is empty
inline bool isEmpty() const { return mVector.isEmpty(); }
//! returns how many items can be stored without reallocating the backing store
inline size_t capacity() const { return mVector.capacity(); }
- //! setst the capacity. capacity can never be reduced less than size()
+ //! sets the capacity. capacity can never be reduced less than size()
inline ssize_t setCapacity(size_t size) { return mVector.setCapacity(size); }
-
+
+ // returns true if the arguments is known to be identical to this vector
+ inline bool isIdenticalTo(const KeyedVector& rhs) const;
+
/*!
* accessors
*/
@@ -64,6 +69,7 @@ public:
const VALUE& valueAt(size_t index) const;
const KEY& keyAt(size_t index) const;
ssize_t indexOfKey(const KEY& key) const;
+ const VALUE& operator[] (size_t index) const;
/*!
* modifying the array
@@ -123,6 +129,11 @@ KeyedVector<KEY,VALUE>::KeyedVector()
}
template<typename KEY, typename VALUE> inline
+bool KeyedVector<KEY,VALUE>::isIdenticalTo(const KeyedVector<KEY,VALUE>& rhs) const {
+ return mVector.array() == rhs.mVector.array();
+}
+
+template<typename KEY, typename VALUE> inline
ssize_t KeyedVector<KEY,VALUE>::indexOfKey(const KEY& key) const {
return mVector.indexOf( key_value_pair_t<KEY,VALUE>(key) );
}
@@ -130,7 +141,7 @@ ssize_t KeyedVector<KEY,VALUE>::indexOfKey(const KEY& key) const {
template<typename KEY, typename VALUE> inline
const VALUE& KeyedVector<KEY,VALUE>::valueFor(const KEY& key) const {
ssize_t i = this->indexOfKey(key);
- assert(i>=0);
+ LOG_ALWAYS_FATAL_IF(i<0, "%s: key not found", __PRETTY_FUNCTION__);
return mVector.itemAt(i).value;
}
@@ -140,6 +151,11 @@ const VALUE& KeyedVector<KEY,VALUE>::valueAt(size_t index) const {
}
template<typename KEY, typename VALUE> inline
+const VALUE& KeyedVector<KEY,VALUE>::operator[] (size_t index) const {
+ return valueAt(index);
+}
+
+template<typename KEY, typename VALUE> inline
const KEY& KeyedVector<KEY,VALUE>::keyAt(size_t index) const {
return mVector.itemAt(index).key;
}
@@ -147,7 +163,7 @@ const KEY& KeyedVector<KEY,VALUE>::keyAt(size_t index) const {
template<typename KEY, typename VALUE> inline
VALUE& KeyedVector<KEY,VALUE>::editValueFor(const KEY& key) {
ssize_t i = this->indexOfKey(key);
- assert(i>=0);
+ LOG_ALWAYS_FATAL_IF(i<0, "%s: key not found", __PRETTY_FUNCTION__);
return mVector.editItemAt(i).value;
}
diff --git a/include/utils/Log.h b/include/utils/Log.h
index 3c6cc8b..98c441c 100644
--- a/include/utils/Log.h
+++ b/include/utils/Log.h
@@ -29,5 +29,43 @@
#define _LIBS_UTILS_LOG_H
#include <cutils/log.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+
+namespace android {
+
+/*
+ * A very simple utility that yells in the log when an operation takes too long.
+ */
+class LogIfSlow {
+public:
+ LogIfSlow(const char* tag, android_LogPriority priority,
+ int timeoutMillis, const char* message);
+ ~LogIfSlow();
+
+private:
+ const char* const mTag;
+ const android_LogPriority mPriority;
+ const int mTimeoutMillis;
+ const char* const mMessage;
+ const int64_t mStart;
+};
+
+/*
+ * Writes the specified debug log message if this block takes longer than the
+ * specified number of milliseconds to run. Includes the time actually taken.
+ *
+ * {
+ * ALOGD_IF_SLOW(50, "Excessive delay doing something.");
+ * doSomething();
+ * }
+ */
+#define ALOGD_IF_SLOW(timeoutMillis, message) \
+ LogIfSlow _logIfSlow(LOG_TAG, ANDROID_LOG_DEBUG, timeoutMillis, message);
+
+} // namespace android
+
+#endif // __cplusplus
#endif // _LIBS_UTILS_LOG_H
diff --git a/include/utils/SortedVector.h b/include/utils/SortedVector.h
index 2445525..fd1cb82 100644
--- a/include/utils/SortedVector.h
+++ b/include/utils/SortedVector.h
@@ -21,6 +21,8 @@
#include <stdint.h>
#include <sys/types.h>
+#include <cutils/log.h>
+
#include <utils/Vector.h>
#include <utils/VectorImpl.h>
#include <utils/TypeHelpers.h>
@@ -61,11 +63,11 @@ public:
//! returns number of items in the vector
inline size_t size() const { return VectorImpl::size(); }
- //! returns wether or not the vector is empty
+ //! returns whether or not the vector is empty
inline bool isEmpty() const { return VectorImpl::isEmpty(); }
//! returns how many items can be stored without reallocating the backing store
inline size_t capacity() const { return VectorImpl::capacity(); }
- //! setst the capacity. capacity can never be reduced less than size()
+ //! sets the capacity. capacity can never be reduced less than size()
inline ssize_t setCapacity(size_t size) { return VectorImpl::setCapacity(size); }
/*!
@@ -76,7 +78,7 @@ public:
inline const TYPE* array() const;
//! read-write C-style access. BE VERY CAREFUL when modifying the array
- //! you ust keep it sorted! You usually don't use this function.
+ //! you must keep it sorted! You usually don't use this function.
TYPE* editArray();
//! finds the index of an item
@@ -100,7 +102,7 @@ public:
const TYPE& mirrorItemAt(ssize_t index) const;
/*!
- * modifing the array
+ * modifying the array
*/
//! add an item in the right place (and replace the one that is there)
@@ -186,7 +188,9 @@ TYPE* SortedVector<TYPE>::editArray() {
template<class TYPE> inline
const TYPE& SortedVector<TYPE>::operator[](size_t index) const {
- assert( index<size() );
+ LOG_FATAL_IF(index>=size(),
+ "%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
+ int(index), int(size()));
return *(array() + index);
}
@@ -197,8 +201,11 @@ const TYPE& SortedVector<TYPE>::itemAt(size_t index) const {
template<class TYPE> inline
const TYPE& SortedVector<TYPE>::mirrorItemAt(ssize_t index) const {
- assert( (index>0 ? index : -index)<size() );
- return *(array() + ((index<0) ? (size()-index) : index));
+ const size_t i = index>0 ? index : -index;
+ LOG_FATAL_IF(index>=size(),
+ "%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
+ int(index), int(size()));
+ return *(array() + i);
}
template<class TYPE> inline
diff --git a/include/utils/SystemClock.h b/include/utils/SystemClock.h
index 7c319be..d75264c 100644
--- a/include/utils/SystemClock.h
+++ b/include/utils/SystemClock.h
@@ -25,6 +25,7 @@ namespace android {
int setCurrentTimeMillis(int64_t millis);
int64_t uptimeMillis();
int64_t elapsedRealtime();
+int64_t elapsedRealtimeNano();
}; // namespace android
diff --git a/include/utils/Timers.h b/include/utils/Timers.h
index 8b4d322..92f66c9 100644
--- a/include/utils/Timers.h
+++ b/include/utils/Timers.h
@@ -78,9 +78,10 @@ enum {
SYSTEM_TIME_REALTIME = 0, // system-wide realtime clock
SYSTEM_TIME_MONOTONIC = 1, // monotonic time since unspecified starting point
SYSTEM_TIME_PROCESS = 2, // high-resolution per-process clock
- SYSTEM_TIME_THREAD = 3 // high-resolution per-thread clock
+ SYSTEM_TIME_THREAD = 3, // high-resolution per-thread clock
+ SYSTEM_TIME_BOOTTIME = 4 // same as SYSTEM_TIME_MONOTONIC, but including CPU suspend time
};
-
+
// return the system-time according to the specified clock
#ifdef __cplusplus
nsecs_t systemTime(int clock = SYSTEM_TIME_MONOTONIC);
diff --git a/include/utils/Trace.h b/include/utils/Trace.h
index 4219206..e5cc7ec 100644
--- a/include/utils/Trace.h
+++ b/include/utils/Trace.h
@@ -51,7 +51,8 @@
#define ATRACE_TAG_SYNC_MANAGER (1<<7)
#define ATRACE_TAG_AUDIO (1<<8)
#define ATRACE_TAG_VIDEO (1<<9)
-#define ATRACE_TAG_LAST ATRACE_TAG_VIDEO
+#define ATRACE_TAG_CAMERA (1<<10)
+#define ATRACE_TAG_LAST ATRACE_TAG_CAMERA
#define ATRACE_TAG_VALID_MASK ((ATRACE_TAG_LAST - 1) | ATRACE_TAG_LAST)
diff --git a/include/utils/Vector.h b/include/utils/Vector.h
index e39a5b7..506acae 100644
--- a/include/utils/Vector.h
+++ b/include/utils/Vector.h
@@ -21,7 +21,8 @@
#include <stdint.h>
#include <sys/types.h>
-#include <utils/Log.h>
+#include <cutils/log.h>
+
#include <utils/VectorImpl.h>
#include <utils/TypeHelpers.h>
@@ -72,11 +73,11 @@ public:
//! returns number of items in the vector
inline size_t size() const { return VectorImpl::size(); }
- //! returns wether or not the vector is empty
+ //! returns whether or not the vector is empty
inline bool isEmpty() const { return VectorImpl::isEmpty(); }
//! returns how many items can be stored without reallocating the backing store
inline size_t capacity() const { return VectorImpl::capacity(); }
- //! setst the capacity. capacity can never be reduced less than size()
+ //! sets the capacity. capacity can never be reduced less than size()
inline ssize_t setCapacity(size_t size) { return VectorImpl::setCapacity(size); }
/*!
@@ -102,12 +103,12 @@ public:
const TYPE& mirrorItemAt(ssize_t index) const;
/*!
- * modifing the array
+ * modifying the array
*/
//! copy-on write support, grants write access to an item
TYPE& editItemAt(size_t index);
- //! grants right acces to the top of the stack (last element)
+ //! grants right access to the top of the stack (last element)
TYPE& editTop();
/*!
@@ -271,8 +272,9 @@ TYPE* Vector<TYPE>::editArray() {
template<class TYPE> inline
const TYPE& Vector<TYPE>::operator[](size_t index) const {
- LOG_FATAL_IF( index>=size(),
- "itemAt: index %d is past size %d", (int)index, (int)size() );
+ LOG_FATAL_IF(index>=size(),
+ "%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
+ int(index), int(size()));
return *(array() + index);
}
@@ -283,10 +285,11 @@ const TYPE& Vector<TYPE>::itemAt(size_t index) const {
template<class TYPE> inline
const TYPE& Vector<TYPE>::mirrorItemAt(ssize_t index) const {
- LOG_FATAL_IF( (index>0 ? index : -index)>=size(),
- "mirrorItemAt: index %d is past size %d",
- (int)index, (int)size() );
- return *(array() + ((index<0) ? (size()-index) : index));
+ const size_t i = index>0 ? index : -index;
+ LOG_FATAL_IF(index>=size(),
+ "%s: index=%u out of range (%u)", __PRETTY_FUNCTION__,
+ int(index), int(size()));
+ return *(array() + i);
}
template<class TYPE> inline
diff --git a/include/utils/VectorImpl.h b/include/utils/VectorImpl.h
index c4ec2ff..b1224c6 100644
--- a/include/utils/VectorImpl.h
+++ b/include/utils/VectorImpl.h
@@ -104,16 +104,6 @@ protected:
virtual void do_splat(void* dest, const void* item, size_t num) const = 0;
virtual void do_move_forward(void* dest, const void* from, size_t num) const = 0;
virtual void do_move_backward(void* dest, const void* from, size_t num) const = 0;
-
- // take care of FBC...
- virtual void reservedVectorImpl1();
- virtual void reservedVectorImpl2();
- virtual void reservedVectorImpl3();
- virtual void reservedVectorImpl4();
- virtual void reservedVectorImpl5();
- virtual void reservedVectorImpl6();
- virtual void reservedVectorImpl7();
- virtual void reservedVectorImpl8();
private:
void* _grow(size_t where, size_t amount);
@@ -165,16 +155,6 @@ public:
protected:
virtual int do_compare(const void* lhs, const void* rhs) const = 0;
- // take care of FBC...
- virtual void reservedSortedVectorImpl1();
- virtual void reservedSortedVectorImpl2();
- virtual void reservedSortedVectorImpl3();
- virtual void reservedSortedVectorImpl4();
- virtual void reservedSortedVectorImpl5();
- virtual void reservedSortedVectorImpl6();
- virtual void reservedSortedVectorImpl7();
- virtual void reservedSortedVectorImpl8();
-
private:
ssize_t _indexOrderOf(const void* item, size_t* order = 0) const;
diff --git a/include/utils/misc.h b/include/utils/misc.h
index d7d5bc1..f1aa432 100644
--- a/include/utils/misc.h
+++ b/include/utils/misc.h
@@ -23,41 +23,12 @@
#include <sys/time.h>
#include <utils/Endian.h>
-namespace android {
-
/* get #of elements in a static array */
#ifndef NELEM
# define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
#endif
-/*
- * Make a copy of the string, using "new[]" instead of "malloc". Free the
- * string with delete[].
- *
- * Returns NULL if "str" is NULL.
- */
-char* strdupNew(const char* str);
-
-/*
- * Concatenate an argument vector into a single string. If argc is >= 0
- * it will be used; if it's < 0 then the last element in the arg vector
- * must be NULL.
- *
- * This inserts a space between each argument.
- *
- * This does not automatically add double quotes around arguments with
- * spaces in them. This practice is necessary for Win32, because Win32's
- * CreateProcess call is stupid.
- *
- * The caller should delete[] the returned string.
- */
-char* concatArgv(int argc, const char* const argv[]);
-
-/*
- * Count up the number of arguments in "argv". The count does not include
- * the final NULL entry.
- */
-int countArgv(const char* const argv[]);
+namespace android {
/*
* Some utility functions for working with files. These could be made
@@ -79,15 +50,6 @@ FileType getFileType(const char* fileName);
/* get the file's modification date; returns -1 w/errno set on failure */
time_t getFileModDate(const char* fileName);
-/*
- * Round up to the nearest power of 2. Handy for hash tables.
- */
-unsigned int roundUpPower2(unsigned int val);
-
-void strreverse(char* begin, char* end);
-void k_itoa(int value, char* str, int base);
-char* itoa(int val, int base);
-
typedef void (*sysprop_change_callback)(void);
void add_sysprop_change_callback(sysprop_change_callback cb, int priority);
void report_sysprop_change();