quic/qbox
Loading...
Searching...
No Matches
module_factory_registery.h
1/*
2 * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef GREENSOCS_MODULE_FACTORY_REG_H
8#define GREENSOCS_MODULE_FACTORY_REG_H
9
10#define CCI_GS_MF_NAME "__GS.ModuleFactory."
11
12#include <cciutils.h>
13
19namespace gs {
20namespace ModuleFactory {
21std::vector<std::function<cci::cci_param<gs::cci_constructor_vl>*()>>* GetAvailableModuleList();
22
24 ModuleRegistrationWrapper(std::function<cci::cci_param<gs::cci_constructor_vl>*()> fn)
25 {
26 auto mods = gs::ModuleFactory::GetAvailableModuleList();
27 mods->push_back(fn);
28 }
29};
30} // namespace ModuleFactory
31} // namespace gs
37template <>
38struct cci::cci_value_converter<gs::cci_constructor_vl> {
40 static bool pack(cci::cci_value::reference dst, type const& src)
41 {
42 dst.set_string(src.type);
43 return true;
44 }
45 static bool unpack(type& dst, cci::cci_value::const_reference src)
46 {
47 if (!src.is_string()) {
48 return false;
49 }
50 std::string moduletype;
51 if (!src.try_get(moduletype)) {
52 return false;
53 }
54 cci::cci_param_typed_handle<gs::cci_constructor_vl> m_fac(
55 cci::cci_get_broker().get_param_handle(CCI_GS_MF_NAME + moduletype));
56 if (!m_fac.is_valid()) {
57 return false;
58 }
59 dst = *m_fac;
60
61 return true;
62 }
63};
64#define GSC_MODULE_REGISTER(__NAME__, ...) \
65 struct GS_MODULEFACTORY_moduleReg_##__NAME__ { \
66 static gs::ModuleFactory::ModuleRegistrationWrapper& get() \
67 { \
68 static gs::ModuleFactory::ModuleRegistrationWrapper inst([]() -> cci::cci_param<gs::cci_constructor_vl>* { \
69 return new cci::cci_param<gs::cci_constructor_vl>( \
70 CCI_GS_MF_NAME #__NAME__, \
71 gs::cci_constructor_vl::FactoryMaker<__NAME__, ##__VA_ARGS__>(#__NAME__), "default constructor", \
72 cci::CCI_ABSOLUTE_NAME); \
73 }); \
74 return inst; \
75 } \
76 }; \
77 static struct gs::ModuleFactory::ModuleRegistrationWrapper& \
78 GS_MODULEFACTORY_moduleReg_inst_##__NAME__ = GS_MODULEFACTORY_moduleReg_##__NAME__::get()
79
80// This will create a memory leak to all the constructors parameters behond the lifetime of the dynamic library
81#define GSC_MODULE_REGISTER_C(__NAME__, ...) \
82 cci::cci_param<gs::cci_constructor_vl>* module_construct_param##__NAME__ = new cci::cci_param<gs::cci_constructor_vl>( \
83 CCI_GS_MF_NAME #__NAME__, gs::cci_constructor_vl::FactoryMaker<__NAME__, ##__VA_ARGS__>(#__NAME__), \
84 "default constructor", cci::CCI_ABSOLUTE_NAME)
85
86#endif
Definition target.h:160
sc_module constructor container for CCI This uses the CCI Function container, and the FactoryMaker in...
Definition cciutils.h:59
Tool which reads a Lua configuration file and sets parameters.
Definition biflow.cc:10
Definition module_factory_registery.h:23