You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/08/02 16:40:14 UTC
svn commit: r1368491 [5/8] - in /incubator/etch/trunk: ./
binding-cpp/runtime/ binding-cpp/runtime/include/common/
binding-cpp/runtime/include/serialization/
binding-cpp/runtime/include/transport/ binding-cpp/runtime/lib/capu/
binding-cpp/runtime/lib/c...
Modified: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Thread.inc
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Thread.inc?rev=1368491&r1=1368490&r2=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Thread.inc (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Thread.inc Thu Aug 2 14:40:08 2012
@@ -1,25 +1,27 @@
-/* $Id$
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you 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.
- */
-
-
-
-#ifdef ARCH_LINUX
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.
+ */
+
+#if defined(OS_LINUX)
#include "Linux/Thread.inc"
-#elif ARCH_WIN32
- #include "Win32/Thread.inc"
-#endif
+#elif defined(OS_WINDOWS)
+ #include "Windows/Thread.inc"
+#elif defined(OS_INTEGRITY)
+ #include "Linux/Thread.inc"
+#elif defined(OS_QNX)
+ #include "Linux/Thread.inc"
+#endif
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Time.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Thread.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Time.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Time.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Thread.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Thread.inc (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Time.inc Thu Aug 2 14:40:08 2012
@@ -17,9 +17,13 @@
*/
-
-#ifdef ARCH_LINUX
- #include "Linux/Thread.inc"
-#elif ARCH_WIN32
- #include "Win32/Thread.inc"
+#if defined(OS_LINUX)
+ #include "Linux/Time.inc"
+#elif defined(OS_WINDOWS)
+ #include "Windows/Time.inc"
+#elif defined(OS_INTEGRITY)
+ #include "Linux/Time.inc"
+#elif defined(OS_QNX)
+ #include "Linux/Time.inc"
#endif
+
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/UdpSocket.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/AtomicOperation.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/UdpSocket.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/UdpSocket.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/AtomicOperation.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/AtomicOperation.inc (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/UdpSocket.inc Thu Aug 2 14:40:08 2012
@@ -16,9 +16,13 @@
* limitations under the License.
*/
-#ifdef ARCH_LINUX
-#include "Linux/AtomicOperation.inc"
-#elif ARCH_WIN32
-#include "Win32/AtomicOperation.inc"
+#if defined(OS_LINUX)
+ #include "Linux/UdpSocket.inc"
+#elif defined(OS_WINDOWS)
+ #include "Windows/UdpSocket.inc"
+#elif defined(OS_INTEGRITY)
+ #include "Linux/UdpSocket.inc"
+#elif defined(OS_QNX)
+ #include "Qnx/UdpSocket.inc"
#endif
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/CondVar.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/CondVar.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/CondVar.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/CondVar.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/CondVar.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/CondVar.inc (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/CondVar.inc Thu Aug 2 14:40:08 2012
@@ -40,7 +40,7 @@ private:
inline CondVar::~CondVar() {
CloseHandle(mSemaphore);
}
-
+
inline status_t CondVar::signal()
{
bool releaseSemaphore = false;
@@ -50,7 +50,7 @@ private:
++mGeneration;
}
mLockWaitCounter.unlock();
- if (releaseSemaphore){
+ if (releaseSemaphore){
ReleaseSemaphore(mSemaphore, 1, NULL);
}
return CAPU_OK;
@@ -64,13 +64,13 @@ private:
++mGeneration;
}
mLockWaitCounter.unlock();
- if (releaseSemaphore){
+ if (releaseSemaphore){
ReleaseSemaphore(mSemaphore, mWaitCounter, NULL);
}
return CAPU_OK;
}
- inline status_t CondVar::wait(Mutex *mutex)
+ inline status_t CondVar::wait(Mutex *mutex, uint32_t millisec)
{
uint32_t myGeneration = mGeneration;
if (mutex == NULL) {
@@ -81,23 +81,38 @@ private:
mLockWaitCounter.unlock();
mutex->unlock();
DWORD waitResult;
- while (true) {
- waitResult = WaitForSingleObject(mSemaphore,INFINITE);
- if (waitResult == WAIT_OBJECT_0) {
- if (myGeneration != mGeneration) {
+ while (true) {
+ if(millisec == 0) {
+ // regular wait
+ waitResult = WaitForSingleObject(mSemaphore, INFINITE);
+ } else {
+ // timed wait
+ waitResult = WaitForSingleObject(mSemaphore, millisec);
+ }
+
+ if (waitResult == WAIT_OBJECT_0) {
+ if (myGeneration != mGeneration) {
+ mLockWaitCounter.lock();
+ --mWaitCounter;
+ mLockWaitCounter.unlock();
+
+ mutex->lock();
+ return CAPU_OK;
+ } else {
+ ReleaseSemaphore(mSemaphore, 1, NULL);
+ }
+ }
+ if (waitResult == WAIT_TIMEOUT) {
mLockWaitCounter.lock();
--mWaitCounter;
mLockWaitCounter.unlock();
- break;
+
+ mutex->lock();
+ return CAPU_ETIMEOUT;
} else {
- ReleaseSemaphore(mSemaphore, 1, NULL);
+ return CAPU_ERROR;
}
- } else {
- return CAPU_ERROR;
- }
}
- mutex->lock();
- return CAPU_OK;
} else {
return CAPU_ERROR;
}
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Debug.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/main.cpp)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Debug.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Debug.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/main.cpp&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/main.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Debug.inc Thu Aug 2 14:40:08 2012
@@ -16,30 +16,24 @@
* limitations under the License.
*/
-#ifdef BUILD_CHECK_MEMORY
-#ifdef ARCH_WIN32
-#include "vld.h"
+#ifdef DEBUG_INC_HEADER
+#include <assert.h>
#endif
+
+#ifdef DEBUG_INC_MEMBER
+public:
+
+
+private:
#endif
-#include <iostream>
-#include "gtest/gtest.h"
+#ifdef DEBUG_INC_IMPL
-GTEST_API_ int main(int argc, char **argv) {
- std::cout << "Running main() from capu-test\n";
-
- bool insideIde = false;
- if(argc > 1) {
- insideIde = true;
- }
-
- testing::InitGoogleTest(&argc, argv);
- int result = RUN_ALL_TESTS();
-
- if(insideIde) {
- printf("press <enter> to exit.\n");
- getchar();
- }
+ inline void Debug::Assert(bool condition)
+{
+ #ifdef _DEBUG
+ assert(condition);
+ #endif
+};
- return result;
-}
+#endif
Added: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Math.inc
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Math.inc?rev=1368491&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Math.inc (added)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Math.inc Thu Aug 2 14:40:08 2012
@@ -0,0 +1,153 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.
+ */
+
+
+#ifdef MATH_INC_HEADER
+#include <cmath>
+#endif
+
+#ifdef MATH_INC_MEMBER
+public:
+static const float_t PI_f;
+static const double_t PI_d;
+#endif
+
+#ifdef MATH_INC_IMPL
+inline float_t Math::Ceil(float_t val) {
+ return ceilf(val);
+}
+
+inline double_t Math::Ceil(double_t val) {
+ return ceil(val);
+}
+
+inline float_t Floor(float_t val)
+{
+ return floorf(val);
+}
+
+inline double_t Floor(double_t val)
+{
+ return floor(val);
+}
+
+
+inline float_t Math::Abs(float_t val) {
+ return fabs(val);
+}
+
+inline double_t Math::Abs(double_t val) {
+ return abs(val);
+}
+
+inline int_t Abs(int_t val)
+{
+ return abs(val);
+}
+
+inline float_t Math::Sqrt(float_t val) {
+ return sqrtf(val);
+}
+
+inline double_t Math::Sqrt(double_t val) {
+ return sqrt(val);
+}
+
+inline float_t Math::Pow2(float_t val) {
+ return val * val;
+}
+
+inline double_t Math::Pow2(double_t val) {
+ return val * val;
+}
+
+inline float_t Math::Cos(float_t val) {
+ return cosf(val);
+}
+
+inline float_t Pow(float_t val, float_t exponent)
+{
+ return powf(val, exponent);
+}
+
+inline double_t Por(double_t val, double_t exponent)
+{
+ return pow(val, exponent);
+}
+
+inline double_t Math::Cos(double_t val) {
+ return cos(val);
+}
+
+inline float_t Math::Sin(float_t val) {
+ return sinf(val);
+}
+
+inline double_t Math::Sin(double_t val) {
+ return sin(val);
+}
+
+inline float_t Math::Tan(float_t val) {
+ return tanf(val);
+}
+
+inline double_t Math::Tan(double_t val) {
+ return tan(val);
+}
+
+inline float_t Math::ArcCos(float_t val) {
+ return acosf(val);
+}
+
+inline double_t Math::ArcCos(double_t val) {
+ return acos(val);
+}
+
+inline float_t Math::ArcSin(float_t val) {
+ return asinf(val);
+}
+
+inline double_t Math::ArcSin(double_t val) {
+ return asin(val);
+}
+
+inline float_t Math::ArcTan(float_t val) {
+ return atanf(val);
+}
+
+inline double_t Math::ArcTan(double_t val) {
+ return atan(val);
+}
+
+inline float_t Math::Rad2Deg(float_t val) {
+ return val * (180.f / PI_f);
+}
+
+inline double_t Math::Rad2Deg(double_t val) {
+ return val * (180.0 / PI_d);
+}
+
+inline float_t Math::Deg2Rad(float_t val) {
+ return val * (PI_f / 180.f);
+}
+
+inline double_t Math::Deg2Rad(double_t val) {
+ return val * (PI_d / 180.0);
+}
+
+#endif
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Memory.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/main.cpp)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Memory.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Memory.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/main.cpp&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/main.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Memory.inc Thu Aug 2 14:40:08 2012
@@ -1,6 +1,6 @@
/* $Id$
-*
* Licensed to the Apache Software Foundation (ASF) under one or more
+*
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version
@@ -16,30 +16,36 @@
* limitations under the License.
*/
-#ifdef BUILD_CHECK_MEMORY
-#ifdef ARCH_WIN32
-#include "vld.h"
+#ifdef MEMORY_INC_HEADER
+#include <memory.h>
+#include "capu/Config.h"
#endif
+
+#ifdef MEMORY_INC_MEMBER
#endif
-#include <iostream>
-#include "gtest/gtest.h"
+#ifdef MEMORY_INC_IMPL
-GTEST_API_ int main(int argc, char **argv) {
- std::cout << "Running main() from capu-test\n";
-
- bool insideIde = false;
- if(argc > 1) {
- insideIde = true;
- }
-
- testing::InitGoogleTest(&argc, argv);
- int result = RUN_ALL_TESTS();
-
- if(insideIde) {
- printf("press <enter> to exit.\n");
- getchar();
- }
+inline
+void Memory::Set(void* dst, int32_t val, uint_t size)
+{
+ memset(dst, val, size);
+}
- return result;
+inline
+void Memory::Copy(void* dst, const void* src, uint_t size)
+{
+ memcpy(dst, src, size);
}
+
+inline
+void Memory::Move(void* dst, const void* src, uint_t size)
+{
+ memmove(dst, src, size);
+}
+
+int32_t Memory::Compare(const void* ptr1, const void* ptr2, uint_t num)
+{
+ return memcmp(ptr1, ptr2, num);
+}
+#endif
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Mutex.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/Mutex.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Mutex.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Mutex.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/Mutex.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
(empty)
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/NumericLimits.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/NumericLimits.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/NumericLimits.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/NumericLimits.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/NumericLimits.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/NumericLimits.inc (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/NumericLimits.inc Thu Aug 2 14:40:08 2012
@@ -18,4 +18,4 @@
#ifdef NUMERIC_LIMITS_INC_HEADER
#include <float.h>
-#endif
+#endif
\ No newline at end of file
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/ServerSocket.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/ServerSocket.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/ServerSocket.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/ServerSocket.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/ServerSocket.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
(empty)
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Socket.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/Socket.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Socket.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Socket.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/Socket.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/Socket.inc (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Socket.inc Thu Aug 2 14:40:08 2012
@@ -104,7 +104,7 @@ inline status_t Socket::receive(unsigned
numBytes = 0;
result = WSAGetLastError();
if (result == WSAETIMEDOUT) {
- return CAPU_TIMEOUT;
+ return CAPU_ETIMEOUT;
}
else{
return CAPU_ERROR;
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/StringUtils.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/StringUtils.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/StringUtils.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/StringUtils.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/StringUtils.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/StringUtils.inc (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/StringUtils.inc Thu Aug 2 14:40:08 2012
@@ -29,28 +29,32 @@ private:
#ifdef STRINGUTILS_INC_IMPL
- inline void StringUtils::Strncpy(char* dst, uint32_t dstSize, const char* src)
+ inline void StringUtils::Strncpy(char* dst, uint_t dstSize, const char* src)
{
strcpy_s(dst, dstSize, src);
}
- inline uint32_t StringUtils::Strlen(const char* str)
+ inline uint_t StringUtils::Strlen(const char* str)
{
return strlen(str);
}
- inline int32_t StringUtils::Strcmp(const char* str1, const char* str2)
+ inline int_t StringUtils::Strcmp(const char* str1, const char* str2)
{
return strcmp(str1, str2);
}
- inline void StringUtils::Vsprintf(char* buffer, size_t bufferSize,const char* format, va_list values)
+ inline void StringUtils::Vsprintf(char* buffer, uint_t bufferSize, const char* format, va_list values)
{
vsprintf_s(buffer, bufferSize, format, values);
}
- inline void StringUtils::Sprintf(char* buffer, uint32_t bufferSize, const char* format, ...)
+ inline int32_t StringUtils::Vscprintf(const char* format, va_list values) {
+ return _vscprintf(format, values);
+ }
+
+ inline void StringUtils::Sprintf(char* buffer, uint_t bufferSize, const char* format, ...)
{
va_list argptr;
va_start(argptr,format);
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Thread.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/Thread.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Thread.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Thread.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/Thread.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/Thread.inc (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Thread.inc Thu Aug 2 14:40:08 2012
@@ -24,39 +24,36 @@ private:
DWORD mThreadId;
HANDLE mThreadHandle;
- template <typename T>
- static DWORD WINAPI run(LPVOID arg);
-
- template <class K>
class ThreadParam
{
public:
- K* object;
+ Runnable* object;
void* param;
};
-#endif
-#ifdef THREAD_INC_IMPL
- template <typename T>
- static DWORD WINAPI Thread::run(LPVOID param)
+ static DWORD WINAPI run(LPVOID arg)
{
- ThreadParam<T>* args= (ThreadParam<T>*) param;
+ ThreadParam* args= (ThreadParam*) arg;
(*args->object)(args->param);
delete args;
return NULL;
}
-template <typename T>
-inline Thread::Thread(T *object,void* args)
-{
+
+#endif
+
+#ifdef THREAD_INC_IMPL
+
+inline Thread::Thread(Runnable *object,void* args)
+{
if (object == NULL)
{
return;
}
- ThreadParam<T> *param = new ThreadParam<T>();
+ ThreadParam *param = new ThreadParam();
param->object=object;
param->param=args;
- mThreadHandle = CreateThread(NULL, 0, Thread::run<T>, param, 0, &mThreadId);
+ mThreadHandle = CreateThread(NULL, 0, Thread::run, param, 0, &mThreadId);
}
inline Thread::~Thread()
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Time.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Socket.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Time.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Time.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Socket.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Socket.inc (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/Time.inc Thu Aug 2 14:40:08 2012
@@ -15,14 +15,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#ifdef TIME_INC_HEADER
+#define _WINSOCKAPI_
+#include <windows.h>
+#endif
-
-
-#ifdef ARCH_LINUX
-#include "Linux/Socket.inc"
-#elif ARCH_WIN32
-#include "Win32/Socket.inc"
+#ifdef TIME_INC_MEMBER
#endif
+#ifdef TIME_INC_IMPL
+inline
+uint32_t Time::GetMilliseconds()
+{
+ LONGLONG res, freq;
+ QueryPerformanceCounter((LARGE_INTEGER*)&res);
+ QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
+ return static_cast<uint32_t>( (LONGLONG)res*1000/(LONGLONG)freq );
+}
+#endif
Added: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/UdpSocket.inc
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/UdpSocket.inc?rev=1368491&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/UdpSocket.inc (added)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows/UdpSocket.inc Thu Aug 2 14:40:08 2012
@@ -0,0 +1,251 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.
+ */
+
+#ifdef UDPSOCKET_INC_HEADER
+#define WIN32_LEAN_AND_MEAN
+// Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
+#pragma comment (lib, "Ws2_32.lib")
+#pragma comment (lib, "Mswsock.lib")
+#pragma comment (lib, "AdvApi32.lib")
+#include <windows.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include "capu/os/StringUtils.h"
+#endif
+
+#ifdef UDPSOCKET_INC_MEMBER
+public:
+private:
+ SOCKET mSocket;
+ WSADATA mWsaData;
+ int32_t mAddressFamily;
+ int32_t mSocketType;
+ int32_t mProtocol;
+ bool_t mIsBound;
+#endif
+
+#ifdef UDPSOCKET_INC_IMPL
+inline UdpSocket::UdpSocket() {
+ //Initialize Winsock
+ int32_t result = WSAStartup(MAKEWORD(2,2), &mWsaData);
+ if (result == 0) {
+ //create the socket which is used to connect the server
+ mAddressFamily = AF_INET;
+ mSocketType = SOCK_DGRAM;
+ mProtocol = IPPROTO_UDP;
+ mSocket = socket(mAddressFamily, mSocketType, mProtocol);
+ mIsBound = false;
+ if (mSocket == INVALID_SOCKET) {
+ WSACleanup();
+ } else {
+ int32_t optVal = 1;
+ setsockopt(mSocket, SOL_SOCKET, SO_REUSEADDR, (char*)&optVal, sizeof(optVal));
+ }
+ } else {
+ mSocket = INVALID_SOCKET;
+ }
+}
+
+inline UdpSocket::~UdpSocket() {
+ close();
+}
+
+inline status_t UdpSocket::bind(uint16_t port, const char *addr) {
+ if (port == 0) {
+ return CAPU_EINVAL;
+ }
+
+ //check if the address is valid
+
+ if (mIsBound) {
+ return CAPU_ERROR;
+ }
+
+ if (mSocket == INVALID_SOCKET)
+ return CAPU_SOCKET_ESOCKET;
+
+ sockaddr_in socketAddr;
+ memset((char*) &socketAddr, 0x00, sizeof(socketAddr));
+ socketAddr.sin_family = AF_INET;
+ if (addr == NULL) {
+ socketAddr.sin_addr.s_addr = INADDR_ANY;
+ } else if (inet_addr(addr) == INADDR_NONE) {
+ return CAPU_SOCKET_EADDR;
+ } else {
+ socketAddr.sin_addr.s_addr = inet_addr(addr);
+ }
+ socketAddr.sin_port = htons(port);
+
+ int32_t result = ::bind(mSocket, (sockaddr*) &socketAddr, sizeof(socketAddr));
+ if (result == SOCKET_ERROR) {
+ return CAPU_SOCKET_EBIND;
+ }
+
+ mIsBound = true;
+ return CAPU_OK;
+}
+
+
+inline status_t UdpSocket::send(unsigned char *buffer, int32_t length, const char* receiverAddr, uint16_t receiverPort) {
+ if ((buffer == NULL) || (length < 0)) {
+ return CAPU_EINVAL;
+ }
+
+ if (mSocket == INVALID_SOCKET) {
+ return CAPU_SOCKET_ESOCKET;
+ }
+
+ struct hostent* serverHost = gethostbyname((const char *) receiverAddr);
+ if (serverHost == NULL) {
+ return CAPU_SOCKET_EADDR;
+ }
+
+ struct sockaddr_in receiverSockAddr;
+ memset((char *) &receiverSockAddr, 0x00, sizeof (receiverSockAddr));
+
+ receiverSockAddr.sin_family = AF_INET;
+ memcpy((char *) &receiverSockAddr.sin_addr.s_addr, (char *) serverHost->h_addr_list[0], serverHost->h_length);
+ receiverSockAddr.sin_port = htons(receiverPort);
+
+ int32_t result = sendto(mSocket,(char*)buffer, length, 0, (sockaddr*) &receiverSockAddr, sizeof(receiverSockAddr));
+ if (result == SOCKET_ERROR) {
+ return CAPU_ERROR;
+ }
+ return CAPU_OK;
+
+}
+
+inline status_t UdpSocket::send(unsigned char *buffer, int32_t length, SocketAddrInfo& receiverAddr) {
+ return send(buffer, length, receiverAddr.addr, receiverAddr.port);
+}
+
+inline status_t UdpSocket::receive(unsigned char *buffer, int32_t length, int32_t &numBytes, SocketAddrInfo* sender) {
+ if ((buffer == NULL) || (length < 0)) {
+ return CAPU_EINVAL;
+ }
+
+ if (mSocket == INVALID_SOCKET) {
+ return CAPU_SOCKET_ESOCKET;
+ }
+
+ sockaddr remoteSocketAddr;
+ int32_t remoteSocketAddrSize = sizeof(remoteSocketAddr);
+
+ int32_t result = recvfrom(mSocket, (char*)buffer, length, 0, &remoteSocketAddr, &remoteSocketAddrSize);
+ if (result == SOCKET_ERROR) {
+ numBytes = 0;
+ result = WSAGetLastError();
+ if (result == WSAETIMEDOUT) {
+ return CAPU_ETIMEOUT;
+ }
+ else{
+ return CAPU_ERROR;
+ }
+ }else{
+ if(sender != 0)
+ {
+ sender->port = ntohs(((sockaddr_in*)&remoteSocketAddr)->sin_port);
+ char* addr = inet_ntoa(((sockaddr_in*)&remoteSocketAddr)->sin_addr);
+ StringUtils::Strncpy(sender->addr, sizeof(sender->addr), addr);
+ }
+ }
+
+ numBytes = result;
+ return CAPU_OK;
+}
+
+inline status_t UdpSocket::close() {
+ int32_t returnValue = CAPU_OK;
+ if (mSocket == INVALID_SOCKET) {
+ returnValue = CAPU_SOCKET_ESOCKET;
+ } else {
+ int32_t result = closesocket(mSocket);
+ if (result != 0) {
+ result = WSAGetLastError();
+ if (result != WSANOTINITIALISED){ //socket has already been closed
+ returnValue = CAPU_SOCKET_ECLOSE;
+ }
+ }
+ }
+ mSocket = INVALID_SOCKET;
+ WSACleanup();
+ return returnValue;
+}
+
+inline status_t UdpSocket::setBufferSize(int32_t bufferSize) {
+ if (bufferSize < 0) {
+ return CAPU_EINVAL;
+ }
+ if (mSocket == INVALID_SOCKET) {
+ return CAPU_SOCKET_ESOCKET;
+ }
+
+ if (setsockopt(mSocket, SOL_SOCKET, SO_RCVBUF, (char*)&bufferSize, sizeof(bufferSize)) == SOCKET_ERROR) {
+ return CAPU_ERROR;
+ }
+
+ return CAPU_OK;
+}
+
+inline status_t UdpSocket::setTimeout(int32_t timeout) {
+ if (mSocket == INVALID_SOCKET)
+ return CAPU_SOCKET_ESOCKET;
+
+ struct timeval soTimeout;
+ soTimeout.tv_sec = timeout;
+ soTimeout.tv_usec = 0;
+
+ if (setsockopt(mSocket, SOL_SOCKET, SO_RCVTIMEO, (char*)&soTimeout, sizeof(soTimeout)) == SOCKET_ERROR) {
+ return CAPU_ERROR;
+ }
+ if (setsockopt(mSocket, SOL_SOCKET, SO_SNDTIMEO, (char*)&soTimeout, sizeof(soTimeout)) == SOCKET_ERROR) {
+ return CAPU_ERROR;
+ }
+
+ return CAPU_OK;
+}
+
+inline status_t UdpSocket::getBufferSize(int32_t& bufferSize) {
+ if (mSocket == INVALID_SOCKET) {
+ return CAPU_SOCKET_ESOCKET;
+ }
+
+ socklen_t len = sizeof (bufferSize);
+ if (getsockopt(mSocket, SOL_SOCKET, SO_RCVBUF, (char*)&bufferSize, &len) == SOCKET_ERROR) {
+ return CAPU_ERROR;
+ }
+
+ return CAPU_OK;
+}
+
+inline status_t UdpSocket::getTimeout(int32_t& timeout) {
+ if (mSocket == INVALID_SOCKET)
+ return CAPU_SOCKET_ESOCKET;
+
+ struct timeval soTimeout;
+ socklen_t len = sizeof(soTimeout);
+
+ if (getsockopt(mSocket, SOL_SOCKET, SO_RCVTIMEO, (char*)&soTimeout, &len) == SOCKET_ERROR) {
+ return CAPU_ERROR;
+ }
+
+ timeout = soTimeout.tv_sec;
+
+ return CAPU_OK;
+}
+#endif
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows_X86_32/AtomicOperation.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/AtomicOperation.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows_X86_32/AtomicOperation.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows_X86_32/AtomicOperation.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/AtomicOperation.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
(empty)
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows_X86_64/AtomicOperation.inc (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/AtomicOperation.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows_X86_64/AtomicOperation.inc?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Windows_X86_64/AtomicOperation.inc&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/Win32/AtomicOperation.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
(empty)
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Appender.h (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/container/Comparator.h)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Appender.h?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Appender.h&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/container/Comparator.h&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/container/Comparator.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Appender.h Thu Aug 2 14:40:08 2012
@@ -16,27 +16,33 @@
* limitations under the License.
*/
-#ifndef __COMPARATOR_H__
-#define __COMPARATOR_H__
-
-#include "capu/Config.h"
+#ifndef __APPENDER_H__
+#define __APPENDER_H__
namespace capu {
- class Comparator {
-
- public:
- template <class T>
- bool_t operator () (const T &x, const T &y) const {
- return x == y;
- }
-
- bool_t operator () (const char* x, const char* y) const {
- return (strcmp(x,y) == 0);
- }
+ class Appender {
+ public:
+
+ /**
+ * open logger appender
+ */
+ virtual status_t open() = 0;
+
+ /**
+ * print trace message to the logger appender.
+ * @param message that will be logged
+ */
+ virtual status_t log(class LoggerMessage* message) = 0;
+
+ /**
+ * close logger appender
+ */
+ virtual status_t close() = 0;
+
+ };
- };
}
-#endif /* COMPARATOR_H */
+#endif /* __APPENDER_H__ */
\ No newline at end of file
Added: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Logger.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Logger.h?rev=1368491&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Logger.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Logger.h Thu Aug 2 14:40:08 2012
@@ -0,0 +1,365 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 __LOGGER_H__
+#define __LOGGER_H__
+
+#include "capu/Error.h"
+#include "capu/Config.h"
+#include "capu/os/StringUtils.h"
+#include <stdarg.h>
+
+#define CAPU_LOG(logger, level, tag, format, ...) logger->log(level, tag, __FILE__, __LINE__, format, ##__VA_ARGS__)
+#define CAPU_LOG_TRACE(logger, tag, format, ...) logger->log(capu::CLL_TRACE, tag, __FILE__, __LINE__, format, ##__VA_ARGS__)
+#define CAPU_LOG_DEBUG(logger, tag, format, ...) logger->log(capu::CLL_DEBUG, tag, __FILE__, __LINE__, format, ##__VA_ARGS__)
+#define CAPU_LOG_INFO(logger, tag, format, ...) logger->log(capu::CLL_INFO, tag, __FILE__, __LINE__, format, ##__VA_ARGS__)
+#define CAPU_LOG_WARN(logger, tag, format, ...) logger->log(capu::CLL_WARN, tag, __FILE__, __LINE__, format, ##__VA_ARGS__)
+#define CAPU_LOG_ERROR(logger, tag, format, ...) logger->log(capu::CLL_ERROR, tag, __FILE__, __LINE__, format, ##__VA_ARGS__)
+
+namespace capu {
+
+ class Appender;
+
+ /**
+ * Logger levels
+ */
+ enum LoggerLevel {
+ CLL_INVALID,
+ CLL_TRACE,
+ CLL_DEBUG,
+ CLL_INFO,
+ CLL_WARN,
+ CLL_ERROR
+ };
+
+
+ class LoggerMessage {
+ public:
+ /**
+ * creats a new LoggerMessage instance
+ */
+ LoggerMessage();
+
+ // id
+ void setId(int32_t id);
+ int32_t getId();
+
+ // timestamp
+ void setTimestamp(int32_t timestamp);
+ int32_t getTimestamp();
+
+ // threadId
+ void setThreadId(const char *threadId);
+ const char* getThreadId();
+
+ // level
+ void setLevel(LoggerLevel level);
+ LoggerLevel getLevel();
+
+ // tag
+ void setTag(const char *tag);
+ const char* getTag();
+
+ // filename
+ void setFile(const char *file);
+ const char* getFile();
+
+ // line
+ void setLine(int32_t line);
+ int32_t getLine();
+
+ // message
+ void setMessage(const char* message);
+ const char* getMessage();
+
+ /**
+ * cleanup current message
+ */
+ ~LoggerMessage();
+
+ private:
+ int32_t mId;
+ int32_t mTimestamp;
+ char *mThreadId;
+ LoggerLevel mLevel;
+ char *mTag;
+ char *mFile;
+ int32_t mLine;
+ char *mMessage;
+ };
+
+ // id
+ inline void LoggerMessage::setId(int32_t id) {
+ mId = id;
+ }
+ inline int32_t LoggerMessage::getId() {
+ return mId;
+ }
+
+ // timestamp
+ inline void LoggerMessage::setTimestamp(int32_t timestamp) {
+ mTimestamp = timestamp;
+ }
+ inline int32_t LoggerMessage::getTimestamp() {
+ return mTimestamp;
+ }
+
+ // threadId
+ inline void LoggerMessage::setThreadId(const char *threadId) {
+ if(threadId != NULL) {
+ if(mThreadId != NULL) {
+ delete mThreadId;
+ mThreadId = NULL;
+ }
+ uint_t length = StringUtils::Strlen(threadId);
+ mThreadId = new char[length + 1];
+ StringUtils::Strncpy(mThreadId, length + 1, threadId);
+ }
+ }
+ inline const char* LoggerMessage::getThreadId() {
+ return mThreadId;
+ }
+
+ // level
+ inline void LoggerMessage::setLevel(LoggerLevel level) {
+ mLevel = level;
+ }
+ inline LoggerLevel LoggerMessage::getLevel() {
+ return mLevel;
+ }
+
+ // tag
+ inline void LoggerMessage::setTag(const char *tag) {
+ if(tag != NULL) {
+ if(mTag != NULL) {
+ delete mTag;
+ mTag = NULL;
+ }
+ uint_t length = StringUtils::Strlen(tag);
+ mTag = new char[length + 1];
+ StringUtils::Strncpy(mTag, length + 1, tag);
+ }
+ }
+ inline const char* LoggerMessage::getTag() {
+ return mTag;
+ }
+
+ // filename
+ inline void LoggerMessage::setFile(const char *file) {
+ if(file != NULL) {
+ if(mFile != NULL) {
+ delete mFile;
+ mFile = NULL;
+ }
+ uint_t length = StringUtils::Strlen(file);
+ mFile = new char[length + 1];
+ StringUtils::Strncpy(mFile, length + 1, file);
+ }
+ }
+ inline const char* LoggerMessage::getFile() {
+ return mFile;
+ }
+
+ // line
+ inline void LoggerMessage::setLine(int32_t line) {
+ mLine = line;
+ }
+ inline int32_t LoggerMessage::getLine() {
+ return mLine;
+ }
+
+ // message
+ inline void LoggerMessage::setMessage(const char* message) {
+ if(message != NULL) {
+ if(mMessage != NULL) {
+ delete mMessage;
+ mMessage = NULL;
+ }
+ uint_t length = StringUtils::Strlen(message);
+ mMessage = new char[length + 1];
+ StringUtils::Strncpy(mMessage, length + 1, message);
+ }
+ }
+ inline const char* LoggerMessage::getMessage() {
+ return mMessage;
+ }
+
+ class Logger {
+ public:
+
+ /**
+ * creats a new Logger
+ * @param id of the logger
+ */
+ Logger(int32_t id = 0);
+
+ /**
+ * destroy logger instance
+ */
+ ~Logger();
+
+ /**
+ * sets an appender for the logger
+ */
+ status_t setAppender(Appender *appender);
+
+ /**
+ * removes the appender identified by name
+ */
+ status_t removeAppender(Appender *appender);
+
+ /**
+ * opens the logger
+ */
+ status_t open();
+
+ /**
+ * print trace message to the logger.
+ * @param tag that will be logged
+ * @param message that will be logged
+ * @param file name of the log call
+ * @param line number of the log call
+ * @param msgFormat of the log message
+ */
+ status_t trace(const char *tag, const char *file, int32_t line,const char *msgFormat, ...);
+
+ /**
+ * print debug message to the logger.
+ * @param tag that will be logged
+ * @param message that will be logged
+ * @param file name of the log call
+ * @param line number of the log call
+ * @param msgFormat of the log message
+ */
+ status_t debug(const char *tag, const char *file, int32_t line,const char *msgFormat, ...);
+
+ /**
+ * print info message to the logger.
+ * @param tag that will be logged
+ * @param message that will be logged
+ * @param file name of the log call
+ * @param line number of the log call
+ * @param msgFormat of the log message
+ */
+ status_t info(const char *tag, const char *file, int32_t line,const char *msgFormat, ...);
+
+ /**
+ * print warn message to the logger.
+ * @param tag that will be logged
+ * @param message that will be logged
+ * @param file name of the log call
+ * @param line number of the log call
+ * @param msgFormat of the log message
+ */
+ status_t warn(const char *tag, const char *file, int32_t line,const char *msgFormat, ...);
+
+ /**
+ * print error message to the logger.
+ * @param tag that will be logged
+ * @param message that will be logged
+ * @param file name of the log call
+ * @param line number of the log call
+ * @param msgFormat of the log message
+ */
+ status_t error(const char *tag, const char *file, int32_t line,const char *msgFormat, ...);
+
+ /**
+ * print log message with given level to the logger.
+ * @param level of the lov message
+ * @param tag that will be logged
+ * @param message that will be logged
+ * @param file name of the log call
+ * @param line number of the log call
+ * @param msgFormat of the log message
+ */
+ status_t log(LoggerLevel level, const char *tag, const char *file, int32_t line,const char *msgFormat, ...);
+
+ /**
+ * close the logger
+ */
+ status_t close();
+
+ private:
+ /**
+ * print log message with given level to the logger.
+ * @param level of the lov message
+ * @param tag that will be logged
+ * @param message that will be logged
+ * @param file name of the log call
+ * @param line number of the log call
+ * @param msgFormat of the log message
+ * @param args variable argument list
+ */
+ status_t vlog(LoggerLevel level, const char *tag, const char *file, int32_t line,const char *msgFormat, va_list args);
+
+ private:
+ int32_t mId;
+ Appender* mAppenders[LOGGER_APPENDER_MAX];
+ bool_t mOpen;
+ };
+
+ inline status_t Logger::trace(const char *tag, const char *file, int32_t line, const char *msgFormat, ...) {
+ va_list args;
+ va_start(args, msgFormat);
+ status_t status = vlog(CLL_TRACE, tag, file, line, msgFormat, args);
+ va_end(args);
+ return status;
+ }
+
+ inline status_t Logger::debug(const char *tag, const char *file, int32_t line,const char *msgFormat, ...) {
+ va_list args;
+ va_start(args, msgFormat);
+ status_t status = vlog(CLL_DEBUG, tag, file, line, msgFormat, args);
+ va_end(args);
+ return status;
+ }
+
+ inline status_t Logger::info(const char *tag, const char *file, int32_t line,const char *msgFormat, ...) {
+ va_list args;
+ va_start(args, msgFormat);
+ status_t status = vlog(CLL_INFO, tag, file, line, msgFormat, args);
+ va_end(args);
+ return status;
+ }
+
+ inline status_t Logger::warn(const char *tag, const char *file, int32_t line,const char *msgFormat, ...) {
+ va_list args;
+ va_start(args, msgFormat);
+ status_t status = vlog(CLL_WARN, tag, file, line, msgFormat, args);
+ return status;
+ }
+
+ inline status_t Logger::error(const char *tag, const char *file, int32_t line,const char *msgFormat, ...) {
+ va_list args;
+ va_start(args, msgFormat);
+ status_t status = vlog(CLL_ERROR, tag, file, line, msgFormat, args);
+ va_end(args);
+ return status;
+ }
+
+ inline status_t Logger::log(LoggerLevel level, const char *tag, const char *file, int32_t line,const char *msgFormat, ...) {
+ va_list args;
+ va_start(args, msgFormat);
+ status_t status = vlog(level, tag, file, line, msgFormat, args);
+ va_end(args);
+ return status;
+ }
+
+}
+
+#endif /* __LOGGER_H__ */
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Runnable.h (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/StringUtils.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Runnable.h?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Runnable.h&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/StringUtils.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/StringUtils.inc (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/Runnable.h Thu Aug 2 14:40:08 2012
@@ -16,10 +16,20 @@
* limitations under the License.
*/
+#ifndef __RUNNABLE_H__
+#define __RUNNABLE_H__
+namespace capu
+{
+ class Runnable
+ {
+ public:
+ virtual ~Runnable() {}
+ /**
+ * Thread Execution Function
+ */
+ virtual void operator()(void* args) = 0;
+ };
+}
-#ifdef ARCH_LINUX
- #include "Linux/StringUtils.inc"
-#elif ARCH_WIN32
- #include "Win32/StringUtils.inc"
-#endif
+#endif /* __RUNNABLE_H__ */
Modified: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/SmartPointer.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/SmartPointer.h?rev=1368491&r1=1368490&r2=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/SmartPointer.h (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/util/SmartPointer.h Thu Aug 2 14:40:08 2012
@@ -1,334 +1,315 @@
-/* $Id$
-*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to you 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 __SMARTPOINTER_H__
-#define __SMARTPOINTER_H__
-
-#include "capu/Config.h"
-#include "capu/os/AtomicOperation.h"
-
-namespace capu {
-
- template<class T>
- class SmartPointer
- {
- public:
- /**
- * Default constructor
- */
- SmartPointer();
-
- /**
- * Constructor
- * @param pointer to object
- */
- SmartPointer(T* ptr);
-
- /**
- * Copy constructor for different, but castable type
- * @param reference to smartPointer
- */
- template<class X> friend class SmartPointer;
- template<class X>
- SmartPointer(const SmartPointer<X>& smartPointer);
-
- /**
- * Copy constructor
- * @param reference to smartPointer
- */
- SmartPointer(const SmartPointer& smartPointer);
-
- /**
- * Deconstructor
- */
- ~SmartPointer();
-
- /**
- * Overload assignment operator to be able to decrement the
- * reference count if another object gets assigned to this smart pointer
- * @param reference to smartPointer
- */
- SmartPointer& operator= (const SmartPointer& smartPointer);
-
- /**
- * Overload assignment operator for castable, but different type
- * @param reference to smartPointer
- */
- template <class X>
- SmartPointer<T>& operator= (const SmartPointer<X>& smartPointer);
-
- /**
- * Overload assignment operator to be able to decrement the
- * reference count if another object gets assigned to this smart pointer
- */
- SmartPointer& operator= (T* ptr);
-
- /**
- * Overload file operator to be able to access the object
- * referenced by the pointer
- */
- T* operator->() const;
-
- /**
- * Overload dereference operator to be able to get the object
- * referenced by the pointer. Use with care!
- */
- T& operator*() const;
-
- /**
- * Returns true if two smart pointer are equal to each other
- * false otherwise
- */
- capu::bool_t operator==(const SmartPointer<T>& x) const;
-
- /**
- * Returns true if two smart pointer aren't equal to each other
- * false otherwise
- */
- capu::bool_t operator!=(const SmartPointer<T>& x) const;
-
- /**
- * Returns the object stored by the smartPointer
- */
- T* get() const;
-
- /**
- * Check if object exists
- * @return true if object exists
- */
- operator bool();
-
- /**
- * Returns the reference counter value.
- * If the object does not exist, 0 ist returned
- * @return reference count
- */
- capu::uint32_t getRefCount();
-
- /**
- * cast a SmartPointer of type X to type T
- * this is a simple C-cast, so there are no type checks
- * @param reference to smartPointer
- */
- template<class X>
- SmartPointer<X> unchecked_cast();
-
- private:
- T* mData;
- capu::uint32_t* mReferenceCount;
-
- void incRefCount();
- void decRefCount();
-
- void freeData();
- };
-
- template<class T>
- inline
- SmartPointer<T>::SmartPointer()
- : mData(0)
- , mReferenceCount(0)
- {
- }
-
- template<class T>
- inline
- SmartPointer<T>::SmartPointer(T* ptr)
- : mData(0)
- , mReferenceCount(0)
- {
- if( mData != ptr)
- {
- mData = ptr;
- mReferenceCount = new capu::uint32_t(0);
- incRefCount();
- }
- }
-
- template<class T>
- template<class X>
- inline
- SmartPointer<T>::SmartPointer(const SmartPointer<X>& smartPointer)
- : mData(smartPointer.mData)
- , mReferenceCount(smartPointer.mReferenceCount)
- {
- incRefCount();
- }
-
- template<class T>
- inline
- SmartPointer<T>::SmartPointer(const SmartPointer<T>& smartPointer)
- : mData(smartPointer.mData)
- , mReferenceCount(smartPointer.mReferenceCount)
- {
- incRefCount();
- }
-
- template<class T>
- inline
- SmartPointer<T>::~SmartPointer()
- {
- decRefCount();
- }
-
- template<class T>
- inline
- SmartPointer<T>& SmartPointer<T>::operator= (const SmartPointer<T>& smartPointer)
- {
- if(this != &smartPointer)
- {
- decRefCount();
-
- mData = smartPointer.mData;
- mReferenceCount = smartPointer.mReferenceCount;
-
- incRefCount();
- }
-
- return *this;
- }
-
- template<class T>
- inline
- SmartPointer<T>& SmartPointer<T>::operator= (T* ptr)
- {
- if( mData != ptr)
- {
- decRefCount();
-
- mData = ptr;
- mReferenceCount = new capu::uint32_t(0);
-
- incRefCount();
- }
- return *this;
- }
-
- template <class T>
- template <class X>
- inline
- SmartPointer<T>& SmartPointer<T>::operator= (const SmartPointer<X>& smartPointer) {
- if (*this != smartPointer) {
- decRefCount();
- mData = smartPointer.mData;
- mReferenceCount = smartPointer.mReferenceCount;
- incRefCount();
- }
- return *this;
- }
-
- template<class T>
- inline
- T* SmartPointer<T>::operator->() const
- {
- return mData;
- }
-
- template<class T>
- inline
- T& SmartPointer<T>::operator*() const
- {
- return *mData;
- }
-
- template<class T>
- capu::bool_t SmartPointer<T>::operator==(const SmartPointer<T>& x) const {
- return ((x.mData == this->mData) && (x.mReferenceCount == this->mReferenceCount));
- }
-
- template<class T>
- capu::bool_t SmartPointer<T>::operator!=(const SmartPointer<T>& x) const {
- return ((x.mData != this->mData) || (x.mReferenceCount != this->mReferenceCount));
- }
-
- template<class T>
- inline
- void SmartPointer<T>::incRefCount()
- {
- if(mReferenceCount)
- {
- capu::AtomicOperation::AtomicInc32(*mReferenceCount);
- }
- }
-
- template<class T>
- inline
- void SmartPointer<T>::decRefCount()
- {
- if(mReferenceCount) {
- capu::AtomicOperation::AtomicDec32(*mReferenceCount);
- if (!(*mReferenceCount)) {
- freeData();
- }
- }
- }
-
- template<class T>
- inline
- void SmartPointer<T>::freeData()
- {
- delete mData;
- delete mReferenceCount;
- mData = 0;
- mReferenceCount = 0;
- }
-
- template<class T>
- inline
- T* SmartPointer<T>::get() const
- {
- return mData;
- }
-
- template<class T>
- inline
- SmartPointer<T>::operator bool()
- {
- return mData != 0;
- }
-
- template<class T>
- inline
- capu::uint32_t SmartPointer<T>::getRefCount()
- {
- if (mReferenceCount != 0)
- return *mReferenceCount;
- else
- return 0;
- }
-
- template<class T>
- template<class X>
- inline
- SmartPointer<X> SmartPointer<T>::unchecked_cast()
- {
- SmartPointer<X> p;
- p.mData = (X*)mData;
- p.mReferenceCount = mReferenceCount;
- incRefCount();
- return p;
- }
-
- template<class X, class T>
- SmartPointer<X> smartpointer_cast(SmartPointer<T>& ptr)
- {
- return ptr.template unchecked_cast<X>();
- }
-}
-
-#endif // __SMARTPOINTER_H__
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 __SMARTPOINTER_H__
+#define __SMARTPOINTER_H__
+
+#include "capu/Config.h"
+#include "capu/os/AtomicOperation.h"
+
+namespace capu {
+
+ template<class T>
+ class SmartPointer {
+ public:
+ /**
+ * Default constructor
+ */
+ SmartPointer();
+
+ /**
+ * Constructor
+ * @param pointer to object
+ */
+ SmartPointer(T* ptr);
+
+ /**
+ * Copy constructor for different, but castable type
+ * @param reference to smartPointer
+ */
+ template<class X> friend class SmartPointer;
+ template<class X>
+ SmartPointer(const SmartPointer<X>& smartPointer);
+
+ /**
+ * Copy constructor
+ * @param reference to smartPointer
+ */
+ SmartPointer(const SmartPointer& smartPointer);
+
+ /**
+ * Deconstructor
+ */
+ ~SmartPointer();
+
+ /**
+ * Overload assignment operator to be able to decrement the
+ * reference count if another object gets assigned to this smart pointer
+ * @param reference to smartPointer
+ */
+ SmartPointer& operator= (const SmartPointer& smartPointer);
+
+ /**
+ * Overload assignment operator for castable, but different type
+ * @param reference to smartPointer
+ */
+ template <class X>
+ SmartPointer<T>& operator= (const SmartPointer<X>& smartPointer);
+
+ /**
+ * Overload assignment operator to be able to decrement the
+ * reference count if another object gets assigned to this smart pointer
+ */
+ SmartPointer& operator= (T* ptr);
+
+ /**
+ * Overload file operator to be able to access the object
+ * referenced by the pointer
+ */
+ T* operator->() const;
+
+ /**
+ * Overload dereference operator to be able to get the object
+ * referenced by the pointer. Use with care!
+ */
+ T& operator*() const;
+
+ /**
+ * Returns true if two smart pointer are equal to each other
+ * false otherwise
+ */
+ capu::bool_t operator==(const SmartPointer<T>& x) const;
+
+ /**
+ * Returns true if two smart pointer aren't equal to each other
+ * false otherwise
+ */
+ capu::bool_t operator!=(const SmartPointer<T>& x) const;
+
+ /**
+ * Returns the object stored by the smartPointer
+ */
+ T* get() const;
+
+ /**
+ * Check if object exists
+ * @return true if object exists
+ */
+ operator bool();
+
+ /**
+ * Returns the reference counter value.
+ * If the object does not exist, 0 ist returned
+ * @return reference count
+ */
+ capu::uint32_t getRefCount();
+
+ /**
+ * cast a SmartPointer of type X to type T
+ * this is a simple C-cast, so there are no type checks
+ * @param reference to smartPointer
+ */
+ template<class X>
+ SmartPointer<X> unchecked_cast();
+
+ private:
+ T* mData;
+ capu::uint32_t* mReferenceCount;
+
+ void incRefCount();
+ void decRefCount();
+
+ void freeData();
+ };
+
+ template<class T>
+ inline
+ SmartPointer<T>::SmartPointer()
+ : mData(0)
+ , mReferenceCount(0) {
+ }
+
+ template<class T>
+ inline
+ SmartPointer<T>::SmartPointer(T* ptr)
+ : mData(0)
+ , mReferenceCount(0) {
+ if (mData != ptr) {
+ mData = ptr;
+ mReferenceCount = new capu::uint32_t(0);
+ incRefCount();
+ }
+ }
+
+ template<class T>
+ template<class X>
+ inline
+ SmartPointer<T>::SmartPointer(const SmartPointer<X>& smartPointer)
+ : mData(static_cast<T*> (smartPointer.mData))
+ , mReferenceCount(smartPointer.mReferenceCount)
+ {
+ incRefCount();
+ }
+
+ template<class T>
+ inline
+ SmartPointer<T>::SmartPointer(const SmartPointer<T>& smartPointer)
+ : mData(smartPointer.mData)
+ , mReferenceCount(smartPointer.mReferenceCount) {
+ incRefCount();
+ }
+
+ template<class T>
+ inline
+ SmartPointer<T>::~SmartPointer() {
+ decRefCount();
+ }
+
+ template<class T>
+ inline
+ SmartPointer<T>& SmartPointer<T>::operator=(const SmartPointer<T>& smartPointer) {
+ if (this != &smartPointer) {
+ decRefCount();
+
+ mData = smartPointer.mData;
+ mReferenceCount = smartPointer.mReferenceCount;
+
+ incRefCount();
+ }
+
+ return *this;
+ }
+
+ template<class T>
+ inline
+ SmartPointer<T>& SmartPointer<T>::operator=(T* ptr) {
+ if (mData != ptr) {
+ decRefCount();
+
+ mData = ptr;
+ mReferenceCount = new capu::uint32_t(0);
+
+ incRefCount();
+ }
+ return *this;
+ }
+
+ template <class T>
+ template <class X>
+ inline
+ SmartPointer<T>& SmartPointer<T>::operator= (const SmartPointer<X>& smartPointer) {
+ if (*this != smartPointer) {
+ decRefCount();
+ mData = static_cast<T*> (smartPointer.mData);
+ mReferenceCount = smartPointer.mReferenceCount;
+ incRefCount();
+ }
+ return *this;
+ }
+
+ template<class T>
+ inline
+ T* SmartPointer<T>::operator->() const {
+ return mData;
+ }
+
+ template<class T>
+ inline
+ T& SmartPointer<T>::operator*() const {
+ return *mData;
+ }
+
+ template<class T>
+ capu::bool_t SmartPointer<T>::operator==(const SmartPointer<T>& x) const {
+ return ((x.mData == this->mData) && (x.mReferenceCount == this->mReferenceCount));
+ }
+
+ template<class T>
+ capu::bool_t SmartPointer<T>::operator!=(const SmartPointer<T>& x) const {
+ return ((x.mData != this->mData) || (x.mReferenceCount != this->mReferenceCount));
+ }
+
+ template<class T>
+ inline
+ void SmartPointer<T>::incRefCount() {
+ if (mReferenceCount) {
+ capu::AtomicOperation::AtomicInc32(*mReferenceCount);
+ }
+ }
+
+ template<class T>
+ inline
+ void SmartPointer<T>::decRefCount() {
+ if (mReferenceCount) {
+ capu::AtomicOperation::AtomicDec32(*mReferenceCount);
+ if (!(*mReferenceCount)) {
+ freeData();
+ }
+ }
+ }
+
+ template<class T>
+ inline
+ void SmartPointer<T>::freeData() {
+ delete mData;
+ delete mReferenceCount;
+ mData = 0;
+ mReferenceCount = 0;
+ }
+
+ template<class T>
+ inline
+ T* SmartPointer<T>::get() const {
+ return mData;
+ }
+
+ template<class T>
+ inline
+ SmartPointer<T>::operator bool() {
+ return mData != 0;
+ }
+
+ template<class T>
+ inline
+ capu::uint32_t SmartPointer<T>::getRefCount() {
+ if (mReferenceCount != 0)
+ return *mReferenceCount;
+ else
+ return 0;
+ }
+
+ template<class T>
+ template<class X>
+ inline
+ SmartPointer<X> SmartPointer<T>::unchecked_cast()
+ {
+ SmartPointer<X> p;
+ p.mData = (X*)mData;
+ p.mReferenceCount = mReferenceCount;
+ incRefCount();
+ return p;
+ }
+
+ template<class X, class T>
+ SmartPointer<X> smartpointer_cast(SmartPointer<T>& ptr)
+ {
+ return ptr.template unchecked_cast<X>();
+ }
+}
+
+#endif // __SMARTPOINTER_H__
Copied: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/src/os/Math.cpp (from r1368489, incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/StringUtils.inc)
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/src/os/Math.cpp?p2=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/src/os/Math.cpp&p1=incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/StringUtils.inc&r1=1368489&r2=1368491&rev=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/include/capu/os/arch/StringUtils.inc (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/src/os/Math.cpp Thu Aug 2 14:40:08 2012
@@ -16,10 +16,12 @@
* limitations under the License.
*/
+#include <capu/os/Math.h>
+#include <capu/Config.h>
+namespace capu
+{
+ const float_t Math::PI_f = 3.1415926535897932384626433832795028841971693993751058209749f;
+ const double_t Math::PI_d = 3.1415926535897932384626433832795028841971693993751058209749;
+}
-#ifdef ARCH_LINUX
- #include "Linux/StringUtils.inc"
-#elif ARCH_WIN32
- #include "Win32/StringUtils.inc"
-#endif
Added: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/src/util/Logger.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/src/util/Logger.cpp?rev=1368491&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/src/util/Logger.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/src/util/Logger.cpp Thu Aug 2 14:40:08 2012
@@ -0,0 +1,139 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 "capu/util/Logger.h"
+#include "capu/util/Appender.h"
+#include "capu/os/Memory.h"
+
+namespace capu {
+
+ //
+ // LoggerMessage
+ //
+
+ LoggerMessage::LoggerMessage()
+ : mId(0)
+ , mTimestamp(0)
+ , mThreadId(NULL)
+ , mLevel(CLL_INVALID)
+ , mTag(NULL)
+ , mFile(NULL)
+ , mLine(0)
+ , mMessage(NULL) {
+ }
+
+ LoggerMessage::~LoggerMessage() {
+ if(mThreadId != NULL) {
+ delete mThreadId;
+ }
+ if(mTag != NULL) {
+ delete mTag;
+ }
+ if(mFile != NULL) {
+ delete mFile;
+ }
+ if(mMessage != NULL) {
+ delete mMessage;
+ }
+ }
+
+ //
+ // Logger
+ //
+
+ Logger::Logger(int32_t id)
+ : mId(id)
+ , mOpen(false) {
+ Memory::Set(mAppenders, 0, sizeof(Appender*) * LOGGER_APPENDER_MAX);
+ }
+
+ Logger::~Logger() {
+ if(mOpen) {
+ close();
+ }
+ }
+
+ status_t Logger::setAppender(Appender* appender) {
+ for(int i = 0; i < LOGGER_APPENDER_MAX; i++) {
+ if(mAppenders[i] == NULL) {
+ mAppenders[i] = appender;
+ return CAPU_OK;
+ }
+ }
+ return CAPU_ERROR;
+ }
+
+ status_t Logger::removeAppender(Appender* appender) {
+ for(int i = 0; i < LOGGER_APPENDER_MAX; i++) {
+ if(mAppenders[i] == appender) {
+ mAppenders[i] = NULL;
+ return CAPU_OK;
+ }
+ }
+ return CAPU_ERROR;
+ }
+
+ status_t Logger::open() {
+ for(int i = 0; i < LOGGER_APPENDER_MAX; i++) {
+ if(mAppenders[i] != NULL) {
+ mAppenders[i]->open();
+ }
+ }
+ mOpen = true;
+ return CAPU_OK;
+ }
+
+ status_t Logger::vlog(LoggerLevel level, const char *tag, const char *file, int32_t line,const char *msgFormat, va_list args) {
+
+ LoggerMessage *msg = new LoggerMessage();
+ msg->setId(mId);
+ msg->setTimestamp(0); // not implemented
+ msg->setThreadId(0); // not implemented
+ msg->setLevel(level);
+ msg->setTag(tag);
+ msg->setFile(file);
+ msg->setLine(line);
+
+ int32_t size = StringUtils::Vscprintf(msgFormat, args);
+ char* buffer = new char[size + 1];
+ StringUtils::Vsprintf(buffer, size + 1, msgFormat, args);
+ msg->setMessage(buffer);
+ delete buffer;
+
+ // log message
+ for(int i = 0; i < LOGGER_APPENDER_MAX; i++) {
+ if(mAppenders[i] != NULL) {
+ mAppenders[i]->log(msg);
+ }
+ }
+ delete msg;
+
+ return CAPU_OK;
+ }
+
+ status_t Logger::close() {
+ for(int i = 0; i < LOGGER_APPENDER_MAX; i++) {
+ if(mAppenders[i] != NULL) {
+ mAppenders[i]->close();
+ }
+ }
+ mOpen = false;
+ return CAPU_OK;
+ }
+
+}
\ No newline at end of file
Added: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/ArrayTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/ArrayTest.cpp?rev=1368491&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/ArrayTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/ArrayTest.cpp Thu Aug 2 14:40:08 2012
@@ -0,0 +1,259 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 <gtest/gtest.h>
+#include "capu/container/Array.h"
+#include "capu/Error.h"
+#include "capu/Config.h"
+
+TEST(Array, Constructor) {
+ capu::Array<capu::uint32_t> emptyArray;
+ EXPECT_EQ(0u, emptyArray.size());
+
+ capu::Array<capu::uint32_t> *myArray = NULL;
+ myArray = new capu::Array<capu::uint32_t>(10);
+ EXPECT_TRUE(myArray != NULL);
+ EXPECT_EQ(10u,myArray->size());
+ delete myArray;
+}
+
+TEST(Array, SetAndGetValues) {
+ capu::Array<capu::uint32_t> myArray(10);
+ myArray.set(5);
+ for (capu::int32_t i = 0; i< 10; i++) {
+ EXPECT_EQ(5u,myArray[i]);
+ }
+
+ EXPECT_EQ(capu::CAPU_OK, myArray.set(3,0,3));
+ EXPECT_EQ(3u,myArray[0]);
+ EXPECT_EQ(3u,myArray[1]);
+ EXPECT_EQ(3u,myArray[2]);
+
+ EXPECT_EQ(capu::CAPU_OK, myArray.set(7,7,3));
+ EXPECT_EQ(7u,myArray[7]);
+ EXPECT_EQ(7u,myArray[8]);
+ EXPECT_EQ(7u,myArray[9]);
+
+ EXPECT_EQ(capu::CAPU_OK, myArray.set(4,4,3));
+ EXPECT_EQ(4u,myArray[4]);
+ EXPECT_EQ(4u,myArray[5]);
+ EXPECT_EQ(4u,myArray[6]);
+
+ capu::Array<capu::uint32_t> myArray2(20);
+ myArray2.set(5);
+ for (capu::int32_t i = 0; i< 20; i++) {
+ EXPECT_EQ(5u,myArray2[i]);
+ }
+
+ EXPECT_EQ(capu::CAPU_OK,myArray2.set(3,0,3));
+ EXPECT_EQ(3u,myArray2[0]);
+ EXPECT_EQ(3u,myArray2[1]);
+ EXPECT_EQ(3u,myArray2[2]);
+
+ EXPECT_EQ(capu::CAPU_OK,myArray2.set(7,17,3));
+ EXPECT_EQ(7u,myArray2[17]);
+ EXPECT_EQ(7u,myArray2[18]);
+ EXPECT_EQ(7u,myArray2[19]);
+
+ EXPECT_EQ(capu::CAPU_OK,myArray2.set(4,5,12));
+ EXPECT_EQ(5u,myArray2[4]);
+ EXPECT_EQ(4u,myArray2[5]);
+ EXPECT_EQ(4u,myArray2[6]);
+ EXPECT_EQ(4u,myArray2[7]);
+ EXPECT_EQ(4u,myArray2[8]);
+ EXPECT_EQ(4u,myArray2[9]);
+ EXPECT_EQ(4u,myArray2[10]);
+ EXPECT_EQ(4u,myArray2[11]);
+ EXPECT_EQ(4u,myArray2[12]);
+ EXPECT_EQ(4u,myArray2[13]);
+ EXPECT_EQ(4u,myArray2[14]);
+ EXPECT_EQ(4u,myArray2[15]);
+ EXPECT_EQ(4u,myArray2[16]);
+ EXPECT_EQ(7u,myArray2[17]);
+
+ myArray2[0] = 1;
+ myArray2[1] = 2;
+
+ EXPECT_EQ(1u,myArray2[0]);
+ EXPECT_EQ(2u,myArray2[1]);
+
+ EXPECT_EQ(capu::CAPU_OK,myArray2.set(4,0,20));
+ EXPECT_EQ(capu::CAPU_ERANGE,myArray2.set(4,0,21));
+ EXPECT_EQ(capu::CAPU_ERANGE,myArray2.set(4,1,20));
+}
+
+TEST(Array, Swap) {
+ capu::Array<capu::uint32_t> myArray(10);
+ myArray.set(5);
+ myArray[3] = 10;
+ myArray[7] = 15;
+ EXPECT_EQ(10u,myArray[3]);
+ EXPECT_EQ(15u,myArray[7]);
+
+ EXPECT_EQ(capu::CAPU_OK,myArray.swap(3,7));
+ EXPECT_EQ(15u,myArray[3]);
+ EXPECT_EQ(10u,myArray[7]);
+
+ EXPECT_EQ(capu::CAPU_ERANGE,myArray.swap(13,17));
+ EXPECT_EQ(capu::CAPU_ERANGE,myArray.swap(3,17));
+ EXPECT_EQ(capu::CAPU_ERANGE,myArray.swap(13,7));
+}
+
+TEST(Array, Move) {
+ capu::Array<capu::uint32_t> myArray(10);
+ myArray.set(5);
+
+ myArray[0] = 10;
+ myArray[1] = 15;
+ myArray[2] = 20;
+
+ EXPECT_EQ(capu::CAPU_OK,myArray.move(0,3,7));
+ EXPECT_EQ(10u,myArray[7]);
+ EXPECT_EQ(15u,myArray[8]);
+ EXPECT_EQ(20u,myArray[9]);
+
+ EXPECT_EQ(capu::CAPU_ERANGE,myArray.move(13,3,7));
+ EXPECT_EQ(capu::CAPU_ERANGE,myArray.move(0,13,7));
+ EXPECT_EQ(capu::CAPU_ERANGE,myArray.move(0,3,13));
+}
+
+TEST(Array, CopyConstructor)
+{
+
+ capu::Array<capu::uint32_t> myArray(10);
+ myArray.set(5);
+
+ capu::Array<capu::uint32_t> myArray2(myArray);
+
+ EXPECT_EQ(5u, myArray2[0]);
+ EXPECT_EQ(5u, myArray2[4]);
+ EXPECT_EQ(5u, myArray2[9]);
+}
+
+TEST(Array, Assignment)
+{
+ capu::Array<capu::uint32_t> myEmptyArray;
+
+ capu::Array<capu::uint32_t> myArray(10);
+ myArray.set(5);
+
+ myEmptyArray = myArray;
+
+ EXPECT_EQ(5u, myEmptyArray[0]);
+ EXPECT_EQ(5u, myEmptyArray[4]);
+ EXPECT_EQ(5u, myEmptyArray[9]);
+
+ capu::Array<capu::uint32_t> myArray2(10);
+ myArray2 = myArray;
+
+ EXPECT_EQ(5u, myArray2[0]);
+ EXPECT_EQ(5u, myArray2[4]);
+ EXPECT_EQ(5u, myArray2[9]);
+}
+
+TEST(Array, CopyMethodNormal)
+{
+ capu::Array<capu::uint32_t> original(5);
+ capu::uint32_t newVals[5];
+
+ // fill with default values
+ for(capu::uint32_t i=0;i<original.size();i++)
+ {
+ original[i] = i;
+ newVals[i] = i+1;
+ }
+
+ capu::status_t status = original.copy(newVals, original.size());
+ EXPECT_EQ(capu::CAPU_OK, status);
+
+ for(capu::uint32_t i=0;i<original.size();i++)
+ {
+ EXPECT_EQ(i+1, original[i]);
+ }
+}
+
+TEST(Array, CopyMethodNormalWithBiggerArray)
+{
+ capu::Array<capu::uint32_t> original(5);
+ capu::uint32_t newVals[50]; // this one's bigger
+
+ // fill with default values
+ for(capu::uint32_t i=0;i<original.size();i++)
+ {
+ original[i] = i;
+ }
+ for(capu::uint32_t i=0;i<50;i++)
+ {
+ newVals[i] = i+1;
+ }
+
+ capu::status_t status = original.copy(newVals, original.size()); // only copy the first 5 values
+ EXPECT_EQ(capu::CAPU_OK, status);
+
+ for(capu::uint32_t i=0;i<original.size();i++)
+ {
+ EXPECT_EQ(i+1, original[i]);
+ }
+}
+
+TEST(Array, CopyMethodInvalidSize)
+{
+ capu::Array<capu::uint32_t> original(5);
+ for(capu::uint32_t i=0;i<original.size();i++)
+ {
+ original[i] = i;
+ }
+ capu::uint32_t newVals[3];
+
+ capu::status_t status = original.copy(newVals, 3); // give invalid size
+ EXPECT_EQ(capu::CAPU_ERANGE, status);
+
+ // no changes in original array
+ for(capu::uint32_t i=0;i<original.size();i++)
+ {
+ EXPECT_EQ(i, original[i]);
+ }
+}
+
+TEST(Array, CopyMethodZeroSizeNormal)
+{
+ capu::Array<capu::uint32_t> original(0);
+ capu::uint32_t newVals[1];
+
+ capu::status_t status = original.copy(newVals, original.size()); // copy with zero, no error expected
+ EXPECT_EQ(capu::CAPU_OK, status);
+}
+
+TEST(Array, CopyMethodZeroSizeInvalidSize)
+{
+ capu::Array<capu::uint32_t> original(0);
+ capu::uint32_t newVals[1];
+
+ capu::status_t status = original.copy(newVals, 1);
+ EXPECT_EQ(capu::CAPU_ERANGE, status);
+}
+
+TEST(Array, SetRawData)
+{
+ capu::Array<capu::uint32_t> array(3u);
+
+ array.setRawData(0);
+
+ EXPECT_EQ(0u, array[0]);
+ EXPECT_EQ(0u, array[1]);
+ EXPECT_EQ(0u, array[2]);
+}
Modified: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/HashSetTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/HashSetTest.cpp?rev=1368491&r1=1368490&r2=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/HashSetTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/HashSetTest.cpp Thu Aug 2 14:40:08 2012
@@ -19,7 +19,7 @@
#include <gtest/gtest.h>
#include "capu/container/HashSet.h"
#include "capu/Error.h"
-#include "capu/capu/Config.h"
+#include "capu/Config.h"
TEST(HashSet, Constructor_Default) {
capu::HashSet<capu::int32_t>* list = new capu::HashSet<capu::int32_t > ();
@@ -144,6 +144,31 @@ TEST(HashSet, remove) {
delete h1;
}
+TEST(HashSet, hasElement) {
+ capu::int32_t value = 5;
+ capu::int32_t value2 = 6;
+ capu::status_t status = capu::CAPU_OK;
+ capu::bool_t isElementinHashSet;
+
+ capu::HashSet<capu::int32_t>* h1 = new capu::HashSet<capu::int32_t > ();
+ // add new keys
+ status = h1->put(value);
+ EXPECT_TRUE(status == capu::CAPU_OK);
+
+ isElementinHashSet = h1->hasElement(value2);
+ EXPECT_TRUE(isElementinHashSet == false);
+
+ //add new value
+ status = h1->put(value2);
+ EXPECT_TRUE(status == capu::CAPU_OK);
+
+ //delete existing value
+ isElementinHashSet = h1->hasElement(value2);
+ EXPECT_TRUE(isElementinHashSet == true);
+
+ delete h1;
+}
+
TEST(HashSetIterator, hasNext) {
capu::int32_t value = 10;
capu::int32_t value2 = 12;
@@ -171,7 +196,7 @@ TEST(HashSetIterator, hasNext) {
delete h1;
}
-TEST(HashSetIterator, NEXT) {
+TEST(HashSetIterator, next) {
capu::int32_t value = 10;
capu::int32_t value2 = 12;
@@ -179,6 +204,7 @@ TEST(HashSetIterator, NEXT) {
capu::HashSet<capu::int32_t>* h1 = new capu::HashSet<capu::int32_t > ();
capu::int32_t check_value = 0;
+ capu::int32_t check_value2 = 0;
//create iterator
capu::HashSet<capu::int32_t>::Iterator it = h1->begin();
@@ -197,9 +223,11 @@ TEST(HashSetIterator, NEXT) {
it = h1->begin();
it.next(&check_value);
- EXPECT_TRUE(check_value == value);
+ EXPECT_TRUE(check_value == value || check_value == value2);
- it.next(&check_value);
- EXPECT_TRUE(check_value == value2);
+ it.next(&check_value2);
+ EXPECT_TRUE(check_value == value || check_value == value2);
+
+ EXPECT_FALSE(check_value == check_value2);
delete h1;
}
Modified: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/HashTableTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/HashTableTest.cpp?rev=1368491&r1=1368490&r2=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/HashTableTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/HashTableTest.cpp Thu Aug 2 14:40:08 2012
@@ -228,8 +228,10 @@ TEST(HashtableIterator, next) {
capu::int32_t key2 = 12;
capu::int32_t value = 5;
+ capu::int32_t value2 = 6;
capu::status_t status = capu::CAPU_OK;
capu::Pair<capu::int32_t, capu::int32_t> pair;
+ capu::Pair<capu::int32_t, capu::int32_t> pair2;
capu::HashTable<capu::int32_t, capu::int32_t>* h1 = new capu::HashTable<capu::int32_t, capu::int32_t > ();
//create iterator
@@ -245,16 +247,18 @@ TEST(HashtableIterator, next) {
EXPECT_TRUE(status == capu::CAPU_OK);
//add new value
- status = h1->put(key2, value);
+ status = h1->put(key2, value2);
EXPECT_TRUE(status == capu::CAPU_OK);
it = h1->begin();
it.next(&pair);
- EXPECT_TRUE(pair.first == key);
- EXPECT_TRUE(pair.second == value);
-
- it.next(&pair);
- EXPECT_TRUE(pair.first == key2);
- EXPECT_TRUE(pair.second == value);
+ //we don't know the order the pairs have been added in the hashtable
+ EXPECT_TRUE((pair.first == key && pair.second == value) || (pair.first == key2 && pair.second == value2));
+
+ it.next(&pair2);
+ EXPECT_TRUE((pair2.first == key && pair2.second == value) || (pair2.first == key2 && pair2.second == value2));
+
+ EXPECT_FALSE(pair == pair2);
+
delete h1;
}
Modified: incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/ListTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/ListTest.cpp?rev=1368491&r1=1368490&r2=1368491&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/ListTest.cpp (original)
+++ incubator/etch/trunk/binding-cpp/runtime/lib/capu/modules/capu/test/container/ListTest.cpp Thu Aug 2 14:40:08 2012
@@ -179,15 +179,10 @@ TEST(List, get) {
TEST(List, size) {
capu::List<capu::int32_t>* list = new capu::List<capu::int32_t > ();
capu::int32_t data1;
- capu::int32_t data2;
- capu::int32_t data3;
- capu::int32_t result;
+ capu::int_t result;
data1 = 32;
- data2 = 43;
- data3 = 56;
-
//size of empty list
result = list->size();
EXPECT_TRUE(result == 0);
@@ -219,14 +214,10 @@ TEST(List, size) {
TEST(List, empty) {
capu::List<capu::int32_t>* list = new capu::List<capu::int32_t > ();
capu::int32_t data1;
- capu::int32_t data2;
- capu::int32_t data3;
capu::bool_t result;
data1 = 32;
- data2 = 43;
- data3 = 56;
//check the empty list
result = list->isEmpty();
@@ -245,7 +236,7 @@ TEST(List, find) {
capu::int32_t data1;
capu::int32_t data2;
capu::int32_t data3;
- capu::int32_t result;
+ capu::int_t result;
data1 = 32;
data2 = 43;
@@ -378,7 +369,7 @@ TEST(ListIterator, next) {
capu::int32_t data2;
capu::int32_t data3;
capu::List<capu::int32_t>::Iterator it = list->begin();
- int cnt = 0;
+ capu::int32_t cnt = 0;
EXPECT_TRUE(it.hasNext() == false);
data1 = 32;
data2 = 43;
@@ -400,7 +391,7 @@ TEST(ListIterator, current){
capu::List<capu::int32_t> list;
capu::int32_t data1 = 0;
capu::List<capu::int32_t>::Iterator it = list.begin();
-
+
EXPECT_TRUE(it.current(&data1) == capu::CAPU_ERANGE);
list.add(1);
it = list.begin();
@@ -491,7 +482,7 @@ TEST(ListIterator, add){
EXPECT_TRUE(list.get(3, &data1) == capu::CAPU_OK);
EXPECT_TRUE(data1 == 3);
-
+
iter.next();
iter.next();
list.add(iter, 5);
@@ -523,3 +514,36 @@ TEST(ListIterator, add){
}
+
+TEST(ListIterator, loopAdd){
+ capu::List<capu::int32_t> list;
+ capu::List<capu::int32_t>::Iterator iter;
+ capu::int32_t data1 = 0;
+
+ list.add(iter, 1);
+
+ iter = list.begin();
+ while(iter.hasNext())
+ {
+ iter.next(&data1);
+ }
+
+ list.add(iter, 2);
+
+ EXPECT_TRUE(list.get(0, &data1) == capu::CAPU_OK);
+ EXPECT_EQ(1, data1);
+ EXPECT_TRUE(list.get(1, &data1) == capu::CAPU_OK);
+ EXPECT_EQ(2, data1);
+
+ list.add(iter, 3);
+ iter = list.begin();
+ capu::int32_t i = 1;
+ while(i <= 3)
+ {
+ EXPECT_TRUE(iter.current(&data1) == capu::CAPU_OK);
+ EXPECT_EQ(i, data1);
+ iter.next();
+ i++;
+ }
+
+}