* limitations under the License.
*/
+#include "app-core-cpp/app_core_base.hh"
+
#include <aul.h>
#include <aul_app_lifecycle.h>
#include <aul_watchdog.h>
#include <bundle_internal.h>
#include <dlfcn.h>
#include <errno.h>
-#include <execinfo.h>
#include <gio/gio.h>
+#include <glib-unix.h>
#include <glib.h>
#include <libintl.h>
#include <linux/limits.h>
#include <utility>
#include <vector>
-#include "app-core-cpp/app_core_base.hh"
+#include "app-core-cpp/app_core_plugin_private.hh"
+#include "app-core-cpp/exit_handler_private.hh"
+#include "app-core-cpp/sigterm_handler_private.hh"
#include "common/glib_private.hh"
#include "common/log_private.hh"
+#include "common/log_tracer.hh"
extern "C" void aul_finalize();
namespace tizen_cpp {
namespace {
-constexpr const int BACKTRACE_BUFFER_SIZE = 128;
-
-class ExitHandler {
- public:
- ExitHandler() {
- on_exit(OnExit, this);
- }
-
- private:
- static void OnExit(int status, void *user_data) {
- if (status != 127)
- return;
-
- char* buffer[BACKTRACE_BUFFER_SIZE];
- int nptrs = backtrace(reinterpret_cast<void**>(buffer),
- BACKTRACE_BUFFER_SIZE);
- fprintf(stderr, "%s backtrace() returned %d addesses\n",
- __FUNCTION__, nptrs);
-
- // To print numbers, we use backtrace_symbols() instead of backtrace_symbols_fd().
- // If there is an issues related to the memory, we cannot use backtrace_symbols().
- // backtrace_symbols_fd(buffer, nptrs, STDERR_FILENO);
- char** strings = backtrace_symbols(reinterpret_cast<void**>(buffer), nptrs);
- if (strings == nullptr) {
- perror("backtrace_symbols");
- return;
- }
-
- Dl_info info;
- for (int i = 0; i < nptrs; ++i) {
- dladdr(buffer[i], &info);
- fprintf(stderr, "[%3d] %s %s\n",
- i, info.dli_sname ? info.dli_sname : "?", strings[i]);
- }
- free(strings);
-
- fprintf(stderr, "%s(%d) abort()\n", __FUNCTION__, __LINE__);
- abort();
- }
-};
-
-ExitHandler exit_handler;
+internal::ExitHandler exit_handler;
+internal::SigtermHandler sigterm_handler;
enum TizenProfile {
Unknown = 0x00,
static void ReceiveSuspendSignalCb(GDBusConnection*, const gchar*,
const gchar*, const gchar*, const gchar*, GVariant*, gpointer);
static void OnLowBatteryCb(keynode_t* key, void* data);
+ static void OnTimeZoneChangedCb(keynode_t* key, void* data);
static void LockCb(keynode_t* node, void* user_data);
static void AutoRotationChangedCb(sensor_t sensor, unsigned int event_type,
sensor_data_t* data, void* user_data);
void VerifyLanguage();
void SetDefaultEvents();
void UnsetDefaultEvents();
+ void PluginInit(int argc, char** argv);
+ void PluginFini();
private:
friend class AppCoreBase;
int feature_ = 0;
IAppCore* core_delegator_ = nullptr;
IMainLoop* loop_delegator_ = nullptr;
+ guint signal_handler_source_ = 0;
+ std::unique_ptr<AppCorePlugin> plugin_;
};
AppCoreBase::EventBase::EventBase(Type type)
GError* err = nullptr;
__bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);
if (__bus == nullptr) {
- _E("Failed to connect to the D-BUS daemon: %s", err->message);
- g_error_free(err);
+ _E("Failed to connect to the D-BUS daemon: %s", err ? err->message : "");
+ if (err)
+ g_error_free(err);
+
return;
}
}
}
}
+void AppCoreBase::Impl::OnTimeZoneChangedCb(keynode_t* key, void* data) {
+ char* time_zone_id = vconf_keynode_get_str(key);
+ if (time_zone_id == nullptr) {
+ return;
+ }
+
+ char* time_zone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_INT);
+ if (time_zone != nullptr) {
+ AppCoreBase* base = reinterpret_cast<AppCoreBase*>(data);
+ base->impl_->InvokeCallback(std::string(time_zone) + "|" + time_zone_id,
+ IEvent::Type::TIME_ZONE_CHANGED);
+ free(time_zone);
+ }
+}
+
void AppCoreBase::Impl::UnregisterRotationChangedEvent() {
if (!__rotation.ref)
return;
break;
case IEvent::Type::SUSPENDED_STATE_CHANGE:
break;
+ case IEvent::Type::TIME_ZONE_CHANGED:
+ vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_ID,
+ impl_->OnTimeZoneChangedCb, this);
+ break;
default:
break;
}
}
void AppCoreBase::Init(int argc, char** argv) {
+ LogTracer tracer("AppCoreBase::Init()");
impl_->tid_ = 0;
impl_->suspended_state_ = false;
impl_->allowed_bg_ = false;
impl_->argc_ = argc;
impl_->argv_ = argv;
traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:OPS_INIT");
+ sigterm_handler.Restore();
if (impl_->loop_delegator_)
impl_->loop_delegator_->OnLoopInit(argc, argv);
else
OnLoopInit(argc, argv);
- signal(SIGTERM, [](int n) {
- _W("sigterm handler");
- if (context_ != nullptr)
- context_->Exit();
- });
+ impl_->signal_handler_source_ = g_unix_signal_add(SIGTERM,
+ [](gpointer data) -> gboolean {
+ _W("sigterm handler");
+ if (context_ != nullptr) {
+ context_->Exit();
+ context_->impl_->signal_handler_source_ = 0;
+ }
+
+ return G_SOURCE_REMOVE;
+ }, nullptr);
+
+ if (impl_->signal_handler_source_ == 0)
+ _E("Failed to add sigterm handler.");
+
+ traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
+ traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:PLUGIN_INIT");
+ impl_->PluginInit(argc, argv);
traceEnd(TTRACE_TAG_APPLICATION_MANAGER);
if (impl_->feature_ & FEATURE_BACKGROUND_MANAGEMENT)
}
void AppCoreBase::Fini() {
+ LogTracer tracer("AppCoreBase::Fini()");
+ if (impl_->signal_handler_source_) {
+ g_source_remove(impl_->signal_handler_source_);
+ impl_->signal_handler_source_ = 0;
+ }
+
Dispose();
}
}
RemoveSuspendTimer();
+ impl_->PluginFini();
impl_->dirty_ = false;
if (impl_->loop_delegator_)
impl_->loop_delegator_->OnLoopFinish();
return impl_->feature_;
}
+void AppCoreBase::Impl::PluginInit(int argc, char** argv) {
+ plugin_.reset(AppCorePlugin::Load());
+ if (!plugin_)
+ return;
+
+ plugin_->Init(argc, argv);
+}
+
+void AppCoreBase::Impl::PluginFini() {
+ if (!plugin_)
+ return;
+
+ plugin_->Fini();
+}
+
} // namespace tizen_cpp