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