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