2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://www.tizenopensource.org/license
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.
23 #include <Ecore_Evas.h> /* fb.h */
28 #include <com-core_packet.h>
33 #include "slave_life.h"
34 #include "slave_rpc.h"
35 #include "client_life.h"
37 #include "client_rpc.h"
39 #include "script_handler.h"
40 #include "buffer_handler.h"
42 #include "fault_manager.h"
43 #include "fb.h" /* fb_type */
62 /* Share this with provider */
70 struct client_node *client;
71 struct inst_info *inst;
74 static struct packet *client_acquire(pid_t pid, int handle, const struct packet *packet) /*!< timestamp, ret */
76 struct client_node *client;
77 struct packet *result;
81 client = client_find_by_pid(pid);
83 ErrPrint("Client is already exists %d\n", pid);
88 if (packet_get(packet, "d", ×tamp) != 1) {
89 ErrPrint("Invalid arguemnt\n");
94 DbgPrint("Acquired %lf\n", timestamp);
99 * client_create will invoke the client created callback
101 client = client_create(pid, handle);
103 ErrPrint("Failed to create a new client for %d\n", pid);
108 result = packet_create_reply(packet, "i", ret);
110 ErrPrint("Failed to create a packet\n");
115 static struct packet *cilent_release(pid_t pid, int handle, const struct packet *packet) /*!< pid, ret */
117 struct client_node *client;
118 struct packet *result;
121 client = client_find_by_pid(pid);
123 ErrPrint("Client %d is not exists\n", pid);
128 client_destroy(client);
132 result = packet_create_reply(packet, "i", ret);
134 ErrPrint("Failed to create a packet\n");
139 /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
140 static struct packet *client_clicked(pid_t pid, int handle, const struct packet *packet)
142 struct client_node *client;
150 struct inst_info *inst;
152 client = client_find_by_pid(pid);
154 ErrPrint("Client %d is not exists\n", pid);
159 ret = packet_get(packet, "sssddd", &pkgname, &id, &event, ×tamp, &x, &y);
161 ErrPrint("Parameter is not matched\n");
166 DbgPrint("pid[%d] pkgname[%s] id[%s] event[%s] timestamp[%lf] x[%lf] y[%lf]\n", pid, pkgname, id, event, timestamp, x, y);
170 * Trust the package name which are sent by the client.
171 * The package has to be a livebox package name.
173 inst = package_find_instance_by_id(pkgname, id);
176 else if (package_is_fault(instance_package(inst)))
179 ret = instance_clicked(inst, event, timestamp, x, y);
182 /*! \note No reply packet */
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)
189 struct client_node *client;
190 struct packet *result;
193 const char *emission;
199 struct inst_info *inst;
202 client = client_find_by_pid(pid);
204 ErrPrint("Client %d is not exists\n", pid);
209 ret = packet_get(packet, "ssssdddd", &pkgname, &id, &emission, &source, &sx, &sy, &ex, &ey);
211 ErrPrint("Parameter is not matched\n");
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);
220 * Trust the package name which are sent by the client.
221 * The package has to be a livebox package name.
223 inst = package_find_instance_by_id(pkgname, id);
226 else if (package_is_fault(instance_package(inst)))
229 ret = instance_text_signal_emit(inst, emission, source, sx, sy, ex, ey);
232 result = packet_create_reply(packet, "i", ret);
234 ErrPrint("Failed to create a packet\n");
239 static Eina_Bool lazy_delete_cb(void *data)
241 struct deleted_item *item = data;
243 DbgPrint("Send delete event to the client\n");
246 * Before invoke this callback, the instance is able to already remove this client
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);
254 client_unref(item->client);
255 instance_unref(item->inst);
257 return ECORE_CALLBACK_CANCEL;
260 static struct packet *client_delete(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
262 struct client_node *client;
263 struct packet *result;
266 struct inst_info *inst;
269 client = client_find_by_pid(pid);
271 ErrPrint("Client %d is not exists\n", pid);
276 ret = packet_get(packet, "ss", &pkgname, &id);
278 ErrPrint("Parameter is not matched\n");
283 DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
287 * Trust the package name which are sent by the client.
288 * The package has to be a livebox package name.
290 inst = package_find_instance_by_id(pkgname, id);
293 } else if (package_is_fault(instance_package(inst))) {
295 } else if (instance_client(inst) != client) {
296 if (instance_has_client(inst, client)) {
297 struct deleted_item *item;
299 item = malloc(sizeof(*item));
301 ErrPrint("Heap: %s\n", strerror(errno));
307 * Send DELETED EVENT to the client.
308 * after return from this function.
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.
314 item->client = client_ref(client);
315 item->inst = instance_ref(inst);
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);
329 ret = instance_destroy(inst);
333 result = packet_create_reply(packet, "i", ret);
335 ErrPrint("Failed to create a packet\n");
340 static struct packet *client_resize(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, w, h, ret */
342 struct client_node *client;
343 struct packet *result;
348 struct inst_info *inst;
351 client = client_find_by_pid(pid);
353 ErrPrint("Client %d is not exists\n", pid);
358 ret = packet_get(packet, "ssii", &pkgname, &id, &w, &h);
360 ErrPrint("Parameter is not matched\n");
365 DbgPrint("pid[%d] pkgname[%s] id[%s] w[%d] h[%d]\n", pid, pkgname, id, w, h);
369 * Trust the package name which are sent by the client.
370 * The package has to be a livebox package name.
372 inst = package_find_instance_by_id(pkgname, id);
375 } else if (package_is_fault(instance_package(inst))) {
377 } else if (instance_client(inst) != client) {
380 ret = instance_resize(inst, w, h);
384 result = packet_create_reply(packet, "i", ret);
386 ErrPrint("Failed to create a packet\n");
391 static struct packet *client_new(pid_t pid, int handle, const struct packet *packet) /* pid, timestamp, pkgname, content, cluster, category, period, ret */
393 struct client_node *client;
394 struct packet *result;
398 const char *category;
402 struct pkg_info *info;
407 client = client_find_by_pid(pid);
409 ErrPrint("Client %d is not exists\n", pid);
414 ret = packet_get(packet, "dssssdii", ×tamp, &pkgname, &content, &cluster, &category, &period, &width, &height);
416 ErrPrint("Parameter is not matched\n");
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);
424 lb_pkgname = package_lb_pkgname(pkgname);
426 ErrPrint("This %s has no livebox package\n", pkgname);
431 info = package_find(lb_pkgname);
433 info = package_create(lb_pkgname);
437 } else if (package_is_fault(info)) {
439 } else if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE) {
440 ErrPrint("Not enough space\n");
443 struct inst_info *inst;
445 if (period > 0.0f && period < MINIMUM_PERIOD)
446 period = MINIMUM_PERIOD;
448 if (!strlen(content))
449 content = DEFAULT_CONTENT;
451 inst = instance_create(client, timestamp, lb_pkgname, content, cluster, category, period, width, height);
454 * Using the "inst" without validate its value is at my disposal. ;)
456 ret = inst ? 0 : -EFAULT;
462 result = packet_create_reply(packet, "i", ret);
464 ErrPrint("Failed to create a packet\n");
469 static struct packet *client_change_visibility(pid_t pid, int handle, const struct packet *packet)
471 struct client_node *client;
474 enum livebox_visible_state state;
476 struct inst_info *inst;
478 client = client_find_by_pid(pid);
480 ErrPrint("Client %d is not exists\n", pid);
485 ret = packet_get(packet, "ssi", &pkgname, &id, (int *)&state);
487 ErrPrint("Parameter is not matched\n");
492 DbgPrint("pid[%d] pkgname[%s] id[%s] state[%d]\n", pid, pkgname, id, state);
496 * Trust the package name which are sent by the client.
497 * The package has to be a livebox package name.
499 inst = package_find_instance_by_id(pkgname, id);
502 } else if (package_is_fault(instance_package(inst))) {
504 } else if (instance_client(inst) != client) {
507 ret = instance_set_visible_state(inst, state);
511 /*! \note No reply packet */
515 static struct packet *client_set_period(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, period, ret */
517 struct client_node *client;
518 struct packet *result;
523 struct inst_info *inst;
525 client = client_find_by_pid(pid);
527 ErrPrint("Client %d is not exists\n", pid);
532 ret = packet_get(packet, "ssd", &pkgname, &id, &period);
534 ErrPrint("Parameter is not matched\n");
539 DbgPrint("pid[%d] pkgname[%s] id[%s] period[%lf]\n", pid, pkgname, id, period);
543 * Trust the package name which are sent by the client.
544 * The package has to be a livebox package name.
546 inst = package_find_instance_by_id(pkgname, id);
549 } else if (package_is_fault(instance_package(inst))) {
551 } else if (instance_client(inst) != client) {
554 ret = instance_set_period(inst, period);
558 result = packet_create_reply(packet, "i", ret);
560 ErrPrint("Failed to create a packet\n");
565 static struct packet *client_change_group(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, cluster, category, ret */
567 struct client_node *client;
568 struct packet *result;
572 const char *category;
573 struct inst_info *inst;
576 client = client_find_by_pid(pid);
578 ErrPrint("Client %d is not exists\n", pid);
583 ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category);
585 ErrPrint("Parameter is not matched\n");
590 DbgPrint("pid[%d] pkgname[%s] id[%s] cluster[%s] category[%s]\n", pid, pkgname, id, cluster, category);
594 * Trust the package name which are sent by the client.
595 * The package has to be a livebox package name.
597 inst = package_find_instance_by_id(pkgname, id);
600 } else if (package_is_fault(instance_package(inst))) {
602 } else if (instance_client(inst) != client) {
605 ret = instance_change_group(inst, cluster, category);
609 result = packet_create_reply(packet, "i", ret);
611 ErrPrint("Failed to create a packet\n");
616 static struct packet *client_pd_mouse_enter(pid_t pid, int handle, const struct packet *packet)
618 struct client_node *client;
627 struct inst_info *inst;
628 const struct pkg_info *pkg;
630 client = client_find_by_pid(pid);
632 ErrPrint("Client %d is not exists\n", pid);
637 ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, ×tamp, &x, &y);
639 ErrPrint("Invalid parameter\n");
646 * Trust the package name which are sent by the client.
647 * The package has to be a livebox package name.
649 inst = package_find_instance_by_id(pkgname, id);
651 ErrPrint("Instance[%s] is not exists\n", id);
656 pkg = instance_package(inst);
658 ErrPrint("Package[%s] info is not found\n", pkgname);
663 if (package_is_fault(pkg)) {
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!
669 DbgPrint("Package[%s] is faulted\n", pkgname);
671 } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
672 struct buffer_info *buffer;
673 struct slave_node *slave;
674 struct packet *packet;
676 buffer = instance_pd_buffer(inst);
678 ErrPrint("Instance[%s] has no buffer\n", id);
683 slave = package_slave(pkg);
685 ErrPrint("Package[%s] has no slave\n", pkgname);
690 packet = packet_create_noack("pd_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
692 ErrPrint("Failed to create a packet[%s]\n", pkgname);
697 ret = slave_rpc_request_only(slave, pkgname, packet, 0);
698 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
699 struct script_info *script;
702 script = instance_pd_script(inst);
708 e = script_handler_evas(script);
714 script_handler_update_pointer(script, x, y, -1);
715 evas_event_feed_mouse_in(e, timestamp, NULL);
718 ErrPrint("Unsupported package\n");
723 /*! \note No reply packet */
727 static struct packet *client_pd_mouse_leave(pid_t pid, int handle, const struct packet *packet)
729 struct client_node *client;
738 struct inst_info *inst;
739 const struct pkg_info *pkg;
741 client = client_find_by_pid(pid);
743 ErrPrint("Client %d is not exists\n", pid);
748 ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, ×tamp, &x, &y);
750 ErrPrint("Parameter is not matched\n");
757 * Trust the package name which are sent by the client.
758 * The package has to be a livebox package name.
760 inst = package_find_instance_by_id(pkgname, id);
762 ErrPrint("Instance[%s] is not exists\n", id);
767 pkg = instance_package(inst);
769 ErrPrint("Package[%s] info is not found\n", pkgname);
774 if (package_is_fault(pkg)) {
777 * If the package is registered as fault module,
778 * slave has not load it, so we don't need to do anything at here!
780 DbgPrint("Package[%s] is faulted\n", pkgname);
782 } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
783 struct buffer_info *buffer;
784 struct slave_node *slave;
785 struct packet *packet;
787 buffer = instance_pd_buffer(inst);
789 ErrPrint("Instance[%s] has no buffer\n", id);
794 slave = package_slave(pkg);
796 ErrPrint("Package[%s] has no slave\n", pkgname);
801 packet = packet_create_noack("pd_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
803 ErrPrint("Failed to create a packet[%s]\n", pkgname);
808 ret = slave_rpc_request_only(slave, pkgname, packet, 0);
809 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
810 struct script_info *script;
813 script = instance_pd_script(inst);
819 e = script_handler_evas(script);
825 script_handler_update_pointer(script, x, y, -1);
826 evas_event_feed_mouse_out(e, timestamp, NULL);
829 ErrPrint("Unsupported package\n");
834 /*! \note No reply packet */
838 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 */
840 struct client_node *client;
849 struct inst_info *inst;
850 const struct pkg_info *pkg;
852 client = client_find_by_pid(pid);
854 ErrPrint("Client %d is not exists\n", pid);
859 ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, ×tamp, &x, &y);
861 ErrPrint("Parameter is not matched\n");
868 * Trust the package name which are sent by the client.
869 * The package has to be a livebox package name.
871 inst = package_find_instance_by_id(pkgname, id);
873 ErrPrint("Instance[%s] is not exists\n", id);
878 pkg = instance_package(inst);
880 ErrPrint("Package[%s] info is not found\n", pkgname);
885 if (package_is_fault(pkg)) {
888 * If the package is registered as fault module,
889 * slave has not load it, so we don't need to do anything at here!
891 DbgPrint("Package[%s] is faulted\n", pkgname);
893 } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
894 struct buffer_info *buffer;
895 struct slave_node *slave;
896 struct packet *packet;
898 buffer = instance_pd_buffer(inst);
900 ErrPrint("Instance[%s] has no buffer\n", id);
905 slave = package_slave(pkg);
907 ErrPrint("Package[%s] has no slave\n", pkgname);
912 packet = packet_create_noack("pd_mouse_down", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
914 ErrPrint("Failed to create a packet[%s]\n", pkgname);
919 ret = slave_rpc_request_only(slave, pkgname, packet, 0);
920 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
921 struct script_info *script;
924 script = instance_pd_script(inst);
930 e = script_handler_evas(script);
936 script_handler_update_pointer(script, x, y, 1);
937 evas_event_feed_mouse_move(e, x * w, y * h, timestamp, NULL);
938 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
941 ErrPrint("Unsupported package\n");
946 /*! \note No reply packet */
950 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 */
952 struct client_node *client;
961 struct inst_info *inst;
962 const struct pkg_info *pkg;
964 client = client_find_by_pid(pid);
966 ErrPrint("Client %d is not exists\n", pid);
971 ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, ×tamp, &x, &y);
973 ErrPrint("Parameter is not matched\n");
980 * Trust the package name which are sent by the client.
981 * The package has to be a livebox package name.
983 inst = package_find_instance_by_id(pkgname, id);
985 ErrPrint("Instance[%s] is not exists\n", id);
990 pkg = instance_package(inst);
992 ErrPrint("Package[%s] info is not exists\n", pkgname);
997 if (package_is_fault(pkg)) {
1000 * If the package is registered as fault module,
1001 * slave has not load it, so we don't need to do anything at here!
1003 DbgPrint("Package[%s] is faulted\n", pkgname);
1005 } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1006 struct buffer_info *buffer;
1007 struct slave_node *slave;
1008 struct packet *packet;
1010 buffer = instance_pd_buffer(inst);
1012 ErrPrint("Instance[%s] has no buffer\n", id);
1017 slave = package_slave(pkg);
1019 ErrPrint("Package[%s] has no slave\n", pkgname);
1024 packet = packet_create_noack("pd_mouse_up", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1026 ErrPrint("Failed to create a packet[%s]\n", pkgname);
1031 ret = slave_rpc_request_only(slave, pkgname, packet, 0);
1032 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1033 struct script_info *script;
1036 script = instance_pd_script(inst);
1042 e = script_handler_evas(script);
1048 script_handler_update_pointer(script, x, y, 0);
1049 evas_event_feed_mouse_move(e, x * w, y * h, timestamp, NULL);
1050 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.1f, NULL);
1053 ErrPrint("Unsupported package\n");
1058 /*! \note No reply packet */
1062 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 */
1064 struct client_node *client;
1065 const char *pkgname;
1073 struct inst_info *inst;
1074 const struct pkg_info *pkg;
1076 client = client_find_by_pid(pid);
1078 ErrPrint("Client %d is not exists\n", pid);
1083 ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, ×tamp, &x, &y);
1085 ErrPrint("Parameter is not matched\n");
1092 * Trust the package name which are sent by the client.
1093 * The package has to be a livebox package name.
1095 inst = package_find_instance_by_id(pkgname, id);
1097 ErrPrint("Instance[%s] is not exists\n", id);
1102 pkg = instance_package(inst);
1104 ErrPrint("Package[%s] info is not exists\n", pkgname);
1109 if (package_is_fault(pkg)) {
1112 * If the package is registered as fault module,
1113 * slave has not load it, so we don't need to do anything at here!
1115 DbgPrint("Package[%s] is faulted\n", pkgname);
1117 } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1118 struct buffer_info *buffer;
1119 struct slave_node *slave;
1120 //struct packet *packet;
1122 buffer = instance_pd_buffer(inst);
1124 ErrPrint("Instance[%s] has no buffer\n", id);
1129 slave = package_slave(pkg);
1131 ErrPrint("Package[%s] has no slave\n", pkgname);
1138 packet = packet_create_noack("pd_mouse_move", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1140 ErrPrint("Failed to create a packet[%s]\n", pkgname);
1145 packet_ref((struct packet *)packet);
1146 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
1147 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1148 struct script_info *script;
1151 script = instance_pd_script(inst);
1157 e = script_handler_evas(script);
1163 script_handler_update_pointer(script, x, y, -1);
1164 evas_event_feed_mouse_move(e, x * w, y * h, timestamp, NULL);
1167 ErrPrint("Unsupported package\n");
1172 /*! \note No reply packet */
1176 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 */
1178 struct client_node *client;
1179 const char *pkgname;
1187 struct inst_info *inst;
1188 const struct pkg_info *pkg;
1190 client = client_find_by_pid(pid);
1192 ErrPrint("Client %d is not exists\n", pid);
1197 ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, ×tamp, &x, &y);
1199 ErrPrint("Parameter is not matched\n");
1206 * Trust the package name which are sent by the client.
1207 * The package has to be a livebox package name.
1209 inst = package_find_instance_by_id(pkgname, id);
1211 ErrPrint("Instance[%s] is not exists\n", id);
1216 pkg = instance_package(inst);
1218 ErrPrint("Package[%s] info is not exists\n", pkgname);
1223 if (package_is_fault(pkg)) {
1226 * If the package is registered as fault module,
1227 * slave has not load it, so we don't need to do anything at here!
1229 DbgPrint("Package[%s] is faulted\n", pkgname);
1231 } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1232 struct buffer_info *buffer;
1233 struct slave_node *slave;
1234 //struct packet *packet;
1236 buffer = instance_lb_buffer(inst);
1238 ErrPrint("Instance[%s] has no buffer\n", id);
1243 slave = package_slave(pkg);
1245 ErrPrint("Package[%s] has no slave\n", pkgname);
1251 packet = packet_create_noack("lb_mouse_move", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1253 ErrPrint("Failed to create a packet[%s]\n", pkgname);
1258 packet_ref((struct packet *)packet);
1259 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
1260 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1261 struct script_info *script;
1264 script = instance_lb_script(inst);
1270 e = script_handler_evas(script);
1276 script_handler_update_pointer(script, x, y, -1);
1277 evas_event_feed_mouse_move(e, x * w, y * h, timestamp, NULL);
1280 ErrPrint("Unsupported package\n");
1285 /*! \note No reply packet */
1289 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 */
1291 struct client_node *client;
1292 const char *pkgname;
1300 struct inst_info *inst;
1301 const struct pkg_info *pkg;
1303 client = client_find_by_pid(pid);
1305 ErrPrint("Client %d is not exists\n", pid);
1310 ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, ×tamp, &x, &y);
1312 ErrPrint("Parameter is not matched\n");
1319 * Trust the package name which are sent by the client.
1320 * The package has to be a livebox package name.
1322 inst = package_find_instance_by_id(pkgname, id);
1324 ErrPrint("Instance[%s] is not exists\n", id);
1329 pkg = instance_package(inst);
1331 ErrPrint("Package[%s] info is not exists\n", pkgname);
1336 if (package_is_fault(pkg)) {
1339 * If the package is registered as fault module,
1340 * slave has not load it, so we don't need to do anything at here!
1342 DbgPrint("Package[%s] is faulted\n", pkgname);
1344 } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1345 struct buffer_info *buffer;
1346 struct slave_node *slave;
1347 struct packet *packet;
1349 buffer = instance_lb_buffer(inst);
1351 ErrPrint("Instance[%s] has no buffer\n", id);
1356 slave = package_slave(pkg);
1358 ErrPrint("Package[%s] has no slave\n", pkgname);
1363 packet = packet_create_noack("lb_mouse_enter", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1365 ErrPrint("Failed to create a packet[%s]\n", pkgname);
1370 ret = slave_rpc_request_only(slave, pkgname, packet, 0);
1371 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1372 struct script_info *script;
1375 script = instance_lb_script(inst);
1381 e = script_handler_evas(script);
1387 script_handler_update_pointer(script, x, y, -1);
1388 evas_event_feed_mouse_in(e, timestamp, NULL);
1391 ErrPrint("Unsupported package\n");
1396 /*! \note No reply packet */
1400 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 */
1402 struct client_node *client;
1403 const char *pkgname;
1411 struct inst_info *inst;
1412 const struct pkg_info *pkg;
1414 client = client_find_by_pid(pid);
1416 ErrPrint("Client %d is not exists\n", pid);
1421 ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, ×tamp, &x, &y);
1423 ErrPrint("Parameter is not matched\n");
1430 * Trust the package name which are sent by the client.
1431 * The package has to be a livebox package name.
1433 inst = package_find_instance_by_id(pkgname, id);
1435 ErrPrint("Instance[%s] is not exists\n", id);
1440 pkg = instance_package(inst);
1442 ErrPrint("Package[%s] info is not exists\n", pkgname);
1447 if (package_is_fault(pkg)) {
1450 * If the package is registered as fault module,
1451 * slave has not load it, so we don't need to do anything at here!
1453 DbgPrint("Package[%s] is faulted\n", pkgname);
1455 } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1456 struct buffer_info *buffer;
1457 struct slave_node *slave;
1458 struct packet *packet;
1460 buffer = instance_lb_buffer(inst);
1462 ErrPrint("Instance[%s] has no buffer\n", id);
1467 slave = package_slave(pkg);
1469 ErrPrint("Package[%s] has no slave\n", pkgname);
1474 packet = packet_create_noack("lb_mouse_leave", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1476 ErrPrint("Failed to create a packet[%s]\n", pkgname);
1481 ret = slave_rpc_request_only(slave, pkgname, packet, 0);
1482 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1483 struct script_info *script;
1486 script = instance_lb_script(inst);
1492 e = script_handler_evas(script);
1498 script_handler_update_pointer(script, x, y, -1);
1499 evas_event_feed_mouse_out(e, timestamp, NULL);
1502 ErrPrint("Unsupported package\n");
1507 /*! \note No reply packet */
1511 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 */
1513 struct client_node *client;
1514 const char *pkgname;
1522 struct inst_info *inst;
1523 const struct pkg_info *pkg;
1525 client = client_find_by_pid(pid);
1527 ErrPrint("Client %d is not exists\n", pid);
1532 ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, ×tamp, &x, &y);
1534 ErrPrint("Parameter is not matched\n");
1541 * Trust the package name which are sent by the client.
1542 * The package has to be a livebox package name.
1544 inst = package_find_instance_by_id(pkgname, id);
1546 ErrPrint("Instance[%s] is not exists\n", id);
1551 pkg = instance_package(inst);
1553 ErrPrint("Package[%s] info is not exists\n", pkgname);
1558 if (package_is_fault(pkg)) {
1561 * If the package is registered as fault module,
1562 * slave has not load it, so we don't need to do anything at here!
1564 DbgPrint("Package[%s] is faulted\n", pkgname);
1566 } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1567 struct buffer_info *buffer;
1568 struct slave_node *slave;
1569 struct packet *packet;
1571 buffer = instance_lb_buffer(inst);
1573 ErrPrint("Instance[%s] has no buffer\n", id);
1578 slave = package_slave(pkg);
1580 ErrPrint("Package[%s] has no slave\n", pkgname);
1585 packet = packet_create_noack("lb_mouse_down", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1587 ErrPrint("Failed to create a packet[%s]\n", pkgname);
1592 ret = slave_rpc_request_only(slave, pkgname, packet, 0);
1593 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1594 struct script_info *script;
1597 script = instance_lb_script(inst);
1603 e = script_handler_evas(script);
1609 script_handler_update_pointer(script, x, y, 1);
1610 evas_event_feed_mouse_move(e, x * w, y * h, timestamp, NULL);
1611 evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, timestamp + 0.01f, NULL);
1614 ErrPrint("Unsupported package\n");
1619 /*! \note No reply packet */
1623 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 */
1625 struct client_node *client;
1626 const char *pkgname;
1634 struct inst_info *inst;
1635 const struct pkg_info *pkg;
1637 client = client_find_by_pid(pid);
1639 ErrPrint("Client %d is not exists\n", pid);
1644 ret = packet_get(packet, "ssiiddd", &pkgname, &id, &w, &h, ×tamp, &x, &y);
1646 ErrPrint("Parameter is not matched\n");
1653 * Trust the package name which are sent by the client.
1654 * The package has to be a livebox package name.
1656 inst = package_find_instance_by_id(pkgname, id);
1658 ErrPrint("Instance[%s] is not exists\n", id);
1663 pkg = instance_package(inst);
1665 ErrPrint("Package[%s] info is not exists\n", pkgname);
1670 if (package_is_fault(pkg)) {
1673 * If the package is registered as fault module,
1674 * slave has not load it, so we don't need to do anything at here!
1676 DbgPrint("Package[%s] is faulted\n", pkgname);
1678 } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1679 struct buffer_info *buffer;
1680 struct slave_node *slave;
1681 struct packet *packet;
1683 buffer = instance_lb_buffer(inst);
1685 ErrPrint("Instance[%s] has no buffer\n", id);
1690 slave = package_slave(pkg);
1692 ErrPrint("Package[%s] has no slave\n", pkgname);
1697 packet = packet_create_noack("lb_mouse_up", "ssiiddd", pkgname, id, w, h, timestamp, x, y);
1699 ErrPrint("Failed to create a packet[%s]\n", pkgname);
1704 ret = slave_rpc_request_only(slave, pkgname, packet, 0);
1705 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1706 struct script_info *script;
1709 script = instance_lb_script(inst);
1715 e = script_handler_evas(script);
1721 script_handler_update_pointer(script, x, y, 0);
1722 evas_event_feed_mouse_move(e, x * w, y * h, timestamp, NULL);
1723 evas_event_feed_mouse_up(e, 1, EVAS_BUTTON_NONE, timestamp + 0.1f, NULL);
1726 ErrPrint("Unsupported package\n");
1731 /*! \note No reply packet */
1735 static int release_pixmap_cb(struct client_node *client, void *canvas)
1737 DbgPrint("Forcely unref the \"buffer\"\n");
1738 buffer_handler_pixmap_unref(canvas);
1739 return -1; /* Delete this callback */
1742 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 */
1744 struct packet *result;
1745 const char *pkgname;
1747 struct client_node *client;
1748 struct inst_info *inst;
1753 client = client_find_by_pid(pid);
1755 ErrPrint("Client %d is not exists\n", pid);
1759 ret = packet_get(packet, "ss", &pkgname, &id);
1761 ErrPrint("Parameter is not matched\n");
1767 * Trust the package name which are sent by the client.
1768 * The package has to be a livebox package name.
1770 inst = package_find_instance_by_id(pkgname, id);
1772 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
1776 DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
1778 buf_ptr = buffer_handler_pixmap_ref(instance_lb_buffer(inst));
1780 ErrPrint("Failed to ref pixmap\n");
1784 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
1786 ErrPrint("Failed to add a new client deactivate callback\n");
1787 buffer_handler_pixmap_unref(buf_ptr);
1790 pixmap = buffer_handler_pixmap(instance_lb_buffer(inst));
1794 result = packet_create_reply(packet, "i", pixmap);
1796 ErrPrint("Failed to create a reply packet\n");
1801 static struct packet *client_lb_release_pixmap(pid_t pid, int handle, const struct packet *packet)
1803 const char *pkgname;
1805 struct client_node *client;
1806 struct inst_info *inst;
1811 client = client_find_by_pid(pid);
1813 ErrPrint("Client %d is not exists\n", pid);
1817 ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
1819 ErrPrint("Parameter is not matched\n");
1822 DbgPrint("pid[%d] pkgname[%s] id[%s] Pixmap[0x%X]\n", pid, pkgname, id, pixmap);
1826 * Trust the package name which are sent by the client.
1827 * The package has to be a livebox package name.
1829 inst = package_find_instance_by_id(pkgname, id);
1831 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
1835 buf_ptr = buffer_handler_pixmap_find(pixmap);
1837 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
1841 if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0)
1842 buffer_handler_pixmap_unref(buf_ptr);
1845 /*! \note No reply packet */
1849 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 */
1851 struct packet *result;
1852 const char *pkgname;
1854 struct client_node *client;
1855 struct inst_info *inst;
1860 client = client_find_by_pid(pid);
1862 ErrPrint("Client %d is not exists\n", pid);
1866 ret = packet_get(packet, "ss", &pkgname, &id);
1868 ErrPrint("Parameter is not matched\n");
1874 * Trust the package name which are sent by the client.
1875 * The package has to be a livebox package name.
1877 inst = package_find_instance_by_id(pkgname, id);
1879 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
1883 DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
1885 buf_ptr = buffer_handler_pixmap_ref(instance_pd_buffer(inst));
1887 ErrPrint("Failed to ref pixmap\n");
1891 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
1893 buffer_handler_pixmap_unref(buf_ptr);
1895 pixmap = buffer_handler_pixmap(instance_pd_buffer(inst));
1897 result = packet_create_reply(packet, "i", pixmap);
1899 ErrPrint("Failed to create a reply packet\n");
1904 static struct packet *client_pd_release_pixmap(pid_t pid, int handle, const struct packet *packet)
1906 const char *pkgname;
1908 struct client_node *client;
1909 struct inst_info *inst;
1914 client = client_find_by_pid(pid);
1916 ErrPrint("Client %d is not exists\n", pid);
1920 ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
1922 ErrPrint("Parameter is not matched\n");
1925 DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
1929 * Trust the package name which are sent by the client.
1930 * The package has to be a livebox package name.
1932 inst = package_find_instance_by_id(pkgname, id);
1934 ErrPrint("Failed to find an instance (%s - %s)\n", pkgname, id);
1938 buf_ptr = buffer_handler_pixmap_find(pixmap);
1940 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
1944 if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0)
1945 buffer_handler_pixmap_unref(buf_ptr);
1948 /*! \note No reply packet */
1952 static struct packet *client_pinup_changed(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, pinup, ret */
1954 struct client_node *client;
1955 struct packet *result;
1956 const char *pkgname;
1960 struct inst_info *inst;
1962 client = client_find_by_pid(pid);
1964 ErrPrint("Client %d is not exists\n", pid);
1970 ret = packet_get(packet, "ssi", &pkgname, &id, &pinup);
1972 ErrPrint("Parameter is not matched\n");
1978 DbgPrint("pid[%d] pkgname[%s] id[%s] pinup[%d]\n", pid, pkgname, id, pinup);
1982 * Trust the package name which are sent by the client.
1983 * The package has to be a livebox package name.
1985 inst = package_find_instance_by_id(pkgname, id);
1988 else if (package_is_fault(instance_package(inst)))
1991 ret = instance_set_pinup(inst, pinup);
1994 result = packet_create_reply(packet, "i", ret);
1996 ErrPrint("Failed to create a packet\n");
2001 static Eina_Bool lazy_pd_created_cb(void *data)
2003 DbgPrint("Send PD Create event\n");
2004 instance_client_pd_created(data, 0);
2006 instance_unref(data);
2007 return ECORE_CALLBACK_CANCEL;
2010 static Eina_Bool lazy_pd_destroyed_cb(void *data)
2012 DbgPrint("Send PD Destroy event\n");
2013 instance_client_pd_destroyed(data, 0);
2015 instance_unref(data);
2016 return ECORE_CALLBACK_CANCEL;
2019 static struct packet *client_create_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
2021 struct client_node *client;
2022 struct packet *result;
2023 const char *pkgname;
2026 struct inst_info *inst;
2030 client = client_find_by_pid(pid);
2032 ErrPrint("Client %d is not exists\n", pid);
2037 ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
2039 ErrPrint("Parameter is not matched\n");
2044 DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
2048 * Trust the package name which are sent by the client.
2049 * The package has to be a livebox package name.
2051 inst = package_find_instance_by_id(pkgname, id);
2054 else if (package_is_fault(instance_package(inst)))
2056 else if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE)
2058 else if (package_pd_type(instance_package(inst)) == PD_TYPE_BUFFER) {
2059 instance_slave_set_pd_pos(inst, x, y);
2060 ret = instance_slave_open_pd(inst, client);
2061 ret = instance_signal_emit(inst,
2062 "pd,show", util_uri_to_path(instance_id(inst)),
2063 0.0, 0.0, 0.0, 0.0, x, y, 0);
2066 * PD craeted event will be send by the acquire_buffer function.
2067 * Because the slave will make request the acquire_buffer to
2070 * instance_client_pd_created(inst);
2072 } else if (package_pd_type(instance_package(inst)) == PD_TYPE_SCRIPT) {
2075 * ret value should be cared but in this case,
2076 * we ignore this for this moment, so we have to handle this error later.
2078 * if ret is less than 0, the slave has some problem.
2079 * but the script mode doesn't need slave for rendering default view of PD
2080 * so we can hanle it later.
2082 instance_slave_set_pd_pos(inst, x, y);
2083 ret = instance_slave_open_pd(inst, client);
2084 script_handler_update_pointer(instance_pd_script(inst), x, y, 0);
2085 ret = script_handler_load(instance_pd_script(inst), 1);
2089 * Send the PD created event to the clients,
2094 * But the created event has to be send afte return
2095 * from this function or the viewer couldn't care
2096 * the event correctly.
2098 inst = instance_ref(inst); /* To guarantee the inst */
2099 if (!ecore_timer_add(DELAY_TIME, lazy_pd_created_cb, inst))
2100 instance_unref(inst);
2103 ErrPrint("Invalid PD TYPE\n");
2108 result = packet_create_reply(packet, "i", ret);
2110 ErrPrint("Failed to create a packet\n");
2115 static struct packet *client_destroy_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
2117 struct client_node *client;
2118 struct packet *result;
2119 const char *pkgname;
2122 struct inst_info *inst;
2124 client = client_find_by_pid(pid);
2126 ErrPrint("Client %d is not exists\n", pid);
2131 ret = packet_get(packet, "ss", &pkgname, &id);
2133 ErrPrint("Parameter is not matched\n");
2138 DbgPrint("pid[%d] pkgname[%s] id[%s]\n", pid, pkgname, id);
2142 * Trust the package name which are sent by the client.
2143 * The package has to be a livebox package name.
2145 inst = package_find_instance_by_id(pkgname, id);
2148 else if (package_is_fault(instance_package(inst)))
2150 else if (package_pd_type(instance_package(inst)) == PD_TYPE_BUFFER) {
2151 ret = instance_signal_emit(inst,
2152 "pd,hide", util_uri_to_path(instance_id(inst)),
2153 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
2154 ret = instance_slave_close_pd(inst, client);
2158 * release_buffer will be called by the slave after this.
2159 * Then it will send the "pd_destroyed" event to the client
2161 * instance_client_pd_destroyed(inst);
2164 } else if (package_pd_type(instance_package(inst)) == PD_TYPE_SCRIPT) {
2165 ret = instance_slave_close_pd(inst, client);
2167 ret = script_handler_unload(instance_pd_script(inst), 1);
2171 * Send the destroyed PD event to the client
2174 inst = instance_ref(inst);
2175 if (!ecore_timer_add(DELAY_TIME, lazy_pd_destroyed_cb, inst))
2176 instance_unref(inst);
2179 ErrPrint("Invalid PD TYPE\n");
2184 result = packet_create_reply(packet, "i", ret);
2186 ErrPrint("Failed to create a packet\n");
2191 static struct packet *client_activate_package(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, ret */
2193 struct client_node *client;
2194 struct packet *result;
2195 const char *pkgname;
2197 struct pkg_info *info;
2199 client = client_find_by_pid(pid);
2201 ErrPrint("Client %d is not exists\n", pid);
2207 ret = packet_get(packet, "s", &pkgname);
2209 ErrPrint("Parameter is not matched\n");
2215 DbgPrint("pid[%d] pkgname[%s]\n", pid, pkgname);
2219 * Validate the livebox package name.
2221 if (!package_is_lb_pkgname(pkgname)) {
2222 ErrPrint("%s is not a valid livebox package\n", pkgname);
2228 info = package_find(pkgname);
2232 ret = package_clear_fault(info);
2235 result = packet_create_reply(packet, "is", ret, pkgname);
2237 ErrPrint("Failed to create a packet\n");
2242 static struct packet *client_subscribed(pid_t pid, int handle, const struct packet *packet)
2244 const char *cluster;
2245 const char *category;
2246 struct client_node *client;
2249 client = client_find_by_pid(pid);
2251 ErrPrint("Client %d is not exists\n", pid);
2256 ret = packet_get(packet, "ss", &cluster, &category);
2258 ErrPrint("Invalid argument\n");
2263 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
2264 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
2265 ErrPrint("Invalid cluster name\n");
2271 * SUBSCRIBE cluster & sub-cluster for a client.
2273 ret = client_subscribe(client, cluster, category);
2275 package_alter_instances_to_client(client, ALTER_CREATE);
2278 /*! \note No reply packet */
2282 static struct packet *client_delete_cluster(pid_t pid, int handle, const struct packet *packet)
2284 const char *cluster;
2285 struct client_node *client;
2286 struct packet *result;
2289 client = client_find_by_pid(pid);
2291 ErrPrint("Client %d is not exists\n", pid);
2296 ret = packet_get(packet, "s", &cluster);
2298 ErrPrint("Invalid parameters\n");
2303 DbgPrint("pid[%d] cluster[%s]\n", pid, cluster);
2305 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
2306 ErrPrint("Invalid cluster: %s\n", cluster);
2317 result = packet_create_reply(packet, "i", ret);
2319 ErrPrint("Failed to create a packet\n");
2323 static inline int update_pkg_cb(struct category *category, const char *pkgname)
2328 c_name = group_cluster_name_by_category(category);
2329 s_name = group_category_name(category);
2331 if (!c_name || !s_name || !pkgname) {
2332 ErrPrint("Name is not valid\n");
2333 return EXIT_FAILURE;
2336 DbgPrint("Send refresh request: %s (%s/%s)\n", pkgname, c_name, s_name);
2337 slave_rpc_request_update(pkgname, "", c_name, s_name);
2339 /* Just try to create a new package */
2340 if (util_free_space(IMAGE_PATH) > MINIMUM_SPACE) {
2342 struct inst_info *inst;
2344 timestamp = util_timestamp();
2347 * Don't need to check the subscribed clients.
2348 * Because this callback is called by the requests of clients.
2349 * It means. some clients wants to handle this instances ;)
2351 inst = instance_create(NULL, timestamp, pkgname, DEFAULT_CONTENT, c_name, s_name, DEFAULT_PERIOD, 0, 0);
2353 ErrPrint("Failed to create a new instance\n");
2355 ErrPrint("Not enough space\n");
2357 return EXIT_SUCCESS;
2360 static struct packet *client_refresh_group(pid_t pid, int handle, const struct packet *packet)
2362 const char *cluster_id;
2363 const char *category_id;
2364 struct client_node *client;
2366 struct cluster *cluster;
2367 struct category *category;
2368 struct context_info *info;
2369 Eina_List *info_list;
2372 client = client_find_by_pid(pid);
2374 ErrPrint("Cilent %d is not exists\n", pid);
2379 ret = packet_get(packet, "ss", &cluster_id, &category_id);
2381 ErrPrint("Invalid parameter\n");
2386 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster_id, category_id);
2388 if (!strlen(cluster_id) || !strcasecmp(cluster_id, DEFAULT_CLUSTER)) {
2389 ErrPrint("Invalid cluster name: %s\n", cluster_id);
2394 cluster = group_find_cluster(cluster_id);
2396 ErrPrint("Cluster [%s] is not registered\n", cluster_id);
2401 category = group_find_category(cluster, category_id);
2403 ErrPrint("Category [%s] is not registered\n", category_id);
2408 info_list = group_context_info_list(category);
2409 EINA_LIST_FOREACH(info_list, l, info) {
2410 update_pkg_cb(category, group_pkgname_from_context_info(info));
2414 /*! \note No reply packet */
2418 static struct packet *client_delete_category(pid_t pid, int handle, const struct packet *packet)
2420 const char *cluster;
2421 const char *category;
2422 struct client_node *client;
2423 struct packet *result;
2426 client = client_find_by_pid(pid);
2428 ErrPrint("Client %d is not exists\n", pid);
2433 ret = packet_get(packet, "ss", &cluster, &category);
2435 ErrPrint("Invalid paramenters\n");
2440 DbgPrint("pid[%d] cluster[%s] category[%s]\n", pid, cluster, category);
2441 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
2442 ErrPrint("Invalid cluster: %s\n", cluster);
2453 result = packet_create_reply(packet, "i", ret);
2455 ErrPrint("Failed to create a packet\n");
2459 static struct packet *client_unsubscribed(pid_t pid, int handle, const struct packet *packet)
2461 const char *cluster;
2462 const char *category;
2463 struct client_node *client;
2466 client = client_find_by_pid(pid);
2468 ErrPrint("Client %d is not exists\n", pid);
2473 ret = packet_get(packet, "ss", &cluster, &category);
2475 ErrPrint("Invalid argument\n");
2480 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
2482 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
2483 ErrPrint("Invalid cluster name: %s\n", cluster);
2489 * UNSUBSCRIBE cluster & sub-cluster for a client.
2491 ret = client_unsubscribe(client, cluster, category);
2493 package_alter_instances_to_client(client, ALTER_DESTROY);
2496 /*! \note No reply packet */
2500 static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
2502 struct slave_node *slave;
2503 const char *slavename;
2506 ret = packet_get(packet, "s", &slavename);
2508 ErrPrint("Parameter is not matched\n");
2513 DbgPrint("New slave[%s](%d) is arrived\n", slavename, pid);
2515 slave = slave_find_by_pid(pid);
2518 char pkgname[pathconf("/", _PC_PATH_MAX)];
2521 if (aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)) != AUL_R_OK) {
2522 ErrPrint("pid[%d] is not authroized provider package\n", pid);
2527 slave = slave_find_by_pkgname(pkgname);
2529 abi = abi_find_by_pkgname(pkgname);
2533 slave = slave_create(slavename, 1, abi, pkgname);
2535 ErrPrint("Failed to create a new slave for %s\n", slavename);
2540 DbgPrint("New slave is created\n");
2542 DbgPrint("Registered slave is replaced with this new one\n");
2543 abi = slave_abi(slave);
2546 slave_set_pid(slave, pid);
2547 DbgPrint("Provider is forcely activated, pkgname(%s), abi(%s), slavename(%s)\n", pkgname, abi, slavename);
2549 ErrPrint("Slave[%d] is not exists\n", pid);
2557 * After updating handle,
2558 * slave activated callback will be called.
2560 slave_rpc_update_handle(slave, handle);
2566 static struct packet *slave_ping(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
2568 struct slave_node *slave;
2569 const char *slavename;
2572 slave = slave_find_by_pid(pid);
2574 ErrPrint("Slave %d is not exists\n", pid);
2579 ret = packet_get(packet, "s", &slavename);
2581 ErrPrint("Parameter is not matched\n");
2586 slave_rpc_ping(slave);
2592 static struct packet *slave_faulted(pid_t pid, int handle, const struct packet *packet)
2594 struct slave_node *slave;
2595 struct inst_info *inst;
2596 const char *slavename;
2597 const char *pkgname;
2602 slave = slave_find_by_pid(pid);
2604 ErrPrint("Slave %d is not exists\n", pid);
2609 ret = packet_get(packet, "ssss", &slavename, &pkgname, &id, &func);
2611 ErrPrint("Parameter is not matched\n");
2616 ret = fault_info_set(slave, pkgname, id, func);
2617 DbgPrint("Slave Faulted: %s (%d)\n", slavename, ret);
2619 inst = package_find_instance_by_id(pkgname, id);
2621 DbgPrint("There is no such instance: %s\n", id);
2623 } else if (instance_state(inst) == INST_DESTROYED) {
2624 ErrPrint("Instance is already destroyed (%s)\n", id);
2627 DbgPrint("Destroy instance (%s)\n", id);
2628 ret = instance_destroy(inst);
2635 static struct packet *slave_call(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
2637 struct slave_node *slave;
2638 const char *slavename;
2639 const char *pkgname;
2644 slave = slave_find_by_pid(pid);
2646 ErrPrint("Slave %d is not exists\n", pid);
2651 ret = packet_get(packet, "ssss", &slavename, &pkgname, &id, &func);
2653 ErrPrint("Parameter is not matched\n");
2658 ret = fault_func_call(slave, pkgname, id, func);
2659 slave_give_more_ttl(slave);
2665 static struct packet *slave_ret(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
2667 struct slave_node *slave;
2668 const char *slavename;
2669 const char *pkgname;
2674 slave = slave_find_by_pid(pid);
2676 ErrPrint("Slave %d is not exists\n", pid);
2681 ret = packet_get(packet, "ssss", &slavename, &pkgname, &id, &func);
2683 ErrPrint("Parameter is not matched\n");
2688 ret = fault_func_ret(slave, pkgname, id, func);
2689 slave_give_more_ttl(slave);
2695 static inline char *get_file_kept_in_safe(const char *id)
2702 path = util_uri_to_path(id);
2704 ErrPrint("Invalid URI(%s)\n", id);
2711 if (OVERWRITE_CONTENT)
2712 return strdup(path);
2717 while (base_idx > 0 && path[base_idx] != '/') base_idx--;
2718 base_idx += (path[base_idx] == '/');
2720 new_path = malloc(len + 10);
2722 ErrPrint("Heap: %s\n", strerror(errno));
2726 strncpy(new_path, path, base_idx);
2727 snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
2731 static struct packet *slave_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, width, height, priority, ret */
2733 struct slave_node *slave;
2734 const char *slavename;
2735 const char *pkgname;
2737 const char *content_info;
2743 struct inst_info *inst;
2745 slave = slave_find_by_pid(pid);
2747 ErrPrint("Slave %d is not exists\n", pid);
2752 ret = packet_get(packet, "sssiidss", &slavename, &pkgname, &id,
2754 &content_info, &title);
2756 ErrPrint("Parameter is not matched\n");
2761 inst = package_find_instance_by_id(pkgname, id);
2764 } else if (package_is_fault(instance_package(inst))) {
2765 ErrPrint("Faulted instance cannot make any event.\n");
2767 } else if (instance_state(inst) == INST_DESTROYED) {
2768 ErrPrint("Instance is already destroyed\n");
2773 instance_set_lb_info(inst, w, h, priority, content_info, title);
2775 switch (package_lb_type(instance_package(inst))) {
2776 case LB_TYPE_SCRIPT:
2777 script_handler_resize(instance_lb_script(inst), w, h);
2779 filename = get_file_kept_in_safe(id);
2781 ret = script_handler_parse_desc(pkgname, id,
2785 ret = script_handler_parse_desc(pkgname, id,
2786 util_uri_to_path(id), 0);
2789 case LB_TYPE_BUFFER:
2790 instance_lb_updated_by_instance(inst);
2796 * text format (inst)
2798 instance_lb_updated_by_instance(inst);
2803 slave_give_more_ttl(slave);
2810 static struct packet *slave_desc_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, decsfile, ret */
2812 struct slave_node *slave;
2813 const char *slavename;
2814 const char *pkgname;
2816 const char *descfile;
2818 struct inst_info *inst;
2820 slave = slave_find_by_pid(pid);
2822 ErrPrint("Slave %d is not exists\n", pid);
2827 ret = packet_get(packet, "ssss", &slavename, &pkgname, &id, &descfile);
2829 ErrPrint("Parameter is not matched\n");
2834 inst = package_find_instance_by_id(pkgname, id);
2837 } else if (package_is_fault(instance_package(inst))) {
2838 ErrPrint("Faulted package cannot make event\n");
2840 } else if (instance_state(inst) == INST_DESTROYED) {
2841 ErrPrint("Instance is already destroyed\n");
2844 switch (package_pd_type(instance_package(inst))) {
2845 case PD_TYPE_SCRIPT:
2846 DbgPrint("Script (%s)\n", id);
2847 if (script_handler_is_loaded(instance_pd_script(inst))) {
2848 ret = script_handler_parse_desc(pkgname, id,
2853 instance_set_pd_info(inst, 0, 0);
2854 case PD_TYPE_BUFFER:
2855 instance_pd_updated(pkgname, id, descfile);
2859 DbgPrint("Ignore updated DESC(%s - %s - %s)\n",
2860 pkgname, id, descfile);
2870 static struct packet *slave_deleted(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, id, ret */
2872 struct slave_node *slave;
2873 const char *slavename;
2874 const char *pkgname;
2877 struct inst_info *inst;
2879 slave = slave_find_by_pid(pid);
2881 ErrPrint("Slave %d is not exists\n", pid);
2886 ret = packet_get(packet, "sss", &slavename, &pkgname, &id);
2888 ErrPrint("Parameter is not matched\n");
2893 inst = package_find_instance_by_id(pkgname, id);
2896 else if (package_is_fault(instance_package(inst)))
2899 ret = instance_destroyed(inst);
2906 * \note for the BUFFER Type slave
2908 static struct packet *slave_acquire_buffer(pid_t pid, int handle, const struct packet *packet) /* type, id, w, h, size */
2910 enum target_type target;
2911 const char *slavename;
2912 const char *pkgname;
2917 struct packet *result;
2918 struct slave_node *slave;
2919 struct inst_info *inst;
2920 const struct pkg_info *pkg;
2923 slave = slave_find_by_pid(pid);
2925 ErrPrint("Failed to find a slave\n");
2931 ret = packet_get(packet, "isssiii", &target, &slavename, &pkgname, &id, &w, &h, &pixel_size);
2933 ErrPrint("Invalid argument\n");
2939 if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE) {
2940 DbgPrint("No space\n");
2947 inst = package_find_instance_by_id(pkgname, id);
2949 DbgPrint("Package[%s] Id[%s] is not found\n", pkgname, id);
2955 pkg = instance_package(inst);
2958 if (target == TYPE_LB) {
2959 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2960 struct buffer_info *info;
2962 info = instance_lb_buffer(inst);
2964 if (!instance_create_lb_buffer(inst)) {
2965 ErrPrint("Failed to create a LB buffer\n");
2967 info = instance_lb_buffer(inst);
2969 ErrPrint("LB buffer is not valid\n");
2977 ret = buffer_handler_resize(info, w, h);
2978 DbgPrint("Buffer resize returns %d\n", ret);
2980 ret = buffer_handler_load(info);
2982 id = buffer_handler_id(info);
2983 DbgPrint("Buffer handler ID: %s\n", id);
2985 DbgPrint("Failed to load a buffer(%d)\n", ret);
2988 } else if (target == TYPE_PD) {
2989 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2990 struct buffer_info *info;
2992 DbgPrint("Slave acquire buffer for PD\n");
2994 info = instance_pd_buffer(inst);
2996 if (!instance_create_pd_buffer(inst)) {
2997 ErrPrint("Failed to create a PD buffer\n");
2999 info = instance_pd_buffer(inst);
3001 ErrPrint("PD buffer is not valid\n");
3004 instance_client_pd_created(inst, ret);
3010 ret = buffer_handler_resize(info, w, h);
3011 DbgPrint("Buffer resize returns %d\n", ret);
3013 ret = buffer_handler_load(info);
3015 id = buffer_handler_id(info);
3016 DbgPrint("Buffer handler ID: %s\n", id);
3018 DbgPrint("Failed to load a buffer (%d)\n", ret);
3022 * Send the PD created event to the client
3024 instance_client_pd_created(inst, ret);
3029 result = packet_create_reply(packet, "is", ret, id);
3031 ErrPrint("Failed to create a packet\n");
3036 static struct packet *slave_resize_buffer(pid_t pid, int handle, const struct packet *packet)
3038 struct slave_node *slave;
3039 struct packet *result;
3040 enum target_type type;
3041 const char *slavename;
3042 const char *pkgname;
3046 struct inst_info *inst;
3047 const struct pkg_info *pkg;
3050 slave = slave_find_by_pid(pid);
3052 ErrPrint("Failed to find a slave\n");
3058 if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE) {
3059 ErrPrint("Not enough space\n");
3065 ret = packet_get(packet, "isssii", &type, &slavename, &pkgname, &id, &w, &h);
3067 ErrPrint("Invalid argument\n");
3073 inst = package_find_instance_by_id(pkgname, id);
3075 DbgPrint("Instance is not found[%s] [%s]\n", pkgname, id);
3081 pkg = instance_package(inst);
3085 * THIS statement should not be entered.
3087 ErrPrint("PACKAGE INFORMATION IS NOT VALID\n");
3096 * Reset "id", It will be re-used from here
3099 if (type == TYPE_LB) {
3100 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3101 struct buffer_info *info;
3102 info = instance_lb_buffer(inst);
3103 ret = buffer_handler_resize(info, w, h);
3106 * id is resued for newly assigned ID
3109 id = buffer_handler_id(info);
3111 } else if (type == TYPE_PD) {
3112 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3113 struct buffer_info *info;
3114 info = instance_pd_buffer(inst);
3115 ret = buffer_handler_resize(info, w, h);
3118 * id is resued for newly assigned ID
3121 id = buffer_handler_id(info);
3126 result = packet_create_reply(packet, "is", ret, id);
3128 ErrPrint("Failed to create a packet\n");
3133 static struct packet *slave_release_buffer(pid_t pid, int handle, const struct packet *packet)
3135 enum target_type type;
3136 const char *slavename;
3137 const char *pkgname;
3139 struct packet *result;
3140 struct slave_node *slave;
3141 struct inst_info *inst;
3144 slave = slave_find_by_pid(pid);
3146 ErrPrint("Failed to find a slave\n");
3151 if (packet_get(packet, "isss", &type, &slavename, &pkgname, &id) != 4) {
3152 ErrPrint("Inavlid argument\n");
3157 inst = package_find_instance_by_id(pkgname, id);
3159 ErrPrint("Instance is not found [%s - %s]\n", pkgname, id);
3165 if (type == TYPE_LB) {
3166 struct buffer_info *info;
3168 info = instance_lb_buffer(inst);
3169 ret = buffer_handler_unload(info);
3170 } else if (type == TYPE_PD) {
3171 struct buffer_info *info;
3173 DbgPrint("Slave release buffer for PD\n");
3175 info = instance_pd_buffer(inst);
3176 ret = buffer_handler_unload(info);
3180 * Send the PD destroyed event to the client
3182 instance_client_pd_destroyed(inst, ret);
3186 result = packet_create_reply(packet, "i", ret);
3188 ErrPrint("Failed to create a packet\n");
3193 static struct packet *service_update(pid_t pid, int handle, const struct packet *packet)
3195 struct packet *result;
3196 const char *pkgname;
3197 const char *cluster;
3198 const char *category;
3202 ret = packet_get(packet, "sss", &pkgname, &cluster, &category);
3204 ErrPrint("Invalid Packet\n");
3209 lb_pkgname = package_lb_pkgname(pkgname);
3211 ErrPrint("Invalid package %s\n", pkgname);
3218 * Validate the update requstor.
3220 slave_rpc_request_update(lb_pkgname, "", cluster, category);
3221 DbgFree(lb_pkgname);
3225 result = packet_create_reply(packet, "i", ret);
3227 ErrPrint("Failed to create a packet\n");
3232 static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet *packet)
3234 struct liveinfo *info;
3235 struct packet *result;
3237 const char *fifo_name;
3240 DbgPrint("Request arrived from %d\n", pid);
3242 if (packet_get(packet, "d", ×tamp) != 1) {
3243 ErrPrint("Invalid packet\n");
3249 info = liveinfo_create(pid, handle);
3251 ErrPrint("Failed to create a liveinfo object\n");
3258 fifo_name = liveinfo_filename(info);
3259 DbgPrint("FIFO Created: %s (Serve for %d)\n", fifo_name, pid);
3262 result = packet_create_reply(packet, "si", fifo_name, ret);
3264 ErrPrint("Failed to create a result packet\n");
3269 static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet)
3273 struct liveinfo *info;
3274 struct slave_node *slave;
3278 if (packet_get(packet, "d", ×tamp) != 1) {
3279 ErrPrint("Invalid argument\n");
3283 info = liveinfo_find_by_pid(pid);
3285 ErrPrint("Invalid request\n");
3289 liveinfo_open_fifo(info);
3291 fp = liveinfo_fifo(info);
3295 fprintf(fp, "----------------------------------------------------------------------[Slave List]------------------------------------------------------------------------------\n");
3296 fprintf(fp, " pid slave name package name abi secured refcnt fault state inst pkg ttl \n");
3297 fprintf(fp, "----------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
3298 list = (Eina_List *)slave_list();
3299 EINA_LIST_FOREACH(list, l, slave) {
3300 fprintf(fp, " %7d %20s %39s %7s %7s %6d %5d %21s %4d %3d %3.4lf \n",
3303 slave_pkgname(slave),
3305 slave_is_secured(slave) ? "true" : "false",
3306 slave_refcnt(slave),
3307 slave_fault_count(slave),
3308 slave_state_string(slave),
3309 slave_loaded_instance(slave),
3310 slave_loaded_package(slave),
3314 liveinfo_close_fifo(info);
3320 static struct packet *liveinfo_slave_load(pid_t pid, int handle, const struct packet *packet)
3322 struct liveinfo *info;
3324 struct slave_node *slave;
3325 struct pkg_info *pkg;
3326 Eina_List *pkg_list;
3330 if (packet_get(packet, "i", &slave_pid) != 1) {
3331 ErrPrint("Invalid argument\n");
3335 info = liveinfo_find_by_pid(pid);
3337 ErrPrint("Invalid request\n");
3341 slave = slave_find_by_pid(slave_pid);
3343 ErrPrint("Slave is not exists\n");
3347 liveinfo_open_fifo(info);
3348 fp = liveinfo_fifo(info);
3352 fprintf(fp, "%s = { ", slave_name(slave));
3353 pkg_list = (Eina_List *)package_list();
3354 EINA_LIST_FOREACH(pkg_list, l, pkg) {
3355 if (package_slave(pkg) == slave)
3356 fprintf(fp, "%s, ", package_name(pkg));
3360 liveinfo_close_fifo(info);
3366 static inline const char *visible_state_string(enum livebox_visible_state state)
3373 case LB_HIDE_WITH_PAUSE:
3382 static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet)
3384 const char *pkgname;
3385 struct liveinfo *info;
3386 struct pkg_info *pkg;
3388 Eina_List *inst_list;
3389 struct inst_info *inst;
3392 if (packet_get(packet, "s", &pkgname) != 1) {
3393 ErrPrint("Invalid argument\n");
3397 if (!package_is_lb_pkgname(pkgname)) {
3398 ErrPrint("Invalid package name\n");
3402 pkg = package_find(pkgname);
3404 ErrPrint("Package is not exists\n");
3408 info = liveinfo_find_by_pid(pid);
3410 ErrPrint("Invalid request\n");
3414 liveinfo_open_fifo(info);
3416 fp = liveinfo_fifo(info);
3418 ErrPrint("Invalid fp\n");
3422 fprintf(fp, "-----------------------------------------------[Instance List]---------------------------------------\n");
3423 fprintf(fp, " ID | Cluster ID | Sub cluster ID | Period | Visibility | Width | Height \n");
3424 fprintf(fp, "-----------------------------------------------------------------------------------------------------\n");
3426 inst_list = package_instance_list(pkg);
3427 EINA_LIST_FOREACH(inst_list, l, inst) {
3428 fprintf(fp, " %18s %18s %18s %3.3lf %10s %5d %6d\n",
3430 instance_cluster(inst),
3431 instance_category(inst),
3432 instance_period(inst),
3433 visible_state_string(instance_visible_state(inst)),
3434 instance_lb_width(inst),
3435 instance_lb_height(inst));
3438 liveinfo_close_fifo(info);
3444 static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet)
3448 Eina_List *inst_list;
3449 struct liveinfo *info;
3450 struct pkg_info *pkg;
3451 struct slave_node *slave;
3453 const char *slavename;
3456 if (packet_get(packet, "d", ×tamp) != 1) {
3457 ErrPrint("Invalid argument\n");
3461 info = liveinfo_find_by_pid(pid);
3463 ErrPrint("Invalid request\n");
3467 liveinfo_open_fifo(info);
3469 fp = liveinfo_fifo(info);
3473 fprintf(fp, "+----------------------------------------------[Package List]------------------------------------------------+\n");
3474 fprintf(fp, " pid slave name package name abi refcnt fault inst \n");
3475 fprintf(fp, "+------------------------------------------------------------------------------------------------------------+\n");
3476 list = (Eina_List *)package_list();
3477 EINA_LIST_FOREACH(list, l, pkg) {
3478 slave = package_slave(pkg);
3481 slavename = slave_name(slave);
3482 pid = slave_pid(slave);
3488 inst_list = (Eina_List *)package_instance_list(pkg);
3490 fprintf(fp, " %7d %20s %39s %7s %6d %5d %4d \n",
3495 package_refcnt(pkg),
3496 package_fault_count(pkg),
3497 eina_list_count(inst_list)
3500 liveinfo_close_fifo(info);
3506 static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct packet *packet)
3511 static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet)
3516 static struct method s_info_table[] = {
3518 .cmd = "liveinfo_hello",
3519 .handler = liveinfo_hello,
3522 .cmd = "slave_list",
3523 .handler = liveinfo_slave_list,
3527 .handler = liveinfo_pkg_list,
3531 .handler = liveinfo_inst_list,
3534 .cmd = "slave_load",
3535 .handler = liveinfo_slave_load,
3538 .cmd = "slave_ctrl",
3539 .handler = liveinfo_slave_ctrl,
3543 .handler = liveinfo_pkg_ctrl,
3551 static struct method s_client_table[] = {
3553 .cmd = "pd_mouse_move",
3554 .handler = client_pd_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
3557 .cmd = "lb_mouse_move",
3558 .handler = client_lb_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
3561 .cmd = "pd_mouse_down",
3562 .handler = client_pd_mouse_down, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
3565 .cmd = "pd_mouse_up",
3566 .handler = client_pd_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
3569 .cmd = "lb_mouse_down",
3570 .handler = client_lb_mouse_down, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
3573 .cmd = "lb_mouse_up",
3574 .handler = client_lb_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
3577 .cmd = "pd_mouse_enter",
3578 .handler = client_pd_mouse_enter, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
3581 .cmd = "pd_mouse_leave",
3582 .handler = client_pd_mouse_leave, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
3585 .cmd = "lb_mouse_enter",
3586 .handler = client_lb_mouse_enter, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
3589 .cmd = "lb_mouse_leave",
3590 .handler = client_lb_mouse_leave, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
3593 .cmd = "change,visibility",
3594 .handler = client_change_visibility,
3597 .cmd = "lb_acquire_pixmap",
3598 .handler = client_lb_acquire_pixmap,
3601 .cmd = "lb_release_pixmap",
3602 .handler = client_lb_release_pixmap,
3605 .cmd = "pd_acquire_pixmap",
3606 .handler = client_pd_acquire_pixmap,
3609 .cmd = "pd_release_pixmap",
3610 .handler = client_pd_release_pixmap,
3614 .handler = client_acquire, /*!< pid, ret */
3618 .handler = cilent_release, /*!< pid, ret */
3622 .handler = client_clicked, /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
3625 .cmd = "text_signal",
3626 .handler = client_text_signal, /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
3630 .handler = client_delete, /* pid, pkgname, filename, ret */
3634 .handler = client_resize, /* pid, pkgname, filename, w, h, ret */
3638 .handler = client_new, /* pid, timestamp, pkgname, content, cluster, category, period, ret */
3641 .cmd = "set_period",
3642 .handler = client_set_period, /* pid, pkgname, filename, period, ret, period */
3645 .cmd = "change_group",
3646 .handler = client_change_group, /* pid, pkgname, filename, cluster, category, ret */
3649 .cmd = "pinup_changed",
3650 .handler = client_pinup_changed, /* pid, pkgname, filename, pinup, ret */
3654 .handler = client_create_pd, /* pid, pkgname, filename, ret */
3657 .cmd = "destroy_pd",
3658 .handler = client_destroy_pd, /* pid, pkgname, filename, ret */
3661 .cmd = "activate_package",
3662 .handler = client_activate_package, /* pid, pkgname, ret */
3665 .cmd = "subscribe", /* pid, cluster, sub-cluster */
3666 .handler = client_subscribed,
3669 .cmd = "unsubscribe", /* pid, cluster, sub-cluster */
3670 .handler = client_unsubscribed,
3673 .cmd = "delete_cluster",
3674 .handler = client_delete_cluster,
3677 .cmd = "delete_category",
3678 .handler = client_delete_category,
3681 .cmd = "refresh_group",
3682 .handler = client_refresh_group,
3690 static struct method s_service_table[] = {
3692 .cmd = "service_update",
3693 .handler = service_update,
3701 static struct method s_slave_table[] = {
3704 .handler = slave_hello, /* slave_name, ret */
3708 .handler = slave_ping, /* slave_name, ret */
3712 .handler = slave_call, /* slave_name, pkgname, filename, function, ret */
3716 .handler = slave_ret, /* slave_name, pkgname, filename, function, ret */
3720 .handler = slave_updated, /* slave_name, pkgname, filename, width, height, priority, ret */
3723 .cmd = "desc_updated",
3724 .handler = slave_desc_updated, /* slave_name, pkgname, filename, decsfile, ret */
3728 .handler = slave_deleted, /* slave_name, pkgname, filename, ret */
3731 .cmd = "acquire_buffer",
3732 .handler = slave_acquire_buffer, /* slave_name, id, w, h, size, - out - type, shmid */
3735 .cmd = "resize_buffer",
3736 .handler = slave_resize_buffer,
3739 .cmd = "release_buffer",
3740 .handler = slave_release_buffer, /* slave_name, id - ret */
3744 .handler = slave_faulted, /* slave_name, pkgname, id, funcname */
3752 HAPI int server_init(void)
3754 com_core_packet_use_thread(COM_CORE_THREAD);
3756 if (unlink(INFO_SOCKET) < 0)
3757 ErrPrint("info socket: %s\n", strerror(errno));
3759 if (unlink(SLAVE_SOCKET) < 0)
3760 ErrPrint("slave socket: %s\n", strerror(errno));
3762 if (unlink(CLIENT_SOCKET) < 0)
3763 ErrPrint("client socket: %s\n", strerror(errno));
3765 if (unlink(SERVICE_SOCKET) < 0)
3766 ErrPrint("service socket: %s\n", strerror(errno));
3768 s_info.info_fd = com_core_packet_server_init(INFO_SOCKET, s_info_table);
3769 if (s_info.info_fd < 0)
3770 ErrPrint("Failed to create a info socket\n");
3772 s_info.slave_fd = com_core_packet_server_init(SLAVE_SOCKET, s_slave_table);
3773 if (s_info.slave_fd < 0)
3774 ErrPrint("Failed to create a slave socket\n");
3776 s_info.client_fd = com_core_packet_server_init(CLIENT_SOCKET, s_client_table);
3777 if (s_info.client_fd < 0)
3778 ErrPrint("Failed to create a client socket\n");
3780 s_info.service_fd = com_core_packet_server_init(SERVICE_SOCKET, s_service_table);
3781 if (s_info.service_fd < 0)
3782 ErrPrint("Faild to create a service socket\n");
3784 if (chmod(INFO_SOCKET, 0600) < 0)
3785 ErrPrint("info socket: %s\n", strerror(errno));
3787 if (chmod(SLAVE_SOCKET, 0666) < 0)
3788 ErrPrint("slave socket: %s\n", strerror(errno));
3790 if (chmod(CLIENT_SOCKET, 0666) < 0)
3791 ErrPrint("client socket: %s\n", strerror(errno));
3793 if (chmod(SERVICE_SOCKET, 0666) < 0)
3794 ErrPrint("service socket: %s\n", strerror(errno));
3799 HAPI int server_fini(void)
3801 if (s_info.info_fd > 0) {
3802 com_core_packet_server_fini(s_info.info_fd);
3803 s_info.info_fd = -1;
3806 if (s_info.slave_fd > 0) {
3807 com_core_packet_server_fini(s_info.slave_fd);
3808 s_info.slave_fd = -1;
3811 if (s_info.client_fd > 0) {
3812 com_core_packet_server_fini(s_info.client_fd);
3813 s_info.client_fd = -1;
3816 if (s_info.service_fd > 0) {
3817 com_core_packet_server_fini(s_info.service_fd);
3818 s_info.service_fd = -1;