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.
27 #include <com-core_packet.h>
28 #include <livebox-errno.h>
29 #include <livebox-service.h>
31 #include "critical_log.h"
35 #include "slave_life.h"
36 #include "slave_rpc.h"
37 #include "client_life.h"
39 #include "client_rpc.h"
41 #include "script_handler.h"
42 #include "buffer_handler.h"
44 #include "fault_manager.h"
52 #define PD_OPEN_MONITOR_TAG "pd,open,monitor"
53 #define PD_RESIZE_MONITOR_TAG "pd,resize,monitor"
54 #define PD_CLOSE_MONITOR_TAG "pd,close,monitor"
56 #define LAZY_PD_OPEN_TAG "lazy,pd,open"
57 #define LAZY_PD_CLOSE_TAG "lazy,pd,close"
70 .remote_client_fd = -1,
73 /* Share this with provider */
82 struct inst_info *inst;
86 struct client_node *client;
87 struct inst_info *inst;
90 static int forward_lb_event_packet(const struct pkg_info *pkg, struct inst_info *inst, const struct packet *packet)
92 struct buffer_info *buffer;
93 struct slave_node *slave;
96 buffer = instance_lb_buffer(inst);
98 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
99 ret = LB_STATUS_ERROR_FAULT;
103 slave = package_slave(pkg);
105 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
106 ret = LB_STATUS_ERROR_INVALID;
110 packet_ref((struct packet *)packet);
111 ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0);
117 static int forward_pd_event_packet(const struct pkg_info *pkg, struct inst_info *inst, const struct packet *packet)
119 struct buffer_info *buffer;
120 struct slave_node *slave;
123 buffer = instance_pd_buffer(inst);
125 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
126 ret = LB_STATUS_ERROR_FAULT;
130 slave = package_slave(pkg);
132 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
133 ret = LB_STATUS_ERROR_INVALID;
137 packet_ref((struct packet *)packet);
138 ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0);
144 static int forward_pd_access_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, int x, int y)
147 struct buffer_info *buffer;
148 struct slave_node *slave;
151 buffer = instance_pd_buffer(inst);
153 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
154 ret = LB_STATUS_ERROR_FAULT;
158 slave = package_slave(pkg);
160 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
161 ret = LB_STATUS_ERROR_INVALID;
165 p = packet_create_noack(command, "ssdii", package_name(pkg), instance_id(inst), timestamp, x, y);
166 ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
172 static int forward_lb_access_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, int x, int y)
175 struct buffer_info *buffer;
176 struct slave_node *slave;
179 buffer = instance_lb_buffer(inst);
181 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
182 ret = LB_STATUS_ERROR_FAULT;
186 slave = package_slave(pkg);
188 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
189 ret = LB_STATUS_ERROR_INVALID;
193 p = packet_create_noack(command, "ssdii", package_name(pkg), instance_id(inst), timestamp, x, y);
194 ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
200 static int forward_pd_key_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, unsigned int keycode)
203 struct buffer_info *buffer;
204 struct slave_node *slave;
207 buffer = instance_lb_buffer(inst);
209 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
210 ret = LB_STATUS_ERROR_FAULT;
214 slave = package_slave(pkg);
216 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
217 ret = LB_STATUS_ERROR_INVALID;
221 p = packet_create_noack(command, "ssdi", package_name(pkg), instance_id(inst), timestamp, keycode);
222 ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
228 static int forward_lb_key_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, unsigned int keycode)
231 struct buffer_info *buffer;
232 struct slave_node *slave;
235 buffer = instance_lb_buffer(inst);
237 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
238 ret = LB_STATUS_ERROR_FAULT;
242 slave = package_slave(pkg);
244 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
245 ret = LB_STATUS_ERROR_INVALID;
249 p = packet_create_noack(command, "ssdi", package_name(pkg), instance_id(inst), timestamp, keycode);
250 ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
256 static Eina_Bool lazy_key_status_cb(void *data)
258 struct event_cbdata *cbdata = data;
260 if (instance_unref(cbdata->inst)) {
261 instance_send_key_status(cbdata->inst, cbdata->status);
263 DbgPrint("Skip sending key status (%d)\n", cbdata->status);
266 * If instance_unref returns NULL,
267 * The instance is destroyed. it means, we don't need to send event to the viewer
270 return ECORE_CALLBACK_CANCEL;
273 static Eina_Bool lazy_access_status_cb(void *data)
275 struct event_cbdata *cbdata = data;
277 if (instance_unref(cbdata->inst)) {
278 instance_send_access_status(cbdata->inst, cbdata->status);
280 DbgPrint("Skip sending access status (%d)\n", cbdata->status);
283 * If instance_unref returns NULL,
284 * The instance is destroyed. it means, we don't need to send event to the viewer
287 return ECORE_CALLBACK_CANCEL;
290 static int slave_fault_open_script_cb(struct slave_node *slave, void *data)
294 (void)script_handler_unload(instance_pd_script(data), 1);
295 (void)instance_slave_close_pd(data, instance_pd_owner(data));
296 (void)instance_client_pd_created(data, LB_STATUS_ERROR_FAULT);
298 timer = instance_del_data(data, LAZY_PD_OPEN_TAG);
300 ecore_timer_del(timer);
303 (void)instance_unref(data);
305 return -1; /* remove this handler */
308 static int slave_fault_open_buffer_cb(struct slave_node *slave, void *data)
312 (void)instance_slave_close_pd(data, instance_pd_owner(data));
313 (void)instance_client_pd_created(data, LB_STATUS_ERROR_FAULT);
315 timer = instance_del_data(data, PD_OPEN_MONITOR_TAG);
317 ecore_timer_del(timer);
320 (void)instance_unref(data);
322 return -1; /* remove this handler */
325 static int slave_fault_close_script_cb(struct slave_node *slave, void *data)
329 (void)instance_client_pd_destroyed(data, LB_STATUS_ERROR_FAULT);
331 timer = instance_del_data(data, LAZY_PD_CLOSE_TAG);
333 ecore_timer_del(timer);
336 (void)instance_unref(data);
338 return -1; /* remove this handler */
341 static int slave_fault_close_buffer_cb(struct slave_node *slave, void *data)
345 (void)instance_client_pd_destroyed(data, LB_STATUS_ERROR_FAULT);
347 timer = instance_del_data(data, LAZY_PD_CLOSE_TAG);
349 timer = instance_del_data(data, PD_CLOSE_MONITOR_TAG);
353 ecore_timer_del(timer);
356 (void)instance_unref(data);
358 return -1; /* remove this handler */
361 static int slave_fault_resize_buffer_cb(struct slave_node *slave, void *data)
365 (void)instance_slave_close_pd(data, instance_pd_owner(data));
366 (void)instance_client_pd_destroyed(data, LB_STATUS_ERROR_FAULT);
368 timer = instance_del_data(data, PD_RESIZE_MONITOR_TAG);
370 ecore_timer_del(timer);
373 (void)instance_unref(data);
375 return -1; /* remove this handler */
378 static int key_event_lb_route_cb(enum event_state state, struct event_data *event_info, void *data)
380 struct inst_info *inst = data;
381 const struct pkg_info *pkg;
382 struct slave_node *slave;
383 struct packet *packet;
386 pkg = instance_package(inst);
388 return LB_STATUS_ERROR_INVALID;
391 slave = package_slave(pkg);
393 return LB_STATUS_ERROR_INVALID;
397 case EVENT_STATE_ACTIVATE:
398 cmdstr = "lb_key_down";
400 case EVENT_STATE_ACTIVATED:
401 cmdstr = "lb_key_down";
403 case EVENT_STATE_DEACTIVATE:
404 cmdstr = "lb_key_up";
407 return LB_STATUS_ERROR_INVALID;
410 packet = packet_create_noack(cmdstr, "ssdi", package_name(pkg), instance_id(inst), util_timestamp(), event_info->keycode);
412 return LB_STATUS_ERROR_FAULT;
415 return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
418 static int mouse_event_lb_route_cb(enum event_state state, struct event_data *event_info, void *data)
420 struct inst_info *inst = data;
421 const struct pkg_info *pkg;
422 struct slave_node *slave;
423 struct packet *packet;
426 pkg = instance_package(inst);
428 return LB_STATUS_ERROR_INVALID;
431 slave = package_slave(pkg);
433 return LB_STATUS_ERROR_INVALID;
437 case EVENT_STATE_ACTIVATE:
438 cmdstr = "lb_mouse_down";
440 case EVENT_STATE_ACTIVATED:
441 cmdstr = "lb_mouse_move";
443 case EVENT_STATE_DEACTIVATE:
444 cmdstr = "lb_mouse_up";
447 return LB_STATUS_ERROR_INVALID;
450 packet = packet_create_noack(cmdstr, "ssdii", package_name(pkg), instance_id(inst), util_timestamp(), event_info->x, event_info->y);
452 return LB_STATUS_ERROR_FAULT;
455 return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
458 static int key_event_lb_consume_cb(enum event_state state, struct event_data *event_info, void *data)
460 struct script_info *script;
461 struct inst_info *inst = data;
462 const struct pkg_info *pkg;
465 pkg = instance_package(inst);
470 script = instance_lb_script(inst);
472 return LB_STATUS_ERROR_FAULT;
475 timestamp = util_timestamp();
478 case EVENT_STATE_ACTIVATE:
479 script_handler_update_keycode(script, event_info->keycode);
480 (void)script_handler_feed_event(script, LB_SCRIPT_KEY_DOWN, timestamp);
482 case EVENT_STATE_ACTIVATED:
483 script_handler_update_keycode(script, event_info->keycode);
484 (void)script_handler_feed_event(script, LB_SCRIPT_KEY_DOWN, timestamp);
486 case EVENT_STATE_DEACTIVATE:
487 script_handler_update_keycode(script, event_info->keycode);
488 (void)script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
491 ErrPrint("Unknown event\n");
498 static int mouse_event_lb_consume_cb(enum event_state state, struct event_data *event_info, void *data)
500 struct script_info *script;
501 struct inst_info *inst = data;
502 const struct pkg_info *pkg;
505 pkg = instance_package(inst);
510 script = instance_lb_script(inst);
512 return LB_STATUS_ERROR_FAULT;
515 timestamp = util_timestamp();
518 case EVENT_STATE_ACTIVATE:
519 script_handler_update_pointer(script, event_info->x, event_info->y, 1);
520 (void)script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
522 case EVENT_STATE_ACTIVATED:
523 script_handler_update_pointer(script, event_info->x, event_info->y, -1);
524 (void)script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
526 case EVENT_STATE_DEACTIVATE:
527 script_handler_update_pointer(script, event_info->x, event_info->y, 0);
528 (void)script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
537 static int key_event_pd_route_cb(enum event_state state, struct event_data *event_info, void *data)
539 struct inst_info *inst = data;
540 const struct pkg_info *pkg;
541 struct slave_node *slave;
542 struct packet *packet;
545 pkg = instance_package(inst);
547 return LB_STATUS_ERROR_INVALID;
550 slave = package_slave(pkg);
552 return LB_STATUS_ERROR_INVALID;
556 case EVENT_STATE_ACTIVATE:
557 cmdstr = "pd_key_down";
559 case EVENT_STATE_ACTIVATED:
560 cmdstr = "pd_key_down";
562 case EVENT_STATE_DEACTIVATE:
563 cmdstr = "pd_key_up";
566 return LB_STATUS_ERROR_INVALID;
569 packet = packet_create_noack(cmdstr, "ssdi", package_name(pkg), instance_id(inst), util_timestamp(), event_info->keycode);
571 return LB_STATUS_ERROR_FAULT;
574 return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
577 static int mouse_event_pd_route_cb(enum event_state state, struct event_data *event_info, void *data)
579 struct inst_info *inst = data;
580 const struct pkg_info *pkg;
581 struct slave_node *slave;
582 struct packet *packet;
585 pkg = instance_package(inst);
587 return LB_STATUS_ERROR_INVALID;
590 slave = package_slave(pkg);
592 return LB_STATUS_ERROR_INVALID;
596 case EVENT_STATE_ACTIVATE:
597 cmdstr = "pd_mouse_down";
599 case EVENT_STATE_ACTIVATED:
600 cmdstr = "pd_mouse_move";
602 case EVENT_STATE_DEACTIVATE:
603 cmdstr = "pd_mouse_up";
606 return LB_STATUS_ERROR_INVALID;
609 packet = packet_create_noack(cmdstr, "ssdii", package_name(pkg), instance_id(inst), util_timestamp(), event_info->x, event_info->y);
611 return LB_STATUS_ERROR_FAULT;
614 return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
617 static int key_event_pd_consume_cb(enum event_state state, struct event_data *event_info, void *data)
619 struct script_info *script;
620 struct inst_info *inst = data;
621 const struct pkg_info *pkg;
624 pkg = instance_package(inst);
629 script = instance_pd_script(inst);
631 return LB_STATUS_ERROR_FAULT;
634 timestamp = util_timestamp();
637 case EVENT_STATE_ACTIVATE:
638 script_handler_update_keycode(script, event_info->keycode);
639 (void)script_handler_feed_event(script, LB_SCRIPT_KEY_DOWN, timestamp);
641 case EVENT_STATE_ACTIVATED:
642 script_handler_update_keycode(script, event_info->keycode);
643 (void)script_handler_feed_event(script, LB_SCRIPT_KEY_DOWN, timestamp);
645 case EVENT_STATE_DEACTIVATE:
646 script_handler_update_keycode(script, event_info->keycode);
647 (void)script_handler_feed_event(script, LB_SCRIPT_KEY_UP, timestamp);
650 ErrPrint("Unknown event\n");
657 static int mouse_event_pd_consume_cb(enum event_state state, struct event_data *event_info, void *data)
659 struct script_info *script;
660 struct inst_info *inst = data;
661 const struct pkg_info *pkg;
664 pkg = instance_package(inst);
669 script = instance_pd_script(inst);
671 return LB_STATUS_ERROR_FAULT;
674 timestamp = util_timestamp();
677 case EVENT_STATE_ACTIVATE:
678 script_handler_update_pointer(script, event_info->x, event_info->y, 1);
679 (void)script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
681 case EVENT_STATE_ACTIVATED:
682 script_handler_update_pointer(script, event_info->x, event_info->y, -1);
683 (void)script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
685 case EVENT_STATE_DEACTIVATE:
686 script_handler_update_pointer(script, event_info->x, event_info->y, 0);
687 (void)script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
695 static struct packet *client_acquire(pid_t pid, int handle, const struct packet *packet) /*!< timestamp, ret */
697 struct client_node *client;
698 struct packet *result;
702 client = client_find_by_rpc_handle(handle);
704 ErrPrint("Client is already exists %d\n", pid);
705 ret = LB_STATUS_ERROR_EXIST;
709 if (packet_get(packet, "d", ×tamp) != 1) {
710 ErrPrint("Invalid arguemnt\n");
711 ret = LB_STATUS_ERROR_INVALID;
718 * client_create will invoke the client created callback
720 client = client_create(pid, handle);
722 ErrPrint("Failed to create a new client for %d\n", pid);
723 ret = LB_STATUS_ERROR_FAULT;
727 result = packet_create_reply(packet, "i", ret);
729 ErrPrint("Failed to create a packet\n");
735 static struct packet *cilent_release(pid_t pid, int handle, const struct packet *packet) /*!< pid, ret */
737 struct client_node *client;
738 struct packet *result;
741 client = client_find_by_rpc_handle(handle);
743 ErrPrint("Client %d is not exists\n", pid);
744 ret = LB_STATUS_ERROR_NOT_EXIST;
748 client_destroy(client);
752 result = packet_create_reply(packet, "i", ret);
754 ErrPrint("Failed to create a packet\n");
760 static int validate_request(const char *pkgname, const char *id, struct inst_info **out_inst, const struct pkg_info **out_pkg)
762 struct inst_info *inst;
763 const struct pkg_info *pkg;
765 inst = package_find_instance_by_id(pkgname, id);
767 ErrPrint("Instance is not exists (%s)\n", id);
768 return LB_STATUS_ERROR_NOT_EXIST;
771 pkg = instance_package(inst);
773 ErrPrint("System error - instance has no package?\n");
774 return LB_STATUS_ERROR_INVALID;
777 if (package_is_fault(pkg)) {
778 ErrPrint("Faulted package: %s\n", pkgname);
779 return LB_STATUS_ERROR_FAULT;
790 return LB_STATUS_SUCCESS;
793 /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
794 static struct packet *client_clicked(pid_t pid, int handle, const struct packet *packet)
796 struct client_node *client;
804 struct inst_info *inst = NULL;
806 client = client_find_by_rpc_handle(handle);
808 ErrPrint("Client %d is not exists\n", pid);
812 ret = packet_get(packet, "sssddd", &pkgname, &id, &event, ×tamp, &x, &y);
814 ErrPrint("Parameter is not matched\n");
820 * Trust the package name which are sent by the client.
821 * The package has to be a livebox package name.
823 ret = validate_request(pkgname, id, &inst, NULL);
824 if (ret == LB_STATUS_SUCCESS) {
825 (void)instance_clicked(inst, event, timestamp, x, y);
829 /*! \note No reply packet */
833 static struct packet *client_update_mode(pid_t pid, int handle, const struct packet *packet)
835 struct packet *result;
836 struct client_node *client;
841 struct inst_info *inst = NULL;
843 client = client_find_by_rpc_handle(handle);
845 ErrPrint("Client %d is not exists\n", pid);
846 ret = LB_STATUS_ERROR_INVALID;
850 ret = packet_get(packet, "ssi", &pkgname, &id, &active_update);
852 ErrPrint("Invalid argument\n");
853 ret = LB_STATUS_ERROR_INVALID;
857 ret = validate_request(pkgname, id, &inst, NULL);
858 if (ret == LB_STATUS_SUCCESS) {
861 * Send change update mode request to a slave
863 ret = instance_set_update_mode(inst, active_update);
867 result = packet_create_reply(packet, "i", ret);
869 ErrPrint("Failed to create a packet\n");
875 /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
876 static struct packet *client_text_signal(pid_t pid, int handle, const struct packet *packet)
878 struct client_node *client;
879 struct packet *result;
882 const char *emission;
888 struct inst_info *inst = NULL;
891 client = client_find_by_rpc_handle(handle);
893 ErrPrint("Client %d is not exists\n", pid);
894 ret = LB_STATUS_ERROR_NOT_EXIST;
898 ret = packet_get(packet, "ssssdddd", &pkgname, &id, &emission, &source, &sx, &sy, &ex, &ey);
900 ErrPrint("Parameter is not matched\n");
901 ret = LB_STATUS_ERROR_INVALID;
907 * Trust the package name which are sent by the client.
908 * The package has to be a livebox package name.
910 ret = validate_request(pkgname, id, &inst, NULL);
911 if (ret == LB_STATUS_SUCCESS) {
912 ret = instance_text_signal_emit(inst, emission, source, sx, sy, ex, ey);
916 result = packet_create_reply(packet, "i", ret);
918 ErrPrint("Failed to create a packet\n");
924 static Eina_Bool lazy_delete_cb(void *data)
926 struct deleted_item *item = data;
928 DbgPrint("Lazy delete callback called\n");
930 * Before invoke this callback, the instance is able to already remove this client
933 if (instance_has_client(item->inst, item->client)) {
934 (void)instance_unicast_deleted_event(item->inst, item->client, LB_STATUS_SUCCESS);
935 (void)instance_del_client(item->inst, item->client);
938 (void)client_unref(item->client);
939 (void)instance_unref(item->inst);
941 return ECORE_CALLBACK_CANCEL;
944 static struct packet *client_delete(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
946 struct client_node *client;
947 struct packet *result;
950 struct inst_info *inst = NULL;
951 const struct pkg_info *pkg;
955 client = client_find_by_rpc_handle(handle);
957 ErrPrint("Client %d is not exists\n", pid);
958 ret = LB_STATUS_ERROR_NOT_EXIST;
962 ret = packet_get(packet, "ssi", &pkgname, &id, &type);
964 ErrPrint("Parameter is not matched\n");
965 ret = LB_STATUS_ERROR_INVALID;
970 * Below two types must has to be sync'd with livebox-viewer
972 * LB_DELETE_PERMANENTLY = 0x01,
973 * LB_DELETE_TEMPORARY = 0x02,
979 * Trust the package name which are sent by the client.
980 * The package has to be a livebox package name.
982 ret = validate_request(pkgname, id, &inst, &pkg);
983 if (ret != LB_STATUS_SUCCESS) {
987 if (package_is_fault(pkg)) {
988 DbgPrint("Faulted package. will be deleted soon: %s\n", id);
989 ret = LB_STATUS_ERROR_FAULT;
993 if (instance_client(inst) != client) {
994 if (instance_has_client(inst, client)) {
995 struct deleted_item *item;
997 item = malloc(sizeof(*item));
999 ErrPrint("Heap: %s\n", strerror(errno));
1000 ret = LB_STATUS_ERROR_MEMORY;
1004 * Send DELETED EVENT to the client.
1005 * after return from this function.
1007 * Client will prepare the deleted event after get this function's return value.
1008 * So We have to make a delay to send a deleted event.
1011 item->client = client_ref(client);
1012 item->inst = instance_ref(inst);
1014 if (!ecore_timer_add(DELAY_TIME, lazy_delete_cb, item)) {
1015 ErrPrint("Failed to add a delayzed delete callback\n");
1016 (void)client_unref(client);
1017 (void)instance_unref(inst);
1019 ret = LB_STATUS_ERROR_FAULT;
1021 ret = LB_STATUS_SUCCESS;
1025 ErrPrint("Client has no permission\n");
1026 ret = LB_STATUS_ERROR_PERMISSION;
1030 case LB_DELETE_PERMANENTLY:
1031 ret = instance_destroy(inst, INSTANCE_DESTROY_DEFAULT);
1033 case LB_DELETE_TEMPORARY:
1034 ret = instance_destroy(inst, INSTANCE_DESTROY_TEMPORARY);
1042 result = packet_create_reply(packet, "i", ret);
1044 ErrPrint("Failed to create a packet\n");
1050 static struct packet *client_resize(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, w, h, ret */
1052 struct client_node *client;
1053 struct packet *result;
1054 const char *pkgname;
1058 struct inst_info *inst = NULL;
1061 client = client_find_by_rpc_handle(handle);
1063 ErrPrint("Client %d is not exists\n", pid);
1064 ret = LB_STATUS_ERROR_NOT_EXIST;
1068 ret = packet_get(packet, "ssii", &pkgname, &id, &w, &h);
1070 ErrPrint("Parameter is not matched\n");
1071 ret = LB_STATUS_ERROR_INVALID;
1075 DbgPrint("RESIZE: Client request resize to %dx%d (pid: %d, pkgname: %s)\n", w, h, pid, pkgname);
1079 * Trust the package name which are sent by the client.
1080 * The package has to be a livebox package name.
1082 ret = validate_request(pkgname, id, &inst, NULL);
1083 if (ret != LB_STATUS_SUCCESS) {
1087 if (instance_client(inst) != client) {
1088 ret = LB_STATUS_ERROR_PERMISSION;
1090 ret = instance_resize(inst, w, h);
1094 result = packet_create_reply(packet, "i", ret);
1096 ErrPrint("Failed to create a packet\n");
1102 static struct packet *client_new(pid_t pid, int handle, const struct packet *packet) /* pid, timestamp, pkgname, content, cluster, category, period, ret */
1104 struct client_node *client;
1105 struct packet *result;
1106 const char *pkgname;
1107 const char *content;
1108 const char *cluster;
1109 const char *category;
1113 struct pkg_info *info;
1119 client = client_find_by_rpc_handle(handle);
1121 ErrPrint("Client %d is not exists\n", pid);
1122 ret = LB_STATUS_ERROR_NOT_EXIST;
1126 ret = packet_get(packet, "dssssdii", ×tamp, &pkgname, &content, &cluster, &category, &period, &width, &height);
1128 ErrPrint("Parameter is not matched\n");
1129 ret = LB_STATUS_ERROR_INVALID;
1133 DbgPrint("pid[%d] period[%lf] pkgname[%s] content[%s] cluster[%s] category[%s] period[%lf]\n",
1134 pid, timestamp, pkgname, content, cluster, category, period);
1136 lbid = package_lb_pkgname(pkgname);
1138 ErrPrint("This %s has no livebox package\n", pkgname);
1139 ret = LB_STATUS_ERROR_INVALID;
1143 mainappid = livebox_service_mainappid(lbid);
1144 if (!package_is_enabled(mainappid)) {
1147 ret = LB_STATUS_ERROR_DISABLED;
1152 info = package_find(lbid);
1155 pkgid = livebox_service_appid(lbid);
1159 ret = LB_STATUS_ERROR_FAULT;
1163 info = package_create(pkgid, lbid);
1168 ret = LB_STATUS_ERROR_FAULT;
1169 } else if (package_is_fault(info)) {
1170 ret = LB_STATUS_ERROR_FAULT;
1171 } else if (util_free_space(IMAGE_PATH) <= MINIMUM_SPACE) {
1172 ErrPrint("Not enough space\n");
1173 ret = LB_STATUS_ERROR_NO_SPACE;
1175 struct inst_info *inst;
1177 if (period > 0.0f && period < MINIMUM_PERIOD) {
1178 period = MINIMUM_PERIOD;
1181 inst = instance_create(client, timestamp, lbid, content, cluster, category, period, width, height);
1184 * Using the "inst" without validate its value is at my disposal. ;)
1186 ret = inst ? 0 : LB_STATUS_ERROR_FAULT;
1192 result = packet_create_reply(packet, "i", ret);
1194 ErrPrint("Failed to create a packet\n");
1200 static struct packet *client_change_visibility(pid_t pid, int handle, const struct packet *packet)
1202 struct client_node *client;
1203 const char *pkgname;
1205 enum livebox_visible_state state;
1207 struct inst_info *inst = NULL;
1209 client = client_find_by_rpc_handle(handle);
1211 ErrPrint("Client %d is not exists\n", pid);
1212 ret = LB_STATUS_ERROR_NOT_EXIST;
1216 ret = packet_get(packet, "ssi", &pkgname, &id, (int *)&state);
1218 ErrPrint("Parameter is not matched\n");
1219 ret = LB_STATUS_ERROR_INVALID;
1225 * Trust the package name which are sent by the client.
1226 * The package has to be a livebox package name.
1228 ret = validate_request(pkgname, id, &inst, NULL);
1229 if (ret != LB_STATUS_SUCCESS) {
1233 if (instance_client(inst) != client) {
1234 ret = LB_STATUS_ERROR_PERMISSION;
1236 ret = instance_set_visible_state(inst, state);
1240 /*! \note No reply packet */
1244 static struct packet *client_set_period(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, period, ret */
1246 struct client_node *client;
1247 struct packet *result;
1248 const char *pkgname;
1252 struct inst_info *inst = NULL;
1254 client = client_find_by_rpc_handle(handle);
1256 ErrPrint("Client %d is not exists\n", pid);
1257 ret = LB_STATUS_ERROR_NOT_EXIST;
1261 ret = packet_get(packet, "ssd", &pkgname, &id, &period);
1263 ErrPrint("Parameter is not matched\n");
1264 ret = LB_STATUS_ERROR_INVALID;
1268 DbgPrint("pid[%d] pkgname[%s] period[%lf]\n", pid, pkgname, period);
1272 * Trust the package name which are sent by the client.
1273 * The package has to be a livebox package name.
1275 ret = validate_request(pkgname, id, &inst, NULL);
1276 if (ret != LB_STATUS_SUCCESS) {
1280 if (instance_client(inst) != client) {
1281 ret = LB_STATUS_ERROR_PERMISSION;
1283 ret = instance_set_period(inst, period);
1287 result = packet_create_reply(packet, "i", ret);
1289 ErrPrint("Failed to create a packet\n");
1295 static struct packet *client_change_group(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, cluster, category, ret */
1297 struct client_node *client;
1298 struct packet *result;
1299 const char *pkgname;
1301 const char *cluster;
1302 const char *category;
1303 struct inst_info *inst = NULL;
1306 client = client_find_by_rpc_handle(handle);
1308 ErrPrint("Client %d is not exists\n", pid);
1309 ret = LB_STATUS_ERROR_NOT_EXIST;
1313 ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category);
1315 ErrPrint("Parameter is not matched\n");
1316 ret = LB_STATUS_ERROR_INVALID;
1320 DbgPrint("pid[%d] pkgname[%s] cluster[%s] category[%s]\n", pid, pkgname, cluster, category);
1324 * Trust the package name which are sent by the client.
1325 * The package has to be a livebox package name.
1327 ret = validate_request(pkgname, id, &inst, NULL);
1328 if (ret != LB_STATUS_SUCCESS) {
1332 if (instance_client(inst) != client) {
1333 ret = LB_STATUS_ERROR_PERMISSION;
1335 ret = instance_change_group(inst, cluster, category);
1339 result = packet_create_reply(packet, "i", ret);
1341 ErrPrint("Failed to create a packet\n");
1347 static struct packet *client_pd_mouse_enter(pid_t pid, int handle, const struct packet *packet)
1349 struct client_node *client;
1350 const char *pkgname;
1356 struct inst_info *inst = NULL;
1357 const struct pkg_info *pkg = NULL;
1359 client = client_find_by_rpc_handle(handle);
1361 ErrPrint("Client %d is not exists\n", pid);
1362 ret = LB_STATUS_ERROR_NOT_EXIST;
1366 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1368 ErrPrint("Invalid parameter\n");
1369 ret = LB_STATUS_ERROR_INVALID;
1373 ret = validate_request(pkgname, id, &inst, &pkg);
1374 if (ret != LB_STATUS_SUCCESS) {
1378 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1379 ret = forward_pd_event_packet(pkg, inst, packet);
1380 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1381 struct script_info *script;
1383 script = instance_pd_script(inst);
1385 ret = LB_STATUS_ERROR_FAULT;
1389 script_handler_update_pointer(script, x, y, -1);
1390 script_handler_feed_event(script, LB_SCRIPT_MOUSE_IN, timestamp);
1393 ErrPrint("Unsupported package\n");
1394 ret = LB_STATUS_ERROR_INVALID;
1398 /*! \note No reply packet */
1402 static struct packet *client_pd_mouse_leave(pid_t pid, int handle, const struct packet *packet)
1404 struct client_node *client;
1405 const char *pkgname;
1411 struct inst_info *inst = NULL;
1412 const struct pkg_info *pkg = NULL;
1414 client = client_find_by_rpc_handle(handle);
1416 ErrPrint("Client %d is not exists\n", pid);
1417 ret = LB_STATUS_ERROR_NOT_EXIST;
1421 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1423 ErrPrint("Parameter is not matched\n");
1424 ret = LB_STATUS_ERROR_INVALID;
1428 ret = validate_request(pkgname, id, &inst, &pkg);
1429 if (ret != LB_STATUS_SUCCESS) {
1433 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1434 ret = forward_pd_event_packet(pkg, inst, packet);
1435 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1436 struct script_info *script;
1438 script = instance_pd_script(inst);
1440 ret = LB_STATUS_ERROR_FAULT;
1444 script_handler_update_pointer(script, x, y, -1);
1445 script_handler_feed_event(script, LB_SCRIPT_MOUSE_OUT, timestamp);
1448 ErrPrint("Unsupported package\n");
1449 ret = LB_STATUS_ERROR_INVALID;
1453 /*! \note No reply packet */
1457 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 */
1459 struct client_node *client;
1460 const char *pkgname;
1466 struct inst_info *inst = NULL;
1467 const struct pkg_info *pkg = NULL;
1469 client = client_find_by_rpc_handle(handle);
1471 ErrPrint("Client %d is not exists\n", pid);
1472 ret = LB_STATUS_ERROR_NOT_EXIST;
1476 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1478 ErrPrint("Parameter is not matched\n");
1479 ret = LB_STATUS_ERROR_INVALID;
1483 ret = validate_request(pkgname, id, &inst, &pkg);
1484 if (ret != LB_STATUS_SUCCESS) {
1488 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1489 ret = forward_pd_event_packet(pkg, inst, packet);
1490 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1491 struct script_info *script;
1493 script = instance_pd_script(inst);
1495 ret = LB_STATUS_ERROR_FAULT;
1499 script_handler_update_pointer(script, x, y, 1);
1500 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
1503 ErrPrint("Unsupported package\n");
1504 ret = LB_STATUS_ERROR_INVALID;
1508 /*! \note No reply packet */
1512 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 */
1514 struct client_node *client;
1515 const char *pkgname;
1521 struct inst_info *inst = NULL;
1522 const struct pkg_info *pkg = NULL;
1524 client = client_find_by_rpc_handle(handle);
1526 ErrPrint("Client %d is not exists\n", pid);
1527 ret = LB_STATUS_ERROR_NOT_EXIST;
1531 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1533 ErrPrint("Parameter is not matched\n");
1534 ret = LB_STATUS_ERROR_INVALID;
1538 ret = validate_request(pkgname, id, &inst, &pkg);
1539 if (ret != LB_STATUS_SUCCESS) {
1543 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1544 ret = forward_pd_event_packet(pkg, inst, packet);
1545 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1546 struct script_info *script;
1548 script = instance_pd_script(inst);
1550 ret = LB_STATUS_ERROR_FAULT;
1554 script_handler_update_pointer(script, x, y, 0);
1555 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
1558 ErrPrint("Unsupported package\n");
1559 ret = LB_STATUS_ERROR_INVALID;
1563 /*! \note No reply packet */
1567 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 */
1569 struct client_node *client;
1570 const char *pkgname;
1576 struct inst_info *inst = NULL;
1577 const struct pkg_info *pkg = NULL;
1579 client = client_find_by_rpc_handle(handle);
1581 ErrPrint("Client %d is not exists\n", pid);
1582 ret = LB_STATUS_ERROR_NOT_EXIST;
1586 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1588 ErrPrint("Parameter is not matched\n");
1589 ret = LB_STATUS_ERROR_INVALID;
1593 ret = validate_request(pkgname, id, &inst, &pkg);
1594 if (ret != LB_STATUS_SUCCESS) {
1598 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1599 ret = forward_pd_event_packet(pkg, inst, packet);
1600 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1601 struct script_info *script;
1603 script = instance_pd_script(inst);
1605 ret = LB_STATUS_ERROR_FAULT;
1609 script_handler_update_pointer(script, x, y, -1);
1610 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
1613 ErrPrint("Unsupported package\n");
1614 ret = LB_STATUS_ERROR_INVALID;
1618 /*! \note No reply packet */
1622 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 */
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_lb_type(pkg) == LB_TYPE_BUFFER) {
1654 ret = forward_lb_event_packet(pkg, inst, packet);
1655 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1656 struct script_info *script;
1658 script = instance_lb_script(inst);
1660 ret = LB_STATUS_ERROR_FAULT;
1664 script_handler_update_pointer(script, x, y, -1);
1665 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
1668 ErrPrint("Unsupported package\n");
1669 ret = LB_STATUS_ERROR_INVALID;
1673 /*! \note No reply packet */
1677 static int inst_del_cb(struct inst_info *inst, void *data)
1679 (void)event_deactivate(data, inst);
1680 return -1; /* Delete this callback */
1684 static struct packet *client_pd_key_set(pid_t pid, int handle, const struct packet *packet)
1686 struct client_node *client;
1687 const char *pkgname;
1691 unsigned int keycode;
1692 struct inst_info *inst;
1693 const struct pkg_info *pkg;
1694 struct packet *result;
1696 client = client_find_by_rpc_handle(handle);
1698 ErrPrint("Client %d is not exists\n", pid);
1699 ret = LB_STATUS_ERROR_NOT_EXIST;
1703 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
1705 ErrPrint("Parameter is not matched\n");
1706 ret = LB_STATUS_ERROR_INVALID;
1710 ret = validate_request(pkgname, id, &inst, &pkg);
1711 if (ret != LB_STATUS_SUCCESS) {
1715 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1716 ret = event_activate(0, 0, key_event_pd_route_cb, inst);
1718 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_pd_route_cb);
1720 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1721 ret = event_activate(0, 0, key_event_pd_consume_cb, inst);
1723 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_pd_consume_cb);
1726 ErrPrint("Unsupported package\n");
1727 ret = LB_STATUS_ERROR_INVALID;
1731 result = packet_create_reply(packet, "i", ret);
1733 ErrPrint("Failed to create a reply packet\n");
1739 static struct packet *client_pd_key_unset(pid_t pid, int handle, const struct packet *packet)
1741 struct client_node *client;
1742 const char *pkgname;
1746 unsigned int keycode;
1747 struct inst_info *inst;
1748 const struct pkg_info *pkg;
1749 struct packet *result;
1751 client = client_find_by_rpc_handle(handle);
1753 ErrPrint("Client %d is not exists\n", pid);
1754 ret = LB_STATUS_ERROR_NOT_EXIST;
1758 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
1760 ErrPrint("Parameter is not matched\n");
1761 ret = LB_STATUS_ERROR_INVALID;
1765 ret = validate_request(pkgname, id, &inst, &pkg);
1766 if (ret != LB_STATUS_SUCCESS) {
1770 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1771 ret = event_deactivate(key_event_pd_route_cb, inst);
1773 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_pd_route_cb);
1775 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1776 ret = event_deactivate(key_event_pd_consume_cb, inst);
1778 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_pd_consume_cb);
1781 ErrPrint("Unsupported package\n");
1782 ret = LB_STATUS_ERROR_INVALID;
1786 result = packet_create_reply(packet, "i", ret);
1788 ErrPrint("Failed to create a reply packet\n");
1794 static struct packet *client_lb_key_set(pid_t pid, int handle, const struct packet *packet)
1796 struct client_node *client;
1797 const char *pkgname;
1801 unsigned int keycode;
1802 struct inst_info *inst;
1803 const struct pkg_info *pkg;
1804 struct packet *result;
1806 client = client_find_by_rpc_handle(handle);
1808 ErrPrint("Client %d is not exists\n", pid);
1809 ret = LB_STATUS_ERROR_NOT_EXIST;
1813 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
1815 ErrPrint("Parameter is not matched\n");
1816 ret = LB_STATUS_ERROR_INVALID;
1820 ret = validate_request(pkgname, id, &inst, &pkg);
1821 if (ret != LB_STATUS_SUCCESS) {
1825 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1826 ret = event_activate(0, 0, key_event_lb_route_cb, inst);
1828 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_lb_route_cb);
1830 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1831 ret = event_activate(0, 0, key_event_lb_consume_cb, inst);
1833 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_lb_consume_cb);
1836 ErrPrint("Unsupported package\n");
1837 ret = LB_STATUS_ERROR_INVALID;
1841 result = packet_create_reply(packet, "i", ret);
1843 ErrPrint("Failed to create a reply packet\n");
1849 static struct packet *client_lb_key_unset(pid_t pid, int handle, const struct packet *packet)
1851 struct client_node *client;
1852 const char *pkgname;
1856 unsigned int keycode;
1857 struct inst_info *inst;
1858 const struct pkg_info *pkg;
1859 struct packet *result;
1861 client = client_find_by_rpc_handle(handle);
1863 ErrPrint("Client %d is not exists\n", pid);
1864 ret = LB_STATUS_ERROR_NOT_EXIST;
1868 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
1870 ErrPrint("Parameter is not matched\n");
1871 ret = LB_STATUS_ERROR_INVALID;
1875 ret = validate_request(pkgname, id, &inst, &pkg);
1876 if (ret != LB_STATUS_SUCCESS) {
1880 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1881 ret = event_deactivate(key_event_lb_route_cb, inst);
1883 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_lb_route_cb);
1885 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1886 ret = event_deactivate(key_event_lb_consume_cb, inst);
1888 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_lb_consume_cb);
1891 ErrPrint("Unsupported package\n");
1892 ret = LB_STATUS_ERROR_INVALID;
1896 result = packet_create_reply(packet, "i", ret);
1898 ErrPrint("Failed to create a reply packet\n");
1904 static struct packet *client_lb_mouse_set(pid_t pid, int handle, const struct packet *packet)
1906 struct client_node *client;
1907 const char *pkgname;
1913 struct inst_info *inst = NULL;
1914 const struct pkg_info *pkg = NULL;
1916 client = client_find_by_rpc_handle(handle);
1918 ErrPrint("Client %d is not exists\n", pid);
1919 ret = LB_STATUS_ERROR_NOT_EXIST;
1923 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1925 ErrPrint("Parameter is not matched\n");
1926 ret = LB_STATUS_ERROR_INVALID;
1930 ret = validate_request(pkgname, id, &inst, &pkg);
1931 if (ret != LB_STATUS_SUCCESS) {
1935 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1936 ret = event_activate(x, y, mouse_event_lb_route_cb, inst);
1938 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_lb_route_cb);
1940 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1941 ret = event_activate(x, y, mouse_event_lb_consume_cb, inst);
1943 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_lb_consume_cb);
1946 ErrPrint("Unsupported package\n");
1947 ret = LB_STATUS_ERROR_INVALID;
1953 static struct packet *client_lb_mouse_unset(pid_t pid, int handle, const struct packet *packet)
1955 struct client_node *client;
1956 const char *pkgname;
1962 struct inst_info *inst = NULL;
1963 const struct pkg_info *pkg = NULL;
1965 client = client_find_by_rpc_handle(handle);
1967 ErrPrint("Client %d is not exists\n", pid);
1968 ret = LB_STATUS_ERROR_NOT_EXIST;
1972 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1974 ErrPrint("Parameter is not matched\n");
1975 ret = LB_STATUS_ERROR_INVALID;
1979 ret = validate_request(pkgname, id, &inst, &pkg);
1980 if (ret != LB_STATUS_SUCCESS) {
1984 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1985 ret = event_deactivate(mouse_event_lb_route_cb, inst);
1987 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_lb_route_cb);
1989 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1990 ret = event_deactivate(mouse_event_lb_consume_cb, inst);
1992 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_lb_consume_cb);
1995 ErrPrint("Unsupported package\n");
1996 ret = LB_STATUS_ERROR_INVALID;
2002 static struct packet *client_pd_mouse_set(pid_t pid, int handle, const struct packet *packet)
2004 struct client_node *client;
2005 const char *pkgname;
2011 struct inst_info *inst = NULL;
2012 const struct pkg_info *pkg = NULL;
2014 client = client_find_by_rpc_handle(handle);
2016 ErrPrint("Client %d is not exists\n", pid);
2017 ret = LB_STATUS_ERROR_NOT_EXIST;
2021 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2023 ErrPrint("Parameter is not matched\n");
2024 ret = LB_STATUS_ERROR_INVALID;
2028 ret = validate_request(pkgname, id, &inst, &pkg);
2029 if (ret != LB_STATUS_SUCCESS) {
2033 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2034 ret = event_activate(x, y, mouse_event_pd_route_cb, inst);
2036 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_pd_route_cb);
2038 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2039 ret = event_activate(x, y, mouse_event_pd_consume_cb, inst);
2041 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_pd_consume_cb);
2044 ErrPrint("Unsupported package\n");
2045 ret = LB_STATUS_ERROR_INVALID;
2052 static struct packet *client_pd_mouse_unset(pid_t pid, int handle, const struct packet *packet)
2054 struct client_node *client;
2055 const char *pkgname;
2061 struct inst_info *inst = NULL;
2062 const struct pkg_info *pkg = NULL;
2064 client = client_find_by_rpc_handle(handle);
2066 ErrPrint("Client %d is not exists\n", pid);
2067 ret = LB_STATUS_ERROR_NOT_EXIST;
2071 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2073 ErrPrint("Parameter is not matched\n");
2074 ret = LB_STATUS_ERROR_INVALID;
2078 ret = validate_request(pkgname, id, &inst, &pkg);
2079 if (ret != LB_STATUS_SUCCESS) {
2083 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2084 ret = event_deactivate(mouse_event_pd_route_cb, inst);
2086 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_pd_route_cb);
2088 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2089 ret = event_deactivate(mouse_event_pd_consume_cb, inst);
2091 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_pd_consume_cb);
2094 ErrPrint("Unsupported package\n");
2095 ret = LB_STATUS_ERROR_INVALID;
2101 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 */
2103 struct client_node *client;
2104 const char *pkgname;
2110 struct inst_info *inst = NULL;
2111 const struct pkg_info *pkg = NULL;
2113 client = client_find_by_rpc_handle(handle);
2115 ErrPrint("Client %d is not exists\n", pid);
2116 ret = LB_STATUS_ERROR_NOT_EXIST;
2120 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2122 ErrPrint("Parameter is not matched\n");
2123 ret = LB_STATUS_ERROR_INVALID;
2127 ret = validate_request(pkgname, id, &inst, &pkg);
2128 if (ret != LB_STATUS_SUCCESS) {
2132 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2133 ret = forward_lb_event_packet(pkg, inst, packet);
2134 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2135 struct script_info *script;
2137 script = instance_lb_script(inst);
2139 ret = LB_STATUS_ERROR_FAULT;
2143 script_handler_update_pointer(script, x, y, -1);
2144 script_handler_feed_event(script, LB_SCRIPT_MOUSE_IN, timestamp);
2147 ErrPrint("Unsupported package\n");
2148 ret = LB_STATUS_ERROR_INVALID;
2152 /*! \note No reply packet */
2156 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 */
2158 struct client_node *client;
2159 const char *pkgname;
2165 struct inst_info *inst = NULL;
2166 const struct pkg_info *pkg = NULL;
2168 client = client_find_by_rpc_handle(handle);
2170 ErrPrint("Client %d is not exists\n", pid);
2171 ret = LB_STATUS_ERROR_NOT_EXIST;
2175 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2177 ErrPrint("Parameter is not matched\n");
2178 ret = LB_STATUS_ERROR_INVALID;
2182 ret = validate_request(pkgname, id, &inst, &pkg);
2183 if (ret != LB_STATUS_SUCCESS) {
2187 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2188 ret = forward_lb_event_packet(pkg, inst, packet);
2189 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2190 struct script_info *script;
2192 script = instance_lb_script(inst);
2194 ret = LB_STATUS_ERROR_FAULT;
2198 script_handler_update_pointer(script, x, y, -1);
2199 script_handler_feed_event(script, LB_SCRIPT_MOUSE_OUT, timestamp);
2202 ErrPrint("Unsupported package\n");
2203 ret = LB_STATUS_ERROR_INVALID;
2207 /*! \note No reply packet */
2211 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 */
2213 struct client_node *client;
2214 const char *pkgname;
2220 struct inst_info *inst = NULL;
2221 const struct pkg_info *pkg = NULL;
2223 client = client_find_by_rpc_handle(handle);
2225 ErrPrint("Client %d is not exists\n", pid);
2226 ret = LB_STATUS_ERROR_NOT_EXIST;
2230 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2232 ErrPrint("Parameter is not matched\n");
2233 ret = LB_STATUS_ERROR_INVALID;
2237 ret = validate_request(pkgname, id, &inst, &pkg);
2238 if (ret != LB_STATUS_SUCCESS) {
2242 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2243 ret = forward_lb_event_packet(pkg, inst, packet);
2244 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2245 struct script_info *script;
2247 script = instance_lb_script(inst);
2249 ret = LB_STATUS_ERROR_FAULT;
2253 script_handler_update_pointer(script, x, y, 1);
2254 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
2257 ErrPrint("Unsupported package\n");
2258 ret = LB_STATUS_ERROR_INVALID;
2262 /*! \note No reply packet */
2266 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 */
2268 struct client_node *client;
2269 const char *pkgname;
2275 struct inst_info *inst = NULL;
2276 const struct pkg_info *pkg = NULL;
2278 client = client_find_by_rpc_handle(handle);
2280 ErrPrint("Client %d is not exists\n", pid);
2281 ret = LB_STATUS_ERROR_NOT_EXIST;
2285 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2287 ErrPrint("Parameter is not matched\n");
2288 ret = LB_STATUS_ERROR_INVALID;
2292 ret = validate_request(pkgname, id, &inst, &pkg);
2293 if (ret != LB_STATUS_SUCCESS) {
2297 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2298 ret = forward_lb_event_packet(pkg, inst, packet);
2299 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2300 struct script_info *script;
2302 script = instance_lb_script(inst);
2304 ret = LB_STATUS_ERROR_FAULT;
2308 script_handler_update_pointer(script, x, y, 0);
2309 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
2312 ErrPrint("Unsupported package\n");
2313 ret = LB_STATUS_ERROR_INVALID;
2317 /*! \note No reply packet */
2321 static struct packet *client_pd_access_action_up(pid_t pid, int handle, const struct packet *packet)
2323 struct packet *result;
2324 struct client_node *client;
2325 const char *pkgname;
2331 struct inst_info *inst = NULL;
2332 const struct pkg_info *pkg = NULL;
2334 client = client_find_by_rpc_handle(handle);
2336 ErrPrint("Client %d is not exists\n", pid);
2337 ret = LB_STATUS_ERROR_NOT_EXIST;
2341 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2343 ErrPrint("Invalid parameter\n");
2344 ret = LB_STATUS_ERROR_INVALID;
2348 ret = validate_request(pkgname, id, &inst, &pkg);
2349 if (ret != LB_STATUS_SUCCESS) {
2353 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2354 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2355 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2356 struct script_info *script;
2358 script = instance_pd_script(inst);
2360 ret = LB_STATUS_ERROR_FAULT;
2364 script_handler_update_pointer(script, x, y, 0);
2365 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
2367 struct event_cbdata *cbdata;
2369 cbdata = malloc(sizeof(*cbdata));
2371 ret = LB_STATUS_ERROR_MEMORY;
2373 cbdata->inst = instance_ref(inst);
2374 cbdata->status = ret;
2376 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2377 (void)instance_unref(cbdata->inst);
2379 ret = LB_STATUS_ERROR_FAULT;
2381 ret = LB_STATUS_SUCCESS;
2386 ErrPrint("Unsupported package\n");
2387 ret = LB_STATUS_ERROR_INVALID;
2391 result = packet_create_reply(packet, "i", ret);
2393 ErrPrint("Failed to create a reply packet\n");
2399 static struct packet *client_pd_access_action_down(pid_t pid, int handle, const struct packet *packet)
2401 struct packet *result;
2402 struct client_node *client;
2403 const char *pkgname;
2409 struct inst_info *inst = NULL;
2410 const struct pkg_info *pkg = NULL;
2412 client = client_find_by_rpc_handle(handle);
2414 ErrPrint("Client %d is not exists\n", pid);
2415 ret = LB_STATUS_ERROR_NOT_EXIST;
2419 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2421 ErrPrint("Invalid parameter\n");
2422 ret = LB_STATUS_ERROR_INVALID;
2426 ret = validate_request(pkgname, id, &inst, &pkg);
2427 if (ret != LB_STATUS_SUCCESS) {
2431 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2432 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2433 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2434 struct script_info *script;
2436 script = instance_pd_script(inst);
2438 ret = LB_STATUS_ERROR_FAULT;
2442 script_handler_update_pointer(script, x, y, 1);
2443 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
2445 struct event_cbdata *cbdata;
2447 cbdata = malloc(sizeof(*cbdata));
2449 ret = LB_STATUS_ERROR_MEMORY;
2451 cbdata->inst = instance_ref(inst);
2452 cbdata->status = ret;
2454 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2455 (void)instance_unref(cbdata->inst);
2457 ret = LB_STATUS_ERROR_FAULT;
2459 ret = LB_STATUS_SUCCESS;
2464 ErrPrint("Unsupported package\n");
2465 ret = LB_STATUS_ERROR_INVALID;
2469 result = packet_create_reply(packet, "i", ret);
2471 ErrPrint("Failed to create a reply packet\n");
2477 static struct packet *client_pd_access_scroll_down(pid_t pid, int handle, const struct packet *packet)
2479 struct packet *result;
2480 struct client_node *client;
2481 const char *pkgname;
2487 struct inst_info *inst = NULL;
2488 const struct pkg_info *pkg = NULL;
2490 client = client_find_by_rpc_handle(handle);
2492 ErrPrint("Client %d is not exists\n", pid);
2493 ret = LB_STATUS_ERROR_NOT_EXIST;
2497 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2499 ErrPrint("Invalid parameter\n");
2500 ret = LB_STATUS_ERROR_INVALID;
2504 ret = validate_request(pkgname, id, &inst, &pkg);
2505 if (ret != LB_STATUS_SUCCESS) {
2509 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2510 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2511 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2512 struct script_info *script;
2514 script = instance_pd_script(inst);
2516 ret = LB_STATUS_ERROR_FAULT;
2520 script_handler_update_pointer(script, x, y, 1);
2521 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
2523 struct event_cbdata *cbdata;
2525 cbdata = malloc(sizeof(*cbdata));
2527 ret = LB_STATUS_ERROR_MEMORY;
2529 cbdata->inst = instance_ref(inst);
2530 cbdata->status = ret;
2532 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2533 (void)instance_unref(cbdata->inst);
2535 ret = LB_STATUS_ERROR_FAULT;
2537 ret = LB_STATUS_SUCCESS;
2542 ErrPrint("Unsupported package\n");
2543 ret = LB_STATUS_ERROR_INVALID;
2547 result = packet_create_reply(packet, "i", ret);
2549 ErrPrint("Failed to create a reply packet\n");
2555 static struct packet *client_pd_access_scroll_move(pid_t pid, int handle, const struct packet *packet)
2557 struct packet *result;
2558 struct client_node *client;
2559 const char *pkgname;
2565 struct inst_info *inst = NULL;
2566 const struct pkg_info *pkg = NULL;
2568 client = client_find_by_rpc_handle(handle);
2570 ErrPrint("Client %d is not exists\n", pid);
2571 ret = LB_STATUS_ERROR_NOT_EXIST;
2575 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2577 ErrPrint("Invalid parameter\n");
2578 ret = LB_STATUS_ERROR_INVALID;
2582 ret = validate_request(pkgname, id, &inst, &pkg);
2583 if (ret != LB_STATUS_SUCCESS) {
2587 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2588 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2589 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2590 struct script_info *script;
2592 script = instance_pd_script(inst);
2594 ret = LB_STATUS_ERROR_FAULT;
2598 script_handler_update_pointer(script, x, y, -1);
2599 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
2601 struct event_cbdata *cbdata;
2603 cbdata = malloc(sizeof(*cbdata));
2605 ret = LB_STATUS_ERROR_MEMORY;
2607 cbdata->inst = instance_ref(inst);
2608 cbdata->status = ret;
2610 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2611 (void)instance_unref(cbdata->inst);
2613 ret = LB_STATUS_ERROR_FAULT;
2615 ret = LB_STATUS_SUCCESS;
2620 ErrPrint("Unsupported package\n");
2621 ret = LB_STATUS_ERROR_INVALID;
2625 result = packet_create_reply(packet, "i", ret);
2627 ErrPrint("Failed to create a reply packet\n");
2633 static struct packet *client_pd_access_scroll_up(pid_t pid, int handle, const struct packet *packet)
2635 struct packet *result;
2636 struct client_node *client;
2637 const char *pkgname;
2643 struct inst_info *inst = NULL;
2644 const struct pkg_info *pkg = NULL;
2646 client = client_find_by_rpc_handle(handle);
2648 ErrPrint("Client %d is not exists\n", pid);
2649 ret = LB_STATUS_ERROR_NOT_EXIST;
2653 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2655 ErrPrint("Invalid parameter\n");
2656 ret = LB_STATUS_ERROR_INVALID;
2660 ret = validate_request(pkgname, id, &inst, &pkg);
2661 if (ret != LB_STATUS_SUCCESS) {
2665 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2666 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2667 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2668 struct script_info *script;
2670 script = instance_pd_script(inst);
2672 ret = LB_STATUS_ERROR_FAULT;
2676 script_handler_update_pointer(script, x, y, 0);
2677 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
2679 struct event_cbdata *cbdata;
2681 cbdata = malloc(sizeof(*cbdata));
2683 ret = LB_STATUS_ERROR_MEMORY;
2685 cbdata->inst = instance_ref(inst);
2686 cbdata->status = ret;
2688 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2689 (void)instance_unref(cbdata->inst);
2691 ret = LB_STATUS_ERROR_FAULT;
2693 ret = LB_STATUS_SUCCESS;
2698 ErrPrint("Unsupported package\n");
2699 ret = LB_STATUS_ERROR_INVALID;
2703 result = packet_create_reply(packet, "i", ret);
2705 ErrPrint("Failed to create a reply packet\n");
2711 static struct packet *client_pd_access_unhighlight(pid_t pid, int handle, const struct packet *packet)
2713 struct packet *result;
2714 struct client_node *client;
2715 const char *pkgname;
2719 struct inst_info *inst = NULL;
2720 const struct pkg_info *pkg = NULL;
2724 client = client_find_by_rpc_handle(handle);
2726 ErrPrint("Client %d is not exists\n", pid);
2727 ret = LB_STATUS_ERROR_NOT_EXIST;
2731 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2733 ErrPrint("Invalid parameter\n");
2734 ret = LB_STATUS_ERROR_INVALID;
2738 ret = validate_request(pkgname, id, &inst, &pkg);
2739 if (ret != LB_STATUS_SUCCESS) {
2743 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2744 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2745 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2746 struct script_info *script;
2748 script = instance_pd_script(inst);
2750 ret = LB_STATUS_ERROR_FAULT;
2754 script_handler_update_pointer(script, x, y, -1);
2755 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_UNHIGHLIGHT, timestamp);
2757 struct event_cbdata *cbdata;
2759 cbdata = malloc(sizeof(*cbdata));
2761 ret = LB_STATUS_ERROR_MEMORY;
2763 cbdata->inst = instance_ref(inst);
2764 cbdata->status = ret;
2766 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2767 (void)instance_unref(cbdata->inst);
2769 ret = LB_STATUS_ERROR_FAULT;
2771 ret = LB_STATUS_SUCCESS;
2776 ErrPrint("Unsupported package\n");
2777 ret = LB_STATUS_ERROR_INVALID;
2780 result = packet_create_reply(packet, "i", ret);
2782 ErrPrint("Failed to create a reply packet\n");
2788 static struct packet *client_pd_access_hl(pid_t pid, int handle, const struct packet *packet)
2790 struct packet *result;
2791 struct client_node *client;
2792 const char *pkgname;
2798 struct inst_info *inst = NULL;
2799 const struct pkg_info *pkg = NULL;
2801 client = client_find_by_rpc_handle(handle);
2803 ErrPrint("Client %d is not exists\n", pid);
2804 ret = LB_STATUS_ERROR_NOT_EXIST;
2808 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2810 ErrPrint("Invalid parameter\n");
2811 ret = LB_STATUS_ERROR_INVALID;
2815 ret = validate_request(pkgname, id, &inst, &pkg);
2816 if (ret != LB_STATUS_SUCCESS) {
2820 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2821 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2822 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2823 struct script_info *script;
2825 script = instance_pd_script(inst);
2827 ret = LB_STATUS_ERROR_FAULT;
2831 script_handler_update_pointer(script, x, y, -1);
2832 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT, timestamp);
2834 struct event_cbdata *cbdata;
2836 cbdata = malloc(sizeof(*cbdata));
2838 ret = LB_STATUS_ERROR_MEMORY;
2840 cbdata->inst = instance_ref(inst);
2841 cbdata->status = ret;
2843 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2844 (void)instance_unref(cbdata->inst);
2846 ret = LB_STATUS_ERROR_FAULT;
2848 ret = LB_STATUS_SUCCESS;
2853 ErrPrint("Unsupported package\n");
2854 ret = LB_STATUS_ERROR_INVALID;
2858 result = packet_create_reply(packet, "i", ret);
2860 ErrPrint("Failed to create a reply packet\n");
2866 static struct packet *client_pd_access_hl_prev(pid_t pid, int handle, const struct packet *packet)
2868 struct packet *result;
2869 struct client_node *client;
2870 const char *pkgname;
2876 struct inst_info *inst = NULL;
2877 const struct pkg_info *pkg = NULL;
2879 client = client_find_by_rpc_handle(handle);
2881 ErrPrint("Client %d is not exists\n", pid);
2882 ret = LB_STATUS_ERROR_NOT_EXIST;
2886 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2888 ErrPrint("Invalid parameter\n");
2889 ret = LB_STATUS_ERROR_INVALID;
2893 ret = validate_request(pkgname, id, &inst, &pkg);
2894 if (ret != LB_STATUS_SUCCESS) {
2898 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2899 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2900 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2901 struct script_info *script;
2903 script = instance_pd_script(inst);
2905 ret = LB_STATUS_ERROR_FAULT;
2909 script_handler_update_pointer(script, x, y, -1);
2910 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_PREV, timestamp);
2912 struct event_cbdata *cbdata;
2914 cbdata = malloc(sizeof(*cbdata));
2916 ret = LB_STATUS_ERROR_MEMORY;
2918 cbdata->inst = instance_ref(inst);
2919 cbdata->status = ret;
2921 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2922 (void)instance_unref(cbdata->inst);
2924 ret = LB_STATUS_ERROR_FAULT;
2926 ret = LB_STATUS_SUCCESS;
2931 ErrPrint("Unsupported package\n");
2932 ret = LB_STATUS_ERROR_INVALID;
2936 result = packet_create_reply(packet, "i", ret);
2938 ErrPrint("Failed to create a reply packet\n");
2944 static struct packet *client_pd_access_hl_next(pid_t pid, int handle, const struct packet *packet)
2946 struct packet *result;
2947 struct client_node *client;
2948 const char *pkgname;
2954 struct inst_info *inst = NULL;
2955 const struct pkg_info *pkg = NULL;
2957 client = client_find_by_rpc_handle(handle);
2959 ErrPrint("Client %d is not exists\n", pid);
2960 ret = LB_STATUS_ERROR_NOT_EXIST;
2964 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2966 ErrPrint("Invalid parameter\n");
2967 ret = LB_STATUS_ERROR_INVALID;
2971 ret = validate_request(pkgname, id, &inst, &pkg);
2972 if (ret != LB_STATUS_SUCCESS) {
2976 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2977 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2978 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2979 struct script_info *script;
2981 script = instance_pd_script(inst);
2983 ErrPrint("Script is not created yet\n");
2984 ret = LB_STATUS_ERROR_FAULT;
2988 script_handler_update_pointer(script, x, y, -1);
2989 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT, timestamp);
2991 struct event_cbdata *cbdata;
2993 cbdata = malloc(sizeof(*cbdata));
2995 ErrPrint("Heap: %s\n", strerror(errno));
2996 ret = LB_STATUS_ERROR_MEMORY;
2998 cbdata->inst = instance_ref(inst);
2999 cbdata->status = ret;
3001 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3002 ErrPrint("Failed to add timer\n");
3003 (void)instance_unref(cbdata->inst);
3005 ret = LB_STATUS_ERROR_FAULT;
3007 ret = LB_STATUS_SUCCESS;
3011 DbgPrint("Returns: %d\n", ret);
3014 ErrPrint("Unsupported package\n");
3015 ret = LB_STATUS_ERROR_INVALID;
3019 result = packet_create_reply(packet, "i", ret);
3021 ErrPrint("Failed to create a reply packet\n");
3027 static struct packet *client_pd_access_activate(pid_t pid, int handle, const struct packet *packet)
3029 struct packet *result;
3030 struct client_node *client;
3031 const char *pkgname;
3037 struct inst_info *inst = NULL;
3038 const struct pkg_info *pkg = NULL;
3040 client = client_find_by_rpc_handle(handle);
3042 ErrPrint("Client %d is not exists\n", pid);
3043 ret = LB_STATUS_ERROR_NOT_EXIST;
3047 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3049 ErrPrint("Invalid parameter\n");
3050 ret = LB_STATUS_ERROR_INVALID;
3054 ret = validate_request(pkgname, id, &inst, &pkg);
3055 if (ret != LB_STATUS_SUCCESS) {
3059 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3060 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3061 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3062 struct script_info *script;
3064 script = instance_pd_script(inst);
3066 ret = LB_STATUS_ERROR_FAULT;
3070 script_handler_update_pointer(script, x, y, -1);
3071 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTIVATE, timestamp);
3073 struct event_cbdata *cbdata;
3075 cbdata = malloc(sizeof(*cbdata));
3077 ret = LB_STATUS_ERROR_MEMORY;
3079 cbdata->inst = instance_ref(inst);
3080 cbdata->status = ret;
3082 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3083 (void)instance_unref(cbdata->inst);
3085 ret = LB_STATUS_ERROR_FAULT;
3087 ret = LB_STATUS_SUCCESS;
3092 ErrPrint("Unsupported package\n");
3093 ret = LB_STATUS_ERROR_INVALID;
3097 result = packet_create_reply(packet, "i", ret);
3099 ErrPrint("Failed to create a reply packet\n");
3105 static struct packet *client_pd_key_focus_in(pid_t pid, int handle, const struct packet *packet)
3107 struct client_node *client;
3108 const char *pkgname;
3112 unsigned int keycode;
3113 struct inst_info *inst;
3114 const struct pkg_info *pkg;
3115 struct packet *result;
3117 client = client_find_by_rpc_handle(handle);
3119 ErrPrint("Client %d is not exists\n", pid);
3120 ret = LB_STATUS_ERROR_NOT_EXIST;
3124 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3126 ErrPrint("Invalid parameter\n");
3127 ret = LB_STATUS_ERROR_INVALID;
3131 ret = validate_request(pkgname, id, &inst, &pkg);
3132 if (ret != LB_STATUS_SUCCESS) {
3136 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3137 ret = forward_pd_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3138 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3139 struct script_info *script;
3141 script = instance_pd_script(inst);
3143 ret = LB_STATUS_ERROR_FAULT;
3147 script_handler_update_keycode(script, keycode);
3148 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_FOCUS_IN, timestamp);
3150 struct event_cbdata *cbdata;
3152 cbdata = malloc(sizeof(*cbdata));
3154 ret = LB_STATUS_ERROR_MEMORY;
3156 cbdata->inst = instance_ref(inst);
3157 cbdata->status = ret;
3159 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
3160 (void)instance_unref(cbdata->inst);
3162 ret = LB_STATUS_ERROR_FAULT;
3164 ret = LB_STATUS_SUCCESS;
3169 ErrPrint("Unsupported package\n");
3170 ret = LB_STATUS_ERROR_INVALID;
3174 result = packet_create_reply(packet, "i", ret);
3176 ErrPrint("Failed to create a reply packet\n");
3182 static struct packet *client_pd_key_focus_out(pid_t pid, int handle, const struct packet *packet)
3184 struct client_node *client;
3185 const char *pkgname;
3189 unsigned int keycode;
3190 struct inst_info *inst = NULL;
3191 const struct pkg_info *pkg = NULL;
3192 struct packet *result;
3194 client = client_find_by_rpc_handle(handle);
3196 ErrPrint("Client %d is not exists\n", pid);
3197 ret = LB_STATUS_ERROR_NOT_EXIST;
3201 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3203 ErrPrint("Invalid parameter\n");
3204 ret = LB_STATUS_ERROR_INVALID;
3208 ret = validate_request(pkgname, id, &inst, &pkg);
3209 if (ret != LB_STATUS_SUCCESS) {
3213 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3214 ret = forward_pd_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3215 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3216 struct script_info *script;
3218 script = instance_pd_script(inst);
3220 ret = LB_STATUS_ERROR_FAULT;
3224 script_handler_update_keycode(script, keycode);
3225 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_FOCUS_OUT, timestamp);
3227 struct event_cbdata *cbdata;
3229 cbdata = malloc(sizeof(*cbdata));
3231 ret = LB_STATUS_ERROR_MEMORY;
3233 cbdata->inst = instance_ref(inst);
3234 cbdata->status = ret;
3236 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
3237 (void)instance_unref(cbdata->inst);
3239 ret = LB_STATUS_ERROR_FAULT;
3241 ret = LB_STATUS_SUCCESS;
3246 ErrPrint("Unsupported package\n");
3247 ret = LB_STATUS_ERROR_INVALID;
3251 result = packet_create_reply(packet, "i", ret);
3253 ErrPrint("Failed to create a reply packet\n");
3259 static struct packet *client_pd_key_down(pid_t pid, int handle, const struct packet *packet)
3261 struct client_node *client;
3262 const char *pkgname;
3266 unsigned int keycode;
3267 struct inst_info *inst;
3268 const struct pkg_info *pkg;
3269 struct packet *result;
3271 client = client_find_by_rpc_handle(handle);
3273 ErrPrint("Client %d is not exists\n", pid);
3274 ret = LB_STATUS_ERROR_NOT_EXIST;
3278 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3280 ErrPrint("Invalid parameter\n");
3281 ret = LB_STATUS_ERROR_INVALID;
3285 ret = validate_request(pkgname, id, &inst, &pkg);
3286 if (ret != LB_STATUS_SUCCESS) {
3290 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3291 ret = forward_pd_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3292 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3293 struct script_info *script;
3295 script = instance_pd_script(inst);
3297 ret = LB_STATUS_ERROR_FAULT;
3301 script_handler_update_keycode(script, keycode);
3302 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_DOWN, timestamp);
3304 struct event_cbdata *cbdata;
3306 cbdata = malloc(sizeof(*cbdata));
3308 ret = LB_STATUS_ERROR_MEMORY;
3310 cbdata->inst = instance_ref(inst);
3311 cbdata->status = ret;
3313 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
3314 (void)instance_unref(cbdata->inst);
3316 ret = LB_STATUS_ERROR_FAULT;
3318 ret = LB_STATUS_SUCCESS;
3323 ErrPrint("Unsupported package\n");
3324 ret = LB_STATUS_ERROR_INVALID;
3328 result = packet_create_reply(packet, "i", ret);
3330 ErrPrint("Failed to create a reply packet\n");
3336 static struct packet *client_pause_request(pid_t pid, int handle, const struct packet *packet)
3338 struct client_node *client;
3342 client = client_find_by_rpc_handle(handle);
3344 ErrPrint("Client %d is paused - manually reported\n", pid);
3345 ret = LB_STATUS_ERROR_NOT_EXIST;
3349 ret = packet_get(packet, "d", ×tamp);
3351 ErrPrint("Invalid parameter\n");
3352 ret = LB_STATUS_ERROR_INVALID;
3357 DbgPrint("XMONITOR enabled. ignore client paused request\n");
3359 xmonitor_pause(client);
3366 static struct packet *client_resume_request(pid_t pid, int handle, const struct packet *packet)
3368 struct client_node *client;
3372 client = client_find_by_rpc_handle(handle);
3374 ErrPrint("Client %d is not exists\n", pid);
3378 ret = packet_get(packet, "d", ×tamp);
3380 ErrPrint("Invalid parameter\n");
3385 DbgPrint("XMONITOR enabled. ignore client resumed request\n");
3387 xmonitor_resume(client);
3394 static struct packet *client_pd_key_up(pid_t pid, int handle, const struct packet *packet)
3396 struct client_node *client;
3397 const char *pkgname;
3401 unsigned int keycode;
3402 struct inst_info *inst = NULL;
3403 const struct pkg_info *pkg = NULL;
3404 struct packet *result;
3406 client = client_find_by_rpc_handle(handle);
3408 ErrPrint("Client %d is not exists\n", pid);
3409 ret = LB_STATUS_ERROR_NOT_EXIST;
3413 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3415 ErrPrint("Invalid parameter\n");
3416 ret = LB_STATUS_ERROR_INVALID;
3420 ret = validate_request(pkgname, id, &inst, &pkg);
3421 if (ret != LB_STATUS_SUCCESS) {
3425 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3426 ret = forward_pd_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3427 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3428 struct script_info *script;
3430 script = instance_pd_script(inst);
3432 ret = LB_STATUS_ERROR_FAULT;
3436 script_handler_update_keycode(script, keycode);
3437 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_UP, timestamp);
3439 struct event_cbdata *cbdata;
3441 cbdata = malloc(sizeof(*cbdata));
3443 ret = LB_STATUS_ERROR_MEMORY;
3445 cbdata->inst = instance_ref(inst);
3446 cbdata->status = ret;
3448 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
3449 (void)instance_unref(cbdata->inst);
3451 ret = LB_STATUS_ERROR_FAULT;
3453 ret = LB_STATUS_SUCCESS;
3458 ErrPrint("Unsupported package\n");
3459 ret = LB_STATUS_ERROR_INVALID;
3463 result = packet_create_reply(packet, "i", ret);
3465 ErrPrint("Failed to create a reply packet\n");
3471 static struct packet *client_lb_access_hl(pid_t pid, int handle, const struct packet *packet)
3473 struct packet *result;
3474 struct client_node *client;
3475 const char *pkgname;
3481 struct inst_info *inst = NULL;
3482 const struct pkg_info *pkg = NULL;
3484 client = client_find_by_rpc_handle(handle);
3486 ErrPrint("Client %d is not exists\n", pid);
3487 ret = LB_STATUS_ERROR_NOT_EXIST;
3491 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3493 ErrPrint("Parameter is not matched\n");
3494 ret = LB_STATUS_ERROR_INVALID;
3498 ret = validate_request(pkgname, id, &inst, &pkg);
3499 if (ret != LB_STATUS_SUCCESS) {
3503 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3504 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3505 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3506 struct script_info *script;
3508 script = instance_lb_script(inst);
3510 ret = LB_STATUS_ERROR_FAULT;
3514 script_handler_update_pointer(script, x, y, -1);
3515 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT, timestamp);
3517 struct event_cbdata *cbdata;
3519 cbdata = malloc(sizeof(*cbdata));
3521 ret = LB_STATUS_ERROR_MEMORY;
3523 cbdata->inst = instance_ref(inst);
3524 cbdata->status = ret;
3526 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3527 (void)instance_unref(cbdata->inst);
3529 ret = LB_STATUS_ERROR_FAULT;
3531 ret = LB_STATUS_SUCCESS;
3536 ErrPrint("Unsupported package\n");
3537 ret = LB_STATUS_ERROR_INVALID;
3541 result = packet_create_reply(packet, "i", ret);
3543 ErrPrint("Failed to create a reply packet\n");
3549 static struct packet *client_lb_access_hl_prev(pid_t pid, int handle, const struct packet *packet)
3551 struct packet *result;
3552 struct client_node *client;
3553 const char *pkgname;
3559 struct inst_info *inst = NULL;
3560 const struct pkg_info *pkg = NULL;
3562 client = client_find_by_rpc_handle(handle);
3564 ErrPrint("Client %d is not exists\n", pid);
3565 ret = LB_STATUS_ERROR_NOT_EXIST;
3569 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3571 ErrPrint("Parameter is not matched\n");
3572 ret = LB_STATUS_ERROR_INVALID;
3576 ret = validate_request(pkgname, id, &inst, &pkg);
3577 if (ret != LB_STATUS_SUCCESS) {
3581 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3582 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3583 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3584 struct script_info *script;
3586 script = instance_lb_script(inst);
3588 ret = LB_STATUS_ERROR_FAULT;
3592 script_handler_update_pointer(script, x, y, -1);
3593 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_PREV, timestamp);
3595 struct event_cbdata *cbdata;
3597 cbdata = malloc(sizeof(*cbdata));
3599 ret = LB_STATUS_ERROR_MEMORY;
3601 cbdata->inst = instance_ref(inst);
3602 cbdata->status = ret;
3604 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3605 (void)instance_unref(cbdata->inst);
3607 ret = LB_STATUS_ERROR_FAULT;
3609 ret = LB_STATUS_SUCCESS;
3614 ErrPrint("Unsupported package\n");
3615 ret = LB_STATUS_ERROR_INVALID;
3619 result = packet_create_reply(packet, "i", ret);
3621 ErrPrint("Failed to create a reply packet\n");
3627 static struct packet *client_lb_access_hl_next(pid_t pid, int handle, const struct packet *packet)
3629 struct packet *result;
3630 struct client_node *client;
3631 const char *pkgname;
3637 struct inst_info *inst = NULL;
3638 const struct pkg_info *pkg = NULL;
3640 client = client_find_by_rpc_handle(handle);
3642 ErrPrint("Client %d is not exists\n", pid);
3643 ret = LB_STATUS_ERROR_NOT_EXIST;
3647 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3649 ErrPrint("Parameter is not matched\n");
3650 ret = LB_STATUS_ERROR_INVALID;
3654 ret = validate_request(pkgname, id, &inst, &pkg);
3655 if (ret != LB_STATUS_SUCCESS) {
3659 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3660 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3661 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3662 struct script_info *script;
3664 script = instance_lb_script(inst);
3666 ret = LB_STATUS_ERROR_FAULT;
3670 script_handler_update_pointer(script, x, y, -1);
3671 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT, timestamp);
3673 struct event_cbdata *cbdata;
3675 cbdata = malloc(sizeof(*cbdata));
3677 ret = LB_STATUS_ERROR_MEMORY;
3679 cbdata->inst = instance_ref(inst);
3680 cbdata->status = ret;
3682 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3683 (void)instance_unref(cbdata->inst);
3685 ret = LB_STATUS_ERROR_FAULT;
3687 ret = LB_STATUS_SUCCESS;
3692 ErrPrint("Unsupported package\n");
3693 ret = LB_STATUS_ERROR_INVALID;
3697 result = packet_create_reply(packet, "i", ret);
3699 ErrPrint("Failed to create a reply packet\n");
3705 static struct packet *client_lb_access_action_up(pid_t pid, int handle, const struct packet *packet)
3707 struct packet *result;
3708 struct client_node *client;
3709 const char *pkgname;
3713 struct inst_info *inst = NULL;
3714 const struct pkg_info *pkg = NULL;
3718 client = client_find_by_rpc_handle(handle);
3720 ErrPrint("Client %d is not exist\n", pid);
3721 ret = LB_STATUS_ERROR_NOT_EXIST;
3725 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3727 ErrPrint("Parameter is not matched\n");
3728 ret = LB_STATUS_ERROR_INVALID;
3732 ret = validate_request(pkgname, id, &inst, &pkg);
3733 if (ret != LB_STATUS_SUCCESS) {
3737 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3738 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3740 * Enen if it fails to send packet,
3741 * The packet will be unref'd
3742 * So we don't need to check the ret value.
3744 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3745 struct script_info *script;
3747 script = instance_lb_script(inst);
3749 ErrPrint("Instance has no script\n");
3750 ret = LB_STATUS_ERROR_FAULT;
3754 script_handler_update_pointer(script, x, y, 0);
3755 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
3757 struct event_cbdata *cbdata;
3759 cbdata = malloc(sizeof(*cbdata));
3761 ret = LB_STATUS_ERROR_MEMORY;
3763 cbdata->inst = instance_ref(inst);
3764 cbdata->status = ret;
3766 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3767 (void)instance_unref(cbdata->inst);
3769 ret = LB_STATUS_ERROR_FAULT;
3771 ret = LB_STATUS_SUCCESS;
3776 ErrPrint("Unsupported package\n");
3777 ret = LB_STATUS_ERROR_INVALID;
3781 result = packet_create_reply(packet, "i", ret);
3783 ErrPrint("Failed to create a reply packet\n");
3789 static struct packet *client_lb_access_action_down(pid_t pid, int handle, const struct packet *packet)
3791 struct packet *result;
3792 struct client_node *client;
3793 const char *pkgname;
3797 struct inst_info *inst = NULL;
3798 const struct pkg_info *pkg = NULL;
3802 client = client_find_by_rpc_handle(handle);
3804 ErrPrint("Client %d is not exist\n", pid);
3805 ret = LB_STATUS_ERROR_NOT_EXIST;
3809 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3811 ErrPrint("Parameter is not matched\n");
3812 ret = LB_STATUS_ERROR_INVALID;
3816 ret = validate_request(pkgname, id, &inst, &pkg);
3817 if (ret != LB_STATUS_SUCCESS) {
3821 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3822 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3824 * Enen if it fails to send packet,
3825 * The packet will be unref'd
3826 * So we don't need to check the ret value.
3828 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3829 struct script_info *script;
3831 script = instance_lb_script(inst);
3833 ErrPrint("Instance has no script\n");
3834 ret = LB_STATUS_ERROR_FAULT;
3838 script_handler_update_pointer(script, x, y, 1);
3839 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
3841 struct event_cbdata *cbdata;
3843 cbdata = malloc(sizeof(*cbdata));
3845 ret = LB_STATUS_ERROR_MEMORY;
3847 cbdata->inst = instance_ref(inst);
3848 cbdata->status = ret;
3850 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3851 (void)instance_unref(cbdata->inst);
3853 ret = LB_STATUS_ERROR_FAULT;
3855 ret = LB_STATUS_SUCCESS;
3860 ErrPrint("Unsupported package\n");
3861 ret = LB_STATUS_ERROR_INVALID;
3865 result = packet_create_reply(packet, "i", ret);
3867 ErrPrint("Failed to create a reply packet\n");
3873 static struct packet *client_lb_access_unhighlight(pid_t pid, int handle, const struct packet *packet)
3875 struct packet *result;
3876 struct client_node *client;
3877 const char *pkgname;
3883 struct inst_info *inst = NULL;
3884 const struct pkg_info *pkg = NULL;
3886 client = client_find_by_rpc_handle(handle);
3888 ErrPrint("Client %d is not exists\n", pid);
3889 ret = LB_STATUS_ERROR_NOT_EXIST;
3893 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3895 ErrPrint("Parameter is not matched\n");
3896 ret = LB_STATUS_ERROR_INVALID;
3900 ret = validate_request(pkgname, id, &inst, &pkg);
3901 if (ret != LB_STATUS_SUCCESS) {
3905 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3906 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3907 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3908 struct script_info *script;
3910 script = instance_lb_script(inst);
3912 ret = LB_STATUS_ERROR_FAULT;
3916 script_handler_update_pointer(script, x, y, -1);
3917 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_UNHIGHLIGHT, timestamp);
3919 struct event_cbdata *cbdata;
3921 cbdata = malloc(sizeof(*cbdata));
3923 ret = LB_STATUS_ERROR_MEMORY;
3925 cbdata->inst = instance_ref(inst);
3926 cbdata->status = ret;
3928 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3929 (void)instance_unref(cbdata->inst);
3931 ret = LB_STATUS_ERROR_FAULT;
3933 ret = LB_STATUS_SUCCESS;
3938 ErrPrint("Unsupported package\n");
3939 ret = LB_STATUS_ERROR_INVALID;
3943 result = packet_create_reply(packet, "i", ret);
3945 ErrPrint("Failed to create a reply packet\n");
3951 static struct packet *client_lb_access_scroll_down(pid_t pid, int handle, const struct packet *packet)
3953 struct packet *result;
3954 struct client_node *client;
3955 const char *pkgname;
3959 struct inst_info *inst = NULL;
3960 const struct pkg_info *pkg = NULL;
3964 client = client_find_by_rpc_handle(handle);
3966 ErrPrint("Client %d is not exist\n", pid);
3967 ret = LB_STATUS_ERROR_NOT_EXIST;
3971 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3973 ErrPrint("Parameter is not matched\n");
3974 ret = LB_STATUS_ERROR_INVALID;
3978 ret = validate_request(pkgname, id, &inst, &pkg);
3979 if (ret != LB_STATUS_SUCCESS) {
3983 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3984 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3986 * Enen if it fails to send packet,
3987 * The packet will be unref'd
3988 * So we don't need to check the ret value.
3990 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3991 struct script_info *script;
3993 script = instance_lb_script(inst);
3995 ErrPrint("Instance has no script\n");
3996 ret = LB_STATUS_ERROR_FAULT;
4000 script_handler_update_pointer(script, x, y, 1);
4001 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
4003 struct event_cbdata *cbdata;
4005 cbdata = malloc(sizeof(*cbdata));
4007 ret = LB_STATUS_ERROR_MEMORY;
4009 cbdata->inst = instance_ref(inst);
4010 cbdata->status = ret;
4012 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
4013 (void)instance_unref(cbdata->inst);
4015 ret = LB_STATUS_ERROR_FAULT;
4017 ret = LB_STATUS_SUCCESS;
4022 ErrPrint("Unsupported package\n");
4023 ret = LB_STATUS_ERROR_INVALID;
4027 result = packet_create_reply(packet, "i", ret);
4029 ErrPrint("Failed to create a reply packet\n");
4035 static struct packet *client_lb_access_scroll_move(pid_t pid, int handle, const struct packet *packet)
4037 struct packet *result;
4038 struct client_node *client;
4039 const char *pkgname;
4043 struct inst_info *inst = NULL;
4044 const struct pkg_info *pkg = NULL;
4048 client = client_find_by_rpc_handle(handle);
4050 ErrPrint("Client %d is not exist\n", pid);
4051 ret = LB_STATUS_ERROR_NOT_EXIST;
4055 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
4057 ErrPrint("Parameter is not matched\n");
4058 ret = LB_STATUS_ERROR_INVALID;
4062 ret = validate_request(pkgname, id, &inst, &pkg);
4063 if (ret != LB_STATUS_SUCCESS) {
4067 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4068 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
4070 * Enen if it fails to send packet,
4071 * The packet will be unref'd
4072 * So we don't need to check the ret value.
4074 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4075 struct script_info *script;
4077 script = instance_lb_script(inst);
4079 ErrPrint("Instance has no script\n");
4080 ret = LB_STATUS_ERROR_FAULT;
4084 script_handler_update_pointer(script, x, y, -1);
4085 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
4087 struct event_cbdata *cbdata;
4089 cbdata = malloc(sizeof(*cbdata));
4091 ret = LB_STATUS_ERROR_MEMORY;
4093 cbdata->inst = instance_ref(inst);
4094 cbdata->status = ret;
4096 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
4097 (void)instance_unref(cbdata->inst);
4099 ret = LB_STATUS_ERROR_FAULT;
4101 ret = LB_STATUS_SUCCESS;
4106 ErrPrint("Unsupported package\n");
4107 ret = LB_STATUS_ERROR_INVALID;
4111 result = packet_create_reply(packet, "i", ret);
4113 ErrPrint("Failed to create a reply packet\n");
4119 static struct packet *client_lb_access_scroll_up(pid_t pid, int handle, const struct packet *packet)
4121 struct packet *result;
4122 struct client_node *client;
4123 const char *pkgname;
4127 struct inst_info *inst = NULL;
4128 const struct pkg_info *pkg = NULL;
4132 client = client_find_by_rpc_handle(handle);
4134 ErrPrint("Client %d is not exist\n", pid);
4135 ret = LB_STATUS_ERROR_NOT_EXIST;
4139 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
4141 ErrPrint("Parameter is not matched\n");
4142 ret = LB_STATUS_ERROR_INVALID;
4146 ret = validate_request(pkgname, id, &inst, &pkg);
4147 if (ret != LB_STATUS_SUCCESS) {
4151 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4152 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
4154 * Enen if it fails to send packet,
4155 * The packet will be unref'd
4156 * So we don't need to check the ret value.
4158 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4159 struct script_info *script;
4161 script = instance_lb_script(inst);
4163 ErrPrint("Instance has no script\n");
4164 ret = LB_STATUS_ERROR_FAULT;
4168 script_handler_update_pointer(script, x, y, 0);
4169 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
4171 struct event_cbdata *cbdata;
4173 cbdata = malloc(sizeof(*cbdata));
4175 ret = LB_STATUS_ERROR_MEMORY;
4177 cbdata->inst = instance_ref(inst);
4178 cbdata->status = ret;
4180 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
4181 (void)instance_unref(cbdata->inst);
4183 ret = LB_STATUS_ERROR_FAULT;
4185 ret = LB_STATUS_SUCCESS;
4190 ErrPrint("Unsupported package\n");
4191 ret = LB_STATUS_ERROR_INVALID;
4195 result = packet_create_reply(packet, "i", ret);
4197 ErrPrint("Failed to create a reply packet\n");
4203 static struct packet *client_lb_access_activate(pid_t pid, int handle, const struct packet *packet)
4205 struct packet *result;
4206 struct client_node *client;
4207 const char *pkgname;
4213 struct inst_info *inst = NULL;
4214 const struct pkg_info *pkg = NULL;
4216 client = client_find_by_rpc_handle(handle);
4218 ErrPrint("Client %d is not exists\n", pid);
4219 ret = LB_STATUS_ERROR_NOT_EXIST;
4223 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
4225 ErrPrint("Parameter is not matched\n");
4226 ret = LB_STATUS_ERROR_INVALID;
4230 ret = validate_request(pkgname, id, &inst, &pkg);
4231 if (ret != LB_STATUS_SUCCESS) {
4235 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4236 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
4237 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4238 struct script_info *script;
4240 script = instance_lb_script(inst);
4242 ErrPrint("Instance has no script\n");
4243 ret = LB_STATUS_ERROR_FAULT;
4247 script_handler_update_pointer(script, x, y, -1);
4248 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTIVATE, timestamp);
4250 struct event_cbdata *cbdata;
4252 cbdata = malloc(sizeof(*cbdata));
4254 ret = LB_STATUS_ERROR_MEMORY;
4256 cbdata->inst = instance_ref(inst);
4257 cbdata->status = ret;
4259 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
4260 (void)instance_unref(cbdata->inst);
4262 ret = LB_STATUS_ERROR_FAULT;
4264 ret = LB_STATUS_SUCCESS;
4269 ErrPrint("Unsupported package\n");
4270 ret = LB_STATUS_ERROR_INVALID;
4274 result = packet_create_reply(packet, "i", ret);
4276 ErrPrint("Failed to create a reply packet\n");
4282 static struct packet *client_lb_key_down(pid_t pid, int handle, const struct packet *packet)
4284 struct client_node *client;
4285 const char *pkgname;
4289 unsigned int keycode;
4290 struct inst_info *inst;
4291 const struct pkg_info *pkg;
4292 struct packet *result;
4294 client = client_find_by_rpc_handle(handle);
4296 ErrPrint("Client %d is not exists\n", pid);
4297 ret = LB_STATUS_ERROR_NOT_EXIST;
4301 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4303 ErrPrint("Parameter is not matched\n");
4304 ret = LB_STATUS_ERROR_INVALID;
4308 ret = validate_request(pkgname, id, &inst, &pkg);
4309 if (ret != LB_STATUS_SUCCESS) {
4313 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4314 ret = forward_lb_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4315 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4316 struct script_info *script;
4318 script = instance_lb_script(inst);
4320 ret = LB_STATUS_ERROR_FAULT;
4324 script_handler_update_keycode(script, keycode);
4325 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_DOWN, timestamp);
4327 struct event_cbdata *cbdata;
4329 cbdata = malloc(sizeof(*cbdata));
4331 ret = LB_STATUS_ERROR_MEMORY;
4333 cbdata->inst = instance_ref(inst);
4334 cbdata->status = ret;
4336 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
4337 (void)instance_unref(cbdata->inst);
4339 ret = LB_STATUS_ERROR_FAULT;
4341 ret = LB_STATUS_SUCCESS;
4346 ErrPrint("Unsupported package\n");
4347 ret = LB_STATUS_ERROR_INVALID;
4351 result = packet_create_reply(packet, "i", ret);
4353 ErrPrint("Failed to create a reply packet\n");
4359 static struct packet *client_lb_key_focus_in(pid_t pid, int handle, const struct packet *packet)
4361 struct client_node *client;
4362 const char *pkgname;
4366 unsigned int keycode;
4367 struct inst_info *inst = NULL;
4368 const struct pkg_info *pkg = NULL;
4369 struct packet *result;
4371 client = client_find_by_rpc_handle(handle);
4373 ErrPrint("Client %d is not exists\n", pid);
4374 ret = LB_STATUS_ERROR_NOT_EXIST;
4378 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4380 ErrPrint("Parameter is not matched\n");
4381 ret = LB_STATUS_ERROR_INVALID;
4385 ret = validate_request(pkgname, id, &inst, &pkg);
4386 if (ret != LB_STATUS_SUCCESS) {
4390 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4391 ret = forward_lb_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4392 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4393 struct script_info *script;
4395 script = instance_lb_script(inst);
4397 ret = LB_STATUS_ERROR_FAULT;
4401 script_handler_update_keycode(script, keycode);
4402 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_FOCUS_IN, timestamp);
4404 struct event_cbdata *cbdata;
4406 cbdata = malloc(sizeof(*cbdata));
4408 ret = LB_STATUS_ERROR_MEMORY;
4410 cbdata->inst = instance_ref(inst);
4411 cbdata->status = ret;
4413 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
4414 (void)instance_unref(cbdata->inst);
4416 ret = LB_STATUS_ERROR_FAULT;
4418 ret = LB_STATUS_SUCCESS;
4423 ErrPrint("Unsupported package\n");
4424 ret = LB_STATUS_ERROR_INVALID;
4428 result = packet_create_reply(packet, "i", ret);
4430 ErrPrint("Failed to create a reply packet\n");
4436 static struct packet *client_lb_key_focus_out(pid_t pid, int handle, const struct packet *packet)
4438 struct client_node *client;
4439 const char *pkgname;
4443 unsigned int keycode;
4444 struct inst_info *inst = NULL;
4445 const struct pkg_info *pkg = NULL;
4446 struct packet *result;
4448 client = client_find_by_rpc_handle(handle);
4450 ErrPrint("Client %d is not exists\n", pid);
4451 ret = LB_STATUS_ERROR_NOT_EXIST;
4455 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4457 ErrPrint("Parameter is not matched\n");
4458 ret = LB_STATUS_ERROR_INVALID;
4462 ret = validate_request(pkgname, id, &inst, &pkg);
4463 if (ret != LB_STATUS_SUCCESS) {
4467 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4468 ret = forward_lb_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4469 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4470 struct script_info *script;
4472 script = instance_lb_script(inst);
4474 ret = LB_STATUS_ERROR_FAULT;
4478 script_handler_update_keycode(script, keycode);
4479 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_FOCUS_OUT, timestamp);
4481 struct event_cbdata *cbdata;
4483 cbdata = malloc(sizeof(*cbdata));
4485 ret = LB_STATUS_ERROR_MEMORY;
4487 cbdata->inst = instance_ref(inst);
4488 cbdata->status = ret;
4490 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
4491 (void)instance_unref(cbdata->inst);
4493 ret = LB_STATUS_ERROR_FAULT;
4495 ret = LB_STATUS_SUCCESS;
4500 ErrPrint("Unsupported package\n");
4501 ret = LB_STATUS_ERROR_INVALID;
4505 result = packet_create_reply(packet, "i", ret);
4507 ErrPrint("Failed to create a reply packet\n");
4513 static struct packet *client_lb_key_up(pid_t pid, int handle, const struct packet *packet)
4515 struct client_node *client;
4516 const char *pkgname;
4520 unsigned int keycode;
4521 struct inst_info *inst = NULL;
4522 const struct pkg_info *pkg = NULL;
4523 struct packet *result;
4525 client = client_find_by_rpc_handle(handle);
4527 ErrPrint("Client %d is not exists\n", pid);
4528 ret = LB_STATUS_ERROR_NOT_EXIST;
4532 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4534 ErrPrint("Parameter is not matched\n");
4535 ret = LB_STATUS_ERROR_INVALID;
4539 ret = validate_request(pkgname, id, &inst, &pkg);
4540 if (ret != LB_STATUS_SUCCESS) {
4544 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4545 ret = forward_lb_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4546 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4547 struct script_info *script;
4549 script = instance_lb_script(inst);
4551 ret = LB_STATUS_ERROR_FAULT;
4555 script_handler_update_keycode(script, keycode);
4556 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_UP, timestamp);
4558 struct event_cbdata *cbdata;
4560 cbdata = malloc(sizeof(*cbdata));
4562 ret = LB_STATUS_ERROR_MEMORY;
4564 cbdata->inst = instance_ref(inst);
4565 cbdata->status = ret;
4567 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
4568 (void)instance_unref(cbdata->inst);
4570 ret = LB_STATUS_ERROR_FAULT;
4572 ret = LB_STATUS_SUCCESS;
4577 ErrPrint("Unsupported package\n");
4578 ret = LB_STATUS_ERROR_INVALID;
4582 result = packet_create_reply(packet, "i", ret);
4584 ErrPrint("Failed to create a reply packet\n");
4590 static int release_pixmap_cb(struct client_node *client, void *canvas)
4592 DbgPrint("Forcely unref the \"buffer\"\n");
4593 buffer_handler_pixmap_unref(canvas);
4594 return -1; /* Delete this callback */
4597 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 */
4599 struct packet *result;
4600 const char *pkgname;
4602 struct client_node *client;
4603 struct inst_info *inst = NULL;
4607 struct buffer_info *buffer;
4609 client = client_find_by_rpc_handle(handle);
4611 ErrPrint("Client %d is not exists\n", pid);
4612 ret = LB_STATUS_ERROR_INVALID;
4616 ret = packet_get(packet, "ss", &pkgname, &id);
4618 ErrPrint("Parameter is not matched\n");
4619 ret = LB_STATUS_ERROR_INVALID;
4623 ret = validate_request(pkgname, id, &inst, NULL);
4624 if (ret != LB_STATUS_SUCCESS) {
4628 buffer = instance_lb_buffer(inst);
4630 struct script_info *script_info;
4632 script_info = instance_lb_script(inst);
4634 ErrPrint("Unable to get LB buffer: %s\n", id);
4635 ret = LB_STATUS_ERROR_FAULT;
4639 buffer = script_handler_buffer_info(script_info);
4641 ErrPrint("Unable to get buffer_info: %s\n", id);
4642 ret = LB_STATUS_ERROR_FAULT;
4647 buf_ptr = buffer_handler_pixmap_ref(buffer);
4649 ErrPrint("Failed to ref pixmap\n");
4650 ret = LB_STATUS_ERROR_FAULT;
4654 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
4656 ErrPrint("Failed to add a new client deactivate callback\n");
4657 buffer_handler_pixmap_unref(buf_ptr);
4659 pixmap = buffer_handler_pixmap(buffer);
4660 ret = LB_STATUS_SUCCESS;
4664 result = packet_create_reply(packet, "ii", pixmap, ret);
4666 ErrPrint("Failed to create a reply packet\n");
4672 static struct packet *client_lb_release_pixmap(pid_t pid, int handle, const struct packet *packet)
4674 const char *pkgname;
4676 struct client_node *client;
4681 client = client_find_by_rpc_handle(handle);
4683 ErrPrint("Client %d is not exists\n", pid);
4687 ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
4689 ErrPrint("Parameter is not matched\n");
4693 ret = validate_request(pkgname, id, NULL, NULL);
4694 if (ret != LB_STATUS_SUCCESS) {
4698 buf_ptr = buffer_handler_pixmap_find(pixmap);
4700 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
4704 if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) {
4705 buffer_handler_pixmap_unref(buf_ptr);
4709 /*! \note No reply packet */
4713 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 */
4715 struct packet *result;
4716 const char *pkgname;
4718 struct client_node *client;
4719 struct inst_info *inst = NULL;
4723 struct buffer_info *buffer;
4725 client = client_find_by_rpc_handle(handle);
4727 ret = LB_STATUS_ERROR_INVALID;
4728 ErrPrint("Client %d is not exists\n", pid);
4732 ret = packet_get(packet, "ss", &pkgname, &id);
4734 ret = LB_STATUS_ERROR_INVALID;
4735 ErrPrint("Parameter is not matched\n");
4739 ret = validate_request(pkgname, id, &inst, NULL);
4740 if (ret != LB_STATUS_SUCCESS) {
4744 if (instance_get_data(inst, PD_RESIZE_MONITOR_TAG)) {
4745 ret = LB_STATUS_ERROR_BUSY;
4749 buffer = instance_pd_buffer(inst);
4751 struct script_info *script_info;
4753 script_info = instance_pd_script(inst);
4755 ErrPrint("Unable to get LB buffer: %s\n", id);
4756 ret = LB_STATUS_ERROR_FAULT;
4760 buffer = script_handler_buffer_info(script_info);
4762 ErrPrint("Unable to get buffer_info: %s\n", id);
4763 ret = LB_STATUS_ERROR_FAULT;
4768 buf_ptr = buffer_handler_pixmap_ref(buffer);
4770 ErrPrint("Failed to ref pixmap\n");
4771 ret = LB_STATUS_ERROR_FAULT;
4775 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
4777 ErrPrint("Failed to add a new client deactivate callback\n");
4778 buffer_handler_pixmap_unref(buf_ptr);
4780 pixmap = buffer_handler_pixmap(buffer);
4781 ret = LB_STATUS_SUCCESS;
4785 result = packet_create_reply(packet, "ii", pixmap, ret);
4787 ErrPrint("Failed to create a reply packet\n");
4793 static struct packet *client_pd_release_pixmap(pid_t pid, int handle, const struct packet *packet)
4795 const char *pkgname;
4797 struct client_node *client;
4802 client = client_find_by_rpc_handle(handle);
4804 ErrPrint("Client %d is not exists\n", pid);
4808 ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
4810 ErrPrint("Parameter is not matched\n");
4814 ret = validate_request(pkgname, id, NULL, NULL);
4815 if (ret != LB_STATUS_SUCCESS) {
4819 buf_ptr = buffer_handler_pixmap_find(pixmap);
4821 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
4825 if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) {
4826 buffer_handler_pixmap_unref(buf_ptr);
4830 /*! \note No reply packet */
4834 static struct packet *client_pinup_changed(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, pinup, ret */
4836 struct client_node *client;
4837 struct packet *result;
4838 const char *pkgname;
4842 struct inst_info *inst = NULL;
4844 client = client_find_by_rpc_handle(handle);
4846 ErrPrint("Client %d is not exists\n", pid);
4847 ret = LB_STATUS_ERROR_NOT_EXIST;
4852 ret = packet_get(packet, "ssi", &pkgname, &id, &pinup);
4854 ErrPrint("Parameter is not matched\n");
4855 ret = LB_STATUS_ERROR_INVALID;
4860 ret = validate_request(pkgname, id, &inst, NULL);
4861 if (ret == LB_STATUS_SUCCESS) {
4862 ret = instance_set_pinup(inst, pinup);
4866 result = packet_create_reply(packet, "i", ret);
4868 ErrPrint("Failed to create a packet\n");
4874 static Eina_Bool lazy_pd_created_cb(void *inst)
4876 struct pkg_info *pkg;
4878 if (!instance_del_data(inst, LAZY_PD_OPEN_TAG)) {
4879 ErrPrint("lazy,pd,open is already deleted.\n");
4880 return ECORE_CALLBACK_CANCEL;
4883 pkg = instance_package(inst);
4885 struct slave_node *slave;
4887 slave = package_slave(pkg);
4889 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst);
4894 * After unref instance first,
4895 * if the instance is not destroyed, try to notify the created PD event to the client.
4897 if (instance_unref(inst)) {
4899 ret = instance_client_pd_created(inst, LB_STATUS_SUCCESS);
4900 DbgPrint("Send PD Create event (%d) to client\n", ret);
4903 return ECORE_CALLBACK_CANCEL;
4906 static Eina_Bool lazy_pd_destroyed_cb(void *inst)
4908 struct pkg_info *pkg;
4909 struct slave_node *slave;
4911 if (!instance_del_data(inst, LAZY_PD_CLOSE_TAG)) {
4912 ErrPrint("lazy,pd,close is already deleted.\n");
4913 return ECORE_CALLBACK_CANCEL;
4916 pkg = instance_package(inst);
4918 slave = package_slave(pkg);
4920 if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
4921 DbgPrint("Delete script type close callback\n");
4922 (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst);
4923 } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
4924 DbgPrint("Delete buffer type close callback\n");
4925 (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
4930 if (instance_unref(inst)) {
4934 * If the instance is not deleted, we should send pd-destroy event from here.
4936 ret = instance_client_pd_destroyed(inst, LB_STATUS_SUCCESS);
4938 ErrPrint("Failed sending PD Destroy event (%d)\n", ret);
4942 return ECORE_CALLBACK_CANCEL;
4945 static struct packet *client_pd_move(pid_t pid, int handle, const struct packet *packet) /* pkgname, id, x, y */
4947 struct client_node *client;
4948 struct inst_info *inst = NULL;
4949 const struct pkg_info *pkg = NULL;
4950 const char *pkgname;
4956 client = client_find_by_rpc_handle(handle);
4958 ErrPrint("Client %d is not exists\n", pid);
4959 ret = LB_STATUS_ERROR_NOT_EXIST;
4963 ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
4965 ErrPrint("Parameter is not correct\n");
4966 ret = LB_STATUS_ERROR_INVALID;
4970 ret = validate_request(pkgname, id, &inst, &pkg);
4971 if (ret != LB_STATUS_SUCCESS) {
4975 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
4976 instance_slave_set_pd_pos(inst, x, y);
4977 ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
4978 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
4982 instance_slave_set_pd_pos(inst, x, y);
4983 ix = x * instance_pd_width(inst);
4984 iy = y * instance_pd_height(inst);
4985 script_handler_update_pointer(instance_pd_script(inst), ix, iy, 0);
4986 ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
4988 ErrPrint("Invalid PD type\n");
4989 ret = LB_STATUS_ERROR_INVALID;
4992 DbgPrint("Update PD position: %d\n", ret);
4996 static Eina_Bool pd_open_monitor_cb(void *inst)
4999 struct pkg_info *pkg;
5001 pkg = instance_package(inst);
5003 struct slave_node *slave;
5005 slave = package_slave(pkg);
5007 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst);
5011 ret = instance_slave_close_pd(inst, instance_pd_owner(inst));
5012 ret = instance_client_pd_created(inst, LB_STATUS_ERROR_TIMEOUT);
5013 (void)instance_del_data(inst, PD_OPEN_MONITOR_TAG);
5014 (void)instance_unref(inst);
5015 ErrPrint("PD Open request is timed-out (%lf), ret: %d\n", PD_REQUEST_TIMEOUT, ret);
5016 return ECORE_CALLBACK_CANCEL;
5019 static Eina_Bool pd_close_monitor_cb(void *inst)
5022 struct pkg_info *pkg;
5024 pkg = instance_package(inst);
5026 struct slave_node *slave;
5028 slave = package_slave(pkg);
5030 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
5034 ret = instance_client_pd_destroyed(inst, LB_STATUS_ERROR_TIMEOUT);
5035 (void)instance_del_data(inst, PD_CLOSE_MONITOR_TAG);
5036 (void)instance_unref(inst);
5037 ErrPrint("PD Close request is not processed in %lf seconds (%d)\n", PD_REQUEST_TIMEOUT, ret);
5038 return ECORE_CALLBACK_CANCEL;
5041 static Eina_Bool pd_resize_monitor_cb(void *inst)
5044 struct pkg_info *pkg;
5046 pkg = instance_package(inst);
5048 struct slave_node *slave;
5049 slave = package_slave(pkg);
5051 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst);
5055 ret = instance_slave_close_pd(inst, instance_pd_owner(inst));
5056 ret = instance_client_pd_destroyed(inst, LB_STATUS_ERROR_TIMEOUT);
5057 (void)instance_del_data(inst, PD_RESIZE_MONITOR_TAG);
5058 (void)instance_unref(inst);
5059 ErrPrint("PD Resize request is not processed in %lf seconds (%d)\n", PD_REQUEST_TIMEOUT, ret);
5060 return ECORE_CALLBACK_CANCEL;
5063 static struct packet *client_create_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
5065 struct client_node *client;
5066 struct packet *result;
5067 const char *pkgname;
5070 struct inst_info *inst = NULL;
5071 const struct pkg_info *pkg = NULL;
5072 Ecore_Timer *pd_monitor;
5076 DbgPrint("PERF_DBOX\n");
5078 client = client_find_by_rpc_handle(handle);
5080 ErrPrint("Client %d is not exists\n", pid);
5081 ret = LB_STATUS_ERROR_NOT_EXIST;
5085 ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
5087 ErrPrint("Parameter is not matched\n");
5088 ret = LB_STATUS_ERROR_INVALID;
5092 ret = validate_request(pkgname, id, &inst, &pkg);
5093 if (ret != LB_STATUS_SUCCESS) {
5097 if (instance_pd_owner(inst)) {
5098 ErrPrint("PD is already owned\n");
5099 ret = LB_STATUS_ERROR_ALREADY;
5100 } else if (package_pd_type(instance_package(inst)) == PD_TYPE_BUFFER) {
5101 pd_monitor = instance_get_data(inst, LAZY_PD_CLOSE_TAG);
5103 ecore_timer_del(pd_monitor);
5104 /* This timer attribute will be deleted */
5105 lazy_pd_destroyed_cb(inst);
5108 if (instance_get_data(inst, PD_OPEN_MONITOR_TAG)) {
5109 DbgPrint("PD Open request is already processed\n");
5110 ret = LB_STATUS_ERROR_ALREADY;
5114 if (instance_get_data(inst, PD_CLOSE_MONITOR_TAG)) {
5115 DbgPrint("PD Close request is already in process\n");
5116 ret = LB_STATUS_ERROR_BUSY;
5120 if (instance_get_data(inst, PD_RESIZE_MONITOR_TAG)) {
5121 DbgPrint("PD resize request is already in process\n");
5122 ret = LB_STATUS_ERROR_BUSY;
5126 instance_slave_set_pd_pos(inst, x, y);
5129 * Send request to the slave.
5130 * The SLAVE must has to repsonse this via "release_buffer" method.
5132 ret = instance_slave_open_pd(inst, client);
5133 if (ret == LB_STATUS_SUCCESS) {
5134 ret = instance_signal_emit(inst, "pd,show", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
5135 if (ret != LB_STATUS_SUCCESS) {
5138 tmp_ret = instance_slave_close_pd(inst, client);
5139 ErrPrint("Unable to send script event for openning PD [%s], %d\n", pkgname, tmp_ret);
5141 pd_monitor = ecore_timer_add(PD_REQUEST_TIMEOUT, pd_open_monitor_cb, instance_ref(inst));
5143 (void)instance_unref(inst);
5144 ErrPrint("Failed to create a timer for PD Open monitor\n");
5146 struct slave_node *slave;
5148 (void)instance_set_data(inst, PD_OPEN_MONITOR_TAG, pd_monitor);
5150 slave = package_slave(pkg);
5152 ErrPrint("Failed to get slave(%s)\n", pkgname);
5156 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) != LB_STATUS_SUCCESS) {
5157 ErrPrint("Failed to add fault handler: %s\n");
5162 ErrPrint("Unable to send request for openning PD [%s]\n", pkgname);
5167 * PD craeted event will be send by the acquire_buffer function.
5168 * Because the slave will make request the acquire_buffer to
5171 * instance_client_pd_created(inst);
5173 } else if (package_pd_type(instance_package(inst)) == PD_TYPE_SCRIPT) {
5177 pd_monitor = instance_get_data(inst, LAZY_PD_CLOSE_TAG);
5179 ecore_timer_del(pd_monitor);
5180 /* lazy,pd,close will be deleted */
5181 lazy_pd_destroyed_cb(inst);
5186 * ret value should be cared but in this case,
5187 * we ignore this for this moment, so we have to handle this error later.
5189 * if ret is less than 0, the slave has some problem.
5190 * but the script mode doesn't need slave for rendering default view of PD
5191 * so we can hanle it later.
5193 instance_slave_set_pd_pos(inst, x, y);
5194 ix = x * instance_pd_width(inst);
5195 iy = y * instance_pd_height(inst);
5197 script_handler_update_pointer(instance_pd_script(inst), ix, iy, 0);
5199 ret = instance_slave_open_pd(inst, client);
5200 if (ret == LB_STATUS_SUCCESS) {
5201 ret = script_handler_load(instance_pd_script(inst), 1);
5205 * Send the PD created event to the clients,
5207 if (ret == LB_STATUS_SUCCESS) {
5211 * But the created event has to be send afte return
5212 * from this function or the viewer couldn't care
5213 * the event correctly.
5215 inst = instance_ref(inst); /* To guarantee the inst */
5219 * At here, we don't need to rememeber the timer object.
5220 * Even if the timer callback is called, after the instance is destroyed.
5221 * lazy_pd_created_cb will decrease the instance refcnt first.
5222 * At that time, if the instance is released, the timer callback will do nothing.
5225 * I change my mind. There is no requirements to keep the timer handler.
5226 * But I just add it to the tagged-data of the instance.
5227 * Just reserve for future-use.
5229 pd_monitor = ecore_timer_add(DELAY_TIME, lazy_pd_created_cb, inst);
5231 ret = script_handler_unload(instance_pd_script(inst), 1);
5232 ErrPrint("Unload script: %d\n", ret);
5234 ret = instance_slave_close_pd(inst, client);
5235 ErrPrint("Close PD %d\n", ret);
5237 inst = instance_unref(inst);
5239 DbgPrint("Instance destroyed\n");
5242 ErrPrint("Instance: %s\n", pkgname);
5244 ret = LB_STATUS_ERROR_FAULT;
5246 struct slave_node *slave;
5248 (void)instance_set_data(inst, LAZY_PD_OPEN_TAG, pd_monitor);
5250 slave = package_slave(pkg);
5252 ErrPrint("Failed to get slave: %s\n", pkgname);
5256 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst) != LB_STATUS_SUCCESS) {
5257 ErrPrint("Failed to add fault callback: %s\n", pkgname);
5262 tmp_ret = instance_slave_close_pd(inst, client);
5263 ErrPrint("Unable to load script: %d, (close: %d)\n", ret, tmp_ret);
5266 ErrPrint("Unable open PD(%s): %d\n", pkgname, ret);
5269 ErrPrint("Invalid PD TYPE\n");
5270 ret = LB_STATUS_ERROR_INVALID;
5274 result = packet_create_reply(packet, "i", ret);
5276 ErrPrint("Failed to create a packet\n");
5282 static struct packet *client_destroy_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
5284 struct client_node *client;
5285 struct packet *result;
5286 const char *pkgname;
5289 struct inst_info *inst = NULL;
5290 const struct pkg_info *pkg = NULL;
5291 Ecore_Timer *pd_monitor;
5292 struct slave_node *slave;
5294 DbgPrint("PERF_DBOX\n");
5296 client = client_find_by_rpc_handle(handle);
5298 ErrPrint("Client %d is not exists\n", pid);
5299 ret = LB_STATUS_ERROR_NOT_EXIST;
5303 ret = packet_get(packet, "ss", &pkgname, &id);
5305 ErrPrint("Parameter is not matched\n");
5306 ret = LB_STATUS_ERROR_INVALID;
5310 ret = validate_request(pkgname, id, &inst, &pkg);
5311 if (ret != LB_STATUS_SUCCESS) {
5315 slave = package_slave(pkg);
5317 ret = LB_STATUS_ERROR_INVALID;
5321 if (instance_pd_owner(inst) != client) {
5322 if (instance_pd_owner(inst) == NULL) {
5323 ErrPrint("PD looks already closed\n");
5324 ret = LB_STATUS_ERROR_ALREADY;
5326 ErrPrint("PD owner mimatched\n");
5327 ret = LB_STATUS_ERROR_PERMISSION;
5329 } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
5330 DbgPrint("Buffer type PD\n");
5331 pd_monitor = instance_del_data(inst, PD_OPEN_MONITOR_TAG);
5333 ErrPrint("PD Open request is found. cancel it [%s]\n", pkgname);
5335 if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) < 0) {
5336 DbgPrint("Failed to delete a deactivate callback\n");
5341 * We should return negative value
5342 * Or we have to send "destroyed" event to the client.
5343 * If we didn't send destroyed event after return SUCCESS from here,
5344 * The client will permanently waiting destroyed event.
5345 * Because they understand that the destroy request is successfully processed.
5347 ret = instance_client_pd_created(inst, LB_STATUS_ERROR_CANCEL);
5349 ErrPrint("PD client create event: %d\n", ret);
5352 ret = instance_client_pd_destroyed(inst, LB_STATUS_SUCCESS);
5354 ErrPrint("PD client destroy event: %d\n", ret);
5357 ret = instance_signal_emit(inst, "pd,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
5359 ErrPrint("PD close signal emit failed: %d\n", ret);
5362 ret = instance_slave_close_pd(inst, client);
5364 ErrPrint("PD close request failed: %d\n", ret);
5367 ecore_timer_del(pd_monitor);
5368 inst = instance_unref(inst);
5370 DbgPrint("Instance is deleted\n");
5372 } else if (instance_get_data(inst, LAZY_PD_CLOSE_TAG) || instance_get_data(inst, PD_CLOSE_MONITOR_TAG)) {
5373 DbgPrint("Close monitor is already fired\n");
5374 ret = LB_STATUS_ERROR_ALREADY;
5376 int resize_aborted = 0;
5378 pd_monitor = instance_del_data(inst, PD_RESIZE_MONITOR_TAG);
5380 ErrPrint("PD Resize request is found. clear it [%s]\n", pkgname);
5381 if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) < 0) {
5382 DbgPrint("Failed to delete a deactivate callback\n");
5385 ecore_timer_del(pd_monitor);
5387 inst = instance_unref(inst);
5389 DbgPrint("Instance is destroyed while resizing\n");
5396 ret = instance_signal_emit(inst, "pd,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
5398 ErrPrint("PD close signal emit failed: %d\n", ret);
5401 ret = instance_slave_close_pd(inst, client);
5403 ErrPrint("PD close request failed: %d\n", ret);
5404 } else if (resize_aborted) {
5405 pd_monitor = ecore_timer_add(DELAY_TIME, lazy_pd_destroyed_cb, instance_ref(inst));
5407 ErrPrint("Failed to create a timer: %s\n", pkgname);
5408 inst = instance_unref(inst);
5410 DbgPrint("Instance is deleted\n");
5413 DbgPrint("Resize is aborted\n");
5414 (void)instance_set_data(inst, LAZY_PD_CLOSE_TAG, pd_monitor);
5415 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) {
5416 ErrPrint("Failed to add a slave event callback\n");
5420 pd_monitor = ecore_timer_add(PD_REQUEST_TIMEOUT, pd_close_monitor_cb, instance_ref(inst));
5422 ErrPrint("Failed to add pd close monitor\n");
5423 inst = instance_unref(inst);
5425 ErrPrint("Instance is deleted while closing PD\n");
5428 DbgPrint("Add close monitor\n");
5429 (void)instance_set_data(inst, PD_CLOSE_MONITOR_TAG, pd_monitor);
5430 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) {
5431 ErrPrint("Failed to add SLAVE EVENT callback\n");
5438 * release_buffer will be called by the slave after this routine.
5439 * It will send the "pd_destroyed" event to the client
5441 * instance_client_pd_destroyed(inst, LB_STATUS_SUCCESS);
5443 * Or the "pd_close_monitor_cb" or "lazy_pd_destroyed_cb" will be called.
5446 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
5447 DbgPrint("Script TYPE PD\n");
5448 pd_monitor = instance_get_data(inst, LAZY_PD_OPEN_TAG);
5450 ecore_timer_del(pd_monitor);
5451 (void)lazy_pd_created_cb(inst);
5454 ret = script_handler_unload(instance_pd_script(inst), 1);
5456 ErrPrint("Unable to unload the script: %s, %d\n", pkgname, ret);
5461 * Send request to the slave.
5462 * The SLAVE must has to repsonse this via "release_buffer" method.
5464 ret = instance_slave_close_pd(inst, client);
5466 ErrPrint("Unable to close the PD: %s, %d\n", pkgname, ret);
5471 * Send the destroyed PD event to the client
5473 if (ret == LB_STATUS_SUCCESS) {
5477 * I've changed my mind. There is no requirements to keep the timer handler.
5478 * But I just add it to the tagged-data of the instance.
5479 * Just reserve for future-use.
5481 DbgPrint("Add lazy PD destroy timer\n");
5482 pd_monitor = ecore_timer_add(DELAY_TIME, lazy_pd_destroyed_cb, instance_ref(inst));
5484 ErrPrint("Failed to create a timer: %s\n", pkgname);
5485 inst = instance_unref(inst);
5487 DbgPrint("instance is deleted\n");
5490 (void)instance_set_data(inst, LAZY_PD_CLOSE_TAG, pd_monitor);
5491 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst) < 0) {
5492 ErrPrint("Failed to add a event callback for slave\n");
5497 ErrPrint("Invalid PD TYPE\n");
5498 ret = LB_STATUS_ERROR_INVALID;
5502 result = packet_create_reply(packet, "i", ret);
5504 ErrPrint("Failed to create a packet\n");
5510 static struct packet *client_activate_package(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, ret */
5512 struct client_node *client;
5513 struct packet *result;
5514 const char *pkgname;
5516 struct pkg_info *info;
5518 client = client_find_by_rpc_handle(handle);
5520 ErrPrint("Client %d is not exists\n", pid);
5521 ret = LB_STATUS_ERROR_NOT_EXIST;
5526 ret = packet_get(packet, "s", &pkgname);
5528 ErrPrint("Parameter is not matched\n");
5529 ret = LB_STATUS_ERROR_INVALID;
5534 DbgPrint("pid[%d] pkgname[%s]\n", pid, pkgname);
5538 * Validate the livebox package name.
5540 if (!package_is_lb_pkgname(pkgname)) {
5541 ErrPrint("%s is not a valid livebox package\n", pkgname);
5543 ret = LB_STATUS_ERROR_INVALID;
5547 info = package_find(pkgname);
5549 ret = LB_STATUS_ERROR_NOT_EXIST;
5551 ret = package_clear_fault(info);
5555 result = packet_create_reply(packet, "is", ret, pkgname);
5557 ErrPrint("Failed to create a packet\n");
5563 static struct packet *client_subscribed(pid_t pid, int handle, const struct packet *packet)
5565 const char *cluster;
5566 const char *category;
5567 struct client_node *client;
5570 client = client_find_by_rpc_handle(handle);
5572 ErrPrint("Client %d is not exists\n", pid);
5573 ret = LB_STATUS_ERROR_NOT_EXIST;
5577 ret = packet_get(packet, "ss", &cluster, &category);
5579 ErrPrint("Invalid argument\n");
5580 ret = LB_STATUS_ERROR_INVALID;
5584 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
5585 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5586 ErrPrint("Invalid cluster name\n");
5592 * SUBSCRIBE cluster & sub-cluster for a client.
5594 ret = client_subscribe(client, cluster, category);
5596 package_alter_instances_to_client(client, ALTER_CREATE);
5600 /*! \note No reply packet */
5604 static struct packet *client_delete_cluster(pid_t pid, int handle, const struct packet *packet)
5606 const char *cluster;
5607 struct client_node *client;
5608 struct packet *result;
5611 client = client_find_by_rpc_handle(handle);
5613 ErrPrint("Client %d is not exists\n", pid);
5614 ret = LB_STATUS_ERROR_NOT_EXIST;
5618 ret = packet_get(packet, "s", &cluster);
5620 ErrPrint("Invalid parameters\n");
5621 ret = LB_STATUS_ERROR_INVALID;
5625 DbgPrint("pid[%d] cluster[%s]\n", pid, cluster);
5627 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5628 ErrPrint("Invalid cluster: %s\n", cluster);
5629 ret = LB_STATUS_ERROR_INVALID;
5636 ret = LB_STATUS_ERROR_NOT_IMPLEMENTED;
5639 result = packet_create_reply(packet, "i", ret);
5641 ErrPrint("Failed to create a packet\n");
5647 static inline int update_pkg_cb(struct category *category, const char *pkgname, int force)
5652 c_name = group_cluster_name_by_category(category);
5653 s_name = group_category_name(category);
5655 if (!c_name || !s_name || !pkgname) {
5656 ErrPrint("Name is not valid\n");
5657 return EXIT_FAILURE;
5660 DbgPrint("Send refresh request: %s (%s/%s)\n", pkgname, c_name, s_name);
5661 slave_rpc_request_update(pkgname, "", c_name, s_name, NULL, force);
5663 /* Just try to create a new package */
5664 if (util_free_space(IMAGE_PATH) > MINIMUM_SPACE) {
5666 struct inst_info *inst;
5668 timestamp = util_timestamp();
5671 * Don't need to check the subscribed clients.
5672 * Because this callback is called by the requests of clients.
5673 * It means. some clients wants to handle this instances ;)
5675 inst = instance_create(NULL, timestamp, pkgname, "", c_name, s_name, DEFAULT_PERIOD, 0, 0);
5677 ErrPrint("Failed to create a new instance\n");
5681 return EXIT_SUCCESS;
5684 static struct packet *client_update(pid_t pid, int handle, const struct packet *packet)
5686 struct inst_info *inst = NULL;
5687 struct client_node *client;
5688 const char *pkgname;
5693 client = client_find_by_rpc_handle(handle);
5695 ErrPrint("Cilent %d is not exists\n", pid);
5699 ret = packet_get(packet, "ssi", &pkgname, &id, &force);
5701 ErrPrint("Invalid argument\n");
5705 ret = validate_request(pkgname, id, &inst, NULL);
5706 if (ret != LB_STATUS_SUCCESS) {
5710 if (instance_client(inst) != client) {
5712 ErrPrint("Insufficient permissions [%s] - %d\n", pkgname, pid);
5714 slave_rpc_request_update(pkgname, id, instance_cluster(inst), instance_category(inst), NULL, force);
5718 /*! \note No reply packet */
5722 static struct packet *client_refresh_group(pid_t pid, int handle, const struct packet *packet)
5724 const char *cluster_id;
5725 const char *category_id;
5726 struct client_node *client;
5728 struct cluster *cluster;
5729 struct category *category;
5730 struct context_info *info;
5731 Eina_List *info_list;
5735 client = client_find_by_rpc_handle(handle);
5737 ErrPrint("Cilent %d is not exists\n", pid);
5741 ret = packet_get(packet, "ssi", &cluster_id, &category_id, &force);
5743 ErrPrint("Invalid parameter\n");
5747 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster_id, category_id);
5749 if (!strlen(cluster_id) || !strcasecmp(cluster_id, DEFAULT_CLUSTER)) {
5750 ErrPrint("Invalid cluster name: %s\n", cluster_id);
5754 cluster = group_find_cluster(cluster_id);
5756 ErrPrint("Cluster [%s] is not registered\n", cluster_id);
5760 category = group_find_category(cluster, category_id);
5762 ErrPrint("Category [%s] is not registered\n", category_id);
5766 info_list = group_context_info_list(category);
5767 EINA_LIST_FOREACH(info_list, l, info) {
5768 update_pkg_cb(category, group_pkgname_from_context_info(info), force);
5772 /*! \note No reply packet */
5776 static struct packet *client_delete_category(pid_t pid, int handle, const struct packet *packet)
5778 const char *cluster;
5779 const char *category;
5780 struct client_node *client;
5781 struct packet *result;
5784 client = client_find_by_rpc_handle(handle);
5786 ErrPrint("Client %d is not exists\n", pid);
5787 ret = LB_STATUS_ERROR_NOT_EXIST;
5791 ret = packet_get(packet, "ss", &cluster, &category);
5793 ErrPrint("Invalid paramenters\n");
5794 ret = LB_STATUS_ERROR_INVALID;
5798 DbgPrint("pid[%d] cluster[%s] category[%s]\n", pid, cluster, category);
5799 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5800 ErrPrint("Invalid cluster: %s\n", cluster);
5801 ret = LB_STATUS_ERROR_INVALID;
5808 ret = LB_STATUS_ERROR_NOT_IMPLEMENTED;
5811 result = packet_create_reply(packet, "i", ret);
5813 ErrPrint("Failed to create a packet\n");
5819 static struct packet *client_unsubscribed(pid_t pid, int handle, const struct packet *packet)
5821 const char *cluster;
5822 const char *category;
5823 struct client_node *client;
5826 client = client_find_by_rpc_handle(handle);
5828 ErrPrint("Client %d is not exists\n", pid);
5829 ret = LB_STATUS_ERROR_NOT_EXIST;
5833 ret = packet_get(packet, "ss", &cluster, &category);
5835 ErrPrint("Invalid argument\n");
5836 ret = LB_STATUS_ERROR_INVALID;
5840 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
5842 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5843 ErrPrint("Invalid cluster name: %s\n", cluster);
5849 * UNSUBSCRIBE cluster & sub-cluster for a client.
5851 ret = client_unsubscribe(client, cluster, category);
5853 package_alter_instances_to_client(client, ALTER_DESTROY);
5857 /*! \note No reply packet */
5861 static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
5863 struct slave_node *slave;
5864 const char *slavename;
5867 ret = packet_get(packet, "s", &slavename);
5869 ErrPrint("Parameter is not matched\n");
5873 DbgPrint("New slave[%s](%d) is arrived\n", slavename, pid);
5875 slave = slave_find_by_name(slavename);
5877 if (!slave) { /* Try again to find a slave using pid */
5878 slave = slave_find_by_pid(pid);
5883 char pkgname[pathconf("/", _PC_PATH_MAX)];
5886 if (aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)) != AUL_R_OK) {
5887 ErrPrint("pid[%d] is not authroized provider package, try to find it using its name[%s]\n", pid, slavename);
5888 slave = slave_find_by_name(slavename);
5889 pkgname[0] = '\0'; /* Reset the pkgname */
5891 slave = slave_find_by_pkgname(pkgname);
5895 abi = abi_find_by_pkgname(pkgname);
5898 DbgPrint("Slave pkgname is invalid, ABI is replaced with '%s'(default)\n", abi);
5901 slave = slave_create(slavename, 1, abi, pkgname, 0);
5903 ErrPrint("Failed to create a new slave for %s\n", slavename);
5907 DbgPrint("New slave is created (net: 0)\n");
5909 DbgPrint("Registered slave is replaced with this new one\n");
5910 abi = slave_abi(slave);
5912 ErrPrint("ABI is not valid: %s\n", slavename);
5917 slave_set_pid(slave, pid);
5918 DbgPrint("Provider is forcely activated, pkgname(%s), abi(%s), slavename(%s)\n", pkgname, abi, slavename);
5920 ErrPrint("Slave[%d, %s] is not exists\n", pid, slavename);
5924 if (slave_pid(slave) != pid) {
5925 if (slave_pid(slave) > 0) {
5926 CRITICAL_LOG("Slave(%s) is already assigned to %d\n", slave_name(slave), slave_pid(slave));
5928 ret = aul_terminate_pid(pid);
5929 CRITICAL_LOG("Terminate %d (ret: %d)\n", pid, ret);
5933 CRITICAL_LOG("PID of slave(%s) is updated (%d -> %d)\n", slave_name(slave), slave_pid(slave), pid);
5934 slave_set_pid(slave, pid);
5940 * After updating handle,
5941 * slave activated callback will be called.
5943 slave_rpc_update_handle(slave, handle);
5949 static struct packet *slave_ping(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
5951 struct slave_node *slave;
5952 const char *slavename;
5955 slave = slave_find_by_pid(pid);
5957 ErrPrint("Slave %d is not exists\n", pid);
5961 ret = packet_get(packet, "s", &slavename);
5963 ErrPrint("Parameter is not matched\n");
5965 slave_rpc_ping(slave);
5972 static struct packet *slave_faulted(pid_t pid, int handle, const struct packet *packet)
5974 struct slave_node *slave;
5975 struct inst_info *inst;
5976 const char *pkgname;
5981 slave = slave_find_by_pid(pid);
5983 ErrPrint("Slave %d is not exists\n", pid);
5987 ret = packet_get(packet, "sss", &pkgname, &id, &func);
5989 ErrPrint("Parameter is not matched\n");
5993 ret = fault_info_set(slave, pkgname, id, func);
5994 DbgPrint("Slave Faulted: %s (%d)\n", slave_name(slave), ret);
5996 inst = package_find_instance_by_id(pkgname, id);
5998 DbgPrint("There is a no such instance(%s)\n", id);
5999 } else if (instance_state(inst) == INST_DESTROYED) {
6000 ErrPrint("Instance(%s) is already destroyed\n", id);
6002 ret = instance_destroy(inst, INSTANCE_DESTROY_FAULT);
6009 static struct packet *slave_lb_update_begin(pid_t pid, int handle, const struct packet *packet)
6011 struct slave_node *slave;
6012 struct inst_info *inst = NULL;
6013 const struct pkg_info *pkg = NULL;
6014 const char *pkgname;
6017 const char *content;
6021 slave = slave_find_by_pid(pid);
6023 ErrPrint("Slave %d is not exists\n", pid);
6027 ret = packet_get(packet, "ssdss", &pkgname, &id, &priority, &content, &title);
6029 ErrPrint("Invalid parameters\n");
6033 ret = validate_request(pkgname, id, &inst, &pkg);
6034 if (ret != LB_STATUS_SUCCESS) {
6038 if (instance_state(inst) == INST_DESTROYED) {
6039 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6043 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
6044 ret = instance_lb_update_begin(inst, priority, content, title);
6045 if (ret == LB_STATUS_SUCCESS) {
6046 slave_freeze_ttl(slave);
6049 ErrPrint("Invalid request[%s]\n", id);
6056 static struct packet *slave_lb_update_end(pid_t pid, int handle, const struct packet *packet)
6058 struct slave_node *slave;
6059 struct inst_info *inst = NULL;
6060 const struct pkg_info *pkg = NULL;
6061 const char *pkgname;
6065 slave = slave_find_by_pid(pid);
6067 ErrPrint("Slave %d is not exists\n", pid);
6071 ret = packet_get(packet, "ss", &pkgname, &id);
6073 ErrPrint("Invalid parameters\n");
6077 ret = validate_request(pkgname, id, &inst, &pkg);
6078 if (ret != LB_STATUS_SUCCESS) {
6082 if (instance_state(inst) == INST_DESTROYED) {
6083 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6087 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
6088 ret = instance_lb_update_end(inst);
6089 if (ret == LB_STATUS_SUCCESS) {
6090 slave_thaw_ttl(slave);
6093 ErrPrint("Invalid request[%s]\n", id);
6100 static struct packet *slave_pd_update_begin(pid_t pid, int handle, const struct packet *packet)
6102 struct slave_node *slave;
6103 const struct pkg_info *pkg = NULL;
6104 struct inst_info *inst = NULL;
6105 const char *pkgname;
6109 slave = slave_find_by_pid(pid);
6111 ErrPrint("Slave %d is not exists\n", pid);
6115 ret = packet_get(packet, "ss", &pkgname, &id);
6117 ErrPrint("Invalid parameters\n");
6121 ret = validate_request(pkgname, id, &inst, &pkg);
6122 if (ret != LB_STATUS_SUCCESS) {
6126 if (instance_state(inst) == INST_DESTROYED) {
6127 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6131 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
6132 (void)instance_pd_update_begin(inst);
6134 ErrPrint("Invalid request[%s]\n", id);
6141 static struct packet *slave_key_status(pid_t pid, int handle, const struct packet *packet)
6143 struct slave_node *slave;
6144 struct inst_info *inst;
6145 const char *pkgname;
6150 slave = slave_find_by_pid(pid);
6152 ErrPrint("Slave %d is not exists\n", pid);
6156 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6158 ErrPrint("Invalid parameters\n");
6162 ret = validate_request(pkgname, id, &inst, NULL);
6163 if (ret == LB_STATUS_SUCCESS) {
6164 if (instance_state(inst) == INST_DESTROYED) {
6165 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6167 (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6175 static struct packet *slave_access_status(pid_t pid, int handle, const struct packet *packet)
6177 struct slave_node *slave;
6178 struct inst_info *inst = NULL;
6179 const char *pkgname;
6184 slave = slave_find_by_pid(pid);
6186 ErrPrint("Slave %d is not exists\n", pid);
6190 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6192 ErrPrint("Invalid parameters\n");
6196 ret = validate_request(pkgname, id, &inst, NULL);
6197 if (ret == LB_STATUS_SUCCESS) {
6198 if (instance_state(inst) == INST_DESTROYED) {
6199 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6201 (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6209 static struct packet *slave_close_pd(pid_t pid, int handle, const struct packet *packet)
6211 struct slave_node *slave;
6212 struct inst_info *inst;
6213 const char *pkgname;
6218 slave = slave_find_by_pid(pid);
6220 ErrPrint("Slave %d is not exists\n", pid);
6224 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6226 ErrPrint("Invalid parameters\n");
6230 ret = validate_request(pkgname, id, &inst, NULL);
6231 if (ret == LB_STATUS_SUCCESS) {
6232 if (instance_state(inst) == INST_DESTROYED) {
6233 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6235 (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6243 static struct packet *slave_pd_update_end(pid_t pid, int handle, const struct packet *packet)
6245 struct slave_node *slave;
6246 const struct pkg_info *pkg;
6247 struct inst_info *inst;
6248 const char *pkgname;
6252 slave = slave_find_by_pid(pid);
6254 ErrPrint("Slave %d is not exists\n", pid);
6258 ret = packet_get(packet, "ss", &pkgname, &id);
6260 ErrPrint("Invalid parameters\n");
6264 ret = validate_request(pkgname, id, &inst, &pkg);
6265 if (ret != LB_STATUS_SUCCESS) {
6269 if (instance_state(inst) == INST_DESTROYED) {
6270 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6274 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
6275 (void)instance_pd_update_end(inst);
6277 ErrPrint("Invalid request[%s]\n", id);
6284 static struct packet *slave_call(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
6286 struct slave_node *slave;
6287 const char *pkgname;
6292 slave = slave_find_by_pid(pid);
6294 ErrPrint("Slave %d is not exists\n", pid);
6298 ret = packet_get(packet, "sss", &pkgname, &id, &func);
6300 ErrPrint("Parameter is not matched\n");
6304 ret = fault_func_call(slave, pkgname, id, func);
6305 slave_give_more_ttl(slave);
6311 static struct packet *slave_ret(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
6313 struct slave_node *slave;
6314 const char *pkgname;
6319 slave = slave_find_by_pid(pid);
6321 ErrPrint("Slave %d is not exists\n", pid);
6325 ret = packet_get(packet, "sss", &pkgname, &id, &func);
6327 ErrPrint("Parameter is not matched\n");
6331 ret = fault_func_ret(slave, pkgname, id, func);
6332 slave_give_more_ttl(slave);
6338 static struct packet *slave_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, width, height, priority, ret */
6340 struct slave_node *slave;
6341 const char *pkgname;
6342 const char *safe_filename;
6344 const char *content_info;
6346 const char *icon = NULL;
6347 const char *name = NULL;
6352 struct inst_info *inst = NULL;
6354 slave = slave_find_by_pid(pid);
6356 ErrPrint("Slave %d is not exists\n", pid);
6360 ret = packet_get(packet, "ssiidsssss", &pkgname, &id,
6362 &content_info, &title,
6363 &safe_filename, &icon, &name);
6365 ErrPrint("Parameter is not matched\n");
6369 ret = validate_request(pkgname, id, &inst, NULL);
6370 if (ret == LB_STATUS_SUCCESS) {
6371 if (instance_state(inst) == INST_DESTROYED) {
6372 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6376 instance_set_lb_info(inst, priority, content_info, title);
6377 instance_set_alt_info(inst, icon, name);
6379 switch (package_lb_type(instance_package(inst))) {
6380 case LB_TYPE_SCRIPT:
6381 script_handler_resize(instance_lb_script(inst), w, h);
6382 if (safe_filename) {
6383 (void)script_handler_parse_desc(inst, safe_filename, 0);
6385 safe_filename = util_uri_to_path(id);
6386 (void)script_handler_parse_desc(inst, safe_filename, 0);
6389 if (unlink(safe_filename) < 0) {
6390 ErrPrint("unlink: %s - %s\n", strerror(errno), safe_filename);
6393 case LB_TYPE_BUFFER:
6397 * text format (inst)
6399 instance_set_lb_size(inst, w, h);
6400 instance_lb_updated_by_instance(inst, safe_filename);
6404 slave_give_more_ttl(slave);
6411 static struct packet *slave_hold_scroll(pid_t pid, int handle, const struct packet *packet)
6413 struct slave_node *slave;
6414 struct inst_info *inst = NULL;
6415 const char *pkgname;
6420 slave = slave_find_by_pid(pid);
6422 ErrPrint("Slave %d is not exists\n", pid);
6426 ret = packet_get(packet, "ssi", &pkgname, &id, &seize);
6428 ErrPrint("Parameter is not matched\n");
6432 ret = validate_request(pkgname, id, &inst, NULL);
6433 if (ret == LB_STATUS_SUCCESS) {
6434 if (instance_state(inst) == INST_DESTROYED) {
6435 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6437 (void)instance_hold_scroll(inst, seize);
6445 static struct packet *slave_desc_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, decsfile, ret */
6447 struct slave_node *slave;
6448 const char *pkgname;
6450 const char *descfile;
6452 struct inst_info *inst = NULL;
6454 slave = slave_find_by_pid(pid);
6456 ErrPrint("Slave %d is not exists\n", pid);
6460 ret = packet_get(packet, "sss", &pkgname, &id, &descfile);
6462 ErrPrint("Parameter is not matched\n");
6466 ret = validate_request(pkgname, id, &inst, NULL);
6467 if (ret != LB_STATUS_SUCCESS) {
6471 if (instance_state(inst) == INST_DESTROYED) {
6472 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6476 switch (package_pd_type(instance_package(inst))) {
6477 case PD_TYPE_SCRIPT:
6478 DbgPrint("%s updated (%s)\n", instance_id(inst), descfile);
6479 if (script_handler_is_loaded(instance_pd_script(inst))) {
6480 (void)script_handler_parse_desc(inst, descfile, 1);
6484 instance_set_pd_size(inst, 0, 0);
6485 case PD_TYPE_BUFFER:
6486 instance_pd_updated(pkgname, id, descfile);
6489 DbgPrint("Ignore updated DESC(%s)\n", pkgname);
6497 static struct packet *slave_deleted(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, id, ret */
6499 struct slave_node *slave;
6500 const char *pkgname;
6503 struct inst_info *inst = NULL;
6505 slave = slave_find_by_pid(pid);
6507 ErrPrint("Slave %d is not exists\n", pid);
6511 ret = packet_get(packet, "ss", &pkgname, &id);
6513 ErrPrint("Parameter is not matched\n");
6517 ret = validate_request(pkgname, id, &inst, NULL);
6518 if (ret == LB_STATUS_SUCCESS) {
6519 ret = instance_destroyed(inst, LB_STATUS_SUCCESS);
6527 * \note for the BUFFER Type slave
6529 static struct packet *slave_acquire_buffer(pid_t pid, int handle, const struct packet *packet) /* type, id, w, h, size */
6531 enum target_type target;
6532 const char *pkgname;
6537 struct packet *result;
6538 struct slave_node *slave;
6539 struct inst_info *inst = NULL;
6540 const struct pkg_info *pkg = NULL;
6543 slave = slave_find_by_pid(pid);
6545 ErrPrint("Failed to find a slave\n");
6547 ret = LB_STATUS_ERROR_NOT_EXIST;
6551 ret = packet_get(packet, "issiii", &target, &pkgname, &id, &w, &h, &pixel_size);
6553 ErrPrint("Invalid argument\n");
6555 ret = LB_STATUS_ERROR_INVALID;
6559 ret = validate_request(pkgname, id, &inst, &pkg);
6562 if (ret != LB_STATUS_SUCCESS) {
6566 ret = LB_STATUS_ERROR_INVALID;
6568 if (instance_state(inst) == INST_DESTROYED) {
6569 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6573 if (target == TYPE_LB && package_lb_type(pkg) == LB_TYPE_BUFFER) {
6574 struct buffer_info *info;
6576 info = instance_lb_buffer(inst);
6578 if (!instance_create_lb_buffer(inst)) {
6579 ErrPrint("Failed to create a LB buffer\n");
6580 ret = LB_STATUS_ERROR_FAULT;
6584 info = instance_lb_buffer(inst);
6586 ErrPrint("LB buffer is not valid\n");
6589 * ret value should not be changed.
6595 ret = buffer_handler_resize(info, w, h);
6596 ret = buffer_handler_load(info);
6598 instance_set_lb_size(inst, w, h);
6599 instance_set_lb_info(inst, PRIORITY_NO_CHANGE, CONTENT_NO_CHANGE, TITLE_NO_CHANGE);
6600 id = buffer_handler_id(info);
6602 ErrPrint("Failed to load a buffer(%d)\n", ret);
6604 } else if (target == TYPE_PD && package_pd_type(pkg) == PD_TYPE_BUFFER) {
6605 struct buffer_info *info;
6606 Ecore_Timer *pd_monitor;
6610 pd_monitor = instance_del_data(inst, PD_OPEN_MONITOR_TAG);
6612 pd_monitor = instance_del_data(inst, PD_RESIZE_MONITOR_TAG);
6613 is_resize = !!pd_monitor;
6615 /* Invalid request. Reject this */
6616 ErrPrint("Invalid request\n");
6620 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst);
6622 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst);
6625 ecore_timer_del(pd_monitor);
6626 inst = instance_unref(inst);
6628 ErrPrint("Instance refcnt is ZERO: %s\n", pkgname);
6632 info = instance_pd_buffer(inst);
6634 if (!instance_create_pd_buffer(inst)) {
6635 ErrPrint("Failed to create a PD buffer\n");
6636 ret = LB_STATUS_ERROR_FAULT;
6637 instance_client_pd_created(inst, ret);
6641 info = instance_pd_buffer(inst);
6643 ErrPrint("PD buffer is not valid\n");
6646 * ret value should not be changed.
6648 instance_client_pd_created(inst, ret);
6653 ret = buffer_handler_resize(info, w, h);
6654 ret = buffer_handler_load(info);
6656 instance_set_pd_size(inst, w, h);
6657 id = buffer_handler_id(info);
6659 ErrPrint("Failed to load a buffer (%d)\n", ret);
6663 * Send the PD created event to the client
6666 instance_client_pd_created(inst, ret);
6671 result = packet_create_reply(packet, "is", ret, id);
6673 ErrPrint("Failed to create a packet\n");
6679 static struct packet *slave_resize_buffer(pid_t pid, int handle, const struct packet *packet)
6681 struct slave_node *slave;
6682 struct packet *result;
6683 enum target_type type;
6684 const char *pkgname;
6688 struct inst_info *inst = NULL;
6689 const struct pkg_info *pkg = NULL;
6692 slave = slave_find_by_pid(pid);
6694 ErrPrint("Failed to find a slave\n");
6695 ret = LB_STATUS_ERROR_NOT_EXIST;
6700 ret = packet_get(packet, "issii", &type, &pkgname, &id, &w, &h);
6702 ErrPrint("Invalid argument\n");
6703 ret = LB_STATUS_ERROR_INVALID;
6708 ret = validate_request(pkgname, id, &inst, &pkg);
6710 if (ret != LB_STATUS_SUCCESS) {
6714 ret = LB_STATUS_ERROR_INVALID;
6717 * Reset "id", It will be re-used from here
6720 if (instance_state(inst) == INST_DESTROYED) {
6721 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6725 if (type == TYPE_LB && package_lb_type(pkg) == LB_TYPE_BUFFER) {
6726 struct buffer_info *info;
6728 info = instance_lb_buffer(inst);
6733 ret = buffer_handler_resize(info, w, h);
6736 * id is resued for newly assigned ID
6738 if (ret == LB_STATUS_SUCCESS) {
6739 id = buffer_handler_id(info);
6740 instance_set_lb_size(inst, w, h);
6741 instance_set_lb_info(inst, PRIORITY_NO_CHANGE, CONTENT_NO_CHANGE, TITLE_NO_CHANGE);
6743 } else if (type == TYPE_PD && package_pd_type(pkg) == PD_TYPE_BUFFER) {
6744 struct buffer_info *info;
6746 info = instance_pd_buffer(inst);
6751 ret = buffer_handler_resize(info, w, h);
6754 * id is resued for newly assigned ID
6756 if (ret == LB_STATUS_SUCCESS) {
6757 id = buffer_handler_id(info);
6758 instance_set_pd_size(inst, w, h);
6763 result = packet_create_reply(packet, "is", ret, id);
6765 ErrPrint("Failed to create a packet\n");
6771 static struct packet *slave_release_buffer(pid_t pid, int handle, const struct packet *packet)
6773 enum target_type type;
6774 const char *pkgname;
6776 struct packet *result;
6777 struct slave_node *slave;
6778 struct inst_info *inst = NULL;
6779 const struct pkg_info *pkg = NULL;
6782 slave = slave_find_by_pid(pid);
6784 ErrPrint("Failed to find a slave\n");
6785 ret = LB_STATUS_ERROR_NOT_EXIST;
6789 if (packet_get(packet, "iss", &type, &pkgname, &id) != 3) {
6790 ErrPrint("Inavlid argument\n");
6791 ret = LB_STATUS_ERROR_INVALID;
6795 ret = validate_request(pkgname, id, &inst, &pkg);
6796 if (ret != LB_STATUS_SUCCESS) {
6800 ret = LB_STATUS_ERROR_INVALID;
6802 if (type == TYPE_LB && package_lb_type(pkg) == LB_TYPE_BUFFER) {
6803 struct buffer_info *info;
6805 info = instance_lb_buffer(inst);
6806 ret = buffer_handler_unload(info);
6807 } else if (type == TYPE_PD && package_pd_type(pkg) == PD_TYPE_BUFFER) {
6808 struct buffer_info *info;
6809 Ecore_Timer *pd_monitor;
6811 pd_monitor = instance_del_data(inst, PD_CLOSE_MONITOR_TAG);
6812 if (!pd_monitor && !package_is_fault(pkg)) {
6813 ErrPrint("Slave requests to release a buffer\n");
6816 * In this case just keep going to release buffer,
6817 * Even if a user(client) doesn't wants to destroy the PD.
6819 * If the slave tries to destroy PD buffer, it should be
6820 * released and reported to the client about its status.
6822 * Even if the pd is destroyed by timeout handler,
6823 * instance_client_pd_destroyed function will be ignored
6824 * by pd.need_to_send_close_event flag.
6825 * which will be checked by instance_client_pd_destroyed function.
6830 * provider can try to resize the buffer size.
6831 * in that case, it will release the buffer first.
6832 * Then even though the client doesn't request to close the PD,
6833 * the provider can release it.
6834 * If we send the close event to the client,
6835 * The client will not able to allocate PD again.
6836 * In this case, add the pd,monitor again. from here.
6837 * to wait the re-allocate buffer.
6838 * If the client doesn't request buffer reallocation,
6839 * Treat it as a fault. and close the PD.
6841 info = instance_pd_buffer(inst);
6842 ret = buffer_handler_unload(info);
6844 if (ret == LB_STATUS_SUCCESS) {
6845 pd_monitor = ecore_timer_add(PD_REQUEST_TIMEOUT, pd_resize_monitor_cb, instance_ref(inst));
6847 ErrPrint("Failed to create a timer for PD Open monitor\n");
6848 inst = instance_unref(inst);
6850 DbgPrint("Instance is deleted\n");
6853 (void)instance_set_data(inst, PD_RESIZE_MONITOR_TAG, pd_monitor);
6854 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) != LB_STATUS_SUCCESS) {
6855 ErrPrint("Failed to add event handler: %s\n", pkgname);
6863 * If the instance has pd_monitor, the pd close requested from client via client_destroy_pd.
6865 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
6866 ecore_timer_del(pd_monitor);
6868 inst = instance_unref(inst);
6870 ErrPrint("Instance is released: %s\n", pkgname);
6871 ret = LB_STATUS_ERROR_FAULT;
6876 This case means that the package is faulted so the service provider tries to release the buffer
6879 info = instance_pd_buffer(inst);
6880 ret = buffer_handler_unload(info);
6884 * Send the PD destroyed event to the client
6886 instance_client_pd_destroyed(inst, ret);
6891 result = packet_create_reply(packet, "i", ret);
6893 ErrPrint("Failed to create a packet\n");
6899 static struct packet *service_change_period(pid_t pid, int handle, const struct packet *packet)
6901 struct inst_info *inst = NULL;
6902 struct packet *result;
6903 const char *pkgname;
6908 ret = packet_get(packet, "ssd", &pkgname, &id, &period);
6910 ErrPrint("Invalid packet\n");
6911 ret = LB_STATUS_ERROR_INVALID;
6916 struct pkg_info *pkg;
6918 pkg = package_find(pkgname);
6920 ret = LB_STATUS_ERROR_NOT_EXIST;
6921 } else if (package_is_fault(pkg)) {
6922 ret = LB_STATUS_ERROR_FAULT;
6924 Eina_List *inst_list;
6927 inst_list = package_instance_list(pkg);
6928 EINA_LIST_FOREACH(inst_list, l, inst) {
6929 ret = instance_set_period(inst, period);
6931 ErrPrint("Failed to change the period of %s to (%lf)\n", pkgname, period);
6936 ret = validate_request(pkgname, id, &inst, NULL);
6937 if (ret == LB_STATUS_SUCCESS) {
6938 if (instance_state(inst) == INST_DESTROYED) {
6939 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6940 ret = LB_STATUS_ERROR_INVALID;
6944 ret = instance_set_period(inst, period);
6948 DbgPrint("Change the update period: %s, %lf : %d\n", pkgname, period, ret);
6950 result = packet_create_reply(packet, "i", ret);
6952 ErrPrint("Failed to create a packet\n");
6958 static struct packet *service_update(pid_t pid, int handle, const struct packet *packet)
6960 Eina_List *inst_list;
6961 struct pkg_info *pkg;
6962 struct packet *result;
6963 const char *pkgname;
6965 const char *cluster;
6966 const char *category;
6967 const char *content;
6972 ret = packet_get(packet, "sssssi", &pkgname, &id, &cluster, &category, &content, &force);
6974 ErrPrint("Invalid Packet\n");
6975 ret = LB_STATUS_ERROR_INVALID;
6979 lbid = package_lb_pkgname(pkgname);
6981 ErrPrint("Invalid package %s\n", pkgname);
6982 ret = LB_STATUS_ERROR_INVALID;
6986 pkg = package_find(lbid);
6988 ret = LB_STATUS_ERROR_NOT_EXIST;
6993 if (package_is_fault(pkg)) {
6994 ret = LB_STATUS_ERROR_FAULT;
6999 inst_list = package_instance_list(pkg);
7000 if (!eina_list_count(inst_list)) {
7001 ret = LB_STATUS_ERROR_NOT_EXIST;
7006 if (id && strlen(id)) {
7008 struct inst_info *inst;
7010 ret = LB_STATUS_ERROR_NOT_EXIST;
7011 EINA_LIST_FOREACH(inst_list, l, inst) {
7012 if (!strcmp(instance_id(inst), id)) {
7013 ret = LB_STATUS_SUCCESS;
7018 if (ret == LB_STATUS_ERROR_NOT_EXIST) {
7026 * Validate the update requstor.
7028 slave_rpc_request_update(lbid, id, cluster, category, content, force);
7030 ret = LB_STATUS_SUCCESS;
7033 result = packet_create_reply(packet, "i", ret);
7035 ErrPrint("Failed to create a packet\n");
7041 static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet *packet)
7043 struct liveinfo *info;
7044 struct packet *result;
7046 const char *fifo_name;
7049 DbgPrint("Request arrived from %d\n", pid);
7051 if (packet_get(packet, "d", ×tamp) != 1) {
7052 ErrPrint("Invalid packet\n");
7054 ret = LB_STATUS_ERROR_INVALID;
7058 info = liveinfo_create(pid, handle);
7060 ErrPrint("Failed to create a liveinfo object\n");
7062 ret = LB_STATUS_ERROR_INVALID;
7067 fifo_name = liveinfo_filename(info);
7068 DbgPrint("FIFO Created: %s (Serve for %d)\n", fifo_name, pid);
7071 result = packet_create_reply(packet, "si", fifo_name, ret);
7073 ErrPrint("Failed to create a result packet\n");
7079 static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet)
7083 struct liveinfo *info;
7084 struct slave_node *slave;
7088 if (packet_get(packet, "d", ×tamp) != 1) {
7089 ErrPrint("Invalid argument\n");
7093 info = liveinfo_find_by_pid(pid);
7095 ErrPrint("Invalid request\n");
7099 liveinfo_open_fifo(info);
7100 fp = liveinfo_fifo(info);
7102 liveinfo_close_fifo(info);
7106 list = (Eina_List *)slave_list();
7107 EINA_LIST_FOREACH(list, l, slave) {
7108 fprintf(fp, "%d %s %s %s %d %d %d %s %d %d %lf\n",
7111 slave_pkgname(slave),
7113 slave_is_secured(slave),
7114 slave_refcnt(slave),
7115 slave_fault_count(slave),
7116 slave_state_string(slave),
7117 slave_loaded_instance(slave),
7118 slave_loaded_package(slave),
7123 fprintf(fp, "EOD\n");
7124 liveinfo_close_fifo(info);
7129 static inline const char *visible_state_string(enum livebox_visible_state state)
7136 case LB_HIDE_WITH_PAUSE:
7145 static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet)
7147 const char *pkgname;
7148 struct liveinfo *info;
7149 struct pkg_info *pkg;
7151 Eina_List *inst_list;
7152 struct inst_info *inst;
7155 if (packet_get(packet, "s", &pkgname) != 1) {
7156 ErrPrint("Invalid argument\n");
7160 info = liveinfo_find_by_pid(pid);
7162 ErrPrint("Invalid request\n");
7166 liveinfo_open_fifo(info);
7167 fp = liveinfo_fifo(info);
7169 ErrPrint("Invalid fp\n");
7170 liveinfo_close_fifo(info);
7174 if (!package_is_lb_pkgname(pkgname)) {
7175 ErrPrint("Invalid package name\n");
7179 pkg = package_find(pkgname);
7181 ErrPrint("Package is not exists\n");
7185 inst_list = package_instance_list(pkg);
7186 EINA_LIST_FOREACH(inst_list, l, inst) {
7187 fprintf(fp, "%s %s %s %lf %s %d %d\n",
7189 instance_cluster(inst),
7190 instance_category(inst),
7191 instance_period(inst),
7192 visible_state_string(instance_visible_state(inst)),
7193 instance_lb_width(inst),
7194 instance_lb_height(inst));
7198 fprintf(fp, "EOD\n");
7199 liveinfo_close_fifo(info);
7205 static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet)
7209 Eina_List *inst_list;
7210 struct liveinfo *info;
7211 struct pkg_info *pkg;
7212 struct slave_node *slave;
7214 const char *slavename;
7217 if (packet_get(packet, "d", ×tamp) != 1) {
7218 ErrPrint("Invalid argument\n");
7222 info = liveinfo_find_by_pid(pid);
7224 ErrPrint("Invalid request\n");
7228 liveinfo_open_fifo(info);
7229 fp = liveinfo_fifo(info);
7231 liveinfo_close_fifo(info);
7235 list = (Eina_List *)package_list();
7236 EINA_LIST_FOREACH(list, l, pkg) {
7237 slave = package_slave(pkg);
7240 slavename = slave_name(slave);
7241 pid = slave_pid(slave);
7247 inst_list = (Eina_List *)package_instance_list(pkg);
7248 fprintf(fp, "%d %s %s %s %d %d %d\n",
7250 strlen(slavename) ? slavename : "(none)",
7253 package_refcnt(pkg),
7254 package_fault_count(pkg),
7255 eina_list_count(inst_list)
7259 fprintf(fp, "EOD\n");
7260 liveinfo_close_fifo(info);
7265 static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct packet *packet)
7270 static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet)
7272 struct liveinfo *info;
7278 if (packet_get(packet, "sss", &cmd, &pkgname, &id) != 3) {
7279 ErrPrint("Invalid argument\n");
7283 info = liveinfo_find_by_pid(pid);
7285 ErrPrint("Invalid request\n");
7289 liveinfo_open_fifo(info);
7290 fp = liveinfo_fifo(info);
7292 liveinfo_close_fifo(info);
7296 if (!strcmp(cmd, "rmpack")) {
7297 fprintf(fp, "%d\n", ENOSYS);
7298 } else if (!strcmp(cmd, "rminst")) {
7299 struct inst_info *inst;
7300 inst = package_find_instance_by_id(pkgname, id);
7302 fprintf(fp, "%d\n", ENOENT);
7304 (void)instance_destroy(inst, INSTANCE_DESTROY_DEFAULT);
7305 fprintf(fp, "%d\n", 0);
7307 } else if (!strcmp(cmd, "faultinst")) {
7308 struct inst_info *inst;
7309 inst = package_find_instance_by_id(pkgname, id);
7311 fprintf(fp, "%d\n", ENOENT);
7313 struct pkg_info *pkg;
7315 pkg = instance_package(inst);
7317 fprintf(fp, "%d\n", EFAULT);
7319 (void)package_faulted(pkg);
7320 fprintf(fp, "%d\n", 0);
7325 fprintf(fp, "EOD\n");
7326 liveinfo_close_fifo(info);
7332 static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct packet *packet)
7334 struct liveinfo *info;
7339 int ret = LB_STATUS_ERROR_INVALID;
7341 if (packet_get(packet, "sss", &cmd, &var, &val) != 3) {
7342 ErrPrint("Invalid argument\n");
7346 info = liveinfo_find_by_pid(pid);
7348 ErrPrint("Invalid request\n");
7352 if (!strcasecmp(var, "debug")) {
7353 if (!strcasecmp(cmd, "set")) {
7354 g_conf.debug_mode = !strcasecmp(val, "on");
7355 } else if (!strcasecmp(cmd, "get")) {
7357 ret = g_conf.debug_mode;
7358 } else if (!strcasecmp(var, "slave_max_load")) {
7359 if (!strcasecmp(cmd, "set")) {
7360 g_conf.slave_max_load = atoi(val);
7361 } else if (!strcasecmp(cmd, "get")) {
7363 ret = g_conf.slave_max_load;
7366 liveinfo_open_fifo(info);
7367 fp = liveinfo_fifo(info);
7369 liveinfo_close_fifo(info);
7372 fprintf(fp, "%d\nEOD\n", ret);
7373 liveinfo_close_fifo(info);
7379 static struct method s_info_table[] = {
7381 .cmd = "liveinfo_hello",
7382 .handler = liveinfo_hello,
7385 .cmd = "slave_list",
7386 .handler = liveinfo_slave_list,
7390 .handler = liveinfo_pkg_list,
7394 .handler = liveinfo_inst_list,
7397 .cmd = "slave_ctrl",
7398 .handler = liveinfo_slave_ctrl,
7402 .handler = liveinfo_pkg_ctrl,
7405 .cmd = "master_ctrl",
7406 .handler = liveinfo_master_ctrl,
7414 static struct method s_client_table[] = {
7416 .cmd = "pd_mouse_move",
7417 .handler = client_pd_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7420 .cmd = "lb_mouse_move",
7421 .handler = client_lb_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7424 .cmd = "pd_mouse_down",
7425 .handler = client_pd_mouse_down, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
7428 .cmd = "pd_mouse_up",
7429 .handler = client_pd_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7432 .cmd = "lb_mouse_down",
7433 .handler = client_lb_mouse_down, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7436 .cmd = "lb_mouse_up",
7437 .handler = client_lb_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7440 .cmd = "pd_mouse_enter",
7441 .handler = client_pd_mouse_enter, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
7444 .cmd = "pd_mouse_leave",
7445 .handler = client_pd_mouse_leave, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
7448 .cmd = "lb_mouse_enter",
7449 .handler = client_lb_mouse_enter, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7452 .cmd = "lb_mouse_leave",
7453 .handler = client_lb_mouse_leave, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7456 .cmd = "lb_mouse_set",
7457 .handler = client_lb_mouse_set,
7460 .cmd = "lb_mouse_unset",
7461 .handler = client_lb_mouse_unset,
7464 .cmd = "pd_mouse_set",
7465 .handler = client_pd_mouse_set,
7468 .cmd = "pd_mouse_unset",
7469 .handler = client_pd_mouse_unset,
7472 .cmd = "change,visibility",
7473 .handler = client_change_visibility,
7476 .cmd = "lb_acquire_pixmap",
7477 .handler = client_lb_acquire_pixmap,
7480 .cmd = "lb_release_pixmap",
7481 .handler = client_lb_release_pixmap,
7484 .cmd = "pd_acquire_pixmap",
7485 .handler = client_pd_acquire_pixmap,
7488 .cmd = "pd_release_pixmap",
7489 .handler = client_pd_release_pixmap,
7493 .handler = client_acquire, /*!< pid, ret */
7497 .handler = cilent_release, /*!< pid, ret */
7501 .handler = client_clicked, /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
7504 .cmd = "text_signal",
7505 .handler = client_text_signal, /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
7509 .handler = client_delete, /* pid, pkgname, filename, ret */
7513 .handler = client_resize, /* pid, pkgname, filename, w, h, ret */
7517 .handler = client_new, /* pid, timestamp, pkgname, content, cluster, category, period, ret */
7520 .cmd = "set_period",
7521 .handler = client_set_period, /* pid, pkgname, filename, period, ret, period */
7524 .cmd = "change_group",
7525 .handler = client_change_group, /* pid, pkgname, filename, cluster, category, ret */
7528 .cmd = "pinup_changed",
7529 .handler = client_pinup_changed, /* pid, pkgname, filename, pinup, ret */
7533 .handler = client_create_pd, /* pid, pkgname, filename, ret */
7537 .handler = client_pd_move, /* pkgname, id, x, y */
7540 .cmd = "destroy_pd",
7541 .handler = client_destroy_pd, /* pid, pkgname, filename, ret */
7544 .cmd = "activate_package",
7545 .handler = client_activate_package, /* pid, pkgname, ret */
7548 .cmd = "subscribe", /* pid, cluster, sub-cluster */
7549 .handler = client_subscribed,
7552 .cmd = "unsubscribe", /* pid, cluster, sub-cluster */
7553 .handler = client_unsubscribed,
7556 .cmd = "delete_cluster",
7557 .handler = client_delete_cluster,
7560 .cmd = "delete_category",
7561 .handler = client_delete_category,
7564 .cmd = "refresh_group",
7565 .handler = client_refresh_group,
7569 .handler = client_update,
7573 .cmd = "pd_access_hl",
7574 .handler = client_pd_access_hl,
7577 .cmd = "pd_access_hl_prev",
7578 .handler = client_pd_access_hl_prev,
7581 .cmd = "pd_access_hl_next",
7582 .handler = client_pd_access_hl_next,
7585 .cmd = "pd_access_activate",
7586 .handler = client_pd_access_activate,
7589 .cmd = "pd_access_action_up",
7590 .handler = client_pd_access_action_up,
7593 .cmd = "pd_access_action_down",
7594 .handler = client_pd_access_action_down,
7597 .cmd = "pd_access_unhighlight",
7598 .handler = client_pd_access_unhighlight,
7601 .cmd = "pd_access_scroll_down",
7602 .handler = client_pd_access_scroll_down,
7605 .cmd = "pd_access_scroll_move",
7606 .handler = client_pd_access_scroll_move,
7609 .cmd = "pd_access_scroll_up",
7610 .handler = client_pd_access_scroll_up,
7614 .cmd = "lb_access_hl",
7615 .handler = client_lb_access_hl,
7618 .cmd = "lb_access_hl_prev",
7619 .handler = client_lb_access_hl_prev,
7622 .cmd = "lb_access_hl_next",
7623 .handler = client_lb_access_hl_next,
7626 .cmd = "lb_access_activate",
7627 .handler = client_lb_access_activate,
7630 .cmd = "lb_access_action_up",
7631 .handler = client_lb_access_action_up,
7634 .cmd = "lb_access_action_down",
7635 .handler = client_lb_access_action_down,
7638 .cmd = "lb_access_unhighlight",
7639 .handler = client_lb_access_unhighlight,
7642 .cmd = "lb_access_scroll_down",
7643 .handler = client_lb_access_scroll_down,
7646 .cmd = "lb_access_scroll_move",
7647 .handler = client_lb_access_scroll_move,
7650 .cmd = "lb_access_scroll_up",
7651 .handler = client_lb_access_scroll_up,
7655 .cmd = "lb_key_down",
7656 .handler = client_lb_key_down,
7660 .handler = client_lb_key_up,
7663 .cmd = "lb_key_focus_in",
7664 .handler = client_lb_key_focus_in,
7667 .cmd = "lb_key_focus_out",
7668 .handler = client_lb_key_focus_out,
7671 .cmd = "lb_key_set",
7672 .handler = client_lb_key_set,
7675 .cmd = "lb_key_unset",
7676 .handler = client_lb_key_unset,
7680 .cmd = "pd_key_down",
7681 .handler = client_pd_key_down,
7685 .handler = client_pd_key_up,
7688 .cmd = "pd_key_focus_in",
7689 .handler = client_pd_key_focus_in,
7692 .cmd = "pd_key_focus_out",
7693 .handler = client_pd_key_focus_out,
7696 .cmd = "pd_key_set",
7697 .handler = client_pd_key_set,
7700 .cmd = "pd_key_unset",
7701 .handler = client_pd_key_unset,
7705 .cmd = "client_paused",
7706 .handler = client_pause_request,
7709 .cmd = "client_resumed",
7710 .handler = client_resume_request,
7714 .cmd = "update_mode",
7715 .handler = client_update_mode,
7724 static struct method s_service_table[] = {
7726 .cmd = "service_update",
7727 .handler = service_update,
7730 .cmd = "service_change_period",
7731 .handler = service_change_period,
7739 static struct method s_slave_table[] = {
7742 .handler = slave_call, /* slave_name, pkgname, filename, function, ret */
7746 .handler = slave_ret, /* slave_name, pkgname, filename, function, ret */
7750 .handler = slave_updated, /* slave_name, pkgname, filename, width, height, priority, ret */
7753 .cmd = "desc_updated",
7754 .handler = slave_desc_updated, /* slave_name, pkgname, filename, decsfile, ret */
7758 .handler = slave_deleted, /* slave_name, pkgname, filename, ret */
7761 .cmd = "acquire_buffer",
7762 .handler = slave_acquire_buffer, /* slave_name, id, w, h, size, - out - type, shmid */
7765 .cmd = "resize_buffer",
7766 .handler = slave_resize_buffer,
7769 .cmd = "release_buffer",
7770 .handler = slave_release_buffer, /* slave_name, id - ret */
7774 .handler = slave_faulted, /* slave_name, pkgname, id, funcname */
7778 .handler = slave_hold_scroll, /* slave_name, pkgname, id, seize */
7782 .cmd = "lb_update_begin",
7783 .handler = slave_lb_update_begin,
7786 .cmd = "lb_update_end",
7787 .handler = slave_lb_update_end,
7790 .cmd = "pd_update_begin",
7791 .handler = slave_pd_update_begin,
7794 .cmd = "pd_update_end",
7795 .handler = slave_pd_update_end,
7799 .cmd = "access_status",
7800 .handler = slave_access_status,
7803 .cmd = "key_status",
7804 .handler = slave_key_status,
7808 .handler = slave_close_pd,
7813 .handler = slave_hello, /* slave_name, ret */
7817 .handler = slave_ping, /* slave_name, ret */
7826 HAPI int server_init(void)
7828 com_core_packet_use_thread(COM_CORE_THREAD);
7830 if (unlink(INFO_SOCKET) < 0) {
7831 ErrPrint("info socket: %s\n", strerror(errno));
7834 if (unlink(SLAVE_SOCKET) < 0) {
7835 ErrPrint("slave socket: %s\n", strerror(errno));
7838 if (unlink(CLIENT_SOCKET) < 0) {
7839 ErrPrint("client socket: %s\n", strerror(errno));
7842 if (unlink(SERVICE_SOCKET) < 0) {
7843 ErrPrint("service socket: %s\n", strerror(errno));
7846 s_info.info_fd = com_core_packet_server_init(INFO_SOCKET, s_info_table);
7847 if (s_info.info_fd < 0) {
7848 ErrPrint("Failed to create a info socket\n");
7851 s_info.slave_fd = com_core_packet_server_init(SLAVE_SOCKET, s_slave_table);
7852 if (s_info.slave_fd < 0) {
7853 ErrPrint("Failed to create a slave socket\n");
7856 s_info.client_fd = com_core_packet_server_init(CLIENT_SOCKET, s_client_table);
7857 if (s_info.client_fd < 0) {
7858 ErrPrint("Failed to create a client socket\n");
7864 * Skip address to use the NULL.
7866 s_info.remote_client_fd = com_core_packet_server_init("remote://:"CLIENT_PORT, s_client_table);
7867 if (s_info.client_fd < 0) {
7868 ErrPrint("Failed to create a remote client socket\n");
7871 s_info.service_fd = com_core_packet_server_init(SERVICE_SOCKET, s_service_table);
7872 if (s_info.service_fd < 0) {
7873 ErrPrint("Faild to create a service socket\n");
7876 if (chmod(INFO_SOCKET, 0600) < 0) {
7877 ErrPrint("info socket: %s\n", strerror(errno));
7880 if (chmod(SLAVE_SOCKET, 0666) < 0) {
7881 ErrPrint("slave socket: %s\n", strerror(errno));
7884 if (chmod(CLIENT_SOCKET, 0666) < 0) {
7885 ErrPrint("client socket: %s\n", strerror(errno));
7888 if (chmod(SERVICE_SOCKET, 0666) < 0) {
7889 ErrPrint("service socket: %s\n", strerror(errno));
7895 HAPI int server_fini(void)
7897 if (s_info.info_fd > 0) {
7898 com_core_packet_server_fini(s_info.info_fd);
7899 s_info.info_fd = -1;
7902 if (s_info.slave_fd > 0) {
7903 com_core_packet_server_fini(s_info.slave_fd);
7904 s_info.slave_fd = -1;
7907 if (s_info.client_fd > 0) {
7908 com_core_packet_server_fini(s_info.client_fd);
7909 s_info.client_fd = -1;
7912 if (s_info.remote_client_fd > 0) {
7913 com_core_packet_server_fini(s_info.remote_client_fd);
7914 s_info.remote_client_fd = -1;
7917 if (s_info.service_fd > 0) {
7918 com_core_packet_server_fini(s_info.service_fd);
7919 s_info.service_fd = -1;