Add notification-ex feature 52/201052/7
authorhyunho <hhstark.kang@samsung.com>
Thu, 7 Mar 2019 23:28:12 +0000 (08:28 +0900)
committerhyunho <hhstark.kang@samsung.com>
Tue, 19 Mar 2019 06:55:33 +0000 (15:55 +0900)
Change-Id: I8a4c3c5ad8dc9c8d41a93ed08c179af12c609688
Signed-off-by: hyunho <hhstark.kang@samsung.com>
14 files changed:
CMakeLists.txt
data-provider-master.conf.in
include/badge_service.h
include/conf.h
include/debug.h
include/notification_ex_service.h [new file with mode: 0644]
include/notification_service.h
include/pkgmgr.h
include/service_common.h
include/shortcut_service.h
packaging/data-provider-master.spec
src/main.cc [moved from src/main.c with 95% similarity]
src/notification_ex_service.cc [new file with mode: 0644]
src/service_common.c

index 44e9783..4bf8906 100644 (file)
@@ -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
index 1433d76..73b6738 100644 (file)
@@ -5,6 +5,8 @@
 <busconfig>
        <policy user="app_fw">
                <allow own="org.tizen.data_provider_service"/>
+               <allow own="org.tizen.notification_ex._data-provider-master"/>
+               <allow send_type="signal" send_interface="org.tizen.notification_ex"/>
                <allow send_type="signal" send_interface="org.tizen.data_provider_noti_service"/>
                <allow send_type="signal" send_interface="org.tizen.data_provider_noti_event_service"/>
                <allow send_type="signal" send_interface="org.tizen.data_provider_badge_service"/>
@@ -19,6 +21,7 @@
                <deny send_type="signal" send_interface="org.tizen.data_provider_badge_service"/>
                <deny send_type="signal" send_interface="org.tizen.data_provider_shortcut_service"/>
                <check send_type="method_call" send_destination="org.tizen.data_provider_service" send_interface="org.tizen.data_provider_noti_service" privilege="http://tizen.org/privilege/notification"/>
+               <check send_type="method_call" send_destination="org.tizen.notification_ex._data-provider-master" send_interface="org.tizen.notification_ex" privilege="http://tizen.org/privilege/notification"/>
                <check send_destination="org.tizen.data_provider_service" send_interface="org.tizen.data_provider_badge_service" privilege="http://tizen.org/privilege/notification"/>
                <check send_destination="org.tizen.data_provider_service" send_interface="org.tizen.data_provider_shortcut_service" privilege="http://tizen.org/privilege/shortcut"/>
        </policy>
index 6428739..75c0814 100755 (executable)
 #include <gio/gio.h>
 #include <sys/types.h>
 
-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_
index 4899076..0e03135 100755 (executable)
@@ -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
index 3b55124..061e8d3 100755 (executable)
@@ -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 (file)
index 0000000..c6b3477
--- /dev/null
@@ -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 <gio/gio.h>
+
+#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
index f837d79..6d2e44e 100755 (executable)
 
 #include <gio/gio.h>
 
-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
index 0ac0524..2fc3c3f 100755 (executable)
  * 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
index b5394ce..8e75a7c 100755 (executable)
 #include <shortcut.h>
 #include <stdlib.h>
 
+#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_
index 35cb758..68a38b3 100755 (executable)
 
 #include <gio/gio.h>
 
-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
index c823326..79aadb3 100755 (executable)
@@ -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)
similarity index 95%
rename from src/main.c
rename to src/main.cc
index c9a8747..eb33ba7 100755 (executable)
@@ -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 (file)
index 0000000..121fd9d
--- /dev/null
@@ -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 <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <glib.h>
+#include <math.h>
+#include <gio/gio.h>
+
+#include <aul.h>
+#include <dlog.h>
+
+#include <notification-ex/manager.h>
+#include <notification-ex/reporter.h>
+#include <notification-ex/dbus_sender.h>
+#include <notification-ex/dbus_event_listener.h>
+#include <notification-ex/dbus_connection_manager.h>
+#include <notification-ex/button_item.h>
+#include <notification-ex/ex_util.h>
+
+#include "debug.h"
+#include "notification_ex_service.h"
+
+using namespace notification;
+using namespace std;
+
+class DPMFacade {
+  public:
+   DPMFacade(unique_ptr<Reporter> reporter, unique_ptr<Manager> manager)
+    : reporter_(move(reporter)), manager_(move(manager)) {
+   }
+
+   void DelegateReporterEvent(const EventInfo& info, shared_ptr<item::AbstractItem> item) {
+     reporter_->SendEvent(info, item);
+   }
+
+   void DelegateManagerEvent(const EventInfo& info, shared_ptr<item::AbstractItem> noti) {
+     manager_->SendEvent(info, noti);
+   }
+
+   unique_ptr<Reporter> reporter_;
+   unique_ptr<Manager> manager_;
+};
+
+static DPMFacade* facade_;
+
+class DPMReporter : public Reporter {
+ protected:
+  void OnEvent(const EventInfo& info,
+      list<shared_ptr<item::AbstractItem>> 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<shared_ptr<item::AbstractItem>> OnRequestEvent(const EventInfo& info) override {
+    DBG("Get report !!! %s", info.GetItemId().c_str());
+    list<shared_ptr<item::AbstractItem>> ret {
+      make_shared<item::ButtonItem>(info.GetItemId().c_str(), "title")
+    };
+    return ret;
+  }
+
+ public:
+  DPMReporter(std::unique_ptr<IEventSender> sender,
+      std::unique_ptr<IEventListener> listener)
+    : Reporter(move(sender), move(listener)) {
+  }
+};
+
+class DPMManager : public Manager {
+ protected:
+  void OnAdd(const EventInfo& info,
+      list<shared_ptr<item::AbstractItem>> addedItem) override {
+    DBG("Add !!!");
+    //TODO: store it to DB
+    for (auto& i : addedItem)
+      facade_->DelegateReporterEvent(info, i);
+  }
+
+  void OnUpdate(const EventInfo& info,
+      shared_ptr<item::AbstractItem> updatedItem) override {
+    DBG("Update !!!");
+    facade_->DelegateReporterEvent(info, updatedItem);
+  }
+
+  void OnDelete(const EventInfo& info,
+      shared_ptr<item::AbstractItem> deletedItem) override {
+    DBG("Delete !!!");
+    facade_->DelegateReporterEvent(info, deletedItem);
+  }
+
+  list<shared_ptr<item::AbstractItem>> OnRequestEvent(const EventInfo& info) override {
+    DBG("Get !!! %s", info.GetItemId().c_str());
+    //TODO: Get it from DB
+    list<shared_ptr<item::AbstractItem>> ret {
+      make_shared<item::ButtonItem>(info.GetItemId().c_str(), "title")
+    };
+    return ret;
+  }
+
+ public:
+  DPMManager(std::unique_ptr<IEventSender> sender,
+      std::unique_ptr<IEventListener> listener)
+    : Manager(move(sender), move(listener)) {
+  }
+};
+
+HAPI int notification_ex_service_init() {
+  facade_ = new DPMFacade(
+    unique_ptr<Reporter>(
+      new DPMReporter(
+        unique_ptr<DBusSender>(new DBusSender(Manager::GetPath())),
+        unique_ptr<DBusEventListener>(new DBusEventListener(Reporter::GetPath()))
+      )
+    ),
+    unique_ptr<Manager>(
+      new DPMManager(
+        unique_ptr<DBusSender>(new DBusSender(Reporter::GetPath())),
+        unique_ptr<DBusEventListener>(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
index 9c07f1e..0396194 100755 (executable)
@@ -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