MCPcopy Create free account
hub / github.com/Kistler-Group/sdbus-cpp / processSignals

Method processSignals

tools/xml2cpp-codegen/AdaptorGenerator.cpp:258–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256
257
258std::tuple<std::vector<std::string>, std::string> AdaptorGenerator::processSignals(const Nodes& signals) const
259{
260 std::ostringstream signalMethodSS;
261
262 std::vector<std::string> signalRegistrations;
263
264 for (const auto& signal : signals)
265 {
266 std::stringstream signalRegistrationSS;
267
268 auto name = signal->get("name");
269
270 auto annotations = getAnnotations(*signal);
271 std::string annotationRegistration;
272 for (const auto& annotation : annotations)
273 {
274 const auto& annotationName = annotation.first;
275 const auto& annotationValue = annotation.second;
276
277 if (annotationName == "org.freedesktop.DBus.Deprecated" && annotationValue == "true")
278 annotationRegistration += ".markAsDeprecated()";
279 else
280 std::cerr << "Node: " << name << ": "
281 << "Option '" << annotationName << "' not allowed or supported in this context! Option ignored..." << std::endl;
282 }
283
284 Nodes args = (*signal)["arg"];
285
286 std::string argStr, argTypeStr, typeStr, argStringsStr;
287 std::tie(argStr, argTypeStr, typeStr, argStringsStr) = argsToNamesAndTypes(args);
288
289 signalRegistrationSS << "sdbus::registerSignal(\"" << name << "\")";
290
291 if (args.size() > 0)
292 {
293 signalRegistrationSS << ".withParameters<" << typeStr << ">(" << argStringsStr << ")";
294 }
295
296 signalRegistrationSS << annotationRegistration;
297
298 signalRegistrations.push_back(signalRegistrationSS.str());
299
300 auto nameWithCapFirstLetter = name;
301 nameWithCapFirstLetter[0] = std::toupper(nameWithCapFirstLetter[0]);
302 nameWithCapFirstLetter = mangle_name(nameWithCapFirstLetter);
303
304 signalMethodSS << tab << "void emit" << nameWithCapFirstLetter << "(" << argTypeStr << ")" << endl
305 << tab << "{" << endl
306 << tab << tab << "m_object.emitSignal(\"" << name << "\")"
307 ".onInterface(INTERFACE_NAME)";
308
309 if (!argStr.empty())
310 {
311 signalMethodSS << ".withArguments(" << argStr << ")";
312 }
313
314 signalMethodSS << ";" << endl
315 << tab << "}" << endl << endl;

Callers

nothing calls this directly

Calls 3

mangle_nameFunction · 0.85
push_backMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected