Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reason for change : Replacing the stub functions introduced for handl… #2

Merged
merged 1 commit into from
Aug 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion ctrlm_vendor_network_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,44 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <glib.h>
#include <vector>
#include "ctrlm_vendor_network_factory.h"
#include "ctrlm_log.h"

// vector contains vendor's network factory functions
// vector is declared as pointer, because vendor's network factory initializers objects
// constructors might be called before vector constructor if declare it as object
typedef std::vector<ctrlm_vendor_network_factory_func_t*> ctrlm_vendor_network_factory_func_chain_t;
static ctrlm_vendor_network_factory_func_chain_t* ctrlm_vendor_network_factory_func_chain = 0;

static class factory_chain_garbage_collector {
public:
~factory_chain_garbage_collector(){
if (0 != ctrlm_vendor_network_factory_func_chain){
delete ctrlm_vendor_network_factory_func_chain;
ctrlm_vendor_network_factory_func_chain = 0;
}
}
} _garbage_collector;;

// vendors should add to chain network factory function their with this call
void ctrlm_vendor_network_factory_func_add(ctrlm_vendor_network_factory_func_t* func) {
if (0 == ctrlm_vendor_network_factory_func_chain){
ctrlm_vendor_network_factory_func_chain = new ctrlm_vendor_network_factory_func_chain_t;
}
ctrlm_vendor_network_factory_func_chain->push_back(func);
}


// by the time of this function call, ctrlm_vendor_network_factory_func_chain will be initialized with
// vendor factory functions
int ctrlm_vendor_network_factory(unsigned long ignore_mask, json_t *json_config_root, networks_map_t& networks) {
if (0 == ctrlm_vendor_network_factory_func_chain){
return 0;
}
for (auto factory_func : *ctrlm_vendor_network_factory_func_chain){
factory_func(ignore_mask, json_config_root, networks);
}
return networks.size();
}