3434#include < algorithm>
3535#include < iterator>
3636#include < regex>
37+ #include < unordered_map>
3738
3839using std::endl;
3940
@@ -62,6 +63,20 @@ int ProxyGenerator::transformXmlToFileImpl(const Document &doc, const char *file
6263 return writeToFile (filename, code.str ());
6364}
6465
66+ std::string prepareDefaultTimeout (const std::string& val, const std::string& unit)
67+ {
68+ const std::unordered_map<std::string, std::string> chronoTypes = {
69+ {" us" , " std::chrono::microseconds" },
70+ {" ms" , " std::chrono::milliseconds" },
71+ {" s" , " std::chrono::seconds" },
72+ {" min" , " std::chrono::minutes" }
73+ };
74+ const auto iter = chronoTypes.find (unit);
75+
76+ const std::string type = (iter != chronoTypes.end ()) ? iter->second : " std::chrono::microseconds" ;
77+ const std::string defaultValue = type + " (" + val + " )" ;
78+ return defaultValue;
79+ }
6580
6681std::string ProxyGenerator::processInterface (Node& interface) const
6782{
@@ -212,13 +227,16 @@ std::tuple<std::string, std::string> ProxyGenerator::processMethods(const Nodes&
212227 std::tie (outArgStr, outArgTypeStr, std::ignore, std::ignore) = argsToNamesAndTypes (outArgs);
213228
214229 const std::string realRetType = (async && !dontExpectReply ? (future ? " std::future<" + retType + " >" : " sdbus::PendingAsyncCall" ) : async ? " void" : retType);
215- definitionSS << tab << realRetType << " " << nameSafe << " (" << inArgTypeStr << " )" << endl
216- << tab << " {" << endl;
217230
231+ std::string timeoutDefaultValue;
218232 if (!timeoutValue.empty ())
219233 {
220- definitionSS << tab << tab << " using namespace std::chrono_literals;" << endl;
234+ const auto val = smTimeout.str (1 );
235+ const auto unit = smTimeout.str (2 );
236+ timeoutDefaultValue = prepareDefaultTimeout (val, unit);
221237 }
238+ definitionSS << tab << realRetType << " " << nameSafe << " (" << inArgTypeStr << (!timeoutDefaultValue.empty () ? " , const std::chrono::microseconds& timeout = " + timeoutDefaultValue : " " ) << " )" << endl
239+ << tab << " {" << endl;
222240
223241 if (outArgs.size () > 0 && !async)
224242 {
@@ -230,9 +248,7 @@ std::tuple<std::string, std::string> ProxyGenerator::processMethods(const Nodes&
230248
231249 if (!timeoutValue.empty ())
232250 {
233- const auto val = smTimeout.str (1 );
234- const auto unit = smTimeout.str (2 );
235- definitionSS << " .withTimeout(" << val << (unit.empty () ? " us" : unit) << " )" ;
251+ definitionSS << " .withTimeout(" << " timeout" << " )" ;
236252 }
237253
238254 if (inArgs.size () > 0 )
0 commit comments