xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdSsiShMap.hh
Go to the documentation of this file.
1 #ifndef __SSI_SHMAP__
2 #define __SSI_SHMAP__
3 /******************************************************************************/
4 /* */
5 /* X r d S s i S h M a p . h h */
6 /* */
7 /* (c) 2015 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* Produced by Andrew Hanushevsky for Stanford University under contract */
9 /* DE-AC02-76-SFO0515 with the Department of Energy */
10 /* */
11 /* This file is part of the XRootD software suite. */
12 /* */
13 /* XRootD is free software: you can redistribute it and/or modify it under */
14 /* the terms of the GNU Lesser General Public License as published by the */
15 /* Free Software Foundation, either version 3 of the License, or (at your */
16 /* option) any later version. */
17 /* */
18 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
19 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
20 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
21 /* License for more details. */
22 /* */
23 /* You should have received a copy of the GNU Lesser General Public License */
24 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
25 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
26 /* */
27 /* The copyright holder's institutional names and contributor's names may not */
28 /* be used to endorse or promote products derived from this software without */
29 /* specific prior written permission of the institution or contributor. */
30 /******************************************************************************/
31 
32 #include <cstdlib>
33 #include <cstring>
34 
35 #include "XrdSsi/XrdSsiShMat.hh"
36 
37 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
42 
43 namespace XrdSsi
44 {
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
48 
50  {ReadOnly = 1,
51  ReadWrite = 2
52  };
53 
54 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
59 
60 static const int ShMap_4Resize = -1;
61 
63  {int indexSize;
64  int maxKeyLen;
65  int maxKeys;
66  int mode;
67  int options;
68  int reserved;
69 
70 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
73 
74 static const
75  int MultW = 0x88000000;
76 static const
77  int noMultW = 0x08000000;
78 static const
79  int ReUse = 0x44000000;
80 static const
81  int noReUse = 0x04000000;
82 
83 //-----------------------------------------------------------------------------
85 //-----------------------------------------------------------------------------
86 
87  ShMap_Parms() : indexSize(16381), maxKeyLen(63), maxKeys(32768),
88  mode(0640), options(0), reserved(0) {}
89 
90 //-----------------------------------------------------------------------------
92 //-----------------------------------------------------------------------------
93 static const
94  int ForResize = 0;
95 
96  ShMap_Parms(int rsz) : indexSize(0), maxKeyLen(0), maxKeys(0),
97  mode(0640), options(0), reserved(rsz) {}
98 
99 //-----------------------------------------------------------------------------
101 //-----------------------------------------------------------------------------
102 
104  };
105 
106 //-----------------------------------------------------------------------------
108 //-----------------------------------------------------------------------------
109 
111 
112 //-----------------------------------------------------------------------------
120 //-----------------------------------------------------------------------------
121 
122 typedef int (*ShMap_Hash_t)(const char *key);
123 
124 template<class T>
125 class ShMap
126 {
127 public:
128 
129 //-----------------------------------------------------------------------------
147 //-----------------------------------------------------------------------------
148 
149 bool Attach(const char *path, ShMap_Access access, int tmo=-1);
150 
151 //-----------------------------------------------------------------------------
176 //-----------------------------------------------------------------------------
177 
178 bool Create(const char *path, ShMap_Parms &parms);
179 
180 //-----------------------------------------------------------------------------
182 //-----------------------------------------------------------------------------
183 
184 void Detach();
185 
186 //-----------------------------------------------------------------------------
191 //-----------------------------------------------------------------------------
192 
193 bool Export();
194 
195 //-----------------------------------------------------------------------------
204 //-----------------------------------------------------------------------------
205 
206 bool Add(const char *key, T &val);
207 
208 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------
221 
222 bool Del(const char *key, T *valP=0);
223 
224 //-----------------------------------------------------------------------------
245 //-----------------------------------------------------------------------------
246 
247 bool Enumerate(void *&jar, char *&key, T *&val);
248 
249 //-----------------------------------------------------------------------------
262 //-----------------------------------------------------------------------------
263 
264 bool Enumerate(void *&jar);
265 
266 //-----------------------------------------------------------------------------
273 //-----------------------------------------------------------------------------
274 
275 bool Exists(const char *key);
276 
277 //-----------------------------------------------------------------------------
286 //-----------------------------------------------------------------------------
287 
288 bool Get(const char *key, T &val);
289 
290 //-----------------------------------------------------------------------------
322 //-----------------------------------------------------------------------------
323 
324 int Info(const char *vname, char *buff=0, int blen=0);
325 
326 //-----------------------------------------------------------------------------
338 //-----------------------------------------------------------------------------
339 
340 bool Rep(const char *key, T &val, T *valP=0);
341 
342 //-----------------------------------------------------------------------------
354 //-----------------------------------------------------------------------------
355 
356 bool Resize(ShMap_Parms *parms=0);
357 
358 //-----------------------------------------------------------------------------
380 //-----------------------------------------------------------------------------
381 
382 bool Sync(SyncOpt dosync, int syncqsz=256);
383 
384 //-----------------------------------------------------------------------------
399 //-----------------------------------------------------------------------------
400 
401  ShMap(const char *typeName, ShMap_Hash_t hFunc=0,
402  const char *implName=0)
403  : shMat(0), hashFunc(hFunc), typeID(strdup(typeName)),
404  implID((implName ? strdup(implName) : 0)) {}
405 
406 //-----------------------------------------------------------------------------
408 //-----------------------------------------------------------------------------
409 
411  if (typeID) free(typeID);
412  if (implID) free(implID);
413  }
414 
415 private:
416 
419 char *typeID;
420 char *implID;
421 };
422 }
423 
424 /******************************************************************************/
425 /* A c t u a l I m p l e m e n t a t i o n */
426 /******************************************************************************/
427 
428 #include "XrdSsi/XrdSsiShMap.icc"
429 #endif
static const int noReUse
Opposite (default for Create)
Definition: XrdSsiShMap.hh:81
reading &amp; writing
Definition: XrdSsiShMap.hh:51
void Detach()
Detach the map from the shared memory.
Definition: XrdSsiShMat.hh:41
int reserved
Reserved for future ABI complaint use.
Definition: XrdSsiShMap.hh:68
bool Rep(const char *key, T &val, T *valP=0)
SyncOpt
Options valid for the Sync() method.
Definition: XrdSsiShMap.hh:110
Definition: XrdSsiShMap.hh:125
static const int ReUse
Reuse map storage.
Definition: XrdSsiShMap.hh:79
bool Del(const char *key, T *valP=0)
bool Add(const char *key, T &val)
bool Get(const char *key, T &val)
bool Sync(SyncOpt dosync, int syncqsz=256)
static const int ForResize
Constructor suitable for Resize() (use ShMap_Parms(ForResize)).
Definition: XrdSsiShMap.hh:94
int(* ShMap_Hash_t)(const char *key)
Definition: XrdSsiShMap.hh:122
bool Create(const char *path, ShMap_Parms &parms)
int maxKeyLen
Maximum key length.
Definition: XrdSsiShMap.hh:64
int Info(const char *vname, char *buff=0, int blen=0)
Definition: XrdSsiShMap.hh:110
ShMap(const char *typeName, ShMap_Hash_t hFunc=0, const char *implName=0)
Definition: XrdSsiShMap.hh:401
int options
Bit or&#39;d ShMop_xxxx options below.
Definition: XrdSsiShMap.hh:67
~ShMap_Parms()
Destructor.
Definition: XrdSsiShMap.hh:103
ShMap_Parms()
Constructor suitable for Create()
Definition: XrdSsiShMap.hh:87
Definition: XrdSsiShMap.hh:110
bool Attach(const char *path, ShMap_Access access, int tmo=-1)
bool Resize(ShMap_Parms *parms=0)
Definition: XrdSsiShMap.hh:110
static const int MultW
Bit options that may be or&#39;d into he options member above.
Definition: XrdSsiShMap.hh:75
static const int ShMap_4Resize
Definition: XrdSsiShMap.hh:60
ShMap_Hash_t hashFunc
Definition: XrdSsiShMap.hh:418
Definition: XrdSsiShMap.hh:110
int indexSize
Number of hash table entries to create.
Definition: XrdSsiShMap.hh:63
~ShMap()
Destructor.
Definition: XrdSsiShMap.hh:410
ShMap_Parms(int rsz)
Definition: XrdSsiShMap.hh:96
#define access(a, b)
Definition: XrdPosix.hh:39
char * typeID
Definition: XrdSsiShMap.hh:419
bool Enumerate(void *&jar, char *&key, T *&val)
XrdSsiShMat * shMat
Definition: XrdSsiShMap.hh:417
int maxKeys
Maximum expected keys.
Definition: XrdSsiShMap.hh:65
reading
Definition: XrdSsiShMap.hh:50
Definition: XrdSsiShMap.hh:62
char * implID
Definition: XrdSsiShMap.hh:420
Definition: XrdSsiShMap.hh:110
static const int noMultW
Opposite (default for Create)
Definition: XrdSsiShMap.hh:77
int mode
Mode setting for the newly created file.
Definition: XrdSsiShMap.hh:66
ShMap_Access
The action parameter that must be passed to the Attach() method.
Definition: XrdSsiShMap.hh:49
bool Exists(const char *key)