| Directory: | ./ |
|---|---|
| File: | src/PAbstractConnector_impl.h |
| Date: | 2024-12-09 11:00:39 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 65 | 66 | 98.5% |
| Branches: | 35 | 43 | 81.4% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #ifndef __PABSTRACTCONNECTOR_H_IMPL__ | ||
| 8 | #define __PABSTRACTCONNECTOR_H_IMPL__ | ||
| 9 | |||
| 10 | #include "PAbstractConnector.h" | ||
| 11 | |||
| 12 | ///Default constructor of PAbstractConnector | ||
| 13 | /** @param mode : Mode of the Connector (no mock, mock, mock_record) | ||
| 14 | * @param mockParam : parameters of the mock backend | ||
| 15 | * @param manager : pointer to the manager data | ||
| 16 | * @param mockManager : pointer to the mock manager data | ||
| 17 | */ | ||
| 18 | template<typename _TBackend, typename _TMockBackend> | ||
| 19 | 25 | PAbstractConnector<_TBackend, _TMockBackend>::PAbstractConnector(ConnectorMode::ConnectorMode mode, const typename _TMockBackend::Param & mockParam, typename _TBackend::Manager * manager, typename _TMockBackend::Manager * mockManager){ | |
| 20 |
1/1✓ Branch 1 taken 25 times.
|
25 | initialisationPAbstractConnector(mode, mockParam, manager, mockManager); |
| 21 | 25 | } | |
| 22 | |||
| 23 | ///Destructor of PAbstractConnector | ||
| 24 | template<typename _TBackend, typename _TMockBackend> | ||
| 25 | 100 | PAbstractConnector<_TBackend, _TMockBackend>::~PAbstractConnector(){ | |
| 26 | 50 | if(p_mode != ConnectorMode::MOCK){ | |
| 27 | 38 | _TBackend::close(p_connector); | |
| 28 | } | ||
| 29 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 15 times.
|
50 | if(p_mode != ConnectorMode::NO_MOCK){ |
| 30 | 20 | _TMockBackend::close(p_mockConnector); | |
| 31 | } | ||
| 32 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 6 times.
|
150 | } |
| 33 | |||
| 34 | |||
| 35 | ///Create a Client Connector | ||
| 36 | /** @param address : name of the host of the connector | ||
| 37 | * @param param : extra parameters from the backend _TBackend | ||
| 38 | * @return true on success, false otherwise | ||
| 39 | */ | ||
| 40 | template<typename _TBackend, typename _TMockBackend> | ||
| 41 | 23 | bool PAbstractConnector<_TBackend, _TMockBackend>::createClientConnector(const std::string & address, const typename _TBackend::Param & param){ | |
| 42 | 23 | bool b(true); | |
| 43 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 5 times.
|
23 | if(p_mode != ConnectorMode::MOCK){ |
| 44 | 18 | b &= _TBackend::createClientConnector(*p_manager, p_connector, address, param); | |
| 45 | } | ||
| 46 |
3/4✓ Branch 0 taken 9 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
23 | if(p_mode != ConnectorMode::NO_MOCK && b){ |
| 47 | 9 | b &= _TMockBackend::createClientConnector(*p_mockManager, p_mockConnector, address, p_mockParam); | |
| 48 | } | ||
| 49 | 23 | return b; | |
| 50 | } | ||
| 51 | |||
| 52 | ///Create a Server Connector | ||
| 53 | /** @param address : name of the host of the connector | ||
| 54 | * @param param : extra parameters from the backend _TBackend | ||
| 55 | * @return true on success, false otherwise | ||
| 56 | */ | ||
| 57 | template<typename _TBackend, typename _TMockBackend> | ||
| 58 | 2 | bool PAbstractConnector<_TBackend, _TMockBackend>::createServerConnector(const std::string & address, const typename _TBackend::Param & param){ | |
| 59 | 2 | bool b(true); | |
| 60 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if(p_mode != ConnectorMode::MOCK){ |
| 61 | 1 | b &= _TBackend::createServerConnector(*p_manager, p_connector, address, param); | |
| 62 | } | ||
| 63 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | if(p_mode != ConnectorMode::NO_MOCK && b){ |
| 64 | 1 | b &= _TMockBackend::createServerConnector(*p_mockManager, p_mockConnector, address, p_mockParam); | |
| 65 | } | ||
| 66 | 2 | return b; | |
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | ///Regiter a variable which can be used by the given connector | ||
| 71 | /** @param composeVar : variable to be refistered | ||
| 72 | * @return true on success, false otherwise | ||
| 73 | */ | ||
| 74 | template<typename _TBackend, typename _TMockBackend> | ||
| 75 | 13 | bool PAbstractConnector<_TBackend, _TMockBackend>::registerVar(const PComposeVar & composeVar){ | |
| 76 | 13 | bool b(true); | |
| 77 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 4 times.
|
13 | if(p_mode != ConnectorMode::MOCK){ |
| 78 | 9 | b &= _TBackend::registerVar(p_connector, composeVar); | |
| 79 | } | ||
| 80 |
3/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
13 | if(p_mode != ConnectorMode::NO_MOCK && b){ |
| 81 | 6 | b &= _TMockBackend::registerVar(p_mockConnector, composeVar); | |
| 82 | } | ||
| 83 | 13 | return b; | |
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | ///Regiter a method which can be called by the given connector | ||
| 88 | /** @param prototype : prototype of the method to be called | ||
| 89 | * @return true on success, false otherwise | ||
| 90 | */ | ||
| 91 | template<typename _TBackend, typename _TMockBackend> | ||
| 92 | 2 | bool PAbstractConnector<_TBackend, _TMockBackend>::registerCall(const PFunctionPrototype & prototype){ | |
| 93 | 2 | bool b(true); | |
| 94 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if(p_mode != ConnectorMode::MOCK){ |
| 95 | 2 | b &= _TBackend::registerCall(p_connector, prototype); | |
| 96 | } | ||
| 97 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | if(p_mode != ConnectorMode::NO_MOCK && b){ |
| 98 | 1 | b &= _TMockBackend::registerCall(p_mockConnector, prototype); | |
| 99 | } | ||
| 100 | 2 | return b; | |
| 101 | } | ||
| 102 | |||
| 103 | |||
| 104 | ///Push a message in a server / client | ||
| 105 | /** @param varName : name of the variable which is pushed | ||
| 106 | * @param msg : message to be pushed | ||
| 107 | * @return true on success, false otherwise | ||
| 108 | */ | ||
| 109 | template<typename _TBackend, typename _TMockBackend> | ||
| 110 | 40 | bool PAbstractConnector<_TBackend, _TMockBackend>::pushMsg(const std::string & varName, const typename _TBackend::Message & msg){ | |
| 111 | 40 | bool b(true); | |
| 112 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
40 | if(p_mode != ConnectorMode::MOCK){ |
| 113 | 20 | b &= _TBackend::push(p_connector, varName, msg); | |
| 114 | } | ||
| 115 |
3/4✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
40 | if(p_mode != ConnectorMode::NO_MOCK && b){ |
| 116 | 20 | typename _TMockBackend::Message vecTmp; | |
| 117 |
1/1✓ Branch 1 taken 20 times.
|
20 | phoenix_copy<_TMockBackend, _TBackend>(vecTmp, msg); |
| 118 |
1/1✓ Branch 1 taken 20 times.
|
20 | b &= _TMockBackend::push(p_mockConnector, varName, vecTmp); |
| 119 | 20 | } | |
| 120 | 40 | return b; | |
| 121 | } | ||
| 122 | |||
| 123 | |||
| 124 | ///Pull a message from a server / client | ||
| 125 | /** @param varName : name of the variable which is pushed | ||
| 126 | * @param[out] msg : pulled message | ||
| 127 | * @return true on success, false otherwise | ||
| 128 | */ | ||
| 129 | template<typename _TBackend, typename _TMockBackend> | ||
| 130 | bool PAbstractConnector<_TBackend, _TMockBackend>::pullMsg(const std::string & varName, typename _TBackend::Message & msg){ | ||
| 131 | bool b(true); | ||
| 132 | if(p_mode != ConnectorMode::MOCK){ | ||
| 133 | b &= _TBackend::pull(p_connector, varName, msg); | ||
| 134 | } | ||
| 135 | if(p_mode == ConnectorMode::MOCK){ | ||
| 136 | typename _TMockBackend::Message vecTmp; | ||
| 137 | if(_TMockBackend::pull(p_mockConnector, varName, vecTmp)){ | ||
| 138 | phoenix_copy<_TBackend, _TMockBackend>(msg, vecTmp); | ||
| 139 | } | ||
| 140 | }else if(p_mode == ConnectorMode::MOCK_RECORD){ | ||
| 141 | typename _TMockBackend::Message vecTmp; | ||
| 142 | phoenix_copy<_TMockBackend, _TBackend>(vecTmp, msg); | ||
| 143 | b &= _TMockBackend::pull(p_mockConnector, varName, vecTmp); //Save converted msg in mock pull | ||
| 144 | } | ||
| 145 | return b; | ||
| 146 | } | ||
| 147 | |||
| 148 | ///Call a method of a remote client/server | ||
| 149 | /** @param[out] methodCall : method to be called | ||
| 150 | * @return true on success, false otherwise | ||
| 151 | */ | ||
| 152 | template<typename _TBackend, typename _TMockBackend> | ||
| 153 | 20 | bool PAbstractConnector<_TBackend, _TMockBackend>::call(PFunctionCall & methodCall){ | |
| 154 | // std::string & functionName = methodCall.getPrototype().getName(); | ||
| 155 | // std::vector<typename _TBackend::Message> & vecParam = methodCall.getVecParam(); | ||
| 156 | // std::vector<typename _TBackend::Message> & vecResult = methodCall.getVecResult(); | ||
| 157 | |||
| 158 | 20 | bool b(true); | |
| 159 |
1/2✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
|
20 | if(p_mode != ConnectorMode::MOCK){ |
| 160 | 20 | b &= _TBackend::call(p_connector, methodCall); | |
| 161 | } | ||
| 162 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if(p_mode == ConnectorMode::MOCK){ |
| 163 | //Convert backend message to mock message for param | ||
| 164 | // std::vector<typename _TMockBackend::Message> vecMockParam, vecMockResult; | ||
| 165 | // phoenix_copy<_TMockBackend, _TBackend>(vecMockParam, vecParam); | ||
| 166 | ✗ | b &= _TMockBackend::call(p_connector, methodCall); | |
| 167 | // if(b){ //If the call is a success, let's copy the result back into the backend | ||
| 168 | // phoenix_copy<_TBackend, _TMockBackend>(vecResult, vecMockResult); | ||
| 169 | // } | ||
| 170 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
20 | }else if(p_mode == ConnectorMode::MOCK_RECORD){ |
| 171 | //Convert backend message to mock message for param | ||
| 172 | // std::vector<typename _TMockBackend::Message> vecMockParam, vecMockResult; | ||
| 173 | // phoenix_copy<_TMockBackend, _TBackend>(vecMockParam, vecParam); //Get param from backend | ||
| 174 | // phoenix_copy<_TMockBackend, _TBackend>(vecMockResult, vecResult); //Get result from backend | ||
| 175 | 10 | b &= _TMockBackend::call(p_mockConnector, methodCall); | |
| 176 | } | ||
| 177 | 20 | return b; | |
| 178 | } | ||
| 179 | |||
| 180 | ///Set the pointer to the map of internal varaibles the Connector can use | ||
| 181 | /** @param mapInternalVar : pointer to the map of internal varaibles the Connector can use | ||
| 182 | */ | ||
| 183 | template<typename _TBackend, typename _TMockBackend> | ||
| 184 | 25 | void PAbstractConnector<_TBackend, _TMockBackend>::setMapInternalVarPtr(std::map<std::string, PGenericInternalVar<_TBackend, _TMockBackend>* > * mapInternalVar){ | |
| 185 | 25 | p_mapInternalVar = mapInternalVar; | |
| 186 | 25 | } | |
| 187 | |||
| 188 | ///Initialisation function of the class PAbstractConnector | ||
| 189 | /** @param mode : Mode of the Connector (no mock, mock, mock_record) | ||
| 190 | * @param mockParam : parameters of the mock backend | ||
| 191 | * @param manager : pointer to the manager data | ||
| 192 | * @param mockManager : pointer to the mock manager data | ||
| 193 | */ | ||
| 194 | template<typename _TBackend, typename _TMockBackend> | ||
| 195 | 25 | void PAbstractConnector<_TBackend, _TMockBackend>::initialisationPAbstractConnector(ConnectorMode::ConnectorMode mode, const typename _TMockBackend::Param & mockParam, typename _TBackend::Manager * manager, typename _TMockBackend::Manager * mockManager){ | |
| 196 | 25 | p_mode = mode; | |
| 197 | 25 | p_mockParam = mockParam; | |
| 198 | 25 | p_mapInternalVar = NULL; | |
| 199 | 25 | p_manager = manager; | |
| 200 | 25 | p_mockManager = mockManager; | |
| 201 | 25 | } | |
| 202 | |||
| 203 | |||
| 204 | |||
| 205 | |||
| 206 | |||
| 207 | #endif | ||
| 208 | |||
| 209 | |||
| 210 | |||
| 211 |