00001 /* 00002 * Copyright 2016 CERN 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 */ 00017 00018 00019 00020 /// @file DomeDavixPool.h 00021 /// @brief Pool of davix contexts 00022 /// @author Fabrizio Furano <furano@cern.ch> 00023 /// @date Jan 2016 00024 00025 00026 00027 #ifndef UTILS_DAVIXPOOL_H 00028 #define UTILS_DAVIXPOOL_H 00029 00030 00031 #ifdef __APPLE__ 00032 #include <bsm/audit_errno.h> 00033 #endif 00034 00035 #include <algorithm> 00036 #include <stdlib.h> 00037 #include "utils/logger.h" 00038 #include "utils/poolcontainer.h" 00039 #include "utils/Config.hh" 00040 00041 #include <davix/davix.hpp> 00042 00043 namespace dmlite { 00044 00045 extern Logger::bitmask davixpoollogmask; 00046 extern Logger::component davixpoollogname; 00047 00048 class DavixStuff { 00049 public: 00050 DavixStuff(Davix::RequestParams params) { 00051 ctx = new Davix::Context(); 00052 parms = new Davix::RequestParams(params); 00053 creationtime = time(0); 00054 } 00055 00056 ~DavixStuff() { 00057 delete parms; 00058 delete ctx; 00059 parms = 0; 00060 ctx = 0; 00061 } 00062 00063 time_t creationtime; 00064 Davix::Context *ctx; 00065 Davix::RequestParams *parms; 00066 }; 00067 00068 /// Factory for davix contexts 00069 /// This is just mechanics of how the Poolcontainer class works 00070 /// and wraps the creation of the actual instances 00071 class DavixCtxFactory: public dmlite::PoolElementFactory<DavixStuff *> { 00072 public: 00073 DavixCtxFactory(); 00074 00075 DavixStuff* create(); 00076 void destroy(DavixStuff*); 00077 bool isValid(DavixStuff*); 00078 00079 void configure(const std::string &key, const std::string &value); 00080 void setRequestParams(const Davix::RequestParams ¶ms); 00081 protected: 00082 //boost::mutex mtx; 00083 private: 00084 Davix::RequestParams params_; 00085 00086 std::string davix_cert_path; 00087 std::string davix_privkey_path; 00088 }; 00089 00090 class DavixCtxPool : public dmlite::PoolContainer<DavixStuff *> { 00091 public: 00092 DavixCtxPool(PoolElementFactory<DavixStuff *> *factory, int n) : 00093 dmlite::PoolContainer<DavixStuff *>(factory, n) { } 00094 }; 00095 00096 00097 class DavixGrabber : public PoolGrabber<DavixStuff*> { 00098 public: 00099 DavixGrabber(DavixCtxPool &pool, bool block = true) : 00100 PoolGrabber<DavixStuff *>(pool, block) {} 00101 }; 00102 00103 } 00104 00105 00106 #endif