2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.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 */
29 #include <com-core_packet.h>
30 #include <livebox-errno.h>
31 #include <livebox-service.h>
33 #include "critical_log.h"
37 #include "slave_life.h"
38 #include "slave_rpc.h"
39 #include "client_life.h"
41 #include "client_rpc.h"
43 #include "script_handler.h"
44 #include "buffer_handler.h"
46 #include "fault_manager.h"
47 #include "fb.h" /* fb_type */
66 .remote_client_fd = -1,
69 /* Share this with provider */
76 struct access_cbdata {
78 struct inst_info *inst;
82 struct client_node *client;
83 struct inst_info *inst;
86 static inline int forward_lb_event_packet(const struct pkg_info *pkg, struct inst_info *inst, const struct packet *packet)
88 struct buffer_info *buffer;
89 struct slave_node *slave;
92 buffer = instance_lb_buffer(inst);
94 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
95 ret = LB_STATUS_ERROR_FAULT;
99 slave = package_slave(pkg);
101 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
102 ret = LB_STATUS_ERROR_INVALID;
106 packet_ref((struct packet *)packet);
107 ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0);
113 static inline int forward_pd_event_packet(const struct pkg_info *pkg, struct inst_info *inst, const struct packet *packet)
115 struct buffer_info *buffer;
116 struct slave_node *slave;
119 buffer = instance_pd_buffer(inst);
121 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
122 ret = LB_STATUS_ERROR_FAULT;
126 slave = package_slave(pkg);
128 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
129 ret = LB_STATUS_ERROR_INVALID;
133 packet_ref((struct packet *)packet);
134 ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0);
140 static inline int forward_pd_access_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, int x, int y)
143 struct buffer_info *buffer;
144 struct slave_node *slave;
147 buffer = instance_pd_buffer(inst);
149 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
150 ret = LB_STATUS_ERROR_FAULT;
154 slave = package_slave(pkg);
156 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
157 ret = LB_STATUS_ERROR_INVALID;
161 p = packet_create_noack(command, "ssdii", package_name(pkg), instance_id(inst), timestamp, x, y);
162 ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
168 static int forward_lb_access_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, int x, int y)
171 struct buffer_info *buffer;
172 struct slave_node *slave;
175 buffer = instance_lb_buffer(inst);
177 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
178 ret = LB_STATUS_ERROR_FAULT;
182 slave = package_slave(pkg);
184 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
185 ret = LB_STATUS_ERROR_INVALID;
189 p = packet_create_noack(command, "ssdii", package_name(pkg), instance_id(inst), timestamp, x, y);
190 ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
196 static Eina_Bool lazy_access_status_cb(void *data)
198 struct access_cbdata *cbdata = data;
200 if (instance_unref(cbdata->inst)) {
201 instance_send_access_status(cbdata->inst, cbdata->status);
203 DbgPrint("Skip sending access status (%d)\n", cbdata->status);
206 * If instance_unref returns NULL,
207 * The instance is destroyed. it means, we don't need to send event to the viewer
210 return ECORE_CALLBACK_CANCEL;
213 static int slave_fault_open_script_cb(struct slave_node *slave, void *data)
217 (void)script_handler_unload(instance_pd_script(data), 1);
218 (void)instance_slave_close_pd(data, instance_pd_owner(data));
219 (void)instance_client_pd_created(data, LB_STATUS_ERROR_FAULT);
221 timer = instance_del_data(data, "lazy,pd,open");
223 ecore_timer_del(timer);
226 (void)instance_unref(data);
228 return -1; /* remove this handler */
231 static int slave_fault_open_buffer_cb(struct slave_node *slave, void *data)
235 (void)instance_slave_close_pd(data, instance_pd_owner(data));
236 (void)instance_client_pd_created(data, LB_STATUS_ERROR_FAULT);
238 timer = instance_del_data(data, "pd,open,monitor");
240 ecore_timer_del(timer);
243 (void)instance_unref(data);
245 return -1; /* remove this handler */
248 static int slave_fault_close_script_cb(struct slave_node *slave, void *data)
252 (void)instance_client_pd_destroyed(data, LB_STATUS_ERROR_FAULT);
254 timer = instance_del_data(data, "lazy,pd,close");
256 ecore_timer_del(timer);
259 (void)instance_unref(data);
261 return -1; /* remove this handler */
264 static int slave_fault_close_buffer_cb(struct slave_node *slave, void *data)
268 (void)instance_client_pd_destroyed(data, LB_STATUS_ERROR_FAULT);
270 timer = instance_del_data(data, "lazy,pd,close");
272 timer = instance_del_data(data, "pd,close,monitor");
276 ecore_timer_del(timer);
279 (void)instance_unref(data);
281 return -1; /* remove this handler */
284 static int slave_fault_resize_buffer_cb(struct slave_node *slave, void *data)
288 (void)instance_slave_close_pd(data, instance_pd_owner(data));
289 (void)instance_client_pd_destroyed(data, LB_STATUS_ERROR_FAULT);
291 timer = instance_del_data(data, "pd,resize,monitor");
293 ecore_timer_del(timer);
296 (void)instance_unref(data);
298 return -1; /* remove this handler */
301 static int event_lb_route_cb(enum event_state state, struct event_data *event_info, void *data)
303 struct inst_info *inst = data;
304 const struct pkg_info *pkg;
305 struct slave_node *slave;
306 struct packet *packet;
309 pkg = instance_package(inst);
311 return LB_STATUS_ERROR_INVALID;
314 slave = package_slave(pkg);
316 return LB_STATUS_ERROR_INVALID;
320 case EVENT_STATE_ACTIVATE:
321 cmdstr = "lb_mouse_down";
323 case EVENT_STATE_ACTIVATED:
324 cmdstr = "lb_mouse_move";
326 case EVENT_STATE_DEACTIVATE:
327 cmdstr = "lb_mouse_up";
330 return LB_STATUS_ERROR_INVALID;
333 packet = packet_create_noack(cmdstr, "ssdii", package_name(pkg), instance_id(inst), util_timestamp(), event_info->x, event_info->y);
335 return LB_STATUS_ERROR_FAULT;
338 return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
341 static int event_lb_consume_cb(enum event_state state, struct event_data *event_info, void *data)
343 struct script_info *script;
344 struct inst_info *inst = data;
345 const struct pkg_info *pkg;
349 pkg = instance_package(inst);
354 script = instance_lb_script(inst);
356 return LB_STATUS_ERROR_FAULT;
359 e = script_handler_evas(script);
361 return LB_STATUS_ERROR_FAULT;
364 timestamp = util_timestamp();
367 case EVENT_STATE_ACTIVATE:
368 script_handler_update_pointer(script, event_info->x, event_info->y, 1);
369 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
371 case EVENT_STATE_ACTIVATED:
372 script_handler_update_pointer(script, event_info->x, event_info->y, -1);
373 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
375 case EVENT_STATE_DEACTIVATE:
376 script_handler_update_pointer(script, event_info->x, event_info->y, 0);
377 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
386 static int event_pd_route_cb(enum event_state state, struct event_data *event_info, void *data)
388 struct inst_info *inst = data;
389 const struct pkg_info *pkg;
390 struct slave_node *slave;
391 struct packet *packet;
394 pkg = instance_package(inst);
396 return LB_STATUS_ERROR_INVALID;
399 slave = package_slave(pkg);
401 return LB_STATUS_ERROR_INVALID;
405 case EVENT_STATE_ACTIVATE:
406 cmdstr = "pd_mouse_down";
408 case EVENT_STATE_ACTIVATED:
409 cmdstr = "pd_mouse_move";
411 case EVENT_STATE_DEACTIVATE:
412 cmdstr = "pd_mouse_up";
415 return LB_STATUS_ERROR_INVALID;
418 packet = packet_create_noack(cmdstr, "ssdii", package_name(pkg), instance_id(inst), util_timestamp(), event_info->x, event_info->y);
420 return LB_STATUS_ERROR_FAULT;
423 return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
426 static int event_pd_consume_cb(enum event_state state, struct event_data *event_info, void *data)
428 struct script_info *script;
429 struct inst_info *inst = data;
430 const struct pkg_info *pkg;
434 pkg = instance_package(inst);
439 script = instance_pd_script(inst);
441 return LB_STATUS_ERROR_FAULT;
444 e = script_handler_evas(script);
446 return LB_STATUS_ERROR_FAULT;
449 timestamp = util_timestamp();
452 case EVENT_STATE_ACTIVATE:
453 script_handler_update_pointer(script, event_info->x, event_info->y, 1);
454 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
456 case EVENT_STATE_ACTIVATED:
457 script_handler_update_pointer(script, event_info->x, event_info->y, -1);
458 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
460 case EVENT_STATE_DEACTIVATE:
461 script_handler_update_pointer(script, event_info->x, event_info->y, 0);
462 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
470 static struct packet *client_acquire(pid_t pid, int handle, const struct packet *packet) /*!< timestamp, ret */
472 struct client_node *client;
473 struct packet *result;
477 client = client_find_by_rpc_handle(handle);
479 ErrPrint("Client is already exists %d\n", pid);
480 ret = LB_STATUS_ERROR_EXIST;
484 if (packet_get(packet, "d", ×tamp) != 1) {
485 ErrPrint("Invalid arguemnt\n");
486 ret = LB_STATUS_ERROR_INVALID;
493 * client_create will invoke the client created callback
495 client = client_create(pid, handle);
497 ErrPrint("Failed to create a new client for %d\n", pid);
498 ret = LB_STATUS_ERROR_FAULT;
502 result = packet_create_reply(packet, "i", ret);
504 ErrPrint("Failed to create a packet\n");
510 static struct packet *cilent_release(pid_t pid, int handle, const struct packet *packet) /*!< pid, ret */
512 struct client_node *client;
513 struct packet *result;
516 client = client_find_by_rpc_handle(handle);
518 ErrPrint("Client %d is not exists\n", pid);
519 ret = LB_STATUS_ERROR_NOT_EXIST;
523 client_destroy(client);
527 result = packet_create_reply(packet, "i", ret);
529 ErrPrint("Failed to create a packet\n");
535 static int validate_request(const char *pkgname, const char *id, struct inst_info **out_inst, const struct pkg_info **out_pkg)
537 struct inst_info *inst;
538 const struct pkg_info *pkg;
540 inst = package_find_instance_by_id(pkgname, id);
542 ErrPrint("Instance is not exists\n");
543 return LB_STATUS_ERROR_NOT_EXIST;
546 pkg = instance_package(inst);
548 ErrPrint("System error - instance has no package?\n");
549 return LB_STATUS_ERROR_INVALID;
552 if (package_is_fault(pkg)) {
553 ErrPrint("Faulted package: %s\n", pkgname);
554 return LB_STATUS_ERROR_FAULT;
565 return LB_STATUS_SUCCESS;
568 /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
569 static struct packet *client_clicked(pid_t pid, int handle, const struct packet *packet)
571 struct client_node *client;
579 struct inst_info *inst = NULL;
581 client = client_find_by_rpc_handle(handle);
583 ErrPrint("Client %d is not exists\n", pid);
587 ret = packet_get(packet, "sssddd", &pkgname, &id, &event, ×tamp, &x, &y);
589 ErrPrint("Parameter is not matched\n");
595 * Trust the package name which are sent by the client.
596 * The package has to be a livebox package name.
598 ret = validate_request(pkgname, id, &inst, NULL);
599 if (ret == LB_STATUS_SUCCESS) {
600 (void)instance_clicked(inst, event, timestamp, x, y);
604 /*! \note No reply packet */
608 static struct packet *client_update_mode(pid_t pid, int handle, const struct packet *packet)
610 struct packet *result;
611 struct client_node *client;
616 struct inst_info *inst = NULL;
618 client = client_find_by_rpc_handle(handle);
620 ErrPrint("Client %d is not exists\n", pid);
621 ret = LB_STATUS_ERROR_INVALID;
625 ret = packet_get(packet, "ssi", &pkgname, &id, &active_update);
627 ErrPrint("Invalid argument\n");
628 ret = LB_STATUS_ERROR_INVALID;
632 ret = validate_request(pkgname, id, &inst, NULL);
633 if (ret == LB_STATUS_SUCCESS) {
636 * Send change update mode request to a slave
638 ret = instance_set_update_mode(inst, active_update);
642 result = packet_create_reply(packet, "i", ret);
644 ErrPrint("Failed to create a packet\n");
650 /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
651 static struct packet *client_text_signal(pid_t pid, int handle, const struct packet *packet)
653 struct client_node *client;
654 struct packet *result;
657 const char *emission;
663 struct inst_info *inst = NULL;
666 client = client_find_by_rpc_handle(handle);
668 ErrPrint("Client %d is not exists\n", pid);
669 ret = LB_STATUS_ERROR_NOT_EXIST;
673 ret = packet_get(packet, "ssssdddd", &pkgname, &id, &emission, &source, &sx, &sy, &ex, &ey);
675 ErrPrint("Parameter is not matched\n");
676 ret = LB_STATUS_ERROR_INVALID;
682 * Trust the package name which are sent by the client.
683 * The package has to be a livebox package name.
685 ret = validate_request(pkgname, id, &inst, NULL);
686 if (ret == LB_STATUS_SUCCESS) {
687 ret = instance_text_signal_emit(inst, emission, source, sx, sy, ex, ey);
691 result = packet_create_reply(packet, "i", ret);
693 ErrPrint("Failed to create a packet\n");
699 static Eina_Bool lazy_delete_cb(void *data)
701 struct deleted_item *item = data;
704 * Before invoke this callback, the instance is able to already remove this client
707 if (instance_has_client(item->inst, item->client)) {
708 (void)instance_unicast_deleted_event(item->inst, item->client);
709 (void)instance_del_client(item->inst, item->client);
712 (void)client_unref(item->client);
713 (void)instance_unref(item->inst);
715 return ECORE_CALLBACK_CANCEL;
718 static struct packet *client_delete(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
720 struct client_node *client;
721 struct packet *result;
724 struct inst_info *inst = NULL;
727 client = client_find_by_rpc_handle(handle);
729 ErrPrint("Client %d is not exists\n", pid);
730 ret = LB_STATUS_ERROR_NOT_EXIST;
734 ret = packet_get(packet, "ss", &pkgname, &id);
736 ErrPrint("Parameter is not matched\n");
737 ret = LB_STATUS_ERROR_INVALID;
743 * Trust the package name which are sent by the client.
744 * The package has to be a livebox package name.
746 ret = validate_request(pkgname, id, &inst, NULL);
747 if (ret != LB_STATUS_SUCCESS) {
751 if (instance_client(inst) != client) {
752 if (instance_has_client(inst, client)) {
753 struct deleted_item *item;
755 item = malloc(sizeof(*item));
757 ErrPrint("Heap: %s\n", strerror(errno));
758 ret = LB_STATUS_ERROR_MEMORY;
762 * Send DELETED EVENT to the client.
763 * after return from this function.
765 * Client will prepare the deleted event after get this function's return value.
766 * So We have to make a delay to send a deleted event.
769 item->client = client_ref(client);
770 item->inst = instance_ref(inst);
772 if (!ecore_timer_add(DELAY_TIME, lazy_delete_cb, item)) {
773 ErrPrint("Failed to add a delayzed delete callback\n");
774 (void)client_unref(client);
775 (void)instance_unref(inst);
777 ret = LB_STATUS_ERROR_FAULT;
779 ret = LB_STATUS_SUCCESS;
783 ErrPrint("Client has no permission\n");
784 ret = LB_STATUS_ERROR_PERMISSION;
787 ret = instance_destroy(inst, INSTANCE_DESTROY_DEFAULT);
791 result = packet_create_reply(packet, "i", ret);
793 ErrPrint("Failed to create a packet\n");
799 static struct packet *client_resize(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, w, h, ret */
801 struct client_node *client;
802 struct packet *result;
807 struct inst_info *inst = NULL;
810 client = client_find_by_rpc_handle(handle);
812 ErrPrint("Client %d is not exists\n", pid);
813 ret = LB_STATUS_ERROR_NOT_EXIST;
817 ret = packet_get(packet, "ssii", &pkgname, &id, &w, &h);
819 ErrPrint("Parameter is not matched\n");
820 ret = LB_STATUS_ERROR_INVALID;
824 DbgPrint("RESIZE: Client request resize to %dx%d (pid: %d, pkgname: %s)\n", w, h, pid, pkgname);
828 * Trust the package name which are sent by the client.
829 * The package has to be a livebox package name.
831 ret = validate_request(pkgname, id, &inst, NULL);
832 if (ret != LB_STATUS_SUCCESS) {
836 if (instance_client(inst) != client) {
837 ret = LB_STATUS_ERROR_PERMISSION;
839 ret = instance_resize(inst, w, h);
843 result = packet_create_reply(packet, "i", ret);
845 ErrPrint("Failed to create a packet\n");
851 static struct packet *client_new(pid_t pid, int handle, const struct packet *packet) /* pid, timestamp, pkgname, content, cluster, category, period, ret */
853 struct client_node *client;
854 struct packet *result;
858 const char *category;
862 struct pkg_info *info;
868 client = client_find_by_rpc_handle(handle);
870 ErrPrint("Client %d is not exists\n", pid);
871 ret = LB_STATUS_ERROR_NOT_EXIST;
875 ret = packet_get(packet, "dssssdii", ×tamp, &pkgname, &content, &cluster, &category, &period, &width, &height);
877 ErrPrint("Parameter is not matched\n");
878 ret = LB_STATUS_ERROR_INVALID;
882 DbgPrint("pid[%d] period[%lf] pkgname[%s] content[%s] cluster[%s] category[%s] period[%lf]\n",
883 pid, timestamp, pkgname, content, cluster, category, period);
885 lbid = package_lb_pkgname(pkgname);
887 ErrPrint("This %s has no livebox package\n", pkgname);
888 ret = LB_STATUS_ERROR_INVALID;
892 mainappid = livebox_service_mainappid(lbid);
893 if (!package_is_enabled(mainappid)) {
896 ret = LB_STATUS_ERROR_DISABLED;
901 info = package_find(lbid);
904 pkgid = livebox_service_appid(lbid);
908 ret = LB_STATUS_ERROR_FAULT;
912 info = package_create(pkgid, lbid);
917 ret = LB_STATUS_ERROR_FAULT;
918 } else if (package_is_fault(info)) {
919 ret = LB_STATUS_ERROR_FAULT;
920 } else if (util_free_space(IMAGE_PATH) < MINIMUM_SPACE) {
921 ErrPrint("Not enough space\n");
922 ret = LB_STATUS_ERROR_NO_SPACE;
924 struct inst_info *inst;
926 if (period > 0.0f && period < MINIMUM_PERIOD) {
927 period = MINIMUM_PERIOD;
930 inst = instance_create(client, timestamp, lbid, content, cluster, category, period, width, height);
933 * Using the "inst" without validate its value is at my disposal. ;)
935 ret = inst ? 0 : LB_STATUS_ERROR_FAULT;
941 result = packet_create_reply(packet, "i", ret);
943 ErrPrint("Failed to create a packet\n");
949 static struct packet *client_change_visibility(pid_t pid, int handle, const struct packet *packet)
951 struct client_node *client;
954 enum livebox_visible_state state;
956 struct inst_info *inst = NULL;
958 client = client_find_by_rpc_handle(handle);
960 ErrPrint("Client %d is not exists\n", pid);
961 ret = LB_STATUS_ERROR_NOT_EXIST;
965 ret = packet_get(packet, "ssi", &pkgname, &id, (int *)&state);
967 ErrPrint("Parameter is not matched\n");
968 ret = LB_STATUS_ERROR_INVALID;
974 * Trust the package name which are sent by the client.
975 * The package has to be a livebox package name.
977 ret = validate_request(pkgname, id, &inst, NULL);
978 if (ret != LB_STATUS_SUCCESS) {
982 if (instance_client(inst) != client) {
983 ret = LB_STATUS_ERROR_PERMISSION;
985 ret = instance_set_visible_state(inst, state);
989 /*! \note No reply packet */
993 static struct packet *client_set_period(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, period, ret */
995 struct client_node *client;
996 struct packet *result;
1001 struct inst_info *inst = NULL;
1003 client = client_find_by_rpc_handle(handle);
1005 ErrPrint("Client %d is not exists\n", pid);
1006 ret = LB_STATUS_ERROR_NOT_EXIST;
1010 ret = packet_get(packet, "ssd", &pkgname, &id, &period);
1012 ErrPrint("Parameter is not matched\n");
1013 ret = LB_STATUS_ERROR_INVALID;
1017 DbgPrint("pid[%d] pkgname[%s] period[%lf]\n", pid, pkgname, period);
1021 * Trust the package name which are sent by the client.
1022 * The package has to be a livebox package name.
1024 ret = validate_request(pkgname, id, &inst, NULL);
1025 if (ret != LB_STATUS_SUCCESS) {
1029 if (instance_client(inst) != client) {
1030 ret = LB_STATUS_ERROR_PERMISSION;
1032 ret = instance_set_period(inst, period);
1036 result = packet_create_reply(packet, "i", ret);
1038 ErrPrint("Failed to create a packet\n");
1044 static struct packet *client_change_group(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, cluster, category, ret */
1046 struct client_node *client;
1047 struct packet *result;
1048 const char *pkgname;
1050 const char *cluster;
1051 const char *category;
1052 struct inst_info *inst = NULL;
1055 client = client_find_by_rpc_handle(handle);
1057 ErrPrint("Client %d is not exists\n", pid);
1058 ret = LB_STATUS_ERROR_NOT_EXIST;
1062 ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category);
1064 ErrPrint("Parameter is not matched\n");
1065 ret = LB_STATUS_ERROR_INVALID;
1069 DbgPrint("pid[%d] pkgname[%s] cluster[%s] category[%s]\n", pid, pkgname, cluster, category);
1073 * Trust the package name which are sent by the client.
1074 * The package has to be a livebox package name.
1076 ret = validate_request(pkgname, id, &inst, NULL);
1077 if (ret != LB_STATUS_SUCCESS) {
1081 if (instance_client(inst) != client) {
1082 ret = LB_STATUS_ERROR_PERMISSION;
1084 ret = instance_change_group(inst, cluster, category);
1088 result = packet_create_reply(packet, "i", ret);
1090 ErrPrint("Failed to create a packet\n");
1096 static struct packet *client_pd_mouse_enter(pid_t pid, int handle, const struct packet *packet)
1098 struct client_node *client;
1099 const char *pkgname;
1105 struct inst_info *inst = NULL;
1106 const struct pkg_info *pkg = NULL;
1108 client = client_find_by_rpc_handle(handle);
1110 ErrPrint("Client %d is not exists\n", pid);
1111 ret = LB_STATUS_ERROR_NOT_EXIST;
1115 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1117 ErrPrint("Invalid parameter\n");
1118 ret = LB_STATUS_ERROR_INVALID;
1122 ret = validate_request(pkgname, id, &inst, &pkg);
1123 if (ret != LB_STATUS_SUCCESS) {
1127 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1128 ret = forward_pd_event_packet(pkg, inst, packet);
1129 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1130 struct script_info *script;
1133 script = instance_pd_script(inst);
1135 ret = LB_STATUS_ERROR_FAULT;
1139 e = script_handler_evas(script);
1141 ret = LB_STATUS_ERROR_FAULT;
1145 script_handler_update_pointer(script, x, y, -1);
1146 script_handler_feed_event(script, LB_SCRIPT_MOUSE_IN, timestamp);
1149 ErrPrint("Unsupported package\n");
1150 ret = LB_STATUS_ERROR_INVALID;
1154 /*! \note No reply packet */
1158 static struct packet *client_pd_mouse_leave(pid_t pid, int handle, const struct packet *packet)
1160 struct client_node *client;
1161 const char *pkgname;
1167 struct inst_info *inst = NULL;
1168 const struct pkg_info *pkg = NULL;
1170 client = client_find_by_rpc_handle(handle);
1172 ErrPrint("Client %d is not exists\n", pid);
1173 ret = LB_STATUS_ERROR_NOT_EXIST;
1177 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1179 ErrPrint("Parameter is not matched\n");
1180 ret = LB_STATUS_ERROR_INVALID;
1184 ret = validate_request(pkgname, id, &inst, &pkg);
1185 if (ret != LB_STATUS_SUCCESS) {
1189 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1190 ret = forward_pd_event_packet(pkg, inst, packet);
1191 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1192 struct script_info *script;
1195 script = instance_pd_script(inst);
1197 ret = LB_STATUS_ERROR_FAULT;
1201 e = script_handler_evas(script);
1203 ret = LB_STATUS_ERROR_FAULT;
1207 script_handler_update_pointer(script, x, y, -1);
1208 script_handler_feed_event(script, LB_SCRIPT_MOUSE_OUT, timestamp);
1211 ErrPrint("Unsupported package\n");
1212 ret = LB_STATUS_ERROR_INVALID;
1216 /*! \note No reply packet */
1220 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 */
1222 struct client_node *client;
1223 const char *pkgname;
1229 struct inst_info *inst = NULL;
1230 const struct pkg_info *pkg = NULL;
1232 client = client_find_by_rpc_handle(handle);
1234 ErrPrint("Client %d is not exists\n", pid);
1235 ret = LB_STATUS_ERROR_NOT_EXIST;
1239 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1241 ErrPrint("Parameter is not matched\n");
1242 ret = LB_STATUS_ERROR_INVALID;
1246 ret = validate_request(pkgname, id, &inst, &pkg);
1247 if (ret != LB_STATUS_SUCCESS) {
1251 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1252 ret = forward_pd_event_packet(pkg, inst, packet);
1253 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1254 struct script_info *script;
1257 script = instance_pd_script(inst);
1259 ret = LB_STATUS_ERROR_FAULT;
1263 e = script_handler_evas(script);
1265 ret = LB_STATUS_ERROR_FAULT;
1269 script_handler_update_pointer(script, x, y, 1);
1270 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
1273 ErrPrint("Unsupported package\n");
1274 ret = LB_STATUS_ERROR_INVALID;
1278 /*! \note No reply packet */
1282 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 */
1284 struct client_node *client;
1285 const char *pkgname;
1291 struct inst_info *inst = NULL;
1292 const struct pkg_info *pkg = NULL;
1294 client = client_find_by_rpc_handle(handle);
1296 ErrPrint("Client %d is not exists\n", pid);
1297 ret = LB_STATUS_ERROR_NOT_EXIST;
1301 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1303 ErrPrint("Parameter is not matched\n");
1304 ret = LB_STATUS_ERROR_INVALID;
1308 ret = validate_request(pkgname, id, &inst, &pkg);
1309 if (ret != LB_STATUS_SUCCESS) {
1313 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1314 ret = forward_pd_event_packet(pkg, inst, packet);
1315 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1316 struct script_info *script;
1319 script = instance_pd_script(inst);
1321 ret = LB_STATUS_ERROR_FAULT;
1325 e = script_handler_evas(script);
1327 ret = LB_STATUS_ERROR_FAULT;
1331 script_handler_update_pointer(script, x, y, 0);
1332 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
1335 ErrPrint("Unsupported package\n");
1336 ret = LB_STATUS_ERROR_INVALID;
1340 /*! \note No reply packet */
1344 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 */
1346 struct client_node *client;
1347 const char *pkgname;
1353 struct inst_info *inst = NULL;
1354 const struct pkg_info *pkg = NULL;
1356 client = client_find_by_rpc_handle(handle);
1358 ErrPrint("Client %d is not exists\n", pid);
1359 ret = LB_STATUS_ERROR_NOT_EXIST;
1363 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1365 ErrPrint("Parameter is not matched\n");
1366 ret = LB_STATUS_ERROR_INVALID;
1370 ret = validate_request(pkgname, id, &inst, &pkg);
1371 if (ret != LB_STATUS_SUCCESS) {
1375 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1376 ret = forward_pd_event_packet(pkg, inst, packet);
1377 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1378 struct script_info *script;
1381 script = instance_pd_script(inst);
1383 ret = LB_STATUS_ERROR_FAULT;
1387 e = script_handler_evas(script);
1389 ret = LB_STATUS_ERROR_FAULT;
1393 script_handler_update_pointer(script, x, y, -1);
1394 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
1397 ErrPrint("Unsupported package\n");
1398 ret = LB_STATUS_ERROR_INVALID;
1402 /*! \note No reply packet */
1406 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 */
1408 struct client_node *client;
1409 const char *pkgname;
1415 struct inst_info *inst = NULL;
1416 const struct pkg_info *pkg = NULL;
1418 client = client_find_by_rpc_handle(handle);
1420 ErrPrint("Client %d is not exists\n", pid);
1421 ret = LB_STATUS_ERROR_NOT_EXIST;
1425 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1427 ErrPrint("Parameter is not matched\n");
1428 ret = LB_STATUS_ERROR_INVALID;
1432 ret = validate_request(pkgname, id, &inst, &pkg);
1433 if (ret != LB_STATUS_SUCCESS) {
1437 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1438 ret = forward_lb_event_packet(pkg, inst, packet);
1439 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1440 struct script_info *script;
1443 script = instance_lb_script(inst);
1445 ret = LB_STATUS_ERROR_FAULT;
1449 e = script_handler_evas(script);
1451 ret = LB_STATUS_ERROR_FAULT;
1455 script_handler_update_pointer(script, x, y, -1);
1456 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
1459 ErrPrint("Unsupported package\n");
1460 ret = LB_STATUS_ERROR_INVALID;
1464 /*! \note No reply packet */
1468 static int inst_del_cb(struct inst_info *inst, void *data)
1470 (void)event_deactivate(data, inst);
1471 return -1; /* Delete this callback */
1474 static struct packet *client_lb_mouse_set(pid_t pid, int handle, const struct packet *packet)
1476 struct client_node *client;
1477 const char *pkgname;
1483 struct inst_info *inst = NULL;
1484 const struct pkg_info *pkg = NULL;
1486 client = client_find_by_rpc_handle(handle);
1488 ErrPrint("Client %d is not exists\n", pid);
1489 ret = LB_STATUS_ERROR_NOT_EXIST;
1493 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1495 ErrPrint("Parameter is not matched\n");
1496 ret = LB_STATUS_ERROR_INVALID;
1500 ret = validate_request(pkgname, id, &inst, &pkg);
1501 if (ret != LB_STATUS_SUCCESS) {
1505 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1506 ret = event_activate(x, y, event_lb_route_cb, inst);
1508 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, event_lb_route_cb);
1510 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1511 ret = event_activate(x, y, event_lb_consume_cb, inst);
1513 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, event_lb_consume_cb);
1516 ErrPrint("Unsupported package\n");
1517 ret = LB_STATUS_ERROR_INVALID;
1523 static struct packet *client_lb_mouse_unset(pid_t pid, int handle, const struct packet *packet)
1525 struct client_node *client;
1526 const char *pkgname;
1532 struct inst_info *inst = NULL;
1533 const struct pkg_info *pkg = NULL;
1535 client = client_find_by_rpc_handle(handle);
1537 ErrPrint("Client %d is not exists\n", pid);
1538 ret = LB_STATUS_ERROR_NOT_EXIST;
1542 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1544 ErrPrint("Parameter is not matched\n");
1545 ret = LB_STATUS_ERROR_INVALID;
1549 ret = validate_request(pkgname, id, &inst, &pkg);
1550 if (ret != LB_STATUS_SUCCESS) {
1554 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1555 ret = event_deactivate(event_lb_route_cb, inst);
1557 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1559 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1560 ret = event_deactivate(event_lb_consume_cb, inst);
1562 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1565 ErrPrint("Unsupported package\n");
1566 ret = LB_STATUS_ERROR_INVALID;
1572 static struct packet *client_pd_mouse_set(pid_t pid, int handle, const struct packet *packet)
1574 struct client_node *client;
1575 const char *pkgname;
1581 struct inst_info *inst = NULL;
1582 const struct pkg_info *pkg = NULL;
1584 client = client_find_by_rpc_handle(handle);
1586 ErrPrint("Client %d is not exists\n", pid);
1587 ret = LB_STATUS_ERROR_NOT_EXIST;
1591 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1593 ErrPrint("Parameter is not matched\n");
1594 ret = LB_STATUS_ERROR_INVALID;
1598 ret = validate_request(pkgname, id, &inst, &pkg);
1599 if (ret != LB_STATUS_SUCCESS) {
1603 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1604 ret = event_activate(x, y, event_pd_route_cb, inst);
1606 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, event_pd_route_cb);
1608 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1609 ret = event_activate(x, y, event_pd_consume_cb, inst);
1611 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, event_pd_consume_cb);
1614 ErrPrint("Unsupported package\n");
1615 ret = LB_STATUS_ERROR_INVALID;
1622 static struct packet *client_pd_mouse_unset(pid_t pid, int handle, const struct packet *packet)
1624 struct client_node *client;
1625 const char *pkgname;
1631 struct inst_info *inst = NULL;
1632 const struct pkg_info *pkg = NULL;
1634 client = client_find_by_rpc_handle(handle);
1636 ErrPrint("Client %d is not exists\n", pid);
1637 ret = LB_STATUS_ERROR_NOT_EXIST;
1641 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1643 ErrPrint("Parameter is not matched\n");
1644 ret = LB_STATUS_ERROR_INVALID;
1648 ret = validate_request(pkgname, id, &inst, &pkg);
1649 if (ret != LB_STATUS_SUCCESS) {
1653 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1654 ret = event_deactivate(event_pd_route_cb, inst);
1656 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1658 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1659 ret = event_deactivate(event_pd_consume_cb, inst);
1661 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb);
1664 ErrPrint("Unsupported package\n");
1665 ret = LB_STATUS_ERROR_INVALID;
1671 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 */
1673 struct client_node *client;
1674 const char *pkgname;
1680 struct inst_info *inst = NULL;
1681 const struct pkg_info *pkg = NULL;
1683 client = client_find_by_rpc_handle(handle);
1685 ErrPrint("Client %d is not exists\n", pid);
1686 ret = LB_STATUS_ERROR_NOT_EXIST;
1690 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1692 ErrPrint("Parameter is not matched\n");
1693 ret = LB_STATUS_ERROR_INVALID;
1697 ret = validate_request(pkgname, id, &inst, &pkg);
1698 if (ret != LB_STATUS_SUCCESS) {
1702 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1703 ret = forward_lb_event_packet(pkg, inst, packet);
1704 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1705 struct script_info *script;
1708 script = instance_lb_script(inst);
1710 ret = LB_STATUS_ERROR_FAULT;
1714 e = script_handler_evas(script);
1716 ret = LB_STATUS_ERROR_FAULT;
1720 script_handler_update_pointer(script, x, y, -1);
1721 script_handler_feed_event(script, LB_SCRIPT_MOUSE_IN, timestamp);
1724 ErrPrint("Unsupported package\n");
1725 ret = LB_STATUS_ERROR_INVALID;
1729 /*! \note No reply packet */
1733 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 */
1735 struct client_node *client;
1736 const char *pkgname;
1742 struct inst_info *inst = NULL;
1743 const struct pkg_info *pkg = NULL;
1745 client = client_find_by_rpc_handle(handle);
1747 ErrPrint("Client %d is not exists\n", pid);
1748 ret = LB_STATUS_ERROR_NOT_EXIST;
1752 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1754 ErrPrint("Parameter is not matched\n");
1755 ret = LB_STATUS_ERROR_INVALID;
1759 ret = validate_request(pkgname, id, &inst, &pkg);
1760 if (ret != LB_STATUS_SUCCESS) {
1764 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1765 ret = forward_lb_event_packet(pkg, inst, packet);
1766 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1767 struct script_info *script;
1770 script = instance_lb_script(inst);
1772 ret = LB_STATUS_ERROR_FAULT;
1776 e = script_handler_evas(script);
1778 ret = LB_STATUS_ERROR_FAULT;
1782 script_handler_update_pointer(script, x, y, -1);
1783 script_handler_feed_event(script, LB_SCRIPT_MOUSE_OUT, timestamp);
1786 ErrPrint("Unsupported package\n");
1787 ret = LB_STATUS_ERROR_INVALID;
1791 /*! \note No reply packet */
1795 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 */
1797 struct client_node *client;
1798 const char *pkgname;
1804 struct inst_info *inst = NULL;
1805 const struct pkg_info *pkg = NULL;
1807 client = client_find_by_rpc_handle(handle);
1809 ErrPrint("Client %d is not exists\n", pid);
1810 ret = LB_STATUS_ERROR_NOT_EXIST;
1814 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1816 ErrPrint("Parameter is not matched\n");
1817 ret = LB_STATUS_ERROR_INVALID;
1821 ret = validate_request(pkgname, id, &inst, &pkg);
1822 if (ret != LB_STATUS_SUCCESS) {
1826 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1827 ret = forward_lb_event_packet(pkg, inst, packet);
1828 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1829 struct script_info *script;
1832 script = instance_lb_script(inst);
1834 ret = LB_STATUS_ERROR_FAULT;
1838 e = script_handler_evas(script);
1840 ret = LB_STATUS_ERROR_FAULT;
1844 script_handler_update_pointer(script, x, y, 1);
1845 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
1848 ErrPrint("Unsupported package\n");
1849 ret = LB_STATUS_ERROR_INVALID;
1853 /*! \note No reply packet */
1857 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 */
1859 struct client_node *client;
1860 const char *pkgname;
1866 struct inst_info *inst = NULL;
1867 const struct pkg_info *pkg = NULL;
1869 client = client_find_by_rpc_handle(handle);
1871 ErrPrint("Client %d is not exists\n", pid);
1872 ret = LB_STATUS_ERROR_NOT_EXIST;
1876 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1878 ErrPrint("Parameter is not matched\n");
1879 ret = LB_STATUS_ERROR_INVALID;
1883 ret = validate_request(pkgname, id, &inst, &pkg);
1884 if (ret != LB_STATUS_SUCCESS) {
1888 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1889 ret = forward_lb_event_packet(pkg, inst, packet);
1890 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1891 struct script_info *script;
1894 script = instance_lb_script(inst);
1896 ret = LB_STATUS_ERROR_FAULT;
1900 e = script_handler_evas(script);
1902 ret = LB_STATUS_ERROR_FAULT;
1906 script_handler_update_pointer(script, x, y, 0);
1907 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
1910 ErrPrint("Unsupported package\n");
1911 ret = LB_STATUS_ERROR_INVALID;
1915 /*! \note No reply packet */
1919 static struct packet *client_pd_access_action_up(pid_t pid, int handle, const struct packet *packet)
1921 struct packet *result;
1922 struct client_node *client;
1923 const char *pkgname;
1929 struct inst_info *inst = NULL;
1930 const struct pkg_info *pkg = NULL;
1932 client = client_find_by_rpc_handle(handle);
1934 ErrPrint("Client %d is not exists\n", pid);
1935 ret = LB_STATUS_ERROR_NOT_EXIST;
1939 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1941 ErrPrint("Invalid parameter\n");
1942 ret = LB_STATUS_ERROR_INVALID;
1946 ret = validate_request(pkgname, id, &inst, &pkg);
1947 if (ret != LB_STATUS_SUCCESS) {
1951 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1952 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
1953 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1954 struct script_info *script;
1957 script = instance_pd_script(inst);
1959 ret = LB_STATUS_ERROR_FAULT;
1963 e = script_handler_evas(script);
1965 ret = LB_STATUS_ERROR_FAULT;
1969 script_handler_update_pointer(script, x, y, 0);
1970 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
1972 struct access_cbdata *cbdata;
1974 cbdata = malloc(sizeof(*cbdata));
1976 ret = LB_STATUS_ERROR_MEMORY;
1978 cbdata->inst = instance_ref(inst);
1979 cbdata->status = ret;
1981 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
1982 (void)instance_unref(cbdata->inst);
1984 ret = LB_STATUS_ERROR_FAULT;
1986 ret = LB_STATUS_SUCCESS;
1991 ErrPrint("Unsupported package\n");
1992 ret = LB_STATUS_ERROR_INVALID;
1996 result = packet_create_reply(packet, "i", ret);
1998 ErrPrint("Failed to create a reply packet\n");
2004 static struct packet *client_pd_access_action_down(pid_t pid, int handle, const struct packet *packet)
2006 struct packet *result;
2007 struct client_node *client;
2008 const char *pkgname;
2014 struct inst_info *inst = NULL;
2015 const struct pkg_info *pkg = NULL;
2017 client = client_find_by_rpc_handle(handle);
2019 ErrPrint("Client %d is not exists\n", pid);
2020 ret = LB_STATUS_ERROR_NOT_EXIST;
2024 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2026 ErrPrint("Invalid parameter\n");
2027 ret = LB_STATUS_ERROR_INVALID;
2031 ret = validate_request(pkgname, id, &inst, &pkg);
2032 if (ret != LB_STATUS_SUCCESS) {
2036 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2037 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2038 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2039 struct script_info *script;
2042 script = instance_pd_script(inst);
2044 ret = LB_STATUS_ERROR_FAULT;
2048 e = script_handler_evas(script);
2050 ret = LB_STATUS_ERROR_FAULT;
2054 script_handler_update_pointer(script, x, y, 1);
2055 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
2057 struct access_cbdata *cbdata;
2059 cbdata = malloc(sizeof(*cbdata));
2061 ret = LB_STATUS_ERROR_MEMORY;
2063 cbdata->inst = instance_ref(inst);
2064 cbdata->status = ret;
2066 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2067 (void)instance_unref(cbdata->inst);
2069 ret = LB_STATUS_ERROR_FAULT;
2071 ret = LB_STATUS_SUCCESS;
2076 ErrPrint("Unsupported package\n");
2077 ret = LB_STATUS_ERROR_INVALID;
2081 result = packet_create_reply(packet, "i", ret);
2083 ErrPrint("Failed to create a reply packet\n");
2089 static struct packet *client_pd_access_scroll_down(pid_t pid, int handle, const struct packet *packet)
2091 struct packet *result;
2092 struct client_node *client;
2093 const char *pkgname;
2099 struct inst_info *inst = NULL;
2100 const struct pkg_info *pkg = NULL;
2102 client = client_find_by_rpc_handle(handle);
2104 ErrPrint("Client %d is not exists\n", pid);
2105 ret = LB_STATUS_ERROR_NOT_EXIST;
2109 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2111 ErrPrint("Invalid parameter\n");
2112 ret = LB_STATUS_ERROR_INVALID;
2116 ret = validate_request(pkgname, id, &inst, &pkg);
2117 if (ret != LB_STATUS_SUCCESS) {
2121 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2122 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2123 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2124 struct script_info *script;
2127 script = instance_pd_script(inst);
2129 ret = LB_STATUS_ERROR_FAULT;
2133 e = script_handler_evas(script);
2135 ret = LB_STATUS_ERROR_FAULT;
2139 script_handler_update_pointer(script, x, y, 1);
2140 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
2142 struct access_cbdata *cbdata;
2144 cbdata = malloc(sizeof(*cbdata));
2146 ret = LB_STATUS_ERROR_MEMORY;
2148 cbdata->inst = instance_ref(inst);
2149 cbdata->status = ret;
2151 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2152 (void)instance_unref(cbdata->inst);
2154 ret = LB_STATUS_ERROR_FAULT;
2156 ret = LB_STATUS_SUCCESS;
2161 ErrPrint("Unsupported package\n");
2162 ret = LB_STATUS_ERROR_INVALID;
2166 result = packet_create_reply(packet, "i", ret);
2168 ErrPrint("Failed to create a reply packet\n");
2174 static struct packet *client_pd_access_scroll_move(pid_t pid, int handle, const struct packet *packet)
2176 struct packet *result;
2177 struct client_node *client;
2178 const char *pkgname;
2184 struct inst_info *inst = NULL;
2185 const struct pkg_info *pkg = NULL;
2187 client = client_find_by_rpc_handle(handle);
2189 ErrPrint("Client %d is not exists\n", pid);
2190 ret = LB_STATUS_ERROR_NOT_EXIST;
2194 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2196 ErrPrint("Invalid parameter\n");
2197 ret = LB_STATUS_ERROR_INVALID;
2201 ret = validate_request(pkgname, id, &inst, &pkg);
2202 if (ret != LB_STATUS_SUCCESS) {
2206 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2207 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2208 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2209 struct script_info *script;
2212 script = instance_pd_script(inst);
2214 ret = LB_STATUS_ERROR_FAULT;
2218 e = script_handler_evas(script);
2220 ret = LB_STATUS_ERROR_FAULT;
2224 script_handler_update_pointer(script, x, y, -1);
2225 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
2227 struct access_cbdata *cbdata;
2229 cbdata = malloc(sizeof(*cbdata));
2231 ret = LB_STATUS_ERROR_MEMORY;
2233 cbdata->inst = instance_ref(inst);
2234 cbdata->status = ret;
2236 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2237 (void)instance_unref(cbdata->inst);
2239 ret = LB_STATUS_ERROR_FAULT;
2241 ret = LB_STATUS_SUCCESS;
2246 ErrPrint("Unsupported package\n");
2247 ret = LB_STATUS_ERROR_INVALID;
2251 result = packet_create_reply(packet, "i", ret);
2253 ErrPrint("Failed to create a reply packet\n");
2259 static struct packet *client_pd_access_scroll_up(pid_t pid, int handle, const struct packet *packet)
2261 struct packet *result;
2262 struct client_node *client;
2263 const char *pkgname;
2269 struct inst_info *inst = NULL;
2270 const struct pkg_info *pkg = NULL;
2272 client = client_find_by_rpc_handle(handle);
2274 ErrPrint("Client %d is not exists\n", pid);
2275 ret = LB_STATUS_ERROR_NOT_EXIST;
2279 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2281 ErrPrint("Invalid parameter\n");
2282 ret = LB_STATUS_ERROR_INVALID;
2286 ret = validate_request(pkgname, id, &inst, &pkg);
2287 if (ret != LB_STATUS_SUCCESS) {
2291 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2292 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2293 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2294 struct script_info *script;
2297 script = instance_pd_script(inst);
2299 ret = LB_STATUS_ERROR_FAULT;
2303 e = script_handler_evas(script);
2305 ret = LB_STATUS_ERROR_FAULT;
2309 script_handler_update_pointer(script, x, y, 0);
2310 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
2312 struct access_cbdata *cbdata;
2314 cbdata = malloc(sizeof(*cbdata));
2316 ret = LB_STATUS_ERROR_MEMORY;
2318 cbdata->inst = instance_ref(inst);
2319 cbdata->status = ret;
2321 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2322 (void)instance_unref(cbdata->inst);
2324 ret = LB_STATUS_ERROR_FAULT;
2326 ret = LB_STATUS_SUCCESS;
2331 ErrPrint("Unsupported package\n");
2332 ret = LB_STATUS_ERROR_INVALID;
2336 result = packet_create_reply(packet, "i", ret);
2338 ErrPrint("Failed to create a reply packet\n");
2344 static struct packet *client_pd_access_unhighlight(pid_t pid, int handle, const struct packet *packet)
2346 struct packet *result;
2347 struct client_node *client;
2348 const char *pkgname;
2352 struct inst_info *inst = NULL;
2353 const struct pkg_info *pkg = NULL;
2357 client = client_find_by_rpc_handle(handle);
2359 ErrPrint("Client %d is not exists\n", pid);
2360 ret = LB_STATUS_ERROR_NOT_EXIST;
2364 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2366 ErrPrint("Invalid parameter\n");
2367 ret = LB_STATUS_ERROR_INVALID;
2371 ret = validate_request(pkgname, id, &inst, &pkg);
2372 if (ret != LB_STATUS_SUCCESS) {
2376 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2377 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2378 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2379 struct script_info *script;
2382 script = instance_pd_script(inst);
2384 ret = LB_STATUS_ERROR_FAULT;
2388 e = script_handler_evas(script);
2390 ret = LB_STATUS_ERROR_FAULT;
2394 script_handler_update_pointer(script, x, y, -1);
2395 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_UNHIGHLIGHT, timestamp);
2397 struct access_cbdata *cbdata;
2399 cbdata = malloc(sizeof(*cbdata));
2401 ret = LB_STATUS_ERROR_MEMORY;
2403 cbdata->inst = instance_ref(inst);
2404 cbdata->status = ret;
2406 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2407 (void)instance_unref(cbdata->inst);
2409 ret = LB_STATUS_ERROR_FAULT;
2411 ret = LB_STATUS_SUCCESS;
2416 ErrPrint("Unsupported package\n");
2417 ret = LB_STATUS_ERROR_INVALID;
2420 result = packet_create_reply(packet, "i", ret);
2422 ErrPrint("Failed to create a reply packet\n");
2428 static struct packet *client_pd_access_hl(pid_t pid, int handle, const struct packet *packet)
2430 struct packet *result;
2431 struct client_node *client;
2432 const char *pkgname;
2438 struct inst_info *inst = NULL;
2439 const struct pkg_info *pkg = NULL;
2441 client = client_find_by_rpc_handle(handle);
2443 ErrPrint("Client %d is not exists\n", pid);
2444 ret = LB_STATUS_ERROR_NOT_EXIST;
2448 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2450 ErrPrint("Invalid parameter\n");
2451 ret = LB_STATUS_ERROR_INVALID;
2455 ret = validate_request(pkgname, id, &inst, &pkg);
2456 if (ret != LB_STATUS_SUCCESS) {
2460 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2461 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2462 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2463 struct script_info *script;
2466 script = instance_pd_script(inst);
2468 ret = LB_STATUS_ERROR_FAULT;
2472 e = script_handler_evas(script);
2474 ret = LB_STATUS_ERROR_FAULT;
2478 script_handler_update_pointer(script, x, y, -1);
2479 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT, timestamp);
2481 struct access_cbdata *cbdata;
2483 cbdata = malloc(sizeof(*cbdata));
2485 ret = LB_STATUS_ERROR_MEMORY;
2487 cbdata->inst = instance_ref(inst);
2488 cbdata->status = ret;
2490 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2491 (void)instance_unref(cbdata->inst);
2493 ret = LB_STATUS_ERROR_FAULT;
2495 ret = LB_STATUS_SUCCESS;
2500 ErrPrint("Unsupported package\n");
2501 ret = LB_STATUS_ERROR_INVALID;
2505 result = packet_create_reply(packet, "i", ret);
2507 ErrPrint("Failed to create a reply packet\n");
2513 static struct packet *client_pd_access_hl_prev(pid_t pid, int handle, const struct packet *packet)
2515 struct packet *result;
2516 struct client_node *client;
2517 const char *pkgname;
2523 struct inst_info *inst = NULL;
2524 const struct pkg_info *pkg = NULL;
2526 client = client_find_by_rpc_handle(handle);
2528 ErrPrint("Client %d is not exists\n", pid);
2529 ret = LB_STATUS_ERROR_NOT_EXIST;
2533 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2535 ErrPrint("Invalid parameter\n");
2536 ret = LB_STATUS_ERROR_INVALID;
2540 ret = validate_request(pkgname, id, &inst, &pkg);
2541 if (ret != LB_STATUS_SUCCESS) {
2545 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2546 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2547 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2548 struct script_info *script;
2551 script = instance_pd_script(inst);
2553 ret = LB_STATUS_ERROR_FAULT;
2557 e = script_handler_evas(script);
2559 ret = LB_STATUS_ERROR_FAULT;
2563 script_handler_update_pointer(script, x, y, -1);
2564 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_PREV, timestamp);
2566 struct access_cbdata *cbdata;
2568 cbdata = malloc(sizeof(*cbdata));
2570 ret = LB_STATUS_ERROR_MEMORY;
2572 cbdata->inst = instance_ref(inst);
2573 cbdata->status = ret;
2575 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2576 (void)instance_unref(cbdata->inst);
2578 ret = LB_STATUS_ERROR_FAULT;
2580 ret = LB_STATUS_SUCCESS;
2585 ErrPrint("Unsupported package\n");
2586 ret = LB_STATUS_ERROR_INVALID;
2590 result = packet_create_reply(packet, "i", ret);
2592 ErrPrint("Failed to create a reply packet\n");
2598 static struct packet *client_pd_access_hl_next(pid_t pid, int handle, const struct packet *packet)
2600 struct packet *result;
2601 struct client_node *client;
2602 const char *pkgname;
2608 struct inst_info *inst = NULL;
2609 const struct pkg_info *pkg = NULL;
2611 client = client_find_by_rpc_handle(handle);
2613 ErrPrint("Client %d is not exists\n", pid);
2614 ret = LB_STATUS_ERROR_NOT_EXIST;
2618 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2620 ErrPrint("Invalid parameter\n");
2621 ret = LB_STATUS_ERROR_INVALID;
2625 ret = validate_request(pkgname, id, &inst, &pkg);
2626 if (ret != LB_STATUS_SUCCESS) {
2630 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2631 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2632 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2633 struct script_info *script;
2636 script = instance_pd_script(inst);
2638 ErrPrint("Script is not created yet\n");
2639 ret = LB_STATUS_ERROR_FAULT;
2643 e = script_handler_evas(script);
2645 ErrPrint("Evas is not exists\n");
2646 ret = LB_STATUS_ERROR_FAULT;
2650 script_handler_update_pointer(script, x, y, -1);
2651 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT, timestamp);
2653 struct access_cbdata *cbdata;
2655 cbdata = malloc(sizeof(*cbdata));
2657 ErrPrint("Heap: %s\n", strerror(errno));
2658 ret = LB_STATUS_ERROR_MEMORY;
2660 cbdata->inst = instance_ref(inst);
2661 cbdata->status = ret;
2663 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2664 ErrPrint("Failed to add timer\n");
2665 (void)instance_unref(cbdata->inst);
2667 ret = LB_STATUS_ERROR_FAULT;
2669 ret = LB_STATUS_SUCCESS;
2673 DbgPrint("Returns: %d\n", ret);
2676 ErrPrint("Unsupported package\n");
2677 ret = LB_STATUS_ERROR_INVALID;
2681 result = packet_create_reply(packet, "i", ret);
2683 ErrPrint("Failed to create a reply packet\n");
2689 static struct packet *client_pd_access_activate(pid_t pid, int handle, const struct packet *packet)
2691 struct packet *result;
2692 struct client_node *client;
2693 const char *pkgname;
2699 struct inst_info *inst = NULL;
2700 const struct pkg_info *pkg = NULL;
2702 client = client_find_by_rpc_handle(handle);
2704 ErrPrint("Client %d is not exists\n", pid);
2705 ret = LB_STATUS_ERROR_NOT_EXIST;
2709 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2711 ErrPrint("Invalid parameter\n");
2712 ret = LB_STATUS_ERROR_INVALID;
2716 ret = validate_request(pkgname, id, &inst, &pkg);
2717 if (ret != LB_STATUS_SUCCESS) {
2721 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2722 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2723 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2724 struct script_info *script;
2727 script = instance_pd_script(inst);
2729 ret = LB_STATUS_ERROR_FAULT;
2733 e = script_handler_evas(script);
2735 ret = LB_STATUS_ERROR_FAULT;
2739 script_handler_update_pointer(script, x, y, -1);
2740 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTIVATE, timestamp);
2742 struct access_cbdata *cbdata;
2744 cbdata = malloc(sizeof(*cbdata));
2746 ret = LB_STATUS_ERROR_MEMORY;
2748 cbdata->inst = instance_ref(inst);
2749 cbdata->status = ret;
2751 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2752 (void)instance_unref(cbdata->inst);
2754 ret = LB_STATUS_ERROR_FAULT;
2756 ret = LB_STATUS_SUCCESS;
2761 ErrPrint("Unsupported package\n");
2762 ret = LB_STATUS_ERROR_INVALID;
2766 result = packet_create_reply(packet, "i", ret);
2768 ErrPrint("Failed to create a reply packet\n");
2774 static struct packet *client_pd_key_down(pid_t pid, int handle, const struct packet *packet)
2776 struct client_node *client;
2777 const char *pkgname;
2783 struct inst_info *inst = NULL;
2784 const struct pkg_info *pkg = NULL;
2786 client = client_find_by_rpc_handle(handle);
2788 ErrPrint("Client %d is not exists\n", pid);
2789 ret = LB_STATUS_ERROR_NOT_EXIST;
2793 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2795 ErrPrint("Invalid parameter\n");
2796 ret = LB_STATUS_ERROR_INVALID;
2800 ret = validate_request(pkgname, id, &inst, &pkg);
2801 if (ret != LB_STATUS_SUCCESS) {
2805 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2806 ret = forward_pd_event_packet(pkg, inst, packet);
2807 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2808 struct script_info *script;
2811 script = instance_pd_script(inst);
2813 ret = LB_STATUS_ERROR_FAULT;
2817 e = script_handler_evas(script);
2819 ret = LB_STATUS_ERROR_FAULT;
2823 script_handler_update_pointer(script, x, y, -1);
2825 * \TODO: Push up the KEY_DOWN event
2829 ErrPrint("Unsupported package\n");
2830 ret = LB_STATUS_ERROR_INVALID;
2834 /*! \note No reply packet */
2838 static struct packet *client_pause_request(pid_t pid, int handle, const struct packet *packet)
2840 struct client_node *client;
2844 client = client_find_by_rpc_handle(handle);
2846 ErrPrint("Client %d is paused - manually reported\n", pid);
2847 ret = LB_STATUS_ERROR_NOT_EXIST;
2851 ret = packet_get(packet, "d", ×tamp);
2853 ErrPrint("Invalid parameter\n");
2854 ret = LB_STATUS_ERROR_INVALID;
2859 DbgPrint("XMONITOR enabled. ignore client paused request\n");
2861 xmonitor_pause(client);
2868 static struct packet *client_resume_request(pid_t pid, int handle, const struct packet *packet)
2870 struct client_node *client;
2874 client = client_find_by_rpc_handle(handle);
2876 ErrPrint("Client %d is not exists\n", pid);
2880 ret = packet_get(packet, "d", ×tamp);
2882 ErrPrint("Invalid parameter\n");
2887 DbgPrint("XMONITOR enabled. ignore client resumed request\n");
2889 xmonitor_resume(client);
2896 static struct packet *client_pd_key_up(pid_t pid, int handle, const struct packet *packet)
2898 struct client_node *client;
2899 const char *pkgname;
2905 struct inst_info *inst = NULL;
2906 const struct pkg_info *pkg = NULL;
2908 client = client_find_by_rpc_handle(handle);
2910 ErrPrint("Client %d is not exists\n", pid);
2911 ret = LB_STATUS_ERROR_NOT_EXIST;
2915 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2917 ErrPrint("Invalid parameter\n");
2918 ret = LB_STATUS_ERROR_INVALID;
2922 ret = validate_request(pkgname, id, &inst, &pkg);
2923 if (ret != LB_STATUS_SUCCESS) {
2927 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2928 ret = forward_pd_event_packet(pkg, inst, packet);
2929 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2930 struct script_info *script;
2933 script = instance_pd_script(inst);
2935 ret = LB_STATUS_ERROR_FAULT;
2939 e = script_handler_evas(script);
2941 ret = LB_STATUS_ERROR_FAULT;
2945 script_handler_update_pointer(script, x, y, -1);
2947 * \TODO: Push up the KEY_UP event
2951 ErrPrint("Unsupported package\n");
2952 ret = LB_STATUS_ERROR_INVALID;
2956 /*! \note No reply packet */
2960 static struct packet *client_lb_access_hl(pid_t pid, int handle, const struct packet *packet)
2962 struct packet *result;
2963 struct client_node *client;
2964 const char *pkgname;
2970 struct inst_info *inst = NULL;
2971 const struct pkg_info *pkg = NULL;
2973 client = client_find_by_rpc_handle(handle);
2975 ErrPrint("Client %d is not exists\n", pid);
2976 ret = LB_STATUS_ERROR_NOT_EXIST;
2980 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2982 ErrPrint("Parameter is not matched\n");
2983 ret = LB_STATUS_ERROR_INVALID;
2987 ret = validate_request(pkgname, id, &inst, &pkg);
2988 if (ret != LB_STATUS_SUCCESS) {
2992 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2993 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2994 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2995 struct script_info *script;
2998 script = instance_lb_script(inst);
3000 ret = LB_STATUS_ERROR_FAULT;
3004 e = script_handler_evas(script);
3006 ret = LB_STATUS_ERROR_FAULT;
3010 script_handler_update_pointer(script, x, y, -1);
3011 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT, timestamp);
3013 struct access_cbdata *cbdata;
3015 cbdata = malloc(sizeof(*cbdata));
3017 ret = LB_STATUS_ERROR_MEMORY;
3019 cbdata->inst = instance_ref(inst);
3020 cbdata->status = ret;
3022 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3023 (void)instance_unref(cbdata->inst);
3025 ret = LB_STATUS_ERROR_FAULT;
3027 ret = LB_STATUS_SUCCESS;
3032 ErrPrint("Unsupported package\n");
3033 ret = LB_STATUS_ERROR_INVALID;
3037 result = packet_create_reply(packet, "i", ret);
3039 ErrPrint("Failed to create a reply packet\n");
3045 static struct packet *client_lb_access_hl_prev(pid_t pid, int handle, const struct packet *packet)
3047 struct packet *result;
3048 struct client_node *client;
3049 const char *pkgname;
3055 struct inst_info *inst = NULL;
3056 const struct pkg_info *pkg = NULL;
3058 client = client_find_by_rpc_handle(handle);
3060 ErrPrint("Client %d is not exists\n", pid);
3061 ret = LB_STATUS_ERROR_NOT_EXIST;
3065 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3067 ErrPrint("Parameter is not matched\n");
3068 ret = LB_STATUS_ERROR_INVALID;
3072 ret = validate_request(pkgname, id, &inst, &pkg);
3073 if (ret != LB_STATUS_SUCCESS) {
3077 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3078 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3079 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3080 struct script_info *script;
3083 script = instance_lb_script(inst);
3085 ret = LB_STATUS_ERROR_FAULT;
3089 e = script_handler_evas(script);
3091 ret = LB_STATUS_ERROR_FAULT;
3095 script_handler_update_pointer(script, x, y, -1);
3096 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_PREV, timestamp);
3098 struct access_cbdata *cbdata;
3100 cbdata = malloc(sizeof(*cbdata));
3102 ret = LB_STATUS_ERROR_MEMORY;
3104 cbdata->inst = instance_ref(inst);
3105 cbdata->status = ret;
3107 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3108 (void)instance_unref(cbdata->inst);
3110 ret = LB_STATUS_ERROR_FAULT;
3112 ret = LB_STATUS_SUCCESS;
3117 ErrPrint("Unsupported package\n");
3118 ret = LB_STATUS_ERROR_INVALID;
3122 result = packet_create_reply(packet, "i", ret);
3124 ErrPrint("Failed to create a reply packet\n");
3130 static struct packet *client_lb_access_hl_next(pid_t pid, int handle, const struct packet *packet)
3132 struct packet *result;
3133 struct client_node *client;
3134 const char *pkgname;
3140 struct inst_info *inst = NULL;
3141 const struct pkg_info *pkg = NULL;
3143 client = client_find_by_rpc_handle(handle);
3145 ErrPrint("Client %d is not exists\n", pid);
3146 ret = LB_STATUS_ERROR_NOT_EXIST;
3150 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3152 ErrPrint("Parameter is not matched\n");
3153 ret = LB_STATUS_ERROR_INVALID;
3157 ret = validate_request(pkgname, id, &inst, &pkg);
3158 if (ret != LB_STATUS_SUCCESS) {
3162 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3163 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3164 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3165 struct script_info *script;
3168 script = instance_lb_script(inst);
3170 ret = LB_STATUS_ERROR_FAULT;
3174 e = script_handler_evas(script);
3176 ret = LB_STATUS_ERROR_FAULT;
3180 script_handler_update_pointer(script, x, y, -1);
3181 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT, timestamp);
3183 struct access_cbdata *cbdata;
3185 cbdata = malloc(sizeof(*cbdata));
3187 ret = LB_STATUS_ERROR_MEMORY;
3189 cbdata->inst = instance_ref(inst);
3190 cbdata->status = ret;
3192 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3193 (void)instance_unref(cbdata->inst);
3195 ret = LB_STATUS_ERROR_FAULT;
3197 ret = LB_STATUS_SUCCESS;
3202 ErrPrint("Unsupported package\n");
3203 ret = LB_STATUS_ERROR_INVALID;
3207 result = packet_create_reply(packet, "i", ret);
3209 ErrPrint("Failed to create a reply packet\n");
3215 static struct packet *client_lb_access_action_up(pid_t pid, int handle, const struct packet *packet)
3217 struct packet *result;
3218 struct client_node *client;
3219 const char *pkgname;
3223 struct inst_info *inst = NULL;
3224 const struct pkg_info *pkg = NULL;
3228 client = client_find_by_rpc_handle(handle);
3230 ErrPrint("Client %d is not exist\n", pid);
3231 ret = LB_STATUS_ERROR_NOT_EXIST;
3235 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3237 ErrPrint("Parameter is not matched\n");
3238 ret = LB_STATUS_ERROR_INVALID;
3242 ret = validate_request(pkgname, id, &inst, &pkg);
3243 if (ret != LB_STATUS_SUCCESS) {
3247 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3248 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3250 * Enen if it fails to send packet,
3251 * The packet will be unref'd
3252 * So we don't need to check the ret value.
3254 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3255 struct script_info *script;
3258 script = instance_lb_script(inst);
3260 ErrPrint("Instance has no script\n");
3261 ret = LB_STATUS_ERROR_FAULT;
3265 e = script_handler_evas(script);
3267 ErrPrint("Script has no evas\n");
3268 ret = LB_STATUS_ERROR_INVALID;
3272 script_handler_update_pointer(script, x, y, 0);
3273 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
3275 struct access_cbdata *cbdata;
3277 cbdata = malloc(sizeof(*cbdata));
3279 ret = LB_STATUS_ERROR_MEMORY;
3281 cbdata->inst = instance_ref(inst);
3282 cbdata->status = ret;
3284 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3285 (void)instance_unref(cbdata->inst);
3287 ret = LB_STATUS_ERROR_FAULT;
3289 ret = LB_STATUS_SUCCESS;
3294 ErrPrint("Unsupported package\n");
3295 ret = LB_STATUS_ERROR_INVALID;
3299 result = packet_create_reply(packet, "i", ret);
3301 ErrPrint("Failed to create a reply packet\n");
3307 static struct packet *client_lb_access_action_down(pid_t pid, int handle, const struct packet *packet)
3309 struct packet *result;
3310 struct client_node *client;
3311 const char *pkgname;
3315 struct inst_info *inst = NULL;
3316 const struct pkg_info *pkg = NULL;
3320 client = client_find_by_rpc_handle(handle);
3322 ErrPrint("Client %d is not exist\n", pid);
3323 ret = LB_STATUS_ERROR_NOT_EXIST;
3327 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3329 ErrPrint("Parameter is not matched\n");
3330 ret = LB_STATUS_ERROR_INVALID;
3334 ret = validate_request(pkgname, id, &inst, &pkg);
3335 if (ret != LB_STATUS_SUCCESS) {
3339 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3340 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3342 * Enen if it fails to send packet,
3343 * The packet will be unref'd
3344 * So we don't need to check the ret value.
3346 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3347 struct script_info *script;
3350 script = instance_lb_script(inst);
3352 ErrPrint("Instance has no script\n");
3353 ret = LB_STATUS_ERROR_FAULT;
3357 e = script_handler_evas(script);
3359 ErrPrint("Script has no evas\n");
3360 ret = LB_STATUS_ERROR_INVALID;
3364 script_handler_update_pointer(script, x, y, 1);
3365 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
3367 struct access_cbdata *cbdata;
3369 cbdata = malloc(sizeof(*cbdata));
3371 ret = LB_STATUS_ERROR_MEMORY;
3373 cbdata->inst = instance_ref(inst);
3374 cbdata->status = ret;
3376 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3377 (void)instance_unref(cbdata->inst);
3379 ret = LB_STATUS_ERROR_FAULT;
3381 ret = LB_STATUS_SUCCESS;
3386 ErrPrint("Unsupported package\n");
3387 ret = LB_STATUS_ERROR_INVALID;
3391 result = packet_create_reply(packet, "i", ret);
3393 ErrPrint("Failed to create a reply packet\n");
3399 static struct packet *client_lb_access_unhighlight(pid_t pid, int handle, const struct packet *packet)
3401 struct packet *result;
3402 struct client_node *client;
3403 const char *pkgname;
3409 struct inst_info *inst = NULL;
3410 const struct pkg_info *pkg = NULL;
3412 client = client_find_by_rpc_handle(handle);
3414 ErrPrint("Client %d is not exists\n", pid);
3415 ret = LB_STATUS_ERROR_NOT_EXIST;
3419 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3421 ErrPrint("Parameter is not matched\n");
3422 ret = LB_STATUS_ERROR_INVALID;
3426 ret = validate_request(pkgname, id, &inst, &pkg);
3427 if (ret != LB_STATUS_SUCCESS) {
3431 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3432 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3433 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3434 struct script_info *script;
3437 script = instance_lb_script(inst);
3439 ret = LB_STATUS_ERROR_FAULT;
3443 e = script_handler_evas(script);
3445 ret = LB_STATUS_ERROR_FAULT;
3449 script_handler_update_pointer(script, x, y, -1);
3450 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_UNHIGHLIGHT, timestamp);
3452 struct access_cbdata *cbdata;
3454 cbdata = malloc(sizeof(*cbdata));
3456 ret = LB_STATUS_ERROR_MEMORY;
3458 cbdata->inst = instance_ref(inst);
3459 cbdata->status = ret;
3461 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3462 (void)instance_unref(cbdata->inst);
3464 ret = LB_STATUS_ERROR_FAULT;
3466 ret = LB_STATUS_SUCCESS;
3471 ErrPrint("Unsupported package\n");
3472 ret = LB_STATUS_ERROR_INVALID;
3476 result = packet_create_reply(packet, "i", ret);
3478 ErrPrint("Failed to create a reply packet\n");
3484 static struct packet *client_lb_access_scroll_down(pid_t pid, int handle, const struct packet *packet)
3486 struct packet *result;
3487 struct client_node *client;
3488 const char *pkgname;
3492 struct inst_info *inst = NULL;
3493 const struct pkg_info *pkg = NULL;
3497 client = client_find_by_rpc_handle(handle);
3499 ErrPrint("Client %d is not exist\n", pid);
3500 ret = LB_STATUS_ERROR_NOT_EXIST;
3504 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3506 ErrPrint("Parameter is not matched\n");
3507 ret = LB_STATUS_ERROR_INVALID;
3511 ret = validate_request(pkgname, id, &inst, &pkg);
3512 if (ret != LB_STATUS_SUCCESS) {
3516 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3517 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3519 * Enen if it fails to send packet,
3520 * The packet will be unref'd
3521 * So we don't need to check the ret value.
3523 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3524 struct script_info *script;
3527 script = instance_lb_script(inst);
3529 ErrPrint("Instance has no script\n");
3530 ret = LB_STATUS_ERROR_FAULT;
3534 e = script_handler_evas(script);
3536 ErrPrint("Instance has no evas\n");
3537 ret = LB_STATUS_ERROR_INVALID;
3541 script_handler_update_pointer(script, x, y, 1);
3542 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
3544 struct access_cbdata *cbdata;
3546 cbdata = malloc(sizeof(*cbdata));
3548 ret = LB_STATUS_ERROR_MEMORY;
3550 cbdata->inst = instance_ref(inst);
3551 cbdata->status = ret;
3553 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3554 (void)instance_unref(cbdata->inst);
3556 ret = LB_STATUS_ERROR_FAULT;
3558 ret = LB_STATUS_SUCCESS;
3563 ErrPrint("Unsupported package\n");
3564 ret = LB_STATUS_ERROR_INVALID;
3568 result = packet_create_reply(packet, "i", ret);
3570 ErrPrint("Failed to create a reply packet\n");
3576 static struct packet *client_lb_access_scroll_move(pid_t pid, int handle, const struct packet *packet)
3578 struct packet *result;
3579 struct client_node *client;
3580 const char *pkgname;
3584 struct inst_info *inst = NULL;
3585 const struct pkg_info *pkg = NULL;
3589 client = client_find_by_rpc_handle(handle);
3591 ErrPrint("Client %d is not exist\n", pid);
3592 ret = LB_STATUS_ERROR_NOT_EXIST;
3596 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3598 ErrPrint("Parameter is not matched\n");
3599 ret = LB_STATUS_ERROR_INVALID;
3603 ret = validate_request(pkgname, id, &inst, &pkg);
3604 if (ret != LB_STATUS_SUCCESS) {
3608 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3609 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3611 * Enen if it fails to send packet,
3612 * The packet will be unref'd
3613 * So we don't need to check the ret value.
3615 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3616 struct script_info *script;
3619 script = instance_lb_script(inst);
3621 ErrPrint("Instance has no script\n");
3622 ret = LB_STATUS_ERROR_FAULT;
3626 e = script_handler_evas(script);
3628 ErrPrint("Instance has no evas\n");
3629 ret = LB_STATUS_ERROR_INVALID;
3633 script_handler_update_pointer(script, x, y, -1);
3634 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
3636 struct access_cbdata *cbdata;
3638 cbdata = malloc(sizeof(*cbdata));
3640 ret = LB_STATUS_ERROR_MEMORY;
3642 cbdata->inst = instance_ref(inst);
3643 cbdata->status = ret;
3645 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3646 (void)instance_unref(cbdata->inst);
3648 ret = LB_STATUS_ERROR_FAULT;
3650 ret = LB_STATUS_SUCCESS;
3655 ErrPrint("Unsupported package\n");
3656 ret = LB_STATUS_ERROR_INVALID;
3660 result = packet_create_reply(packet, "i", ret);
3662 ErrPrint("Failed to create a reply packet\n");
3668 static struct packet *client_lb_access_scroll_up(pid_t pid, int handle, const struct packet *packet)
3670 struct packet *result;
3671 struct client_node *client;
3672 const char *pkgname;
3676 struct inst_info *inst = NULL;
3677 const struct pkg_info *pkg = NULL;
3681 client = client_find_by_rpc_handle(handle);
3683 ErrPrint("Client %d is not exist\n", pid);
3684 ret = LB_STATUS_ERROR_NOT_EXIST;
3688 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3690 ErrPrint("Parameter is not matched\n");
3691 ret = LB_STATUS_ERROR_INVALID;
3695 ret = validate_request(pkgname, id, &inst, &pkg);
3696 if (ret != LB_STATUS_SUCCESS) {
3700 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3701 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3703 * Enen if it fails to send packet,
3704 * The packet will be unref'd
3705 * So we don't need to check the ret value.
3707 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3708 struct script_info *script;
3711 script = instance_lb_script(inst);
3713 ErrPrint("Instance has no script\n");
3714 ret = LB_STATUS_ERROR_FAULT;
3718 e = script_handler_evas(script);
3720 ErrPrint("Instance has no evas\n");
3721 ret = LB_STATUS_ERROR_INVALID;
3725 script_handler_update_pointer(script, x, y, 0);
3726 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
3728 struct access_cbdata *cbdata;
3730 cbdata = malloc(sizeof(*cbdata));
3732 ret = LB_STATUS_ERROR_MEMORY;
3734 cbdata->inst = instance_ref(inst);
3735 cbdata->status = ret;
3737 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3738 (void)instance_unref(cbdata->inst);
3740 ret = LB_STATUS_ERROR_FAULT;
3742 ret = LB_STATUS_SUCCESS;
3747 ErrPrint("Unsupported package\n");
3748 ret = LB_STATUS_ERROR_INVALID;
3752 result = packet_create_reply(packet, "i", ret);
3754 ErrPrint("Failed to create a reply packet\n");
3760 static struct packet *client_lb_access_activate(pid_t pid, int handle, const struct packet *packet)
3762 struct packet *result;
3763 struct client_node *client;
3764 const char *pkgname;
3770 struct inst_info *inst = NULL;
3771 const struct pkg_info *pkg = NULL;
3773 client = client_find_by_rpc_handle(handle);
3775 ErrPrint("Client %d is not exists\n", pid);
3776 ret = LB_STATUS_ERROR_NOT_EXIST;
3780 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3782 ErrPrint("Parameter is not matched\n");
3783 ret = LB_STATUS_ERROR_INVALID;
3787 ret = validate_request(pkgname, id, &inst, &pkg);
3788 if (ret != LB_STATUS_SUCCESS) {
3792 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3793 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3794 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3795 struct script_info *script;
3798 script = instance_lb_script(inst);
3800 ErrPrint("Instance has no script\n");
3801 ret = LB_STATUS_ERROR_FAULT;
3805 e = script_handler_evas(script);
3807 ErrPrint("Script has no Evas\n");
3808 ret = LB_STATUS_ERROR_INVALID;
3812 script_handler_update_pointer(script, x, y, -1);
3813 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTIVATE, timestamp);
3815 struct access_cbdata *cbdata;
3817 cbdata = malloc(sizeof(*cbdata));
3819 ret = LB_STATUS_ERROR_MEMORY;
3821 cbdata->inst = instance_ref(inst);
3822 cbdata->status = ret;
3824 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3825 (void)instance_unref(cbdata->inst);
3827 ret = LB_STATUS_ERROR_FAULT;
3829 ret = LB_STATUS_SUCCESS;
3834 ErrPrint("Unsupported package\n");
3835 ret = LB_STATUS_ERROR_INVALID;
3839 result = packet_create_reply(packet, "i", ret);
3841 ErrPrint("Failed to create a reply packet\n");
3847 static struct packet *client_lb_key_down(pid_t pid, int handle, const struct packet *packet)
3849 struct client_node *client;
3850 const char *pkgname;
3856 struct inst_info *inst = NULL;
3857 const struct pkg_info *pkg = NULL;
3859 client = client_find_by_rpc_handle(handle);
3861 ErrPrint("Client %d is not exists\n", pid);
3862 ret = LB_STATUS_ERROR_NOT_EXIST;
3866 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3868 ErrPrint("Parameter is not matched\n");
3869 ret = LB_STATUS_ERROR_INVALID;
3873 ret = validate_request(pkgname, id, &inst, &pkg);
3874 if (ret != LB_STATUS_SUCCESS) {
3878 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3879 ret = forward_lb_event_packet(pkg, inst, packet);
3880 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3881 struct script_info *script;
3884 script = instance_lb_script(inst);
3886 ret = LB_STATUS_ERROR_FAULT;
3890 e = script_handler_evas(script);
3892 ret = LB_STATUS_ERROR_FAULT;
3896 script_handler_update_pointer(script, x, y, -1);
3899 * \TODO: Feed up this KEY_DOWN event
3903 ErrPrint("Unsupported package\n");
3904 ret = LB_STATUS_ERROR_INVALID;
3908 /*! \note No reply packet */
3912 static struct packet *client_lb_key_up(pid_t pid, int handle, const struct packet *packet)
3914 struct client_node *client;
3915 const char *pkgname;
3921 struct inst_info *inst = NULL;
3922 const struct pkg_info *pkg = NULL;
3924 client = client_find_by_rpc_handle(handle);
3926 ErrPrint("Client %d is not exists\n", pid);
3927 ret = LB_STATUS_ERROR_NOT_EXIST;
3931 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3933 ErrPrint("Parameter is not matched\n");
3934 ret = LB_STATUS_ERROR_INVALID;
3938 ret = validate_request(pkgname, id, &inst, &pkg);
3939 if (ret != LB_STATUS_SUCCESS) {
3943 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3944 ret = forward_lb_event_packet(pkg, inst, packet);
3945 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3946 struct script_info *script;
3949 script = instance_lb_script(inst);
3951 ret = LB_STATUS_ERROR_FAULT;
3955 e = script_handler_evas(script);
3957 ret = LB_STATUS_ERROR_FAULT;
3961 script_handler_update_pointer(script, x, y, -1);
3964 * \TODO: Feed up this KEY_UP event
3968 ErrPrint("Unsupported package\n");
3969 ret = LB_STATUS_ERROR_INVALID;
3973 /*! \note No reply packet */
3977 static int release_pixmap_cb(struct client_node *client, void *canvas)
3979 DbgPrint("Forcely unref the \"buffer\"\n");
3980 buffer_handler_pixmap_unref(canvas);
3981 return -1; /* Delete this callback */
3984 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 */
3986 struct packet *result;
3987 const char *pkgname;
3989 struct client_node *client;
3990 struct inst_info *inst = NULL;
3994 struct buffer_info *buffer;
3996 client = client_find_by_rpc_handle(handle);
3998 ErrPrint("Client %d is not exists\n", pid);
3999 ret = LB_STATUS_ERROR_INVALID;
4003 ret = packet_get(packet, "ss", &pkgname, &id);
4005 ErrPrint("Parameter is not matched\n");
4006 ret = LB_STATUS_ERROR_INVALID;
4010 ret = validate_request(pkgname, id, &inst, NULL);
4011 if (ret != LB_STATUS_SUCCESS) {
4015 buffer = instance_lb_buffer(inst);
4017 struct script_info *script_info;
4018 struct fb_info *fb_info;
4020 script_info = instance_lb_script(inst);
4022 ErrPrint("Unable to get LB buffer: %s\n", id);
4023 ret = LB_STATUS_ERROR_FAULT;
4027 fb_info = script_handler_fb(script_info);
4029 ErrPrint("Unable to get fb_info: %s\n", id);
4030 ret = LB_STATUS_ERROR_FAULT;
4034 buffer = fb_buffer_info(fb_info);
4036 ErrPrint("Unable to get buffer_info: %s\n", id);
4037 ret = LB_STATUS_ERROR_FAULT;
4042 buf_ptr = buffer_handler_pixmap_ref(buffer);
4044 ErrPrint("Failed to ref pixmap\n");
4045 ret = LB_STATUS_ERROR_FAULT;
4049 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
4051 ErrPrint("Failed to add a new client deactivate callback\n");
4052 buffer_handler_pixmap_unref(buf_ptr);
4054 pixmap = buffer_handler_pixmap(buffer);
4055 ret = LB_STATUS_SUCCESS;
4059 result = packet_create_reply(packet, "ii", pixmap, ret);
4061 ErrPrint("Failed to create a reply packet\n");
4067 static struct packet *client_lb_release_pixmap(pid_t pid, int handle, const struct packet *packet)
4069 const char *pkgname;
4071 struct client_node *client;
4072 struct inst_info *inst = NULL;
4077 client = client_find_by_rpc_handle(handle);
4079 ErrPrint("Client %d is not exists\n", pid);
4083 ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
4085 ErrPrint("Parameter is not matched\n");
4089 ret = validate_request(pkgname, id, &inst, NULL);
4090 if (ret != LB_STATUS_SUCCESS) {
4094 buf_ptr = buffer_handler_pixmap_find(pixmap);
4096 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
4100 if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) {
4101 buffer_handler_pixmap_unref(buf_ptr);
4105 /*! \note No reply packet */
4109 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 */
4111 struct packet *result;
4112 const char *pkgname;
4114 struct client_node *client;
4115 struct inst_info *inst = NULL;
4119 struct buffer_info *buffer;
4121 client = client_find_by_rpc_handle(handle);
4123 ret = LB_STATUS_ERROR_INVALID;
4124 ErrPrint("Client %d is not exists\n", pid);
4128 ret = packet_get(packet, "ss", &pkgname, &id);
4130 ret = LB_STATUS_ERROR_INVALID;
4131 ErrPrint("Parameter is not matched\n");
4135 ret = validate_request(pkgname, id, &inst, NULL);
4136 if (ret != LB_STATUS_SUCCESS) {
4140 if (instance_get_data(inst, "pd,resize,monitor")) {
4141 ret = LB_STATUS_ERROR_BUSY;
4145 buffer = instance_pd_buffer(inst);
4147 struct script_info *script_info;
4148 struct fb_info *fb_info;
4150 script_info = instance_pd_script(inst);
4152 ErrPrint("Unable to get LB buffer: %s\n", id);
4153 ret = LB_STATUS_ERROR_FAULT;
4157 fb_info = script_handler_fb(script_info);
4159 ErrPrint("Unable to get fb_info: %s\n", id);
4160 ret = LB_STATUS_ERROR_FAULT;
4164 buffer = fb_buffer_info(fb_info);
4166 ErrPrint("Unable to get buffer_info: %s\n", id);
4167 ret = LB_STATUS_ERROR_FAULT;
4172 buf_ptr = buffer_handler_pixmap_ref(buffer);
4174 ErrPrint("Failed to ref pixmap\n");
4175 ret = LB_STATUS_ERROR_FAULT;
4179 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
4181 buffer_handler_pixmap_unref(buf_ptr);
4184 pixmap = buffer_handler_pixmap(buffer);
4186 result = packet_create_reply(packet, "ii", pixmap, ret);
4188 ErrPrint("Failed to create a reply packet\n");
4194 static struct packet *client_pd_release_pixmap(pid_t pid, int handle, const struct packet *packet)
4196 const char *pkgname;
4198 struct client_node *client;
4203 client = client_find_by_rpc_handle(handle);
4205 ErrPrint("Client %d is not exists\n", pid);
4209 ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
4211 ErrPrint("Parameter is not matched\n");
4215 ret = validate_request(pkgname, id, NULL, NULL);
4216 if (ret != LB_STATUS_SUCCESS) {
4220 buf_ptr = buffer_handler_pixmap_find(pixmap);
4222 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
4226 if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) {
4227 buffer_handler_pixmap_unref(buf_ptr);
4231 /*! \note No reply packet */
4235 static struct packet *client_pinup_changed(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, pinup, ret */
4237 struct client_node *client;
4238 struct packet *result;
4239 const char *pkgname;
4243 struct inst_info *inst = NULL;
4245 client = client_find_by_rpc_handle(handle);
4247 ErrPrint("Client %d is not exists\n", pid);
4248 ret = LB_STATUS_ERROR_NOT_EXIST;
4253 ret = packet_get(packet, "ssi", &pkgname, &id, &pinup);
4255 ErrPrint("Parameter is not matched\n");
4256 ret = LB_STATUS_ERROR_INVALID;
4261 ret = validate_request(pkgname, id, &inst, NULL);
4262 if (ret == LB_STATUS_SUCCESS) {
4263 ret = instance_set_pinup(inst, pinup);
4267 result = packet_create_reply(packet, "i", ret);
4269 ErrPrint("Failed to create a packet\n");
4275 static Eina_Bool lazy_pd_created_cb(void *inst)
4277 struct pkg_info *pkg;
4279 if (!instance_del_data(inst, "lazy,pd,open")) {
4280 ErrPrint("lazy,pd,open is already deleted.\n");
4281 return ECORE_CALLBACK_CANCEL;
4284 pkg = instance_package(inst);
4286 struct slave_node *slave;
4288 slave = package_slave(pkg);
4290 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst);
4295 * After unref instance first,
4296 * if the instance is not destroyed, try to notify the created PD event to the client.
4298 if (instance_unref(inst)) {
4300 ret = instance_client_pd_created(inst, LB_STATUS_SUCCESS);
4301 DbgPrint("Send PD Create event (%d) to client\n", ret);
4304 return ECORE_CALLBACK_CANCEL;
4307 static Eina_Bool lazy_pd_destroyed_cb(void *inst)
4309 struct pkg_info *pkg;
4310 struct slave_node *slave;
4312 if (!instance_del_data(inst, "lazy,pd,close")) {
4313 ErrPrint("lazy,pd,close is already deleted.\n");
4314 return ECORE_CALLBACK_CANCEL;
4317 pkg = instance_package(inst);
4319 slave = package_slave(pkg);
4321 if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
4322 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst);
4323 } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
4324 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
4329 if (instance_unref(inst)) {
4331 ret = instance_client_pd_destroyed(inst, LB_STATUS_SUCCESS);
4333 ErrPrint("Failed sending PD Destroy event (%d)\n", ret);
4337 return ECORE_CALLBACK_CANCEL;
4340 static struct packet *client_pd_move(pid_t pid, int handle, const struct packet *packet) /* pkgname, id, x, y */
4342 struct client_node *client;
4343 struct inst_info *inst = NULL;
4344 const struct pkg_info *pkg = NULL;
4345 const char *pkgname;
4351 client = client_find_by_rpc_handle(handle);
4353 ErrPrint("Client %d is not exists\n", pid);
4354 ret = LB_STATUS_ERROR_NOT_EXIST;
4358 ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
4360 ErrPrint("Parameter is not correct\n");
4361 ret = LB_STATUS_ERROR_INVALID;
4365 ret = validate_request(pkgname, id, &inst, &pkg);
4366 if (ret != LB_STATUS_SUCCESS) {
4370 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
4371 instance_slave_set_pd_pos(inst, x, y);
4372 ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
4373 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
4377 instance_slave_set_pd_pos(inst, x, y);
4378 ix = x * instance_pd_width(inst);
4379 iy = y * instance_pd_height(inst);
4380 script_handler_update_pointer(instance_pd_script(inst), ix, iy, 0);
4381 ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
4383 ErrPrint("Invalid PD type\n");
4384 ret = LB_STATUS_ERROR_INVALID;
4387 DbgPrint("Update PD position: %d\n", ret);
4391 static Eina_Bool pd_open_monitor_cb(void *inst)
4394 struct pkg_info *pkg;
4396 pkg = instance_package(inst);
4398 struct slave_node *slave;
4400 slave = package_slave(pkg);
4402 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst);
4406 ret = instance_slave_close_pd(inst, instance_pd_owner(inst));
4407 ret = instance_client_pd_created(inst, LB_STATUS_ERROR_TIMEOUT);
4408 (void)instance_del_data(inst, "pd,open,monitor");
4409 (void)instance_unref(inst);
4410 ErrPrint("PD Open request is timed-out (%lf), ret: %d\n", PD_REQUEST_TIMEOUT, ret);
4411 return ECORE_CALLBACK_CANCEL;
4414 static Eina_Bool pd_close_monitor_cb(void *inst)
4417 struct pkg_info *pkg;
4419 pkg = instance_package(inst);
4421 struct slave_node *slave;
4423 slave = package_slave(pkg);
4425 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
4429 ret = instance_client_pd_destroyed(inst, LB_STATUS_ERROR_TIMEOUT);
4430 (void)instance_del_data(inst, "pd,close,monitor");
4431 (void)instance_unref(inst);
4432 ErrPrint("PD Close request is not processed in %lf seconds (%d)\n", PD_REQUEST_TIMEOUT, ret);
4433 return ECORE_CALLBACK_CANCEL;
4436 static Eina_Bool pd_resize_monitor_cb(void *inst)
4439 struct pkg_info *pkg;
4441 pkg = instance_package(inst);
4443 struct slave_node *slave;
4444 slave = package_slave(pkg);
4446 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst);
4450 ret = instance_slave_close_pd(inst, instance_pd_owner(inst));
4451 ret = instance_client_pd_destroyed(inst, LB_STATUS_ERROR_TIMEOUT);
4452 (void)instance_del_data(inst, "pd,resize,monitor");
4453 (void)instance_unref(inst);
4454 ErrPrint("PD Resize request is not processed in %lf seconds (%d)\n", PD_REQUEST_TIMEOUT, ret);
4455 return ECORE_CALLBACK_CANCEL;
4458 static struct packet *client_create_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
4460 struct client_node *client;
4461 struct packet *result;
4462 const char *pkgname;
4465 struct inst_info *inst = NULL;
4466 const struct pkg_info *pkg = NULL;
4467 Ecore_Timer *pd_monitor;
4471 DbgPrint("PERF_DBOX\n");
4473 client = client_find_by_rpc_handle(handle);
4475 ErrPrint("Client %d is not exists\n", pid);
4476 ret = LB_STATUS_ERROR_NOT_EXIST;
4480 ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
4482 ErrPrint("Parameter is not matched\n");
4483 ret = LB_STATUS_ERROR_INVALID;
4487 ret = validate_request(pkgname, id, &inst, &pkg);
4488 if (ret != LB_STATUS_SUCCESS) {
4492 if (instance_pd_owner(inst)) {
4493 ErrPrint("PD is already owned\n");
4494 ret = LB_STATUS_ERROR_ALREADY;
4495 } else if (package_pd_type(instance_package(inst)) == PD_TYPE_BUFFER) {
4496 pd_monitor = instance_get_data(inst, "lazy,pd,close");
4498 ecore_timer_del(pd_monitor);
4499 /* This timer attribute will be deleted */
4500 lazy_pd_destroyed_cb(inst);
4503 if (instance_get_data(inst, "pd,open,monitor")) {
4504 DbgPrint("PD Open request is already processed\n");
4505 ret = LB_STATUS_ERROR_ALREADY;
4509 if (instance_get_data(inst, "pd,close,monitor")) {
4510 DbgPrint("PD Close request is already in process\n");
4511 ret = LB_STATUS_ERROR_BUSY;
4515 if (instance_get_data(inst, "pd,resize,monitor")) {
4516 DbgPrint("PD resize request is already in process\n");
4517 ret = LB_STATUS_ERROR_BUSY;
4521 instance_slave_set_pd_pos(inst, x, y);
4524 * Send request to the slave.
4525 * The SLAVE must has to repsonse this via "release_buffer" method.
4527 ret = instance_slave_open_pd(inst, client);
4528 if (ret == LB_STATUS_SUCCESS) {
4529 ret = instance_signal_emit(inst, "pd,show", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
4530 if (ret != LB_STATUS_SUCCESS) {
4533 tmp_ret = instance_slave_close_pd(inst, client);
4534 ErrPrint("Unable to send script event for openning PD [%s], %d\n", pkgname, tmp_ret);
4536 pd_monitor = ecore_timer_add(PD_REQUEST_TIMEOUT, pd_open_monitor_cb, instance_ref(inst));
4538 (void)instance_unref(inst);
4539 ErrPrint("Failed to create a timer for PD Open monitor\n");
4541 struct slave_node *slave;
4543 (void)instance_set_data(inst, "pd,open,monitor", pd_monitor);
4545 slave = package_slave(pkg);
4547 ErrPrint("Failed to get slave(%s)\n", pkgname);
4551 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) != LB_STATUS_SUCCESS) {
4552 ErrPrint("Failed to add fault handler: %s\n");
4557 ErrPrint("Unable to send request for openning PD [%s]\n", pkgname);
4562 * PD craeted event will be send by the acquire_buffer function.
4563 * Because the slave will make request the acquire_buffer to
4566 * instance_client_pd_created(inst);
4568 } else if (package_pd_type(instance_package(inst)) == PD_TYPE_SCRIPT) {
4572 pd_monitor = instance_get_data(inst, "lazy,pd,close");
4574 ecore_timer_del(pd_monitor);
4575 /* lazy,pd,close will be deleted */
4576 lazy_pd_destroyed_cb(inst);
4581 * ret value should be cared but in this case,
4582 * we ignore this for this moment, so we have to handle this error later.
4584 * if ret is less than 0, the slave has some problem.
4585 * but the script mode doesn't need slave for rendering default view of PD
4586 * so we can hanle it later.
4588 instance_slave_set_pd_pos(inst, x, y);
4589 ix = x * instance_pd_width(inst);
4590 iy = y * instance_pd_height(inst);
4592 script_handler_update_pointer(instance_pd_script(inst), ix, iy, 0);
4594 ret = instance_slave_open_pd(inst, client);
4595 if (ret == LB_STATUS_SUCCESS) {
4596 ret = script_handler_load(instance_pd_script(inst), 1);
4600 * Send the PD created event to the clients,
4602 if (ret == LB_STATUS_SUCCESS) {
4606 * But the created event has to be send afte return
4607 * from this function or the viewer couldn't care
4608 * the event correctly.
4610 inst = instance_ref(inst); /* To guarantee the inst */
4614 * At here, we don't need to rememeber the timer object.
4615 * Even if the timer callback is called, after the instance is destroyed.
4616 * lazy_pd_created_cb will decrease the instance refcnt first.
4617 * At that time, if the instance is released, the timer callback will do nothing.
4620 * I change my mind. There is no requirements to keep the timer handler.
4621 * But I just add it to the tagged-data of the instance.
4622 * Just reserve for future-use.
4624 pd_monitor = ecore_timer_add(DELAY_TIME, lazy_pd_created_cb, inst);
4626 ret = script_handler_unload(instance_pd_script(inst), 1);
4627 ErrPrint("Unload script: %d\n", ret);
4629 ret = instance_slave_close_pd(inst, client);
4630 ErrPrint("Close PD %d\n", ret);
4632 inst = instance_unref(inst);
4634 DbgPrint("Instance destroyed\n");
4637 ErrPrint("Instance: %s\n", pkgname);
4639 ret = LB_STATUS_ERROR_FAULT;
4641 struct slave_node *slave;
4643 (void)instance_set_data(inst, "lazy,pd,open", pd_monitor);
4645 slave = package_slave(pkg);
4647 ErrPrint("Failed to get slave: %s\n", pkgname);
4651 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst) != LB_STATUS_SUCCESS) {
4652 ErrPrint("Failed to add fault callback: %s\n", pkgname);
4657 tmp_ret = instance_slave_close_pd(inst, client);
4658 ErrPrint("Unable to load script: %d, (close: %d)\n", ret, tmp_ret);
4661 ErrPrint("Unable open PD(%s): %d\n", pkgname, ret);
4664 ErrPrint("Invalid PD TYPE\n");
4665 ret = LB_STATUS_ERROR_INVALID;
4669 result = packet_create_reply(packet, "i", ret);
4671 ErrPrint("Failed to create a packet\n");
4677 static struct packet *client_destroy_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
4679 struct client_node *client;
4680 struct packet *result;
4681 const char *pkgname;
4684 struct inst_info *inst = NULL;
4685 const struct pkg_info *pkg = NULL;
4686 Ecore_Timer *pd_monitor;
4687 struct slave_node *slave;
4689 DbgPrint("PERF_DBOX\n");
4691 client = client_find_by_rpc_handle(handle);
4693 ErrPrint("Client %d is not exists\n", pid);
4694 ret = LB_STATUS_ERROR_NOT_EXIST;
4698 ret = packet_get(packet, "ss", &pkgname, &id);
4700 ErrPrint("Parameter is not matched\n");
4701 ret = LB_STATUS_ERROR_INVALID;
4705 ret = validate_request(pkgname, id, &inst, &pkg);
4706 if (ret != LB_STATUS_SUCCESS) {
4710 slave = package_slave(pkg);
4712 ret = LB_STATUS_ERROR_INVALID;
4716 if (instance_pd_owner(inst) != client) {
4717 if (instance_pd_owner(inst) == NULL) {
4718 ErrPrint("PD looks already closed\n");
4719 ret = LB_STATUS_ERROR_ALREADY;
4721 ErrPrint("PD owner mimatched\n");
4722 ret = LB_STATUS_ERROR_PERMISSION;
4724 } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
4725 int resize_aborted = 0;
4727 pd_monitor = instance_del_data(inst, "pd,open,monitor");
4730 ErrPrint("PD Open request is found. cancel it [%s]\n", pkgname);
4732 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst);
4736 * We should return negative value
4737 * Or we have to send "destroyed" event to the client.
4738 * If we didn't send destroyed event after return SUCCESS from here,
4739 * The client will permanently waiting destroyed event.
4740 * Because they understand that the destroy request is successfully processed.
4742 ret = LB_STATUS_ERROR_CANCEL;
4743 ret = instance_client_pd_created(inst, ret);
4745 ErrPrint("PD client create event: %d\n", ret);
4748 ret = instance_client_pd_destroyed(inst, LB_STATUS_SUCCESS);
4750 ErrPrint("PD client destroy event: %d\n", ret);
4753 ret = instance_signal_emit(inst, "pd,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
4755 ErrPrint("PD close signal emit failed: %d\n", ret);
4758 ret = instance_slave_close_pd(inst, client);
4760 ErrPrint("PD close request failed: %d\n", ret);
4763 ecore_timer_del(pd_monitor);
4764 (void)instance_unref(inst);
4768 if (instance_get_data(inst, "lazy,pd,close") || instance_get_data(inst, "pd,close,monitor")) {
4769 ret = LB_STATUS_ERROR_ALREADY;
4773 pd_monitor = instance_del_data(inst, "pd,resize,monitor");
4775 ErrPrint("PD Resize request is found. clear it [%s]\n", pkgname);
4776 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst);
4778 ecore_timer_del(pd_monitor);
4780 inst = instance_unref(inst);
4788 ret = instance_signal_emit(inst, "pd,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
4790 ErrPrint("PD close signal emit failed: %d\n", ret);
4793 ret = instance_slave_close_pd(inst, client);
4795 ErrPrint("PD close request failed: %d\n", ret);
4796 } else if (resize_aborted) {
4797 pd_monitor = ecore_timer_add(DELAY_TIME, lazy_pd_destroyed_cb, instance_ref(inst));
4799 ErrPrint("Failed to create a timer: %s\n", pkgname);
4800 (void)instance_unref(inst);
4802 (void)instance_set_data(inst, "lazy,pd,close", pd_monitor);
4803 slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
4806 pd_monitor = ecore_timer_add(PD_REQUEST_TIMEOUT, pd_close_monitor_cb, instance_ref(inst));
4808 (void)instance_unref(inst);
4809 ErrPrint("Failed to add pd close monitor\n");
4811 (void)instance_set_data(inst, "pd,close,monitor", pd_monitor);
4812 slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
4817 * release_buffer will be called by the slave after this.
4818 * Then it will send the "pd_destroyed" event to the client
4820 * instance_client_pd_destroyed(inst);
4822 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
4823 pd_monitor = instance_get_data(inst, "lazy,pd,open");
4825 ecore_timer_del(pd_monitor);
4826 lazy_pd_created_cb(inst);
4829 ret = script_handler_unload(instance_pd_script(inst), 1);
4831 ErrPrint("Unable to unload the script: %s, %d\n", pkgname, ret);
4836 * Send request to the slave.
4837 * The SLAVE must has to repsonse this via "release_buffer" method.
4839 ret = instance_slave_close_pd(inst, client);
4841 ErrPrint("Unable to close the PD: %s, %d\n", pkgname, ret);
4846 * Send the destroyed PD event to the client
4848 if (ret == LB_STATUS_SUCCESS) {
4852 * I change my mind. There is no requirements to keep the timer handler.
4853 * But I just add it to the tagged-data of the instance.
4854 * Just reserve for future-use.
4856 pd_monitor = ecore_timer_add(DELAY_TIME, lazy_pd_destroyed_cb, instance_ref(inst));
4858 ErrPrint("Failed to create a timer: %s\n", pkgname);
4859 (void)instance_unref(inst);
4861 (void)instance_set_data(inst, "lazy,pd,close", pd_monitor);
4862 slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst);
4866 ErrPrint("Invalid PD TYPE\n");
4867 ret = LB_STATUS_ERROR_INVALID;
4871 result = packet_create_reply(packet, "i", ret);
4873 ErrPrint("Failed to create a packet\n");
4879 static struct packet *client_activate_package(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, ret */
4881 struct client_node *client;
4882 struct packet *result;
4883 const char *pkgname;
4885 struct pkg_info *info;
4887 client = client_find_by_rpc_handle(handle);
4889 ErrPrint("Client %d is not exists\n", pid);
4890 ret = LB_STATUS_ERROR_NOT_EXIST;
4895 ret = packet_get(packet, "s", &pkgname);
4897 ErrPrint("Parameter is not matched\n");
4898 ret = LB_STATUS_ERROR_INVALID;
4903 DbgPrint("pid[%d] pkgname[%s]\n", pid, pkgname);
4907 * Validate the livebox package name.
4909 if (!package_is_lb_pkgname(pkgname)) {
4910 ErrPrint("%s is not a valid livebox package\n", pkgname);
4912 ret = LB_STATUS_ERROR_INVALID;
4916 info = package_find(pkgname);
4918 ret = LB_STATUS_ERROR_NOT_EXIST;
4920 ret = package_clear_fault(info);
4924 result = packet_create_reply(packet, "is", ret, pkgname);
4926 ErrPrint("Failed to create a packet\n");
4932 static struct packet *client_subscribed(pid_t pid, int handle, const struct packet *packet)
4934 const char *cluster;
4935 const char *category;
4936 struct client_node *client;
4939 client = client_find_by_rpc_handle(handle);
4941 ErrPrint("Client %d is not exists\n", pid);
4942 ret = LB_STATUS_ERROR_NOT_EXIST;
4946 ret = packet_get(packet, "ss", &cluster, &category);
4948 ErrPrint("Invalid argument\n");
4949 ret = LB_STATUS_ERROR_INVALID;
4953 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
4954 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
4955 ErrPrint("Invalid cluster name\n");
4961 * SUBSCRIBE cluster & sub-cluster for a client.
4963 ret = client_subscribe(client, cluster, category);
4965 package_alter_instances_to_client(client, ALTER_CREATE);
4969 /*! \note No reply packet */
4973 static struct packet *client_delete_cluster(pid_t pid, int handle, const struct packet *packet)
4975 const char *cluster;
4976 struct client_node *client;
4977 struct packet *result;
4980 client = client_find_by_rpc_handle(handle);
4982 ErrPrint("Client %d is not exists\n", pid);
4983 ret = LB_STATUS_ERROR_NOT_EXIST;
4987 ret = packet_get(packet, "s", &cluster);
4989 ErrPrint("Invalid parameters\n");
4990 ret = LB_STATUS_ERROR_INVALID;
4994 DbgPrint("pid[%d] cluster[%s]\n", pid, cluster);
4996 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
4997 ErrPrint("Invalid cluster: %s\n", cluster);
4998 ret = LB_STATUS_ERROR_INVALID;
5005 ret = LB_STATUS_ERROR_NOT_IMPLEMENTED;
5008 result = packet_create_reply(packet, "i", ret);
5010 ErrPrint("Failed to create a packet\n");
5016 static inline int update_pkg_cb(struct category *category, const char *pkgname)
5021 c_name = group_cluster_name_by_category(category);
5022 s_name = group_category_name(category);
5024 if (!c_name || !s_name || !pkgname) {
5025 ErrPrint("Name is not valid\n");
5026 return EXIT_FAILURE;
5029 DbgPrint("Send refresh request: %s (%s/%s)\n", pkgname, c_name, s_name);
5030 slave_rpc_request_update(pkgname, "", c_name, s_name);
5032 /* Just try to create a new package */
5033 if (util_free_space(IMAGE_PATH) > MINIMUM_SPACE) {
5035 struct inst_info *inst;
5037 timestamp = util_timestamp();
5040 * Don't need to check the subscribed clients.
5041 * Because this callback is called by the requests of clients.
5042 * It means. some clients wants to handle this instances ;)
5044 inst = instance_create(NULL, timestamp, pkgname, "", c_name, s_name, DEFAULT_PERIOD, 0, 0);
5046 ErrPrint("Failed to create a new instance\n");
5049 ErrPrint("Not enough space\n");
5051 return EXIT_SUCCESS;
5054 static struct packet *client_update(pid_t pid, int handle, const struct packet *packet)
5056 struct inst_info *inst = NULL;
5057 struct client_node *client;
5058 const char *pkgname;
5062 client = client_find_by_rpc_handle(handle);
5064 ErrPrint("Cilent %d is not exists\n", pid);
5068 ret = packet_get(packet, "ss", &pkgname, &id);
5070 ErrPrint("Invalid argument\n");
5074 ret = validate_request(pkgname, id, &inst, NULL);
5075 if (ret != LB_STATUS_SUCCESS) {
5079 if (instance_client(inst) != client) {
5081 ErrPrint("Insufficient permissions [%s] - %d\n", pkgname, pid);
5083 slave_rpc_request_update(pkgname, id, instance_cluster(inst), instance_category(inst));
5087 /*! \note No reply packet */
5091 static struct packet *client_refresh_group(pid_t pid, int handle, const struct packet *packet)
5093 const char *cluster_id;
5094 const char *category_id;
5095 struct client_node *client;
5097 struct cluster *cluster;
5098 struct category *category;
5099 struct context_info *info;
5100 Eina_List *info_list;
5103 client = client_find_by_rpc_handle(handle);
5105 ErrPrint("Cilent %d is not exists\n", pid);
5109 ret = packet_get(packet, "ss", &cluster_id, &category_id);
5111 ErrPrint("Invalid parameter\n");
5115 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster_id, category_id);
5117 if (!strlen(cluster_id) || !strcasecmp(cluster_id, DEFAULT_CLUSTER)) {
5118 ErrPrint("Invalid cluster name: %s\n", cluster_id);
5122 cluster = group_find_cluster(cluster_id);
5124 ErrPrint("Cluster [%s] is not registered\n", cluster_id);
5128 category = group_find_category(cluster, category_id);
5130 ErrPrint("Category [%s] is not registered\n", category_id);
5134 info_list = group_context_info_list(category);
5135 EINA_LIST_FOREACH(info_list, l, info) {
5136 update_pkg_cb(category, group_pkgname_from_context_info(info));
5140 /*! \note No reply packet */
5144 static struct packet *client_delete_category(pid_t pid, int handle, const struct packet *packet)
5146 const char *cluster;
5147 const char *category;
5148 struct client_node *client;
5149 struct packet *result;
5152 client = client_find_by_rpc_handle(handle);
5154 ErrPrint("Client %d is not exists\n", pid);
5155 ret = LB_STATUS_ERROR_NOT_EXIST;
5159 ret = packet_get(packet, "ss", &cluster, &category);
5161 ErrPrint("Invalid paramenters\n");
5162 ret = LB_STATUS_ERROR_INVALID;
5166 DbgPrint("pid[%d] cluster[%s] category[%s]\n", pid, cluster, category);
5167 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5168 ErrPrint("Invalid cluster: %s\n", cluster);
5169 ret = LB_STATUS_ERROR_INVALID;
5176 ret = LB_STATUS_ERROR_NOT_IMPLEMENTED;
5179 result = packet_create_reply(packet, "i", ret);
5181 ErrPrint("Failed to create a packet\n");
5187 static struct packet *client_unsubscribed(pid_t pid, int handle, const struct packet *packet)
5189 const char *cluster;
5190 const char *category;
5191 struct client_node *client;
5194 client = client_find_by_rpc_handle(handle);
5196 ErrPrint("Client %d is not exists\n", pid);
5197 ret = LB_STATUS_ERROR_NOT_EXIST;
5201 ret = packet_get(packet, "ss", &cluster, &category);
5203 ErrPrint("Invalid argument\n");
5204 ret = LB_STATUS_ERROR_INVALID;
5208 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
5210 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5211 ErrPrint("Invalid cluster name: %s\n", cluster);
5217 * UNSUBSCRIBE cluster & sub-cluster for a client.
5219 ret = client_unsubscribe(client, cluster, category);
5221 package_alter_instances_to_client(client, ALTER_DESTROY);
5225 /*! \note No reply packet */
5229 static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
5231 struct slave_node *slave;
5232 const char *slavename;
5235 ret = packet_get(packet, "s", &slavename);
5237 ErrPrint("Parameter is not matched\n");
5241 DbgPrint("New slave[%s](%d) is arrived\n", slavename, pid);
5243 slave = slave_find_by_name(slavename);
5245 if (!slave) { /* Try again to find a slave using pid */
5246 slave = slave_find_by_pid(pid);
5251 char pkgname[pathconf("/", _PC_PATH_MAX)];
5254 if (aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)) != AUL_R_OK) {
5255 ErrPrint("pid[%d] is not authroized provider package, try to find it using its name[%s]\n", pid, slavename);
5256 slave = slave_find_by_name(slavename);
5257 pkgname[0] = '\0'; /* Reset the pkgname */
5259 slave = slave_find_by_pkgname(pkgname);
5263 abi = abi_find_by_pkgname(pkgname);
5266 DbgPrint("Slave pkgname is invalid, ABI is replaced with '%s'(default)\n", abi);
5269 slave = slave_create(slavename, 1, abi, pkgname, 0);
5271 ErrPrint("Failed to create a new slave for %s\n", slavename);
5275 DbgPrint("New slave is created (net: 0)\n");
5277 DbgPrint("Registered slave is replaced with this new one\n");
5278 abi = slave_abi(slave);
5280 ErrPrint("ABI is not valid: %s\n", slavename);
5285 slave_set_pid(slave, pid);
5286 DbgPrint("Provider is forcely activated, pkgname(%s), abi(%s), slavename(%s)\n", pkgname, abi, slavename);
5288 ErrPrint("Slave[%d, %s] is not exists\n", pid, slavename);
5292 if (slave_pid(slave) != pid) {
5293 if (slave_pid(slave) > 0) {
5294 CRITICAL_LOG("Slave(%s) is already assigned to %d\n", slave_name(slave), slave_pid(slave));
5296 ret = aul_terminate_pid(pid);
5297 CRITICAL_LOG("Terminate %d (ret: %d)\n", pid, ret);
5301 CRITICAL_LOG("PID of slave(%s) is updated (%d -> %d)\n", slave_name(slave), slave_pid(slave), pid);
5302 slave_set_pid(slave, pid);
5308 * After updating handle,
5309 * slave activated callback will be called.
5311 slave_rpc_update_handle(slave, handle);
5317 static struct packet *slave_ping(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
5319 struct slave_node *slave;
5320 const char *slavename;
5323 slave = slave_find_by_pid(pid);
5325 ErrPrint("Slave %d is not exists\n", pid);
5329 ret = packet_get(packet, "s", &slavename);
5331 ErrPrint("Parameter is not matched\n");
5333 slave_rpc_ping(slave);
5340 static struct packet *slave_faulted(pid_t pid, int handle, const struct packet *packet)
5342 struct slave_node *slave;
5343 struct inst_info *inst;
5344 const char *pkgname;
5349 slave = slave_find_by_pid(pid);
5351 ErrPrint("Slave %d is not exists\n", pid);
5355 ret = packet_get(packet, "sss", &pkgname, &id, &func);
5357 ErrPrint("Parameter is not matched\n");
5361 ret = fault_info_set(slave, pkgname, id, func);
5362 DbgPrint("Slave Faulted: %s (%d)\n", slave_name(slave), ret);
5364 inst = package_find_instance_by_id(pkgname, id);
5366 DbgPrint("There is a no such instance(%s)\n", id);
5367 } else if (instance_state(inst) == INST_DESTROYED) {
5368 ErrPrint("Instance(%s) is already destroyed\n", id);
5370 ret = instance_destroy(inst, INSTANCE_DESTROY_FAULT);
5377 static struct packet *slave_lb_update_begin(pid_t pid, int handle, const struct packet *packet)
5379 struct slave_node *slave;
5380 struct inst_info *inst = NULL;
5381 const struct pkg_info *pkg = NULL;
5382 const char *pkgname;
5385 const char *content;
5389 slave = slave_find_by_pid(pid);
5391 ErrPrint("Slave %d is not exists\n", pid);
5395 ret = packet_get(packet, "ssdss", &pkgname, &id, &priority, &content, &title);
5397 ErrPrint("Invalid parameters\n");
5401 ret = validate_request(pkgname, id, &inst, &pkg);
5402 if (ret != LB_STATUS_SUCCESS) {
5406 if (instance_state(inst) == INST_DESTROYED) {
5407 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
5411 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
5412 ret = instance_lb_update_begin(inst, priority, content, title);
5413 if (ret == LB_STATUS_SUCCESS) {
5414 slave_freeze_ttl(slave);
5417 ErrPrint("Invalid request[%s]\n", id);
5424 static struct packet *slave_lb_update_end(pid_t pid, int handle, const struct packet *packet)
5426 struct slave_node *slave;
5427 struct inst_info *inst = NULL;
5428 const struct pkg_info *pkg = NULL;
5429 const char *pkgname;
5433 slave = slave_find_by_pid(pid);
5435 ErrPrint("Slave %d is not exists\n", pid);
5439 ret = packet_get(packet, "ss", &pkgname, &id);
5441 ErrPrint("Invalid parameters\n");
5445 ret = validate_request(pkgname, id, &inst, &pkg);
5446 if (ret != LB_STATUS_SUCCESS) {
5450 if (instance_state(inst) == INST_DESTROYED) {
5451 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
5455 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
5456 ret = instance_lb_update_end(inst);
5457 if (ret == LB_STATUS_SUCCESS) {
5458 slave_thaw_ttl(slave);
5461 ErrPrint("Invalid request[%s]\n", id);
5468 static struct packet *slave_pd_update_begin(pid_t pid, int handle, const struct packet *packet)
5470 struct slave_node *slave;
5471 const struct pkg_info *pkg = NULL;
5472 struct inst_info *inst = NULL;
5473 const char *pkgname;
5477 slave = slave_find_by_pid(pid);
5479 ErrPrint("Slave %d is not exists\n", pid);
5483 ret = packet_get(packet, "ss", &pkgname, &id);
5485 ErrPrint("Invalid parameters\n");
5489 ret = validate_request(pkgname, id, &inst, &pkg);
5490 if (ret != LB_STATUS_SUCCESS) {
5494 if (instance_state(inst) == INST_DESTROYED) {
5495 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
5499 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
5500 (void)instance_pd_update_begin(inst);
5502 ErrPrint("Invalid request[%s]\n", id);
5509 static struct packet *slave_access_status(pid_t pid, int handle, const struct packet *packet)
5511 struct slave_node *slave;
5512 struct inst_info *inst = NULL;
5513 const char *pkgname;
5518 slave = slave_find_by_pid(pid);
5520 ErrPrint("Slave %d is not exists\n", pid);
5524 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
5526 ErrPrint("Invalid parameters\n");
5530 ret = validate_request(pkgname, id, &inst, NULL);
5531 if (ret == LB_STATUS_SUCCESS) {
5532 if (instance_state(inst) == INST_DESTROYED) {
5533 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
5535 (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
5543 static struct packet *slave_pd_update_end(pid_t pid, int handle, const struct packet *packet)
5545 struct slave_node *slave;
5546 const struct pkg_info *pkg = NULL;
5547 struct inst_info *inst = NULL;
5548 const char *pkgname;
5552 slave = slave_find_by_pid(pid);
5554 ErrPrint("Slave %d is not exists\n", pid);
5558 ret = packet_get(packet, "ss", &pkgname, &id);
5560 ErrPrint("Invalid parameters\n");
5564 ret = validate_request(pkgname, id, &inst, &pkg);
5565 if (ret != LB_STATUS_SUCCESS) {
5569 if (instance_state(inst) == INST_DESTROYED) {
5570 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
5574 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
5575 (void)instance_pd_update_end(inst);
5577 ErrPrint("Invalid request[%s]\n", id);
5584 static struct packet *slave_call(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
5586 struct slave_node *slave;
5587 const char *pkgname;
5592 slave = slave_find_by_pid(pid);
5594 ErrPrint("Slave %d is not exists\n", pid);
5598 ret = packet_get(packet, "sss", &pkgname, &id, &func);
5600 ErrPrint("Parameter is not matched\n");
5604 ret = fault_func_call(slave, pkgname, id, func);
5605 slave_give_more_ttl(slave);
5611 static struct packet *slave_ret(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
5613 struct slave_node *slave;
5614 const char *pkgname;
5619 slave = slave_find_by_pid(pid);
5621 ErrPrint("Slave %d is not exists\n", pid);
5625 ret = packet_get(packet, "sss", &pkgname, &id, &func);
5627 ErrPrint("Parameter is not matched\n");
5631 ret = fault_func_ret(slave, pkgname, id, func);
5632 slave_give_more_ttl(slave);
5638 static struct packet *slave_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, width, height, priority, ret */
5640 struct slave_node *slave;
5641 const char *pkgname;
5642 const char *safe_filename;
5644 const char *content_info;
5650 struct inst_info *inst = NULL;
5652 slave = slave_find_by_pid(pid);
5654 ErrPrint("Slave %d is not exists\n", pid);
5658 ret = packet_get(packet, "ssiidsss", &pkgname, &id,
5660 &content_info, &title,
5663 ErrPrint("Parameter is not matched\n");
5667 ret = validate_request(pkgname, id, &inst, NULL);
5668 if (ret == LB_STATUS_SUCCESS) {
5669 if (instance_state(inst) == INST_DESTROYED) {
5670 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
5674 instance_set_lb_info(inst, priority, content_info, title);
5676 switch (package_lb_type(instance_package(inst))) {
5677 case LB_TYPE_SCRIPT:
5678 script_handler_resize(instance_lb_script(inst), w, h);
5679 if (safe_filename) {
5680 (void)script_handler_parse_desc(inst, safe_filename, 0);
5682 safe_filename = util_uri_to_path(id);
5683 (void)script_handler_parse_desc(inst, safe_filename, 0);
5686 if (unlink(safe_filename) < 0) {
5687 ErrPrint("unlink: %s - %s\n", strerror(errno), safe_filename);
5690 case LB_TYPE_BUFFER:
5694 * text format (inst)
5696 instance_set_lb_size(inst, w, h);
5697 instance_lb_updated_by_instance(inst, safe_filename);
5701 slave_give_more_ttl(slave);
5708 static struct packet *slave_hold_scroll(pid_t pid, int handle, const struct packet *packet)
5710 struct slave_node *slave;
5711 struct inst_info *inst = NULL;
5712 const char *pkgname;
5717 slave = slave_find_by_pid(pid);
5719 ErrPrint("Slave %d is not exists\n", pid);
5723 ret = packet_get(packet, "ssi", &pkgname, &id, &seize);
5725 ErrPrint("Parameter is not matched\n");
5729 ret = validate_request(pkgname, id, &inst, NULL);
5730 if (ret == LB_STATUS_SUCCESS) {
5731 if (instance_state(inst) == INST_DESTROYED) {
5732 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
5734 (void)instance_hold_scroll(inst, seize);
5742 static struct packet *slave_desc_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, decsfile, ret */
5744 struct slave_node *slave;
5745 const char *pkgname;
5747 const char *descfile;
5749 struct inst_info *inst = NULL;
5751 slave = slave_find_by_pid(pid);
5753 ErrPrint("Slave %d is not exists\n", pid);
5757 ret = packet_get(packet, "sss", &pkgname, &id, &descfile);
5759 ErrPrint("Parameter is not matched\n");
5763 ret = validate_request(pkgname, id, &inst, NULL);
5764 if (ret != LB_STATUS_SUCCESS) {
5768 if (instance_state(inst) == INST_DESTROYED) {
5769 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
5773 switch (package_pd_type(instance_package(inst))) {
5774 case PD_TYPE_SCRIPT:
5775 if (script_handler_is_loaded(instance_pd_script(inst))) {
5776 (void)script_handler_parse_desc(inst, descfile, 1);
5780 instance_set_pd_size(inst, 0, 0);
5781 case PD_TYPE_BUFFER:
5782 instance_pd_updated(pkgname, id, descfile);
5785 DbgPrint("Ignore updated DESC(%s)\n", pkgname);
5793 static struct packet *slave_deleted(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, id, ret */
5795 struct slave_node *slave;
5796 const char *pkgname;
5799 struct inst_info *inst = NULL;
5801 slave = slave_find_by_pid(pid);
5803 ErrPrint("Slave %d is not exists\n", pid);
5807 ret = packet_get(packet, "ss", &pkgname, &id);
5809 ErrPrint("Parameter is not matched\n");
5813 ret = validate_request(pkgname, id, &inst, NULL);
5814 if (ret == LB_STATUS_SUCCESS) {
5815 ret = instance_destroyed(inst);
5823 * \note for the BUFFER Type slave
5825 static struct packet *slave_acquire_buffer(pid_t pid, int handle, const struct packet *packet) /* type, id, w, h, size */
5827 enum target_type target;
5828 const char *pkgname;
5833 struct packet *result;
5834 struct slave_node *slave;
5835 struct inst_info *inst = NULL;
5836 const struct pkg_info *pkg = NULL;
5839 slave = slave_find_by_pid(pid);
5841 ErrPrint("Failed to find a slave\n");
5843 ret = LB_STATUS_ERROR_NOT_EXIST;
5847 ret = packet_get(packet, "issiii", &target, &pkgname, &id, &w, &h, &pixel_size);
5849 ErrPrint("Invalid argument\n");
5851 ret = LB_STATUS_ERROR_INVALID;
5855 ret = validate_request(pkgname, id, &inst, &pkg);
5858 if (ret != LB_STATUS_SUCCESS) {
5862 ret = LB_STATUS_ERROR_INVALID;
5864 if (instance_state(inst) == INST_DESTROYED) {
5865 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
5869 if (target == TYPE_LB && package_lb_type(pkg) == LB_TYPE_BUFFER) {
5870 struct buffer_info *info;
5872 info = instance_lb_buffer(inst);
5874 if (!instance_create_lb_buffer(inst)) {
5875 ErrPrint("Failed to create a LB buffer\n");
5876 ret = LB_STATUS_ERROR_FAULT;
5880 info = instance_lb_buffer(inst);
5882 ErrPrint("LB buffer is not valid\n");
5885 * ret value should not be changed.
5891 ret = buffer_handler_resize(info, w, h);
5892 ret = buffer_handler_load(info);
5894 instance_set_lb_size(inst, w, h);
5895 instance_set_lb_info(inst, PRIORITY_NO_CHANGE, CONTENT_NO_CHANGE, TITLE_NO_CHANGE);
5896 id = buffer_handler_id(info);
5898 ErrPrint("Failed to load a buffer(%d)\n", ret);
5900 } else if (target == TYPE_PD && package_pd_type(pkg) == PD_TYPE_BUFFER) {
5901 struct buffer_info *info;
5902 Ecore_Timer *pd_monitor;
5906 pd_monitor = instance_del_data(inst, "pd,open,monitor");
5908 pd_monitor = instance_del_data(inst, "pd,resize,monitor");
5909 is_resize = !!pd_monitor;
5911 /* Invalid request. Reject this */
5912 ErrPrint("Invalid request\n");
5916 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst);
5918 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst);
5921 ecore_timer_del(pd_monitor);
5922 inst = instance_unref(inst);
5924 ErrPrint("Instance refcnt is ZERO: %s\n", pkgname);
5928 info = instance_pd_buffer(inst);
5930 if (!instance_create_pd_buffer(inst)) {
5931 ErrPrint("Failed to create a PD buffer\n");
5932 ret = LB_STATUS_ERROR_FAULT;
5933 instance_client_pd_created(inst, ret);
5937 info = instance_pd_buffer(inst);
5939 ErrPrint("PD buffer is not valid\n");
5942 * ret value should not be changed.
5944 instance_client_pd_created(inst, ret);
5949 ret = buffer_handler_resize(info, w, h);
5950 ret = buffer_handler_load(info);
5952 instance_set_pd_size(inst, w, h);
5953 id = buffer_handler_id(info);
5955 ErrPrint("Failed to load a buffer (%d)\n", ret);
5959 * Send the PD created event to the client
5962 instance_client_pd_created(inst, ret);
5967 result = packet_create_reply(packet, "is", ret, id);
5969 ErrPrint("Failed to create a packet\n");
5975 static struct packet *slave_resize_buffer(pid_t pid, int handle, const struct packet *packet)
5977 struct slave_node *slave;
5978 struct packet *result;
5979 enum target_type type;
5980 const char *pkgname;
5984 struct inst_info *inst = NULL;
5985 const struct pkg_info *pkg = NULL;
5988 slave = slave_find_by_pid(pid);
5990 ErrPrint("Failed to find a slave\n");
5991 ret = LB_STATUS_ERROR_NOT_EXIST;
5996 ret = packet_get(packet, "issii", &type, &pkgname, &id, &w, &h);
5998 ErrPrint("Invalid argument\n");
5999 ret = LB_STATUS_ERROR_INVALID;
6004 ret = validate_request(pkgname, id, &inst, &pkg);
6006 if (ret != LB_STATUS_SUCCESS) {
6010 ret = LB_STATUS_ERROR_INVALID;
6013 * Reset "id", It will be re-used from here
6016 if (instance_state(inst) == INST_DESTROYED) {
6017 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6021 if (type == TYPE_LB && package_lb_type(pkg) == LB_TYPE_BUFFER) {
6022 struct buffer_info *info;
6024 info = instance_lb_buffer(inst);
6029 ret = buffer_handler_resize(info, w, h);
6032 * id is resued for newly assigned ID
6034 if (ret == LB_STATUS_SUCCESS) {
6035 id = buffer_handler_id(info);
6036 instance_set_lb_size(inst, w, h);
6037 instance_set_lb_info(inst, PRIORITY_NO_CHANGE, CONTENT_NO_CHANGE, TITLE_NO_CHANGE);
6039 } else if (type == TYPE_PD && package_pd_type(pkg) == PD_TYPE_BUFFER) {
6040 struct buffer_info *info;
6042 info = instance_pd_buffer(inst);
6047 ret = buffer_handler_resize(info, w, h);
6050 * id is resued for newly assigned ID
6052 if (ret == LB_STATUS_SUCCESS) {
6053 id = buffer_handler_id(info);
6054 instance_set_pd_size(inst, w, h);
6059 result = packet_create_reply(packet, "is", ret, id);
6061 ErrPrint("Failed to create a packet\n");
6067 static struct packet *slave_release_buffer(pid_t pid, int handle, const struct packet *packet)
6069 enum target_type type;
6070 const char *pkgname;
6072 struct packet *result;
6073 struct slave_node *slave;
6074 struct inst_info *inst = NULL;
6075 const struct pkg_info *pkg = NULL;
6078 slave = slave_find_by_pid(pid);
6080 ErrPrint("Failed to find a slave\n");
6081 ret = LB_STATUS_ERROR_NOT_EXIST;
6085 if (packet_get(packet, "iss", &type, &pkgname, &id) != 3) {
6086 ErrPrint("Inavlid argument\n");
6087 ret = LB_STATUS_ERROR_INVALID;
6091 ret = validate_request(pkgname, id, &inst, &pkg);
6092 if (ret != LB_STATUS_SUCCESS) {
6096 ret = LB_STATUS_ERROR_INVALID;
6098 if (type == TYPE_LB && package_lb_type(pkg) == LB_TYPE_BUFFER) {
6099 struct buffer_info *info;
6101 info = instance_lb_buffer(inst);
6102 ret = buffer_handler_unload(info);
6103 } else if (type == TYPE_PD && package_pd_type(pkg) == PD_TYPE_BUFFER) {
6104 struct buffer_info *info;
6105 Ecore_Timer *pd_monitor;
6107 pd_monitor = instance_del_data(inst, "pd,close,monitor");
6109 ErrPrint("Slave requests to release a buffer\n");
6112 * In this case just keep going to release buffer,
6113 * Even if a user(client) doesn't wants to destroy the PD.
6115 * If the slave tries to destroy PD buffer, it should be
6116 * released and reported to the client about its status.
6118 * Even if the pd is destroyed by timeout handler,
6119 * instance_client_pd_destroyed function will be ignored
6120 * by pd.need_to_send_close_event flag.
6121 * which will be checked by instance_client_pd_destroyed function.
6126 * provider can try to resize the buffer size.
6127 * in that case, it will release the buffer first.
6128 * Then even though the client doesn't request to close the PD,
6129 * the provider can release it.
6130 * If we send the close event to the client,
6131 * The client will not able to allocate PD again.
6132 * In this case, add the pd,monitor again. from here.
6133 * to wait the re-allocate buffer.
6134 * If the client doesn't request buffer reallocation,
6135 * Treat it as a fault. and close the PD.
6137 info = instance_pd_buffer(inst);
6138 ret = buffer_handler_unload(info);
6140 if (ret == LB_STATUS_SUCCESS) {
6141 pd_monitor = ecore_timer_add(PD_REQUEST_TIMEOUT, pd_resize_monitor_cb, instance_ref(inst));
6143 (void)instance_unref(inst);
6144 ErrPrint("Failed to create a timer for PD Open monitor\n");
6146 (void)instance_set_data(inst, "pd,resize,monitor", pd_monitor);
6147 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) != LB_STATUS_SUCCESS) {
6148 ErrPrint("Failed to add event handler: %s\n", pkgname);
6153 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
6155 ecore_timer_del(pd_monitor);
6156 inst = instance_unref(inst);
6158 ErrPrint("Instance is released: %s\n", pkgname);
6159 ret = LB_STATUS_ERROR_FAULT;
6163 info = instance_pd_buffer(inst);
6164 ret = buffer_handler_unload(info);
6168 * Send the PD destroyed event to the client
6170 instance_client_pd_destroyed(inst, ret);
6175 result = packet_create_reply(packet, "i", ret);
6177 ErrPrint("Failed to create a packet\n");
6183 static struct packet *service_change_period(pid_t pid, int handle, const struct packet *packet)
6185 struct inst_info *inst = NULL;
6186 struct packet *result;
6187 const char *pkgname;
6192 ret = packet_get(packet, "ssd", &pkgname, &id, &period);
6194 ErrPrint("Invalid packet\n");
6195 ret = LB_STATUS_ERROR_INVALID;
6200 struct pkg_info *pkg;
6202 pkg = package_find(pkgname);
6204 ret = LB_STATUS_ERROR_NOT_EXIST;
6205 } else if (package_is_fault(pkg)) {
6206 ret = LB_STATUS_ERROR_FAULT;
6208 Eina_List *inst_list;
6211 inst_list = package_instance_list(pkg);
6212 EINA_LIST_FOREACH(inst_list, l, inst) {
6213 ret = instance_set_period(inst, period);
6215 ErrPrint("Failed to change the period of %s to (%lf)\n", pkgname, period);
6220 ret = validate_request(pkgname, id, &inst, NULL);
6221 if (ret == LB_STATUS_SUCCESS) {
6222 if (instance_state(inst) == INST_DESTROYED) {
6223 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6224 ret = LB_STATUS_ERROR_INVALID;
6228 ret = instance_set_period(inst, period);
6232 DbgPrint("Change the update period: %s, %lf : %d\n", pkgname, period, ret);
6234 result = packet_create_reply(packet, "i", ret);
6236 ErrPrint("Failed to create a packet\n");
6242 static struct packet *service_update(pid_t pid, int handle, const struct packet *packet)
6244 Eina_List *inst_list;
6245 struct pkg_info *pkg;
6246 struct packet *result;
6247 const char *pkgname;
6249 const char *cluster;
6250 const char *category;
6254 ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category);
6256 ErrPrint("Invalid Packet\n");
6257 ret = LB_STATUS_ERROR_INVALID;
6261 lbid = package_lb_pkgname(pkgname);
6263 ErrPrint("Invalid package %s\n", pkgname);
6264 ret = LB_STATUS_ERROR_INVALID;
6268 pkg = package_find(lbid);
6270 ret = LB_STATUS_ERROR_NOT_EXIST;
6275 if (package_is_fault(pkg)) {
6276 ret = LB_STATUS_ERROR_FAULT;
6281 inst_list = package_instance_list(pkg);
6282 if (!eina_list_count(inst_list)) {
6283 ret = LB_STATUS_ERROR_NOT_EXIST;
6288 if (id && strlen(id)) {
6290 struct inst_info *inst;
6292 ret = LB_STATUS_ERROR_NOT_EXIST;
6293 EINA_LIST_FOREACH(inst_list, l, inst) {
6294 if (!strcmp(instance_id(inst), id)) {
6295 ret = LB_STATUS_SUCCESS;
6300 if (ret == LB_STATUS_ERROR_NOT_EXIST) {
6308 * Validate the update requstor.
6310 slave_rpc_request_update(lbid, id, cluster, category);
6312 ret = LB_STATUS_SUCCESS;
6315 result = packet_create_reply(packet, "i", ret);
6317 ErrPrint("Failed to create a packet\n");
6323 static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet *packet)
6325 struct liveinfo *info;
6326 struct packet *result;
6328 const char *fifo_name;
6331 DbgPrint("Request arrived from %d\n", pid);
6333 if (packet_get(packet, "d", ×tamp) != 1) {
6334 ErrPrint("Invalid packet\n");
6336 ret = LB_STATUS_ERROR_INVALID;
6340 info = liveinfo_create(pid, handle);
6342 ErrPrint("Failed to create a liveinfo object\n");
6344 ret = LB_STATUS_ERROR_INVALID;
6349 fifo_name = liveinfo_filename(info);
6350 DbgPrint("FIFO Created: %s (Serve for %d)\n", fifo_name, pid);
6353 result = packet_create_reply(packet, "si", fifo_name, ret);
6355 ErrPrint("Failed to create a result packet\n");
6361 static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet)
6365 struct liveinfo *info;
6366 struct slave_node *slave;
6370 if (packet_get(packet, "d", ×tamp) != 1) {
6371 ErrPrint("Invalid argument\n");
6375 info = liveinfo_find_by_pid(pid);
6377 ErrPrint("Invalid request\n");
6381 liveinfo_open_fifo(info);
6382 fp = liveinfo_fifo(info);
6384 liveinfo_close_fifo(info);
6388 list = (Eina_List *)slave_list();
6389 EINA_LIST_FOREACH(list, l, slave) {
6390 fprintf(fp, "%d %s %s %s %d %d %d %s %d %d %lf\n",
6393 slave_pkgname(slave),
6395 slave_is_secured(slave),
6396 slave_refcnt(slave),
6397 slave_fault_count(slave),
6398 slave_state_string(slave),
6399 slave_loaded_instance(slave),
6400 slave_loaded_package(slave),
6405 fprintf(fp, "EOD\n");
6406 liveinfo_close_fifo(info);
6411 static inline const char *visible_state_string(enum livebox_visible_state state)
6418 case LB_HIDE_WITH_PAUSE:
6427 static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet)
6429 const char *pkgname;
6430 struct liveinfo *info;
6431 struct pkg_info *pkg;
6433 Eina_List *inst_list;
6434 struct inst_info *inst;
6437 if (packet_get(packet, "s", &pkgname) != 1) {
6438 ErrPrint("Invalid argument\n");
6442 info = liveinfo_find_by_pid(pid);
6444 ErrPrint("Invalid request\n");
6448 liveinfo_open_fifo(info);
6449 fp = liveinfo_fifo(info);
6451 ErrPrint("Invalid fp\n");
6452 liveinfo_close_fifo(info);
6456 if (!package_is_lb_pkgname(pkgname)) {
6457 ErrPrint("Invalid package name\n");
6461 pkg = package_find(pkgname);
6463 ErrPrint("Package is not exists\n");
6467 inst_list = package_instance_list(pkg);
6468 EINA_LIST_FOREACH(inst_list, l, inst) {
6469 fprintf(fp, "%s %s %s %lf %s %d %d\n",
6471 instance_cluster(inst),
6472 instance_category(inst),
6473 instance_period(inst),
6474 visible_state_string(instance_visible_state(inst)),
6475 instance_lb_width(inst),
6476 instance_lb_height(inst));
6480 fprintf(fp, "EOD\n");
6481 liveinfo_close_fifo(info);
6487 static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet)
6491 Eina_List *inst_list;
6492 struct liveinfo *info;
6493 struct pkg_info *pkg;
6494 struct slave_node *slave;
6496 const char *slavename;
6499 if (packet_get(packet, "d", ×tamp) != 1) {
6500 ErrPrint("Invalid argument\n");
6504 info = liveinfo_find_by_pid(pid);
6506 ErrPrint("Invalid request\n");
6510 liveinfo_open_fifo(info);
6511 fp = liveinfo_fifo(info);
6513 liveinfo_close_fifo(info);
6517 list = (Eina_List *)package_list();
6518 EINA_LIST_FOREACH(list, l, pkg) {
6519 slave = package_slave(pkg);
6522 slavename = slave_name(slave);
6523 pid = slave_pid(slave);
6529 inst_list = (Eina_List *)package_instance_list(pkg);
6530 fprintf(fp, "%d %s %s %s %d %d %d\n",
6532 strlen(slavename) ? slavename : "(none)",
6535 package_refcnt(pkg),
6536 package_fault_count(pkg),
6537 eina_list_count(inst_list)
6541 fprintf(fp, "EOD\n");
6542 liveinfo_close_fifo(info);
6547 static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct packet *packet)
6552 static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet)
6554 struct liveinfo *info;
6560 if (packet_get(packet, "sss", &cmd, &pkgname, &id) != 3) {
6561 ErrPrint("Invalid argument\n");
6565 info = liveinfo_find_by_pid(pid);
6567 ErrPrint("Invalid request\n");
6571 liveinfo_open_fifo(info);
6572 fp = liveinfo_fifo(info);
6574 liveinfo_close_fifo(info);
6578 if (!strcmp(cmd, "rmpack")) {
6579 fprintf(fp, "%d\n", ENOSYS);
6580 } else if (!strcmp(cmd, "rminst")) {
6581 struct inst_info *inst;
6582 inst = package_find_instance_by_id(pkgname, id);
6584 fprintf(fp, "%d\n", ENOENT);
6586 (void)instance_destroy(inst, INSTANCE_DESTROY_DEFAULT);
6587 fprintf(fp, "%d\n", 0);
6589 } else if (!strcmp(cmd, "faultinst")) {
6590 struct inst_info *inst;
6591 inst = package_find_instance_by_id(pkgname, id);
6593 fprintf(fp, "%d\n", ENOENT);
6595 struct pkg_info *pkg;
6597 pkg = instance_package(inst);
6599 fprintf(fp, "%d\n", EFAULT);
6601 (void)package_faulted(pkg);
6602 fprintf(fp, "%d\n", 0);
6607 fprintf(fp, "EOD\n");
6608 liveinfo_close_fifo(info);
6614 static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct packet *packet)
6616 struct liveinfo *info;
6621 int ret = LB_STATUS_ERROR_INVALID;
6623 if (packet_get(packet, "sss", &cmd, &var, &val) != 3) {
6624 ErrPrint("Invalid argument\n");
6628 info = liveinfo_find_by_pid(pid);
6630 ErrPrint("Invalid request\n");
6634 if (!strcasecmp(var, "debug")) {
6635 if (!strcasecmp(cmd, "set")) {
6636 g_conf.debug_mode = !strcasecmp(val, "on");
6637 } else if (!strcasecmp(cmd, "get")) {
6639 ret = g_conf.debug_mode;
6640 } else if (!strcasecmp(var, "slave_max_load")) {
6641 if (!strcasecmp(cmd, "set")) {
6642 g_conf.slave_max_load = atoi(val);
6643 } else if (!strcasecmp(cmd, "get")) {
6645 ret = g_conf.slave_max_load;
6648 liveinfo_open_fifo(info);
6649 fp = liveinfo_fifo(info);
6651 liveinfo_close_fifo(info);
6654 fprintf(fp, "%d\nEOD\n", ret);
6655 liveinfo_close_fifo(info);
6661 static struct method s_info_table[] = {
6663 .cmd = "liveinfo_hello",
6664 .handler = liveinfo_hello,
6667 .cmd = "slave_list",
6668 .handler = liveinfo_slave_list,
6672 .handler = liveinfo_pkg_list,
6676 .handler = liveinfo_inst_list,
6679 .cmd = "slave_ctrl",
6680 .handler = liveinfo_slave_ctrl,
6684 .handler = liveinfo_pkg_ctrl,
6687 .cmd = "master_ctrl",
6688 .handler = liveinfo_master_ctrl,
6696 static struct method s_client_table[] = {
6698 .cmd = "pd_mouse_move",
6699 .handler = client_pd_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6702 .cmd = "lb_mouse_move",
6703 .handler = client_lb_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6706 .cmd = "pd_mouse_down",
6707 .handler = client_pd_mouse_down, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
6710 .cmd = "pd_mouse_up",
6711 .handler = client_pd_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6714 .cmd = "lb_mouse_down",
6715 .handler = client_lb_mouse_down, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6718 .cmd = "lb_mouse_up",
6719 .handler = client_lb_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6722 .cmd = "pd_mouse_enter",
6723 .handler = client_pd_mouse_enter, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
6726 .cmd = "pd_mouse_leave",
6727 .handler = client_pd_mouse_leave, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
6730 .cmd = "lb_mouse_enter",
6731 .handler = client_lb_mouse_enter, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6734 .cmd = "lb_mouse_leave",
6735 .handler = client_lb_mouse_leave, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
6738 .cmd = "lb_mouse_set",
6739 .handler = client_lb_mouse_set,
6742 .cmd = "lb_mouse_unset",
6743 .handler = client_lb_mouse_unset,
6746 .cmd = "pd_mouse_set",
6747 .handler = client_pd_mouse_set,
6750 .cmd = "pd_mouse_unset",
6751 .handler = client_pd_mouse_unset,
6754 .cmd = "change,visibility",
6755 .handler = client_change_visibility,
6758 .cmd = "lb_acquire_pixmap",
6759 .handler = client_lb_acquire_pixmap,
6762 .cmd = "lb_release_pixmap",
6763 .handler = client_lb_release_pixmap,
6766 .cmd = "pd_acquire_pixmap",
6767 .handler = client_pd_acquire_pixmap,
6770 .cmd = "pd_release_pixmap",
6771 .handler = client_pd_release_pixmap,
6775 .handler = client_acquire, /*!< pid, ret */
6779 .handler = cilent_release, /*!< pid, ret */
6783 .handler = client_clicked, /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
6786 .cmd = "text_signal",
6787 .handler = client_text_signal, /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
6791 .handler = client_delete, /* pid, pkgname, filename, ret */
6795 .handler = client_resize, /* pid, pkgname, filename, w, h, ret */
6799 .handler = client_new, /* pid, timestamp, pkgname, content, cluster, category, period, ret */
6802 .cmd = "set_period",
6803 .handler = client_set_period, /* pid, pkgname, filename, period, ret, period */
6806 .cmd = "change_group",
6807 .handler = client_change_group, /* pid, pkgname, filename, cluster, category, ret */
6810 .cmd = "pinup_changed",
6811 .handler = client_pinup_changed, /* pid, pkgname, filename, pinup, ret */
6815 .handler = client_create_pd, /* pid, pkgname, filename, ret */
6819 .handler = client_pd_move, /* pkgname, id, x, y */
6822 .cmd = "destroy_pd",
6823 .handler = client_destroy_pd, /* pid, pkgname, filename, ret */
6826 .cmd = "activate_package",
6827 .handler = client_activate_package, /* pid, pkgname, ret */
6830 .cmd = "subscribe", /* pid, cluster, sub-cluster */
6831 .handler = client_subscribed,
6834 .cmd = "unsubscribe", /* pid, cluster, sub-cluster */
6835 .handler = client_unsubscribed,
6838 .cmd = "delete_cluster",
6839 .handler = client_delete_cluster,
6842 .cmd = "delete_category",
6843 .handler = client_delete_category,
6846 .cmd = "refresh_group",
6847 .handler = client_refresh_group,
6851 .handler = client_update,
6855 .cmd = "pd_access_hl",
6856 .handler = client_pd_access_hl,
6859 .cmd = "pd_access_hl_prev",
6860 .handler = client_pd_access_hl_prev,
6863 .cmd = "pd_access_hl_next",
6864 .handler = client_pd_access_hl_next,
6867 .cmd = "pd_access_activate",
6868 .handler = client_pd_access_activate,
6871 .cmd = "pd_access_action_up",
6872 .handler = client_pd_access_action_up,
6875 .cmd = "pd_access_action_down",
6876 .handler = client_pd_access_action_down,
6879 .cmd = "pd_access_unhighlight",
6880 .handler = client_pd_access_unhighlight,
6883 .cmd = "pd_access_scroll_down",
6884 .handler = client_pd_access_scroll_down,
6887 .cmd = "pd_access_scroll_move",
6888 .handler = client_pd_access_scroll_move,
6891 .cmd = "pd_access_scroll_up",
6892 .handler = client_pd_access_scroll_up,
6896 .cmd = "lb_access_hl",
6897 .handler = client_lb_access_hl,
6900 .cmd = "lb_access_hl_prev",
6901 .handler = client_lb_access_hl_prev,
6904 .cmd = "lb_access_hl_next",
6905 .handler = client_lb_access_hl_next,
6908 .cmd = "lb_access_activate",
6909 .handler = client_lb_access_activate,
6912 .cmd = "lb_access_action_up",
6913 .handler = client_lb_access_action_up,
6916 .cmd = "lb_access_action_down",
6917 .handler = client_lb_access_action_down,
6920 .cmd = "lb_access_unhighlight",
6921 .handler = client_lb_access_unhighlight,
6924 .cmd = "lb_access_scroll_down",
6925 .handler = client_lb_access_scroll_down,
6928 .cmd = "lb_access_scroll_move",
6929 .handler = client_lb_access_scroll_move,
6932 .cmd = "lb_access_scroll_up",
6933 .handler = client_lb_access_scroll_up,
6937 .cmd = "lb_key_down",
6938 .handler = client_lb_key_down,
6942 .handler = client_lb_key_up,
6946 .cmd = "pd_key_down",
6947 .handler = client_pd_key_down,
6951 .handler = client_pd_key_up,
6955 .cmd = "client_paused",
6956 .handler = client_pause_request,
6959 .cmd = "client_resumed",
6960 .handler = client_resume_request,
6964 .cmd = "update_mode",
6965 .handler = client_update_mode,
6974 static struct method s_service_table[] = {
6976 .cmd = "service_update",
6977 .handler = service_update,
6980 .cmd = "service_change_period",
6981 .handler = service_change_period,
6989 static struct method s_slave_table[] = {
6992 .handler = slave_call, /* slave_name, pkgname, filename, function, ret */
6996 .handler = slave_ret, /* slave_name, pkgname, filename, function, ret */
7000 .handler = slave_updated, /* slave_name, pkgname, filename, width, height, priority, ret */
7003 .cmd = "desc_updated",
7004 .handler = slave_desc_updated, /* slave_name, pkgname, filename, decsfile, ret */
7008 .handler = slave_deleted, /* slave_name, pkgname, filename, ret */
7011 .cmd = "acquire_buffer",
7012 .handler = slave_acquire_buffer, /* slave_name, id, w, h, size, - out - type, shmid */
7015 .cmd = "resize_buffer",
7016 .handler = slave_resize_buffer,
7019 .cmd = "release_buffer",
7020 .handler = slave_release_buffer, /* slave_name, id - ret */
7024 .handler = slave_faulted, /* slave_name, pkgname, id, funcname */
7028 .handler = slave_hold_scroll, /* slave_name, pkgname, id, seize */
7032 .cmd = "lb_update_begin",
7033 .handler = slave_lb_update_begin,
7036 .cmd = "lb_update_end",
7037 .handler = slave_lb_update_end,
7040 .cmd = "pd_update_begin",
7041 .handler = slave_pd_update_begin,
7044 .cmd = "pd_update_end",
7045 .handler = slave_pd_update_end,
7049 .cmd = "access_status",
7050 .handler = slave_access_status,
7055 .handler = slave_hello, /* slave_name, ret */
7059 .handler = slave_ping, /* slave_name, ret */
7068 HAPI int server_init(void)
7070 com_core_packet_use_thread(COM_CORE_THREAD);
7072 if (unlink(INFO_SOCKET) < 0) {
7073 ErrPrint("info socket: %s\n", strerror(errno));
7076 if (unlink(SLAVE_SOCKET) < 0) {
7077 ErrPrint("slave socket: %s\n", strerror(errno));
7080 if (unlink(CLIENT_SOCKET) < 0) {
7081 ErrPrint("client socket: %s\n", strerror(errno));
7084 if (unlink(SERVICE_SOCKET) < 0) {
7085 ErrPrint("service socket: %s\n", strerror(errno));
7088 s_info.info_fd = com_core_packet_server_init(INFO_SOCKET, s_info_table);
7089 if (s_info.info_fd < 0) {
7090 ErrPrint("Failed to create a info socket\n");
7093 s_info.slave_fd = com_core_packet_server_init(SLAVE_SOCKET, s_slave_table);
7094 if (s_info.slave_fd < 0) {
7095 ErrPrint("Failed to create a slave socket\n");
7098 s_info.client_fd = com_core_packet_server_init(CLIENT_SOCKET, s_client_table);
7099 if (s_info.client_fd < 0) {
7100 ErrPrint("Failed to create a client socket\n");
7106 * Skip address to use the NULL.
7108 s_info.remote_client_fd = com_core_packet_server_init("remote://:"CLIENT_PORT, s_client_table);
7109 if (s_info.client_fd < 0) {
7110 ErrPrint("Failed to create a remote client socket\n");
7113 s_info.service_fd = com_core_packet_server_init(SERVICE_SOCKET, s_service_table);
7114 if (s_info.service_fd < 0) {
7115 ErrPrint("Faild to create a service socket\n");
7118 if (chmod(INFO_SOCKET, 0600) < 0) {
7119 ErrPrint("info socket: %s\n", strerror(errno));
7122 if (chmod(SLAVE_SOCKET, 0666) < 0) {
7123 ErrPrint("slave socket: %s\n", strerror(errno));
7126 if (chmod(CLIENT_SOCKET, 0666) < 0) {
7127 ErrPrint("client socket: %s\n", strerror(errno));
7130 if (chmod(SERVICE_SOCKET, 0666) < 0) {
7131 ErrPrint("service socket: %s\n", strerror(errno));
7137 HAPI int server_fini(void)
7139 if (s_info.info_fd > 0) {
7140 com_core_packet_server_fini(s_info.info_fd);
7141 s_info.info_fd = -1;
7144 if (s_info.slave_fd > 0) {
7145 com_core_packet_server_fini(s_info.slave_fd);
7146 s_info.slave_fd = -1;
7149 if (s_info.client_fd > 0) {
7150 com_core_packet_server_fini(s_info.client_fd);
7151 s_info.client_fd = -1;
7154 if (s_info.remote_client_fd > 0) {
7155 com_core_packet_server_fini(s_info.remote_client_fd);
7156 s_info.remote_client_fd = -1;
7159 if (s_info.service_fd > 0) {
7160 com_core_packet_server_fini(s_info.service_fd);
7161 s_info.service_fd = -1;