#include <aul_app_lifecycle.h>
#include <dlog.h>
+#include <list>
#include <memory>
#include <string>
};
std::unique_ptr<AppCore> __context;
+std::list<std::shared_ptr<AppCoreBase::EventBase>> __event_list;
int __on_control(bundle* b, void* data) {
return appcore_base_on_control(b);
int argc, char** argv, void* data) {
__context.reset(new AppCore(ops, data));
try {
+ for (auto& event : __event_list)
+ __context->AddEvent(std::move(event));
+
+ __event_list.clear();
__context->Init(argc, argv);
} catch (const std::runtime_error&) {
return -1;
enum appcore_base_event event,
appcore_base_event_cb cb,
void* data) {
- if (__context == nullptr)
- return nullptr;
-
auto* ev = new std::shared_ptr<AppCore::AppCoreEvent>(
std::make_shared<AppCore::AppCoreEvent>(event, cb, data));
if (ev == nullptr)
return nullptr;
- __context->AddEvent(*ev);
+ if (__context == nullptr) {
+ __event_list.push_back(*ev);
+ } else {
+ __context->AddEvent(*ev);
+ }
+
return static_cast<appcore_base_event_h>(ev);
}
extern "C" EXPORT_API int appcore_base_remove_event(
appcore_base_event_h handle) {
auto* ev = static_cast<std::shared_ptr<AppCoreBase::EventBase>*>(handle);
- if (ev == nullptr || __context == nullptr)
+ if (ev == nullptr)
return -1;
- bool ret = __context->RemoveEvent(*ev);
+ int ret;
+ if (__context == nullptr) {
+ ret = -1;
+ for (auto it = __event_list.begin(); it != __event_list.end(); ++it) {
+ if (*it == *ev) {
+ it = __event_list.erase(it);
+ ret = 0;
+ break;
+ }
+ }
+ } else {
+ ret = (__context->RemoveEvent(*ev) ? 0 : -1);
+ }
+
delete ev;
- return ret ? 0 : -1;
+ return ret;
}
extern "C" DEPRECATED EXPORT_API int appcore_base_raise_event(