2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <sys/types.h>
23 #include <download-provider-log.h>
24 #include <download-provider-client.h>
25 #include <download-provider-client-manager.h>
26 #include <download-provider-ipc.h>
28 static char *__dp_notify_get_path(pid_t pid)
30 size_t path_size = sizeof(NOTIFY_DIR) + 21;
31 char *notify_fifo = (char *)calloc(path_size, sizeof(char));
32 if (notify_fifo == NULL) {
33 TRACE_ERROR("failed to alocalte fifo path pid:%d", (int)pid);
36 if (snprintf(notify_fifo, path_size, "%s/%d", NOTIFY_DIR, pid) < 0) {
37 TRACE_ERROR("failed to make fifo path pid:%d", (int)pid);
44 int dp_notify_init(pid_t pid)
46 char *notify_fifo = __dp_notify_get_path(pid);
47 if (notify_fifo == NULL)
50 struct stat fifo_state;
51 if (stat(notify_fifo, &fifo_state) == 0) // found
53 if (mkfifo(notify_fifo, 0644/*-rwrr*/) < 0)
54 TRACE_ERROR("failed to make fifo %s", notify_fifo);
56 notify_fd = open(notify_fifo, O_RDWR | O_NONBLOCK, 0644);
62 void dp_notify_deinit(pid_t pid)
64 char *notify_fifo = __dp_notify_get_path(pid);
65 if (notify_fifo == NULL)
67 struct stat fifo_state;
68 if (stat(notify_fifo, &fifo_state) == 0) // found
73 static int __dp_notify_feedback(int sock, int id, int state, int errorcode, unsigned long long received_size)
75 dp_ipc_event_fmt eventinfo;
76 memset(&eventinfo, 0x00, sizeof(dp_ipc_event_fmt));
78 eventinfo.state = state;
79 eventinfo.errorcode = errorcode;
80 eventinfo.received_size = received_size;
81 if (dp_ipc_write(sock, &eventinfo, sizeof(dp_ipc_event_fmt)) < 0) {
82 // failed to read from socket // ignore this status
88 int dp_notify_feedback(int sock, void *slot, int id, int state, int errorcode, unsigned long long received_size)
90 if (__dp_notify_feedback(sock, id, state, errorcode, received_size) < 0) {
91 TRACE_ERROR("notify failure by IO_ERROR");
93 dp_client_slots_fmt *base_slot = slot;
94 if (base_slot->client.notify >= 0)
95 close(base_slot->client.notify);
96 base_slot->client.notify = -1;
97 dp_notify_deinit(base_slot->credential.pid);
98 TRACE_ERROR("disable notify channel by IO_ERROR");