#ifndef __SERVICE_MAIN_H__
#define __SERVICE_MAIN_H__
+#include <chrono>
#include <string>
#include <vector>
IPreferenceManager& mPreferenceManager;
pid_t mLastDuckingRequester{-1};
+
+ std::chrono::time_point<std::chrono::steady_clock> mStartedTime;
};
#endif /* __SERVICE_MAIN_H__ */
#include <string.h>
#include <glib.h>
-#include <chrono>
#include <ctime>
#include <list>
#include <sstream>
+#include <thread>
#include <tuple>
#include <vector>
// Todo: add your code here.
MAS_LOGE("[ENTER] Service app create");
+ mStartedTime = std::chrono::steady_clock::now();
g_service_main = this;
mClientManager.set_application_manager(&mApplicationManager);
void CServiceMain::app_restart()
{
+ MAS_LOGE("[ENTER]");
+
+ /* It would be best if we could sleep only when the current restart request
+ * is the 5th operation within 10 seconds, however we don't have a way to
+ * determine the number of restart operations since such information has to be
+ * stored externally but there isn't appropriate place to store it at the moment. */
+ const std::chrono::seconds minimum_interval(3);
+ auto interval = std::chrono::steady_clock::now() - mStartedTime;
+ if (interval < minimum_interval) {
+ MAS_LOGE("sleeping for %lld ms",
+ std::chrono::duration_cast<std::chrono::milliseconds>(minimum_interval - interval).count());
+ std::this_thread::sleep_for(minimum_interval - interval);
+ } else {
+ MAS_LOGE("interval is %lld ms, no need to sleep",
+ std::chrono::duration_cast<std::chrono::milliseconds>(interval).count());
+ }
mServiceIpc.send_restart_notification();
+
service_app_exit();
}