activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r565191 - in /activemq/activemq-cpp/trunk/src/decaf/src/main: Makefile.am decaf/internal/AprPool.cpp decaf/internal/AprPool.h decaf/lang/System.cpp decaf/lang/System.h
Date Sun, 12 Aug 2007 22:50:28 GMT
Author: tabish
Date: Sun Aug 12 15:50:27 2007
New Revision: 565191

URL: http://svn.apache.org/viewvc?view=rev&rev=565191
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103

Adding a System class

Added:
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.h
Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/AprPool.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/AprPool.h

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am?view=diff&rev=565191&r1=565190&r2=565191
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am Sun Aug 12 15:50:27 2007
@@ -34,6 +34,7 @@
    decaf/lang/Float.cpp \
    decaf/lang/Double.cpp \
    decaf/lang/Math.cpp \
+   decaf/lang/System.cpp \
    decaf/io/BufferedOutputStream.cpp \
    decaf/io/BufferedInputStream.cpp \
    decaf/io/ByteArrayInputStream.cpp \
@@ -86,6 +87,7 @@
    decaf/lang/Number.h \
    decaf/lang/Runnable.h \
    decaf/lang/Math.h \
+   decaf/lang/System.h \
    decaf/lang/exceptions/NoSuchElementException.h \
    decaf/lang/exceptions/RuntimeException.h \
    decaf/lang/exceptions/IndexOutOfBoundsException.h \

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/AprPool.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/AprPool.cpp?view=diff&rev=565191&r1=565190&r2=565191
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/AprPool.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/AprPool.cpp Sun Aug 12 15:50:27
2007
@@ -29,3 +29,8 @@
 AprPool::~AprPool() {
     apr_pool_destroy( aprPool );
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void AprPool::cleanup() {
+    apr_pool_clear( aprPool );
+}

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/AprPool.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/AprPool.h?view=diff&rev=565191&r1=565190&r2=565191
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/AprPool.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/AprPool.h Sun Aug 12 15:50:27
2007
@@ -47,6 +47,13 @@
             return aprPool;
         }
 
+        /**
+         * Clears data that was allocated by this pool.  Users should call this
+         * after getting the data from the APR functions and copying it to
+         * someplace safe.
+         */
+        void cleanup();
+
     };
 
 }}

Added: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.cpp?view=auto&rev=565191
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.cpp Sun Aug 12 15:50:27
2007
@@ -0,0 +1,64 @@
+/*
+ * 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 "System.h"
+
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <apr_errno.h>
+#include <apr_env.h>
+
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::internal;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+AprPool System::aprPool;
+
+////////////////////////////////////////////////////////////////////////////////
+System::System() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string System::getenv( const std::string& name ) throw ( Exception ) {
+
+    char* value = NULL;
+    apr_status_t result = APR_SUCCESS;
+
+    // Read the value, errors are thrown out as an exception
+    result = apr_env_get( &value, name.c_str(), aprPool.getAprPool() );
+
+    if( result != APR_SUCCESS ) {
+
+        char buffer[256] = {0};
+
+        throw NullPointerException(
+            __FILE__, __LINE__,
+            "System::getenv - ",
+            apr_strerror( result, buffer, 255 ) );
+    }
+
+    // Copy and cleanup
+    if( value == NULL ) {
+        return "";
+    }
+
+    std::string envVal( value );
+    aprPool.cleanup();
+
+    return value;
+}

Added: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.h?view=auto&rev=565191
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.h Sun Aug 12 15:50:27
2007
@@ -0,0 +1,55 @@
+/*
+ * 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_SYSTEM_H_
+#define _DECAF_LANG_SYSTEM_H_
+
+#include <decaf/util/Config.h>
+#include <decaf/lang/Exception.h>
+#include <decaf/internal/AprPool.h>
+#include <string>
+
+namespace decaf{
+namespace lang{
+
+    class DECAF_API System {
+    private:
+
+        static internal::AprPool aprPool;
+
+    public:
+
+        System();
+        virtual ~System() {}
+
+    public:  // Static Methods
+
+        /**
+         * Reads an environment value from the system and returns it as a
+         * string object
+         * @param name - the env var to read
+         * @return a string with the value from the var or ""
+         * @throws an Exception if an error occurs while reading the Env.
+         */
+        static std::string getenv( const std::string& name )
+            throw ( lang::Exception );
+
+    };
+
+}}
+
+#endif /*_DECAF_LANG_SYSTEM_H_*/



Mime
View raw message