Return-Path: Delivered-To: apmail-geronimo-activemq-commits-archive@www.apache.org Received: (qmail 16544 invoked from network); 13 Feb 2006 17:44:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 13 Feb 2006 17:44:41 -0000 Received: (qmail 5343 invoked by uid 500); 13 Feb 2006 17:44:41 -0000 Delivered-To: apmail-geronimo-activemq-commits-archive@geronimo.apache.org Received: (qmail 5308 invoked by uid 500); 13 Feb 2006 17:44:41 -0000 Mailing-List: contact activemq-commits-help@geronimo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: activemq-dev@geronimo.apache.org Delivered-To: mailing list activemq-commits@geronimo.apache.org Received: (qmail 5294 invoked by uid 99); 13 Feb 2006 17:44:40 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Feb 2006 09:44:40 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 13 Feb 2006 09:44:37 -0800 Received: (qmail 16481 invoked by uid 65534); 13 Feb 2006 17:44:16 -0000 Message-ID: <20060213174416.16475.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r377433 [4/4] - in /incubator/activemq/trunk/openwire-cpp: ./ src/ src/command/ src/io/ src/marshal/ src/transport/ src/util/ src/util/ifr/ src/util/ifr/v1/ Date: Mon, 13 Feb 2006 17:43:55 -0000 To: activemq-commits@geronimo.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.0.6 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 + +// 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 Guid::getGuidString() +{ + unsigned char* buffer = NULL ; + char* result = NULL ; + p 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 +#include + +#if (defined(__unix__) || defined(unix)) && !defined(USG) +#include +#endif +#include +#include +#if defined(WIN32) || defined(__CYGWIN__) +#include +#elif defined MACOSX +#include "uuid.h" +#else +#include +#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 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 +#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 +#endif +#include + +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 = *