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