Prevent [CID 370482] fixed
[apps/native/widget/widget-provider.git] / widget_provider / src / widget_provider.c
1 /*
2  * Copyright 2013  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (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
7  *
8  * http://floralicense.org/license/
9  *
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.
15  */
16
17 #include <stdio.h>
18 #include <sys/types.h>
19 #include <sys/shm.h>
20 #include <errno.h>
21 #include <unistd.h>
22 #include <fcntl.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include <sys/time.h>
26
27 #include <com-core.h>
28 #include <packet.h>
29 #include <com-core_packet.h>
30
31 #include <dlog.h>
32 #include <widget_errno.h>
33 #include <widget_service.h> /* WIDGET_ACCESS_STATUS_XXXX */
34 #include <widget_service_internal.h>
35 #include <widget_cmd_list.h>
36 #include <widget_conf.h>
37 #include <widget_util.h>
38 #include <widget_buffer.h>
39
40 #include "widget_provider.h"
41 #include "widget_provider_buffer.h"
42 #include "provider_buffer_internal.h"
43 #include "dlist.h"
44 #include "util.h"
45 #include "debug.h"
46 #include "fb.h"
47 #include "event.h"
48
49 #define EAPI __attribute__((visibility("default")))
50 #define SW_ACCEL "use-sw"
51
52 static struct info {
53         int closing_fd;
54         int fd;
55         char *name;
56         char *abi;
57         char *accel;
58         int secured;
59         struct widget_event_table table;
60         void *data;
61         int prevent_overwrite;
62 } s_info = {
63         .closing_fd = 0,
64         .fd = -1,
65         .name = NULL,
66         .abi = NULL,
67         .accel = NULL,
68         .data = NULL,
69         .prevent_overwrite = 0,
70         .secured = 0,
71 };
72
73 #define EAPI __attribute__((visibility("default")))
74
75 static double current_time_get(double timestamp)
76 {
77         double ret;
78
79         if (WIDGET_CONF_USE_GETTIMEOFDAY) {
80                 struct timeval tv;
81                 if (gettimeofday(&tv, NULL) < 0) {
82                         ErrPrint("gettimeofday: %d\n", errno);
83                         ret = timestamp;
84                 } else {
85                         ret = (double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0f);
86                 }
87         } else {
88                 ret = timestamp;
89         }
90
91         return ret;
92 }
93
94 /* pkgname, id, signal_name, source, sx, sy, ex, ey, x, y, down, ret */
95 static struct packet *master_script(pid_t pid, int handle, const struct packet *packet)
96 {
97         struct widget_event_arg arg;
98         int ret;
99
100         ret = packet_get(packet, "ssssddddddi",
101                         &arg.pkgname, &arg.id,
102                         &arg.info.content_event.signal_name, &arg.info.content_event.source,
103                         &(arg.info.content_event.info.part.sx), &(arg.info.content_event.info.part.sy),
104                         &(arg.info.content_event.info.part.ex), &(arg.info.content_event.info.part.ey),
105                         &(arg.info.content_event.info.pointer.x), &(arg.info.content_event.info.pointer.y),
106                         &(arg.info.content_event.info.pointer.down));
107         if (ret != 11) {
108                 ErrPrint("Parameter is not valid\n");
109                 goto errout;
110         }
111
112         arg.type = WIDGET_EVENT_CONTENT_EVENT;
113
114         if (s_info.table.content_event) {
115                 (void)s_info.table.content_event(&arg, s_info.data);
116         }
117
118 errout:
119         return NULL;
120 }
121
122 /* pkgname, id, event, timestamp, x, y, ret */
123 static struct packet *master_clicked(pid_t pid, int handle, const struct packet *packet)
124 {
125         int ret;
126         struct widget_event_arg arg;
127
128         ret = packet_get(packet, "sssddd",
129                         &arg.pkgname, &arg.id,
130                         &arg.info.clicked.event,
131                         &arg.info.clicked.timestamp,
132                         &arg.info.clicked.x, &arg.info.clicked.y);
133         if (ret != 6) {
134                 ErrPrint("Parameter is not valid\n");
135                 goto errout;
136         }
137
138         arg.type = WIDGET_EVENT_CLICKED;
139
140         DbgPrint("Clicked: %s\n", arg.id);
141         if (s_info.table.clicked) {
142                 (void)s_info.table.clicked(&arg, s_info.data);
143         }
144
145 errout:
146         return NULL;
147 }
148
149 /* pkgname, id, signal_name, source, x, y, ex, ey, ret */
150 static struct packet *master_text_signal(pid_t pid, int handle, const struct packet *packet)
151 {
152         struct widget_event_arg arg;
153         int ret;
154
155         ret = packet_get(packet, "ssssdddd",
156                         &arg.pkgname, &arg.id,
157                         &arg.info.text_signal.signal_name, &arg.info.text_signal.source,
158                         &(arg.info.text_signal.info.part.sx), &(arg.info.text_signal.info.part.sy),
159                         &(arg.info.text_signal.info.part.ex), &(arg.info.text_signal.info.part.ey));
160
161         if (ret != 8) {
162                 ErrPrint("Parameter is not valid\n");
163                 goto errout;
164         }
165
166         arg.info.text_signal.info.pointer.x = 0.0f;
167         arg.info.text_signal.info.pointer.y = 0.0f;
168         arg.info.text_signal.info.pointer.down = 0;
169         arg.type = WIDGET_EVENT_TEXT_SIGNAL;
170
171         if (s_info.table.text_signal) {
172                 (void)s_info.table.text_signal(&arg, s_info.data);
173         }
174
175 errout:
176         return NULL;
177 }
178
179 /* pkgname, id, ret */
180 static struct packet *master_delete(pid_t pid, int handle, const struct packet *packet)
181 {
182         struct packet *result;
183         struct widget_event_arg arg;
184         int ret;
185         int type;
186
187         ret = packet_get(packet, "ssi", &arg.pkgname, &arg.id, &type);
188         if (ret != 3) {
189                 ErrPrint("Parameter is not valid\n");
190                 ret = WIDGET_ERROR_INVALID_PARAMETER;
191                 goto errout;
192         }
193
194         arg.type = WIDGET_EVENT_DELETE;
195         arg.info.widget_destroy.type = type;
196         DbgPrint("WIDGET Deleted, reason(%d)\n", type);
197
198         if (s_info.table.widget_destroy) {
199                 ret = s_info.table.widget_destroy(&arg, s_info.data);
200         } else {
201                 ret = WIDGET_ERROR_NOT_SUPPORTED;
202         }
203
204 errout:
205         result = packet_create_reply(packet, "i", ret);
206         return result;
207 }
208
209 /* pkgname, id, w, h, ret */
210 static struct packet *master_resize(pid_t pid, int handle, const struct packet *packet)
211 {
212         struct widget_event_arg arg;
213         int ret;
214         struct packet *result;
215
216         ret = packet_get(packet, "ssii", &arg.pkgname, &arg.id, &arg.info.resize.w, &arg.info.resize.h);
217         if (ret != 4) {
218                 ErrPrint("Parameter is not valid\n");
219                 ret = WIDGET_ERROR_INVALID_PARAMETER;
220                 goto errout;
221         }
222
223         arg.type = WIDGET_EVENT_RESIZE;
224
225         if (s_info.table.resize) {
226                 ret = s_info.table.resize(&arg, s_info.data);
227         } else {
228                 ret = WIDGET_ERROR_NOT_SUPPORTED;
229         }
230
231 errout:
232         result = packet_create_reply(packet, "i", ret);
233         return result;
234 }
235
236 /* pkgname, id, content, timeout, has_Script, period, cluster, category, pinup, width, height, abi, ret */
237 static struct packet *master_renew(pid_t pid, int handle, const struct packet *packet)
238 {
239         struct widget_event_arg arg;
240         int ret;
241         struct packet *result;
242         char *content;
243         char *title;
244
245         arg.info.widget_recreate.out_title = NULL;
246         arg.info.widget_recreate.out_content = NULL;
247         arg.info.widget_recreate.out_is_pinned_up = 0;
248
249         ret = packet_get(packet, "sssiidssiisiis", &arg.pkgname, &arg.id,
250                         &arg.info.widget_recreate.content,
251                         &arg.info.widget_recreate.timeout,
252                         &arg.info.widget_recreate.has_script,
253                         &arg.info.widget_recreate.period,
254                         &arg.info.widget_recreate.cluster, &arg.info.widget_recreate.category,
255                         &arg.info.widget_recreate.width, &arg.info.widget_recreate.height,
256                         &arg.info.widget_recreate.abi,
257                         &arg.info.widget_recreate.hold_scroll,
258                         &arg.info.widget_recreate.active_update,
259                         &arg.info.widget_recreate.direct_addr);
260         if (ret != 14) {
261                 ErrPrint("Parameter is not valid\n");
262                 ret = WIDGET_ERROR_INVALID_PARAMETER;
263                 goto errout;
264         }
265
266         arg.type = WIDGET_EVENT_RENEW;
267
268         if (s_info.table.widget_recreate) {
269                 ret = s_info.table.widget_recreate(&arg, s_info.data);
270         } else {
271                 ret = WIDGET_ERROR_NOT_SUPPORTED;
272         }
273
274 errout:
275         if (arg.info.widget_recreate.out_content) {
276                 content = arg.info.widget_recreate.out_content;
277         } else {
278                 content = "";
279         }
280
281         if (arg.info.widget_recreate.out_title) {
282                 title = arg.info.widget_recreate.out_title;
283         } else {
284                 title = "";
285         }
286
287         result = packet_create_reply(packet, "issi", ret, content, title, arg.info.widget_recreate.out_is_pinned_up);
288         /*!
289          * \note
290          * Release.
291          */
292         free(arg.info.widget_recreate.out_title);
293         free(arg.info.widget_recreate.out_content);
294         arg.info.widget_recreate.out_title = NULL;
295         arg.info.widget_recreate.out_content = NULL;
296         return result;
297 }
298
299 /* pkgname, id, content, timeout, has_script, period, cluster, category, pinup, skip_need_to_create, abi, result, width, height, priority */
300 static struct packet *master_new(pid_t pid, int handle, const struct packet *packet)
301 {
302         struct widget_event_arg arg;
303         int ret;
304         struct packet *result;
305         int width = 0;
306         int height = 0;
307         double priority = 0.0f;
308         char *content;
309         char *title;
310
311         arg.info.widget_create.out_content = NULL;
312         arg.info.widget_create.out_title = NULL;
313         arg.info.widget_create.out_is_pinned_up = 0;
314
315         ret = packet_get(packet, "sssiidssisiis", &arg.pkgname, &arg.id,
316                         &arg.info.widget_create.content,
317                         &arg.info.widget_create.timeout,
318                         &arg.info.widget_create.has_script,
319                         &arg.info.widget_create.period,
320                         &arg.info.widget_create.cluster, &arg.info.widget_create.category,
321                         &arg.info.widget_create.skip_need_to_create,
322                         &arg.info.widget_create.abi,
323                         &arg.info.widget_create.width,
324                         &arg.info.widget_create.height,
325                         &arg.info.widget_create.direct_addr);
326         if (ret != 13) {
327                 ErrPrint("Parameter is not valid\n");
328                 ret = WIDGET_ERROR_INVALID_PARAMETER;
329                 goto errout;
330         }
331
332         arg.type = WIDGET_EVENT_NEW;
333
334         if (s_info.table.widget_create) {
335                 ret = s_info.table.widget_create(&arg, &width, &height, &priority, s_info.data);
336         } else {
337                 ret = WIDGET_ERROR_NOT_SUPPORTED;
338         }
339
340 errout:
341         if (arg.info.widget_create.out_content) {
342                 content = arg.info.widget_create.out_content;
343         } else {
344                 content = "";
345         }
346
347         if (arg.info.widget_create.out_title) {
348                 title = arg.info.widget_create.out_title;
349         } else {
350                 title = "";
351         }
352
353         result = packet_create_reply(packet, "iiidssi", ret, width, height, priority, content, title, arg.info.widget_create.out_is_pinned_up);
354
355         /*!
356          * Note:
357          * Skip checking the address of out_content, out_title
358          */
359         free(arg.info.widget_create.out_content);
360         free(arg.info.widget_create.out_title);
361         return result;
362 }
363
364 /* pkgname, id, period, ret */
365 static struct packet *master_set_period(pid_t pid, int handle, const struct packet *packet)
366 {
367         struct widget_event_arg arg;
368         int ret;
369         struct packet *result;
370
371         ret = packet_get(packet, "ssd", &arg.pkgname, &arg.id, &arg.info.set_period.period);
372         if (ret != 3) {
373                 ErrPrint("Parameter is not valid\n");
374                 ret = WIDGET_ERROR_INVALID_PARAMETER;
375                 goto errout;
376         }
377
378         arg.type = WIDGET_EVENT_SET_PERIOD;
379
380         if (s_info.table.set_period) {
381                 ret = s_info.table.set_period(&arg, s_info.data);
382         } else {
383                 ret = WIDGET_ERROR_NOT_SUPPORTED;
384         }
385
386 errout:
387         result = packet_create_reply(packet, "i", ret);
388         return result;
389 }
390
391 /* pkgname, id, cluster, category, ret */
392 static struct packet *master_change_group(pid_t pid, int handle, const struct packet *packet)
393 {
394         struct widget_event_arg arg;
395         int ret;
396         struct packet *result;
397
398         ret = packet_get(packet, "ssss", &arg.pkgname, &arg.id,
399                         &arg.info.change_group.cluster, &arg.info.change_group.category);
400         if (ret != 4) {
401                 ErrPrint("Parameter is not valid\n");
402                 ret = WIDGET_ERROR_INVALID_PARAMETER;
403                 goto errout;
404         }
405
406         arg.type = WIDGET_EVENT_CHANGE_GROUP;
407
408         if (s_info.table.change_group) {
409                 ret = s_info.table.change_group(&arg, s_info.data);
410         } else {
411                 ret = WIDGET_ERROR_NOT_SUPPORTED;
412         }
413
414 errout:
415         result = packet_create_reply(packet, "i", ret);
416         return result;
417 }
418
419 /* pkgname, id, pinup, ret */
420 static struct packet *master_pinup(pid_t pid, int handle, const struct packet *packet)
421 {
422         struct widget_event_arg arg;
423         int ret;
424         struct packet *result;
425         const char *content;
426
427         ret = packet_get(packet, "ssi", &arg.pkgname, &arg.id, &arg.info.pinup.state);
428         if (ret != 3) {
429                 ErrPrint("Parameter is not valid\n");
430                 ret = WIDGET_ERROR_INVALID_PARAMETER;
431                 goto errout;
432         }
433
434         arg.type = WIDGET_EVENT_PINUP;
435
436         if (s_info.table.pinup) {
437                 ret = s_info.table.pinup(&arg, s_info.data);
438         } else {
439                 ret = WIDGET_ERROR_NOT_SUPPORTED;
440         }
441
442 errout:
443         content = "default";
444         if (ret == 0 && arg.info.pinup.content_info) {
445                 content = arg.info.pinup.content_info;
446         }
447
448         result = packet_create_reply(packet, "is", ret, content);
449         if (ret == 0) {
450                 free(arg.info.pinup.content_info);
451         }
452         return result;
453 }
454
455 /* pkgname, id, cluster, category, content, ret */
456 static struct packet *master_update_content(pid_t pid, int handle, const struct packet *packet)
457 {
458         struct widget_event_arg arg;
459         int ret;
460
461         ret = packet_get(packet, "sssssi", &arg.pkgname, &arg.id, &arg.info.update_content.cluster, &arg.info.update_content.category, &arg.info.update_content.content, &arg.info.update_content.force);
462         if (ret != 6) {
463                 ErrPrint("Parameter is not valid\n");
464                 goto errout;
465         }
466
467         arg.type = WIDGET_EVENT_UPDATE_CONTENT;
468
469         if (s_info.table.update_content) {
470                 (void)s_info.table.update_content(&arg, s_info.data);
471         }
472
473 errout:
474         return NULL;
475 }
476
477 static struct packet *master_widget_pause(pid_t pid, int handle, const struct packet *packet)
478 {
479         struct widget_event_arg arg;
480         int ret;
481
482         ret = packet_get(packet, "ss", &arg.pkgname, &arg.id);
483         if (ret != 2) {
484                 ErrPrint("Invalid parameter\n");
485                 return NULL;
486         }
487
488         arg.type = WIDGET_EVENT_WIDGET_PAUSE;
489
490         if (s_info.table.widget_pause) {
491                 (void)s_info.table.widget_pause(&arg, s_info.data);
492         }
493
494         return NULL;
495 }
496
497 static struct packet *master_widget_resume(pid_t pid, int handle, const struct packet *packet)
498 {
499         struct widget_event_arg arg;
500         int ret;
501
502         ret = packet_get(packet, "ss", &arg.pkgname, &arg.id);
503         if (ret != 2) {
504                 ErrPrint("Invalid parameter\n");
505                 return NULL;
506         }
507
508         arg.type = WIDGET_EVENT_WIDGET_RESUME;
509
510         if (s_info.table.widget_resume) {
511                 (void)s_info.table.widget_resume(&arg, s_info.data);
512         }
513
514         return NULL;
515 }
516
517 /* timestamp, ret */
518 static struct packet *master_pause(pid_t pid, int handle, const struct packet *packet)
519 {
520         struct widget_event_arg arg;
521         struct packet *result;
522         int ret;
523
524         ret = packet_get(packet, "d", &arg.info.pause.timestamp);
525         if (ret != 1) {
526                 ErrPrint("Parameter is not valid\n");
527                 ret = WIDGET_ERROR_INVALID_PARAMETER;
528                 goto errout;
529         }
530         arg.pkgname = NULL;
531         arg.id = NULL;
532         arg.type = WIDGET_EVENT_PAUSE;
533
534         if (s_info.table.pause) {
535                 ret = s_info.table.pause(&arg, s_info.data);
536         } else {
537                 ret = WIDGET_ERROR_NOT_SUPPORTED;
538         }
539
540 errout:
541         result = packet_create_reply(packet, "i", ret);
542         return result;
543 }
544
545 static struct packet *master_update_mode(pid_t pid, int handle, const struct packet *packet)
546 {
547         struct packet *result;
548         struct widget_event_arg arg;
549         int ret;
550
551         ret = packet_get(packet, "ssi", &arg.pkgname, &arg.id, &arg.info.update_mode.active_update);
552         if (ret != 3) {
553                 ErrPrint("Invalid parameter\n");
554                 ret = WIDGET_ERROR_INVALID_PARAMETER;
555                 goto errout;
556         }
557
558         if (s_info.table.update_mode) {
559                 ret = s_info.table.update_mode(&arg, s_info.data);
560         } else {
561                 ret = WIDGET_ERROR_NOT_SUPPORTED;
562         }
563
564 errout:
565         result = packet_create_reply(packet, "i", ret);
566         return result;
567 }
568
569 static struct packet *master_widget_mouse_set(pid_t pid, int handle, const struct packet *packet)
570 {
571         const char *pkgname;
572         double timestamp;
573         const char *id;
574         int ret;
575         int x;
576         int y;
577         int fd;
578
579         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
580         if (ret != 5) {
581                 ErrPrint("Parameter is not matched\n");
582                 ret = WIDGET_ERROR_INVALID_PARAMETER;
583                 goto out;
584         }
585
586         fd = packet_fd(packet);
587         DbgPrint("FD: %d\n", fd);
588         if (fd >= 0 || event_input_fd() >= 0) {
589                 widget_buffer_h buffer_handler;
590
591                 buffer_handler = widget_provider_buffer_find_buffer(WIDGET_TYPE_WIDGET, pkgname, id);
592                 if (!buffer_handler) {
593                         if (close(fd) < 0) {
594                                 ErrPrint("close: %d\n", errno);
595                         }
596
597                         ErrPrint("Unable to find a buffer handler: %s\n", id);
598                         return NULL;
599                 }
600
601                 ret = event_add_object(fd, buffer_handler, current_time_get(timestamp), x, y);
602         }
603
604 out:
605         return NULL;
606 }
607
608 static struct packet *master_widget_mouse_unset(pid_t pid, int handle, const struct packet *packet)
609 {
610         widget_buffer_h buffer_handler;
611         const char *pkgname;
612         double timestamp;
613         const char *id;
614         int ret;
615         int x;
616         int y;
617
618         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
619         if (ret != 5) {
620                 ErrPrint("Parameter is not matched\n");
621                 ret = WIDGET_ERROR_INVALID_PARAMETER;
622                 goto out;
623         }
624
625         buffer_handler = widget_provider_buffer_find_buffer(WIDGET_TYPE_WIDGET, pkgname, id);
626         if (buffer_handler) {
627                 ret = event_remove_object(buffer_handler);
628         }
629
630 out:
631         return NULL;
632 }
633
634 static struct packet *master_gbar_mouse_set(pid_t pid, int handle, const struct packet *packet)
635 {
636         const char *pkgname;
637         double timestamp;
638         const char *id;
639         int ret;
640         int x;
641         int y;
642         int fd;
643
644         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
645         if (ret != 5) {
646                 ErrPrint("Parameter is not matched\n");
647                 ret = WIDGET_ERROR_INVALID_PARAMETER;
648                 goto out;
649         }
650
651         fd = packet_fd(packet);
652         DbgPrint("FD: %d\n", fd);
653         if (fd >= 0 || event_input_fd() >= 0) {
654                 widget_buffer_h buffer_handler;
655
656                 buffer_handler = widget_provider_buffer_find_buffer(WIDGET_TYPE_GBAR, pkgname, id);
657                 if (!buffer_handler) {
658                         if (close(fd) < 0) {
659                                 ErrPrint("close: %d\n", errno);
660                         }
661
662                         ErrPrint("Unable to find a buffer handler: %s\n", id);
663                         return NULL;
664                 }
665
666                 ret = event_add_object(fd, buffer_handler, current_time_get(timestamp), x, y);
667         }
668
669 out:
670         return NULL;
671 }
672
673 static struct packet *master_gbar_mouse_unset(pid_t pid, int handle, const struct packet *packet)
674 {
675         widget_buffer_h buffer_handler;
676         const char *pkgname;
677         double timestamp;
678         const char *id;
679         int ret;
680         int x;
681         int y;
682
683         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
684         if (ret != 5) {
685                 ErrPrint("Parameter is not matched\n");
686                 ret = WIDGET_ERROR_INVALID_PARAMETER;
687                 goto out;
688         }
689
690         buffer_handler = widget_provider_buffer_find_buffer(WIDGET_TYPE_GBAR, pkgname, id);
691         if (buffer_handler) {
692                 ret = event_remove_object(buffer_handler);
693         }
694
695 out:
696         return NULL;
697 }
698
699 /* timestamp, ret */
700 static struct packet *master_resume(pid_t pid, int handle, const struct packet *packet)
701 {
702         struct packet *result;
703         struct widget_event_arg arg;
704         int ret;
705
706         ret = packet_get(packet, "d", &arg.info.resume.timestamp);
707         if (ret != 1) {
708                 ErrPrint("Parameter is not valid\n");
709                 ret = WIDGET_ERROR_INVALID_PARAMETER;
710                 goto errout;
711         }
712
713         arg.pkgname = NULL;
714         arg.id = NULL;
715         arg.type = WIDGET_EVENT_RESUME;
716
717         if (s_info.table.resume) {
718                 ret = s_info.table.resume(&arg, s_info.data);
719         } else {
720                 ret = WIDGET_ERROR_NOT_SUPPORTED;
721         }
722
723 errout:
724         result = packet_create_reply(packet, "i", ret);
725         if (!result) {
726                 ErrPrint("Failed to create result packet\n");
727         }
728         return result;
729 }
730
731 struct packet *master_gbar_create(pid_t pid, int handle, const struct packet *packet)
732 {
733         struct widget_event_arg arg;
734         int ret;
735
736         ret = packet_get(packet, "ssiidd", &arg.pkgname, &arg.id, &arg.info.gbar_create.w, &arg.info.gbar_create.h, &arg.info.gbar_create.x, &arg.info.gbar_create.y);
737         if (ret != 6) {
738                 ErrPrint("Invalid packet\n");
739                 goto out;
740         }
741
742         arg.type = WIDGET_EVENT_GBAR_CREATE;
743
744         DbgPrint("PERF_WIDGET\n");
745         if (s_info.table.gbar_create) {
746                 (void)s_info.table.gbar_create(&arg, s_info.data);
747         }
748
749 out:
750         return NULL;
751 }
752
753 struct packet *master_disconnect(pid_t pid, int handle, const struct packet *packet)
754 {
755         double timestamp;
756         int ret;
757
758         ret = packet_get(packet, "d", &timestamp);
759         if (ret != 1) {
760                 ErrPrint("Invalid packet\n");
761                 goto errout;
762         }
763
764         if (s_info.fd >= 0 && s_info.closing_fd == 0) {
765                 s_info.closing_fd = 1;
766                 com_core_packet_client_fini(s_info.fd);
767                 fb_master_disconnected();
768                 s_info.fd = -1;
769                 s_info.closing_fd = 0;
770         }
771
772 errout:
773         return NULL;
774 }
775
776 struct packet *master_viewer_connected(pid_t pid, int handle, const struct packet *packet)
777 {
778         int ret;
779         struct widget_event_arg arg;
780
781         ret = packet_get(packet, "sss", &arg.pkgname, &arg.id, &arg.info.viewer_connected.direct_addr);
782         if (ret != 3) {
783                 ErrPrint("Invalid packet\n");
784                 goto errout;
785         }
786
787         /**
788          * Create a new connection if the direct_path is valid
789          */
790         arg.type = WIDGET_EVENT_VIEWER_CONNECTED;
791
792         if (s_info.table.viewer_connected) {
793                 ret = s_info.table.viewer_connected(&arg, s_info.data);
794         } else {
795                 ret = WIDGET_ERROR_NOT_SUPPORTED;
796         }
797
798 errout:
799         return NULL;
800 }
801
802 struct packet *master_viewer_disconnected(pid_t pid, int handle, const struct packet *packet)
803 {
804         int ret;
805         struct widget_event_arg arg;
806
807         ret = packet_get(packet, "sss", &arg.pkgname, &arg.id, &arg.info.viewer_disconnected.direct_addr);
808         if (ret != 3) {
809                 ErrPrint("Invalid packet\n");
810                 goto errout;
811         }
812
813         /**
814          * Destroy a connection, maybe it is already destroyed. ;)
815          */
816         arg.type = WIDGET_EVENT_VIEWER_DISCONNECTED;
817
818         if (s_info.table.viewer_disconnected) {
819                 ret = s_info.table.viewer_disconnected(&arg, s_info.data);
820         } else {
821                 ret = WIDGET_ERROR_NOT_SUPPORTED;
822         }
823
824 errout:
825         return NULL;
826 }
827
828 struct packet *master_gbar_move(pid_t pid, int handle, const struct packet *packet)
829 {
830         struct widget_event_arg arg;
831         int ret;
832
833         ret = packet_get(packet, "ssiidd", &arg.pkgname, &arg.id, &arg.info.gbar_move.w, &arg.info.gbar_move.h, &arg.info.gbar_move.x, &arg.info.gbar_move.y);
834         if (ret != 6) {
835                 ErrPrint("Invalid packet\n");
836                 goto out;
837         }
838
839         arg.type = WIDGET_EVENT_GBAR_MOVE;
840
841         if (s_info.table.gbar_move) {
842                 (void)s_info.table.gbar_move(&arg, s_info.data);
843         }
844
845 out:
846         return NULL;
847 }
848
849 struct packet *master_gbar_destroy(pid_t pid, int handle, const struct packet *packet)
850 {
851         struct widget_event_arg arg;
852         int ret;
853
854         ret = packet_get(packet, "ssi", &arg.pkgname, &arg.id, &arg.info.gbar_destroy.reason);
855         if (ret != 3) {
856                 ErrPrint("Invalid packet\n");
857                 goto out;
858         }
859
860         arg.type = WIDGET_EVENT_GBAR_DESTROY;
861         if (s_info.table.gbar_destroy) {
862                 (void)s_info.table.gbar_destroy(&arg, s_info.data);
863         }
864
865 out:
866         return NULL;
867 }
868
869 static struct method s_table[] = {
870         /*!< For the buffer type */
871         {
872                 .cmd = CMD_STR_GBAR_MOUSE_MOVE,
873                 .handler = provider_buffer_gbar_mouse_move,
874         },
875         {
876                 .cmd = CMD_STR_WIDGET_MOUSE_MOVE,
877                 .handler = provider_buffer_widget_mouse_move,
878         },
879         {
880                 .cmd = CMD_STR_GBAR_MOUSE_DOWN,
881                 .handler = provider_buffer_gbar_mouse_down,
882         },
883         {
884                 .cmd = CMD_STR_GBAR_MOUSE_UP,
885                 .handler = provider_buffer_gbar_mouse_up,
886         },
887         {
888                 .cmd = CMD_STR_WIDGET_MOUSE_DOWN,
889                 .handler = provider_buffer_widget_mouse_down,
890         },
891         {
892                 .cmd = CMD_STR_WIDGET_MOUSE_UP,
893                 .handler = provider_buffer_widget_mouse_up,
894         },
895         {
896                 .cmd = CMD_STR_GBAR_MOUSE_ENTER,
897                 .handler = provider_buffer_gbar_mouse_enter,
898         },
899         {
900                 .cmd = CMD_STR_GBAR_MOUSE_LEAVE,
901                 .handler = provider_buffer_gbar_mouse_leave,
902         },
903         {
904                 .cmd = CMD_STR_WIDGET_MOUSE_ENTER,
905                 .handler = provider_buffer_widget_mouse_enter,
906         },
907         {
908                 .cmd = CMD_STR_WIDGET_MOUSE_LEAVE,
909                 .handler = provider_buffer_widget_mouse_leave,
910         },
911         {
912                 .cmd = CMD_STR_WIDGET_MOUSE_ON_SCROLL,
913                 .handler = provider_buffer_widget_mouse_on_hold,
914         },
915         {
916                 .cmd = CMD_STR_WIDGET_MOUSE_OFF_SCROLL,
917                 .handler = provider_buffer_widget_mouse_off_hold,
918         },
919         {
920                 .cmd = CMD_STR_GBAR_MOUSE_ON_SCROLL,
921                 .handler = provider_buffer_gbar_mouse_on_hold,
922         },
923         {
924                 .cmd = CMD_STR_GBAR_MOUSE_OFF_SCROLL,
925                 .handler = provider_buffer_gbar_mouse_off_hold,
926         },
927         {
928                 .cmd = CMD_STR_WIDGET_MOUSE_ON_HOLD,
929                 .handler = provider_buffer_widget_mouse_on_hold,
930         },
931         {
932                 .cmd = CMD_STR_WIDGET_MOUSE_OFF_HOLD,
933                 .handler = provider_buffer_widget_mouse_off_hold,
934         },
935         {
936                 .cmd = CMD_STR_GBAR_MOUSE_ON_HOLD,
937                 .handler = provider_buffer_gbar_mouse_on_hold,
938         },
939         {
940                 .cmd = CMD_STR_GBAR_MOUSE_OFF_HOLD,
941                 .handler = provider_buffer_gbar_mouse_off_hold,
942         },
943         {
944                 .cmd = CMD_STR_CLICKED,
945                 .handler = master_clicked, /* pkgname, id, event, timestamp, x, y, ret */
946         },
947         {
948                 .cmd = CMD_STR_TEXT_SIGNAL,
949                 .handler = master_text_signal, /* pkgname, id, signal_name, source, x, y, ex, ey, ret */
950         },
951         {
952                 .cmd = CMD_STR_DELETE,
953                 .handler = master_delete, /* pkgname, id, ret */
954         },
955         {
956                 .cmd = CMD_STR_RESIZE,
957                 .handler = master_resize, /* pkgname, id, w, h, ret */
958         },
959         {
960                 .cmd = CMD_STR_NEW,
961                 .handler = master_new, /* pkgname, id, content, timeout, has_script, period, cluster, category, pinup, skip_need_to_create, abi, result, width, height, priority */
962         },
963         {
964                 .cmd = CMD_STR_SET_PERIOD,
965                 .handler = master_set_period, /* pkgname, id, period, ret */
966         },
967         {
968                 .cmd = CMD_STR_CHANGE_GROUP,
969                 .handler = master_change_group, /* pkgname, id, cluster, category, ret */
970         },
971         {
972                 .cmd = CMD_STR_GBAR_MOVE,
973                 .handler = master_gbar_move,
974         },
975         {
976                 .cmd = CMD_STR_GBAR_ACCESS_HL,
977                 .handler = provider_buffer_gbar_access_hl,
978         },
979         {
980                 .cmd = CMD_STR_GBAR_ACCESS_ACTIVATE,
981                 .handler = provider_buffer_gbar_access_activate,
982         },
983         {
984                 .cmd = CMD_STR_GBAR_ACCESS_ACTION,
985                 .handler = provider_buffer_gbar_access_action,
986         },
987         {
988                 .cmd = CMD_STR_GBAR_ACCESS_SCROLL,
989                 .handler = provider_buffer_gbar_access_scroll,
990         },
991         {
992                 .cmd = CMD_STR_GBAR_ACCESS_VALUE_CHANGE,
993                 .handler = provider_buffer_gbar_access_value_change,
994         },
995         {
996                 .cmd = CMD_STR_GBAR_ACCESS_MOUSE,
997                 .handler = provider_buffer_gbar_access_mouse,
998         },
999         {
1000                 .cmd = CMD_STR_GBAR_ACCESS_BACK,
1001                 .handler = provider_buffer_gbar_access_back,
1002         },
1003         {
1004                 .cmd = CMD_STR_GBAR_ACCESS_OVER,
1005                 .handler = provider_buffer_gbar_access_over,
1006         },
1007         {
1008                 .cmd = CMD_STR_GBAR_ACCESS_READ,
1009                 .handler = provider_buffer_gbar_access_read,
1010         },
1011         {
1012                 .cmd = CMD_STR_GBAR_ACCESS_ENABLE,
1013                 .handler = provider_buffer_gbar_access_enable,
1014         },
1015         {
1016                 .cmd = CMD_STR_WIDGET_ACCESS_HL,
1017                 .handler = provider_buffer_widget_access_hl,
1018         },
1019         {
1020                 .cmd = CMD_STR_WIDGET_ACCESS_ACTIVATE,
1021                 .handler = provider_buffer_widget_access_activate,
1022         },
1023         {
1024                 .cmd = CMD_STR_WIDGET_ACCESS_ACTION,
1025                 .handler = provider_buffer_widget_access_action,
1026         },
1027         {
1028                 .cmd = CMD_STR_WIDGET_ACCESS_SCROLL,
1029                 .handler = provider_buffer_widget_access_scroll,
1030         },
1031         {
1032                 .cmd = CMD_STR_WIDGET_ACCESS_VALUE_CHANGE,
1033                 .handler = provider_buffer_widget_access_value_change,
1034         },
1035         {
1036                 .cmd = CMD_STR_WIDGET_ACCESS_MOUSE,
1037                 .handler = provider_buffer_widget_access_mouse,
1038         },
1039         {
1040                 .cmd = CMD_STR_WIDGET_ACCESS_BACK,
1041                 .handler = provider_buffer_widget_access_back,
1042         },
1043         {
1044                 .cmd = CMD_STR_WIDGET_ACCESS_OVER,
1045                 .handler = provider_buffer_widget_access_over,
1046         },
1047         {
1048                 .cmd = CMD_STR_WIDGET_ACCESS_READ,
1049                 .handler = provider_buffer_widget_access_read,
1050         },
1051         {
1052                 .cmd = CMD_STR_WIDGET_ACCESS_ENABLE,
1053                 .handler = provider_buffer_widget_access_enable,
1054         },
1055         {
1056                 .cmd = CMD_STR_WIDGET_KEY_DOWN,
1057                 .handler = provider_buffer_widget_key_down,
1058         },
1059         {
1060                 .cmd = CMD_STR_WIDGET_KEY_UP,
1061                 .handler = provider_buffer_widget_key_up,
1062         },
1063         {
1064                 .cmd = CMD_STR_WIDGET_KEY_FOCUS_IN,
1065                 .handler = provider_buffer_widget_key_focus_in,
1066         },
1067         {
1068                 .cmd = CMD_STR_WIDGET_KEY_FOCUS_OUT,
1069                 .handler = provider_buffer_widget_key_focus_out,
1070         },
1071         {
1072                 .cmd = CMD_STR_GBAR_KEY_DOWN,
1073                 .handler = provider_buffer_gbar_key_down,
1074         },
1075         {
1076                 .cmd = CMD_STR_GBAR_KEY_UP,
1077                 .handler = provider_buffer_gbar_key_up,
1078         },
1079         {
1080                 .cmd = CMD_STR_GBAR_KEY_FOCUS_IN,
1081                 .handler = provider_buffer_widget_key_focus_in,
1082         },
1083         {
1084                 .cmd = CMD_STR_GBAR_KEY_FOCUS_OUT,
1085                 .handler = provider_buffer_widget_key_focus_out,
1086         },
1087         {
1088                 .cmd = CMD_STR_UPDATE_MODE,
1089                 .handler = master_update_mode,
1090         },
1091         {
1092                 .cmd = CMD_STR_WIDGET_MOUSE_SET,
1093                 .handler = master_widget_mouse_set,
1094         },
1095         {
1096                 .cmd = CMD_STR_WIDGET_MOUSE_UNSET,
1097                 .handler = master_widget_mouse_unset,
1098         },
1099         {
1100                 .cmd = CMD_STR_GBAR_MOUSE_SET,
1101                 .handler = master_gbar_mouse_set,
1102         },
1103         {
1104                 .cmd = CMD_STR_GBAR_MOUSE_UNSET,
1105                 .handler = master_gbar_mouse_unset,
1106         },
1107         {
1108                 .cmd = CMD_STR_GBAR_SHOW,
1109                 .handler = master_gbar_create,
1110         },
1111         {
1112                 .cmd = CMD_STR_GBAR_HIDE,
1113                 .handler = master_gbar_destroy,
1114         },
1115         {
1116                 .cmd = CMD_STR_WIDGET_PAUSE,
1117                 .handler = master_widget_pause,
1118         },
1119         {
1120                 .cmd = CMD_STR_WIDGET_RESUME,
1121                 .handler = master_widget_resume,
1122         },
1123         {
1124                 .cmd = CMD_STR_SCRIPT,
1125                 .handler = master_script, /* pkgname, id, signal_name, source, sx, sy, ex, ey, x, y, down, ret */
1126         },
1127         {
1128                 .cmd = CMD_STR_RENEW,
1129                 .handler = master_renew, /* pkgname, id, content, timeout, has_script, period, cluster, category, pinup, width, height, abi, ret */
1130         },
1131         {
1132                 .cmd = CMD_STR_PINUP,
1133                 .handler = master_pinup, /* pkgname, id, pinup, ret */
1134         },
1135         {
1136                 .cmd = CMD_STR_UPDATE_CONTENT,
1137                 .handler = master_update_content, /* pkgname, cluster, category, ret */
1138         },
1139         {
1140                 .cmd = CMD_STR_PAUSE,
1141                 .handler = master_pause, /* timestamp, ret */
1142         },
1143         {
1144                 .cmd = CMD_STR_RESUME,
1145                 .handler = master_resume, /* timestamp, ret */
1146         },
1147         {
1148                 .cmd = CMD_STR_DISCONNECT,
1149                 .handler = master_disconnect,
1150         },
1151         {
1152                 .cmd = CMD_STR_VIEWER_CONNECTED,
1153                 .handler = master_viewer_connected,
1154         },
1155         {
1156                 .cmd = CMD_STR_VIEWER_DISCONNECTED,
1157                 .handler = master_viewer_disconnected,
1158         },
1159         {
1160                 .cmd = NULL,
1161                 .handler = NULL,
1162         },
1163 };
1164
1165 static int connected_cb(int handle, void *data)
1166 {
1167         DbgPrint("Connected (%p) %d\n", s_info.table.connected, handle);
1168
1169         if (s_info.fd >= 0) {
1170                 ErrPrint("Already connected. Ignore this (%d)?\n", handle);
1171                 return 0;
1172         }
1173
1174         s_info.fd = handle;
1175
1176         if (s_info.table.connected) {
1177                 s_info.table.connected(NULL, s_info.data);
1178         }
1179
1180         return 0;
1181 }
1182
1183 static int disconnected_cb(int handle, void *data)
1184 {
1185         if (s_info.fd != handle) {
1186                 DbgPrint("%d is not my favor (%d)\n", handle, s_info.fd);
1187                 return 0;
1188         }
1189
1190         DbgPrint("Disconnected (%d)\n", handle);
1191         if (s_info.table.disconnected) {
1192                 s_info.table.disconnected(NULL, s_info.data);
1193         }
1194
1195         /* Reset the FD */
1196         s_info.fd = -1;
1197         return 0;
1198 }
1199
1200 static int initialize_provider(void *disp, const char *name, widget_event_table_h table, void *data)
1201 {
1202         int ret;
1203
1204         s_info.name = strdup(name);
1205         if (!s_info.name) {
1206                 ErrPrint("Heap: %d\n", errno);
1207                 return WIDGET_ERROR_OUT_OF_MEMORY;
1208         }
1209
1210         memcpy(&s_info.table, table, sizeof(*table));
1211         s_info.data = data;
1212
1213         com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
1214
1215         ret = com_core_packet_client_init(SLAVE_SOCKET, 0, s_table);
1216         if (ret < 0) {
1217                 ErrPrint("Failed to establish the connection with the master\n");
1218                 s_info.data = NULL;
1219                 free(s_info.name);
1220                 s_info.name = NULL;
1221                 return (ret == -EACCES) ? WIDGET_ERROR_PERMISSION_DENIED : WIDGET_ERROR_FAULT;
1222         }
1223
1224         widget_provider_buffer_init(disp);
1225         connected_cb(ret, NULL);
1226
1227         DbgPrint("Slave is initialized\n");
1228         return WIDGET_ERROR_NONE;
1229 }
1230
1231 static char *keep_file_in_safe(const char *id, int uri)
1232 {
1233         const char *path;
1234         int len;
1235         int base_idx;
1236         char *new_path;
1237
1238         path = uri ? widget_util_uri_to_path(id) : id;
1239         if (!path) {
1240                 ErrPrint("Invalid path\n");
1241                 return NULL;
1242         }
1243
1244         if (s_info.prevent_overwrite) {
1245                 char *ret;
1246
1247                 ret = strdup(path);
1248                 if (!ret) {
1249                         ErrPrint("Heap: %d\n", errno);
1250                 }
1251
1252                 return ret;
1253         }
1254
1255         if (access(path, R_OK | F_OK) != 0) {
1256                 ErrPrint("[%s] %d\n", path, errno);
1257                 return NULL;
1258         }
1259
1260         len = strlen(path);
1261         base_idx = len - 1;
1262
1263         while (base_idx > 0 && path[base_idx] != '/') base_idx--;
1264         base_idx += (path[base_idx] == '/');
1265
1266         new_path = malloc(len + 10 + 30); /* for "tmp" tv_sec, tv_usec */
1267         if (!new_path) {
1268                 ErrPrint("Heap: %d\n", errno);
1269                 return NULL;
1270         }
1271
1272         strncpy(new_path, path, base_idx);
1273
1274 #if defined(_USE_ECORE_TIME_GET)
1275         double tval;
1276
1277         tval = util_timestamp();
1278
1279         snprintf(new_path + base_idx, len + 10 - base_idx + 30, "reader/%lf.%s", tval, path + base_idx);
1280 #else
1281         struct timeval tv;
1282         if (gettimeofday(&tv, NULL) < 0) {
1283                 ErrPrint("gettimeofday: %d\n", errno);
1284                 tv.tv_sec = rand();
1285                 tv.tv_usec = rand();
1286         }
1287
1288         snprintf(new_path + base_idx, len + 10 - base_idx + 30, "reader/%lu.%lu.%s", tv.tv_sec, tv.tv_usec, path + base_idx);
1289 #endif
1290
1291         /*!
1292          * To prevent from failing of rename a content file
1293          */
1294         (void)unlink(new_path);
1295
1296         if (rename(path, new_path) < 0) {
1297                 ErrPrint("Failed to keep content in safe: %d (%s -> %s)\n", errno, path, new_path);
1298         }
1299
1300         return new_path;
1301 }
1302
1303 const char *provider_name(void)
1304 {
1305         return s_info.name;
1306 }
1307
1308 EAPI int widget_provider_prepare_init(const char *abi, const char *accel, int secured)
1309 {
1310         if (s_info.abi) {
1311                 free(s_info.abi);
1312                 s_info.abi = NULL;
1313         }
1314
1315         if (s_info.accel) {
1316                 free(s_info.accel);
1317                 s_info.accel = NULL;
1318         }
1319
1320         if (abi) {
1321                 s_info.abi = strdup(abi);
1322                 if (!s_info.abi) {
1323                         ErrPrint("strdup: %d\n", errno);
1324                         return WIDGET_ERROR_OUT_OF_MEMORY;
1325                 }
1326         }
1327
1328         if (accel) {
1329                 s_info.accel = strdup(accel);
1330                 if (!s_info.accel) {
1331                         ErrPrint("strdup: %d\n", errno);
1332                         free(s_info.abi);
1333                         s_info.abi = NULL;
1334                         return WIDGET_ERROR_OUT_OF_MEMORY;
1335                 }
1336         }
1337
1338         s_info.secured = secured;
1339
1340         return WIDGET_ERROR_NONE;
1341 }
1342
1343 EAPI int widget_provider_init(void *disp, const char *name, widget_event_table_h table, void *data, int prevent_overwrite, int com_core_use_thread)
1344 {
1345         if (!name || !table) {
1346                 ErrPrint("Invalid argument\n");
1347                 return WIDGET_ERROR_INVALID_PARAMETER;
1348         }
1349
1350         if (s_info.name) {
1351                 ErrPrint("Provider is already initialized\n");
1352                 return WIDGET_ERROR_ALREADY_STARTED;
1353         }
1354
1355         s_info.prevent_overwrite = prevent_overwrite;
1356         com_core_packet_use_thread(com_core_use_thread);
1357
1358         return initialize_provider(disp, name, table, data);
1359 }
1360
1361 EAPI void *widget_provider_fini(void)
1362 {
1363         void *ret;
1364         static int provider_fini_called = 0;
1365
1366         if (provider_fini_called) {
1367                 ErrPrint("Provider finalize is already called\n");
1368                 return NULL;
1369         }
1370
1371         if (!s_info.name) {
1372                 ErrPrint("Connection is not established (or cleared already)\n");
1373                 return NULL;
1374         }
1375
1376         provider_fini_called = 1;
1377
1378         if (s_info.fd >= 0 && s_info.closing_fd == 0) {
1379                 s_info.closing_fd = 1;
1380                 com_core_packet_client_fini(s_info.fd);
1381                 fb_master_disconnected();
1382                 s_info.fd = -1;
1383                 s_info.closing_fd = 0;
1384         }
1385
1386         provider_fini_called = 0;
1387
1388         com_core_del_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
1389
1390         widget_provider_buffer_fini();
1391
1392         free(s_info.name);
1393         s_info.name = NULL;
1394
1395         free(s_info.accel);
1396         s_info.accel = NULL;
1397
1398         free(s_info.abi);
1399         s_info.abi = NULL;
1400
1401         ret = s_info.data;
1402         s_info.data = NULL;
1403
1404         return ret;
1405 }
1406
1407 EAPI int widget_provider_send_call(const char *pkgname, const char *id, const char *funcname)
1408 {
1409         struct packet *packet;
1410         unsigned int cmd = CMD_CALL;
1411         int ret;
1412
1413         if (!pkgname || !id || !funcname) {
1414                 ErrPrint("Invalid argument\n");
1415                 return WIDGET_ERROR_INVALID_PARAMETER;
1416         }
1417
1418         packet = packet_create_noack((const char *)&cmd, "sss", pkgname, id, funcname);
1419         if (!packet) {
1420                 ErrPrint("Failed to create a packet\n");
1421                 return WIDGET_ERROR_FAULT;
1422         }
1423
1424         ret = com_core_packet_send_only(s_info.fd, packet);
1425         packet_destroy(packet);
1426         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1427 }
1428
1429 EAPI int widget_provider_send_ret(const char *pkgname, const char *id, const char *funcname)
1430 {
1431         struct packet *packet;
1432         unsigned int cmd = CMD_RET;
1433         int ret;
1434
1435         if (!pkgname || !id || !funcname) {
1436                 ErrPrint("Invalid argument\n");
1437                 return WIDGET_ERROR_INVALID_PARAMETER;
1438         }
1439
1440         packet = packet_create_noack((const char *)&cmd, "sss", pkgname, id, funcname);
1441         if (!packet) {
1442                 ErrPrint("Failed to create a packet\n");
1443                 return WIDGET_ERROR_FAULT;
1444         }
1445
1446         ret = com_core_packet_send_only(s_info.fd, packet);
1447         packet_destroy(packet);
1448         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1449 }
1450
1451 EAPI int widget_provider_send_faulted(const char *pkgname, const char *id, const char *funcname)
1452 {
1453         struct packet *packet;
1454         unsigned int cmd = CMD_FAULTED;
1455         int ret;
1456
1457         if (!pkgname || !id || !funcname) {
1458                 ErrPrint("Invalid argument\n");
1459                 return WIDGET_ERROR_INVALID_PARAMETER;
1460         }
1461
1462         packet = packet_create_noack((const char *)&cmd, "sss", pkgname, id, funcname);
1463         if (!packet) {
1464                 ErrPrint("Failed to create a packet\n");
1465                 return WIDGET_ERROR_FAULT;
1466         }
1467
1468         ret = com_core_packet_send_only(s_info.fd, packet);
1469         packet_destroy(packet);
1470         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1471 }
1472
1473 EAPI int widget_provider_send_hello_sync(const char *pkgname)
1474 {
1475         struct packet *packet;
1476         struct packet *result;
1477         unsigned int cmd;
1478         int ret;
1479         const char *accel;
1480         const char *abi;
1481         struct widget_event_arg arg;
1482         int width = 0;
1483         int height = 0;
1484         double priority = 0.0f;
1485         double sync_ctx;
1486
1487         DbgPrint("name[%s]\n", s_info.name);
1488
1489         if (!s_info.name) {
1490                 ErrPrint("Provider is not initialized\n");
1491                 return WIDGET_ERROR_INVALID_PARAMETER;
1492         }
1493
1494         if (s_info.fd < 0) {
1495                 ErrPrint("Connection is not established\n");
1496                 return WIDGET_ERROR_INVALID_PARAMETER;
1497         }
1498
1499         accel = s_info.accel ? s_info.accel : SW_ACCEL;
1500         abi = s_info.abi ? s_info.abi : WIDGET_CONF_DEFAULT_ABI;
1501         DbgPrint("Accel[%s], abi[%s]\n", accel, abi);
1502
1503         cmd = CMD_HELLO_SYNC_PREPARE;
1504         sync_ctx = util_timestamp();
1505         packet = packet_create_noack((const char *)&cmd, "d", sync_ctx);
1506         if (!packet) {
1507                 ErrPrint("Failed to create a packet\n");
1508                 return WIDGET_ERROR_FAULT;
1509         }
1510
1511         ret = com_core_packet_send_only(s_info.fd, packet);
1512         packet_destroy(packet);
1513         if (ret < 0) {
1514                 return WIDGET_ERROR_FAULT;
1515         }
1516
1517         cmd = CMD_HELLO_SYNC;
1518         packet = packet_create((const char *)&cmd, "dissss", sync_ctx, s_info.secured, s_info.name, pkgname, accel, abi);
1519         if (!packet) {
1520                 ErrPrint("Failed to create a packet\n");
1521                 return WIDGET_ERROR_FAULT;
1522         }
1523
1524         result = com_core_packet_oneshot_send(SLAVE_SOCKET, packet, 0.0f);
1525         packet_destroy(packet);
1526
1527         if (s_info.table.widget_create) {
1528                 arg.info.widget_create.out_content = NULL;
1529                 arg.info.widget_create.out_title = NULL;
1530                 arg.info.widget_create.out_is_pinned_up = 0;
1531
1532                 ret = packet_get(result, "sssiidssisiis", &arg.pkgname, &arg.id,
1533                                 &arg.info.widget_create.content,
1534                                 &arg.info.widget_create.timeout,
1535                                 &arg.info.widget_create.has_script,
1536                                 &arg.info.widget_create.period,
1537                                 &arg.info.widget_create.cluster, &arg.info.widget_create.category,
1538                                 &arg.info.widget_create.skip_need_to_create,
1539                                 &arg.info.widget_create.abi,
1540                                 &arg.info.widget_create.width,
1541                                 &arg.info.widget_create.height,
1542                                 &arg.info.widget_create.direct_addr);
1543                 if (ret != 13) {
1544                         ErrPrint("Parameter is not valid\n");
1545                         packet_destroy(result);
1546                         return WIDGET_ERROR_INVALID_PARAMETER;
1547                 }
1548
1549                 arg.type = WIDGET_EVENT_NEW;
1550
1551                 ret = s_info.table.widget_create(&arg, &width, &height, &priority, s_info.data);
1552         } else {
1553                 ret = WIDGET_ERROR_NOT_SUPPORTED;
1554         }
1555
1556         ErrPrint("#widget_create return [%d]\n", ret);
1557         packet_destroy(result);
1558         return WIDGET_ERROR_NONE;
1559 }
1560
1561 EAPI int widget_provider_send_hello(void)
1562 {
1563         struct packet *packet;
1564         unsigned int cmd = CMD_HELLO;
1565         int ret;
1566         const char *accel;
1567         const char *abi;
1568
1569         DbgPrint("name[%s]\n", s_info.name);
1570
1571         if (!s_info.name) {
1572                 ErrPrint("Provider is not initialized\n");
1573                 return WIDGET_ERROR_INVALID_PARAMETER;
1574         }
1575
1576         if (s_info.fd < 0) {
1577                 ErrPrint("Connection is not established\n");
1578                 return WIDGET_ERROR_INVALID_PARAMETER;
1579         }
1580
1581         accel = s_info.accel ? s_info.accel : SW_ACCEL;
1582         abi = s_info.abi ? s_info.abi : WIDGET_CONF_DEFAULT_ABI;
1583         DbgPrint("Accel[%s], abi[%s]\n", accel, abi);
1584
1585         packet = packet_create_noack((const char *)&cmd, "isss", s_info.secured, s_info.name, accel, abi);
1586         if (!packet) {
1587                 ErrPrint("Failed to create a packet\n");
1588                 return WIDGET_ERROR_FAULT;
1589         }
1590
1591         ret = com_core_packet_send_only(s_info.fd, packet);
1592         packet_destroy(packet);
1593         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1594 }
1595
1596 EAPI int widget_provider_send_ping(void)
1597 {
1598         struct packet *packet;
1599         unsigned int cmd = CMD_PING;
1600         int ret;
1601
1602         DbgPrint("name[%s]\n", s_info.name);
1603         if (!s_info.name) {
1604                 ErrPrint("Provider is not initialized\n");
1605                 return WIDGET_ERROR_INVALID_PARAMETER;
1606         }
1607
1608         if (s_info.fd < 0) {
1609                 ErrPrint("Connection is not established\n");
1610                 return WIDGET_ERROR_INVALID_PARAMETER;
1611         }
1612
1613         packet = packet_create_noack((const char *)&cmd, "s", s_info.name);
1614         if (!packet) {
1615                 ErrPrint("Failed to create a a packet\n");
1616                 return WIDGET_ERROR_FAULT;
1617         }
1618
1619         ret = com_core_packet_send_only(s_info.fd, packet);
1620         packet_destroy(packet);
1621         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1622 }
1623
1624 EAPI int widget_provider_send_widget_update_begin(const char *pkgname, const char *id, double priority, const char *content_info, const char *title)
1625 {
1626         struct packet *packet;
1627         unsigned int cmd = CMD_WIDGET_UPDATE_BEGIN;
1628         int ret;
1629
1630         if (!pkgname || !id) {
1631                 ErrPrint("Invalid argument\n");
1632                 return WIDGET_ERROR_INVALID_PARAMETER;
1633         }
1634
1635         if (!content_info) {
1636                 content_info = "";
1637         }
1638
1639         if (!title) {
1640                 title = "";
1641         }
1642
1643         if (s_info.fd < 0) {
1644                 ErrPrint("Connection is not established\n");
1645                 return WIDGET_ERROR_INVALID_PARAMETER;
1646         }
1647
1648         packet = packet_create_noack((const char *)&cmd, "ssdss",
1649                         pkgname, id, priority, content_info, title);
1650         if (!packet) {
1651                 ErrPrint("Failed to build a packet\n");
1652                 return WIDGET_ERROR_FAULT;
1653         }
1654
1655         ret = com_core_packet_send_only(s_info.fd, packet);
1656         packet_destroy(packet);
1657
1658         DbgPrint("[ACTIVE] WIDGET BEGIN: %s (%d)\n", id, ret);
1659         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1660 }
1661
1662 EAPI int widget_provider_send_widget_update_end(const char *pkgname, const char *id)
1663 {
1664         struct packet *packet;
1665         unsigned int cmd = CMD_WIDGET_UPDATE_END;
1666         int ret;
1667
1668         if (!pkgname || !id) {
1669                 ErrPrint("Invalid argument\n");
1670                 return WIDGET_ERROR_INVALID_PARAMETER;
1671         }
1672
1673         if (s_info.fd < 0) {
1674                 ErrPrint("Connection is not established\n");
1675                 return WIDGET_ERROR_INVALID_PARAMETER;
1676         }
1677
1678         packet = packet_create_noack((const char *)&cmd, "ss", pkgname, id);
1679         if (!packet) {
1680                 ErrPrint("Failed to build a packet\n");
1681                 return WIDGET_ERROR_FAULT;
1682         }
1683
1684         ret = com_core_packet_send_only(s_info.fd, packet);
1685         packet_destroy(packet);
1686
1687         DbgPrint("[ACTIVE] WIDGET END: %s (%d)\n", id, ret);
1688         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1689 }
1690
1691 EAPI int widget_provider_send_gbar_update_begin(const char *pkgname, const char *id)
1692 {
1693         struct packet *packet;
1694         unsigned int cmd = CMD_GBAR_UPDATE_BEGIN;
1695         int ret;
1696
1697         if (!pkgname || !id) {
1698                 ErrPrint("Invalid argument\n");
1699                 return WIDGET_ERROR_INVALID_PARAMETER;
1700         }
1701
1702         if (s_info.fd < 0) {
1703                 ErrPrint("Connection is not established\n");
1704                 return WIDGET_ERROR_INVALID_PARAMETER;
1705         }
1706
1707         packet = packet_create_noack((const char *)&cmd, "ss", pkgname, id);
1708         if (!packet) {
1709                 ErrPrint("Failed to build a packet\n");
1710                 return WIDGET_ERROR_FAULT;
1711         }
1712
1713         ret = com_core_packet_send_only(s_info.fd, packet);
1714         packet_destroy(packet);
1715
1716         DbgPrint("[ACTIVE] GBAR BEGIN: %s (%d)\n", id, ret);
1717         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1718 }
1719
1720 EAPI int widget_provider_send_gbar_update_end(const char *pkgname, const char *id)
1721 {
1722         struct packet *packet;
1723         unsigned int cmd = CMD_GBAR_UPDATE_END;
1724         int ret;
1725
1726         if (!pkgname || !id) {
1727                 ErrPrint("Invalid argument\n");
1728                 return WIDGET_ERROR_INVALID_PARAMETER;
1729         }
1730
1731         if (s_info.fd < 0) {
1732                 ErrPrint("Connection is not established\n");
1733                 return WIDGET_ERROR_INVALID_PARAMETER;
1734         }
1735
1736         packet = packet_create_noack((const char *)&cmd, "ss", pkgname, id);
1737         if (!packet) {
1738                 ErrPrint("Failed to build a packet\n");
1739                 return WIDGET_ERROR_FAULT;
1740         }
1741
1742         ret = com_core_packet_send_only(s_info.fd, packet);
1743         packet_destroy(packet);
1744
1745         DbgPrint("[ACTIVE] GBAR END: %s (%d)\n", id, ret);
1746         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1747 }
1748
1749 EAPI int widget_provider_send_extra_info(const char *pkgname, const char *id, double priority, const char *content_info, const char *title, const char *icon, const char *name)
1750 {
1751         struct packet *packet;
1752         unsigned int cmd = CMD_EXTRA_INFO;
1753         int ret;
1754
1755         if (!pkgname || !id) {
1756                 ErrPrint("Invalid argument\n");
1757                 return WIDGET_ERROR_INVALID_PARAMETER;
1758         }
1759
1760         if (s_info.fd < 0) {
1761                 ErrPrint("Connection is not established\n");
1762                 return WIDGET_ERROR_INVALID_PARAMETER;
1763         }
1764
1765         packet = packet_create_noack((const char *)&cmd, "ssssssd", pkgname, id, content_info, title, icon, name, priority);
1766         if (!packet) {
1767                 ErrPrint("failed to build a packet\n");
1768                 return WIDGET_ERROR_FAULT;
1769         }
1770
1771         ret = com_core_packet_send_only(s_info.fd, packet);
1772         packet_destroy(packet);
1773         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1774 }
1775
1776 __attribute__((always_inline)) static inline int send_extra_buffer_updated(int fd, const char *pkgname, const char *id, widget_buffer_h info, int idx, widget_damage_region_s *region, int direct, int is_gbar)
1777 {
1778         int ret;
1779         struct packet *packet;
1780         unsigned int cmd;
1781
1782         if (info->extra_buffer[idx] == 0u) {
1783                 return WIDGET_ERROR_INVALID_PARAMETER;
1784         }
1785
1786         fb_sync_xdamage(info->fb, region);
1787
1788         cmd = CMD_EXTRA_UPDATED;
1789
1790         if (direct) {
1791                 packet = packet_create_noack((const char *)&cmd, "ssiiiiii", pkgname, id, is_gbar, idx, region->x, region->y, region->w, region->h);
1792         } else {
1793                 packet = packet_create_noack((const char *)&cmd, "ssiiiiii", pkgname, id, is_gbar, idx, region->x, region->y, region->w, region->h);
1794         }
1795
1796         if (!packet) {
1797                 ErrPrint("failed to build a packet\n");
1798                 return WIDGET_ERROR_FAULT;
1799         }
1800
1801         ret = com_core_packet_send_only(fd, packet);
1802         packet_destroy(packet);
1803
1804         return ret;
1805 }
1806
1807 __attribute__((always_inline)) static inline int send_extra_updated(int fd, const char *pkgname, const char *id, int idx, widget_damage_region_s *region, int direct, int is_gbar)
1808 {
1809         widget_buffer_h info;
1810         widget_damage_region_s _region = {
1811                 .x = 0,
1812                 .y = 0,
1813                 .w = 0,
1814                 .h = 0,
1815         };
1816         int ret;
1817
1818         if (!pkgname || !id || is_gbar < 0 || idx < 0 || idx > WIDGET_CONF_EXTRA_BUFFER_COUNT) {
1819                 ErrPrint("Invalid argument\n");
1820                 return WIDGET_ERROR_INVALID_PARAMETER;
1821         }
1822
1823         if (fd < 0) {
1824                 ErrPrint("Connection is not established\n");
1825                 return WIDGET_ERROR_INVALID_PARAMETER;
1826         }
1827
1828         info = widget_provider_buffer_find_buffer(WIDGET_TYPE_WIDGET, pkgname, id);
1829         if (!info) {
1830                 return WIDGET_ERROR_INVALID_PARAMETER;
1831         }
1832
1833         if (!region) {
1834                 int bpp = 0;
1835                 (void)widget_provider_buffer_get_size(info, &_region.w, &_region.h, &bpp);
1836                 region = &_region;
1837         }
1838
1839         ret = send_extra_buffer_updated(fd, pkgname, id, info, idx, region, direct, is_gbar);
1840         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1841 }
1842
1843 __attribute__((always_inline)) static inline int send_buffer_updated(int fd, const char *pkgname, const char *id, widget_buffer_h info, widget_damage_region_s *region, int direct, int for_gbar, const char *safe_filename)
1844 {
1845         struct packet *packet;
1846         unsigned int cmd = for_gbar ? CMD_DESC_UPDATED : CMD_UPDATED;
1847         int ret;
1848
1849         if (direct && info && widget_provider_buffer_uri(info)) {
1850                 fb_sync_xdamage(info->fb, region);
1851                 packet = packet_create_noack((const char *)&cmd, "ssssiiii", pkgname, id, widget_provider_buffer_uri(info), safe_filename, region->x, region->y, region->w, region->h);
1852         } else {
1853                 if (info) {
1854                         fb_sync_xdamage(info->fb, region);
1855                 }
1856                 packet = packet_create_noack((const char *)&cmd, "sssiiii", pkgname, id, safe_filename, region->x, region->y, region->w, region->h);
1857         }
1858
1859         if (!packet) {
1860                 ErrPrint("failed to build a packet\n");
1861                 return WIDGET_ERROR_FAULT;
1862         }
1863
1864         ret = com_core_packet_send_only(fd, packet);
1865         packet_destroy(packet);
1866
1867         return ret;
1868 }
1869
1870 __attribute__((always_inline)) static inline int send_updated(int fd, const char *pkgname, const char *id, widget_damage_region_s *region, int direct, int for_gbar, const char *descfile)
1871 {
1872         widget_buffer_h info;
1873         char *safe_filename = NULL;
1874         widget_damage_region_s _region = {
1875                 .x = 0,
1876                 .y = 0,
1877                 .w = 0,
1878                 .h = 0,
1879         };
1880         int ret;
1881
1882         if (!pkgname || !id) {
1883                 ErrPrint("Invalid argument\n");
1884                 return WIDGET_ERROR_INVALID_PARAMETER;
1885         }
1886
1887         if (fd < 0) {
1888                 ErrPrint("Connection is not established\n");
1889                 return WIDGET_ERROR_INVALID_PARAMETER;
1890         }
1891
1892         if (for_gbar && !descfile) {
1893                 descfile = widget_util_uri_to_path(id); /* In case of the NULL descfilename, use the ID */
1894                 if (!descfile) {
1895                         ErrPrint("Invalid descfile: %s\n", id);
1896                         return WIDGET_ERROR_INVALID_PARAMETER;
1897                 }
1898         }
1899
1900         info = widget_provider_buffer_find_buffer(for_gbar ? WIDGET_TYPE_GBAR : WIDGET_TYPE_WIDGET, pkgname, id);
1901         if (!info) {
1902                 safe_filename = keep_file_in_safe(for_gbar ? descfile : id, 1);
1903                 if (!safe_filename) {
1904                         return WIDGET_ERROR_INVALID_PARAMETER;
1905                 }
1906         } else {
1907                 if (for_gbar) {
1908                         safe_filename = strdup(descfile);
1909                         if (!safe_filename) {
1910                                 ErrPrint("strdup: %d\n", errno);
1911                                 return WIDGET_ERROR_OUT_OF_MEMORY;
1912                         }
1913                 }
1914         }
1915
1916         if (!region) {
1917                 if (info) {
1918                         int bpp = 0;
1919                         (void)widget_provider_buffer_get_size(info, &_region.w, &_region.h, &bpp);
1920                 }
1921                 region = &_region;
1922         }
1923
1924         ret = send_buffer_updated(fd, pkgname, id, info, region, direct, for_gbar, safe_filename);
1925         free(safe_filename);
1926         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
1927 }
1928
1929 EAPI int widget_provider_send_direct_updated(int fd, const char *pkgname, const char *id, int idx, widget_damage_region_s *region, int for_gbar, const char *descfile)
1930 {
1931         int ret;
1932
1933         if (idx == WIDGET_PRIMARY_BUFFER) {
1934                 ret = send_updated(fd, pkgname, id, region, 1, for_gbar, descfile);
1935         } else {
1936                 ret = send_extra_updated(fd, pkgname, id, idx, region, 1, for_gbar);
1937         }
1938
1939         return ret;
1940 }
1941
1942 EAPI int widget_provider_send_updated(const char *pkgname, const char *id, int idx, widget_damage_region_s *region, int for_gbar, const char *descfile)
1943 {
1944         int ret;
1945
1946         if (idx == WIDGET_PRIMARY_BUFFER) {
1947                 ret = send_updated(s_info.fd, pkgname, id, region, 0, for_gbar, descfile);
1948         } else {
1949                 ret = send_extra_updated(s_info.fd, pkgname, id, idx, region, 0, for_gbar);
1950         }
1951
1952         return ret;
1953 }
1954
1955 EAPI int widget_provider_send_direct_buffer_updated(int fd, widget_buffer_h handle, int idx, widget_damage_region_s *region, int for_gbar, const char *descfile)
1956 {
1957         int ret;
1958         const char *pkgname;
1959         const char *id;
1960
1961         pkgname = widget_provider_buffer_pkgname(handle);
1962         id = widget_provider_buffer_id(handle);
1963
1964         if (idx == WIDGET_PRIMARY_BUFFER) {
1965                 ret = send_buffer_updated(fd, pkgname, id, handle, region, 1, for_gbar, descfile);
1966         } else {
1967                 ret = send_extra_buffer_updated(fd, pkgname, id, handle, idx, region, 1, for_gbar);
1968         }
1969
1970         return ret;
1971 }
1972
1973 EAPI int widget_provider_send_buffer_updated(widget_buffer_h handle, int idx, widget_damage_region_s *region, int for_gbar, const char *descfile)
1974 {
1975         int ret;
1976         const char *pkgname;
1977         const char *id;
1978
1979         pkgname = widget_provider_buffer_pkgname(handle);
1980         id = widget_provider_buffer_id(handle);
1981
1982         if (idx == WIDGET_PRIMARY_BUFFER) {
1983                 ret = send_buffer_updated(s_info.fd, pkgname, id, handle, region, 0, for_gbar, descfile);
1984         } else {
1985                 ret = send_extra_buffer_updated(s_info.fd, pkgname, id, handle, idx, region, 0, for_gbar);
1986         }
1987
1988         return ret;
1989 }
1990
1991 EAPI int widget_provider_send_deleted(const char *pkgname, const char *id)
1992 {
1993         struct packet *packet;
1994         unsigned int cmd = CMD_DELETED;
1995         int ret;
1996
1997         if (!pkgname || !id) {
1998                 ErrPrint("Invalid arguement\n");
1999                 return WIDGET_ERROR_INVALID_PARAMETER;
2000         }
2001
2002         if (s_info.fd < 0) {
2003                 ErrPrint("Connection is not established\n");
2004                 return WIDGET_ERROR_INVALID_PARAMETER;
2005         }
2006
2007         packet = packet_create_noack((const char *)&cmd, "ss", pkgname, id);
2008         if (!packet) {
2009                 ErrPrint("Failed to build a packet\n");
2010                 return WIDGET_ERROR_FAULT;
2011         }
2012
2013         ret = com_core_packet_send_only(s_info.fd, packet);
2014         packet_destroy(packet);
2015         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
2016 }
2017
2018 EAPI int widget_provider_send_hold_scroll(const char *pkgname, const char *id, int hold)
2019 {
2020         struct packet *packet;
2021         unsigned int cmd = CMD_SCROLL;
2022         int ret;
2023
2024         if (!pkgname || !id) {
2025                 ErrPrint("Invalid argument\n");
2026                 return WIDGET_ERROR_INVALID_PARAMETER;
2027         }
2028
2029         if (s_info.fd < 0) {
2030                 ErrPrint("Connection is not established\n");
2031                 return WIDGET_ERROR_INVALID_PARAMETER;
2032         }
2033
2034         packet = packet_create_noack((const char *)&cmd, "ssi", pkgname, id, !!hold);
2035         if (!packet) {
2036                 ErrPrint("Failed to build a packet\n");
2037                 return WIDGET_ERROR_FAULT;
2038         }
2039
2040         ret = com_core_packet_send_only(s_info.fd, packet);
2041         packet_destroy(packet);
2042         DbgPrint("[HOLD] Send hold: %d (%s) ret(%d)\n", hold, id, ret);
2043         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
2044 }
2045
2046 EAPI int widget_provider_send_access_status(const char *pkgname, const char *id, int status)
2047 {
2048         struct packet *packet;
2049         unsigned int cmd = CMD_ACCESS_STATUS;
2050         int ret;
2051
2052         if (!pkgname || !id) {
2053                 ErrPrint("Invalid argument\n");
2054                 return WIDGET_ERROR_INVALID_PARAMETER;
2055         }
2056
2057         if (s_info.fd < 0) {
2058                 ErrPrint("Connection is not established\n");
2059                 return WIDGET_ERROR_INVALID_PARAMETER;
2060         }
2061
2062         packet = packet_create_noack((const char *)&cmd, "ssi", pkgname, id, status);
2063         if (!packet) {
2064                 ErrPrint("Failed to build a packet\n");
2065                 return WIDGET_ERROR_FAULT;
2066         }
2067
2068         ret = com_core_packet_send_only(s_info.fd, packet);
2069         packet_destroy(packet);
2070
2071         DbgPrint("[ACCESS] Send status: %d (%s) (%d)\n", status, id, ret);
2072         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
2073 }
2074
2075 EAPI int widget_provider_send_key_status(const char *pkgname, const char *id, int status)
2076 {
2077         struct packet *packet;
2078         unsigned int cmd = CMD_KEY_STATUS;
2079         int ret;
2080
2081         if (!pkgname || !id) {
2082                 ErrPrint("Invalid argument\n");
2083                 return WIDGET_ERROR_INVALID_PARAMETER;
2084         }
2085
2086         if (s_info.fd < 0) {
2087                 ErrPrint("Connection is not established\n");
2088                 return WIDGET_ERROR_INVALID_PARAMETER;
2089         }
2090
2091         packet = packet_create_noack((const char *)&cmd, "ssi", pkgname, id, status);
2092         if (!packet) {
2093                 ErrPrint("Failed to build a packet\n");
2094                 return WIDGET_ERROR_FAULT;
2095         }
2096
2097         ret = com_core_packet_send_only(s_info.fd, packet);
2098         packet_destroy(packet);
2099
2100         DbgPrint("[KEY] Send status: %d (%s) (%d)\n", status, id, ret);
2101         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
2102 }
2103
2104 EAPI int widget_provider_send_request_close_gbar(const char *pkgname, const char *id, int reason)
2105 {
2106         struct packet *packet;
2107         unsigned int cmd = CMD_CLOSE_GBAR;
2108         int ret;
2109
2110         if (!pkgname || !id) {
2111                 ErrPrint("Invalid argument\n");
2112                 return WIDGET_ERROR_INVALID_PARAMETER;
2113         }
2114
2115         if (s_info.fd < 0) {
2116                 ErrPrint("Connection is not established\n");
2117                 return WIDGET_ERROR_INVALID_PARAMETER;
2118         }
2119
2120         packet = packet_create_noack((const char *)&cmd, "ssi", pkgname, id, reason);
2121         if (!packet) {
2122                 ErrPrint("Failed to build a packet\n");
2123                 return WIDGET_ERROR_FAULT;
2124         }
2125
2126         ret = com_core_packet_send_only(s_info.fd, packet);
2127         packet_destroy(packet);
2128
2129         DbgPrint("[GBAR] Close GBAR: %d (%s) (%d)\n", reason, id, ret);
2130         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
2131 }
2132
2133 EAPI int widget_provider_control(int ctrl)
2134 {
2135         struct packet *packet;
2136         unsigned int cmd = CMD_CTRL;
2137         int ret;
2138
2139         if (s_info.fd < 0) {
2140                 ErrPrint("Connection is not established\n");
2141                 return WIDGET_ERROR_INVALID_PARAMETER;
2142         }
2143
2144         packet = packet_create_noack((const char *)&cmd, "i", ctrl);
2145         if (!packet) {
2146                 ErrPrint("Failed to build a packet\n");
2147                 return WIDGET_ERROR_FAULT;
2148         }
2149
2150         ret = com_core_packet_send_only(s_info.fd, packet);
2151         packet_destroy(packet);
2152
2153         DbgPrint("[CTRL] Request: 0x%x\n", (unsigned int)ctrl);
2154         return ret < 0 ? WIDGET_ERROR_FAULT : WIDGET_ERROR_NONE;
2155 }
2156
2157 EAPI void *widget_provider_callback_data(void)
2158 {
2159         return s_info.data;
2160 }
2161
2162 /* End of a file */