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>
24 #include <download-provider-log.h>
25 #include <download-provider-client.h>
26 #include <download-provider-client-manager.h>
27 #include <download-provider-ipc.h>
29 static char *__dp_notify_get_path(pid_t pid)
31 size_t path_size = sizeof(NOTIFY_DIR) + 21;
32 char *notify_fifo = (char *)calloc(path_size, sizeof(char));
33 if (notify_fifo == NULL) {
34 TRACE_ERROR("failed to alocalte fifo path pid:%d", (int)pid);
37 if (snprintf(notify_fifo, path_size, "%s/%d", NOTIFY_DIR, pid) < 0) {
38 TRACE_ERROR("failed to make fifo path pid:%d", (int)pid);
45 int dp_notify_init(pid_t pid)
47 char *notify_fifo = __dp_notify_get_path(pid);
48 if (notify_fifo == NULL)
52 if (unlink(notify_fifo) < 0)
53 TRACE_ERROR("%s might not be exist. Ignored. errno(%d)", notify_fifo, errno);
55 if (mkfifo(notify_fifo, 0644/*-rwrr*/) < 0)
56 TRACE_ERROR("failed to make fifo %s", notify_fifo);
58 notify_fd = open(notify_fifo, O_RDWR | O_NONBLOCK, 0644);
64 void dp_notify_deinit(pid_t pid)
66 char *notify_fifo = __dp_notify_get_path(pid);
67 if (notify_fifo == NULL)
70 if (unlink(notify_fifo) < 0)
71 TRACE_ERROR("%s might not be exist. Ignored. errno(%d)", notify_fifo, errno);
76 static int __dp_notify_feedback(int sock, int id, int state, int errorcode, unsigned long long received_size)
78 dp_ipc_event_fmt eventinfo;
79 memset(&eventinfo, 0x00, sizeof(dp_ipc_event_fmt));
81 eventinfo.state = state;
82 eventinfo.errorcode = errorcode;
83 eventinfo.received_size = received_size;
84 if (dp_ipc_write(sock, &eventinfo, sizeof(dp_ipc_event_fmt)) < 0) {
85 // failed to read from socket // ignore this status
91 int dp_notify_feedback(int sock, void *slot, int id, int state, int errorcode, unsigned long long received_size)
93 if (__dp_notify_feedback(sock, id, state, errorcode, received_size) < 0) {
94 TRACE_ERROR("notify failure by IO_ERROR");
96 dp_client_slots_fmt *base_slot = slot;
97 if (base_slot->client.notify >= 0)
98 close(base_slot->client.notify);
99 base_slot->client.notify = -1;
100 dp_notify_deinit(base_slot->credential.pid);
101 TRACE_ERROR("disable notify channel by IO_ERROR");