diff --git a/libextsupport/GetServiceSupport.h b/libextsupport/GetServiceSupport.h index 11e0090..fe65246 100644 --- a/libextsupport/GetServiceSupport.h +++ b/libextsupport/GetServiceSupport.h @@ -1,3 +1,6 @@ +#include +#include + #include #include @@ -17,3 +20,24 @@ static inline std::shared_ptr getServiceDefault(void) { return getService(std::string() + T::descriptor + "/default"); } + +template +static std::shared_ptr waitServiceDefault(int retries = 5) +{ + std::shared_ptr kService = nullptr; + const auto kServiceDesc = std::string() + T::descriptor + "/default"; + + // If not declared, just return null + if (AServiceManager_isDeclared(kServiceDesc.c_str())) { + do { + kService = getService(kServiceDesc); + if (kService == nullptr) { + std::this_thread::sleep_for(std::chrono::seconds(5)); + --retries; + } else { + break; + } + } while (retries > 0); + } + return kService; +}