Added: incubator/activemq/trunk/openwire-cpp/src/util/Endian.cpp
URL:
http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/util/Endian.cpp?rev=377433&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/util/Endian.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/util/Endian.cpp Mon Feb 13
09:43:48 2006
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "util/Endian.hpp"
+
+#if APR_IS_BIGENDIAN
+ // Don't define
+#else
+
+float htonf( const float f )
+{
+ int i = htoni( *(int *)&f ) ;
+ return *(float *)&i ;
+}
+
+float ntohf( const float f )
+{
+ int i = ntohi( *(int *)&f ) ;
+ return *(float *)&i ;
+}
+
+double htond( const double d )
+{
+ long long l = htonl( *(long long *)&d ) ;
+ return *(double *)&l ;
+}
+
+double ntohd( const double d )
+{
+ long long l = ntohl( *(long long *)&d ) ;
+ return *(double *)&l ;
+}
+
+#endif
Propchange: incubator/activemq/trunk/openwire-cpp/src/util/Endian.cpp
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/activemq/trunk/openwire-cpp/src/util/Endian.hpp
URL:
http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/util/Endian.hpp?rev=377433&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/util/Endian.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/util/Endian.hpp Mon Feb 13
09:43:48 2006
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Endian_hpp_
+#define Endian_hpp_
+
+#include <apr.h>
+
+// Use these if the compiler does not support _intXX
+#ifdef NEEDS_INT_DEFINED
+#define _int16 short
+#define _int32 int
+#define _int64 long long
+#endif
+
+// Macros and helpers for endian conversion
+#if APR_IS_BIGENDIAN
+#define htons(x) x
+#define htoni(x) x
+#define htonl(x) x
+#define htonf(x) x
+#define htond(x) x
+#define ntohs(x) x
+#define ntohi(x) x
+#define ntohl(x) x
+#define ntohf(x) x
+#define ntohd(x) x
+#else
+#define htons(x) \
+ ( x << 8 ) & 0xFF00 | \
+ ( x >> 8 ) & 0x00FF
+#define htoni(x) \
+ ( x << 24 ) & 0xFF000000 | \
+ ( x << 8 ) & 0x00FF0000 | \
+ ( x >> 8 ) & 0x0000FF00 | \
+ ( x >> 24 ) & 0x000000FF
+#define htonl(x) \
+ ( x << 56 ) & 0xFF00000000000000LL | \
+ ( x << 40 ) & 0x00FF000000000000LL | \
+ ( x << 24 ) & 0x0000FF0000000000LL | \
+ ( x << 8 ) & 0x000000FF00000000LL | \
+ ( x >> 8 ) & 0x00000000FF000000LL | \
+ ( x >> 24 ) & 0x0000000000FF0000LL | \
+ ( x >> 40 ) & 0x000000000000FF00LL | \
+ ( x >> 56 ) & 0x00000000000000FFLL
+#define ntohs htons
+#define ntohi htoni
+#define ntohl htonl
+
+extern float htonf( const float f ) ;
+extern float ntohf( const float f ) ;
+extern double htond( const double d ) ;
+extern double ntohd( const double d ) ;
+
+#endif
+
+#endif /*Endian_hpp_*/
\ No newline at end of file
Propchange: incubator/activemq/trunk/openwire-cpp/src/util/Endian.hpp
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/activemq/trunk/openwire-cpp/src/util/Guid.cpp
URL:
http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/util/Guid.cpp?rev=377433&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/util/Guid.cpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/util/Guid.cpp Mon Feb 13 09:43:48
2006
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "util/guid.hpp"
+
+using namespace apache::activemq::client::util;
+
+/*
+ *
+ */
+Guid::Guid()
+{
+ // no-op
+}
+
+/*
+ *
+ */
+Guid::~Guid()
+{
+ // no-op
+}
+
+/*
+ * Creates a new UUID string.
+ */
+unsigned char* Guid::getGuid()
+{
+ unsigned char* buffer = new unsigned char[16] ;
+
+#if defined(WIN32) || defined(__CYGWIN__)
+ GUID guid = GUID_NULL ;
+
+ // Create GUID
+ CoCreateGuid(&guid) ;
+ if( guid == GUID_NULL )
+ {
+ // TODO: exception
+ //cerr << "Failed to create an UUID" << endl ;
+ return NULL ;
+ }
+ // Store GUID in internal buffer
+ memcpy(buffer, &guid, 16) ;
+
+#else
+ uuid_t uuid ;
+
+ // Create UUID
+ uuid_generate(uuid) ;
+
+ // Store UUID in internal buffer
+ memcpy(buffer, uuid, 16) ;
+#endif
+
+ return buffer ;
+}
+
+/*
+ *
+ */
+p<string> Guid::getGuidString()
+{
+ unsigned char* buffer = NULL ;
+ char* result = NULL ;
+ p<string> guidStr ;
+
+ buffer = getGuid() ;
+ result = new char[36] ;
+
+ // Format into a string
+ sprintf(result,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\0",
+ buffer[0], buffer[1], buffer[2], buffer[3],
+ buffer[4], buffer[5], buffer[6], buffer[7],
+ buffer[8], buffer[9], buffer[10], buffer[11],
+ buffer[12], buffer[13], buffer[14], buffer[15]) ;
+
+ guidStr = new string(result) ;
+
+ // Clean up
+ delete result ;
+ delete buffer ;
+
+ return guidStr ;
+}
Propchange: incubator/activemq/trunk/openwire-cpp/src/util/Guid.cpp
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/activemq/trunk/openwire-cpp/src/util/Guid.hpp
URL:
http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/util/Guid.hpp?rev=377433&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/util/Guid.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/util/Guid.hpp Mon Feb 13 09:43:48
2006
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef Guid_hpp_
+#define Guid_hpp_
+
+#include <string>
+#include <util/ifr/p>
+
+#if (defined(__unix__) || defined(unix)) && !defined(USG)
+#include <sys/param.h>
+#endif
+#include <stdio.h>
+#include <assert.h>
+#if defined(WIN32) || defined(__CYGWIN__)
+#include <objbase.h>
+#elif defined MACOSX
+#include "uuid.h"
+#else
+#include <uuid/uuid.h>
+#endif
+
+namespace apache
+{
+ namespace activemq
+ {
+ namespace client
+ {
+ namespace util
+ {
+ using namespace std ;
+ using namespace ifr ;
+
+/*
+ * Helper class that generates global unique identifiers.
+ */
+class Guid
+{
+private:
+ Guid() ;
+
+public:
+ ~Guid() ;
+
+ static unsigned char* getGuid() ;
+ static p<string> getGuidString() ;
+} ;
+
+/* namespace */
+ }
+ }
+ }
+}
+
+#endif /*Guid_hpp_*/
Propchange: incubator/activemq/trunk/openwire-cpp/src/util/Guid.hpp
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/activemq/trunk/openwire-cpp/src/util/SimpleMutex.hpp
URL:
http://svn.apache.org/viewcvs/incubator/activemq/trunk/openwire-cpp/src/util/SimpleMutex.hpp?rev=377433&view=auto
==============================================================================
--- incubator/activemq/trunk/openwire-cpp/src/util/SimpleMutex.hpp (added)
+++ incubator/activemq/trunk/openwire-cpp/src/util/SimpleMutex.hpp Mon Feb 13
09:43:48 2006
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2006 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef SIMPLE_MUTEX_HPP
+#define SIMPLE_MUTEX_HPP
+
+#if (defined(__unix__) || defined(unix) || defined(MACOSX)) && !defined(USG)
+#define unix
+#include <pthread.h>
+#endif
+#if defined(WIN32) || defined(__CYGWIN__)
+#if ( !defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0400)
+#pragma message "Unsupported platform, Windows NT 4.0 or later required"
+#endif
+#include <windows.h>
+#endif
+#include <assert.h>
+
+namespace apache
+{
+ namespace activemq
+ {
+ namespace client
+ {
+ namespace util
+ {
+
+/*
+ *
+ */
+class SimpleMutex
+{
+private:
+#ifdef unix
+ pthread_mutex_t mutex ;
+#else
+ CRITICAL_SECTION mutex ;
+#endif
+
+public:
+ SimpleMutex() ;
+ virtual ~SimpleMutex() ;
+
+ bool trylock() ;
+ void lock() ;
+ void unlock() ;
+} ;
+
+// Optimize all methods via inline code
+
+inline SimpleMutex::SimpleMutex()
+{
+#ifdef unix
+ pthread_mutexattr_t attr ;
+ pthread_mutexattr_init(&attr) ;
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) ;
+ pthread_mutex_init(&mutex, &attr) ;
+ pthread_mutexattr_destroy(&attr) ;
+#else
+ InitializeCriticalSection(&mutex) ;
+#endif
+}
+
+inline SimpleMutex::~SimpleMutex()
+{
+#ifdef unix
+ pthread_mutex_destroy(&mutex) ;
+#else
+ DeleteCriticalSection(&mutex) ;
+#endif
+}
+
+inline bool SimpleMutex::trylock()
+{
+#ifdef unix
+ int try_l = pthread_mutex_trylock(&mutex) ;
+ if (try_l == 0)
+ return true;
+ else
+ return false ;
+#else
+ return (TryEnterCriticalSection(&mutex) != 0) ;
+#endif
+}
+
+inline void SimpleMutex::lock()
+{
+#ifdef unix
+ pthread_mutex_lock(&mutex) ;
+#else
+ EnterCriticalSection(&mutex) ;
+#endif
+}
+
+inline void SimpleMutex::unlock()
+{
+#ifdef unix
+ pthread_mutex_unlock(&mutex) ;
+#else
+ LeaveCriticalSection(&mutex) ;
+#endif
+}
+
+/* namespace */
+ }
+ }
+ }
+}
+
+#endif /*SIMPLE_MUTEX_HPP*/
Propchange: incubator/activemq/trunk/openwire-cpp/src/util/SimpleMutex.hpp
------------------------------------------------------------------------------
svn:executable = *