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;
956 client = client_find_by_rpc_handle(handle);
958 ErrPrint("Client %d is not exists\n", pid);
959 ret = LB_STATUS_ERROR_NOT_EXIST;
963 ret = packet_get(packet, "ssid", &pkgname, &id, &type, ×tamp);
965 ErrPrint("Parameter is not matched\n");
966 ret = LB_STATUS_ERROR_INVALID;
971 * Below two types must has to be sync'd with livebox-viewer
973 * LB_DELETE_PERMANENTLY = 0x01,
974 * LB_DELETE_TEMPORARY = 0x02,
980 * Trust the package name which are sent by the client.
981 * The package has to be a livebox package name.
983 ret = validate_request(pkgname, id, &inst, &pkg);
984 if (ret != LB_STATUS_SUCCESS) {
985 DbgPrint("Failed to find by id(%s), try to find it using timestamp(%lf)\n", id, timestamp);
986 inst = package_find_instance_by_timestamp(pkgname, timestamp);
991 pkg = instance_package(inst);
993 ErrPrint("Package info is not valid: %s\n", id);
998 if (package_is_fault(pkg)) {
999 DbgPrint("Faulted package. will be deleted soon: %s\n", id);
1000 ret = LB_STATUS_ERROR_FAULT;
1004 if (instance_client(inst) != client) {
1005 if (instance_has_client(inst, client)) {
1006 struct deleted_item *item;
1008 item = malloc(sizeof(*item));
1010 ErrPrint("Heap: %s\n", strerror(errno));
1011 ret = LB_STATUS_ERROR_MEMORY;
1015 * Send DELETED EVENT to the client.
1016 * after return from this function.
1018 * Client will prepare the deleted event after get this function's return value.
1019 * So We have to make a delay to send a deleted event.
1022 item->client = client_ref(client);
1023 item->inst = instance_ref(inst);
1025 if (!ecore_timer_add(DELAY_TIME, lazy_delete_cb, item)) {
1026 ErrPrint("Failed to add a delayzed delete callback\n");
1027 (void)client_unref(client);
1028 (void)instance_unref(inst);
1030 ret = LB_STATUS_ERROR_FAULT;
1032 ret = LB_STATUS_SUCCESS;
1036 ErrPrint("Client has no permission\n");
1037 ret = LB_STATUS_ERROR_PERMISSION;
1041 case LB_DELETE_PERMANENTLY:
1042 ret = instance_destroy(inst, INSTANCE_DESTROY_DEFAULT);
1044 case LB_DELETE_TEMPORARY:
1045 ret = instance_destroy(inst, INSTANCE_DESTROY_TEMPORARY);
1053 result = packet_create_reply(packet, "i", ret);
1055 ErrPrint("Failed to create a packet\n");
1061 static struct packet *client_resize(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, w, h, ret */
1063 struct client_node *client;
1064 struct packet *result;
1065 const char *pkgname;
1069 struct inst_info *inst = NULL;
1072 client = client_find_by_rpc_handle(handle);
1074 ErrPrint("Client %d is not exists\n", pid);
1075 ret = LB_STATUS_ERROR_NOT_EXIST;
1079 ret = packet_get(packet, "ssii", &pkgname, &id, &w, &h);
1081 ErrPrint("Parameter is not matched\n");
1082 ret = LB_STATUS_ERROR_INVALID;
1086 DbgPrint("RESIZE: Client request resize to %dx%d (pid: %d, pkgname: %s)\n", w, h, pid, pkgname);
1090 * Trust the package name which are sent by the client.
1091 * The package has to be a livebox package name.
1093 ret = validate_request(pkgname, id, &inst, NULL);
1094 if (ret != LB_STATUS_SUCCESS) {
1098 if (instance_client(inst) != client) {
1099 ret = LB_STATUS_ERROR_PERMISSION;
1101 ret = instance_resize(inst, w, h);
1105 result = packet_create_reply(packet, "i", ret);
1107 ErrPrint("Failed to create a packet\n");
1113 static struct packet *client_new(pid_t pid, int handle, const struct packet *packet) /* pid, timestamp, pkgname, content, cluster, category, period, ret */
1115 struct client_node *client;
1116 struct packet *result;
1117 const char *pkgname;
1118 const char *content;
1119 const char *cluster;
1120 const char *category;
1124 struct pkg_info *info;
1130 client = client_find_by_rpc_handle(handle);
1132 ErrPrint("Client %d is not exists\n", pid);
1133 ret = LB_STATUS_ERROR_NOT_EXIST;
1137 ret = packet_get(packet, "dssssdii", ×tamp, &pkgname, &content, &cluster, &category, &period, &width, &height);
1139 ErrPrint("Parameter is not matched\n");
1140 ret = LB_STATUS_ERROR_INVALID;
1144 DbgPrint("pid[%d] period[%lf] pkgname[%s] content[%s] cluster[%s] category[%s] period[%lf]\n",
1145 pid, timestamp, pkgname, content, cluster, category, period);
1147 lbid = package_lb_pkgname(pkgname);
1149 ErrPrint("This %s has no livebox package\n", pkgname);
1150 ret = LB_STATUS_ERROR_INVALID;
1154 mainappid = livebox_service_mainappid(lbid);
1155 if (!package_is_enabled(mainappid)) {
1158 ret = LB_STATUS_ERROR_DISABLED;
1163 info = package_find(lbid);
1166 pkgid = livebox_service_appid(lbid);
1170 ret = LB_STATUS_ERROR_FAULT;
1174 info = package_create(pkgid, lbid);
1179 ret = LB_STATUS_ERROR_FAULT;
1180 } else if (package_is_fault(info)) {
1181 ret = LB_STATUS_ERROR_FAULT;
1182 } else if (util_free_space(IMAGE_PATH) <= MINIMUM_SPACE) {
1183 ErrPrint("Not enough space\n");
1184 ret = LB_STATUS_ERROR_NO_SPACE;
1186 struct inst_info *inst;
1188 if (period > 0.0f && period < MINIMUM_PERIOD) {
1189 period = MINIMUM_PERIOD;
1192 inst = instance_create(client, timestamp, lbid, content, cluster, category, period, width, height);
1195 * Using the "inst" without validate its value is at my disposal. ;)
1197 ret = inst ? 0 : LB_STATUS_ERROR_FAULT;
1203 result = packet_create_reply(packet, "i", ret);
1205 ErrPrint("Failed to create a packet\n");
1211 static struct packet *client_change_visibility(pid_t pid, int handle, const struct packet *packet)
1213 struct client_node *client;
1214 const char *pkgname;
1216 enum livebox_visible_state state;
1218 struct inst_info *inst = NULL;
1220 client = client_find_by_rpc_handle(handle);
1222 ErrPrint("Client %d is not exists\n", pid);
1223 ret = LB_STATUS_ERROR_NOT_EXIST;
1227 ret = packet_get(packet, "ssi", &pkgname, &id, (int *)&state);
1229 ErrPrint("Parameter is not matched\n");
1230 ret = LB_STATUS_ERROR_INVALID;
1236 * Trust the package name which are sent by the client.
1237 * The package has to be a livebox package name.
1239 ret = validate_request(pkgname, id, &inst, NULL);
1240 if (ret != LB_STATUS_SUCCESS) {
1244 if (instance_client(inst) != client) {
1245 ret = LB_STATUS_ERROR_PERMISSION;
1247 ret = instance_set_visible_state(inst, state);
1251 /*! \note No reply packet */
1255 static struct packet *client_set_period(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, period, ret */
1257 struct client_node *client;
1258 struct packet *result;
1259 const char *pkgname;
1263 struct inst_info *inst = NULL;
1265 client = client_find_by_rpc_handle(handle);
1267 ErrPrint("Client %d is not exists\n", pid);
1268 ret = LB_STATUS_ERROR_NOT_EXIST;
1272 ret = packet_get(packet, "ssd", &pkgname, &id, &period);
1274 ErrPrint("Parameter is not matched\n");
1275 ret = LB_STATUS_ERROR_INVALID;
1279 DbgPrint("pid[%d] pkgname[%s] period[%lf]\n", pid, pkgname, period);
1283 * Trust the package name which are sent by the client.
1284 * The package has to be a livebox package name.
1286 ret = validate_request(pkgname, id, &inst, NULL);
1287 if (ret != LB_STATUS_SUCCESS) {
1291 if (instance_client(inst) != client) {
1292 ret = LB_STATUS_ERROR_PERMISSION;
1294 ret = instance_set_period(inst, period);
1298 result = packet_create_reply(packet, "i", ret);
1300 ErrPrint("Failed to create a packet\n");
1306 static struct packet *client_change_group(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, cluster, category, ret */
1308 struct client_node *client;
1309 struct packet *result;
1310 const char *pkgname;
1312 const char *cluster;
1313 const char *category;
1314 struct inst_info *inst = NULL;
1317 client = client_find_by_rpc_handle(handle);
1319 ErrPrint("Client %d is not exists\n", pid);
1320 ret = LB_STATUS_ERROR_NOT_EXIST;
1324 ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category);
1326 ErrPrint("Parameter is not matched\n");
1327 ret = LB_STATUS_ERROR_INVALID;
1331 DbgPrint("pid[%d] pkgname[%s] cluster[%s] category[%s]\n", pid, pkgname, cluster, category);
1335 * Trust the package name which are sent by the client.
1336 * The package has to be a livebox package name.
1338 ret = validate_request(pkgname, id, &inst, NULL);
1339 if (ret != LB_STATUS_SUCCESS) {
1343 if (instance_client(inst) != client) {
1344 ret = LB_STATUS_ERROR_PERMISSION;
1346 ret = instance_change_group(inst, cluster, category);
1350 result = packet_create_reply(packet, "i", ret);
1352 ErrPrint("Failed to create a packet\n");
1358 static struct packet *client_pd_mouse_enter(pid_t pid, int handle, const struct packet *packet)
1360 struct client_node *client;
1361 const char *pkgname;
1367 struct inst_info *inst = NULL;
1368 const struct pkg_info *pkg = NULL;
1370 client = client_find_by_rpc_handle(handle);
1372 ErrPrint("Client %d is not exists\n", pid);
1373 ret = LB_STATUS_ERROR_NOT_EXIST;
1377 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1379 ErrPrint("Invalid parameter\n");
1380 ret = LB_STATUS_ERROR_INVALID;
1384 ret = validate_request(pkgname, id, &inst, &pkg);
1385 if (ret != LB_STATUS_SUCCESS) {
1389 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1390 ret = forward_pd_event_packet(pkg, inst, packet);
1391 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1392 struct script_info *script;
1394 script = instance_pd_script(inst);
1396 ret = LB_STATUS_ERROR_FAULT;
1400 script_handler_update_pointer(script, x, y, -1);
1401 script_handler_feed_event(script, LB_SCRIPT_MOUSE_IN, timestamp);
1404 ErrPrint("Unsupported package\n");
1405 ret = LB_STATUS_ERROR_INVALID;
1409 /*! \note No reply packet */
1413 static struct packet *client_pd_mouse_leave(pid_t pid, int handle, const struct packet *packet)
1415 struct client_node *client;
1416 const char *pkgname;
1422 struct inst_info *inst = NULL;
1423 const struct pkg_info *pkg = NULL;
1425 client = client_find_by_rpc_handle(handle);
1427 ErrPrint("Client %d is not exists\n", pid);
1428 ret = LB_STATUS_ERROR_NOT_EXIST;
1432 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1434 ErrPrint("Parameter is not matched\n");
1435 ret = LB_STATUS_ERROR_INVALID;
1439 ret = validate_request(pkgname, id, &inst, &pkg);
1440 if (ret != LB_STATUS_SUCCESS) {
1444 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1445 ret = forward_pd_event_packet(pkg, inst, packet);
1446 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1447 struct script_info *script;
1449 script = instance_pd_script(inst);
1451 ret = LB_STATUS_ERROR_FAULT;
1455 script_handler_update_pointer(script, x, y, -1);
1456 script_handler_feed_event(script, LB_SCRIPT_MOUSE_OUT, timestamp);
1459 ErrPrint("Unsupported package\n");
1460 ret = LB_STATUS_ERROR_INVALID;
1464 /*! \note No reply packet */
1468 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 */
1470 struct client_node *client;
1471 const char *pkgname;
1477 struct inst_info *inst = NULL;
1478 const struct pkg_info *pkg = NULL;
1480 client = client_find_by_rpc_handle(handle);
1482 ErrPrint("Client %d is not exists\n", pid);
1483 ret = LB_STATUS_ERROR_NOT_EXIST;
1487 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1489 ErrPrint("Parameter is not matched\n");
1490 ret = LB_STATUS_ERROR_INVALID;
1494 ret = validate_request(pkgname, id, &inst, &pkg);
1495 if (ret != LB_STATUS_SUCCESS) {
1499 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1500 ret = forward_pd_event_packet(pkg, inst, packet);
1501 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1502 struct script_info *script;
1504 script = instance_pd_script(inst);
1506 ret = LB_STATUS_ERROR_FAULT;
1510 script_handler_update_pointer(script, x, y, 1);
1511 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
1514 ErrPrint("Unsupported package\n");
1515 ret = LB_STATUS_ERROR_INVALID;
1519 /*! \note No reply packet */
1523 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 */
1525 struct client_node *client;
1526 const char *pkgname;
1532 struct inst_info *inst = NULL;
1533 const struct pkg_info *pkg = NULL;
1535 client = client_find_by_rpc_handle(handle);
1537 ErrPrint("Client %d is not exists\n", pid);
1538 ret = LB_STATUS_ERROR_NOT_EXIST;
1542 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1544 ErrPrint("Parameter is not matched\n");
1545 ret = LB_STATUS_ERROR_INVALID;
1549 ret = validate_request(pkgname, id, &inst, &pkg);
1550 if (ret != LB_STATUS_SUCCESS) {
1554 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1555 ret = forward_pd_event_packet(pkg, inst, packet);
1556 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1557 struct script_info *script;
1559 script = instance_pd_script(inst);
1561 ret = LB_STATUS_ERROR_FAULT;
1565 script_handler_update_pointer(script, x, y, 0);
1566 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
1569 ErrPrint("Unsupported package\n");
1570 ret = LB_STATUS_ERROR_INVALID;
1574 /*! \note No reply packet */
1578 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 */
1580 struct client_node *client;
1581 const char *pkgname;
1587 struct inst_info *inst = NULL;
1588 const struct pkg_info *pkg = NULL;
1590 client = client_find_by_rpc_handle(handle);
1592 ErrPrint("Client %d is not exists\n", pid);
1593 ret = LB_STATUS_ERROR_NOT_EXIST;
1597 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1599 ErrPrint("Parameter is not matched\n");
1600 ret = LB_STATUS_ERROR_INVALID;
1604 ret = validate_request(pkgname, id, &inst, &pkg);
1605 if (ret != LB_STATUS_SUCCESS) {
1609 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
1610 ret = forward_pd_event_packet(pkg, inst, packet);
1611 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
1612 struct script_info *script;
1614 script = instance_pd_script(inst);
1616 ret = LB_STATUS_ERROR_FAULT;
1620 script_handler_update_pointer(script, x, y, -1);
1621 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
1624 ErrPrint("Unsupported package\n");
1625 ret = LB_STATUS_ERROR_INVALID;
1629 /*! \note No reply packet */
1633 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 */
1635 struct client_node *client;
1636 const char *pkgname;
1642 struct inst_info *inst = NULL;
1643 const struct pkg_info *pkg = NULL;
1645 client = client_find_by_rpc_handle(handle);
1647 ErrPrint("Client %d is not exists\n", pid);
1648 ret = LB_STATUS_ERROR_NOT_EXIST;
1652 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1654 ErrPrint("Parameter is not matched\n");
1655 ret = LB_STATUS_ERROR_INVALID;
1659 ret = validate_request(pkgname, id, &inst, &pkg);
1660 if (ret != LB_STATUS_SUCCESS) {
1664 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1665 ret = forward_lb_event_packet(pkg, inst, packet);
1666 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1667 struct script_info *script;
1669 script = instance_lb_script(inst);
1671 ret = LB_STATUS_ERROR_FAULT;
1675 script_handler_update_pointer(script, x, y, -1);
1676 script_handler_feed_event(script, LB_SCRIPT_MOUSE_MOVE, timestamp);
1679 ErrPrint("Unsupported package\n");
1680 ret = LB_STATUS_ERROR_INVALID;
1684 /*! \note No reply packet */
1688 static int inst_del_cb(struct inst_info *inst, void *data)
1690 (void)event_deactivate(data, inst);
1691 return -1; /* Delete this callback */
1695 static struct packet *client_pd_key_set(pid_t pid, int handle, const struct packet *packet)
1697 struct client_node *client;
1698 const char *pkgname;
1702 unsigned int keycode;
1703 struct inst_info *inst;
1704 const struct pkg_info *pkg;
1705 struct packet *result;
1707 client = client_find_by_rpc_handle(handle);
1709 ErrPrint("Client %d is not exists\n", pid);
1710 ret = LB_STATUS_ERROR_NOT_EXIST;
1714 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
1716 ErrPrint("Parameter is not matched\n");
1717 ret = LB_STATUS_ERROR_INVALID;
1721 ret = validate_request(pkgname, id, &inst, &pkg);
1722 if (ret != LB_STATUS_SUCCESS) {
1726 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1727 ret = event_activate(0, 0, key_event_pd_route_cb, inst);
1729 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_pd_route_cb);
1731 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1732 ret = event_activate(0, 0, key_event_pd_consume_cb, inst);
1734 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_pd_consume_cb);
1737 ErrPrint("Unsupported package\n");
1738 ret = LB_STATUS_ERROR_INVALID;
1742 result = packet_create_reply(packet, "i", ret);
1744 ErrPrint("Failed to create a reply packet\n");
1750 static struct packet *client_pd_key_unset(pid_t pid, int handle, const struct packet *packet)
1752 struct client_node *client;
1753 const char *pkgname;
1757 unsigned int keycode;
1758 struct inst_info *inst;
1759 const struct pkg_info *pkg;
1760 struct packet *result;
1762 client = client_find_by_rpc_handle(handle);
1764 ErrPrint("Client %d is not exists\n", pid);
1765 ret = LB_STATUS_ERROR_NOT_EXIST;
1769 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
1771 ErrPrint("Parameter is not matched\n");
1772 ret = LB_STATUS_ERROR_INVALID;
1776 ret = validate_request(pkgname, id, &inst, &pkg);
1777 if (ret != LB_STATUS_SUCCESS) {
1781 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1782 ret = event_deactivate(key_event_pd_route_cb, inst);
1784 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_pd_route_cb);
1786 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1787 ret = event_deactivate(key_event_pd_consume_cb, inst);
1789 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_pd_consume_cb);
1792 ErrPrint("Unsupported package\n");
1793 ret = LB_STATUS_ERROR_INVALID;
1797 result = packet_create_reply(packet, "i", ret);
1799 ErrPrint("Failed to create a reply packet\n");
1805 static struct packet *client_lb_key_set(pid_t pid, int handle, const struct packet *packet)
1807 struct client_node *client;
1808 const char *pkgname;
1812 unsigned int keycode;
1813 struct inst_info *inst;
1814 const struct pkg_info *pkg;
1815 struct packet *result;
1817 client = client_find_by_rpc_handle(handle);
1819 ErrPrint("Client %d is not exists\n", pid);
1820 ret = LB_STATUS_ERROR_NOT_EXIST;
1824 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
1826 ErrPrint("Parameter is not matched\n");
1827 ret = LB_STATUS_ERROR_INVALID;
1831 ret = validate_request(pkgname, id, &inst, &pkg);
1832 if (ret != LB_STATUS_SUCCESS) {
1836 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1837 ret = event_activate(0, 0, key_event_lb_route_cb, inst);
1839 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_lb_route_cb);
1841 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1842 ret = event_activate(0, 0, key_event_lb_consume_cb, inst);
1844 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_lb_consume_cb);
1847 ErrPrint("Unsupported package\n");
1848 ret = LB_STATUS_ERROR_INVALID;
1852 result = packet_create_reply(packet, "i", ret);
1854 ErrPrint("Failed to create a reply packet\n");
1860 static struct packet *client_lb_key_unset(pid_t pid, int handle, const struct packet *packet)
1862 struct client_node *client;
1863 const char *pkgname;
1867 unsigned int keycode;
1868 struct inst_info *inst;
1869 const struct pkg_info *pkg;
1870 struct packet *result;
1872 client = client_find_by_rpc_handle(handle);
1874 ErrPrint("Client %d is not exists\n", pid);
1875 ret = LB_STATUS_ERROR_NOT_EXIST;
1879 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
1881 ErrPrint("Parameter is not matched\n");
1882 ret = LB_STATUS_ERROR_INVALID;
1886 ret = validate_request(pkgname, id, &inst, &pkg);
1887 if (ret != LB_STATUS_SUCCESS) {
1891 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1892 ret = event_deactivate(key_event_lb_route_cb, inst);
1894 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_lb_route_cb);
1896 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1897 ret = event_deactivate(key_event_lb_consume_cb, inst);
1899 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_lb_consume_cb);
1902 ErrPrint("Unsupported package\n");
1903 ret = LB_STATUS_ERROR_INVALID;
1907 result = packet_create_reply(packet, "i", ret);
1909 ErrPrint("Failed to create a reply packet\n");
1915 static struct packet *client_lb_mouse_set(pid_t pid, int handle, const struct packet *packet)
1917 struct client_node *client;
1918 const char *pkgname;
1924 struct inst_info *inst = NULL;
1925 const struct pkg_info *pkg = NULL;
1927 client = client_find_by_rpc_handle(handle);
1929 ErrPrint("Client %d is not exists\n", pid);
1930 ret = LB_STATUS_ERROR_NOT_EXIST;
1934 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1936 ErrPrint("Parameter is not matched\n");
1937 ret = LB_STATUS_ERROR_INVALID;
1941 ret = validate_request(pkgname, id, &inst, &pkg);
1942 if (ret != LB_STATUS_SUCCESS) {
1946 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1947 ret = event_activate(x, y, mouse_event_lb_route_cb, inst);
1949 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_lb_route_cb);
1951 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
1952 ret = event_activate(x, y, mouse_event_lb_consume_cb, inst);
1954 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_lb_consume_cb);
1957 ErrPrint("Unsupported package\n");
1958 ret = LB_STATUS_ERROR_INVALID;
1964 static struct packet *client_lb_mouse_unset(pid_t pid, int handle, const struct packet *packet)
1966 struct client_node *client;
1967 const char *pkgname;
1973 struct inst_info *inst = NULL;
1974 const struct pkg_info *pkg = NULL;
1976 client = client_find_by_rpc_handle(handle);
1978 ErrPrint("Client %d is not exists\n", pid);
1979 ret = LB_STATUS_ERROR_NOT_EXIST;
1983 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1985 ErrPrint("Parameter is not matched\n");
1986 ret = LB_STATUS_ERROR_INVALID;
1990 ret = validate_request(pkgname, id, &inst, &pkg);
1991 if (ret != LB_STATUS_SUCCESS) {
1995 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
1996 ret = event_deactivate(mouse_event_lb_route_cb, inst);
1998 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_lb_route_cb);
2000 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2001 ret = event_deactivate(mouse_event_lb_consume_cb, inst);
2003 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_lb_consume_cb);
2006 ErrPrint("Unsupported package\n");
2007 ret = LB_STATUS_ERROR_INVALID;
2013 static struct packet *client_pd_mouse_set(pid_t pid, int handle, const struct packet *packet)
2015 struct client_node *client;
2016 const char *pkgname;
2022 struct inst_info *inst = NULL;
2023 const struct pkg_info *pkg = NULL;
2025 client = client_find_by_rpc_handle(handle);
2027 ErrPrint("Client %d is not exists\n", pid);
2028 ret = LB_STATUS_ERROR_NOT_EXIST;
2032 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2034 ErrPrint("Parameter is not matched\n");
2035 ret = LB_STATUS_ERROR_INVALID;
2039 ret = validate_request(pkgname, id, &inst, &pkg);
2040 if (ret != LB_STATUS_SUCCESS) {
2044 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2045 ret = event_activate(x, y, mouse_event_pd_route_cb, inst);
2047 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_pd_route_cb);
2049 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2050 ret = event_activate(x, y, mouse_event_pd_consume_cb, inst);
2052 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_pd_consume_cb);
2055 ErrPrint("Unsupported package\n");
2056 ret = LB_STATUS_ERROR_INVALID;
2063 static struct packet *client_pd_mouse_unset(pid_t pid, int handle, const struct packet *packet)
2065 struct client_node *client;
2066 const char *pkgname;
2072 struct inst_info *inst = NULL;
2073 const struct pkg_info *pkg = NULL;
2075 client = client_find_by_rpc_handle(handle);
2077 ErrPrint("Client %d is not exists\n", pid);
2078 ret = LB_STATUS_ERROR_NOT_EXIST;
2082 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2084 ErrPrint("Parameter is not matched\n");
2085 ret = LB_STATUS_ERROR_INVALID;
2089 ret = validate_request(pkgname, id, &inst, &pkg);
2090 if (ret != LB_STATUS_SUCCESS) {
2094 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2095 ret = event_deactivate(mouse_event_pd_route_cb, inst);
2097 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_pd_route_cb);
2099 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2100 ret = event_deactivate(mouse_event_pd_consume_cb, inst);
2102 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_pd_consume_cb);
2105 ErrPrint("Unsupported package\n");
2106 ret = LB_STATUS_ERROR_INVALID;
2112 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 */
2114 struct client_node *client;
2115 const char *pkgname;
2121 struct inst_info *inst = NULL;
2122 const struct pkg_info *pkg = NULL;
2124 client = client_find_by_rpc_handle(handle);
2126 ErrPrint("Client %d is not exists\n", pid);
2127 ret = LB_STATUS_ERROR_NOT_EXIST;
2131 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2133 ErrPrint("Parameter is not matched\n");
2134 ret = LB_STATUS_ERROR_INVALID;
2138 ret = validate_request(pkgname, id, &inst, &pkg);
2139 if (ret != LB_STATUS_SUCCESS) {
2143 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2144 ret = forward_lb_event_packet(pkg, inst, packet);
2145 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2146 struct script_info *script;
2148 script = instance_lb_script(inst);
2150 ret = LB_STATUS_ERROR_FAULT;
2154 script_handler_update_pointer(script, x, y, -1);
2155 script_handler_feed_event(script, LB_SCRIPT_MOUSE_IN, timestamp);
2158 ErrPrint("Unsupported package\n");
2159 ret = LB_STATUS_ERROR_INVALID;
2163 /*! \note No reply packet */
2167 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 */
2169 struct client_node *client;
2170 const char *pkgname;
2176 struct inst_info *inst = NULL;
2177 const struct pkg_info *pkg = NULL;
2179 client = client_find_by_rpc_handle(handle);
2181 ErrPrint("Client %d is not exists\n", pid);
2182 ret = LB_STATUS_ERROR_NOT_EXIST;
2186 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2188 ErrPrint("Parameter is not matched\n");
2189 ret = LB_STATUS_ERROR_INVALID;
2193 ret = validate_request(pkgname, id, &inst, &pkg);
2194 if (ret != LB_STATUS_SUCCESS) {
2198 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2199 ret = forward_lb_event_packet(pkg, inst, packet);
2200 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2201 struct script_info *script;
2203 script = instance_lb_script(inst);
2205 ret = LB_STATUS_ERROR_FAULT;
2209 script_handler_update_pointer(script, x, y, -1);
2210 script_handler_feed_event(script, LB_SCRIPT_MOUSE_OUT, timestamp);
2213 ErrPrint("Unsupported package\n");
2214 ret = LB_STATUS_ERROR_INVALID;
2218 /*! \note No reply packet */
2222 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 */
2224 struct client_node *client;
2225 const char *pkgname;
2231 struct inst_info *inst = NULL;
2232 const struct pkg_info *pkg = NULL;
2234 client = client_find_by_rpc_handle(handle);
2236 ErrPrint("Client %d is not exists\n", pid);
2237 ret = LB_STATUS_ERROR_NOT_EXIST;
2241 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2243 ErrPrint("Parameter is not matched\n");
2244 ret = LB_STATUS_ERROR_INVALID;
2248 ret = validate_request(pkgname, id, &inst, &pkg);
2249 if (ret != LB_STATUS_SUCCESS) {
2253 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2254 ret = forward_lb_event_packet(pkg, inst, packet);
2255 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2256 struct script_info *script;
2258 script = instance_lb_script(inst);
2260 ret = LB_STATUS_ERROR_FAULT;
2264 script_handler_update_pointer(script, x, y, 1);
2265 script_handler_feed_event(script, LB_SCRIPT_MOUSE_DOWN, timestamp);
2268 ErrPrint("Unsupported package\n");
2269 ret = LB_STATUS_ERROR_INVALID;
2273 /*! \note No reply packet */
2277 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 */
2279 struct client_node *client;
2280 const char *pkgname;
2286 struct inst_info *inst = NULL;
2287 const struct pkg_info *pkg = NULL;
2289 client = client_find_by_rpc_handle(handle);
2291 ErrPrint("Client %d is not exists\n", pid);
2292 ret = LB_STATUS_ERROR_NOT_EXIST;
2296 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2298 ErrPrint("Parameter is not matched\n");
2299 ret = LB_STATUS_ERROR_INVALID;
2303 ret = validate_request(pkgname, id, &inst, &pkg);
2304 if (ret != LB_STATUS_SUCCESS) {
2308 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
2309 ret = forward_lb_event_packet(pkg, inst, packet);
2310 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
2311 struct script_info *script;
2313 script = instance_lb_script(inst);
2315 ret = LB_STATUS_ERROR_FAULT;
2319 script_handler_update_pointer(script, x, y, 0);
2320 script_handler_feed_event(script, LB_SCRIPT_MOUSE_UP, timestamp);
2323 ErrPrint("Unsupported package\n");
2324 ret = LB_STATUS_ERROR_INVALID;
2328 /*! \note No reply packet */
2332 static struct packet *client_pd_access_action_up(pid_t pid, int handle, const struct packet *packet)
2334 struct packet *result;
2335 struct client_node *client;
2336 const char *pkgname;
2342 struct inst_info *inst = NULL;
2343 const struct pkg_info *pkg = NULL;
2345 client = client_find_by_rpc_handle(handle);
2347 ErrPrint("Client %d is not exists\n", pid);
2348 ret = LB_STATUS_ERROR_NOT_EXIST;
2352 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2354 ErrPrint("Invalid parameter\n");
2355 ret = LB_STATUS_ERROR_INVALID;
2359 ret = validate_request(pkgname, id, &inst, &pkg);
2360 if (ret != LB_STATUS_SUCCESS) {
2364 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2365 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2366 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2367 struct script_info *script;
2369 script = instance_pd_script(inst);
2371 ret = LB_STATUS_ERROR_FAULT;
2375 script_handler_update_pointer(script, x, y, 0);
2376 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
2378 struct event_cbdata *cbdata;
2380 cbdata = malloc(sizeof(*cbdata));
2382 ret = LB_STATUS_ERROR_MEMORY;
2384 cbdata->inst = instance_ref(inst);
2385 cbdata->status = ret;
2387 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2388 (void)instance_unref(cbdata->inst);
2390 ret = LB_STATUS_ERROR_FAULT;
2392 ret = LB_STATUS_SUCCESS;
2397 ErrPrint("Unsupported package\n");
2398 ret = LB_STATUS_ERROR_INVALID;
2402 result = packet_create_reply(packet, "i", ret);
2404 ErrPrint("Failed to create a reply packet\n");
2410 static struct packet *client_pd_access_action_down(pid_t pid, int handle, const struct packet *packet)
2412 struct packet *result;
2413 struct client_node *client;
2414 const char *pkgname;
2420 struct inst_info *inst = NULL;
2421 const struct pkg_info *pkg = NULL;
2423 client = client_find_by_rpc_handle(handle);
2425 ErrPrint("Client %d is not exists\n", pid);
2426 ret = LB_STATUS_ERROR_NOT_EXIST;
2430 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2432 ErrPrint("Invalid parameter\n");
2433 ret = LB_STATUS_ERROR_INVALID;
2437 ret = validate_request(pkgname, id, &inst, &pkg);
2438 if (ret != LB_STATUS_SUCCESS) {
2442 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2443 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2444 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2445 struct script_info *script;
2447 script = instance_pd_script(inst);
2449 ret = LB_STATUS_ERROR_FAULT;
2453 script_handler_update_pointer(script, x, y, 1);
2454 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
2456 struct event_cbdata *cbdata;
2458 cbdata = malloc(sizeof(*cbdata));
2460 ret = LB_STATUS_ERROR_MEMORY;
2462 cbdata->inst = instance_ref(inst);
2463 cbdata->status = ret;
2465 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2466 (void)instance_unref(cbdata->inst);
2468 ret = LB_STATUS_ERROR_FAULT;
2470 ret = LB_STATUS_SUCCESS;
2475 ErrPrint("Unsupported package\n");
2476 ret = LB_STATUS_ERROR_INVALID;
2480 result = packet_create_reply(packet, "i", ret);
2482 ErrPrint("Failed to create a reply packet\n");
2488 static struct packet *client_pd_access_scroll_down(pid_t pid, int handle, const struct packet *packet)
2490 struct packet *result;
2491 struct client_node *client;
2492 const char *pkgname;
2498 struct inst_info *inst = NULL;
2499 const struct pkg_info *pkg = NULL;
2501 client = client_find_by_rpc_handle(handle);
2503 ErrPrint("Client %d is not exists\n", pid);
2504 ret = LB_STATUS_ERROR_NOT_EXIST;
2508 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2510 ErrPrint("Invalid parameter\n");
2511 ret = LB_STATUS_ERROR_INVALID;
2515 ret = validate_request(pkgname, id, &inst, &pkg);
2516 if (ret != LB_STATUS_SUCCESS) {
2520 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2521 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2522 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2523 struct script_info *script;
2525 script = instance_pd_script(inst);
2527 ret = LB_STATUS_ERROR_FAULT;
2531 script_handler_update_pointer(script, x, y, 1);
2532 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
2534 struct event_cbdata *cbdata;
2536 cbdata = malloc(sizeof(*cbdata));
2538 ret = LB_STATUS_ERROR_MEMORY;
2540 cbdata->inst = instance_ref(inst);
2541 cbdata->status = ret;
2543 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2544 (void)instance_unref(cbdata->inst);
2546 ret = LB_STATUS_ERROR_FAULT;
2548 ret = LB_STATUS_SUCCESS;
2553 ErrPrint("Unsupported package\n");
2554 ret = LB_STATUS_ERROR_INVALID;
2558 result = packet_create_reply(packet, "i", ret);
2560 ErrPrint("Failed to create a reply packet\n");
2566 static struct packet *client_pd_access_scroll_move(pid_t pid, int handle, const struct packet *packet)
2568 struct packet *result;
2569 struct client_node *client;
2570 const char *pkgname;
2576 struct inst_info *inst = NULL;
2577 const struct pkg_info *pkg = NULL;
2579 client = client_find_by_rpc_handle(handle);
2581 ErrPrint("Client %d is not exists\n", pid);
2582 ret = LB_STATUS_ERROR_NOT_EXIST;
2586 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2588 ErrPrint("Invalid parameter\n");
2589 ret = LB_STATUS_ERROR_INVALID;
2593 ret = validate_request(pkgname, id, &inst, &pkg);
2594 if (ret != LB_STATUS_SUCCESS) {
2598 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2599 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2600 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2601 struct script_info *script;
2603 script = instance_pd_script(inst);
2605 ret = LB_STATUS_ERROR_FAULT;
2609 script_handler_update_pointer(script, x, y, -1);
2610 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
2612 struct event_cbdata *cbdata;
2614 cbdata = malloc(sizeof(*cbdata));
2616 ret = LB_STATUS_ERROR_MEMORY;
2618 cbdata->inst = instance_ref(inst);
2619 cbdata->status = ret;
2621 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2622 (void)instance_unref(cbdata->inst);
2624 ret = LB_STATUS_ERROR_FAULT;
2626 ret = LB_STATUS_SUCCESS;
2631 ErrPrint("Unsupported package\n");
2632 ret = LB_STATUS_ERROR_INVALID;
2636 result = packet_create_reply(packet, "i", ret);
2638 ErrPrint("Failed to create a reply packet\n");
2644 static struct packet *client_pd_access_scroll_up(pid_t pid, int handle, const struct packet *packet)
2646 struct packet *result;
2647 struct client_node *client;
2648 const char *pkgname;
2654 struct inst_info *inst = NULL;
2655 const struct pkg_info *pkg = NULL;
2657 client = client_find_by_rpc_handle(handle);
2659 ErrPrint("Client %d is not exists\n", pid);
2660 ret = LB_STATUS_ERROR_NOT_EXIST;
2664 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2666 ErrPrint("Invalid parameter\n");
2667 ret = LB_STATUS_ERROR_INVALID;
2671 ret = validate_request(pkgname, id, &inst, &pkg);
2672 if (ret != LB_STATUS_SUCCESS) {
2676 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2677 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2678 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2679 struct script_info *script;
2681 script = instance_pd_script(inst);
2683 ret = LB_STATUS_ERROR_FAULT;
2687 script_handler_update_pointer(script, x, y, 0);
2688 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
2690 struct event_cbdata *cbdata;
2692 cbdata = malloc(sizeof(*cbdata));
2694 ret = LB_STATUS_ERROR_MEMORY;
2696 cbdata->inst = instance_ref(inst);
2697 cbdata->status = ret;
2699 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2700 (void)instance_unref(cbdata->inst);
2702 ret = LB_STATUS_ERROR_FAULT;
2704 ret = LB_STATUS_SUCCESS;
2709 ErrPrint("Unsupported package\n");
2710 ret = LB_STATUS_ERROR_INVALID;
2714 result = packet_create_reply(packet, "i", ret);
2716 ErrPrint("Failed to create a reply packet\n");
2722 static struct packet *client_pd_access_unhighlight(pid_t pid, int handle, const struct packet *packet)
2724 struct packet *result;
2725 struct client_node *client;
2726 const char *pkgname;
2730 struct inst_info *inst = NULL;
2731 const struct pkg_info *pkg = NULL;
2735 client = client_find_by_rpc_handle(handle);
2737 ErrPrint("Client %d is not exists\n", pid);
2738 ret = LB_STATUS_ERROR_NOT_EXIST;
2742 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2744 ErrPrint("Invalid parameter\n");
2745 ret = LB_STATUS_ERROR_INVALID;
2749 ret = validate_request(pkgname, id, &inst, &pkg);
2750 if (ret != LB_STATUS_SUCCESS) {
2754 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2755 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2756 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2757 struct script_info *script;
2759 script = instance_pd_script(inst);
2761 ret = LB_STATUS_ERROR_FAULT;
2765 script_handler_update_pointer(script, x, y, -1);
2766 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_UNHIGHLIGHT, timestamp);
2768 struct event_cbdata *cbdata;
2770 cbdata = malloc(sizeof(*cbdata));
2772 ret = LB_STATUS_ERROR_MEMORY;
2774 cbdata->inst = instance_ref(inst);
2775 cbdata->status = ret;
2777 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2778 (void)instance_unref(cbdata->inst);
2780 ret = LB_STATUS_ERROR_FAULT;
2782 ret = LB_STATUS_SUCCESS;
2787 ErrPrint("Unsupported package\n");
2788 ret = LB_STATUS_ERROR_INVALID;
2791 result = packet_create_reply(packet, "i", ret);
2793 ErrPrint("Failed to create a reply packet\n");
2799 static struct packet *client_pd_access_hl(pid_t pid, int handle, const struct packet *packet)
2801 struct packet *result;
2802 struct client_node *client;
2803 const char *pkgname;
2809 struct inst_info *inst = NULL;
2810 const struct pkg_info *pkg = NULL;
2812 client = client_find_by_rpc_handle(handle);
2814 ErrPrint("Client %d is not exists\n", pid);
2815 ret = LB_STATUS_ERROR_NOT_EXIST;
2819 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2821 ErrPrint("Invalid parameter\n");
2822 ret = LB_STATUS_ERROR_INVALID;
2826 ret = validate_request(pkgname, id, &inst, &pkg);
2827 if (ret != LB_STATUS_SUCCESS) {
2831 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2832 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2833 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2834 struct script_info *script;
2836 script = instance_pd_script(inst);
2838 ret = LB_STATUS_ERROR_FAULT;
2842 script_handler_update_pointer(script, x, y, -1);
2843 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT, timestamp);
2845 struct event_cbdata *cbdata;
2847 cbdata = malloc(sizeof(*cbdata));
2849 ret = LB_STATUS_ERROR_MEMORY;
2851 cbdata->inst = instance_ref(inst);
2852 cbdata->status = ret;
2854 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2855 (void)instance_unref(cbdata->inst);
2857 ret = LB_STATUS_ERROR_FAULT;
2859 ret = LB_STATUS_SUCCESS;
2864 ErrPrint("Unsupported package\n");
2865 ret = LB_STATUS_ERROR_INVALID;
2869 result = packet_create_reply(packet, "i", ret);
2871 ErrPrint("Failed to create a reply packet\n");
2877 static struct packet *client_pd_access_hl_prev(pid_t pid, int handle, const struct packet *packet)
2879 struct packet *result;
2880 struct client_node *client;
2881 const char *pkgname;
2887 struct inst_info *inst = NULL;
2888 const struct pkg_info *pkg = NULL;
2890 client = client_find_by_rpc_handle(handle);
2892 ErrPrint("Client %d is not exists\n", pid);
2893 ret = LB_STATUS_ERROR_NOT_EXIST;
2897 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2899 ErrPrint("Invalid parameter\n");
2900 ret = LB_STATUS_ERROR_INVALID;
2904 ret = validate_request(pkgname, id, &inst, &pkg);
2905 if (ret != LB_STATUS_SUCCESS) {
2909 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2910 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2911 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2912 struct script_info *script;
2914 script = instance_pd_script(inst);
2916 ret = LB_STATUS_ERROR_FAULT;
2920 script_handler_update_pointer(script, x, y, -1);
2921 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_PREV, timestamp);
2923 struct event_cbdata *cbdata;
2925 cbdata = malloc(sizeof(*cbdata));
2927 ret = LB_STATUS_ERROR_MEMORY;
2929 cbdata->inst = instance_ref(inst);
2930 cbdata->status = ret;
2932 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
2933 (void)instance_unref(cbdata->inst);
2935 ret = LB_STATUS_ERROR_FAULT;
2937 ret = LB_STATUS_SUCCESS;
2942 ErrPrint("Unsupported package\n");
2943 ret = LB_STATUS_ERROR_INVALID;
2947 result = packet_create_reply(packet, "i", ret);
2949 ErrPrint("Failed to create a reply packet\n");
2955 static struct packet *client_pd_access_hl_next(pid_t pid, int handle, const struct packet *packet)
2957 struct packet *result;
2958 struct client_node *client;
2959 const char *pkgname;
2965 struct inst_info *inst = NULL;
2966 const struct pkg_info *pkg = NULL;
2968 client = client_find_by_rpc_handle(handle);
2970 ErrPrint("Client %d is not exists\n", pid);
2971 ret = LB_STATUS_ERROR_NOT_EXIST;
2975 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2977 ErrPrint("Invalid parameter\n");
2978 ret = LB_STATUS_ERROR_INVALID;
2982 ret = validate_request(pkgname, id, &inst, &pkg);
2983 if (ret != LB_STATUS_SUCCESS) {
2987 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
2988 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
2989 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
2990 struct script_info *script;
2992 script = instance_pd_script(inst);
2994 ErrPrint("Script is not created yet\n");
2995 ret = LB_STATUS_ERROR_FAULT;
2999 script_handler_update_pointer(script, x, y, -1);
3000 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT, timestamp);
3002 struct event_cbdata *cbdata;
3004 cbdata = malloc(sizeof(*cbdata));
3006 ErrPrint("Heap: %s\n", strerror(errno));
3007 ret = LB_STATUS_ERROR_MEMORY;
3009 cbdata->inst = instance_ref(inst);
3010 cbdata->status = ret;
3012 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3013 ErrPrint("Failed to add timer\n");
3014 (void)instance_unref(cbdata->inst);
3016 ret = LB_STATUS_ERROR_FAULT;
3018 ret = LB_STATUS_SUCCESS;
3022 DbgPrint("Returns: %d\n", ret);
3025 ErrPrint("Unsupported package\n");
3026 ret = LB_STATUS_ERROR_INVALID;
3030 result = packet_create_reply(packet, "i", ret);
3032 ErrPrint("Failed to create a reply packet\n");
3038 static struct packet *client_pd_access_activate(pid_t pid, int handle, const struct packet *packet)
3040 struct packet *result;
3041 struct client_node *client;
3042 const char *pkgname;
3048 struct inst_info *inst = NULL;
3049 const struct pkg_info *pkg = NULL;
3051 client = client_find_by_rpc_handle(handle);
3053 ErrPrint("Client %d is not exists\n", pid);
3054 ret = LB_STATUS_ERROR_NOT_EXIST;
3058 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3060 ErrPrint("Invalid parameter\n");
3061 ret = LB_STATUS_ERROR_INVALID;
3065 ret = validate_request(pkgname, id, &inst, &pkg);
3066 if (ret != LB_STATUS_SUCCESS) {
3070 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3071 ret = forward_pd_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3072 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3073 struct script_info *script;
3075 script = instance_pd_script(inst);
3077 ret = LB_STATUS_ERROR_FAULT;
3081 script_handler_update_pointer(script, x, y, -1);
3082 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTIVATE, timestamp);
3084 struct event_cbdata *cbdata;
3086 cbdata = malloc(sizeof(*cbdata));
3088 ret = LB_STATUS_ERROR_MEMORY;
3090 cbdata->inst = instance_ref(inst);
3091 cbdata->status = ret;
3093 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3094 (void)instance_unref(cbdata->inst);
3096 ret = LB_STATUS_ERROR_FAULT;
3098 ret = LB_STATUS_SUCCESS;
3103 ErrPrint("Unsupported package\n");
3104 ret = LB_STATUS_ERROR_INVALID;
3108 result = packet_create_reply(packet, "i", ret);
3110 ErrPrint("Failed to create a reply packet\n");
3116 static struct packet *client_pd_key_focus_in(pid_t pid, int handle, const struct packet *packet)
3118 struct client_node *client;
3119 const char *pkgname;
3123 unsigned int keycode;
3124 struct inst_info *inst;
3125 const struct pkg_info *pkg;
3126 struct packet *result;
3128 client = client_find_by_rpc_handle(handle);
3130 ErrPrint("Client %d is not exists\n", pid);
3131 ret = LB_STATUS_ERROR_NOT_EXIST;
3135 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3137 ErrPrint("Invalid parameter\n");
3138 ret = LB_STATUS_ERROR_INVALID;
3142 ret = validate_request(pkgname, id, &inst, &pkg);
3143 if (ret != LB_STATUS_SUCCESS) {
3147 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3148 ret = forward_pd_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3149 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3150 struct script_info *script;
3152 script = instance_pd_script(inst);
3154 ret = LB_STATUS_ERROR_FAULT;
3158 script_handler_update_keycode(script, keycode);
3159 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_FOCUS_IN, timestamp);
3161 struct event_cbdata *cbdata;
3163 cbdata = malloc(sizeof(*cbdata));
3165 ret = LB_STATUS_ERROR_MEMORY;
3167 cbdata->inst = instance_ref(inst);
3168 cbdata->status = ret;
3170 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
3171 (void)instance_unref(cbdata->inst);
3173 ret = LB_STATUS_ERROR_FAULT;
3175 ret = LB_STATUS_SUCCESS;
3180 ErrPrint("Unsupported package\n");
3181 ret = LB_STATUS_ERROR_INVALID;
3185 result = packet_create_reply(packet, "i", ret);
3187 ErrPrint("Failed to create a reply packet\n");
3193 static struct packet *client_pd_key_focus_out(pid_t pid, int handle, const struct packet *packet)
3195 struct client_node *client;
3196 const char *pkgname;
3200 unsigned int keycode;
3201 struct inst_info *inst = NULL;
3202 const struct pkg_info *pkg = NULL;
3203 struct packet *result;
3205 client = client_find_by_rpc_handle(handle);
3207 ErrPrint("Client %d is not exists\n", pid);
3208 ret = LB_STATUS_ERROR_NOT_EXIST;
3212 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3214 ErrPrint("Invalid parameter\n");
3215 ret = LB_STATUS_ERROR_INVALID;
3219 ret = validate_request(pkgname, id, &inst, &pkg);
3220 if (ret != LB_STATUS_SUCCESS) {
3224 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3225 ret = forward_pd_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3226 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3227 struct script_info *script;
3229 script = instance_pd_script(inst);
3231 ret = LB_STATUS_ERROR_FAULT;
3235 script_handler_update_keycode(script, keycode);
3236 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_FOCUS_OUT, timestamp);
3238 struct event_cbdata *cbdata;
3240 cbdata = malloc(sizeof(*cbdata));
3242 ret = LB_STATUS_ERROR_MEMORY;
3244 cbdata->inst = instance_ref(inst);
3245 cbdata->status = ret;
3247 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
3248 (void)instance_unref(cbdata->inst);
3250 ret = LB_STATUS_ERROR_FAULT;
3252 ret = LB_STATUS_SUCCESS;
3257 ErrPrint("Unsupported package\n");
3258 ret = LB_STATUS_ERROR_INVALID;
3262 result = packet_create_reply(packet, "i", ret);
3264 ErrPrint("Failed to create a reply packet\n");
3270 static struct packet *client_pd_key_down(pid_t pid, int handle, const struct packet *packet)
3272 struct client_node *client;
3273 const char *pkgname;
3277 unsigned int keycode;
3278 struct inst_info *inst;
3279 const struct pkg_info *pkg;
3280 struct packet *result;
3282 client = client_find_by_rpc_handle(handle);
3284 ErrPrint("Client %d is not exists\n", pid);
3285 ret = LB_STATUS_ERROR_NOT_EXIST;
3289 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3291 ErrPrint("Invalid parameter\n");
3292 ret = LB_STATUS_ERROR_INVALID;
3296 ret = validate_request(pkgname, id, &inst, &pkg);
3297 if (ret != LB_STATUS_SUCCESS) {
3301 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3302 ret = forward_pd_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3303 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3304 struct script_info *script;
3306 script = instance_pd_script(inst);
3308 ret = LB_STATUS_ERROR_FAULT;
3312 script_handler_update_keycode(script, keycode);
3313 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_DOWN, timestamp);
3315 struct event_cbdata *cbdata;
3317 cbdata = malloc(sizeof(*cbdata));
3319 ret = LB_STATUS_ERROR_MEMORY;
3321 cbdata->inst = instance_ref(inst);
3322 cbdata->status = ret;
3324 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
3325 (void)instance_unref(cbdata->inst);
3327 ret = LB_STATUS_ERROR_FAULT;
3329 ret = LB_STATUS_SUCCESS;
3334 ErrPrint("Unsupported package\n");
3335 ret = LB_STATUS_ERROR_INVALID;
3339 result = packet_create_reply(packet, "i", ret);
3341 ErrPrint("Failed to create a reply packet\n");
3347 static struct packet *client_pause_request(pid_t pid, int handle, const struct packet *packet)
3349 struct client_node *client;
3353 client = client_find_by_rpc_handle(handle);
3355 ErrPrint("Client %d is paused - manually reported\n", pid);
3356 ret = LB_STATUS_ERROR_NOT_EXIST;
3360 ret = packet_get(packet, "d", ×tamp);
3362 ErrPrint("Invalid parameter\n");
3363 ret = LB_STATUS_ERROR_INVALID;
3368 DbgPrint("XMONITOR enabled. ignore client paused request\n");
3370 xmonitor_pause(client);
3377 static struct packet *client_resume_request(pid_t pid, int handle, const struct packet *packet)
3379 struct client_node *client;
3383 client = client_find_by_rpc_handle(handle);
3385 ErrPrint("Client %d is not exists\n", pid);
3389 ret = packet_get(packet, "d", ×tamp);
3391 ErrPrint("Invalid parameter\n");
3396 DbgPrint("XMONITOR enabled. ignore client resumed request\n");
3398 xmonitor_resume(client);
3405 static struct packet *client_pd_key_up(pid_t pid, int handle, const struct packet *packet)
3407 struct client_node *client;
3408 const char *pkgname;
3412 unsigned int keycode;
3413 struct inst_info *inst = NULL;
3414 const struct pkg_info *pkg = NULL;
3415 struct packet *result;
3417 client = client_find_by_rpc_handle(handle);
3419 ErrPrint("Client %d is not exists\n", pid);
3420 ret = LB_STATUS_ERROR_NOT_EXIST;
3424 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3426 ErrPrint("Invalid parameter\n");
3427 ret = LB_STATUS_ERROR_INVALID;
3431 ret = validate_request(pkgname, id, &inst, &pkg);
3432 if (ret != LB_STATUS_SUCCESS) {
3436 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
3437 ret = forward_pd_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3438 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
3439 struct script_info *script;
3441 script = instance_pd_script(inst);
3443 ret = LB_STATUS_ERROR_FAULT;
3447 script_handler_update_keycode(script, keycode);
3448 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_UP, timestamp);
3450 struct event_cbdata *cbdata;
3452 cbdata = malloc(sizeof(*cbdata));
3454 ret = LB_STATUS_ERROR_MEMORY;
3456 cbdata->inst = instance_ref(inst);
3457 cbdata->status = ret;
3459 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
3460 (void)instance_unref(cbdata->inst);
3462 ret = LB_STATUS_ERROR_FAULT;
3464 ret = LB_STATUS_SUCCESS;
3469 ErrPrint("Unsupported package\n");
3470 ret = LB_STATUS_ERROR_INVALID;
3474 result = packet_create_reply(packet, "i", ret);
3476 ErrPrint("Failed to create a reply packet\n");
3482 static struct packet *client_lb_access_hl(pid_t pid, int handle, const struct packet *packet)
3484 struct packet *result;
3485 struct client_node *client;
3486 const char *pkgname;
3492 struct inst_info *inst = NULL;
3493 const struct pkg_info *pkg = NULL;
3495 client = client_find_by_rpc_handle(handle);
3497 ErrPrint("Client %d is not exists\n", pid);
3498 ret = LB_STATUS_ERROR_NOT_EXIST;
3502 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3504 ErrPrint("Parameter is not matched\n");
3505 ret = LB_STATUS_ERROR_INVALID;
3509 ret = validate_request(pkgname, id, &inst, &pkg);
3510 if (ret != LB_STATUS_SUCCESS) {
3514 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3515 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3516 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3517 struct script_info *script;
3519 script = instance_lb_script(inst);
3521 ret = LB_STATUS_ERROR_FAULT;
3525 script_handler_update_pointer(script, x, y, -1);
3526 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT, timestamp);
3528 struct event_cbdata *cbdata;
3530 cbdata = malloc(sizeof(*cbdata));
3532 ret = LB_STATUS_ERROR_MEMORY;
3534 cbdata->inst = instance_ref(inst);
3535 cbdata->status = ret;
3537 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3538 (void)instance_unref(cbdata->inst);
3540 ret = LB_STATUS_ERROR_FAULT;
3542 ret = LB_STATUS_SUCCESS;
3547 ErrPrint("Unsupported package\n");
3548 ret = LB_STATUS_ERROR_INVALID;
3552 result = packet_create_reply(packet, "i", ret);
3554 ErrPrint("Failed to create a reply packet\n");
3560 static struct packet *client_lb_access_hl_prev(pid_t pid, int handle, const struct packet *packet)
3562 struct packet *result;
3563 struct client_node *client;
3564 const char *pkgname;
3570 struct inst_info *inst = NULL;
3571 const struct pkg_info *pkg = NULL;
3573 client = client_find_by_rpc_handle(handle);
3575 ErrPrint("Client %d is not exists\n", pid);
3576 ret = LB_STATUS_ERROR_NOT_EXIST;
3580 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3582 ErrPrint("Parameter is not matched\n");
3583 ret = LB_STATUS_ERROR_INVALID;
3587 ret = validate_request(pkgname, id, &inst, &pkg);
3588 if (ret != LB_STATUS_SUCCESS) {
3592 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3593 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3594 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3595 struct script_info *script;
3597 script = instance_lb_script(inst);
3599 ret = LB_STATUS_ERROR_FAULT;
3603 script_handler_update_pointer(script, x, y, -1);
3604 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_PREV, timestamp);
3606 struct event_cbdata *cbdata;
3608 cbdata = malloc(sizeof(*cbdata));
3610 ret = LB_STATUS_ERROR_MEMORY;
3612 cbdata->inst = instance_ref(inst);
3613 cbdata->status = ret;
3615 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3616 (void)instance_unref(cbdata->inst);
3618 ret = LB_STATUS_ERROR_FAULT;
3620 ret = LB_STATUS_SUCCESS;
3625 ErrPrint("Unsupported package\n");
3626 ret = LB_STATUS_ERROR_INVALID;
3630 result = packet_create_reply(packet, "i", ret);
3632 ErrPrint("Failed to create a reply packet\n");
3638 static struct packet *client_lb_access_hl_next(pid_t pid, int handle, const struct packet *packet)
3640 struct packet *result;
3641 struct client_node *client;
3642 const char *pkgname;
3648 struct inst_info *inst = NULL;
3649 const struct pkg_info *pkg = NULL;
3651 client = client_find_by_rpc_handle(handle);
3653 ErrPrint("Client %d is not exists\n", pid);
3654 ret = LB_STATUS_ERROR_NOT_EXIST;
3658 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3660 ErrPrint("Parameter is not matched\n");
3661 ret = LB_STATUS_ERROR_INVALID;
3665 ret = validate_request(pkgname, id, &inst, &pkg);
3666 if (ret != LB_STATUS_SUCCESS) {
3670 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3671 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3672 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3673 struct script_info *script;
3675 script = instance_lb_script(inst);
3677 ret = LB_STATUS_ERROR_FAULT;
3681 script_handler_update_pointer(script, x, y, -1);
3682 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_HIGHLIGHT_NEXT, timestamp);
3684 struct event_cbdata *cbdata;
3686 cbdata = malloc(sizeof(*cbdata));
3688 ret = LB_STATUS_ERROR_MEMORY;
3690 cbdata->inst = instance_ref(inst);
3691 cbdata->status = ret;
3693 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3694 (void)instance_unref(cbdata->inst);
3696 ret = LB_STATUS_ERROR_FAULT;
3698 ret = LB_STATUS_SUCCESS;
3703 ErrPrint("Unsupported package\n");
3704 ret = LB_STATUS_ERROR_INVALID;
3708 result = packet_create_reply(packet, "i", ret);
3710 ErrPrint("Failed to create a reply packet\n");
3716 static struct packet *client_lb_access_action_up(pid_t pid, int handle, const struct packet *packet)
3718 struct packet *result;
3719 struct client_node *client;
3720 const char *pkgname;
3724 struct inst_info *inst = NULL;
3725 const struct pkg_info *pkg = NULL;
3729 client = client_find_by_rpc_handle(handle);
3731 ErrPrint("Client %d is not exist\n", pid);
3732 ret = LB_STATUS_ERROR_NOT_EXIST;
3736 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3738 ErrPrint("Parameter is not matched\n");
3739 ret = LB_STATUS_ERROR_INVALID;
3743 ret = validate_request(pkgname, id, &inst, &pkg);
3744 if (ret != LB_STATUS_SUCCESS) {
3748 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3749 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3751 * Enen if it fails to send packet,
3752 * The packet will be unref'd
3753 * So we don't need to check the ret value.
3755 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3756 struct script_info *script;
3758 script = instance_lb_script(inst);
3760 ErrPrint("Instance has no script\n");
3761 ret = LB_STATUS_ERROR_FAULT;
3765 script_handler_update_pointer(script, x, y, 0);
3766 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
3768 struct event_cbdata *cbdata;
3770 cbdata = malloc(sizeof(*cbdata));
3772 ret = LB_STATUS_ERROR_MEMORY;
3774 cbdata->inst = instance_ref(inst);
3775 cbdata->status = ret;
3777 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3778 (void)instance_unref(cbdata->inst);
3780 ret = LB_STATUS_ERROR_FAULT;
3782 ret = LB_STATUS_SUCCESS;
3787 ErrPrint("Unsupported package\n");
3788 ret = LB_STATUS_ERROR_INVALID;
3792 result = packet_create_reply(packet, "i", ret);
3794 ErrPrint("Failed to create a reply packet\n");
3800 static struct packet *client_lb_access_action_down(pid_t pid, int handle, const struct packet *packet)
3802 struct packet *result;
3803 struct client_node *client;
3804 const char *pkgname;
3808 struct inst_info *inst = NULL;
3809 const struct pkg_info *pkg = NULL;
3813 client = client_find_by_rpc_handle(handle);
3815 ErrPrint("Client %d is not exist\n", pid);
3816 ret = LB_STATUS_ERROR_NOT_EXIST;
3820 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3822 ErrPrint("Parameter is not matched\n");
3823 ret = LB_STATUS_ERROR_INVALID;
3827 ret = validate_request(pkgname, id, &inst, &pkg);
3828 if (ret != LB_STATUS_SUCCESS) {
3832 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3833 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3835 * Enen if it fails to send packet,
3836 * The packet will be unref'd
3837 * So we don't need to check the ret value.
3839 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3840 struct script_info *script;
3842 script = instance_lb_script(inst);
3844 ErrPrint("Instance has no script\n");
3845 ret = LB_STATUS_ERROR_FAULT;
3849 script_handler_update_pointer(script, x, y, 1);
3850 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTION, timestamp);
3852 struct event_cbdata *cbdata;
3854 cbdata = malloc(sizeof(*cbdata));
3856 ret = LB_STATUS_ERROR_MEMORY;
3858 cbdata->inst = instance_ref(inst);
3859 cbdata->status = ret;
3861 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3862 (void)instance_unref(cbdata->inst);
3864 ret = LB_STATUS_ERROR_FAULT;
3866 ret = LB_STATUS_SUCCESS;
3871 ErrPrint("Unsupported package\n");
3872 ret = LB_STATUS_ERROR_INVALID;
3876 result = packet_create_reply(packet, "i", ret);
3878 ErrPrint("Failed to create a reply packet\n");
3884 static struct packet *client_lb_access_unhighlight(pid_t pid, int handle, const struct packet *packet)
3886 struct packet *result;
3887 struct client_node *client;
3888 const char *pkgname;
3894 struct inst_info *inst = NULL;
3895 const struct pkg_info *pkg = NULL;
3897 client = client_find_by_rpc_handle(handle);
3899 ErrPrint("Client %d is not exists\n", pid);
3900 ret = LB_STATUS_ERROR_NOT_EXIST;
3904 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3906 ErrPrint("Parameter is not matched\n");
3907 ret = LB_STATUS_ERROR_INVALID;
3911 ret = validate_request(pkgname, id, &inst, &pkg);
3912 if (ret != LB_STATUS_SUCCESS) {
3916 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3917 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3918 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
3919 struct script_info *script;
3921 script = instance_lb_script(inst);
3923 ret = LB_STATUS_ERROR_FAULT;
3927 script_handler_update_pointer(script, x, y, -1);
3928 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_UNHIGHLIGHT, timestamp);
3930 struct event_cbdata *cbdata;
3932 cbdata = malloc(sizeof(*cbdata));
3934 ret = LB_STATUS_ERROR_MEMORY;
3936 cbdata->inst = instance_ref(inst);
3937 cbdata->status = ret;
3939 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
3940 (void)instance_unref(cbdata->inst);
3942 ret = LB_STATUS_ERROR_FAULT;
3944 ret = LB_STATUS_SUCCESS;
3949 ErrPrint("Unsupported package\n");
3950 ret = LB_STATUS_ERROR_INVALID;
3954 result = packet_create_reply(packet, "i", ret);
3956 ErrPrint("Failed to create a reply packet\n");
3962 static struct packet *client_lb_access_scroll_down(pid_t pid, int handle, const struct packet *packet)
3964 struct packet *result;
3965 struct client_node *client;
3966 const char *pkgname;
3970 struct inst_info *inst = NULL;
3971 const struct pkg_info *pkg = NULL;
3975 client = client_find_by_rpc_handle(handle);
3977 ErrPrint("Client %d is not exist\n", pid);
3978 ret = LB_STATUS_ERROR_NOT_EXIST;
3982 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
3984 ErrPrint("Parameter is not matched\n");
3985 ret = LB_STATUS_ERROR_INVALID;
3989 ret = validate_request(pkgname, id, &inst, &pkg);
3990 if (ret != LB_STATUS_SUCCESS) {
3994 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
3995 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
3997 * Enen if it fails to send packet,
3998 * The packet will be unref'd
3999 * So we don't need to check the ret value.
4001 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4002 struct script_info *script;
4004 script = instance_lb_script(inst);
4006 ErrPrint("Instance has no script\n");
4007 ret = LB_STATUS_ERROR_FAULT;
4011 script_handler_update_pointer(script, x, y, 1);
4012 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
4014 struct event_cbdata *cbdata;
4016 cbdata = malloc(sizeof(*cbdata));
4018 ret = LB_STATUS_ERROR_MEMORY;
4020 cbdata->inst = instance_ref(inst);
4021 cbdata->status = ret;
4023 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
4024 (void)instance_unref(cbdata->inst);
4026 ret = LB_STATUS_ERROR_FAULT;
4028 ret = LB_STATUS_SUCCESS;
4033 ErrPrint("Unsupported package\n");
4034 ret = LB_STATUS_ERROR_INVALID;
4038 result = packet_create_reply(packet, "i", ret);
4040 ErrPrint("Failed to create a reply packet\n");
4046 static struct packet *client_lb_access_scroll_move(pid_t pid, int handle, const struct packet *packet)
4048 struct packet *result;
4049 struct client_node *client;
4050 const char *pkgname;
4054 struct inst_info *inst = NULL;
4055 const struct pkg_info *pkg = NULL;
4059 client = client_find_by_rpc_handle(handle);
4061 ErrPrint("Client %d is not exist\n", pid);
4062 ret = LB_STATUS_ERROR_NOT_EXIST;
4066 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
4068 ErrPrint("Parameter is not matched\n");
4069 ret = LB_STATUS_ERROR_INVALID;
4073 ret = validate_request(pkgname, id, &inst, &pkg);
4074 if (ret != LB_STATUS_SUCCESS) {
4078 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4079 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
4081 * Enen if it fails to send packet,
4082 * The packet will be unref'd
4083 * So we don't need to check the ret value.
4085 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4086 struct script_info *script;
4088 script = instance_lb_script(inst);
4090 ErrPrint("Instance has no script\n");
4091 ret = LB_STATUS_ERROR_FAULT;
4095 script_handler_update_pointer(script, x, y, -1);
4096 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
4098 struct event_cbdata *cbdata;
4100 cbdata = malloc(sizeof(*cbdata));
4102 ret = LB_STATUS_ERROR_MEMORY;
4104 cbdata->inst = instance_ref(inst);
4105 cbdata->status = ret;
4107 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
4108 (void)instance_unref(cbdata->inst);
4110 ret = LB_STATUS_ERROR_FAULT;
4112 ret = LB_STATUS_SUCCESS;
4117 ErrPrint("Unsupported package\n");
4118 ret = LB_STATUS_ERROR_INVALID;
4122 result = packet_create_reply(packet, "i", ret);
4124 ErrPrint("Failed to create a reply packet\n");
4130 static struct packet *client_lb_access_scroll_up(pid_t pid, int handle, const struct packet *packet)
4132 struct packet *result;
4133 struct client_node *client;
4134 const char *pkgname;
4138 struct inst_info *inst = NULL;
4139 const struct pkg_info *pkg = NULL;
4143 client = client_find_by_rpc_handle(handle);
4145 ErrPrint("Client %d is not exist\n", pid);
4146 ret = LB_STATUS_ERROR_NOT_EXIST;
4150 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
4152 ErrPrint("Parameter is not matched\n");
4153 ret = LB_STATUS_ERROR_INVALID;
4157 ret = validate_request(pkgname, id, &inst, &pkg);
4158 if (ret != LB_STATUS_SUCCESS) {
4162 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4163 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
4165 * Enen if it fails to send packet,
4166 * The packet will be unref'd
4167 * So we don't need to check the ret value.
4169 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4170 struct script_info *script;
4172 script = instance_lb_script(inst);
4174 ErrPrint("Instance has no script\n");
4175 ret = LB_STATUS_ERROR_FAULT;
4179 script_handler_update_pointer(script, x, y, 0);
4180 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_SCROLL, timestamp);
4182 struct event_cbdata *cbdata;
4184 cbdata = malloc(sizeof(*cbdata));
4186 ret = LB_STATUS_ERROR_MEMORY;
4188 cbdata->inst = instance_ref(inst);
4189 cbdata->status = ret;
4191 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
4192 (void)instance_unref(cbdata->inst);
4194 ret = LB_STATUS_ERROR_FAULT;
4196 ret = LB_STATUS_SUCCESS;
4201 ErrPrint("Unsupported package\n");
4202 ret = LB_STATUS_ERROR_INVALID;
4206 result = packet_create_reply(packet, "i", ret);
4208 ErrPrint("Failed to create a reply packet\n");
4214 static struct packet *client_lb_access_activate(pid_t pid, int handle, const struct packet *packet)
4216 struct packet *result;
4217 struct client_node *client;
4218 const char *pkgname;
4224 struct inst_info *inst = NULL;
4225 const struct pkg_info *pkg = NULL;
4227 client = client_find_by_rpc_handle(handle);
4229 ErrPrint("Client %d is not exists\n", pid);
4230 ret = LB_STATUS_ERROR_NOT_EXIST;
4234 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
4236 ErrPrint("Parameter is not matched\n");
4237 ret = LB_STATUS_ERROR_INVALID;
4241 ret = validate_request(pkgname, id, &inst, &pkg);
4242 if (ret != LB_STATUS_SUCCESS) {
4246 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4247 ret = forward_lb_access_packet(pkg, inst, packet_command(packet), timestamp, x, y);
4248 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4249 struct script_info *script;
4251 script = instance_lb_script(inst);
4253 ErrPrint("Instance has no script\n");
4254 ret = LB_STATUS_ERROR_FAULT;
4258 script_handler_update_pointer(script, x, y, -1);
4259 ret = script_handler_feed_event(script, LB_SCRIPT_ACCESS_ACTIVATE, timestamp);
4261 struct event_cbdata *cbdata;
4263 cbdata = malloc(sizeof(*cbdata));
4265 ret = LB_STATUS_ERROR_MEMORY;
4267 cbdata->inst = instance_ref(inst);
4268 cbdata->status = ret;
4270 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
4271 (void)instance_unref(cbdata->inst);
4273 ret = LB_STATUS_ERROR_FAULT;
4275 ret = LB_STATUS_SUCCESS;
4280 ErrPrint("Unsupported package\n");
4281 ret = LB_STATUS_ERROR_INVALID;
4285 result = packet_create_reply(packet, "i", ret);
4287 ErrPrint("Failed to create a reply packet\n");
4293 static struct packet *client_lb_key_down(pid_t pid, int handle, const struct packet *packet)
4295 struct client_node *client;
4296 const char *pkgname;
4300 unsigned int keycode;
4301 struct inst_info *inst;
4302 const struct pkg_info *pkg;
4303 struct packet *result;
4305 client = client_find_by_rpc_handle(handle);
4307 ErrPrint("Client %d is not exists\n", pid);
4308 ret = LB_STATUS_ERROR_NOT_EXIST;
4312 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4314 ErrPrint("Parameter is not matched\n");
4315 ret = LB_STATUS_ERROR_INVALID;
4319 ret = validate_request(pkgname, id, &inst, &pkg);
4320 if (ret != LB_STATUS_SUCCESS) {
4324 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4325 ret = forward_lb_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4326 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4327 struct script_info *script;
4329 script = instance_lb_script(inst);
4331 ret = LB_STATUS_ERROR_FAULT;
4335 script_handler_update_keycode(script, keycode);
4336 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_DOWN, timestamp);
4338 struct event_cbdata *cbdata;
4340 cbdata = malloc(sizeof(*cbdata));
4342 ret = LB_STATUS_ERROR_MEMORY;
4344 cbdata->inst = instance_ref(inst);
4345 cbdata->status = ret;
4347 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
4348 (void)instance_unref(cbdata->inst);
4350 ret = LB_STATUS_ERROR_FAULT;
4352 ret = LB_STATUS_SUCCESS;
4357 ErrPrint("Unsupported package\n");
4358 ret = LB_STATUS_ERROR_INVALID;
4362 result = packet_create_reply(packet, "i", ret);
4364 ErrPrint("Failed to create a reply packet\n");
4370 static struct packet *client_lb_key_focus_in(pid_t pid, int handle, const struct packet *packet)
4372 struct client_node *client;
4373 const char *pkgname;
4377 unsigned int keycode;
4378 struct inst_info *inst = NULL;
4379 const struct pkg_info *pkg = NULL;
4380 struct packet *result;
4382 client = client_find_by_rpc_handle(handle);
4384 ErrPrint("Client %d is not exists\n", pid);
4385 ret = LB_STATUS_ERROR_NOT_EXIST;
4389 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4391 ErrPrint("Parameter is not matched\n");
4392 ret = LB_STATUS_ERROR_INVALID;
4396 ret = validate_request(pkgname, id, &inst, &pkg);
4397 if (ret != LB_STATUS_SUCCESS) {
4401 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4402 ret = forward_lb_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4403 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4404 struct script_info *script;
4406 script = instance_lb_script(inst);
4408 ret = LB_STATUS_ERROR_FAULT;
4412 script_handler_update_keycode(script, keycode);
4413 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_FOCUS_IN, timestamp);
4415 struct event_cbdata *cbdata;
4417 cbdata = malloc(sizeof(*cbdata));
4419 ret = LB_STATUS_ERROR_MEMORY;
4421 cbdata->inst = instance_ref(inst);
4422 cbdata->status = ret;
4424 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
4425 (void)instance_unref(cbdata->inst);
4427 ret = LB_STATUS_ERROR_FAULT;
4429 ret = LB_STATUS_SUCCESS;
4434 ErrPrint("Unsupported package\n");
4435 ret = LB_STATUS_ERROR_INVALID;
4439 result = packet_create_reply(packet, "i", ret);
4441 ErrPrint("Failed to create a reply packet\n");
4447 static struct packet *client_lb_key_focus_out(pid_t pid, int handle, const struct packet *packet)
4449 struct client_node *client;
4450 const char *pkgname;
4454 unsigned int keycode;
4455 struct inst_info *inst = NULL;
4456 const struct pkg_info *pkg = NULL;
4457 struct packet *result;
4459 client = client_find_by_rpc_handle(handle);
4461 ErrPrint("Client %d is not exists\n", pid);
4462 ret = LB_STATUS_ERROR_NOT_EXIST;
4466 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4468 ErrPrint("Parameter is not matched\n");
4469 ret = LB_STATUS_ERROR_INVALID;
4473 ret = validate_request(pkgname, id, &inst, &pkg);
4474 if (ret != LB_STATUS_SUCCESS) {
4478 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4479 ret = forward_lb_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4480 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4481 struct script_info *script;
4483 script = instance_lb_script(inst);
4485 ret = LB_STATUS_ERROR_FAULT;
4489 script_handler_update_keycode(script, keycode);
4490 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_FOCUS_OUT, timestamp);
4492 struct event_cbdata *cbdata;
4494 cbdata = malloc(sizeof(*cbdata));
4496 ret = LB_STATUS_ERROR_MEMORY;
4498 cbdata->inst = instance_ref(inst);
4499 cbdata->status = ret;
4501 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
4502 (void)instance_unref(cbdata->inst);
4504 ret = LB_STATUS_ERROR_FAULT;
4506 ret = LB_STATUS_SUCCESS;
4511 ErrPrint("Unsupported package\n");
4512 ret = LB_STATUS_ERROR_INVALID;
4516 result = packet_create_reply(packet, "i", ret);
4518 ErrPrint("Failed to create a reply packet\n");
4524 static struct packet *client_lb_key_up(pid_t pid, int handle, const struct packet *packet)
4526 struct client_node *client;
4527 const char *pkgname;
4531 unsigned int keycode;
4532 struct inst_info *inst = NULL;
4533 const struct pkg_info *pkg = NULL;
4534 struct packet *result;
4536 client = client_find_by_rpc_handle(handle);
4538 ErrPrint("Client %d is not exists\n", pid);
4539 ret = LB_STATUS_ERROR_NOT_EXIST;
4543 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4545 ErrPrint("Parameter is not matched\n");
4546 ret = LB_STATUS_ERROR_INVALID;
4550 ret = validate_request(pkgname, id, &inst, &pkg);
4551 if (ret != LB_STATUS_SUCCESS) {
4555 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
4556 ret = forward_lb_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4557 } else if (package_lb_type(pkg) == LB_TYPE_SCRIPT) {
4558 struct script_info *script;
4560 script = instance_lb_script(inst);
4562 ret = LB_STATUS_ERROR_FAULT;
4566 script_handler_update_keycode(script, keycode);
4567 ret = script_handler_feed_event(script, LB_SCRIPT_KEY_UP, timestamp);
4569 struct event_cbdata *cbdata;
4571 cbdata = malloc(sizeof(*cbdata));
4573 ret = LB_STATUS_ERROR_MEMORY;
4575 cbdata->inst = instance_ref(inst);
4576 cbdata->status = ret;
4578 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
4579 (void)instance_unref(cbdata->inst);
4581 ret = LB_STATUS_ERROR_FAULT;
4583 ret = LB_STATUS_SUCCESS;
4588 ErrPrint("Unsupported package\n");
4589 ret = LB_STATUS_ERROR_INVALID;
4593 result = packet_create_reply(packet, "i", ret);
4595 ErrPrint("Failed to create a reply packet\n");
4601 static int release_pixmap_cb(struct client_node *client, void *canvas)
4603 DbgPrint("Forcely unref the \"buffer\"\n");
4604 buffer_handler_pixmap_unref(canvas);
4605 return -1; /* Delete this callback */
4608 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 */
4610 struct packet *result;
4611 const char *pkgname;
4613 struct client_node *client;
4614 struct inst_info *inst = NULL;
4618 struct buffer_info *buffer;
4620 client = client_find_by_rpc_handle(handle);
4622 ErrPrint("Client %d is not exists\n", pid);
4623 ret = LB_STATUS_ERROR_INVALID;
4627 ret = packet_get(packet, "ss", &pkgname, &id);
4629 ErrPrint("Parameter is not matched\n");
4630 ret = LB_STATUS_ERROR_INVALID;
4634 ret = validate_request(pkgname, id, &inst, NULL);
4635 if (ret != LB_STATUS_SUCCESS) {
4639 buffer = instance_lb_buffer(inst);
4641 struct script_info *script_info;
4643 script_info = instance_lb_script(inst);
4645 ErrPrint("Unable to get LB buffer: %s\n", id);
4646 ret = LB_STATUS_ERROR_FAULT;
4650 buffer = script_handler_buffer_info(script_info);
4652 ErrPrint("Unable to get buffer_info: %s\n", id);
4653 ret = LB_STATUS_ERROR_FAULT;
4658 buf_ptr = buffer_handler_pixmap_ref(buffer);
4660 ErrPrint("Failed to ref pixmap\n");
4661 ret = LB_STATUS_ERROR_FAULT;
4665 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
4667 ErrPrint("Failed to add a new client deactivate callback\n");
4668 buffer_handler_pixmap_unref(buf_ptr);
4670 pixmap = buffer_handler_pixmap(buffer);
4671 ret = LB_STATUS_SUCCESS;
4675 result = packet_create_reply(packet, "ii", pixmap, ret);
4677 ErrPrint("Failed to create a reply packet\n");
4683 static struct packet *client_lb_release_pixmap(pid_t pid, int handle, const struct packet *packet)
4685 const char *pkgname;
4687 struct client_node *client;
4692 client = client_find_by_rpc_handle(handle);
4694 ErrPrint("Client %d is not exists\n", pid);
4698 ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
4700 ErrPrint("Parameter is not matched\n");
4704 ret = validate_request(pkgname, id, NULL, NULL);
4705 if (ret != LB_STATUS_SUCCESS) {
4709 buf_ptr = buffer_handler_pixmap_find(pixmap);
4711 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
4715 if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) {
4716 buffer_handler_pixmap_unref(buf_ptr);
4720 /*! \note No reply packet */
4724 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 */
4726 struct packet *result;
4727 const char *pkgname;
4729 struct client_node *client;
4730 struct inst_info *inst = NULL;
4734 struct buffer_info *buffer;
4736 client = client_find_by_rpc_handle(handle);
4738 ret = LB_STATUS_ERROR_INVALID;
4739 ErrPrint("Client %d is not exists\n", pid);
4743 ret = packet_get(packet, "ss", &pkgname, &id);
4745 ret = LB_STATUS_ERROR_INVALID;
4746 ErrPrint("Parameter is not matched\n");
4750 ret = validate_request(pkgname, id, &inst, NULL);
4751 if (ret != LB_STATUS_SUCCESS) {
4755 if (instance_get_data(inst, PD_RESIZE_MONITOR_TAG)) {
4756 ret = LB_STATUS_ERROR_BUSY;
4760 buffer = instance_pd_buffer(inst);
4762 struct script_info *script_info;
4764 script_info = instance_pd_script(inst);
4766 ErrPrint("Unable to get LB buffer: %s\n", id);
4767 ret = LB_STATUS_ERROR_FAULT;
4771 buffer = script_handler_buffer_info(script_info);
4773 ErrPrint("Unable to get buffer_info: %s\n", id);
4774 ret = LB_STATUS_ERROR_FAULT;
4779 buf_ptr = buffer_handler_pixmap_ref(buffer);
4781 ErrPrint("Failed to ref pixmap\n");
4782 ret = LB_STATUS_ERROR_FAULT;
4786 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
4788 ErrPrint("Failed to add a new client deactivate callback\n");
4789 buffer_handler_pixmap_unref(buf_ptr);
4791 pixmap = buffer_handler_pixmap(buffer);
4792 ret = LB_STATUS_SUCCESS;
4796 result = packet_create_reply(packet, "ii", pixmap, ret);
4798 ErrPrint("Failed to create a reply packet\n");
4804 static struct packet *client_pd_release_pixmap(pid_t pid, int handle, const struct packet *packet)
4806 const char *pkgname;
4808 struct client_node *client;
4813 client = client_find_by_rpc_handle(handle);
4815 ErrPrint("Client %d is not exists\n", pid);
4819 ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
4821 ErrPrint("Parameter is not matched\n");
4825 ret = validate_request(pkgname, id, NULL, NULL);
4826 if (ret != LB_STATUS_SUCCESS) {
4830 buf_ptr = buffer_handler_pixmap_find(pixmap);
4832 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
4836 if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) {
4837 buffer_handler_pixmap_unref(buf_ptr);
4841 /*! \note No reply packet */
4845 static struct packet *client_pinup_changed(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, pinup, ret */
4847 struct client_node *client;
4848 struct packet *result;
4849 const char *pkgname;
4853 struct inst_info *inst = NULL;
4855 client = client_find_by_rpc_handle(handle);
4857 ErrPrint("Client %d is not exists\n", pid);
4858 ret = LB_STATUS_ERROR_NOT_EXIST;
4863 ret = packet_get(packet, "ssi", &pkgname, &id, &pinup);
4865 ErrPrint("Parameter is not matched\n");
4866 ret = LB_STATUS_ERROR_INVALID;
4871 ret = validate_request(pkgname, id, &inst, NULL);
4872 if (ret == LB_STATUS_SUCCESS) {
4873 ret = instance_set_pinup(inst, pinup);
4877 result = packet_create_reply(packet, "i", ret);
4879 ErrPrint("Failed to create a packet\n");
4885 static Eina_Bool lazy_pd_created_cb(void *inst)
4887 struct pkg_info *pkg;
4889 if (!instance_del_data(inst, LAZY_PD_OPEN_TAG)) {
4890 ErrPrint("lazy,pd,open is already deleted.\n");
4891 return ECORE_CALLBACK_CANCEL;
4894 pkg = instance_package(inst);
4896 struct slave_node *slave;
4898 slave = package_slave(pkg);
4900 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst);
4905 * After unref instance first,
4906 * if the instance is not destroyed, try to notify the created PD event to the client.
4908 if (instance_unref(inst)) {
4910 ret = instance_client_pd_created(inst, LB_STATUS_SUCCESS);
4911 DbgPrint("Send PD Create event (%d) to client\n", ret);
4914 return ECORE_CALLBACK_CANCEL;
4917 static Eina_Bool lazy_pd_destroyed_cb(void *inst)
4919 struct pkg_info *pkg;
4920 struct slave_node *slave;
4922 if (!instance_del_data(inst, LAZY_PD_CLOSE_TAG)) {
4923 ErrPrint("lazy,pd,close is already deleted.\n");
4924 return ECORE_CALLBACK_CANCEL;
4927 pkg = instance_package(inst);
4929 slave = package_slave(pkg);
4931 if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
4932 DbgPrint("Delete script type close callback\n");
4933 (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst);
4934 } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
4935 DbgPrint("Delete buffer type close callback\n");
4936 (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
4941 if (instance_unref(inst)) {
4945 * If the instance is not deleted, we should send pd-destroy event from here.
4947 ret = instance_client_pd_destroyed(inst, LB_STATUS_SUCCESS);
4949 ErrPrint("Failed sending PD Destroy event (%d)\n", ret);
4953 return ECORE_CALLBACK_CANCEL;
4956 static struct packet *client_pd_move(pid_t pid, int handle, const struct packet *packet) /* pkgname, id, x, y */
4958 struct client_node *client;
4959 struct inst_info *inst = NULL;
4960 const struct pkg_info *pkg = NULL;
4961 const char *pkgname;
4967 client = client_find_by_rpc_handle(handle);
4969 ErrPrint("Client %d is not exists\n", pid);
4970 ret = LB_STATUS_ERROR_NOT_EXIST;
4974 ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
4976 ErrPrint("Parameter is not correct\n");
4977 ret = LB_STATUS_ERROR_INVALID;
4981 ret = validate_request(pkgname, id, &inst, &pkg);
4982 if (ret != LB_STATUS_SUCCESS) {
4986 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
4987 instance_slave_set_pd_pos(inst, x, y);
4988 ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
4989 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
4993 instance_slave_set_pd_pos(inst, x, y);
4994 ix = x * instance_pd_width(inst);
4995 iy = y * instance_pd_height(inst);
4996 script_handler_update_pointer(instance_pd_script(inst), ix, iy, 0);
4997 ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
4999 ErrPrint("Invalid PD type\n");
5000 ret = LB_STATUS_ERROR_INVALID;
5003 DbgPrint("Update PD position: %d\n", ret);
5007 static Eina_Bool pd_open_monitor_cb(void *inst)
5010 struct pkg_info *pkg;
5012 pkg = instance_package(inst);
5014 struct slave_node *slave;
5016 slave = package_slave(pkg);
5018 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst);
5022 ret = instance_slave_close_pd(inst, instance_pd_owner(inst));
5023 ret = instance_client_pd_created(inst, LB_STATUS_ERROR_TIMEOUT);
5024 (void)instance_del_data(inst, PD_OPEN_MONITOR_TAG);
5025 (void)instance_unref(inst);
5026 ErrPrint("PD Open request is timed-out (%lf), ret: %d\n", PD_REQUEST_TIMEOUT, ret);
5027 return ECORE_CALLBACK_CANCEL;
5030 static Eina_Bool pd_close_monitor_cb(void *inst)
5033 struct pkg_info *pkg;
5035 pkg = instance_package(inst);
5037 struct slave_node *slave;
5039 slave = package_slave(pkg);
5041 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
5045 ret = instance_client_pd_destroyed(inst, LB_STATUS_ERROR_TIMEOUT);
5046 (void)instance_del_data(inst, PD_CLOSE_MONITOR_TAG);
5047 (void)instance_unref(inst);
5048 ErrPrint("PD Close request is not processed in %lf seconds (%d)\n", PD_REQUEST_TIMEOUT, ret);
5049 return ECORE_CALLBACK_CANCEL;
5052 static Eina_Bool pd_resize_monitor_cb(void *inst)
5055 struct pkg_info *pkg;
5057 pkg = instance_package(inst);
5059 struct slave_node *slave;
5060 slave = package_slave(pkg);
5062 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst);
5066 ret = instance_slave_close_pd(inst, instance_pd_owner(inst));
5067 ret = instance_client_pd_destroyed(inst, LB_STATUS_ERROR_TIMEOUT);
5068 (void)instance_del_data(inst, PD_RESIZE_MONITOR_TAG);
5069 (void)instance_unref(inst);
5070 ErrPrint("PD Resize request is not processed in %lf seconds (%d)\n", PD_REQUEST_TIMEOUT, ret);
5071 return ECORE_CALLBACK_CANCEL;
5074 static struct packet *client_create_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
5076 struct client_node *client;
5077 struct packet *result;
5078 const char *pkgname;
5081 struct inst_info *inst = NULL;
5082 const struct pkg_info *pkg = NULL;
5083 Ecore_Timer *pd_monitor;
5087 DbgPrint("PERF_DBOX\n");
5089 client = client_find_by_rpc_handle(handle);
5091 ErrPrint("Client %d is not exists\n", pid);
5092 ret = LB_STATUS_ERROR_NOT_EXIST;
5096 ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
5098 ErrPrint("Parameter is not matched\n");
5099 ret = LB_STATUS_ERROR_INVALID;
5103 ret = validate_request(pkgname, id, &inst, &pkg);
5104 if (ret != LB_STATUS_SUCCESS) {
5108 if (instance_pd_owner(inst)) {
5109 ErrPrint("PD is already owned\n");
5110 ret = LB_STATUS_ERROR_ALREADY;
5111 } else if (package_pd_type(instance_package(inst)) == PD_TYPE_BUFFER) {
5112 pd_monitor = instance_get_data(inst, LAZY_PD_CLOSE_TAG);
5114 ecore_timer_del(pd_monitor);
5115 /* This timer attribute will be deleted */
5116 lazy_pd_destroyed_cb(inst);
5119 if (instance_get_data(inst, PD_OPEN_MONITOR_TAG)) {
5120 DbgPrint("PD Open request is already processed\n");
5121 ret = LB_STATUS_ERROR_ALREADY;
5125 if (instance_get_data(inst, PD_CLOSE_MONITOR_TAG)) {
5126 DbgPrint("PD Close request is already in process\n");
5127 ret = LB_STATUS_ERROR_BUSY;
5131 if (instance_get_data(inst, PD_RESIZE_MONITOR_TAG)) {
5132 DbgPrint("PD resize request is already in process\n");
5133 ret = LB_STATUS_ERROR_BUSY;
5137 instance_slave_set_pd_pos(inst, x, y);
5140 * Send request to the slave.
5141 * The SLAVE must has to repsonse this via "release_buffer" method.
5143 ret = instance_slave_open_pd(inst, client);
5144 if (ret == LB_STATUS_SUCCESS) {
5145 ret = instance_signal_emit(inst, "pd,show", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
5146 if (ret != LB_STATUS_SUCCESS) {
5149 tmp_ret = instance_slave_close_pd(inst, client);
5150 ErrPrint("Unable to send script event for openning PD [%s], %d\n", pkgname, tmp_ret);
5152 pd_monitor = ecore_timer_add(PD_REQUEST_TIMEOUT, pd_open_monitor_cb, instance_ref(inst));
5154 (void)instance_unref(inst);
5155 ErrPrint("Failed to create a timer for PD Open monitor\n");
5157 struct slave_node *slave;
5159 (void)instance_set_data(inst, PD_OPEN_MONITOR_TAG, pd_monitor);
5161 slave = package_slave(pkg);
5163 ErrPrint("Failed to get slave(%s)\n", pkgname);
5167 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) != LB_STATUS_SUCCESS) {
5168 ErrPrint("Failed to add fault handler: %s\n");
5173 ErrPrint("Unable to send request for openning PD [%s]\n", pkgname);
5178 * PD craeted event will be send by the acquire_buffer function.
5179 * Because the slave will make request the acquire_buffer to
5182 * instance_client_pd_created(inst);
5184 } else if (package_pd_type(instance_package(inst)) == PD_TYPE_SCRIPT) {
5188 pd_monitor = instance_get_data(inst, LAZY_PD_CLOSE_TAG);
5190 ecore_timer_del(pd_monitor);
5191 /* lazy,pd,close will be deleted */
5192 lazy_pd_destroyed_cb(inst);
5197 * ret value should be cared but in this case,
5198 * we ignore this for this moment, so we have to handle this error later.
5200 * if ret is less than 0, the slave has some problem.
5201 * but the script mode doesn't need slave for rendering default view of PD
5202 * so we can hanle it later.
5204 instance_slave_set_pd_pos(inst, x, y);
5205 ix = x * instance_pd_width(inst);
5206 iy = y * instance_pd_height(inst);
5208 script_handler_update_pointer(instance_pd_script(inst), ix, iy, 0);
5210 ret = instance_slave_open_pd(inst, client);
5211 if (ret == LB_STATUS_SUCCESS) {
5212 ret = script_handler_load(instance_pd_script(inst), 1);
5216 * Send the PD created event to the clients,
5218 if (ret == LB_STATUS_SUCCESS) {
5222 * But the created event has to be send afte return
5223 * from this function or the viewer couldn't care
5224 * the event correctly.
5226 inst = instance_ref(inst); /* To guarantee the inst */
5230 * At here, we don't need to rememeber the timer object.
5231 * Even if the timer callback is called, after the instance is destroyed.
5232 * lazy_pd_created_cb will decrease the instance refcnt first.
5233 * At that time, if the instance is released, the timer callback will do nothing.
5236 * I change my mind. There is no requirements to keep the timer handler.
5237 * But I just add it to the tagged-data of the instance.
5238 * Just reserve for future-use.
5240 pd_monitor = ecore_timer_add(DELAY_TIME, lazy_pd_created_cb, inst);
5242 ret = script_handler_unload(instance_pd_script(inst), 1);
5243 ErrPrint("Unload script: %d\n", ret);
5245 ret = instance_slave_close_pd(inst, client);
5246 ErrPrint("Close PD %d\n", ret);
5248 inst = instance_unref(inst);
5250 DbgPrint("Instance destroyed\n");
5253 ErrPrint("Instance: %s\n", pkgname);
5255 ret = LB_STATUS_ERROR_FAULT;
5257 struct slave_node *slave;
5259 (void)instance_set_data(inst, LAZY_PD_OPEN_TAG, pd_monitor);
5261 slave = package_slave(pkg);
5263 ErrPrint("Failed to get slave: %s\n", pkgname);
5267 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst) != LB_STATUS_SUCCESS) {
5268 ErrPrint("Failed to add fault callback: %s\n", pkgname);
5273 tmp_ret = instance_slave_close_pd(inst, client);
5274 ErrPrint("Unable to load script: %d, (close: %d)\n", ret, tmp_ret);
5277 ErrPrint("Unable open PD(%s): %d\n", pkgname, ret);
5280 ErrPrint("Invalid PD TYPE\n");
5281 ret = LB_STATUS_ERROR_INVALID;
5285 result = packet_create_reply(packet, "i", ret);
5287 ErrPrint("Failed to create a packet\n");
5293 static struct packet *client_destroy_pd(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
5295 struct client_node *client;
5296 struct packet *result;
5297 const char *pkgname;
5300 struct inst_info *inst = NULL;
5301 const struct pkg_info *pkg = NULL;
5302 Ecore_Timer *pd_monitor;
5303 struct slave_node *slave;
5305 DbgPrint("PERF_DBOX\n");
5307 client = client_find_by_rpc_handle(handle);
5309 ErrPrint("Client %d is not exists\n", pid);
5310 ret = LB_STATUS_ERROR_NOT_EXIST;
5314 ret = packet_get(packet, "ss", &pkgname, &id);
5316 ErrPrint("Parameter is not matched\n");
5317 ret = LB_STATUS_ERROR_INVALID;
5321 ret = validate_request(pkgname, id, &inst, &pkg);
5322 if (ret != LB_STATUS_SUCCESS) {
5326 slave = package_slave(pkg);
5328 ret = LB_STATUS_ERROR_INVALID;
5332 if (instance_pd_owner(inst) != client) {
5333 if (instance_pd_owner(inst) == NULL) {
5334 ErrPrint("PD looks already closed\n");
5335 ret = LB_STATUS_ERROR_ALREADY;
5337 ErrPrint("PD owner mimatched\n");
5338 ret = LB_STATUS_ERROR_PERMISSION;
5340 } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
5341 DbgPrint("Buffer type PD\n");
5342 pd_monitor = instance_del_data(inst, PD_OPEN_MONITOR_TAG);
5344 ErrPrint("PD Open request is found. cancel it [%s]\n", pkgname);
5346 if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) < 0) {
5347 DbgPrint("Failed to delete a deactivate callback\n");
5352 * We should return negative value
5353 * Or we have to send "destroyed" event to the client.
5354 * If we didn't send destroyed event after return SUCCESS from here,
5355 * The client will permanently waiting destroyed event.
5356 * Because they understand that the destroy request is successfully processed.
5358 ret = instance_client_pd_created(inst, LB_STATUS_ERROR_CANCEL);
5360 ErrPrint("PD client create event: %d\n", ret);
5363 ret = instance_client_pd_destroyed(inst, LB_STATUS_SUCCESS);
5365 ErrPrint("PD client destroy event: %d\n", ret);
5368 ret = instance_signal_emit(inst, "pd,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
5370 ErrPrint("PD close signal emit failed: %d\n", ret);
5373 ret = instance_slave_close_pd(inst, client);
5375 ErrPrint("PD close request failed: %d\n", ret);
5378 ecore_timer_del(pd_monitor);
5379 inst = instance_unref(inst);
5381 DbgPrint("Instance is deleted\n");
5383 } else if (instance_get_data(inst, LAZY_PD_CLOSE_TAG) || instance_get_data(inst, PD_CLOSE_MONITOR_TAG)) {
5384 DbgPrint("Close monitor is already fired\n");
5385 ret = LB_STATUS_ERROR_ALREADY;
5387 int resize_aborted = 0;
5389 pd_monitor = instance_del_data(inst, PD_RESIZE_MONITOR_TAG);
5391 ErrPrint("PD Resize request is found. clear it [%s]\n", pkgname);
5392 if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) < 0) {
5393 DbgPrint("Failed to delete a deactivate callback\n");
5396 ecore_timer_del(pd_monitor);
5398 inst = instance_unref(inst);
5400 DbgPrint("Instance is destroyed while resizing\n");
5407 ret = instance_signal_emit(inst, "pd,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
5409 ErrPrint("PD close signal emit failed: %d\n", ret);
5412 ret = instance_slave_close_pd(inst, client);
5414 ErrPrint("PD close request failed: %d\n", ret);
5415 } else if (resize_aborted) {
5416 pd_monitor = ecore_timer_add(DELAY_TIME, lazy_pd_destroyed_cb, instance_ref(inst));
5418 ErrPrint("Failed to create a timer: %s\n", pkgname);
5419 inst = instance_unref(inst);
5421 DbgPrint("Instance is deleted\n");
5424 DbgPrint("Resize is aborted\n");
5425 (void)instance_set_data(inst, LAZY_PD_CLOSE_TAG, pd_monitor);
5426 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) {
5427 ErrPrint("Failed to add a slave event callback\n");
5431 pd_monitor = ecore_timer_add(PD_REQUEST_TIMEOUT, pd_close_monitor_cb, instance_ref(inst));
5433 ErrPrint("Failed to add pd close monitor\n");
5434 inst = instance_unref(inst);
5436 ErrPrint("Instance is deleted while closing PD\n");
5439 DbgPrint("Add close monitor\n");
5440 (void)instance_set_data(inst, PD_CLOSE_MONITOR_TAG, pd_monitor);
5441 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) {
5442 ErrPrint("Failed to add SLAVE EVENT callback\n");
5449 * release_buffer will be called by the slave after this routine.
5450 * It will send the "pd_destroyed" event to the client
5452 * instance_client_pd_destroyed(inst, LB_STATUS_SUCCESS);
5454 * Or the "pd_close_monitor_cb" or "lazy_pd_destroyed_cb" will be called.
5457 } else if (package_pd_type(pkg) == PD_TYPE_SCRIPT) {
5458 DbgPrint("Script TYPE PD\n");
5459 pd_monitor = instance_get_data(inst, LAZY_PD_OPEN_TAG);
5461 ecore_timer_del(pd_monitor);
5462 (void)lazy_pd_created_cb(inst);
5465 ret = script_handler_unload(instance_pd_script(inst), 1);
5467 ErrPrint("Unable to unload the script: %s, %d\n", pkgname, ret);
5472 * Send request to the slave.
5473 * The SLAVE must has to repsonse this via "release_buffer" method.
5475 ret = instance_slave_close_pd(inst, client);
5477 ErrPrint("Unable to close the PD: %s, %d\n", pkgname, ret);
5482 * Send the destroyed PD event to the client
5484 if (ret == LB_STATUS_SUCCESS) {
5488 * I've changed my mind. There is no requirements to keep the timer handler.
5489 * But I just add it to the tagged-data of the instance.
5490 * Just reserve for future-use.
5492 DbgPrint("Add lazy PD destroy timer\n");
5493 pd_monitor = ecore_timer_add(DELAY_TIME, lazy_pd_destroyed_cb, instance_ref(inst));
5495 ErrPrint("Failed to create a timer: %s\n", pkgname);
5496 inst = instance_unref(inst);
5498 DbgPrint("instance is deleted\n");
5501 (void)instance_set_data(inst, LAZY_PD_CLOSE_TAG, pd_monitor);
5502 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst) < 0) {
5503 ErrPrint("Failed to add a event callback for slave\n");
5508 ErrPrint("Invalid PD TYPE\n");
5509 ret = LB_STATUS_ERROR_INVALID;
5513 result = packet_create_reply(packet, "i", ret);
5515 ErrPrint("Failed to create a packet\n");
5521 static struct packet *client_activate_package(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, ret */
5523 struct client_node *client;
5524 struct packet *result;
5525 const char *pkgname;
5527 struct pkg_info *info;
5529 client = client_find_by_rpc_handle(handle);
5531 ErrPrint("Client %d is not exists\n", pid);
5532 ret = LB_STATUS_ERROR_NOT_EXIST;
5537 ret = packet_get(packet, "s", &pkgname);
5539 ErrPrint("Parameter is not matched\n");
5540 ret = LB_STATUS_ERROR_INVALID;
5545 DbgPrint("pid[%d] pkgname[%s]\n", pid, pkgname);
5549 * Validate the livebox package name.
5551 if (!package_is_lb_pkgname(pkgname)) {
5552 ErrPrint("%s is not a valid livebox package\n", pkgname);
5554 ret = LB_STATUS_ERROR_INVALID;
5558 info = package_find(pkgname);
5560 ret = LB_STATUS_ERROR_NOT_EXIST;
5562 ret = package_clear_fault(info);
5566 result = packet_create_reply(packet, "is", ret, pkgname);
5568 ErrPrint("Failed to create a packet\n");
5574 static struct packet *client_subscribed(pid_t pid, int handle, const struct packet *packet)
5576 const char *cluster;
5577 const char *category;
5578 struct client_node *client;
5581 client = client_find_by_rpc_handle(handle);
5583 ErrPrint("Client %d is not exists\n", pid);
5584 ret = LB_STATUS_ERROR_NOT_EXIST;
5588 ret = packet_get(packet, "ss", &cluster, &category);
5590 ErrPrint("Invalid argument\n");
5591 ret = LB_STATUS_ERROR_INVALID;
5595 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
5596 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5597 ErrPrint("Invalid cluster name\n");
5603 * SUBSCRIBE cluster & sub-cluster for a client.
5605 ret = client_subscribe(client, cluster, category);
5607 package_alter_instances_to_client(client, ALTER_CREATE);
5611 /*! \note No reply packet */
5615 static struct packet *client_delete_cluster(pid_t pid, int handle, const struct packet *packet)
5617 const char *cluster;
5618 struct client_node *client;
5619 struct packet *result;
5622 client = client_find_by_rpc_handle(handle);
5624 ErrPrint("Client %d is not exists\n", pid);
5625 ret = LB_STATUS_ERROR_NOT_EXIST;
5629 ret = packet_get(packet, "s", &cluster);
5631 ErrPrint("Invalid parameters\n");
5632 ret = LB_STATUS_ERROR_INVALID;
5636 DbgPrint("pid[%d] cluster[%s]\n", pid, cluster);
5638 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5639 ErrPrint("Invalid cluster: %s\n", cluster);
5640 ret = LB_STATUS_ERROR_INVALID;
5647 ret = LB_STATUS_ERROR_NOT_IMPLEMENTED;
5650 result = packet_create_reply(packet, "i", ret);
5652 ErrPrint("Failed to create a packet\n");
5658 static inline int update_pkg_cb(struct category *category, const char *pkgname, int force)
5663 c_name = group_cluster_name_by_category(category);
5664 s_name = group_category_name(category);
5666 if (!c_name || !s_name || !pkgname) {
5667 ErrPrint("Name is not valid\n");
5668 return EXIT_FAILURE;
5671 DbgPrint("Send refresh request: %s (%s/%s)\n", pkgname, c_name, s_name);
5672 slave_rpc_request_update(pkgname, "", c_name, s_name, NULL, force);
5674 /* Just try to create a new package */
5675 if (util_free_space(IMAGE_PATH) > MINIMUM_SPACE) {
5677 struct inst_info *inst;
5679 timestamp = util_timestamp();
5682 * Don't need to check the subscribed clients.
5683 * Because this callback is called by the requests of clients.
5684 * It means. some clients wants to handle this instances ;)
5686 inst = instance_create(NULL, timestamp, pkgname, "", c_name, s_name, DEFAULT_PERIOD, 0, 0);
5688 ErrPrint("Failed to create a new instance\n");
5692 return EXIT_SUCCESS;
5695 static struct packet *client_update(pid_t pid, int handle, const struct packet *packet)
5697 struct inst_info *inst = NULL;
5698 struct client_node *client;
5699 const char *pkgname;
5704 client = client_find_by_rpc_handle(handle);
5706 ErrPrint("Cilent %d is not exists\n", pid);
5710 ret = packet_get(packet, "ssi", &pkgname, &id, &force);
5712 ErrPrint("Invalid argument\n");
5716 ret = validate_request(pkgname, id, &inst, NULL);
5717 if (ret != LB_STATUS_SUCCESS) {
5721 if (instance_client(inst) != client) {
5723 ErrPrint("Insufficient permissions [%s] - %d\n", pkgname, pid);
5725 slave_rpc_request_update(pkgname, id, instance_cluster(inst), instance_category(inst), NULL, force);
5729 /*! \note No reply packet */
5733 static struct packet *client_refresh_group(pid_t pid, int handle, const struct packet *packet)
5735 const char *cluster_id;
5736 const char *category_id;
5737 struct client_node *client;
5739 struct cluster *cluster;
5740 struct category *category;
5741 struct context_info *info;
5742 Eina_List *info_list;
5746 client = client_find_by_rpc_handle(handle);
5748 ErrPrint("Cilent %d is not exists\n", pid);
5752 ret = packet_get(packet, "ssi", &cluster_id, &category_id, &force);
5754 ErrPrint("Invalid parameter\n");
5758 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster_id, category_id);
5760 if (!strlen(cluster_id) || !strcasecmp(cluster_id, DEFAULT_CLUSTER)) {
5761 ErrPrint("Invalid cluster name: %s\n", cluster_id);
5765 cluster = group_find_cluster(cluster_id);
5767 ErrPrint("Cluster [%s] is not registered\n", cluster_id);
5771 category = group_find_category(cluster, category_id);
5773 ErrPrint("Category [%s] is not registered\n", category_id);
5777 info_list = group_context_info_list(category);
5778 EINA_LIST_FOREACH(info_list, l, info) {
5779 update_pkg_cb(category, group_pkgname_from_context_info(info), force);
5783 /*! \note No reply packet */
5787 static struct packet *client_delete_category(pid_t pid, int handle, const struct packet *packet)
5789 const char *cluster;
5790 const char *category;
5791 struct client_node *client;
5792 struct packet *result;
5795 client = client_find_by_rpc_handle(handle);
5797 ErrPrint("Client %d is not exists\n", pid);
5798 ret = LB_STATUS_ERROR_NOT_EXIST;
5802 ret = packet_get(packet, "ss", &cluster, &category);
5804 ErrPrint("Invalid paramenters\n");
5805 ret = LB_STATUS_ERROR_INVALID;
5809 DbgPrint("pid[%d] cluster[%s] category[%s]\n", pid, cluster, category);
5810 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5811 ErrPrint("Invalid cluster: %s\n", cluster);
5812 ret = LB_STATUS_ERROR_INVALID;
5819 ret = LB_STATUS_ERROR_NOT_IMPLEMENTED;
5822 result = packet_create_reply(packet, "i", ret);
5824 ErrPrint("Failed to create a packet\n");
5830 static struct packet *client_unsubscribed(pid_t pid, int handle, const struct packet *packet)
5832 const char *cluster;
5833 const char *category;
5834 struct client_node *client;
5837 client = client_find_by_rpc_handle(handle);
5839 ErrPrint("Client %d is not exists\n", pid);
5840 ret = LB_STATUS_ERROR_NOT_EXIST;
5844 ret = packet_get(packet, "ss", &cluster, &category);
5846 ErrPrint("Invalid argument\n");
5847 ret = LB_STATUS_ERROR_INVALID;
5851 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
5853 if (!strlen(cluster) || !strcasecmp(cluster, DEFAULT_CLUSTER)) {
5854 ErrPrint("Invalid cluster name: %s\n", cluster);
5860 * UNSUBSCRIBE cluster & sub-cluster for a client.
5862 ret = client_unsubscribe(client, cluster, category);
5864 package_alter_instances_to_client(client, ALTER_DESTROY);
5868 /*! \note No reply packet */
5872 static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
5874 struct slave_node *slave;
5875 const char *slavename;
5878 ret = packet_get(packet, "s", &slavename);
5880 ErrPrint("Parameter is not matched\n");
5884 DbgPrint("New slave[%s](%d) is arrived\n", slavename, pid);
5886 slave = slave_find_by_name(slavename);
5888 if (!slave) { /* Try again to find a slave using pid */
5889 slave = slave_find_by_pid(pid);
5894 char pkgname[pathconf("/", _PC_PATH_MAX)];
5897 if (aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)) != AUL_R_OK) {
5898 ErrPrint("pid[%d] is not authroized provider package, try to find it using its name[%s]\n", pid, slavename);
5899 slave = slave_find_by_name(slavename);
5900 pkgname[0] = '\0'; /* Reset the pkgname */
5902 slave = slave_find_by_pkgname(pkgname);
5906 abi = abi_find_by_pkgname(pkgname);
5909 DbgPrint("Slave pkgname is invalid, ABI is replaced with '%s'(default)\n", abi);
5912 slave = slave_create(slavename, 1, abi, pkgname, 0);
5914 ErrPrint("Failed to create a new slave for %s\n", slavename);
5918 DbgPrint("New slave is created (net: 0)\n");
5920 DbgPrint("Registered slave is replaced with this new one\n");
5921 abi = slave_abi(slave);
5923 ErrPrint("ABI is not valid: %s\n", slavename);
5928 slave_set_pid(slave, pid);
5929 DbgPrint("Provider is forcely activated, pkgname(%s), abi(%s), slavename(%s)\n", pkgname, abi, slavename);
5931 ErrPrint("Slave[%d, %s] is not exists\n", pid, slavename);
5935 if (slave_pid(slave) != pid) {
5936 if (slave_pid(slave) > 0) {
5937 CRITICAL_LOG("Slave(%s) is already assigned to %d\n", slave_name(slave), slave_pid(slave));
5939 ret = aul_terminate_pid(pid);
5940 CRITICAL_LOG("Terminate %d (ret: %d)\n", pid, ret);
5944 CRITICAL_LOG("PID of slave(%s) is updated (%d -> %d)\n", slave_name(slave), slave_pid(slave), pid);
5945 slave_set_pid(slave, pid);
5951 * After updating handle,
5952 * slave activated callback will be called.
5954 slave_rpc_update_handle(slave, handle);
5960 static struct packet *slave_ping(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
5962 struct slave_node *slave;
5963 const char *slavename;
5966 slave = slave_find_by_pid(pid);
5968 ErrPrint("Slave %d is not exists\n", pid);
5972 ret = packet_get(packet, "s", &slavename);
5974 ErrPrint("Parameter is not matched\n");
5976 slave_rpc_ping(slave);
5983 static struct packet *slave_faulted(pid_t pid, int handle, const struct packet *packet)
5985 struct slave_node *slave;
5986 struct inst_info *inst;
5987 const char *pkgname;
5992 slave = slave_find_by_pid(pid);
5994 ErrPrint("Slave %d is not exists\n", pid);
5998 ret = packet_get(packet, "sss", &pkgname, &id, &func);
6000 ErrPrint("Parameter is not matched\n");
6004 ret = fault_info_set(slave, pkgname, id, func);
6005 DbgPrint("Slave Faulted: %s (%d)\n", slave_name(slave), ret);
6007 inst = package_find_instance_by_id(pkgname, id);
6009 DbgPrint("There is a no such instance(%s)\n", id);
6010 } else if (instance_state(inst) == INST_DESTROYED) {
6011 ErrPrint("Instance(%s) is already destroyed\n", id);
6013 ret = instance_destroy(inst, INSTANCE_DESTROY_FAULT);
6020 static struct packet *slave_lb_update_begin(pid_t pid, int handle, const struct packet *packet)
6022 struct slave_node *slave;
6023 struct inst_info *inst = NULL;
6024 const struct pkg_info *pkg = NULL;
6025 const char *pkgname;
6028 const char *content;
6032 slave = slave_find_by_pid(pid);
6034 ErrPrint("Slave %d is not exists\n", pid);
6038 ret = packet_get(packet, "ssdss", &pkgname, &id, &priority, &content, &title);
6040 ErrPrint("Invalid parameters\n");
6044 ret = validate_request(pkgname, id, &inst, &pkg);
6045 if (ret != LB_STATUS_SUCCESS) {
6049 if (instance_state(inst) == INST_DESTROYED) {
6050 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6054 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
6055 ret = instance_lb_update_begin(inst, priority, content, title);
6056 if (ret == LB_STATUS_SUCCESS) {
6057 slave_freeze_ttl(slave);
6060 ErrPrint("Invalid request[%s]\n", id);
6067 static struct packet *slave_lb_update_end(pid_t pid, int handle, const struct packet *packet)
6069 struct slave_node *slave;
6070 struct inst_info *inst = NULL;
6071 const struct pkg_info *pkg = NULL;
6072 const char *pkgname;
6076 slave = slave_find_by_pid(pid);
6078 ErrPrint("Slave %d is not exists\n", pid);
6082 ret = packet_get(packet, "ss", &pkgname, &id);
6084 ErrPrint("Invalid parameters\n");
6088 ret = validate_request(pkgname, id, &inst, &pkg);
6089 if (ret != LB_STATUS_SUCCESS) {
6093 if (instance_state(inst) == INST_DESTROYED) {
6094 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6098 if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
6099 ret = instance_lb_update_end(inst);
6100 if (ret == LB_STATUS_SUCCESS) {
6101 slave_thaw_ttl(slave);
6104 ErrPrint("Invalid request[%s]\n", id);
6111 static struct packet *slave_pd_update_begin(pid_t pid, int handle, const struct packet *packet)
6113 struct slave_node *slave;
6114 const struct pkg_info *pkg = NULL;
6115 struct inst_info *inst = NULL;
6116 const char *pkgname;
6120 slave = slave_find_by_pid(pid);
6122 ErrPrint("Slave %d is not exists\n", pid);
6126 ret = packet_get(packet, "ss", &pkgname, &id);
6128 ErrPrint("Invalid parameters\n");
6132 ret = validate_request(pkgname, id, &inst, &pkg);
6133 if (ret != LB_STATUS_SUCCESS) {
6137 if (instance_state(inst) == INST_DESTROYED) {
6138 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6142 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
6143 (void)instance_pd_update_begin(inst);
6145 ErrPrint("Invalid request[%s]\n", id);
6152 static struct packet *slave_key_status(pid_t pid, int handle, const struct packet *packet)
6154 struct slave_node *slave;
6155 struct inst_info *inst;
6156 const char *pkgname;
6161 slave = slave_find_by_pid(pid);
6163 ErrPrint("Slave %d is not exists\n", pid);
6167 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6169 ErrPrint("Invalid parameters\n");
6173 ret = validate_request(pkgname, id, &inst, NULL);
6174 if (ret == LB_STATUS_SUCCESS) {
6175 if (instance_state(inst) == INST_DESTROYED) {
6176 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6178 (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6186 static struct packet *slave_access_status(pid_t pid, int handle, const struct packet *packet)
6188 struct slave_node *slave;
6189 struct inst_info *inst = NULL;
6190 const char *pkgname;
6195 slave = slave_find_by_pid(pid);
6197 ErrPrint("Slave %d is not exists\n", pid);
6201 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6203 ErrPrint("Invalid parameters\n");
6207 ret = validate_request(pkgname, id, &inst, NULL);
6208 if (ret == LB_STATUS_SUCCESS) {
6209 if (instance_state(inst) == INST_DESTROYED) {
6210 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6212 (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6220 static struct packet *slave_close_pd(pid_t pid, int handle, const struct packet *packet)
6222 struct slave_node *slave;
6223 struct inst_info *inst;
6224 const char *pkgname;
6229 slave = slave_find_by_pid(pid);
6231 ErrPrint("Slave %d is not exists\n", pid);
6235 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6237 ErrPrint("Invalid parameters\n");
6241 ret = validate_request(pkgname, id, &inst, NULL);
6242 if (ret == LB_STATUS_SUCCESS) {
6243 if (instance_state(inst) == INST_DESTROYED) {
6244 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6246 (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6254 static struct packet *slave_pd_update_end(pid_t pid, int handle, const struct packet *packet)
6256 struct slave_node *slave;
6257 const struct pkg_info *pkg;
6258 struct inst_info *inst;
6259 const char *pkgname;
6263 slave = slave_find_by_pid(pid);
6265 ErrPrint("Slave %d is not exists\n", pid);
6269 ret = packet_get(packet, "ss", &pkgname, &id);
6271 ErrPrint("Invalid parameters\n");
6275 ret = validate_request(pkgname, id, &inst, &pkg);
6276 if (ret != LB_STATUS_SUCCESS) {
6280 if (instance_state(inst) == INST_DESTROYED) {
6281 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6285 if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
6286 (void)instance_pd_update_end(inst);
6288 ErrPrint("Invalid request[%s]\n", id);
6295 static struct packet *slave_call(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
6297 struct slave_node *slave;
6298 const char *pkgname;
6303 slave = slave_find_by_pid(pid);
6305 ErrPrint("Slave %d is not exists\n", pid);
6309 ret = packet_get(packet, "sss", &pkgname, &id, &func);
6311 ErrPrint("Parameter is not matched\n");
6315 ret = fault_func_call(slave, pkgname, id, func);
6316 slave_give_more_ttl(slave);
6322 static struct packet *slave_ret(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
6324 struct slave_node *slave;
6325 const char *pkgname;
6330 slave = slave_find_by_pid(pid);
6332 ErrPrint("Slave %d is not exists\n", pid);
6336 ret = packet_get(packet, "sss", &pkgname, &id, &func);
6338 ErrPrint("Parameter is not matched\n");
6342 ret = fault_func_ret(slave, pkgname, id, func);
6343 slave_give_more_ttl(slave);
6349 static struct packet *slave_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, width, height, priority, ret */
6351 struct slave_node *slave;
6352 const char *pkgname;
6353 const char *safe_filename;
6355 const char *content_info;
6357 const char *icon = NULL;
6358 const char *name = NULL;
6363 struct inst_info *inst = NULL;
6365 slave = slave_find_by_pid(pid);
6367 ErrPrint("Slave %d is not exists\n", pid);
6371 ret = packet_get(packet, "ssiidsssss", &pkgname, &id,
6373 &content_info, &title,
6374 &safe_filename, &icon, &name);
6376 ErrPrint("Parameter is not matched\n");
6380 ret = validate_request(pkgname, id, &inst, NULL);
6381 if (ret == LB_STATUS_SUCCESS) {
6382 if (instance_state(inst) == INST_DESTROYED) {
6383 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6387 instance_set_lb_info(inst, priority, content_info, title);
6388 instance_set_alt_info(inst, icon, name);
6390 switch (package_lb_type(instance_package(inst))) {
6391 case LB_TYPE_SCRIPT:
6392 script_handler_resize(instance_lb_script(inst), w, h);
6393 if (safe_filename) {
6394 (void)script_handler_parse_desc(inst, safe_filename, 0);
6396 safe_filename = util_uri_to_path(id);
6397 (void)script_handler_parse_desc(inst, safe_filename, 0);
6400 if (unlink(safe_filename) < 0) {
6401 ErrPrint("unlink: %s - %s\n", strerror(errno), safe_filename);
6404 case LB_TYPE_BUFFER:
6408 * text format (inst)
6410 instance_set_lb_size(inst, w, h);
6411 instance_lb_updated_by_instance(inst, safe_filename);
6415 slave_give_more_ttl(slave);
6422 static struct packet *slave_hold_scroll(pid_t pid, int handle, const struct packet *packet)
6424 struct slave_node *slave;
6425 struct inst_info *inst = NULL;
6426 const char *pkgname;
6431 slave = slave_find_by_pid(pid);
6433 ErrPrint("Slave %d is not exists\n", pid);
6437 ret = packet_get(packet, "ssi", &pkgname, &id, &seize);
6439 ErrPrint("Parameter is not matched\n");
6443 ret = validate_request(pkgname, id, &inst, NULL);
6444 if (ret == LB_STATUS_SUCCESS) {
6445 if (instance_state(inst) == INST_DESTROYED) {
6446 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6448 (void)instance_hold_scroll(inst, seize);
6456 static struct packet *slave_desc_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, decsfile, ret */
6458 struct slave_node *slave;
6459 const char *pkgname;
6461 const char *descfile;
6463 struct inst_info *inst = NULL;
6465 slave = slave_find_by_pid(pid);
6467 ErrPrint("Slave %d is not exists\n", pid);
6471 ret = packet_get(packet, "sss", &pkgname, &id, &descfile);
6473 ErrPrint("Parameter is not matched\n");
6477 ret = validate_request(pkgname, id, &inst, NULL);
6478 if (ret != LB_STATUS_SUCCESS) {
6482 if (instance_state(inst) == INST_DESTROYED) {
6483 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6487 switch (package_pd_type(instance_package(inst))) {
6488 case PD_TYPE_SCRIPT:
6489 DbgPrint("%s updated (%s)\n", instance_id(inst), descfile);
6490 if (script_handler_is_loaded(instance_pd_script(inst))) {
6491 (void)script_handler_parse_desc(inst, descfile, 1);
6495 instance_set_pd_size(inst, 0, 0);
6496 case PD_TYPE_BUFFER:
6497 instance_pd_updated(pkgname, id, descfile);
6500 DbgPrint("Ignore updated DESC(%s)\n", pkgname);
6508 static struct packet *slave_deleted(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, id, ret */
6510 struct slave_node *slave;
6511 const char *pkgname;
6514 struct inst_info *inst = NULL;
6516 slave = slave_find_by_pid(pid);
6518 ErrPrint("Slave %d is not exists\n", pid);
6522 ret = packet_get(packet, "ss", &pkgname, &id);
6524 ErrPrint("Parameter is not matched\n");
6528 ret = validate_request(pkgname, id, &inst, NULL);
6529 if (ret == LB_STATUS_SUCCESS) {
6530 ret = instance_destroyed(inst, LB_STATUS_SUCCESS);
6538 * \note for the BUFFER Type slave
6540 static struct packet *slave_acquire_buffer(pid_t pid, int handle, const struct packet *packet) /* type, id, w, h, size */
6542 enum target_type target;
6543 const char *pkgname;
6548 struct packet *result;
6549 struct slave_node *slave;
6550 struct inst_info *inst = NULL;
6551 const struct pkg_info *pkg = NULL;
6554 slave = slave_find_by_pid(pid);
6556 ErrPrint("Failed to find a slave\n");
6558 ret = LB_STATUS_ERROR_NOT_EXIST;
6562 ret = packet_get(packet, "issiii", &target, &pkgname, &id, &w, &h, &pixel_size);
6564 ErrPrint("Invalid argument\n");
6566 ret = LB_STATUS_ERROR_INVALID;
6570 ret = validate_request(pkgname, id, &inst, &pkg);
6573 if (ret != LB_STATUS_SUCCESS) {
6577 ret = LB_STATUS_ERROR_INVALID;
6579 if (instance_state(inst) == INST_DESTROYED) {
6580 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6584 if (target == TYPE_LB && package_lb_type(pkg) == LB_TYPE_BUFFER) {
6585 struct buffer_info *info;
6587 info = instance_lb_buffer(inst);
6589 if (!instance_create_lb_buffer(inst)) {
6590 ErrPrint("Failed to create a LB buffer\n");
6591 ret = LB_STATUS_ERROR_FAULT;
6595 info = instance_lb_buffer(inst);
6597 ErrPrint("LB buffer is not valid\n");
6600 * ret value should not be changed.
6606 ret = buffer_handler_resize(info, w, h);
6607 ret = buffer_handler_load(info);
6609 instance_set_lb_size(inst, w, h);
6610 instance_set_lb_info(inst, PRIORITY_NO_CHANGE, CONTENT_NO_CHANGE, TITLE_NO_CHANGE);
6611 id = buffer_handler_id(info);
6613 ErrPrint("Failed to load a buffer(%d)\n", ret);
6615 } else if (target == TYPE_PD && package_pd_type(pkg) == PD_TYPE_BUFFER) {
6616 struct buffer_info *info;
6617 Ecore_Timer *pd_monitor;
6621 pd_monitor = instance_del_data(inst, PD_OPEN_MONITOR_TAG);
6623 pd_monitor = instance_del_data(inst, PD_RESIZE_MONITOR_TAG);
6624 is_resize = !!pd_monitor;
6626 /* Invalid request. Reject this */
6627 ErrPrint("Invalid request\n");
6631 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst);
6633 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst);
6636 ecore_timer_del(pd_monitor);
6637 inst = instance_unref(inst);
6639 ErrPrint("Instance refcnt is ZERO: %s\n", pkgname);
6643 info = instance_pd_buffer(inst);
6645 if (!instance_create_pd_buffer(inst)) {
6646 ErrPrint("Failed to create a PD buffer\n");
6647 ret = LB_STATUS_ERROR_FAULT;
6648 instance_client_pd_created(inst, ret);
6652 info = instance_pd_buffer(inst);
6654 ErrPrint("PD buffer is not valid\n");
6657 * ret value should not be changed.
6659 instance_client_pd_created(inst, ret);
6664 ret = buffer_handler_resize(info, w, h);
6665 ret = buffer_handler_load(info);
6667 instance_set_pd_size(inst, w, h);
6668 id = buffer_handler_id(info);
6670 ErrPrint("Failed to load a buffer (%d)\n", ret);
6674 * Send the PD created event to the client
6677 instance_client_pd_created(inst, ret);
6682 result = packet_create_reply(packet, "is", ret, id);
6684 ErrPrint("Failed to create a packet\n");
6690 static struct packet *slave_resize_buffer(pid_t pid, int handle, const struct packet *packet)
6692 struct slave_node *slave;
6693 struct packet *result;
6694 enum target_type type;
6695 const char *pkgname;
6699 struct inst_info *inst = NULL;
6700 const struct pkg_info *pkg = NULL;
6703 slave = slave_find_by_pid(pid);
6705 ErrPrint("Failed to find a slave\n");
6706 ret = LB_STATUS_ERROR_NOT_EXIST;
6711 ret = packet_get(packet, "issii", &type, &pkgname, &id, &w, &h);
6713 ErrPrint("Invalid argument\n");
6714 ret = LB_STATUS_ERROR_INVALID;
6719 ret = validate_request(pkgname, id, &inst, &pkg);
6721 if (ret != LB_STATUS_SUCCESS) {
6725 ret = LB_STATUS_ERROR_INVALID;
6728 * Reset "id", It will be re-used from here
6731 if (instance_state(inst) == INST_DESTROYED) {
6732 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6736 if (type == TYPE_LB && package_lb_type(pkg) == LB_TYPE_BUFFER) {
6737 struct buffer_info *info;
6739 info = instance_lb_buffer(inst);
6744 ret = buffer_handler_resize(info, w, h);
6747 * id is resued for newly assigned ID
6749 if (ret == LB_STATUS_SUCCESS) {
6750 id = buffer_handler_id(info);
6751 instance_set_lb_size(inst, w, h);
6752 instance_set_lb_info(inst, PRIORITY_NO_CHANGE, CONTENT_NO_CHANGE, TITLE_NO_CHANGE);
6754 } else if (type == TYPE_PD && package_pd_type(pkg) == PD_TYPE_BUFFER) {
6755 struct buffer_info *info;
6757 info = instance_pd_buffer(inst);
6762 ret = buffer_handler_resize(info, w, h);
6765 * id is resued for newly assigned ID
6767 if (ret == LB_STATUS_SUCCESS) {
6768 id = buffer_handler_id(info);
6769 instance_set_pd_size(inst, w, h);
6774 result = packet_create_reply(packet, "is", ret, id);
6776 ErrPrint("Failed to create a packet\n");
6782 static struct packet *slave_release_buffer(pid_t pid, int handle, const struct packet *packet)
6784 enum target_type type;
6785 const char *pkgname;
6787 struct packet *result;
6788 struct slave_node *slave;
6789 struct inst_info *inst = NULL;
6790 const struct pkg_info *pkg = NULL;
6793 slave = slave_find_by_pid(pid);
6795 ErrPrint("Failed to find a slave\n");
6796 ret = LB_STATUS_ERROR_NOT_EXIST;
6800 if (packet_get(packet, "iss", &type, &pkgname, &id) != 3) {
6801 ErrPrint("Inavlid argument\n");
6802 ret = LB_STATUS_ERROR_INVALID;
6806 ret = validate_request(pkgname, id, &inst, &pkg);
6807 if (ret != LB_STATUS_SUCCESS) {
6811 ret = LB_STATUS_ERROR_INVALID;
6813 if (type == TYPE_LB && package_lb_type(pkg) == LB_TYPE_BUFFER) {
6814 struct buffer_info *info;
6816 info = instance_lb_buffer(inst);
6817 ret = buffer_handler_unload(info);
6818 } else if (type == TYPE_PD && package_pd_type(pkg) == PD_TYPE_BUFFER) {
6819 struct buffer_info *info;
6820 Ecore_Timer *pd_monitor;
6822 pd_monitor = instance_del_data(inst, PD_CLOSE_MONITOR_TAG);
6823 if (!pd_monitor && !package_is_fault(pkg)) {
6824 ErrPrint("Slave requests to release a buffer\n");
6827 * In this case just keep going to release buffer,
6828 * Even if a user(client) doesn't wants to destroy the PD.
6830 * If the slave tries to destroy PD buffer, it should be
6831 * released and reported to the client about its status.
6833 * Even if the pd is destroyed by timeout handler,
6834 * instance_client_pd_destroyed function will be ignored
6835 * by pd.need_to_send_close_event flag.
6836 * which will be checked by instance_client_pd_destroyed function.
6841 * provider can try to resize the buffer size.
6842 * in that case, it will release the buffer first.
6843 * Then even though the client doesn't request to close the PD,
6844 * the provider can release it.
6845 * If we send the close event to the client,
6846 * The client will not able to allocate PD again.
6847 * In this case, add the pd,monitor again. from here.
6848 * to wait the re-allocate buffer.
6849 * If the client doesn't request buffer reallocation,
6850 * Treat it as a fault. and close the PD.
6852 info = instance_pd_buffer(inst);
6853 ret = buffer_handler_unload(info);
6855 if (ret == LB_STATUS_SUCCESS) {
6856 pd_monitor = ecore_timer_add(PD_REQUEST_TIMEOUT, pd_resize_monitor_cb, instance_ref(inst));
6858 ErrPrint("Failed to create a timer for PD Open monitor\n");
6859 inst = instance_unref(inst);
6861 DbgPrint("Instance is deleted\n");
6864 (void)instance_set_data(inst, PD_RESIZE_MONITOR_TAG, pd_monitor);
6865 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) != LB_STATUS_SUCCESS) {
6866 ErrPrint("Failed to add event handler: %s\n", pkgname);
6874 * If the instance has pd_monitor, the pd close requested from client via client_destroy_pd.
6876 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
6877 ecore_timer_del(pd_monitor);
6879 inst = instance_unref(inst);
6881 ErrPrint("Instance is released: %s\n", pkgname);
6882 ret = LB_STATUS_ERROR_FAULT;
6887 This case means that the package is faulted so the service provider tries to release the buffer
6890 info = instance_pd_buffer(inst);
6891 ret = buffer_handler_unload(info);
6895 * Send the PD destroyed event to the client
6897 instance_client_pd_destroyed(inst, ret);
6902 result = packet_create_reply(packet, "i", ret);
6904 ErrPrint("Failed to create a packet\n");
6910 static struct packet *service_change_period(pid_t pid, int handle, const struct packet *packet)
6912 struct inst_info *inst = NULL;
6913 struct packet *result;
6914 const char *pkgname;
6919 ret = packet_get(packet, "ssd", &pkgname, &id, &period);
6921 ErrPrint("Invalid packet\n");
6922 ret = LB_STATUS_ERROR_INVALID;
6927 struct pkg_info *pkg;
6929 pkg = package_find(pkgname);
6931 ret = LB_STATUS_ERROR_NOT_EXIST;
6932 } else if (package_is_fault(pkg)) {
6933 ret = LB_STATUS_ERROR_FAULT;
6935 Eina_List *inst_list;
6938 inst_list = package_instance_list(pkg);
6939 EINA_LIST_FOREACH(inst_list, l, inst) {
6940 ret = instance_set_period(inst, period);
6942 ErrPrint("Failed to change the period of %s to (%lf)\n", pkgname, period);
6947 ret = validate_request(pkgname, id, &inst, NULL);
6948 if (ret == LB_STATUS_SUCCESS) {
6949 if (instance_state(inst) == INST_DESTROYED) {
6950 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6951 ret = LB_STATUS_ERROR_INVALID;
6955 ret = instance_set_period(inst, period);
6959 DbgPrint("Change the update period: %s, %lf : %d\n", pkgname, period, ret);
6961 result = packet_create_reply(packet, "i", ret);
6963 ErrPrint("Failed to create a packet\n");
6969 static struct packet *service_update(pid_t pid, int handle, const struct packet *packet)
6971 Eina_List *inst_list;
6972 struct pkg_info *pkg;
6973 struct packet *result;
6974 const char *pkgname;
6976 const char *cluster;
6977 const char *category;
6978 const char *content;
6983 ret = packet_get(packet, "sssssi", &pkgname, &id, &cluster, &category, &content, &force);
6985 ErrPrint("Invalid Packet\n");
6986 ret = LB_STATUS_ERROR_INVALID;
6990 lbid = package_lb_pkgname(pkgname);
6992 ErrPrint("Invalid package %s\n", pkgname);
6993 ret = LB_STATUS_ERROR_INVALID;
6997 pkg = package_find(lbid);
6999 ret = LB_STATUS_ERROR_NOT_EXIST;
7004 if (package_is_fault(pkg)) {
7005 ret = LB_STATUS_ERROR_FAULT;
7010 inst_list = package_instance_list(pkg);
7011 if (!eina_list_count(inst_list)) {
7012 ret = LB_STATUS_ERROR_NOT_EXIST;
7017 if (id && strlen(id)) {
7019 struct inst_info *inst;
7021 ret = LB_STATUS_ERROR_NOT_EXIST;
7022 EINA_LIST_FOREACH(inst_list, l, inst) {
7023 if (!strcmp(instance_id(inst), id)) {
7024 ret = LB_STATUS_SUCCESS;
7029 if (ret == LB_STATUS_ERROR_NOT_EXIST) {
7037 * Validate the update requstor.
7039 slave_rpc_request_update(lbid, id, cluster, category, content, force);
7041 ret = LB_STATUS_SUCCESS;
7044 result = packet_create_reply(packet, "i", ret);
7046 ErrPrint("Failed to create a packet\n");
7052 static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet *packet)
7054 struct liveinfo *info;
7055 struct packet *result;
7057 const char *fifo_name;
7060 DbgPrint("Request arrived from %d\n", pid);
7062 if (packet_get(packet, "d", ×tamp) != 1) {
7063 ErrPrint("Invalid packet\n");
7065 ret = LB_STATUS_ERROR_INVALID;
7069 info = liveinfo_create(pid, handle);
7071 ErrPrint("Failed to create a liveinfo object\n");
7073 ret = LB_STATUS_ERROR_INVALID;
7078 fifo_name = liveinfo_filename(info);
7079 DbgPrint("FIFO Created: %s (Serve for %d)\n", fifo_name, pid);
7082 result = packet_create_reply(packet, "si", fifo_name, ret);
7084 ErrPrint("Failed to create a result packet\n");
7090 static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet)
7094 struct liveinfo *info;
7095 struct slave_node *slave;
7099 if (packet_get(packet, "d", ×tamp) != 1) {
7100 ErrPrint("Invalid argument\n");
7104 info = liveinfo_find_by_pid(pid);
7106 ErrPrint("Invalid request\n");
7110 liveinfo_open_fifo(info);
7111 fp = liveinfo_fifo(info);
7113 liveinfo_close_fifo(info);
7117 list = (Eina_List *)slave_list();
7118 EINA_LIST_FOREACH(list, l, slave) {
7119 fprintf(fp, "%d %s %s %s %d %d %d %s %d %d %lf\n",
7122 slave_pkgname(slave),
7124 slave_is_secured(slave),
7125 slave_refcnt(slave),
7126 slave_fault_count(slave),
7127 slave_state_string(slave),
7128 slave_loaded_instance(slave),
7129 slave_loaded_package(slave),
7134 fprintf(fp, "EOD\n");
7135 liveinfo_close_fifo(info);
7140 static inline const char *visible_state_string(enum livebox_visible_state state)
7147 case LB_HIDE_WITH_PAUSE:
7156 static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet)
7158 const char *pkgname;
7159 struct liveinfo *info;
7160 struct pkg_info *pkg;
7162 Eina_List *inst_list;
7163 struct inst_info *inst;
7166 if (packet_get(packet, "s", &pkgname) != 1) {
7167 ErrPrint("Invalid argument\n");
7171 info = liveinfo_find_by_pid(pid);
7173 ErrPrint("Invalid request\n");
7177 liveinfo_open_fifo(info);
7178 fp = liveinfo_fifo(info);
7180 ErrPrint("Invalid fp\n");
7181 liveinfo_close_fifo(info);
7185 if (!package_is_lb_pkgname(pkgname)) {
7186 ErrPrint("Invalid package name\n");
7190 pkg = package_find(pkgname);
7192 ErrPrint("Package is not exists\n");
7196 inst_list = package_instance_list(pkg);
7197 EINA_LIST_FOREACH(inst_list, l, inst) {
7198 fprintf(fp, "%s %s %s %lf %s %d %d\n",
7200 instance_cluster(inst),
7201 instance_category(inst),
7202 instance_period(inst),
7203 visible_state_string(instance_visible_state(inst)),
7204 instance_lb_width(inst),
7205 instance_lb_height(inst));
7209 fprintf(fp, "EOD\n");
7210 liveinfo_close_fifo(info);
7216 static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet)
7220 Eina_List *inst_list;
7221 struct liveinfo *info;
7222 struct pkg_info *pkg;
7223 struct slave_node *slave;
7225 const char *slavename;
7228 if (packet_get(packet, "d", ×tamp) != 1) {
7229 ErrPrint("Invalid argument\n");
7233 info = liveinfo_find_by_pid(pid);
7235 ErrPrint("Invalid request\n");
7239 liveinfo_open_fifo(info);
7240 fp = liveinfo_fifo(info);
7242 liveinfo_close_fifo(info);
7246 list = (Eina_List *)package_list();
7247 EINA_LIST_FOREACH(list, l, pkg) {
7248 slave = package_slave(pkg);
7251 slavename = slave_name(slave);
7252 pid = slave_pid(slave);
7258 inst_list = (Eina_List *)package_instance_list(pkg);
7259 fprintf(fp, "%d %s %s %s %d %d %d\n",
7261 strlen(slavename) ? slavename : "(none)",
7264 package_refcnt(pkg),
7265 package_fault_count(pkg),
7266 eina_list_count(inst_list)
7270 fprintf(fp, "EOD\n");
7271 liveinfo_close_fifo(info);
7276 static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct packet *packet)
7281 static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet)
7283 struct liveinfo *info;
7289 if (packet_get(packet, "sss", &cmd, &pkgname, &id) != 3) {
7290 ErrPrint("Invalid argument\n");
7294 info = liveinfo_find_by_pid(pid);
7296 ErrPrint("Invalid request\n");
7300 liveinfo_open_fifo(info);
7301 fp = liveinfo_fifo(info);
7303 liveinfo_close_fifo(info);
7307 if (!strcmp(cmd, "rmpack")) {
7308 fprintf(fp, "%d\n", ENOSYS);
7309 } else if (!strcmp(cmd, "rminst")) {
7310 struct inst_info *inst;
7311 inst = package_find_instance_by_id(pkgname, id);
7313 fprintf(fp, "%d\n", ENOENT);
7315 (void)instance_destroy(inst, INSTANCE_DESTROY_DEFAULT);
7316 fprintf(fp, "%d\n", 0);
7318 } else if (!strcmp(cmd, "faultinst")) {
7319 struct inst_info *inst;
7320 inst = package_find_instance_by_id(pkgname, id);
7322 fprintf(fp, "%d\n", ENOENT);
7324 struct pkg_info *pkg;
7326 pkg = instance_package(inst);
7328 fprintf(fp, "%d\n", EFAULT);
7330 (void)package_faulted(pkg);
7331 fprintf(fp, "%d\n", 0);
7336 fprintf(fp, "EOD\n");
7337 liveinfo_close_fifo(info);
7343 static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct packet *packet)
7345 struct liveinfo *info;
7350 int ret = LB_STATUS_ERROR_INVALID;
7352 if (packet_get(packet, "sss", &cmd, &var, &val) != 3) {
7353 ErrPrint("Invalid argument\n");
7357 info = liveinfo_find_by_pid(pid);
7359 ErrPrint("Invalid request\n");
7363 if (!strcasecmp(var, "debug")) {
7364 if (!strcasecmp(cmd, "set")) {
7365 g_conf.debug_mode = !strcasecmp(val, "on");
7366 } else if (!strcasecmp(cmd, "get")) {
7368 ret = g_conf.debug_mode;
7369 } else if (!strcasecmp(var, "slave_max_load")) {
7370 if (!strcasecmp(cmd, "set")) {
7371 g_conf.slave_max_load = atoi(val);
7372 } else if (!strcasecmp(cmd, "get")) {
7374 ret = g_conf.slave_max_load;
7377 liveinfo_open_fifo(info);
7378 fp = liveinfo_fifo(info);
7380 liveinfo_close_fifo(info);
7383 fprintf(fp, "%d\nEOD\n", ret);
7384 liveinfo_close_fifo(info);
7390 static struct method s_info_table[] = {
7392 .cmd = "liveinfo_hello",
7393 .handler = liveinfo_hello,
7396 .cmd = "slave_list",
7397 .handler = liveinfo_slave_list,
7401 .handler = liveinfo_pkg_list,
7405 .handler = liveinfo_inst_list,
7408 .cmd = "slave_ctrl",
7409 .handler = liveinfo_slave_ctrl,
7413 .handler = liveinfo_pkg_ctrl,
7416 .cmd = "master_ctrl",
7417 .handler = liveinfo_master_ctrl,
7425 static struct method s_client_table[] = {
7427 .cmd = "pd_mouse_move",
7428 .handler = client_pd_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7431 .cmd = "lb_mouse_move",
7432 .handler = client_lb_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7435 .cmd = "pd_mouse_down",
7436 .handler = client_pd_mouse_down, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
7439 .cmd = "pd_mouse_up",
7440 .handler = client_pd_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7443 .cmd = "lb_mouse_down",
7444 .handler = client_lb_mouse_down, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7447 .cmd = "lb_mouse_up",
7448 .handler = client_lb_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7451 .cmd = "pd_mouse_enter",
7452 .handler = client_pd_mouse_enter, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
7455 .cmd = "pd_mouse_leave",
7456 .handler = client_pd_mouse_leave, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
7459 .cmd = "lb_mouse_enter",
7460 .handler = client_lb_mouse_enter, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7463 .cmd = "lb_mouse_leave",
7464 .handler = client_lb_mouse_leave, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
7467 .cmd = "lb_mouse_set",
7468 .handler = client_lb_mouse_set,
7471 .cmd = "lb_mouse_unset",
7472 .handler = client_lb_mouse_unset,
7475 .cmd = "pd_mouse_set",
7476 .handler = client_pd_mouse_set,
7479 .cmd = "pd_mouse_unset",
7480 .handler = client_pd_mouse_unset,
7483 .cmd = "change,visibility",
7484 .handler = client_change_visibility,
7487 .cmd = "lb_acquire_pixmap",
7488 .handler = client_lb_acquire_pixmap,
7491 .cmd = "lb_release_pixmap",
7492 .handler = client_lb_release_pixmap,
7495 .cmd = "pd_acquire_pixmap",
7496 .handler = client_pd_acquire_pixmap,
7499 .cmd = "pd_release_pixmap",
7500 .handler = client_pd_release_pixmap,
7504 .handler = client_acquire, /*!< pid, ret */
7508 .handler = cilent_release, /*!< pid, ret */
7512 .handler = client_clicked, /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
7515 .cmd = "text_signal",
7516 .handler = client_text_signal, /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
7520 .handler = client_delete, /* pid, pkgname, filename, ret */
7524 .handler = client_resize, /* pid, pkgname, filename, w, h, ret */
7528 .handler = client_new, /* pid, timestamp, pkgname, content, cluster, category, period, ret */
7531 .cmd = "set_period",
7532 .handler = client_set_period, /* pid, pkgname, filename, period, ret, period */
7535 .cmd = "change_group",
7536 .handler = client_change_group, /* pid, pkgname, filename, cluster, category, ret */
7539 .cmd = "pinup_changed",
7540 .handler = client_pinup_changed, /* pid, pkgname, filename, pinup, ret */
7544 .handler = client_create_pd, /* pid, pkgname, filename, ret */
7548 .handler = client_pd_move, /* pkgname, id, x, y */
7551 .cmd = "destroy_pd",
7552 .handler = client_destroy_pd, /* pid, pkgname, filename, ret */
7555 .cmd = "activate_package",
7556 .handler = client_activate_package, /* pid, pkgname, ret */
7559 .cmd = "subscribe", /* pid, cluster, sub-cluster */
7560 .handler = client_subscribed,
7563 .cmd = "unsubscribe", /* pid, cluster, sub-cluster */
7564 .handler = client_unsubscribed,
7567 .cmd = "delete_cluster",
7568 .handler = client_delete_cluster,
7571 .cmd = "delete_category",
7572 .handler = client_delete_category,
7575 .cmd = "refresh_group",
7576 .handler = client_refresh_group,
7580 .handler = client_update,
7584 .cmd = "pd_access_hl",
7585 .handler = client_pd_access_hl,
7588 .cmd = "pd_access_hl_prev",
7589 .handler = client_pd_access_hl_prev,
7592 .cmd = "pd_access_hl_next",
7593 .handler = client_pd_access_hl_next,
7596 .cmd = "pd_access_activate",
7597 .handler = client_pd_access_activate,
7600 .cmd = "pd_access_action_up",
7601 .handler = client_pd_access_action_up,
7604 .cmd = "pd_access_action_down",
7605 .handler = client_pd_access_action_down,
7608 .cmd = "pd_access_unhighlight",
7609 .handler = client_pd_access_unhighlight,
7612 .cmd = "pd_access_scroll_down",
7613 .handler = client_pd_access_scroll_down,
7616 .cmd = "pd_access_scroll_move",
7617 .handler = client_pd_access_scroll_move,
7620 .cmd = "pd_access_scroll_up",
7621 .handler = client_pd_access_scroll_up,
7625 .cmd = "lb_access_hl",
7626 .handler = client_lb_access_hl,
7629 .cmd = "lb_access_hl_prev",
7630 .handler = client_lb_access_hl_prev,
7633 .cmd = "lb_access_hl_next",
7634 .handler = client_lb_access_hl_next,
7637 .cmd = "lb_access_activate",
7638 .handler = client_lb_access_activate,
7641 .cmd = "lb_access_action_up",
7642 .handler = client_lb_access_action_up,
7645 .cmd = "lb_access_action_down",
7646 .handler = client_lb_access_action_down,
7649 .cmd = "lb_access_unhighlight",
7650 .handler = client_lb_access_unhighlight,
7653 .cmd = "lb_access_scroll_down",
7654 .handler = client_lb_access_scroll_down,
7657 .cmd = "lb_access_scroll_move",
7658 .handler = client_lb_access_scroll_move,
7661 .cmd = "lb_access_scroll_up",
7662 .handler = client_lb_access_scroll_up,
7666 .cmd = "lb_key_down",
7667 .handler = client_lb_key_down,
7671 .handler = client_lb_key_up,
7674 .cmd = "lb_key_focus_in",
7675 .handler = client_lb_key_focus_in,
7678 .cmd = "lb_key_focus_out",
7679 .handler = client_lb_key_focus_out,
7682 .cmd = "lb_key_set",
7683 .handler = client_lb_key_set,
7686 .cmd = "lb_key_unset",
7687 .handler = client_lb_key_unset,
7691 .cmd = "pd_key_down",
7692 .handler = client_pd_key_down,
7696 .handler = client_pd_key_up,
7699 .cmd = "pd_key_focus_in",
7700 .handler = client_pd_key_focus_in,
7703 .cmd = "pd_key_focus_out",
7704 .handler = client_pd_key_focus_out,
7707 .cmd = "pd_key_set",
7708 .handler = client_pd_key_set,
7711 .cmd = "pd_key_unset",
7712 .handler = client_pd_key_unset,
7716 .cmd = "client_paused",
7717 .handler = client_pause_request,
7720 .cmd = "client_resumed",
7721 .handler = client_resume_request,
7725 .cmd = "update_mode",
7726 .handler = client_update_mode,
7735 static struct method s_service_table[] = {
7737 .cmd = "service_update",
7738 .handler = service_update,
7741 .cmd = "service_change_period",
7742 .handler = service_change_period,
7750 static struct method s_slave_table[] = {
7753 .handler = slave_call, /* slave_name, pkgname, filename, function, ret */
7757 .handler = slave_ret, /* slave_name, pkgname, filename, function, ret */
7761 .handler = slave_updated, /* slave_name, pkgname, filename, width, height, priority, ret */
7764 .cmd = "desc_updated",
7765 .handler = slave_desc_updated, /* slave_name, pkgname, filename, decsfile, ret */
7769 .handler = slave_deleted, /* slave_name, pkgname, filename, ret */
7772 .cmd = "acquire_buffer",
7773 .handler = slave_acquire_buffer, /* slave_name, id, w, h, size, - out - type, shmid */
7776 .cmd = "resize_buffer",
7777 .handler = slave_resize_buffer,
7780 .cmd = "release_buffer",
7781 .handler = slave_release_buffer, /* slave_name, id - ret */
7785 .handler = slave_faulted, /* slave_name, pkgname, id, funcname */
7789 .handler = slave_hold_scroll, /* slave_name, pkgname, id, seize */
7793 .cmd = "lb_update_begin",
7794 .handler = slave_lb_update_begin,
7797 .cmd = "lb_update_end",
7798 .handler = slave_lb_update_end,
7801 .cmd = "pd_update_begin",
7802 .handler = slave_pd_update_begin,
7805 .cmd = "pd_update_end",
7806 .handler = slave_pd_update_end,
7810 .cmd = "access_status",
7811 .handler = slave_access_status,
7814 .cmd = "key_status",
7815 .handler = slave_key_status,
7819 .handler = slave_close_pd,
7824 .handler = slave_hello, /* slave_name, ret */
7828 .handler = slave_ping, /* slave_name, ret */
7837 HAPI int server_init(void)
7839 com_core_packet_use_thread(COM_CORE_THREAD);
7841 if (unlink(INFO_SOCKET) < 0) {
7842 ErrPrint("info socket: %s\n", strerror(errno));
7845 if (unlink(SLAVE_SOCKET) < 0) {
7846 ErrPrint("slave socket: %s\n", strerror(errno));
7849 if (unlink(CLIENT_SOCKET) < 0) {
7850 ErrPrint("client socket: %s\n", strerror(errno));
7853 if (unlink(SERVICE_SOCKET) < 0) {
7854 ErrPrint("service socket: %s\n", strerror(errno));
7857 s_info.info_fd = com_core_packet_server_init(INFO_SOCKET, s_info_table);
7858 if (s_info.info_fd < 0) {
7859 ErrPrint("Failed to create a info socket\n");
7862 s_info.slave_fd = com_core_packet_server_init(SLAVE_SOCKET, s_slave_table);
7863 if (s_info.slave_fd < 0) {
7864 ErrPrint("Failed to create a slave socket\n");
7867 s_info.client_fd = com_core_packet_server_init(CLIENT_SOCKET, s_client_table);
7868 if (s_info.client_fd < 0) {
7869 ErrPrint("Failed to create a client socket\n");
7875 * Skip address to use the NULL.
7877 s_info.remote_client_fd = com_core_packet_server_init("remote://:"CLIENT_PORT, s_client_table);
7878 if (s_info.client_fd < 0) {
7879 ErrPrint("Failed to create a remote client socket\n");
7882 s_info.service_fd = com_core_packet_server_init(SERVICE_SOCKET, s_service_table);
7883 if (s_info.service_fd < 0) {
7884 ErrPrint("Faild to create a service socket\n");
7887 if (chmod(INFO_SOCKET, 0600) < 0) {
7888 ErrPrint("info socket: %s\n", strerror(errno));
7891 if (chmod(SLAVE_SOCKET, 0666) < 0) {
7892 ErrPrint("slave socket: %s\n", strerror(errno));
7895 if (chmod(CLIENT_SOCKET, 0666) < 0) {
7896 ErrPrint("client socket: %s\n", strerror(errno));
7899 if (chmod(SERVICE_SOCKET, 0666) < 0) {
7900 ErrPrint("service socket: %s\n", strerror(errno));
7906 HAPI int server_fini(void)
7908 if (s_info.info_fd > 0) {
7909 com_core_packet_server_fini(s_info.info_fd);
7910 s_info.info_fd = -1;
7913 if (s_info.slave_fd > 0) {
7914 com_core_packet_server_fini(s_info.slave_fd);
7915 s_info.slave_fd = -1;
7918 if (s_info.client_fd > 0) {
7919 com_core_packet_server_fini(s_info.client_fd);
7920 s_info.client_fd = -1;
7923 if (s_info.remote_client_fd > 0) {
7924 com_core_packet_server_fini(s_info.remote_client_fd);
7925 s_info.remote_client_fd = -1;
7928 if (s_info.service_fd > 0) {
7929 com_core_packet_server_fini(s_info.service_fd);
7930 s_info.service_fd = -1;