| Directory: | ./ |
|---|---|
| File: | src/PAbstractControlManager_impl.h |
| Date: | 2024-12-09 11:00:39 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 74 | 76 | 97.4% |
| Branches: | 31 | 41 | 75.6% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #ifndef __PABSTRACTCONTROLMANAGER_H_IMPL__ | ||
| 8 | #define __PABSTRACTCONTROLMANAGER_H_IMPL__ | ||
| 9 | |||
| 10 | #include "PAbstractControlManager.h" | ||
| 11 | |||
| 12 | ///Default constructor of PAbstractControlManager | ||
| 13 | /** @param mode : Mode of the Connector (no mock, mock, mock_record) | ||
| 14 | * @param mgrParam : parameters of the backend manager | ||
| 15 | * @param mockParam : parameters of the mock backend | ||
| 16 | * @param mockMgrParam : parameters of the mock backend manager | ||
| 17 | */ | ||
| 18 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 19 |
2/2✓ Branch 4 taken 22 times.
✓ Branch 7 taken 22 times.
|
22 | PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::PAbstractControlManager(ConnectorMode::ConnectorMode mode, const typename _TBackend::MgrParam & mgrParam, const typename _TMockBackend::Param & mockParam, const typename _TMockBackend::MgrParam & mockMgrParam){ |
| 20 |
1/1✓ Branch 1 taken 22 times.
|
22 | initialisationPAbstractControlManager(mode, mgrParam, mockParam, mockMgrParam); |
| 21 | 22 | } | |
| 22 | |||
| 23 | ///Destructor of PAbstractControlManager | ||
| 24 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 25 | 44 | PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::~PAbstractControlManager(){ | |
| 26 | 44 | clear(); | |
| 27 | } | ||
| 28 | |||
| 29 | ///Add a Client Connector | ||
| 30 | /** @param name : name of the Connector | ||
| 31 | * @param hostName : name of the host of the connector | ||
| 32 | * @param param : extra parameters from the backend _TBackend | ||
| 33 | * @return true on success, false otherwise | ||
| 34 | */ | ||
| 35 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 36 | 23 | bool PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::addClientConnector(const _TConnectorKey & name, const std::string & hostName, const typename _TBackend::Param & param){ | |
| 37 |
1/1✓ Branch 2 taken 23 times.
|
23 | PAbstractConnector<_TBackend, _TMockBackend>* connector = new PAbstractConnector<_TBackend, _TMockBackend>(p_mode, p_mockParam, &p_manager, &p_mockManager); |
| 38 | 23 | bool b(connector != NULL); | |
| 39 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | if(b){ |
| 40 | 23 | b &= connector->createClientConnector(hostName, param); | |
| 41 |
1/2✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
|
23 | if(b){ |
| 42 | 23 | connector->setMapInternalVarPtr(&p_mapInternalVar); | |
| 43 | 23 | p_mapConnector[name] = connector; | |
| 44 | } | ||
| 45 | } | ||
| 46 | 23 | return b; | |
| 47 | } | ||
| 48 | |||
| 49 | ///Add a Server Connector | ||
| 50 | /** @param name : name of the Connector | ||
| 51 | * @param hostName : name of the host of the connector | ||
| 52 | * @param param : extra parameters from the backend _TBackend | ||
| 53 | * @return true on success, false otherwise | ||
| 54 | */ | ||
| 55 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 56 | 2 | bool PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::addServerConnector(const _TConnectorKey & name, const std::string & hostName, const typename _TBackend::Param & param){ | |
| 57 |
1/1✓ Branch 2 taken 2 times.
|
2 | PAbstractConnector<_TBackend, _TMockBackend>* connector = new PAbstractConnector<_TBackend, _TMockBackend>(p_mode, p_mockParam, &p_manager, &p_mockManager); |
| 58 | 2 | bool b(connector != NULL); | |
| 59 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if(b){ |
| 60 | 2 | b &= connector->createServerConnector(hostName, param); | |
| 61 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if(b){ |
| 62 | 2 | connector->setMapInternalVarPtr(&p_mapInternalVar); | |
| 63 | 2 | p_mapConnector[name] = connector; | |
| 64 | } | ||
| 65 | } | ||
| 66 | 2 | return b; | |
| 67 | } | ||
| 68 | |||
| 69 | ///Remove the given connector | ||
| 70 | /** @param name : name (key) of the connector to be removed | ||
| 71 | */ | ||
| 72 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 73 | 1 | void PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::removeConnector(const _TConnectorKey & name){ | |
| 74 |
1/1✓ Branch 1 taken 1 times.
|
1 | typename std::map<_TConnectorKey, PAbstractConnector<_TBackend, _TMockBackend>* >::iterator it(p_mapConnector.find(name)); |
| 75 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | if(it != p_mapConnector.end()){ |
| 76 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | delete it->second; |
| 77 |
1/1✓ Branch 1 taken 1 times.
|
1 | p_mapConnector.erase(it); |
| 78 | } | ||
| 79 | 1 | } | |
| 80 | |||
| 81 | ///Clear the map of Connector | ||
| 82 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 83 | 22 | void PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::clearConnector(){ | |
| 84 |
2/2✓ Branch 4 taken 24 times.
✓ Branch 5 taken 22 times.
|
46 | for(typename std::map<_TConnectorKey, PAbstractConnector<_TBackend, _TMockBackend>* >::iterator it(p_mapConnector.begin()); it != p_mapConnector.end(); ++it){ |
| 85 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | delete it->second; |
| 86 | } | ||
| 87 | 22 | p_mapConnector.clear(); | |
| 88 | 22 | } | |
| 89 | |||
| 90 | ///Clear the map of Connector and the map of internal variables | ||
| 91 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 92 | 22 | void PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::clear(){ | |
| 93 | 22 | clearAllInternalVar(); | |
| 94 | 22 | clearConnector(); | |
| 95 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 5 times.
|
22 | if(p_mode != ConnectorMode::MOCK){ |
| 96 | 17 | _TBackend::closeMgr(p_manager); | |
| 97 | } | ||
| 98 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 13 times.
|
22 | if(p_mode != ConnectorMode::NO_MOCK){ |
| 99 | 9 | _TMockBackend::closeMgr(p_mockManager); | |
| 100 | } | ||
| 101 | 22 | } | |
| 102 | |||
| 103 | ///Regiter a variable which can be used by the given connector | ||
| 104 | /** @param name : name of the connector to be used | ||
| 105 | * @param composeVar : variable to be refistered | ||
| 106 | * @return true on success, false otherwise | ||
| 107 | */ | ||
| 108 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 109 | 13 | bool PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::registerVar(const _TConnectorKey & name, const PComposeVar & composeVar){ | |
| 110 | 13 | PAbstractConnector<_TBackend, _TMockBackend> * connector = getConnector(name); | |
| 111 |
1/2✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | if(connector != NULL){ |
| 112 | 13 | return connector->registerVar(composeVar); | |
| 113 | }else{ | ||
| 114 | ✗ | return false; | |
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | ///Regiter a method which can be called by the given connector | ||
| 119 | /** @param name : name of the connector to be used | ||
| 120 | * @param prototype : prototype of the method to be called | ||
| 121 | * @return true on success, false otherwise | ||
| 122 | */ | ||
| 123 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 124 | 2 | bool PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::registerCall(const _TConnectorKey & name, const PFunctionPrototype & prototype){ | |
| 125 | 2 | PAbstractConnector<_TBackend, _TMockBackend> * connector = getConnector(name); | |
| 126 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if(connector != NULL){ |
| 127 | 2 | return connector->registerCall(prototype); | |
| 128 | }else{ | ||
| 129 | ✗ | return false; | |
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | ///Push a value in a message | ||
| 134 | /** @param name : name of the connector to be used | ||
| 135 | * @param varName : name of the variable to be pushed | ||
| 136 | * @param msg : message to be pushed | ||
| 137 | * @return true on success, false otherwise | ||
| 138 | */ | ||
| 139 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 140 | 41 | bool PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::pushMsg(const _TConnectorKey & name, const std::string & varName, const typename _TBackend::Message & msg){ | |
| 141 | 41 | PAbstractConnector<_TBackend, _TMockBackend> * connector = getConnector(name); | |
| 142 |
2/2✓ Branch 0 taken 40 times.
✓ Branch 1 taken 1 times.
|
41 | if(connector != NULL){ |
| 143 | 40 | return connector->pushMsg(varName, msg); | |
| 144 | }else{ | ||
| 145 | 1 | return false; | |
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | ///Pull a value in a message | ||
| 150 | /** @param name : name of the connector to be used | ||
| 151 | * @param varName : name of the variable to be pushed | ||
| 152 | * @param[out] msg : pulled message | ||
| 153 | * @return true on success, false otherwise | ||
| 154 | */ | ||
| 155 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 156 | bool PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::pullMsg(const _TConnectorKey & name, const std::string & varName, typename _TBackend::Message & msg){ | ||
| 157 | PAbstractConnector<_TBackend, _TMockBackend> * connector = getConnector(name); | ||
| 158 | if(connector != NULL){ | ||
| 159 | return connector->pullMsg(varName, msg); | ||
| 160 | }else{ | ||
| 161 | return false; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | ///Call a method of a remote client/server | ||
| 166 | /** @param name : name of the connector to be used | ||
| 167 | * @param methodCall : method to be called | ||
| 168 | * @return true on success, false otherwise | ||
| 169 | */ | ||
| 170 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 171 | bool PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::call(const _TConnectorKey & name, PFunctionCall & methodCall){ | ||
| 172 | PAbstractConnector<_TBackend, _TMockBackend> * connector = getConnector(name); | ||
| 173 | if(connector != NULL){ | ||
| 174 | return connector->call(methodCall); | ||
| 175 | }else{ | ||
| 176 | return false; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | ///Clear a given internal variable | ||
| 181 | /** @param varName : name of the variable to be cleared | ||
| 182 | */ | ||
| 183 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 184 | void PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::removeInternalVar(const std::string & varName){ | ||
| 185 | typename std::map<std::string, PGenericInternalVar<_TBackend, _TMockBackend>* >::iterator it(p_mapInternalVar.find(varName)); | ||
| 186 | if(it != p_mapInternalVar.end()){ | ||
| 187 | delete it->second; | ||
| 188 | p_mapInternalVar.erase(it); | ||
| 189 | } | ||
| 190 | } | ||
| 191 | |||
| 192 | ///Clear the map of all the internal variables | ||
| 193 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 194 | 22 | void PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::clearAllInternalVar(){ | |
| 195 |
2/2✓ Branch 4 taken 2 times.
✓ Branch 5 taken 22 times.
|
24 | for(typename std::map<std::string, PGenericInternalVar<_TBackend, _TMockBackend>* >::iterator it(p_mapInternalVar.begin()); it != p_mapInternalVar.end(); ++it){ |
| 196 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | delete it->second; |
| 197 | } | ||
| 198 | 22 | p_mapInternalVar.clear(); | |
| 199 | 22 | } | |
| 200 | |||
| 201 | ///Get a connector by name | ||
| 202 | /** @param name : name to the connector we want | ||
| 203 | * @return pointer to the connector or NULL if the connector does not exist | ||
| 204 | */ | ||
| 205 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 206 | 179 | PAbstractConnector<_TBackend, _TMockBackend>* PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::getConnector(const _TConnectorKey & name){ | |
| 207 |
1/1✓ Branch 1 taken 179 times.
|
179 | typename std::map<_TConnectorKey, PAbstractConnector<_TBackend, _TMockBackend>* >::iterator it(p_mapConnector.find(name)); |
| 208 |
2/2✓ Branch 2 taken 177 times.
✓ Branch 3 taken 2 times.
|
179 | if(it != p_mapConnector.end()){ |
| 209 | 177 | return it->second; | |
| 210 | }else{ | ||
| 211 | 2 | return NULL; | |
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | ///Say if a connector does exist | ||
| 216 | /** @param name : name of the connector to be searched | ||
| 217 | * @return true if the connector does exist, false otherwise | ||
| 218 | */ | ||
| 219 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 220 | 2 | bool PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::isConnectorExist(const _TConnectorKey & name) const{ | |
| 221 |
1/1✓ Branch 1 taken 2 times.
|
2 | typename std::map<_TConnectorKey, PAbstractConnector<_TBackend, _TMockBackend>* >::const_iterator it(p_mapConnector.find(name)); |
| 222 | 2 | return it != p_mapConnector.end(); | |
| 223 | } | ||
| 224 | |||
| 225 | ///Initialisation function of the class PAbstractControlManager | ||
| 226 | /** @param mode : Mode of the Connector (no mock, mock, mock_record) | ||
| 227 | * @param mgrParam : parameters of the backend manager | ||
| 228 | * @param mockParam : parameters of the mock backend | ||
| 229 | * @param mockMgrParam : parameters of the mock backend manager | ||
| 230 | */ | ||
| 231 | template<typename _TConnectorKey, typename _TBackend, typename _TMockBackend> | ||
| 232 | 22 | void PAbstractControlManager<_TConnectorKey, _TBackend, _TMockBackend>::initialisationPAbstractControlManager(ConnectorMode::ConnectorMode mode, const typename _TBackend::MgrParam & mgrParam, const typename _TMockBackend::Param & mockParam, const typename _TMockBackend::MgrParam & mockMgrParam){ | |
| 233 | 22 | p_mode = mode; | |
| 234 | 22 | p_mockParam = mockParam; | |
| 235 | 22 | _TBackend::initialiseDataManager(p_manager, mgrParam); | |
| 236 | 22 | _TMockBackend::initialiseDataManager(p_mockManager, mockMgrParam); | |
| 237 | 22 | } | |
| 238 | |||
| 239 | |||
| 240 | |||
| 241 | |||
| 242 | |||
| 243 | #endif | ||
| 244 | |||
| 245 | |||
| 246 | |||
| 247 |