/
registration.tmpl.cpp
129 lines (110 loc) · 5.35 KB
/
registration.tmpl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//this is a machine generated file...
#include <Pothos/Framework.hpp>
#include <Pothos/Proxy.hpp>
#include <gnuradio/block.h>
using namespace gr;
/***********************************************************************
* include block definitions
**********************************************************************/
% for header in headers:
#include "${header}"
% endfor
/***********************************************************************
* make GrPothosBlock wrapper with a gr::block
**********************************************************************/
template <typename BlockType>
std::shared_ptr<Pothos::Block> makeGrPothosBlock(boost::shared_ptr<BlockType> block, size_t vlen, const Pothos::DType& overrideDType)
{
auto block_ptr = boost::dynamic_pointer_cast<gr::block>(block);
auto env = Pothos::ProxyEnvironment::make("managed");
auto registry = env->findProxy("Pothos/BlockRegistry");
return registry.call<std::shared_ptr<Pothos::Block>>("/gnuradio/block", block_ptr, vlen, overrideDType);
}
/***********************************************************************
* create block factories
**********************************************************************/
// To disambiguate
using DeclareSampleDelayPtr = void(gr::block::*)(unsigned);
% for factory in factories:
% for ns in factory.namespace.split("::"):
namespace ${ns} {
% endfor
std::shared_ptr<Pothos::Block> factory__${factory.name}(${factory.exported_factory_args})
{
auto __orig_block = ${factory.factory_function_path}(${factory.internal_factory_args});
auto __pothos_block = makeGrPothosBlock(__orig_block, ${factory.vlen}, ${factory.dtype});
auto __orig_block_ref = std::ref(*static_cast<${factory.namespace}::${factory.className} *>(__orig_block.get()));
% if factory.block_methods:
% endif
% for method in factory.block_methods:
__pothos_block->registerCallable("${method.name}", Pothos::Callable(&${factory.namespace}::${factory.className}::${method.name}).bind(__orig_block_ref, 0));
% if not method.parameters and method.name not in ["start", "stop"]:
__pothos_block->registerProbe("${method.name}", "${method.name}_triggered", "probe_${method.name}");
%endif
% endfor
__pothos_block->registerCallable("declare_sample_delay", Pothos::Callable((DeclareSampleDelayPtr)&${factory.namespace}::${factory.className}::declare_sample_delay).bind(__orig_block_ref, 0));
__pothos_block->registerCallable("tag_propagation_policy", Pothos::Callable(&${factory.namespace}::${factory.className}::tag_propagation_policy).bind(__orig_block_ref, 0));
__pothos_block->registerCallable("set_tag_propagation_policy", Pothos::Callable(&${factory.namespace}::${factory.className}::set_tag_propagation_policy).bind(__orig_block_ref, 0));
return __pothos_block;
}
% for ns in factory.namespace.split("::"):
} //namespace $ns
% endfor
% endfor
/***********************************************************************
* meta block factories
**********************************************************************/
% for factory in meta_factories:
% for ns in factory.namespace.split("::"):
namespace ${ns} {
% endfor
std::shared_ptr<Pothos::Block> factory__${factory.name}(${factory.exported_factory_args})
{
% for sub_factory in factory.sub_factories:
if (${factory.type_key} == "${sub_factory.name}") return factory__${sub_factory.name}(${sub_factory['internal_factory_args']});
% endfor
throw Pothos::RuntimeException("${factory.name} unknown type: "+${factory.type_key});
}
% for ns in factory.namespace.split("::"):
} //namespace $ns
% endfor
% endfor
/***********************************************************************
* register block factories
**********************************************************************/
% for registration in registrations:
static Pothos::BlockRegistry register__${registration.name}("${registration.path}", &${registration.namespace}::factory__${registration.name});
% endfor
/***********************************************************************
* enum conversions
**********************************************************************/
% for enum in enums:
${enum.namespace}${enum.name} int_to_${enum.name}(const int v)
{
return ${enum.namespace}${enum.name}(v);
}
${enum.namespace}${enum.name} string_to_${enum.name}(const std::string &s)
{
% for value in enum['values']:
if (s == "${value['name']}") return ${enum.namespace}${value['name']};
% endfor
throw Pothos::RuntimeException("convert string to ${enum.name} unknown value: "+s);
}
% endfor
/***********************************************************************
* register block descriptions and conversions
**********************************************************************/
#include <Pothos/Plugin.hpp>
pothos_static_block(registerGrPothosUtilBlockDocs)
{
% for path, blockDesc in blockDescs.items():
<%
escaped = ''.join([hex(ord(ch)).replace('0x', '\\x') for ch in blockDesc])
%>
Pothos::PluginRegistry::add("/blocks/docs${path}", std::string("${escaped}"));
% endfor
% for enum in enums:
Pothos::PluginRegistry::add("/object/convert/gr_enums/int_to_${enum.namespace.replace('::', '_')}${enum.name}", Pothos::Callable(&int_to_${enum.name}));
Pothos::PluginRegistry::add("/object/convert/gr_enums/string_to_${enum.namespace.replace('::', '_')}${enum.name}", Pothos::Callable(&string_to_${enum.name}));
% endfor
}