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 } 00054 00055 ~DavixStuff() { 00056 delete parms; 00057 delete ctx; 00058 parms = 0; 00059 ctx = 0; 00060 } 00061 00062 Davix::Context *ctx; 00063 Davix::RequestParams *parms; 00064 }; 00065 00066 /// Factory for davix contexts 00067 /// This is just mechanics of how the Poolcontainer class works 00068 /// and wraps the creation of the actual instances 00069 class DavixCtxFactory: public dmlite::PoolElementFactory<DavixStuff *> { 00070 public: 00071 DavixCtxFactory(); 00072 00073 DavixStuff* create(); 00074 void destroy(DavixStuff*); 00075 bool isValid(DavixStuff*); 00076 00077 void configure(const std::string &key, const std::string &value); 00078 void setRequestParams(const Davix::RequestParams ¶ms); 00079 protected: 00080 private: 00081 Davix::RequestParams params_; 00082 00083 std::string davix_cert_path; 00084 std::string davix_privkey_path; 00085 }; 00086 00087 class DavixCtxPool : public dmlite::PoolContainer<DavixStuff *> { 00088 public: 00089 DavixCtxPool(PoolElementFactory<DavixStuff *> *factory, int n) : 00090 dmlite::PoolContainer<DavixStuff *>(factory, n) { } 00091 }; 00092 00093 00094 class DavixGrabber : public PoolGrabber<DavixStuff*> { 00095 public: 00096 DavixGrabber(DavixCtxPool &pool, bool block = true) : 00097 PoolGrabber<DavixStuff *>(pool, block) {} 00098 }; 00099 00100 } 00101 00102 00103 #endif