dmlite  0.6
DavixPool.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 CERN
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 
19 
20 /// @file DomeDavixPool.h
21 /// @brief Pool of davix contexts
22 /// @author Fabrizio Furano <furano@cern.ch>
23 /// @date Jan 2016
24 
25 
26 
27 #ifndef UTILS_DAVIXPOOL_H
28 #define UTILS_DAVIXPOOL_H
29 
30 
31 #ifdef __APPLE__
32 #include <bsm/audit_errno.h>
33 #endif
34 
35 #include <algorithm>
36 #include <stdlib.h>
37 #include "utils/logger.h"
38 #include "utils/poolcontainer.h"
39 #include "utils/Config.hh"
40 
41 #include <davix/davix.hpp>
42 
43 namespace dmlite {
44 
47 
48  class DavixStuff {
49  public:
50  DavixStuff(Davix::RequestParams params) {
51  ctx = new Davix::Context();
52  parms = new Davix::RequestParams(params);
53  }
54 
56  delete parms;
57  delete ctx;
58  parms = 0;
59  ctx = 0;
60  }
61 
62  Davix::Context *ctx;
63  Davix::RequestParams *parms;
64  };
65 
66  /// Factory for davix contexts
67  /// This is just mechanics of how the Poolcontainer class works
68  /// and wraps the creation of the actual instances
69  class DavixCtxFactory: public dmlite::PoolElementFactory<DavixStuff *> {
70  public:
72 
73  DavixStuff* create();
74  void destroy(DavixStuff*);
75  bool isValid(DavixStuff*);
76 
77  void configure(const std::string &key, const std::string &value);
78  void setRequestParams(const Davix::RequestParams &params);
79  protected:
80  //boost::mutex mtx;
81  private:
82  Davix::RequestParams params_;
83 
84  std::string davix_cert_path;
85  std::string davix_privkey_path;
86  };
87 
88  class DavixCtxPool : public dmlite::PoolContainer<DavixStuff *> {
89  public:
91  dmlite::PoolContainer<DavixStuff *>(factory, n) { }
92  };
93 
94 
95 class DavixGrabber : public PoolGrabber<DavixStuff*> {
96 public:
97  DavixGrabber(DavixCtxPool &pool, bool block = true) :
98  PoolGrabber<DavixStuff *>(pool, block) {}
99 };
100 
101 }
102 
103 
104 #endif
Convenience class that releases a resource on destruction.
Definition: poolcontainer.h:206
Implements a pool of whichever resource.
Definition: poolcontainer.h:38
Davix::RequestParams * parms
Definition: DavixPool.h:63
DavixStuff(Davix::RequestParams params)
Definition: DavixPool.h:50
Definition: DavixPool.h:48
~DavixStuff()
Definition: DavixPool.h:55
Davix::RequestParams params_
Definition: DavixPool.h:82
Logger::bitmask davixpoollogmask
Definition: DavixPool.h:69
Definition: DavixPool.h:88
unsigned long long bitmask
typedef for a bitmask (long long)
Definition: logger.h:41
Definition: DavixPool.h:95
DavixCtxPool(PoolElementFactory< DavixStuff *> *factory, int n)
Definition: DavixPool.h:90
std::string component
typedef for a component name (std:string)
Definition: logger.h:43
Davix::Context * ctx
Definition: DavixPool.h:62
Logger::component davixpoollogname
std::string davix_cert_path
Definition: DavixPool.h:84
std::string davix_privkey_path
Definition: DavixPool.h:85
DavixGrabber(DavixCtxPool &pool, bool block=true)
Definition: DavixPool.h:97
Namespace for the dmlite C++ API.
Definition: authn.h:15
Definition: poolcontainer.h:20