MCPcopy Create free account
hub / github.com/NetSys/bess / CreateModule

Method CreateModule

core/module_graph.cc:246–286  ·  view source on GitHub ↗

Creates a module to the graph.

Source from the content-addressed store, hash-verified

244
245// Creates a module to the graph.
246Module *ModuleGraph::CreateModule(const ModuleBuilder &builder,
247 const std::string &module_name,
248 const google::protobuf::Any &arg,
249 pb_error_t *perr) {
250 Module *m =
251 builder.CreateModule(module_name, &bess::metadata::default_pipeline);
252
253 CommandResponse ret = m->InitWithGenericArg(arg);
254 {
255 google::protobuf::Any empty;
256
257 if (ret.data().SerializeAsString() != empty.SerializeAsString()) {
258 LOG(WARNING) << module_name << "::" << builder.class_name()
259 << " Init() returned non-empty response: "
260 << ret.data().DebugString();
261 }
262 }
263
264 if (ret.error().code() != 0) {
265 *perr = ret.error();
266 delete m;
267 return nullptr;
268 }
269
270 if (m->is_task()) {
271 if (!tasks_.insert(m->name()).second) {
272 *perr = pb_errno(ENOMEM);
273 delete m;
274 return nullptr;
275 }
276 }
277
278 bool module_added = all_modules_.insert({m->name(), m}).second;
279 if (!module_added) {
280 *perr = pb_errno(ENOMEM);
281 delete m;
282 return nullptr;
283 }
284
285 return m;
286}
287
288void ModuleGraph::DestroyModule(Module *m, bool erase) {
289 changes_made_ = true;

Callers

nothing calls this directly

Calls 4

pb_errnoFunction · 0.85
dataMethod · 0.80
is_taskMethod · 0.80
InitWithGenericArgMethod · 0.45

Tested by

no test coverage detected