All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DBDrvLib.h
Go to the documentation of this file.
1 /*
2  * DBDrvLib.h
3  *
4  * This file is part of the HausmiSEP project
5  *
6  * Copyright (C) 2012, 2013 Marco Alvarado (malvcr@gmail.com)
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef DBDRVLIB_H_
23 #define DBDRVLIB_H_
24 
25 #include <HSEPData/ErrorCode.h>
26 #include <HSEP/Library.h>
27 #include <cstddef>
28 #include <cstring>
29 
30 #include <map>
31 
32 using namespace std;
33 
38 typedef HSEPData::DBEnvironment* (*createEnvironmentType)();
39 
40 namespace HSEPData {
41 
42  class DBDrvLib : public HSEP::Library {
43  createEnvironmentType fCreateEnvironment;
44  public:
45  DBDrvLib(string& pPath) : Library("DBDrvLib",pPath) {
46  if (valid()) {
47  /*
48  * The dynamic method is only retrieved once to be used many times with the
49  * getEnvironment method.
50  */
68  union {
69  void* aPOSIX;
71  } vMethod;
72 
73  memset((void*)&vMethod,0,(long int)sizeof(vMethod)); // this way, we have clear information containers
74 
75  string vCreateEnvironmentStr = string("createEnvironment");
76 
77  vMethod.aPOSIX = getMethodPtr(vCreateEnvironmentStr);
78  fCreateEnvironment = vMethod.aCPP;
79 
80  }
81  } // constructor
82 
94  DBEnvironment* getEnvironmentPtr(string& pConnStrRef, string& pUserRef, string& pPasswordRef, string& pSchemaRef) {
95 
96  DBEnvironment* vResult = nullptr;
97  if (valid()) {
98  vResult = fCreateEnvironment();
99 
100  if (EC::OK == vResult->connect(pConnStrRef,pUserRef,pPasswordRef)) {
101  vResult->setSchema(pSchemaRef);
102  }
103  else {
104  setLastError(vResult->lastErrorRef());
105  delete vResult;
106  vResult = nullptr;
107  }
108 
109  }
110  return vResult;
111  }
112  }; // DBDrvLib class
113 
119  typedef map<string,DBDrvLib*> DBDrvLibMap;
120 
127  typedef DBDrvLibMap::iterator DBDrvLibMapIterator;
128 
129 } // HSEPData namespace
130 
131 #endif /* DBDRVLIB_H_ */