Author: tabish
Date: Tue Apr 24 15:41:45 2007
New Revision: 532121
URL: http://svn.apache.org/viewvc?view=rev&rev=532121
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103
Building Decaf lib
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Boolean.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Character.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Integer.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Long.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Math.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Number.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Runnable.h
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Boolean.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Boolean.h?view=auto&rev=532121
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Boolean.h
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Boolean.h Tue
Apr 24 15:41:45 2007
@@ -0,0 +1,61 @@
+/*
+ * 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 _DECAF_LANG_BOOLEAN_H_
+#define _DECAF_LANG_BOOLEAN_H_
+
+#include <decaf/lang/Number.h>
+
+namespace decaf{
+namespace lang{
+
+ class Boolean : public Number
+ {
+ public:
+
+ Boolean() {}
+ virtual ~Boolean() {}
+
+ /**
+ * Parses the String passed and extracts an bool.
+ * @param String to parse
+ * @return bool value
+ */
+ static bool parseBoolean( const std::string& value ){
+ bool ret = 0;
+ std::istringstream istream(value);
+ istream.clear();
+ istream >> std::boolalpha >> ret;
+ return ret;
+ }
+
+ /**
+ * Converts the bool to a String representation
+ * @param bool to convert
+ * @return string representation
+ */
+ static std::string toString( bool value ){
+ std::ostringstream ostream;
+ ostream << std::boolalpha << value;
+ return ostream.str();
+ }
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_BOOLEAN_H_*/
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Character.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Character.h?view=auto&rev=532121
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Character.h
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Character.h
Tue Apr 24 15:41:45 2007
@@ -0,0 +1,89 @@
+/*
+ * 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 _DECAF_LANG_CHARACTER_H_
+#define _DECAF_LANG_CHARACTER_H_
+
+namespace decaf{
+namespace lang{
+
+ class Character{
+
+ public:
+
+ /**
+ * Indicates whether or not the given character is considered
+ * whitespace.
+ */
+ static bool isWhitespace( char c ){
+ switch ( c )
+ {
+ case '\n':
+ case '\t':
+ case '\r':
+ case '\f':
+ case ' ':
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Indicates whether or not the given character is
+ * a digit.
+ */
+ static bool isDigit( char c ){
+ return c >= '0' && c <= '9';
+ }
+
+ /**
+ * Indicates whether or not the given character is
+ * a lower case character.
+ */
+ static bool isLowerCase( char c ){
+ return c >= 'a' && c <= 'z';
+ }
+
+ /**
+ * Indicates whether or not the given character is
+ * a upper case character.
+ */
+ static bool isUpperCase( char c ){
+ return c >= 'A' && c <= 'Z';
+ }
+
+ /**
+ * Indicates whether or not the given character is
+ * a letter.
+ */
+ static bool isLetter( char c ){
+ return isUpperCase(c) || isLowerCase(c);
+ }
+
+ /**
+ * Indicates whether or not the given character is
+ * either a letter or a digit.
+ */
+ static bool isLetterOrDigit( char c ){
+ return isLetter(c) || isDigit(c);
+ }
+ };
+
+}}
+
+#endif /*_DECAF_LANG_CHARACTER_H_*/
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Integer.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Integer.h?view=auto&rev=532121
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Integer.h
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Integer.h Tue
Apr 24 15:41:45 2007
@@ -0,0 +1,61 @@
+/*
+ * 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 _DECAF_LANG_INTEGER_H_
+#define _DECAF_LANG_INTEGER_H_
+
+#include <decaf/lang/Number.h>
+
+namespace decaf{
+namespace lang{
+
+ class Integer : public Number
+ {
+ public:
+
+ Integer() {}
+ virtual ~Integer() {}
+
+ /**
+ * Parses the String passed and extracts an int.
+ * @param String to parse
+ * @return int value
+ */
+ static int parseInt( const std::string& value ){
+ int ret = 0;
+ std::istringstream istream(value);
+ istream.clear();
+ istream >> ret;
+ return ret;
+ }
+
+ /**
+ * Converts the int to a String representation
+ * @param int to convert
+ * @return string representation
+ */
+ static std::string toString( int value ){
+ std::ostringstream ostream;
+ ostream << value;
+ return ostream.str();
+ }
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_INTEGER_H_*/
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Long.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Long.h?view=auto&rev=532121
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Long.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Long.h Tue Apr
24 15:41:45 2007
@@ -0,0 +1,59 @@
+/*
+ * 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 _DECAF_LANG_LONG_H_
+#define _DECAF_LANG_LONG_H_
+
+#include <decaf/lang/Number.h>
+
+namespace decaf{
+namespace lang{
+
+ class Long : public Number{
+ public:
+
+ Long() {}
+ virtual ~Long() {}
+
+ /**
+ * Parses the String passed and extracts an long.
+ * @param String to parse
+ * @return long value
+ */
+ static long long parseLong( const std::string& value ){
+ long long ret = 0;
+ std::istringstream istream(value);
+ istream.clear();
+ istream >> ret;
+ return ret;
+ }
+
+ /**
+ * Converts the long to a String representation
+ * @param long to convert
+ * @return string representation
+ */
+ static std::string toString( long long value ){
+ std::ostringstream ostream;
+ ostream << value;
+ return ostream.str();
+ }
+ };
+
+}}
+
+#endif /*_DECAF_LANG_LONG_H_*/
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Math.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Math.h?view=auto&rev=532121
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Math.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Math.h Tue Apr
24 15:41:45 2007
@@ -0,0 +1,97 @@
+/**
+ * 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 _DECAF_LANG_MATH_H_
+#define _DECAF_LANG_MATH_H_
+
+#undef min
+#undef max
+
+namespace decaf{
+namespace lang{
+
+ /**
+ * The class <code>Math</code> contains methods for performing basic
+ * numeric operations such as the elementary exponential, logarithm,
+ * square root, and trigonometric functions.
+ */
+ class Math
+ {
+ public:
+
+ Math();
+ virtual ~Math();
+
+ public:
+
+ /**
+ * Returns the smaller of two <code>short</code> values. That is,
+ * the result the argument closer to the value of
+ * <code>Short::MIN_VALUE</code>. If the arguments have the same
+ * value, the result is that same value.
+ * @param a - an argument.
+ * @param b - another argument.
+ * @return the smaller of <code>a</code> and <code>b</code>.
+ */
+ static short min( short a, short b ) {
+ return ( a <= b ? a : b );
+ }
+
+ /**
+ * Returns the smaller of two <code>int</code> values. That is,
+ * the result the argument closer to the value of
+ * <code>Integer::MIN_VALUE</code>. If the arguments have the same
+ * value, the result is that same value.
+ * @param a - an argument.
+ * @param b - another argument.
+ * @return the smaller of <code>a</code> and <code>b</code>.
+ */
+ static int min( int a, int b ) {
+ return ( a <= b ? a : b );
+ }
+
+ /**
+ * Returns the larger of two <code>short</code> values. That is,
+ * the result the argument closer to the value of
+ * <code>Short::MAX_VALUE</code>. If the arguments have the same
+ * value, the result is that same value.
+ * @param a - an argument.
+ * @param b - another argument.
+ * @return the larger of <code>a</code> and <code>b</code>.
+ */
+ static short max( short a, short b ) {
+ return ( a >= b ? a : b );
+ }
+
+ /**
+ * Returns the larger of two <code>int</code> values. That is,
+ * the result the argument closer to the value of
+ * <code>Integer::MAX_VALUE</code>. If the arguments have the same
+ * value, the result is that same value.
+ * @param a - an argument.
+ * @param b - another argument.
+ * @return the larger of <code>a</code> and <code>b</code>.
+ */
+ static int max( int a, int b ) {
+ return ( a >= b ? a : b );
+ }
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_MATH_H_*/
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Number.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Number.h?view=auto&rev=532121
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Number.h
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Number.h Tue
Apr 24 15:41:45 2007
@@ -0,0 +1,42 @@
+/*
+ * 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 _DECAF_LANG_NUMBER_H_
+#define _DECAF_LANG_NUMBER_H_
+
+#include <sstream>
+
+namespace decaf{
+namespace lang{
+
+ /**
+ * The abstract class Number is the superclass of classes Byte, Double,
+ * Float, Integer, Long, and Short.
+ *
+ * Subclasses of Number must provide methods to convert the represented
+ * numeric value to byte, double, float, int, long, and short.
+ */
+ class Number {
+ public:
+
+ virtual ~Number() {}
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_NUMBER_H_*/
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Runnable.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Runnable.h?view=auto&rev=532121
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Runnable.h
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Runnable.h Tue
Apr 24 15:41:45 2007
@@ -0,0 +1,41 @@
+/*
+ * 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 _DECAF_LANG_RUNNABLE_H_
+#define _DECAF_LANG_RUNNABLE_H_
+
+namespace decaf{
+namespace lang{
+
+ /**
+ * Interface for a runnable object - defines a task
+ * that can be run by a thread.
+ */
+ class Runnable{
+ public:
+
+ virtual ~Runnable(){}
+
+ /**
+ * Run method - called by the Thread class in the context
+ * of the thread.
+ */
+ virtual void run() = 0;
+ };
+
+}}
+
+#endif /*_DECAF_LANG_RUNNABLE_H_*/
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp?view=auto&rev=532121
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp Tue
Apr 24 15:41:45 2007
@@ -0,0 +1,171 @@
+/*
+ * 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 "Thread.h"
+
+#ifdef HAVE_PTHREAD_H
+ #include <errno.h>
+#else
+ #include <process.h> // _endthreadex
+#endif
+
+#include <decaf/lang/Exception.h>
+#include <activemq/exceptions/RuntimeException.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+Thread::Thread()
+{
+ task = this;
+ started = false;
+ joined = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Thread::Thread( Runnable* task )
+{
+ this->task = task;
+ started = false;
+ joined = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Thread::~Thread()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Thread::start() throw ( Exception )
+{
+ if (this->started) {
+ throw exceptions::ActiveMQException( __FILE__, __LINE__,
+ "Thread already started");
+ }
+
+#ifdef HAVE_PTHREAD_H
+
+ ::pthread_attr_init (&attributes);
+ ::pthread_attr_setdetachstate (&attributes, PTHREAD_CREATE_JOINABLE);
+ int err = ::pthread_create (
+ &this->threadHandle,
+ &attributes,
+ runCallback,
+ this);
+ if (err != 0) {
+ throw exceptions::ActiveMQException( __FILE__, __LINE__,
+ "Coud not start thread");
+ }
+
+#else
+
+ unsigned int threadId = 0;
+ this->threadHandle =
+ (HANDLE)::_beginthreadex(NULL, 0, runCallback, this, 0, &threadId);
+ if (this->threadHandle == NULL) {
+ throw exceptions::ActiveMQException( __FILE__, __LINE__,
+ "Coud not start thread");
+ }
+
+#endif
+
+ // Mark the thread as started.
+ started = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Thread::join() throw( exceptions::ActiveMQException )
+{
+ if (!this->started) {
+ throw exceptions::ActiveMQException( __FILE__, __LINE__,
+ "Thread::join() called without having called Thread::start()");
+ }
+ if (!this->joined) {
+
+#ifdef HAVE_PTHREAD_H
+ ::pthread_join(this->threadHandle, NULL);
+#else
+ ::WaitForSingleObject (this->threadHandle, INFINITE);
+#endif
+
+ }
+ this->joined = true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Thread::sleep( int millisecs )
+{
+#ifdef HAVE_PTHREAD_H
+ struct timespec rec, rem;
+ rec.tv_sec = millisecs / 1000;
+ rec.tv_nsec = (millisecs % 1000) * 1000000;
+ while( nanosleep( &rec, &rem ) == -1 ){
+ if( errno != EINTR ){
+ break;
+ }
+ }
+
+#else
+ ::Sleep (millisecs);
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned long Thread::getId(void)
+{
+ #ifdef HAVE_PTHREAD_H
+ return (long)(pthread_self());
+ #else
+ return GetCurrentThreadId();
+ #endif
+}
+
+////////////////////////////////////////////////////////////////////////////////
+#ifdef HAVE_PTHREAD_H
+ void*
+#else
+ unsigned int WINAPI
+#endif
+Thread::runCallback( void* param )
+{
+ // Get the instance.
+ Thread* thread = (Thread*)param;
+
+ // Invoke run on the task.
+ try{
+ thread->task->run();
+ } catch( ... ){
+ exceptions::RuntimeException ex(__FILE__, __LINE__, "unhandled
exception bubbled up to Thread::run");
+ ex.printStackTrace();
+ }
+
+#ifdef HAVE_PTHREAD_H
+ ::pthread_attr_destroy( &thread->attributes );
+ return NULL;
+#else
+
+ // Needed when using threads and CRT in Windows. Otherwise memleak can
appear.
+ ::_endthreadex(0);
+
+ // _endthreadex (unlike _endthread) does not automatically close the
thread handle
+ // so we need to do this manually.
+ ::CloseHandle(thread->threadHandle);
+
+ return 0;
+#endif
+}
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h
URL:
http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h?view=auto&rev=532121
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h
(added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h Tue
Apr 24 15:41:45 2007
@@ -0,0 +1,134 @@
+/*
+ * 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 _DECAF_LANG_THREAD_H_
+#define _DECAF_LANG_THREAD_H_
+
+#include <decaf/lang/Exception.h>
+#include <decaf/lang/Runnable.h>
+#include <decaf/util/Config.h>
+#include <stdexcept>
+#include <assert.h>
+
+#ifdef HAVE_PTHREAD_H
+ #include <pthread.h>
+#else
+ #include <windows.h>
+#endif
+
+namespace decaf{
+namespace lang{
+
+ /**
+ * Basic thread class - mimics the Java Thread. Derived classes may
+ * implement the run method, or this class can be used as is with
+ * a provided Runnable delegate.
+ */
+ class Thread : public Runnable
+ {
+ private:
+
+ /**
+ * The task to be run by this thread, defaults to
+ * this thread object.
+ */
+ Runnable* task;
+
+ #ifdef HAVE_PTHREAD_H
+ pthread_attr_t attributes;
+ pthread_t threadHandle;
+ #else
+ HANDLE threadHandle;
+ #endif
+
+ /**
+ * Started state of this thread.
+ */
+ bool started;
+
+ /**
+ * Indicates whether the thread has already been
+ * joined.
+ */
+ bool joined;
+
+ public:
+
+ /**
+ * default Constructor
+ */
+ Thread();
+
+ /**
+ * Constructor
+ * @param task the Runnable that this thread manages
+ */
+ Thread( Runnable* task );
+
+ virtual ~Thread();
+
+ /**
+ * Creates a system thread and starts it in a joinable mode.
+ * Upon creation, the
+ * run() method of either this object or the provided Runnable
+ * object will be invoked in the context of this thread.
+ * @exception runtime_error is thrown if the system could
+ * not start the thread.
+ */
+ virtual void start() throw ( exceptions::ActiveMQException );
+
+ /**
+ * Wait til the thread exits. This is when the run()
+ * method has returned or has thrown an exception.
+ */
+ virtual void join() throw ( exceptions::ActiveMQException );
+
+ /**
+ * Default implementation of the run method - does nothing.
+ */
+ virtual void run(){};
+
+ public:
+
+ /**
+ * Halts execution of the calling thread for a specified no of
millisec.
+ *
+ * Note that this method is a static method that applies to the
+ * calling thread and not to the thread object.
+ * @param millisecs time in milliseconds to sleep
+ */
+ static void sleep( int millisecs );
+
+ /**
+ * Obtains the Thread Id of the current thread
+ * @return Thread Id
+ */
+ static unsigned long getId(void);
+
+ private:
+
+ // Internal thread handling
+ #ifdef HAVE_PTHREAD_H
+ static void* runCallback (void* param);
+ #else
+ static unsigned int WINAPI runCallback (void* param);
+ #endif
+
+ };
+
+}}
+
+#endif /*_DECAF_LANG_THREAD_H_*/