#include <dali-test-suite-utils.h>
#include <dali/devel-api/common/stage-devel.h>
+#include <dali/devel-api/threading/thread.h>
#include <dali/integration-api/context-notifier.h>
#include <dali/integration-api/events/key-event-integ.h>
#include <dali/integration-api/events/touch-event-integ.h>
#include <dali/public-api/dali-core.h>
#include <dali/public-api/events/key-event.h>
#include <stdlib.h>
+#include <unistd.h>
#include <iostream>
application.ProcessEvent(touchEvent);
}
+volatile bool gRunThreadEntryFunc = false;
+
+class TestThread : public Dali::Thread
+{
+public:
+ TestThread()
+ : mCallback(nullptr)
+ {
+ }
+ TestThread(Dali::CallbackBase* callback)
+ : mCallback(callback)
+ {
+ }
+
+ ~TestThread()
+ {
+ delete mCallback;
+ }
+
+ virtual void Run()
+ {
+ if(mCallback)
+ {
+ Dali::CallbackBase::Execute(*mCallback);
+ }
+
+ gRunThreadEntryFunc = true;
+ }
+
+private:
+ Dali::CallbackBase* mCallback{nullptr};
+};
+
+void CoreThreadCheck()
+{
+ DALI_TEST_CHECK(!Stage::IsCoreThread());
+}
+
} // unnamed namespace
int UtcDaliStageDefaultConstructorP(void)
END_TEST;
}
+int UtcDaliStageIsShuttingDown(void)
+{
+ DALI_TEST_CHECK(!Stage::IsShuttingDown());
+
+ {
+ TestApplication application;
+
+ DALI_TEST_CHECK(!Stage::IsShuttingDown());
+
+ Stage::GetCurrent();
+
+ DALI_TEST_CHECK(!Stage::IsShuttingDown());
+ }
+
+ // Core destroyed
+ DALI_TEST_CHECK(Stage::IsShuttingDown());
+ END_TEST;
+}
+
+int UtcDaliStageIsCoreThread(void)
+{
+ DALI_TEST_CHECK(!Stage::IsCoreThread());
+
+ {
+ TestApplication application;
+
+ DALI_TEST_CHECK(Stage::IsCoreThread());
+
+ Stage::GetCurrent();
+
+ DALI_TEST_CHECK(Stage::IsCoreThread());
+
+ TestThread thread(Dali::MakeCallback(&CoreThreadCheck));
+
+ gRunThreadEntryFunc = false;
+
+ thread.Start();
+ // wait till the thread is terminated
+ while(!gRunThreadEntryFunc)
+ {
+ usleep(1); // 1 microsecond
+ }
+ DALI_TEST_EQUALS(true, gRunThreadEntryFunc, TEST_LOCATION);
+
+ thread.Join();
+ }
+
+ // Core destroyed
+ DALI_TEST_CHECK(Stage::IsCoreThread());
+ END_TEST;
+}
+
+
int UtcDaliStageCopyConstructorP(void)
{
TestApplication application;
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return Internal::Stage::IsInstalled();
}
+bool Stage::IsShuttingDown()
+{
+ return Internal::Stage::IsShuttingDown();
+}
+
+bool Stage::IsCoreThread()
+{
+ return IsInstalled() || ///< Check if Core is installed now,
+ IsShuttingDown(); ///< or Core is shutting down now.
+}
+
void Stage::Add(Actor& actor)
{
GetImplementation(*this).Add(GetImplementation(actor));
#define DALI_STAGE_H
/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
static bool IsInstalled();
+ /**
+ * @brief Queries whether the Stage shutting down now; this should only return false during or before destruction of Dali core.
+ *
+ * @return True when Dali core destructor called.
+ */
+ static bool IsShuttingDown();
+
+ /**
+ * @brief Queries whether we installed Dali core before, or not.
+ * It will be useful whether you want to check we are on valid core ui thread or not, after Core initalized ensured.
+ *
+ * @return True when this API called at core ui thread. False otherwise.
+ */
+ static bool IsCoreThread();
+
/**
* @brief Destructor.
*