/home/aconway/svn/qpid/cpp/src/qpid/sys/apr/APRBase.h

00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  * 
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  * 
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
00019  *
00020  */
00021 #ifndef _APRBase_
00022 #define _APRBase_
00023 
00024 #include <string>
00025 #include <apr_thread_mutex.h>
00026 #include <apr_errno.h>
00027 #include "qpid/QpidError.h"
00028 
00029 namespace qpid {
00030 namespace sys {
00031 
00039     class APRBase{
00040         static APRBase* instance;
00041         apr_pool_t* pool;
00042         apr_thread_mutex_t* mutex;
00043         int count;
00044 
00045         APRBase();
00046         ~APRBase();
00047         static APRBase* getInstance();
00048         bool _increment();
00049         void _decrement();
00050     public:
00051         static void increment();
00052         static void decrement();
00053     };
00054 
00055     //this is also a convenient place for a helper function for error checking:
00056     void check(apr_status_t status, const char* file, const int line);
00057     std::string get_desc(apr_status_t status);
00058 
00059 #define CHECK_APR_SUCCESS(A) qpid::sys::check(A, __FILE__, __LINE__); 
00060 
00061 }
00062 }
00063 
00064 // Inlined as it is called *a lot*
00065 void inline qpid::sys::check(apr_status_t status, const char* file, const int line){
00066     if (status != APR_SUCCESS){
00067         const int size = 50;
00068         char tmp[size];
00069         std::string msg(apr_strerror(status, tmp, size));
00070         throw qpid::QpidError(APR_ERROR + ((int) status), msg,
00071                         qpid::SrcLine(file, line));
00072     }
00073 }
00074 
00075 
00076 
00077 
00078 #endif

Generated on Tue Apr 17 14:22:03 2007 for Qpid by  doxygen 1.4.7