Update the liveinfo
[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_pd_key_up(pid_t pid, int handle, const struct packet *packet)
2339 {
2340         struct client_node *client;
2341         const char *pkgname;
2342         const char *id;
2343         int ret;
2344         int w;
2345         int h;
2346         double timestamp;
2347         double x;
2348         double y;
2349         struct inst_info *inst;
2350         const struct pkg_info *pkg;
2351
2352         client = client_find_by_pid(pid);
2353         if (!client) {
2354                 ErrPrint("Client %d is not exists\n", pid);
2355                 ret = -ENOENT;
2356                 goto out;
2357         }
2358
2359         ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
2360         if (ret != 7) {
2361                 ErrPrint("Invalid parameter\n");
2362                 ret = -EINVAL;
2363                 goto out;
2364         }
2365
2366         /*!
2367          * \NOTE:
2368          * Trust the package name which are sent by the client.
2369          * The package has to be a livebox package name.
2370          */
2371         inst = package_find_instance_by_id(pkgname, id);
2372         if (!inst) {
2373                 ErrPrint("Instance[%s] is not exists\n", id);
2374                 ret = -ENOENT;
2375                 goto out;
2376         }
2377
2378         pkg = instance_package(inst);
2379         if (!pkg) {
2380                 ErrPrint("Package[%s] info is not found\n", pkgname);
2381                 ret = -EFAULT;
2382                 goto out;
2383         }
2384
2385         if (package_is_fault(pkg)) {
2386                 /*!
2387                  * \note
2388                  * If the package is registered as fault module,
2389                  * slave has not load it, so we don't need to do anything at here!
2390                  */
2391                 DbgPrint("Package[%s] is faulted\n", pkgname);
2392                 ret = -EFAULT;
2393         } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2394                 struct buffer_info *buffer;
2395                 struct slave_node *slave;
2396                 // struct packet *packet;
2397
2398                 buffer = instance_pd_buffer(inst);
2399                 if (!buffer) {
2400                         ErrPrint("Instance[%s] has no buffer\n", id);
2401                         ret = -EFAULT;
2402                         goto out;
2403                 }
2404
2405                 slave = package_slave(pkg);
2406                 if (!slave) {
2407                         ErrPrint("Package[%s] has no slave\n", pkgname);
2408                         ret = -EINVAL;
2409                         goto out;
2410                 }
2411
2412                 /*
2413                 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2414                 if (!packet) {
2415                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2416                         ret = -EFAULT;
2417                         goto out;
2418                 }
2419                 */
2420
2421                 packet_ref((struct packet *)packet);
2422                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2423         } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2424                 struct script_info *script;
2425                 Evas *e;
2426
2427                 script = instance_pd_script(inst);
2428                 if (!script) {
2429                         ret = -EFAULT;
2430                         goto out;
2431                 }
2432
2433                 e = script_handler_evas(script);
2434                 if (!e) {
2435                         ret = -EFAULT;
2436                         goto out;
2437                 }
2438
2439                 script_handler_update_pointer(script, x, y, -1);
2440                 /*!
2441                  * \TODO: Push up the KEY_UP event
2442                  */
2443                 ret = 0;
2444         } else {
2445                 ErrPrint("Unsupported package\n");
2446                 ret = -EINVAL;
2447         }
2448
2449 out:
2450         /*! \note No reply packet */
2451         return NULL;
2452 }
2453
2454 static struct packet *client_lb_access_read(pid_t pid, int handle, const struct packet *packet)
2455 {
2456         struct client_node *client;
2457         const char *pkgname;
2458         const char *id;
2459         int ret;
2460         int w;
2461         int h;
2462         double timestamp;
2463         double x;
2464         double y;
2465         struct inst_info *inst;
2466         const struct pkg_info *pkg;
2467
2468         client = client_find_by_pid(pid);
2469         if (!client) {
2470                 ErrPrint("Client %d is not exists\n", pid);
2471                 ret = -ENOENT;
2472                 goto out;
2473         }
2474
2475         ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
2476         if (ret != 7) {
2477                 ErrPrint("Parameter is not matched\n");
2478                 ret = -EINVAL;
2479                 goto out;
2480         }
2481
2482         /*!
2483          * \NOTE:
2484          * Trust the package name which are sent by the client.
2485          * The package has to be a livebox package name.
2486          */
2487         inst = package_find_instance_by_id(pkgname, id);
2488         if (!inst) {
2489                 ErrPrint("Instance[%s] is not exists\n", id);
2490                 ret = -ENOENT;
2491                 goto out;
2492         }
2493
2494         pkg = instance_package(inst);
2495         if (!pkg) {
2496                 ErrPrint("Package[%s] info is not exists\n", pkgname);
2497                 ret = -EFAULT;
2498                 goto out;
2499         }
2500
2501         if (package_is_fault(pkg)) {
2502                 /*!
2503                  * \note
2504                  * If the package is registered as fault module,
2505                  * slave has not load it, so we don't need to do anything at here!
2506                  */
2507                 DbgPrint("Package[%s] is faulted\n", pkgname);
2508                 ret = -EFAULT;
2509         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2510                 struct buffer_info *buffer;
2511                 struct slave_node *slave;
2512                 //struct packet *packet;
2513
2514                 buffer = instance_lb_buffer(inst);
2515                 if (!buffer) {
2516                         ErrPrint("Instance[%s] has no buffer\n", id);
2517                         ret = -EFAULT;
2518                         goto out;
2519                 }
2520
2521                 slave = package_slave(pkg);
2522                 if (!slave) {
2523                         ErrPrint("Package[%s] has no slave\n", pkgname);
2524                         ret = -EINVAL;
2525                         goto out;
2526                 }
2527
2528                 /*
2529                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2530                 if (!packet) {
2531                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2532                         ret = -EFAULT;
2533                         goto out;
2534                 }
2535                 */
2536
2537                 packet_ref((struct packet *)packet);
2538                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2539         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2540                 struct script_info *script;
2541                 Evas *e;
2542
2543                 script = instance_lb_script(inst);
2544                 if (!script) {
2545                         ret = -EFAULT;
2546                         goto out;
2547                 }
2548
2549                 e = script_handler_evas(script);
2550                 if (!e) {
2551                         ret = -EFAULT;
2552                         goto out;
2553                 }
2554
2555                 script_handler_update_pointer(script, x, y, -1);
2556
2557                 /*!
2558                  * \TODO: Feed up this ACCESS_READ event
2559                  */
2560                 ret = 0;
2561         } else {
2562                 ErrPrint("Unsupported package\n");
2563                 ret = -EINVAL;
2564         }
2565
2566 out:
2567         /*! \note No reply packet */
2568         return NULL;
2569 }
2570
2571 static struct packet *client_lb_access_read_prev(pid_t pid, int handle, const struct packet *packet)
2572 {
2573         struct client_node *client;
2574         const char *pkgname;
2575         const char *id;
2576         int ret;
2577         int w;
2578         int h;
2579         double timestamp;
2580         double x;
2581         double y;
2582         struct inst_info *inst;
2583         const struct pkg_info *pkg;
2584
2585         client = client_find_by_pid(pid);
2586         if (!client) {
2587                 ErrPrint("Client %d is not exists\n", pid);
2588                 ret = -ENOENT;
2589                 goto out;
2590         }
2591
2592         ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
2593         if (ret != 7) {
2594                 ErrPrint("Parameter is not matched\n");
2595                 ret = -EINVAL;
2596                 goto out;
2597         }
2598
2599         /*!
2600          * \NOTE:
2601          * Trust the package name which are sent by the client.
2602          * The package has to be a livebox package name.
2603          */
2604         inst = package_find_instance_by_id(pkgname, id);
2605         if (!inst) {
2606                 ErrPrint("Instance[%s] is not exists\n", id);
2607                 ret = -ENOENT;
2608                 goto out;
2609         }
2610
2611         pkg = instance_package(inst);
2612         if (!pkg) {
2613                 ErrPrint("Package[%s] info is not exists\n", pkgname);
2614                 ret = -EFAULT;
2615                 goto out;
2616         }
2617
2618         if (package_is_fault(pkg)) {
2619                 /*!
2620                  * \note
2621                  * If the package is registered as fault module,
2622                  * slave has not load it, so we don't need to do anything at here!
2623                  */
2624                 DbgPrint("Package[%s] is faulted\n", pkgname);
2625                 ret = -EFAULT;
2626         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2627                 struct buffer_info *buffer;
2628                 struct slave_node *slave;
2629                 //struct packet *packet;
2630
2631                 buffer = instance_lb_buffer(inst);
2632                 if (!buffer) {
2633                         ErrPrint("Instance[%s] has no buffer\n", id);
2634                         ret = -EFAULT;
2635                         goto out;
2636                 }
2637
2638                 slave = package_slave(pkg);
2639                 if (!slave) {
2640                         ErrPrint("Package[%s] has no slave\n", pkgname);
2641                         ret = -EINVAL;
2642                         goto out;
2643                 }
2644
2645                 /*
2646                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2647                 if (!packet) {
2648                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2649                         ret = -EFAULT;
2650                         goto out;
2651                 }
2652                 */
2653
2654                 packet_ref((struct packet *)packet);
2655                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2656         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2657                 struct script_info *script;
2658                 Evas *e;
2659
2660                 script = instance_lb_script(inst);
2661                 if (!script) {
2662                         ret = -EFAULT;
2663                         goto out;
2664                 }
2665
2666                 e = script_handler_evas(script);
2667                 if (!e) {
2668                         ret = -EFAULT;
2669                         goto out;
2670                 }
2671
2672                 script_handler_update_pointer(script, x, y, -1);
2673
2674                 /*!
2675                  * \TODO: Feed up this ACCESS_READ_PREV event
2676                  */
2677                 ret = 0;
2678         } else {
2679                 ErrPrint("Unsupported package\n");
2680                 ret = -EINVAL;
2681         }
2682
2683 out:
2684         /*! \note No reply packet */
2685         return NULL;
2686 }
2687
2688 static struct packet *client_lb_access_read_next(pid_t pid, int handle, const struct packet *packet)
2689 {
2690         struct client_node *client;
2691         const char *pkgname;
2692         const char *id;
2693         int ret;
2694         int w;
2695         int h;
2696         double timestamp;
2697         double x;
2698         double y;
2699         struct inst_info *inst;
2700         const struct pkg_info *pkg;
2701
2702         client = client_find_by_pid(pid);
2703         if (!client) {
2704                 ErrPrint("Client %d is not exists\n", pid);
2705                 ret = -ENOENT;
2706                 goto out;
2707         }
2708
2709         ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
2710         if (ret != 7) {
2711                 ErrPrint("Parameter is not matched\n");
2712                 ret = -EINVAL;
2713                 goto out;
2714         }
2715
2716         /*!
2717          * \NOTE:
2718          * Trust the package name which are sent by the client.
2719          * The package has to be a livebox package name.
2720          */
2721         inst = package_find_instance_by_id(pkgname, id);
2722         if (!inst) {
2723                 ErrPrint("Instance[%s] is not exists\n", id);
2724                 ret = -ENOENT;
2725                 goto out;
2726         }
2727
2728         pkg = instance_package(inst);
2729         if (!pkg) {
2730                 ErrPrint("Package[%s] info is not exists\n", pkgname);
2731                 ret = -EFAULT;
2732                 goto out;
2733         }
2734
2735         if (package_is_fault(pkg)) {
2736                 /*!
2737                  * \note
2738                  * If the package is registered as fault module,
2739                  * slave has not load it, so we don't need to do anything at here!
2740                  */
2741                 DbgPrint("Package[%s] is faulted\n", pkgname);
2742                 ret = -EFAULT;
2743         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2744                 struct buffer_info *buffer;
2745                 struct slave_node *slave;
2746                 //struct packet *packet;
2747
2748                 buffer = instance_lb_buffer(inst);
2749                 if (!buffer) {
2750                         ErrPrint("Instance[%s] has no buffer\n", id);
2751                         ret = -EFAULT;
2752                         goto out;
2753                 }
2754
2755                 slave = package_slave(pkg);
2756                 if (!slave) {
2757                         ErrPrint("Package[%s] has no slave\n", pkgname);
2758                         ret = -EINVAL;
2759                         goto out;
2760                 }
2761
2762                 /*
2763                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2764                 if (!packet) {
2765                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2766                         ret = -EFAULT;
2767                         goto out;
2768                 }
2769                 */
2770
2771                 packet_ref((struct packet *)packet);
2772                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2773         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2774                 struct script_info *script;
2775                 Evas *e;
2776
2777                 script = instance_lb_script(inst);
2778                 if (!script) {
2779                         ret = -EFAULT;
2780                         goto out;
2781                 }
2782
2783                 e = script_handler_evas(script);
2784                 if (!e) {
2785                         ret = -EFAULT;
2786                         goto out;
2787                 }
2788
2789                 script_handler_update_pointer(script, x, y, -1);
2790
2791                 /*!
2792                  * \TODO: Feed up this ACCESS_READ_NEXT event
2793                  */
2794                 ret = 0;
2795         } else {
2796                 ErrPrint("Unsupported package\n");
2797                 ret = -EINVAL;
2798         }
2799
2800 out:
2801         /*! \note No reply packet */
2802         return NULL;
2803 }
2804
2805 static struct packet *client_lb_access_activate(pid_t pid, int handle, const struct packet *packet)
2806 {
2807         struct client_node *client;
2808         const char *pkgname;
2809         const char *id;
2810         int ret;
2811         int w;
2812         int h;
2813         double timestamp;
2814         double x;
2815         double y;
2816         struct inst_info *inst;
2817         const struct pkg_info *pkg;
2818
2819         client = client_find_by_pid(pid);
2820         if (!client) {
2821                 ErrPrint("Client %d is not exists\n", pid);
2822                 ret = -ENOENT;
2823                 goto out;
2824         }
2825
2826         ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
2827         if (ret != 7) {
2828                 ErrPrint("Parameter is not matched\n");
2829                 ret = -EINVAL;
2830                 goto out;
2831         }
2832
2833         /*!
2834          * \NOTE:
2835          * Trust the package name which are sent by the client.
2836          * The package has to be a livebox package name.
2837          */
2838         inst = package_find_instance_by_id(pkgname, id);
2839         if (!inst) {
2840                 ErrPrint("Instance[%s] is not exists\n", id);
2841                 ret = -ENOENT;
2842                 goto out;
2843         }
2844
2845         pkg = instance_package(inst);
2846         if (!pkg) {
2847                 ErrPrint("Package[%s] info is not exists\n", pkgname);
2848                 ret = -EFAULT;
2849                 goto out;
2850         }
2851
2852         if (package_is_fault(pkg)) {
2853                 /*!
2854                  * \note
2855                  * If the package is registered as fault module,
2856                  * slave has not load it, so we don't need to do anything at here!
2857                  */
2858                 DbgPrint("Package[%s] is faulted\n", pkgname);
2859                 ret = -EFAULT;
2860         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2861                 struct buffer_info *buffer;
2862                 struct slave_node *slave;
2863                 //struct packet *packet;
2864
2865                 buffer = instance_lb_buffer(inst);
2866                 if (!buffer) {
2867                         ErrPrint("Instance[%s] has no buffer\n", id);
2868                         ret = -EFAULT;
2869                         goto out;
2870                 }
2871
2872                 slave = package_slave(pkg);
2873                 if (!slave) {
2874                         ErrPrint("Package[%s] has no slave\n", pkgname);
2875                         ret = -EINVAL;
2876                         goto out;
2877                 }
2878
2879                 /*
2880                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2881                 if (!packet) {
2882                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
2883                         ret = -EFAULT;
2884                         goto out;
2885                 }
2886                 */
2887
2888                 packet_ref((struct packet *)packet);
2889                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2890         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2891                 struct script_info *script;
2892                 Evas *e;
2893
2894                 script = instance_lb_script(inst);
2895                 if (!script) {
2896                         ret = -EFAULT;
2897                         goto out;
2898                 }
2899
2900                 e = script_handler_evas(script);
2901                 if (!e) {
2902                         ret = -EFAULT;
2903                         goto out;
2904                 }
2905
2906                 script_handler_update_pointer(script, x, y, -1);
2907
2908                 /*!
2909                  * \TODO: Feed up this ACCESS_ACTIVATE event
2910                  */
2911                 ret = 0;
2912         } else {
2913                 ErrPrint("Unsupported package\n");
2914                 ret = -EINVAL;
2915         }
2916
2917 out:
2918         /*! \note No reply packet */
2919         return NULL;
2920 }
2921
2922 static struct packet *client_lb_key_down(pid_t pid, int handle, const struct packet *packet)
2923 {
2924         struct client_node *client;
2925         const char *pkgname;
2926         const char *id;
2927         int ret;
2928         int w;
2929         int h;
2930         double timestamp;
2931         double x;
2932         double y;
2933         struct inst_info *inst;
2934         const struct pkg_info *pkg;
2935
2936         client = client_find_by_pid(pid);
2937         if (!client) {
2938                 ErrPrint("Client %d is not exists\n", pid);
2939                 ret = -ENOENT;
2940                 goto out;
2941         }
2942
2943         ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
2944         if (ret != 7) {
2945                 ErrPrint("Parameter is not matched\n");
2946                 ret = -EINVAL;
2947                 goto out;
2948         }
2949
2950         /*!
2951          * \NOTE:
2952          * Trust the package name which are sent by the client.
2953          * The package has to be a livebox package name.
2954          */
2955         inst = package_find_instance_by_id(pkgname, id);
2956         if (!inst) {
2957                 ErrPrint("Instance[%s] is not exists\n", id);
2958                 ret = -ENOENT;
2959                 goto out;
2960         }
2961
2962         pkg = instance_package(inst);
2963         if (!pkg) {
2964                 ErrPrint("Package[%s] info is not exists\n", pkgname);
2965                 ret = -EFAULT;
2966                 goto out;
2967         }
2968
2969         if (package_is_fault(pkg)) {
2970                 /*!
2971                  * \note
2972                  * If the package is registered as fault module,
2973                  * slave has not load it, so we don't need to do anything at here!
2974                  */
2975                 DbgPrint("Package[%s] is faulted\n", pkgname);
2976                 ret = -EFAULT;
2977         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2978                 struct buffer_info *buffer;
2979                 struct slave_node *slave;
2980                 //struct packet *packet;
2981
2982                 buffer = instance_lb_buffer(inst);
2983                 if (!buffer) {
2984                         ErrPrint("Instance[%s] has no buffer\n", id);
2985                         ret = -EFAULT;
2986                         goto out;
2987                 }
2988
2989                 slave = package_slave(pkg);
2990                 if (!slave) {
2991                         ErrPrint("Package[%s] has no slave\n", pkgname);
2992                         ret = -EINVAL;
2993                         goto out;
2994                 }
2995
2996                 /*
2997                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
2998                 if (!packet) {
2999                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
3000                         ret = -EFAULT;
3001                         goto out;
3002                 }
3003                 */
3004
3005                 packet_ref((struct packet *)packet);
3006                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
3007         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3008                 struct script_info *script;
3009                 Evas *e;
3010
3011                 script = instance_lb_script(inst);
3012                 if (!script) {
3013                         ret = -EFAULT;
3014                         goto out;
3015                 }
3016
3017                 e = script_handler_evas(script);
3018                 if (!e) {
3019                         ret = -EFAULT;
3020                         goto out;
3021                 }
3022
3023                 script_handler_update_pointer(script, x, y, -1);
3024
3025                 /*!
3026                  * \TODO: Feed up this KEY_DOWN event
3027                  */
3028                 ret = 0;
3029         } else {
3030                 ErrPrint("Unsupported package\n");
3031                 ret = -EINVAL;
3032         }
3033
3034 out:
3035         /*! \note No reply packet */
3036         return NULL;
3037 }
3038
3039 static struct packet *client_lb_key_up(pid_t pid, int handle, const struct packet *packet)
3040 {
3041         struct client_node *client;
3042         const char *pkgname;
3043         const char *id;
3044         int ret;
3045         int w;
3046         int h;
3047         double timestamp;
3048         double x;
3049         double y;
3050         struct inst_info *inst;
3051         const struct pkg_info *pkg;
3052
3053         client = client_find_by_pid(pid);
3054         if (!client) {
3055                 ErrPrint("Client %d is not exists\n", pid);
3056                 ret = -ENOENT;
3057                 goto out;
3058         }
3059
3060         ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, &timestamp, &x, &y);
3061         if (ret != 7) {
3062                 ErrPrint("Parameter is not matched\n");
3063                 ret = -EINVAL;
3064                 goto out;
3065         }
3066
3067         /*!
3068          * \NOTE:
3069          * Trust the package name which are sent by the client.
3070          * The package has to be a livebox package name.
3071          */
3072         inst = package_find_instance_by_id(pkgname, id);
3073         if (!inst) {
3074                 ErrPrint("Instance[%s] is not exists\n", id);
3075                 ret = -ENOENT;
3076                 goto out;
3077         }
3078
3079         pkg = instance_package(inst);
3080         if (!pkg) {
3081                 ErrPrint("Package[%s] info is not exists\n", pkgname);
3082                 ret = -EFAULT;
3083                 goto out;
3084         }
3085
3086         if (package_is_fault(pkg)) {
3087                 /*!
3088                  * \note
3089                  * If the package is registered as fault module,
3090                  * slave has not load it, so we don't need to do anything at here!
3091                  */
3092                 DbgPrint("Package[%s] is faulted\n", pkgname);
3093                 ret = -EFAULT;
3094         } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3095                 struct buffer_info *buffer;
3096                 struct slave_node *slave;
3097                 //struct packet *packet;
3098
3099                 buffer = instance_lb_buffer(inst);
3100                 if (!buffer) {
3101                         ErrPrint("Instance[%s] has no buffer\n", id);
3102                         ret = -EFAULT;
3103                         goto out;
3104                 }
3105
3106                 slave = package_slave(pkg);
3107                 if (!slave) {
3108                         ErrPrint("Package[%s] has no slave\n", pkgname);
3109                         ret = -EINVAL;
3110                         goto out;
3111                 }
3112
3113                 /*
3114                 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
3115                 if (!packet) {
3116                         ErrPrint("Failed to create a packet[%s]\n", pkgname);
3117                         ret = -EFAULT;
3118                         goto out;
3119                 }
3120                 */
3121
3122                 packet_ref((struct packet *)packet);
3123                 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
3124         } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3125                 struct script_info *script;
3126                 Evas *e;
3127
3128                 script = instance_lb_script(inst);
3129                 if (!script) {
3130                         ret = -EFAULT;
3131                         goto out;
3132                 }
3133
3134                 e = script_handler_evas(script);
3135                 if (!e) {
3136                         ret = -EFAULT;
3137                         goto out;
3138                 }
3139
3140                 script_handler_update_pointer(script, x, y, -1);
3141
3142                 /*!
3143                  * \TODO: Feed up this KEY_UP event
3144                  */
3145                 ret = 0;
3146         } else {
3147                 ErrPrint("Unsupported package\n");
3148                 ret = -EINVAL;
3149         }
3150
3151 out:
3152         /*! \note No reply packet */
3153         return NULL;
3154 }
3155
3156 static int release_pixmap_cb(struct client_node *client, void *canvas)
3157 {
3158         DbgPrint("Forcely unref the \"buffer\"\n");
3159         buffer_handler_pixmap_unref(canvas);
3160         return -1; /* Delete this callback */
3161 }
3162
3163 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 */
3164 {
3165         struct packet *result;
3166         const char *pkgname;
3167         const char *id;
3168         struct client_node *client;
3169         struct inst_info *inst;
3170         int ret;
3171         int pixmap = 0;
3172         void *buf_ptr;
3173
3174         client = client_find_by_pid(pid);
3175         if (!client) {
3176                 ErrPrint("Client %d is not exists\n", pid);
3177                 goto out;
3178         }
3179
3180         ret = packet_get(packet, "ss", &pkgname, &id);
3181         if (ret != 2) {
3182                 ErrPrint("Parameter is not matched\n");
3183                 goto out;
3184         }
3185
3186         /*!
3187          * \NOTE:
3188          * Trust the package name which are sent by the client.
3189          * The package has to be a livebox package name.
3190          */
3191         inst = package_find_instance_by_id(pkgname, id);
3192         if (!inst) {
3193                 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
3194                 goto out;
3195         }
3196
3197         DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
3198
3199         buf_ptr = buffer_handler_pixmap_ref(instance_lb_buffer(inst));
3200         if (!buf_ptr) {
3201                 ErrPrint("Failed to ref pixmap\n");
3202                 goto out;
3203         }
3204
3205         ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
3206         if (ret < 0) {
3207                 ErrPrint("Failed to add a new client deactivate callback\n");
3208                 buffer_handler_pixmap_unref(buf_ptr);
3209                 pixmap = 0;
3210         } else {
3211                 pixmap = buffer_handler_pixmap(instance_lb_buffer(inst));
3212         }
3213
3214 out:
3215         result = packet_create_reply(packet, "i", pixmap);
3216         if (!result)
3217                 ErrPrint("Failed to create a reply packet\n");
3218
3219         return result;
3220 }
3221
3222 static struct packet *client_lb_release_pixmap(pid_t pid, int handle, const struct packet *packet)
3223 {
3224         const char *pkgname;
3225         const char *id;
3226         struct client_node *client;
3227         struct inst_info *inst;
3228         int pixmap;
3229         void *buf_ptr;
3230         int ret;
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, "ssi", &pkgname, &id, &pixmap);
3239         if (ret != 3) {
3240                 ErrPrint("Parameter is not matched\n");
3241                 goto out;
3242         }
3243         DbgPrint("pid[%d] pkgname[%s] id[%s] Pixmap[0x%X]\n", pid, pkgname, id, pixmap);
3244
3245         /*!
3246          * \NOTE:
3247          * Trust the package name which are sent by the client.
3248          * The package has to be a livebox package name.
3249          */
3250         inst = package_find_instance_by_id(pkgname, id);
3251         if (!inst) {
3252                 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
3253                 goto out;
3254         }
3255
3256         buf_ptr = buffer_handler_pixmap_find(pixmap);
3257         if (!buf_ptr) {
3258                 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
3259                 goto out;
3260         }
3261
3262         if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0)
3263                 buffer_handler_pixmap_unref(buf_ptr);
3264
3265 out:
3266         /*! \note No reply packet */
3267         return NULL;
3268 }
3269
3270 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 */
3271 {
3272         struct packet *result;
3273         const char *pkgname;
3274         const char *id;
3275         struct client_node *client;
3276         struct inst_info *inst;
3277         int ret;
3278         int pixmap = 0;
3279         void *buf_ptr;
3280
3281         client = client_find_by_pid(pid);
3282         if (!client) {
3283                 ErrPrint("Client %d is not exists\n", pid);
3284                 goto out;
3285         }
3286
3287         ret = packet_get(packet, "ss", &pkgname, &id);
3288         if (ret != 2) {
3289                 ErrPrint("Parameter is not matched\n");
3290                 goto out;
3291         }
3292
3293         /*!
3294          * \NOTE:
3295          * Trust the package name which are sent by the client.
3296          * The package has to be a livebox package name.
3297          */
3298         inst = package_find_instance_by_id(pkgname, id);
3299         if (!inst) {
3300                 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
3301                 goto out;
3302         }
3303
3304         DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
3305
3306         buf_ptr = buffer_handler_pixmap_ref(instance_pd_buffer(inst));
3307         if (!buf_ptr) {
3308                 ErrPrint("Failed to ref pixmap\n");
3309                 goto out;
3310         }
3311
3312         ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
3313         if (ret < 0)
3314                 buffer_handler_pixmap_unref(buf_ptr);
3315
3316         pixmap = buffer_handler_pixmap(instance_pd_buffer(inst));
3317 out:
3318         result = packet_create_reply(packet, "i", pixmap);
3319         if (!result)
3320                 ErrPrint("Failed to create a reply packet\n");
3321
3322         return result;
3323 }
3324
3325 static struct packet *client_pd_release_pixmap(pid_t pid, int handle, const struct packet *packet)
3326 {
3327         const char *pkgname;
3328         const char *id;
3329         struct client_node *client;
3330         struct inst_info *inst;
3331         int pixmap;
3332         void *buf_ptr;
3333         int ret;
3334
3335         client = client_find_by_pid(pid);
3336         if (!client) {
3337                 ErrPrint("Client %d is not exists\n", pid);
3338                 goto out;
3339         }
3340
3341         ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
3342         if (ret != 3) {
3343                 ErrPrint("Parameter is not matched\n");
3344                 goto out;
3345         }
3346         DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
3347
3348         /*!
3349          * \NOTE:
3350          * Trust the package name which are sent by the client.
3351          * The package has to be a livebox package name.
3352          */
3353         inst = package_find_instance_by_id(pkgname, id);
3354         if (!inst) {
3355                 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
3356                 goto out;
3357         }
3358
3359         buf_ptr = buffer_handler_pixmap_find(pixmap);
3360         if (!buf_ptr) {
3361                 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
3362                 goto out;
3363         }
3364
3365         if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0)
3366                 buffer_handler_pixmap_unref(buf_ptr);
3367
3368 out:
3369         /*! \note No reply packet */
3370         return NULL;
3371 }
3372
3373 static struct packet *client_pinup_changed(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, pinup, ret */
3374 {
3375         struct client_node *client;
3376         struct packet *result;
3377         const char *pkgname;
3378         const char *id;
3379         int pinup;
3380         int ret;
3381         struct inst_info *inst;
3382
3383         client = client_find_by_pid(pid);
3384         if (!client) {
3385                 ErrPrint("Client %d is not exists\n", pid);
3386                 ret = -ENOENT;
3387                 pinup = 0;
3388                 goto out;
3389         }
3390
3391         ret = packet_get(packet, "ssi", &pkgname, &id, &pinup);
3392         if (ret != 3) {
3393                 ErrPrint("Parameter is not matched\n");
3394                 ret = -EINVAL;
3395                 pinup = 0;
3396                 goto out;
3397         }
3398
3399         DbgPrint("pid[%d] pkgname[%s] id[%s] pinup[%d]\n", pid, pkgname, id, pinup);
3400
3401         /*!
3402          * \NOTE:
3403          * Trust the package name which are sent by the client.
3404          * The package has to be a livebox package name.
3405          */
3406         inst = package_find_instance_by_id(pkgname, id);
3407         if (!inst)
3408                 ret = -ENOENT;
3409         else if (package_is_fault(instance_package(inst)))
3410                 ret = -EFAULT;
3411         else
3412                 ret = instance_set_pinup(inst, pinup);
3413
3414 out:
3415         result = packet_create_reply(packet, "i", ret);
3416         if (!result)
3417                 ErrPrint("Failed to create a packet\n");
3418
3419         return result;
3420 }
3421
3422 static Eina_Bool lazy_pd_created_cb(void *data)
3423 {
3424         DbgPrint("Send PD Create event\n");
3425         instance_client_pd_created(data, 0);
3426
3427         instance_unref(data);
3428         return ECORE_CALLBACK_CANCEL;
3429 }
3430
3431 static Eina_Bool lazy_pd_destroyed_cb(void *data)
3432 {
3433         DbgPrint("Send PD Destroy event\n");
3434         instance_client_pd_destroyed(data, 0);
3435
3436         instance_unref(data);
3437         return ECORE_CALLBACK_CANCEL;
3438 }
3439
3440 static struct packet *client_create_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
3441 {
3442         struct client_node *client;
3443         struct packet *result;
3444         const char *pkgname;
3445         const char *id;
3446         int ret;
3447         struct inst_info *inst;
3448         double x;
3449         double y;
3450
3451         client = client_find_by_pid(pid);
3452         if (!client) {
3453                 ErrPrint("Client %d is not exists\n", pid);
3454                 ret = -ENOENT;
3455                 goto out;
3456         }
3457
3458         ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
3459         if (ret != 4) {
3460                 ErrPrint("Parameter is not matched\n");
3461                 ret = -EINVAL;
3462                 goto out;
3463         }
3464
3465         DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
3466
3467         /*!
3468          * \NOTE:
3469          * Trust the package name which are sent by the client.
3470          * The package has to be a livebox package name.
3471          */
3472         inst = package_find_instance_by_id(pkgname, id);
3473         if (!inst)
3474                 ret = -ENOENT;
3475         else if (package_is_fault(instance_package(inst)))
3476                 ret = -EFAULT;
3477         else if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE)
3478                 ret = -ENOSPC;
3479         else if (package_pd_type(instance_package(inst)) == PD_TYPE_BUFFER) {
3480                 instance_slave_set_pd_pos(inst, x, y);
3481                 ret = instance_slave_open_pd(inst, client);
3482                 ret = instance_signal_emit(inst,
3483                                 "pd,show", util_uri_to_path(instance_id(inst)),
3484                                 0.0, 0.0, 0.0, 0.0, x, y, 0);
3485                 /*!
3486                  * \note
3487                  * PD craeted event will be send by the acquire_buffer function.
3488                  * Because the slave will make request the acquire_buffer to
3489                  * render the PD
3490                  *
3491                  * instance_client_pd_created(inst);
3492                  */
3493         } else if (package_pd_type(instance_package(inst)) == PD_TYPE_SCRIPT) {
3494                 /*!
3495                  * \note
3496                  * ret value should be cared but in this case,
3497                  * we ignore this for this moment, so we have to handle this error later.
3498                  *
3499                  * if ret is less than 0, the slave has some problem.
3500                  * but the script mode doesn't need slave for rendering default view of PD
3501                  * so we can hanle it later.
3502                  */
3503                 instance_slave_set_pd_pos(inst, x, y);
3504                 ret = instance_slave_open_pd(inst, client);
3505                 script_handler_update_pointer(instance_pd_script(inst), x, y, 0);
3506                 ret = script_handler_load(instance_pd_script(inst), 1);
3507
3508                 /*!
3509                  * \note
3510                  * Send the PD created event to the clients,
3511                  */
3512                 if (ret == 0) {
3513                         /*!
3514                          * \note
3515                          * But the created event has to be send afte return
3516                          * from this function or the viewer couldn't care
3517                          * the event correctly.
3518                          */
3519                         inst = instance_ref(inst); /* To guarantee the inst */
3520                         if (!ecore_timer_add(DELAY_TIME, lazy_pd_created_cb, inst))
3521                                 instance_unref(inst);
3522                 }
3523         } else {
3524                 ErrPrint("Invalid PD TYPE\n");
3525                 ret = -EINVAL;
3526         }
3527
3528 out:
3529         result = packet_create_reply(packet, "i", ret);
3530         if (!result)
3531                 ErrPrint("Failed to create a packet\n");
3532
3533         return result;
3534 }
3535
3536 static struct packet *client_destroy_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
3537 {
3538         struct client_node *client;
3539         struct packet *result;
3540         const char *pkgname;
3541         const char *id;
3542         int ret;
3543         struct inst_info *inst;
3544
3545         client = client_find_by_pid(pid);
3546         if (!client) {
3547                 ErrPrint("Client %d is not exists\n", pid);
3548                 ret = -ENOENT;
3549                 goto out;
3550         }
3551
3552         ret = packet_get(packet, "ss", &pkgname, &id);
3553         if (ret != 2) {
3554                 ErrPrint("Parameter is not matched\n");
3555                 ret = -EINVAL;
3556                 goto out;
3557         }
3558
3559         DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
3560
3561         /*!
3562          * \NOTE:
3563          * Trust the package name which are sent by the client.
3564          * The package has to be a livebox package name.
3565          */
3566         inst = package_find_instance_by_id(pkgname, id);
3567         if (!inst)
3568                 ret = -ENOENT;
3569         else if (package_is_fault(instance_package(inst)))
3570                 ret = -EFAULT;
3571         else if (package_pd_type(instance_package(inst)) == PD_TYPE_BUFFER) {
3572                 ret = instance_signal_emit(inst,
3573                                 "pd,hide", util_uri_to_path(instance_id(inst)),
3574                                 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
3575                 ret = instance_slave_close_pd(inst, client);
3576
3577                 /*!
3578                  * \note
3579                  * release_buffer will be called by the slave after this.
3580                  * Then it will send the "pd_destroyed" event to the client
3581                  *
3582                  * instance_client_pd_destroyed(inst);
3583                  */
3584
3585         } else if (package_pd_type(instance_package(inst)) == PD_TYPE_SCRIPT) {
3586                 ret = instance_slave_close_pd(inst, client);
3587
3588                 ret = script_handler_unload(instance_pd_script(inst), 1);
3589
3590                 /*!
3591                  * \note
3592                  * Send the destroyed PD event to the client
3593                  */
3594                 if (ret == 0) {
3595                         inst = instance_ref(inst);
3596                         if (!ecore_timer_add(DELAY_TIME, lazy_pd_destroyed_cb, inst))
3597                                 instance_unref(inst);
3598                 }
3599         } else {
3600                 ErrPrint("Invalid PD TYPE\n");
3601                 ret = -EINVAL;
3602         }
3603
3604 out:
3605         result = packet_create_reply(packet, "i", ret);
3606         if (!result)
3607                 ErrPrint("Failed to create a packet\n");
3608
3609         return result;
3610 }
3611
3612 static struct packet *client_activate_package(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, ret */
3613 {
3614         struct client_node *client;
3615         struct packet *result;
3616         const char *pkgname;
3617         int ret;
3618         struct pkg_info *info;
3619
3620         client = client_find_by_pid(pid);
3621         if (!client) {
3622                 ErrPrint("Client %d is not exists\n", pid);
3623                 ret = -ENOENT;
3624                 pkgname = "";
3625                 goto out;
3626         }
3627
3628         ret = packet_get(packet, "s", &pkgname);
3629         if (ret != 1) {
3630                 ErrPrint("Parameter is not matched\n");
3631                 ret = -EINVAL;
3632                 pkgname = "";
3633                 goto out;
3634         }
3635
3636         DbgPrint("pid[%d] pkgname[%s]\n", pid, pkgname);
3637
3638         /*!
3639          * \NOTE:
3640          * Validate the livebox package name.
3641          */
3642         if (!package_is_lb_pkgname(pkgname)) {
3643                 ErrPrint("%s is not a valid livebox package\n", pkgname);
3644                 pkgname = "";
3645                 ret = -EINVAL;
3646                 goto out;
3647         }
3648
3649         info = package_find(pkgname);
3650         if (!info)
3651                 ret = -ENOENT;
3652         else
3653                 ret = package_clear_fault(info);
3654
3655 out:
3656         result = packet_create_reply(packet, "is", ret, pkgname);
3657         if (!result)
3658                 ErrPrint("Failed to create a packet\n");
3659
3660         return result;
3661 }
3662
3663 static struct packet *client_subscribed(pid_t pid, int handle, const struct packet *packet)
3664 {
3665         const char *cluster;
3666         const char *category;
3667         struct client_node *client;
3668         int ret;
3669
3670         client = client_find_by_pid(pid);
3671         if (!client) {
3672                 ErrPrint("Client %d is not exists\n", pid);
3673                 ret = -ENOENT;
3674                 goto out;
3675         }
3676
3677         ret = packet_get(packet, "ss", &cluster, &category);
3678         if (ret != 2) {
3679                 ErrPrint("Invalid argument\n");
3680                 ret = -EINVAL;
3681                 goto out;
3682         }
3683
3684         DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
3685         if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
3686                 ErrPrint("Invalid cluster name\n");
3687                 goto out;
3688         }
3689
3690         /*!
3691          * \todo
3692          * SUBSCRIBE cluster & sub-cluster for a client.
3693          */
3694         ret = client_subscribe(client, cluster, category);
3695         if (ret == 0)
3696                 package_alter_instances_to_client(client, ALTER_CREATE);
3697
3698 out:
3699         /*! \note No reply packet */
3700         return NULL;
3701 }
3702
3703 static struct packet *client_delete_cluster(pid_t pid, int handle, const struct packet *packet)
3704 {
3705         const char *cluster;
3706         struct client_node *client;
3707         struct packet *result;
3708         int ret;
3709
3710         client = client_find_by_pid(pid);
3711         if (!client) {
3712                 ErrPrint("Client %d is not exists\n", pid);
3713                 ret = -ENOENT;
3714                 goto out;
3715         }
3716
3717         ret = packet_get(packet, "s", &cluster);
3718         if (ret != 1) {
3719                 ErrPrint("Invalid parameters\n");
3720                 ret = -EINVAL;
3721                 goto out;
3722         }
3723
3724         DbgPrint("pid[%d] cluster[%s]\n", pid, cluster);
3725
3726         if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
3727                 ErrPrint("Invalid cluster: %s\n", cluster);
3728                 ret = -EINVAL;
3729                 goto out;
3730         }
3731
3732         /*!
3733          * \todo
3734          */
3735         ret = -ENOSYS;
3736
3737 out:
3738         result = packet_create_reply(packet, "i", ret);
3739         if (!result)
3740                 ErrPrint("Failed to create a packet\n");
3741         return result;
3742 }
3743
3744 static inline int update_pkg_cb(struct category *category, const char *pkgname)
3745 {
3746         const char *c_name;
3747         const char *s_name;
3748
3749         c_name = group_cluster_name_by_category(category);
3750         s_name = group_category_name(category);
3751
3752         if (!c_name || !s_name || !pkgname) {
3753                 ErrPrint("Name is not valid\n");
3754                 return EXIT_FAILURE;
3755         }
3756
3757         DbgPrint("Send refresh request: %s (%s/%s)\n", pkgname, c_name, s_name);
3758         slave_rpc_request_update(pkgname, "", c_name, s_name);
3759
3760         /* Just try to create a new package */
3761         if (util_free_space(IMAGE_PATH) > MINIMUM_SPACE) {
3762                 double timestamp;
3763                 struct inst_info *inst;
3764
3765                 timestamp = util_timestamp();
3766                 /*!
3767                  * \NOTE
3768                  * Don't need to check the subscribed clients.
3769                  * Because this callback is called by the requests of clients.
3770                  * It means. some clients wants to handle this instances ;)
3771                  */
3772                 inst = instance_create(NULL, timestamp, pkgname, DEFAULT_CONTENT, c_name, s_name, DEFAULT_PERIOD, 0, 0);
3773                 if (!inst)
3774                         ErrPrint("Failed to create a new instance\n");
3775         } else {
3776                 ErrPrint("Not enough space\n");
3777         }
3778         return EXIT_SUCCESS;
3779 }
3780
3781 static struct packet *client_refresh_group(pid_t pid, int handle, const struct packet *packet)
3782 {
3783         const char *cluster_id;
3784         const char *category_id;
3785         struct client_node *client;
3786         int ret;
3787         struct cluster *cluster;
3788         struct category *category;
3789         struct context_info *info;
3790         Eina_List *info_list;
3791         Eina_List *l;
3792
3793         client = client_find_by_pid(pid);
3794         if (!client) {
3795                 ErrPrint("Cilent %d is not exists\n", pid);
3796                 ret = -ENOMEM;
3797                 goto out;
3798         }
3799
3800         ret = packet_get(packet, "ss", &cluster_id, &category_id);
3801         if (ret != 2) {
3802                 ErrPrint("Invalid parameter\n");
3803                 ret = -EINVAL;
3804                 goto out;
3805         }
3806
3807         DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster_id, category_id);
3808
3809         if (!strlen(cluster_id) || !strcasecmp(cluster_id, DEFAULT_CLUSTER)) {
3810                 ErrPrint("Invalid cluster name: %s\n", cluster_id);
3811                 ret = -EINVAL;
3812                 goto out;
3813         }
3814
3815         cluster = group_find_cluster(cluster_id);
3816         if (!cluster) {
3817                 ErrPrint("Cluster [%s] is not registered\n", cluster_id);
3818                 ret = -EINVAL;
3819                 goto out;
3820         }
3821
3822         category = group_find_category(cluster, category_id);
3823         if (!category) {
3824                 ErrPrint("Category [%s] is not registered\n", category_id);
3825                 ret = -EINVAL;
3826                 goto out;
3827         }
3828
3829         info_list = group_context_info_list(category);
3830         EINA_LIST_FOREACH(info_list, l, info) {
3831                 update_pkg_cb(category, group_pkgname_from_context_info(info));
3832         }
3833
3834 out:
3835         /*! \note No reply packet */
3836         return NULL;
3837 }
3838
3839 static struct packet *client_delete_category(pid_t pid, int handle, const struct packet *packet)
3840 {
3841         const char *cluster;
3842         const char *category;
3843         struct client_node *client;
3844         struct packet *result;
3845         int ret;
3846
3847         client = client_find_by_pid(pid);
3848         if (!client) {
3849                 ErrPrint("Client %d is not exists\n", pid);
3850                 ret = -ENOENT;
3851                 goto out;
3852         }
3853
3854         ret = packet_get(packet, "ss", &cluster, &category);
3855         if (ret != 2) {
3856                 ErrPrint("Invalid paramenters\n");
3857                 ret = -EINVAL;
3858                 goto out;
3859         }
3860
3861         DbgPrint("pid[%d] cluster[%s] category[%s]\n", pid, cluster, category);
3862         if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
3863                 ErrPrint("Invalid cluster: %s\n", cluster);
3864                 ret = -EINVAL;
3865                 goto out;
3866         }
3867
3868         /*!
3869          * \todo
3870          */
3871         ret = -ENOSYS;
3872
3873 out:
3874         result = packet_create_reply(packet, "i", ret);
3875         if (!result)
3876                 ErrPrint("Failed to create a packet\n");
3877         return result;
3878 }
3879
3880 static struct packet *client_unsubscribed(pid_t pid, int handle, const struct packet *packet)
3881 {
3882         const char *cluster;
3883         const char *category;
3884         struct client_node *client;
3885         int ret;
3886
3887         client = client_find_by_pid(pid);
3888         if (!client) {
3889                 ErrPrint("Client %d is not exists\n", pid);
3890                 ret = -ENOENT;
3891                 goto out;
3892         }
3893
3894         ret = packet_get(packet, "ss", &cluster, &category);
3895         if (ret != 2) {
3896                 ErrPrint("Invalid argument\n");
3897                 ret = -EINVAL;
3898                 goto out;
3899         }
3900
3901         DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
3902
3903         if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
3904                 ErrPrint("Invalid cluster name: %s\n", cluster);
3905                 goto out;
3906         }
3907
3908         /*!
3909          * \todo
3910          * UNSUBSCRIBE cluster & sub-cluster for a client.
3911          */
3912         ret = client_unsubscribe(client, cluster, category);
3913         if (ret == 0)
3914                 package_alter_instances_to_client(client, ALTER_DESTROY);
3915
3916 out:
3917         /*! \note No reply packet */
3918         return NULL;
3919 }
3920
3921 static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
3922 {
3923         struct slave_node *slave;
3924         const char *slavename;
3925         int ret;
3926
3927         ret = packet_get(packet, "s", &slavename);
3928         if (ret != 1) {
3929                 ErrPrint("Parameter is not matched\n");
3930                 ret = -EINVAL;
3931                 goto out;
3932         }
3933
3934         DbgPrint("New slave[%s](%d) is arrived\n", slavename, pid);
3935
3936         slave = slave_find_by_pid(pid);
3937         if (!slave) {
3938                 if (DEBUG_MODE) {
3939                         char pkgname[pathconf("/", _PC_PATH_MAX)];
3940                         const char *abi;
3941
3942                         if (aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)) != AUL_R_OK) {
3943                                 ErrPrint("pid[%d] is not authroized provider package, try to find it using its name[%s]\n", pid, slavename);
3944                                 slave = slave_find_by_name(slavename);
3945                                 pkgname[0] = '\0'; /* Reset the pkgname */
3946                         } else {
3947                                 slave = slave_find_by_pkgname(pkgname);
3948                         }
3949
3950                         if (!slave) {
3951                                 abi = abi_find_by_pkgname(pkgname);
3952                                 if (!abi) {
3953                                         abi = DEFAULT_ABI;
3954                                         DbgPrint("Slave pkgname is invalid, ABI is replaced with '%s'(default)\n", abi);
3955                                 }
3956
3957                                 slave = slave_create(slavename, 1, abi, pkgname);
3958                                 if (!slave) {
3959                                         ErrPrint("Failed to create a new slave for %s\n", slavename);
3960                                         ret = -EFAULT;
3961                                         goto out;
3962                                 }
3963
3964                                 DbgPrint("New slave is created\n");
3965                         } else {
3966                                 DbgPrint("Registered slave is replaced with this new one\n");
3967                                 abi = slave_abi(slave);
3968                         }
3969
3970                         slave_set_pid(slave, pid);
3971                         DbgPrint("Provider is forcely activated, pkgname(%s), abi(%s), slavename(%s)\n", pkgname, abi, slavename);
3972                 } else {
3973                         ErrPrint("Slave[%d] is not exists\n", pid);
3974                         ret = -ENOENT;
3975                         goto out;
3976                 }
3977         }
3978
3979         /*!
3980          * \note
3981          * After updating handle,
3982          * slave activated callback will be called.
3983          */
3984         slave_rpc_update_handle(slave, handle);
3985
3986 out:
3987         return NULL;
3988 }
3989
3990 static struct packet *slave_ping(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
3991 {
3992         struct slave_node *slave;
3993         const char *slavename;
3994         int ret;
3995
3996         slave = slave_find_by_pid(pid);
3997         if (!slave) {
3998                 ErrPrint("Slave %d is not exists\n", pid);
3999                 ret = -ENOENT;
4000                 goto out;
4001         }
4002
4003         ret = packet_get(packet, "s", &slavename);
4004         if (ret != 1) {
4005                 ErrPrint("Parameter is not matched\n");
4006                 ret = -EINVAL;
4007                 goto out;
4008         }
4009
4010         slave_rpc_ping(slave);
4011
4012 out:
4013         return NULL;
4014 }
4015
4016 static struct packet *slave_faulted(pid_t pid, int handle, const struct packet *packet)
4017 {
4018         struct slave_node *slave;
4019         struct inst_info *inst;
4020         const char *slavename;
4021         const char *pkgname;
4022         const char *id;
4023         const char *func;
4024         int ret;
4025
4026         slave = slave_find_by_pid(pid);
4027         if (!slave) {
4028                 ErrPrint("Slave %d is not exists\n", pid);
4029                 ret = -ENOENT;
4030                 goto out;
4031         }
4032
4033         ret = packet_get(packet, "ssss", &slavename, &pkgname, &id, &func);
4034         if (ret != 4) {
4035                 ErrPrint("Parameter is not matched\n");
4036                 ret = -EINVAL;
4037                 goto out;
4038         }
4039
4040         ret = fault_info_set(slave, pkgname, id, func);
4041         DbgPrint("Slave Faulted: %s (%d)\n", slavename, ret);
4042
4043         inst = package_find_instance_by_id(pkgname, id);
4044         if (!inst) {
4045                 DbgPrint("There is no such instance: %s\n", id);
4046                 ret = -ENOENT;
4047         } else if (instance_state(inst) == INST_DESTROYED) {
4048                 ErrPrint("Instance is already destroyed (%s)\n", id);
4049                 ret = -EINVAL;
4050         } else {
4051                 DbgPrint("Destroy instance (%s)\n", id);
4052                 ret = instance_destroy(inst);
4053         }
4054
4055 out:
4056         return NULL;
4057 }
4058
4059 static struct packet *slave_call(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
4060 {
4061         struct slave_node *slave;
4062         const char *slavename;
4063         const char *pkgname;
4064         const char *id;
4065         const char *func;
4066         int ret;
4067
4068         slave = slave_find_by_pid(pid);
4069         if (!slave) {
4070                 ErrPrint("Slave %d is not exists\n", pid);
4071                 ret = -ENOENT;
4072                 goto out;
4073         }
4074
4075         ret = packet_get(packet, "ssss", &slavename, &pkgname, &id, &func);
4076         if (ret != 4) {
4077                 ErrPrint("Parameter is not matched\n");
4078                 ret = -EINVAL;
4079                 goto out;
4080         }
4081
4082         ret = fault_func_call(slave, pkgname, id, func);
4083         slave_give_more_ttl(slave);
4084
4085 out:
4086         return NULL;
4087 }
4088
4089 static struct packet *slave_ret(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
4090 {
4091         struct slave_node *slave;
4092         const char *slavename;
4093         const char *pkgname;
4094         const char *id;
4095         const char *func;
4096         int ret;
4097
4098         slave = slave_find_by_pid(pid);
4099         if (!slave) {
4100                 ErrPrint("Slave %d is not exists\n", pid);
4101                 ret = -ENOENT;
4102                 goto out;
4103         }
4104
4105         ret = packet_get(packet, "ssss", &slavename, &pkgname, &id, &func);
4106         if (ret != 4) {
4107                 ErrPrint("Parameter is not matched\n");
4108                 ret = -EINVAL;
4109                 goto out;
4110         }
4111
4112         ret = fault_func_ret(slave, pkgname, id, func);
4113         slave_give_more_ttl(slave);
4114
4115 out:
4116         return NULL;
4117 }
4118
4119 static struct packet *slave_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, width, height, priority, ret */
4120 {
4121         struct slave_node *slave;
4122         const char *slavename;
4123         const char *pkgname;
4124         const char *id;
4125         const char *content_info;
4126         const char *title;
4127         int w;
4128         int h;
4129         double priority;
4130         int ret;
4131         struct inst_info *inst;
4132
4133         slave = slave_find_by_pid(pid);
4134         if (!slave) {
4135                 ErrPrint("Slave %d is not exists\n", pid);
4136                 ret = -ENOENT;
4137                 goto out;
4138         }
4139
4140         ret = packet_get(packet, "sssiidss", &slavename, &pkgname, &id,
4141                                                 &w, &h, &priority,
4142                                                 &content_info, &title);
4143         if (ret != 8) {
4144                 ErrPrint("Parameter is not matched\n");
4145                 ret = -EINVAL;
4146                 goto out;
4147         }
4148
4149         inst = package_find_instance_by_id(pkgname, id);
4150         if (!inst) {
4151                 ret = -ENOENT;
4152         } else if (package_is_fault(instance_package(inst))) {
4153                 ErrPrint("Faulted instance cannot make any event.\n");
4154                 ret = -EFAULT;
4155         } else if (instance_state(inst) == INST_DESTROYED) {
4156                 ErrPrint("Instance is already destroyed\n");
4157                 ret = -EINVAL;
4158         } else {
4159                 char *filename;
4160
4161                 instance_set_lb_info(inst, w, h, priority, content_info, title);
4162
4163                 switch (package_lb_type(instance_package(inst))) {
4164                 case LB_TYPE_SCRIPT:
4165                         script_handler_resize(instance_lb_script(inst), w, h);
4166
4167                         filename = util_get_file_kept_in_safe(id);
4168                         if (filename) {
4169                                 ret = script_handler_parse_desc(pkgname, id,
4170                                                                 filename, 0);
4171                                 DbgFree(filename);
4172                         } else {
4173                                 ret = script_handler_parse_desc(pkgname, id,
4174                                                         util_uri_to_path(id), 0);
4175                         }
4176                         break;
4177                 case LB_TYPE_BUFFER:
4178                         instance_lb_updated_by_instance(inst);
4179                         ret = 0;
4180                         break;
4181                 default:
4182                         /*!
4183                          * \check
4184                          * text format (inst)
4185                          */
4186                         instance_lb_updated_by_instance(inst);
4187                         ret = 0;
4188                         break;
4189                 }
4190
4191                 slave_give_more_ttl(slave);
4192         }
4193
4194 out:
4195         return NULL;
4196 }
4197
4198 static struct packet *slave_desc_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, decsfile, ret */
4199 {
4200         struct slave_node *slave;
4201         const char *slavename;
4202         const char *pkgname;
4203         const char *id;
4204         const char *descfile;
4205         int ret;
4206         struct inst_info *inst;
4207
4208         slave = slave_find_by_pid(pid);
4209         if (!slave) {
4210                 ErrPrint("Slave %d is not exists\n", pid);
4211                 ret = -ENOENT;
4212                 goto out;
4213         }
4214
4215         ret = packet_get(packet, "ssss", &slavename, &pkgname, &id, &descfile);
4216         if (ret != 4) {
4217                 ErrPrint("Parameter is not matched\n");
4218                 ret = -EINVAL;
4219                 goto out;
4220         }
4221
4222         inst = package_find_instance_by_id(pkgname, id);
4223         if (!inst) {
4224                 ret = -ENOENT;
4225         } else if (package_is_fault(instance_package(inst))) {
4226                 ErrPrint("Faulted package cannot make event\n");
4227                 ret = -EFAULT;
4228         } else if (instance_state(inst) == INST_DESTROYED) {
4229                 ErrPrint("Instance is already destroyed\n");
4230                 ret = -EINVAL;
4231         } else {
4232                 switch (package_pd_type(instance_package(inst))) {
4233                 case PD_TYPE_SCRIPT:
4234                         DbgPrint("Script (%s)\n", id);
4235                         if (script_handler_is_loaded(instance_pd_script(inst))) {
4236                                 ret = script_handler_parse_desc(pkgname, id,
4237                                                                 descfile, 1);
4238                         }
4239                         break;
4240                 case PD_TYPE_TEXT:
4241                         instance_set_pd_info(inst, 0, 0);
4242                 case PD_TYPE_BUFFER:
4243                         instance_pd_updated(pkgname, id, descfile);
4244                         ret = 0;
4245                         break;
4246                 default:
4247                         DbgPrint("Ignore updated DESC(%s - %s - %s)\n",
4248                                                         pkgname, id, descfile);
4249                         ret = 0;
4250                         break;
4251                 }
4252         }
4253
4254 out:
4255         return NULL;
4256 }
4257
4258 static struct packet *slave_deleted(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, id, ret */
4259 {
4260         struct slave_node *slave;
4261         const char *slavename;
4262         const char *pkgname;
4263         const char *id;
4264         int ret;
4265         struct inst_info *inst;
4266
4267         slave = slave_find_by_pid(pid);
4268         if (!slave) {
4269                 ErrPrint("Slave %d is not exists\n", pid);
4270                 ret = -ENOENT;
4271                 goto out;
4272         }
4273
4274         ret = packet_get(packet, "sss", &slavename, &pkgname, &id);
4275         if (ret != 3) {
4276                 ErrPrint("Parameter is not matched\n");
4277                 ret = -EINVAL;
4278                 goto out;
4279         }
4280
4281         inst = package_find_instance_by_id(pkgname, id);
4282         if (!inst)
4283                 ret = -ENOENT;
4284         else if (package_is_fault(instance_package(inst)))
4285                 ret = -EFAULT;
4286         else
4287                 ret = instance_destroyed(inst);
4288
4289 out:
4290         return NULL;
4291 }
4292
4293 /*!
4294  * \note for the BUFFER Type slave
4295  */
4296 static struct packet *slave_acquire_buffer(pid_t pid, int handle, const struct packet *packet) /* type, id, w, h, size */
4297 {
4298         enum target_type target;
4299         const char *slavename;
4300         const char *pkgname;
4301         const char *id;
4302         int w;
4303         int h;
4304         int pixel_size;
4305         struct packet *result;
4306         struct slave_node *slave;
4307         struct inst_info *inst;
4308         const struct pkg_info *pkg;
4309         int ret;
4310
4311         slave = slave_find_by_pid(pid);
4312         if (!slave) {
4313                 ErrPrint("Failed to find a slave\n");
4314                 id = "";
4315                 ret = -ENOENT;
4316                 goto out;
4317         }
4318
4319         ret = packet_get(packet, "isssiii", &target, &slavename, &pkgname, &id, &w, &h, &pixel_size);
4320         if (ret != 7) {
4321                 ErrPrint("Invalid argument\n");
4322                 id = "";
4323                 ret = -EINVAL;
4324                 goto out;
4325         }
4326
4327         if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE) {
4328                 DbgPrint("No space\n");
4329                 ret = -ENOSPC;
4330                 id = "";
4331                 goto out;
4332         }
4333
4334         /* TODO: */
4335         inst = package_find_instance_by_id(pkgname, id);
4336         if (!inst) {
4337                 DbgPrint("Package[%s] Id[%s] is not found\n", pkgname, id);
4338                 ret = -EINVAL;
4339                 id = "";
4340                 goto out;
4341         }
4342
4343         pkg = instance_package(inst);
4344         id = "";
4345         ret = -EINVAL;
4346         if (target == TYPE_LB) {
4347                 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4348                         struct buffer_info *info;
4349
4350                         info = instance_lb_buffer(inst);
4351                         if (!info) {
4352                                 if (!instance_create_lb_buffer(inst)) {
4353                                         ErrPrint("Failed to create a LB buffer\n");
4354                                 } else {
4355                                         info = instance_lb_buffer(inst);
4356                                         if (!info) {
4357                                                 ErrPrint("LB buffer is not valid\n");
4358                                                 ret = -EINVAL;
4359                                                 id = "";
4360                                                 goto out;
4361                                         }
4362                                 }
4363                         }
4364
4365                         ret = buffer_handler_resize(info, w, h);
4366                         DbgPrint("Buffer resize returns %d\n", ret);
4367
4368                         ret = buffer_handler_load(info);
4369                         if (ret == 0) {
4370                                 instance_set_lb_info(inst, w, h, -1.0f, NULL, NULL);
4371                                 id = buffer_handler_id(info);
4372                                 DbgPrint("Buffer handler ID: %s\n", id);
4373                         } else {
4374                                 DbgPrint("Failed to load a buffer(%d)\n", ret);
4375                         }
4376                 }
4377         } else if (target == TYPE_PD) {
4378                 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
4379                         struct buffer_info *info;
4380
4381                         DbgPrint("Slave acquire buffer for PD\n");
4382
4383                         info = instance_pd_buffer(inst);
4384                         if (!info) {
4385                                 if (!instance_create_pd_buffer(inst)) {
4386                                         ErrPrint("Failed to create a PD buffer\n");
4387                                 } else {
4388                                         info = instance_pd_buffer(inst);
4389                                         if (!info) {
4390                                                 ErrPrint("PD buffer is not valid\n");
4391                                                 ret = -EINVAL;
4392                                                 id = "";
4393                                                 instance_client_pd_created(inst, ret);
4394                                                 goto out;
4395                                         }
4396                                 }
4397                         }
4398
4399                         ret = buffer_handler_resize(info, w, h);
4400                         DbgPrint("Buffer resize returns %d\n", ret);
4401
4402                         ret = buffer_handler_load(info);
4403                         if (ret == 0) {
4404                                 instance_set_pd_info(inst, w, h);
4405                                 id = buffer_handler_id(info);
4406                                 DbgPrint("Buffer handler ID: %s\n", id);
4407                         } else {
4408                                 DbgPrint("Failed to load a buffer (%d)\n", ret);
4409                         }
4410
4411                         /*!
4412                          * Send the PD created event to the client
4413                          */
4414                         instance_client_pd_created(inst, ret);
4415                 }
4416         }
4417
4418 out:
4419         result = packet_create_reply(packet, "is", ret, id);
4420         if (!result)
4421                 ErrPrint("Failed to create a packet\n");
4422
4423         return result;
4424 }
4425
4426 static struct packet *slave_resize_buffer(pid_t pid, int handle, const struct packet *packet)
4427 {
4428         struct slave_node *slave;
4429         struct packet *result;
4430         enum target_type type;
4431         const char *slavename;
4432         const char *pkgname;
4433         const char *id;
4434         int w;
4435         int h;
4436         struct inst_info *inst;
4437         const struct pkg_info *pkg;
4438         int ret;
4439
4440         slave = slave_find_by_pid(pid);
4441         if (!slave) {
4442                 ErrPrint("Failed to find a slave\n");
4443                 ret = -ENOENT;
4444                 id = "";
4445                 goto out;
4446         }
4447
4448         if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE) {
4449                 ErrPrint("Not enough space\n");
4450                 ret = -ENOSPC;
4451                 id = "";
4452                 goto out;
4453         }
4454
4455         ret = packet_get(packet, "isssii", &type, &slavename, &pkgname, &id, &w, &h);
4456         if (ret != 6) {
4457                 ErrPrint("Invalid argument\n");
4458                 ret = -EINVAL;
4459                 id = "";
4460                 goto out;
4461         }
4462
4463         inst = package_find_instance_by_id(pkgname, id);
4464         if (!inst) {
4465                 DbgPrint("Instance is not found[%s] [%s]\n", pkgname, id);
4466                 ret = -ENOENT;
4467                 id = "";
4468                 goto out;
4469         }
4470
4471         pkg = instance_package(inst);
4472         if (!pkg) {
4473                 /*!
4474                  * \note
4475                  * THIS statement should not be entered.
4476                  */
4477                 ErrPrint("PACKAGE INFORMATION IS NOT VALID\n");
4478                 ret = -EFAULT;
4479                 id = "";
4480                 goto out;
4481         }
4482
4483         ret = -EINVAL;
4484         /*!
4485          * \note
4486          * Reset "id", It will be re-used from here
4487          */
4488         id = "";
4489         if (type == TYPE_LB) {
4490                 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4491                         struct buffer_info *info;
4492
4493                         info = instance_lb_buffer(inst);
4494                         if (info) {
4495                                 ret = buffer_handler_resize(info, w, h);
4496                                 /*!
4497                                  * \note
4498                                  * id is resued for newly assigned ID
4499                                  */
4500                                 if (!ret) {
4501                                         id = buffer_handler_id(info);
4502                                         instance_set_lb_info(inst, w, h, -1.0f, NULL, NULL);
4503                                 }
4504                         }
4505                 }
4506         } else if (type == TYPE_PD) {
4507                 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
4508                         struct buffer_info *info;
4509
4510                         info = instance_pd_buffer(inst);
4511                         if (info) {
4512                                 ret = buffer_handler_resize(info, w, h);
4513                                 /*!
4514                                  * \note
4515                                  * id is resued for newly assigned ID
4516                                  */
4517                                 if (!ret) {
4518                                         id = buffer_handler_id(info);
4519                                         DbgPrint("Set PD Info: %dx%d\n", w, h);
4520                                         instance_set_pd_info(inst, w, h);
4521                                 }
4522                         }
4523                 }
4524         }
4525
4526 out:
4527         result = packet_create_reply(packet, "is", ret, id);
4528         if (!result)
4529                 ErrPrint("Failed to create a packet\n");
4530
4531         return result;
4532 }
4533
4534 static struct packet *slave_release_buffer(pid_t pid, int handle, const struct packet *packet)
4535 {
4536         enum target_type type;
4537         const char *slavename;
4538         const char *pkgname;
4539         const char *id;
4540         struct packet *result;
4541         struct slave_node *slave;
4542         struct inst_info *inst;
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                 goto out;
4550         }
4551
4552         if (packet_get(packet, "isss", &type, &slavename, &pkgname, &id) != 4) {
4553                 ErrPrint("Inavlid argument\n");
4554                 ret = -EINVAL;
4555                 goto out;
4556         }
4557
4558         inst = package_find_instance_by_id(pkgname, id);
4559         if (!inst) {
4560                 ErrPrint("Instance is not found [%s - %s]\n", pkgname, id);
4561                 ret = -ENOENT;
4562                 goto out;
4563         }
4564
4565         ret = -EINVAL;
4566         if (type == TYPE_LB) {
4567                 struct buffer_info *info;
4568
4569                 info = instance_lb_buffer(inst);
4570                 ret = buffer_handler_unload(info);
4571         } else if (type == TYPE_PD) {
4572                 struct buffer_info *info;
4573
4574                 DbgPrint("Slave release buffer for PD\n");
4575
4576                 info = instance_pd_buffer(inst);
4577                 ret = buffer_handler_unload(info);
4578
4579                 /*!
4580                  * \note
4581                  * Send the PD destroyed event to the client
4582                  */
4583                 instance_client_pd_destroyed(inst, ret);
4584         }
4585
4586 out:
4587         result = packet_create_reply(packet, "i", ret);
4588         if (!result)
4589                 ErrPrint("Failed to create a packet\n");
4590
4591         return result;
4592 }
4593
4594 static struct packet *service_update(pid_t pid, int handle, const struct packet *packet)
4595 {
4596         struct packet *result;
4597         const char *pkgname;
4598         const char *cluster;
4599         const char *category;
4600         char *lb_pkgname;
4601         int ret;
4602
4603         ret = packet_get(packet, "sss", &pkgname, &cluster, &category);
4604         if (ret != 3) {
4605                 ErrPrint("Invalid Packet\n");
4606                 ret = -EINVAL;
4607                 goto out;
4608         }
4609
4610         lb_pkgname = package_lb_pkgname(pkgname);
4611         if (!lb_pkgname) {
4612                 ErrPrint("Invalid package %s\n", pkgname);
4613                 ret = -EINVAL;
4614                 goto out;
4615         }
4616
4617         /*!
4618          * \TODO
4619          * Validate the update requstor.
4620          */
4621         slave_rpc_request_update(lb_pkgname, "", cluster, category);
4622         DbgFree(lb_pkgname);
4623         ret = 0;
4624
4625 out:
4626         result = packet_create_reply(packet, "i", ret);
4627         if (!result)
4628                 ErrPrint("Failed to create a packet\n");
4629
4630         return result;
4631 }
4632
4633 static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet *packet)
4634 {
4635         struct liveinfo *info;
4636         struct packet *result;
4637         int ret;
4638         const char *fifo_name;
4639         double timestamp;
4640
4641         DbgPrint("Request arrived from %d\n", pid);
4642
4643         if (packet_get(packet, "d", &timestamp) != 1) {
4644                 ErrPrint("Invalid packet\n");
4645                 fifo_name = "";
4646                 ret = -EINVAL;
4647                 goto out;
4648         }
4649
4650         info = liveinfo_create(pid, handle);
4651         if (!info) {
4652                 ErrPrint("Failed to create a liveinfo object\n");
4653                 fifo_name = "";
4654                 ret = -EINVAL;
4655                 goto out;
4656         }
4657
4658         ret = 0;
4659         fifo_name = liveinfo_filename(info);
4660         DbgPrint("FIFO Created: %s (Serve for %d)\n", fifo_name, pid);
4661
4662 out:
4663         result = packet_create_reply(packet, "si", fifo_name, ret);
4664         if (!result)
4665                 ErrPrint("Failed to create a result packet\n");
4666
4667         return result;
4668 }
4669
4670 static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet)
4671 {
4672         Eina_List *l;
4673         Eina_List *list;
4674         struct liveinfo *info;
4675         struct slave_node *slave;
4676         FILE *fp;
4677         double timestamp;
4678
4679         if (packet_get(packet, "d", &timestamp) != 1) {
4680                 ErrPrint("Invalid argument\n");
4681                 goto out;
4682         }
4683
4684         info = liveinfo_find_by_pid(pid);
4685         if (!info) {
4686                 ErrPrint("Invalid request\n");
4687                 goto out;
4688         }
4689
4690         liveinfo_open_fifo(info);
4691         fp = liveinfo_fifo(info);
4692         if (!fp) {
4693                 liveinfo_close_fifo(info);
4694                 goto out;
4695         }
4696
4697         list = (Eina_List *)slave_list();
4698         EINA_LIST_FOREACH(list, l, slave) {
4699                 fprintf(fp, "%d %s %s %s %d %d %d %s %d %d %lf\n", 
4700                         slave_pid(slave),
4701                         slave_name(slave),
4702                         slave_pkgname(slave),
4703                         slave_abi(slave),
4704                         slave_is_secured(slave),
4705                         slave_refcnt(slave),
4706                         slave_fault_count(slave),
4707                         slave_state_string(slave),
4708                         slave_loaded_instance(slave),
4709                         slave_loaded_package(slave),
4710                         slave_ttl(slave)
4711                 );
4712         }
4713
4714         fprintf(fp, "EOD\n");
4715         liveinfo_close_fifo(info);
4716 out:
4717         return NULL;
4718 }
4719
4720 static inline const char *visible_state_string(enum livebox_visible_state state)
4721 {
4722         switch (state) {
4723         case LB_SHOW:
4724                 return "Show";
4725         case LB_HIDE:
4726                 return "Hide";
4727         case LB_HIDE_WITH_PAUSE:
4728                 return "Paused";
4729         default:
4730                 break;
4731         }
4732
4733         return "Unknown";
4734 }
4735
4736 static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet)
4737 {
4738         const char *pkgname;
4739         struct liveinfo *info;
4740         struct pkg_info *pkg;
4741         Eina_List *l;
4742         Eina_List *inst_list;
4743         struct inst_info *inst;
4744         FILE *fp;
4745
4746         if (packet_get(packet, "s", &pkgname) != 1) {
4747                 ErrPrint("Invalid argument\n");
4748                 goto out;
4749         }
4750
4751         info = liveinfo_find_by_pid(pid);
4752         if (!info) {
4753                 ErrPrint("Invalid request\n");
4754                 goto out;
4755         }
4756
4757         liveinfo_open_fifo(info);
4758         fp = liveinfo_fifo(info);
4759         if (!fp) {
4760                 ErrPrint("Invalid fp\n");
4761                 liveinfo_close_fifo(info);
4762                 goto out;
4763         }
4764
4765         if (!package_is_lb_pkgname(pkgname)) {
4766                 ErrPrint("Invalid package name\n");
4767                 goto close_out;
4768         }
4769
4770         pkg = package_find(pkgname);
4771         if (!pkg) {
4772                 ErrPrint("Package is not exists\n");
4773                 goto close_out;
4774         }
4775
4776         inst_list = package_instance_list(pkg);
4777         EINA_LIST_FOREACH(inst_list, l, inst) {
4778                 fprintf(fp, "%s %s %s %lf %s %d %d\n",
4779                         instance_id(inst),
4780                         instance_cluster(inst),
4781                         instance_category(inst),
4782                         instance_period(inst),
4783                         visible_state_string(instance_visible_state(inst)),
4784                         instance_lb_width(inst),
4785                         instance_lb_height(inst));
4786         }
4787
4788 close_out:
4789         fprintf(fp, "EOD\n");
4790         liveinfo_close_fifo(info);
4791
4792 out:
4793         return NULL;
4794 }
4795
4796 static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet)
4797 {
4798         Eina_List *l;
4799         Eina_List *list;
4800         Eina_List *inst_list;
4801         struct liveinfo *info;
4802         struct pkg_info *pkg;
4803         struct slave_node *slave;
4804         FILE *fp;
4805         const char *slavename;
4806         double timestamp;
4807
4808         if (packet_get(packet, "d", &timestamp) != 1) {
4809                 ErrPrint("Invalid argument\n");
4810                 goto out;
4811         }
4812
4813         info = liveinfo_find_by_pid(pid);
4814         if (!info) {
4815                 ErrPrint("Invalid request\n");
4816                 goto out;
4817         }
4818
4819         liveinfo_open_fifo(info);
4820         fp = liveinfo_fifo(info);
4821         if (!fp) {
4822                 liveinfo_close_fifo(info);
4823                 goto out;
4824         }
4825
4826         list = (Eina_List *)package_list();
4827         EINA_LIST_FOREACH(list, l, pkg) {
4828                 slave = package_slave(pkg);
4829
4830                 if (slave) {
4831                         slavename = slave_name(slave);
4832                         pid = slave_pid(slave);
4833                 } else {
4834                         pid = (pid_t)-1;
4835                         slavename = "";
4836                 }
4837
4838                 inst_list = (Eina_List *)package_instance_list(pkg);
4839                 fprintf(fp, "%d %s %s %s %d %d %d\n",
4840                         pid,
4841                         strlen(slavename) ? slavename : "(none)",
4842                         package_name(pkg),
4843                         package_abi(pkg),
4844                         package_refcnt(pkg),
4845                         package_fault_count(pkg),
4846                         eina_list_count(inst_list)
4847                 );
4848         }
4849
4850         fprintf(fp, "EOD\n");
4851         liveinfo_close_fifo(info);
4852 out:
4853         return NULL;
4854 }
4855
4856 static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct packet *packet)
4857 {
4858         return NULL;
4859 }
4860
4861 static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet)
4862 {
4863         struct liveinfo *info;
4864         FILE *fp;
4865         char *cmd;
4866         char *pkgname;
4867         char *id;
4868
4869         if (packet_get(packet, "sss", &cmd, &pkgname, &id) != 3) {
4870                 ErrPrint("Invalid argument\n");
4871                 goto out;
4872         }
4873
4874         info = liveinfo_find_by_pid(pid);
4875         if (!info) {
4876                 ErrPrint("Invalid request\n");
4877                 goto out;
4878         }
4879
4880         liveinfo_open_fifo(info);
4881         fp = liveinfo_fifo(info);
4882         if (!fp) {
4883                 liveinfo_close_fifo(info);
4884                 goto out;
4885         }
4886
4887         if (!strcmp(cmd, "rmpack")) {
4888                 fprintf(fp, "%d\n", ENOSYS);
4889         } else if (!strcmp(cmd, "rminst")) {
4890                 struct inst_info *inst;
4891                 inst = package_find_instance_by_id(pkgname, id);
4892                 if (!inst) {
4893                         fprintf(fp, "%d\n", ENOENT);
4894                 } else {
4895                         instance_destroy(inst);
4896                         fprintf(fp, "%d\n", 0);
4897                 }
4898         }
4899
4900         fprintf(fp, "EOD\n");
4901         liveinfo_close_fifo(info);
4902
4903 out:
4904         return NULL;
4905 }
4906
4907 static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct packet *packet)
4908 {
4909         struct liveinfo *info;
4910         char *cmd;
4911         char *var;
4912         char *val;
4913         FILE *fp;
4914         int ret = -EINVAL;
4915
4916         if (packet_get(packet, "sss", &cmd, &var, &val) != 3) {
4917                 ErrPrint("Invalid argument\n");
4918                 goto out;
4919         }
4920
4921         info = liveinfo_find_by_pid(pid);
4922         if (!info) {
4923                 ErrPrint("Invalid request\n");
4924                 goto out;
4925         }
4926
4927         if (!strcasecmp(var, "debug")) {
4928                 if (!strcasecmp(cmd, "set")) {
4929                         g_conf.debug_mode = !strcasecmp(val, "on");
4930                 } else if (!strcasecmp(cmd, "get")) {
4931                 }
4932                 ret = g_conf.debug_mode;
4933         } else if (!strcasecmp(var, "slave_max_load")) {
4934                 if (!strcasecmp(cmd, "set")) {
4935                         g_conf.slave_max_load = atoi(val);
4936                 } else if (!strcasecmp(cmd, "get")) {
4937                 }
4938                 ret = g_conf.slave_max_load;
4939         }
4940
4941         liveinfo_open_fifo(info);
4942         fp = liveinfo_fifo(info);
4943         if (!fp) {
4944                 liveinfo_close_fifo(info);
4945                 goto out;
4946         }
4947         fprintf(fp, "%d\nEOD\n", ret);
4948         liveinfo_close_fifo(info);
4949
4950 out:
4951         return NULL;
4952 }
4953
4954 static struct method s_info_table[] = {
4955         {
4956                 .cmd = "liveinfo_hello",
4957                 .handler = liveinfo_hello,
4958         },
4959         {
4960                 .cmd = "slave_list",
4961                 .handler = liveinfo_slave_list,
4962         },
4963         {
4964                 .cmd = "pkg_list",
4965                 .handler = liveinfo_pkg_list,
4966         },
4967         {
4968                 .cmd = "inst_list",
4969                 .handler = liveinfo_inst_list,
4970         },
4971         {
4972                 .cmd = "slave_ctrl",
4973                 .handler = liveinfo_slave_ctrl,
4974         },
4975         {
4976                 .cmd = "pkg_ctrl",
4977                 .handler = liveinfo_pkg_ctrl,
4978         },
4979         {
4980                 .cmd = "master_ctrl",
4981                 .handler = liveinfo_master_ctrl,
4982         },
4983         {
4984                 .cmd = NULL,
4985                 .handler = NULL,
4986         },
4987 };
4988
4989 static struct method s_client_table[] = {
4990         {
4991                 .cmd = "pd_mouse_move",
4992                 .handler = client_pd_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
4993         },
4994         {
4995                 .cmd = "lb_mouse_move",
4996                 .handler = client_lb_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
4997         },
4998         {
4999                 .cmd = "pd_mouse_down",
5000                 .handler = client_pd_mouse_down, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
5001         },
5002         {
5003                 .cmd = "pd_mouse_up",
5004                 .handler = client_pd_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
5005         },
5006         {
5007                 .cmd = "lb_mouse_down",
5008                 .handler = client_lb_mouse_down, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
5009         },
5010         {
5011                 .cmd = "lb_mouse_up",
5012                 .handler = client_lb_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
5013         },
5014         {
5015                 .cmd = "pd_mouse_enter",
5016                 .handler = client_pd_mouse_enter, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
5017         },
5018         {
5019                 .cmd = "pd_mouse_leave",
5020                 .handler = client_pd_mouse_leave, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
5021         },
5022         {
5023                 .cmd = "lb_mouse_enter",
5024                 .handler = client_lb_mouse_enter, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
5025         },
5026         {
5027                 .cmd = "lb_mouse_leave",
5028                 .handler = client_lb_mouse_leave, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
5029         },
5030         {
5031                 .cmd = "change,visibility",
5032                 .handler = client_change_visibility,
5033         },
5034         {
5035                 .cmd = "lb_acquire_pixmap",
5036                 .handler = client_lb_acquire_pixmap,
5037         },
5038         {
5039                 .cmd = "lb_release_pixmap",
5040                 .handler = client_lb_release_pixmap,
5041         },
5042         {
5043                 .cmd = "pd_acquire_pixmap",
5044                 .handler = client_pd_acquire_pixmap,
5045         },
5046         {
5047                 .cmd = "pd_release_pixmap",
5048                 .handler = client_pd_release_pixmap,
5049         },
5050         {
5051                 .cmd = "acquire",
5052                 .handler = client_acquire, /*!< pid, ret */
5053         },
5054         {
5055                 .cmd = "release",
5056                 .handler = cilent_release, /*!< pid, ret */
5057         },
5058         {
5059                 .cmd = "clicked",
5060                 .handler = client_clicked, /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
5061         },
5062         {
5063                 .cmd = "text_signal",
5064                 .handler = client_text_signal, /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
5065         },
5066         {
5067                 .cmd = "delete",
5068                 .handler = client_delete, /* pid, pkgname, filename, ret */
5069         },
5070         {
5071                 .cmd = "resize",
5072                 .handler = client_resize, /* pid, pkgname, filename, w, h, ret */
5073         },
5074         {
5075                 .cmd = "new",
5076                 .handler = client_new, /* pid, timestamp, pkgname, content, cluster, category, period, ret */
5077         },
5078         {
5079                 .cmd = "set_period",
5080                 .handler = client_set_period, /* pid, pkgname, filename, period, ret, period */
5081         },
5082         {
5083                 .cmd = "change_group",
5084                 .handler = client_change_group, /* pid, pkgname, filename, cluster, category, ret */
5085         },
5086         {
5087                 .cmd = "pinup_changed",
5088                 .handler = client_pinup_changed, /* pid, pkgname, filename, pinup, ret */
5089         },
5090         {
5091                 .cmd = "create_pd",
5092                 .handler = client_create_pd, /* pid, pkgname, filename, ret */
5093         },
5094         {
5095                 .cmd = "destroy_pd",
5096                 .handler = client_destroy_pd, /* pid, pkgname, filename, ret */
5097         },
5098         {
5099                 .cmd = "activate_package",
5100                 .handler = client_activate_package, /* pid, pkgname, ret */
5101         },
5102         {
5103                 .cmd = "subscribe", /* pid, cluster, sub-cluster */
5104                 .handler = client_subscribed,
5105         },
5106         {
5107                 .cmd = "unsubscribe", /* pid, cluster, sub-cluster */
5108                 .handler = client_unsubscribed,
5109         },
5110         {
5111                 .cmd = "delete_cluster",
5112                 .handler = client_delete_cluster,
5113         },
5114         {
5115                 .cmd = "delete_category",
5116                 .handler = client_delete_category,
5117         },
5118         {
5119                 .cmd = "refresh_group",
5120                 .handler = client_refresh_group,
5121         },
5122
5123         {
5124                 .cmd = "pd_access_read",
5125                 .handler = client_pd_access_read,
5126         },
5127         {
5128                 .cmd = "pd_access_read_prev",
5129                 .handler = client_pd_access_read_prev,
5130         },
5131         {
5132                 .cmd = "pd_access_read_next",
5133                 .handler = client_pd_access_read_next,
5134         },
5135         {
5136                 .cmd = "pd_access_activate",
5137                 .handler = client_pd_access_activate,
5138         },
5139
5140         {
5141                 .cmd = "lb_access_read",
5142                 .handler = client_lb_access_read,
5143         },
5144         {
5145                 .cmd = "lb_access_read_prev",
5146                 .handler = client_lb_access_read_prev,
5147         },
5148         {
5149                 .cmd = "lb_access_read_next",
5150                 .handler = client_lb_access_read_next,
5151         },
5152         {
5153                 .cmd = "lb_access_activate",
5154                 .handler = client_lb_access_activate,
5155         },
5156
5157         {
5158                 .cmd = "lb_key_down",
5159                 .handler = client_lb_key_down,
5160         },
5161         {
5162                 .cmd = "lb_key_up",
5163                 .handler = client_lb_key_up,
5164         },
5165
5166         {
5167                 .cmd = "pd_key_down",
5168                 .handler = client_pd_key_down,
5169         },
5170         {
5171                 .cmd = "pd_key_up",
5172                 .handler = client_pd_key_up,
5173         },
5174
5175         {
5176                 .cmd = NULL,
5177                 .handler = NULL,
5178         },
5179 };
5180
5181 static struct method s_service_table[] = {
5182         {
5183                 .cmd = "service_update",
5184                 .handler = service_update,
5185         },
5186         {
5187                 .cmd = NULL,
5188                 .handler = NULL,
5189         },
5190 };
5191
5192 static struct method s_slave_table[] = {
5193         {
5194                 .cmd = "hello",
5195                 .handler = slave_hello, /* slave_name, ret */
5196         },
5197         {
5198                 .cmd = "ping",
5199                 .handler = slave_ping, /* slave_name, ret */
5200         },
5201         {
5202                 .cmd = "call",
5203                 .handler = slave_call, /* slave_name, pkgname, filename, function, ret */
5204         },
5205         {
5206                 .cmd = "ret",
5207                 .handler = slave_ret, /* slave_name, pkgname, filename, function, ret */
5208         },
5209         {
5210                 .cmd = "updated",
5211                 .handler = slave_updated, /* slave_name, pkgname, filename, width, height, priority, ret */
5212         },
5213         {
5214                 .cmd = "desc_updated",
5215                 .handler = slave_desc_updated, /* slave_name, pkgname, filename, decsfile, ret */
5216         },
5217         {
5218                 .cmd = "deleted",
5219                 .handler = slave_deleted, /* slave_name, pkgname, filename, ret */
5220         },
5221         {
5222                 .cmd = "acquire_buffer",
5223                 .handler = slave_acquire_buffer, /* slave_name, id, w, h, size, - out - type, shmid */
5224         },
5225         {
5226                 .cmd = "resize_buffer",
5227                 .handler = slave_resize_buffer,
5228         },
5229         {
5230                 .cmd = "release_buffer",
5231                 .handler = slave_release_buffer, /* slave_name, id - ret */
5232         },
5233         {
5234                 .cmd = "faulted",
5235                 .handler = slave_faulted, /* slave_name, pkgname, id, funcname */
5236         },
5237         {
5238                 .cmd = NULL,
5239                 .handler = NULL,
5240         },
5241 };
5242
5243 HAPI int server_init(void)
5244 {
5245         com_core_packet_use_thread(COM_CORE_THREAD);
5246
5247         if (unlink(INFO_SOCKET) < 0)
5248                 ErrPrint("info socket: %s\n", strerror(errno));
5249
5250         if (unlink(SLAVE_SOCKET) < 0)
5251                 ErrPrint("slave socket: %s\n", strerror(errno));
5252
5253         if (unlink(CLIENT_SOCKET) < 0)
5254                 ErrPrint("client socket: %s\n", strerror(errno));
5255
5256         if (unlink(SERVICE_SOCKET) < 0)
5257                 ErrPrint("service socket: %s\n", strerror(errno));
5258
5259         s_info.info_fd = com_core_packet_server_init(INFO_SOCKET, s_info_table);
5260         if (s_info.info_fd < 0)
5261                 ErrPrint("Failed to create a info socket\n");
5262
5263         s_info.slave_fd = com_core_packet_server_init(SLAVE_SOCKET, s_slave_table);
5264         if (s_info.slave_fd < 0)
5265                 ErrPrint("Failed to create a slave socket\n");
5266
5267         s_info.client_fd = com_core_packet_server_init(CLIENT_SOCKET, s_client_table);
5268         if (s_info.client_fd < 0)
5269                 ErrPrint("Failed to create a client socket\n");
5270
5271         s_info.service_fd = com_core_packet_server_init(SERVICE_SOCKET, s_service_table);
5272         if (s_info.service_fd < 0)
5273                 ErrPrint("Faild to create a service socket\n");
5274
5275         if (chmod(INFO_SOCKET, 0600) < 0)
5276                 ErrPrint("info socket: %s\n", strerror(errno));
5277
5278         if (chmod(SLAVE_SOCKET, 0666) < 0)
5279                 ErrPrint("slave socket: %s\n", strerror(errno));
5280
5281         if (chmod(CLIENT_SOCKET, 0666) < 0)
5282                 ErrPrint("client socket: %s\n", strerror(errno));
5283
5284         if (chmod(SERVICE_SOCKET, 0666) < 0)
5285                 ErrPrint("service socket: %s\n", strerror(errno));
5286
5287         return 0;
5288 }
5289
5290 HAPI int server_fini(void)
5291 {
5292         if (s_info.info_fd > 0) {
5293                 com_core_packet_server_fini(s_info.info_fd);
5294                 s_info.info_fd = -1;
5295         }
5296
5297         if (s_info.slave_fd > 0) {
5298                 com_core_packet_server_fini(s_info.slave_fd);
5299                 s_info.slave_fd = -1;
5300         }
5301
5302         if (s_info.client_fd > 0) {
5303                 com_core_packet_server_fini(s_info.client_fd);
5304                 s_info.client_fd = -1;
5305         }
5306
5307         if (s_info.service_fd > 0) {
5308                 com_core_packet_server_fini(s_info.service_fd);
5309                 s_info.service_fd = -1;
5310         }
5311
5312         return 0;
5313 }
5314
5315 /* End of a file */