From 68357470aacb19d4a7d260a233f863dbbc33be45 Mon Sep 17 00:00:00 2001 From: hyunho Date: Fri, 8 Mar 2019 08:28:12 +0900 Subject: [PATCH] Add notification-ex feature Change-Id: I8a4c3c5ad8dc9c8d41a93ed08c179af12c609688 Signed-off-by: hyunho --- CMakeLists.txt | 66 +++++----------- data-provider-master.conf.in | 3 + include/badge_service.h | 17 +++- include/conf.h | 5 +- include/debug.h | 5 +- include/notification_ex_service.h | 26 ++++++ include/notification_service.h | 17 +++- include/pkgmgr.h | 12 ++- include/service_common.h | 14 +++- include/shortcut_service.h | 18 ++++- packaging/data-provider-master.spec | 1 + src/{main.c => main.cc} | 8 ++ src/notification_ex_service.cc | 153 ++++++++++++++++++++++++++++++++++++ src/service_common.c | 5 ++ 14 files changed, 292 insertions(+), 58 deletions(-) create mode 100644 include/notification_ex_service.h rename src/{main.c => main.cc} (95%) create mode 100644 src/notification_ex_service.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 44e9783..4bf8906 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,24 +1,27 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(${NAME} C) +PROJECT(data-provider-master C CXX) -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(PREFIX "${CMAKE_INSTALL_PREFIX}") SET(EXEC_PREFIX "\${prefix}") +SET(PROJECT_NAME "${PROJECT_NAME}") SET(LIBDIR ${LIB_INSTALL_DIR}) -SET(INCLUDEDIR "\${prefix}/include") +SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") +SET(VERSION_MAJOR 1) +SET(VERSION "${VERSION_MAJOR}.0.0") INCLUDE(FindPkgConfig) -pkg_check_modules(pkg REQUIRED +pkg_check_modules(pkgs REQUIRED dlog aul vconf sqlite3 - db-util glib-2.0 gio-2.0 gio-unix-2.0 bundle pkgmgr notification + notification-ex badge libsmack shortcut @@ -29,49 +32,23 @@ pkg_check_modules(pkg REQUIRED libtzplatform-config ) -SET(PACKAGE "${PROJECT_NAME}") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Winline -Werror -fno-builtin-malloc -fno-omit-frame-pointer -g -fPIE -Wl,-z,relro") +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -Werror -Winline") -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) - -#ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") -ADD_DEFINITIONS("-DPATH_MAX=256") -ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"") -ADD_DEFINITIONS("-DLOCALEDIR=\"${LOCALEDIR}\"") - -ADD_DEFINITIONS("-D_GNU_SOURCE") -ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64") - -ADD_DEFINITIONS("-DSHORTCUT_SMACK_LABEL=NULL") -ADD_DEFINITIONS("-DNOTIFICATION_SMACK_LABEL=NULL") -ADD_DEFINITIONS("-DBADGE_SMACK_LABEL=NULL") -ADD_DEFINITIONS("-DDATA_SHARE_LABEL=NULL") -ADD_DEFINITIONS("-DDEFAULT_SMACK_LABEL=NULL") - -ADD_DEFINITIONS("-DNDEBUG") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++11") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2") -ADD_DEFINITIONS("-D_USE_ECORE_TIME_GET") - -SET(BUILD_SOURCE - src/main.c - src/pkgmgr.c - src/shortcut_service.c - src/badge_service.c - src/notification_service.c - src/service_common.c -) - -STRING(REPLACE "-L-l" "-l" pkg_fixed_LDFLAGS ${pkg_LDFLAGS}) -STRING(REPLACE "-l" " -l" pkg_LDFLAGS ${pkg_fixed_LDFLAGS}) -STRING(REPLACE "-L" " -L" pkg_fixed_LDFLAGS ${pkg_LDFLAGS}) -STRING(REGEX REPLACE "^ " "" pkg_LDFLAGS ${pkg_fixed_LDFLAGS}) - -ADD_DEFINITIONS(${pkg_CFLAGS}) -ADD_DEFINITIONS(${pkg_LDFLAGS}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) -ADD_EXECUTABLE(${PROJECT_NAME} ${BUILD_SOURCE}) +AUX_SOURCE_DIRECTORY(src SOURCES) +ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCES}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkg_LDFLAGS} "-ldl -lrt -pie") +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS} -fPIE") +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-pie") +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) @@ -80,4 +57,3 @@ CONFIGURE_FILE(org.tizen.data-provider-master.service.in org.tizen.data-provider INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.tizen.data-provider-master.service DESTINATION ${SHARE_INSTALL_PREFIX}/dbus-1/system-services/) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.conf DESTINATION ${SYSCONF_INSTALL_DIR}/dbus-1/system.d/) -# End of a file diff --git a/data-provider-master.conf.in b/data-provider-master.conf.in index 1433d76..73b6738 100644 --- a/data-provider-master.conf.in +++ b/data-provider-master.conf.in @@ -5,6 +5,8 @@ + + @@ -19,6 +21,7 @@ + diff --git a/include/badge_service.h b/include/badge_service.h index 6428739..75c0814 100755 --- a/include/badge_service.h +++ b/include/badge_service.h @@ -17,8 +17,15 @@ #include #include -extern int badge_service_init(void); -extern int badge_service_fini(void); +#ifndef BADGE_SERVICE_H_ +#define BADGE_SERVICE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int badge_service_init(void); +int badge_service_fini(void); int badge_get_badge_existing(GVariant *parameters, GVariant **reply_body, uid_t uid); int badge_get_badge_list(GVariant *parameters, GVariant **reply_body, uid_t uid); @@ -36,4 +43,8 @@ int badge_get_setting_property(GVariant *parameters, GVariant **reply_body, uid_ int badge_init_display(GVariant *parameters, GVariant **reply_body, uid_t uid); int badge_register_dbus_interface(); -/* End of a file */ +#ifdef __cplusplus +} +#endif + +#endif // BADGE_SERVICE_H_ diff --git a/include/conf.h b/include/conf.h index 4899076..0e03135 100755 --- a/include/conf.h +++ b/include/conf.h @@ -14,6 +14,9 @@ * limitations under the License. */ +#ifndef CONF_H_ +#define CONF_H_ + #define DELAY_TIME 0.0000001f #define HAPI __attribute__((visibility("hidden"))) @@ -29,4 +32,4 @@ #define CR 13 #define LF 10 -/* End of a file */ +#endif // CONF_H_ \ No newline at end of file diff --git a/include/debug.h b/include/debug.h index 3b55124..061e8d3 100755 --- a/include/debug.h +++ b/include/debug.h @@ -14,6 +14,9 @@ * limitations under the License. */ +#ifndef DEBUG_H_ +#define DEBUG_H_ + #define DBG(format, arg...) SECURE_LOGD(format, ##arg) #define ERR(format, arg...) SECURE_LOGE(format, ##arg) #define WARN(format, arg...) SECURE_LOGW(format, ##arg) @@ -27,4 +30,4 @@ #define HAPI __attribute__((visibility("hidden"))) -/* End of a file */ +#endif //DEBUG_H_ \ No newline at end of file diff --git a/include/notification_ex_service.h b/include/notification_ex_service.h new file mode 100644 index 0000000..c6b3477 --- /dev/null +++ b/include/notification_ex_service.h @@ -0,0 +1,26 @@ +/* + * Copyright 2016 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 + +#ifndef NOTIFICATION_EX_SERVICE_H_ +#define NOTIFICATION_EX_SERVICE_H_ + +extern int notification_ex_service_init(void); +extern int notification_ex_service_fini(void); +extern GDBusConnection* notification_ex_service_get_gdbus_connection(void); + +#endif //NOTIFICATION_EX_SERVICE_H_ \ No newline at end of file diff --git a/include/notification_service.h b/include/notification_service.h index f837d79..6d2e44e 100755 --- a/include/notification_service.h +++ b/include/notification_service.h @@ -16,8 +16,15 @@ #include -extern int notification_service_init(void); -extern int notification_service_fini(void); +#ifndef NOTIFICATION_SERVICE_H_ +#define NOTIFICATION_SERVICE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int notification_service_init(void); +int notification_service_fini(void); int notification_add_noti(GVariant *parameters, GVariant **reply_body, const char *sender, pid_t pid, uid_t uid); @@ -53,4 +60,8 @@ int notification_reset_event_receiver(GVariant *parameters, GVariant **reply_bod int notification_register_dbus_interface(); int notification_delete_noti_by_app_id(const char *app_id, uid_t uid); -/* End of a file */ +#ifdef __cplusplus +} +#endif + +#endif //NOTIFICATION_SERVICE_H_ \ No newline at end of file diff --git a/include/pkgmgr.h b/include/pkgmgr.h index 0ac0524..2fc3c3f 100755 --- a/include/pkgmgr.h +++ b/include/pkgmgr.h @@ -14,6 +14,13 @@ * limitations under the License. */ +#ifndef PKGMGR_H_ +#define PKGMGR_H_ + +#ifdef __cplusplus +extern "C" { +#endif + enum pkgmgr_event_type { PKGMGR_EVENT_DOWNLOAD, PKGMGR_EVENT_INSTALL, @@ -37,5 +44,8 @@ extern int pkgmgr_fini(void); extern int pkgmgr_add_event_callback(enum pkgmgr_event_type type, int (*cb)(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value, void *data), void *data); extern void *pkgmgr_del_event_callback(enum pkgmgr_event_type type, int (*cb)(uid_t uid, const char *pkgname, enum pkgmgr_status status, double value, void *data), void *data); +#ifdef __cplusplus +} +#endif -/* End of a file */ +#endif //PKGMGR_H_ \ No newline at end of file diff --git a/include/service_common.h b/include/service_common.h index b5394ce..8e75a7c 100755 --- a/include/service_common.h +++ b/include/service_common.h @@ -20,8 +20,15 @@ #include #include +#ifndef SERVICE_COMMON_H_ +#define SERVICE_COMMON_H_ + #define NORMAL_UID_BASE 5000 +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { NOTIFICATION_SERVICE = 0, SHORTCUT_SERVICE, @@ -62,5 +69,10 @@ uid_t get_sender_uid(const char *sender_name); pid_t get_sender_pid(const char *sender_name); void free_monitoring_list(gpointer data); void service_common_init(void); +void service_common_set_connection(GDBusConnection *conn); + +#ifdef __cplusplus +} +#endif -/* End of a file */ +#endif //SERVICE_COMMON_H_ diff --git a/include/shortcut_service.h b/include/shortcut_service.h index 35cb758..68a38b3 100755 --- a/include/shortcut_service.h +++ b/include/shortcut_service.h @@ -16,8 +16,15 @@ #include -extern int shortcut_service_init(void); -extern int shortcut_service_fini(void); +#ifndef SHORTCUT_SERVICE_H_ +#define SHORTCUT_SERVICE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int shortcut_service_init(void); +int shortcut_service_fini(void); void shortcut_add(GVariant *parameters, GDBusMethodInvocation *invocation, uid_t uid); void shortcut_add_widget(GVariant *parameters, GDBusMethodInvocation *invocation, uid_t uid); @@ -26,4 +33,9 @@ int shortcut_register_dbus_interface(); int shortcut_get_shortcut_service_list(GVariant *parameters, GVariant **reply_body, uid_t uid); int shortcut_check_privilege(void); int shortcut_send_return_value(GVariant *parameters, GVariant **reply_body); -/* End of a file */ + +#ifdef __cplusplus +} +#endif + +#endif //SHORTCUT_SERVICE_H_ \ No newline at end of file diff --git a/packaging/data-provider-master.spec b/packaging/data-provider-master.spec index c823326..79aadb3 100755 --- a/packaging/data-provider-master.spec +++ b/packaging/data-provider-master.spec @@ -24,6 +24,7 @@ BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(pkgmgr) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(notification) +BuildRequires: pkgconfig(notification-ex) BuildRequires: pkgconfig(badge) BuildRequires: pkgconfig(shortcut) BuildRequires: pkgconfig(libsystemd-daemon) diff --git a/src/main.c b/src/main.cc similarity index 95% rename from src/main.c rename to src/main.cc index c9a8747..eb33ba7 100755 --- a/src/main.c +++ b/src/main.cc @@ -36,6 +36,7 @@ #include "service_common.h" #include "shortcut_service.h" #include "notification_service.h" +#include "notification_ex_service.h" #include "badge_service.h" static GMainLoop *main_loop; @@ -72,6 +73,13 @@ static inline int app_create(void) lang_key_changed_cb(NULL, NULL); + ret = notification_ex_service_init(); + if (ret < 0) + WARN("notification_ex [%d]", ret); + + service_common_set_connection( + notification_ex_service_get_gdbus_connection()); + ret = shortcut_service_init(); if (ret < 0) WARN("shortcut [%d]", ret); diff --git a/src/notification_ex_service.cc b/src/notification_ex_service.cc new file mode 100644 index 0000000..121fd9d --- /dev/null +++ b/src/notification_ex_service.cc @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2019 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 +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "debug.h" +#include "notification_ex_service.h" + +using namespace notification; +using namespace std; + +class DPMFacade { + public: + DPMFacade(unique_ptr reporter, unique_ptr manager) + : reporter_(move(reporter)), manager_(move(manager)) { + } + + void DelegateReporterEvent(const EventInfo& info, shared_ptr item) { + reporter_->SendEvent(info, item); + } + + void DelegateManagerEvent(const EventInfo& info, shared_ptr noti) { + manager_->SendEvent(info, noti); + } + + unique_ptr reporter_; + unique_ptr manager_; +}; + +static DPMFacade* facade_; + +class DPMReporter : public Reporter { + protected: + void OnEvent(const EventInfo& info, + list> noti_list) override { + LOGI("Event received (%d) !!", (int)info.GetEventType()); + for (auto& i : noti_list) { + facade_->DelegateManagerEvent(info, i); + + /* noti to viewers */ + facade_->DelegateReporterEvent(info, i); + } + } + + list> OnRequestEvent(const EventInfo& info) override { + DBG("Get report !!! %s", info.GetItemId().c_str()); + list> ret { + make_shared(info.GetItemId().c_str(), "title") + }; + return ret; + } + + public: + DPMReporter(std::unique_ptr sender, + std::unique_ptr listener) + : Reporter(move(sender), move(listener)) { + } +}; + +class DPMManager : public Manager { + protected: + void OnAdd(const EventInfo& info, + list> addedItem) override { + DBG("Add !!!"); + //TODO: store it to DB + for (auto& i : addedItem) + facade_->DelegateReporterEvent(info, i); + } + + void OnUpdate(const EventInfo& info, + shared_ptr updatedItem) override { + DBG("Update !!!"); + facade_->DelegateReporterEvent(info, updatedItem); + } + + void OnDelete(const EventInfo& info, + shared_ptr deletedItem) override { + DBG("Delete !!!"); + facade_->DelegateReporterEvent(info, deletedItem); + } + + list> OnRequestEvent(const EventInfo& info) override { + DBG("Get !!! %s", info.GetItemId().c_str()); + //TODO: Get it from DB + list> ret { + make_shared(info.GetItemId().c_str(), "title") + }; + return ret; + } + + public: + DPMManager(std::unique_ptr sender, + std::unique_ptr listener) + : Manager(move(sender), move(listener)) { + } +}; + +HAPI int notification_ex_service_init() { + facade_ = new DPMFacade( + unique_ptr( + new DPMReporter( + unique_ptr(new DBusSender(Manager::GetPath())), + unique_ptr(new DBusEventListener(Reporter::GetPath())) + ) + ), + unique_ptr( + new DPMManager( + unique_ptr(new DBusSender(Reporter::GetPath())), + unique_ptr(new DBusEventListener(Manager::GetPath())) + ) + ) + ); + + return 0; +} + +HAPI int notification_ex_service_fini() { + delete facade_; + return 0; +} + +HAPI GDBusConnection* notification_ex_service_get_gdbus_connection() { + return DBusConnectionManager::GetInst().GetConnection(); +} \ No newline at end of file diff --git a/src/service_common.c b/src/service_common.c index 9c07f1e..0396194 100755 --- a/src/service_common.c +++ b/src/service_common.c @@ -532,3 +532,8 @@ void service_common_init(void) pkgmgr_add_event_callback(PKGMGR_EVENT_APP_ENABLE, _app_enabled_cb, NULL); pkgmgr_add_event_callback(PKGMGR_EVENT_APP_DISABLE, _app_disabled_cb, NULL); } + +void service_common_set_connection(GDBusConnection *conn) +{ + _gdbus_conn = conn; +} \ No newline at end of file -- 2.7.4