From 9cfc2342991b6d847d2b5320549b25855b22376f Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Fri, 26 Jan 2024 13:14:12 +0900 Subject: [PATCH] Remove capi-system-info library dependency To remove capi-system-info dependency, the app-core-cpp removes using system-info library. Change-Id: I025c9b972a46aaaac480f6844cd428b446727a8f Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 1 - legacy/CMakeLists.txt | 2 +- legacy/src/legacy/appcore.c | 1 - packaging/app-core.spec | 1 - tizen-cpp/app-core-cpp/CMakeLists.txt | 1 - tizen-cpp/app-core-cpp/app_core_base.cc | 209 ++++-------------------- tizen-cpp/app-core-cpp/suspend_event_private.cc | 99 +++++++++++ tizen-cpp/app-core-cpp/suspend_event_private.hh | 55 +++++++ unittests/CMakeLists.txt | 1 - unittests/mock/dbus_mock.cc | 44 ++++- unittests/mock/dbus_mock.h | 25 ++- 11 files changed, 243 insertions(+), 196 deletions(-) create mode 100644 tizen-cpp/app-core-cpp/suspend_event_private.cc create mode 100644 tizen-cpp/app-core-cpp/suspend_event_private.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index a24831a..36b2ac0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,6 @@ INCLUDE(ApplyPkgConfig) PKG_CHECK_MODULES(AUL_DEPS REQUIRED aul) PKG_CHECK_MODULES(BUNDLE_DEPS REQUIRED bundle) -PKG_CHECK_MODULES(CAPI_SYSTEM_INFO_DEPS REQUIRED capi-system-info) PKG_CHECK_MODULES(DLOG_DEPS REQUIRED dlog) PKG_CHECK_MODULES(ECORE_DEPS REQUIRED ecore) PKG_CHECK_MODULES(ECORE_WL2_DEPS REQUIRED ecore-wl2) diff --git a/legacy/CMakeLists.txt b/legacy/CMakeLists.txt index d7dd697..f6b42b0 100644 --- a/legacy/CMakeLists.txt +++ b/legacy/CMakeLists.txt @@ -40,7 +40,7 @@ SET(HEADERS_common appcore_base_control.h) INCLUDE(FindPkgConfig) -SET(APPCORE_PKG_CHECK_MODULES "gio-2.0 vconf sensor aul dlog capi-system-info ttrace pkgmgr-info") +SET(APPCORE_PKG_CHECK_MODULES "gio-2.0 vconf sensor aul dlog ttrace pkgmgr-info") pkg_check_modules(pkg_common REQUIRED ${APPCORE_PKG_CHECK_MODULES}) diff --git a/legacy/src/legacy/appcore.c b/legacy/src/legacy/appcore.c index af0c251..81d36b8 100644 --- a/legacy/src/legacy/appcore.c +++ b/legacy/src/legacy/appcore.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include "appcore-internal.h" diff --git a/packaging/app-core.spec b/packaging/app-core.spec index 0eb502a..7a5e715 100644 --- a/packaging/app-core.spec +++ b/packaging/app-core.spec @@ -10,7 +10,6 @@ Source1001: app-core.manifest BuildRequires: cmake BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(bundle) -BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(ecore) BuildRequires: pkgconfig(ecore-wl2) diff --git a/tizen-cpp/app-core-cpp/CMakeLists.txt b/tizen-cpp/app-core-cpp/CMakeLists.txt index 61cd425..6f427fb 100644 --- a/tizen-cpp/app-core-cpp/CMakeLists.txt +++ b/tizen-cpp/app-core-cpp/CMakeLists.txt @@ -16,7 +16,6 @@ SET_TARGET_PROPERTIES(${TARGET_APP_CORE_CPP} PROPERTIES VERSION ${FULLVER}) APPLY_PKG_CONFIG(${TARGET_APP_CORE_CPP} PUBLIC AUL_DEPS BUNDLE_DEPS - CAPI_SYSTEM_INFO_DEPS DLOG_DEPS GIO_2_DEPS SENSOR_DEPS diff --git a/tizen-cpp/app-core-cpp/app_core_base.cc b/tizen-cpp/app-core-cpp/app_core_base.cc index eaf7f51..2e14d8a 100644 --- a/tizen-cpp/app-core-cpp/app_core_base.cc +++ b/tizen-cpp/app-core-cpp/app_core_base.cc @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -54,6 +53,7 @@ #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 "app-core-cpp/suspend_event_private.hh" #include "common/glib_private.hh" #include "common/log_private.hh" #include "common/log_tracer.hh" @@ -68,60 +68,8 @@ namespace { internal::ExitHandler exit_handler; internal::SigtermHandler sigterm_handler; -enum TizenProfile { - Unknown = 0x00, - Mobile = 0x01, - Wearable = 0x02, - Tv = 0x04, - Ivi = 0x08, - Common = 0x10, -}; - -TizenProfile TizenProfileGet() { - static TizenProfile profile = TizenProfile::Unknown; - if (__builtin_expect(profile != TizenProfile::Unknown, 1)) - return profile; - - char* profile_name = nullptr; - system_info_get_platform_string("http://tizen.org/feature/profile", - &profile_name); - if (profile_name == nullptr) - return profile; - - switch (*profile_name) { - case 'm': - case 'M': - profile = TizenProfile::Mobile; - break; - case 'w': - case 'W': - profile = TizenProfile::Wearable; - break; - case 't': - case 'T': - profile = TizenProfile::Tv; - break; - case 'i': - case 'I': - profile = TizenProfile::Ivi; - break; - default: - profile = TizenProfile::Common; - break; - } - free(profile_name); - - return profile; -} - constexpr const char PATH_LOCALE[] = "locale"; constexpr int SQLITE_FLUSH_MAX = 1024 * 1024; -constexpr const char RESOURCED_FREEZER_PATH[] = - "/Org/Tizen/ResourceD/Freezer"; -constexpr const char RESOURCED_FREEZER_INTERFACE[] = - "org.tizen.resourced.freezer"; -constexpr const char RESOURCED_FREEZER_SIGNAL[] = - "FreezerState"; struct Rotation { int conn; @@ -133,8 +81,6 @@ struct Rotation { }; Rotation __rotation; -GDBusConnection* __bus; -guint __suspend_dbus_handler_initialized; AppCoreBase::DisplayState __display_state = AppCoreBase::DISPLAY_STATE_UNKNOWN; } // namespace @@ -147,14 +93,9 @@ class AppCoreBase::EventBase::Impl { int val_ = -1; }; -class AppCoreBase::Impl { +class AppCoreBase::Impl : public SuspendEvent::IEventListener { public: - explicit Impl(AppCoreBase* parent) : parent_(parent) { - if (TizenProfileGet() & TizenProfile::Wearable) - feature_ |= FEATURE_CHARGER_STATUS; - if (!(TizenProfileGet() & TizenProfile::Tv)) - feature_ |= FEATURE_BACKGROUND_MANAGEMENT; - } + explicit Impl(AppCoreBase* parent) : parent_(parent) {} private: void UnregisterRotationChangedEvent(); @@ -188,17 +129,14 @@ class AppCoreBase::Impl { } } - static void InitSuspendDbusHandler(gpointer data); - static gboolean InitSuspendCb(gpointer data); + void InitSuspend(); + void OnSuspend(pid_t pid, int status) override; static gboolean InvokeLangChangeCb(gpointer data); - 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); - static void ChargerStatusChangedCb(keynode_t* keynode, void* user_data); static void LanguageChangeCb(keynode_t* key, void* data); static void RegionChangeCb(keynode_t* key, void* data); static void LowMemoryCb(keynode_t* key, void* data); @@ -229,6 +167,7 @@ class AppCoreBase::Impl { IMainLoop* loop_delegator_ = nullptr; guint signal_handler_source_ = 0; std::unique_ptr plugin_; + std::unique_ptr suspend_event_; }; AppCoreBase::EventBase::EventBase(Type type) @@ -328,38 +267,8 @@ AppCoreBase::RotationState AppCoreBase::Impl::GetRm(sensor_data_t data) { } } -void AppCoreBase::Impl::InitSuspendDbusHandler(gpointer data) { - if (__suspend_dbus_handler_initialized) - return; - - if (__bus == nullptr) { - 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 ? err->message : ""); - if (err) - g_error_free(err); - - return; - } - } - - __suspend_dbus_handler_initialized = g_dbus_connection_signal_subscribe( - __bus, nullptr, RESOURCED_FREEZER_INTERFACE, RESOURCED_FREEZER_SIGNAL, - RESOURCED_FREEZER_PATH, nullptr, G_DBUS_SIGNAL_FLAGS_NONE, - ReceiveSuspendSignalCb, data, nullptr); - - if (__suspend_dbus_handler_initialized == 0) { - _E("g_dbus_connection_signal_subscribe() is failed."); - return; - } - - _D("[__SUSPEND__] suspend signal initialized"); -} - -gboolean AppCoreBase::Impl::InitSuspendCb(gpointer data) { - InitSuspendDbusHandler(data); - return G_SOURCE_REMOVE; +void AppCoreBase::Impl::InitSuspend() { + suspend_event_.reset(new SuspendEvent(this)); } gboolean AppCoreBase::Impl::InvokeLangChangeCb(gpointer data) { @@ -369,18 +278,8 @@ gboolean AppCoreBase::Impl::InvokeLangChangeCb(gpointer data) { return G_SOURCE_REMOVE; } -void AppCoreBase::Impl::ReceiveSuspendSignalCb(GDBusConnection*, const gchar*, - const gchar*, const gchar*, const gchar* signal_name, GVariant* parameters, - gpointer user_data) { - if (g_strcmp0(signal_name, RESOURCED_FREEZER_SIGNAL) == 0) { - gint pid = -1; - gint status = 0; - g_variant_get(parameters, "(ii)", &status, &pid); - if (pid == getpid() && status == 0) { - AppCoreBase* base = reinterpret_cast(user_data); - base->impl_->OnFreezerSignal(); - } - } +void AppCoreBase::Impl::OnSuspend(pid_t pid, int status) { + if (pid == getpid() && status == 0) OnFreezerSignal(); } void AppCoreBase::Impl::LanguageChangeCb(keynode_t* key, void* user_data) { @@ -425,23 +324,6 @@ void AppCoreBase::Impl::LowMemoryCb(keynode_t* key, void* user_data) { malloc_trim(0); } -void AppCoreBase::Impl::ChargerStatusChangedCb(keynode_t* keynode, - void* user_data) { - AppCoreBase* base = reinterpret_cast(user_data); - if (base->impl_->feature_ & FEATURE_CHARGER_STATUS) { - __rotation.charger_status = vconf_keynode_get_int(keynode); - if (__rotation.ref) { - if (__rotation.charger_status) { - base->impl_->InitRotation(); - } else { - base->impl_->FiniRotation(); - } - } - - _D("charger status(%d)", __rotation.charger_status); - } -} - void AppCoreBase::Impl::LockCb(keynode_t* node, void* user_data) { AppCoreBase::RotationState rm; AppCoreBase* base = reinterpret_cast(user_data); @@ -594,13 +476,10 @@ int AppCoreBase::OnReceive(aul_type type, tizen_base::Bundle b) { switch (type) { case AUL_START: _D("[APP %d] AUL event: AUL_START", getpid()); - if (impl_->feature_ & FEATURE_BACKGROUND_MANAGEMENT) { - std::string bg = b.GetString(AUL_K_ALLOWED_BG); - if (bg == "ALLOWED_BG") { - _D("[__SUSPEND__] allowed background"); - impl_->allowed_bg_ = true; - RemoveSuspendTimer(); - } + if (b.GetString(AUL_K_ALLOWED_BG) == "ALLOWED_BG") { + _D("[__SUSPEND__] allowed background"); + impl_->allowed_bg_ = true; + RemoveSuspendTimer(); } traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:RESET"); @@ -612,13 +491,10 @@ int AppCoreBase::OnReceive(aul_type type, tizen_base::Bundle b) { break; case AUL_RESUME: _D("[APP %d] AUL event: AUL_RESUME", getpid()); - if (impl_->feature_ & FEATURE_BACKGROUND_MANAGEMENT) { - std::string bg = b.GetString(AUL_K_ALLOWED_BG); - if (bg == "ALLOWED_BG") { - _D("[__SUSPEND__] allowed background"); - impl_->allowed_bg_ = true; - RemoveSuspendTimer(); - } + if (b.GetString(AUL_K_ALLOWED_BG) == "ALLOWED_BG") { + _D("[__SUSPEND__] allowed background"); + impl_->allowed_bg_ = true; + RemoveSuspendTimer(); } break; case AUL_TERMINATE: @@ -638,22 +514,18 @@ int AppCoreBase::OnReceive(aul_type type, tizen_base::Bundle b) { break; case AUL_WAKE: _D("[APP %d] AUL event: AUL_WAKE", getpid()); - if (impl_->feature_ & FEATURE_BACKGROUND_MANAGEMENT) { - if (!impl_->allowed_bg_ && impl_->suspended_state_) { - RemoveSuspendTimer(); - int suspend = SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND; - impl_->InvokeCallback(suspend, IEvent::Type::SUSPENDED_STATE_CHANGE); - impl_->suspended_state_ = false; - } + if (!impl_->allowed_bg_ && impl_->suspended_state_) { + RemoveSuspendTimer(); + int suspend = SUSPENDED_STATE_DID_EXIT_FROM_SUSPEND; + impl_->InvokeCallback(suspend, IEvent::Type::SUSPENDED_STATE_CHANGE); + impl_->suspended_state_ = false; } break; case AUL_SUSPEND: _D("[APP %d] AUL event: AUL_SUSPEND", getpid()); - if (impl_->feature_ & FEATURE_BACKGROUND_MANAGEMENT) { - if (!impl_->allowed_bg_ && !impl_->suspended_state_) { - RemoveSuspendTimer(); - FlushMemory(); - } + if (!impl_->allowed_bg_ && !impl_->suspended_state_) { + RemoveSuspendTimer(); + FlushMemory(); } break; case AUL_UPDATE_REQUESTED: @@ -781,27 +653,11 @@ void AppCoreBase::Impl::UnregisterRotationChangedEvent() { return; __rotation.ref--; - if (__rotation.ref == 0) { - FiniRotation(); - if (feature_ & FEATURE_CHARGER_STATUS) { - vconf_ignore_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS, - ChargerStatusChangedCb); - } - } + if (__rotation.ref == 0) FiniRotation(); } void AppCoreBase::Impl::RegisterRotationChangedEvent() { - if (__rotation.ref == 0) { - if (feature_ & FEATURE_CHARGER_STATUS) { - vconf_get_int(VCONFKEY_SYSMAN_CHARGER_STATUS, &__rotation.charger_status); - vconf_notify_key_changed(VCONFKEY_SYSMAN_CHARGER_STATUS, - ChargerStatusChangedCb, parent_); - if (__rotation.charger_status) - InitRotation(); - } else { - InitRotation(); - } - } + if (__rotation.ref == 0) InitRotation(); __rotation.ref++; } @@ -1244,8 +1100,13 @@ void AppCoreBase::Init(int argc, char** argv) { impl_->PluginInit(argc, argv); traceEnd(TTRACE_TAG_APPLICATION_MANAGER); - if (impl_->feature_ & FEATURE_BACKGROUND_MANAGEMENT) - GLib::IdleAdd(Impl::InitSuspendCb, this); + GLib::IdleAdd( + [](gpointer data) -> gboolean { + AppCoreBase* base = reinterpret_cast(data); + base->impl_->InitSuspend(); + return G_SOURCE_REMOVE; + }, + this); traceBegin(TTRACE_TAG_APPLICATION_MANAGER, "APPCORE:SET_SYSTEM_EVENT"); if (!impl_->dirty_) { diff --git a/tizen-cpp/app-core-cpp/suspend_event_private.cc b/tizen-cpp/app-core-cpp/suspend_event_private.cc new file mode 100644 index 0000000..2c88ed8 --- /dev/null +++ b/tizen-cpp/app-core-cpp/suspend_event_private.cc @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2024 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "app-core-cpp/suspend_event_private.hh" + +#include "common/log_private.hh" + +namespace { + +constexpr const char RESOURCED_FREEZER_PATH[] = + "/Org/Tizen/ResourceD/Freezer"; +constexpr const char RESOURCED_FREEZER_INTERFACE[] = + "org.tizen.resourced.freezer"; +constexpr const char RESOURCED_FREEZER_SIGNAL[] = + "FreezerState"; + +} // namespace + +namespace tizen_cpp { + +SuspendEvent::SuspendEvent(IEventListener* listener) : listener_(listener) { + cancellable_ = g_cancellable_new(); + if (cancellable_ == nullptr) { + _E("g_cancellable_new() is failed"); + return; + } + + g_bus_get(G_BUS_TYPE_SYSTEM, cancellable_, GAsyncReadyCb, this); +} + +SuspendEvent::~SuspendEvent() { + if (source_ != 0) + g_dbus_connection_signal_unsubscribe(conn_, source_); + + if (conn_ != nullptr) + g_object_unref(conn_); + + if (cancellable_ != nullptr) { + g_cancellable_cancel(cancellable_); + g_object_unref(cancellable_); + } +} + +void SuspendEvent::GAsyncReadyCb(GObject* source_object, GAsyncResult* res, + gpointer user_data) { + auto* event = static_cast(user_data); + g_object_unref(event->cancellable_); + event->cancellable_ = nullptr; + + GError* error = nullptr; + event->conn_ = g_bus_get_finish(res, &error); + if (event->conn_ == nullptr) { + _E("g_bus_get_finish() is failed. error(%s)", error ? error->message : ""); + g_clear_error(&error); + return; + } + + event->source_ = g_dbus_connection_signal_subscribe( + event->conn_, nullptr, RESOURCED_FREEZER_INTERFACE, + RESOURCED_FREEZER_SIGNAL, RESOURCED_FREEZER_PATH, nullptr, + G_DBUS_SIGNAL_FLAGS_NONE, GDBusSignalCb, user_data, nullptr); + if (event->source_ == 0) { + _E("g_dbus_connection_signal_subscribe() is failed"); + return; + } + + _D("Suspend signal subscribed"); +} + +void SuspendEvent::GDBusSignalCb(GDBusConnection* conn, + const gchar* sender_name, + const gchar* object_path, + const gchar* interface_name, + const gchar* signal_name, GVariant* parameters, + gpointer user_data) { + if (g_strcmp0(signal_name, RESOURCED_FREEZER_SIGNAL) != 0) + return; + + gint pid = -1; + gint status = 0; + g_variant_get(parameters, "(ii)", &status, &pid); + auto* event = static_cast(user_data); + event->listener_->OnSuspend(pid, status); +} + +} // namespace tizen_cpp diff --git a/tizen-cpp/app-core-cpp/suspend_event_private.hh b/tizen-cpp/app-core-cpp/suspend_event_private.hh new file mode 100644 index 0000000..46cbe3e --- /dev/null +++ b/tizen-cpp/app-core-cpp/suspend_event_private.hh @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TIZEN_CPP_APP_CORE_CPP_SUSPEND_EVENT_PRIVATE_HH_ +#define TIZEN_CPP_APP_CORE_CPP_SUSPEND_EVENT_PRIVATE_HH_ + +#include +#include +#include + +namespace tizen_cpp { + +class SuspendEvent { + public: + class IEventListener { + public: + virtual ~IEventListener() = default; + virtual void OnSuspend(pid_t pid, int status) = 0; + }; + + explicit SuspendEvent(IEventListener* listener); + ~SuspendEvent(); + + private: + static void GAsyncReadyCb(GObject* source_object, GAsyncResult* res, + gpointer user_data); + static void GDBusSignalCb(GDBusConnection* conn, const gchar* sender_name, + const gchar* object_path, + const gchar* interface_name, + const gchar* signal_name, GVariant* parameters, + gpointer user_data); + + private: + IEventListener* listener_; + GDBusConnection* conn_ = nullptr; + GCancellable* cancellable_ = nullptr; + guint source_ = 0; +}; + +} // namespace tizen_cpp + +#endif // TIZEN_CPP_APP_CORE_CPP_SUSPEND_EVENT_PRIVATE_HH_ diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index b7a6671..2e79bc9 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -39,7 +39,6 @@ TARGET_INCLUDE_DIRECTORIES(${TARGET_UNIT_TEST} PUBLIC APPLY_PKG_CONFIG(${TARGET_UNIT_TEST} PUBLIC AUL_DEPS BUNDLE_DEPS - CAPI_SYSTEM_INFO_DEPS DLOG_DEPS ECORE_WL2_DEPS ELEMENTARY_DEPS diff --git a/unittests/mock/dbus_mock.cc b/unittests/mock/dbus_mock.cc index 56f23d0..d2ff12c 100644 --- a/unittests/mock/dbus_mock.cc +++ b/unittests/mock/dbus_mock.cc @@ -21,14 +21,44 @@ #include "mock/test_fixture.h" extern "C" GDBusConnection* g_bus_get_sync(GBusType bus_type, - GCancellable* cancellable, GError** error) { + GCancellable* cancellable, + GError** error) { return MOCK_HOOK_P3(DbusMock, g_bus_get_sync, bus_type, cancellable, error); } -extern "C" guint g_dbus_connection_signal_subscribe(GDBusConnection* arg0, - const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4, - const gchar* arg5, GDBusSignalFlags arg6, GDBusSignalCallback arg7, - gpointer arg8, GDestroyNotify arg9) { - return MOCK_HOOK_P10(DbusMock, g_dbus_connection_signal_subscribe, - arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); +extern "C" guint g_dbus_connection_signal_subscribe( + GDBusConnection* arg0, const gchar* arg1, const gchar* arg2, + const gchar* arg3, const gchar* arg4, const gchar* arg5, + GDBusSignalFlags arg6, GDBusSignalCallback arg7, gpointer arg8, + GDestroyNotify arg9) { + return MOCK_HOOK_P10(DbusMock, g_dbus_connection_signal_subscribe, arg0, arg1, + arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); +} + +extern "C" void g_bus_get(GBusType bus_type, GCancellable* cancellable, + GAsyncReadyCallback callback, gpointer user_data) { + MOCK_HOOK_P4(DbusMock, g_bus_get, bus_type, cancellable, callback, user_data); +} + +extern "C" GDBusConnection* g_bus_get_finish(GAsyncResult* res, + GError** error) { + return MOCK_HOOK_P2(DbusMock, g_bus_get_finish, res, error); +} + +extern "C" void g_dbus_connection_signal_unsubscribe(GDBusConnection* conn, + guint subscription_id) { + MOCK_HOOK_P2(DbusMock, g_dbus_connection_signal_unsubscribe, conn, + subscription_id); +} + +extern "C" GCancellable* g_cancellable_new(void) { + return MOCK_HOOK_P0(DbusMock, g_cancellable_new); +} + +extern "C" void g_cancellable_cancel(GCancellable* cancellable) { + MOCK_HOOK_P1(DbusMock, g_cancellable_cancel, cancellable); +} + +extern "C" void g_object_unref(gpointer object) { + MOCK_HOOK_P1(DbusMock, g_object_unref, object); } diff --git a/unittests/mock/dbus_mock.h b/unittests/mock/dbus_mock.h index c4bf82b..f1b5143 100644 --- a/unittests/mock/dbus_mock.h +++ b/unittests/mock/dbus_mock.h @@ -27,25 +27,32 @@ class DbusMock : public virtual ModuleMock { public: DbusMock() { using ::testing::_; - using ::testing::Return; using ::testing::Invoke; + using ::testing::Return; static int dummy; - conn_ = (GDBusConnection*)&dummy; + conn_ = reinterpret_cast(&dummy); - ON_CALL(*this, g_bus_get_sync(_, _, _)) - .WillByDefault(Return(conn_)); + ON_CALL(*this, g_bus_get_sync(_, _, _)).WillByDefault(Return(conn_)); } - MOCK_METHOD3(g_bus_get_sync, GDBusConnection* (GBusType, GCancellable*, GError**)); + MOCK_METHOD3(g_bus_get_sync, + GDBusConnection*(GBusType, GCancellable*, GError**)); + MOCK_METHOD4(g_bus_get, + void(GBusType, GCancellable*, GAsyncReadyCallback, gpointer)); MOCK_METHOD10(g_dbus_connection_signal_subscribe, guint(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, const gchar*, GDBusSignalFlags, GDBusSignalCallback, gpointer, GDestroyNotify)); - - private: - GDBusConnection* conn_ = nullptr; + MOCK_METHOD2(g_dbus_connection_signal_unsubscribe, + void(GDBusConnection*, guint)); + MOCK_METHOD0(g_cancellable_new, GCancellable*()); + MOCK_METHOD1(g_cancellable_cancel, void(GCancellable*)); + MOCK_METHOD1(g_object_unref, void(gpointer)); + MOCK_METHOD2(g_bus_get_finish, GDBusConnection*(GAsyncResult*, GError**)); + + private: + GDBusConnection* conn_ = nullptr; }; #endif // UNIT_TESTS_MOCK_DBUS_MOCK_H_ - -- 2.7.4