Add new accessibilty events & fixed prevent issues
[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.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.tizenopensource.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 <dlog.h>
22 #include <Evas.h>
23 #include <Ecore_Evas.h> /* fb.h */
24 #include <aul.h>
25 #include <Ecore.h>
26
27 #include <packet.h>
28 #include <com-core_packet.h>
29 #include <livebox-errno.h>
30 #include <livebox-service.h>
31
32 #include "conf.h"
33 #include "debug.h"
34 #include "server.h"
35 #include "slave_life.h"
36 #include "slave_rpc.h"
37 #include "client_life.h"
38 #include "instance.h"
39 #include "client_rpc.h"
40 #include "package.h"
41 #include "script_handler.h"
42 #include "buffer_handler.h"
43 #include "util.h"
44 #include "fault_manager.h"
45 #include "fb.h" /* fb_type */
46 #include "group.h"
47 #include "xmonitor.h"
48 #include "abi.h"
49 #include "liveinfo.h"
50 #include "io.h"
51 #include "event.h"
52
53 static struct info {
54         int info_fd;
55         int client_fd;
56         int service_fd;
57         int slave_fd;
58 } s_info = {
59         .info_fd = -1,
60         .client_fd = -1,
61         .service_fd = -1,
62         .slave_fd = -1,
63 };
64
65 /* Share this with provider */
66 enum target_type {
67         TYPE_LB,
68         TYPE_PD,
69         TYPE_ERROR,
70 };
71
72 struct access_cbdata {
73         int status;
74         struct inst_info *inst;
75 };
76
77 struct deleted_item {
78         struct client_node *client;
79         struct inst_info *inst;
80 };
81
82 static Eina_Bool lazy_access_status_cb(void *data)
83 {
84         struct access_cbdata *cbdata = data;
85
86         if (instance_unref(cbdata->inst)) {
87                 instance_send_access_status(cbdata->inst, cbdata->status);
88         } else {
89                 DbgPrint("Skip sending access status (%d)\n", cbdata->status);
90         }
91         /*!
92          * If instance_unref returns NULL,
93          * The instance is destroyed. it means, we don't need to send event to the viewer
94          */
95         free(cbdata);
96         return ECORE_CALLBACK_CANCEL;
97 }
98
99 static int event_lb_route_cb(enum event_state state, struct event_data *event_info, void *data)
100 {
101         struct inst_info *inst = data;
102         const struct pkg_info *pkg;
103         struct slave_node *slave;
104         struct packet *packet;
105         const char *cmdstr;
106
107         pkg = instance_package(inst);
108         if (!pkg)
109                 return LB_STATUS_ERROR_INVALID;
110
111         slave = package_slave(pkg);
112         if (!slave)
113                 return LB_STATUS_ERROR_INVALID;
114
115         switch (state) {
116         case EVENT_STATE_ACTIVATE:
117                 cmdstr = "lb_mouse_down";
118                 break;
119         case EVENT_STATE_ACTIVATED:
120                 cmdstr = "lb_mouse_move";
121                 break;
122         case EVENT_STATE_DEACTIVATE:
123                 cmdstr = "lb_mouse_up";
124                 break;
125         default:
126                 return LB_STATUS_ERROR_INVALID;
127         }
128
129         packet = packet_create_noack(cmdstr, "ssdii", package_name(pkg), instance_id(inst), util_timestamp(), event_info->x, event_info->y);
130         if (!packet)
131                 return LB_STATUS_ERROR_FAULT;
132
133         return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
134 }
135
136 static int event_lb_consume_cb(enum event_state state, struct event_data *event_info, void *data)
137 {
138         struct script_info *script;
139         struct inst_info *inst = data;
140         const struct pkg_info *pkg;
141         double timestamp;
142         Evas *e;
143
144         pkg = instance_package(inst);
145         if (!pkg)
146                 return 0;
147
148         script = instance_lb_script(inst);
149         if (!script)
150                 return LB_STATUS_ERROR_FAULT;
151
152         e = script_handler_evas(script);
153         if (!e)
154                 return LB_STATUS_ERROR_FAULT;
155
156         timestamp = util_timestamp();
157
158         switch (state) {
159         case EVENT_STATE_ACTIVATE:
160                 script_handler_update_pointer(script, event_info->x, event_info->y, 1);
161                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
162                 break;
163         case EVENT_STATE_ACTIVATED:
164                 script_handler_update_pointer(script, event_info->x, event_info->y, -1);
165                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
166                 break;
167         case EVENT_STATE_DEACTIVATE:
168                 script_handler_update_pointer(script, event_info->x, event_info->y, 0);
169                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
170                 break;
171         default:
172                 break;
173         }
174
175         return 0;
176 }
177
178 static int event_pd_route_cb(enum event_state state, struct event_data *event_info, void *data)
179 {
180         struct inst_info *inst = data;
181         const struct pkg_info *pkg;
182         struct slave_node *slave;
183         struct packet *packet;
184         const char *cmdstr;
185
186         pkg = instance_package(inst);
187         if (!pkg)
188                 return LB_STATUS_ERROR_INVALID;
189
190         slave = package_slave(pkg);
191         if (!slave)
192                 return LB_STATUS_ERROR_INVALID;
193
194         DbgPrint("Event: %dx%d\n", event_info->x, event_info->y);
195         switch (state) {
196         case EVENT_STATE_ACTIVATE:
197                 cmdstr = "pd_mouse_down";
198                 break;
199         case EVENT_STATE_ACTIVATED:
200                 cmdstr = "pd_mouse_move";
201                 break;
202         case EVENT_STATE_DEACTIVATE:
203                 cmdstr = "pd_mouse_up";
204                 break;
205         default:
206                 return LB_STATUS_ERROR_INVALID;
207         }
208
209         packet = packet_create_noack(cmdstr, "ssdii", package_name(pkg), instance_id(inst), util_timestamp(), event_info->x, event_info->y);
210         if (!packet)
211                 return LB_STATUS_ERROR_FAULT;
212
213         return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
214 }
215
216 static int event_pd_consume_cb(enum event_state state, struct event_data *event_info, void *data)
217 {
218         struct script_info *script;
219         struct inst_info *inst = data;
220         const struct pkg_info *pkg;
221         double timestamp;
222         Evas *e;
223
224         pkg = instance_package(inst);
225         if (!pkg)
226                 return 0;
227
228         script = instance_pd_script(inst);
229         if (!script)
230                 return LB_STATUS_ERROR_FAULT;
231
232         e = script_handler_evas(script);
233         if (!e)
234                 return LB_STATUS_ERROR_FAULT;
235
236         DbgPrint("Event: %dx%d\n", event_info->x, event_info->y);
237         timestamp = util_timestamp();
238
239         switch (state) {
240         case EVENT_STATE_ACTIVATE:
241                 script_handler_update_pointer(script, event_info->x, event_info->y, 1);
242                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
243                 break;
244         case EVENT_STATE_ACTIVATED:
245                 script_handler_update_pointer(script, event_info->x, event_info->y, -1);
246                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
247                 break;
248         case EVENT_STATE_DEACTIVATE:
249                 script_handler_update_pointer(script, event_info->x, event_info->y, 0);
250                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
251                 break;
252         default:
253                 break;
254         }
255         return 0;
256 }
257
258 static struct packet *client_acquire(pid_t pid, int handle, const struct packet *packet) /*!< timestamp, ret */
259 {
260         struct client_node *client;
261         struct packet *result;
262         double timestamp;
263         int ret;
264
265         client = client_find_by_pid(pid);
266         if (client) {
267                 ErrPrint("Client is already exists %d\n", pid);
268                 ret = LB_STATUS_ERROR_EXIST;
269                 goto out;
270         }
271
272         if (packet_get(packet, "d", &timestamp) != 1) {
273                 ErrPrint("Invalid arguemnt\n");
274                 ret = LB_STATUS_ERROR_INVALID;
275                 goto out;
276         }
277
278         ret = 0;
279         /*!
280          * \note
281          * client_create will invoke the client created callback
282          */
283         client = client_create(pid, handle);
284         if (!client) {
285                 ErrPrint("Failed to create a new client for %d\n", pid);
286                 ret = LB_STATUS_ERROR_FAULT;
287         }
288
289 out:
290         result = packet_create_reply(packet, "i", ret);
291         if (!result)
292                 ErrPrint("Failed to create a packet\n");
293
294         return result;
295 }
296
297 static struct packet *cilent_release(pid_t pid, int handle, const struct packet *packet) /*!< pid, ret */
298 {
299         struct client_node *client;
300         struct packet *result;
301         int ret;
302
303         client = client_find_by_pid(pid);
304         if (!client) {
305                 ErrPrint("Client %d is not exists\n", pid);
306                 ret = LB_STATUS_ERROR_NOT_EXIST;
307                 goto out;
308         }
309
310         client_destroy(client);
311         ret = 0;
312
313 out:
314         result = packet_create_reply(packet, "i", ret);
315         if (!result)
316                 ErrPrint("Failed to create a packet\n");
317
318         return result;
319 }
320
321 /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
322 static struct packet *client_clicked(pid_t pid, int handle, const struct packet *packet)
323 {
324         struct client_node *client;
325         const char *pkgname;
326         const char *id;
327         const char *event;
328         double timestamp;
329         double x;
330         double y;
331         int ret;
332         struct inst_info *inst;
333
334         client = client_find_by_pid(pid);
335         if (!client) {
336                 ErrPrint("Client %d is not exists\n", pid);
337                 goto out;
338         }
339
340         ret = packet_get(packet, "sssddd", &pkgname, &id, &event, &timestamp, &x, &y);
341         if (ret != 6) {
342                 ErrPrint("Parameter is not matched\n");
343                 goto out;
344         }
345
346         DbgPrint("pid[%d] pkgname[%s] id[%s] event[%s] timestamp[%lf] x[%lf] y[%lf]\n", pid, pkgname, id, event, timestamp, x, y);
347
348         /*!
349          * \NOTE:
350          * Trust the package name which are sent by the client.
351          * The package has to be a livebox package name.
352          */
353         inst = package_find_instance_by_id(pkgname, id);
354         if (!inst)
355                 ErrPrint("Instance is not exists\n");
356         else if (package_is_fault(instance_package(inst)))
357                 ErrPrint("Fault package\n");
358         else
359                 (void)instance_clicked(inst, event, timestamp, x, y);
360
361 out:
362         /*! \note No reply packet */
363         return NULL;
364 }
365
366 static struct packet *client_update_mode(pid_t pid, int handle, const struct packet *packet)
367 {
368         struct packet *result;
369         struct client_node *client;
370         int active_update;
371         const char *pkgname;
372         const char *id;
373         int ret;
374         struct inst_info *inst;
375
376         client = client_find_by_pid(pid);
377         if (!client) {
378                 ErrPrint("Client %d is not exists\n", pid);
379                 ret = LB_STATUS_ERROR_INVALID;
380                 goto out;
381         }
382
383         ret = packet_get(packet, "ssi", &pkgname, &id, &active_update);
384         if (ret != 3) {
385                 ErrPrint("Invalid argument\n");
386                 ret = LB_STATUS_ERROR_INVALID;
387                 goto out;
388         }
389
390         inst = package_find_instance_by_id(pkgname, id);
391         if (!inst) {
392                 ErrPrint("Instance is not exists\n");
393                 ret = LB_STATUS_ERROR_NOT_EXIST;
394         } else if (package_is_fault(instance_package(inst))) {
395                 ErrPrint("Fault package\n");
396                 ret = LB_STATUS_ERROR_FAULT;
397         } else {
398                 /*!
399                  * \note
400                  * Send change update mode request to a slave
401                  */
402                 ret = instance_set_update_mode(inst, active_update);
403         }
404
405 out:
406         result = packet_create_reply(packet, "i", ret);
407         if (!result)
408                 ErrPrint("Failed to create a packet\n");
409
410         return result;
411 }
412
413 /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
414 static struct packet *client_text_signal(pid_t pid, int handle, const struct packet *packet)
415 {
416         struct client_node *client;
417         struct packet *result;
418         const char *pkgname;
419         const char *id;
420         const char *emission;
421         const char *source;
422         double sx;
423         double sy;
424         double ex;
425         double ey;
426         struct inst_info *inst;
427         int ret;
428
429         client = client_find_by_pid(pid);
430         if (!client) {
431                 ErrPrint("Client %d is not exists\n", pid);
432                 ret = LB_STATUS_ERROR_NOT_EXIST;
433                 goto out;
434         }
435
436         ret = packet_get(packet, "ssssdddd", &pkgname, &id, &emission, &source, &sx, &sy, &ex, &ey);
437         if (ret != 8) {
438                 ErrPrint("Parameter is not matched\n");
439                 ret = LB_STATUS_ERROR_INVALID;
440                 goto out;
441         }
442
443         DbgPrint("pid[%d] pkgname[%s] id[%s] emission[%s] source[%s] sx[%lf] sy[%lf] ex[%lf] ey[%lf]\n", pid, pkgname, id, emission, source, sx, sy, ex, ey);
444
445         /*!
446          * \NOTE:
447          * Trust the package name which are sent by the client.
448          * The package has to be a livebox package name.
449          */
450         inst = package_find_instance_by_id(pkgname, id);
451         if (!inst)
452                 ret = LB_STATUS_ERROR_NOT_EXIST;
453         else if (package_is_fault(instance_package(inst)))
454                 ret = LB_STATUS_ERROR_FAULT;
455         else
456                 ret = instance_text_signal_emit(inst, emission, source, sx, sy, ex, ey);
457
458 out:
459         result = packet_create_reply(packet, "i", ret);
460         if (!result)
461                 ErrPrint("Failed to create a packet\n");
462
463         return result;
464 }
465
466 static Eina_Bool lazy_delete_cb(void *data)
467 {
468         struct deleted_item *item = data;
469
470         DbgPrint("Send delete event to the client\n");
471
472         /*!
473          * Before invoke this callback, the instance is able to already remove this client
474          * So check it again
475          */
476         if (instance_has_client(item->inst, item->client)) {
477                 instance_unicast_deleted_event(item->inst, item->client);
478                 instance_del_client(item->inst, item->client);
479         }
480
481         client_unref(item->client);
482         instance_unref(item->inst);
483         DbgFree(item);
484         return ECORE_CALLBACK_CANCEL;
485 }
486
487 static struct packet *client_delete(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
488 {
489         struct client_node *client;
490         struct packet *result;
491         const char *pkgname;
492         const char *id;
493         struct inst_info *inst;
494         int ret;
495
496         client = client_find_by_pid(pid);
497         if (!client) {
498                 ErrPrint("Client %d is not exists\n", pid);
499                 ret = LB_STATUS_ERROR_NOT_EXIST;
500                 goto out;
501         }
502
503         ret = packet_get(packet, "ss", &pkgname, &id);
504         if (ret != 2) {
505                 ErrPrint("Parameter is not matched\n");
506                 ret = LB_STATUS_ERROR_INVALID;
507                 goto out;
508         }
509
510         DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
511
512         /*!
513          * \NOTE:
514          * Trust the package name which are sent by the client.
515          * The package has to be a livebox package name.
516          */
517         inst = package_find_instance_by_id(pkgname, id);
518         if (!inst) {
519                 ret = LB_STATUS_ERROR_NOT_EXIST;
520         } else if (package_is_fault(instance_package(inst))) {
521                 ret = LB_STATUS_ERROR_FAULT;
522         } else if (instance_client(inst) != client) {
523                 if (instance_has_client(inst, client)) {
524                         struct deleted_item *item;
525
526                         item = malloc(sizeof(*item));
527                         if (!item) {
528                                 ErrPrint("Heap: %s\n", strerror(errno));
529                                 ret = LB_STATUS_ERROR_MEMORY;
530                         } else {
531                                 /*!
532                                  * \NOTE:
533                                  * Send DELETED EVENT to the client.
534                                  * after return from this function.
535                                  *
536                                  * Client will prepare the deleted event after get this function's return value.
537                                  * So We have to make a delay to send a deleted event.
538                                  */
539
540                                 item->client = client_ref(client);
541                                 item->inst = instance_ref(inst);
542
543                                 if (!ecore_timer_add(DELAY_TIME, lazy_delete_cb, item)) {
544                                         ErrPrint("Failed to add a delayzed delete callback\n");
545                                         client_unref(client);
546                                         instance_unref(inst);
547                                         DbgFree(item);
548                                         ret = LB_STATUS_ERROR_FAULT;
549                                 } else {
550                                         ret = LB_STATUS_SUCCESS;
551                                 }
552                         }
553                 } else {
554                         ret = LB_STATUS_ERROR_PERMISSION;
555                 }
556         } else {
557                 ret = instance_destroy(inst);
558         }
559
560 out:
561         result = packet_create_reply(packet, "i", ret);
562         if (!result)
563                 ErrPrint("Failed to create a packet\n");
564
565         return result;
566 }
567
568 static struct packet *client_resize(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, w, h, ret */
569 {
570         struct client_node *client;
571         struct packet *result;
572         const char *pkgname;
573         const char *id;
574         int w;
575         int h;
576         struct inst_info *inst;
577         int ret;
578
579         client = client_find_by_pid(pid);
580         if (!client) {
581                 ErrPrint("Client %d is not exists\n", pid);
582                 ret = LB_STATUS_ERROR_NOT_EXIST;
583                 goto out;
584         }
585
586         ret = packet_get(packet, "ssii", &pkgname, &id, &w, &h);
587         if (ret != 4) {
588                 ErrPrint("Parameter is not matched\n");
589                 ret = LB_STATUS_ERROR_INVALID;
590                 goto out;
591         }
592
593         DbgPrint("pid[%d] pkgname[%s] id[%s] w[%d] h[%d]\n", pid, pkgname, id, w, h);
594         DbgPrint("RESIZE: INSTANCE[%s] Client request resize to %dx%d\n", id, w, h);
595
596         /*!
597          * \NOTE:
598          * Trust the package name which are sent by the client.
599          * The package has to be a livebox package name.
600          */
601         inst = package_find_instance_by_id(pkgname, id);
602         if (!inst) {
603                 ret = LB_STATUS_ERROR_NOT_EXIST;
604         } else if (package_is_fault(instance_package(inst))) {
605                 ret = LB_STATUS_ERROR_FAULT;
606         } else if (instance_client(inst) != client) {
607                 ret = LB_STATUS_ERROR_PERMISSION;
608         } else {
609                 ret = instance_resize(inst, w, h);
610         }
611
612 out:
613         result = packet_create_reply(packet, "i", ret);
614         if (!result)
615                 ErrPrint("Failed to create a packet\n");
616
617         return result;
618 }
619
620 static struct packet *client_new(pid_t pid, int handle, const struct packet *packet) /* pid, timestamp, pkgname, content, cluster, category, period, ret */
621 {
622         struct client_node *client;
623         struct packet *result;
624         const char *pkgname;
625         const char *content;
626         const char *cluster;
627         const char *category;
628         double period;
629         double timestamp;
630         int ret;
631         struct pkg_info *info;
632         int width;
633         int height;
634         char *lb_pkgname;
635
636         client = client_find_by_pid(pid);
637         if (!client) {
638                 ErrPrint("Client %d is not exists\n", pid);
639                 ret = LB_STATUS_ERROR_NOT_EXIST;
640                 goto out;
641         }
642
643         ret = packet_get(packet, "dssssdii", &timestamp, &pkgname, &content, &cluster, &category, &period, &width, &height);
644         if (ret != 8) {
645                 ErrPrint("Parameter is not matched\n");
646                 ret = LB_STATUS_ERROR_INVALID;
647                 goto out;
648         }
649
650         DbgPrint("pid[%d] period[%lf] pkgname[%s] content[%s] cluster[%s] category[%s] period[%lf]\n",
651                                                 pid, timestamp, pkgname, content, cluster, category, period);
652
653         lb_pkgname = package_lb_pkgname(pkgname);
654         if (!lb_pkgname) {
655                 ErrPrint("This %s has no livebox package\n", pkgname);
656                 ret = LB_STATUS_ERROR_INVALID;
657                 goto out;
658         }
659
660         info = package_find(lb_pkgname);
661         if (!info)
662                 info = package_create(lb_pkgname);
663
664         if (!info) {
665                 ret = LB_STATUS_ERROR_FAULT;
666         } else if (package_is_fault(info)) {
667                 ret = LB_STATUS_ERROR_FAULT;
668         } else if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE) {
669                 ErrPrint("Not enough space\n");
670                 ret = LB_STATUS_ERROR_NO_SPACE;
671         } else {
672                 struct inst_info *inst;
673
674                 if (period > 0.0f && period < MINIMUM_PERIOD)
675                         period = MINIMUM_PERIOD;
676
677                 if (!strlen(content))
678                         content = DEFAULT_CONTENT;
679
680                 inst = instance_create(client, timestamp, lb_pkgname, content, cluster, category, period, width, height);
681                 /*!
682                  * \note
683                  * Using the "inst" without validate its value is at my disposal. ;)
684                  */
685                 ret = inst ? 0 : LB_STATUS_ERROR_FAULT;
686         }
687
688         DbgFree(lb_pkgname);
689
690 out:
691         result = packet_create_reply(packet, "i", ret);
692         if (!result)
693                 ErrPrint("Failed to create a packet\n");
694
695         return result;
696 }
697
698 static struct packet *client_change_visibility(pid_t pid, int handle, const struct packet *packet)
699 {
700         struct client_node *client;
701         const char *pkgname;
702         const char *id;
703         enum livebox_visible_state state;
704         int ret;
705         struct inst_info *inst;
706
707         client = client_find_by_pid(pid);
708         if (!client) {
709                 ErrPrint("Client %d is not exists\n", pid);
710                 ret = LB_STATUS_ERROR_NOT_EXIST;
711                 goto out;
712         }
713
714         ret = packet_get(packet, "ssi", &pkgname, &id, (int *)&state);
715         if (ret != 3) {
716                 ErrPrint("Parameter is not matched\n");
717                 ret = LB_STATUS_ERROR_INVALID;
718                 goto out;
719         }
720
721         DbgPrint("pid[%d] pkgname[%s] id[%s] state[%d]\n", pid, pkgname, id, state);
722
723         /*!
724          * \NOTE:
725          * Trust the package name which are sent by the client.
726          * The package has to be a livebox package name.
727          */
728         inst = package_find_instance_by_id(pkgname, id);
729         if (!inst) {
730                 ret = LB_STATUS_ERROR_NOT_EXIST;
731         } else if (package_is_fault(instance_package(inst))) {
732                 ret = LB_STATUS_ERROR_FAULT;
733         } else if (instance_client(inst) != client) {
734                 ret = LB_STATUS_ERROR_PERMISSION;
735         } else {
736                 ret = instance_set_visible_state(inst, state);
737         }
738
739 out:
740         /*! \note No reply packet */
741         return NULL;
742 }
743
744 static struct packet *client_set_period(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, period, ret */
745 {
746         struct client_node *client;
747         struct packet *result;
748         const char *pkgname;
749         const char *id;
750         double period;
751         int ret;
752         struct inst_info *inst;
753
754         client = client_find_by_pid(pid);
755         if (!client) {
756                 ErrPrint("Client %d is not exists\n", pid);
757                 ret = LB_STATUS_ERROR_NOT_EXIST;
758                 goto out;
759         }
760
761         ret = packet_get(packet, "ssd", &pkgname, &id, &period);
762         if (ret != 3) {
763                 ErrPrint("Parameter is not matched\n");
764                 ret = LB_STATUS_ERROR_INVALID;
765                 goto out;
766         }
767
768         DbgPrint("pid[%d] pkgname[%s] id[%s] period[%lf]\n", pid, pkgname, id, period);
769
770         /*!
771          * \NOTE:
772          * Trust the package name which are sent by the client.
773          * The package has to be a livebox package name.
774          */
775         inst = package_find_instance_by_id(pkgname, id);
776         if (!inst) {
777                 ret = LB_STATUS_ERROR_NOT_EXIST;
778         } else if (package_is_fault(instance_package(inst))) {
779                 ret = LB_STATUS_ERROR_FAULT;
780         } else if (instance_client(inst) != client) {
781                 ret = LB_STATUS_ERROR_PERMISSION;
782         } else {
783                 ret = instance_set_period(inst, period);
784         }
785
786 out:
787         result = packet_create_reply(packet, "i", ret);
788         if (!result)
789                 ErrPrint("Failed to create a packet\n");
790
791         return result;
792 }
793
794 static struct packet *client_change_group(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, cluster, category, ret */
795 {
796         struct client_node *client;
797         struct packet *result;
798         const char *pkgname;
799         const char *id;
800         const char *cluster;
801         const char *category;
802         struct inst_info *inst;
803         int ret;
804
805         client = client_find_by_pid(pid);
806         if (!client) {
807                 ErrPrint("Client %d is not exists\n", pid);
808                 ret = LB_STATUS_ERROR_NOT_EXIST;
809                 goto out;
810         }
811
812         ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category);
813         if (ret != 4) {
814                 ErrPrint("Parameter is not matched\n");
815                 ret = LB_STATUS_ERROR_INVALID;
816                 goto out;
817         }
818
819         DbgPrint("pid[%d] pkgname[%s] id[%s] cluster[%s] category[%s]\n", pid, pkgname, id, cluster, category);
820
821         /*!
822          * \NOTE:
823          * Trust the package name which are sent by the client.
824          * The package has to be a livebox package name.
825          */
826         inst = package_find_instance_by_id(pkgname, id);
827         if (!inst) {
828                 ret = LB_STATUS_ERROR_NOT_EXIST;
829         } else if (package_is_fault(instance_package(inst))) {
830                 ret = LB_STATUS_ERROR_FAULT;
831         } else if (instance_client(inst) != client) {
832                 ret = LB_STATUS_ERROR_PERMISSION;
833         } else {
834                 ret = instance_change_group(inst, cluster, category);
835         }
836
837 out:
838         result = packet_create_reply(packet, "i", ret);
839         if (!result)
840                 ErrPrint("Failed to create a packet\n");
841
842         return result;
843 }
844
845 static struct packet *client_pd_mouse_enter(pid_t pid, int handle, const struct packet *packet)
846 {
847         struct client_node *client;
848         const char *pkgname;
849         const char *id;
850         int ret;
851         double timestamp;
852         int x;
853         int y;
854         struct inst_info *inst;
855         const struct pkg_info *pkg;
856
857         client = client_find_by_pid(pid);
858         if (!client) {
859                 ErrPrint("Client %d is not exists\n", pid);
860                 ret = LB_STATUS_ERROR_NOT_EXIST;
861                 goto out;
862         }
863
864         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
865         if (ret != 5) {
866                 ErrPrint("Invalid parameter\n");
867                 ret = LB_STATUS_ERROR_INVALID;
868                 goto out;
869         }
870
871         /*!
872          * \NOTE:
873          * Trust the package name which are sent by the client.
874          * The package has to be a livebox package name.
875          */
876         inst = package_find_instance_by_id(pkgname, id);
877         if (!inst) {
878                 ErrPrint("Instance[%s] is not exists\n", id);
879                 ret = LB_STATUS_ERROR_NOT_EXIST;
880                 goto out;
881         }
882
883         pkg = instance_package(inst);
884         if (!pkg) {
885                 ErrPrint("Package[%s] info is not found\n", pkgname);
886                 ret = LB_STATUS_ERROR_FAULT;
887                 goto out;
888         }
889
890         if (package_is_fault(pkg)) {
891                 /*!
892                  * \note
893                  * If the package is registered as fault module,
894                  * slave has not load it, so we don't need to do anything at here!
895                  */
896                 DbgPrint("Package[%s] is faulted\n", pkgname);
897                 ret = LB_STATUS_ERROR_FAULT;
898         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
899                 struct buffer_info *buffer;
900                 struct slave_node *slave;
901                 // struct packet *packet;
902
903                 buffer = instance_pd_buffer(inst);
904                 if (!buffer) {
905                         ErrPrint("Instance[%s] has no buffer\n", id);
906                         ret = LB_STATUS_ERROR_FAULT;
907                         goto out;
908                 }
909
910                 slave = package_slave(pkg);
911                 if (!slave) {
912                         ErrPrint("Package[%s] has no slave\n", pkgname);
913                         ret = LB_STATUS_ERROR_INVALID;
914                         goto out;
915                 }
916
917                 /*
918                 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
919                 if (!packet) {
920                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
921                         ret = LB_STATUS_ERROR_FAULT;
922                         goto out;
923                 }
924                 */
925
926                 packet_ref((struct packet *)packet);
927                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
928         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
929                 struct script_info *script;
930                 Evas *e;
931
932                 script = instance_pd_script(inst);
933                 if (!script) {
934                         ret = LB_STATUS_ERROR_FAULT;
935                         goto out;
936                 }
937
938                 e = script_handler_evas(script);
939                 if (!e) {
940                         ret = LB_STATUS_ERROR_FAULT;
941                         goto out;
942                 }
943
944                 script_handler_update_pointer(script, x, y, -1);
945                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_IN, timestamp);
946                 ret = 0;
947         } else {
948                 ErrPrint("Unsupported package\n");
949                 ret = LB_STATUS_ERROR_INVALID;
950         }
951
952 out:
953         /*! \note No reply packet */
954         return NULL;
955 }
956
957 static struct packet *client_pd_mouse_leave(pid_t pid, int handle, const struct packet *packet)
958 {
959         struct client_node *client;
960         const char *pkgname;
961         const char *id;
962         int ret;
963         double timestamp;
964         int x;
965         int y;
966         struct inst_info *inst;
967         const struct pkg_info *pkg;
968
969         client = client_find_by_pid(pid);
970         if (!client) {
971                 ErrPrint("Client %d is not exists\n", pid);
972                 ret = LB_STATUS_ERROR_NOT_EXIST;
973                 goto out;
974         }
975
976         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
977         if (ret != 5) {
978                 ErrPrint("Parameter is not matched\n");
979                 ret = LB_STATUS_ERROR_INVALID;
980                 goto out;
981         }
982
983         /*!
984          * \NOTE:
985          * Trust the package name which are sent by the client.
986          * The package has to be a livebox package name.
987          */
988         inst = package_find_instance_by_id(pkgname, id);
989         if (!inst) {
990                 ErrPrint("Instance[%s] is not exists\n", id);
991                 ret = LB_STATUS_ERROR_NOT_EXIST;
992                 goto out;
993         }
994
995         pkg = instance_package(inst);
996         if (!pkg) {
997                 ErrPrint("Package[%s] info is not found\n", pkgname);
998                 ret = LB_STATUS_ERROR_FAULT;
999                 goto out;
1000         }
1001
1002         if (package_is_fault(pkg)) {
1003                 /*!
1004                  * \note
1005                  * If the package is registered as fault module,
1006                  * slave has not load it, so we don't need to do anything at here!
1007                  */
1008                 DbgPrint("Package[%s] is faulted\n", pkgname);
1009                 ret = LB_STATUS_ERROR_FAULT;
1010         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1011                 struct buffer_info *buffer;
1012                 struct slave_node *slave;
1013                 // struct packet *packet;
1014
1015                 buffer = instance_pd_buffer(inst);
1016                 if (!buffer) {
1017                         ErrPrint("Instance[%s] has no buffer\n", id);
1018                         ret = LB_STATUS_ERROR_FAULT;
1019                         goto out;
1020                 }
1021
1022                 slave = package_slave(pkg);
1023                 if (!slave) {
1024                         ErrPrint("Package[%s] has no slave\n", pkgname);
1025                         ret = LB_STATUS_ERROR_INVALID;
1026                         goto out;
1027                 }
1028
1029                 /*
1030                 packet = packet_create_noack("pd_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1031                 if (!packet) {
1032                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
1033                         ret = LB_STATUS_ERROR_FAULT;
1034                         goto out;
1035                 }
1036                 */
1037
1038                 packet_ref((struct packet *)packet);
1039                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
1040         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1041                 struct script_info *script;
1042                 Evas *e;
1043
1044                 script = instance_pd_script(inst);
1045                 if (!script) {
1046                         ret = LB_STATUS_ERROR_FAULT;
1047                         goto out;
1048                 }
1049
1050                 e = script_handler_evas(script);
1051                 if (!e) {
1052                         ret = LB_STATUS_ERROR_FAULT;
1053                         goto out;
1054                 }
1055
1056                 script_handler_update_pointer(script, x, y, -1);
1057                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_OUT, timestamp);
1058                 ret = 0;
1059         } else {
1060                 ErrPrint("Unsupported package\n");
1061                 ret = LB_STATUS_ERROR_INVALID;
1062         }
1063
1064 out:
1065         /*! \note No reply packet */
1066         return NULL;
1067 }
1068
1069 static struct packet *client_pd_mouse_down(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, id, width, height, timestamp, x, y, ret */
1070 {
1071         struct client_node *client;
1072         const char *pkgname;
1073         const char *id;
1074         int ret;
1075         double timestamp;
1076         int x;
1077         int y;
1078         struct inst_info *inst;
1079         const struct pkg_info *pkg;
1080
1081         client = client_find_by_pid(pid);
1082         if (!client) {
1083                 ErrPrint("Client %d is not exists\n", pid);
1084                 ret = LB_STATUS_ERROR_NOT_EXIST;
1085                 goto out;
1086         }
1087
1088         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1089         if (ret != 5) {
1090                 ErrPrint("Parameter is not matched\n");
1091                 ret = LB_STATUS_ERROR_INVALID;
1092                 goto out;
1093         }
1094
1095         DbgPrint("(%dx%d)\n", x, y);
1096
1097         /*!
1098          * \NOTE:
1099          * Trust the package name which are sent by the client.
1100          * The package has to be a livebox package name.
1101          */
1102         inst = package_find_instance_by_id(pkgname, id);
1103         if (!inst) {
1104                 ErrPrint("Instance[%s] is not exists\n", id);
1105                 ret = LB_STATUS_ERROR_NOT_EXIST;
1106                 goto out;
1107         }
1108
1109         pkg = instance_package(inst);
1110         if (!pkg) {
1111                 ErrPrint("Package[%s] info is not found\n", pkgname);
1112                 ret = LB_STATUS_ERROR_FAULT;
1113                 goto out;
1114         }
1115
1116         if (package_is_fault(pkg)) {
1117                 /*!
1118                  * \note
1119                  * If the package is registered as fault module,
1120                  * slave has not load it, so we don't need to do anything at here!
1121                  */
1122                 DbgPrint("Package[%s] is faulted\n", pkgname);
1123                 ret = LB_STATUS_ERROR_FAULT;
1124         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1125                 struct buffer_info *buffer;
1126                 struct slave_node *slave;
1127                 // struct packet *packet;
1128
1129                 buffer = instance_pd_buffer(inst);
1130                 if (!buffer) {
1131                         ErrPrint("Instance[%s] has no buffer\n", id);
1132                         ret = LB_STATUS_ERROR_FAULT;
1133                         goto out;
1134                 }
1135
1136                 slave = package_slave(pkg);
1137                 if (!slave) {
1138                         ErrPrint("Package[%s] has no slave\n", pkgname);
1139                         ret = LB_STATUS_ERROR_INVALID;
1140                         goto out;
1141                 }
1142
1143                 /*
1144                 packet = packet_create_noack("pd_mouse_down", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1145                 if (!packet) {
1146                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
1147                         ret = LB_STATUS_ERROR_FAULT;
1148                         goto out;
1149                 }
1150                 */
1151
1152                 packet_ref((struct packet *)packet);
1153                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
1154         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1155                 struct script_info *script;
1156                 Evas *e;
1157
1158                 script = instance_pd_script(inst);
1159                 if (!script) {
1160                         ret = LB_STATUS_ERROR_FAULT;
1161                         goto out;
1162                 }
1163
1164                 e = script_handler_evas(script);
1165                 if (!e) {
1166                         ret = LB_STATUS_ERROR_FAULT;
1167                         goto out;
1168                 }
1169
1170                 script_handler_update_pointer(script, x, y, 1);
1171                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
1172                 ret = 0;
1173         } else {
1174                 ErrPrint("Unsupported package\n");
1175                 ret = LB_STATUS_ERROR_INVALID;
1176         }
1177
1178 out:
1179         /*! \note No reply packet */
1180         return NULL;
1181 }
1182
1183 static struct packet *client_pd_mouse_up(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
1184 {
1185         struct client_node *client;
1186         const char *pkgname;
1187         const char *id;
1188         int ret;
1189         double timestamp;
1190         int x;
1191         int y;
1192         struct inst_info *inst;
1193         const struct pkg_info *pkg;
1194
1195         client = client_find_by_pid(pid);
1196         if (!client) {
1197                 ErrPrint("Client %d is not exists\n", pid);
1198                 ret = LB_STATUS_ERROR_NOT_EXIST;
1199                 goto out;
1200         }
1201
1202         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1203         if (ret != 5) {
1204                 ErrPrint("Parameter is not matched\n");
1205                 ret = LB_STATUS_ERROR_INVALID;
1206                 goto out;
1207         }
1208
1209         DbgPrint("(%dx%d)\n", x, y);
1210         /*!
1211          * \NOTE:
1212          * Trust the package name which are sent by the client.
1213          * The package has to be a livebox package name.
1214          */
1215         inst = package_find_instance_by_id(pkgname, id);
1216         if (!inst) {
1217                 ErrPrint("Instance[%s] is not exists\n", id);
1218                 ret = LB_STATUS_ERROR_NOT_EXIST;
1219                 goto out;
1220         }
1221
1222         pkg = instance_package(inst);
1223         if (!pkg) {
1224                 ErrPrint("Package[%s] info is not exists\n", pkgname);
1225                 ret = LB_STATUS_ERROR_FAULT;
1226                 goto out;
1227         }
1228
1229         if (package_is_fault(pkg)) {
1230                 /*!
1231                  * \note
1232                  * If the package is registered as fault module,
1233                  * slave has not load it, so we don't need to do anything at here!
1234                  */
1235                 DbgPrint("Package[%s] is faulted\n", pkgname);
1236                 ret = LB_STATUS_ERROR_FAULT;
1237         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1238                 struct buffer_info *buffer;
1239                 struct slave_node *slave;
1240                 //struct packet *packet;
1241
1242                 buffer = instance_pd_buffer(inst);
1243                 if (!buffer) {
1244                         ErrPrint("Instance[%s] has no buffer\n", id);
1245                         ret = LB_STATUS_ERROR_FAULT;
1246                         goto out;
1247                 }
1248
1249                 slave = package_slave(pkg);
1250                 if (!slave) {
1251                         ErrPrint("Package[%s] has no slave\n", pkgname);
1252                         ret = LB_STATUS_ERROR_INVALID;
1253                         goto out;
1254                 }
1255
1256                 /*
1257                 packet = packet_create_noack("pd_mouse_up", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1258                 if (!packet) {
1259                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
1260                         ret = LB_STATUS_ERROR_FAULT;
1261                         goto out;
1262                 }
1263                 */
1264
1265                 packet_ref((struct packet *)packet);
1266                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
1267         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1268                 struct script_info *script;
1269                 Evas *e;
1270
1271                 script = instance_pd_script(inst);
1272                 if (!script) {
1273                         ret = LB_STATUS_ERROR_FAULT;
1274                         goto out;
1275                 }
1276
1277                 e = script_handler_evas(script);
1278                 if (!e) {
1279                         ret = LB_STATUS_ERROR_FAULT;
1280                         goto out;
1281                 }
1282
1283                 script_handler_update_pointer(script, x, y, 0);
1284                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
1285                 ret = 0;
1286         } else {
1287                 ErrPrint("Unsupported package\n");
1288                 ret = LB_STATUS_ERROR_INVALID;
1289         }
1290
1291 out:
1292         /*! \note No reply packet */
1293         return NULL;
1294 }
1295
1296 static struct packet *client_pd_mouse_move(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
1297 {
1298         struct client_node *client;
1299         const char *pkgname;
1300         const char *id;
1301         int ret;
1302         double timestamp;
1303         int x;
1304         int y;
1305         struct inst_info *inst;
1306         const struct pkg_info *pkg;
1307
1308         client = client_find_by_pid(pid);
1309         if (!client) {
1310                 ErrPrint("Client %d is not exists\n", pid);
1311                 ret = LB_STATUS_ERROR_NOT_EXIST;
1312                 goto out;
1313         }
1314
1315         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1316         if (ret != 5) {
1317                 ErrPrint("Parameter is not matched\n");
1318                 ret = LB_STATUS_ERROR_INVALID;
1319                 goto out;
1320         }
1321
1322         DbgPrint("(%dx%d)\n", x, y);
1323         /*!
1324          * \NOTE:
1325          * Trust the package name which are sent by the client.
1326          * The package has to be a livebox package name.
1327          */
1328         inst = package_find_instance_by_id(pkgname, id);
1329         if (!inst) {
1330                 ErrPrint("Instance[%s] is not exists\n", id);
1331                 ret = LB_STATUS_ERROR_NOT_EXIST;
1332                 goto out;
1333         }
1334
1335         pkg = instance_package(inst);
1336         if (!pkg) {
1337                 ErrPrint("Package[%s] info is not exists\n", pkgname);
1338                 ret = LB_STATUS_ERROR_FAULT;
1339                 goto out;
1340         }
1341
1342         if (package_is_fault(pkg)) {
1343                 /*!
1344                  * \note
1345                  * If the package is registered as fault module,
1346                  * slave has not load it, so we don't need to do anything at here!
1347                  */
1348                 DbgPrint("Package[%s] is faulted\n", pkgname);
1349                 ret = LB_STATUS_ERROR_FAULT;
1350         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1351                 struct buffer_info *buffer;
1352                 struct slave_node *slave;
1353                 //struct packet *packet;
1354
1355                 buffer = instance_pd_buffer(inst);
1356                 if (!buffer) {
1357                         ErrPrint("Instance[%s] has no buffer\n", id);
1358                         ret = LB_STATUS_ERROR_FAULT;
1359                         goto out;
1360                 }
1361
1362                 slave = package_slave(pkg);
1363                 if (!slave) {
1364                         ErrPrint("Package[%s] has no slave\n", pkgname);
1365                         ret = LB_STATUS_ERROR_INVALID;
1366                         goto out;
1367                 }
1368
1369                 /*!
1370                  * Reuse the packet.
1371                 packet = packet_create_noack("pd_mouse_move", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1372                 if (!packet) {
1373                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
1374                         ret = LB_STATUS_ERROR_FAULT;
1375                         goto out;
1376                 }
1377                  */
1378                 packet_ref((struct packet *)packet);
1379                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
1380         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1381                 struct script_info *script;
1382                 Evas *e;
1383
1384                 script = instance_pd_script(inst);
1385                 if (!script) {
1386                         ret = LB_STATUS_ERROR_FAULT;
1387                         goto out;
1388                 }
1389
1390                 e = script_handler_evas(script);
1391                 if (!e) {
1392                         ret = LB_STATUS_ERROR_FAULT;
1393                         goto out;
1394                 }
1395
1396                 script_handler_update_pointer(script, x, y, -1);
1397                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
1398                 ret = 0;
1399         } else {
1400                 ErrPrint("Unsupported package\n");
1401                 ret = LB_STATUS_ERROR_INVALID;
1402         }
1403
1404 out:
1405         /*! \note No reply packet */
1406         return NULL;
1407 }
1408
1409 static struct packet *client_lb_mouse_move(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
1410 {
1411         struct client_node *client;
1412         const char *pkgname;
1413         const char *id;
1414         int ret;
1415         double timestamp;
1416         int x;
1417         int y;
1418         struct inst_info *inst;
1419         const struct pkg_info *pkg;
1420
1421         client = client_find_by_pid(pid);
1422         if (!client) {
1423                 ErrPrint("Client %d is not exists\n", pid);
1424                 ret = LB_STATUS_ERROR_NOT_EXIST;
1425                 goto out;
1426         }
1427
1428         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1429         if (ret != 5) {
1430                 ErrPrint("Parameter is not matched\n");
1431                 ret = LB_STATUS_ERROR_INVALID;
1432                 goto out;
1433         }
1434
1435         /*!
1436          * \NOTE:
1437          * Trust the package name which are sent by the client.
1438          * The package has to be a livebox package name.
1439          */
1440         inst = package_find_instance_by_id(pkgname, id);
1441         if (!inst) {
1442                 ErrPrint("Instance[%s] is not exists\n", id);
1443                 ret = LB_STATUS_ERROR_NOT_EXIST;
1444                 goto out;
1445         }
1446
1447         pkg = instance_package(inst);
1448         if (!pkg) {
1449                 ErrPrint("Package[%s] info is not exists\n", pkgname);
1450                 ret = LB_STATUS_ERROR_FAULT;
1451                 goto out;
1452         }
1453
1454         if (package_is_fault(pkg)) {
1455                 /*!
1456                  * \note
1457                  * If the package is registered as fault module,
1458                  * slave has not load it, so we don't need to do anything at here!
1459                  */
1460                 DbgPrint("Package[%s] is faulted\n", pkgname);
1461                 ret = LB_STATUS_ERROR_FAULT;
1462         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1463                 struct buffer_info *buffer;
1464                 struct slave_node *slave;
1465                 //struct packet *packet;
1466
1467                 buffer = instance_lb_buffer(inst);
1468                 if (!buffer) {
1469                         ErrPrint("Instance[%s] has no buffer\n", id);
1470                         ret = LB_STATUS_ERROR_FAULT;
1471                         goto out;
1472                 }
1473
1474                 slave = package_slave(pkg);
1475                 if (!slave) {
1476                         ErrPrint("Package[%s] has no slave\n", pkgname);
1477                         ret = LB_STATUS_ERROR_INVALID;
1478                         goto out;
1479                 }
1480
1481                 /*
1482                 packet = packet_create_noack("lb_mouse_move", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1483                 if (!packet) {
1484                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
1485                         ret = LB_STATUS_ERROR_FAULT;
1486                         goto out;
1487                 }
1488                 */
1489                 packet_ref((struct packet *)packet);
1490                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
1491         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1492                 struct script_info *script;
1493                 Evas *e;
1494
1495                 script = instance_lb_script(inst);
1496                 if (!script) {
1497                         ret = LB_STATUS_ERROR_FAULT;
1498                         goto out;
1499                 }
1500
1501                 e = script_handler_evas(script);
1502                 if (!e) {
1503                         ret = LB_STATUS_ERROR_FAULT;
1504                         goto out;
1505                 }
1506
1507                 script_handler_update_pointer(script, x, y, -1);
1508                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
1509                 ret = 0;
1510         } else {
1511                 ErrPrint("Unsupported package\n");
1512                 ret = LB_STATUS_ERROR_INVALID;
1513         }
1514
1515 out:
1516         /*! \note No reply packet */
1517         return NULL;
1518 }
1519
1520 static int inst_del_cb(struct inst_info *inst, void *data)
1521 {
1522         (void)event_deactivate();
1523         return -1; /* Delete this callback */
1524 }
1525
1526 static struct packet *client_lb_mouse_set(pid_t pid, int handle, const struct packet *packet)
1527 {
1528         struct client_node *client;
1529         const char *pkgname;
1530         const char *id;
1531         int ret;
1532         double timestamp;
1533         int x;
1534         int y;
1535         struct inst_info *inst;
1536         const struct pkg_info *pkg;
1537
1538         client = client_find_by_pid(pid);
1539         if (!client) {
1540                 ErrPrint("Client %d is not exists\n", pid);
1541                 ret = LB_STATUS_ERROR_NOT_EXIST;
1542                 goto out;
1543         }
1544
1545         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1546         if (ret != 5) {
1547                 ErrPrint("Parameter is not matched\n");
1548                 ret = LB_STATUS_ERROR_INVALID;
1549                 goto out;
1550         }
1551
1552         inst = package_find_instance_by_id(pkgname, id);
1553         if (!inst) {
1554                 ErrPrint("Instance[%s] is not exists\n", id);
1555                 ret = LB_STATUS_ERROR_NOT_EXIST;
1556                 goto out;
1557         }
1558
1559         pkg = instance_package(inst);
1560         if (!pkg) {
1561                 ErrPrint("Package[%s] info is not exists\n", pkgname);
1562                 ret = LB_STATUS_ERROR_FAULT;
1563                 goto out;
1564         }
1565
1566         if (package_is_fault(pkg)) {
1567                 /*!
1568                  * \note
1569                  * If the package is registered as fault module,
1570                  * slave has not load it, so we don't need to do anything at here!
1571                  */
1572                 DbgPrint("Package[%s] is faulted\n", pkgname);
1573                 ret = LB_STATUS_ERROR_FAULT;
1574         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1575                 if (event_is_activated()) {
1576                         if (event_deactivate() == 0)
1577                                 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1578                 }
1579
1580                 ret = event_activate(x, y, event_lb_route_cb, inst);
1581                 if (ret == 0)
1582                         instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, NULL);
1583         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1584                 if (event_is_activated()) {
1585                         if (event_deactivate() == 0)
1586                                 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1587                 }
1588
1589                 ret = event_activate(x, y, event_lb_consume_cb, inst);
1590                 if (ret == 0)
1591                         instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, NULL);
1592         } else {
1593                 ErrPrint("Unsupported package\n");
1594                 ret = LB_STATUS_ERROR_INVALID;
1595         }
1596 out:
1597         return NULL;
1598 }
1599
1600 static struct packet *client_lb_mouse_unset(pid_t pid, int handle, const struct packet *packet)
1601 {
1602         struct client_node *client;
1603         const char *pkgname;
1604         const char *id;
1605         int ret;
1606         double timestamp;
1607         int x;
1608         int y;
1609         struct inst_info *inst;
1610         const struct pkg_info *pkg;
1611         client = client_find_by_pid(pid);
1612         if (!client) {
1613                 ErrPrint("Client %d is not exists\n", pid);
1614                 ret = LB_STATUS_ERROR_NOT_EXIST;
1615                 goto out;
1616         }
1617         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1618         if (ret != 5) {
1619                 ErrPrint("Parameter is not matched\n");
1620                 ret = LB_STATUS_ERROR_INVALID;
1621                 goto out;
1622         }
1623
1624         inst = package_find_instance_by_id(pkgname, id);
1625         if (!inst) {
1626                 ErrPrint("Instance[%s] is not exists\n", id);
1627                 ret = LB_STATUS_ERROR_NOT_EXIST;
1628                 goto out;
1629         }
1630
1631         pkg = instance_package(inst);
1632         if (!pkg) {
1633                 ErrPrint("Package[%s] info is not exists\n", pkgname);
1634                 ret = LB_STATUS_ERROR_FAULT;
1635                 goto out;
1636         }
1637
1638         if (package_is_fault(pkg)) {
1639                 /*!
1640                  * \note
1641                  * If the package is registered as fault module,
1642                  * slave has not load it, so we don't need to do anything at here!
1643                  */
1644                 DbgPrint("Package[%s] is faulted\n", pkgname);
1645                 ret = LB_STATUS_ERROR_FAULT;
1646         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1647                 ret = event_deactivate();
1648                 if (ret == 0)
1649                         instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1650         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1651                 ret = event_deactivate();
1652                 if (ret == 0)
1653                         instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1654         } else {
1655                 ErrPrint("Unsupported package\n");
1656                 ret = LB_STATUS_ERROR_INVALID;
1657         }
1658 out:
1659         return NULL;
1660 }
1661
1662 static struct packet *client_pd_mouse_set(pid_t pid, int handle, const struct packet *packet)
1663 {
1664         struct client_node *client;
1665         const char *pkgname;
1666         const char *id;
1667         int ret;
1668         double timestamp;
1669         int x;
1670         int y;
1671         struct inst_info *inst;
1672         const struct pkg_info *pkg;
1673
1674         client = client_find_by_pid(pid);
1675         if (!client) {
1676                 ErrPrint("Client %d is not exists\n", pid);
1677                 ret = LB_STATUS_ERROR_NOT_EXIST;
1678                 goto out;
1679         }
1680
1681         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1682         if (ret != 5) {
1683                 ErrPrint("Parameter is not matched\n");
1684                 ret = LB_STATUS_ERROR_INVALID;
1685                 goto out;
1686         }
1687
1688         inst = package_find_instance_by_id(pkgname, id);
1689         if (!inst) {
1690                 ErrPrint("Instance[%s] is not exists\n", id);
1691                 ret = LB_STATUS_ERROR_NOT_EXIST;
1692                 goto out;
1693         }
1694
1695         pkg = instance_package(inst);
1696         if (!pkg) {
1697                 ErrPrint("Package[%s] info is not exists\n", pkgname);
1698                 ret = LB_STATUS_ERROR_FAULT;
1699                 goto out;
1700         }
1701
1702         if (package_is_fault(pkg)) {
1703                 /*!
1704                  * \note
1705                  * If the package is registered as fault module,
1706                  * slave has not load it, so we don't need to do anything at here!
1707                  */
1708                 DbgPrint("Package[%s] is faulted\n", pkgname);
1709                 ret = LB_STATUS_ERROR_FAULT;
1710         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1711                 if (event_is_activated()) {
1712                         if (event_deactivate() == 0)
1713                                 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1714                 }
1715
1716                 ret = event_activate(x, y, event_pd_route_cb, inst);
1717                 if (ret == 0)
1718                         instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, NULL);
1719         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1720                 if (event_is_activated()) {
1721                         if (event_deactivate() == 0)
1722                                 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1723                 }
1724
1725                 ret = event_activate(x, y, event_pd_consume_cb, inst);
1726                 if (ret == 0)
1727                         instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, NULL);
1728         } else {
1729                 ErrPrint("Unsupported package\n");
1730                 ret = LB_STATUS_ERROR_INVALID;
1731         }
1732
1733 out:
1734         return NULL;
1735 }
1736
1737 static struct packet *client_pd_mouse_unset(pid_t pid, int handle, const struct packet *packet)
1738 {
1739         struct client_node *client;
1740         const char *pkgname;
1741         const char *id;
1742         int ret;
1743         double timestamp;
1744         int x;
1745         int y;
1746         struct inst_info *inst;
1747         const struct pkg_info *pkg;
1748
1749         client = client_find_by_pid(pid);
1750         if (!client) {
1751                 ErrPrint("Client %d is not exists\n", pid);
1752                 ret = LB_STATUS_ERROR_NOT_EXIST;
1753                 goto out;
1754         }
1755
1756         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1757         if (ret != 5) {
1758                 ErrPrint("Parameter is not matched\n");
1759                 ret = LB_STATUS_ERROR_INVALID;
1760                 goto out;
1761         }
1762
1763         inst = package_find_instance_by_id(pkgname, id);
1764         if (!inst) {
1765                 ErrPrint("Instance[%s] is not exists\n", id);
1766                 ret = LB_STATUS_ERROR_NOT_EXIST;
1767                 goto out;
1768         }
1769
1770         pkg = instance_package(inst);
1771         if (!pkg) {
1772                 ErrPrint("Package[%s] info is not exists\n", pkgname);
1773                 ret = LB_STATUS_ERROR_FAULT;
1774                 goto out;
1775         }
1776
1777         if (package_is_fault(pkg)) {
1778                 /*!
1779                  * \note
1780                  * If the package is registered as fault module,
1781                  * slave has not load it, so we don't need to do anything at here!
1782                  */
1783                 DbgPrint("Package[%s] is faulted\n", pkgname);
1784                 ret = LB_STATUS_ERROR_FAULT;
1785         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1786                 ret = event_deactivate();
1787                 if (ret == 0)
1788                         instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1789         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1790                 ret = event_deactivate();
1791                 if (ret == 0)
1792                         instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1793         } else {
1794                 ErrPrint("Unsupported package\n");
1795                 ret = LB_STATUS_ERROR_INVALID;
1796         }
1797 out:
1798         return NULL;
1799 }
1800
1801 static struct packet *client_lb_mouse_enter(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
1802 {
1803         struct client_node *client;
1804         const char *pkgname;
1805         const char *id;
1806         int ret;
1807         double timestamp;
1808         int x;
1809         int y;
1810         struct inst_info *inst;
1811         const struct pkg_info *pkg;
1812
1813         client = client_find_by_pid(pid);
1814         if (!client) {
1815                 ErrPrint("Client %d is not exists\n", pid);
1816                 ret = LB_STATUS_ERROR_NOT_EXIST;
1817                 goto out;
1818         }
1819
1820         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1821         if (ret != 5) {
1822                 ErrPrint("Parameter is not matched\n");
1823                 ret = LB_STATUS_ERROR_INVALID;
1824                 goto out;
1825         }
1826
1827         /*!
1828          * \NOTE:
1829          * Trust the package name which are sent by the client.
1830          * The package has to be a livebox package name.
1831          */
1832         inst = package_find_instance_by_id(pkgname, id);
1833         if (!inst) {
1834                 ErrPrint("Instance[%s] is not exists\n", id);
1835                 ret = LB_STATUS_ERROR_NOT_EXIST;
1836                 goto out;
1837         }
1838
1839         pkg = instance_package(inst);
1840         if (!pkg) {
1841                 ErrPrint("Package[%s] info is not exists\n", pkgname);
1842                 ret = LB_STATUS_ERROR_FAULT;
1843                 goto out;
1844         }
1845
1846         if (package_is_fault(pkg)) {
1847                 /*!
1848                  * \note
1849                  * If the package is registered as fault module,
1850                  * slave has not load it, so we don't need to do anything at here!
1851                  */
1852                 DbgPrint("Package[%s] is faulted\n", pkgname);
1853                 ret = LB_STATUS_ERROR_FAULT;
1854         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1855                 struct buffer_info *buffer;
1856                 struct slave_node *slave;
1857                 //struct packet *packet;
1858
1859                 buffer = instance_lb_buffer(inst);
1860                 if (!buffer) {
1861                         ErrPrint("Instance[%s] has no buffer\n", id);
1862                         ret = LB_STATUS_ERROR_FAULT;
1863                         goto out;
1864                 }
1865
1866                 slave = package_slave(pkg);
1867                 if (!slave) {
1868                         ErrPrint("Package[%s] has no slave\n", pkgname);
1869                         ret = LB_STATUS_ERROR_INVALID;
1870                         goto out;
1871                 }
1872
1873                 /*
1874                 packet = packet_create_noack("lb_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1875                 if (!packet) {
1876                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
1877                         ret = LB_STATUS_ERROR_FAULT;
1878                         goto out;
1879                 }
1880                 */
1881                 packet_ref((struct packet *)packet);
1882                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
1883         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1884                 struct script_info *script;
1885                 Evas *e;
1886
1887                 script = instance_lb_script(inst);
1888                 if (!script) {
1889                         ret = LB_STATUS_ERROR_FAULT;
1890                         goto out;
1891                 }
1892
1893                 e = script_handler_evas(script);
1894                 if (!e) {
1895                         ret = LB_STATUS_ERROR_FAULT;
1896                         goto out;
1897                 }
1898
1899                 script_handler_update_pointer(script, x, y, -1);
1900                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_IN, timestamp);
1901                 ret = 0;
1902         } else {
1903                 ErrPrint("Unsupported package\n");
1904                 ret = LB_STATUS_ERROR_INVALID;
1905         }
1906
1907 out:
1908         /*! \note No reply packet */
1909         return NULL;
1910 }
1911
1912 static struct packet *client_lb_mouse_leave(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
1913 {
1914         struct client_node *client;
1915         const char *pkgname;
1916         const char *id;
1917         int ret;
1918         double timestamp;
1919         int x;
1920         int y;
1921         struct inst_info *inst;
1922         const struct pkg_info *pkg;
1923
1924         client = client_find_by_pid(pid);
1925         if (!client) {
1926                 ErrPrint("Client %d is not exists\n", pid);
1927                 ret = LB_STATUS_ERROR_NOT_EXIST;
1928                 goto out;
1929         }
1930
1931         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
1932         if (ret != 5) {
1933                 ErrPrint("Parameter is not matched\n");
1934                 ret = LB_STATUS_ERROR_INVALID;
1935                 goto out;
1936         }
1937
1938         /*!
1939          * \NOTE:
1940          * Trust the package name which are sent by the client.
1941          * The package has to be a livebox package name.
1942          */
1943         inst = package_find_instance_by_id(pkgname, id);
1944         if (!inst) {
1945                 ErrPrint("Instance[%s] is not exists\n", id);
1946                 ret = LB_STATUS_ERROR_NOT_EXIST;
1947                 goto out;
1948         }
1949
1950         pkg = instance_package(inst);
1951         if (!pkg) {
1952                 ErrPrint("Package[%s] info is not exists\n", pkgname);
1953                 ret = LB_STATUS_ERROR_FAULT;
1954                 goto out;
1955         }
1956
1957         if (package_is_fault(pkg)) {
1958                 /*!
1959                  * \note
1960                  * If the package is registered as fault module,
1961                  * slave has not load it, so we don't need to do anything at here!
1962                  */
1963                 DbgPrint("Package[%s] is faulted\n", pkgname);
1964                 ret = LB_STATUS_ERROR_FAULT;
1965         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1966                 struct buffer_info *buffer;
1967                 struct slave_node *slave;
1968                 //struct packet *packet;
1969
1970                 buffer = instance_lb_buffer(inst);
1971                 if (!buffer) {
1972                         ErrPrint("Instance[%s] has no buffer\n", id);
1973                         ret = LB_STATUS_ERROR_FAULT;
1974                         goto out;
1975                 }
1976
1977                 slave = package_slave(pkg);
1978                 if (!slave) {
1979                         ErrPrint("Package[%s] has no slave\n", pkgname);
1980                         ret = LB_STATUS_ERROR_INVALID;
1981                         goto out;
1982                 }
1983
1984                 /*
1985                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1986                 if (!packet) {
1987                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
1988                         ret = LB_STATUS_ERROR_FAULT;
1989                         goto out;
1990                 }
1991                 */
1992
1993                 packet_ref((struct packet *)packet);
1994                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
1995         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1996                 struct script_info *script;
1997                 Evas *e;
1998
1999                 script = instance_lb_script(inst);
2000                 if (!script) {
2001                         ret = LB_STATUS_ERROR_FAULT;
2002                         goto out;
2003                 }
2004
2005                 e = script_handler_evas(script);
2006                 if (!e) {
2007                         ret = LB_STATUS_ERROR_FAULT;
2008                         goto out;
2009                 }
2010
2011                 script_handler_update_pointer(script, x, y, -1);
2012                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_OUT, timestamp);
2013                 ret = 0;
2014         } else {
2015                 ErrPrint("Unsupported package\n");
2016                 ret = LB_STATUS_ERROR_INVALID;
2017         }
2018
2019 out:
2020         /*! \note No reply packet */
2021         return NULL;
2022 }
2023
2024 static struct packet *client_lb_mouse_down(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
2025 {
2026         struct client_node *client;
2027         const char *pkgname;
2028         const char *id;
2029         int ret;
2030         double timestamp;
2031         int x;
2032         int y;
2033         struct inst_info *inst;
2034         const struct pkg_info *pkg;
2035
2036         client = client_find_by_pid(pid);
2037         if (!client) {
2038                 ErrPrint("Client %d is not exists\n", pid);
2039                 ret = LB_STATUS_ERROR_NOT_EXIST;
2040                 goto out;
2041         }
2042
2043         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2044         if (ret != 5) {
2045                 ErrPrint("Parameter is not matched\n");
2046                 ret = LB_STATUS_ERROR_INVALID;
2047                 goto out;
2048         }
2049
2050         /*!
2051          * \NOTE:
2052          * Trust the package name which are sent by the client.
2053          * The package has to be a livebox package name.
2054          */
2055         inst = package_find_instance_by_id(pkgname, id);
2056         if (!inst) {
2057                 ErrPrint("Instance[%s] is not exists\n", id);
2058                 ret = LB_STATUS_ERROR_NOT_EXIST;
2059                 goto out;
2060         }
2061
2062         pkg = instance_package(inst);
2063         if (!pkg) {
2064                 ErrPrint("Package[%s] info is not exists\n", pkgname);
2065                 ret = LB_STATUS_ERROR_FAULT;
2066                 goto out;
2067         }
2068
2069         if (package_is_fault(pkg)) {
2070                 /*!
2071                  * \note
2072                  * If the package is registered as fault module,
2073                  * slave has not load it, so we don't need to do anything at here!
2074                  */
2075                 DbgPrint("Package[%s] is faulted\n", pkgname);
2076                 ret = LB_STATUS_ERROR_FAULT;
2077         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2078                 struct buffer_info *buffer;
2079                 struct slave_node *slave;
2080                 // struct packet *packet;
2081
2082                 buffer = instance_lb_buffer(inst);
2083                 if (!buffer) {
2084                         ErrPrint("Instance[%s] has no buffer\n", id);
2085                         ret = LB_STATUS_ERROR_FAULT;
2086                         goto out;
2087                 }
2088
2089                 slave = package_slave(pkg);
2090                 if (!slave) {
2091                         ErrPrint("Package[%s] has no slave\n", pkgname);
2092                         ret = LB_STATUS_ERROR_INVALID;
2093                         goto out;
2094                 }
2095
2096                 /*
2097                 packet = packet_create_noack("lb_mouse_down", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2098                 if (!packet) {
2099                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2100                         ret = LB_STATUS_ERROR_FAULT;
2101                         goto out;
2102                 }
2103                 */
2104
2105                 packet_ref((struct packet *)packet);
2106                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2107         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2108                 struct script_info *script;
2109                 Evas *e;
2110
2111                 script = instance_lb_script(inst);
2112                 if (!script) {
2113                         ret = LB_STATUS_ERROR_FAULT;
2114                         goto out;
2115                 }
2116
2117                 e = script_handler_evas(script);
2118                 if (!e) {
2119                         ret = LB_STATUS_ERROR_FAULT;
2120                         goto out;
2121                 }
2122
2123                 script_handler_update_pointer(script, x, y, 1);
2124                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
2125                 ret = 0;
2126         } else {
2127                 ErrPrint("Unsupported package\n");
2128                 ret = LB_STATUS_ERROR_INVALID;
2129         }
2130
2131 out:
2132         /*! \note No reply packet */
2133         return NULL;
2134 }
2135
2136 static struct packet *client_lb_mouse_up(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
2137 {
2138         struct client_node *client;
2139         const char *pkgname;
2140         const char *id;
2141         int ret;
2142         double timestamp;
2143         int x;
2144         int y;
2145         struct inst_info *inst;
2146         const struct pkg_info *pkg;
2147
2148         client = client_find_by_pid(pid);
2149         if (!client) {
2150                 ErrPrint("Client %d is not exists\n", pid);
2151                 ret = LB_STATUS_ERROR_NOT_EXIST;
2152                 goto out;
2153         }
2154
2155         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2156         if (ret != 5) {
2157                 ErrPrint("Parameter is not matched\n");
2158                 ret = LB_STATUS_ERROR_INVALID;
2159                 goto out;
2160         }
2161
2162         /*!
2163          * \NOTE:
2164          * Trust the package name which are sent by the client.
2165          * The package has to be a livebox package name.
2166          */
2167         inst = package_find_instance_by_id(pkgname, id);
2168         if (!inst) {
2169                 ErrPrint("Instance[%s] is not exists\n", id);
2170                 ret = LB_STATUS_ERROR_NOT_EXIST;
2171                 goto out;
2172         }
2173
2174         pkg = instance_package(inst);
2175         if (!pkg) {
2176                 ErrPrint("Package[%s] info is not exists\n", pkgname);
2177                 ret = LB_STATUS_ERROR_FAULT;
2178                 goto out;
2179         }
2180
2181         if (package_is_fault(pkg)) {
2182                 /*!
2183                  * \note
2184                  * If the package is registered as fault module,
2185                  * slave has not load it, so we don't need to do anything at here!
2186                  */
2187                 DbgPrint("Package[%s] is faulted\n", pkgname);
2188                 ret = LB_STATUS_ERROR_FAULT;
2189         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2190                 struct buffer_info *buffer;
2191                 struct slave_node *slave;
2192                 //struct packet *packet;
2193
2194                 buffer = instance_lb_buffer(inst);
2195                 if (!buffer) {
2196                         ErrPrint("Instance[%s] has no buffer\n", id);
2197                         ret = LB_STATUS_ERROR_FAULT;
2198                         goto out;
2199                 }
2200
2201                 slave = package_slave(pkg);
2202                 if (!slave) {
2203                         ErrPrint("Package[%s] has no slave\n", pkgname);
2204                         ret = LB_STATUS_ERROR_INVALID;
2205                         goto out;
2206                 }
2207
2208                 /*
2209                 packet = packet_create_noack("lb_mouse_up", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2210                 if (!packet) {
2211                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2212                         ret = LB_STATUS_ERROR_FAULT;
2213                         goto out;
2214                 }
2215                 */
2216
2217                 packet_ref((struct packet *)packet);
2218                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2219         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2220                 struct script_info *script;
2221                 Evas *e;
2222
2223                 script = instance_lb_script(inst);
2224                 if (!script) {
2225                         ret = LB_STATUS_ERROR_FAULT;
2226                         goto out;
2227                 }
2228
2229                 e = script_handler_evas(script);
2230                 if (!e) {
2231                         ret = LB_STATUS_ERROR_FAULT;
2232                         goto out;
2233                 }
2234
2235                 script_handler_update_pointer(script, x, y, 0);
2236                 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
2237                 ret = 0;
2238         } else {
2239                 ErrPrint("Unsupported package\n");
2240                 ret = LB_STATUS_ERROR_INVALID;
2241         }
2242
2243 out:
2244         /*! \note No reply packet */
2245         return NULL;
2246 }
2247
2248 static struct packet *client_pd_access_value_change(pid_t pid, int handle, const struct packet *packet)
2249 {
2250         struct packet *result;
2251         struct client_node *client;
2252         const char *pkgname;
2253         const char *id;
2254         int ret;
2255         double timestamp;
2256         int x;
2257         int y;
2258         struct inst_info *inst;
2259         const struct pkg_info *pkg;
2260
2261         client = client_find_by_pid(pid);
2262         if (!client) {
2263                 ErrPrint("Client %d is not exists\n", pid);
2264                 ret = LB_STATUS_ERROR_NOT_EXIST;
2265                 goto out;
2266         }
2267
2268         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2269         if (ret != 5) {
2270                 ErrPrint("Invalid parameter\n");
2271                 ret = LB_STATUS_ERROR_INVALID;
2272                 goto out;
2273         }
2274
2275         /*!
2276          * \NOTE:
2277          * Trust the package name which are sent by the client.
2278          * The package has to be a livebox package name.
2279          */
2280         inst = package_find_instance_by_id(pkgname, id);
2281         if (!inst) {
2282                 ErrPrint("Instance[%s] is not exists\n", id);
2283                 ret = LB_STATUS_ERROR_NOT_EXIST;
2284                 goto out;
2285         }
2286
2287         pkg = instance_package(inst);
2288         if (!pkg) {
2289                 ErrPrint("Package[%s] info is not found\n", pkgname);
2290                 ret = LB_STATUS_ERROR_FAULT;
2291                 goto out;
2292         }
2293
2294         if (package_is_fault(pkg)) {
2295                 /*!
2296                  * \note
2297                  * If the package is registered as fault module,
2298                  * slave has not load it, so we don't need to do anything at here!
2299                  */
2300                 DbgPrint("Package[%s] is faulted\n", pkgname);
2301                 ret = LB_STATUS_ERROR_FAULT;
2302         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2303                 struct buffer_info *buffer;
2304                 struct slave_node *slave;
2305                 // struct packet *packet;
2306
2307                 buffer = instance_pd_buffer(inst);
2308                 if (!buffer) {
2309                         ErrPrint("Instance[%s] has no buffer\n", id);
2310                         ret = LB_STATUS_ERROR_FAULT;
2311                         goto out;
2312                 }
2313
2314                 slave = package_slave(pkg);
2315                 if (!slave) {
2316                         ErrPrint("Package[%s] has no slave\n", pkgname);
2317                         ret = LB_STATUS_ERROR_INVALID;
2318                         goto out;
2319                 }
2320
2321                 /*
2322                 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2323                 if (!packet) {
2324                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2325                         ret = LB_STATUS_ERROR_FAULT;
2326                         goto out;
2327                 }
2328                 */
2329
2330                 packet_ref((struct packet *)packet);
2331                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2332         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2333                 struct script_info *script;
2334                 Evas *e;
2335
2336                 script = instance_pd_script(inst);
2337                 if (!script) {
2338                         ret = LB_STATUS_ERROR_FAULT;
2339                         goto out;
2340                 }
2341
2342                 e = script_handler_evas(script);
2343                 if (!e) {
2344                         ret = LB_STATUS_ERROR_FAULT;
2345                         goto out;
2346                 }
2347
2348                 script_handler_update_pointer(script, x, y, -1);
2349                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_VALUE_CHANGE, timestamp);
2350                 if (ret >= 0) {
2351                         struct access_cbdata *cbdata;
2352
2353                         cbdata = malloc(sizeof(*cbdata));
2354                         if (!cbdata) {
2355                                 ret = LB_STATUS_ERROR_MEMORY;
2356                         } else {
2357                                 cbdata->inst = instance_ref(inst);
2358                                 cbdata->status = ret;
2359
2360                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2361                                         instance_unref(cbdata->inst);
2362                                         free(cbdata);
2363                                         ret = LB_STATUS_ERROR_FAULT;
2364                                 } else {
2365                                         ret = LB_STATUS_SUCCESS;
2366                                 }
2367                         }
2368                 }
2369         } else {
2370                 ErrPrint("Unsupported package\n");
2371                 ret = LB_STATUS_ERROR_INVALID;
2372         }
2373
2374 out:
2375         result = packet_create_reply(packet, "i", ret);
2376         if (!result)
2377                 ErrPrint("Failed to create a reply packet\n");
2378
2379         return result;
2380 }
2381
2382 static struct packet *client_pd_access_scroll(pid_t pid, int handle, const struct packet *packet)
2383 {
2384         struct packet *result;
2385         struct client_node *client;
2386         const char *pkgname;
2387         const char *id;
2388         int ret;
2389         double timestamp;
2390         int x;
2391         int y;
2392         struct inst_info *inst;
2393         const struct pkg_info *pkg;
2394
2395         client = client_find_by_pid(pid);
2396         if (!client) {
2397                 ErrPrint("Client %d is not exists\n", pid);
2398                 ret = LB_STATUS_ERROR_NOT_EXIST;
2399                 goto out;
2400         }
2401
2402         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2403         if (ret != 5) {
2404                 ErrPrint("Invalid parameter\n");
2405                 ret = LB_STATUS_ERROR_INVALID;
2406                 goto out;
2407         }
2408
2409         /*!
2410          * \NOTE:
2411          * Trust the package name which are sent by the client.
2412          * The package has to be a livebox package name.
2413          */
2414         inst = package_find_instance_by_id(pkgname, id);
2415         if (!inst) {
2416                 ErrPrint("Instance[%s] is not exists\n", id);
2417                 ret = LB_STATUS_ERROR_NOT_EXIST;
2418                 goto out;
2419         }
2420
2421         pkg = instance_package(inst);
2422         if (!pkg) {
2423                 ErrPrint("Package[%s] info is not found\n", pkgname);
2424                 ret = LB_STATUS_ERROR_FAULT;
2425                 goto out;
2426         }
2427
2428         if (package_is_fault(pkg)) {
2429                 /*!
2430                  * \note
2431                  * If the package is registered as fault module,
2432                  * slave has not load it, so we don't need to do anything at here!
2433                  */
2434                 DbgPrint("Package[%s] is faulted\n", pkgname);
2435                 ret = LB_STATUS_ERROR_FAULT;
2436         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2437                 struct buffer_info *buffer;
2438                 struct slave_node *slave;
2439                 // struct packet *packet;
2440
2441                 buffer = instance_pd_buffer(inst);
2442                 if (!buffer) {
2443                         ErrPrint("Instance[%s] has no buffer\n", id);
2444                         ret = LB_STATUS_ERROR_FAULT;
2445                         goto out;
2446                 }
2447
2448                 slave = package_slave(pkg);
2449                 if (!slave) {
2450                         ErrPrint("Package[%s] has no slave\n", pkgname);
2451                         ret = LB_STATUS_ERROR_INVALID;
2452                         goto out;
2453                 }
2454
2455                 /*
2456                 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2457                 if (!packet) {
2458                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2459                         ret = LB_STATUS_ERROR_FAULT;
2460                         goto out;
2461                 }
2462                 */
2463
2464                 packet_ref((struct packet *)packet);
2465                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2466         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2467                 struct script_info *script;
2468                 Evas *e;
2469
2470                 script = instance_pd_script(inst);
2471                 if (!script) {
2472                         ret = LB_STATUS_ERROR_FAULT;
2473                         goto out;
2474                 }
2475
2476                 e = script_handler_evas(script);
2477                 if (!e) {
2478                         ret = LB_STATUS_ERROR_FAULT;
2479                         goto out;
2480                 }
2481
2482                 script_handler_update_pointer(script, x, y, -1);
2483                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
2484                 if (ret >= 0) {
2485                         struct access_cbdata *cbdata;
2486
2487                         cbdata = malloc(sizeof(*cbdata));
2488                         if (!cbdata) {
2489                                 ret = LB_STATUS_ERROR_MEMORY;
2490                         } else {
2491                                 cbdata->inst = instance_ref(inst);
2492                                 cbdata->status = ret;
2493
2494                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2495                                         instance_unref(cbdata->inst);
2496                                         free(cbdata);
2497                                         ret = LB_STATUS_ERROR_FAULT;
2498                                 } else {
2499                                         ret = LB_STATUS_SUCCESS;
2500                                 }
2501                         }
2502                 }
2503         } else {
2504                 ErrPrint("Unsupported package\n");
2505                 ret = LB_STATUS_ERROR_INVALID;
2506         }
2507
2508 out:
2509         result = packet_create_reply(packet, "i", ret);
2510         if (!result)
2511                 ErrPrint("Failed to create a reply packet\n");
2512
2513         return result;
2514 }
2515
2516 static struct packet *client_pd_access_unhighlight(pid_t pid, int handle, const struct packet *packet)
2517 {
2518         struct packet *result;
2519         struct client_node *client;
2520         const char *pkgname;
2521         const char *id;
2522         int x;
2523         int y;
2524         struct inst_info *inst;
2525         const struct pkg_info *pkg;
2526         int ret;
2527         double timestamp;
2528
2529         client = client_find_by_pid(pid);
2530         if (!client) {
2531                 ErrPrint("Client %d is not exists\n", pid);
2532                 ret = LB_STATUS_ERROR_NOT_EXIST;
2533                 goto out;
2534         }
2535
2536         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2537         if (ret != 5) {
2538                 ErrPrint("Invalid parameter\n");
2539                 ret = LB_STATUS_ERROR_INVALID;
2540                 goto out;
2541         }
2542
2543         inst = package_find_instance_by_id(pkgname, id);
2544         if (!inst) {
2545                 ErrPrint("Instance[%s] is not exists\n", id);
2546                 ret = LB_STATUS_ERROR_NOT_EXIST;
2547                 goto out;
2548         }
2549
2550         pkg = instance_package(inst);
2551         if (!pkg) {
2552                 ErrPrint("Package[%s] info is not found\n", pkgname);
2553                 ret = LB_STATUS_ERROR_FAULT;
2554                 goto out;
2555         }
2556
2557         if (package_is_fault(pkg)) {
2558                 DbgPrint("Package[%s] is faulted\n", pkgname);
2559                 ret = LB_STATUS_ERROR_FAULT;
2560         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2561                 struct buffer_info *buffer;
2562                 struct slave_node *slave;
2563                 // struct packet *packet;
2564
2565                 buffer = instance_pd_buffer(inst);
2566                 if (!buffer) {
2567                         ErrPrint("Instance[%s] has no buffer\n", id);
2568                         ret = LB_STATUS_ERROR_FAULT;
2569                         goto out;
2570                 }
2571
2572                 slave = package_slave(pkg);
2573                 if (!slave) {
2574                         ErrPrint("Package[%s] has no slave\n", pkgname);
2575                         ret = LB_STATUS_ERROR_INVALID;
2576                         goto out;
2577                 }
2578
2579                 /*
2580                 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2581                 if (!packet) {
2582                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2583                         ret = LB_STATUS_ERROR_FAULT;
2584                         goto out;
2585                 }
2586                 */
2587
2588                 packet_ref((struct packet *)packet);
2589                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2590         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2591                 struct script_info *script;
2592                 Evas *e;
2593
2594                 script = instance_pd_script(inst);
2595                 if (!script) {
2596                         ret = LB_STATUS_ERROR_FAULT;
2597                         goto out;
2598                 }
2599
2600                 e = script_handler_evas(script);
2601                 if (!e) {
2602                         ret = LB_STATUS_ERROR_FAULT;
2603                         goto out;
2604                 }
2605
2606                 script_handler_update_pointer(script, x, y, -1);
2607                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_UNHIGHLIGHT, timestamp);
2608                 if (ret >= 0) {
2609                         struct access_cbdata *cbdata;
2610
2611                         cbdata = malloc(sizeof(*cbdata));
2612                         if (!cbdata) {
2613                                 ret = LB_STATUS_ERROR_MEMORY;
2614                         } else {
2615                                 cbdata->inst = instance_ref(inst);
2616                                 cbdata->status = ret;
2617
2618                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2619                                         instance_unref(cbdata->inst);
2620                                         free(cbdata);
2621                                         ret = LB_STATUS_ERROR_FAULT;
2622                                 } else {
2623                                         ret = LB_STATUS_SUCCESS;
2624                                 }
2625                         }
2626                 }
2627         } else {
2628                 ErrPrint("Unsupported package\n");
2629                 ret = LB_STATUS_ERROR_INVALID;
2630         }
2631 out:
2632         result = packet_create_reply(packet, "i", ret);
2633         if (!result)
2634                 ErrPrint("Failed to create a reply packet\n");
2635
2636         return result;
2637 }
2638
2639 static struct packet *client_pd_access_hl(pid_t pid, int handle, const struct packet *packet)
2640 {
2641         struct packet *result;
2642         struct client_node *client;
2643         const char *pkgname;
2644         const char *id;
2645         int ret;
2646         double timestamp;
2647         int x;
2648         int y;
2649         struct inst_info *inst;
2650         const struct pkg_info *pkg;
2651
2652         client = client_find_by_pid(pid);
2653         if (!client) {
2654                 ErrPrint("Client %d is not exists\n", pid);
2655                 ret = LB_STATUS_ERROR_NOT_EXIST;
2656                 goto out;
2657         }
2658
2659         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2660         if (ret != 5) {
2661                 ErrPrint("Invalid parameter\n");
2662                 ret = LB_STATUS_ERROR_INVALID;
2663                 goto out;
2664         }
2665
2666         /*!
2667          * \NOTE:
2668          * Trust the package name which are sent by the client.
2669          * The package has to be a livebox package name.
2670          */
2671         inst = package_find_instance_by_id(pkgname, id);
2672         if (!inst) {
2673                 ErrPrint("Instance[%s] is not exists\n", id);
2674                 ret = LB_STATUS_ERROR_NOT_EXIST;
2675                 goto out;
2676         }
2677
2678         pkg = instance_package(inst);
2679         if (!pkg) {
2680                 ErrPrint("Package[%s] info is not found\n", pkgname);
2681                 ret = LB_STATUS_ERROR_FAULT;
2682                 goto out;
2683         }
2684
2685         if (package_is_fault(pkg)) {
2686                 /*!
2687                  * \note
2688                  * If the package is registered as fault module,
2689                  * slave has not load it, so we don't need to do anything at here!
2690                  */
2691                 DbgPrint("Package[%s] is faulted\n", pkgname);
2692                 ret = LB_STATUS_ERROR_FAULT;
2693         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2694                 struct buffer_info *buffer;
2695                 struct slave_node *slave;
2696                 // struct packet *packet;
2697
2698                 buffer = instance_pd_buffer(inst);
2699                 if (!buffer) {
2700                         ErrPrint("Instance[%s] has no buffer\n", id);
2701                         ret = LB_STATUS_ERROR_FAULT;
2702                         goto out;
2703                 }
2704
2705                 slave = package_slave(pkg);
2706                 if (!slave) {
2707                         ErrPrint("Package[%s] has no slave\n", pkgname);
2708                         ret = LB_STATUS_ERROR_INVALID;
2709                         goto out;
2710                 }
2711
2712                 /*
2713                 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2714                 if (!packet) {
2715                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2716                         ret = LB_STATUS_ERROR_FAULT;
2717                         goto out;
2718                 }
2719                 */
2720
2721                 packet_ref((struct packet *)packet);
2722                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2723         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2724                 struct script_info *script;
2725                 Evas *e;
2726
2727                 script = instance_pd_script(inst);
2728                 if (!script) {
2729                         ret = LB_STATUS_ERROR_FAULT;
2730                         goto out;
2731                 }
2732
2733                 e = script_handler_evas(script);
2734                 if (!e) {
2735                         ret = LB_STATUS_ERROR_FAULT;
2736                         goto out;
2737                 }
2738
2739                 script_handler_update_pointer(script, x, y, -1);
2740                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT, timestamp);
2741                 if (ret >= 0) {
2742                         struct access_cbdata *cbdata;
2743
2744                         cbdata = malloc(sizeof(*cbdata));
2745                         if (!cbdata) {
2746                                 ret = LB_STATUS_ERROR_MEMORY;
2747                         } else {
2748                                 cbdata->inst = instance_ref(inst);
2749                                 cbdata->status = ret;
2750
2751                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2752                                         instance_unref(cbdata->inst);
2753                                         free(cbdata);
2754                                         ret = LB_STATUS_ERROR_FAULT;
2755                                 } else {
2756                                         ret = LB_STATUS_SUCCESS;
2757                                 }
2758                         }
2759                 }
2760         } else {
2761                 ErrPrint("Unsupported package\n");
2762                 ret = LB_STATUS_ERROR_INVALID;
2763         }
2764
2765 out:
2766         result = packet_create_reply(packet, "i", ret);
2767         if (!result)
2768                 ErrPrint("Failed to create a reply packet\n");
2769
2770         return result;
2771 }
2772
2773 static struct packet *client_pd_access_hl_prev(pid_t pid, int handle, const struct packet *packet)
2774 {
2775         struct packet *result;
2776         struct client_node *client;
2777         const char *pkgname;
2778         const char *id;
2779         int ret;
2780         double timestamp;
2781         int x;
2782         int y;
2783         struct inst_info *inst;
2784         const struct pkg_info *pkg;
2785
2786         client = client_find_by_pid(pid);
2787         if (!client) {
2788                 ErrPrint("Client %d is not exists\n", pid);
2789                 ret = LB_STATUS_ERROR_NOT_EXIST;
2790                 goto out;
2791         }
2792
2793         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
2794         if (ret != 5) {
2795                 ErrPrint("Invalid parameter\n");
2796                 ret = LB_STATUS_ERROR_INVALID;
2797                 goto out;
2798         }
2799
2800         /*!
2801          * \NOTE:
2802          * Trust the package name which are sent by the client.
2803          * The package has to be a livebox package name.
2804          */
2805         inst = package_find_instance_by_id(pkgname, id);
2806         if (!inst) {
2807                 ErrPrint("Instance[%s] is not exists\n", id);
2808                 ret = LB_STATUS_ERROR_NOT_EXIST;
2809                 goto out;
2810         }
2811
2812         pkg = instance_package(inst);
2813         if (!pkg) {
2814                 ErrPrint("Package[%s] info is not found\n", pkgname);
2815                 ret = LB_STATUS_ERROR_FAULT;
2816                 goto out;
2817         }
2818
2819         if (package_is_fault(pkg)) {
2820                 /*!
2821                  * \note
2822                  * If the package is registered as fault module,
2823                  * slave has not load it, so we don't need to do anything at here!
2824                  */
2825                 DbgPrint("Package[%s] is faulted\n", pkgname);
2826                 ret = LB_STATUS_ERROR_FAULT;
2827         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2828                 struct buffer_info *buffer;
2829                 struct slave_node *slave;
2830                 // struct packet *packet;
2831
2832                 buffer = instance_pd_buffer(inst);
2833                 if (!buffer) {
2834                         ErrPrint("Instance[%s] has no buffer\n", id);
2835                         ret = LB_STATUS_ERROR_FAULT;
2836                         goto out;
2837                 }
2838
2839                 slave = package_slave(pkg);
2840                 if (!slave) {
2841                         ErrPrint("Package[%s] has no slave\n", pkgname);
2842                         ret = LB_STATUS_ERROR_INVALID;
2843                         goto out;
2844                 }
2845
2846                 /*
2847                 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2848                 if (!packet) {
2849                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2850                         ret = LB_STATUS_ERROR_FAULT;
2851                         goto out;
2852                 }
2853                 */
2854
2855                 packet_ref((struct packet *)packet);
2856                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2857         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2858                 struct script_info *script;
2859                 Evas *e;
2860
2861                 script = instance_pd_script(inst);
2862                 if (!script) {
2863                         ret = LB_STATUS_ERROR_FAULT;
2864                         goto out;
2865                 }
2866
2867                 e = script_handler_evas(script);
2868                 if (!e) {
2869                         ret = LB_STATUS_ERROR_FAULT;
2870                         goto out;
2871                 }
2872
2873                 script_handler_update_pointer(script, x, y, -1);
2874                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_PREV, timestamp);
2875                 if (ret >= 0) {
2876                         struct access_cbdata *cbdata;
2877
2878                         cbdata = malloc(sizeof(*cbdata));
2879                         if (!cbdata) {
2880                                 ret = LB_STATUS_ERROR_MEMORY;
2881                         } else {
2882                                 cbdata->inst = instance_ref(inst);
2883                                 cbdata->status = ret;
2884
2885                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2886                                         instance_unref(cbdata->inst);
2887                                         free(cbdata);
2888                                         ret = LB_STATUS_ERROR_FAULT;
2889                                 } else {
2890                                         ret = LB_STATUS_SUCCESS;
2891                                 }
2892                         }
2893                 }
2894         } else {
2895                 ErrPrint("Unsupported package\n");
2896                 ret = LB_STATUS_ERROR_INVALID;
2897         }
2898
2899 out:
2900         result = packet_create_reply(packet, "i", ret);
2901         if (!result)
2902                 ErrPrint("Failed to create a reply packet\n");
2903
2904         return result;
2905 }
2906
2907 static struct packet *client_pd_access_hl_next(pid_t pid, int handle, const struct packet *packet)
2908 {
2909         struct packet *result;
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_pid(pid);
2921         if (!client) {
2922                 ErrPrint("Client %d is not exists\n", pid);
2923                 ret = LB_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("Invalid parameter\n");
2930                 ret = LB_STATUS_ERROR_INVALID;
2931                 goto out;
2932         }
2933
2934         DbgPrint("%s %s %lf %d %d\n", pkgname, id, timestamp, x, y);
2935         /*!
2936          * \NOTE:
2937          * Trust the package name which are sent by the client.
2938          * The package has to be a livebox package name.
2939          */
2940         inst = package_find_instance_by_id(pkgname, id);
2941         if (!inst) {
2942                 ErrPrint("Instance[%s] is not exists\n", id);
2943                 ret = LB_STATUS_ERROR_NOT_EXIST;
2944                 goto out;
2945         }
2946
2947         pkg = instance_package(inst);
2948         if (!pkg) {
2949                 ErrPrint("Package[%s] info is not found\n", pkgname);
2950                 ret = LB_STATUS_ERROR_FAULT;
2951                 goto out;
2952         }
2953
2954         if (package_is_fault(pkg)) {
2955                 /*!
2956                  * \note
2957                  * If the package is registered as fault module,
2958                  * slave has not load it, so we don't need to do anything at here!
2959                  */
2960                 DbgPrint("Package[%s] is faulted\n", pkgname);
2961                 ret = LB_STATUS_ERROR_FAULT;
2962         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2963                 struct buffer_info *buffer;
2964                 struct slave_node *slave;
2965                 // struct packet *packet;
2966
2967                 buffer = instance_pd_buffer(inst);
2968                 if (!buffer) {
2969                         ErrPrint("Instance[%s] has no buffer\n", id);
2970                         ret = LB_STATUS_ERROR_FAULT;
2971                         goto out;
2972                 }
2973
2974                 slave = package_slave(pkg);
2975                 if (!slave) {
2976                         ErrPrint("Package[%s] has no slave\n", pkgname);
2977                         ret = LB_STATUS_ERROR_INVALID;
2978                         goto out;
2979                 }
2980
2981                 /*
2982                 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2983                 if (!packet) {
2984                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2985                         ret = LB_STATUS_ERROR_FAULT;
2986                         goto out;
2987                 }
2988                 */
2989                 DbgPrint("Buffer type PD\n");
2990
2991                 packet_ref((struct packet *)packet);
2992                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2993         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2994                 struct script_info *script;
2995                 Evas *e;
2996
2997                 script = instance_pd_script(inst);
2998                 if (!script) {
2999                         DbgPrint("Script is not created yet\n");
3000                         ret = LB_STATUS_ERROR_FAULT;
3001                         goto out;
3002                 }
3003
3004                 e = script_handler_evas(script);
3005                 if (!e) {
3006                         DbgPrint("Evas is not exists\n");
3007                         ret = LB_STATUS_ERROR_FAULT;
3008                         goto out;
3009                 }
3010
3011                 script_handler_update_pointer(script, x, y, -1);
3012                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT, timestamp);
3013                 if (ret >= 0) {
3014                         struct access_cbdata *cbdata;
3015
3016                         cbdata = malloc(sizeof(*cbdata));
3017                         if (!cbdata) {
3018                                 ErrPrint("Heap: %s\n", strerror(errno));
3019                                 ret = LB_STATUS_ERROR_MEMORY;
3020                         } else {
3021                                 cbdata->inst = instance_ref(inst);
3022                                 cbdata->status = ret;
3023
3024                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3025                                         DbgPrint("Failed to add timer\n");
3026                                         instance_unref(cbdata->inst);
3027                                         free(cbdata);
3028                                         ret = LB_STATUS_ERROR_FAULT;
3029                                 } else {
3030                                         DbgPrint("Timer is added\n");
3031                                         ret = LB_STATUS_SUCCESS;
3032                                 }
3033                         }
3034                 } else {
3035                         DbgPrint("Returns: %d\n", ret);
3036                 }
3037         } else {
3038                 ErrPrint("Unsupported package\n");
3039                 ret = LB_STATUS_ERROR_INVALID;
3040         }
3041
3042 out:
3043         result = packet_create_reply(packet, "i", ret);
3044         if (!result)
3045                 ErrPrint("Failed to create a reply packet\n");
3046
3047         return result;
3048 }
3049
3050 static struct packet *client_pd_access_activate(pid_t pid, int handle, const struct packet *packet)
3051 {
3052         struct packet *result;
3053         struct client_node *client;
3054         const char *pkgname;
3055         const char *id;
3056         int ret;
3057         double timestamp;
3058         int x;
3059         int y;
3060         struct inst_info *inst;
3061         const struct pkg_info *pkg;
3062
3063         client = client_find_by_pid(pid);
3064         if (!client) {
3065                 ErrPrint("Client %d is not exists\n", pid);
3066                 ret = LB_STATUS_ERROR_NOT_EXIST;
3067                 goto out;
3068         }
3069
3070         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
3071         if (ret != 5) {
3072                 ErrPrint("Invalid parameter\n");
3073                 ret = LB_STATUS_ERROR_INVALID;
3074                 goto out;
3075         }
3076
3077         /*!
3078          * \NOTE:
3079          * Trust the package name which are sent by the client.
3080          * The package has to be a livebox package name.
3081          */
3082         inst = package_find_instance_by_id(pkgname, id);
3083         if (!inst) {
3084                 ErrPrint("Instance[%s] is not exists\n", id);
3085                 ret = LB_STATUS_ERROR_NOT_EXIST;
3086                 goto out;
3087         }
3088
3089         pkg = instance_package(inst);
3090         if (!pkg) {
3091                 ErrPrint("Package[%s] info is not found\n", pkgname);
3092                 ret = LB_STATUS_ERROR_FAULT;
3093                 goto out;
3094         }
3095
3096         if (package_is_fault(pkg)) {
3097                 /*!
3098                  * \note
3099                  * If the package is registered as fault module,
3100                  * slave has not load it, so we don't need to do anything at here!
3101                  */
3102                 DbgPrint("Package[%s] is faulted\n", pkgname);
3103                 ret = LB_STATUS_ERROR_FAULT;
3104         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3105                 struct buffer_info *buffer;
3106                 struct slave_node *slave;
3107                 // struct packet *packet;
3108
3109                 buffer = instance_pd_buffer(inst);
3110                 if (!buffer) {
3111                         ErrPrint("Instance[%s] has no buffer\n", id);
3112                         ret = LB_STATUS_ERROR_FAULT;
3113                         goto out;
3114                 }
3115
3116                 slave = package_slave(pkg);
3117                 if (!slave) {
3118                         ErrPrint("Package[%s] has no slave\n", pkgname);
3119                         ret = LB_STATUS_ERROR_INVALID;
3120                         goto out;
3121                 }
3122
3123                 /*
3124                 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
3125                 if (!packet) {
3126                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
3127                         ret = LB_STATUS_ERROR_FAULT;
3128                         goto out;
3129                 }
3130                 */
3131
3132                 packet_ref((struct packet *)packet);
3133                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
3134         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3135                 struct script_info *script;
3136                 Evas *e;
3137
3138                 script = instance_pd_script(inst);
3139                 if (!script) {
3140                         ret = LB_STATUS_ERROR_FAULT;
3141                         goto out;
3142                 }
3143
3144                 e = script_handler_evas(script);
3145                 if (!e) {
3146                         ret = LB_STATUS_ERROR_FAULT;
3147                         goto out;
3148                 }
3149
3150                 script_handler_update_pointer(script, x, y, -1);
3151                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTIVATE, timestamp);
3152                 if (ret >= 0) {
3153                         struct access_cbdata *cbdata;
3154
3155                         cbdata = malloc(sizeof(*cbdata));
3156                         if (!cbdata) {
3157                                 ret = LB_STATUS_ERROR_MEMORY;
3158                         } else {
3159                                 cbdata->inst = instance_ref(inst);
3160                                 cbdata->status = ret;
3161
3162                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3163                                         instance_unref(cbdata->inst);
3164                                         free(cbdata);
3165                                         ret = LB_STATUS_ERROR_FAULT;
3166                                 } else {
3167                                         ret = LB_STATUS_SUCCESS;
3168                                 }
3169                         }
3170                 }
3171         } else {
3172                 ErrPrint("Unsupported package\n");
3173                 ret = LB_STATUS_ERROR_INVALID;
3174         }
3175
3176 out:
3177         result = packet_create_reply(packet, "i", ret);
3178         if (!result)
3179                 ErrPrint("Failed to create a reply packet\n");
3180
3181         return result;
3182 }
3183
3184 static struct packet *client_pd_key_down(pid_t pid, int handle, const struct packet *packet)
3185 {
3186         struct client_node *client;
3187         const char *pkgname;
3188         const char *id;
3189         int ret;
3190         double timestamp;
3191         int x;
3192         int y;
3193         struct inst_info *inst;
3194         const struct pkg_info *pkg;
3195
3196         client = client_find_by_pid(pid);
3197         if (!client) {
3198                 ErrPrint("Client %d is not exists\n", pid);
3199                 ret = LB_STATUS_ERROR_NOT_EXIST;
3200                 goto out;
3201         }
3202
3203         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
3204         if (ret != 5) {
3205                 ErrPrint("Invalid parameter\n");
3206                 ret = LB_STATUS_ERROR_INVALID;
3207                 goto out;
3208         }
3209
3210         /*!
3211          * \NOTE:
3212          * Trust the package name which are sent by the client.
3213          * The package has to be a livebox package name.
3214          */
3215         inst = package_find_instance_by_id(pkgname, id);
3216         if (!inst) {
3217                 ErrPrint("Instance[%s] is not exists\n", id);
3218                 ret = LB_STATUS_ERROR_NOT_EXIST;
3219                 goto out;
3220         }
3221
3222         pkg = instance_package(inst);
3223         if (!pkg) {
3224                 ErrPrint("Package[%s] info is not found\n", pkgname);
3225                 ret = LB_STATUS_ERROR_FAULT;
3226                 goto out;
3227         }
3228
3229         if (package_is_fault(pkg)) {
3230                 /*!
3231                  * \note
3232                  * If the package is registered as fault module,
3233                  * slave has not load it, so we don't need to do anything at here!
3234                  */
3235                 DbgPrint("Package[%s] is faulted\n", pkgname);
3236                 ret = LB_STATUS_ERROR_FAULT;
3237         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3238                 struct buffer_info *buffer;
3239                 struct slave_node *slave;
3240                 // struct packet *packet;
3241
3242                 buffer = instance_pd_buffer(inst);
3243                 if (!buffer) {
3244                         ErrPrint("Instance[%s] has no buffer\n", id);
3245                         ret = LB_STATUS_ERROR_FAULT;
3246                         goto out;
3247                 }
3248
3249                 slave = package_slave(pkg);
3250                 if (!slave) {
3251                         ErrPrint("Package[%s] has no slave\n", pkgname);
3252                         ret = LB_STATUS_ERROR_INVALID;
3253                         goto out;
3254                 }
3255
3256                 /*
3257                 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
3258                 if (!packet) {
3259                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
3260                         ret = LB_STATUS_ERROR_FAULT;
3261                         goto out;
3262                 }
3263                 */
3264
3265                 packet_ref((struct packet *)packet);
3266                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
3267         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3268                 struct script_info *script;
3269                 Evas *e;
3270
3271                 script = instance_pd_script(inst);
3272                 if (!script) {
3273                         ret = LB_STATUS_ERROR_FAULT;
3274                         goto out;
3275                 }
3276
3277                 e = script_handler_evas(script);
3278                 if (!e) {
3279                         ret = LB_STATUS_ERROR_FAULT;
3280                         goto out;
3281                 }
3282
3283                 script_handler_update_pointer(script, x, y, -1);
3284                 /*!
3285                  * \TODO: Push up the KEY_DOWN event
3286                  */
3287                 ret = 0;
3288         } else {
3289                 ErrPrint("Unsupported package\n");
3290                 ret = LB_STATUS_ERROR_INVALID;
3291         }
3292
3293 out:
3294         /*! \note No reply packet */
3295         return NULL;
3296 }
3297
3298 static struct packet *client_pause_request(pid_t pid, int handle, const struct packet *packet)
3299 {
3300         struct client_node *client;
3301         double timestamp;
3302         int ret;
3303
3304         client = client_find_by_pid(pid);
3305         if (!client) {
3306                 ErrPrint("Client %d is paused - manually reported\n", pid);
3307                 ret = LB_STATUS_ERROR_NOT_EXIST;
3308                 goto out;
3309         }
3310
3311         ret = packet_get(packet, "d", &timestamp);
3312         if (ret != 1) {
3313                 ErrPrint("Invalid parameter\n");
3314                 ret = LB_STATUS_ERROR_INVALID;
3315                 goto out;
3316         }
3317
3318         if (USE_XMONITOR)
3319                 DbgPrint("XMONITOR enabled. ignore client paused request\n");
3320         else
3321                 xmonitor_pause(client);
3322
3323 out:
3324         return NULL;
3325 }
3326
3327 static struct packet *client_resume_request(pid_t pid, int handle, const struct packet *packet)
3328 {
3329         struct client_node *client;
3330         double timestamp;
3331         int ret;
3332
3333         client = client_find_by_pid(pid);
3334         if (!client) {
3335                 ErrPrint("Client %d is not exists\n", pid);
3336                 goto out;
3337         }
3338
3339         ret = packet_get(packet, "d", &timestamp);
3340         if (ret != 1) {
3341                 ErrPrint("Invalid parameter\n");
3342                 goto out;
3343         }
3344
3345         if (USE_XMONITOR)
3346                 DbgPrint("XMONITOR enabled. ignore client resumed request\n");
3347         else
3348                 xmonitor_resume(client);
3349
3350 out:
3351         return NULL;
3352 }
3353
3354 static struct packet *client_pd_key_up(pid_t pid, int handle, const struct packet *packet)
3355 {
3356         struct client_node *client;
3357         const char *pkgname;
3358         const char *id;
3359         int ret;
3360         double timestamp;
3361         int x;
3362         int y;
3363         struct inst_info *inst;
3364         const struct pkg_info *pkg;
3365
3366         client = client_find_by_pid(pid);
3367         if (!client) {
3368                 ErrPrint("Client %d is not exists\n", pid);
3369                 ret = LB_STATUS_ERROR_NOT_EXIST;
3370                 goto out;
3371         }
3372
3373         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
3374         if (ret != 7) {
3375                 ErrPrint("Invalid parameter\n");
3376                 ret = LB_STATUS_ERROR_INVALID;
3377                 goto out;
3378         }
3379
3380         /*!
3381          * \NOTE:
3382          * Trust the package name which are sent by the client.
3383          * The package has to be a livebox package name.
3384          */
3385         inst = package_find_instance_by_id(pkgname, id);
3386         if (!inst) {
3387                 ErrPrint("Instance[%s] is not exists\n", id);
3388                 ret = LB_STATUS_ERROR_NOT_EXIST;
3389                 goto out;
3390         }
3391
3392         pkg = instance_package(inst);
3393         if (!pkg) {
3394                 ErrPrint("Package[%s] info is not found\n", pkgname);
3395                 ret = LB_STATUS_ERROR_FAULT;
3396                 goto out;
3397         }
3398
3399         if (package_is_fault(pkg)) {
3400                 /*!
3401                  * \note
3402                  * If the package is registered as fault module,
3403                  * slave has not load it, so we don't need to do anything at here!
3404                  */
3405                 DbgPrint("Package[%s] is faulted\n", pkgname);
3406                 ret = LB_STATUS_ERROR_FAULT;
3407         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3408                 struct buffer_info *buffer;
3409                 struct slave_node *slave;
3410                 // struct packet *packet;
3411
3412                 buffer = instance_pd_buffer(inst);
3413                 if (!buffer) {
3414                         ErrPrint("Instance[%s] has no buffer\n", id);
3415                         ret = LB_STATUS_ERROR_FAULT;
3416                         goto out;
3417                 }
3418
3419                 slave = package_slave(pkg);
3420                 if (!slave) {
3421                         ErrPrint("Package[%s] has no slave\n", pkgname);
3422                         ret = LB_STATUS_ERROR_INVALID;
3423                         goto out;
3424                 }
3425
3426                 /*
3427                 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
3428                 if (!packet) {
3429                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
3430                         ret = LB_STATUS_ERROR_FAULT;
3431                         goto out;
3432                 }
3433                 */
3434
3435                 packet_ref((struct packet *)packet);
3436                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
3437         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3438                 struct script_info *script;
3439                 Evas *e;
3440
3441                 script = instance_pd_script(inst);
3442                 if (!script) {
3443                         ret = LB_STATUS_ERROR_FAULT;
3444                         goto out;
3445                 }
3446
3447                 e = script_handler_evas(script);
3448                 if (!e) {
3449                         ret = LB_STATUS_ERROR_FAULT;
3450                         goto out;
3451                 }
3452
3453                 script_handler_update_pointer(script, x, y, -1);
3454                 /*!
3455                  * \TODO: Push up the KEY_UP event
3456                  */
3457                 ret = 0;
3458         } else {
3459                 ErrPrint("Unsupported package\n");
3460                 ret = LB_STATUS_ERROR_INVALID;
3461         }
3462
3463 out:
3464         /*! \note No reply packet */
3465         return NULL;
3466 }
3467
3468 static struct packet *client_lb_access_hl(pid_t pid, int handle, const struct packet *packet)
3469 {
3470         struct packet *result;
3471         struct client_node *client;
3472         const char *pkgname;
3473         const char *id;
3474         int ret;
3475         double timestamp;
3476         int x;
3477         int y;
3478         struct inst_info *inst;
3479         const struct pkg_info *pkg;
3480
3481         client = client_find_by_pid(pid);
3482         if (!client) {
3483                 ErrPrint("Client %d is not exists\n", pid);
3484                 ret = LB_STATUS_ERROR_NOT_EXIST;
3485                 goto out;
3486         }
3487
3488         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
3489         if (ret != 5) {
3490                 ErrPrint("Parameter is not matched\n");
3491                 ret = LB_STATUS_ERROR_INVALID;
3492                 goto out;
3493         }
3494
3495         /*!
3496          * \NOTE:
3497          * Trust the package name which are sent by the client.
3498          * The package has to be a livebox package name.
3499          */
3500         inst = package_find_instance_by_id(pkgname, id);
3501         if (!inst) {
3502                 ErrPrint("Instance[%s] is not exists\n", id);
3503                 ret = LB_STATUS_ERROR_NOT_EXIST;
3504                 goto out;
3505         }
3506
3507         pkg = instance_package(inst);
3508         if (!pkg) {
3509                 ErrPrint("Package[%s] info is not exists\n", pkgname);
3510                 ret = LB_STATUS_ERROR_FAULT;
3511                 goto out;
3512         }
3513
3514         if (package_is_fault(pkg)) {
3515                 /*!
3516                  * \note
3517                  * If the package is registered as fault module,
3518                  * slave has not load it, so we don't need to do anything at here!
3519                  */
3520                 DbgPrint("Package[%s] is faulted\n", pkgname);
3521                 ret = LB_STATUS_ERROR_FAULT;
3522         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3523                 struct buffer_info *buffer;
3524                 struct slave_node *slave;
3525                 //struct packet *packet;
3526
3527                 buffer = instance_lb_buffer(inst);
3528                 if (!buffer) {
3529                         ErrPrint("Instance[%s] has no buffer\n", id);
3530                         ret = LB_STATUS_ERROR_FAULT;
3531                         goto out;
3532                 }
3533
3534                 slave = package_slave(pkg);
3535                 if (!slave) {
3536                         ErrPrint("Package[%s] has no slave\n", pkgname);
3537                         ret = LB_STATUS_ERROR_INVALID;
3538                         goto out;
3539                 }
3540
3541                 /*
3542                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
3543                 if (!packet) {
3544                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
3545                         ret = LB_STATUS_ERROR_FAULT;
3546                         goto out;
3547                 }
3548                 */
3549
3550                 packet_ref((struct packet *)packet);
3551                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
3552         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3553                 struct script_info *script;
3554                 Evas *e;
3555
3556                 script = instance_lb_script(inst);
3557                 if (!script) {
3558                         ret = LB_STATUS_ERROR_FAULT;
3559                         goto out;
3560                 }
3561
3562                 e = script_handler_evas(script);
3563                 if (!e) {
3564                         ret = LB_STATUS_ERROR_FAULT;
3565                         goto out;
3566                 }
3567
3568                 script_handler_update_pointer(script, x, y, -1);
3569                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT, timestamp);
3570                 if (ret >= 0) {
3571                         struct access_cbdata *cbdata;
3572
3573                         cbdata = malloc(sizeof(*cbdata));
3574                         if (!cbdata) {
3575                                 ret = LB_STATUS_ERROR_MEMORY;
3576                         } else {
3577                                 cbdata->inst = instance_ref(inst);
3578                                 cbdata->status = ret;
3579
3580                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3581                                         instance_unref(cbdata->inst);
3582                                         free(cbdata);
3583                                         ret = LB_STATUS_ERROR_FAULT;
3584                                 } else {
3585                                         ret = LB_STATUS_SUCCESS;
3586                                 }
3587                         }
3588                 }
3589         } else {
3590                 ErrPrint("Unsupported package\n");
3591                 ret = LB_STATUS_ERROR_INVALID;
3592         }
3593
3594 out:
3595         result = packet_create_reply(packet, "i", ret);
3596         if (!result)
3597                 ErrPrint("Failed to create a reply packet\n");
3598
3599         return result;
3600 }
3601
3602 static struct packet *client_lb_access_hl_prev(pid_t pid, int handle, const struct packet *packet)
3603 {
3604         struct packet *result;
3605         struct client_node *client;
3606         const char *pkgname;
3607         const char *id;
3608         int ret;
3609         double timestamp;
3610         int x;
3611         int y;
3612         struct inst_info *inst;
3613         const struct pkg_info *pkg;
3614
3615         client = client_find_by_pid(pid);
3616         if (!client) {
3617                 ErrPrint("Client %d is not exists\n", pid);
3618                 ret = LB_STATUS_ERROR_NOT_EXIST;
3619                 goto out;
3620         }
3621
3622         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
3623         if (ret != 5) {
3624                 ErrPrint("Parameter is not matched\n");
3625                 ret = LB_STATUS_ERROR_INVALID;
3626                 goto out;
3627         }
3628
3629         /*!
3630          * \NOTE:
3631          * Trust the package name which are sent by the client.
3632          * The package has to be a livebox package name.
3633          */
3634         inst = package_find_instance_by_id(pkgname, id);
3635         if (!inst) {
3636                 ErrPrint("Instance[%s] is not exists\n", id);
3637                 ret = LB_STATUS_ERROR_NOT_EXIST;
3638                 goto out;
3639         }
3640
3641         pkg = instance_package(inst);
3642         if (!pkg) {
3643                 ErrPrint("Package[%s] info is not exists\n", pkgname);
3644                 ret = LB_STATUS_ERROR_FAULT;
3645                 goto out;
3646         }
3647
3648         if (package_is_fault(pkg)) {
3649                 /*!
3650                  * \note
3651                  * If the package is registered as fault module,
3652                  * slave has not load it, so we don't need to do anything at here!
3653                  */
3654                 DbgPrint("Package[%s] is faulted\n", pkgname);
3655                 ret = LB_STATUS_ERROR_FAULT;
3656         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3657                 struct buffer_info *buffer;
3658                 struct slave_node *slave;
3659                 //struct packet *packet;
3660
3661                 buffer = instance_lb_buffer(inst);
3662                 if (!buffer) {
3663                         ErrPrint("Instance[%s] has no buffer\n", id);
3664                         ret = LB_STATUS_ERROR_FAULT;
3665                         goto out;
3666                 }
3667
3668                 slave = package_slave(pkg);
3669                 if (!slave) {
3670                         ErrPrint("Package[%s] has no slave\n", pkgname);
3671                         ret = LB_STATUS_ERROR_INVALID;
3672                         goto out;
3673                 }
3674
3675                 /*
3676                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
3677                 if (!packet) {
3678                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
3679                         ret = LB_STATUS_ERROR_FAULT;
3680                         goto out;
3681                 }
3682                 */
3683
3684                 packet_ref((struct packet *)packet);
3685                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
3686         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3687                 struct script_info *script;
3688                 Evas *e;
3689
3690                 script = instance_lb_script(inst);
3691                 if (!script) {
3692                         ret = LB_STATUS_ERROR_FAULT;
3693                         goto out;
3694                 }
3695
3696                 e = script_handler_evas(script);
3697                 if (!e) {
3698                         ret = LB_STATUS_ERROR_FAULT;
3699                         goto out;
3700                 }
3701
3702                 script_handler_update_pointer(script, x, y, -1);
3703                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_PREV, timestamp);
3704                 if (ret >= 0) {
3705                         struct access_cbdata *cbdata;
3706
3707                         cbdata = malloc(sizeof(*cbdata));
3708                         if (!cbdata) {
3709                                 ret = LB_STATUS_ERROR_MEMORY;
3710                         } else {
3711                                 cbdata->inst = instance_ref(inst);
3712                                 cbdata->status = ret;
3713
3714                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3715                                         instance_unref(cbdata->inst);
3716                                         free(cbdata);
3717                                         ret = LB_STATUS_ERROR_FAULT;
3718                                 } else {
3719                                         ret = LB_STATUS_SUCCESS;
3720                                 }
3721                         }
3722                 }
3723         } else {
3724                 ErrPrint("Unsupported package\n");
3725                 ret = LB_STATUS_ERROR_INVALID;
3726         }
3727
3728 out:
3729         result = packet_create_reply(packet, "i", ret);
3730         if (!result)
3731                 ErrPrint("Failed to create a reply packet\n");
3732
3733         return result;
3734 }
3735
3736 static struct packet *client_lb_access_hl_next(pid_t pid, int handle, const struct packet *packet)
3737 {
3738         struct packet *result;
3739         struct client_node *client;
3740         const char *pkgname;
3741         const char *id;
3742         int ret;
3743         double timestamp;
3744         int x;
3745         int y;
3746         struct inst_info *inst;
3747         const struct pkg_info *pkg;
3748
3749         client = client_find_by_pid(pid);
3750         if (!client) {
3751                 ErrPrint("Client %d is not exists\n", pid);
3752                 ret = LB_STATUS_ERROR_NOT_EXIST;
3753                 goto out;
3754         }
3755
3756         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
3757         if (ret != 5) {
3758                 ErrPrint("Parameter is not matched\n");
3759                 ret = LB_STATUS_ERROR_INVALID;
3760                 goto out;
3761         }
3762
3763         /*!
3764          * \NOTE:
3765          * Trust the package name which are sent by the client.
3766          * The package has to be a livebox package name.
3767          */
3768         inst = package_find_instance_by_id(pkgname, id);
3769         if (!inst) {
3770                 ErrPrint("Instance[%s] is not exists\n", id);
3771                 ret = LB_STATUS_ERROR_NOT_EXIST;
3772                 goto out;
3773         }
3774
3775         pkg = instance_package(inst);
3776         if (!pkg) {
3777                 ErrPrint("Package[%s] info is not exists\n", pkgname);
3778                 ret = LB_STATUS_ERROR_FAULT;
3779                 goto out;
3780         }
3781
3782         if (package_is_fault(pkg)) {
3783                 /*!
3784                  * \note
3785                  * If the package is registered as fault module,
3786                  * slave has not load it, so we don't need to do anything at here!
3787                  */
3788                 DbgPrint("Package[%s] is faulted\n", pkgname);
3789                 ret = LB_STATUS_ERROR_FAULT;
3790         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3791                 struct buffer_info *buffer;
3792                 struct slave_node *slave;
3793                 //struct packet *packet;
3794
3795                 buffer = instance_lb_buffer(inst);
3796                 if (!buffer) {
3797                         ErrPrint("Instance[%s] has no buffer\n", id);
3798                         ret = LB_STATUS_ERROR_FAULT;
3799                         goto out;
3800                 }
3801
3802                 slave = package_slave(pkg);
3803                 if (!slave) {
3804                         ErrPrint("Package[%s] has no slave\n", pkgname);
3805                         ret = LB_STATUS_ERROR_INVALID;
3806                         goto out;
3807                 }
3808
3809                 /*
3810                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
3811                 if (!packet) {
3812                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
3813                         ret = LB_STATUS_ERROR_FAULT;
3814                         goto out;
3815                 }
3816                 */
3817
3818                 packet_ref((struct packet *)packet);
3819                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
3820         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3821                 struct script_info *script;
3822                 Evas *e;
3823
3824                 script = instance_lb_script(inst);
3825                 if (!script) {
3826                         ret = LB_STATUS_ERROR_FAULT;
3827                         goto out;
3828                 }
3829
3830                 e = script_handler_evas(script);
3831                 if (!e) {
3832                         ret = LB_STATUS_ERROR_FAULT;
3833                         goto out;
3834                 }
3835
3836                 script_handler_update_pointer(script, x, y, -1);
3837                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT, timestamp);
3838                 if (ret >= 0) {
3839                         struct access_cbdata *cbdata;
3840
3841                         cbdata = malloc(sizeof(*cbdata));
3842                         if (!cbdata) {
3843                                 ret = LB_STATUS_ERROR_MEMORY;
3844                         } else {
3845                                 cbdata->inst = instance_ref(inst);
3846                                 cbdata->status = ret;
3847
3848                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3849                                         instance_unref(cbdata->inst);
3850                                         free(cbdata);
3851                                         ret = LB_STATUS_ERROR_FAULT;
3852                                 } else {
3853                                         ret = LB_STATUS_SUCCESS;
3854                                 }
3855                         }
3856                 }
3857         } else {
3858                 ErrPrint("Unsupported package\n");
3859                 ret = LB_STATUS_ERROR_INVALID;
3860         }
3861
3862 out:
3863         result = packet_create_reply(packet, "i", ret);
3864         if (!result)
3865                 ErrPrint("Failed to create a reply packet\n");
3866
3867         return result;
3868 }
3869
3870 static struct packet *client_lb_access_value_change(pid_t pid, int handle, const struct packet *packet)
3871 {
3872         struct packet *result;
3873         struct client_node *client;
3874         const char *pkgname;
3875         const char *id;
3876         int ret;
3877         double timestamp;
3878         struct inst_info *inst;
3879         const struct pkg_info *pkg;
3880         int x;
3881         int y;
3882
3883         client = client_find_by_pid(pid);
3884         if (!client) {
3885                 ErrPrint("Client %d is not exist\n", pid);
3886                 ret = LB_STATUS_ERROR_NOT_EXIST;
3887                 goto out;
3888         }
3889
3890         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
3891         if (ret != 5) {
3892                 ErrPrint("Parameter is not matched\n");
3893                 ret = LB_STATUS_ERROR_INVALID;
3894                 goto out;
3895         }
3896
3897         inst = package_find_instance_by_id(pkgname, id);
3898         if (!inst) {
3899                 ErrPrint("Instance[%s] is not exists\n", id);
3900                 ret = LB_STATUS_ERROR_NOT_EXIST;
3901                 goto out;
3902         }
3903
3904         pkg = instance_package(inst);
3905         if (!pkg) {
3906                 ErrPrint("Package[%s] info is not exists\n", pkgname);
3907                 ret = LB_STATUS_ERROR_FAULT;
3908                 goto out;
3909         }
3910
3911         if (package_is_fault(pkg)) {
3912                 ret = LB_STATUS_ERROR_FAULT;
3913         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3914                 struct buffer_info *buffer;
3915                 struct slave_node *slave;
3916
3917                 buffer = instance_lb_buffer(inst);
3918                 if (!buffer) {
3919                         ErrPrint("Instance[%s] has no buffer\n", id);
3920                         ret = LB_STATUS_ERROR_FAULT;
3921                         goto out;
3922                 }
3923
3924                 slave = package_slave(pkg);
3925                 if (!slave) {
3926                         ErrPrint("Slave is not exists\n");
3927                         ret = LB_STATUS_ERROR_INVALID;
3928                         goto out;
3929                 }
3930
3931                 packet_ref((struct packet *)packet);
3932                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
3933                 /*!
3934                  * Enen if it fails to send packet,
3935                  * The packet will be unref'd
3936                  * So we don't need to check the ret value.
3937                  */
3938         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3939                 struct script_info *script;
3940                 Evas *e;
3941
3942                 script = instance_lb_script(inst);
3943                 if (!script) {
3944                         ErrPrint("Instance has no script\n");
3945                         ret = LB_STATUS_ERROR_FAULT;
3946                         goto out;
3947                 }
3948
3949                 e = script_handler_evas(script);
3950                 if (!e) {
3951                         ErrPrint("Script has no evas\n");
3952                         ret = LB_STATUS_ERROR_INVALID;
3953                         goto out;
3954                 }
3955
3956                 script_handler_update_pointer(script, x, y, -1);
3957                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_VALUE_CHANGE, timestamp);
3958                 if (ret >= 0) {
3959                         struct access_cbdata *cbdata;
3960
3961                         cbdata = malloc(sizeof(*cbdata));
3962                         if (!cbdata) {
3963                                 ret = LB_STATUS_ERROR_MEMORY;
3964                         } else {
3965                                 cbdata->inst = instance_ref(inst);
3966                                 cbdata->status = ret;
3967
3968                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3969                                         instance_unref(cbdata->inst);
3970                                         free(cbdata);
3971                                         ret = LB_STATUS_ERROR_FAULT;
3972                                 } else {
3973                                         ret = LB_STATUS_SUCCESS;
3974                                 }
3975                         }
3976                 }
3977         } else {
3978                 ErrPrint("Unsupported package\n");
3979                 ret = LB_STATUS_ERROR_INVALID;
3980         }
3981
3982 out:
3983         result = packet_create_reply(packet, "i", ret);
3984         if (!result)
3985                 ErrPrint("Failed to create a reply packet\n");
3986
3987         return result;
3988 }
3989
3990 static struct packet *client_lb_access_unhighlight(pid_t pid, int handle, const struct packet *packet)
3991 {
3992         struct packet *result;
3993         struct client_node *client;
3994         const char *pkgname;
3995         const char *id;
3996         int ret;
3997         double timestamp;
3998         int x;
3999         int y;
4000         struct inst_info *inst;
4001         const struct pkg_info *pkg;
4002
4003         client = client_find_by_pid(pid);
4004         if (!client) {
4005                 ErrPrint("Client %d is not exists\n", pid);
4006                 ret = LB_STATUS_ERROR_NOT_EXIST;
4007                 goto out;
4008         }
4009
4010         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
4011         if (ret != 5) {
4012                 ErrPrint("Parameter is not matched\n");
4013                 ret = LB_STATUS_ERROR_INVALID;
4014                 goto out;
4015         }
4016
4017         /*!
4018          * \NOTE:
4019          * Trust the package name which are sent by the client.
4020          * The package has to be a livebox package name.
4021          */
4022         inst = package_find_instance_by_id(pkgname, id);
4023         if (!inst) {
4024                 ErrPrint("Instance[%s] is not exists\n", id);
4025                 ret = LB_STATUS_ERROR_NOT_EXIST;
4026                 goto out;
4027         }
4028
4029         pkg = instance_package(inst);
4030         if (!pkg) {
4031                 ErrPrint("Package[%s] info is not exists\n", pkgname);
4032                 ret = LB_STATUS_ERROR_FAULT;
4033                 goto out;
4034         }
4035
4036         if (package_is_fault(pkg)) {
4037                 /*!
4038                  * \note
4039                  * If the package is registered as fault module,
4040                  * slave has not load it, so we don't need to do anything at here!
4041                  */
4042                 DbgPrint("Package[%s] is faulted\n", pkgname);
4043                 ret = LB_STATUS_ERROR_FAULT;
4044         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4045                 struct buffer_info *buffer;
4046                 struct slave_node *slave;
4047                 //struct packet *packet;
4048
4049                 buffer = instance_lb_buffer(inst);
4050                 if (!buffer) {
4051                         ErrPrint("Instance[%s] has no buffer\n", id);
4052                         ret = LB_STATUS_ERROR_FAULT;
4053                         goto out;
4054                 }
4055
4056                 slave = package_slave(pkg);
4057                 if (!slave) {
4058                         ErrPrint("Package[%s] has no slave\n", pkgname);
4059                         ret = LB_STATUS_ERROR_INVALID;
4060                         goto out;
4061                 }
4062
4063                 /*
4064                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
4065                 if (!packet) {
4066                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
4067                         ret = LB_STATUS_ERROR_FAULT;
4068                         goto out;
4069                 }
4070                 */
4071
4072                 packet_ref((struct packet *)packet);
4073                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
4074         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4075                 struct script_info *script;
4076                 Evas *e;
4077
4078                 script = instance_lb_script(inst);
4079                 if (!script) {
4080                         ret = LB_STATUS_ERROR_FAULT;
4081                         goto out;
4082                 }
4083
4084                 e = script_handler_evas(script);
4085                 if (!e) {
4086                         ret = LB_STATUS_ERROR_FAULT;
4087                         goto out;
4088                 }
4089
4090                 script_handler_update_pointer(script, x, y, -1);
4091                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_UNHIGHLIGHT, timestamp);
4092                 if (ret >= 0) {
4093                         struct access_cbdata *cbdata;
4094
4095                         cbdata = malloc(sizeof(*cbdata));
4096                         if (!cbdata) {
4097                                 ret = LB_STATUS_ERROR_MEMORY;
4098                         } else {
4099                                 cbdata->inst = instance_ref(inst);
4100                                 cbdata->status = ret;
4101
4102                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
4103                                         instance_unref(cbdata->inst);
4104                                         free(cbdata);
4105                                         ret = LB_STATUS_ERROR_FAULT;
4106                                 } else {
4107                                         ret = LB_STATUS_SUCCESS;
4108                                 }
4109                         }
4110                 }
4111         } else {
4112                 ErrPrint("Unsupported package\n");
4113                 ret = LB_STATUS_ERROR_INVALID;
4114         }
4115
4116 out:
4117         result = packet_create_reply(packet, "i", ret);
4118         if (!result)
4119                 ErrPrint("Failed to create a reply packet\n");
4120
4121         return result;
4122 }
4123
4124 static struct packet *client_lb_access_scroll(pid_t pid, int handle, const struct packet *packet)
4125 {
4126         struct packet *result;
4127         struct client_node *client;
4128         const char *pkgname;
4129         const char *id;
4130         int ret;
4131         double timestamp;
4132         struct inst_info *inst;
4133         const struct pkg_info *pkg;
4134         int x;
4135         int y;
4136
4137         client = client_find_by_pid(pid);
4138         if (!client) {
4139                 ErrPrint("Client %d is not exist\n", pid);
4140                 ret = LB_STATUS_ERROR_NOT_EXIST;
4141                 goto out;
4142         }
4143
4144         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
4145         if (ret != 5) {
4146                 ErrPrint("Parameter is not matched\n");
4147                 ret = LB_STATUS_ERROR_INVALID;
4148                 goto out;
4149         }
4150
4151         inst = package_find_instance_by_id(pkgname, id);
4152         if (!inst) {
4153                 ErrPrint("Instance[%s] is not exists\n", id);
4154                 ret = LB_STATUS_ERROR_NOT_EXIST;
4155                 goto out;
4156         }
4157
4158         pkg = instance_package(inst);
4159         if (!pkg) {
4160                 ErrPrint("Package[%s] info is not exists\n", pkgname);
4161                 ret = LB_STATUS_ERROR_FAULT;
4162                 goto out;
4163         }
4164
4165         if (package_is_fault(pkg)) {
4166                 ret = LB_STATUS_ERROR_FAULT;
4167         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4168                 struct buffer_info *buffer;
4169                 struct slave_node *slave;
4170
4171                 buffer = instance_lb_buffer(inst);
4172                 if (!buffer) {
4173                         ErrPrint("Instance[%s] has no buffer\n", id);
4174                         ret = LB_STATUS_ERROR_FAULT;
4175                         goto out;
4176                 }
4177
4178                 slave = package_slave(pkg);
4179                 if (!slave) {
4180                         ErrPrint("Slave is not exists\n");
4181                         ret = LB_STATUS_ERROR_INVALID;
4182                         goto out;
4183                 }
4184
4185                 packet_ref((struct packet *)packet);
4186                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
4187                 /*!
4188                  * Enen if it fails to send packet,
4189                  * The packet will be unref'd
4190                  * So we don't need to check the ret value.
4191                  */
4192         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4193                 struct script_info *script;
4194                 Evas *e;
4195
4196                 script = instance_lb_script(inst);
4197                 if (!script) {
4198                         ErrPrint("Instance has no script\n");
4199                         ret = LB_STATUS_ERROR_FAULT;
4200                         goto out;
4201                 }
4202
4203                 e = script_handler_evas(script);
4204                 if (!e) {
4205                         ErrPrint("Instance has no evas\n");
4206                         ret = LB_STATUS_ERROR_INVALID;
4207                         goto out;
4208                 }
4209
4210                 script_handler_update_pointer(script, x, y, -1);
4211                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
4212                 if (ret >= 0) {
4213                         struct access_cbdata *cbdata;
4214
4215                         cbdata = malloc(sizeof(*cbdata));
4216                         if (!cbdata) {
4217                                 ret = LB_STATUS_ERROR_MEMORY;
4218                         } else {
4219                                 cbdata->inst = instance_ref(inst);
4220                                 cbdata->status = ret;
4221
4222                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
4223                                         instance_unref(cbdata->inst);
4224                                         free(cbdata);
4225                                         ret = LB_STATUS_ERROR_FAULT;
4226                                 } else {
4227                                         ret = LB_STATUS_SUCCESS;
4228                                 }
4229                         }
4230                 }
4231         } else {
4232                 ErrPrint("Unsupported package\n");
4233                 ret = LB_STATUS_ERROR_INVALID;
4234         }
4235
4236 out:
4237         result = packet_create_reply(packet, "i", ret);
4238         if (!result)
4239                 ErrPrint("Failed to create a reply packet\n");
4240
4241         return result;
4242 }
4243
4244 static struct packet *client_lb_access_activate(pid_t pid, int handle, const struct packet *packet)
4245 {
4246         struct packet *result;
4247         struct client_node *client;
4248         const char *pkgname;
4249         const char *id;
4250         int ret;
4251         double timestamp;
4252         int x;
4253         int y;
4254         struct inst_info *inst;
4255         const struct pkg_info *pkg;
4256
4257         client = client_find_by_pid(pid);
4258         if (!client) {
4259                 ErrPrint("Client %d is not exists\n", pid);
4260                 ret = LB_STATUS_ERROR_NOT_EXIST;
4261                 goto out;
4262         }
4263
4264         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
4265         if (ret != 5) {
4266                 ErrPrint("Parameter is not matched\n");
4267                 ret = LB_STATUS_ERROR_INVALID;
4268                 goto out;
4269         }
4270
4271         /*!
4272          * \NOTE:
4273          * Trust the package name which are sent by the client.
4274          * The package has to be a livebox package name.
4275          */
4276         inst = package_find_instance_by_id(pkgname, id);
4277         if (!inst) {
4278                 ErrPrint("Instance[%s] is not exists\n", id);
4279                 ret = LB_STATUS_ERROR_NOT_EXIST;
4280                 goto out;
4281         }
4282
4283         pkg = instance_package(inst);
4284         if (!pkg) {
4285                 ErrPrint("Package[%s] info is not exists\n", pkgname);
4286                 ret = LB_STATUS_ERROR_INVALID;
4287                 goto out;
4288         }
4289
4290         if (package_is_fault(pkg)) {
4291                 /*!
4292                  * \note
4293                  * If the package is registered as fault module,
4294                  * slave has not load it, so we don't need to do anything at here!
4295                  */
4296                 DbgPrint("Package[%s] is faulted\n", pkgname);
4297                 ret = LB_STATUS_ERROR_FAULT;
4298         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4299                 struct buffer_info *buffer;
4300                 struct slave_node *slave;
4301                 //struct packet *packet;
4302
4303                 buffer = instance_lb_buffer(inst);
4304                 if (!buffer) {
4305                         ErrPrint("Instance[%s] has no buffer\n", id);
4306                         ret = LB_STATUS_ERROR_FAULT;
4307                         goto out;
4308                 }
4309
4310                 slave = package_slave(pkg);
4311                 if (!slave) {
4312                         ErrPrint("Package[%s] has no slave\n", pkgname);
4313                         ret = LB_STATUS_ERROR_INVALID;
4314                         goto out;
4315                 }
4316
4317                 /*
4318                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
4319                 if (!packet) {
4320                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
4321                         ret = LB_STATUS_ERROR_FAULT;
4322                         goto out;
4323                 }
4324                 */
4325
4326                 packet_ref((struct packet *)packet);
4327                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
4328         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4329                 struct script_info *script;
4330                 Evas *e;
4331
4332                 script = instance_lb_script(inst);
4333                 if (!script) {
4334                         ErrPrint("Instance has no script\n");
4335                         ret = LB_STATUS_ERROR_FAULT;
4336                         goto out;
4337                 }
4338
4339                 e = script_handler_evas(script);
4340                 if (!e) {
4341                         ErrPrint("Script has no Evas\n");
4342                         ret = LB_STATUS_ERROR_INVALID;
4343                         goto out;
4344                 }
4345
4346                 script_handler_update_pointer(script, x, y, -1);
4347                 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTIVATE, timestamp);
4348                 if (ret >= 0) {
4349                         struct access_cbdata *cbdata;
4350
4351                         cbdata = malloc(sizeof(*cbdata));
4352                         if (!cbdata) {
4353                                 ret = LB_STATUS_ERROR_MEMORY;
4354                         } else {
4355                                 cbdata->inst = instance_ref(inst);
4356                                 cbdata->status = ret;
4357
4358                                 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
4359                                         instance_unref(cbdata->inst);
4360                                         free(cbdata);
4361                                         ret = LB_STATUS_ERROR_FAULT;
4362                                 } else {
4363                                         ret = LB_STATUS_SUCCESS;
4364                                 }
4365                         }
4366                 }
4367         } else {
4368                 ErrPrint("Unsupported package\n");
4369                 ret = LB_STATUS_ERROR_INVALID;
4370         }
4371
4372 out:
4373         result = packet_create_reply(packet, "i", ret);
4374         if (!result)
4375                 ErrPrint("Failed to create a reply packet\n");
4376
4377         return result;
4378 }
4379
4380 static struct packet *client_lb_key_down(pid_t pid, int handle, const struct packet *packet)
4381 {
4382         struct client_node *client;
4383         const char *pkgname;
4384         const char *id;
4385         int ret;
4386         double timestamp;
4387         int x;
4388         int y;
4389         struct inst_info *inst;
4390         const struct pkg_info *pkg;
4391
4392         client = client_find_by_pid(pid);
4393         if (!client) {
4394                 ErrPrint("Client %d is not exists\n", pid);
4395                 ret = LB_STATUS_ERROR_NOT_EXIST;
4396                 goto out;
4397         }
4398
4399         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
4400         if (ret != 7) {
4401                 ErrPrint("Parameter is not matched\n");
4402                 ret = LB_STATUS_ERROR_INVALID;
4403                 goto out;
4404         }
4405
4406         /*!
4407          * \NOTE:
4408          * Trust the package name which are sent by the client.
4409          * The package has to be a livebox package name.
4410          */
4411         inst = package_find_instance_by_id(pkgname, id);
4412         if (!inst) {
4413                 ErrPrint("Instance[%s] is not exists\n", id);
4414                 ret = LB_STATUS_ERROR_NOT_EXIST;
4415                 goto out;
4416         }
4417
4418         pkg = instance_package(inst);
4419         if (!pkg) {
4420                 ErrPrint("Package[%s] info is not exists\n", pkgname);
4421                 ret = LB_STATUS_ERROR_FAULT;
4422                 goto out;
4423         }
4424
4425         if (package_is_fault(pkg)) {
4426                 /*!
4427                  * \note
4428                  * If the package is registered as fault module,
4429                  * slave has not load it, so we don't need to do anything at here!
4430                  */
4431                 DbgPrint("Package[%s] is faulted\n", pkgname);
4432                 ret = LB_STATUS_ERROR_FAULT;
4433         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4434                 struct buffer_info *buffer;
4435                 struct slave_node *slave;
4436                 //struct packet *packet;
4437
4438                 buffer = instance_lb_buffer(inst);
4439                 if (!buffer) {
4440                         ErrPrint("Instance[%s] has no buffer\n", id);
4441                         ret = LB_STATUS_ERROR_FAULT;
4442                         goto out;
4443                 }
4444
4445                 slave = package_slave(pkg);
4446                 if (!slave) {
4447                         ErrPrint("Package[%s] has no slave\n", pkgname);
4448                         ret = LB_STATUS_ERROR_INVALID;
4449                         goto out;
4450                 }
4451
4452                 /*
4453                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
4454                 if (!packet) {
4455                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
4456                         ret = LB_STATUS_ERROR_FAULT;
4457                         goto out;
4458                 }
4459                 */
4460
4461                 packet_ref((struct packet *)packet);
4462                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
4463         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4464                 struct script_info *script;
4465                 Evas *e;
4466
4467                 script = instance_lb_script(inst);
4468                 if (!script) {
4469                         ret = LB_STATUS_ERROR_FAULT;
4470                         goto out;
4471                 }
4472
4473                 e = script_handler_evas(script);
4474                 if (!e) {
4475                         ret = LB_STATUS_ERROR_FAULT;
4476                         goto out;
4477                 }
4478
4479                 script_handler_update_pointer(script, x, y, -1);
4480
4481                 /*!
4482                  * \TODO: Feed up this KEY_DOWN event
4483                  */
4484                 ret = 0;
4485         } else {
4486                 ErrPrint("Unsupported package\n");
4487                 ret = LB_STATUS_ERROR_INVALID;
4488         }
4489
4490 out:
4491         /*! \note No reply packet */
4492         return NULL;
4493 }
4494
4495 static struct packet *client_lb_key_up(pid_t pid, int handle, const struct packet *packet)
4496 {
4497         struct client_node *client;
4498         const char *pkgname;
4499         const char *id;
4500         int ret;
4501         double timestamp;
4502         int x;
4503         int y;
4504         struct inst_info *inst;
4505         const struct pkg_info *pkg;
4506
4507         client = client_find_by_pid(pid);
4508         if (!client) {
4509                 ErrPrint("Client %d is not exists\n", pid);
4510                 ret = LB_STATUS_ERROR_NOT_EXIST;
4511                 goto out;
4512         }
4513
4514         ret = packet_get(packet, "ssdii", &pkgname, &id, &timestamp, &x, &y);
4515         if (ret != 7) {
4516                 ErrPrint("Parameter is not matched\n");
4517                 ret = LB_STATUS_ERROR_INVALID;
4518                 goto out;
4519         }
4520
4521         /*!
4522          * \NOTE:
4523          * Trust the package name which are sent by the client.
4524          * The package has to be a livebox package name.
4525          */
4526         inst = package_find_instance_by_id(pkgname, id);
4527         if (!inst) {
4528                 ErrPrint("Instance[%s] is not exists\n", id);
4529                 ret = LB_STATUS_ERROR_NOT_EXIST;
4530                 goto out;
4531         }
4532
4533         pkg = instance_package(inst);
4534         if (!pkg) {
4535                 ErrPrint("Package[%s] info is not exists\n", pkgname);
4536                 ret = LB_STATUS_ERROR_FAULT;
4537                 goto out;
4538         }
4539
4540         if (package_is_fault(pkg)) {
4541                 /*!
4542                  * \note
4543                  * If the package is registered as fault module,
4544                  * slave has not load it, so we don't need to do anything at here!
4545                  */
4546                 DbgPrint("Package[%s] is faulted\n", pkgname);
4547                 ret = LB_STATUS_ERROR_FAULT;
4548         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4549                 struct buffer_info *buffer;
4550                 struct slave_node *slave;
4551                 //struct packet *packet;
4552
4553                 buffer = instance_lb_buffer(inst);
4554                 if (!buffer) {
4555                         ErrPrint("Instance[%s] has no buffer\n", id);
4556                         ret = LB_STATUS_ERROR_FAULT;
4557                         goto out;
4558                 }
4559
4560                 slave = package_slave(pkg);
4561                 if (!slave) {
4562                         ErrPrint("Package[%s] has no slave\n", pkgname);
4563                         ret = LB_STATUS_ERROR_INVALID;
4564                         goto out;
4565                 }
4566
4567                 /*
4568                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
4569                 if (!packet) {
4570                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
4571                         ret = LB_STATUS_ERROR_FAULT;
4572                         goto out;
4573                 }
4574                 */
4575
4576                 packet_ref((struct packet *)packet);
4577                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
4578         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4579                 struct script_info *script;
4580                 Evas *e;
4581
4582                 script = instance_lb_script(inst);
4583                 if (!script) {
4584                         ret = LB_STATUS_ERROR_FAULT;
4585                         goto out;
4586                 }
4587
4588                 e = script_handler_evas(script);
4589                 if (!e) {
4590                         ret = LB_STATUS_ERROR_FAULT;
4591                         goto out;
4592                 }
4593
4594                 script_handler_update_pointer(script, x, y, -1);
4595
4596                 /*!
4597                  * \TODO: Feed up this KEY_UP event
4598                  */
4599                 ret = 0;
4600         } else {
4601                 ErrPrint("Unsupported package\n");
4602                 ret = LB_STATUS_ERROR_INVALID;
4603         }
4604
4605 out:
4606         /*! \note No reply packet */
4607         return NULL;
4608 }
4609
4610 static int release_pixmap_cb(struct client_node *client, void *canvas)
4611 {
4612         DbgPrint("Forcely unref the \"buffer\"\n");
4613         buffer_handler_pixmap_unref(canvas);
4614         return -1; /* Delete this callback */
4615 }
4616
4617 static struct packet *client_lb_acquire_pixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
4618 {
4619         struct packet *result;
4620         const char *pkgname;
4621         const char *id;
4622         struct client_node *client;
4623         struct inst_info *inst;
4624         int ret;
4625         int pixmap = 0;
4626         void *buf_ptr;
4627         struct buffer_info *buffer;
4628
4629         client = client_find_by_pid(pid);
4630         if (!client) {
4631                 ErrPrint("Client %d is not exists\n", pid);
4632                 goto out;
4633         }
4634
4635         ret = packet_get(packet, "ss", &pkgname, &id);
4636         if (ret != 2) {
4637                 ErrPrint("Parameter is not matched\n");
4638                 goto out;
4639         }
4640
4641         /*!
4642          * \NOTE:
4643          * Trust the package name which are sent by the client.
4644          * The package has to be a livebox package name.
4645          */
4646         inst = package_find_instance_by_id(pkgname, id);
4647         if (!inst) {
4648                 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
4649                 goto out;
4650         }
4651
4652         DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
4653         buffer = instance_lb_buffer(inst);
4654         if (!buffer) {
4655                 ErrPrint("Unable to get LB buffer: %s\n", id);
4656                 goto out;
4657         }
4658
4659         buf_ptr = buffer_handler_pixmap_ref(buffer);
4660         if (!buf_ptr) {
4661                 ErrPrint("Failed to ref pixmap\n");
4662                 goto out;
4663         }
4664
4665         ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
4666         if (ret < 0) {
4667                 ErrPrint("Failed to add a new client deactivate callback\n");
4668                 buffer_handler_pixmap_unref(buf_ptr);
4669         } else {
4670                 pixmap = buffer_handler_pixmap(buffer);
4671         }
4672
4673 out:
4674         result = packet_create_reply(packet, "i", pixmap);
4675         if (!result)
4676                 ErrPrint("Failed to create a reply packet\n");
4677
4678         return result;
4679 }
4680
4681 static struct packet *client_lb_release_pixmap(pid_t pid, int handle, const struct packet *packet)
4682 {
4683         const char *pkgname;
4684         const char *id;
4685         struct client_node *client;
4686         struct inst_info *inst;
4687         int pixmap;
4688         void *buf_ptr;
4689         int ret;
4690
4691         client = client_find_by_pid(pid);
4692         if (!client) {
4693                 ErrPrint("Client %d is not exists\n", pid);
4694                 goto out;
4695         }
4696
4697         ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
4698         if (ret != 3) {
4699                 ErrPrint("Parameter is not matched\n");
4700                 goto out;
4701         }
4702         DbgPrint("pid[%d] pkgname[%s] id[%s] Pixmap[0x%X]\n", pid, pkgname, id, pixmap);
4703
4704         /*!
4705          * \NOTE:
4706          * Trust the package name which are sent by the client.
4707          * The package has to be a livebox package name.
4708          */
4709         inst = package_find_instance_by_id(pkgname, id);
4710         if (!inst) {
4711                 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
4712                 goto out;
4713         }
4714
4715         buf_ptr = buffer_handler_pixmap_find(pixmap);
4716         if (!buf_ptr) {
4717                 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
4718                 goto out;
4719         }
4720
4721         if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0)
4722                 buffer_handler_pixmap_unref(buf_ptr);
4723
4724 out:
4725         /*! \note No reply packet */
4726         return NULL;
4727 }
4728
4729 static struct packet *client_pd_acquire_pixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
4730 {
4731         struct packet *result;
4732         const char *pkgname;
4733         const char *id;
4734         struct client_node *client;
4735         struct inst_info *inst;
4736         int ret;
4737         int pixmap = 0;
4738         void *buf_ptr;
4739         struct buffer_info *buffer;
4740
4741         client = client_find_by_pid(pid);
4742         if (!client) {
4743                 ErrPrint("Client %d is not exists\n", pid);
4744                 goto out;
4745         }
4746
4747         ret = packet_get(packet, "ss", &pkgname, &id);
4748         if (ret != 2) {
4749                 ErrPrint("Parameter is not matched\n");
4750                 goto out;
4751         }
4752
4753         /*!
4754          * \NOTE:
4755          * Trust the package name which are sent by the client.
4756          * The package has to be a livebox package name.
4757          */
4758         inst = package_find_instance_by_id(pkgname, id);
4759         if (!inst) {
4760                 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
4761                 goto out;
4762         }
4763
4764         DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
4765         buffer = instance_pd_buffer(inst);
4766         if (!buffer) {
4767                 ErrPrint("Unable to get PD buffer (%s)\n", id);
4768                 goto out;
4769         }
4770
4771         buf_ptr = buffer_handler_pixmap_ref(buffer);
4772         if (!buf_ptr) {
4773                 ErrPrint("Failed to ref pixmap\n");
4774                 goto out;
4775         }
4776
4777         ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
4778         if (ret < 0)
4779                 buffer_handler_pixmap_unref(buf_ptr);
4780
4781         pixmap = buffer_handler_pixmap(buffer);
4782 out:
4783         result = packet_create_reply(packet, "i", pixmap);
4784         if (!result)
4785                 ErrPrint("Failed to create a reply packet\n");
4786
4787         return result;
4788 }
4789
4790 static struct packet *client_pd_release_pixmap(pid_t pid, int handle, const struct packet *packet)
4791 {
4792         const char *pkgname;
4793         const char *id;
4794         struct client_node *client;
4795         struct inst_info *inst;
4796         int pixmap;
4797         void *buf_ptr;
4798         int ret;
4799
4800         client = client_find_by_pid(pid);
4801         if (!client) {
4802                 ErrPrint("Client %d is not exists\n", pid);
4803                 goto out;
4804         }
4805
4806         ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
4807         if (ret != 3) {
4808                 ErrPrint("Parameter is not matched\n");
4809                 goto out;
4810         }
4811         DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
4812
4813         /*!
4814          * \NOTE:
4815          * Trust the package name which are sent by the client.
4816          * The package has to be a livebox package name.
4817          */
4818         inst = package_find_instance_by_id(pkgname, id);
4819         if (!inst) {
4820                 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
4821                 goto out;
4822         }
4823
4824         buf_ptr = buffer_handler_pixmap_find(pixmap);
4825         if (!buf_ptr) {
4826                 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
4827                 goto out;
4828         }
4829
4830         if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0)
4831                 buffer_handler_pixmap_unref(buf_ptr);
4832
4833 out:
4834         /*! \note No reply packet */
4835         return NULL;
4836 }
4837
4838 static struct packet *client_pinup_changed(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, pinup, ret */
4839 {
4840         struct client_node *client;
4841         struct packet *result;
4842         const char *pkgname;
4843         const char *id;
4844         int pinup;
4845         int ret;
4846         struct inst_info *inst;
4847
4848         client = client_find_by_pid(pid);
4849         if (!client) {
4850                 ErrPrint("Client %d is not exists\n", pid);
4851                 ret = LB_STATUS_ERROR_NOT_EXIST;
4852                 pinup = 0;
4853                 goto out;
4854         }
4855
4856         ret = packet_get(packet, "ssi", &pkgname, &id, &pinup);
4857         if (ret != 3) {
4858                 ErrPrint("Parameter is not matched\n");
4859                 ret = LB_STATUS_ERROR_INVALID;
4860                 pinup = 0;
4861                 goto out;
4862         }
4863
4864         DbgPrint("pid[%d] pkgname[%s] id[%s] pinup[%d]\n", pid, pkgname, id, pinup);
4865
4866         /*!
4867          * \NOTE:
4868          * Trust the package name which are sent by the client.
4869          * The package has to be a livebox package name.
4870          */
4871         inst = package_find_instance_by_id(pkgname, id);
4872         if (!inst)
4873                 ret = LB_STATUS_ERROR_NOT_EXIST;
4874         else if (package_is_fault(instance_package(inst)))
4875                 ret = LB_STATUS_ERROR_FAULT;
4876         else
4877                 ret = instance_set_pinup(inst, pinup);
4878
4879 out:
4880         result = packet_create_reply(packet, "i", ret);
4881         if (!result)
4882                 ErrPrint("Failed to create a packet\n");
4883
4884         return result;
4885 }
4886
4887 static Eina_Bool lazy_pd_created_cb(void *data)
4888 {
4889         if (instance_unref(data)) {
4890                 int ret;
4891                 ret = instance_client_pd_created(data, LB_STATUS_SUCCESS);
4892                 DbgPrint("Send PD Create event (%d)\n", ret);
4893         }
4894
4895         return ECORE_CALLBACK_CANCEL;
4896 }
4897
4898 static Eina_Bool lazy_pd_destroyed_cb(void *data)
4899 {
4900         if (instance_unref(data)) {
4901                 DbgPrint("Send PD Destroy event\n");
4902                 instance_client_pd_destroyed(data, LB_STATUS_SUCCESS);
4903         }
4904
4905         return ECORE_CALLBACK_CANCEL;
4906 }
4907
4908 static struct packet *client_pd_move(pid_t pid, int handle, const struct packet *packet) /* pkgname, id, x, y */
4909 {
4910         struct client_node *client;
4911         struct inst_info *inst;
4912         const char *pkgname;
4913         const char *id;
4914         double x = 0.0f;
4915         double y = 0.0f;
4916         int ret;
4917
4918         client = client_find_by_pid(pid);
4919         if (!client) {
4920                 ErrPrint("Client %d is not exists\n", pid);
4921                 ret = LB_STATUS_ERROR_NOT_EXIST;
4922                 goto out;
4923         }
4924
4925         ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
4926         if (ret != 4) {
4927                 ErrPrint("Parameter is not correct\n");
4928                 ret = LB_STATUS_ERROR_INVALID;
4929                 goto out;
4930         }
4931
4932         DbgPrint("pid[%d] pkgname[%s] id[%s] %lfx%lf\n", pid, pkgname, id, x, y);
4933
4934         inst = package_find_instance_by_id(pkgname, id);
4935         if (!inst)
4936                 ret = LB_STATUS_ERROR_NOT_EXIST;
4937         else if (package_is_fault(instance_package(inst)))
4938                 ret = LB_STATUS_ERROR_FAULT;
4939         else if (package_pd_type(instance_package(inst)) == PD_TYPE_BUFFER) {
4940                 instance_slave_set_pd_pos(inst, x, y);
4941                 ret = instance_signal_emit(inst,
4942                                 "pd,move", util_uri_to_path(instance_id(inst)),
4943                                 0.0, 0.0, 0.0, 0.0, x, y, 0);
4944         } else if (package_pd_type(instance_package(inst)) == PD_TYPE_SCRIPT) {
4945                 int ix;
4946                 int iy;
4947
4948                 instance_slave_set_pd_pos(inst, x, y);
4949                 ix = x * instance_pd_width(inst);
4950                 iy = y * instance_pd_height(inst);
4951                 script_handler_update_pointer(instance_pd_script(inst), ix, iy, 0);
4952                 ret = instance_signal_emit(inst,
4953                                 "pd,move", util_uri_to_path(instance_id(inst)),
4954                                 0.0, 0.0, 0.0, 0.0, x, y, 0);
4955         } else {
4956                 ErrPrint("Invalid PD type\n");
4957                 ret = LB_STATUS_ERROR_INVALID;
4958         }
4959 out:
4960         DbgPrint("Update PD position: %lfx%lf (%d)\n", x, y, ret);
4961         return NULL;
4962 }
4963
4964 static struct packet *client_create_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
4965 {
4966         struct client_node *client;
4967         struct packet *result;
4968         const char *pkgname;
4969         const char *id;
4970         int ret;
4971         struct inst_info *inst;
4972         double x;
4973         double y;
4974
4975         client = client_find_by_pid(pid);
4976         if (!client) {
4977                 ErrPrint("Client %d is not exists\n", pid);
4978                 ret = LB_STATUS_ERROR_NOT_EXIST;
4979                 goto out;
4980         }
4981
4982         ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
4983         if (ret != 4) {
4984                 ErrPrint("Parameter is not matched\n");
4985                 ret = LB_STATUS_ERROR_INVALID;
4986                 goto out;
4987         }
4988
4989         DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
4990
4991         /*!
4992          * \NOTE:
4993          * Trust the package name which are sent by the client.
4994          * The package has to be a livebox package name.
4995          */
4996         inst = package_find_instance_by_id(pkgname, id);
4997         if (!inst)
4998                 ret = LB_STATUS_ERROR_NOT_EXIST;
4999         else if (package_is_fault(instance_package(inst)))
5000                 ret = LB_STATUS_ERROR_FAULT;
5001         else if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE)
5002                 ret = LB_STATUS_ERROR_NO_SPACE;
5003         else if (package_pd_type(instance_package(inst)) == PD_TYPE_BUFFER) {
5004                 instance_slave_set_pd_pos(inst, x, y);
5005                 ret = instance_slave_open_pd(inst, client);
5006                 ret = instance_signal_emit(inst,
5007                                 "pd,show", util_uri_to_path(instance_id(inst)),
5008                                 0.0, 0.0, 0.0, 0.0, x, y, 0);
5009                 /*!
5010                  * \note
5011                  * PD craeted event will be send by the acquire_buffer function.
5012                  * Because the slave will make request the acquire_buffer to
5013                  * render the PD
5014                  *
5015                  * instance_client_pd_created(inst);
5016                  */
5017         } else if (package_pd_type(instance_package(inst)) == PD_TYPE_SCRIPT) {
5018                 int ix;
5019                 int iy;
5020                 /*!
5021                  * \note
5022                  * ret value should be cared but in this case,
5023                  * we ignore this for this moment, so we have to handle this error later.
5024                  *
5025                  * if ret is less than 0, the slave has some problem.
5026                  * but the script mode doesn't need slave for rendering default view of PD
5027                  * so we can hanle it later.
5028                  */
5029                 instance_slave_set_pd_pos(inst, x, y);
5030                 ix = x * instance_pd_width(inst);
5031                 iy = y * instance_pd_height(inst);
5032
5033                 script_handler_update_pointer(instance_pd_script(inst), ix, iy, 0);
5034
5035                 ret = instance_slave_open_pd(inst, client);
5036                 if (ret == LB_STATUS_SUCCESS) {
5037                         ret = script_handler_load(instance_pd_script(inst), 1);
5038
5039                         /*!
5040                          * \note
5041                          * Send the PD created event to the clients,
5042                          */
5043                         if (ret == LB_STATUS_SUCCESS) {
5044                                 /*!
5045                                  * \note
5046                                  * But the created event has to be send afte return
5047                                  * from this function or the viewer couldn't care
5048                                  * the event correctly.
5049                                  */
5050                                 inst = instance_ref(inst); /* To guarantee the inst */
5051                                 if (!ecore_timer_add(DELAY_TIME, lazy_pd_created_cb, inst)) {
5052                                         instance_unref(inst);
5053                                         script_handler_unload(instance_pd_script(inst), 1);
5054                                         instance_slave_close_pd(inst, client);
5055
5056                                         ErrPrint("Failed to add delayed timer\n");
5057                                         ret = LB_STATUS_ERROR_FAULT;
5058                                 }
5059                         } else {
5060                                 instance_slave_close_pd(inst, client);
5061                         }
5062                 } else {
5063                         ErrPrint("Failed to request open PD to the slave\n");
5064                 }
5065         } else {
5066                 ErrPrint("Invalid PD TYPE\n");
5067                 ret = LB_STATUS_ERROR_INVALID;
5068         }
5069
5070 out:
5071         result = packet_create_reply(packet, "i", ret);
5072         if (!result)
5073                 ErrPrint("Failed to create a packet\n");
5074
5075         return result;
5076 }
5077
5078 static struct packet *client_destroy_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
5079 {
5080         struct client_node *client;
5081         struct packet *result;
5082         const char *pkgname;
5083         const char *id;
5084         int ret;
5085         struct inst_info *inst;
5086
5087         client = client_find_by_pid(pid);
5088         if (!client) {
5089                 ErrPrint("Client %d is not exists\n", pid);
5090                 ret = LB_STATUS_ERROR_NOT_EXIST;
5091                 goto out;
5092         }
5093
5094         ret = packet_get(packet, "ss", &pkgname, &id);
5095         if (ret != 2) {
5096                 ErrPrint("Parameter is not matched\n");
5097                 ret = LB_STATUS_ERROR_INVALID;
5098                 goto out;
5099         }
5100
5101         DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
5102
5103         /*!
5104          * \NOTE:
5105          * Trust the package name which are sent by the client.
5106          * The package has to be a livebox package name.
5107          */
5108         inst = package_find_instance_by_id(pkgname, id);
5109         if (!inst)
5110                 ret = LB_STATUS_ERROR_NOT_EXIST;
5111         else if (package_is_fault(instance_package(inst)))
5112                 ret = LB_STATUS_ERROR_FAULT;
5113         else if (package_pd_type(instance_package(inst)) == PD_TYPE_BUFFER) {
5114                 ret = instance_signal_emit(inst,
5115                                 "pd,hide", util_uri_to_path(instance_id(inst)),
5116                                 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
5117                 ret = instance_slave_close_pd(inst, client);
5118
5119                 /*!
5120                  * \note
5121                  * release_buffer will be called by the slave after this.
5122                  * Then it will send the "pd_destroyed" event to the client
5123                  *
5124                  * instance_client_pd_destroyed(inst);
5125                  */
5126
5127         } else if (package_pd_type(instance_package(inst)) == PD_TYPE_SCRIPT) {
5128                 ret = script_handler_unload(instance_pd_script(inst), 1);
5129                 ret = instance_slave_close_pd(inst, client);
5130
5131                 /*!
5132                  * \note
5133                  * Send the destroyed PD event to the client
5134                  */
5135                 if (ret == LB_STATUS_SUCCESS) {
5136                         inst = instance_ref(inst);
5137                         if (!ecore_timer_add(DELAY_TIME, lazy_pd_destroyed_cb, inst)) {
5138                                 instance_unref(inst);
5139                                 /*!
5140                                  * How can we handle this?
5141                                  */
5142                                 ret = LB_STATUS_ERROR_FAULT;
5143                         }
5144                 }
5145         } else {
5146                 ErrPrint("Invalid PD TYPE\n");
5147                 ret = LB_STATUS_ERROR_INVALID;
5148         }
5149
5150 out:
5151         result = packet_create_reply(packet, "i", ret);
5152         if (!result)
5153                 ErrPrint("Failed to create a packet\n");
5154
5155         return result;
5156 }
5157
5158 static struct packet *client_activate_package(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, ret */
5159 {
5160         struct client_node *client;
5161         struct packet *result;
5162         const char *pkgname;
5163         int ret;
5164         struct pkg_info *info;
5165
5166         client = client_find_by_pid(pid);
5167         if (!client) {
5168                 ErrPrint("Client %d is not exists\n", pid);
5169                 ret = LB_STATUS_ERROR_NOT_EXIST;
5170                 pkgname = "";
5171                 goto out;
5172         }
5173
5174         ret = packet_get(packet, "s", &pkgname);
5175         if (ret != 1) {
5176                 ErrPrint("Parameter is not matched\n");
5177                 ret = LB_STATUS_ERROR_INVALID;
5178                 pkgname = "";
5179                 goto out;
5180         }
5181
5182         DbgPrint("pid[%d] pkgname[%s]\n", pid, pkgname);
5183
5184         /*!
5185          * \NOTE:
5186          * Validate the livebox package name.
5187          */
5188         if (!package_is_lb_pkgname(pkgname)) {
5189                 ErrPrint("%s is not a valid livebox package\n", pkgname);
5190                 pkgname = "";
5191                 ret = LB_STATUS_ERROR_INVALID;
5192                 goto out;
5193         }
5194
5195         info = package_find(pkgname);
5196         if (!info)
5197                 ret = LB_STATUS_ERROR_NOT_EXIST;
5198         else
5199                 ret = package_clear_fault(info);
5200
5201 out:
5202         result = packet_create_reply(packet, "is", ret, pkgname);
5203         if (!result)
5204                 ErrPrint("Failed to create a packet\n");
5205
5206         return result;
5207 }
5208
5209 static struct packet *client_subscribed(pid_t pid, int handle, const struct packet *packet)
5210 {
5211         const char *cluster;
5212         const char *category;
5213         struct client_node *client;
5214         int ret;
5215
5216         client = client_find_by_pid(pid);
5217         if (!client) {
5218                 ErrPrint("Client %d is not exists\n", pid);
5219                 ret = LB_STATUS_ERROR_NOT_EXIST;
5220                 goto out;
5221         }
5222
5223         ret = packet_get(packet, "ss", &cluster, &category);
5224         if (ret != 2) {
5225                 ErrPrint("Invalid argument\n");
5226                 ret = LB_STATUS_ERROR_INVALID;
5227                 goto out;
5228         }
5229
5230         DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
5231         if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5232                 ErrPrint("Invalid cluster name\n");
5233                 goto out;
5234         }
5235
5236         /*!
5237          * \todo
5238          * SUBSCRIBE cluster & sub-cluster for a client.
5239          */
5240         ret = client_subscribe(client, cluster, category);
5241         if (ret == 0)
5242                 package_alter_instances_to_client(client, ALTER_CREATE);
5243
5244 out:
5245         /*! \note No reply packet */
5246         return NULL;
5247 }
5248
5249 static struct packet *client_delete_cluster(pid_t pid, int handle, const struct packet *packet)
5250 {
5251         const char *cluster;
5252         struct client_node *client;
5253         struct packet *result;
5254         int ret;
5255
5256         client = client_find_by_pid(pid);
5257         if (!client) {
5258                 ErrPrint("Client %d is not exists\n", pid);
5259                 ret = LB_STATUS_ERROR_NOT_EXIST;
5260                 goto out;
5261         }
5262
5263         ret = packet_get(packet, "s", &cluster);
5264         if (ret != 1) {
5265                 ErrPrint("Invalid parameters\n");
5266                 ret = LB_STATUS_ERROR_INVALID;
5267                 goto out;
5268         }
5269
5270         DbgPrint("pid[%d] cluster[%s]\n", pid, cluster);
5271
5272         if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5273                 ErrPrint("Invalid cluster: %s\n", cluster);
5274                 ret = LB_STATUS_ERROR_INVALID;
5275                 goto out;
5276         }
5277
5278         /*!
5279          * \todo
5280          */
5281         ret = LB_STATUS_ERROR_NOT_IMPLEMENTED;
5282
5283 out:
5284         result = packet_create_reply(packet, "i", ret);
5285         if (!result)
5286                 ErrPrint("Failed to create a packet\n");
5287         return result;
5288 }
5289
5290 static inline int update_pkg_cb(struct category *category, const char *pkgname)
5291 {
5292         const char *c_name;
5293         const char *s_name;
5294
5295         c_name = group_cluster_name_by_category(category);
5296         s_name = group_category_name(category);
5297
5298         if (!c_name || !s_name || !pkgname) {
5299                 ErrPrint("Name is not valid\n");
5300                 return EXIT_FAILURE;
5301         }
5302
5303         DbgPrint("Send refresh request: %s (%s/%s)\n", pkgname, c_name, s_name);
5304         slave_rpc_request_update(pkgname, "", c_name, s_name);
5305
5306         /* Just try to create a new package */
5307         if (util_free_space(IMAGE_PATH) > MINIMUM_SPACE) {
5308                 double timestamp;
5309                 struct inst_info *inst;
5310
5311                 timestamp = util_timestamp();
5312                 /*!
5313                  * \NOTE
5314                  * Don't need to check the subscribed clients.
5315                  * Because this callback is called by the requests of clients.
5316                  * It means. some clients wants to handle this instances ;)
5317                  */
5318                 inst = instance_create(NULL, timestamp, pkgname, DEFAULT_CONTENT, c_name, s_name, DEFAULT_PERIOD, 0, 0);
5319                 if (!inst)
5320                         ErrPrint("Failed to create a new instance\n");
5321         } else {
5322                 ErrPrint("Not enough space\n");
5323         }
5324         return EXIT_SUCCESS;
5325 }
5326
5327 static struct packet *client_update(pid_t pid, int handle, const struct packet *packet)
5328 {
5329         struct inst_info *inst;
5330         struct client_node *client;
5331         const char *pkgname;
5332         const char *id;
5333         int ret;
5334
5335         client = client_find_by_pid(pid);
5336         if (!client) {
5337                 ErrPrint("Cilent %d is not exists\n", pid);
5338                 goto out;
5339         }
5340
5341         ret = packet_get(packet, "ss", &pkgname, &id);
5342         if (ret != 2) {
5343                 ErrPrint("Invalid argument\n");
5344                 goto out;
5345         }
5346
5347         inst = package_find_instance_by_id(pkgname, id);
5348         if (!inst) {
5349         } else if (package_is_fault(instance_package(inst))) {
5350         } else if (instance_client(inst) != client) {
5351         } else {
5352                 slave_rpc_request_update(pkgname, id, instance_cluster(inst), instance_category(inst));
5353         }
5354
5355 out:
5356         /*! \note No reply packet */
5357         return NULL;
5358 }
5359
5360 static struct packet *client_refresh_group(pid_t pid, int handle, const struct packet *packet)
5361 {
5362         const char *cluster_id;
5363         const char *category_id;
5364         struct client_node *client;
5365         int ret;
5366         struct cluster *cluster;
5367         struct category *category;
5368         struct context_info *info;
5369         Eina_List *info_list;
5370         Eina_List *l;
5371
5372         client = client_find_by_pid(pid);
5373         if (!client) {
5374                 ErrPrint("Cilent %d is not exists\n", pid);
5375                 goto out;
5376         }
5377
5378         ret = packet_get(packet, "ss", &cluster_id, &category_id);
5379         if (ret != 2) {
5380                 ErrPrint("Invalid parameter\n");
5381                 goto out;
5382         }
5383
5384         DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster_id, category_id);
5385
5386         if (!strlen(cluster_id) || !strcasecmp(cluster_id, DEFAULT_CLUSTER)) {
5387                 ErrPrint("Invalid cluster name: %s\n", cluster_id);
5388                 goto out;
5389         }
5390
5391         cluster = group_find_cluster(cluster_id);
5392         if (!cluster) {
5393                 ErrPrint("Cluster [%s] is not registered\n", cluster_id);
5394                 goto out;
5395         }
5396
5397         category = group_find_category(cluster, category_id);
5398         if (!category) {
5399                 ErrPrint("Category [%s] is not registered\n", category_id);
5400                 goto out;
5401         }
5402
5403         info_list = group_context_info_list(category);
5404         EINA_LIST_FOREACH(info_list, l, info) {
5405                 update_pkg_cb(category, group_pkgname_from_context_info(info));
5406         }
5407
5408 out:
5409         /*! \note No reply packet */
5410         return NULL;
5411 }
5412
5413 static struct packet *client_delete_category(pid_t pid, int handle, const struct packet *packet)
5414 {
5415         const char *cluster;
5416         const char *category;
5417         struct client_node *client;
5418         struct packet *result;
5419         int ret;
5420
5421         client = client_find_by_pid(pid);
5422         if (!client) {
5423                 ErrPrint("Client %d is not exists\n", pid);
5424                 ret = LB_STATUS_ERROR_NOT_EXIST;
5425                 goto out;
5426         }
5427
5428         ret = packet_get(packet, "ss", &cluster, &category);
5429         if (ret != 2) {
5430                 ErrPrint("Invalid paramenters\n");
5431                 ret = LB_STATUS_ERROR_INVALID;
5432                 goto out;
5433         }
5434
5435         DbgPrint("pid[%d] cluster[%s] category[%s]\n", pid, cluster, category);
5436         if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5437                 ErrPrint("Invalid cluster: %s\n", cluster);
5438                 ret = LB_STATUS_ERROR_INVALID;
5439                 goto out;
5440         }
5441
5442         /*!
5443          * \todo
5444          */
5445         ret = LB_STATUS_ERROR_NOT_IMPLEMENTED;
5446
5447 out:
5448         result = packet_create_reply(packet, "i", ret);
5449         if (!result)
5450                 ErrPrint("Failed to create a packet\n");
5451         return result;
5452 }
5453
5454 static struct packet *client_unsubscribed(pid_t pid, int handle, const struct packet *packet)
5455 {
5456         const char *cluster;
5457         const char *category;
5458         struct client_node *client;
5459         int ret;
5460
5461         client = client_find_by_pid(pid);
5462         if (!client) {
5463                 ErrPrint("Client %d is not exists\n", pid);
5464                 ret = LB_STATUS_ERROR_NOT_EXIST;
5465                 goto out;
5466         }
5467
5468         ret = packet_get(packet, "ss", &cluster, &category);
5469         if (ret != 2) {
5470                 ErrPrint("Invalid argument\n");
5471                 ret = LB_STATUS_ERROR_INVALID;
5472                 goto out;
5473         }
5474
5475         DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
5476
5477         if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5478                 ErrPrint("Invalid cluster name: %s\n", cluster);
5479                 goto out;
5480         }
5481
5482         /*!
5483          * \todo
5484          * UNSUBSCRIBE cluster & sub-cluster for a client.
5485          */
5486         ret = client_unsubscribe(client, cluster, category);
5487         if (ret == 0)
5488                 package_alter_instances_to_client(client, ALTER_DESTROY);
5489
5490 out:
5491         /*! \note No reply packet */
5492         return NULL;
5493 }
5494
5495 static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
5496 {
5497         struct slave_node *slave;
5498         const char *slavename;
5499         int ret;
5500
5501         ret = packet_get(packet, "s", &slavename);
5502         if (ret != 1) {
5503                 ErrPrint("Parameter is not matched\n");
5504                 goto out;
5505         }
5506
5507         DbgPrint("New slave[%s](%d) is arrived\n", slavename, pid);
5508
5509         slave = slave_find_by_pid(pid);
5510         if (!slave) {
5511                 if (DEBUG_MODE) {
5512                         char pkgname[pathconf("/", _PC_PATH_MAX)];
5513                         const char *abi;
5514
5515                         if (aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)) != AUL_R_OK) {
5516                                 ErrPrint("pid[%d] is not authroized provider package, try to find it using its name[%s]\n", pid, slavename);
5517                                 slave = slave_find_by_name(slavename);
5518                                 pkgname[0] = '\0'; /* Reset the pkgname */
5519                         } else {
5520                                 slave = slave_find_by_pkgname(pkgname);
5521                         }
5522
5523                         if (!slave) {
5524                                 abi = abi_find_by_pkgname(pkgname);
5525                                 if (!abi) {
5526                                         abi = DEFAULT_ABI;
5527                                         DbgPrint("Slave pkgname is invalid, ABI is replaced with '%s'(default)\n", abi);
5528                                 }
5529
5530                                 slave = slave_create(slavename, 1, abi, pkgname, 0);
5531                                 if (!slave) {
5532                                         ErrPrint("Failed to create a new slave for %s\n", slavename);
5533                                         goto out;
5534                                 }
5535
5536                                 DbgPrint("New slave is created (net: 0)\n");
5537                         } else {
5538                                 DbgPrint("Registered slave is replaced with this new one\n");
5539                                 abi = slave_abi(slave);
5540                         }
5541
5542                         slave_set_pid(slave, pid);
5543                         DbgPrint("Provider is forcely activated, pkgname(%s), abi(%s), slavename(%s)\n", pkgname, abi, slavename);
5544                 } else {
5545                         ErrPrint("Slave[%d] is not exists\n", pid);
5546                         goto out;
5547                 }
5548         }
5549
5550         /*!
5551          * \note
5552          * After updating handle,
5553          * slave activated callback will be called.
5554          */
5555         slave_rpc_update_handle(slave, handle);
5556
5557 out:
5558         return NULL;
5559 }
5560
5561 static struct packet *slave_ping(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
5562 {
5563         struct slave_node *slave;
5564         const char *slavename;
5565         int ret;
5566
5567         slave = slave_find_by_pid(pid);
5568         if (!slave) {
5569                 ErrPrint("Slave %d is not exists\n", pid);
5570                 goto out;
5571         }
5572
5573         ret = packet_get(packet, "s", &slavename);
5574         if (ret != 1)
5575                 ErrPrint("Parameter is not matched\n");
5576         else
5577                 slave_rpc_ping(slave);
5578
5579 out:
5580         return NULL;
5581 }
5582
5583 static struct packet *slave_faulted(pid_t pid, int handle, const struct packet *packet)
5584 {
5585         struct slave_node *slave;
5586         struct inst_info *inst;
5587         const char *pkgname;
5588         const char *id;
5589         const char *func;
5590         int ret;
5591
5592         slave = slave_find_by_pid(pid);
5593         if (!slave) {
5594                 ErrPrint("Slave %d is not exists\n", pid);
5595                 goto out;
5596         }
5597
5598         ret = packet_get(packet, "sss", &pkgname, &id, &func);
5599         if (ret != 3) {
5600                 ErrPrint("Parameter is not matched\n");
5601                 goto out;
5602         }
5603
5604         ret = fault_info_set(slave, pkgname, id, func);
5605         DbgPrint("Slave Faulted: %s (%d)\n", slave_name(slave), ret);
5606
5607         inst = package_find_instance_by_id(pkgname, id);
5608         if (!inst) {
5609                 DbgPrint("There is a no such instance(%s)\n", id);
5610         } else if (instance_state(inst) == INST_DESTROYED) {
5611                 ErrPrint("Instance(%s) is already destroyed\n", id);
5612         } else {
5613                 ret = instance_destroy(inst);
5614                 DbgPrint("Destroy instance(%s) %d\n", id, ret);
5615         }
5616
5617 out:
5618         return NULL;
5619 }
5620
5621 static struct packet *slave_lb_update_begin(pid_t pid, int handle, const struct packet *packet)
5622 {
5623         struct slave_node *slave;
5624         struct inst_info *inst;
5625         struct pkg_info *pkg;
5626         const char *pkgname;
5627         const char *id;
5628         double priority;
5629         const char *content;
5630         const char *title;
5631         int ret;
5632
5633         slave = slave_find_by_pid(pid);
5634         if (!slave) {
5635                 ErrPrint("Slave %d is not exists\n", pid);
5636                 goto out;
5637         }
5638
5639         ret = packet_get(packet, "ssdss", &pkgname, &id, &priority, &content, &title);
5640         if (ret != 5) {
5641                 ErrPrint("Invalid parameters\n");
5642                 goto out;
5643         }
5644
5645         inst = package_find_instance_by_id(pkgname, id);
5646         if (!inst) {
5647                 ErrPrint("Instance(%s) is not exists\n", id);
5648                 goto out;
5649         } else if (instance_state(inst) == INST_DESTROYED) {
5650                 ErrPrint("Instance(%s) is already destroyed\n", id);
5651                 goto out;
5652         }
5653
5654         pkg = instance_package(inst);
5655         if (!pkg) {
5656                 ErrPrint("Invalid instance\n");
5657         } else if (package_is_fault(pkg)) {
5658                 ErrPrint("Faulted instance %s.\n", id);
5659         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
5660                 ret = instance_lb_update_begin(inst, priority, content, title);
5661                 if (ret == LB_STATUS_SUCCESS)
5662                         slave_freeze_ttl(slave);
5663         } else {
5664                 ErrPrint("Invalid request[%s]\n", id);
5665         }
5666
5667 out:
5668         return NULL;
5669 }
5670
5671 static struct packet *slave_lb_update_end(pid_t pid, int handle, const struct packet *packet)
5672 {
5673         struct slave_node *slave;
5674         struct inst_info *inst;
5675         struct pkg_info *pkg;
5676         const char *pkgname;
5677         const char *id;
5678         int ret;
5679
5680         slave = slave_find_by_pid(pid);
5681         if (!slave) {
5682                 ErrPrint("Slave %d is not exists\n", pid);
5683                 goto out;
5684         }
5685
5686         ret = packet_get(packet, "ss", &pkgname, &id);
5687         if (ret != 2) {
5688                 ErrPrint("Invalid parameters\n");
5689                 goto out;
5690         }
5691
5692         inst = package_find_instance_by_id(pkgname, id);
5693         if (!inst) {
5694                 ErrPrint("Instance[%s] is not exists\n", id);
5695                 goto out;
5696         } else if (instance_state(inst) == INST_DESTROYED) {
5697                 ErrPrint("Instance[%s] is already destroyed\n", id);
5698                 goto out;
5699         }
5700
5701         pkg = instance_package(inst);
5702         if (!pkg) {
5703                 ErrPrint("Invalid instance\n");
5704         } else if (package_is_fault(pkg)) {
5705                 ErrPrint("Faulted instance %s\n", id);
5706         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
5707                 ret = instance_lb_update_end(inst);
5708                 if (ret == LB_STATUS_SUCCESS)
5709                         slave_thaw_ttl(slave);
5710         } else {
5711                 ErrPrint("Invalid request[%s]\n", id);
5712         }
5713
5714 out:
5715         return NULL;
5716 }
5717
5718 static struct packet *slave_pd_update_begin(pid_t pid, int handle, const struct packet *packet)
5719 {
5720         struct slave_node *slave;
5721         struct pkg_info *pkg;
5722         struct inst_info *inst;
5723         const char *pkgname;
5724         const char *id;
5725         int ret;
5726
5727         slave = slave_find_by_pid(pid);
5728         if (!slave) {
5729                 ErrPrint("Slave %d is not exists\n", pid);
5730                 goto out;
5731         }
5732
5733         ret = packet_get(packet, "ss", &pkgname, &id);
5734         if (ret != 2) {
5735                 ErrPrint("Invalid parameters\n");
5736                 goto out;
5737         }
5738
5739         inst = package_find_instance_by_id(pkgname, id);
5740         if (!inst) {
5741                 ErrPrint("Instance[%s] is not exists\n", id);
5742                 goto out;
5743         }
5744
5745         pkg = instance_package(inst);
5746         if (!pkg) {
5747                 ErrPrint("Invalid package\n");
5748         } else if (package_is_fault(pkg)) {
5749                 ErrPrint("Faulted instance %s\n", id);
5750         } else if (instance_state(inst) == INST_DESTROYED) {
5751                 ErrPrint("Instance[%s] is already destroyed\n", id);
5752         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
5753                 (void)instance_pd_update_begin(inst);
5754         } else {
5755                 ErrPrint("Invalid request[%s]\n", id);
5756         }
5757
5758 out:
5759         return NULL;
5760 }
5761
5762 static struct packet *slave_access_status(pid_t pid, int handle, const struct packet *packet)
5763 {
5764         struct slave_node *slave;
5765         struct pkg_info *pkg;
5766         struct inst_info *inst;
5767         const char *pkgname;
5768         const char *id;
5769         int status;
5770         int ret;
5771
5772         slave = slave_find_by_pid(pid);
5773         if (!slave) {
5774                 ErrPrint("Slave %d is not exists\n", pid);
5775                 goto out;
5776         }
5777
5778         ret = packet_get(packet, "ssi", &pkgname, &id, &status);
5779         if (ret != 3) {
5780                 ErrPrint("Invalid parameters\n");
5781                 goto out;
5782         }
5783
5784         inst = package_find_instance_by_id(pkgname, id);
5785         if (!inst) {
5786                 ErrPrint("Instance[%s] is not exists\n", id);
5787                 goto out;
5788         }
5789
5790         pkg = instance_package(inst);
5791         if (!pkg) {
5792                 ErrPrint("Invalid package\n");
5793         } else if (package_is_fault(pkg)) {
5794                 ErrPrint("Faulted instance %s\n", id);
5795         } else if (instance_state(inst) == INST_DESTROYED) {
5796                 ErrPrint("Instance[%s] is already destroyed\n", id);
5797         } else {
5798                 /*!
5799                  * \note
5800                  * Forward packet to client
5801                  */
5802                 (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
5803         }
5804
5805 out:
5806         return NULL;
5807 }
5808
5809 static struct packet *slave_pd_update_end(pid_t pid, int handle, const struct packet *packet)
5810 {
5811         struct slave_node *slave;
5812         struct pkg_info *pkg;
5813         struct inst_info *inst;
5814         const char *pkgname;
5815         const char *id;
5816         int ret;
5817
5818         slave = slave_find_by_pid(pid);
5819         if (!slave) {
5820                 ErrPrint("Slave %d is not exists\n", pid);
5821                 goto out;
5822         }
5823
5824         ret = packet_get(packet, "ss", &pkgname, &id);
5825         if (ret != 2) {
5826                 ErrPrint("Invalid parameters\n");
5827                 goto out;
5828         }
5829
5830         inst = package_find_instance_by_id(pkgname, id);
5831         if (!inst) {
5832                 ErrPrint("Instance[%s] is not exists\n", id);
5833                 goto out;
5834         }
5835
5836         pkg = instance_package(inst);
5837         if (!pkg) {
5838                 ErrPrint("Invalid package\n");
5839         } else if (package_is_fault(pkg)) {
5840                 ErrPrint("Faulted instance %s\n", id);
5841         } else if (instance_state(inst) == INST_DESTROYED) {
5842                 ErrPrint("Instance[%s] is already destroyed\n", id);
5843         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
5844                 (void)instance_pd_update_end(inst);
5845         } else {
5846                 ErrPrint("Invalid request[%s]\n", id);
5847         }
5848
5849 out:
5850         return NULL;
5851 }
5852
5853 static struct packet *slave_call(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
5854 {
5855         struct slave_node *slave;
5856         const char *pkgname;
5857         const char *id;
5858         const char *func;
5859         int ret;
5860
5861         slave = slave_find_by_pid(pid);
5862         if (!slave) {
5863                 ErrPrint("Slave %d is not exists\n", pid);
5864                 goto out;
5865         }
5866
5867         ret = packet_get(packet, "sss", &pkgname, &id, &func);
5868         if (ret != 3) {
5869                 ErrPrint("Parameter is not matched\n");
5870                 goto out;
5871         }
5872
5873         ret = fault_func_call(slave, pkgname, id, func);
5874         slave_give_more_ttl(slave);
5875
5876 out:
5877         return NULL;
5878 }
5879
5880 static struct packet *slave_ret(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
5881 {
5882         struct slave_node *slave;
5883         const char *pkgname;
5884         const char *id;
5885         const char *func;
5886         int ret;
5887
5888         slave = slave_find_by_pid(pid);
5889         if (!slave) {
5890                 ErrPrint("Slave %d is not exists\n", pid);
5891                 goto out;
5892         }
5893
5894         ret = packet_get(packet, "sss", &pkgname, &id, &func);
5895         if (ret != 3) {
5896                 ErrPrint("Parameter is not matched\n");
5897                 goto out;
5898         }
5899
5900         ret = fault_func_ret(slave, pkgname, id, func);
5901         slave_give_more_ttl(slave);
5902
5903 out:
5904         return NULL;
5905 }
5906
5907 static struct packet *slave_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, width, height, priority, ret */
5908 {
5909         struct slave_node *slave;
5910         const char *pkgname;
5911         const char *id;
5912         const char *content_info;
5913         const char *title;
5914         int w;
5915         int h;
5916         double priority;
5917         int ret;
5918         struct inst_info *inst;
5919
5920         slave = slave_find_by_pid(pid);
5921         if (!slave) {
5922                 ErrPrint("Slave %d is not exists\n", pid);
5923                 goto out;
5924         }
5925
5926         ret = packet_get(packet, "ssiidss", &pkgname, &id,
5927                                                 &w, &h, &priority,
5928                                                 &content_info, &title);
5929         if (ret != 7) {
5930                 ErrPrint("Parameter is not matched\n");
5931                 goto out;
5932         }
5933
5934         inst = package_find_instance_by_id(pkgname, id);
5935         if (!inst) {
5936         } else if (package_is_fault(instance_package(inst))) {
5937                 ErrPrint("Faulted instance cannot make any event.\n");
5938         } else if (instance_state(inst) == INST_DESTROYED) {
5939                 ErrPrint("Instance is already destroyed\n");
5940         } else {
5941                 char *filename;
5942
5943                 switch (package_lb_type(instance_package(inst))) {
5944                 case LB_TYPE_SCRIPT:
5945                         script_handler_resize(instance_lb_script(inst), w, h);
5946                         filename = util_get_file_kept_in_safe(id);
5947                         if (filename) {
5948                                 (void)script_handler_parse_desc(pkgname, id,
5949                                                                 filename, 0);
5950                                 DbgFree(filename);
5951                         } else {
5952                                 (void)script_handler_parse_desc(pkgname, id,
5953                                                         util_uri_to_path(id), 0);
5954                         }
5955                         break;
5956                 case LB_TYPE_BUFFER:
5957                 default:
5958                         /*!
5959                          * \check
5960                          * text format (inst)
5961                          */
5962                         instance_set_lb_info(inst, w, h, priority, content_info, title);
5963                         instance_lb_updated_by_instance(inst);
5964                         break;
5965                 }
5966
5967                 slave_give_more_ttl(slave);
5968         }
5969
5970 out:
5971         return NULL;
5972 }
5973
5974 static struct packet *slave_hold_scroll(pid_t pid, int handle, const struct packet *packet)
5975 {
5976         struct slave_node *slave;
5977         struct inst_info *inst;
5978         const char *pkgname;
5979         const char *id;
5980         int seize;
5981         int ret;
5982
5983         slave = slave_find_by_pid(pid);
5984         if (!slave) {
5985                 ErrPrint("Slave %d is not exists\n", pid);
5986                 goto out;
5987         }
5988
5989         ret = packet_get(packet, "ssi", &pkgname, &id, &seize);
5990         if (ret != 3) {
5991                 ErrPrint("Parameter is not matched\n");
5992                 goto out;
5993         }
5994
5995         inst = package_find_instance_by_id(pkgname, id);
5996         if (!inst) {
5997                 ErrPrint("No such instance(%s)\n", id);
5998         } else if (package_is_fault(instance_package(inst))) {
5999                 ErrPrint("Faulted instance cannot seize the screen\n");
6000         } else if (instance_state(inst) == INST_DESTROYED) {
6001                 ErrPrint("Instance(%s) is already destroyed\n", id);
6002         } else {
6003                 (void)instance_hold_scroll(inst, seize);
6004         }
6005
6006 out:
6007         return NULL;
6008 }
6009
6010 static struct packet *slave_desc_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, decsfile, ret */
6011 {
6012         struct slave_node *slave;
6013         const char *pkgname;
6014         const char *id;
6015         const char *descfile;
6016         int ret;
6017         struct inst_info *inst;
6018
6019         slave = slave_find_by_pid(pid);
6020         if (!slave) {
6021                 ErrPrint("Slave %d is not exists\n", pid);
6022                 goto out;
6023         }
6024
6025         ret = packet_get(packet, "sss", &pkgname, &id, &descfile);
6026         if (ret != 3) {
6027                 ErrPrint("Parameter is not matched\n");
6028                 goto out;
6029         }
6030
6031         inst = package_find_instance_by_id(pkgname, id);
6032         if (!inst) {
6033         } else if (package_is_fault(instance_package(inst))) {
6034                 ErrPrint("Faulted package cannot make event\n");
6035         } else if (instance_state(inst) == INST_DESTROYED) {
6036                 ErrPrint("Instance is already destroyed\n");
6037         } else {
6038                 switch (package_pd_type(instance_package(inst))) {
6039                 case PD_TYPE_SCRIPT:
6040                         DbgPrint("Script (%s)\n", id);
6041                         if (script_handler_is_loaded(instance_pd_script(inst))) {
6042                                 (void)script_handler_parse_desc(pkgname, id,
6043                                                                 descfile, 1);
6044                         }
6045                         break;
6046                 case PD_TYPE_TEXT:
6047                         instance_set_pd_info(inst, 0, 0);
6048                 case PD_TYPE_BUFFER:
6049                         instance_pd_updated(pkgname, id, descfile);
6050                         break;
6051                 default:
6052                         DbgPrint("Ignore updated DESC(%s - %s - %s)\n",
6053                                                         pkgname, id, descfile);
6054                         break;
6055                 }
6056         }
6057
6058 out:
6059         return NULL;
6060 }
6061
6062 static struct packet *slave_deleted(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, id, ret */
6063 {
6064         struct slave_node *slave;
6065         const char *pkgname;
6066         const char *id;
6067         int ret;
6068         struct inst_info *inst;
6069
6070         slave = slave_find_by_pid(pid);
6071         if (!slave) {
6072                 ErrPrint("Slave %d is not exists\n", pid);
6073                 goto out;
6074         }
6075
6076         ret = packet_get(packet, "ss", &pkgname, &id);
6077         if (ret != 2) {
6078                 ErrPrint("Parameter is not matched\n");
6079                 goto out;
6080         }
6081
6082         inst = package_find_instance_by_id(pkgname, id);
6083         if (!inst) {
6084         } else if (package_is_fault(instance_package(inst))) {
6085         } else {
6086                 ret = instance_destroyed(inst);
6087                 DbgPrint("Destroy instance %d\n", ret);
6088         }
6089
6090 out:
6091         return NULL;
6092 }
6093
6094 /*!
6095  * \note for the BUFFER Type slave
6096  */
6097 static struct packet *slave_acquire_buffer(pid_t pid, int handle, const struct packet *packet) /* type, id, w, h, size */
6098 {
6099         enum target_type target;
6100         const char *pkgname;
6101         const char *id;
6102         int w;
6103         int h;
6104         int pixel_size;
6105         struct packet *result;
6106         struct slave_node *slave;
6107         struct inst_info *inst;
6108         const struct pkg_info *pkg;
6109         int ret;
6110
6111         slave = slave_find_by_pid(pid);
6112         if (!slave) {
6113                 ErrPrint("Failed to find a slave\n");
6114                 id = "";
6115                 ret = LB_STATUS_ERROR_NOT_EXIST;
6116                 goto out;
6117         }
6118
6119         ret = packet_get(packet, "issiii", &target, &pkgname, &id, &w, &h, &pixel_size);
6120         if (ret != 6) {
6121                 ErrPrint("Invalid argument\n");
6122                 id = "";
6123                 ret = LB_STATUS_ERROR_INVALID;
6124                 goto out;
6125         }
6126
6127         if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE) {
6128                 DbgPrint("No space\n");
6129                 ret = LB_STATUS_ERROR_NO_SPACE;
6130                 id = "";
6131                 goto out;
6132         }
6133
6134         /* TODO: */
6135         inst = package_find_instance_by_id(pkgname, id);
6136         if (!inst) {
6137                 DbgPrint("Package[%s] Id[%s] is not found\n", pkgname, id);
6138                 ret = LB_STATUS_ERROR_INVALID;
6139                 id = "";
6140                 goto out;
6141         }
6142
6143         pkg = instance_package(inst);
6144         id = "";
6145         ret = LB_STATUS_ERROR_INVALID;
6146         if (target == TYPE_LB) {
6147                 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
6148                         struct buffer_info *info;
6149
6150                         info = instance_lb_buffer(inst);
6151                         if (!info) {
6152                                 if (!instance_create_lb_buffer(inst)) {
6153                                         ErrPrint("Failed to create a LB buffer\n");
6154                                 } else {
6155                                         info = instance_lb_buffer(inst);
6156                                         if (!info) {
6157                                                 ErrPrint("LB buffer is not valid\n");
6158                                                 ret = LB_STATUS_ERROR_INVALID;
6159                                                 id = "";
6160                                                 goto out;
6161                                         }
6162                                 }
6163                         }
6164
6165                         ret = buffer_handler_resize(info, w, h);
6166                         DbgPrint("Buffer resize returns %d\n", ret);
6167
6168                         ret = buffer_handler_load(info);
6169                         if (ret == 0) {
6170                                 instance_set_lb_info(inst, w, h, PRIORITY_NO_CHANGE, CONTENT_NO_CHANGE, TITLE_NO_CHANGE);
6171                                 id = buffer_handler_id(info);
6172                                 DbgPrint("Buffer handler ID: %s\n", id);
6173                         } else {
6174                                 DbgPrint("Failed to load a buffer(%d)\n", ret);
6175                         }
6176                 }
6177         } else if (target == TYPE_PD) {
6178                 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
6179                         struct buffer_info *info;
6180
6181                         DbgPrint("Slave acquire buffer for PD\n");
6182
6183                         info = instance_pd_buffer(inst);
6184                         if (!info) {
6185                                 if (!instance_create_pd_buffer(inst)) {
6186                                         ErrPrint("Failed to create a PD buffer\n");
6187                                 } else {
6188                                         info = instance_pd_buffer(inst);
6189                                         if (!info) {
6190                                                 ErrPrint("PD buffer is not valid\n");
6191                                                 ret = LB_STATUS_ERROR_INVALID;
6192                                                 id = "";
6193                                                 instance_client_pd_created(inst, ret);
6194                                                 goto out;
6195                                         }
6196                                 }
6197                         }
6198
6199                         ret = buffer_handler_resize(info, w, h);
6200                         DbgPrint("Buffer resize returns %d\n", ret);
6201
6202                         ret = buffer_handler_load(info);
6203                         if (ret == 0) {
6204                                 instance_set_pd_info(inst, w, h);
6205                                 id = buffer_handler_id(info);
6206                                 DbgPrint("Buffer handler ID: %s\n", id);
6207                         } else {
6208                                 DbgPrint("Failed to load a buffer (%d)\n", ret);
6209                         }
6210
6211                         /*!
6212                          * Send the PD created event to the client
6213                          */
6214                         instance_client_pd_created(inst, ret);
6215                 }
6216         }
6217
6218 out:
6219         result = packet_create_reply(packet, "is", ret, id);
6220         if (!result)
6221                 ErrPrint("Failed to create a packet\n");
6222
6223         return result;
6224 }
6225
6226 static struct packet *slave_resize_buffer(pid_t pid, int handle, const struct packet *packet)
6227 {
6228         struct slave_node *slave;
6229         struct packet *result;
6230         enum target_type type;
6231         const char *pkgname;
6232         const char *id;
6233         int w;
6234         int h;
6235         struct inst_info *inst;
6236         const struct pkg_info *pkg;
6237         int ret;
6238
6239         slave = slave_find_by_pid(pid);
6240         if (!slave) {
6241                 ErrPrint("Failed to find a slave\n");
6242                 ret = LB_STATUS_ERROR_NOT_EXIST;
6243                 id = "";
6244                 goto out;
6245         }
6246
6247         if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE) {
6248                 ErrPrint("Not enough space\n");
6249                 ret = LB_STATUS_ERROR_NO_SPACE;
6250                 id = "";
6251                 goto out;
6252         }
6253
6254         ret = packet_get(packet, "issii", &type, &pkgname, &id, &w, &h);
6255         if (ret != 5) {
6256                 ErrPrint("Invalid argument\n");
6257                 ret = LB_STATUS_ERROR_INVALID;
6258                 id = "";
6259                 goto out;
6260         }
6261
6262         inst = package_find_instance_by_id(pkgname, id);
6263         if (!inst) {
6264                 DbgPrint("Instance is not found[%s] [%s]\n", pkgname, id);
6265                 ret = LB_STATUS_ERROR_NOT_EXIST;
6266                 id = "";
6267                 goto out;
6268         }
6269
6270         pkg = instance_package(inst);
6271         if (!pkg) {
6272                 /*!
6273                  * \note
6274                  * THIS statement should not be entered.
6275                  */
6276                 ErrPrint("PACKAGE INFORMATION IS NOT VALID\n");
6277                 ret = LB_STATUS_ERROR_FAULT;
6278                 id = "";
6279                 goto out;
6280         }
6281
6282         ret = LB_STATUS_ERROR_INVALID;
6283         /*!
6284          * \note
6285          * Reset "id", It will be re-used from here
6286          */
6287         id = "";
6288         if (type == TYPE_LB) {
6289                 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
6290                         struct buffer_info *info;
6291
6292                         info = instance_lb_buffer(inst);
6293                         if (info) {
6294                                 ret = buffer_handler_resize(info, w, h);
6295                                 /*!
6296                                  * \note
6297                                  * id is resued for newly assigned ID
6298                                  */
6299                                 if (!ret) {
6300                                         id = buffer_handler_id(info);
6301                                         instance_set_lb_info(inst, w, h, PRIORITY_NO_CHANGE, CONTENT_NO_CHANGE, TITLE_NO_CHANGE);
6302                                 }
6303                         }
6304                 }
6305         } else if (type == TYPE_PD) {
6306                 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
6307                         struct buffer_info *info;
6308
6309                         info = instance_pd_buffer(inst);
6310                         if (info) {
6311                                 ret = buffer_handler_resize(info, w, h);
6312                                 /*!
6313                                  * \note
6314                                  * id is resued for newly assigned ID
6315                                  */
6316                                 if (!ret) {
6317                                         id = buffer_handler_id(info);
6318                                         instance_set_pd_info(inst, w, h);
6319                                 }
6320                         }
6321                 }
6322         }
6323
6324 out:
6325         result = packet_create_reply(packet, "is", ret, id);
6326         if (!result)
6327                 ErrPrint("Failed to create a packet\n");
6328
6329         return result;
6330 }
6331
6332 static struct packet *slave_release_buffer(pid_t pid, int handle, const struct packet *packet)
6333 {
6334         enum target_type type;
6335         const char *pkgname;
6336         const char *id;
6337         struct packet *result;
6338         struct slave_node *slave;
6339         struct inst_info *inst;
6340         int ret;
6341
6342         slave = slave_find_by_pid(pid);
6343         if (!slave) {
6344                 ErrPrint("Failed to find a slave\n");
6345                 ret = LB_STATUS_ERROR_NOT_EXIST;
6346                 goto out;
6347         }
6348
6349         if (packet_get(packet, "iss", &type, &pkgname, &id) != 3) {
6350                 ErrPrint("Inavlid argument\n");
6351                 ret = LB_STATUS_ERROR_INVALID;
6352                 goto out;
6353         }
6354
6355         inst = package_find_instance_by_id(pkgname, id);
6356         if (!inst) {
6357                 ErrPrint("Instance is not found [%s - %s]\n", pkgname, id);
6358                 ret = LB_STATUS_ERROR_NOT_EXIST;
6359                 goto out;
6360         }
6361
6362         ret = LB_STATUS_ERROR_INVALID;
6363         if (type == TYPE_LB) {
6364                 struct buffer_info *info;
6365
6366                 info = instance_lb_buffer(inst);
6367                 ret = buffer_handler_unload(info);
6368         } else if (type == TYPE_PD) {
6369                 struct buffer_info *info;
6370
6371                 DbgPrint("Slave release buffer for PD\n");
6372
6373                 info = instance_pd_buffer(inst);
6374                 ret = buffer_handler_unload(info);
6375
6376                 /*!
6377                  * \note
6378                  * Send the PD destroyed event to the client
6379                  */
6380                 instance_client_pd_destroyed(inst, ret);
6381         }
6382
6383 out:
6384         result = packet_create_reply(packet, "i", ret);
6385         if (!result)
6386                 ErrPrint("Failed to create a packet\n");
6387
6388         return result;
6389 }
6390
6391 static struct packet *service_change_period(pid_t pid, int handle, const struct packet *packet)
6392 {
6393         struct inst_info *inst;
6394         struct packet *result;
6395         const char *pkgname;
6396         const char *id;
6397         double period;
6398         int ret;
6399
6400         ret = packet_get(packet, "ssd", &pkgname, &id, &period);
6401         if (ret != 3) {
6402                 ErrPrint("Invalid packet\n");
6403                 ret = LB_STATUS_ERROR_INVALID;
6404                 goto out;
6405         }
6406
6407         if (!strlen(id)) {
6408                 struct pkg_info *pkg;
6409
6410                 pkg = package_find(pkgname);
6411                 if (!pkg) {
6412                         ret = LB_STATUS_ERROR_NOT_EXIST;
6413                 } else if (package_is_fault(pkg)) {
6414                         ret = LB_STATUS_ERROR_FAULT;
6415                 } else {
6416                         Eina_List *inst_list;
6417                         Eina_List *l;
6418
6419                         inst_list = package_instance_list(pkg);
6420                         EINA_LIST_FOREACH(inst_list, l, inst) {
6421                                 ret = instance_set_period(inst, period);
6422                                 if (ret < 0)
6423                                         DbgPrint("Failed to change the period of %s to (%lf)\n", instance_id(inst), period);
6424                         }
6425                 }
6426         } else {
6427                 inst = package_find_instance_by_id(pkgname, id);
6428                 if (!inst)
6429                         ret = LB_STATUS_ERROR_NOT_EXIST;
6430                 else if (package_is_fault(instance_package(inst)))
6431                         ret = LB_STATUS_ERROR_FAULT;
6432                 else
6433                         ret = instance_set_period(inst, period);
6434         }
6435
6436         DbgPrint("Change the update period: %s(%s), %lf : %d\n", pkgname, id, period, ret);
6437 out:
6438         result = packet_create_reply(packet, "i", ret);
6439         if (!result)
6440                 ErrPrint("Failed to create a packet\n");
6441
6442         return result;
6443 }
6444
6445 static struct packet *service_update(pid_t pid, int handle, const struct packet *packet)
6446 {
6447         struct pkg_info *pkg;
6448         struct packet *result;
6449         const char *pkgname;
6450         const char *id;
6451         const char *cluster;
6452         const char *category;
6453         char *lb_pkgname;
6454         int ret;
6455
6456         ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category);
6457         if (ret != 4) {
6458                 ErrPrint("Invalid Packet\n");
6459                 ret = LB_STATUS_ERROR_INVALID;
6460                 goto out;
6461         }
6462
6463         lb_pkgname = package_lb_pkgname(pkgname);
6464         if (!lb_pkgname) {
6465                 ErrPrint("Invalid package %s\n", pkgname);
6466                 ret = LB_STATUS_ERROR_INVALID;
6467                 goto out;
6468         }
6469
6470         pkg = package_find(lb_pkgname);
6471         if (!pkg) {
6472                 ret = LB_STATUS_ERROR_NOT_EXIST;
6473                 DbgFree(lb_pkgname);
6474                 goto out;
6475         }
6476
6477         if (package_is_fault(pkg)) {
6478                 ret = LB_STATUS_ERROR_FAULT;
6479                 DbgFree(lb_pkgname);
6480                 goto out;
6481         }
6482
6483         /*!
6484          * \TODO
6485          * Validate the update requstor.
6486          */
6487         slave_rpc_request_update(lb_pkgname, id, cluster, category);
6488         DbgFree(lb_pkgname);
6489         ret = LB_STATUS_SUCCESS;
6490
6491 out:
6492         result = packet_create_reply(packet, "i", ret);
6493         if (!result)
6494                 ErrPrint("Failed to create a packet\n");
6495
6496         return result;
6497 }
6498
6499 static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet *packet)
6500 {
6501         struct liveinfo *info;
6502         struct packet *result;
6503         int ret;
6504         const char *fifo_name;
6505         double timestamp;
6506
6507         DbgPrint("Request arrived from %d\n", pid);
6508
6509         if (packet_get(packet, "d", &timestamp) != 1) {
6510                 ErrPrint("Invalid packet\n");
6511                 fifo_name = "";
6512                 ret = LB_STATUS_ERROR_INVALID;
6513                 goto out;
6514         }
6515
6516         info = liveinfo_create(pid, handle);
6517         if (!info) {
6518                 ErrPrint("Failed to create a liveinfo object\n");
6519                 fifo_name = "";
6520                 ret = LB_STATUS_ERROR_INVALID;
6521                 goto out;
6522         }
6523
6524         ret = 0;
6525         fifo_name = liveinfo_filename(info);
6526         DbgPrint("FIFO Created: %s (Serve for %d)\n", fifo_name, pid);
6527
6528 out:
6529         result = packet_create_reply(packet, "si", fifo_name, ret);
6530         if (!result)
6531                 ErrPrint("Failed to create a result packet\n");
6532
6533         return result;
6534 }
6535
6536 static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet)
6537 {
6538         Eina_List *l;
6539         Eina_List *list;
6540         struct liveinfo *info;
6541         struct slave_node *slave;
6542         FILE *fp;
6543         double timestamp;
6544
6545         if (packet_get(packet, "d", &timestamp) != 1) {
6546                 ErrPrint("Invalid argument\n");
6547                 goto out;
6548         }
6549
6550         info = liveinfo_find_by_pid(pid);
6551         if (!info) {
6552                 ErrPrint("Invalid request\n");
6553                 goto out;
6554         }
6555
6556         liveinfo_open_fifo(info);
6557         fp = liveinfo_fifo(info);
6558         if (!fp) {
6559                 liveinfo_close_fifo(info);
6560                 goto out;
6561         }
6562
6563         list = (Eina_List *)slave_list();
6564         EINA_LIST_FOREACH(list, l, slave) {
6565                 fprintf(fp, "%d %s %s %s %d %d %d %s %d %d %lf\n", 
6566                         slave_pid(slave),
6567                         slave_name(slave),
6568                         slave_pkgname(slave),
6569                         slave_abi(slave),
6570                         slave_is_secured(slave),
6571                         slave_refcnt(slave),
6572                         slave_fault_count(slave),
6573                         slave_state_string(slave),
6574                         slave_loaded_instance(slave),
6575                         slave_loaded_package(slave),
6576                         slave_ttl(slave)
6577                 );
6578         }
6579
6580         fprintf(fp, "EOD\n");
6581         liveinfo_close_fifo(info);
6582 out:
6583         return NULL;
6584 }
6585
6586 static inline const char *visible_state_string(enum livebox_visible_state state)
6587 {
6588         switch (state) {
6589         case LB_SHOW:
6590                 return "Show";
6591         case LB_HIDE:
6592                 return "Hide";
6593         case LB_HIDE_WITH_PAUSE:
6594                 return "Paused";
6595         default:
6596                 break;
6597         }
6598
6599         return "Unknown";
6600 }
6601
6602 static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet)
6603 {
6604         const char *pkgname;
6605         struct liveinfo *info;
6606         struct pkg_info *pkg;
6607         Eina_List *l;
6608         Eina_List *inst_list;
6609         struct inst_info *inst;
6610         FILE *fp;
6611
6612         if (packet_get(packet, "s", &pkgname) != 1) {
6613                 ErrPrint("Invalid argument\n");
6614                 goto out;
6615         }
6616
6617         info = liveinfo_find_by_pid(pid);
6618         if (!info) {
6619                 ErrPrint("Invalid request\n");
6620                 goto out;
6621         }
6622
6623         liveinfo_open_fifo(info);
6624         fp = liveinfo_fifo(info);
6625         if (!fp) {
6626                 ErrPrint("Invalid fp\n");
6627                 liveinfo_close_fifo(info);
6628                 goto out;
6629         }
6630
6631         if (!package_is_lb_pkgname(pkgname)) {
6632                 ErrPrint("Invalid package name\n");
6633                 goto close_out;
6634         }
6635
6636         pkg = package_find(pkgname);
6637         if (!pkg) {
6638                 ErrPrint("Package is not exists\n");
6639                 goto close_out;
6640         }
6641
6642         inst_list = package_instance_list(pkg);
6643         EINA_LIST_FOREACH(inst_list, l, inst) {
6644                 fprintf(fp, "%s %s %s %lf %s %d %d\n",
6645                         instance_id(inst),
6646                         instance_cluster(inst),
6647                         instance_category(inst),
6648                         instance_period(inst),
6649                         visible_state_string(instance_visible_state(inst)),
6650                         instance_lb_width(inst),
6651                         instance_lb_height(inst));
6652         }
6653
6654 close_out:
6655         fprintf(fp, "EOD\n");
6656         liveinfo_close_fifo(info);
6657
6658 out:
6659         return NULL;
6660 }
6661
6662 static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet)
6663 {
6664         Eina_List *l;
6665         Eina_List *list;
6666         Eina_List *inst_list;
6667         struct liveinfo *info;
6668         struct pkg_info *pkg;
6669         struct slave_node *slave;
6670         FILE *fp;
6671         const char *slavename;
6672         double timestamp;
6673
6674         if (packet_get(packet, "d", &timestamp) != 1) {
6675                 ErrPrint("Invalid argument\n");
6676                 goto out;
6677         }
6678
6679         info = liveinfo_find_by_pid(pid);
6680         if (!info) {
6681                 ErrPrint("Invalid request\n");
6682                 goto out;
6683         }
6684
6685         liveinfo_open_fifo(info);
6686         fp = liveinfo_fifo(info);
6687         if (!fp) {
6688                 liveinfo_close_fifo(info);
6689                 goto out;
6690         }
6691
6692         list = (Eina_List *)package_list();
6693         EINA_LIST_FOREACH(list, l, pkg) {
6694                 slave = package_slave(pkg);
6695
6696                 if (slave) {
6697                         slavename = slave_name(slave);
6698                         pid = slave_pid(slave);
6699                 } else {
6700                         pid = (pid_t)-1;
6701                         slavename = "";
6702                 }
6703
6704                 inst_list = (Eina_List *)package_instance_list(pkg);
6705                 fprintf(fp, "%d %s %s %s %d %d %d\n",
6706                         pid,
6707                         strlen(slavename) ? slavename : "(none)",
6708                         package_name(pkg),
6709                         package_abi(pkg),
6710                         package_refcnt(pkg),
6711                         package_fault_count(pkg),
6712                         eina_list_count(inst_list)
6713                 );
6714         }
6715
6716         fprintf(fp, "EOD\n");
6717         liveinfo_close_fifo(info);
6718 out:
6719         return NULL;
6720 }
6721
6722 static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct packet *packet)
6723 {
6724         return NULL;
6725 }
6726
6727 static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet)
6728 {
6729         struct liveinfo *info;
6730         FILE *fp;
6731         char *cmd;
6732         char *pkgname;
6733         char *id;
6734
6735         if (packet_get(packet, "sss", &cmd, &pkgname, &id) != 3) {
6736                 ErrPrint("Invalid argument\n");
6737                 goto out;
6738         }
6739
6740         info = liveinfo_find_by_pid(pid);
6741         if (!info) {
6742                 ErrPrint("Invalid request\n");
6743                 goto out;
6744         }
6745
6746         liveinfo_open_fifo(info);
6747         fp = liveinfo_fifo(info);
6748         if (!fp) {
6749                 liveinfo_close_fifo(info);
6750                 goto out;
6751         }
6752
6753         if (!strcmp(cmd, "rmpack")) {
6754                 fprintf(fp, "%d\n", ENOSYS);
6755         } else if (!strcmp(cmd, "rminst")) {
6756                 struct inst_info *inst;
6757                 inst = package_find_instance_by_id(pkgname, id);
6758                 if (!inst) {
6759                         fprintf(fp, "%d\n", ENOENT);
6760                 } else {
6761                         instance_destroy(inst);
6762                         fprintf(fp, "%d\n", 0);
6763                 }
6764         }
6765
6766         fprintf(fp, "EOD\n");
6767         liveinfo_close_fifo(info);
6768
6769 out:
6770         return NULL;
6771 }
6772
6773 static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct packet *packet)
6774 {
6775         struct liveinfo *info;
6776         char *cmd;
6777         char *var;
6778         char *val;
6779         FILE *fp;
6780         int ret = LB_STATUS_ERROR_INVALID;
6781
6782         if (packet_get(packet, "sss", &cmd, &var, &val) != 3) {
6783                 ErrPrint("Invalid argument\n");
6784                 goto out;
6785         }
6786
6787         info = liveinfo_find_by_pid(pid);
6788         if (!info) {
6789                 ErrPrint("Invalid request\n");
6790                 goto out;
6791         }
6792
6793         if (!strcasecmp(var, "debug")) {
6794                 if (!strcasecmp(cmd, "set")) {
6795                         g_conf.debug_mode = !strcasecmp(val, "on");
6796                 } else if (!strcasecmp(cmd, "get")) {
6797                 }
6798                 ret = g_conf.debug_mode;
6799         } else if (!strcasecmp(var, "slave_max_load")) {
6800                 if (!strcasecmp(cmd, "set")) {
6801                         g_conf.slave_max_load = atoi(val);
6802                 } else if (!strcasecmp(cmd, "get")) {
6803                 }
6804                 ret = g_conf.slave_max_load;
6805         }
6806
6807         liveinfo_open_fifo(info);
6808         fp = liveinfo_fifo(info);
6809         if (!fp) {
6810                 liveinfo_close_fifo(info);
6811                 goto out;
6812         }
6813         fprintf(fp, "%d\nEOD\n", ret);
6814         liveinfo_close_fifo(info);
6815
6816 out:
6817         return NULL;
6818 }
6819
6820 static struct method s_info_table[] = {
6821         {
6822                 .cmd = "liveinfo_hello",
6823                 .handler = liveinfo_hello,
6824         },
6825         {
6826                 .cmd = "slave_list",
6827                 .handler = liveinfo_slave_list,
6828         },
6829         {
6830                 .cmd = "pkg_list",
6831                 .handler = liveinfo_pkg_list,
6832         },
6833         {
6834                 .cmd = "inst_list",
6835                 .handler = liveinfo_inst_list,
6836         },
6837         {
6838                 .cmd = "slave_ctrl",
6839                 .handler = liveinfo_slave_ctrl,
6840         },
6841         {
6842                 .cmd = "pkg_ctrl",
6843                 .handler = liveinfo_pkg_ctrl,
6844         },
6845         {
6846                 .cmd = "master_ctrl",
6847                 .handler = liveinfo_master_ctrl,
6848         },
6849         {
6850                 .cmd = NULL,
6851                 .handler = NULL,
6852         },
6853 };
6854
6855 static struct method s_client_table[] = {
6856         {
6857                 .cmd = "pd_mouse_move",
6858                 .handler = client_pd_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6859         },
6860         {
6861                 .cmd = "lb_mouse_move",
6862                 .handler = client_lb_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6863         },
6864         {
6865                 .cmd = "pd_mouse_down",
6866                 .handler = client_pd_mouse_down, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
6867         },
6868         {
6869                 .cmd = "pd_mouse_up",
6870                 .handler = client_pd_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6871         },
6872         {
6873                 .cmd = "lb_mouse_down",
6874                 .handler = client_lb_mouse_down, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6875         },
6876         {
6877                 .cmd = "lb_mouse_up",
6878                 .handler = client_lb_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6879         },
6880         {
6881                 .cmd = "pd_mouse_enter",
6882                 .handler = client_pd_mouse_enter, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
6883         },
6884         {
6885                 .cmd = "pd_mouse_leave",
6886                 .handler = client_pd_mouse_leave, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
6887         },
6888         {
6889                 .cmd = "lb_mouse_enter",
6890                 .handler = client_lb_mouse_enter, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6891         },
6892         {
6893                 .cmd = "lb_mouse_leave",
6894                 .handler = client_lb_mouse_leave, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6895         },
6896         {
6897                 .cmd = "lb_mouse_set",
6898                 .handler = client_lb_mouse_set,
6899         },
6900         {
6901                 .cmd = "lb_mouse_unset",
6902                 .handler = client_lb_mouse_unset,
6903         },
6904         {
6905                 .cmd = "pd_mouse_set",
6906                 .handler = client_pd_mouse_set,
6907         },
6908         {
6909                 .cmd = "pd_mouse_unset",
6910                 .handler = client_pd_mouse_unset,
6911         },
6912         {
6913                 .cmd = "change,visibility",
6914                 .handler = client_change_visibility,
6915         },
6916         {
6917                 .cmd = "lb_acquire_pixmap",
6918                 .handler = client_lb_acquire_pixmap,
6919         },
6920         {
6921                 .cmd = "lb_release_pixmap",
6922                 .handler = client_lb_release_pixmap,
6923         },
6924         {
6925                 .cmd = "pd_acquire_pixmap",
6926                 .handler = client_pd_acquire_pixmap,
6927         },
6928         {
6929                 .cmd = "pd_release_pixmap",
6930                 .handler = client_pd_release_pixmap,
6931         },
6932         {
6933                 .cmd = "acquire",
6934                 .handler = client_acquire, /*!< pid, ret */
6935         },
6936         {
6937                 .cmd = "release",
6938                 .handler = cilent_release, /*!< pid, ret */
6939         },
6940         {
6941                 .cmd = "clicked",
6942                 .handler = client_clicked, /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
6943         },
6944         {
6945                 .cmd = "text_signal",
6946                 .handler = client_text_signal, /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
6947         },
6948         {
6949                 .cmd = "delete",
6950                 .handler = client_delete, /* pid, pkgname, filename, ret */
6951         },
6952         {
6953                 .cmd = "resize",
6954                 .handler = client_resize, /* pid, pkgname, filename, w, h, ret */
6955         },
6956         {
6957                 .cmd = "new",
6958                 .handler = client_new, /* pid, timestamp, pkgname, content, cluster, category, period, ret */
6959         },
6960         {
6961                 .cmd = "set_period",
6962                 .handler = client_set_period, /* pid, pkgname, filename, period, ret, period */
6963         },
6964         {
6965                 .cmd = "change_group",
6966                 .handler = client_change_group, /* pid, pkgname, filename, cluster, category, ret */
6967         },
6968         {
6969                 .cmd = "pinup_changed",
6970                 .handler = client_pinup_changed, /* pid, pkgname, filename, pinup, ret */
6971         },
6972         {
6973                 .cmd = "create_pd",
6974                 .handler = client_create_pd, /* pid, pkgname, filename, ret */
6975         },
6976         {
6977                 .cmd = "pd_move",
6978                 .handler = client_pd_move, /* pkgname, id, x, y */
6979         },
6980         {
6981                 .cmd = "destroy_pd",
6982                 .handler = client_destroy_pd, /* pid, pkgname, filename, ret */
6983         },
6984         {
6985                 .cmd = "activate_package",
6986                 .handler = client_activate_package, /* pid, pkgname, ret */
6987         },
6988         {
6989                 .cmd = "subscribe", /* pid, cluster, sub-cluster */
6990                 .handler = client_subscribed,
6991         },
6992         {
6993                 .cmd = "unsubscribe", /* pid, cluster, sub-cluster */
6994                 .handler = client_unsubscribed,
6995         },
6996         {
6997                 .cmd = "delete_cluster",
6998                 .handler = client_delete_cluster,
6999         },
7000         {
7001                 .cmd = "delete_category",
7002                 .handler = client_delete_category,
7003         },
7004         {
7005                 .cmd = "refresh_group",
7006                 .handler = client_refresh_group,
7007         },
7008         {
7009                 .cmd = "update",
7010                 .handler = client_update,
7011         },
7012
7013         {
7014                 .cmd = "pd_access_hl",
7015                 .handler = client_pd_access_hl,
7016         },
7017         {
7018                 .cmd = "pd_access_hl_prev",
7019                 .handler = client_pd_access_hl_prev,
7020         },
7021         {
7022                 .cmd = "pd_access_hl_next",
7023                 .handler = client_pd_access_hl_next,
7024         },
7025         {
7026                 .cmd = "pd_access_activate",
7027                 .handler = client_pd_access_activate,
7028         },
7029         {
7030                 .cmd = "pd_access_value_change",
7031                 .handler = client_pd_access_value_change,
7032         },
7033         {
7034                 .cmd = "pd_access_scroll",
7035                 .handler = client_pd_access_scroll,
7036         },
7037         {
7038                 .cmd = "pd_access_unhighlight",
7039                 .handler = client_pd_access_unhighlight,
7040         },
7041
7042         {
7043                 .cmd = "lb_access_hl",
7044                 .handler = client_lb_access_hl,
7045         },
7046         {
7047                 .cmd = "lb_access_hl_prev",
7048                 .handler = client_lb_access_hl_prev,
7049         },
7050         {
7051                 .cmd = "lb_access_hl_next",
7052                 .handler = client_lb_access_hl_next,
7053         },
7054         {
7055                 .cmd = "lb_access_activate",
7056                 .handler = client_lb_access_activate,
7057         },
7058         {
7059                 .cmd = "lb_access_value_change",
7060                 .handler = client_lb_access_value_change,
7061         },
7062         {
7063                 .cmd = "lb_access_scroll",
7064                 .handler = client_lb_access_scroll,
7065         },
7066         {
7067                 .cmd = "lb_access_unhighlight",
7068                 .handler = client_lb_access_unhighlight,
7069         },
7070
7071         {
7072                 .cmd = "lb_key_down",
7073                 .handler = client_lb_key_down,
7074         },
7075         {
7076                 .cmd = "lb_key_up",
7077                 .handler = client_lb_key_up,
7078         },
7079
7080         {
7081                 .cmd = "pd_key_down",
7082                 .handler = client_pd_key_down,
7083         },
7084         {
7085                 .cmd = "pd_key_up",
7086                 .handler = client_pd_key_up,
7087         },
7088
7089         {
7090                 .cmd = "client_paused",
7091                 .handler = client_pause_request,
7092         },
7093         {
7094                 .cmd = "client_resumed",
7095                 .handler = client_resume_request,
7096         },
7097
7098         {
7099                 .cmd = "update_mode",
7100                 .handler = client_update_mode,
7101         },
7102
7103         {
7104                 .cmd = NULL,
7105                 .handler = NULL,
7106         },
7107 };
7108
7109 static struct method s_service_table[] = {
7110         {
7111                 .cmd = "service_update",
7112                 .handler = service_update,
7113         },
7114         {
7115                 .cmd = "service_change_period",
7116                 .handler = service_change_period,
7117         },
7118         {
7119                 .cmd = NULL,
7120                 .handler = NULL,
7121         },
7122 };
7123
7124 static struct method s_slave_table[] = {
7125         {
7126                 .cmd = "hello",
7127                 .handler = slave_hello, /* slave_name, ret */
7128         },
7129         {
7130                 .cmd = "ping",
7131                 .handler = slave_ping, /* slave_name, ret */
7132         },
7133         {
7134                 .cmd = "call",
7135                 .handler = slave_call, /* slave_name, pkgname, filename, function, ret */
7136         },
7137         {
7138                 .cmd = "ret",
7139                 .handler = slave_ret, /* slave_name, pkgname, filename, function, ret */
7140         },
7141         {
7142                 .cmd = "updated",
7143                 .handler = slave_updated, /* slave_name, pkgname, filename, width, height, priority, ret */
7144         },
7145         {
7146                 .cmd = "desc_updated",
7147                 .handler = slave_desc_updated, /* slave_name, pkgname, filename, decsfile, ret */
7148         },
7149         {
7150                 .cmd = "deleted",
7151                 .handler = slave_deleted, /* slave_name, pkgname, filename, ret */
7152         },
7153         {
7154                 .cmd = "acquire_buffer",
7155                 .handler = slave_acquire_buffer, /* slave_name, id, w, h, size, - out - type, shmid */
7156         },
7157         {
7158                 .cmd = "resize_buffer",
7159                 .handler = slave_resize_buffer,
7160         },
7161         {
7162                 .cmd = "release_buffer",
7163                 .handler = slave_release_buffer, /* slave_name, id - ret */
7164         },
7165         {
7166                 .cmd = "faulted",
7167                 .handler = slave_faulted, /* slave_name, pkgname, id, funcname */
7168         },
7169         {
7170                 .cmd = "scroll",
7171                 .handler = slave_hold_scroll, /* slave_name, pkgname, id, seize */
7172         },
7173
7174         {
7175                 .cmd = "lb_update_begin",
7176                 .handler = slave_lb_update_begin,
7177         },
7178         {
7179                 .cmd = "lb_update_end",
7180                 .handler = slave_lb_update_end,
7181         },
7182         {
7183                 .cmd = "pd_update_begin",
7184                 .handler = slave_pd_update_begin,
7185         },
7186         {
7187                 .cmd = "pd_update_end",
7188                 .handler = slave_pd_update_end,
7189         },
7190
7191         {
7192                 .cmd = "access_status",
7193                 .handler = slave_access_status,
7194         },
7195
7196         {
7197                 .cmd = NULL,
7198                 .handler = NULL,
7199         },
7200 };
7201
7202 HAPI int server_init(void)
7203 {
7204         com_core_packet_use_thread(COM_CORE_THREAD);
7205
7206         if (unlink(INFO_SOCKET) < 0)
7207                 ErrPrint("info socket: %s\n", strerror(errno));
7208
7209         if (unlink(SLAVE_SOCKET) < 0)
7210                 ErrPrint("slave socket: %s\n", strerror(errno));
7211
7212         if (unlink(CLIENT_SOCKET) < 0)
7213                 ErrPrint("client socket: %s\n", strerror(errno));
7214
7215         if (unlink(SERVICE_SOCKET) < 0)
7216                 ErrPrint("service socket: %s\n", strerror(errno));
7217
7218         s_info.info_fd = com_core_packet_server_init(INFO_SOCKET, s_info_table);
7219         if (s_info.info_fd < 0)
7220                 ErrPrint("Failed to create a info socket\n");
7221
7222         s_info.slave_fd = com_core_packet_server_init(SLAVE_SOCKET, s_slave_table);
7223         if (s_info.slave_fd < 0)
7224                 ErrPrint("Failed to create a slave socket\n");
7225
7226         s_info.client_fd = com_core_packet_server_init(CLIENT_SOCKET, s_client_table);
7227         if (s_info.client_fd < 0)
7228                 ErrPrint("Failed to create a client socket\n");
7229
7230         s_info.service_fd = com_core_packet_server_init(SERVICE_SOCKET, s_service_table);
7231         if (s_info.service_fd < 0)
7232                 ErrPrint("Faild to create a service socket\n");
7233
7234         if (chmod(INFO_SOCKET, 0600) < 0)
7235                 ErrPrint("info socket: %s\n", strerror(errno));
7236
7237         if (chmod(SLAVE_SOCKET, 0666) < 0)
7238                 ErrPrint("slave socket: %s\n", strerror(errno));
7239
7240         if (chmod(CLIENT_SOCKET, 0666) < 0)
7241                 ErrPrint("client socket: %s\n", strerror(errno));
7242
7243         if (chmod(SERVICE_SOCKET, 0666) < 0)
7244                 ErrPrint("service socket: %s\n", strerror(errno));
7245
7246         return 0;
7247 }
7248
7249 HAPI int server_fini(void)
7250 {
7251         if (s_info.info_fd > 0) {
7252                 com_core_packet_server_fini(s_info.info_fd);
7253                 s_info.info_fd = -1;
7254         }
7255
7256         if (s_info.slave_fd > 0) {
7257                 com_core_packet_server_fini(s_info.slave_fd);
7258                 s_info.slave_fd = -1;
7259         }
7260
7261         if (s_info.client_fd > 0) {
7262                 com_core_packet_server_fini(s_info.client_fd);
7263                 s_info.client_fd = -1;
7264         }
7265
7266         if (s_info.service_fd > 0) {
7267                 com_core_packet_server_fini(s_info.service_fd);
7268                 s_info.service_fd = -1;
7269         }
7270
7271         return 0;
7272 }
7273
7274 /* End of a file */