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

Method processMethods

tools/xml2cpp-codegen/ProxyGenerator.cpp:150–303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148}
149
150std::tuple<std::string, std::string> ProxyGenerator::processMethods(const Nodes& methods) const
151{
152 const std::regex patternTimeout{R"(^(\d+)(min|s|ms|us)?$)"};
153
154 std::ostringstream definitionSS, asyncDeclarationSS;
155
156 for (const auto& method : methods)
157 {
158 auto name = method->get("name");
159 auto nameSafe = mangle_name(name);
160 Nodes args = (*method)["arg"];
161 Nodes inArgs = args.select("direction" , "in");
162 Nodes outArgs = args.select("direction" , "out");
163
164 bool dontExpectReply{false};
165 std::optional<AsyncImpl> asyncImpl;
166 std::string timeoutValue;
167 std::smatch smTimeout;
168
169 Nodes annotations = (*method)["annotation"];
170 for (const auto& annotation : annotations)
171 {
172 const auto annotationName = annotation->get("name");
173 const auto annotationValue = annotation->get("value");
174
175 if (annotationName == "org.freedesktop.DBus.Method.NoReply" && annotationValue == "true")
176 dontExpectReply = true;
177 else
178 {
179 if (annotationName == "org.freedesktop.DBus.Method.Async"
180 && (annotationValue == "client" || annotationValue == "clientserver" || annotationValue == "client-server"))
181 asyncImpl = AsyncImpl::Callback; // Default to callback
182 else if (annotationName == "org.freedesktop.DBus.Method.Async.ClientImpl" && annotationValue == "callback")
183 asyncImpl = AsyncImpl::Callback;
184 else if (annotationName == "org.freedesktop.DBus.Method.Async.ClientImpl" && (annotationValue == "future" || annotationValue == "std::future"))
185 asyncImpl = AsyncImpl::Future;
186 else if (annotationName == "org.freedesktop.DBus.Method.Async.ClientImpl" && (annotationValue == "awaitable" || annotationValue == "coroutine"))
187 asyncImpl = AsyncImpl::Awaitable;
188 }
189 if (annotationName == "org.freedesktop.DBus.Method.Timeout")
190 timeoutValue = annotationValue;
191 }
192 if (dontExpectReply && outArgs.size() > 0)
193 {
194 std::cerr << "Function: " << name << ": ";
195 std::cerr << "Option 'org.freedesktop.DBus.Method.NoReply' not allowed for methods with 'out' variables! Option ignored..." << std::endl;
196 dontExpectReply = false;
197 }
198 if (!timeoutValue.empty() && dontExpectReply)
199 {
200 std::cerr << "Function: " << name << ": ";
201 std::cerr << "Option 'org.freedesktop.DBus.Method.Timeout' not allowed for 'NoReply' methods! Option ignored..." << std::endl;
202 timeoutValue.clear();
203 }
204
205 if (!timeoutValue.empty() && !std::regex_match(timeoutValue, smTimeout, patternTimeout))
206 {
207 std::cerr << "Function: " << name << ": ";

Callers

nothing calls this directly

Calls 4

mangle_nameFunction · 0.85
selectMethod · 0.80
getMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected