Rollback 'notification_wait_response' for backward compatibility 71/40471/1 accepted/tizen/3.0.2015.q2/common/20150615.091743 accepted/tizen/common/20150612.065854 accepted/tizen/mobile/20150615.071214 accepted/tizen/tv/20150615.071239 accepted/tizen/wearable/20150617.012828 submit/tizen/20150604.103646 submit/tizen/20150609.020831 submit/tizen/20150609.074149 submit/tizen/20150611.063059 submit/tizen_3.0.2015.q2_common/20150615.075539 submit/tizen_mobile/20150604.063436 submit/tizen_mobile/20150604.105928 submit/tizen_mobile/20150609.015041 submit/tizen_mobile/20150612.084020 submit/tizen_tv/20150612.084103 submit/tizen_wearable/20150616.000000 submit/tizen_wearble/20150612.084038
authorKyuho Jo <kyuho.jo@samsung.com>
Thu, 4 Jun 2015 06:28:40 +0000 (15:28 +0900)
committerKyuho Jo <kyuho.jo@samsung.com>
Thu, 4 Jun 2015 06:28:40 +0000 (15:28 +0900)
Change-Id: Iedd09b4b5833007284c59df86dff7e3e367412e7
Signed-off-by: Kyuho Jo <kyuho.jo@samsung.com>
CMakeLists.txt
include/notification.h
notification-service.pc.in [deleted file]
src/notification_old.c [new file with mode: 0644]

index e13a7aa..605237d 100644 (file)
@@ -24,7 +24,8 @@ SET(SRCS
        ./src/notification_list.c
        ./src/notification_status.c
        ./src/notification_ipc.c
-       ./src/notification_setting.c)
+       ./src/notification_setting.c
+       ./src/notification_old.c)
 SET(HEADERS-DEVEL
        ./include/notification.h
        ./include/notification_internal.h
index cac2a5d..827f378 100644 (file)
@@ -1420,6 +1420,29 @@ int notification_get_permission(notification_h noti, notification_permission_typ
  */
 int notification_get_pkgname(notification_h noti, char **pkgname);
 
+
+/* For backward compatibility */
+/**
+ * @brief Wait for a response coming for this notification
+ * @details The notification should have the EXECUTE_TYPE_RESPONDING flag
+ * @remarks
+ * @param[in] noti notification handle
+ * @param[in] timeout in seconds - 0 for infinite
+ * @param[out] integer response
+ * @param[out] text response
+ * @return NOTIFICATION_ERROR_NONE if success, other value if failure
+ * @retval NOTIFICATION_ERROR_NONE - success
+ * @retval NOTIFICATION_ERROR_INVALID_PARAMETER - invalid parameter
+ * @retval NOTIFICATION_ERROR_OUT_OF_MEMORY - not enough memory
+ * @pre notification handle should be created by notification_new().
+ * @post
+ * @see
+ */
+int notification_wait_response(notification_h noti,
+                                               int timeout,
+                                               int *respi,
+                                               char **respc);
+
 /**
  * @}
  */
diff --git a/notification-service.pc.in b/notification-service.pc.in
deleted file mode 100644 (file)
index 2708490..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-prefix=@PREFIX@
-exec_prefix=@EXEC_PREFIX@
-libdir=@LIBDIR@
-includedir=@INCLUDEDIR@/service
-
-Name: notification
-Description: Notification Library
-Version: @VERSION@
-Requires: bundle
-Libs: -L${libdir} -lnotification
-Cflags: -I${includedir}
diff --git a/src/notification_old.c b/src/notification_old.c
new file mode 100644 (file)
index 0000000..3b071cf
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ *  libnotification
+ *
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Kyuho Jo <kyuho.jo@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+#define _GNU_SOURCE /* for asprintf */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <libintl.h>
+#include <sys/socket.h>
+#include <sys/syscall.h>
+#include <sys/time.h>
+#include <sys/un.h>
+
+#include <notification.h>
+#include <notification_internal.h>
+
+EXPORT_API int notification_wait_response(notification_h noti,
+                                                          int timeout,
+                                                          int *respi,
+                                                          char **respc)
+{
+       bundle *b, *bc = NULL;
+       pid_t tid;
+       const char *tid_c;
+       int sock_fd, msg_fd;
+       char *sock_path;
+       struct sockaddr_un sock_addr;
+       char msg_buffer[1024];
+       ssize_t msg_size;
+       struct timeval timeout_tv;
+       char *resp;
+
+       memset(msg_buffer, 0, sizeof(msg_buffer));
+
+    /* a response packet *must* have an execute option TYPE_RESPONDING
+           with an associated bundle.
+           If its bundle does not already contain a "tid" hint (which
+           complex applications such as xwalk may overwrite), we will
+           try to find the TID and set it in the bundle ourselves. */
+       notification_get_execute_option (noti, NOTIFICATION_EXECUTE_TYPE_RESPONDING,
+       NULL, &b);
+
+       if (b == NULL)
+               return NOTIFICATION_ERROR_INVALID_PARAMETER;
+
+       tid_c = bundle_get_val(b, "tid");
+       if (tid_c == NULL) {
+               tid = syscall(SYS_gettid);
+               asprintf((char **)&tid_c, "%d", tid);
+               bc = bundle_dup(b);
+               bundle_add(bc, "tid", tid_c);
+               notification_set_execute_option (noti, NOTIFICATION_EXECUTE_TYPE_RESPONDING,
+                                                NULL, NULL, bc);
+               bundle_free(bc);
+               notification_update(noti);
+       }
+
+       sock_fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+       if (sock_fd == -1)
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+
+       sock_addr.sun_family = AF_UNIX;
+       asprintf(&sock_path, "/tmp/.notification-%s", tid_c);
+       strncpy(sock_addr.sun_path, sock_path, sizeof(sock_addr.sun_path) - 1);
+       if (bind(sock_fd, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) == -1) {
+               close(sock_fd);
+               free(sock_path);
+               free((char *)tid_c);
+               return NOTIFICATION_ERROR_OUT_OF_MEMORY;
+       }
+
+       if (timeout > 0) {
+               timeout_tv.tv_sec = timeout;
+               timeout_tv.tv_usec = 0;
+               setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout_tv, sizeof(timeout_tv));
+               setsockopt(sock_fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout_tv, sizeof(timeout_tv));
+       }
+
+       listen(sock_fd, 1);
+       msg_fd = accept(sock_fd, NULL, 0);
+       do {
+               msg_size = read(msg_fd, msg_buffer, 1024);
+       } while (msg_size > 0);
+
+       resp = strtok(msg_buffer, "\n");
+       if (resp) {
+               *respi = atoi(resp);
+               if (respc != NULL) {
+                       resp = strtok(NULL, "\n");
+                       if (resp)
+                               *respc = resp;
+                       else
+                               *respc = NULL;
+               }
+       } else {
+               *respi = 0;
+               if (respc != NULL)
+                       *respc = NULL;
+       }
+
+       close(sock_fd);
+       unlink(sock_path);
+       free(sock_path);
+       free((char *)tid_c);
+
+       return NOTIFICATION_ERROR_NONE;
+}