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

Method processInterface

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

Source from the content-addressed store, hash-verified

65
66
67std::string AdaptorGenerator::processInterface(Node& interface) const
68{
69 std::string ifaceName = interface.get("name");
70 std::cout << "Generating adaptor code for interface " << ifaceName << endl;
71
72 unsigned int namespacesCount = 0;
73 std::string namespacesStr;
74 std::tie(namespacesCount, namespacesStr) = generateNamespaces(ifaceName);
75
76 std::ostringstream body;
77 body << namespacesStr;
78
79 std::string className = ifaceName.substr(ifaceName.find_last_of(".") + 1)
80 + "_adaptor";
81
82 body << "class " << className << endl
83 << "{" << endl
84 << "public:" << endl
85 << tab << "static constexpr const char* INTERFACE_NAME = \"" << ifaceName << "\";" << endl << endl
86 << "protected:" << endl
87 << tab << className << "(sdbus::IObject& object)" << endl
88 << tab << tab << ": m_object(object)" << endl
89 << tab << "{" << endl
90 << tab << "}" << endl << endl;
91
92 // Rule of Five
93 body << tab << className << "(const " << className << "&) = delete;" << endl;
94 body << tab << className << "& operator=(const " << className << "&) = delete;" << endl;
95 body << tab << className << "(" << className << "&&) = delete;" << endl;
96 body << tab << className << "& operator=(" << className << "&&) = delete;" << endl << endl;
97
98 body << tab << "~" << className << "() = default;" << endl << endl;
99
100 Nodes methods = interface["method"];
101 Nodes signals = interface["signal"];
102 Nodes properties = interface["property"];
103
104 auto annotations = getAnnotations(interface);
105 std::string annotationRegistration;
106 for (const auto& annotation : annotations)
107 {
108 const auto& annotationName = annotation.first;
109 const auto& annotationValue = annotation.second;
110
111 if (annotationName == "org.freedesktop.DBus.Deprecated" && annotationValue == "true")
112 annotationRegistration += ".markAsDeprecated()";
113 else if (annotationName == "org.freedesktop.systemd1.Privileged" && annotationValue == "true")
114 annotationRegistration += ".markAsPrivileged()";
115 else if (annotationName == "org.freedesktop.DBus.Property.EmitsChangedSignal")
116 annotationRegistration += ".withPropertyUpdateBehavior(" + propertyAnnotationToFlag(annotationValue) + ")";
117 else
118 std::cerr << "Node: " << ifaceName << ": "
119 << "Option '" << annotationName << "' not allowed or supported in this context! Option ignored..." << std::endl;
120 }
121 if(!annotationRegistration.empty())
122 {
123 std::stringstream str;
124 str << "sdbus::setInterfaceFlags()" << annotationRegistration;

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected