tizen 2.3 release
[apps/livebox/data-provider-master.git] / src / server.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 <unistd.h>
19 #include <errno.h>
20
21 #include <sys/smack.h>
22
23 #include <dlog.h>
24 #include <aul.h>
25 #include <Ecore.h>
26 #include <ail.h>
27
28 #include <packet.h>
29 #include <com-core_packet.h>
30 #include <dynamicbox_errno.h>
31 #include <dynamicbox_service.h>
32 #include <dynamicbox_cmd_list.h>
33 #include <dynamicbox_conf.h>
34 #include <dynamicbox_script.h>
35
36 #include "critical_log.h"
37 #include "conf.h"
38 #include "debug.h"
39 #include "server.h"
40 #include "slave_life.h"
41 #include "slave_rpc.h"
42 #include "client_life.h"
43 #include "instance.h"
44 #include "client_rpc.h"
45 #include "package.h"
46 #include "script_handler.h"
47 #include "buffer_handler.h"
48 #include "util.h"
49 #include "fault_manager.h"
50 #include "group.h"
51 #include "xmonitor.h"
52 #include "abi.h"
53 #include "liveinfo.h"
54 #include "io.h"
55 #include "event.h"
56
57 #define GBAR_OPEN_MONITOR_TAG "gbar,open,monitor"
58 #define GBAR_RESIZE_MONITOR_TAG "gbar,resize,monitor"
59 #define GBAR_CLOSE_MONITOR_TAG "gbar,close,monitor"
60
61 #define LAZY_GBAR_OPEN_TAG "lazy,gbar,open"
62 #define LAZY_GBAR_CLOSE_TAG "lazy,gbar,close"
63
64 #define ACCESS_TYPE_DOWN 0
65 #define ACCESS_TYPE_MOVE 1
66 #define ACCESS_TYPE_UP 2
67 #define ACCESS_TYPE_CUR 0
68 #define ACCESS_TYPE_NEXT 1
69 #define ACCESS_TYPE_PREV 2
70 #define ACCESS_TYPE_OFF 3
71
72 static struct info {
73         int info_fd;
74         int client_fd;
75         int service_fd;
76         int slave_fd;
77         int remote_client_fd;
78 } s_info = {
79         .info_fd = -1,
80         .client_fd = -1,
81         .service_fd = -1,
82         .slave_fd = -1,
83         .remote_client_fd = -1,
84 };
85
86 struct access_info {
87         int x;
88         int y;
89         int type;
90 };
91
92 /* Share this with provider */
93 enum target_type {
94         TYPE_DBOX,
95         TYPE_GBAR,
96         TYPE_ERROR
97 };
98
99 struct event_cbdata {
100         int status;
101         struct inst_info *inst;
102 };
103
104 struct deleted_item {
105         struct client_node *client;
106         struct inst_info *inst;
107 };
108
109 static Eina_Bool lazy_key_status_cb(void *data)
110 {
111         struct event_cbdata *cbdata = data;
112
113         if (instance_unref(cbdata->inst)) {
114                 instance_send_key_status(cbdata->inst, cbdata->status);
115         } else {
116                 DbgPrint("Skip sending key status (%d)\n", cbdata->status);
117         }
118         /*!
119          * If instance_unref returns NULL,
120          * The instance is destroyed. it means, we don't need to send event to the viewer
121          */
122         DbgFree(cbdata);
123         return ECORE_CALLBACK_CANCEL;
124 }
125
126 static Eina_Bool lazy_access_status_cb(void *data)
127 {
128         struct event_cbdata *cbdata = data;
129
130         if (instance_unref(cbdata->inst)) {
131                 instance_send_access_status(cbdata->inst, cbdata->status);
132         } else {
133                 DbgPrint("Skip sending access status (%d)\n", cbdata->status);
134         }
135         /*!
136          * If instance_unref returns NULL,
137          * The instance is destroyed. it means, we don't need to send event to the viewer
138          */
139         DbgFree(cbdata);
140         return ECORE_CALLBACK_CANCEL;
141 }
142
143 int send_delayed_key_status(struct inst_info *inst, int ret)
144 {
145         struct event_cbdata *cbdata;
146
147         cbdata = malloc(sizeof(*cbdata));
148         if (!cbdata) {
149                 ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
150         } else {
151                 cbdata->inst = instance_ref(inst);
152                 cbdata->status = ret;
153
154                 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
155                         (void)instance_unref(cbdata->inst);
156                         DbgFree(cbdata);
157                         ret = DBOX_STATUS_ERROR_FAULT;
158                 } else {
159                         ret = DBOX_STATUS_ERROR_NONE;
160                 }
161         }
162
163         return ret;
164 }
165
166 int send_delayed_access_status(struct inst_info *inst, int ret)
167 {
168         struct event_cbdata *cbdata;
169
170         cbdata = malloc(sizeof(*cbdata));
171         if (!cbdata) {
172                 ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
173         } else {
174                 cbdata->inst = instance_ref(inst);
175                 cbdata->status = ret;
176
177                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
178                         (void)instance_unref(cbdata->inst);
179                         DbgFree(cbdata);
180                         ret = DBOX_STATUS_ERROR_FAULT;
181                 } else {
182                         ret = DBOX_STATUS_ERROR_NONE;
183                 }
184         }
185
186         return ret;
187 }
188
189 static int forward_dbox_event_packet(const struct pkg_info *pkg, struct inst_info *inst, const struct packet *packet)
190 {
191         struct buffer_info *buffer;
192         struct slave_node *slave;
193         int ret;
194
195         buffer = instance_dbox_buffer(inst);
196         if (!buffer) {
197                 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
198                 ret = DBOX_STATUS_ERROR_FAULT;
199                 goto out;
200         }
201
202         slave = package_slave(pkg);
203         if (!slave) {
204                 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
205                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
206                 goto out;
207         }
208
209         packet_ref((struct packet *)packet);
210         ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0);
211
212 out:
213         return ret;
214 }
215
216 static int forward_gbar_event_packet(const struct pkg_info *pkg, struct inst_info *inst, const struct packet *packet)
217 {
218         struct buffer_info *buffer;
219         struct slave_node *slave;
220         int ret;
221
222         buffer = instance_gbar_buffer(inst);
223         if (!buffer) {
224                 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
225                 ret = DBOX_STATUS_ERROR_FAULT;
226                 goto out;
227         }
228
229         slave = package_slave(pkg);
230         if (!slave) {
231                 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
232                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
233                 goto out;
234         }
235
236         packet_ref((struct packet *)packet);
237         ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0);
238
239 out:
240         return ret;
241 }
242
243 static int forward_gbar_access_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, struct access_info *event)
244 {
245         int ret;
246         struct buffer_info *buffer;
247         struct slave_node *slave;
248         struct packet *p;
249
250         buffer = instance_gbar_buffer(inst);
251         if (!buffer) {
252                 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
253                 ret = DBOX_STATUS_ERROR_FAULT;
254                 goto out;
255         }
256
257         slave = package_slave(pkg);
258         if (!slave) {
259                 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
260                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
261                 goto out;
262         }
263
264         p = packet_create_noack(command, "ssdiii", package_name(pkg), instance_id(inst), timestamp, event->x, event->y, event->type);
265         ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
266
267 out:
268         return ret;
269 }
270
271 static int forward_dbox_access_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, struct access_info *event)
272 {
273         int ret;
274         struct buffer_info *buffer;
275         struct slave_node *slave;
276         struct packet *p;
277
278         buffer = instance_dbox_buffer(inst);
279         if (!buffer) {
280                 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
281                 ret = DBOX_STATUS_ERROR_FAULT;
282                 goto out;
283         }
284
285         slave = package_slave(pkg);
286         if (!slave) {
287                 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
288                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
289                 goto out;
290         }
291
292         p = packet_create_noack(command, "ssdiii", package_name(pkg), instance_id(inst), timestamp, event->x, event->y, event->type);
293         ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
294
295 out:
296         return ret;
297 }
298
299 static int forward_gbar_key_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, unsigned int keycode)
300 {
301         int ret;
302         struct buffer_info *buffer;
303         struct slave_node *slave;
304         struct packet *p;
305
306         buffer = instance_dbox_buffer(inst);
307         if (!buffer) {
308                 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
309                 ret = DBOX_STATUS_ERROR_FAULT;
310                 goto out;
311         }
312
313         slave = package_slave(pkg);
314         if (!slave) {
315                 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
316                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
317                 goto out;
318         }
319
320         p = packet_create_noack(command, "ssdi", package_name(pkg), instance_id(inst), timestamp, keycode);
321         ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
322
323 out:
324         return ret;
325 }
326
327 static int forward_dbox_key_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, unsigned int keycode)
328 {
329         int ret;
330         struct buffer_info *buffer;
331         struct slave_node *slave;
332         struct packet *p;
333
334         buffer = instance_dbox_buffer(inst);
335         if (!buffer) {
336                 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
337                 ret = DBOX_STATUS_ERROR_FAULT;
338                 goto out;
339         }
340
341         slave = package_slave(pkg);
342         if (!slave) {
343                 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
344                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
345                 goto out;
346         }
347
348         p = packet_create_noack(command, "ssdi", package_name(pkg), instance_id(inst), timestamp, keycode);
349         ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
350
351 out:
352         return ret;
353 }
354
355 static int slave_fault_open_script_cb(struct slave_node *slave, void *data)
356 {
357         Ecore_Timer *timer;
358
359         (void)script_handler_unload(instance_gbar_script(data), 1);
360         (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT);
361         (void)instance_client_gbar_created(data, DBOX_STATUS_ERROR_FAULT);
362
363         timer = instance_del_data(data, LAZY_GBAR_OPEN_TAG);
364         if (timer) {
365                 ecore_timer_del(timer);
366         }
367
368         (void)instance_unref(data);
369
370         return -1; /* remove this handler */
371 }
372
373 static int slave_fault_open_buffer_cb(struct slave_node *slave, void *data)
374 {
375         Ecore_Timer *timer;
376
377         (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT);
378         (void)instance_client_gbar_created(data, DBOX_STATUS_ERROR_FAULT);
379
380         timer = instance_del_data(data, GBAR_OPEN_MONITOR_TAG);
381         if (timer) {
382                 ecore_timer_del(timer);
383         }
384
385         (void)instance_unref(data);
386
387         return -1; /* remove this handler */
388 }
389
390 static int slave_fault_close_script_cb(struct slave_node *slave, void *data)
391 {
392         Ecore_Timer *timer;
393
394         (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT);
395
396         timer = instance_del_data(data, LAZY_GBAR_CLOSE_TAG);
397         if (timer) {
398                 ecore_timer_del(timer);
399         }
400
401         (void)instance_unref(data);
402
403         return -1; /* remove this handler */
404 }
405
406 static int slave_fault_close_buffer_cb(struct slave_node *slave, void *data)
407 {
408         Ecore_Timer *timer;
409
410         (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT);
411
412         timer = instance_del_data(data, LAZY_GBAR_CLOSE_TAG);
413         if (!timer) {
414                 timer = instance_del_data(data, GBAR_CLOSE_MONITOR_TAG);
415         }
416
417         if (timer) {
418                 ecore_timer_del(timer);
419         }
420
421         (void)instance_unref(data);
422
423         return -1; /* remove this handler */
424 }
425
426 static int slave_fault_resize_buffer_cb(struct slave_node *slave, void *data)
427 {
428         Ecore_Timer *timer;
429
430         (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT);
431         (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT);
432
433         timer = instance_del_data(data, GBAR_RESIZE_MONITOR_TAG);
434         if (timer) {
435                 ecore_timer_del(timer);
436         }
437
438         (void)instance_unref(data);
439
440         return -1; /* remove this handler */
441 }
442
443 static int key_event_dbox_route_cb(enum event_state state, struct event_data *event_info, void *data)
444 {
445         struct inst_info *inst = data;
446         const struct pkg_info *pkg;
447         struct slave_node *slave;
448         struct packet *packet;
449         unsigned int cmd;
450
451         if (!inst) {
452                 DbgPrint("Instance is deleted.\n");
453                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
454         }
455
456         pkg = instance_package(inst);
457         if (!pkg) {
458                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
459         }
460
461         slave = package_slave(pkg);
462         if (!slave) {
463                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
464         }
465
466         switch (state) {
467         case EVENT_STATE_ACTIVATE:
468                 cmd = CMD_DBOX_KEY_DOWN;
469                 break;
470         case EVENT_STATE_ACTIVATED:
471                 cmd = CMD_DBOX_KEY_DOWN;
472                 break;
473         case EVENT_STATE_DEACTIVATE:
474                 cmd = CMD_DBOX_KEY_UP;
475                 break;
476         default:
477                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
478         }
479
480         packet = packet_create_noack((const char *)&cmd, "ssdi", package_name(pkg), instance_id(inst), event_info->tv, event_info->keycode);
481         if (!packet) {
482                 return DBOX_STATUS_ERROR_FAULT;
483         }
484
485         return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
486 }
487
488 static int mouse_event_dbox_route_cb(enum event_state state, struct event_data *event_info, void *data)
489 {
490         struct inst_info *inst = data;
491         const struct pkg_info *pkg;
492         struct slave_node *slave;
493         struct packet *packet;
494         unsigned int cmd;
495
496         if (!inst) {
497                 DbgPrint("Instance is deleted.\n");
498                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
499         }
500
501         pkg = instance_package(inst);
502         if (!pkg) {
503                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
504         }
505
506         slave = package_slave(pkg);
507         if (!slave) {
508                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
509         }
510
511         switch (state) {
512         case EVENT_STATE_ACTIVATE:
513                 cmd = CMD_DBOX_MOUSE_DOWN;
514                 break;
515         case EVENT_STATE_ACTIVATED:
516                 cmd = CMD_DBOX_MOUSE_MOVE;
517                 break;
518         case EVENT_STATE_DEACTIVATE:
519                 cmd = CMD_DBOX_MOUSE_UP;
520                 break;
521         default:
522                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
523         }
524
525         packet = packet_create_noack((const char *)&cmd, "ssdii", package_name(pkg), instance_id(inst), event_info->tv, event_info->x, event_info->y);
526         if (!packet) {
527                 return DBOX_STATUS_ERROR_FAULT;
528         }
529
530         return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
531 }
532
533 static int key_event_dbox_consume_cb(enum event_state state, struct event_data *event_info, void *data)
534 {
535         struct script_info *script;
536         struct inst_info *inst = data;
537         const struct pkg_info *pkg;
538         double timestamp;
539
540         pkg = instance_package(inst);
541         if (!pkg) {
542                 return 0;
543         }
544
545         script = instance_dbox_script(inst);
546         if (!script) {
547                 return DBOX_STATUS_ERROR_FAULT;
548         }
549
550         timestamp = event_info->tv;
551
552         switch (state) {
553         case EVENT_STATE_ACTIVATE:
554                 script_handler_update_keycode(script, event_info->keycode);
555                 (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
556                 break;
557         case EVENT_STATE_ACTIVATED:
558                 script_handler_update_keycode(script, event_info->keycode);
559                 (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
560                 break;
561         case EVENT_STATE_DEACTIVATE:
562                 script_handler_update_keycode(script, event_info->keycode);
563                 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp);
564                 break;
565         default:
566                 ErrPrint("Unknown event\n");
567                 break;
568         }
569
570         return 0;
571 }
572
573 static int mouse_event_dbox_consume_cb(enum event_state state, struct event_data *event_info, void *data)
574 {
575         struct script_info *script;
576         struct inst_info *inst = data;
577         const struct pkg_info *pkg;
578         double timestamp;
579
580         pkg = instance_package(inst);
581         if (!pkg) {
582                 return 0;
583         }
584
585         script = instance_dbox_script(inst);
586         if (!script) {
587                 return DBOX_STATUS_ERROR_FAULT;
588         }
589
590         timestamp = event_info->tv;
591
592         switch (state) {
593         case EVENT_STATE_ACTIVATE:
594                 script_handler_update_pointer(script, event_info->x, event_info->y, 1);
595                 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp);
596                 break;
597         case EVENT_STATE_ACTIVATED:
598                 script_handler_update_pointer(script, event_info->x, event_info->y, -1);
599                 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp);
600                 break;
601         case EVENT_STATE_DEACTIVATE:
602                 script_handler_update_pointer(script, event_info->x, event_info->y, 0);
603                 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp);
604                 break;
605         default:
606                 break;
607         }
608
609         return 0;
610 }
611
612 static int key_event_gbar_route_cb(enum event_state state, struct event_data *event_info, void *data)
613 {
614         struct inst_info *inst = data;
615         const struct pkg_info *pkg;
616         struct slave_node *slave;
617         struct packet *packet;
618         unsigned int cmd;
619
620         if (!inst) {
621                 DbgPrint("Instance is deleted.\n");
622                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
623         }
624
625         pkg = instance_package(inst);
626         if (!pkg) {
627                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
628         }
629
630         slave = package_slave(pkg);
631         if (!slave) {
632                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
633         }
634
635         switch (state) {
636         case EVENT_STATE_ACTIVATE:
637                 cmd = CMD_GBAR_KEY_DOWN;
638                 break;
639         case EVENT_STATE_ACTIVATED:
640                 cmd = CMD_GBAR_KEY_DOWN;
641                 break;
642         case EVENT_STATE_DEACTIVATE:
643                 cmd = CMD_GBAR_KEY_UP;
644                 break;
645         default:
646                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
647         }
648
649         packet = packet_create_noack((const char *)&cmd, "ssdi", package_name(pkg), instance_id(inst), event_info->tv, event_info->keycode);
650         if (!packet) {
651                 return DBOX_STATUS_ERROR_FAULT;
652         }
653
654         return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
655 }
656
657 static int mouse_event_gbar_route_cb(enum event_state state, struct event_data *event_info, void *data)
658 {
659         struct inst_info *inst = data;
660         const struct pkg_info *pkg;
661         struct slave_node *slave;
662         struct packet *packet;
663         unsigned int cmd;
664
665         if (!inst) {
666                 DbgPrint("Instance is deleted.\n");
667                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
668         }
669
670         pkg = instance_package(inst);
671         if (!pkg) {
672                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
673         }
674
675         slave = package_slave(pkg);
676         if (!slave) {
677                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
678         }
679
680         switch (state) {
681         case EVENT_STATE_ACTIVATE:
682                 cmd = CMD_GBAR_MOUSE_DOWN;
683                 break;
684         case EVENT_STATE_ACTIVATED:
685                 cmd = CMD_GBAR_MOUSE_MOVE;
686                 break;
687         case EVENT_STATE_DEACTIVATE:
688                 cmd = CMD_GBAR_MOUSE_UP;
689                 break;
690         default:
691                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
692         }
693
694         packet = packet_create_noack((const char *)&cmd, "ssdii", package_name(pkg), instance_id(inst), event_info->tv, event_info->x, event_info->y);
695         if (!packet) {
696                 return DBOX_STATUS_ERROR_FAULT;
697         }
698
699         return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
700 }
701
702 static int key_event_gbar_consume_cb(enum event_state state, struct event_data *event_info, void *data)
703 {
704         struct script_info *script;
705         struct inst_info *inst = data;
706         const struct pkg_info *pkg;
707         double timestamp;
708
709         pkg = instance_package(inst);
710         if (!pkg) {
711                 return 0;
712         }
713
714         script = instance_gbar_script(inst);
715         if (!script) {
716                 return DBOX_STATUS_ERROR_FAULT;
717         }
718
719         timestamp = event_info->tv;
720
721         switch (state) {
722         case EVENT_STATE_ACTIVATE:
723                 script_handler_update_keycode(script, event_info->keycode);
724                 (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
725                 break;
726         case EVENT_STATE_ACTIVATED:
727                 script_handler_update_keycode(script, event_info->keycode);
728                 (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
729                 break;
730         case EVENT_STATE_DEACTIVATE:
731                 script_handler_update_keycode(script, event_info->keycode);
732                 (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp);
733                 break;
734         default:
735                 ErrPrint("Unknown event\n");
736                 break;
737         }
738
739         return 0;
740 }
741
742 static int mouse_event_gbar_consume_cb(enum event_state state, struct event_data *event_info, void *data)
743 {
744         struct script_info *script;
745         struct inst_info *inst = data;
746         const struct pkg_info *pkg;
747         double timestamp;
748
749         pkg = instance_package(inst);
750         if (!pkg) {
751                 return 0;
752         }
753
754         script = instance_gbar_script(inst);
755         if (!script) {
756                 return DBOX_STATUS_ERROR_FAULT;
757         }
758
759         timestamp = event_info->tv;
760
761         switch (state) {
762         case EVENT_STATE_ACTIVATE:
763                 script_handler_update_pointer(script, event_info->x, event_info->y, 1);
764                 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp);
765                 break;
766         case EVENT_STATE_ACTIVATED:
767                 script_handler_update_pointer(script, event_info->x, event_info->y, -1);
768                 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp);
769                 break;
770         case EVENT_STATE_DEACTIVATE:
771                 script_handler_update_pointer(script, event_info->x, event_info->y, 0);
772                 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp);
773                 break;
774         default:
775                 break;
776         }
777         return 0;
778 }
779
780 static struct packet *client_acquire(pid_t pid, int handle, const struct packet *packet) /*!< timestamp, ret */
781 {
782         struct client_node *client;
783         struct packet *result;
784         const char *direct_addr;
785         double timestamp;
786         int ret;
787
788         client = client_find_by_rpc_handle(handle);
789         if (client) {
790                 ErrPrint("Client is already exists %d\n", pid);
791                 ret = DBOX_STATUS_ERROR_EXIST;
792                 goto out;
793         }
794
795         if (packet_get(packet, "ds", &timestamp, &direct_addr) != 2) {
796                 ErrPrint("Invalid arguemnt\n");
797                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
798                 goto out;
799         }
800
801         ret = 0;
802         /*!
803          * \note
804          * client_create will invoke the client created callback
805          */
806         client = client_create(pid, handle, direct_addr);
807         if (!client) {
808                 ErrPrint("Failed to create a new client for %d\n", pid);
809                 ret = DBOX_STATUS_ERROR_FAULT;
810         }
811
812 out:
813         result = packet_create_reply(packet, "ii", ret, DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT);
814         if (!result) {
815                 ErrPrint("Failed to create a packet\n");
816         }
817
818         return result;
819 }
820
821 static struct packet *cilent_release(pid_t pid, int handle, const struct packet *packet) /*!< pid, ret */
822 {
823         struct client_node *client;
824         struct packet *result;
825         int ret;
826
827         client = client_find_by_rpc_handle(handle);
828         if (!client) {
829                 ErrPrint("Client %d is not exists\n", pid);
830                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
831                 goto out;
832         }
833
834         client_destroy(client);
835         ret = 0;
836
837 out:
838         result = packet_create_reply(packet, "i", ret);
839         if (!result) {
840                 ErrPrint("Failed to create a packet\n");
841         }
842
843         return result;
844 }
845
846 static int validate_request(const char *pkgname, const char *id, struct inst_info **out_inst, const struct pkg_info **out_pkg)
847 {
848         struct inst_info *inst;
849         const struct pkg_info *pkg;
850
851         inst = package_find_instance_by_id(pkgname, id);
852         if (!inst) {
853                 ErrPrint("Instance is not exists (%s)\n", id);
854                 return DBOX_STATUS_ERROR_NOT_EXIST;
855         }
856
857         pkg = instance_package(inst);
858         if (!pkg) {
859                 ErrPrint("System error - instance has no package?\n");
860                 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
861         }
862
863         if (package_is_fault(pkg)) {
864                 ErrPrint("Faulted package: %s\n", pkgname);
865                 return DBOX_STATUS_ERROR_FAULT;
866         }
867
868         if (out_inst) {
869                 *out_inst = inst;
870         }
871
872         if (out_pkg) {
873                 *out_pkg = pkg;
874         }
875
876         return DBOX_STATUS_ERROR_NONE;
877 }
878
879 /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
880 static struct packet *client_clicked(pid_t pid, int handle, const struct packet *packet)
881 {
882         struct client_node *client;
883         const char *pkgname;
884         const char *id;
885         const char *event;
886         double timestamp;
887         double x;
888         double y;
889         int ret;
890         struct inst_info *inst;
891
892         client = client_find_by_rpc_handle(handle);
893         if (!client) {
894                 ErrPrint("Client %d is not exists\n", pid);
895                 goto out;
896         }
897
898         ret = packet_get(packet, "sssddd", &pkgname, &id, &event, &timestamp, &x, &y);
899         if (ret != 6) {
900                 ErrPrint("Parameter is not matched\n");
901                 goto out;
902         }
903
904         /*!
905          * \NOTE:
906          * Trust the package name which are sent by the client.
907          * The package has to be a dynamicbox package name.
908          */
909         ret = validate_request(pkgname, id, &inst, NULL);
910         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
911                 (void)instance_clicked(inst, event, timestamp, x, y);
912         }
913
914 out:
915         /*! \note No reply packet */
916         return NULL;
917 }
918
919 static struct packet *client_update_mode(pid_t pid, int handle, const struct packet *packet)
920 {
921         struct packet *result;
922         struct client_node *client;
923         int active_update;
924         const char *pkgname;
925         const char *id;
926         int ret;
927         struct inst_info *inst;
928
929         client = client_find_by_rpc_handle(handle);
930         if (!client) {
931                 ErrPrint("Client %d is not exists\n", pid);
932                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
933                 goto out;
934         }
935
936         ret = packet_get(packet, "ssi", &pkgname, &id, &active_update);
937         if (ret != 3) {
938                 ErrPrint("Invalid argument\n");
939                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
940                 goto out;
941         }
942
943         ret = validate_request(pkgname, id, &inst, NULL);
944         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
945                 /*!
946                  * \note
947                  * Send change update mode request to a slave
948                  */
949                 ret = instance_set_update_mode(inst, active_update);
950         }
951
952 out:
953         result = packet_create_reply(packet, "i", ret);
954         if (!result) {
955                 ErrPrint("Failed to create a packet\n");
956         }
957
958         return result;
959 }
960
961 /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
962 static struct packet *client_text_signal(pid_t pid, int handle, const struct packet *packet)
963 {
964         struct client_node *client;
965         struct packet *result;
966         const char *pkgname;
967         const char *id;
968         const char *emission;
969         const char *source;
970         double sx;
971         double sy;
972         double ex;
973         double ey;
974         struct inst_info *inst = NULL;
975         int ret;
976
977         client = client_find_by_rpc_handle(handle);
978         if (!client) {
979                 ErrPrint("Client %d is not exists\n", pid);
980                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
981                 goto out;
982         }
983
984         ret = packet_get(packet, "ssssdddd", &pkgname, &id, &emission, &source, &sx, &sy, &ex, &ey);
985         if (ret != 8) {
986                 ErrPrint("Parameter is not matched\n");
987                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
988                 goto out;
989         }
990
991         /*!
992          * \NOTE:
993          * Trust the package name which are sent by the client.
994          * The package has to be a dynamicbox package name.
995          */
996         ret = validate_request(pkgname, id, &inst, NULL);
997         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
998                 ret = instance_text_signal_emit(inst, emission, source, sx, sy, ex, ey);
999         }
1000
1001 out:
1002         result = packet_create_reply(packet, "i", ret);
1003         if (!result) {
1004                 ErrPrint("Failed to create a packet\n");
1005         }
1006
1007         return result;
1008 }
1009
1010 static Eina_Bool lazy_delete_cb(void *data)
1011 {
1012         struct deleted_item *item = data;
1013
1014         DbgPrint("Lazy delete callback called\n");
1015         /*!
1016          * Before invoke this callback, the instance is able to already remove this client
1017          * So check it again
1018          */
1019         if (instance_has_client(item->inst, item->client)) {
1020                 (void)instance_unicast_deleted_event(item->inst, item->client, DBOX_STATUS_ERROR_NONE);
1021                 (void)instance_del_client(item->inst, item->client);
1022         }
1023
1024         (void)client_unref(item->client);
1025         (void)instance_unref(item->inst);
1026         DbgFree(item);
1027         return ECORE_CALLBACK_CANCEL;
1028 }
1029
1030 static struct packet *client_delete(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
1031 {
1032         struct client_node *client;
1033         struct packet *result;
1034         const char *pkgname;
1035         const char *id;
1036         struct inst_info *inst;
1037         const struct pkg_info *pkg;
1038         int ret;
1039         int type;
1040         double timestamp;
1041
1042         client = client_find_by_rpc_handle(handle);
1043         if (!client) {
1044                 ErrPrint("Client %d is not exists\n", pid);
1045                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1046                 goto out;
1047         }
1048
1049         ret = packet_get(packet, "ssid", &pkgname, &id, &type, &timestamp);
1050         if (ret != 4) {
1051                 ErrPrint("Parameter is not matched\n");
1052                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1053                 goto out;
1054         }
1055         /*!
1056          * \note
1057          * Below two types must has to be sync'd with dynamicbox-viewer
1058          *
1059          * DBOX_DELETE_PERMANENTLY = 0x01,
1060          * DBOX_DELETE_TEMPORARY = 0x02,
1061          *
1062          */
1063
1064         /*!
1065          * \NOTE:
1066          * Trust the package name which are sent by the client.
1067          * The package has to be a dynamicbox package name.
1068          */
1069         ret = validate_request(pkgname, id, &inst, &pkg);
1070         if (ret != DBOX_STATUS_ERROR_NONE) {
1071                 DbgPrint("Failed to find by id(%s), try to find it using timestamp(%lf)\n", id, timestamp);
1072                 inst = package_find_instance_by_timestamp(pkgname, timestamp);
1073                 if (!inst) {
1074                         goto out;
1075                 }
1076
1077                 pkg = instance_package(inst);
1078                 if (!pkg) {
1079                         ErrPrint("Package info is not valid: %s\n", id);
1080                         goto out;
1081                 }
1082         }
1083
1084         if (package_is_fault(pkg)) {
1085                 DbgPrint("Faulted package. will be deleted soon: %s\n", id);
1086                 ret = DBOX_STATUS_ERROR_FAULT;
1087                 goto out;
1088         }
1089
1090         if (instance_client(inst) != client) {
1091                 if (instance_has_client(inst, client)) {
1092                         struct deleted_item *item;
1093
1094                         item = malloc(sizeof(*item));
1095                         if (!item) {
1096                                 ErrPrint("Heap: %s\n", strerror(errno));
1097                                 ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1098                         } else {
1099                                 /*!
1100                                  * \NOTE:
1101                                  * Send DELETED EVENT to the client.
1102                                  * after return from this function.
1103                                  *
1104                                  * Client will prepare the deleted event after get this function's return value.
1105                                  * So We have to make a delay to send a deleted event.
1106                                  */
1107
1108                                 item->client = client_ref(client);
1109                                 item->inst = instance_ref(inst);
1110
1111                                 if (!ecore_timer_add(DELAY_TIME, lazy_delete_cb, item)) {
1112                                         ErrPrint("Failed to add a delayzed delete callback\n");
1113                                         (void)client_unref(client);
1114                                         (void)instance_unref(inst);
1115                                         DbgFree(item);
1116                                         ret = DBOX_STATUS_ERROR_FAULT;
1117                                 } else {
1118                                         ret = DBOX_STATUS_ERROR_NONE;
1119                                 }
1120                         }
1121                 } else {
1122                         ErrPrint("Client has no permission\n");
1123                         ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
1124                 }
1125         } else {
1126                 switch (type) {
1127                 case DBOX_DELETE_PERMANENTLY:
1128                         ret = instance_destroy(inst, DBOX_DESTROY_TYPE_DEFAULT);
1129                         break;
1130                 case DBOX_DELETE_TEMPORARY:
1131                         ret = instance_destroy(inst, DBOX_DESTROY_TYPE_TEMPORARY);
1132                         break;
1133                 default:
1134                         break;
1135                 }
1136         }
1137
1138 out:
1139         result = packet_create_reply(packet, "i", ret);
1140         if (!result) {
1141                 ErrPrint("Failed to create a packet\n");
1142         }
1143
1144         return result;
1145 }
1146
1147 static struct packet *client_resize(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, w, h, ret */
1148 {
1149         struct client_node *client;
1150         struct packet *result;
1151         const char *pkgname;
1152         const char *id;
1153         int w;
1154         int h;
1155         struct inst_info *inst = NULL;
1156         int ret;
1157
1158         client = client_find_by_rpc_handle(handle);
1159         if (!client) {
1160                 ErrPrint("Client %d is not exists\n", pid);
1161                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1162                 goto out;
1163         }
1164
1165         ret = packet_get(packet, "ssii", &pkgname, &id, &w, &h);
1166         if (ret != 4) {
1167                 ErrPrint("Parameter is not matched\n");
1168                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1169                 goto out;
1170         }
1171
1172         DbgPrint("RESIZE: Client request resize to %dx%d (pid: %d, pkgname: %s)\n", w, h, pid, pkgname);
1173
1174         /*!
1175          * \NOTE:
1176          * Trust the package name which are sent by the client.
1177          * The package has to be a dynamicbox package name.
1178          */
1179         ret = validate_request(pkgname, id, &inst, NULL);
1180         if (ret != DBOX_STATUS_ERROR_NONE) {
1181                 goto out;
1182         }
1183
1184         if (instance_client(inst) != client) {
1185                 ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
1186         } else {
1187                 ret = instance_resize(inst, w, h);
1188         }
1189
1190 out:
1191         result = packet_create_reply(packet, "i", ret);
1192         if (!result) {
1193                 ErrPrint("Failed to create a packet\n");
1194         }
1195
1196         return result;
1197 }
1198
1199 static struct packet *client_new(pid_t pid, int handle, const struct packet *packet) /* pid, timestamp, pkgname, content, cluster, category, period, ret */
1200 {
1201         struct client_node *client;
1202         struct packet *result;
1203         const char *pkgname;
1204         const char *content;
1205         const char *cluster;
1206         const char *category;
1207         double period;
1208         double timestamp;
1209         int ret;
1210         struct pkg_info *info;
1211         int width;
1212         int height;
1213         char *lbid;
1214         char *mainappid;
1215
1216         client = client_find_by_rpc_handle(handle);
1217         if (!client) {
1218                 ErrPrint("Client %d is not exists\n", pid);
1219                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1220                 goto out;
1221         }
1222
1223         ret = packet_get(packet, "dssssdii", &timestamp, &pkgname, &content, &cluster, &category, &period, &width, &height);
1224         if (ret != 8) {
1225                 ErrPrint("Parameter is not matched\n");
1226                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1227                 goto out;
1228         }
1229
1230         DbgPrint("pid[%d] period[%lf] pkgname[%s] content[%s] cluster[%s] category[%s] period[%lf]\n",
1231                         pid, timestamp, pkgname, content, cluster, category, period);
1232
1233         lbid = package_dbox_pkgname(pkgname);
1234         if (!lbid) {
1235                 ErrPrint("This %s has no dynamicbox package\n", pkgname);
1236                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1237                 goto out;
1238         }
1239
1240         mainappid = dynamicbox_service_mainappid(lbid);
1241         if (!package_is_enabled(mainappid)) {
1242                 DbgFree(mainappid);
1243                 DbgFree(lbid);
1244                 ret = DBOX_STATUS_ERROR_DISABLED;
1245                 goto out;
1246         }
1247         DbgFree(mainappid);
1248
1249         info = package_find(lbid);
1250         if (!info) {
1251                 char *pkgid;
1252                 pkgid = dynamicbox_service_package_id(lbid);
1253                 if (!pkgid) {
1254                         DbgFree(mainappid);
1255                         DbgFree(lbid);
1256                         ret = DBOX_STATUS_ERROR_FAULT;
1257                         goto out;
1258                 }
1259
1260                 info = package_create(pkgid, lbid);
1261                 DbgFree(pkgid);
1262         }
1263
1264         if (!info) {
1265                 ret = DBOX_STATUS_ERROR_FAULT;
1266         } else if (package_is_fault(info)) {
1267                 ret = DBOX_STATUS_ERROR_FAULT;
1268         } else if (util_free_space(DYNAMICBOX_CONF_IMAGE_PATH) <= DYNAMICBOX_CONF_MINIMUM_SPACE) {
1269                 ErrPrint("Not enough space\n");
1270                 ret = DBOX_STATUS_ERROR_NO_SPACE;
1271         } else {
1272                 struct inst_info *inst;
1273
1274                 if (period > 0.0f && period < DYNAMICBOX_CONF_MINIMUM_PERIOD) {
1275                         period = DYNAMICBOX_CONF_MINIMUM_PERIOD;
1276                 }
1277
1278                 inst = instance_create(client, timestamp, lbid, content, cluster, category, period, width, height);
1279                 /*!
1280                  * \note
1281                  * Using the "inst" without validate its value is at my disposal. ;)
1282                  */
1283                 ret = inst ? 0 : DBOX_STATUS_ERROR_FAULT;
1284         }
1285
1286         DbgFree(lbid);
1287
1288 out:
1289         result = packet_create_reply(packet, "i", ret);
1290         if (!result) {
1291                 ErrPrint("Failed to create a packet\n");
1292         }
1293
1294         return result;
1295 }
1296
1297 static struct packet *client_change_visibility(pid_t pid, int handle, const struct packet *packet)
1298 {
1299         struct client_node *client;
1300         const char *pkgname;
1301         const char *id;
1302         enum dynamicbox_visible_state state;
1303         int ret;
1304         struct inst_info *inst;
1305
1306         client = client_find_by_rpc_handle(handle);
1307         if (!client) {
1308                 ErrPrint("Client %d is not exists\n", pid);
1309                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1310                 goto out;
1311         }
1312
1313         ret = packet_get(packet, "ssi", &pkgname, &id, (int *)&state);
1314         if (ret != 3) {
1315                 ErrPrint("Parameter is not matched\n");
1316                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1317                 goto out;
1318         }
1319
1320         /*!
1321          * \NOTE:
1322          * Trust the package name which are sent by the client.
1323          * The package has to be a dynamicbox package name.
1324          */
1325         ret = validate_request(pkgname, id, &inst, NULL);
1326         if (ret != DBOX_STATUS_ERROR_NONE) {
1327                 goto out;
1328         }
1329
1330         if (instance_client(inst) != client) {
1331                 ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
1332         } else {
1333                 ret = instance_set_visible_state(inst, state);
1334         }
1335
1336 out:
1337         /*! \note No reply packet */
1338         return NULL;
1339 }
1340
1341 static struct packet *client_set_period(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, period, ret */
1342 {
1343         struct client_node *client;
1344         struct packet *result;
1345         const char *pkgname;
1346         const char *id;
1347         double period;
1348         int ret;
1349         struct inst_info *inst = NULL;
1350
1351         client = client_find_by_rpc_handle(handle);
1352         if (!client) {
1353                 ErrPrint("Client %d is not exists\n", pid);
1354                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1355                 goto out;
1356         }
1357
1358         ret = packet_get(packet, "ssd", &pkgname, &id, &period);
1359         if (ret != 3) {
1360                 ErrPrint("Parameter is not matched\n");
1361                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1362                 goto out;
1363         }
1364
1365         DbgPrint("pid[%d] pkgname[%s] period[%lf]\n", pid, pkgname, period);
1366
1367         /*!
1368          * \NOTE:
1369          * Trust the package name which are sent by the client.
1370          * The package has to be a dynamicbox package name.
1371          */
1372         ret = validate_request(pkgname, id, &inst, NULL);
1373         if (ret != DBOX_STATUS_ERROR_NONE) {
1374                 goto out;
1375         }
1376
1377         if (instance_client(inst) != client) {
1378                 ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
1379         } else {
1380                 ret = instance_set_period(inst, period);
1381         }
1382
1383 out:
1384         result = packet_create_reply(packet, "i", ret);
1385         if (!result) {
1386                 ErrPrint("Failed to create a packet\n");
1387         }
1388
1389         return result;
1390 }
1391
1392 static struct packet *client_change_group(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, cluster, category, ret */
1393 {
1394         struct client_node *client;
1395         struct packet *result;
1396         const char *pkgname;
1397         const char *id;
1398         const char *cluster;
1399         const char *category;
1400         struct inst_info *inst = NULL;
1401         int ret;
1402
1403         client = client_find_by_rpc_handle(handle);
1404         if (!client) {
1405                 ErrPrint("Client %d is not exists\n", pid);
1406                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1407                 goto out;
1408         }
1409
1410         ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category);
1411         if (ret != 4) {
1412                 ErrPrint("Parameter is not matched\n");
1413                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1414                 goto out;
1415         }
1416
1417         DbgPrint("pid[%d] pkgname[%s] cluster[%s] category[%s]\n", pid, pkgname, cluster, category);
1418
1419         /*!
1420          * \NOTE:
1421          * Trust the package name which are sent by the client.
1422          * The package has to be a dynamicbox package name.
1423          */
1424         ret = validate_request(pkgname, id, &inst, NULL);
1425         if (ret != DBOX_STATUS_ERROR_NONE) {
1426                 goto out;
1427         }
1428
1429         if (instance_client(inst) != client) {
1430                 ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
1431         } else {
1432                 ret = instance_change_group(inst, cluster, category);
1433         }
1434
1435 out:
1436         result = packet_create_reply(packet, "i", ret);
1437         if (!result) {
1438                 ErrPrint("Failed to create a packet\n");
1439         }
1440
1441         return result;
1442 }
1443
1444 static struct packet *client_gbar_mouse_enter(pid_t pid, int handle, const struct packet *packet)
1445 {
1446         struct client_node *client;
1447         const char *pkgname;
1448         const char *id;
1449         int ret;
1450         double timestamp;
1451         int x;
1452         int y;
1453         struct inst_info *inst;
1454         const struct pkg_info *pkg;
1455
1456         client = client_find_by_rpc_handle(handle);
1457         if (!client) {
1458                 ErrPrint("Client %d is not exists\n", pid);
1459                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1460                 goto out;
1461         }
1462
1463         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1464         if (ret != 5) {
1465                 ErrPrint("Invalid parameter\n");
1466                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1467                 goto out;
1468         }
1469
1470         ret = validate_request(pkgname, id, &inst, &pkg);
1471         if (ret != DBOX_STATUS_ERROR_NONE) {
1472                 goto out;
1473         }
1474
1475         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
1476                 ret = forward_gbar_event_packet(pkg, inst, packet);
1477         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
1478                 struct script_info *script;
1479
1480                 script = instance_gbar_script(inst);
1481                 if (!script) {
1482                         ret = DBOX_STATUS_ERROR_FAULT;
1483                         goto out;
1484                 }
1485
1486                 script_handler_update_pointer(script, x, y, -1);
1487                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_IN, timestamp);
1488                 ret = 0;
1489         } else {
1490                 ErrPrint("Unsupported package\n");
1491                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1492         }
1493
1494 out:
1495         /*! \note No reply packet */
1496         return NULL;
1497 }
1498
1499 static struct packet *client_gbar_mouse_leave(pid_t pid, int handle, const struct packet *packet)
1500 {
1501         struct client_node *client;
1502         const char *pkgname;
1503         const char *id;
1504         int ret;
1505         double timestamp;
1506         int x;
1507         int y;
1508         struct inst_info *inst;
1509         const struct pkg_info *pkg;
1510
1511         client = client_find_by_rpc_handle(handle);
1512         if (!client) {
1513                 ErrPrint("Client %d is not exists\n", pid);
1514                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1515                 goto out;
1516         }
1517
1518         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1519         if (ret != 5) {
1520                 ErrPrint("Parameter is not matched\n");
1521                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1522                 goto out;
1523         }
1524
1525         ret = validate_request(pkgname, id, &inst, &pkg);
1526         if (ret != DBOX_STATUS_ERROR_NONE) {
1527                 goto out;
1528         }
1529
1530         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
1531                 ret = forward_gbar_event_packet(pkg, inst, packet);
1532         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
1533                 struct script_info *script;
1534
1535                 script = instance_gbar_script(inst);
1536                 if (!script) {
1537                         ret = DBOX_STATUS_ERROR_FAULT;
1538                         goto out;
1539                 }
1540
1541                 script_handler_update_pointer(script, x, y, -1);
1542                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OUT, timestamp);
1543                 ret = 0;
1544         } else {
1545                 ErrPrint("Unsupported package\n");
1546                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1547         }
1548
1549 out:
1550         /*! \note No reply packet */
1551         return NULL;
1552 }
1553
1554 static struct packet *client_gbar_mouse_down(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, id, width, height, timestamp, x, y, ret */
1555 {
1556         struct client_node *client;
1557         const char *pkgname;
1558         const char *id;
1559         int ret;
1560         double timestamp;
1561         int x;
1562         int y;
1563         struct inst_info *inst;
1564         const struct pkg_info *pkg;
1565
1566         client = client_find_by_rpc_handle(handle);
1567         if (!client) {
1568                 ErrPrint("Client %d is not exists\n", pid);
1569                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1570                 goto out;
1571         }
1572
1573         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1574         if (ret != 5) {
1575                 ErrPrint("Parameter is not matched\n");
1576                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1577                 goto out;
1578         }
1579
1580         ret = validate_request(pkgname, id, &inst, &pkg);
1581         if (ret != DBOX_STATUS_ERROR_NONE) {
1582                 goto out;
1583         }
1584
1585         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
1586                 ret = forward_gbar_event_packet(pkg, inst, packet);
1587         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
1588                 struct script_info *script;
1589
1590                 script = instance_gbar_script(inst);
1591                 if (!script) {
1592                         ret = DBOX_STATUS_ERROR_FAULT;
1593                         goto out;
1594                 }
1595
1596                 script_handler_update_pointer(script, x, y, 1);
1597                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp);
1598                 ret = 0;
1599         } else {
1600                 ErrPrint("Unsupported package\n");
1601                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1602         }
1603
1604 out:
1605         /*! \note No reply packet */
1606         return NULL;
1607 }
1608
1609 static struct packet *client_gbar_mouse_up(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
1610 {
1611         struct client_node *client;
1612         const char *pkgname;
1613         const char *id;
1614         int ret;
1615         double timestamp;
1616         int x;
1617         int y;
1618         struct inst_info *inst;
1619         const struct pkg_info *pkg;
1620
1621         client = client_find_by_rpc_handle(handle);
1622         if (!client) {
1623                 ErrPrint("Client %d is not exists\n", pid);
1624                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1625                 goto out;
1626         }
1627
1628         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1629         if (ret != 5) {
1630                 ErrPrint("Parameter is not matched\n");
1631                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1632                 goto out;
1633         }
1634
1635         ret = validate_request(pkgname, id, &inst, &pkg);
1636         if (ret != DBOX_STATUS_ERROR_NONE) {
1637                 goto out;
1638         }
1639
1640         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
1641                 ret = forward_gbar_event_packet(pkg, inst, packet);
1642         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
1643                 struct script_info *script;
1644
1645                 script = instance_gbar_script(inst);
1646                 if (!script) {
1647                         ret = DBOX_STATUS_ERROR_FAULT;
1648                         goto out;
1649                 }
1650
1651                 script_handler_update_pointer(script, x, y, 0);
1652                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp);
1653                 ret = 0;
1654         } else {
1655                 ErrPrint("Unsupported package\n");
1656                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1657         }
1658
1659 out:
1660         /*! \note No reply packet */
1661         return NULL;
1662 }
1663
1664 static struct packet *client_gbar_mouse_move(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
1665 {
1666         struct client_node *client;
1667         const char *pkgname;
1668         const char *id;
1669         int ret;
1670         double timestamp;
1671         int x;
1672         int y;
1673         struct inst_info *inst;
1674         const struct pkg_info *pkg;
1675
1676         client = client_find_by_rpc_handle(handle);
1677         if (!client) {
1678                 ErrPrint("Client %d is not exists\n", pid);
1679                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1680                 goto out;
1681         }
1682
1683         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1684         if (ret != 5) {
1685                 ErrPrint("Parameter is not matched\n");
1686                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1687                 goto out;
1688         }
1689
1690         ret = validate_request(pkgname, id, &inst, &pkg);
1691         if (ret != DBOX_STATUS_ERROR_NONE) {
1692                 goto out;
1693         }
1694
1695         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
1696                 ret = forward_gbar_event_packet(pkg, inst, packet);
1697         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
1698                 struct script_info *script;
1699
1700                 script = instance_gbar_script(inst);
1701                 if (!script) {
1702                         ret = DBOX_STATUS_ERROR_FAULT;
1703                         goto out;
1704                 }
1705
1706                 script_handler_update_pointer(script, x, y, -1);
1707                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp);
1708                 ret = 0;
1709         } else {
1710                 ErrPrint("Unsupported package\n");
1711                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1712         }
1713
1714 out:
1715         /*! \note No reply packet */
1716         return NULL;
1717 }
1718
1719 static struct packet *client_dbox_mouse_move(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
1720 {
1721         struct client_node *client;
1722         const char *pkgname;
1723         const char *id;
1724         int ret;
1725         double timestamp;
1726         int x;
1727         int y;
1728         struct inst_info *inst;
1729         const struct pkg_info *pkg;
1730
1731         client = client_find_by_rpc_handle(handle);
1732         if (!client) {
1733                 ErrPrint("Client %d is not exists\n", pid);
1734                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1735                 goto out;
1736         }
1737
1738         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1739         if (ret != 5) {
1740                 ErrPrint("Parameter is not matched\n");
1741                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1742                 goto out;
1743         }
1744
1745         ret = validate_request(pkgname, id, &inst, &pkg);
1746         if (ret != DBOX_STATUS_ERROR_NONE) {
1747                 goto out;
1748         }
1749
1750         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
1751                 ret = forward_dbox_event_packet(pkg, inst, packet);
1752         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
1753                 struct script_info *script;
1754
1755                 script = instance_dbox_script(inst);
1756                 if (!script) {
1757                         ret = DBOX_STATUS_ERROR_FAULT;
1758                         goto out;
1759                 }
1760
1761                 script_handler_update_pointer(script, x, y, -1);
1762                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp);
1763                 ret = 0;
1764         } else {
1765                 ErrPrint("Unsupported package\n");
1766                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1767         }
1768
1769 out:
1770         /*! \note No reply packet */
1771         return NULL;
1772 }
1773
1774 static int inst_del_cb(struct inst_info *inst, void *data)
1775 {
1776         int ret;
1777
1778         /*
1779          * If you deactivate the event thread,
1780          * It will calls event callbacks.
1781          * And the event callbacks will try to access the "inst"
1782          */
1783         (void)event_deactivate(data, inst);
1784
1785         /* Reset callback data to prevent accessing inst from event callback */
1786         ret = event_reset_cbdata(data, inst, NULL);
1787         DbgPrint("Instance delete callback called: %s (%d)\n", instance_id(inst), ret);
1788
1789         if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1790                 (void)slave_set_priority(package_slave(instance_package(inst)), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
1791         }
1792
1793         return -1; /* Delete this callback */
1794 }
1795
1796
1797 static struct packet *client_gbar_key_set(pid_t pid, int handle, const struct packet *packet)
1798 {
1799         struct client_node *client;
1800         const char *pkgname;
1801         const char *id;
1802         int ret;
1803         double timestamp;
1804         unsigned int keycode;
1805         struct inst_info *inst;
1806         const struct pkg_info *pkg;
1807         struct packet *result;
1808
1809         client = client_find_by_rpc_handle(handle);
1810         if (!client) {
1811                 ErrPrint("Client %d is not exists\n", pid);
1812                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1813                 goto out;
1814         }
1815
1816         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
1817         if (ret != 4) {
1818                 ErrPrint("Parameter is not matched\n");
1819                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1820                 goto out;
1821         }
1822
1823         ret = validate_request(pkgname, id, &inst, &pkg);
1824         if (ret != DBOX_STATUS_ERROR_NONE) {
1825                 goto out;
1826         }
1827
1828         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
1829                 ret = event_activate(0, 0, key_event_gbar_route_cb, inst);
1830                 if (ret == DBOX_STATUS_ERROR_NONE) {
1831                         if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1832                                 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
1833                         }
1834                         if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb) <= 0) {
1835                                 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb);
1836                         }
1837                 }
1838         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
1839                 ret = event_activate(0, 0, key_event_gbar_consume_cb, inst);
1840                 if (ret == DBOX_STATUS_ERROR_NONE) {
1841                         if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1842                                 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
1843                         }
1844                         if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb) <= 0) {
1845                                 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb);
1846                         }
1847                 }
1848         } else {
1849                 ErrPrint("Unsupported package\n");
1850                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1851         }
1852
1853 out:
1854         result = packet_create_reply(packet, "i", ret);
1855         if (!result) {
1856                 ErrPrint("Failed to create a reply packet\n");
1857         }
1858
1859         return result;
1860 }
1861
1862 static struct packet *client_gbar_key_unset(pid_t pid, int handle, const struct packet *packet)
1863 {
1864         struct client_node *client;
1865         const char *pkgname;
1866         const char *id;
1867         int ret;
1868         double timestamp;
1869         unsigned int keycode;
1870         struct inst_info *inst;
1871         const struct pkg_info *pkg;
1872         struct packet *result;
1873
1874         client = client_find_by_rpc_handle(handle);
1875         if (!client) {
1876                 ErrPrint("Client %d is not exists\n", pid);
1877                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1878                 goto out;
1879         }
1880
1881         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
1882         if (ret != 4) {
1883                 ErrPrint("Parameter is not matched\n");
1884                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1885                 goto out;
1886         }
1887
1888         ret = validate_request(pkgname, id, &inst, &pkg);
1889         if (ret != DBOX_STATUS_ERROR_NONE) {
1890                 goto out;
1891         }
1892
1893         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
1894                 ret = event_deactivate(key_event_gbar_route_cb, inst);
1895                 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1896                         (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
1897                 }
1898                 /*
1899                  * This delete callback will be removed when the instance will be destroyed.
1900                  if (ret == 0) {
1901                  instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb);
1902                  }
1903                  */
1904         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
1905                 ret = event_deactivate(key_event_gbar_consume_cb, inst);
1906                 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1907                         (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
1908                 }
1909                 /*
1910                  * This delete callback will be removed when the instance will be destroyed.
1911                  if (ret == 0) {
1912                  instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb);
1913                  }
1914                  */
1915         } else {
1916                 ErrPrint("Unsupported package\n");
1917                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1918         }
1919
1920 out:
1921         result = packet_create_reply(packet, "i", ret);
1922         if (!result) {
1923                 ErrPrint("Failed to create a reply packet\n");
1924         }
1925
1926         return result;
1927 }
1928
1929 static struct packet *client_dbox_key_set(pid_t pid, int handle, const struct packet *packet)
1930 {
1931         struct client_node *client;
1932         const char *pkgname;
1933         const char *id;
1934         int ret;
1935         double timestamp;
1936         unsigned int keycode;
1937         struct inst_info *inst;
1938         const struct pkg_info *pkg;
1939         struct packet *result;
1940
1941         client = client_find_by_rpc_handle(handle);
1942         if (!client) {
1943                 ErrPrint("Client %d is not exists\n", pid);
1944                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1945                 goto out;
1946         }
1947
1948         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
1949         if (ret != 4) {
1950                 ErrPrint("Parameter is not matched\n");
1951                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1952                 goto out;
1953         }
1954
1955         ret = validate_request(pkgname, id, &inst, &pkg);
1956         if (ret != DBOX_STATUS_ERROR_NONE) {
1957                 goto out;
1958         }
1959
1960         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
1961                 ret = event_activate(0, 0, key_event_dbox_route_cb, inst);
1962                 if (ret == DBOX_STATUS_ERROR_NONE) {
1963                         if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1964                                 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
1965                         }
1966                         if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb) <= 0) {
1967                                 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb);
1968                         }
1969                 }
1970         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
1971                 ret = event_activate(0, 0, key_event_dbox_consume_cb, inst);
1972                 if (ret == DBOX_STATUS_ERROR_NONE) {
1973                         if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1974                                 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
1975                         }
1976                         if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb) <= 0) {
1977                                 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb);
1978                         }
1979                 }
1980         } else {
1981                 ErrPrint("Unsupported package\n");
1982                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1983         }
1984
1985 out:
1986         result = packet_create_reply(packet, "i", ret);
1987         if (!result) {
1988                 ErrPrint("Failed to create a reply packet\n");
1989         }
1990
1991         return result;
1992 }
1993
1994 static struct packet *client_dbox_key_unset(pid_t pid, int handle, const struct packet *packet)
1995 {
1996         struct client_node *client;
1997         const char *pkgname;
1998         const char *id;
1999         int ret;
2000         double timestamp;
2001         unsigned int keycode;
2002         struct inst_info *inst;
2003         const struct pkg_info *pkg;
2004         struct packet *result;
2005
2006         client = client_find_by_rpc_handle(handle);
2007         if (!client) {
2008                 ErrPrint("Client %d is not exists\n", pid);
2009                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2010                 goto out;
2011         }
2012
2013         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
2014         if (ret != 4) {
2015                 ErrPrint("Parameter is not matched\n");
2016                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2017                 goto out;
2018         }
2019
2020         ret = validate_request(pkgname, id, &inst, &pkg);
2021         if (ret != DBOX_STATUS_ERROR_NONE) {
2022                 goto out;
2023         }
2024
2025         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2026                 ret = event_deactivate(key_event_dbox_route_cb, inst);
2027                 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2028                         (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2029                 }
2030                 /*
2031                  * This delete callback will be removed when the instance will be destroyed.
2032                  if (ret == 0) {
2033                  instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb);
2034                  }
2035                  */
2036         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2037                 ret = event_deactivate(key_event_dbox_consume_cb, inst);
2038                 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2039                         (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2040                 }
2041                 /*
2042                  * This delete callback will be removed when the instance will be destroyed.
2043                  if (ret == 0) {
2044                  instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb);
2045                  }
2046                  */
2047         } else {
2048                 ErrPrint("Unsupported package\n");
2049                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2050         }
2051
2052 out:
2053         result = packet_create_reply(packet, "i", ret);
2054         if (!result) {
2055                 ErrPrint("Failed to create a reply packet\n");
2056         }
2057
2058         return result;
2059 }
2060
2061 static struct packet *client_dbox_mouse_set(pid_t pid, int handle, const struct packet *packet)
2062 {
2063         struct client_node *client;
2064         const char *pkgname;
2065         const char *id;
2066         int ret;
2067         double timestamp;
2068         int x;
2069         int y;
2070         struct inst_info *inst;
2071         const struct pkg_info *pkg;
2072
2073         client = client_find_by_rpc_handle(handle);
2074         if (!client) {
2075                 ErrPrint("Client %d is not exists\n", pid);
2076                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2077                 goto out;
2078         }
2079
2080         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2081         if (ret != 5) {
2082                 ErrPrint("Parameter is not matched\n");
2083                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2084                 goto out;
2085         }
2086
2087         ret = validate_request(pkgname, id, &inst, &pkg);
2088         if (ret != DBOX_STATUS_ERROR_NONE) {
2089                 goto out;
2090         }
2091
2092         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2093                 if (package_direct_input(pkg) == 0 || packet_set_fd((struct packet *)packet, event_input_fd()) < 0) {
2094                         ret = event_activate(x, y, mouse_event_dbox_route_cb, inst);
2095                         if (ret == DBOX_STATUS_ERROR_NONE) {
2096                                 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2097                                         (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
2098                                 }
2099                                 if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb) <= 0) {
2100                                         instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb);
2101                                 }
2102                         }
2103                 } else {
2104                         struct slave_node *slave;
2105
2106                         DbgPrint("Direct input is enabled(set for %s:%d)\n", id, packet_fd(packet));
2107                         slave = package_slave(pkg);
2108                         if (slave) {
2109                                 packet_ref((struct packet *)packet);
2110                                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2111                         } else {
2112                                 ErrPrint("Unable to find a slave for %s\n", pkgname);
2113                                 ret = DBOX_STATUS_ERROR_FAULT;
2114                         }
2115                 }
2116         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2117                 ret = event_activate(x, y, mouse_event_dbox_consume_cb, inst);
2118                 if (ret == DBOX_STATUS_ERROR_NONE) {
2119                         if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2120                                 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
2121                         }
2122                         if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb) <= 0) {
2123                                 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb);
2124                         }
2125                 }
2126         } else {
2127                 ErrPrint("Unsupported package\n");
2128                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2129         }
2130 out:
2131         return NULL;
2132 }
2133
2134 static struct packet *client_dbox_mouse_unset(pid_t pid, int handle, const struct packet *packet)
2135 {
2136         struct client_node *client;
2137         const char *pkgname;
2138         const char *id;
2139         int ret;
2140         double timestamp;
2141         int x;
2142         int y;
2143         struct inst_info *inst;
2144         const struct pkg_info *pkg;
2145
2146         client = client_find_by_rpc_handle(handle);
2147         if (!client) {
2148                 ErrPrint("Client %d is not exists\n", pid);
2149                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2150                 goto out;
2151         }
2152
2153         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2154         if (ret != 5) {
2155                 ErrPrint("Parameter is not matched\n");
2156                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2157                 goto out;
2158         }
2159
2160         ret = validate_request(pkgname, id, &inst, &pkg);
2161         if (ret != DBOX_STATUS_ERROR_NONE) {
2162                 goto out;
2163         }
2164
2165         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2166                 if (package_direct_input(pkg) == 0) {
2167                         ret = event_deactivate(mouse_event_dbox_route_cb, inst);
2168                         if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2169                                 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2170                         }
2171                         /*
2172                          * This delete callback will be removed when the instance will be destroyed.
2173                          if (ret == 0) {
2174                          instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb);
2175                          }
2176                          */
2177                 } else {
2178                         struct slave_node *slave;
2179
2180                         DbgPrint("Direct input is enabled(unset) for %s\n", id);
2181                         slave = package_slave(pkg);
2182                         if (slave) {
2183                                 packet_ref((struct packet *)packet);
2184                                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2185                         } else {
2186                                 ErrPrint("Unable to find a slave for %s\n", pkgname);
2187                                 ret = DBOX_STATUS_ERROR_FAULT;
2188                         }
2189                 }
2190         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2191                 ret = event_deactivate(mouse_event_dbox_consume_cb, inst);
2192                 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2193                         (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2194                 }
2195                 /*
2196                  * This delete callback will be removed when the instance will be destroyed.
2197                  if (ret == 0) {
2198                  instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb);
2199                  }
2200                  */
2201         } else {
2202                 ErrPrint("Unsupported package\n");
2203                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2204         }
2205 out:
2206         return NULL;
2207 }
2208
2209 static struct packet *client_gbar_mouse_set(pid_t pid, int handle, const struct packet *packet)
2210 {
2211         struct client_node *client;
2212         const char *pkgname;
2213         const char *id;
2214         int ret;
2215         double timestamp;
2216         int x;
2217         int y;
2218         struct inst_info *inst;
2219         const struct pkg_info *pkg;
2220
2221         client = client_find_by_rpc_handle(handle);
2222         if (!client) {
2223                 ErrPrint("Client %d is not exists\n", pid);
2224                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2225                 goto out;
2226         }
2227
2228         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2229         if (ret != 5) {
2230                 ErrPrint("Parameter is not matched\n");
2231                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2232                 goto out;
2233         }
2234
2235         ret = validate_request(pkgname, id, &inst, &pkg);
2236         if (ret != DBOX_STATUS_ERROR_NONE) {
2237                 goto out;
2238         }
2239
2240         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2241                 if (package_direct_input(pkg) == 0 || packet_set_fd((struct packet *)packet, event_input_fd()) < 0) {
2242                         ret = event_activate(x, y, mouse_event_gbar_route_cb, inst);
2243                         if (ret == DBOX_STATUS_ERROR_NONE) {
2244                                 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2245                                         (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
2246                                 }
2247                                 if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb) <= 0) {
2248                                         instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb);
2249                                 }
2250                         }
2251                 } else {
2252                         struct slave_node *slave;
2253
2254                         DbgPrint("Direct input is enabled(set for %s:%d)\n", id, packet_fd(packet));
2255                         slave = package_slave(pkg);
2256                         if (slave) {
2257                                 packet_ref((struct packet *)packet);
2258                                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2259                         } else {
2260                                 ErrPrint("Unable to find a slave for %s\n", pkgname);
2261                                 ret = DBOX_STATUS_ERROR_FAULT;
2262                         }
2263                 }
2264         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2265                 ret = event_activate(x, y, mouse_event_gbar_consume_cb, inst);
2266                 if (ret == DBOX_STATUS_ERROR_NONE) {
2267                         if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2268                                 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
2269                         }
2270                         if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb) <= 0) {
2271                                 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb);
2272                         }
2273                 }
2274         } else {
2275                 ErrPrint("Unsupported package\n");
2276                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2277         }
2278
2279 out:
2280         return NULL;
2281 }
2282
2283 static struct packet *client_dbox_mouse_on_scroll(pid_t pid, int handle, const struct packet *packet)
2284 {
2285         struct client_node *client;
2286         const char *pkgname;
2287         const char *id;
2288         int ret;
2289         double timestamp;
2290         int x;
2291         int y;
2292         struct inst_info *inst;
2293         const struct pkg_info *pkg;
2294
2295         client = client_find_by_rpc_handle(handle);
2296         if (!client) {
2297                 ErrPrint("Client %d is not exists\n", pid);
2298                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2299                 goto out;
2300         }
2301
2302         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2303         if (ret != 5) {
2304                 ErrPrint("Parameter is not matched\n");
2305                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2306                 goto out;
2307         }
2308
2309         ret = validate_request(pkgname, id, &inst, &pkg);
2310         if (ret != DBOX_STATUS_ERROR_NONE) {
2311                 goto out;
2312         }
2313
2314         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2315                 ret = forward_dbox_event_packet(pkg, inst, packet);
2316         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2317                 struct script_info *script;
2318
2319                 script = instance_dbox_script(inst);
2320                 if (!script) {
2321                         ret = DBOX_STATUS_ERROR_FAULT;
2322                         goto out;
2323                 }
2324
2325                 script_handler_update_pointer(script, x, y, -1);
2326                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_SCROLL, timestamp);
2327                 ret = 0;
2328         } else {
2329                 ErrPrint("Unsupported package\n");
2330                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2331         }
2332
2333 out:
2334         /*! \note No reply packet */
2335         return NULL;
2336 }
2337
2338 static struct packet *client_dbox_mouse_off_scroll(pid_t pid, int handle, const struct packet *packet)
2339 {
2340         struct client_node *client;
2341         const char *pkgname;
2342         const char *id;
2343         int ret;
2344         double timestamp;
2345         int x;
2346         int y;
2347         struct inst_info *inst;
2348         const struct pkg_info *pkg;
2349
2350         client = client_find_by_rpc_handle(handle);
2351         if (!client) {
2352                 ErrPrint("Client %d is not exists\n", pid);
2353                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2354                 goto out;
2355         }
2356
2357         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2358         if (ret != 5) {
2359                 ErrPrint("Parameter is not matched\n");
2360                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2361                 goto out;
2362         }
2363
2364         ret = validate_request(pkgname, id, &inst, &pkg);
2365         if (ret != DBOX_STATUS_ERROR_NONE) {
2366                 goto out;
2367         }
2368
2369         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2370                 ret = forward_dbox_event_packet(pkg, inst, packet);
2371         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2372                 struct script_info *script;
2373
2374                 script = instance_dbox_script(inst);
2375                 if (!script) {
2376                         ret = DBOX_STATUS_ERROR_FAULT;
2377                         goto out;
2378                 }
2379
2380                 script_handler_update_pointer(script, x, y, -1);
2381                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_SCROLL, timestamp);
2382                 ret = 0;
2383         } else {
2384                 ErrPrint("Unsupported package\n");
2385                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2386         }
2387
2388 out:
2389         /*! \note No reply packet */
2390         return NULL;
2391 }
2392
2393 static struct packet *client_dbox_mouse_on_hold(pid_t pid, int handle, const struct packet *packet)
2394 {
2395         struct client_node *client;
2396         const char *pkgname;
2397         const char *id;
2398         int ret;
2399         double timestamp;
2400         int x;
2401         int y;
2402         struct inst_info *inst;
2403         const struct pkg_info *pkg;
2404
2405         client = client_find_by_rpc_handle(handle);
2406         if (!client) {
2407                 ErrPrint("Client %d is not exists\n", pid);
2408                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2409                 goto out;
2410         }
2411
2412         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2413         if (ret != 5) {
2414                 ErrPrint("Parameter is not matched\n");
2415                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2416                 goto out;
2417         }
2418
2419         ret = validate_request(pkgname, id, &inst, &pkg);
2420         if (ret != DBOX_STATUS_ERROR_NONE) {
2421                 goto out;
2422         }
2423
2424         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2425                 ret = forward_dbox_event_packet(pkg, inst, packet);
2426         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2427                 struct script_info *script;
2428
2429                 script = instance_dbox_script(inst);
2430                 if (!script) {
2431                         ret = DBOX_STATUS_ERROR_FAULT;
2432                         goto out;
2433                 }
2434
2435                 script_handler_update_pointer(script, x, y, -1);
2436                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_HOLD, timestamp);
2437                 ret = 0;
2438         } else {
2439                 ErrPrint("Unsupported package\n");
2440                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2441         }
2442
2443 out:
2444         /*! \note No reply packet */
2445         return NULL;
2446 }
2447
2448 static struct packet *client_dbox_mouse_off_hold(pid_t pid, int handle, const struct packet *packet)
2449 {
2450         struct client_node *client;
2451         const char *pkgname;
2452         const char *id;
2453         int ret;
2454         double timestamp;
2455         int x;
2456         int y;
2457         struct inst_info *inst;
2458         const struct pkg_info *pkg;
2459
2460         client = client_find_by_rpc_handle(handle);
2461         if (!client) {
2462                 ErrPrint("Client %d is not exists\n", pid);
2463                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2464                 goto out;
2465         }
2466
2467         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2468         if (ret != 5) {
2469                 ErrPrint("Parameter is not matched\n");
2470                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2471                 goto out;
2472         }
2473
2474         ret = validate_request(pkgname, id, &inst, &pkg);
2475         if (ret != DBOX_STATUS_ERROR_NONE) {
2476                 goto out;
2477         }
2478
2479         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2480                 ret = forward_dbox_event_packet(pkg, inst, packet);
2481         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2482                 struct script_info *script;
2483
2484                 script = instance_dbox_script(inst);
2485                 if (!script) {
2486                         ret = DBOX_STATUS_ERROR_FAULT;
2487                         goto out;
2488                 }
2489
2490                 script_handler_update_pointer(script, x, y, -1);
2491                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_HOLD, timestamp);
2492                 ret = 0;
2493         } else {
2494                 ErrPrint("Unsupported package\n");
2495                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2496         }
2497
2498 out:
2499         /*! \note No reply packet */
2500         return NULL;
2501 }
2502
2503 static struct packet *client_gbar_mouse_on_scroll(pid_t pid, int handle, const struct packet *packet)
2504 {
2505         struct client_node *client;
2506         const char *pkgname;
2507         const char *id;
2508         int ret;
2509         double timestamp;
2510         int x;
2511         int y;
2512         struct inst_info *inst;
2513         const struct pkg_info *pkg;
2514
2515         client = client_find_by_rpc_handle(handle);
2516         if (!client) {
2517                 ErrPrint("Client %d is not exists\n", pid);
2518                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2519                 goto out;
2520         }
2521
2522         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2523         if (ret != 5) {
2524                 ErrPrint("Parameter is not matched\n");
2525                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2526                 goto out;
2527         }
2528
2529         ret = validate_request(pkgname, id, &inst, &pkg);
2530         if (ret != DBOX_STATUS_ERROR_NONE) {
2531                 goto out;
2532         }
2533
2534         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2535                 ret = forward_gbar_event_packet(pkg, inst, packet);
2536         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2537                 struct script_info *script;
2538
2539                 script = instance_gbar_script(inst);
2540                 if (!script) {
2541                         ret = DBOX_STATUS_ERROR_FAULT;
2542                         goto out;
2543                 }
2544
2545                 script_handler_update_pointer(script, x, y, -1);
2546                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_SCROLL, timestamp);
2547                 ret = 0;
2548         } else {
2549                 ErrPrint("Unsupported package\n");
2550                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2551         }
2552
2553 out:
2554         /*! \note No reply packet */
2555         return NULL;
2556 }
2557
2558 static struct packet *client_gbar_mouse_off_scroll(pid_t pid, int handle, const struct packet *packet)
2559 {
2560         struct client_node *client;
2561         const char *pkgname;
2562         const char *id;
2563         int ret;
2564         double timestamp;
2565         int x;
2566         int y;
2567         struct inst_info *inst;
2568         const struct pkg_info *pkg;
2569
2570         client = client_find_by_rpc_handle(handle);
2571         if (!client) {
2572                 ErrPrint("Client %d is not exists\n", pid);
2573                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2574                 goto out;
2575         }
2576
2577         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2578         if (ret != 5) {
2579                 ErrPrint("Parameter is not matched\n");
2580                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2581                 goto out;
2582         }
2583
2584         ret = validate_request(pkgname, id, &inst, &pkg);
2585         if (ret != DBOX_STATUS_ERROR_NONE) {
2586                 goto out;
2587         }
2588
2589         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2590                 ret = forward_gbar_event_packet(pkg, inst, packet);
2591         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2592                 struct script_info *script;
2593
2594                 script = instance_gbar_script(inst);
2595                 if (!script) {
2596                         ret = DBOX_STATUS_ERROR_FAULT;
2597                         goto out;
2598                 }
2599
2600                 script_handler_update_pointer(script, x, y, -1);
2601                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_SCROLL, timestamp);
2602                 ret = 0;
2603         } else {
2604                 ErrPrint("Unsupported package\n");
2605                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2606         }
2607
2608 out:
2609         /*! \note No reply packet */
2610         return NULL;
2611 }
2612
2613 static struct packet *client_gbar_mouse_on_hold(pid_t pid, int handle, const struct packet *packet)
2614 {
2615         struct client_node *client;
2616         const char *pkgname;
2617         const char *id;
2618         int ret;
2619         double timestamp;
2620         int x;
2621         int y;
2622         struct inst_info *inst;
2623         const struct pkg_info *pkg;
2624
2625         client = client_find_by_rpc_handle(handle);
2626         if (!client) {
2627                 ErrPrint("Client %d is not exists\n", pid);
2628                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2629                 goto out;
2630         }
2631
2632         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2633         if (ret != 5) {
2634                 ErrPrint("Parameter is not matched\n");
2635                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2636                 goto out;
2637         }
2638
2639         ret = validate_request(pkgname, id, &inst, &pkg);
2640         if (ret != DBOX_STATUS_ERROR_NONE) {
2641                 goto out;
2642         }
2643
2644         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2645                 ret = forward_gbar_event_packet(pkg, inst, packet);
2646         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2647                 struct script_info *script;
2648
2649                 script = instance_gbar_script(inst);
2650                 if (!script) {
2651                         ret = DBOX_STATUS_ERROR_FAULT;
2652                         goto out;
2653                 }
2654
2655                 script_handler_update_pointer(script, x, y, -1);
2656                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_HOLD, timestamp);
2657                 ret = 0;
2658         } else {
2659                 ErrPrint("Unsupported package\n");
2660                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2661         }
2662
2663 out:
2664         /*! \note No reply packet */
2665         return NULL;
2666 }
2667
2668 static struct packet *client_gbar_mouse_off_hold(pid_t pid, int handle, const struct packet *packet)
2669 {
2670         struct client_node *client;
2671         const char *pkgname;
2672         const char *id;
2673         int ret;
2674         double timestamp;
2675         int x;
2676         int y;
2677         struct inst_info *inst;
2678         const struct pkg_info *pkg;
2679
2680         client = client_find_by_rpc_handle(handle);
2681         if (!client) {
2682                 ErrPrint("Client %d is not exists\n", pid);
2683                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2684                 goto out;
2685         }
2686
2687         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2688         if (ret != 5) {
2689                 ErrPrint("Parameter is not matched\n");
2690                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2691                 goto out;
2692         }
2693
2694         ret = validate_request(pkgname, id, &inst, &pkg);
2695         if (ret != DBOX_STATUS_ERROR_NONE) {
2696                 goto out;
2697         }
2698
2699         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2700                 ret = forward_gbar_event_packet(pkg, inst, packet);
2701         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2702                 struct script_info *script;
2703
2704                 script = instance_gbar_script(inst);
2705                 if (!script) {
2706                         ret = DBOX_STATUS_ERROR_FAULT;
2707                         goto out;
2708                 }
2709
2710                 script_handler_update_pointer(script, x, y, -1);
2711                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_HOLD, timestamp);
2712                 ret = 0;
2713         } else {
2714                 ErrPrint("Unsupported package\n");
2715                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2716         }
2717
2718 out:
2719         /*! \note No reply packet */
2720         return NULL;
2721 }
2722
2723 static struct packet *client_gbar_mouse_unset(pid_t pid, int handle, const struct packet *packet)
2724 {
2725         struct client_node *client;
2726         const char *pkgname;
2727         const char *id;
2728         int ret;
2729         double timestamp;
2730         int x;
2731         int y;
2732         struct inst_info *inst;
2733         const struct pkg_info *pkg;
2734
2735         client = client_find_by_rpc_handle(handle);
2736         if (!client) {
2737                 ErrPrint("Client %d is not exists\n", pid);
2738                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2739                 goto out;
2740         }
2741
2742         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2743         if (ret != 5) {
2744                 ErrPrint("Parameter is not matched\n");
2745                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2746                 goto out;
2747         }
2748
2749         ret = validate_request(pkgname, id, &inst, &pkg);
2750         if (ret != DBOX_STATUS_ERROR_NONE) {
2751                 goto out;
2752         }
2753
2754         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2755                 if (package_direct_input(pkg) == 0) {
2756                         ret = event_deactivate(mouse_event_gbar_route_cb, inst);
2757                         if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2758                                 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2759                         }
2760                         /*
2761                          * This delete callback will be removed when the instance will be destroyed.
2762                          if (ret == 0) {
2763                          instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb);
2764                          }
2765                          */
2766                 } else {
2767                         struct slave_node *slave;
2768
2769                         DbgPrint("Direct input is enabled(unset) for %s\n", id);
2770                         slave = package_slave(pkg);
2771                         if (slave) {
2772                                 packet_ref((struct packet *)packet);
2773                                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2774                         } else {
2775                                 ErrPrint("Unable to find a slave for %s\n", pkgname);
2776                                 ret = DBOX_STATUS_ERROR_FAULT;
2777                         }
2778                 }
2779         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2780                 ret = event_deactivate(mouse_event_gbar_consume_cb, inst);
2781                 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2782                         (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2783                 }
2784                 /*
2785                  * This delete callback will be removed when the instance will be destroyed.
2786                  if (ret == 0) {
2787                  instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb);
2788                  }
2789                  */
2790         } else {
2791                 ErrPrint("Unsupported package\n");
2792                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2793         }
2794 out:
2795         return NULL;
2796 }
2797
2798 static struct packet *client_dbox_mouse_enter(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
2799 {
2800         struct client_node *client;
2801         const char *pkgname;
2802         const char *id;
2803         int ret;
2804         double timestamp;
2805         int x;
2806         int y;
2807         struct inst_info *inst;
2808         const struct pkg_info *pkg;
2809
2810         client = client_find_by_rpc_handle(handle);
2811         if (!client) {
2812                 ErrPrint("Client %d is not exists\n", pid);
2813                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2814                 goto out;
2815         }
2816
2817         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2818         if (ret != 5) {
2819                 ErrPrint("Parameter is not matched\n");
2820                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2821                 goto out;
2822         }
2823
2824         ret = validate_request(pkgname, id, &inst, &pkg);
2825         if (ret != DBOX_STATUS_ERROR_NONE) {
2826                 goto out;
2827         }
2828
2829         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2830                 ret = forward_dbox_event_packet(pkg, inst, packet);
2831         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2832                 struct script_info *script;
2833
2834                 script = instance_dbox_script(inst);
2835                 if (!script) {
2836                         ret = DBOX_STATUS_ERROR_FAULT;
2837                         goto out;
2838                 }
2839
2840                 script_handler_update_pointer(script, x, y, -1);
2841                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_IN, timestamp);
2842                 ret = 0;
2843         } else {
2844                 ErrPrint("Unsupported package\n");
2845                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2846         }
2847
2848 out:
2849         /*! \note No reply packet */
2850         return NULL;
2851 }
2852
2853 static struct packet *client_dbox_mouse_leave(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
2854 {
2855         struct client_node *client;
2856         const char *pkgname;
2857         const char *id;
2858         int ret;
2859         double timestamp;
2860         int x;
2861         int y;
2862         struct inst_info *inst;
2863         const struct pkg_info *pkg;
2864
2865         client = client_find_by_rpc_handle(handle);
2866         if (!client) {
2867                 ErrPrint("Client %d is not exists\n", pid);
2868                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2869                 goto out;
2870         }
2871
2872         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2873         if (ret != 5) {
2874                 ErrPrint("Parameter is not matched\n");
2875                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2876                 goto out;
2877         }
2878
2879         ret = validate_request(pkgname, id, &inst, &pkg);
2880         if (ret != DBOX_STATUS_ERROR_NONE) {
2881                 goto out;
2882         }
2883
2884         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2885                 ret = forward_dbox_event_packet(pkg, inst, packet);
2886         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2887                 struct script_info *script;
2888
2889                 script = instance_dbox_script(inst);
2890                 if (!script) {
2891                         ret = DBOX_STATUS_ERROR_FAULT;
2892                         goto out;
2893                 }
2894
2895                 script_handler_update_pointer(script, x, y, -1);
2896                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OUT, timestamp);
2897                 ret = 0;
2898         } else {
2899                 ErrPrint("Unsupported package\n");
2900                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2901         }
2902
2903 out:
2904         /*! \note No reply packet */
2905         return NULL;
2906 }
2907
2908 static struct packet *client_dbox_mouse_down(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
2909 {
2910         struct client_node *client;
2911         const char *pkgname;
2912         const char *id;
2913         int ret;
2914         double timestamp;
2915         int x;
2916         int y;
2917         struct inst_info *inst;
2918         const struct pkg_info *pkg;
2919
2920         client = client_find_by_rpc_handle(handle);
2921         if (!client) {
2922                 ErrPrint("Client %d is not exists\n", pid);
2923                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2924                 goto out;
2925         }
2926
2927         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2928         if (ret != 5) {
2929                 ErrPrint("Parameter is not matched\n");
2930                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2931                 goto out;
2932         }
2933
2934         ret = validate_request(pkgname, id, &inst, &pkg);
2935         if (ret != DBOX_STATUS_ERROR_NONE) {
2936                 goto out;
2937         }
2938
2939         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2940                 ret = forward_dbox_event_packet(pkg, inst, packet);
2941         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2942                 struct script_info *script;
2943
2944                 script = instance_dbox_script(inst);
2945                 if (!script) {
2946                         ret = DBOX_STATUS_ERROR_FAULT;
2947                         goto out;
2948                 }
2949
2950                 script_handler_update_pointer(script, x, y, 1);
2951                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp);
2952                 ret = 0;
2953         } else {
2954                 ErrPrint("Unsupported package\n");
2955                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2956         }
2957
2958 out:
2959         /*! \note No reply packet */
2960         return NULL;
2961 }
2962
2963 static struct packet *client_dbox_mouse_up(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
2964 {
2965         struct client_node *client;
2966         const char *pkgname;
2967         const char *id;
2968         int ret;
2969         double timestamp;
2970         int x;
2971         int y;
2972         struct inst_info *inst;
2973         const struct pkg_info *pkg;
2974
2975         client = client_find_by_rpc_handle(handle);
2976         if (!client) {
2977                 ErrPrint("Client %d is not exists\n", pid);
2978                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2979                 goto out;
2980         }
2981
2982         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2983         if (ret != 5) {
2984                 ErrPrint("Parameter is not matched\n");
2985                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2986                 goto out;
2987         }
2988
2989         ret = validate_request(pkgname, id, &inst, &pkg);
2990         if (ret != DBOX_STATUS_ERROR_NONE) {
2991                 goto out;
2992         }
2993
2994         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2995                 ret = forward_dbox_event_packet(pkg, inst, packet);
2996         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2997                 struct script_info *script;
2998
2999                 script = instance_dbox_script(inst);
3000                 if (!script) {
3001                         ret = DBOX_STATUS_ERROR_FAULT;
3002                         goto out;
3003                 }
3004
3005                 script_handler_update_pointer(script, x, y, 0);
3006                 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp);
3007                 ret = 0;
3008         } else {
3009                 ErrPrint("Unsupported package\n");
3010                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3011         }
3012
3013 out:
3014         /*! \note No reply packet */
3015         return NULL;
3016 }
3017
3018 static struct packet *client_gbar_access_action(pid_t pid, int handle, const struct packet *packet)
3019 {
3020         struct packet *result;
3021         struct client_node *client;
3022         const char *pkgname;
3023         const char *id;
3024         int ret;
3025         double timestamp;
3026         struct access_info event;
3027         struct inst_info *inst = NULL;
3028         const struct pkg_info *pkg = NULL;
3029
3030         client = client_find_by_rpc_handle(handle);
3031         if (!client) {
3032                 ErrPrint("Client %d is not exists\n", pid);
3033                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3034                 goto out;
3035         }
3036
3037         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
3038         if (ret != 6) {
3039                 ErrPrint("Invalid parameter\n");
3040                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3041                 goto out;
3042         }
3043
3044         ret = validate_request(pkgname, id, &inst, &pkg);
3045         if (ret != DBOX_STATUS_ERROR_NONE) {
3046                 goto out;
3047         }
3048
3049         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3050                 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3051         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3052                 struct script_info *script;
3053
3054                 script = instance_gbar_script(inst);
3055                 if (!script) {
3056                         ret = DBOX_STATUS_ERROR_FAULT;
3057                         goto out;
3058                 }
3059
3060                 script_handler_update_pointer(script, event.x, event.y, event.type);
3061                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTION, timestamp);
3062                 if (ret >= 0) {
3063                         ret = send_delayed_access_status(inst, ret);
3064                 }
3065         } else {
3066                 ErrPrint("Unsupported package\n");
3067                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3068         }
3069
3070 out:
3071         result = packet_create_reply(packet, "i", ret);
3072         if (!result) {
3073                 ErrPrint("Failed to create a reply packet\n");
3074         }
3075
3076         return result;
3077 }
3078
3079 static struct packet *client_gbar_access_scroll(pid_t pid, int handle, const struct packet *packet)
3080 {
3081         struct packet *result;
3082         struct client_node *client;
3083         const char *pkgname;
3084         const char *id;
3085         int ret;
3086         double timestamp;
3087         struct access_info event;
3088         struct inst_info *inst = NULL;
3089         const struct pkg_info *pkg = NULL;
3090
3091         client = client_find_by_rpc_handle(handle);
3092         if (!client) {
3093                 ErrPrint("Client %d is not exists\n", pid);
3094                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3095                 goto out;
3096         }
3097
3098         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
3099         if (ret != 6) {
3100                 ErrPrint("Invalid parameter\n");
3101                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3102                 goto out;
3103         }
3104
3105         ret = validate_request(pkgname, id, &inst, &pkg);
3106         if (ret != DBOX_STATUS_ERROR_NONE) {
3107                 goto out;
3108         }
3109
3110         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3111                 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3112         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3113                 struct script_info *script;
3114
3115                 script = instance_gbar_script(inst);
3116                 if (!script) {
3117                         ret = DBOX_STATUS_ERROR_FAULT;
3118                         goto out;
3119                 }
3120
3121                 script_handler_update_pointer(script, event.x, event.y, event.type);
3122                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_SCROLL, timestamp);
3123                 if (ret >= 0) {
3124                         ret = send_delayed_access_status(inst, ret);
3125                 }
3126         } else {
3127                 ErrPrint("Unsupported package\n");
3128                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3129         }
3130
3131 out:
3132         result = packet_create_reply(packet, "i", ret);
3133         if (!result) {
3134                 ErrPrint("Failed to create a reply packet\n");
3135         }
3136
3137         return result;
3138 }
3139
3140 static struct packet *client_gbar_access_value_change(pid_t pid, int handle, const struct packet *packet)
3141 {
3142         struct packet *result;
3143         struct client_node *client;
3144         const char *pkgname;
3145         const char *id;
3146         int ret;
3147         double timestamp;
3148         struct access_info event;
3149         struct inst_info *inst = NULL;
3150         const struct pkg_info *pkg = NULL;
3151
3152         client = client_find_by_rpc_handle(handle);
3153         if (!client) {
3154                 ErrPrint("Client %d is not exists\n", pid);
3155                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3156                 goto out;
3157         }
3158
3159         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
3160         if (ret != 6) {
3161                 ErrPrint("Invalid parameter\n");
3162                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3163                 goto out;
3164         }
3165
3166         ret = validate_request(pkgname, id, &inst, &pkg);
3167         if (ret != DBOX_STATUS_ERROR_NONE) {
3168                 goto out;
3169         }
3170
3171         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3172                 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3173         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3174                 struct script_info *script;
3175
3176                 script = instance_gbar_script(inst);
3177                 if (!script) {
3178                         ret = DBOX_STATUS_ERROR_FAULT;
3179                         goto out;
3180                 }
3181
3182                 script_handler_update_pointer(script, event.x, event.y, event.type);
3183                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_VALUE_CHANGE, timestamp);
3184                 if (ret >= 0) {
3185                         ret = send_delayed_access_status(inst, ret);
3186                 }
3187         } else {
3188                 ErrPrint("Unsupported package\n");
3189                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3190         }
3191
3192 out:
3193         result = packet_create_reply(packet, "i", ret);
3194         if (!result) {
3195                 ErrPrint("Failed to create a reply packet\n");
3196         }
3197
3198         return result;
3199 }
3200
3201 static struct packet *client_gbar_access_mouse(pid_t pid, int handle, const struct packet *packet)
3202 {
3203         struct packet *result;
3204         struct client_node *client;
3205         const char *pkgname;
3206         const char *id;
3207         int ret;
3208         double timestamp;
3209         struct access_info event;
3210         struct inst_info *inst = NULL;
3211         const struct pkg_info *pkg = NULL;
3212
3213         client = client_find_by_rpc_handle(handle);
3214         if (!client) {
3215                 ErrPrint("Client %d is not exists\n", pid);
3216                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3217                 goto out;
3218         }
3219
3220         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
3221         if (ret != 6) {
3222                 ErrPrint("Invalid parameter\n");
3223                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3224                 goto out;
3225         }
3226
3227         ret = validate_request(pkgname, id, &inst, &pkg);
3228         if (ret != DBOX_STATUS_ERROR_NONE) {
3229                 goto out;
3230         }
3231
3232         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3233                 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3234         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3235                 struct script_info *script;
3236
3237                 script = instance_gbar_script(inst);
3238                 if (!script) {
3239                         ret = DBOX_STATUS_ERROR_FAULT;
3240                         goto out;
3241                 }
3242
3243                 script_handler_update_pointer(script, event.x, event.y, event.type);
3244                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_MOUSE, timestamp);
3245                 if (ret >= 0) {
3246                         ret = send_delayed_access_status(inst, ret);
3247                 }
3248         } else {
3249                 ErrPrint("Unsupported package\n");
3250                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3251         }
3252
3253 out:
3254         result = packet_create_reply(packet, "i", ret);
3255         if (!result) {
3256                 ErrPrint("Failed to create a reply packet\n");
3257         }
3258
3259         return result;
3260 }
3261
3262 static struct packet *client_gbar_access_back(pid_t pid, int handle, const struct packet *packet)
3263 {
3264         struct packet *result;
3265         struct client_node *client;
3266         const char *pkgname;
3267         const char *id;
3268         int ret;
3269         double timestamp;
3270         struct access_info event;
3271         struct inst_info *inst = NULL;
3272         const struct pkg_info *pkg = NULL;
3273
3274         client = client_find_by_rpc_handle(handle);
3275         if (!client) {
3276                 ErrPrint("Client %d is not exists\n", pid);
3277                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3278                 goto out;
3279         }
3280
3281         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
3282         if (ret != 6) {
3283                 ErrPrint("Invalid parameter\n");
3284                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3285                 goto out;
3286         }
3287
3288         ret = validate_request(pkgname, id, &inst, &pkg);
3289         if (ret != DBOX_STATUS_ERROR_NONE) {
3290                 goto out;
3291         }
3292
3293         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3294                 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3295         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3296                 struct script_info *script;
3297
3298                 script = instance_gbar_script(inst);
3299                 if (!script) {
3300                         ret = DBOX_STATUS_ERROR_FAULT;
3301                         goto out;
3302                 }
3303
3304                 script_handler_update_pointer(script, event.x, event.y, event.type);
3305                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_BACK, timestamp);
3306                 if (ret >= 0) {
3307                         ret = send_delayed_access_status(inst, ret);
3308                 }
3309         } else {
3310                 ErrPrint("Unsupported package\n");
3311                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3312         }
3313
3314 out:
3315         result = packet_create_reply(packet, "i", ret);
3316         if (!result) {
3317                 ErrPrint("Failed to create a reply packet\n");
3318         }
3319
3320         return result;
3321 }
3322
3323 static struct packet *client_gbar_access_over(pid_t pid, int handle, const struct packet *packet)
3324 {
3325         struct packet *result;
3326         struct client_node *client;
3327         const char *pkgname;
3328         const char *id;
3329         int ret;
3330         double timestamp;
3331         struct access_info event;
3332         struct inst_info *inst = NULL;
3333         const struct pkg_info *pkg = NULL;
3334
3335         client = client_find_by_rpc_handle(handle);
3336         if (!client) {
3337                 ErrPrint("Client %d is not exists\n", pid);
3338                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3339                 goto out;
3340         }
3341
3342         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
3343         if (ret != 6) {
3344                 ErrPrint("Invalid parameter\n");
3345                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3346                 goto out;
3347         }
3348
3349         ret = validate_request(pkgname, id, &inst, &pkg);
3350         if (ret != DBOX_STATUS_ERROR_NONE) {
3351                 goto out;
3352         }
3353
3354         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3355                 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3356         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3357                 struct script_info *script;
3358
3359                 script = instance_gbar_script(inst);
3360                 if (!script) {
3361                         ret = DBOX_STATUS_ERROR_FAULT;
3362                         goto out;
3363                 }
3364
3365                 script_handler_update_pointer(script, event.x, event.y, event.type);
3366                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_OVER, timestamp);
3367                 if (ret >= 0) {
3368                         ret = send_delayed_access_status(inst, ret);
3369                 }
3370         } else {
3371                 ErrPrint("Unsupported package\n");
3372                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3373         }
3374
3375 out:
3376         result = packet_create_reply(packet, "i", ret);
3377         if (!result) {
3378                 ErrPrint("Failed to create a reply packet\n");
3379         }
3380
3381         return result;
3382 }
3383
3384 static struct packet *client_gbar_access_read(pid_t pid, int handle, const struct packet *packet)
3385 {
3386         struct packet *result;
3387         struct client_node *client;
3388         const char *pkgname;
3389         const char *id;
3390         int ret;
3391         double timestamp;
3392         struct access_info event;
3393         struct inst_info *inst = NULL;
3394         const struct pkg_info *pkg = NULL;
3395
3396         client = client_find_by_rpc_handle(handle);
3397         if (!client) {
3398                 ErrPrint("Client %d is not exists\n", pid);
3399                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3400                 goto out;
3401         }
3402
3403         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
3404         if (ret != 6) {
3405                 ErrPrint("Invalid parameter\n");
3406                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3407                 goto out;
3408         }
3409
3410         ret = validate_request(pkgname, id, &inst, &pkg);
3411         if (ret != DBOX_STATUS_ERROR_NONE) {
3412                 goto out;
3413         }
3414
3415         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3416                 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3417         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3418                 struct script_info *script;
3419
3420                 script = instance_gbar_script(inst);
3421                 if (!script) {
3422                         ret = DBOX_STATUS_ERROR_FAULT;
3423                         goto out;
3424                 }
3425
3426                 script_handler_update_pointer(script, event.x, event.y, event.type);
3427                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_READ, timestamp);
3428                 if (ret >= 0) {
3429                         ret = send_delayed_access_status(inst, ret);
3430                 }
3431         } else {
3432                 ErrPrint("Unsupported package\n");
3433                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3434         }
3435
3436 out:
3437         result = packet_create_reply(packet, "i", ret);
3438         if (!result) {
3439                 ErrPrint("Failed to create a reply packet\n");
3440         }
3441
3442         return result;
3443 }
3444
3445 static struct packet *client_gbar_access_enable(pid_t pid, int handle, const struct packet *packet)
3446 {
3447         struct packet *result;
3448         struct client_node *client;
3449         const char *pkgname;
3450         const char *id;
3451         int ret;
3452         double timestamp;
3453         struct access_info event;
3454         struct inst_info *inst = NULL;
3455         const struct pkg_info *pkg = NULL;
3456
3457         client = client_find_by_rpc_handle(handle);
3458         if (!client) {
3459                 ErrPrint("Client %d is not exists\n", pid);
3460                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3461                 goto out;
3462         }
3463
3464         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
3465         if (ret != 6) {
3466                 ErrPrint("Invalid parameter\n");
3467                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3468                 goto out;
3469         }
3470
3471         ret = validate_request(pkgname, id, &inst, &pkg);
3472         if (ret != DBOX_STATUS_ERROR_NONE) {
3473                 goto out;
3474         }
3475
3476         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3477                 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3478         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3479                 struct script_info *script;
3480                 int type;
3481
3482                 script = instance_gbar_script(inst);
3483                 if (!script) {
3484                         ret = DBOX_STATUS_ERROR_FAULT;
3485                         goto out;
3486                 }
3487
3488                 type = (event.type == 0) ? DBOX_SCRIPT_ACCESS_DISABLE : DBOX_SCRIPT_ACCESS_ENABLE;
3489
3490                 script_handler_update_pointer(script, event.x, event.y, event.type);
3491                 ret = script_handler_feed_event(script, type, timestamp);
3492                 if (ret >= 0) {
3493                         ret = send_delayed_access_status(inst, ret);
3494                 }
3495         } else {
3496                 ErrPrint("Unsupported package\n");
3497                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3498         }
3499
3500 out:
3501         result = packet_create_reply(packet, "i", ret);
3502         if (!result) {
3503                 ErrPrint("Failed to create a reply packet\n");
3504         }
3505
3506         return result;
3507 }
3508
3509 static struct packet *client_gbar_access_hl(pid_t pid, int handle, const struct packet *packet)
3510 {
3511         struct packet *result;
3512         struct client_node *client;
3513         const char *pkgname;
3514         const char *id;
3515         int ret;
3516         double timestamp;
3517         struct access_info event;
3518         struct inst_info *inst = NULL;
3519         const struct pkg_info *pkg = NULL;
3520
3521         client = client_find_by_rpc_handle(handle);
3522         if (!client) {
3523                 ErrPrint("Client %d is not exists\n", pid);
3524                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3525                 goto out;
3526         }
3527
3528         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
3529         if (ret != 6) {
3530                 ErrPrint("Invalid parameter\n");
3531                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3532                 goto out;
3533         }
3534
3535         ret = validate_request(pkgname, id, &inst, &pkg);
3536         if (ret != DBOX_STATUS_ERROR_NONE) {
3537                 goto out;
3538         }
3539
3540         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3541                 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3542         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3543                 struct script_info *script;
3544                 int type;
3545
3546                 script = instance_gbar_script(inst);
3547                 if (!script) {
3548                         ret = DBOX_STATUS_ERROR_FAULT;
3549                         goto out;
3550                 }
3551
3552                 switch (event.type) {
3553                 case ACCESS_TYPE_CUR:
3554                         type = DBOX_SCRIPT_ACCESS_HIGHLIGHT;
3555                         break;
3556                 case ACCESS_TYPE_NEXT:
3557                         type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_NEXT;
3558                         break;
3559                 case ACCESS_TYPE_PREV:
3560                         type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_PREV;
3561                         break;
3562                 case ACCESS_TYPE_OFF:
3563                         type = DBOX_SCRIPT_ACCESS_UNHIGHLIGHT;
3564                         break;
3565                 default:
3566                         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3567                         goto out;
3568                 }
3569
3570                 script_handler_update_pointer(script, event.x, event.y, event.type);
3571                 ret = script_handler_feed_event(script, type, timestamp);
3572                 if (ret >= 0) {
3573                         ret = send_delayed_access_status(inst, ret);
3574                 }
3575         } else {
3576                 ErrPrint("Unsupported package\n");
3577                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3578         }
3579
3580 out:
3581         result = packet_create_reply(packet, "i", ret);
3582         if (!result) {
3583                 ErrPrint("Failed to create a reply packet\n");
3584         }
3585
3586         return result;
3587 }
3588
3589 static struct packet *client_gbar_access_activate(pid_t pid, int handle, const struct packet *packet)
3590 {
3591         struct packet *result;
3592         struct client_node *client;
3593         const char *pkgname;
3594         const char *id;
3595         int ret;
3596         double timestamp;
3597         struct access_info event;
3598         struct inst_info *inst = NULL;
3599         const struct pkg_info *pkg = NULL;
3600
3601         client = client_find_by_rpc_handle(handle);
3602         if (!client) {
3603                 ErrPrint("Client %d is not exists\n", pid);
3604                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3605                 goto out;
3606         }
3607
3608         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
3609         if (ret != 6) {
3610                 ErrPrint("Invalid parameter\n");
3611                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3612                 goto out;
3613         }
3614
3615         ret = validate_request(pkgname, id, &inst, &pkg);
3616         if (ret != DBOX_STATUS_ERROR_NONE) {
3617                 goto out;
3618         }
3619
3620         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3621                 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3622         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3623                 struct script_info *script;
3624
3625                 script = instance_gbar_script(inst);
3626                 if (!script) {
3627                         ret = DBOX_STATUS_ERROR_FAULT;
3628                         goto out;
3629                 }
3630
3631                 script_handler_update_pointer(script, event.x, event.y, event.type);
3632                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTIVATE, timestamp);
3633                 if (ret >= 0) {
3634                         ret = send_delayed_access_status(inst, ret);
3635                 }
3636         } else {
3637                 ErrPrint("Unsupported package\n");
3638                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3639         }
3640
3641 out:
3642         result = packet_create_reply(packet, "i", ret);
3643         if (!result) {
3644                 ErrPrint("Failed to create a reply packet\n");
3645         }
3646
3647         return result;
3648 }
3649
3650 static struct packet *client_gbar_key_focus_in(pid_t pid, int handle, const struct packet *packet)
3651 {
3652         struct client_node *client;
3653         const char *pkgname;
3654         const char *id;
3655         int ret;
3656         double timestamp;
3657         unsigned int keycode;
3658         struct inst_info *inst;
3659         const struct pkg_info *pkg;
3660         struct packet *result;
3661
3662         client = client_find_by_rpc_handle(handle);
3663         if (!client) {
3664                 ErrPrint("Client %d is not exists\n", pid);
3665                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3666                 goto out;
3667         }
3668
3669         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
3670         if (ret != 4) {
3671                 ErrPrint("Invalid parameter\n");
3672                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3673                 goto out;
3674         }
3675
3676         ret = validate_request(pkgname, id, &inst, &pkg);
3677         if (ret != DBOX_STATUS_ERROR_NONE) {
3678                 goto out;
3679         }
3680
3681         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3682                 ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3683         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3684                 struct script_info *script;
3685
3686                 script = instance_gbar_script(inst);
3687                 if (!script) {
3688                         ret = DBOX_STATUS_ERROR_FAULT;
3689                         goto out;
3690                 }
3691
3692                 script_handler_update_keycode(script, keycode);
3693                 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_IN, timestamp);
3694                 if (ret >= 0) {
3695                         ret = send_delayed_key_status(inst, ret);
3696                 }
3697         } else {
3698                 ErrPrint("Unsupported package\n");
3699                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3700         }
3701
3702 out:
3703         result = packet_create_reply(packet, "i", ret);
3704         if (!result) {
3705                 ErrPrint("Failed to create a reply packet\n");
3706         }
3707
3708         return result;
3709 }
3710
3711 static struct packet *client_gbar_key_focus_out(pid_t pid, int handle, const struct packet *packet)
3712 {
3713         struct client_node *client;
3714         const char *pkgname;
3715         const char *id;
3716         int ret;
3717         double timestamp;
3718         unsigned int keycode;
3719         struct inst_info *inst;
3720         const struct pkg_info *pkg;
3721         struct packet *result;
3722
3723         client = client_find_by_rpc_handle(handle);
3724         if (!client) {
3725                 ErrPrint("Client %d is not exists\n", pid);
3726                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3727                 goto out;
3728         }
3729
3730         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
3731         if (ret != 4) {
3732                 ErrPrint("Invalid parameter\n");
3733                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3734                 goto out;
3735         }
3736
3737         ret = validate_request(pkgname, id, &inst, &pkg);
3738         if (ret != DBOX_STATUS_ERROR_NONE) {
3739                 goto out;
3740         }
3741
3742         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3743                 ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3744         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3745                 struct script_info *script;
3746
3747                 script = instance_gbar_script(inst);
3748                 if (!script) {
3749                         ret = DBOX_STATUS_ERROR_FAULT;
3750                         goto out;
3751                 }
3752
3753                 script_handler_update_keycode(script, keycode);
3754                 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_OUT, timestamp);
3755                 if (ret >= 0) {
3756                         ret = send_delayed_key_status(inst, ret);
3757                 }
3758         } else {
3759                 ErrPrint("Unsupported package\n");
3760                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3761         }
3762
3763 out:
3764         result = packet_create_reply(packet, "i", ret);
3765         if (!result) {
3766                 ErrPrint("Failed to create a reply packet\n");
3767         }
3768
3769         return result;
3770 }
3771
3772 static struct packet *client_gbar_key_down(pid_t pid, int handle, const struct packet *packet)
3773 {
3774         struct client_node *client;
3775         const char *pkgname;
3776         const char *id;
3777         int ret;
3778         double timestamp;
3779         unsigned int keycode;
3780         struct inst_info *inst;
3781         const struct pkg_info *pkg;
3782         struct packet *result;
3783
3784         client = client_find_by_rpc_handle(handle);
3785         if (!client) {
3786                 ErrPrint("Client %d is not exists\n", pid);
3787                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3788                 goto out;
3789         }
3790
3791         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
3792         if (ret != 4) {
3793                 ErrPrint("Invalid parameter\n");
3794                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3795                 goto out;
3796         }
3797
3798         ret = validate_request(pkgname, id, &inst, &pkg);
3799         if (ret != DBOX_STATUS_ERROR_NONE) {
3800                 goto out;
3801         }
3802
3803         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3804                 ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3805         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3806                 struct script_info *script;
3807
3808                 script = instance_gbar_script(inst);
3809                 if (!script) {
3810                         ret = DBOX_STATUS_ERROR_FAULT;
3811                         goto out;
3812                 }
3813
3814                 script_handler_update_keycode(script, keycode);
3815                 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
3816                 if (ret >= 0) {
3817                         ret = send_delayed_key_status(inst, ret);
3818                 }
3819         } else {
3820                 ErrPrint("Unsupported package\n");
3821                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3822         }
3823
3824 out:
3825         result = packet_create_reply(packet, "i", ret);
3826         if (!result) {
3827                 ErrPrint("Failed to create a reply packet\n");
3828         }
3829
3830         return result;
3831 }
3832
3833 static struct packet *client_pause_request(pid_t pid, int handle, const struct packet *packet)
3834 {
3835         struct client_node *client;
3836         double timestamp;
3837         int ret;
3838
3839         client = client_find_by_rpc_handle(handle);
3840         if (!client) {
3841                 ErrPrint("Client %d is paused - manually reported\n", pid);
3842                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3843                 goto out;
3844         }
3845
3846         ret = packet_get(packet, "d", &timestamp);
3847         if (ret != 1) {
3848                 ErrPrint("Invalid parameter\n");
3849                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3850                 goto out;
3851         }
3852
3853         if (DYNAMICBOX_CONF_USE_XMONITOR) {
3854                 DbgPrint("XMONITOR enabled. ignore client paused request\n");
3855         } else {
3856                 xmonitor_pause(client);
3857         }
3858
3859 out:
3860         return NULL;
3861 }
3862
3863 static struct packet *client_resume_request(pid_t pid, int handle, const struct packet *packet)
3864 {
3865         struct client_node *client;
3866         double timestamp;
3867         int ret;
3868
3869         client = client_find_by_rpc_handle(handle);
3870         if (!client) {
3871                 ErrPrint("Client %d is not exists\n", pid);
3872                 goto out;
3873         }
3874
3875         ret = packet_get(packet, "d", &timestamp);
3876         if (ret != 1) {
3877                 ErrPrint("Invalid parameter\n");
3878                 goto out;
3879         }
3880
3881         if (DYNAMICBOX_CONF_USE_XMONITOR) {
3882                 DbgPrint("XMONITOR enabled. ignore client resumed request\n");
3883         } else {
3884                 xmonitor_resume(client);
3885         }
3886
3887 out:
3888         return NULL;
3889 }
3890
3891 static struct packet *client_gbar_key_up(pid_t pid, int handle, const struct packet *packet)
3892 {
3893         struct client_node *client;
3894         const char *pkgname;
3895         const char *id;
3896         int ret;
3897         double timestamp;
3898         unsigned int keycode;
3899         struct inst_info *inst;
3900         const struct pkg_info *pkg;
3901         struct packet *result;
3902
3903         client = client_find_by_rpc_handle(handle);
3904         if (!client) {
3905                 ErrPrint("Client %d is not exists\n", pid);
3906                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3907                 goto out;
3908         }
3909
3910         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
3911         if (ret != 4) {
3912                 ErrPrint("Invalid parameter\n");
3913                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3914                 goto out;
3915         }
3916
3917         ret = validate_request(pkgname, id, &inst, &pkg);
3918         if (ret != DBOX_STATUS_ERROR_NONE) {
3919                 goto out;
3920         }
3921
3922         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3923                 ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3924         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3925                 struct script_info *script;
3926
3927                 script = instance_gbar_script(inst);
3928                 if (!script) {
3929                         ret = DBOX_STATUS_ERROR_FAULT;
3930                         goto out;
3931                 }
3932
3933                 script_handler_update_keycode(script, keycode);
3934                 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp);
3935                 if (ret >= 0) {
3936                         ret = send_delayed_key_status(inst, ret);
3937                 }
3938         } else {
3939                 ErrPrint("Unsupported package\n");
3940                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3941         }
3942
3943 out:
3944         result = packet_create_reply(packet, "i", ret);
3945         if (!result) {
3946                 ErrPrint("Failed to create a reply packet\n");
3947         }
3948
3949         return result;
3950 }
3951
3952 static struct packet *client_dbox_access_hl(pid_t pid, int handle, const struct packet *packet)
3953 {
3954         struct packet *result;
3955         struct client_node *client;
3956         const char *pkgname;
3957         const char *id;
3958         int ret;
3959         double timestamp;
3960         struct access_info event;
3961         struct inst_info *inst = NULL;
3962         const struct pkg_info *pkg = NULL;
3963
3964         client = client_find_by_rpc_handle(handle);
3965         if (!client) {
3966                 ErrPrint("Client %d is not exists\n", pid);
3967                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3968                 goto out;
3969         }
3970
3971         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
3972         if (ret != 6) {
3973                 ErrPrint("Parameter is not matched\n");
3974                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3975                 goto out;
3976         }
3977
3978         ret = validate_request(pkgname, id, &inst, &pkg);
3979         if (ret != DBOX_STATUS_ERROR_NONE) {
3980                 goto out;
3981         }
3982
3983         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
3984                 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3985         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
3986                 struct script_info *script;
3987                 int type;
3988
3989                 script = instance_dbox_script(inst);
3990                 if (!script) {
3991                         ret = DBOX_STATUS_ERROR_FAULT;
3992                         goto out;
3993                 }
3994
3995                 switch (event.type) {
3996                 case ACCESS_TYPE_CUR:
3997                         type = DBOX_SCRIPT_ACCESS_HIGHLIGHT;
3998                         break;
3999                 case ACCESS_TYPE_NEXT:
4000                         type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_NEXT;
4001                         break;
4002                 case ACCESS_TYPE_PREV:
4003                         type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_PREV;
4004                         break;
4005                 case ACCESS_TYPE_OFF:
4006                         type = DBOX_SCRIPT_ACCESS_UNHIGHLIGHT;
4007                         break;
4008                 default:
4009                         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4010                         goto out;
4011                 }
4012
4013                 script_handler_update_pointer(script, event.x, event.y, event.type);
4014                 ret = script_handler_feed_event(script, type, timestamp);
4015                 if (ret >= 0) {
4016                         ret = send_delayed_access_status(inst, ret);
4017                 }
4018         } else {
4019                 ErrPrint("Unsupported package\n");
4020                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4021         }
4022
4023 out:
4024         result = packet_create_reply(packet, "i", ret);
4025         if (!result) {
4026                 ErrPrint("Failed to create a reply packet\n");
4027         }
4028
4029         return result;
4030 }
4031
4032 static struct packet *client_dbox_access_action(pid_t pid, int handle, const struct packet *packet)
4033 {
4034         struct packet *result;
4035         struct client_node *client;
4036         const char *pkgname;
4037         const char *id;
4038         int ret;
4039         double timestamp;
4040         struct inst_info *inst = NULL;
4041         const struct pkg_info *pkg = NULL;
4042         struct access_info event;
4043
4044         client = client_find_by_rpc_handle(handle);
4045         if (!client) {
4046                 ErrPrint("Client %d is not exist\n", pid);
4047                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4048                 goto out;
4049         }
4050
4051         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
4052         if (ret != 6) {
4053                 ErrPrint("Parameter is not matched\n");
4054                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4055                 goto out;
4056         }
4057
4058         ret = validate_request(pkgname, id, &inst, &pkg);
4059         if (ret != DBOX_STATUS_ERROR_NONE) {
4060                 goto out;
4061         }
4062
4063         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4064                 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4065                 /*!
4066                  * Enen if it fails to send packet,
4067                  * The packet will be unref'd
4068                  * So we don't need to check the ret value.
4069                  */
4070         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4071                 struct script_info *script;
4072
4073                 script = instance_dbox_script(inst);
4074                 if (!script) {
4075                         ErrPrint("Instance has no script\n");
4076                         ret = DBOX_STATUS_ERROR_FAULT;
4077                         goto out;
4078                 }
4079
4080                 script_handler_update_pointer(script, event.x, event.y, event.type);
4081                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTION, timestamp);
4082                 if (ret >= 0) {
4083                         ret = send_delayed_access_status(inst, ret);
4084                 }
4085         } else {
4086                 ErrPrint("Unsupported package\n");
4087                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4088         }
4089
4090 out:
4091         result = packet_create_reply(packet, "i", ret);
4092         if (!result) {
4093                 ErrPrint("Failed to create a reply packet\n");
4094         }
4095
4096         return result;
4097 }
4098
4099 static struct packet *client_dbox_access_scroll(pid_t pid, int handle, const struct packet *packet)
4100 {
4101         struct packet *result;
4102         struct client_node *client;
4103         const char *pkgname;
4104         const char *id;
4105         int ret;
4106         double timestamp;
4107         struct inst_info *inst = NULL;
4108         const struct pkg_info *pkg = NULL;
4109         struct access_info event;
4110
4111         client = client_find_by_rpc_handle(handle);
4112         if (!client) {
4113                 ErrPrint("Client %d is not exist\n", pid);
4114                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4115                 goto out;
4116         }
4117
4118         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
4119         if (ret != 6) {
4120                 ErrPrint("Parameter is not matched\n");
4121                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4122                 goto out;
4123         }
4124
4125         ret = validate_request(pkgname, id, &inst, &pkg);
4126         if (ret != DBOX_STATUS_ERROR_NONE) {
4127                 goto out;
4128         }
4129
4130         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4131                 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4132                 /*!
4133                  * Enen if it fails to send packet,
4134                  * The packet will be unref'd
4135                  * So we don't need to check the ret value.
4136                  */
4137         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4138                 struct script_info *script;
4139
4140                 script = instance_dbox_script(inst);
4141                 if (!script) {
4142                         ErrPrint("Instance has no script\n");
4143                         ret = DBOX_STATUS_ERROR_FAULT;
4144                         goto out;
4145                 }
4146
4147                 script_handler_update_pointer(script, event.x, event.y, event.type);
4148                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_SCROLL, timestamp);
4149                 if (ret >= 0) {
4150                         ret = send_delayed_access_status(inst, ret);
4151                 }
4152         } else {
4153                 ErrPrint("Unsupported package\n");
4154                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4155         }
4156
4157 out:
4158         result = packet_create_reply(packet, "i", ret);
4159         if (!result) {
4160                 ErrPrint("Failed to create a reply packet\n");
4161         }
4162
4163         return result;
4164 }
4165
4166 static struct packet *client_dbox_access_value_change(pid_t pid, int handle, const struct packet *packet)
4167 {
4168         struct packet *result;
4169         struct client_node *client;
4170         const char *pkgname;
4171         const char *id;
4172         int ret;
4173         double timestamp;
4174         struct inst_info *inst = NULL;
4175         const struct pkg_info *pkg = NULL;
4176         struct access_info event;
4177
4178         client = client_find_by_rpc_handle(handle);
4179         if (!client) {
4180                 ErrPrint("Client %d is not exist\n", pid);
4181                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4182                 goto out;
4183         }
4184
4185         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
4186         if (ret != 6) {
4187                 ErrPrint("Parameter is not matched\n");
4188                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4189                 goto out;
4190         }
4191
4192         ret = validate_request(pkgname, id, &inst, &pkg);
4193         if (ret != DBOX_STATUS_ERROR_NONE) {
4194                 goto out;
4195         }
4196
4197         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4198                 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4199                 /*!
4200                  * Enen if it fails to send packet,
4201                  * The packet will be unref'd
4202                  * So we don't need to check the ret value.
4203                  */
4204         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4205                 struct script_info *script;
4206
4207                 script = instance_dbox_script(inst);
4208                 if (!script) {
4209                         ErrPrint("Instance has no script\n");
4210                         ret = DBOX_STATUS_ERROR_FAULT;
4211                         goto out;
4212                 }
4213
4214                 script_handler_update_pointer(script, event.x, event.y, event.type);
4215                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_VALUE_CHANGE, timestamp);
4216                 if (ret >= 0) {
4217                         ret = send_delayed_access_status(inst, ret);
4218                 }
4219         } else {
4220                 ErrPrint("Unsupported package\n");
4221                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4222         }
4223
4224 out:
4225         result = packet_create_reply(packet, "i", ret);
4226         if (!result) {
4227                 ErrPrint("Failed to create a reply packet\n");
4228         }
4229
4230         return result;
4231 }
4232
4233 static struct packet *client_dbox_access_mouse(pid_t pid, int handle, const struct packet *packet)
4234 {
4235         struct packet *result;
4236         struct client_node *client;
4237         const char *pkgname;
4238         const char *id;
4239         int ret;
4240         double timestamp;
4241         struct inst_info *inst = NULL;
4242         const struct pkg_info *pkg = NULL;
4243         struct access_info event;
4244
4245         client = client_find_by_rpc_handle(handle);
4246         if (!client) {
4247                 ErrPrint("Client %d is not exist\n", pid);
4248                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4249                 goto out;
4250         }
4251
4252         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
4253         if (ret != 6) {
4254                 ErrPrint("Parameter is not matched\n");
4255                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4256                 goto out;
4257         }
4258
4259         ret = validate_request(pkgname, id, &inst, &pkg);
4260         if (ret != DBOX_STATUS_ERROR_NONE) {
4261                 goto out;
4262         }
4263
4264         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4265                 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4266                 /*!
4267                  * Enen if it fails to send packet,
4268                  * The packet will be unref'd
4269                  * So we don't need to check the ret value.
4270                  */
4271         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4272                 struct script_info *script;
4273
4274                 script = instance_dbox_script(inst);
4275                 if (!script) {
4276                         ErrPrint("Instance has no script\n");
4277                         ret = DBOX_STATUS_ERROR_FAULT;
4278                         goto out;
4279                 }
4280
4281                 script_handler_update_pointer(script, event.x, event.y, event.type);
4282                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_MOUSE, timestamp);
4283                 if (ret >= 0) {
4284                         ret = send_delayed_access_status(inst, ret);
4285                 }
4286         } else {
4287                 ErrPrint("Unsupported package\n");
4288                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4289         }
4290
4291 out:
4292         result = packet_create_reply(packet, "i", ret);
4293         if (!result) {
4294                 ErrPrint("Failed to create a reply packet\n");
4295         }
4296
4297         return result;
4298 }
4299
4300 static struct packet *client_dbox_access_back(pid_t pid, int handle, const struct packet *packet)
4301 {
4302         struct packet *result;
4303         struct client_node *client;
4304         const char *pkgname;
4305         const char *id;
4306         int ret;
4307         double timestamp;
4308         struct inst_info *inst = NULL;
4309         const struct pkg_info *pkg = NULL;
4310         struct access_info event;
4311
4312         client = client_find_by_rpc_handle(handle);
4313         if (!client) {
4314                 ErrPrint("Client %d is not exist\n", pid);
4315                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4316                 goto out;
4317         }
4318
4319         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
4320         if (ret != 6) {
4321                 ErrPrint("Parameter is not matched\n");
4322                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4323                 goto out;
4324         }
4325
4326         ret = validate_request(pkgname, id, &inst, &pkg);
4327         if (ret != DBOX_STATUS_ERROR_NONE) {
4328                 goto out;
4329         }
4330
4331         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4332                 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4333                 /*!
4334                  * Enen if it fails to send packet,
4335                  * The packet will be unref'd
4336                  * So we don't need to check the ret value.
4337                  */
4338         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4339                 struct script_info *script;
4340
4341                 script = instance_dbox_script(inst);
4342                 if (!script) {
4343                         ErrPrint("Instance has no script\n");
4344                         ret = DBOX_STATUS_ERROR_FAULT;
4345                         goto out;
4346                 }
4347
4348                 script_handler_update_pointer(script, event.x, event.y, event.type);
4349                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_BACK, timestamp);
4350                 if (ret >= 0) {
4351                         ret = send_delayed_access_status(inst, ret);
4352                 }
4353         } else {
4354                 ErrPrint("Unsupported package\n");
4355                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4356         }
4357
4358 out:
4359         result = packet_create_reply(packet, "i", ret);
4360         if (!result) {
4361                 ErrPrint("Failed to create a reply packet\n");
4362         }
4363
4364         return result;
4365 }
4366
4367 static struct packet *client_dbox_access_over(pid_t pid, int handle, const struct packet *packet)
4368 {
4369         struct packet *result;
4370         struct client_node *client;
4371         const char *pkgname;
4372         const char *id;
4373         int ret;
4374         double timestamp;
4375         struct inst_info *inst = NULL;
4376         const struct pkg_info *pkg = NULL;
4377         struct access_info event;
4378
4379         client = client_find_by_rpc_handle(handle);
4380         if (!client) {
4381                 ErrPrint("Client %d is not exist\n", pid);
4382                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4383                 goto out;
4384         }
4385
4386         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
4387         if (ret != 6) {
4388                 ErrPrint("Parameter is not matched\n");
4389                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4390                 goto out;
4391         }
4392
4393         ret = validate_request(pkgname, id, &inst, &pkg);
4394         if (ret != DBOX_STATUS_ERROR_NONE) {
4395                 goto out;
4396         }
4397
4398         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4399                 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4400                 /*!
4401                  * Enen if it fails to send packet,
4402                  * The packet will be unref'd
4403                  * So we don't need to check the ret value.
4404                  */
4405         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4406                 struct script_info *script;
4407
4408                 script = instance_dbox_script(inst);
4409                 if (!script) {
4410                         ErrPrint("Instance has no script\n");
4411                         ret = DBOX_STATUS_ERROR_FAULT;
4412                         goto out;
4413                 }
4414
4415                 script_handler_update_pointer(script, event.x, event.y, event.type);
4416                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_OVER, timestamp);
4417                 if (ret >= 0) {
4418                         ret = send_delayed_access_status(inst, ret);
4419                 }
4420         } else {
4421                 ErrPrint("Unsupported package\n");
4422                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4423         }
4424
4425 out:
4426         result = packet_create_reply(packet, "i", ret);
4427         if (!result) {
4428                 ErrPrint("Failed to create a reply packet\n");
4429         }
4430
4431         return result;
4432 }
4433
4434 static struct packet *client_dbox_access_read(pid_t pid, int handle, const struct packet *packet)
4435 {
4436         struct packet *result;
4437         struct client_node *client;
4438         const char *pkgname;
4439         const char *id;
4440         int ret;
4441         double timestamp;
4442         struct inst_info *inst = NULL;
4443         const struct pkg_info *pkg = NULL;
4444         struct access_info event;
4445
4446         client = client_find_by_rpc_handle(handle);
4447         if (!client) {
4448                 ErrPrint("Client %d is not exist\n", pid);
4449                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4450                 goto out;
4451         }
4452
4453         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
4454         if (ret != 6) {
4455                 ErrPrint("Parameter is not matched\n");
4456                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4457                 goto out;
4458         }
4459
4460         ret = validate_request(pkgname, id, &inst, &pkg);
4461         if (ret != DBOX_STATUS_ERROR_NONE) {
4462                 goto out;
4463         }
4464
4465         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4466                 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4467                 /*!
4468                  * Enen if it fails to send packet,
4469                  * The packet will be unref'd
4470                  * So we don't need to check the ret value.
4471                  */
4472         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4473                 struct script_info *script;
4474
4475                 script = instance_dbox_script(inst);
4476                 if (!script) {
4477                         ErrPrint("Instance has no script\n");
4478                         ret = DBOX_STATUS_ERROR_FAULT;
4479                         goto out;
4480                 }
4481
4482                 script_handler_update_pointer(script, event.x, event.y, event.type);
4483                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_READ, timestamp);
4484                 if (ret >= 0) {
4485                         ret = send_delayed_access_status(inst, ret);
4486                 }
4487         } else {
4488                 ErrPrint("Unsupported package\n");
4489                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4490         }
4491
4492 out:
4493         result = packet_create_reply(packet, "i", ret);
4494         if (!result) {
4495                 ErrPrint("Failed to create a reply packet\n");
4496         }
4497
4498         return result;
4499 }
4500
4501 static struct packet *client_dbox_access_enable(pid_t pid, int handle, const struct packet *packet)
4502 {
4503         struct packet *result;
4504         struct client_node *client;
4505         const char *pkgname;
4506         const char *id;
4507         int ret;
4508         double timestamp;
4509         struct inst_info *inst = NULL;
4510         const struct pkg_info *pkg = NULL;
4511         struct access_info event;
4512
4513         client = client_find_by_rpc_handle(handle);
4514         if (!client) {
4515                 ErrPrint("Client %d is not exist\n", pid);
4516                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4517                 goto out;
4518         }
4519
4520         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
4521         if (ret != 6) {
4522                 ErrPrint("Parameter is not matched\n");
4523                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4524                 goto out;
4525         }
4526
4527         ret = validate_request(pkgname, id, &inst, &pkg);
4528         if (ret != DBOX_STATUS_ERROR_NONE) {
4529                 goto out;
4530         }
4531
4532         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4533                 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4534                 /*!
4535                  * Enen if it fails to send packet,
4536                  * The packet will be unref'd
4537                  * So we don't need to check the ret value.
4538                  */
4539         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4540                 struct script_info *script;
4541                 int type;
4542
4543                 script = instance_dbox_script(inst);
4544                 if (!script) {
4545                         ErrPrint("Instance has no script\n");
4546                         ret = DBOX_STATUS_ERROR_FAULT;
4547                         goto out;
4548                 }
4549
4550                 type = (event.type == 0) ? DBOX_SCRIPT_ACCESS_DISABLE : DBOX_SCRIPT_ACCESS_ENABLE;
4551
4552                 script_handler_update_pointer(script, event.x, event.y, event.type);
4553                 ret = script_handler_feed_event(script, type, timestamp);
4554                 if (ret >= 0) {
4555                         ret = send_delayed_access_status(inst, ret);
4556                 }
4557         } else {
4558                 ErrPrint("Unsupported package\n");
4559                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4560         }
4561
4562 out:
4563         result = packet_create_reply(packet, "i", ret);
4564         if (!result) {
4565                 ErrPrint("Failed to create a reply packet\n");
4566         }
4567
4568         return result;
4569 }
4570
4571 static struct packet *client_dbox_access_activate(pid_t pid, int handle, const struct packet *packet)
4572 {
4573         struct packet *result;
4574         struct client_node *client;
4575         const char *pkgname;
4576         const char *id;
4577         int ret;
4578         double timestamp;
4579         struct access_info event;
4580         struct inst_info *inst = NULL;
4581         const struct pkg_info *pkg = NULL;
4582
4583         client = client_find_by_rpc_handle(handle);
4584         if (!client) {
4585                 ErrPrint("Client %d is not exists\n", pid);
4586                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4587                 goto out;
4588         }
4589
4590         ret = packet_get(packet, "ssdiii", &pkgname, &id, &timestamp, &event.x, &event.y, &event.type);
4591         if (ret != 6) {
4592                 ErrPrint("Parameter is not matched\n");
4593                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4594                 goto out;
4595         }
4596
4597         ret = validate_request(pkgname, id, &inst, &pkg);
4598         if (ret != DBOX_STATUS_ERROR_NONE) {
4599                 goto out;
4600         }
4601
4602         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4603                 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4604         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4605                 struct script_info *script;
4606
4607                 script = instance_dbox_script(inst);
4608                 if (!script) {
4609                         ErrPrint("Instance has no script\n");
4610                         ret = DBOX_STATUS_ERROR_FAULT;
4611                         goto out;
4612                 }
4613
4614                 script_handler_update_pointer(script, event.x, event.y, event.type);
4615                 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTIVATE, timestamp);
4616                 if (ret >= 0) {
4617                         ret = send_delayed_access_status(inst, ret);
4618                 }
4619         } else {
4620                 ErrPrint("Unsupported package\n");
4621                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4622         }
4623
4624 out:
4625         result = packet_create_reply(packet, "i", ret);
4626         if (!result) {
4627                 ErrPrint("Failed to create a reply packet\n");
4628         }
4629
4630         return result;
4631 }
4632
4633 static struct packet *client_dbox_key_down(pid_t pid, int handle, const struct packet *packet)
4634 {
4635         struct client_node *client;
4636         const char *pkgname;
4637         const char *id;
4638         int ret;
4639         double timestamp;
4640         unsigned int keycode;
4641         struct inst_info *inst;
4642         const struct pkg_info *pkg;
4643         struct packet *result;
4644
4645         client = client_find_by_rpc_handle(handle);
4646         if (!client) {
4647                 ErrPrint("Client %d is not exists\n", pid);
4648                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4649                 goto out;
4650         }
4651
4652         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
4653         if (ret != 4) {
4654                 ErrPrint("Parameter is not matched\n");
4655                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4656                 goto out;
4657         }
4658
4659         ret = validate_request(pkgname, id, &inst, &pkg);
4660         if (ret != DBOX_STATUS_ERROR_NONE) {
4661                 goto out;
4662         }
4663
4664         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4665                 ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4666         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4667                 struct script_info *script;
4668
4669                 script = instance_dbox_script(inst);
4670                 if (!script) {
4671                         ret = DBOX_STATUS_ERROR_FAULT;
4672                         goto out;
4673                 }
4674
4675                 script_handler_update_keycode(script, keycode);
4676                 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
4677                 if (ret >= 0) {
4678                         ret = send_delayed_key_status(inst, ret);
4679                 }
4680         } else {
4681                 ErrPrint("Unsupported package\n");
4682                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4683         }
4684
4685 out:
4686         result = packet_create_reply(packet, "i", ret);
4687         if (!result) {
4688                 ErrPrint("Failed to create a reply packet\n");
4689         }
4690
4691         return result;
4692 }
4693
4694 static struct packet *client_dbox_key_focus_in(pid_t pid, int handle, const struct packet *packet)
4695 {
4696         struct client_node *client;
4697         const char *pkgname;
4698         const char *id;
4699         int ret;
4700         double timestamp;
4701         unsigned int keycode;
4702         struct inst_info *inst;
4703         const struct pkg_info *pkg;
4704         struct packet *result;
4705
4706         client = client_find_by_rpc_handle(handle);
4707         if (!client) {
4708                 ErrPrint("Client %d is not exists\n", pid);
4709                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4710                 goto out;
4711         }
4712
4713         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
4714         if (ret != 4) {
4715                 ErrPrint("Parameter is not matched\n");
4716                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4717                 goto out;
4718         }
4719
4720         ret = validate_request(pkgname, id, &inst, &pkg);
4721         if (ret != DBOX_STATUS_ERROR_NONE) {
4722                 goto out;
4723         }
4724
4725         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4726                 ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4727         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4728                 struct script_info *script;
4729
4730                 script = instance_dbox_script(inst);
4731                 if (!script) {
4732                         ret = DBOX_STATUS_ERROR_FAULT;
4733                         goto out;
4734                 }
4735
4736                 script_handler_update_keycode(script, keycode);
4737                 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_IN, timestamp);
4738                 if (ret >= 0) {
4739                         ret = send_delayed_key_status(inst, ret);
4740                 }
4741         } else {
4742                 ErrPrint("Unsupported package\n");
4743                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4744         }
4745
4746 out:
4747         result = packet_create_reply(packet, "i", ret);
4748         if (!result) {
4749                 ErrPrint("Failed to create a reply packet\n");
4750         }
4751
4752         return result;
4753 }
4754
4755 static struct packet *client_dbox_key_focus_out(pid_t pid, int handle, const struct packet *packet)
4756 {
4757         struct client_node *client;
4758         const char *pkgname;
4759         const char *id;
4760         int ret;
4761         double timestamp;
4762         unsigned int keycode;
4763         struct inst_info *inst;
4764         const struct pkg_info *pkg;
4765         struct packet *result;
4766
4767         client = client_find_by_rpc_handle(handle);
4768         if (!client) {
4769                 ErrPrint("Client %d is not exists\n", pid);
4770                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4771                 goto out;
4772         }
4773
4774         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
4775         if (ret != 4) {
4776                 ErrPrint("Parameter is not matched\n");
4777                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4778                 goto out;
4779         }
4780
4781         ret = validate_request(pkgname, id, &inst, &pkg);
4782         if (ret != DBOX_STATUS_ERROR_NONE) {
4783                 goto out;
4784         }
4785
4786         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4787                 ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4788         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4789                 struct script_info *script;
4790
4791                 script = instance_dbox_script(inst);
4792                 if (!script) {
4793                         ret = DBOX_STATUS_ERROR_FAULT;
4794                         goto out;
4795                 }
4796
4797                 script_handler_update_keycode(script, keycode);
4798                 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_OUT, timestamp);
4799                 if (ret >= 0) {
4800                         ret = send_delayed_key_status(inst, ret);
4801                 }
4802         } else {
4803                 ErrPrint("Unsupported package\n");
4804                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4805         }
4806
4807 out:
4808         result = packet_create_reply(packet, "i", ret);
4809         if (!result) {
4810                 ErrPrint("Failed to create a reply packet\n");
4811         }
4812
4813         return result;
4814 }
4815
4816 static struct packet *client_dbox_key_up(pid_t pid, int handle, const struct packet *packet)
4817 {
4818         struct client_node *client;
4819         const char *pkgname;
4820         const char *id;
4821         int ret;
4822         double timestamp;
4823         unsigned int keycode;
4824         struct inst_info *inst;
4825         const struct pkg_info *pkg;
4826         struct packet *result;
4827
4828         client = client_find_by_rpc_handle(handle);
4829         if (!client) {
4830                 ErrPrint("Client %d is not exists\n", pid);
4831                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4832                 goto out;
4833         }
4834
4835         ret = packet_get(packet, "ssdi", &pkgname, &id, &timestamp, &keycode);
4836         if (ret != 4) {
4837                 ErrPrint("Parameter is not matched\n");
4838                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4839                 goto out;
4840         }
4841
4842         ret = validate_request(pkgname, id, &inst, &pkg);
4843         if (ret != DBOX_STATUS_ERROR_NONE) {
4844                 goto out;
4845         }
4846
4847         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4848                 ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4849         } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4850                 struct script_info *script;
4851
4852                 script = instance_dbox_script(inst);
4853                 if (!script) {
4854                         ret = DBOX_STATUS_ERROR_FAULT;
4855                         goto out;
4856                 }
4857
4858                 script_handler_update_keycode(script, keycode);
4859                 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp);
4860                 if (ret >= 0) {
4861                         ret = send_delayed_key_status(inst, ret);
4862                 }
4863         } else {
4864                 ErrPrint("Unsupported package\n");
4865                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4866         }
4867
4868 out:
4869         result = packet_create_reply(packet, "i", ret);
4870         if (!result) {
4871                 ErrPrint("Failed to create a reply packet\n");
4872         }
4873
4874         return result;
4875 }
4876
4877 static int release_pixmap_cb(struct client_node *client, void *canvas)
4878 {
4879         DbgPrint("Forcely unref the \"buffer\"\n");
4880         buffer_handler_pixmap_unref(canvas);
4881         return -1; /* Delete this callback */
4882 }
4883
4884
4885 static struct packet *client_dbox_acquire_xpixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
4886 {
4887         struct packet *result;
4888         const char *pkgname;
4889         const char *id;
4890         struct client_node *client;
4891         struct inst_info *inst;
4892         int ret;
4893         int pixmap = 0;
4894         void *buf_ptr;
4895         struct buffer_info *buffer;
4896         int idx;
4897
4898         client = client_find_by_rpc_handle(handle);
4899         if (!client) {
4900                 ErrPrint("Client %d is not exists\n", pid);
4901                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4902                 goto out;
4903         }
4904
4905         ret = packet_get(packet, "ssi", &pkgname, &id, &idx);
4906         if (ret != 3) {
4907                 ErrPrint("Parameter is not matched\n");
4908                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4909                 goto out;
4910         }
4911
4912         if (idx >= DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT || idx < 0) {
4913                 DbgPrint("Index is not valid: %d\n", idx);
4914                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4915                 goto out;
4916         }
4917
4918         ret = validate_request(pkgname, id, &inst, NULL);
4919         if (ret != DBOX_STATUS_ERROR_NONE) {
4920                 goto out;
4921         }
4922
4923         buffer = instance_dbox_extra_buffer(inst, idx);
4924         if (!buffer) {
4925                 ErrPrint("Extra buffer for %d is not available\n", idx);
4926                 goto out;
4927         }
4928
4929         buf_ptr = buffer_handler_pixmap_ref(buffer);
4930         if (!buf_ptr) {
4931                 ErrPrint("Failed to ref pixmap\n");
4932                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4933                 goto out;
4934         }
4935
4936         ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
4937         if (ret < 0) {
4938                 ErrPrint("Failed to add a new client deactivate callback\n");
4939                 buffer_handler_pixmap_unref(buf_ptr);
4940         } else {
4941                 pixmap = buffer_handler_pixmap(buffer);
4942                 ret = DBOX_STATUS_ERROR_NONE;
4943         }
4944
4945 out:
4946         result = packet_create_reply(packet, "ii", pixmap, ret);
4947         if (!result) {
4948                 ErrPrint("Failed to create a reply packet\n");
4949         }
4950
4951         return result;
4952 }
4953
4954 static struct packet *client_dbox_acquire_pixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
4955 {
4956         struct packet *result;
4957         const char *pkgname;
4958         const char *id;
4959         struct client_node *client;
4960         struct inst_info *inst;
4961         int ret;
4962         int pixmap = 0;
4963         void *buf_ptr;
4964         struct buffer_info *buffer;
4965
4966         client = client_find_by_rpc_handle(handle);
4967         if (!client) {
4968                 ErrPrint("Client %d is not exists\n", pid);
4969                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4970                 goto out;
4971         }
4972
4973         ret = packet_get(packet, "ss", &pkgname, &id);
4974         if (ret != 2) {
4975                 ErrPrint("Parameter is not matched\n");
4976                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4977                 goto out;
4978         }
4979
4980         ret = validate_request(pkgname, id, &inst, NULL);
4981         if (ret != DBOX_STATUS_ERROR_NONE) {
4982                 goto out;
4983         }
4984
4985         buffer = instance_dbox_buffer(inst);
4986         if (!buffer) {
4987                 struct script_info *script_info;
4988
4989                 script_info = instance_dbox_script(inst);
4990                 if (!script_info) {
4991                         ErrPrint("Unable to get DBOX buffer: %s\n", id);
4992                         ret = DBOX_STATUS_ERROR_FAULT;
4993                         goto out;
4994                 }
4995
4996                 buffer = script_handler_buffer_info(script_info);
4997                 if (!buffer) {
4998                         ErrPrint("Unable to get buffer_info: %s\n", id);
4999                         ret = DBOX_STATUS_ERROR_FAULT;
5000                         goto out;
5001                 }
5002         }
5003
5004         buf_ptr = buffer_handler_pixmap_ref(buffer);
5005         if (!buf_ptr) {
5006                 ErrPrint("Failed to ref pixmap\n");
5007                 ret = DBOX_STATUS_ERROR_FAULT;
5008                 goto out;
5009         }
5010
5011         ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
5012         if (ret < 0) {
5013                 ErrPrint("Failed to add a new client deactivate callback\n");
5014                 buffer_handler_pixmap_unref(buf_ptr);
5015         } else {
5016                 pixmap = buffer_handler_pixmap(buffer);
5017                 ret = DBOX_STATUS_ERROR_NONE;
5018         }
5019
5020 out:
5021         result = packet_create_reply(packet, "ii", pixmap, ret);
5022         if (!result) {
5023                 ErrPrint("Failed to create a reply packet\n");
5024         }
5025
5026         return result;
5027 }
5028
5029 static struct packet *client_dbox_release_pixmap(pid_t pid, int handle, const struct packet *packet)
5030 {
5031         const char *pkgname;
5032         const char *id;
5033         struct client_node *client;
5034         int pixmap;
5035         void *buf_ptr;
5036         int ret;
5037
5038         client = client_find_by_rpc_handle(handle);
5039         if (!client) {
5040                 ErrPrint("Client %d is not exists\n", pid);
5041                 goto out;
5042         }
5043
5044         ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
5045         if (ret != 3) {
5046                 ErrPrint("Parameter is not matched\n");
5047                 goto out;
5048         }
5049
5050         ret = validate_request(pkgname, id, NULL, NULL);
5051         if (ret != DBOX_STATUS_ERROR_NONE) {
5052                 DbgPrint("It seems that the instance is already deleted: %s\n", id);
5053         }
5054
5055         buf_ptr = buffer_handler_pixmap_find(pixmap);
5056         if (!buf_ptr) {
5057                 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
5058                 goto out;
5059         }
5060
5061         if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) {
5062                 buffer_handler_pixmap_unref(buf_ptr);
5063         }
5064
5065 out:
5066         /**
5067          * @note No reply packet
5068          */
5069         return NULL;
5070 }
5071
5072 static struct packet *client_gbar_acquire_xpixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
5073 {
5074         struct packet *result;
5075         const char *pkgname;
5076         const char *id;
5077         struct client_node *client;
5078         struct inst_info *inst;
5079         int ret;
5080         int pixmap = 0;
5081         void *buf_ptr;
5082         struct buffer_info *buffer;
5083         int idx;
5084
5085         client = client_find_by_rpc_handle(handle);
5086         if (!client) {
5087                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5088                 ErrPrint("Client %d is not exists\n", pid);
5089                 goto out;
5090         }
5091
5092         ret = packet_get(packet, "ssi", &pkgname, &id, &idx);
5093         if (ret != 3) {
5094                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5095                 ErrPrint("Parameter is not matched\n");
5096                 goto out;
5097         }
5098
5099         if (idx >= DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT || idx < 0) {
5100                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5101                 goto out;
5102         }
5103
5104         ret = validate_request(pkgname, id, &inst, NULL);
5105         if (ret != DBOX_STATUS_ERROR_NONE) {
5106                 goto out;
5107         }
5108
5109         buffer = instance_gbar_extra_buffer(inst, idx);
5110         if (!buffer) {
5111                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5112                 goto out;
5113         }
5114
5115         buf_ptr = buffer_handler_pixmap_ref(buffer);
5116         if (!buf_ptr) {
5117                 ErrPrint("Failed to ref pixmap\n");
5118                 ret = DBOX_STATUS_ERROR_FAULT;
5119                 goto out;
5120         }
5121
5122         ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
5123         if (ret < 0) {
5124                 ErrPrint("Failed to add a new client deactivate callback\n");
5125                 buffer_handler_pixmap_unref(buf_ptr);
5126         } else {
5127                 pixmap = buffer_handler_pixmap(buffer);
5128                 ret = DBOX_STATUS_ERROR_NONE;
5129         }
5130
5131 out:
5132         result = packet_create_reply(packet, "ii", pixmap, ret);
5133         if (!result) {
5134                 ErrPrint("Failed to create a reply packet\n");
5135         }
5136
5137         return result;
5138 }
5139
5140 static struct packet *client_gbar_acquire_pixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
5141 {
5142         struct packet *result;
5143         const char *pkgname;
5144         const char *id;
5145         struct client_node *client;
5146         struct inst_info *inst;
5147         int ret;
5148         int pixmap = 0;
5149         void *buf_ptr;
5150         struct buffer_info *buffer;
5151
5152         client = client_find_by_rpc_handle(handle);
5153         if (!client) {
5154                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5155                 ErrPrint("Client %d is not exists\n", pid);
5156                 goto out;
5157         }
5158
5159         ret = packet_get(packet, "ss", &pkgname, &id);
5160         if (ret != 2) {
5161                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5162                 ErrPrint("Parameter is not matched\n");
5163                 goto out;
5164         }
5165
5166         ret = validate_request(pkgname, id, &inst, NULL);
5167         if (ret != DBOX_STATUS_ERROR_NONE) {
5168                 goto out;
5169         }
5170
5171         if (instance_get_data(inst, GBAR_RESIZE_MONITOR_TAG)) {
5172                 ret = DBOX_STATUS_ERROR_BUSY;
5173                 goto out;
5174         }
5175
5176         buffer = instance_gbar_buffer(inst);
5177         if (!buffer) {
5178                 struct script_info *script_info;
5179
5180                 script_info = instance_gbar_script(inst);
5181                 if (!script_info) {
5182                         ErrPrint("Unable to get DBOX buffer: %s\n", id);
5183                         ret = DBOX_STATUS_ERROR_FAULT;
5184                         goto out;
5185                 }
5186
5187                 buffer = script_handler_buffer_info(script_info);
5188                 if (!buffer) {
5189                         ErrPrint("Unable to get buffer_info: %s\n", id);
5190                         ret = DBOX_STATUS_ERROR_FAULT;
5191                         goto out;
5192                 }
5193         }
5194
5195         buf_ptr = buffer_handler_pixmap_ref(buffer);
5196         if (!buf_ptr) {
5197                 ErrPrint("Failed to ref pixmap\n");
5198                 ret = DBOX_STATUS_ERROR_FAULT;
5199                 goto out;
5200         }
5201
5202         ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
5203         if (ret < 0) {
5204                 ErrPrint("Failed to add a new client deactivate callback\n");
5205                 buffer_handler_pixmap_unref(buf_ptr);
5206         } else {
5207                 pixmap = buffer_handler_pixmap(buffer);
5208                 ret = DBOX_STATUS_ERROR_NONE;
5209         }
5210
5211 out:
5212         result = packet_create_reply(packet, "ii", pixmap, ret);
5213         if (!result) {
5214                 ErrPrint("Failed to create a reply packet\n");
5215         }
5216
5217         return result;
5218 }
5219
5220 static struct packet *client_gbar_release_pixmap(pid_t pid, int handle, const struct packet *packet)
5221 {
5222         const char *pkgname;
5223         const char *id;
5224         struct client_node *client;
5225         int pixmap;
5226         void *buf_ptr;
5227         int ret;
5228
5229         client = client_find_by_rpc_handle(handle);
5230         if (!client) {
5231                 ErrPrint("Client %d is not exists\n", pid);
5232                 goto out;
5233         }
5234
5235         ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
5236         if (ret != 3) {
5237                 ErrPrint("Parameter is not matched\n");
5238                 goto out;
5239         }
5240
5241         ret = validate_request(pkgname, id, NULL, NULL);
5242         if (ret != DBOX_STATUS_ERROR_NONE) {
5243                 DbgPrint("It seems that the instance is already deleted: %s\n", id);
5244         }
5245
5246         buf_ptr = buffer_handler_pixmap_find(pixmap);
5247         if (!buf_ptr) {
5248                 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
5249                 goto out;
5250         }
5251
5252         if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) {
5253                 buffer_handler_pixmap_unref(buf_ptr);
5254         }
5255
5256 out:
5257         /*! \note No reply packet */
5258         return NULL;
5259 }
5260
5261 static struct packet *client_pinup_changed(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, pinup, ret */
5262 {
5263         struct client_node *client;
5264         struct packet *result;
5265         const char *pkgname;
5266         const char *id;
5267         int pinup;
5268         int ret;
5269         struct inst_info *inst;
5270
5271         client = client_find_by_rpc_handle(handle);
5272         if (!client) {
5273                 ErrPrint("Client %d is not exists\n", pid);
5274                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5275                 pinup = 0;
5276                 goto out;
5277         }
5278
5279         ret = packet_get(packet, "ssi", &pkgname, &id, &pinup);
5280         if (ret != 3) {
5281                 ErrPrint("Parameter is not matched\n");
5282                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5283                 pinup = 0;
5284                 goto out;
5285         }
5286
5287         ret = validate_request(pkgname, id, &inst, NULL);
5288         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
5289                 ret = instance_set_pinup(inst, pinup);
5290         }
5291
5292 out:
5293         result = packet_create_reply(packet, "i", ret);
5294         if (!result) {
5295                 ErrPrint("Failed to create a packet\n");
5296         }
5297
5298         return result;
5299 }
5300
5301 static Eina_Bool lazy_gbar_created_cb(void *inst)
5302 {
5303         struct pkg_info *pkg;
5304
5305         if (!instance_del_data(inst, LAZY_GBAR_OPEN_TAG)) {
5306                 ErrPrint("lazy,pd,open is already deleted.\n");
5307                 return ECORE_CALLBACK_CANCEL;
5308         }
5309
5310         pkg = instance_package(inst);
5311         if (pkg) {
5312                 struct slave_node *slave;
5313
5314                 slave = package_slave(pkg);
5315                 if (slave) {
5316                         slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst);
5317                 }
5318         }
5319
5320         /*!
5321          * After unref instance first,
5322          * if the instance is not destroyed, try to notify the created GBAR event to the client.
5323          */
5324         if (instance_unref(inst)) {
5325                 int ret;
5326                 ret = instance_client_gbar_created(inst, DBOX_STATUS_ERROR_NONE);
5327                 if (ret < 0) {
5328                         DbgPrint("Send GBAR Create event (%d) to client\n", ret);
5329                 }
5330         }
5331
5332         return ECORE_CALLBACK_CANCEL;
5333 }
5334
5335 static Eina_Bool lazy_gbar_destroyed_cb(void *inst)
5336 {
5337         struct pkg_info *pkg;
5338         struct slave_node *slave;
5339
5340         if (!instance_del_data(inst, LAZY_GBAR_CLOSE_TAG)) {
5341                 ErrPrint("lazy,pd,close is already deleted.\n");
5342                 return ECORE_CALLBACK_CANCEL;
5343         }
5344
5345         pkg = instance_package(inst);
5346         if (pkg) {
5347                 slave = package_slave(pkg);
5348                 if (slave) {
5349                         if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
5350                                 DbgPrint("Delete script type close callback\n");
5351                                 (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst);
5352                         } else if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
5353                                 DbgPrint("Delete buffer type close callback\n");
5354                                 (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
5355                         }
5356                 }
5357         }
5358
5359         if (instance_unref(inst)) {
5360                 int ret;
5361
5362                 /*!
5363                  * If the instance is not deleted, we should send pd-destroy event from here.
5364                  */
5365                 ret = instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE);
5366                 if (ret < 0) {
5367                         ErrPrint("Failed sending GBAR Destroy event (%d)\n", ret);
5368                 }
5369         }
5370
5371         return ECORE_CALLBACK_CANCEL;
5372 }
5373
5374 static struct packet *client_gbar_move(pid_t pid, int handle, const struct packet *packet) /* pkgname, id, x, y */
5375 {
5376         struct client_node *client;
5377         struct inst_info *inst;
5378         const struct pkg_info *pkg;
5379         const char *pkgname;
5380         const char *id;
5381         double x = 0.0f;
5382         double y = 0.0f;
5383         int ret;
5384
5385         client = client_find_by_rpc_handle(handle);
5386         if (!client) {
5387                 ErrPrint("Client %d is not exists\n", pid);
5388                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5389                 goto out;
5390         }
5391
5392         ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
5393         if (ret != 4) {
5394                 ErrPrint("Parameter is not correct\n");
5395                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5396                 goto out;
5397         }
5398
5399         ret = validate_request(pkgname, id, &inst, &pkg);
5400         if (ret != DBOX_STATUS_ERROR_NONE) {
5401                 goto out;
5402         }
5403
5404         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
5405                 instance_slave_set_gbar_pos(inst, x, y);
5406                 ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
5407         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
5408                 int ix;
5409                 int iy;
5410
5411                 instance_slave_set_gbar_pos(inst, x, y);
5412                 ix = x * instance_gbar_width(inst);
5413                 iy = y * instance_gbar_height(inst);
5414                 script_handler_update_pointer(instance_gbar_script(inst), ix, iy, 0);
5415                 ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
5416         } else {
5417                 ErrPrint("Invalid GBAR type\n");
5418                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5419         }
5420 out:
5421         DbgPrint("Update GBAR position: %d\n", ret);
5422         return NULL;
5423 }
5424
5425 static Eina_Bool gbar_open_monitor_cb(void *inst)
5426 {
5427         struct pkg_info *pkg;
5428
5429         pkg = instance_package(inst);
5430         if (pkg) {
5431                 struct slave_node *slave;
5432
5433                 slave = package_slave(pkg);
5434                 if (slave) {
5435                         slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst);
5436                 }
5437         }
5438
5439         (void)instance_slave_close_gbar(inst, instance_gbar_owner(inst), DBOX_CLOSE_GBAR_TIMEOUT);
5440         (void)instance_client_gbar_created(inst, DBOX_STATUS_ERROR_TIMEOUT);
5441         (void)instance_del_data(inst, GBAR_OPEN_MONITOR_TAG);
5442         (void)instance_unref(inst);
5443         ErrPrint("GBAR Open request is timed-out (%lf)\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT);
5444         return ECORE_CALLBACK_CANCEL;
5445 }
5446
5447 static Eina_Bool gbar_close_monitor_cb(void *inst)
5448 {
5449         struct pkg_info *pkg;
5450
5451         pkg = instance_package(inst);
5452         if (pkg) {
5453                 struct slave_node *slave;
5454
5455                 slave = package_slave(pkg);
5456                 if (slave) {
5457                         slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
5458                 }
5459         }
5460
5461         (void)instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_TIMEOUT);
5462         (void)instance_del_data(inst, GBAR_CLOSE_MONITOR_TAG);
5463         (void)instance_unref(inst);
5464         ErrPrint("GBAR Close request is not processed in %lf seconds\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT);
5465         return ECORE_CALLBACK_CANCEL;
5466 }
5467
5468 static Eina_Bool gbar_resize_monitor_cb(void *inst)
5469 {
5470         struct pkg_info *pkg;
5471
5472         pkg = instance_package(inst);
5473         if (pkg) {
5474                 struct slave_node *slave;
5475                 slave = package_slave(pkg);
5476                 if (slave) {
5477                         slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst);
5478                 }
5479         }
5480
5481         (void)instance_slave_close_gbar(inst, instance_gbar_owner(inst), DBOX_CLOSE_GBAR_TIMEOUT);
5482         (void)instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_TIMEOUT);
5483         (void)instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG);
5484         (void)instance_unref(inst);
5485         ErrPrint("GBAR Resize request is not processed in %lf seconds\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT);
5486         return ECORE_CALLBACK_CANCEL;
5487 }
5488
5489 static struct packet *client_create_gbar(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
5490 {
5491         struct client_node *client;
5492         struct packet *result;
5493         const char *pkgname;
5494         const char *id;
5495         int ret;
5496         struct inst_info *inst = NULL;
5497         const struct pkg_info *pkg = NULL;
5498         Ecore_Timer *gbar_monitor;
5499         double x;
5500         double y;
5501
5502         DbgPrint("PERF_DBOX\n");
5503
5504         client = client_find_by_rpc_handle(handle);
5505         if (!client) {
5506                 ErrPrint("Client %d is not exists\n", pid);
5507                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5508                 goto out;
5509         }
5510
5511         ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
5512         if (ret != 4) {
5513                 ErrPrint("Parameter is not matched\n");
5514                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5515                 goto out;
5516         }
5517
5518         ret = validate_request(pkgname, id, &inst, &pkg);
5519         if (ret != DBOX_STATUS_ERROR_NONE) {
5520                 goto out;
5521         }
5522
5523         if (instance_gbar_owner(inst)) {
5524                 ErrPrint("GBAR is already owned\n");
5525                 ret = DBOX_STATUS_ERROR_ALREADY;
5526         } else if (package_gbar_type(instance_package(inst)) == GBAR_TYPE_BUFFER) {
5527                 gbar_monitor = instance_get_data(inst, LAZY_GBAR_CLOSE_TAG);
5528                 if (gbar_monitor) {
5529                         ecore_timer_del(gbar_monitor);
5530                         /* This timer attribute will be deleted */
5531                         lazy_gbar_destroyed_cb(inst);
5532                 }
5533
5534                 if (instance_get_data(inst, GBAR_OPEN_MONITOR_TAG)) {
5535                         DbgPrint("GBAR Open request is already processed\n");
5536                         ret = DBOX_STATUS_ERROR_ALREADY;
5537                         goto out;
5538                 }
5539
5540                 if (instance_get_data(inst, GBAR_CLOSE_MONITOR_TAG)) {
5541                         DbgPrint("GBAR Close request is already in process\n");
5542                         ret = DBOX_STATUS_ERROR_BUSY;
5543                         goto out;
5544                 }
5545
5546                 if (instance_get_data(inst, GBAR_RESIZE_MONITOR_TAG)) {
5547                         DbgPrint("GBAR resize request is already in process\n");
5548                         ret = DBOX_STATUS_ERROR_BUSY;
5549                         goto out;
5550                 }
5551
5552                 instance_slave_set_gbar_pos(inst, x, y);
5553                 /*!
5554                  * \note
5555                  * Send request to the slave.
5556                  * The SLAVE must has to repsonse this via "release_buffer" method.
5557                  */
5558                 ret = instance_slave_open_gbar(inst, client);
5559                 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
5560                         ret = instance_signal_emit(inst, "gbar,show", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
5561                         if (ret != DBOX_STATUS_ERROR_NONE) {
5562                                 int tmp_ret;
5563
5564                                 tmp_ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_FAULT);
5565                                 if (tmp_ret < 0) {
5566                                         ErrPrint("Unable to send script event for openning GBAR [%s], %d\n", pkgname, tmp_ret);
5567                                 }
5568                         } else {
5569                                 gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_open_monitor_cb, instance_ref(inst));
5570                                 if (!gbar_monitor) {
5571                                         (void)instance_unref(inst);
5572                                         ErrPrint("Failed to create a timer for GBAR Open monitor\n");
5573                                 } else {
5574                                         struct slave_node *slave;
5575
5576                                         (void)instance_set_data(inst, GBAR_OPEN_MONITOR_TAG, gbar_monitor);
5577
5578                                         slave = package_slave(pkg);
5579                                         if (!slave) {
5580                                                 ErrPrint("Failed to get slave(%s)\n", pkgname);
5581                                                 goto out;
5582                                         }
5583
5584                                         if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) != DBOX_STATUS_ERROR_NONE) {
5585                                                 ErrPrint("Failed to add fault handler: %s\n");
5586                                         }
5587                                 }
5588                         }
5589                 } else {
5590                         ErrPrint("Unable to send request for openning GBAR [%s]\n", pkgname);
5591                 }
5592
5593                 /*!
5594                  * \note
5595                  * GBAR craeted event will be send by the acquire_buffer function.
5596                  * Because the slave will make request the acquire_buffer to
5597                  * render the GBAR
5598                  *
5599                  * instance_client_gbar_created(inst);
5600                  */
5601         } else if (package_gbar_type(instance_package(inst)) == GBAR_TYPE_SCRIPT) {
5602                 int ix;
5603                 int iy;
5604
5605                 gbar_monitor = instance_get_data(inst, LAZY_GBAR_CLOSE_TAG);
5606                 if (gbar_monitor) {
5607                         ecore_timer_del(gbar_monitor);
5608                         /* lazy,pd,close will be deleted */
5609                         lazy_gbar_destroyed_cb(inst);
5610                 }
5611
5612                 /*!
5613                  * \note
5614                  * ret value should be cared but in this case,
5615                  * we ignore this for this moment, so we have to handle this error later.
5616                  *
5617                  * if ret is less than 0, the slave has some problem.
5618                  * but the script mode doesn't need slave for rendering default view of GBAR
5619                  * so we can hanle it later.
5620                  */
5621                 instance_slave_set_gbar_pos(inst, x, y);
5622                 ix = x * instance_gbar_width(inst);
5623                 iy = y * instance_gbar_height(inst);
5624
5625                 script_handler_update_pointer(instance_gbar_script(inst), ix, iy, 0);
5626
5627                 ret = instance_slave_open_gbar(inst, client);
5628                 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
5629                         ret = script_handler_load(instance_gbar_script(inst), 1);
5630
5631                         /*!
5632                          * \note
5633                          * Send the GBAR created event to the clients,
5634                          */
5635                         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
5636
5637                                 /*!
5638                                  * \note
5639                                  * But the created event has to be send afte return
5640                                  * from this function or the viewer couldn't care
5641                                  * the event correctly.
5642                                  */
5643                                 inst = instance_ref(inst); /* To guarantee the inst */
5644
5645                                 /*!
5646                                  * \note
5647                                  * At here, we don't need to rememeber the timer object.
5648                                  * Even if the timer callback is called, after the instance is destroyed.
5649                                  * lazy_gbar_created_cb will decrease the instance refcnt first.
5650                                  * At that time, if the instance is released, the timer callback will do nothing.
5651                                  *
5652                                  * 13-05-28
5653                                  * I change my mind. There is no requirements to keep the timer handler.
5654                                  * But I just add it to the tagged-data of the instance.
5655                                  * Just reserve for future-use.
5656                                  */
5657                                 gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_created_cb, inst);
5658                                 if (!gbar_monitor) {
5659                                         ret = script_handler_unload(instance_gbar_script(inst), 1);
5660                                         ErrPrint("Unload script: %d\n", ret);
5661
5662                                         ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL);
5663                                         ErrPrint("Close GBAR %d\n", ret);
5664
5665                                         inst = instance_unref(inst);
5666                                         if (!inst) {
5667                                                 DbgPrint("Instance destroyed\n");
5668                                         }
5669
5670                                         ErrPrint("Instance: %s\n", pkgname);
5671
5672                                         ret = DBOX_STATUS_ERROR_FAULT;
5673                                 } else {
5674                                         struct slave_node *slave;
5675
5676                                         (void)instance_set_data(inst, LAZY_GBAR_OPEN_TAG, gbar_monitor);
5677
5678                                         slave = package_slave(pkg);
5679                                         if (!slave) {
5680                                                 ErrPrint("Failed to get slave: %s\n", pkgname);
5681                                                 goto out;
5682                                         }
5683
5684                                         if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst) != DBOX_STATUS_ERROR_NONE) {
5685                                                 ErrPrint("Failed to add fault callback: %s\n", pkgname);
5686                                         }
5687                                 }
5688                         } else {
5689                                 int tmp_ret;
5690                                 tmp_ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_FAULT);
5691                                 if (tmp_ret < 0) {
5692                                         ErrPrint("Unable to load script: %d, (close: %d)\n", ret, tmp_ret);
5693                                 }
5694                         }
5695                 } else {
5696                         ErrPrint("Unable open GBAR(%s): %d\n", pkgname, ret);
5697                 }
5698         } else {
5699                 ErrPrint("Invalid GBAR TYPE\n");
5700                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5701         }
5702
5703 out:
5704         result = packet_create_reply(packet, "i", ret);
5705         if (!result) {
5706                 ErrPrint("Failed to create a packet\n");
5707         }
5708
5709         return result;
5710 }
5711
5712 static struct packet *client_destroy_gbar(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
5713 {
5714         struct client_node *client;
5715         struct packet *result;
5716         const char *pkgname;
5717         const char *id;
5718         int ret;
5719         struct inst_info *inst = NULL;
5720         const struct pkg_info *pkg = NULL;
5721         Ecore_Timer *gbar_monitor;
5722         struct slave_node *slave;
5723
5724         DbgPrint("PERF_DBOX\n");
5725
5726         client = client_find_by_rpc_handle(handle);
5727         if (!client) {
5728                 ErrPrint("Client %d is not exists\n", pid);
5729                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5730                 goto out;
5731         }
5732
5733         ret = packet_get(packet, "ss", &pkgname, &id);
5734         if (ret != 2) {
5735                 ErrPrint("Parameter is not matched\n");
5736                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5737                 goto out;
5738         }
5739
5740         ret = validate_request(pkgname, id, &inst, &pkg);
5741         if (ret != DBOX_STATUS_ERROR_NONE) {
5742                 goto out;
5743         }
5744
5745         slave = package_slave(pkg);
5746         if (!slave) {
5747                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5748                 goto out;
5749         }
5750
5751         if (instance_gbar_owner(inst) != client) {
5752                 if (instance_gbar_owner(inst) == NULL) {
5753                         ErrPrint("GBAR looks already closed\n");
5754                         ret = DBOX_STATUS_ERROR_ALREADY;
5755                 } else {
5756                         ErrPrint("GBAR owner mimatched\n");
5757                         ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
5758                 }
5759         } else if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
5760                 DbgPrint("Buffer type GBAR\n");
5761                 gbar_monitor = instance_del_data(inst, GBAR_OPEN_MONITOR_TAG);
5762                 if (gbar_monitor) {
5763                         ErrPrint("GBAR Open request is found. cancel it [%s]\n", pkgname);
5764
5765                         if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) < 0) {
5766                                 DbgPrint("Failed to delete a deactivate callback\n");
5767                         }
5768
5769                         /*!
5770                          * \note
5771                          * We should return negative value
5772                          * Or we have to send "destroyed" event to the client.
5773                          * If we didn't send destroyed event after return SUCCESS from here,
5774                          * The client will permanently waiting destroyed event.
5775                          * Because they understand that the destroy request is successfully processed.
5776                          */
5777                         ret = instance_client_gbar_created(inst, DBOX_STATUS_ERROR_CANCEL);
5778                         if (ret < 0) {
5779                                 ErrPrint("GBAR client create event: %d\n", ret);
5780                         }
5781
5782                         ret = instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE);
5783                         if (ret < 0) {
5784                                 ErrPrint("GBAR client destroy event: %d\n", ret);
5785                         }
5786
5787                         ret = instance_signal_emit(inst, "gbar,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
5788                         if (ret < 0) {
5789                                 ErrPrint("GBAR close signal emit failed: %d\n", ret);
5790                         }
5791
5792                         ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL);
5793                         if (ret < 0) {
5794                                 ErrPrint("GBAR close request failed: %d\n", ret);
5795                         }
5796
5797                         ecore_timer_del(gbar_monitor);
5798                         inst = instance_unref(inst);
5799                         if (!inst) {
5800                                 DbgPrint("Instance is deleted\n");
5801                         }
5802                 } else if (instance_get_data(inst, LAZY_GBAR_CLOSE_TAG) || instance_get_data(inst, GBAR_CLOSE_MONITOR_TAG)) {
5803                         DbgPrint("Close monitor is already fired\n");
5804                         ret = DBOX_STATUS_ERROR_ALREADY;
5805                 } else {
5806                         int resize_aborted = 0;
5807
5808                         gbar_monitor = instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG);
5809                         if (gbar_monitor) {
5810                                 ErrPrint("GBAR Resize request is found. clear it [%s]\n", pkgname);
5811                                 if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) < 0) {
5812                                         DbgPrint("Failed to delete a deactivate callback\n");
5813                                 }
5814
5815                                 ecore_timer_del(gbar_monitor);
5816
5817                                 inst = instance_unref(inst);
5818                                 if (!inst) {
5819                                         DbgPrint("Instance is destroyed while resizing\n");
5820                                         goto out;
5821                                 }
5822
5823                                 resize_aborted = 1;
5824                         }
5825
5826                         ret = instance_signal_emit(inst, "gbar,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
5827                         if (ret < 0) {
5828                                 ErrPrint("GBAR close signal emit failed: %d\n", ret);
5829                         }
5830
5831                         ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL);
5832                         if (ret < 0) {
5833                                 ErrPrint("GBAR close request failed: %d\n", ret);
5834                         } else if (resize_aborted) {
5835                                 gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_destroyed_cb, instance_ref(inst));
5836                                 if (!gbar_monitor) {
5837                                         ErrPrint("Failed to create a timer: %s\n", pkgname);
5838                                         inst = instance_unref(inst);
5839                                         if (!inst) {
5840                                                 DbgPrint("Instance is deleted\n");
5841                                         }
5842                                 } else {
5843                                         DbgPrint("Resize is aborted\n");
5844                                         (void)instance_set_data(inst, LAZY_GBAR_CLOSE_TAG, gbar_monitor);
5845                                         if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) {
5846                                                 ErrPrint("Failed to add a slave event callback\n");
5847                                         }
5848                                 }
5849                         } else {
5850                                 gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_close_monitor_cb, instance_ref(inst));
5851                                 if (!gbar_monitor) {
5852                                         ErrPrint("Failed to add pd close monitor\n");
5853                                         inst = instance_unref(inst);
5854                                         if (!inst) {
5855                                                 ErrPrint("Instance is deleted while closing GBAR\n");
5856                                         }
5857                                 } else {
5858                                         DbgPrint("Add close monitor\n");
5859                                         (void)instance_set_data(inst, GBAR_CLOSE_MONITOR_TAG, gbar_monitor);
5860                                         if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) {
5861                                                 ErrPrint("Failed to add SLAVE EVENT callback\n");
5862                                         }
5863                                 }
5864                         }
5865
5866                         /*!
5867                          * \note
5868                          * release_buffer will be called by the slave after this routine.
5869                          * It will send the "gbar_destroyed" event to the client
5870                          *
5871                          * instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE);
5872                          *
5873                          * Or the "gbar_close_monitor_cb" or "lazy_gbar_destroyed_cb" will be called.
5874                          */
5875                 }
5876         } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
5877                 DbgPrint("Script TYPE GBAR\n");
5878                 gbar_monitor = instance_get_data(inst, LAZY_GBAR_OPEN_TAG);
5879                 if (gbar_monitor) {
5880                         ecore_timer_del(gbar_monitor);
5881                         (void)lazy_gbar_created_cb(inst);
5882                 }
5883
5884                 ret = script_handler_unload(instance_gbar_script(inst), 1);
5885                 if (ret < 0) {
5886                         ErrPrint("Unable to unload the script: %s, %d\n", pkgname, ret);
5887                 }
5888
5889                 /*!
5890                  * \note
5891                  * Send request to the slave.
5892                  * The SLAVE must has to repsonse this via "release_buffer" method.
5893                  */
5894                 ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL);
5895                 if (ret < 0) {
5896                         ErrPrint("Unable to close the GBAR: %s, %d\n", pkgname, ret);
5897                 }
5898
5899                 /*!
5900                  * \note
5901                  * Send the destroyed GBAR event to the client
5902                  */
5903                 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
5904                         /*!
5905                          * \note
5906                          * 13-05-28
5907                          * I've changed my mind. There is no requirements to keep the timer handler.
5908                          * But I just add it to the tagged-data of the instance.
5909                          * Just reserve for future-use.
5910                          */
5911                         DbgPrint("Add lazy GBAR destroy timer\n");
5912                         gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_destroyed_cb, instance_ref(inst));
5913                         if (!gbar_monitor) {
5914                                 ErrPrint("Failed to create a timer: %s\n", pkgname);
5915                                 inst = instance_unref(inst);
5916                                 if (!inst) {
5917                                         DbgPrint("instance is deleted\n");
5918                                 }
5919                         } else {
5920                                 (void)instance_set_data(inst, LAZY_GBAR_CLOSE_TAG, gbar_monitor);
5921                                 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst) < 0) {
5922                                         ErrPrint("Failed to add a event callback for slave\n");
5923                                 }
5924                         }
5925                 }
5926         } else {
5927                 ErrPrint("Invalid GBAR TYPE\n");
5928                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5929         }
5930
5931 out:
5932         result = packet_create_reply(packet, "i", ret);
5933         if (!result) {
5934                 ErrPrint("Failed to create a packet\n");
5935         }
5936
5937         return result;
5938 }
5939
5940 static struct packet *client_activate_package(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, ret */
5941 {
5942         struct client_node *client;
5943         struct packet *result;
5944         const char *pkgname;
5945         int ret;
5946         struct pkg_info *info;
5947
5948         client = client_find_by_rpc_handle(handle);
5949         if (!client) {
5950                 ErrPrint("Client %d is not exists\n", pid);
5951                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5952                 pkgname = "";
5953                 goto out;
5954         }
5955
5956         ret = packet_get(packet, "s", &pkgname);
5957         if (ret != 1) {
5958                 ErrPrint("Parameter is not matched\n");
5959                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5960                 pkgname = "";
5961                 goto out;
5962         }
5963
5964         DbgPrint("pid[%d] pkgname[%s]\n", pid, pkgname);
5965
5966         /*!
5967          * \NOTE:
5968          * Validate the dynamicbox package name.
5969          */
5970         if (!package_is_dbox_pkgname(pkgname)) {
5971                 ErrPrint("%s is not a valid dynamicbox package\n", pkgname);
5972                 pkgname = "";
5973                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5974                 goto out;
5975         }
5976
5977         info = package_find(pkgname);
5978         if (!info) {
5979                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5980         } else {
5981                 ret = package_clear_fault(info);
5982         }
5983
5984 out:
5985         result = packet_create_reply(packet, "is", ret, pkgname);
5986         if (!result) {
5987                 ErrPrint("Failed to create a packet\n");
5988         }
5989
5990         return result;
5991 }
5992
5993 static struct packet *client_subscribed(pid_t pid, int handle, const struct packet *packet)
5994 {
5995         const char *cluster;
5996         const char *category;
5997         struct client_node *client;
5998         int ret;
5999
6000         client = client_find_by_rpc_handle(handle);
6001         if (!client) {
6002                 ErrPrint("Client %d is not exists\n", pid);
6003                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
6004                 goto out;
6005         }
6006
6007         ret = packet_get(packet, "ss", &cluster, &category);
6008         if (ret != 2) {
6009                 ErrPrint("Invalid argument\n");
6010                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6011                 goto out;
6012         }
6013
6014         DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
6015         if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) {
6016                 ErrPrint("Invalid cluster name\n");
6017                 goto out;
6018         }
6019
6020         /*!
6021          * \todo
6022          * SUBSCRIBE cluster & sub-cluster for a client.
6023          */
6024         ret = client_subscribe(client, cluster, category);
6025         if (ret == 0) {
6026                 package_alter_instances_to_client(client, ALTER_CREATE);
6027         }
6028
6029 out:
6030         /*! \note No reply packet */
6031         return NULL;
6032 }
6033
6034 static struct packet *client_delete_cluster(pid_t pid, int handle, const struct packet *packet)
6035 {
6036         const char *cluster;
6037         struct client_node *client;
6038         struct packet *result;
6039         int ret;
6040
6041         client = client_find_by_rpc_handle(handle);
6042         if (!client) {
6043                 ErrPrint("Client %d is not exists\n", pid);
6044                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
6045                 goto out;
6046         }
6047
6048         ret = packet_get(packet, "s", &cluster);
6049         if (ret != 1) {
6050                 ErrPrint("Invalid parameters\n");
6051                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6052                 goto out;
6053         }
6054
6055         DbgPrint("pid[%d] cluster[%s]\n", pid, cluster);
6056
6057         if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) {
6058                 ErrPrint("Invalid cluster: %s\n", cluster);
6059                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6060                 goto out;
6061         }
6062
6063         /*!
6064          * \todo
6065          */
6066         ret = DBOX_STATUS_ERROR_NOT_IMPLEMENTED;
6067
6068 out:
6069         result = packet_create_reply(packet, "i", ret);
6070         if (!result) {
6071                 ErrPrint("Failed to create a packet\n");
6072         }
6073
6074         return result;
6075 }
6076
6077 static inline int update_pkg_cb(struct category *category, const char *pkgname, int force)
6078 {
6079         const char *c_name;
6080         const char *s_name;
6081
6082         c_name = group_cluster_name_by_category(category);
6083         s_name = group_category_name(category);
6084
6085         if (!c_name || !s_name || !pkgname) {
6086                 ErrPrint("Name is not valid\n");
6087                 return EXIT_FAILURE;
6088         }
6089
6090         DbgPrint("Send refresh request: %s (%s/%s)\n", pkgname, c_name, s_name);
6091         slave_rpc_request_update(pkgname, "", c_name, s_name, NULL, force);
6092
6093         /* Just try to create a new package */
6094         if (util_free_space(DYNAMICBOX_CONF_IMAGE_PATH) > DYNAMICBOX_CONF_MINIMUM_SPACE) {
6095                 double timestamp;
6096                 struct inst_info *inst;
6097
6098                 timestamp = util_timestamp();
6099                 /*!
6100                  * \NOTE
6101                  * Don't need to check the subscribed clients.
6102                  * Because this callback is called by the requests of clients.
6103                  * It means. some clients wants to handle this instances ;)
6104                  */
6105                 inst = instance_create(NULL, timestamp, pkgname, "", c_name, s_name, DYNAMICBOX_CONF_DEFAULT_PERIOD, 0, 0);
6106                 if (!inst) {
6107                         ErrPrint("Failed to create a new instance\n");
6108                 }
6109         }
6110
6111         return EXIT_SUCCESS;
6112 }
6113
6114 static struct packet *client_update(pid_t pid, int handle, const struct packet *packet)
6115 {
6116         struct inst_info *inst;
6117         struct client_node *client;
6118         const char *pkgname;
6119         const char *id;
6120         int force;
6121         int ret;
6122
6123         client = client_find_by_rpc_handle(handle);
6124         if (!client) {
6125                 ErrPrint("Cilent %d is not exists\n", pid);
6126                 goto out;
6127         }
6128
6129         ret = packet_get(packet, "ssi", &pkgname, &id, &force);
6130         if (ret != 3) {
6131                 ErrPrint("Invalid argument\n");
6132                 goto out;
6133         }
6134
6135         ret = validate_request(pkgname, id, &inst, NULL);
6136         if (ret != DBOX_STATUS_ERROR_NONE) {
6137                 goto out;
6138         }
6139
6140         if (instance_client(inst) != client) {
6141                 /* PERMISSIONS */
6142                 ErrPrint("Insufficient permissions [%s] - %d\n", pkgname, pid);
6143         } else {
6144                 slave_rpc_request_update(pkgname, id, instance_cluster(inst), instance_category(inst), NULL, force);
6145         }
6146
6147 out:
6148         /*! \note No reply packet */
6149         return NULL;
6150 }
6151
6152 static struct packet *client_refresh_group(pid_t pid, int handle, const struct packet *packet)
6153 {
6154         const char *cluster_id;
6155         const char *category_id;
6156         struct client_node *client;
6157         int ret;
6158         struct cluster *cluster;
6159         struct category *category;
6160         struct context_info *info;
6161         Eina_List *info_list;
6162         Eina_List *l;
6163         int force;
6164
6165         client = client_find_by_rpc_handle(handle);
6166         if (!client) {
6167                 ErrPrint("Cilent %d is not exists\n", pid);
6168                 goto out;
6169         }
6170
6171         ret = packet_get(packet, "ssi", &cluster_id, &category_id, &force);
6172         if (ret != 3) {
6173                 ErrPrint("Invalid parameter\n");
6174                 goto out;
6175         }
6176
6177         DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster_id, category_id);
6178
6179         if (!strlen(cluster_id) || !strcasecmp(cluster_id, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) {
6180                 ErrPrint("Invalid cluster name: %s\n", cluster_id);
6181                 goto out;
6182         }
6183
6184         cluster = group_find_cluster(cluster_id);
6185         if (!cluster) {
6186                 ErrPrint("Cluster [%s] is not registered\n", cluster_id);
6187                 goto out;
6188         }
6189
6190         category = group_find_category(cluster, category_id);
6191         if (!category) {
6192                 ErrPrint("Category [%s] is not registered\n", category_id);
6193                 goto out;
6194         }
6195
6196         info_list = group_context_info_list(category);
6197         EINA_LIST_FOREACH(info_list, l, info) {
6198                 update_pkg_cb(category, group_pkgname_from_context_info(info), force);
6199         }
6200
6201 out:
6202         /*! \note No reply packet */
6203         return NULL;
6204 }
6205
6206 static struct packet *client_delete_category(pid_t pid, int handle, const struct packet *packet)
6207 {
6208         const char *cluster;
6209         const char *category;
6210         struct client_node *client;
6211         struct packet *result;
6212         int ret;
6213
6214         client = client_find_by_rpc_handle(handle);
6215         if (!client) {
6216                 ErrPrint("Client %d is not exists\n", pid);
6217                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
6218                 goto out;
6219         }
6220
6221         ret = packet_get(packet, "ss", &cluster, &category);
6222         if (ret != 2) {
6223                 ErrPrint("Invalid paramenters\n");
6224                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6225                 goto out;
6226         }
6227
6228         DbgPrint("pid[%d] cluster[%s] category[%s]\n", pid, cluster, category);
6229         if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) {
6230                 ErrPrint("Invalid cluster: %s\n", cluster);
6231                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6232                 goto out;
6233         }
6234
6235         /*!
6236          * \todo
6237          */
6238         ret = DBOX_STATUS_ERROR_NOT_IMPLEMENTED;
6239
6240 out:
6241         result = packet_create_reply(packet, "i", ret);
6242         if (!result) {
6243                 ErrPrint("Failed to create a packet\n");
6244         }
6245
6246         return result;
6247 }
6248
6249 static struct packet *client_unsubscribed(pid_t pid, int handle, const struct packet *packet)
6250 {
6251         const char *cluster;
6252         const char *category;
6253         struct client_node *client;
6254         int ret;
6255
6256         client = client_find_by_rpc_handle(handle);
6257         if (!client) {
6258                 ErrPrint("Client %d is not exists\n", pid);
6259                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
6260                 goto out;
6261         }
6262
6263         ret = packet_get(packet, "ss", &cluster, &category);
6264         if (ret != 2) {
6265                 ErrPrint("Invalid argument\n");
6266                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6267                 goto out;
6268         }
6269
6270         DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
6271
6272         if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) {
6273                 ErrPrint("Invalid cluster name: %s\n", cluster);
6274                 goto out;
6275         }
6276
6277         /*!
6278          * \todo
6279          * UNSUBSCRIBE cluster & sub-cluster for a client.
6280          */
6281         ret = client_unsubscribe(client, cluster, category);
6282         if (ret == 0) {
6283                 package_alter_instances_to_client(client, ALTER_DESTROY);
6284         }
6285
6286 out:
6287         /*! \note No reply packet */
6288         return NULL;
6289 }
6290
6291 static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
6292 {
6293         struct slave_node *slave;
6294         const char *slavename;
6295         int ret;
6296
6297         ret = packet_get(packet, "s", &slavename);
6298         if (ret != 1) {
6299                 ErrPrint("Parameter is not matched\n");
6300                 goto out;
6301         }
6302
6303         DbgPrint("New slave[%s](%d) is arrived\n", slavename, pid);
6304
6305         slave = slave_find_by_name(slavename);
6306
6307         if (!slave) { /* Try again to find a slave using pid */
6308                 slave = slave_find_by_pid(pid);
6309         }
6310
6311         if (!slave) {
6312                 if (DYNAMICBOX_CONF_DEBUG_MODE || g_conf.debug_mode) {
6313                         char pkgname[pathconf("/", _PC_PATH_MAX)];
6314                         const char *abi;
6315
6316                         if (aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)) != AUL_R_OK) {
6317                                 ErrPrint("pid[%d] is not authroized provider package, try to find it using its name[%s]\n", pid, slavename);
6318                                 slave = slave_find_by_name(slavename);
6319                                 pkgname[0] = '\0'; /* Reset the pkgname */
6320                         } else {
6321                                 slave = slave_find_by_pkgname(pkgname);
6322                         }
6323
6324                         if (!slave) {
6325                                 abi = abi_find_by_pkgname(pkgname);
6326                                 if (!abi) {
6327                                         abi = DYNAMICBOX_CONF_DEFAULT_ABI;
6328                                         DbgPrint("Slave pkgname is invalid, ABI is replaced with '%s'(default)\n", abi);
6329                                 }
6330
6331                                 slave = slave_create(slavename, 1, abi, pkgname, 0, NULL);
6332                                 if (!slave) {
6333                                         ErrPrint("Failed to create a new slave for %s\n", slavename);
6334                                         goto out;
6335                                 }
6336
6337                                 DbgPrint("New slave is created (net: 0)\n");
6338                         } else {
6339                                 DbgPrint("Registered slave is replaced with this new one\n");
6340                                 abi = slave_abi(slave);
6341                                 if (!abi) {
6342                                         ErrPrint("ABI is not valid: %s\n", slavename);
6343                                         abi = DYNAMICBOX_CONF_DEFAULT_ABI;
6344                                 }
6345                         }
6346
6347                         slave_set_pid(slave, pid);
6348                         DbgPrint("Provider is forcely activated, pkgname(%s), abi(%s), slavename(%s)\n", pkgname, abi, slavename);
6349                 } else {
6350                         ErrPrint("Slave[%d, %s] is not exists\n", pid, slavename);
6351                         goto out;
6352                 }
6353         } else {
6354                 if (slave_pid(slave) != pid) {
6355                         if (slave_pid(slave) > 0) {
6356                                 CRITICAL_LOG("Slave(%s) is already assigned to %d\n", slave_name(slave), slave_pid(slave));
6357                                 if (pid > 0) {
6358                                         ret = aul_terminate_pid_async(pid);
6359                                         CRITICAL_LOG("Terminate %d (ret: %d)\n", pid, ret);
6360                                 }
6361                                 goto out;
6362                         }
6363                         CRITICAL_LOG("PID of slave(%s) is updated (%d -> %d)\n", slave_name(slave), slave_pid(slave), pid);
6364                         slave_set_pid(slave, pid);
6365                 }
6366         }
6367
6368         /*!
6369          * \note
6370          * After updating handle,
6371          * slave activated callback will be called.
6372          */
6373         slave_rpc_update_handle(slave, handle);
6374
6375 out:
6376         return NULL;
6377 }
6378
6379 static struct packet *slave_ctrl(pid_t pid, int handle, const struct packet *packet)
6380 {
6381         struct slave_node *slave;
6382         int ctrl;
6383         int ret;
6384
6385         slave = slave_find_by_pid(pid);
6386         if (!slave) {
6387                 ErrPrint("Slave %d is not exists\n", pid);
6388                 goto out;
6389         }
6390
6391         ret = packet_get(packet, "i", &ctrl);
6392         if (ret != 1) {
6393                 ErrPrint("Parameter is not matched\n");
6394         } else {
6395                 slave_set_control_option(slave, ctrl);
6396         }
6397
6398 out:
6399         return NULL;
6400 }
6401
6402 static struct packet *slave_ping(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
6403 {
6404         struct slave_node *slave;
6405         const char *slavename;
6406         int ret;
6407
6408         slave = slave_find_by_pid(pid);
6409         if (!slave) {
6410                 ErrPrint("Slave %d is not exists\n", pid);
6411                 goto out;
6412         }
6413
6414         ret = packet_get(packet, "s", &slavename);
6415         if (ret != 1) {
6416                 ErrPrint("Parameter is not matched\n");
6417         } else {
6418                 slave_rpc_ping(slave);
6419         }
6420
6421 out:
6422         return NULL;
6423 }
6424
6425 static struct packet *slave_faulted(pid_t pid, int handle, const struct packet *packet)
6426 {
6427         struct slave_node *slave;
6428         struct pkg_info *pkg;
6429         const char *pkgname;
6430         const char *id;
6431         const char *func;
6432         int ret;
6433
6434         slave = slave_find_by_pid(pid);
6435         if (!slave) {
6436                 ErrPrint("Slave %d is not exists\n", pid);
6437                 goto out;
6438         }
6439
6440         ret = packet_get(packet, "sss", &pkgname, &id, &func);
6441         if (ret != 3) {
6442                 ErrPrint("Parameter is not matched\n");
6443                 goto out;
6444         }
6445
6446         ret = fault_info_set(slave, pkgname, id, func);
6447         DbgPrint("Slave Faulted: %s (%d)\n", slave_name(slave), ret);
6448
6449         pkg = package_find(pkgname);
6450         if (!pkg) {
6451                 ErrPrint("There is no package info found: %s\n", pkgname);
6452         } else {
6453                 package_faulted(pkg, 0);
6454         }
6455
6456 out:
6457         return NULL;
6458 }
6459
6460 static struct packet *slave_dbox_update_begin(pid_t pid, int handle, const struct packet *packet)
6461 {
6462         struct slave_node *slave;
6463         struct inst_info *inst;
6464         const struct pkg_info *pkg;
6465         const char *pkgname;
6466         const char *id;
6467         double priority;
6468         const char *content;
6469         const char *title;
6470         int ret;
6471
6472         slave = slave_find_by_pid(pid);
6473         if (!slave) {
6474                 ErrPrint("Slave %d is not exists\n", pid);
6475                 goto out;
6476         }
6477
6478         ret = packet_get(packet, "ssdss", &pkgname, &id, &priority, &content, &title);
6479         if (ret != 5) {
6480                 ErrPrint("Invalid parameters\n");
6481                 goto out;
6482         }
6483
6484         ret = validate_request(pkgname, id, &inst, &pkg);
6485         if (ret != DBOX_STATUS_ERROR_NONE) {
6486                 goto out;
6487         }
6488
6489         if (instance_state(inst) == INST_DESTROYED) {
6490                 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6491                 goto out;
6492         }
6493
6494         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
6495                 ret = instance_dbox_update_begin(inst, priority, content, title);
6496                 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6497                         slave_freeze_ttl(slave);
6498                 }
6499         } else {
6500                 ErrPrint("Invalid request[%s]\n", id);
6501         }
6502
6503 out:
6504         return NULL;
6505 }
6506
6507 static struct packet *slave_dbox_update_end(pid_t pid, int handle, const struct packet *packet)
6508 {
6509         struct slave_node *slave;
6510         struct inst_info *inst;
6511         const struct pkg_info *pkg;
6512         const char *pkgname;
6513         const char *id;
6514         int ret;
6515
6516         slave = slave_find_by_pid(pid);
6517         if (!slave) {
6518                 ErrPrint("Slave %d is not exists\n", pid);
6519                 goto out;
6520         }
6521
6522         ret = packet_get(packet, "ss", &pkgname, &id);
6523         if (ret != 2) {
6524                 ErrPrint("Invalid parameters\n");
6525                 goto out;
6526         }
6527
6528         ret = validate_request(pkgname, id, &inst, &pkg);
6529         if (ret != DBOX_STATUS_ERROR_NONE) {
6530                 goto out;
6531         }
6532
6533         if (instance_state(inst) == INST_DESTROYED) {
6534                 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6535                 goto out;
6536         }
6537
6538         if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
6539                 ret = instance_dbox_update_end(inst);
6540                 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6541                         slave_thaw_ttl(slave);
6542                 }
6543         } else {
6544                 ErrPrint("Invalid request[%s]\n", id);
6545         }
6546
6547 out:
6548         return NULL;
6549 }
6550
6551 static struct packet *slave_gbar_update_begin(pid_t pid, int handle, const struct packet *packet)
6552 {
6553         struct slave_node *slave;
6554         const struct pkg_info *pkg;
6555         struct inst_info *inst;
6556         const char *pkgname;
6557         const char *id;
6558         int ret;
6559
6560         slave = slave_find_by_pid(pid);
6561         if (!slave) {
6562                 ErrPrint("Slave %d is not exists\n", pid);
6563                 goto out;
6564         }
6565
6566         ret = packet_get(packet, "ss", &pkgname, &id);
6567         if (ret != 2) {
6568                 ErrPrint("Invalid parameters\n");
6569                 goto out;
6570         }
6571
6572         ret = validate_request(pkgname, id, &inst, &pkg);
6573         if (ret != DBOX_STATUS_ERROR_NONE) {
6574                 goto out;
6575         }
6576
6577         if (instance_state(inst) == INST_DESTROYED) {
6578                 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6579                 goto out;
6580         }
6581
6582         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
6583                 (void)instance_gbar_update_begin(inst);
6584         } else {
6585                 ErrPrint("Invalid request[%s]\n", id);
6586         }
6587
6588 out:
6589         return NULL;
6590 }
6591
6592 static struct packet *slave_key_status(pid_t pid, int handle, const struct packet *packet)
6593 {
6594         struct slave_node *slave;
6595         struct inst_info *inst;
6596         const char *pkgname;
6597         const char *id;
6598         int status;
6599         int ret;
6600
6601         slave = slave_find_by_pid(pid);
6602         if (!slave) {
6603                 ErrPrint("Slave %d is not exists\n", pid);
6604                 goto out;
6605         }
6606
6607         ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6608         if (ret != 3) {
6609                 ErrPrint("Invalid parameters\n");
6610                 goto out;
6611         }
6612
6613         ret = validate_request(pkgname, id, &inst, NULL);
6614         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6615                 if (instance_state(inst) == INST_DESTROYED) {
6616                         ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6617                 } else {
6618                         (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6619                 }
6620         }
6621
6622 out:
6623         return NULL;
6624 }
6625
6626 static struct packet *slave_access_status(pid_t pid, int handle, const struct packet *packet)
6627 {
6628         struct slave_node *slave;
6629         struct inst_info *inst;
6630         const char *pkgname;
6631         const char *id;
6632         int status;
6633         int ret;
6634
6635         slave = slave_find_by_pid(pid);
6636         if (!slave) {
6637                 ErrPrint("Slave %d is not exists\n", pid);
6638                 goto out;
6639         }
6640
6641         ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6642         if (ret != 3) {
6643                 ErrPrint("Invalid parameters\n");
6644                 goto out;
6645         }
6646
6647         ret = validate_request(pkgname, id, &inst, NULL);
6648         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6649                 if (instance_state(inst) == INST_DESTROYED) {
6650                         ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6651                 } else {
6652                         (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6653                 }
6654         }
6655
6656 out:
6657         return NULL;
6658 }
6659
6660 static struct packet *slave_close_gbar(pid_t pid, int handle, const struct packet *packet)
6661 {
6662         struct slave_node *slave;
6663         struct inst_info *inst;
6664         const char *pkgname;
6665         const char *id;
6666         int status;
6667         int ret;
6668
6669         slave = slave_find_by_pid(pid);
6670         if (!slave) {
6671                 ErrPrint("Slave %d is not exists\n", pid);
6672                 goto out;
6673         }
6674
6675         ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6676         if (ret != 3) {
6677                 ErrPrint("Invalid parameters\n");
6678                 goto out;
6679         }
6680
6681         ret = validate_request(pkgname, id, &inst, NULL);
6682         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6683                 if (instance_state(inst) == INST_DESTROYED) {
6684                         ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6685                 } else {
6686                         (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6687                 }
6688         }
6689
6690 out:
6691         return NULL;
6692 }
6693
6694 static struct packet *slave_gbar_update_end(pid_t pid, int handle, const struct packet *packet)
6695 {
6696         struct slave_node *slave;
6697         const struct pkg_info *pkg;
6698         struct inst_info *inst;
6699         const char *pkgname;
6700         const char *id;
6701         int ret;
6702
6703         slave = slave_find_by_pid(pid);
6704         if (!slave) {
6705                 ErrPrint("Slave %d is not exists\n", pid);
6706                 goto out;
6707         }
6708
6709         ret = packet_get(packet, "ss", &pkgname, &id);
6710         if (ret != 2) {
6711                 ErrPrint("Invalid parameters\n");
6712                 goto out;
6713         }
6714
6715         ret = validate_request(pkgname, id, &inst, &pkg);
6716         if (ret != DBOX_STATUS_ERROR_NONE) {
6717                 goto out;
6718         }
6719
6720         if (instance_state(inst) == INST_DESTROYED) {
6721                 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6722                 goto out;
6723         }
6724
6725         if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
6726                 (void)instance_gbar_update_end(inst);
6727         } else {
6728                 ErrPrint("Invalid request[%s]\n", id);
6729         }
6730
6731 out:
6732         return NULL;
6733 }
6734
6735 static struct packet *slave_call(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
6736 {
6737         struct slave_node *slave;
6738         const char *pkgname;
6739         const char *id;
6740         const char *func;
6741         int ret;
6742
6743         slave = slave_find_by_pid(pid);
6744         if (!slave) {
6745                 ErrPrint("Slave %d is not exists\n", pid);
6746                 goto out;
6747         }
6748
6749         ret = packet_get(packet, "sss", &pkgname, &id, &func);
6750         if (ret != 3) {
6751                 ErrPrint("Parameter is not matched\n");
6752                 goto out;
6753         }
6754
6755         ret = fault_func_call(slave, pkgname, id, func);
6756         slave_give_more_ttl(slave);
6757
6758 out:
6759         return NULL;
6760 }
6761
6762 static struct packet *slave_ret(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
6763 {
6764         struct slave_node *slave;
6765         const char *pkgname;
6766         const char *id;
6767         const char *func;
6768         int ret;
6769
6770         slave = slave_find_by_pid(pid);
6771         if (!slave) {
6772                 ErrPrint("Slave %d is not exists\n", pid);
6773                 goto out;
6774         }
6775
6776         ret = packet_get(packet, "sss", &pkgname, &id, &func);
6777         if (ret != 3) {
6778                 ErrPrint("Parameter is not matched\n");
6779                 goto out;
6780         }
6781
6782         ret = fault_func_ret(slave, pkgname, id, func);
6783         slave_give_more_ttl(slave);
6784
6785 out:
6786         return NULL;
6787 }
6788
6789 static struct packet *slave_extra_info(pid_t pid, int handle, const struct packet *packet)
6790 {
6791         struct slave_node *slave;
6792         const char *pkgname;
6793         const char *id;
6794         const char *content_info;
6795         const char *title;
6796         const char *icon;
6797         const char *name;
6798         double priority;
6799         int ret;
6800         struct inst_info *inst;
6801
6802         slave = slave_find_by_pid(pid);
6803         if (!slave) {
6804                 ErrPrint("Slave %d is not exists\n", pid);
6805                 goto out;
6806         }
6807
6808         ret = packet_get(packet, "ssssssd", &pkgname, &id, &content_info, &title, &icon, &name, &priority);
6809         if (ret != 7) {
6810                 ErrPrint("Parameter is not matchd\n");
6811                 goto out;
6812         }
6813
6814         ret = validate_request(pkgname, id, &inst, NULL);
6815         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6816                 if (instance_state(inst) == INST_DESTROYED) {
6817                         ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6818                         goto out;
6819                 }
6820
6821                 instance_set_dbox_info(inst, priority, content_info, title);
6822                 instance_set_alt_info(inst, icon, name);
6823                 instance_extra_info_updated_by_instance(inst);
6824                 slave_give_more_ttl(slave);
6825         }
6826
6827 out:
6828         return NULL;
6829 }
6830
6831 static struct packet *slave_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, width, height, ret */
6832 {
6833         struct slave_node *slave;
6834         const char *pkgname;
6835         const char *safe_filename;
6836         const char *id;
6837         int w;
6838         int h;
6839         int x;
6840         int y;
6841         int ret;
6842         struct inst_info *inst;
6843
6844         slave = slave_find_by_pid(pid);
6845         if (!slave) {
6846                 ErrPrint("Slave %d is not exists\n", pid);
6847                 goto out;
6848         }
6849
6850         ret = packet_get(packet, "sssiiii", &pkgname, &id, &safe_filename, &x, &y, &w, &h);
6851         if (ret != 7) {
6852                 ErrPrint("Parameter is not matched\n");
6853                 goto out;
6854         }
6855
6856         ret = validate_request(pkgname, id, &inst, NULL);
6857         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6858                 if (instance_state(inst) == INST_DESTROYED) {
6859                         ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6860                         goto out;
6861                 }
6862
6863                 switch (package_dbox_type(instance_package(inst))) {
6864                 case DBOX_TYPE_SCRIPT:
6865                         script_handler_resize(instance_dbox_script(inst), w, h);
6866                         if (safe_filename) {
6867                                 (void)script_handler_parse_desc(inst, safe_filename, 0);
6868                         } else {
6869                                 safe_filename = util_uri_to_path(id);
6870                                 (void)script_handler_parse_desc(inst, safe_filename, 0);
6871                         }
6872
6873                         if (unlink(safe_filename) < 0) {
6874                                 ErrPrint("unlink: %s - %s\n", strerror(errno), safe_filename);
6875                         }
6876                         break;
6877                 case DBOX_TYPE_BUFFER:
6878                 default:
6879                         /*!
6880                          * \check
6881                          * text format (inst)
6882                          */
6883                         instance_dbox_updated_by_instance(inst, safe_filename, x, y, w, h);
6884                         break;
6885                 }
6886
6887                 slave_give_more_ttl(slave);
6888         }
6889
6890 out:
6891         return NULL;
6892 }
6893
6894 static struct packet *slave_hold_scroll(pid_t pid, int handle, const struct packet *packet)
6895 {
6896         struct slave_node *slave;
6897         struct inst_info *inst;
6898         const char *pkgname;
6899         const char *id;
6900         int seize;
6901         int ret;
6902
6903         slave = slave_find_by_pid(pid);
6904         if (!slave) {
6905                 ErrPrint("Slave %d is not exists\n", pid);
6906                 goto out;
6907         }
6908
6909         ret = packet_get(packet, "ssi", &pkgname, &id, &seize);
6910         if (ret != 3) {
6911                 ErrPrint("Parameter is not matched\n");
6912                 goto out;
6913         }
6914
6915         ret = validate_request(pkgname, id, &inst, NULL);
6916         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6917                 if (instance_state(inst) == INST_DESTROYED) {
6918                         ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6919                 } else {
6920                         (void)instance_hold_scroll(inst, seize);
6921                 }
6922         }
6923
6924 out:
6925         return NULL;
6926 }
6927
6928 static struct packet *slave_extra_updated(pid_t pid, int handle, const struct packet *packet)
6929 {
6930         struct slave_node *slave;
6931         const char *pkgname;
6932         const char *id;
6933         int idx;
6934         int x;
6935         int y;
6936         int w;
6937         int h;
6938         int ret;
6939         int is_gbar;
6940         struct inst_info *inst;
6941
6942         slave = slave_find_by_pid(pid);
6943         if (!slave) {
6944                 ErrPrint("Slave %d is not exists\n", pid);
6945                 goto out;
6946         }
6947
6948         ret = packet_get(packet, "ssiiiiii", &pkgname, &id, &is_gbar, &idx, &x, &y, &w, &h);
6949         if (ret != 8) {
6950                 ErrPrint("Parameter is not matched\n");
6951                 goto out;
6952         }
6953
6954         ret = validate_request(pkgname, id, &inst, NULL);
6955         if (ret != DBOX_STATUS_ERROR_NONE) {
6956                 goto out;
6957         }
6958
6959         if (instance_state(inst) == INST_DESTROYED) {
6960                 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6961                 goto out;
6962         }
6963
6964         (void)instance_extra_updated_by_instance(inst, is_gbar, idx, x, y, w, h);
6965 out:
6966         return NULL;
6967 }
6968
6969 static struct packet *slave_desc_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, decsfile, ret */
6970 {
6971         struct slave_node *slave;
6972         const char *pkgname;
6973         const char *id;
6974         const char *descfile;
6975         int x;
6976         int y;
6977         int w;
6978         int h;
6979         int ret;
6980         struct inst_info *inst;
6981
6982         slave = slave_find_by_pid(pid);
6983         if (!slave) {
6984                 ErrPrint("Slave %d is not exists\n", pid);
6985                 goto out;
6986         }
6987
6988         ret = packet_get(packet, "sssiiii", &pkgname, &id, &descfile, &x, &y, &w, &h);
6989         if (ret != 7) {
6990                 ErrPrint("Parameter is not matched\n");
6991                 goto out;
6992         }
6993
6994         ret = validate_request(pkgname, id, &inst, NULL);
6995         if (ret != DBOX_STATUS_ERROR_NONE) {
6996                 goto out;
6997         }
6998
6999         if (instance_state(inst) == INST_DESTROYED) {
7000                 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
7001                 goto out;
7002         }
7003
7004         switch (package_gbar_type(instance_package(inst))) {
7005         case GBAR_TYPE_SCRIPT:
7006                 DbgPrint("%s updated (%s)\n", instance_id(inst), descfile);
7007                 if (script_handler_is_loaded(instance_gbar_script(inst))) {
7008                         (void)script_handler_parse_desc(inst, descfile, 1);
7009                 }
7010                 break;
7011         case GBAR_TYPE_TEXT:
7012                 instance_set_gbar_size(inst, 0, 0);
7013         case GBAR_TYPE_BUFFER:
7014                 instance_gbar_updated(pkgname, id, descfile, x, y, w, h);
7015                 break;
7016         default:
7017                 DbgPrint("Ignore updated DESC(%s)\n", pkgname);
7018                 break;
7019         }
7020
7021 out:
7022         return NULL;
7023 }
7024
7025 static struct packet *slave_deleted(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, id, ret */
7026 {
7027         struct slave_node *slave;
7028         const char *pkgname;
7029         const char *id;
7030         int ret;
7031         struct inst_info *inst;
7032
7033         slave = slave_find_by_pid(pid);
7034         if (!slave) {
7035                 ErrPrint("Slave %d is not exists\n", pid);
7036                 goto out;
7037         }
7038
7039         ret = packet_get(packet, "ss", &pkgname, &id);
7040         if (ret != 2) {
7041                 ErrPrint("Parameter is not matched\n");
7042                 goto out;
7043         }
7044
7045         ret = validate_request(pkgname, id, &inst, NULL);
7046         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
7047                 ret = instance_destroyed(inst, DBOX_STATUS_ERROR_NONE);
7048         }
7049
7050 out:
7051         return NULL;
7052 }
7053
7054 /*!
7055  * \note for the BUFFER Type slave
7056  */
7057 static struct packet *slave_acquire_buffer(pid_t pid, int handle, const struct packet *packet) /* type, id, w, h, size */
7058 {
7059         enum target_type target;
7060         const char *pkgname;
7061         const char *id;
7062         int w;
7063         int h;
7064         int pixel_size;
7065         struct packet *result;
7066         struct slave_node *slave;
7067         struct inst_info *inst = NULL;
7068         const struct pkg_info *pkg = NULL;
7069         int ret;
7070
7071         slave = slave_find_by_pid(pid);
7072         if (!slave) {
7073                 ErrPrint("Failed to find a slave\n");
7074                 id = "";
7075                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7076                 goto out;
7077         }
7078
7079         ret = packet_get(packet, "issiii", &target, &pkgname, &id, &w, &h, &pixel_size);
7080         if (ret != 6) {
7081                 ErrPrint("Invalid argument\n");
7082                 id = "";
7083                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7084                 goto out;
7085         }
7086
7087         ret = validate_request(pkgname, id, &inst, &pkg);
7088         id = "";
7089
7090         if (ret != DBOX_STATUS_ERROR_NONE) {
7091                 goto out;
7092         }
7093
7094         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7095
7096         if (instance_state(inst) == INST_DESTROYED) {
7097                 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
7098                 goto out;
7099         }
7100
7101         if (target == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
7102                 struct buffer_info *info;
7103
7104                 info = instance_dbox_buffer(inst);
7105                 if (!info) {
7106                         if (!instance_create_dbox_buffer(inst, pixel_size)) {
7107                                 ErrPrint("Failed to create a DBOX buffer\n");
7108                                 ret = DBOX_STATUS_ERROR_FAULT;
7109                                 goto out;
7110                         }
7111
7112                         info = instance_dbox_buffer(inst);
7113                         if (!info) {
7114                                 ErrPrint("DBOX buffer is not valid\n");
7115                                 /*!
7116                                  * \NOTE
7117                                  * ret value should not be changed.
7118                                  */
7119                                 goto out;
7120                         }
7121                 }
7122
7123                 ret = buffer_handler_resize(info, w, h);
7124                 ret = buffer_handler_load(info);
7125                 if (ret == 0) {
7126                         instance_set_dbox_size(inst, w, h);
7127                         instance_set_dbox_info(inst, DYNAMICBOX_CONF_PRIORITY_NO_CHANGE, DYNAMICBOX_CONF_CONTENT_NO_CHANGE, DYNAMICBOX_CONF_TITLE_NO_CHANGE);
7128                         id = buffer_handler_id(info);
7129                 } else {
7130                         ErrPrint("Failed to load a buffer(%d)\n", ret);
7131                 }
7132         } else if (target == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
7133                 struct buffer_info *info;
7134                 Ecore_Timer *gbar_monitor;
7135                 int is_resize;
7136
7137                 is_resize = 0;
7138                 gbar_monitor = instance_del_data(inst, GBAR_OPEN_MONITOR_TAG);
7139                 if (!gbar_monitor) {
7140                         gbar_monitor = instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG);
7141                         is_resize = !!gbar_monitor;
7142                         if (!is_resize) {
7143                                 /* Invalid request. Reject this */
7144                                 ErrPrint("Invalid request\n");
7145                                 goto out;
7146                         }
7147
7148                         slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst);
7149                 } else {
7150                         slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst);
7151                 }
7152
7153                 ecore_timer_del(gbar_monitor);
7154                 inst = instance_unref(inst);
7155                 if (!inst) {
7156                         ErrPrint("Instance refcnt is ZERO: %s\n", pkgname);
7157                         goto out;
7158                 }
7159
7160                 info = instance_gbar_buffer(inst);
7161                 if (!info) {
7162                         if (!instance_create_gbar_buffer(inst, pixel_size)) {
7163                                 ErrPrint("Failed to create a GBAR buffer\n");
7164                                 ret = DBOX_STATUS_ERROR_FAULT;
7165                                 instance_client_gbar_created(inst, ret);
7166                                 goto out;
7167                         }
7168
7169                         info = instance_gbar_buffer(inst);
7170                         if (!info) {
7171                                 ErrPrint("GBAR buffer is not valid\n");
7172                                 /*!
7173                                  * \NOTE
7174                                  * ret value should not be changed.
7175                                  */
7176                                 instance_client_gbar_created(inst, ret);
7177                                 goto out;
7178                         }
7179                 }
7180
7181                 ret = buffer_handler_resize(info, w, h);
7182                 ret = buffer_handler_load(info);
7183                 if (ret == 0) {
7184                         instance_set_gbar_size(inst, w, h);
7185                         id = buffer_handler_id(info);
7186                 } else {
7187                         ErrPrint("Failed to load a buffer (%d)\n", ret);
7188                 }
7189
7190                 /*!
7191                  * Send the GBAR created event to the client
7192                  */
7193                 if (!is_resize) {
7194                         instance_client_gbar_created(inst, ret);
7195                 }
7196         }
7197
7198 out:
7199         result = packet_create_reply(packet, "is", ret, id);
7200         if (!result) {
7201                 ErrPrint("Failed to create a reply packet\n");
7202         }
7203
7204         return result;
7205 }
7206
7207 static struct packet *slave_acquire_extra_buffer(pid_t pid, int handle, const struct packet *packet)
7208 {
7209         struct slave_node *slave;
7210         struct inst_info *inst;
7211         struct packet *result;
7212         const struct pkg_info *pkg;
7213         const char *pkgname;
7214         const char *id;
7215         int pixel_size;
7216         int target;
7217         int idx;
7218         int ret;
7219         int w;
7220         int h;
7221
7222         slave = slave_find_by_pid(pid);
7223         if (!slave) {
7224                 ErrPrint("Slave %d is not exists\n", pid);
7225                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7226                 id = "";
7227                 goto out;
7228         }
7229
7230         ret = packet_get(packet, "issiiii", &target, &pkgname, &id, &w, &h, &pixel_size, &idx);
7231         if (ret != 7) {
7232                 ErrPrint("Invalid parameters\n");
7233                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7234                 id = "";
7235                 goto out;
7236         }
7237
7238         ret = validate_request(pkgname, id, &inst, &pkg);
7239         id = "";
7240
7241         if (ret != DBOX_STATUS_ERROR_NONE) {
7242                 goto out;
7243         }
7244
7245         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7246
7247         if (instance_state(inst) == INST_DESTROYED) {
7248                 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
7249                 goto out;
7250         }
7251
7252         if (target == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
7253                 struct buffer_info *info;
7254
7255                 info = instance_dbox_extra_buffer(inst, idx);
7256                 if (!info) {
7257                         if (!instance_create_dbox_extra_buffer(inst, pixel_size, idx)) {
7258                                 ErrPrint("Failed to create a DBOX buffer\n");
7259                                 ret = DBOX_STATUS_ERROR_FAULT;
7260                                 goto out;
7261                         }
7262
7263                         info = instance_dbox_extra_buffer(inst, idx);
7264                         if (!info) {
7265                                 ErrPrint("DBOX extra buffer is not valid\n");
7266                                 /*!
7267                                  * \NOTE
7268                                  * ret value should not be changed.
7269                                  */
7270                                 goto out;
7271                         }
7272                 }
7273
7274                 ret = buffer_handler_resize(info, w, h);
7275                 ret = buffer_handler_load(info);
7276                 if (ret == 0) {
7277                         /**
7278                          * @todo
7279                          * Send the extra buffer info to the viewer.
7280                          * Then the viewer will try to acquire extra pixmap(aka, resource id) information
7281                          */
7282                         id = buffer_handler_id(info);
7283                         DbgPrint("Extra buffer is loaded: %s\n", id);
7284                         (void)instance_client_dbox_extra_buffer_created(inst, idx);
7285                 } else {
7286                         ErrPrint("Failed to load a buffer(%d)\n", ret);
7287                 }
7288         } else if (target == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
7289                 struct buffer_info *info;
7290
7291                 info = instance_gbar_extra_buffer(inst, idx);
7292                 if (!info) {
7293                         if (!instance_create_gbar_extra_buffer(inst, pixel_size, idx)) {
7294                                 ErrPrint("Failed to create a GBAR buffer\n");
7295                                 ret = DBOX_STATUS_ERROR_FAULT;
7296                                 goto out;
7297                         }
7298
7299                         info = instance_gbar_extra_buffer(inst, idx);
7300                         if (!info) {
7301                                 ErrPrint("GBAR buffer is not valid\n");
7302                                 /*!
7303                                  * \NOTE
7304                                  * ret value should not be changed.
7305                                  */
7306                                 goto out;
7307                         }
7308                 }
7309
7310                 ret = buffer_handler_resize(info, w, h);
7311                 ret = buffer_handler_load(info);
7312                 if (ret == 0) {
7313                         id = buffer_handler_id(info);
7314                         /**
7315                          * @todo
7316                          * Send the extra buffer acquired event to the viewer
7317                          */
7318                         DbgPrint("Extra buffer is loaded: %s\n", id);
7319                         (void)instance_client_gbar_extra_buffer_created(inst, idx);
7320                 } else {
7321                         ErrPrint("Failed to load a buffer (%d)\n", ret);
7322                 }
7323         }
7324
7325 out:
7326         result = packet_create_reply(packet, "is", ret, id);
7327         if (!result) {
7328                 ErrPrint("Failed to create a reply packet\n");
7329         }
7330
7331         return result;
7332 }
7333
7334 static struct packet *slave_resize_buffer(pid_t pid, int handle, const struct packet *packet)
7335 {
7336         struct slave_node *slave;
7337         struct packet *result;
7338         enum target_type type;
7339         const char *pkgname;
7340         const char *id;
7341         int w;
7342         int h;
7343         struct inst_info *inst = NULL;
7344         const struct pkg_info *pkg = NULL;
7345         int ret;
7346
7347         slave = slave_find_by_pid(pid);
7348         if (!slave) {
7349                 ErrPrint("Failed to find a slave\n");
7350                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7351                 id = "";
7352                 goto out;
7353         }
7354
7355         ret = packet_get(packet, "issii", &type, &pkgname, &id, &w, &h);
7356         if (ret != 5) {
7357                 ErrPrint("Invalid argument\n");
7358                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7359                 id = "";
7360                 goto out;
7361         }
7362
7363         ret = validate_request(pkgname, id, &inst, &pkg);
7364         id = "";
7365
7366         if (ret != DBOX_STATUS_ERROR_NONE) {
7367                 goto out;
7368         }
7369
7370         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7371         /*!
7372          * \note
7373          * Reset "id", It will be re-used from here
7374          */
7375
7376         if (instance_state(inst) == INST_DESTROYED) {
7377                 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
7378                 goto out;
7379         }
7380
7381         if (type == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
7382                 struct buffer_info *info;
7383
7384                 info = instance_dbox_buffer(inst);
7385                 if (!info) {
7386                         goto out;
7387                 }
7388
7389                 ret = buffer_handler_resize(info, w, h);
7390                 /*!
7391                  * \note
7392                  * id is resued for newly assigned ID
7393                  */
7394                 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
7395                         id = buffer_handler_id(info);
7396                         instance_set_dbox_size(inst, w, h);
7397                         instance_set_dbox_info(inst, DYNAMICBOX_CONF_PRIORITY_NO_CHANGE, DYNAMICBOX_CONF_CONTENT_NO_CHANGE, DYNAMICBOX_CONF_TITLE_NO_CHANGE);
7398                 }
7399         } else if (type == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
7400                 struct buffer_info *info;
7401
7402                 info = instance_gbar_buffer(inst);
7403                 if (!info) {
7404                         goto out;
7405                 }
7406
7407                 ret = buffer_handler_resize(info, w, h);
7408                 /*!
7409                  * \note
7410                  * id is resued for newly assigned ID
7411                  */
7412                 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
7413                         id = buffer_handler_id(info);
7414                         instance_set_gbar_size(inst, w, h);
7415                 }
7416         }
7417
7418 out:
7419         result = packet_create_reply(packet, "is", ret, id);
7420         if (!result) {
7421                 ErrPrint("Failed to create a packet\n");
7422         }
7423
7424         return result;
7425 }
7426
7427 static struct packet *slave_release_buffer(pid_t pid, int handle, const struct packet *packet)
7428 {
7429         enum target_type type;
7430         const char *pkgname;
7431         const char *id;
7432         struct packet *result;
7433         struct slave_node *slave;
7434         struct inst_info *inst;
7435         const struct pkg_info *pkg;
7436         int ret;
7437
7438         slave = slave_find_by_pid(pid);
7439         if (!slave) {
7440                 ErrPrint("Failed to find a slave\n");
7441                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7442                 goto out;
7443         }
7444
7445         if (packet_get(packet, "iss", &type, &pkgname, &id) != 3) {
7446                 ErrPrint("Inavlid argument\n");
7447                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7448                 goto out;
7449         }
7450
7451         ret = validate_request(pkgname, id, &inst, &pkg);
7452         if (ret != DBOX_STATUS_ERROR_NONE) {
7453                 goto out;
7454         }
7455
7456         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7457
7458         if (type == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
7459                 struct buffer_info *info;
7460
7461                 info = instance_dbox_buffer(inst);
7462                 ret = buffer_handler_unload(info);
7463         } else if (type == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
7464                 struct buffer_info *info;
7465                 Ecore_Timer *gbar_monitor;
7466
7467                 gbar_monitor = instance_del_data(inst, GBAR_CLOSE_MONITOR_TAG);
7468                 if (!gbar_monitor && !package_is_fault(pkg)) {
7469                         ErrPrint("Slave requests to release a buffer\n");
7470                         /**
7471                          * @note
7472                          * In this case just keep going to release buffer,
7473                          * Even if a user(client) doesn't wants to destroy the GBAR.
7474                          *
7475                          * If the slave tries to destroy GBAR buffer, it should be
7476                          * released and reported to the client about its status.
7477                          *
7478                          * Even if the pd is destroyed by timeout handler,
7479                          * instance_client_gbar_destroyed function will be ignored
7480                          * by pd.need_to_send_close_event flag.
7481                          * which will be checked by instance_client_gbar_destroyed function.
7482                          */
7483
7484                         /**
7485                          * @note
7486                          * provider can try to resize the buffer size.
7487                          * in that case, it will release the buffer first.
7488                          * Then even though the client doesn't request to close the GBAR,
7489                          * the provider can release it.
7490                          * If we send the close event to the client,
7491                          * The client will not able to allocate GBAR again.
7492                          * In this case, add the pd,monitor again. from here.
7493                          * to wait the re-allocate buffer.
7494                          * If the client doesn't request buffer reallocation,
7495                          * Treat it as a fault. and close the GBAR.
7496                          */
7497                         info = instance_gbar_buffer(inst);
7498                         ret = buffer_handler_unload(info);
7499
7500                         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
7501                                 gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_resize_monitor_cb, instance_ref(inst));
7502                                 if (!gbar_monitor) {
7503                                         ErrPrint("Failed to create a timer for GBAR Open monitor\n");
7504                                         inst = instance_unref(inst);
7505                                         if (!inst) {
7506                                                 DbgPrint("Instance is deleted\n");
7507                                         }
7508                                 } else {
7509                                         (void)instance_set_data(inst, GBAR_RESIZE_MONITOR_TAG, gbar_monitor);
7510                                         if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) != DBOX_STATUS_ERROR_NONE) {
7511                                                 ErrPrint("Failed to add event handler: %s\n", pkgname);
7512                                         }
7513                                 }
7514                         }
7515                 } else {
7516                         if (gbar_monitor) {
7517                                 /**
7518                                  * @note
7519                                  * If the instance has gbar_monitor, the pd close requested from client via client_destroy_gbar.
7520                                  */
7521                                 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
7522                                 ecore_timer_del(gbar_monitor);
7523
7524                                 inst = instance_unref(inst);
7525                                 if (!inst) {
7526                                         ErrPrint("Instance is released: %s\n", pkgname);
7527                                         ret = DBOX_STATUS_ERROR_FAULT;
7528                                         goto out;
7529                                 }
7530                         } /* else {
7531                                  @note
7532                                  This case means that the package is faulted so the service provider tries to release the buffer
7533                            */
7534
7535                         info = instance_gbar_buffer(inst);
7536                         ret = buffer_handler_unload(info);
7537
7538                         /**
7539                          * @note
7540                          * Send the GBAR destroyed event to the client
7541                          */
7542                         instance_client_gbar_destroyed(inst, ret);
7543                 }
7544                 }
7545
7546 out:
7547                 result = packet_create_reply(packet, "i", ret);
7548                 if (!result) {
7549                         ErrPrint("Failed to create a packet\n");
7550                 }
7551
7552                 return result;
7553         }
7554
7555         static struct packet *slave_release_extra_buffer(pid_t pid, int handle, const struct packet *packet)
7556         {
7557                 struct slave_node *slave;
7558                 struct packet *result;
7559                 const char *id;
7560                 struct buffer_info *info = NULL;
7561                 int ret;
7562                 int idx;
7563                 int type;
7564                 const char *pkgname;
7565                 struct inst_info *inst;
7566                 const struct pkg_info *pkg;
7567
7568                 slave = slave_find_by_pid(pid);
7569                 if (!slave) {
7570                         ErrPrint("Slave %d is not exists\n", pid);
7571                         ret = DBOX_STATUS_ERROR_NOT_EXIST;
7572                         goto out;
7573                 }
7574
7575                 if (packet_get(packet, "issi", &type, &pkgname, &id, &idx) != 4) {
7576                         ErrPrint("Inavlid argument\n");
7577                         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7578                         goto out;
7579                 }
7580
7581                 ret = validate_request(pkgname, id, &inst, &pkg);
7582                 if (ret != DBOX_STATUS_ERROR_NONE) {
7583                         goto out;
7584                 }
7585
7586                 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7587
7588                 if (type == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
7589                         info = instance_dbox_extra_buffer(inst, idx);
7590                         (void)instance_client_dbox_extra_buffer_destroyed(inst, idx);
7591                 } else if (type == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
7592                         info = instance_gbar_extra_buffer(inst, idx);
7593                         (void)instance_client_gbar_extra_buffer_destroyed(inst, idx);
7594                 }
7595
7596                 if (info) {
7597                         ret = buffer_handler_unload(info);
7598                 }
7599
7600 out:
7601                 result = packet_create_reply(packet, "i", ret);
7602                 if (!result) {
7603                         ErrPrint("Failed to create a reply packet\n");
7604                 }
7605
7606                 return result;
7607         }
7608
7609         static struct packet *service_instance_count(pid_t pid, int handle, const struct packet *packet)
7610         {
7611                 struct packet *result;
7612                 struct pkg_info *pkg;
7613                 double timestamp;
7614                 const char *pkgname;
7615                 const char *cluster;
7616                 const char *category;
7617                 Eina_List *pkg_list;
7618                 Eina_List *l;
7619                 Eina_List *inst_list;
7620                 Eina_List *inst_l;
7621                 struct inst_info *inst;
7622                 int ret;
7623
7624                 ret = packet_get(packet, "sssd", &pkgname, &cluster, &category, &timestamp);
7625                 if (ret != 4) {
7626                         ErrPrint("Invalid packet\n");
7627                         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7628                         goto out;
7629                 }
7630
7631                 pkg_list = (Eina_List *)package_list();
7632
7633                 ret = 0;
7634                 EINA_LIST_FOREACH(pkg_list, l, pkg) {
7635                         if (pkgname && pkgname[0]) {
7636                                 if (strcmp(package_name(pkg), pkgname)) {
7637                                         continue;
7638                                 }
7639                         }
7640
7641                         inst_list = package_instance_list(pkg);
7642                         EINA_LIST_FOREACH(inst_list, inst_l, inst) {
7643                                 if (cluster && cluster[0]) {
7644                                         if (strcmp(instance_cluster(inst), cluster)) {
7645                                                 continue;
7646                                         }
7647                                 }
7648
7649                                 if (category && category[0]) {
7650                                         if (strcmp(instance_category(inst), category)) {
7651                                                 continue;
7652                                         }
7653                                 }
7654
7655                                 ret++;
7656                         }
7657                 }
7658
7659 out:
7660                 result = packet_create_reply(packet, "i", ret);
7661                 if (!result) {
7662                         ErrPrint("Failed to create a packet\n");
7663                 }
7664
7665                 return result;
7666         }
7667
7668         static struct packet *service_change_period(pid_t pid, int handle, const struct packet *packet)
7669         {
7670                 struct inst_info *inst;
7671                 struct packet *result;
7672                 const char *pkgname;
7673                 const char *id;
7674                 double period;
7675                 int ret;
7676
7677                 ret = packet_get(packet, "ssd", &pkgname, &id, &period);
7678                 if (ret != 3) {
7679                         ErrPrint("Invalid packet\n");
7680                         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7681                         goto out;
7682                 }
7683
7684                 if (!strlen(id)) {
7685                         struct pkg_info *pkg;
7686
7687                         pkg = package_find(pkgname);
7688                         if (!pkg) {
7689                                 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7690                         } else if (package_is_fault(pkg)) {
7691                                 ret = DBOX_STATUS_ERROR_FAULT;
7692                         } else {
7693                                 Eina_List *inst_list;
7694                                 Eina_List *l;
7695
7696                                 inst_list = package_instance_list(pkg);
7697                                 EINA_LIST_FOREACH(inst_list, l, inst) {
7698                                         ret = instance_set_period(inst, period);
7699                                         if (ret < 0) {
7700                                                 ErrPrint("Failed to change the period of %s to (%lf)\n", pkgname, period);
7701                                         }
7702                                 }
7703                         }
7704                 } else {
7705                         ret = validate_request(pkgname, id, &inst, NULL);
7706                         if (ret == (int)DBOX_STATUS_ERROR_NONE) {
7707                                 if (instance_state(inst) == INST_DESTROYED) {
7708                                         ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
7709                                         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7710                                         goto out;
7711                                 }
7712
7713                                 ret = instance_set_period(inst, period);
7714                         }
7715                 }
7716
7717                 DbgPrint("Change the update period: %s, %lf : %d\n", pkgname, period, ret);
7718 out:
7719                 result = packet_create_reply(packet, "i", ret);
7720                 if (!result) {
7721                         ErrPrint("Failed to create a packet\n");
7722                 }
7723
7724                 return result;
7725         }
7726
7727         static struct packet *service_update(pid_t pid, int handle, const struct packet *packet)
7728         {
7729                 Eina_List *inst_list;
7730                 struct pkg_info *pkg;
7731                 struct packet *result;
7732                 const char *pkgname;
7733                 const char *id;
7734                 const char *cluster;
7735                 const char *category;
7736                 const char *content;
7737                 int force;
7738                 char *lbid;
7739                 int ret;
7740
7741                 ret = packet_get(packet, "sssssi", &pkgname, &id, &cluster, &category, &content, &force);
7742                 if (ret != 6) {
7743                         ErrPrint("Invalid Packet\n");
7744                         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7745                         goto out;
7746                 }
7747
7748                 lbid = package_dbox_pkgname(pkgname);
7749                 if (!lbid) {
7750                         ErrPrint("Invalid package %s\n", pkgname);
7751                         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7752                         goto out;
7753                 }
7754
7755                 pkg = package_find(lbid);
7756                 if (!pkg) {
7757                         ret = DBOX_STATUS_ERROR_NOT_EXIST;
7758                         DbgFree(lbid);
7759                         goto out;
7760                 }
7761
7762                 if (package_is_fault(pkg)) {
7763                         ret = DBOX_STATUS_ERROR_FAULT;
7764                         DbgFree(lbid);
7765                         goto out;
7766                 }
7767
7768                 inst_list = package_instance_list(pkg);
7769                 if (!eina_list_count(inst_list)) {
7770                         ret = DBOX_STATUS_ERROR_NOT_EXIST;
7771                         DbgFree(lbid);
7772                         goto out;
7773                 }
7774
7775                 if (id && strlen(id)) {
7776                         Eina_List *l;
7777                         struct inst_info *inst;
7778
7779                         ret = DBOX_STATUS_ERROR_NOT_EXIST;
7780                         EINA_LIST_FOREACH(inst_list, l, inst) {
7781                                 if (!strcmp(instance_id(inst), id)) {
7782                                         ret = DBOX_STATUS_ERROR_NONE;
7783                                         break;
7784                                 }
7785                         }
7786
7787                         if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST) {
7788                                 DbgFree(lbid);
7789                                 goto out;
7790                         }
7791                 }
7792
7793                 /*!
7794                  * \TODO
7795                  * Validate the update requstor.
7796                  */
7797                 slave_rpc_request_update(lbid, id, cluster, category, content, force);
7798                 DbgFree(lbid);
7799                 ret = DBOX_STATUS_ERROR_NONE;
7800
7801 out:
7802                 result = packet_create_reply(packet, "i", ret);
7803                 if (!result) {
7804                         ErrPrint("Failed to create a packet\n");
7805                 }
7806
7807                 return result;
7808         }
7809
7810         static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet *packet)
7811         {
7812                 struct liveinfo *info;
7813                 struct packet *result;
7814                 int ret;
7815                 const char *fifo_name;
7816                 double timestamp;
7817
7818                 DbgPrint("Request arrived from %d\n", pid);
7819
7820                 if (packet_get(packet, "d", &timestamp) != 1) {
7821                         ErrPrint("Invalid packet\n");
7822                         fifo_name = "";
7823                         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7824                         goto out;
7825                 }
7826
7827                 info = liveinfo_create(pid, handle);
7828                 if (!info) {
7829                         ErrPrint("Failed to create a liveinfo object\n");
7830                         fifo_name = "";
7831                         ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7832                         goto out;
7833                 }
7834
7835                 ret = 0;
7836                 fifo_name = liveinfo_filename(info);
7837                 DbgPrint("FIFO Created: %s (Serve for %d)\n", fifo_name, pid);
7838
7839 out:
7840                 result = packet_create_reply(packet, "si", fifo_name, ret);
7841                 if (!result) {
7842                         ErrPrint("Failed to create a result packet\n");
7843                 }
7844
7845                 return result;
7846         }
7847
7848         static Eina_Bool lazy_slave_list_cb(void *info)
7849         {
7850                 FILE *fp;
7851                 Eina_List *list;
7852                 Eina_List *l;
7853                 struct slave_node *slave;
7854
7855                 liveinfo_open_fifo(info);
7856                 fp = liveinfo_fifo(info);
7857                 if (!fp) {
7858                         liveinfo_close_fifo(info);
7859                         return ECORE_CALLBACK_CANCEL;
7860                 }
7861
7862                 list = (Eina_List *)slave_list();
7863                 EINA_LIST_FOREACH(list, l, slave) {
7864                         fprintf(fp, "%d %s %s %s %d %d %d %s %d %d %lf\n", 
7865                                         slave_pid(slave),
7866                                         slave_name(slave),
7867                                         slave_pkgname(slave),
7868                                         slave_abi(slave),
7869                                         slave_is_secured(slave),
7870                                         slave_refcnt(slave),
7871                                         slave_fault_count(slave),
7872                                         slave_state_string(slave),
7873                                         slave_loaded_instance(slave),
7874                                         slave_loaded_package(slave),
7875                                         slave_ttl(slave)
7876                                    );
7877                 }
7878
7879                 fprintf(fp, "EOD\n");
7880                 liveinfo_close_fifo(info);
7881                 return ECORE_CALLBACK_CANCEL;
7882         }
7883
7884         static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet)
7885         {
7886                 struct liveinfo *info;
7887                 double timestamp;
7888
7889                 if (packet_get(packet, "d", &timestamp) != 1) {
7890                         ErrPrint("Invalid argument\n");
7891                         goto out;
7892                 }
7893
7894                 info = liveinfo_find_by_pid(pid);
7895                 if (!info) {
7896                         ErrPrint("Invalid request\n");
7897                         goto out;
7898                 }
7899
7900                 lazy_slave_list_cb(info);
7901 out:
7902                 return NULL;
7903         }
7904
7905         static inline const char *visible_state_string(enum dynamicbox_visible_state state)
7906         {
7907                 switch (state) {
7908                 case DBOX_SHOW:
7909                         return "Show";
7910                 case DBOX_HIDE:
7911                         return "Hide";
7912                 case DBOX_HIDE_WITH_PAUSE:
7913                         return "Paused";
7914                 default:
7915                         break;
7916                 }
7917
7918                 return "Unknown";
7919         }
7920
7921         static Eina_Bool inst_list_cb(void *info)
7922         {
7923                 FILE *fp;
7924                 char *pkgname;
7925                 struct pkg_info *pkg;
7926                 Eina_List *l;
7927                 Eina_List *inst_list;
7928                 struct inst_info *inst;
7929
7930                 pkgname = liveinfo_data(info);
7931                 if (!pkgname) {
7932                         return ECORE_CALLBACK_CANCEL;
7933                 }
7934
7935                 liveinfo_open_fifo(info);
7936                 fp = liveinfo_fifo(info);
7937                 if (!fp) {
7938                         ErrPrint("Invalid fp\n");
7939                         liveinfo_close_fifo(info);
7940                         free(pkgname);
7941                         return ECORE_CALLBACK_CANCEL;
7942                 }
7943
7944                 if (!package_is_dbox_pkgname(pkgname)) {
7945                         ErrPrint("Invalid package name\n");
7946                         free(pkgname);
7947                         goto close_out;
7948                 }
7949
7950                 pkg = package_find(pkgname);
7951                 free(pkgname);
7952                 if (!pkg) {
7953                         ErrPrint("Package is not exists\n");
7954                         goto close_out;
7955                 }
7956
7957                 inst_list = package_instance_list(pkg);
7958                 EINA_LIST_FOREACH(inst_list, l, inst) {
7959                         fprintf(fp, "%s %s %s %s %lf %s %d %d\n",
7960                                         instance_id(inst),
7961                                         buffer_handler_id(instance_dbox_buffer(inst)),
7962                                         instance_cluster(inst),
7963                                         instance_category(inst),
7964                                         instance_period(inst),
7965                                         visible_state_string(instance_visible_state(inst)),
7966                                         instance_dbox_width(inst),
7967                                         instance_dbox_height(inst));
7968                 }
7969
7970 close_out:
7971                 fprintf(fp, "EOD\n");
7972                 liveinfo_close_fifo(info);
7973
7974                 return ECORE_CALLBACK_CANCEL;
7975         }
7976
7977         static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet)
7978         {
7979                 const char *pkgname;
7980                 char *dup_pkgname;
7981                 struct liveinfo *info;
7982
7983                 if (packet_get(packet, "s", &pkgname) != 1) {
7984                         ErrPrint("Invalid argument\n");
7985                         goto out;
7986                 }
7987
7988                 info = liveinfo_find_by_pid(pid);
7989                 if (!info) {
7990                         ErrPrint("Invalid request\n");
7991                         goto out;
7992                 }
7993
7994                 dup_pkgname = strdup(pkgname);
7995                 if (!dup_pkgname) {
7996                         ErrPrint("Invalid request\n");
7997                         goto out;
7998                 }
7999
8000                 liveinfo_set_data(info, dup_pkgname);
8001                 inst_list_cb(info);
8002
8003 out:
8004                 return NULL;
8005         }
8006
8007         static Eina_Bool pkg_list_cb(void *info)
8008         {
8009                 FILE *fp;
8010                 Eina_List *l;
8011                 Eina_List *list;
8012                 Eina_List *inst_list;
8013                 struct pkg_info *pkg;
8014                 struct slave_node *slave;
8015                 const char *slavename;
8016                 pid_t pid;
8017
8018                 liveinfo_open_fifo(info);
8019                 fp = liveinfo_fifo(info);
8020                 if (!fp) {
8021                         DbgPrint("Failed to open a pipe\n");
8022                         liveinfo_close_fifo(info);
8023                         return ECORE_CALLBACK_CANCEL;
8024                 }
8025
8026                 list = (Eina_List *)package_list();
8027                 EINA_LIST_FOREACH(list, l, pkg) {
8028                         slave = package_slave(pkg);
8029
8030                         if (slave) {
8031                                 slavename = slave_name(slave);
8032                                 pid = slave_pid(slave);
8033                         } else {
8034                                 pid = (pid_t)-1;
8035                                 slavename = "";
8036                         }
8037
8038                         inst_list = (Eina_List *)package_instance_list(pkg);
8039                         fprintf(fp, "%d %s %s %s %d %d %d\n",
8040                                         pid,
8041                                         strlen(slavename) ? slavename : "(none)",
8042                                         package_name(pkg),
8043                                         package_abi(pkg),
8044                                         package_refcnt(pkg),
8045                                         package_fault_count(pkg),
8046                                         eina_list_count(inst_list)
8047                                    );
8048                         DbgPrint("%d %s %s %s %d %d %d\n",
8049                                         pid,
8050                                         strlen(slavename) ? slavename : "(none)",
8051                                         package_name(pkg),
8052                                         package_abi(pkg),
8053                                         package_refcnt(pkg),
8054                                         package_fault_count(pkg),
8055                                         eina_list_count(inst_list)
8056                                         );
8057                 }
8058
8059                 fprintf(fp, "EOD\n");
8060                 DbgPrint("EOD\n");
8061                 liveinfo_close_fifo(info);
8062                 return ECORE_CALLBACK_CANCEL;
8063         }
8064
8065         static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet)
8066         {
8067                 struct liveinfo *info;
8068                 double timestamp;
8069
8070                 if (packet_get(packet, "d", &timestamp) != 1) {
8071                         ErrPrint("Invalid argument\n");
8072                         goto out;
8073                 }
8074
8075                 DbgPrint("Package List: %lf\n", timestamp);
8076
8077                 info = liveinfo_find_by_pid(pid);
8078                 if (!info) {
8079                         ErrPrint("Invalid request\n");
8080                         goto out;
8081                 }
8082
8083                 pkg_list_cb(info);
8084 out:
8085                 return NULL;
8086         }
8087
8088         static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct packet *packet)
8089         {
8090                 return NULL;
8091         }
8092
8093         static Eina_Bool pkg_ctrl_rmpack_cb(void *info)
8094         {
8095                 FILE *fp;
8096                 liveinfo_open_fifo(info);
8097                 fp = liveinfo_fifo(info);
8098                 if (!fp) {
8099                         liveinfo_close_fifo(info);
8100                         return ECORE_CALLBACK_CANCEL;
8101                 }
8102
8103                 fprintf(fp, "%d\n", ENOSYS);
8104                 fprintf(fp, "EOD\n");
8105                 liveinfo_close_fifo(info);
8106                 return ECORE_CALLBACK_CANCEL;
8107         }
8108
8109         static Eina_Bool pkg_ctrl_rminst_cb(void *info)
8110         {
8111                 FILE *fp;
8112
8113                 liveinfo_open_fifo(info);
8114                 fp = liveinfo_fifo(info);
8115                 if (!fp) {
8116                         liveinfo_close_fifo(info);
8117                         return ECORE_CALLBACK_CANCEL;
8118                 }
8119
8120                 fprintf(fp, "%d\n", (int)liveinfo_data(info));
8121                 fprintf(fp, "EOD\n");
8122                 liveinfo_close_fifo(info);
8123                 return ECORE_CALLBACK_CANCEL;
8124         }
8125
8126         static Eina_Bool pkg_ctrl_faultinst_cb(void *info)
8127         {
8128                 FILE *fp;
8129
8130                 liveinfo_open_fifo(info);
8131                 fp = liveinfo_fifo(info);
8132                 if (!fp) {
8133                         liveinfo_close_fifo(info);
8134                         return ECORE_CALLBACK_CANCEL;
8135                 }
8136
8137                 fprintf(fp, "%d\n", (int)liveinfo_data(info));
8138                 fprintf(fp, "EOD\n");
8139                 liveinfo_close_fifo(info);
8140                 return ECORE_CALLBACK_CANCEL;
8141         }
8142
8143         static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet)
8144         {
8145                 struct liveinfo *info;
8146                 char *cmd;
8147                 char *pkgname;
8148                 char *id;
8149
8150                 if (packet_get(packet, "sss", &cmd, &pkgname, &id) != 3) {
8151                         ErrPrint("Invalid argument\n");
8152                         goto out;
8153                 }
8154
8155                 info = liveinfo_find_by_pid(pid);
8156                 if (!info) {
8157                         ErrPrint("Invalid request\n");
8158                         goto out;
8159                 }
8160
8161                 if (!strcmp(cmd, "rmpack")) {
8162                         pkg_ctrl_rmpack_cb(info);
8163                 } else if (!strcmp(cmd, "rminst")) {
8164                         struct inst_info *inst;
8165                         inst = package_find_instance_by_id(pkgname, id);
8166                         if (!inst) {
8167                                 liveinfo_set_data(info, (void *)ENOENT);
8168                         } else {
8169                                 (void)instance_destroy(inst, DBOX_DESTROY_TYPE_DEFAULT);
8170                                 liveinfo_set_data(info, (void *)0);
8171                         }
8172
8173                         pkg_ctrl_rminst_cb(info);
8174                 } else if (!strcmp(cmd, "faultinst")) {
8175                         struct inst_info *inst;
8176                         inst = package_find_instance_by_id(pkgname, id);
8177                         if (!inst) {
8178                                 liveinfo_set_data(info, (void *)ENOENT);
8179                         } else {
8180                                 struct pkg_info *pkg;
8181
8182                                 pkg = instance_package(inst);
8183                                 if (!pkg) {
8184                                         liveinfo_set_data(info, (void *)EFAULT);
8185                                 } else {
8186                                         (void)package_faulted(pkg, 1);
8187                                         liveinfo_set_data(info, (void *)0);
8188                                 }
8189                         }
8190
8191                         pkg_ctrl_faultinst_cb(info);
8192                 }
8193
8194 out:
8195                 return NULL;
8196         }
8197
8198         static Eina_Bool master_ctrl_cb(void *info)
8199         {
8200                 FILE *fp;
8201
8202                 liveinfo_open_fifo(info);
8203                 fp = liveinfo_fifo(info);
8204                 if (!fp) {
8205                         liveinfo_close_fifo(info);
8206                         return ECORE_CALLBACK_CANCEL;
8207                 }
8208                 fprintf(fp, "%d\nEOD\n", (int)liveinfo_data(info));
8209                 liveinfo_close_fifo(info);
8210
8211                 return ECORE_CALLBACK_CANCEL;
8212         }
8213
8214         static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct packet *packet)
8215         {
8216                 struct liveinfo *info;
8217                 char *cmd;
8218                 char *var;
8219                 char *val;
8220                 int ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
8221
8222                 if (packet_get(packet, "sss", &cmd, &var, &val) != 3) {
8223                         ErrPrint("Invalid argument\n");
8224                         goto out;
8225                 }
8226
8227                 info = liveinfo_find_by_pid(pid);
8228                 if (!info) {
8229                         ErrPrint("Invalid request\n");
8230                         goto out;
8231                 }
8232
8233                 if (!strcasecmp(var, "debug")) {
8234                         if (!strcasecmp(cmd, "set")) {
8235                                 g_conf.debug_mode = !strcasecmp(val, "on");
8236                         } else if (!strcasecmp(cmd, "get")) {
8237                         }
8238                         ret = g_conf.debug_mode;
8239                 } else if (!strcasecmp(var, "slave_max_load")) {
8240                         if (!strcasecmp(cmd, "set")) {
8241                                 g_conf.slave_max_load = atoi(val);
8242                         } else if (!strcasecmp(cmd, "get")) {
8243                         }
8244                         ret = g_conf.slave_max_load;
8245                 }
8246
8247                 liveinfo_set_data(info, (void *)ret);
8248                 master_ctrl_cb(info);
8249
8250 out:
8251                 return NULL;
8252         }
8253
8254         static struct method s_info_table[] = {
8255                 {
8256                         .cmd = CMD_STR_INFO_HELLO,
8257                         .handler = liveinfo_hello,
8258                 },
8259                 {
8260                         .cmd = CMD_STR_INFO_SLAVE_LIST,
8261                         .handler = liveinfo_slave_list,
8262                 },
8263                 {
8264                         .cmd = CMD_STR_INFO_PKG_LIST,
8265                         .handler = liveinfo_pkg_list,
8266                 },
8267                 {
8268                         .cmd = CMD_STR_INFO_INST_LIST,
8269                         .handler = liveinfo_inst_list,
8270                 },
8271                 {
8272                         .cmd = CMD_STR_INFO_SLAVE_CTRL,
8273                         .handler = liveinfo_slave_ctrl,
8274                 },
8275                 {
8276                         .cmd = CMD_STR_INFO_PKG_CTRL,
8277                         .handler = liveinfo_pkg_ctrl,
8278                 },
8279                 {
8280                         .cmd = CMD_STR_INFO_MASTER_CTRL,
8281                         .handler = liveinfo_master_ctrl,
8282                 },
8283                 {
8284                         .cmd = NULL,
8285                         .handler = NULL,
8286                 },
8287         };
8288
8289         static struct method s_client_table[] = {
8290                 {
8291                         .cmd = CMD_STR_GBAR_MOUSE_MOVE,
8292                         .handler = client_gbar_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8293                 },
8294                 {
8295                         .cmd = CMD_STR_DBOX_MOUSE_MOVE,
8296                         .handler = client_dbox_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8297                 },
8298                 {
8299                         .cmd = CMD_STR_GBAR_MOUSE_DOWN,
8300                         .handler = client_gbar_mouse_down, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
8301                 },
8302                 {
8303                         .cmd = CMD_STR_GBAR_MOUSE_UP,
8304                         .handler = client_gbar_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8305                 },
8306                 {
8307                         .cmd = CMD_STR_DBOX_MOUSE_DOWN,
8308                         .handler = client_dbox_mouse_down, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8309                 },
8310                 {
8311                         .cmd = CMD_STR_DBOX_MOUSE_UP,
8312                         .handler = client_dbox_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8313                 },
8314                 {
8315                         .cmd = CMD_STR_GBAR_MOUSE_ENTER,
8316                         .handler = client_gbar_mouse_enter, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
8317                 },
8318                 {
8319                         .cmd = CMD_STR_GBAR_MOUSE_LEAVE,
8320                         .handler = client_gbar_mouse_leave, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
8321                 },
8322                 {
8323                         .cmd = CMD_STR_DBOX_MOUSE_ENTER,
8324                         .handler = client_dbox_mouse_enter, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8325                 },
8326                 {
8327                         .cmd = CMD_STR_DBOX_MOUSE_LEAVE,
8328                         .handler = client_dbox_mouse_leave, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8329                 },
8330                 {
8331                         .cmd = CMD_STR_DBOX_MOUSE_ON_SCROLL,
8332                         .handler = client_dbox_mouse_on_scroll,
8333                 },
8334                 {
8335                         .cmd = CMD_STR_DBOX_MOUSE_OFF_SCROLL,
8336                         .handler = client_dbox_mouse_off_scroll,
8337                 },
8338                 {
8339                         .cmd = CMD_STR_GBAR_MOUSE_ON_SCROLL,
8340                         .handler = client_gbar_mouse_on_scroll,
8341                 },
8342                 {
8343                         .cmd = CMD_STR_GBAR_MOUSE_OFF_SCROLL,
8344                         .handler = client_gbar_mouse_off_scroll,
8345                 },
8346                 {
8347                         .cmd = CMD_STR_DBOX_MOUSE_ON_HOLD,
8348                         .handler = client_dbox_mouse_on_hold,
8349                 },
8350                 {
8351                         .cmd = CMD_STR_DBOX_MOUSE_OFF_HOLD,
8352                         .handler = client_dbox_mouse_off_hold,
8353                 },
8354                 {
8355                         .cmd = CMD_STR_GBAR_MOUSE_ON_HOLD,
8356                         .handler = client_gbar_mouse_on_hold,
8357                 },
8358                 {
8359                         .cmd = CMD_STR_GBAR_MOUSE_OFF_HOLD,
8360                         .handler = client_gbar_mouse_off_hold,
8361                 },
8362                 {
8363                         .cmd = CMD_STR_CLICKED,
8364                         .handler = client_clicked, /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
8365                 },
8366                 {
8367                         .cmd = CMD_STR_TEXT_SIGNAL,
8368                         .handler = client_text_signal, /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
8369                 },
8370                 {
8371                         .cmd = CMD_STR_DELETE,
8372                         .handler = client_delete, /* pid, pkgname, filename, ret */
8373                 },
8374                 {
8375                         .cmd = CMD_STR_RESIZE,
8376                         .handler = client_resize, /* pid, pkgname, filename, w, h, ret */
8377                 },
8378                 {
8379                         .cmd = CMD_STR_NEW,
8380                         .handler = client_new, /* pid, timestamp, pkgname, content, cluster, category, period, ret */
8381                 },
8382                 {
8383                         .cmd = CMD_STR_SET_PERIOD,
8384                         .handler = client_set_period, /* pid, pkgname, filename, period, ret, period */
8385                 },
8386                 {
8387                         .cmd = CMD_STR_CHANGE_GROUP,
8388                         .handler = client_change_group, /* pid, pkgname, filename, cluster, category, ret */
8389                 },
8390                 {
8391                         .cmd = CMD_STR_GBAR_MOVE,
8392                         .handler = client_gbar_move, /* pkgname, id, x, y */
8393                 },
8394                 {
8395                         .cmd = CMD_STR_GBAR_ACCESS_HL,
8396                         .handler = client_gbar_access_hl,
8397                 },
8398                 {
8399                         .cmd = CMD_STR_GBAR_ACCESS_ACTIVATE,
8400                         .handler = client_gbar_access_activate,
8401                 },
8402                 {
8403                         .cmd = CMD_STR_GBAR_ACCESS_ACTION,
8404                         .handler = client_gbar_access_action,
8405                 },
8406                 {
8407                         .cmd = CMD_STR_GBAR_ACCESS_SCROLL,
8408                         .handler = client_gbar_access_scroll,
8409                 },
8410                 {
8411                         .cmd = CMD_STR_GBAR_ACCESS_VALUE_CHANGE,
8412                         .handler = client_gbar_access_value_change,
8413                 },
8414                 {
8415                         .cmd = CMD_STR_GBAR_ACCESS_MOUSE,
8416                         .handler = client_gbar_access_mouse,
8417                 },
8418                 {
8419                         .cmd = CMD_STR_GBAR_ACCESS_BACK,
8420                         .handler = client_gbar_access_back,
8421                 },
8422                 {
8423                         .cmd = CMD_STR_GBAR_ACCESS_OVER,
8424                         .handler = client_gbar_access_over,
8425                 },
8426                 {
8427                         .cmd = CMD_STR_GBAR_ACCESS_READ,
8428                         .handler = client_gbar_access_read,
8429                 },
8430                 {
8431                         .cmd = CMD_STR_GBAR_ACCESS_ENABLE,
8432                         .handler = client_gbar_access_enable,
8433                 },
8434
8435                 {
8436                         .cmd = CMD_STR_DBOX_ACCESS_HL,
8437                         .handler = client_dbox_access_hl,
8438                 },
8439                 {
8440                         .cmd = CMD_STR_DBOX_ACCESS_ACTIVATE,
8441                         .handler = client_dbox_access_activate,
8442                 },
8443                 {
8444                         .cmd = CMD_STR_DBOX_ACCESS_ACTION,
8445                         .handler = client_dbox_access_action,
8446                 },
8447                 {
8448                         .cmd = CMD_STR_DBOX_ACCESS_SCROLL,
8449                         .handler = client_dbox_access_scroll,
8450                 },
8451                 {
8452                         .cmd = CMD_STR_DBOX_ACCESS_VALUE_CHANGE,
8453                         .handler = client_dbox_access_value_change,
8454                 },
8455                 {
8456                         .cmd = CMD_STR_DBOX_ACCESS_MOUSE,
8457                         .handler = client_dbox_access_mouse,
8458                 },
8459                 {
8460                         .cmd = CMD_STR_DBOX_ACCESS_BACK,
8461                         .handler = client_dbox_access_back,
8462                 },
8463                 {
8464                         .cmd = CMD_STR_DBOX_ACCESS_OVER,
8465                         .handler = client_dbox_access_over,
8466                 },
8467                 {
8468                         .cmd = CMD_STR_DBOX_ACCESS_READ,
8469                         .handler = client_dbox_access_read,
8470                 },
8471                 {
8472                         .cmd = CMD_STR_DBOX_ACCESS_ENABLE,
8473                         .handler = client_dbox_access_enable,
8474                 },
8475                 {
8476                         .cmd = CMD_STR_DBOX_KEY_DOWN,
8477                         .handler = client_dbox_key_down,
8478                 },
8479                 {
8480                         .cmd = CMD_STR_DBOX_KEY_UP,
8481                         .handler = client_dbox_key_up,
8482                 },
8483                 {
8484                         .cmd = CMD_STR_DBOX_KEY_FOCUS_IN,
8485                         .handler = client_dbox_key_focus_in,
8486                 },
8487                 {
8488                         .cmd = CMD_STR_DBOX_KEY_FOCUS_OUT,
8489                         .handler = client_dbox_key_focus_out,
8490                 },
8491                 {
8492                         .cmd = CMD_STR_GBAR_KEY_DOWN,
8493                         .handler = client_gbar_key_down,
8494                 },
8495                 {
8496                         .cmd = CMD_STR_GBAR_KEY_UP,
8497                         .handler = client_gbar_key_up,
8498                 },
8499                 {
8500                         .cmd = CMD_STR_GBAR_KEY_FOCUS_IN,
8501                         .handler = client_gbar_key_focus_in,
8502                 },
8503                 {
8504                         .cmd = CMD_STR_GBAR_KEY_FOCUS_OUT,
8505                         .handler = client_gbar_key_focus_out,
8506                 },
8507                 {
8508                         .cmd = CMD_STR_UPDATE_MODE,
8509                         .handler = client_update_mode,
8510                 },
8511                 // Cut HERE. Above list must be sync'd with provider list.
8512
8513                 {
8514                         .cmd = CMD_STR_DBOX_MOUSE_SET,
8515                         .handler = client_dbox_mouse_set,
8516                 },
8517                 {
8518                         .cmd = CMD_STR_DBOX_MOUSE_UNSET,
8519                         .handler = client_dbox_mouse_unset,
8520                 },
8521                 {
8522                         .cmd = CMD_STR_GBAR_MOUSE_SET,
8523                         .handler = client_gbar_mouse_set,
8524                 },
8525                 {
8526                         .cmd = CMD_STR_GBAR_MOUSE_UNSET,
8527                         .handler = client_gbar_mouse_unset,
8528                 },
8529                 {
8530                         .cmd = CMD_STR_CHANGE_VISIBILITY,
8531                         .handler = client_change_visibility,
8532                 },
8533                 {
8534                         .cmd = CMD_STR_DBOX_ACQUIRE_PIXMAP,
8535                         .handler = client_dbox_acquire_pixmap,
8536                 },
8537                 {
8538                         .cmd = CMD_STR_DBOX_RELEASE_PIXMAP,
8539                         .handler = client_dbox_release_pixmap,
8540                 },
8541                 {
8542                         .cmd = CMD_STR_GBAR_ACQUIRE_PIXMAP,
8543                         .handler = client_gbar_acquire_pixmap,
8544                 },
8545                 {
8546                         .cmd = CMD_STR_GBAR_RELEASE_PIXMAP,
8547                         .handler = client_gbar_release_pixmap,
8548                 },
8549                 {
8550                         .cmd = CMD_STR_ACQUIRE,
8551                         .handler = client_acquire, /*!< pid, ret */
8552                 },
8553                 {
8554                         .cmd = CMD_STR_RELEASE,
8555                         .handler = cilent_release, /*!< pid, ret */
8556                 },
8557                 {
8558                         .cmd = CMD_STR_PINUP_CHANGED,
8559                         .handler = client_pinup_changed, /* pid, pkgname, filename, pinup, ret */
8560                 },
8561                 {
8562                         .cmd = CMD_STR_CREATE_GBAR,
8563                         .handler = client_create_gbar, /* pid, pkgname, filename, ret */
8564                 },
8565                 {
8566                         .cmd = CMD_STR_DESTROY_GBAR,
8567                         .handler = client_destroy_gbar, /* pid, pkgname, filename, ret */
8568                 },
8569                 {
8570                         .cmd = CMD_STR_ACTIVATE_PACKAGE,
8571                         .handler = client_activate_package, /* pid, pkgname, ret */
8572                 },
8573                 {
8574                         .cmd = CMD_STR_SUBSCRIBE, /* pid, cluster, sub-cluster */
8575                         .handler = client_subscribed,
8576                 },
8577                 {
8578                         .cmd = CMD_STR_UNSUBSCRIBE, /* pid, cluster, sub-cluster */
8579                         .handler = client_unsubscribed,
8580                 },
8581                 {
8582                         .cmd = CMD_STR_DELETE_CLUSTER,
8583                         .handler = client_delete_cluster,
8584                 },
8585                 {
8586                         .cmd = CMD_STR_DELETE_CATEGORY,
8587                         .handler = client_delete_category,
8588                 },
8589                 {
8590                         .cmd = CMD_STR_REFRESH_GROUP,
8591                         .handler = client_refresh_group,
8592                 },
8593                 {
8594                         .cmd = CMD_STR_UPDATE,
8595                         .handler = client_update,
8596                 },
8597
8598                 {
8599                         .cmd = CMD_STR_DBOX_KEY_SET,
8600                         .handler = client_dbox_key_set,
8601                 },
8602                 {
8603                         .cmd = CMD_STR_DBOX_KEY_UNSET,
8604                         .handler = client_dbox_key_unset,
8605                 },
8606
8607                 {
8608                         .cmd = CMD_STR_GBAR_KEY_SET,
8609                         .handler = client_gbar_key_set,
8610                 },
8611                 {
8612                         .cmd = CMD_STR_GBAR_KEY_UNSET,
8613                         .handler = client_gbar_key_unset,
8614                 },
8615
8616                 {
8617                         .cmd = CMD_STR_CLIENT_PAUSED,
8618                         .handler = client_pause_request,
8619                 },
8620                 {
8621                         .cmd = CMD_STR_CLIENT_RESUMED,
8622                         .handler = client_resume_request,
8623                 },
8624                 {
8625                         .cmd = CMD_STR_DBOX_ACQUIRE_XPIXMAP,
8626                         .handler = client_dbox_acquire_xpixmap,
8627                 },
8628                 {
8629                         .cmd = CMD_STR_GBAR_ACQUIRE_XPIXMAP,
8630                         .handler = client_gbar_acquire_xpixmap,
8631                 },
8632
8633                 {
8634                         .cmd = NULL,
8635                         .handler = NULL,
8636                 },
8637         };
8638
8639         static struct method s_service_table[] = {
8640                 {
8641                         .cmd = CMD_STR_SERVICE_UPDATE,
8642                         .handler = service_update,
8643                 },
8644                 {
8645                         .cmd = CMD_STR_SERVICE_CHANGE_PERIOD,
8646                         .handler = service_change_period,
8647                 },
8648                 {
8649                         .cmd = CMD_STR_SERVICE_INST_CNT,
8650                         .handler = service_instance_count,
8651                 },
8652                 {
8653                         .cmd = NULL,
8654                         .handler = NULL,
8655                 },
8656         };
8657
8658         static struct method s_slave_table[] = {
8659                 {
8660                         .cmd = CMD_STR_UPDATED,
8661                         .handler = slave_updated, /* slave_name, pkgname, filename, width, height, ret */
8662                 },
8663                 {
8664                         .cmd = CMD_STR_DESC_UPDATED,
8665                         .handler = slave_desc_updated, /* slave_name, pkgname, filename, decsfile, ret */
8666                 },
8667                 {
8668                         .cmd = CMD_STR_EXTRA_UPDATED,
8669                         .handler = slave_extra_updated,
8670                 },
8671                 {
8672                         .cmd = CMD_STR_EXTRA_INFO,
8673                         .handler = slave_extra_info, /* slave_name, pkgname, filename, priority, content_info, title, icon, name */
8674                 },
8675                 {
8676                         .cmd = CMD_STR_DELETED,
8677                         .handler = slave_deleted, /* slave_name, pkgname, filename, ret */
8678                 },
8679                 {
8680                         .cmd = CMD_STR_FAULTED,
8681                         .handler = slave_faulted, /* slave_name, pkgname, id, funcname */
8682                 },
8683                 {
8684                         .cmd = CMD_STR_SCROLL,
8685                         .handler = slave_hold_scroll, /* slave_name, pkgname, id, seize */
8686                 },
8687
8688                 {
8689                         .cmd = CMD_STR_DBOX_UPDATE_BEGIN,
8690                         .handler = slave_dbox_update_begin,
8691                 },
8692                 {
8693                         .cmd = CMD_STR_DBOX_UPDATE_END,
8694                         .handler = slave_dbox_update_end,
8695                 },
8696                 {
8697                         .cmd = CMD_STR_GBAR_UPDATE_BEGIN,
8698                         .handler = slave_gbar_update_begin,
8699                 },
8700                 {
8701                         .cmd = CMD_STR_GBAR_UPDATE_END,
8702                         .handler = slave_gbar_update_end,
8703                 },
8704
8705                 {
8706                         .cmd = CMD_STR_ACCESS_STATUS,
8707                         .handler = slave_access_status,
8708                 },
8709                 {
8710                         .cmd = CMD_STR_KEY_STATUS,
8711                         .handler = slave_key_status,
8712                 },
8713                 {
8714                         .cmd = CMD_STR_CLOSE_GBAR,
8715                         .handler = slave_close_gbar,
8716                 },
8717
8718                 {
8719                         .cmd = CMD_STR_CALL,
8720                         .handler = slave_call, /* slave_name, pkgname, filename, function, ret */
8721                 },
8722                 {
8723                         .cmd = CMD_STR_RET,
8724                         .handler = slave_ret, /* slave_name, pkgname, filename, function, ret */
8725                 },
8726                 {
8727                         .cmd = CMD_STR_ACQUIRE_BUFFER,
8728                         .handler = slave_acquire_buffer, /* slave_name, id, w, h, size, - out - type, shmid */
8729                 },
8730                 {
8731                         .cmd = CMD_STR_RESIZE_BUFFER,
8732                         .handler = slave_resize_buffer,
8733                 },
8734                 {
8735                         .cmd = CMD_STR_RELEASE_BUFFER,
8736                         .handler = slave_release_buffer, /* slave_name, id - ret */
8737                 },
8738                 {
8739                         .cmd = CMD_STR_HELLO,
8740                         .handler = slave_hello, /* slave_name, ret */
8741                 },
8742                 {
8743                         .cmd = CMD_STR_PING,
8744                         .handler = slave_ping, /* slave_name, ret */
8745                 },
8746                 {
8747                         .cmd = CMD_STR_CTRL,
8748                         .handler = slave_ctrl, /* control bits */
8749                 },
8750
8751                 {
8752                         .cmd = CMD_STR_ACQUIRE_XBUFFER,
8753                         .handler = slave_acquire_extra_buffer,
8754                 },
8755                 {
8756                         .cmd = CMD_STR_RELEASE_XBUFFER,
8757                         .handler = slave_release_extra_buffer,
8758                 },
8759
8760                 {
8761                         .cmd = NULL,
8762                         .handler = NULL,
8763                 },
8764         };
8765
8766         HAPI int server_init(void)
8767         {
8768                 com_core_packet_use_thread(DYNAMICBOX_CONF_COM_CORE_THREAD);
8769
8770                 if (unlink(INFO_SOCKET) < 0) {
8771                         ErrPrint("info socket: %s\n", strerror(errno));
8772                 }
8773
8774                 if (unlink(SLAVE_SOCKET) < 0) {
8775                         ErrPrint("slave socket: %s\n", strerror(errno));
8776                 }
8777
8778                 if (unlink(CLIENT_SOCKET) < 0) {
8779                         ErrPrint("client socket: %s\n", strerror(errno));
8780                 }
8781
8782                 if (unlink(SERVICE_SOCKET) < 0) {
8783                         ErrPrint("service socket: %s\n", strerror(errno));
8784                 }
8785
8786                 s_info.info_fd = com_core_packet_server_init(INFO_SOCKET, s_info_table);
8787                 if (s_info.info_fd < 0) {
8788                         ErrPrint("Failed to create a info socket\n");
8789                 }
8790
8791                 s_info.slave_fd = com_core_packet_server_init(SLAVE_SOCKET, s_slave_table);
8792                 if (s_info.slave_fd < 0) {
8793                         ErrPrint("Failed to create a slave socket\n");
8794                 }
8795
8796                 smack_fsetlabel(s_info.slave_fd, "data-provider-master::provider", SMACK_LABEL_IPIN);
8797                 smack_fsetlabel(s_info.slave_fd, "data-provider-master::provider", SMACK_LABEL_IPOUT);
8798
8799                 s_info.client_fd = com_core_packet_server_init(CLIENT_SOCKET, s_client_table);
8800                 if (s_info.client_fd < 0) {
8801                         ErrPrint("Failed to create a client socket\n");
8802                 }
8803
8804                 smack_fsetlabel(s_info.client_fd, "data-provider-master::client", SMACK_LABEL_IPIN);
8805                 smack_fsetlabel(s_info.client_fd, "data-provider-master::client", SMACK_LABEL_IPOUT);
8806
8807                 /*!
8808                  * \note
8809                  * remote://:8208
8810                  * Skip address to use the NULL.
8811                  */
8812                 s_info.remote_client_fd = com_core_packet_server_init("remote://:"CLIENT_PORT, s_client_table);
8813                 if (s_info.client_fd < 0) {
8814                         ErrPrint("Failed to create a remote client socket\n");
8815                 }
8816
8817                 smack_fsetlabel(s_info.remote_client_fd, "data-provider-master::client", SMACK_LABEL_IPIN);
8818                 smack_fsetlabel(s_info.remote_client_fd, "data-provider-master::client", SMACK_LABEL_IPOUT);
8819
8820                 s_info.service_fd = com_core_packet_server_init(SERVICE_SOCKET, s_service_table);
8821                 if (s_info.service_fd < 0) {
8822                         ErrPrint("Faild to create a service socket\n");
8823                 }
8824
8825                 smack_fsetlabel(s_info.service_fd, "data-provider-master", SMACK_LABEL_IPIN);
8826                 smack_fsetlabel(s_info.service_fd, "data-provider-master", SMACK_LABEL_IPOUT);
8827
8828                 if (chmod(INFO_SOCKET, 0600) < 0) {
8829                         ErrPrint("info socket: %s\n", strerror(errno));
8830                 }
8831
8832                 if (chmod(SLAVE_SOCKET, 0666) < 0) {
8833                         ErrPrint("slave socket: %s\n", strerror(errno));
8834                 }
8835
8836                 if (chmod(CLIENT_SOCKET, 0666) < 0) {
8837                         ErrPrint("client socket: %s\n", strerror(errno));
8838                 }
8839
8840                 if (chmod(SERVICE_SOCKET, 0666) < 0) {
8841                         ErrPrint("service socket: %s\n", strerror(errno));
8842                 }
8843
8844                 return 0;
8845         }
8846
8847         HAPI int server_fini(void)
8848         {
8849                 if (s_info.info_fd > 0) {
8850                         com_core_packet_server_fini(s_info.info_fd);
8851                         s_info.info_fd = -1;
8852                 }
8853
8854                 if (s_info.slave_fd > 0) {
8855                         com_core_packet_server_fini(s_info.slave_fd);
8856                         s_info.slave_fd = -1;
8857                 }
8858
8859                 if (s_info.client_fd > 0) {
8860                         com_core_packet_server_fini(s_info.client_fd);
8861                         s_info.client_fd = -1;
8862                 }
8863
8864                 if (s_info.remote_client_fd > 0) {
8865                         com_core_packet_server_fini(s_info.remote_client_fd);
8866                         s_info.remote_client_fd = -1;
8867                 }
8868
8869                 if (s_info.service_fd > 0) {
8870                         com_core_packet_server_fini(s_info.service_fd);
8871                         s_info.service_fd = -1;
8872                 }
8873
8874                 return 0;
8875         }
8876
8877         /* End of a file */