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