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.
21 #include <sys/smack.h>
29 #include <com-core_packet.h>
30 #include <dynamicbox_errno.h>
31 #include <dynamicbox_service.h>
32 #include <dynamicbox_cmd_list.h>
33 #include <dynamicbox_conf.h>
34 #include <dynamicbox_script.h>
36 #include "critical_log.h"
40 #include "slave_life.h"
41 #include "slave_rpc.h"
42 #include "client_life.h"
44 #include "client_rpc.h"
46 #include "script_handler.h"
47 #include "buffer_handler.h"
49 #include "fault_manager.h"
57 #define GBAR_OPEN_MONITOR_TAG "gbar,open,monitor"
58 #define GBAR_RESIZE_MONITOR_TAG "gbar,resize,monitor"
59 #define GBAR_CLOSE_MONITOR_TAG "gbar,close,monitor"
61 #define LAZY_GBAR_OPEN_TAG "lazy,gbar,open"
62 #define LAZY_GBAR_CLOSE_TAG "lazy,gbar,close"
64 #define ACCESS_TYPE_DOWN 0
65 #define ACCESS_TYPE_MOVE 1
66 #define ACCESS_TYPE_UP 2
67 #define ACCESS_TYPE_CUR 0
68 #define ACCESS_TYPE_NEXT 1
69 #define ACCESS_TYPE_PREV 2
70 #define ACCESS_TYPE_OFF 3
83 .remote_client_fd = -1,
92 /* Share this with provider */
101 struct inst_info *inst;
104 struct deleted_item {
105 struct client_node *client;
106 struct inst_info *inst;
109 static Eina_Bool lazy_key_status_cb(void *data)
111 struct event_cbdata *cbdata = data;
113 if (instance_unref(cbdata->inst)) {
114 instance_send_key_status(cbdata->inst, cbdata->status);
116 DbgPrint("Skip sending key status (%d)\n", cbdata->status);
119 * If instance_unref returns NULL,
120 * The instance is destroyed. it means, we don't need to send event to the viewer
123 return ECORE_CALLBACK_CANCEL;
126 static Eina_Bool lazy_access_status_cb(void *data)
128 struct event_cbdata *cbdata = data;
130 if (instance_unref(cbdata->inst)) {
131 instance_send_access_status(cbdata->inst, cbdata->status);
133 DbgPrint("Skip sending access status (%d)\n", cbdata->status);
136 * If instance_unref returns NULL,
137 * The instance is destroyed. it means, we don't need to send event to the viewer
140 return ECORE_CALLBACK_CANCEL;
143 int send_delayed_key_status(struct inst_info *inst, int ret)
145 struct event_cbdata *cbdata;
147 cbdata = malloc(sizeof(*cbdata));
149 ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
151 cbdata->inst = instance_ref(inst);
152 cbdata->status = ret;
154 if (!ecore_timer_add(DELAY_TIME, lazy_key_status_cb, cbdata)) {
155 (void)instance_unref(cbdata->inst);
157 ret = DBOX_STATUS_ERROR_FAULT;
159 ret = DBOX_STATUS_ERROR_NONE;
166 int send_delayed_access_status(struct inst_info *inst, int ret)
168 struct event_cbdata *cbdata;
170 cbdata = malloc(sizeof(*cbdata));
172 ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
174 cbdata->inst = instance_ref(inst);
175 cbdata->status = ret;
177 if (!ecore_timer_add(DELAY_TIME, lazy_access_status_cb, cbdata)) {
178 (void)instance_unref(cbdata->inst);
180 ret = DBOX_STATUS_ERROR_FAULT;
182 ret = DBOX_STATUS_ERROR_NONE;
189 static int forward_dbox_event_packet(const struct pkg_info *pkg, struct inst_info *inst, const struct packet *packet)
191 struct buffer_info *buffer;
192 struct slave_node *slave;
195 buffer = instance_dbox_buffer(inst);
197 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
198 ret = DBOX_STATUS_ERROR_FAULT;
202 slave = package_slave(pkg);
204 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
205 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
209 packet_ref((struct packet *)packet);
210 ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0);
216 static int forward_gbar_event_packet(const struct pkg_info *pkg, struct inst_info *inst, const struct packet *packet)
218 struct buffer_info *buffer;
219 struct slave_node *slave;
222 buffer = instance_gbar_buffer(inst);
224 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
225 ret = DBOX_STATUS_ERROR_FAULT;
229 slave = package_slave(pkg);
231 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
232 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
236 packet_ref((struct packet *)packet);
237 ret = slave_rpc_request_only(slave, package_name(pkg), (struct packet *)packet, 0);
243 static int forward_gbar_access_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, struct access_info *event)
246 struct buffer_info *buffer;
247 struct slave_node *slave;
250 buffer = instance_gbar_buffer(inst);
252 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
253 ret = DBOX_STATUS_ERROR_FAULT;
257 slave = package_slave(pkg);
259 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
260 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
264 p = packet_create_noack(command, "ssdiii", package_name(pkg), instance_id(inst), timestamp, event->x, event->y, event->type);
265 ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
271 static int forward_dbox_access_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, struct access_info *event)
274 struct buffer_info *buffer;
275 struct slave_node *slave;
278 buffer = instance_dbox_buffer(inst);
280 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
281 ret = DBOX_STATUS_ERROR_FAULT;
285 slave = package_slave(pkg);
287 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
288 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
292 p = packet_create_noack(command, "ssdiii", package_name(pkg), instance_id(inst), timestamp, event->x, event->y, event->type);
293 ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
299 static int forward_gbar_key_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, unsigned int keycode)
302 struct buffer_info *buffer;
303 struct slave_node *slave;
306 buffer = instance_dbox_buffer(inst);
308 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
309 ret = DBOX_STATUS_ERROR_FAULT;
313 slave = package_slave(pkg);
315 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
316 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
320 p = packet_create_noack(command, "ssdi", package_name(pkg), instance_id(inst), timestamp, keycode);
321 ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
327 static int forward_dbox_key_packet(const struct pkg_info *pkg, struct inst_info *inst, const char *command, double timestamp, unsigned int keycode)
330 struct buffer_info *buffer;
331 struct slave_node *slave;
334 buffer = instance_dbox_buffer(inst);
336 ErrPrint("Instance[%s] has no buffer\n", instance_id(inst));
337 ret = DBOX_STATUS_ERROR_FAULT;
341 slave = package_slave(pkg);
343 ErrPrint("Package[%s] has no slave\n", package_name(pkg));
344 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
348 p = packet_create_noack(command, "ssdi", package_name(pkg), instance_id(inst), timestamp, keycode);
349 ret = slave_rpc_request_only(slave, package_name(pkg), p, 0);
355 static int slave_fault_open_script_cb(struct slave_node *slave, void *data)
359 (void)script_handler_unload(instance_gbar_script(data), 1);
360 (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT);
361 (void)instance_client_gbar_created(data, DBOX_STATUS_ERROR_FAULT);
363 timer = instance_del_data(data, LAZY_GBAR_OPEN_TAG);
365 ecore_timer_del(timer);
368 (void)instance_unref(data);
370 return -1; /* remove this handler */
373 static int slave_fault_open_buffer_cb(struct slave_node *slave, void *data)
377 (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT);
378 (void)instance_client_gbar_created(data, DBOX_STATUS_ERROR_FAULT);
380 timer = instance_del_data(data, GBAR_OPEN_MONITOR_TAG);
382 ecore_timer_del(timer);
385 (void)instance_unref(data);
387 return -1; /* remove this handler */
390 static int slave_fault_close_script_cb(struct slave_node *slave, void *data)
394 (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT);
396 timer = instance_del_data(data, LAZY_GBAR_CLOSE_TAG);
398 ecore_timer_del(timer);
401 (void)instance_unref(data);
403 return -1; /* remove this handler */
406 static int slave_fault_close_buffer_cb(struct slave_node *slave, void *data)
410 (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT);
412 timer = instance_del_data(data, LAZY_GBAR_CLOSE_TAG);
414 timer = instance_del_data(data, GBAR_CLOSE_MONITOR_TAG);
418 ecore_timer_del(timer);
421 (void)instance_unref(data);
423 return -1; /* remove this handler */
426 static int slave_fault_resize_buffer_cb(struct slave_node *slave, void *data)
430 (void)instance_slave_close_gbar(data, instance_gbar_owner(data), DBOX_CLOSE_GBAR_FAULT);
431 (void)instance_client_gbar_destroyed(data, DBOX_STATUS_ERROR_FAULT);
433 timer = instance_del_data(data, GBAR_RESIZE_MONITOR_TAG);
435 ecore_timer_del(timer);
438 (void)instance_unref(data);
440 return -1; /* remove this handler */
443 static int key_event_dbox_route_cb(enum event_state state, struct event_data *event_info, void *data)
445 struct inst_info *inst = data;
446 const struct pkg_info *pkg;
447 struct slave_node *slave;
448 struct packet *packet;
452 DbgPrint("Instance is deleted.\n");
453 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
456 pkg = instance_package(inst);
458 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
461 slave = package_slave(pkg);
463 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
467 case EVENT_STATE_ACTIVATE:
468 cmd = CMD_DBOX_KEY_DOWN;
470 case EVENT_STATE_ACTIVATED:
471 cmd = CMD_DBOX_KEY_DOWN;
473 case EVENT_STATE_DEACTIVATE:
474 cmd = CMD_DBOX_KEY_UP;
477 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
480 packet = packet_create_noack((const char *)&cmd, "ssdi", package_name(pkg), instance_id(inst), event_info->tv, event_info->keycode);
482 return DBOX_STATUS_ERROR_FAULT;
485 return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
488 static int mouse_event_dbox_route_cb(enum event_state state, struct event_data *event_info, void *data)
490 struct inst_info *inst = data;
491 const struct pkg_info *pkg;
492 struct slave_node *slave;
493 struct packet *packet;
497 DbgPrint("Instance is deleted.\n");
498 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
501 pkg = instance_package(inst);
503 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
506 slave = package_slave(pkg);
508 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
512 case EVENT_STATE_ACTIVATE:
513 cmd = CMD_DBOX_MOUSE_DOWN;
515 case EVENT_STATE_ACTIVATED:
516 cmd = CMD_DBOX_MOUSE_MOVE;
518 case EVENT_STATE_DEACTIVATE:
519 cmd = CMD_DBOX_MOUSE_UP;
522 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
525 packet = packet_create_noack((const char *)&cmd, "ssdii", package_name(pkg), instance_id(inst), event_info->tv, event_info->x, event_info->y);
527 return DBOX_STATUS_ERROR_FAULT;
530 return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
533 static int key_event_dbox_consume_cb(enum event_state state, struct event_data *event_info, void *data)
535 struct script_info *script;
536 struct inst_info *inst = data;
537 const struct pkg_info *pkg;
540 pkg = instance_package(inst);
545 script = instance_dbox_script(inst);
547 return DBOX_STATUS_ERROR_FAULT;
550 timestamp = event_info->tv;
553 case EVENT_STATE_ACTIVATE:
554 script_handler_update_keycode(script, event_info->keycode);
555 (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
557 case EVENT_STATE_ACTIVATED:
558 script_handler_update_keycode(script, event_info->keycode);
559 (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
561 case EVENT_STATE_DEACTIVATE:
562 script_handler_update_keycode(script, event_info->keycode);
563 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp);
566 ErrPrint("Unknown event\n");
573 static int mouse_event_dbox_consume_cb(enum event_state state, struct event_data *event_info, void *data)
575 struct script_info *script;
576 struct inst_info *inst = data;
577 const struct pkg_info *pkg;
580 pkg = instance_package(inst);
585 script = instance_dbox_script(inst);
587 return DBOX_STATUS_ERROR_FAULT;
590 timestamp = event_info->tv;
593 case EVENT_STATE_ACTIVATE:
594 script_handler_update_pointer(script, event_info->x, event_info->y, 1);
595 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp);
597 case EVENT_STATE_ACTIVATED:
598 script_handler_update_pointer(script, event_info->x, event_info->y, -1);
599 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp);
601 case EVENT_STATE_DEACTIVATE:
602 script_handler_update_pointer(script, event_info->x, event_info->y, 0);
603 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp);
612 static int key_event_gbar_route_cb(enum event_state state, struct event_data *event_info, void *data)
614 struct inst_info *inst = data;
615 const struct pkg_info *pkg;
616 struct slave_node *slave;
617 struct packet *packet;
621 DbgPrint("Instance is deleted.\n");
622 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
625 pkg = instance_package(inst);
627 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
630 slave = package_slave(pkg);
632 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
636 case EVENT_STATE_ACTIVATE:
637 cmd = CMD_GBAR_KEY_DOWN;
639 case EVENT_STATE_ACTIVATED:
640 cmd = CMD_GBAR_KEY_DOWN;
642 case EVENT_STATE_DEACTIVATE:
643 cmd = CMD_GBAR_KEY_UP;
646 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
649 packet = packet_create_noack((const char *)&cmd, "ssdi", package_name(pkg), instance_id(inst), event_info->tv, event_info->keycode);
651 return DBOX_STATUS_ERROR_FAULT;
654 return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
657 static int mouse_event_gbar_route_cb(enum event_state state, struct event_data *event_info, void *data)
659 struct inst_info *inst = data;
660 const struct pkg_info *pkg;
661 struct slave_node *slave;
662 struct packet *packet;
666 DbgPrint("Instance is deleted.\n");
667 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
670 pkg = instance_package(inst);
672 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
675 slave = package_slave(pkg);
677 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
681 case EVENT_STATE_ACTIVATE:
682 cmd = CMD_GBAR_MOUSE_DOWN;
684 case EVENT_STATE_ACTIVATED:
685 cmd = CMD_GBAR_MOUSE_MOVE;
687 case EVENT_STATE_DEACTIVATE:
688 cmd = CMD_GBAR_MOUSE_UP;
691 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
694 packet = packet_create_noack((const char *)&cmd, "ssdii", package_name(pkg), instance_id(inst), event_info->tv, event_info->x, event_info->y);
696 return DBOX_STATUS_ERROR_FAULT;
699 return slave_rpc_request_only(slave, package_name(pkg), packet, 0);
702 static int key_event_gbar_consume_cb(enum event_state state, struct event_data *event_info, void *data)
704 struct script_info *script;
705 struct inst_info *inst = data;
706 const struct pkg_info *pkg;
709 pkg = instance_package(inst);
714 script = instance_gbar_script(inst);
716 return DBOX_STATUS_ERROR_FAULT;
719 timestamp = event_info->tv;
722 case EVENT_STATE_ACTIVATE:
723 script_handler_update_keycode(script, event_info->keycode);
724 (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
726 case EVENT_STATE_ACTIVATED:
727 script_handler_update_keycode(script, event_info->keycode);
728 (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
730 case EVENT_STATE_DEACTIVATE:
731 script_handler_update_keycode(script, event_info->keycode);
732 (void)script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp);
735 ErrPrint("Unknown event\n");
742 static int mouse_event_gbar_consume_cb(enum event_state state, struct event_data *event_info, void *data)
744 struct script_info *script;
745 struct inst_info *inst = data;
746 const struct pkg_info *pkg;
749 pkg = instance_package(inst);
754 script = instance_gbar_script(inst);
756 return DBOX_STATUS_ERROR_FAULT;
759 timestamp = event_info->tv;
762 case EVENT_STATE_ACTIVATE:
763 script_handler_update_pointer(script, event_info->x, event_info->y, 1);
764 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp);
766 case EVENT_STATE_ACTIVATED:
767 script_handler_update_pointer(script, event_info->x, event_info->y, -1);
768 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp);
770 case EVENT_STATE_DEACTIVATE:
771 script_handler_update_pointer(script, event_info->x, event_info->y, 0);
772 (void)script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp);
780 static struct packet *client_acquire(pid_t pid, int handle, const struct packet *packet) /*!< timestamp, ret */
782 struct client_node *client;
783 struct packet *result;
784 const char *direct_addr;
788 client = client_find_by_rpc_handle(handle);
790 ErrPrint("Client is already exists %d\n", pid);
791 ret = DBOX_STATUS_ERROR_EXIST;
795 if (packet_get(packet, "ds", ×tamp, &direct_addr) != 2) {
796 ErrPrint("Invalid arguemnt\n");
797 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
804 * client_create will invoke the client created callback
806 client = client_create(pid, handle, direct_addr);
808 ErrPrint("Failed to create a new client for %d\n", pid);
809 ret = DBOX_STATUS_ERROR_FAULT;
813 result = packet_create_reply(packet, "ii", ret, DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT);
815 ErrPrint("Failed to create a packet\n");
821 static struct packet *cilent_release(pid_t pid, int handle, const struct packet *packet) /*!< pid, ret */
823 struct client_node *client;
824 struct packet *result;
827 client = client_find_by_rpc_handle(handle);
829 ErrPrint("Client %d is not exists\n", pid);
830 ret = DBOX_STATUS_ERROR_NOT_EXIST;
834 client_destroy(client);
838 result = packet_create_reply(packet, "i", ret);
840 ErrPrint("Failed to create a packet\n");
846 static int validate_request(const char *pkgname, const char *id, struct inst_info **out_inst, const struct pkg_info **out_pkg)
848 struct inst_info *inst;
849 const struct pkg_info *pkg;
851 inst = package_find_instance_by_id(pkgname, id);
853 ErrPrint("Instance is not exists (%s)\n", id);
854 return DBOX_STATUS_ERROR_NOT_EXIST;
857 pkg = instance_package(inst);
859 ErrPrint("System error - instance has no package?\n");
860 return DBOX_STATUS_ERROR_INVALID_PARAMETER;
863 if (package_is_fault(pkg)) {
864 ErrPrint("Faulted package: %s\n", pkgname);
865 return DBOX_STATUS_ERROR_FAULT;
876 return DBOX_STATUS_ERROR_NONE;
879 /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
880 static struct packet *client_clicked(pid_t pid, int handle, const struct packet *packet)
882 struct client_node *client;
890 struct inst_info *inst;
892 client = client_find_by_rpc_handle(handle);
894 ErrPrint("Client %d is not exists\n", pid);
898 ret = packet_get(packet, "sssddd", &pkgname, &id, &event, ×tamp, &x, &y);
900 ErrPrint("Parameter is not matched\n");
906 * Trust the package name which are sent by the client.
907 * The package has to be a dynamicbox package name.
909 ret = validate_request(pkgname, id, &inst, NULL);
910 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
911 (void)instance_clicked(inst, event, timestamp, x, y);
915 /*! \note No reply packet */
919 static struct packet *client_update_mode(pid_t pid, int handle, const struct packet *packet)
921 struct packet *result;
922 struct client_node *client;
927 struct inst_info *inst;
929 client = client_find_by_rpc_handle(handle);
931 ErrPrint("Client %d is not exists\n", pid);
932 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
936 ret = packet_get(packet, "ssi", &pkgname, &id, &active_update);
938 ErrPrint("Invalid argument\n");
939 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
943 ret = validate_request(pkgname, id, &inst, NULL);
944 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
947 * Send change update mode request to a slave
949 ret = instance_set_update_mode(inst, active_update);
953 result = packet_create_reply(packet, "i", ret);
955 ErrPrint("Failed to create a packet\n");
961 /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
962 static struct packet *client_text_signal(pid_t pid, int handle, const struct packet *packet)
964 struct client_node *client;
965 struct packet *result;
968 const char *emission;
974 struct inst_info *inst = NULL;
977 client = client_find_by_rpc_handle(handle);
979 ErrPrint("Client %d is not exists\n", pid);
980 ret = DBOX_STATUS_ERROR_NOT_EXIST;
984 ret = packet_get(packet, "ssssdddd", &pkgname, &id, &emission, &source, &sx, &sy, &ex, &ey);
986 ErrPrint("Parameter is not matched\n");
987 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
993 * Trust the package name which are sent by the client.
994 * The package has to be a dynamicbox package name.
996 ret = validate_request(pkgname, id, &inst, NULL);
997 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
998 ret = instance_text_signal_emit(inst, emission, source, sx, sy, ex, ey);
1002 result = packet_create_reply(packet, "i", ret);
1004 ErrPrint("Failed to create a packet\n");
1010 static Eina_Bool lazy_delete_cb(void *data)
1012 struct deleted_item *item = data;
1014 DbgPrint("Lazy delete callback called\n");
1016 * Before invoke this callback, the instance is able to already remove this client
1019 if (instance_has_client(item->inst, item->client)) {
1020 (void)instance_unicast_deleted_event(item->inst, item->client, DBOX_STATUS_ERROR_NONE);
1021 (void)instance_del_client(item->inst, item->client);
1024 (void)client_unref(item->client);
1025 (void)instance_unref(item->inst);
1027 return ECORE_CALLBACK_CANCEL;
1030 static struct packet *client_delete(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
1032 struct client_node *client;
1033 struct packet *result;
1034 const char *pkgname;
1036 struct inst_info *inst;
1037 const struct pkg_info *pkg;
1042 client = client_find_by_rpc_handle(handle);
1044 ErrPrint("Client %d is not exists\n", pid);
1045 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1049 ret = packet_get(packet, "ssid", &pkgname, &id, &type, ×tamp);
1051 ErrPrint("Parameter is not matched\n");
1052 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1057 * Below two types must has to be sync'd with dynamicbox-viewer
1059 * DBOX_DELETE_PERMANENTLY = 0x01,
1060 * DBOX_DELETE_TEMPORARY = 0x02,
1066 * Trust the package name which are sent by the client.
1067 * The package has to be a dynamicbox package name.
1069 ret = validate_request(pkgname, id, &inst, &pkg);
1070 if (ret != DBOX_STATUS_ERROR_NONE) {
1071 DbgPrint("Failed to find by id(%s), try to find it using timestamp(%lf)\n", id, timestamp);
1072 inst = package_find_instance_by_timestamp(pkgname, timestamp);
1077 pkg = instance_package(inst);
1079 ErrPrint("Package info is not valid: %s\n", id);
1084 if (package_is_fault(pkg)) {
1085 DbgPrint("Faulted package. will be deleted soon: %s\n", id);
1086 ret = DBOX_STATUS_ERROR_FAULT;
1090 if (instance_client(inst) != client) {
1091 if (instance_has_client(inst, client)) {
1092 struct deleted_item *item;
1094 item = malloc(sizeof(*item));
1096 ErrPrint("Heap: %s\n", strerror(errno));
1097 ret = DBOX_STATUS_ERROR_OUT_OF_MEMORY;
1101 * Send DELETED EVENT to the client.
1102 * after return from this function.
1104 * Client will prepare the deleted event after get this function's return value.
1105 * So We have to make a delay to send a deleted event.
1108 item->client = client_ref(client);
1109 item->inst = instance_ref(inst);
1111 if (!ecore_timer_add(DELAY_TIME, lazy_delete_cb, item)) {
1112 ErrPrint("Failed to add a delayzed delete callback\n");
1113 (void)client_unref(client);
1114 (void)instance_unref(inst);
1116 ret = DBOX_STATUS_ERROR_FAULT;
1118 ret = DBOX_STATUS_ERROR_NONE;
1122 ErrPrint("Client has no permission\n");
1123 ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
1127 case DBOX_DELETE_PERMANENTLY:
1128 ret = instance_destroy(inst, DBOX_DESTROY_TYPE_DEFAULT);
1130 case DBOX_DELETE_TEMPORARY:
1131 ret = instance_destroy(inst, DBOX_DESTROY_TYPE_TEMPORARY);
1139 result = packet_create_reply(packet, "i", ret);
1141 ErrPrint("Failed to create a packet\n");
1147 static struct packet *client_resize(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, w, h, ret */
1149 struct client_node *client;
1150 struct packet *result;
1151 const char *pkgname;
1155 struct inst_info *inst = NULL;
1158 client = client_find_by_rpc_handle(handle);
1160 ErrPrint("Client %d is not exists\n", pid);
1161 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1165 ret = packet_get(packet, "ssii", &pkgname, &id, &w, &h);
1167 ErrPrint("Parameter is not matched\n");
1168 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1172 DbgPrint("RESIZE: Client request resize to %dx%d (pid: %d, pkgname: %s)\n", w, h, pid, pkgname);
1176 * Trust the package name which are sent by the client.
1177 * The package has to be a dynamicbox package name.
1179 ret = validate_request(pkgname, id, &inst, NULL);
1180 if (ret != DBOX_STATUS_ERROR_NONE) {
1184 if (instance_client(inst) != client) {
1185 ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
1187 ret = instance_resize(inst, w, h);
1191 result = packet_create_reply(packet, "i", ret);
1193 ErrPrint("Failed to create a packet\n");
1199 static struct packet *client_new(pid_t pid, int handle, const struct packet *packet) /* pid, timestamp, pkgname, content, cluster, category, period, ret */
1201 struct client_node *client;
1202 struct packet *result;
1203 const char *pkgname;
1204 const char *content;
1205 const char *cluster;
1206 const char *category;
1210 struct pkg_info *info;
1216 client = client_find_by_rpc_handle(handle);
1218 ErrPrint("Client %d is not exists\n", pid);
1219 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1223 ret = packet_get(packet, "dssssdii", ×tamp, &pkgname, &content, &cluster, &category, &period, &width, &height);
1225 ErrPrint("Parameter is not matched\n");
1226 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1230 DbgPrint("pid[%d] period[%lf] pkgname[%s] content[%s] cluster[%s] category[%s] period[%lf]\n",
1231 pid, timestamp, pkgname, content, cluster, category, period);
1233 lbid = package_dbox_pkgname(pkgname);
1235 ErrPrint("This %s has no dynamicbox package\n", pkgname);
1236 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1240 mainappid = dynamicbox_service_mainappid(lbid);
1241 if (!package_is_enabled(mainappid)) {
1244 ret = DBOX_STATUS_ERROR_DISABLED;
1249 info = package_find(lbid);
1252 pkgid = dynamicbox_service_package_id(lbid);
1256 ret = DBOX_STATUS_ERROR_FAULT;
1260 info = package_create(pkgid, lbid);
1265 ret = DBOX_STATUS_ERROR_FAULT;
1266 } else if (package_is_fault(info)) {
1267 ret = DBOX_STATUS_ERROR_FAULT;
1268 } else if (util_free_space(DYNAMICBOX_CONF_IMAGE_PATH) <= DYNAMICBOX_CONF_MINIMUM_SPACE) {
1269 ErrPrint("Not enough space\n");
1270 ret = DBOX_STATUS_ERROR_NO_SPACE;
1272 struct inst_info *inst;
1274 if (period > 0.0f && period < DYNAMICBOX_CONF_MINIMUM_PERIOD) {
1275 period = DYNAMICBOX_CONF_MINIMUM_PERIOD;
1278 inst = instance_create(client, timestamp, lbid, content, cluster, category, period, width, height);
1281 * Using the "inst" without validate its value is at my disposal. ;)
1283 ret = inst ? 0 : DBOX_STATUS_ERROR_FAULT;
1289 result = packet_create_reply(packet, "i", ret);
1291 ErrPrint("Failed to create a packet\n");
1297 static struct packet *client_change_visibility(pid_t pid, int handle, const struct packet *packet)
1299 struct client_node *client;
1300 const char *pkgname;
1302 enum dynamicbox_visible_state state;
1304 struct inst_info *inst;
1306 client = client_find_by_rpc_handle(handle);
1308 ErrPrint("Client %d is not exists\n", pid);
1309 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1313 ret = packet_get(packet, "ssi", &pkgname, &id, (int *)&state);
1315 ErrPrint("Parameter is not matched\n");
1316 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1322 * Trust the package name which are sent by the client.
1323 * The package has to be a dynamicbox package name.
1325 ret = validate_request(pkgname, id, &inst, NULL);
1326 if (ret != DBOX_STATUS_ERROR_NONE) {
1330 if (instance_client(inst) != client) {
1331 ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
1333 ret = instance_set_visible_state(inst, state);
1337 /*! \note No reply packet */
1341 static struct packet *client_set_period(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, period, ret */
1343 struct client_node *client;
1344 struct packet *result;
1345 const char *pkgname;
1349 struct inst_info *inst = NULL;
1351 client = client_find_by_rpc_handle(handle);
1353 ErrPrint("Client %d is not exists\n", pid);
1354 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1358 ret = packet_get(packet, "ssd", &pkgname, &id, &period);
1360 ErrPrint("Parameter is not matched\n");
1361 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1365 DbgPrint("pid[%d] pkgname[%s] period[%lf]\n", pid, pkgname, period);
1369 * Trust the package name which are sent by the client.
1370 * The package has to be a dynamicbox package name.
1372 ret = validate_request(pkgname, id, &inst, NULL);
1373 if (ret != DBOX_STATUS_ERROR_NONE) {
1377 if (instance_client(inst) != client) {
1378 ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
1380 ret = instance_set_period(inst, period);
1384 result = packet_create_reply(packet, "i", ret);
1386 ErrPrint("Failed to create a packet\n");
1392 static struct packet *client_change_group(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, cluster, category, ret */
1394 struct client_node *client;
1395 struct packet *result;
1396 const char *pkgname;
1398 const char *cluster;
1399 const char *category;
1400 struct inst_info *inst = NULL;
1403 client = client_find_by_rpc_handle(handle);
1405 ErrPrint("Client %d is not exists\n", pid);
1406 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1410 ret = packet_get(packet, "ssss", &pkgname, &id, &cluster, &category);
1412 ErrPrint("Parameter is not matched\n");
1413 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1417 DbgPrint("pid[%d] pkgname[%s] cluster[%s] category[%s]\n", pid, pkgname, cluster, category);
1421 * Trust the package name which are sent by the client.
1422 * The package has to be a dynamicbox package name.
1424 ret = validate_request(pkgname, id, &inst, NULL);
1425 if (ret != DBOX_STATUS_ERROR_NONE) {
1429 if (instance_client(inst) != client) {
1430 ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
1432 ret = instance_change_group(inst, cluster, category);
1436 result = packet_create_reply(packet, "i", ret);
1438 ErrPrint("Failed to create a packet\n");
1444 static struct packet *client_gbar_mouse_enter(pid_t pid, int handle, const struct packet *packet)
1446 struct client_node *client;
1447 const char *pkgname;
1453 struct inst_info *inst;
1454 const struct pkg_info *pkg;
1456 client = client_find_by_rpc_handle(handle);
1458 ErrPrint("Client %d is not exists\n", pid);
1459 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1463 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1465 ErrPrint("Invalid parameter\n");
1466 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1470 ret = validate_request(pkgname, id, &inst, &pkg);
1471 if (ret != DBOX_STATUS_ERROR_NONE) {
1475 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
1476 ret = forward_gbar_event_packet(pkg, inst, packet);
1477 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
1478 struct script_info *script;
1480 script = instance_gbar_script(inst);
1482 ret = DBOX_STATUS_ERROR_FAULT;
1486 script_handler_update_pointer(script, x, y, -1);
1487 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_IN, timestamp);
1490 ErrPrint("Unsupported package\n");
1491 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1495 /*! \note No reply packet */
1499 static struct packet *client_gbar_mouse_leave(pid_t pid, int handle, const struct packet *packet)
1501 struct client_node *client;
1502 const char *pkgname;
1508 struct inst_info *inst;
1509 const struct pkg_info *pkg;
1511 client = client_find_by_rpc_handle(handle);
1513 ErrPrint("Client %d is not exists\n", pid);
1514 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1518 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1520 ErrPrint("Parameter is not matched\n");
1521 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1525 ret = validate_request(pkgname, id, &inst, &pkg);
1526 if (ret != DBOX_STATUS_ERROR_NONE) {
1530 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
1531 ret = forward_gbar_event_packet(pkg, inst, packet);
1532 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
1533 struct script_info *script;
1535 script = instance_gbar_script(inst);
1537 ret = DBOX_STATUS_ERROR_FAULT;
1541 script_handler_update_pointer(script, x, y, -1);
1542 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OUT, timestamp);
1545 ErrPrint("Unsupported package\n");
1546 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1550 /*! \note No reply packet */
1554 static struct packet *client_gbar_mouse_down(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, id, width, height, timestamp, x, y, ret */
1556 struct client_node *client;
1557 const char *pkgname;
1563 struct inst_info *inst;
1564 const struct pkg_info *pkg;
1566 client = client_find_by_rpc_handle(handle);
1568 ErrPrint("Client %d is not exists\n", pid);
1569 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1573 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1575 ErrPrint("Parameter is not matched\n");
1576 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1580 ret = validate_request(pkgname, id, &inst, &pkg);
1581 if (ret != DBOX_STATUS_ERROR_NONE) {
1585 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
1586 ret = forward_gbar_event_packet(pkg, inst, packet);
1587 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
1588 struct script_info *script;
1590 script = instance_gbar_script(inst);
1592 ret = DBOX_STATUS_ERROR_FAULT;
1596 script_handler_update_pointer(script, x, y, 1);
1597 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp);
1600 ErrPrint("Unsupported package\n");
1601 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1605 /*! \note No reply packet */
1609 static struct packet *client_gbar_mouse_up(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
1611 struct client_node *client;
1612 const char *pkgname;
1618 struct inst_info *inst;
1619 const struct pkg_info *pkg;
1621 client = client_find_by_rpc_handle(handle);
1623 ErrPrint("Client %d is not exists\n", pid);
1624 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1628 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1630 ErrPrint("Parameter is not matched\n");
1631 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1635 ret = validate_request(pkgname, id, &inst, &pkg);
1636 if (ret != DBOX_STATUS_ERROR_NONE) {
1640 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
1641 ret = forward_gbar_event_packet(pkg, inst, packet);
1642 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
1643 struct script_info *script;
1645 script = instance_gbar_script(inst);
1647 ret = DBOX_STATUS_ERROR_FAULT;
1651 script_handler_update_pointer(script, x, y, 0);
1652 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp);
1655 ErrPrint("Unsupported package\n");
1656 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1660 /*! \note No reply packet */
1664 static struct packet *client_gbar_mouse_move(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
1666 struct client_node *client;
1667 const char *pkgname;
1673 struct inst_info *inst;
1674 const struct pkg_info *pkg;
1676 client = client_find_by_rpc_handle(handle);
1678 ErrPrint("Client %d is not exists\n", pid);
1679 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1683 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1685 ErrPrint("Parameter is not matched\n");
1686 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1690 ret = validate_request(pkgname, id, &inst, &pkg);
1691 if (ret != DBOX_STATUS_ERROR_NONE) {
1695 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
1696 ret = forward_gbar_event_packet(pkg, inst, packet);
1697 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
1698 struct script_info *script;
1700 script = instance_gbar_script(inst);
1702 ret = DBOX_STATUS_ERROR_FAULT;
1706 script_handler_update_pointer(script, x, y, -1);
1707 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp);
1710 ErrPrint("Unsupported package\n");
1711 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1715 /*! \note No reply packet */
1719 static struct packet *client_dbox_mouse_move(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
1721 struct client_node *client;
1722 const char *pkgname;
1728 struct inst_info *inst;
1729 const struct pkg_info *pkg;
1731 client = client_find_by_rpc_handle(handle);
1733 ErrPrint("Client %d is not exists\n", pid);
1734 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1738 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
1740 ErrPrint("Parameter is not matched\n");
1741 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1745 ret = validate_request(pkgname, id, &inst, &pkg);
1746 if (ret != DBOX_STATUS_ERROR_NONE) {
1750 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
1751 ret = forward_dbox_event_packet(pkg, inst, packet);
1752 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
1753 struct script_info *script;
1755 script = instance_dbox_script(inst);
1757 ret = DBOX_STATUS_ERROR_FAULT;
1761 script_handler_update_pointer(script, x, y, -1);
1762 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_MOVE, timestamp);
1765 ErrPrint("Unsupported package\n");
1766 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1770 /*! \note No reply packet */
1774 static int inst_del_cb(struct inst_info *inst, void *data)
1779 * If you deactivate the event thread,
1780 * It will calls event callbacks.
1781 * And the event callbacks will try to access the "inst"
1783 (void)event_deactivate(data, inst);
1785 /* Reset callback data to prevent accessing inst from event callback */
1786 ret = event_reset_cbdata(data, inst, NULL);
1787 DbgPrint("Instance delete callback called: %s (%d)\n", instance_id(inst), ret);
1789 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1790 (void)slave_set_priority(package_slave(instance_package(inst)), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
1793 return -1; /* Delete this callback */
1797 static struct packet *client_gbar_key_set(pid_t pid, int handle, const struct packet *packet)
1799 struct client_node *client;
1800 const char *pkgname;
1804 unsigned int keycode;
1805 struct inst_info *inst;
1806 const struct pkg_info *pkg;
1807 struct packet *result;
1809 client = client_find_by_rpc_handle(handle);
1811 ErrPrint("Client %d is not exists\n", pid);
1812 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1816 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
1818 ErrPrint("Parameter is not matched\n");
1819 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1823 ret = validate_request(pkgname, id, &inst, &pkg);
1824 if (ret != DBOX_STATUS_ERROR_NONE) {
1828 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
1829 ret = event_activate(0, 0, key_event_gbar_route_cb, inst);
1830 if (ret == DBOX_STATUS_ERROR_NONE) {
1831 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1832 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
1834 if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb) <= 0) {
1835 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb);
1838 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
1839 ret = event_activate(0, 0, key_event_gbar_consume_cb, inst);
1840 if (ret == DBOX_STATUS_ERROR_NONE) {
1841 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1842 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
1844 if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb) <= 0) {
1845 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb);
1849 ErrPrint("Unsupported package\n");
1850 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1854 result = packet_create_reply(packet, "i", ret);
1856 ErrPrint("Failed to create a reply packet\n");
1862 static struct packet *client_gbar_key_unset(pid_t pid, int handle, const struct packet *packet)
1864 struct client_node *client;
1865 const char *pkgname;
1869 unsigned int keycode;
1870 struct inst_info *inst;
1871 const struct pkg_info *pkg;
1872 struct packet *result;
1874 client = client_find_by_rpc_handle(handle);
1876 ErrPrint("Client %d is not exists\n", pid);
1877 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1881 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
1883 ErrPrint("Parameter is not matched\n");
1884 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1888 ret = validate_request(pkgname, id, &inst, &pkg);
1889 if (ret != DBOX_STATUS_ERROR_NONE) {
1893 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
1894 ret = event_deactivate(key_event_gbar_route_cb, inst);
1895 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1896 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
1899 * This delete callback will be removed when the instance will be destroyed.
1901 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_route_cb);
1904 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
1905 ret = event_deactivate(key_event_gbar_consume_cb, inst);
1906 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1907 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
1910 * This delete callback will be removed when the instance will be destroyed.
1912 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_gbar_consume_cb);
1916 ErrPrint("Unsupported package\n");
1917 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1921 result = packet_create_reply(packet, "i", ret);
1923 ErrPrint("Failed to create a reply packet\n");
1929 static struct packet *client_dbox_key_set(pid_t pid, int handle, const struct packet *packet)
1931 struct client_node *client;
1932 const char *pkgname;
1936 unsigned int keycode;
1937 struct inst_info *inst;
1938 const struct pkg_info *pkg;
1939 struct packet *result;
1941 client = client_find_by_rpc_handle(handle);
1943 ErrPrint("Client %d is not exists\n", pid);
1944 ret = DBOX_STATUS_ERROR_NOT_EXIST;
1948 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
1950 ErrPrint("Parameter is not matched\n");
1951 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1955 ret = validate_request(pkgname, id, &inst, &pkg);
1956 if (ret != DBOX_STATUS_ERROR_NONE) {
1960 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
1961 ret = event_activate(0, 0, key_event_dbox_route_cb, inst);
1962 if (ret == DBOX_STATUS_ERROR_NONE) {
1963 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1964 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
1966 if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb) <= 0) {
1967 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb);
1970 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
1971 ret = event_activate(0, 0, key_event_dbox_consume_cb, inst);
1972 if (ret == DBOX_STATUS_ERROR_NONE) {
1973 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
1974 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
1976 if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb) <= 0) {
1977 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb);
1981 ErrPrint("Unsupported package\n");
1982 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
1986 result = packet_create_reply(packet, "i", ret);
1988 ErrPrint("Failed to create a reply packet\n");
1994 static struct packet *client_dbox_key_unset(pid_t pid, int handle, const struct packet *packet)
1996 struct client_node *client;
1997 const char *pkgname;
2001 unsigned int keycode;
2002 struct inst_info *inst;
2003 const struct pkg_info *pkg;
2004 struct packet *result;
2006 client = client_find_by_rpc_handle(handle);
2008 ErrPrint("Client %d is not exists\n", pid);
2009 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2013 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
2015 ErrPrint("Parameter is not matched\n");
2016 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2020 ret = validate_request(pkgname, id, &inst, &pkg);
2021 if (ret != DBOX_STATUS_ERROR_NONE) {
2025 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2026 ret = event_deactivate(key_event_dbox_route_cb, inst);
2027 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2028 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2031 * This delete callback will be removed when the instance will be destroyed.
2033 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_route_cb);
2036 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2037 ret = event_deactivate(key_event_dbox_consume_cb, inst);
2038 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2039 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2042 * This delete callback will be removed when the instance will be destroyed.
2044 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, key_event_dbox_consume_cb);
2048 ErrPrint("Unsupported package\n");
2049 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2053 result = packet_create_reply(packet, "i", ret);
2055 ErrPrint("Failed to create a reply packet\n");
2061 static struct packet *client_dbox_mouse_set(pid_t pid, int handle, const struct packet *packet)
2063 struct client_node *client;
2064 const char *pkgname;
2070 struct inst_info *inst;
2071 const struct pkg_info *pkg;
2073 client = client_find_by_rpc_handle(handle);
2075 ErrPrint("Client %d is not exists\n", pid);
2076 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2080 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2082 ErrPrint("Parameter is not matched\n");
2083 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2087 ret = validate_request(pkgname, id, &inst, &pkg);
2088 if (ret != DBOX_STATUS_ERROR_NONE) {
2092 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2093 if (package_direct_input(pkg) == 0 || packet_set_fd((struct packet *)packet, event_input_fd()) < 0) {
2094 ret = event_activate(x, y, mouse_event_dbox_route_cb, inst);
2095 if (ret == DBOX_STATUS_ERROR_NONE) {
2096 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2097 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
2099 if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb) <= 0) {
2100 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb);
2104 struct slave_node *slave;
2106 DbgPrint("Direct input is enabled(set for %s:%d)\n", id, packet_fd(packet));
2107 slave = package_slave(pkg);
2109 packet_ref((struct packet *)packet);
2110 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2112 ErrPrint("Unable to find a slave for %s\n", pkgname);
2113 ret = DBOX_STATUS_ERROR_FAULT;
2116 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2117 ret = event_activate(x, y, mouse_event_dbox_consume_cb, inst);
2118 if (ret == DBOX_STATUS_ERROR_NONE) {
2119 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2120 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
2122 if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb) <= 0) {
2123 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb);
2127 ErrPrint("Unsupported package\n");
2128 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2134 static struct packet *client_dbox_mouse_unset(pid_t pid, int handle, const struct packet *packet)
2136 struct client_node *client;
2137 const char *pkgname;
2143 struct inst_info *inst;
2144 const struct pkg_info *pkg;
2146 client = client_find_by_rpc_handle(handle);
2148 ErrPrint("Client %d is not exists\n", pid);
2149 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2153 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2155 ErrPrint("Parameter is not matched\n");
2156 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2160 ret = validate_request(pkgname, id, &inst, &pkg);
2161 if (ret != DBOX_STATUS_ERROR_NONE) {
2165 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2166 if (package_direct_input(pkg) == 0) {
2167 ret = event_deactivate(mouse_event_dbox_route_cb, inst);
2168 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2169 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2172 * This delete callback will be removed when the instance will be destroyed.
2174 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_route_cb);
2178 struct slave_node *slave;
2180 DbgPrint("Direct input is enabled(unset) for %s\n", id);
2181 slave = package_slave(pkg);
2183 packet_ref((struct packet *)packet);
2184 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2186 ErrPrint("Unable to find a slave for %s\n", pkgname);
2187 ret = DBOX_STATUS_ERROR_FAULT;
2190 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2191 ret = event_deactivate(mouse_event_dbox_consume_cb, inst);
2192 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2193 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2196 * This delete callback will be removed when the instance will be destroyed.
2198 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_dbox_consume_cb);
2202 ErrPrint("Unsupported package\n");
2203 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2209 static struct packet *client_gbar_mouse_set(pid_t pid, int handle, const struct packet *packet)
2211 struct client_node *client;
2212 const char *pkgname;
2218 struct inst_info *inst;
2219 const struct pkg_info *pkg;
2221 client = client_find_by_rpc_handle(handle);
2223 ErrPrint("Client %d is not exists\n", pid);
2224 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2228 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2230 ErrPrint("Parameter is not matched\n");
2231 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2235 ret = validate_request(pkgname, id, &inst, &pkg);
2236 if (ret != DBOX_STATUS_ERROR_NONE) {
2240 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2241 if (package_direct_input(pkg) == 0 || packet_set_fd((struct packet *)packet, event_input_fd()) < 0) {
2242 ret = event_activate(x, y, mouse_event_gbar_route_cb, inst);
2243 if (ret == DBOX_STATUS_ERROR_NONE) {
2244 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2245 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
2247 if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb) <= 0) {
2248 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb);
2252 struct slave_node *slave;
2254 DbgPrint("Direct input is enabled(set for %s:%d)\n", id, packet_fd(packet));
2255 slave = package_slave(pkg);
2257 packet_ref((struct packet *)packet);
2258 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2260 ErrPrint("Unable to find a slave for %s\n", pkgname);
2261 ret = DBOX_STATUS_ERROR_FAULT;
2264 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2265 ret = event_activate(x, y, mouse_event_gbar_consume_cb, inst);
2266 if (ret == DBOX_STATUS_ERROR_NONE) {
2267 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2268 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON);
2270 if (instance_event_callback_is_added(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb) <= 0) {
2271 instance_event_callback_add(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb);
2275 ErrPrint("Unsupported package\n");
2276 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2283 static struct packet *client_dbox_mouse_on_scroll(pid_t pid, int handle, const struct packet *packet)
2285 struct client_node *client;
2286 const char *pkgname;
2292 struct inst_info *inst;
2293 const struct pkg_info *pkg;
2295 client = client_find_by_rpc_handle(handle);
2297 ErrPrint("Client %d is not exists\n", pid);
2298 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2302 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2304 ErrPrint("Parameter is not matched\n");
2305 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2309 ret = validate_request(pkgname, id, &inst, &pkg);
2310 if (ret != DBOX_STATUS_ERROR_NONE) {
2314 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2315 ret = forward_dbox_event_packet(pkg, inst, packet);
2316 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2317 struct script_info *script;
2319 script = instance_dbox_script(inst);
2321 ret = DBOX_STATUS_ERROR_FAULT;
2325 script_handler_update_pointer(script, x, y, -1);
2326 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_SCROLL, timestamp);
2329 ErrPrint("Unsupported package\n");
2330 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2334 /*! \note No reply packet */
2338 static struct packet *client_dbox_mouse_off_scroll(pid_t pid, int handle, const struct packet *packet)
2340 struct client_node *client;
2341 const char *pkgname;
2347 struct inst_info *inst;
2348 const struct pkg_info *pkg;
2350 client = client_find_by_rpc_handle(handle);
2352 ErrPrint("Client %d is not exists\n", pid);
2353 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2357 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2359 ErrPrint("Parameter is not matched\n");
2360 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2364 ret = validate_request(pkgname, id, &inst, &pkg);
2365 if (ret != DBOX_STATUS_ERROR_NONE) {
2369 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2370 ret = forward_dbox_event_packet(pkg, inst, packet);
2371 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2372 struct script_info *script;
2374 script = instance_dbox_script(inst);
2376 ret = DBOX_STATUS_ERROR_FAULT;
2380 script_handler_update_pointer(script, x, y, -1);
2381 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_SCROLL, timestamp);
2384 ErrPrint("Unsupported package\n");
2385 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2389 /*! \note No reply packet */
2393 static struct packet *client_dbox_mouse_on_hold(pid_t pid, int handle, const struct packet *packet)
2395 struct client_node *client;
2396 const char *pkgname;
2402 struct inst_info *inst;
2403 const struct pkg_info *pkg;
2405 client = client_find_by_rpc_handle(handle);
2407 ErrPrint("Client %d is not exists\n", pid);
2408 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2412 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2414 ErrPrint("Parameter is not matched\n");
2415 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2419 ret = validate_request(pkgname, id, &inst, &pkg);
2420 if (ret != DBOX_STATUS_ERROR_NONE) {
2424 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2425 ret = forward_dbox_event_packet(pkg, inst, packet);
2426 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2427 struct script_info *script;
2429 script = instance_dbox_script(inst);
2431 ret = DBOX_STATUS_ERROR_FAULT;
2435 script_handler_update_pointer(script, x, y, -1);
2436 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_HOLD, timestamp);
2439 ErrPrint("Unsupported package\n");
2440 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2444 /*! \note No reply packet */
2448 static struct packet *client_dbox_mouse_off_hold(pid_t pid, int handle, const struct packet *packet)
2450 struct client_node *client;
2451 const char *pkgname;
2457 struct inst_info *inst;
2458 const struct pkg_info *pkg;
2460 client = client_find_by_rpc_handle(handle);
2462 ErrPrint("Client %d is not exists\n", pid);
2463 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2467 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2469 ErrPrint("Parameter is not matched\n");
2470 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2474 ret = validate_request(pkgname, id, &inst, &pkg);
2475 if (ret != DBOX_STATUS_ERROR_NONE) {
2479 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2480 ret = forward_dbox_event_packet(pkg, inst, packet);
2481 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2482 struct script_info *script;
2484 script = instance_dbox_script(inst);
2486 ret = DBOX_STATUS_ERROR_FAULT;
2490 script_handler_update_pointer(script, x, y, -1);
2491 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_HOLD, timestamp);
2494 ErrPrint("Unsupported package\n");
2495 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2499 /*! \note No reply packet */
2503 static struct packet *client_gbar_mouse_on_scroll(pid_t pid, int handle, const struct packet *packet)
2505 struct client_node *client;
2506 const char *pkgname;
2512 struct inst_info *inst;
2513 const struct pkg_info *pkg;
2515 client = client_find_by_rpc_handle(handle);
2517 ErrPrint("Client %d is not exists\n", pid);
2518 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2522 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2524 ErrPrint("Parameter is not matched\n");
2525 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2529 ret = validate_request(pkgname, id, &inst, &pkg);
2530 if (ret != DBOX_STATUS_ERROR_NONE) {
2534 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2535 ret = forward_gbar_event_packet(pkg, inst, packet);
2536 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2537 struct script_info *script;
2539 script = instance_gbar_script(inst);
2541 ret = DBOX_STATUS_ERROR_FAULT;
2545 script_handler_update_pointer(script, x, y, -1);
2546 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_SCROLL, timestamp);
2549 ErrPrint("Unsupported package\n");
2550 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2554 /*! \note No reply packet */
2558 static struct packet *client_gbar_mouse_off_scroll(pid_t pid, int handle, const struct packet *packet)
2560 struct client_node *client;
2561 const char *pkgname;
2567 struct inst_info *inst;
2568 const struct pkg_info *pkg;
2570 client = client_find_by_rpc_handle(handle);
2572 ErrPrint("Client %d is not exists\n", pid);
2573 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2577 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2579 ErrPrint("Parameter is not matched\n");
2580 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2584 ret = validate_request(pkgname, id, &inst, &pkg);
2585 if (ret != DBOX_STATUS_ERROR_NONE) {
2589 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2590 ret = forward_gbar_event_packet(pkg, inst, packet);
2591 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2592 struct script_info *script;
2594 script = instance_gbar_script(inst);
2596 ret = DBOX_STATUS_ERROR_FAULT;
2600 script_handler_update_pointer(script, x, y, -1);
2601 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_SCROLL, timestamp);
2604 ErrPrint("Unsupported package\n");
2605 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2609 /*! \note No reply packet */
2613 static struct packet *client_gbar_mouse_on_hold(pid_t pid, int handle, const struct packet *packet)
2615 struct client_node *client;
2616 const char *pkgname;
2622 struct inst_info *inst;
2623 const struct pkg_info *pkg;
2625 client = client_find_by_rpc_handle(handle);
2627 ErrPrint("Client %d is not exists\n", pid);
2628 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2632 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2634 ErrPrint("Parameter is not matched\n");
2635 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2639 ret = validate_request(pkgname, id, &inst, &pkg);
2640 if (ret != DBOX_STATUS_ERROR_NONE) {
2644 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2645 ret = forward_gbar_event_packet(pkg, inst, packet);
2646 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2647 struct script_info *script;
2649 script = instance_gbar_script(inst);
2651 ret = DBOX_STATUS_ERROR_FAULT;
2655 script_handler_update_pointer(script, x, y, -1);
2656 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_ON_HOLD, timestamp);
2659 ErrPrint("Unsupported package\n");
2660 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2664 /*! \note No reply packet */
2668 static struct packet *client_gbar_mouse_off_hold(pid_t pid, int handle, const struct packet *packet)
2670 struct client_node *client;
2671 const char *pkgname;
2677 struct inst_info *inst;
2678 const struct pkg_info *pkg;
2680 client = client_find_by_rpc_handle(handle);
2682 ErrPrint("Client %d is not exists\n", pid);
2683 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2687 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2689 ErrPrint("Parameter is not matched\n");
2690 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2694 ret = validate_request(pkgname, id, &inst, &pkg);
2695 if (ret != DBOX_STATUS_ERROR_NONE) {
2699 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2700 ret = forward_gbar_event_packet(pkg, inst, packet);
2701 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2702 struct script_info *script;
2704 script = instance_gbar_script(inst);
2706 ret = DBOX_STATUS_ERROR_FAULT;
2710 script_handler_update_pointer(script, x, y, -1);
2711 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OFF_HOLD, timestamp);
2714 ErrPrint("Unsupported package\n");
2715 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2719 /*! \note No reply packet */
2723 static struct packet *client_gbar_mouse_unset(pid_t pid, int handle, const struct packet *packet)
2725 struct client_node *client;
2726 const char *pkgname;
2732 struct inst_info *inst;
2733 const struct pkg_info *pkg;
2735 client = client_find_by_rpc_handle(handle);
2737 ErrPrint("Client %d is not exists\n", pid);
2738 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2742 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2744 ErrPrint("Parameter is not matched\n");
2745 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2749 ret = validate_request(pkgname, id, &inst, &pkg);
2750 if (ret != DBOX_STATUS_ERROR_NONE) {
2754 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
2755 if (package_direct_input(pkg) == 0) {
2756 ret = event_deactivate(mouse_event_gbar_route_cb, inst);
2757 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2758 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2761 * This delete callback will be removed when the instance will be destroyed.
2763 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_route_cb);
2767 struct slave_node *slave;
2769 DbgPrint("Direct input is enabled(unset) for %s\n", id);
2770 slave = package_slave(pkg);
2772 packet_ref((struct packet *)packet);
2773 ret = slave_rpc_request_only(slave, pkgname, (struct packet *)packet, 0);
2775 ErrPrint("Unable to find a slave for %s\n", pkgname);
2776 ret = DBOX_STATUS_ERROR_FAULT;
2779 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
2780 ret = event_deactivate(mouse_event_gbar_consume_cb, inst);
2781 if (DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF != DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_ON) {
2782 (void)slave_set_priority(package_slave(pkg), DYNAMICBOX_CONF_SLAVE_EVENT_BOOST_OFF);
2785 * This delete callback will be removed when the instance will be destroyed.
2787 instance_event_callback_del(inst, INSTANCE_EVENT_DESTROY, inst_del_cb, mouse_event_gbar_consume_cb);
2791 ErrPrint("Unsupported package\n");
2792 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2798 static struct packet *client_dbox_mouse_enter(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
2800 struct client_node *client;
2801 const char *pkgname;
2807 struct inst_info *inst;
2808 const struct pkg_info *pkg;
2810 client = client_find_by_rpc_handle(handle);
2812 ErrPrint("Client %d is not exists\n", pid);
2813 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2817 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2819 ErrPrint("Parameter is not matched\n");
2820 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2824 ret = validate_request(pkgname, id, &inst, &pkg);
2825 if (ret != DBOX_STATUS_ERROR_NONE) {
2829 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2830 ret = forward_dbox_event_packet(pkg, inst, packet);
2831 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2832 struct script_info *script;
2834 script = instance_dbox_script(inst);
2836 ret = DBOX_STATUS_ERROR_FAULT;
2840 script_handler_update_pointer(script, x, y, -1);
2841 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_IN, timestamp);
2844 ErrPrint("Unsupported package\n");
2845 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2849 /*! \note No reply packet */
2853 static struct packet *client_dbox_mouse_leave(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
2855 struct client_node *client;
2856 const char *pkgname;
2862 struct inst_info *inst;
2863 const struct pkg_info *pkg;
2865 client = client_find_by_rpc_handle(handle);
2867 ErrPrint("Client %d is not exists\n", pid);
2868 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2872 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2874 ErrPrint("Parameter is not matched\n");
2875 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2879 ret = validate_request(pkgname, id, &inst, &pkg);
2880 if (ret != DBOX_STATUS_ERROR_NONE) {
2884 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2885 ret = forward_dbox_event_packet(pkg, inst, packet);
2886 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2887 struct script_info *script;
2889 script = instance_dbox_script(inst);
2891 ret = DBOX_STATUS_ERROR_FAULT;
2895 script_handler_update_pointer(script, x, y, -1);
2896 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_OUT, timestamp);
2899 ErrPrint("Unsupported package\n");
2900 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2904 /*! \note No reply packet */
2908 static struct packet *client_dbox_mouse_down(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
2910 struct client_node *client;
2911 const char *pkgname;
2917 struct inst_info *inst;
2918 const struct pkg_info *pkg;
2920 client = client_find_by_rpc_handle(handle);
2922 ErrPrint("Client %d is not exists\n", pid);
2923 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2927 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2929 ErrPrint("Parameter is not matched\n");
2930 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2934 ret = validate_request(pkgname, id, &inst, &pkg);
2935 if (ret != DBOX_STATUS_ERROR_NONE) {
2939 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2940 ret = forward_dbox_event_packet(pkg, inst, packet);
2941 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2942 struct script_info *script;
2944 script = instance_dbox_script(inst);
2946 ret = DBOX_STATUS_ERROR_FAULT;
2950 script_handler_update_pointer(script, x, y, 1);
2951 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_DOWN, timestamp);
2954 ErrPrint("Unsupported package\n");
2955 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2959 /*! \note No reply packet */
2963 static struct packet *client_dbox_mouse_up(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
2965 struct client_node *client;
2966 const char *pkgname;
2972 struct inst_info *inst;
2973 const struct pkg_info *pkg;
2975 client = client_find_by_rpc_handle(handle);
2977 ErrPrint("Client %d is not exists\n", pid);
2978 ret = DBOX_STATUS_ERROR_NOT_EXIST;
2982 ret = packet_get(packet, "ssdii", &pkgname, &id, ×tamp, &x, &y);
2984 ErrPrint("Parameter is not matched\n");
2985 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
2989 ret = validate_request(pkgname, id, &inst, &pkg);
2990 if (ret != DBOX_STATUS_ERROR_NONE) {
2994 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
2995 ret = forward_dbox_event_packet(pkg, inst, packet);
2996 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
2997 struct script_info *script;
2999 script = instance_dbox_script(inst);
3001 ret = DBOX_STATUS_ERROR_FAULT;
3005 script_handler_update_pointer(script, x, y, 0);
3006 script_handler_feed_event(script, DBOX_SCRIPT_MOUSE_UP, timestamp);
3009 ErrPrint("Unsupported package\n");
3010 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3014 /*! \note No reply packet */
3018 static struct packet *client_gbar_access_action(pid_t pid, int handle, const struct packet *packet)
3020 struct packet *result;
3021 struct client_node *client;
3022 const char *pkgname;
3026 struct access_info event;
3027 struct inst_info *inst = NULL;
3028 const struct pkg_info *pkg = NULL;
3030 client = client_find_by_rpc_handle(handle);
3032 ErrPrint("Client %d is not exists\n", pid);
3033 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3037 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
3039 ErrPrint("Invalid parameter\n");
3040 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3044 ret = validate_request(pkgname, id, &inst, &pkg);
3045 if (ret != DBOX_STATUS_ERROR_NONE) {
3049 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3050 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3051 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3052 struct script_info *script;
3054 script = instance_gbar_script(inst);
3056 ret = DBOX_STATUS_ERROR_FAULT;
3060 script_handler_update_pointer(script, event.x, event.y, event.type);
3061 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTION, timestamp);
3063 ret = send_delayed_access_status(inst, ret);
3066 ErrPrint("Unsupported package\n");
3067 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3071 result = packet_create_reply(packet, "i", ret);
3073 ErrPrint("Failed to create a reply packet\n");
3079 static struct packet *client_gbar_access_scroll(pid_t pid, int handle, const struct packet *packet)
3081 struct packet *result;
3082 struct client_node *client;
3083 const char *pkgname;
3087 struct access_info event;
3088 struct inst_info *inst = NULL;
3089 const struct pkg_info *pkg = NULL;
3091 client = client_find_by_rpc_handle(handle);
3093 ErrPrint("Client %d is not exists\n", pid);
3094 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3098 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
3100 ErrPrint("Invalid parameter\n");
3101 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3105 ret = validate_request(pkgname, id, &inst, &pkg);
3106 if (ret != DBOX_STATUS_ERROR_NONE) {
3110 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3111 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3112 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3113 struct script_info *script;
3115 script = instance_gbar_script(inst);
3117 ret = DBOX_STATUS_ERROR_FAULT;
3121 script_handler_update_pointer(script, event.x, event.y, event.type);
3122 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_SCROLL, timestamp);
3124 ret = send_delayed_access_status(inst, ret);
3127 ErrPrint("Unsupported package\n");
3128 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3132 result = packet_create_reply(packet, "i", ret);
3134 ErrPrint("Failed to create a reply packet\n");
3140 static struct packet *client_gbar_access_value_change(pid_t pid, int handle, const struct packet *packet)
3142 struct packet *result;
3143 struct client_node *client;
3144 const char *pkgname;
3148 struct access_info event;
3149 struct inst_info *inst = NULL;
3150 const struct pkg_info *pkg = NULL;
3152 client = client_find_by_rpc_handle(handle);
3154 ErrPrint("Client %d is not exists\n", pid);
3155 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3159 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
3161 ErrPrint("Invalid parameter\n");
3162 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3166 ret = validate_request(pkgname, id, &inst, &pkg);
3167 if (ret != DBOX_STATUS_ERROR_NONE) {
3171 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3172 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3173 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3174 struct script_info *script;
3176 script = instance_gbar_script(inst);
3178 ret = DBOX_STATUS_ERROR_FAULT;
3182 script_handler_update_pointer(script, event.x, event.y, event.type);
3183 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_VALUE_CHANGE, timestamp);
3185 ret = send_delayed_access_status(inst, ret);
3188 ErrPrint("Unsupported package\n");
3189 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3193 result = packet_create_reply(packet, "i", ret);
3195 ErrPrint("Failed to create a reply packet\n");
3201 static struct packet *client_gbar_access_mouse(pid_t pid, int handle, const struct packet *packet)
3203 struct packet *result;
3204 struct client_node *client;
3205 const char *pkgname;
3209 struct access_info event;
3210 struct inst_info *inst = NULL;
3211 const struct pkg_info *pkg = NULL;
3213 client = client_find_by_rpc_handle(handle);
3215 ErrPrint("Client %d is not exists\n", pid);
3216 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3220 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
3222 ErrPrint("Invalid parameter\n");
3223 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3227 ret = validate_request(pkgname, id, &inst, &pkg);
3228 if (ret != DBOX_STATUS_ERROR_NONE) {
3232 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3233 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3234 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3235 struct script_info *script;
3237 script = instance_gbar_script(inst);
3239 ret = DBOX_STATUS_ERROR_FAULT;
3243 script_handler_update_pointer(script, event.x, event.y, event.type);
3244 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_MOUSE, timestamp);
3246 ret = send_delayed_access_status(inst, ret);
3249 ErrPrint("Unsupported package\n");
3250 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3254 result = packet_create_reply(packet, "i", ret);
3256 ErrPrint("Failed to create a reply packet\n");
3262 static struct packet *client_gbar_access_back(pid_t pid, int handle, const struct packet *packet)
3264 struct packet *result;
3265 struct client_node *client;
3266 const char *pkgname;
3270 struct access_info event;
3271 struct inst_info *inst = NULL;
3272 const struct pkg_info *pkg = NULL;
3274 client = client_find_by_rpc_handle(handle);
3276 ErrPrint("Client %d is not exists\n", pid);
3277 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3281 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
3283 ErrPrint("Invalid parameter\n");
3284 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3288 ret = validate_request(pkgname, id, &inst, &pkg);
3289 if (ret != DBOX_STATUS_ERROR_NONE) {
3293 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3294 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3295 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3296 struct script_info *script;
3298 script = instance_gbar_script(inst);
3300 ret = DBOX_STATUS_ERROR_FAULT;
3304 script_handler_update_pointer(script, event.x, event.y, event.type);
3305 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_BACK, timestamp);
3307 ret = send_delayed_access_status(inst, ret);
3310 ErrPrint("Unsupported package\n");
3311 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3315 result = packet_create_reply(packet, "i", ret);
3317 ErrPrint("Failed to create a reply packet\n");
3323 static struct packet *client_gbar_access_over(pid_t pid, int handle, const struct packet *packet)
3325 struct packet *result;
3326 struct client_node *client;
3327 const char *pkgname;
3331 struct access_info event;
3332 struct inst_info *inst = NULL;
3333 const struct pkg_info *pkg = NULL;
3335 client = client_find_by_rpc_handle(handle);
3337 ErrPrint("Client %d is not exists\n", pid);
3338 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3342 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
3344 ErrPrint("Invalid parameter\n");
3345 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3349 ret = validate_request(pkgname, id, &inst, &pkg);
3350 if (ret != DBOX_STATUS_ERROR_NONE) {
3354 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3355 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3356 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3357 struct script_info *script;
3359 script = instance_gbar_script(inst);
3361 ret = DBOX_STATUS_ERROR_FAULT;
3365 script_handler_update_pointer(script, event.x, event.y, event.type);
3366 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_OVER, timestamp);
3368 ret = send_delayed_access_status(inst, ret);
3371 ErrPrint("Unsupported package\n");
3372 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3376 result = packet_create_reply(packet, "i", ret);
3378 ErrPrint("Failed to create a reply packet\n");
3384 static struct packet *client_gbar_access_read(pid_t pid, int handle, const struct packet *packet)
3386 struct packet *result;
3387 struct client_node *client;
3388 const char *pkgname;
3392 struct access_info event;
3393 struct inst_info *inst = NULL;
3394 const struct pkg_info *pkg = NULL;
3396 client = client_find_by_rpc_handle(handle);
3398 ErrPrint("Client %d is not exists\n", pid);
3399 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3403 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
3405 ErrPrint("Invalid parameter\n");
3406 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3410 ret = validate_request(pkgname, id, &inst, &pkg);
3411 if (ret != DBOX_STATUS_ERROR_NONE) {
3415 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3416 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3417 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3418 struct script_info *script;
3420 script = instance_gbar_script(inst);
3422 ret = DBOX_STATUS_ERROR_FAULT;
3426 script_handler_update_pointer(script, event.x, event.y, event.type);
3427 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_READ, timestamp);
3429 ret = send_delayed_access_status(inst, ret);
3432 ErrPrint("Unsupported package\n");
3433 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3437 result = packet_create_reply(packet, "i", ret);
3439 ErrPrint("Failed to create a reply packet\n");
3445 static struct packet *client_gbar_access_enable(pid_t pid, int handle, const struct packet *packet)
3447 struct packet *result;
3448 struct client_node *client;
3449 const char *pkgname;
3453 struct access_info event;
3454 struct inst_info *inst = NULL;
3455 const struct pkg_info *pkg = NULL;
3457 client = client_find_by_rpc_handle(handle);
3459 ErrPrint("Client %d is not exists\n", pid);
3460 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3464 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
3466 ErrPrint("Invalid parameter\n");
3467 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3471 ret = validate_request(pkgname, id, &inst, &pkg);
3472 if (ret != DBOX_STATUS_ERROR_NONE) {
3476 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3477 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3478 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3479 struct script_info *script;
3482 script = instance_gbar_script(inst);
3484 ret = DBOX_STATUS_ERROR_FAULT;
3488 type = (event.type == 0) ? DBOX_SCRIPT_ACCESS_DISABLE : DBOX_SCRIPT_ACCESS_ENABLE;
3490 script_handler_update_pointer(script, event.x, event.y, event.type);
3491 ret = script_handler_feed_event(script, type, timestamp);
3493 ret = send_delayed_access_status(inst, ret);
3496 ErrPrint("Unsupported package\n");
3497 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3501 result = packet_create_reply(packet, "i", ret);
3503 ErrPrint("Failed to create a reply packet\n");
3509 static struct packet *client_gbar_access_hl(pid_t pid, int handle, const struct packet *packet)
3511 struct packet *result;
3512 struct client_node *client;
3513 const char *pkgname;
3517 struct access_info event;
3518 struct inst_info *inst = NULL;
3519 const struct pkg_info *pkg = NULL;
3521 client = client_find_by_rpc_handle(handle);
3523 ErrPrint("Client %d is not exists\n", pid);
3524 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3528 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
3530 ErrPrint("Invalid parameter\n");
3531 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3535 ret = validate_request(pkgname, id, &inst, &pkg);
3536 if (ret != DBOX_STATUS_ERROR_NONE) {
3540 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3541 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3542 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3543 struct script_info *script;
3546 script = instance_gbar_script(inst);
3548 ret = DBOX_STATUS_ERROR_FAULT;
3552 switch (event.type) {
3553 case ACCESS_TYPE_CUR:
3554 type = DBOX_SCRIPT_ACCESS_HIGHLIGHT;
3556 case ACCESS_TYPE_NEXT:
3557 type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_NEXT;
3559 case ACCESS_TYPE_PREV:
3560 type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_PREV;
3562 case ACCESS_TYPE_OFF:
3563 type = DBOX_SCRIPT_ACCESS_UNHIGHLIGHT;
3566 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3570 script_handler_update_pointer(script, event.x, event.y, event.type);
3571 ret = script_handler_feed_event(script, type, timestamp);
3573 ret = send_delayed_access_status(inst, ret);
3576 ErrPrint("Unsupported package\n");
3577 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3581 result = packet_create_reply(packet, "i", ret);
3583 ErrPrint("Failed to create a reply packet\n");
3589 static struct packet *client_gbar_access_activate(pid_t pid, int handle, const struct packet *packet)
3591 struct packet *result;
3592 struct client_node *client;
3593 const char *pkgname;
3597 struct access_info event;
3598 struct inst_info *inst = NULL;
3599 const struct pkg_info *pkg = NULL;
3601 client = client_find_by_rpc_handle(handle);
3603 ErrPrint("Client %d is not exists\n", pid);
3604 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3608 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
3610 ErrPrint("Invalid parameter\n");
3611 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3615 ret = validate_request(pkgname, id, &inst, &pkg);
3616 if (ret != DBOX_STATUS_ERROR_NONE) {
3620 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3621 ret = forward_gbar_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3622 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3623 struct script_info *script;
3625 script = instance_gbar_script(inst);
3627 ret = DBOX_STATUS_ERROR_FAULT;
3631 script_handler_update_pointer(script, event.x, event.y, event.type);
3632 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTIVATE, timestamp);
3634 ret = send_delayed_access_status(inst, ret);
3637 ErrPrint("Unsupported package\n");
3638 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3642 result = packet_create_reply(packet, "i", ret);
3644 ErrPrint("Failed to create a reply packet\n");
3650 static struct packet *client_gbar_key_focus_in(pid_t pid, int handle, const struct packet *packet)
3652 struct client_node *client;
3653 const char *pkgname;
3657 unsigned int keycode;
3658 struct inst_info *inst;
3659 const struct pkg_info *pkg;
3660 struct packet *result;
3662 client = client_find_by_rpc_handle(handle);
3664 ErrPrint("Client %d is not exists\n", pid);
3665 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3669 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3671 ErrPrint("Invalid parameter\n");
3672 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3676 ret = validate_request(pkgname, id, &inst, &pkg);
3677 if (ret != DBOX_STATUS_ERROR_NONE) {
3681 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3682 ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3683 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3684 struct script_info *script;
3686 script = instance_gbar_script(inst);
3688 ret = DBOX_STATUS_ERROR_FAULT;
3692 script_handler_update_keycode(script, keycode);
3693 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_IN, timestamp);
3695 ret = send_delayed_key_status(inst, ret);
3698 ErrPrint("Unsupported package\n");
3699 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3703 result = packet_create_reply(packet, "i", ret);
3705 ErrPrint("Failed to create a reply packet\n");
3711 static struct packet *client_gbar_key_focus_out(pid_t pid, int handle, const struct packet *packet)
3713 struct client_node *client;
3714 const char *pkgname;
3718 unsigned int keycode;
3719 struct inst_info *inst;
3720 const struct pkg_info *pkg;
3721 struct packet *result;
3723 client = client_find_by_rpc_handle(handle);
3725 ErrPrint("Client %d is not exists\n", pid);
3726 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3730 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3732 ErrPrint("Invalid parameter\n");
3733 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3737 ret = validate_request(pkgname, id, &inst, &pkg);
3738 if (ret != DBOX_STATUS_ERROR_NONE) {
3742 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3743 ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3744 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3745 struct script_info *script;
3747 script = instance_gbar_script(inst);
3749 ret = DBOX_STATUS_ERROR_FAULT;
3753 script_handler_update_keycode(script, keycode);
3754 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_OUT, timestamp);
3756 ret = send_delayed_key_status(inst, ret);
3759 ErrPrint("Unsupported package\n");
3760 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3764 result = packet_create_reply(packet, "i", ret);
3766 ErrPrint("Failed to create a reply packet\n");
3772 static struct packet *client_gbar_key_down(pid_t pid, int handle, const struct packet *packet)
3774 struct client_node *client;
3775 const char *pkgname;
3779 unsigned int keycode;
3780 struct inst_info *inst;
3781 const struct pkg_info *pkg;
3782 struct packet *result;
3784 client = client_find_by_rpc_handle(handle);
3786 ErrPrint("Client %d is not exists\n", pid);
3787 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3791 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3793 ErrPrint("Invalid parameter\n");
3794 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3798 ret = validate_request(pkgname, id, &inst, &pkg);
3799 if (ret != DBOX_STATUS_ERROR_NONE) {
3803 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3804 ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3805 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3806 struct script_info *script;
3808 script = instance_gbar_script(inst);
3810 ret = DBOX_STATUS_ERROR_FAULT;
3814 script_handler_update_keycode(script, keycode);
3815 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
3817 ret = send_delayed_key_status(inst, ret);
3820 ErrPrint("Unsupported package\n");
3821 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3825 result = packet_create_reply(packet, "i", ret);
3827 ErrPrint("Failed to create a reply packet\n");
3833 static struct packet *client_pause_request(pid_t pid, int handle, const struct packet *packet)
3835 struct client_node *client;
3839 client = client_find_by_rpc_handle(handle);
3841 ErrPrint("Client %d is paused - manually reported\n", pid);
3842 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3846 ret = packet_get(packet, "d", ×tamp);
3848 ErrPrint("Invalid parameter\n");
3849 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3853 if (DYNAMICBOX_CONF_USE_XMONITOR) {
3854 DbgPrint("XMONITOR enabled. ignore client paused request\n");
3856 xmonitor_pause(client);
3863 static struct packet *client_resume_request(pid_t pid, int handle, const struct packet *packet)
3865 struct client_node *client;
3869 client = client_find_by_rpc_handle(handle);
3871 ErrPrint("Client %d is not exists\n", pid);
3875 ret = packet_get(packet, "d", ×tamp);
3877 ErrPrint("Invalid parameter\n");
3881 if (DYNAMICBOX_CONF_USE_XMONITOR) {
3882 DbgPrint("XMONITOR enabled. ignore client resumed request\n");
3884 xmonitor_resume(client);
3891 static struct packet *client_gbar_key_up(pid_t pid, int handle, const struct packet *packet)
3893 struct client_node *client;
3894 const char *pkgname;
3898 unsigned int keycode;
3899 struct inst_info *inst;
3900 const struct pkg_info *pkg;
3901 struct packet *result;
3903 client = client_find_by_rpc_handle(handle);
3905 ErrPrint("Client %d is not exists\n", pid);
3906 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3910 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
3912 ErrPrint("Invalid parameter\n");
3913 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3917 ret = validate_request(pkgname, id, &inst, &pkg);
3918 if (ret != DBOX_STATUS_ERROR_NONE) {
3922 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
3923 ret = forward_gbar_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
3924 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
3925 struct script_info *script;
3927 script = instance_gbar_script(inst);
3929 ret = DBOX_STATUS_ERROR_FAULT;
3933 script_handler_update_keycode(script, keycode);
3934 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp);
3936 ret = send_delayed_key_status(inst, ret);
3939 ErrPrint("Unsupported package\n");
3940 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3944 result = packet_create_reply(packet, "i", ret);
3946 ErrPrint("Failed to create a reply packet\n");
3952 static struct packet *client_dbox_access_hl(pid_t pid, int handle, const struct packet *packet)
3954 struct packet *result;
3955 struct client_node *client;
3956 const char *pkgname;
3960 struct access_info event;
3961 struct inst_info *inst = NULL;
3962 const struct pkg_info *pkg = NULL;
3964 client = client_find_by_rpc_handle(handle);
3966 ErrPrint("Client %d is not exists\n", pid);
3967 ret = DBOX_STATUS_ERROR_NOT_EXIST;
3971 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
3973 ErrPrint("Parameter is not matched\n");
3974 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
3978 ret = validate_request(pkgname, id, &inst, &pkg);
3979 if (ret != DBOX_STATUS_ERROR_NONE) {
3983 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
3984 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
3985 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
3986 struct script_info *script;
3989 script = instance_dbox_script(inst);
3991 ret = DBOX_STATUS_ERROR_FAULT;
3995 switch (event.type) {
3996 case ACCESS_TYPE_CUR:
3997 type = DBOX_SCRIPT_ACCESS_HIGHLIGHT;
3999 case ACCESS_TYPE_NEXT:
4000 type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_NEXT;
4002 case ACCESS_TYPE_PREV:
4003 type = DBOX_SCRIPT_ACCESS_HIGHLIGHT_PREV;
4005 case ACCESS_TYPE_OFF:
4006 type = DBOX_SCRIPT_ACCESS_UNHIGHLIGHT;
4009 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4013 script_handler_update_pointer(script, event.x, event.y, event.type);
4014 ret = script_handler_feed_event(script, type, timestamp);
4016 ret = send_delayed_access_status(inst, ret);
4019 ErrPrint("Unsupported package\n");
4020 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4024 result = packet_create_reply(packet, "i", ret);
4026 ErrPrint("Failed to create a reply packet\n");
4032 static struct packet *client_dbox_access_action(pid_t pid, int handle, const struct packet *packet)
4034 struct packet *result;
4035 struct client_node *client;
4036 const char *pkgname;
4040 struct inst_info *inst = NULL;
4041 const struct pkg_info *pkg = NULL;
4042 struct access_info event;
4044 client = client_find_by_rpc_handle(handle);
4046 ErrPrint("Client %d is not exist\n", pid);
4047 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4051 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
4053 ErrPrint("Parameter is not matched\n");
4054 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4058 ret = validate_request(pkgname, id, &inst, &pkg);
4059 if (ret != DBOX_STATUS_ERROR_NONE) {
4063 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4064 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4066 * Enen if it fails to send packet,
4067 * The packet will be unref'd
4068 * So we don't need to check the ret value.
4070 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4071 struct script_info *script;
4073 script = instance_dbox_script(inst);
4075 ErrPrint("Instance has no script\n");
4076 ret = DBOX_STATUS_ERROR_FAULT;
4080 script_handler_update_pointer(script, event.x, event.y, event.type);
4081 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTION, timestamp);
4083 ret = send_delayed_access_status(inst, ret);
4086 ErrPrint("Unsupported package\n");
4087 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4091 result = packet_create_reply(packet, "i", ret);
4093 ErrPrint("Failed to create a reply packet\n");
4099 static struct packet *client_dbox_access_scroll(pid_t pid, int handle, const struct packet *packet)
4101 struct packet *result;
4102 struct client_node *client;
4103 const char *pkgname;
4107 struct inst_info *inst = NULL;
4108 const struct pkg_info *pkg = NULL;
4109 struct access_info event;
4111 client = client_find_by_rpc_handle(handle);
4113 ErrPrint("Client %d is not exist\n", pid);
4114 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4118 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
4120 ErrPrint("Parameter is not matched\n");
4121 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4125 ret = validate_request(pkgname, id, &inst, &pkg);
4126 if (ret != DBOX_STATUS_ERROR_NONE) {
4130 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4131 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4133 * Enen if it fails to send packet,
4134 * The packet will be unref'd
4135 * So we don't need to check the ret value.
4137 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4138 struct script_info *script;
4140 script = instance_dbox_script(inst);
4142 ErrPrint("Instance has no script\n");
4143 ret = DBOX_STATUS_ERROR_FAULT;
4147 script_handler_update_pointer(script, event.x, event.y, event.type);
4148 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_SCROLL, timestamp);
4150 ret = send_delayed_access_status(inst, ret);
4153 ErrPrint("Unsupported package\n");
4154 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4158 result = packet_create_reply(packet, "i", ret);
4160 ErrPrint("Failed to create a reply packet\n");
4166 static struct packet *client_dbox_access_value_change(pid_t pid, int handle, const struct packet *packet)
4168 struct packet *result;
4169 struct client_node *client;
4170 const char *pkgname;
4174 struct inst_info *inst = NULL;
4175 const struct pkg_info *pkg = NULL;
4176 struct access_info event;
4178 client = client_find_by_rpc_handle(handle);
4180 ErrPrint("Client %d is not exist\n", pid);
4181 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4185 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
4187 ErrPrint("Parameter is not matched\n");
4188 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4192 ret = validate_request(pkgname, id, &inst, &pkg);
4193 if (ret != DBOX_STATUS_ERROR_NONE) {
4197 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4198 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4200 * Enen if it fails to send packet,
4201 * The packet will be unref'd
4202 * So we don't need to check the ret value.
4204 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4205 struct script_info *script;
4207 script = instance_dbox_script(inst);
4209 ErrPrint("Instance has no script\n");
4210 ret = DBOX_STATUS_ERROR_FAULT;
4214 script_handler_update_pointer(script, event.x, event.y, event.type);
4215 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_VALUE_CHANGE, timestamp);
4217 ret = send_delayed_access_status(inst, ret);
4220 ErrPrint("Unsupported package\n");
4221 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4225 result = packet_create_reply(packet, "i", ret);
4227 ErrPrint("Failed to create a reply packet\n");
4233 static struct packet *client_dbox_access_mouse(pid_t pid, int handle, const struct packet *packet)
4235 struct packet *result;
4236 struct client_node *client;
4237 const char *pkgname;
4241 struct inst_info *inst = NULL;
4242 const struct pkg_info *pkg = NULL;
4243 struct access_info event;
4245 client = client_find_by_rpc_handle(handle);
4247 ErrPrint("Client %d is not exist\n", pid);
4248 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4252 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
4254 ErrPrint("Parameter is not matched\n");
4255 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4259 ret = validate_request(pkgname, id, &inst, &pkg);
4260 if (ret != DBOX_STATUS_ERROR_NONE) {
4264 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4265 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4267 * Enen if it fails to send packet,
4268 * The packet will be unref'd
4269 * So we don't need to check the ret value.
4271 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4272 struct script_info *script;
4274 script = instance_dbox_script(inst);
4276 ErrPrint("Instance has no script\n");
4277 ret = DBOX_STATUS_ERROR_FAULT;
4281 script_handler_update_pointer(script, event.x, event.y, event.type);
4282 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_MOUSE, timestamp);
4284 ret = send_delayed_access_status(inst, ret);
4287 ErrPrint("Unsupported package\n");
4288 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4292 result = packet_create_reply(packet, "i", ret);
4294 ErrPrint("Failed to create a reply packet\n");
4300 static struct packet *client_dbox_access_back(pid_t pid, int handle, const struct packet *packet)
4302 struct packet *result;
4303 struct client_node *client;
4304 const char *pkgname;
4308 struct inst_info *inst = NULL;
4309 const struct pkg_info *pkg = NULL;
4310 struct access_info event;
4312 client = client_find_by_rpc_handle(handle);
4314 ErrPrint("Client %d is not exist\n", pid);
4315 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4319 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
4321 ErrPrint("Parameter is not matched\n");
4322 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4326 ret = validate_request(pkgname, id, &inst, &pkg);
4327 if (ret != DBOX_STATUS_ERROR_NONE) {
4331 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4332 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4334 * Enen if it fails to send packet,
4335 * The packet will be unref'd
4336 * So we don't need to check the ret value.
4338 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4339 struct script_info *script;
4341 script = instance_dbox_script(inst);
4343 ErrPrint("Instance has no script\n");
4344 ret = DBOX_STATUS_ERROR_FAULT;
4348 script_handler_update_pointer(script, event.x, event.y, event.type);
4349 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_BACK, timestamp);
4351 ret = send_delayed_access_status(inst, ret);
4354 ErrPrint("Unsupported package\n");
4355 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4359 result = packet_create_reply(packet, "i", ret);
4361 ErrPrint("Failed to create a reply packet\n");
4367 static struct packet *client_dbox_access_over(pid_t pid, int handle, const struct packet *packet)
4369 struct packet *result;
4370 struct client_node *client;
4371 const char *pkgname;
4375 struct inst_info *inst = NULL;
4376 const struct pkg_info *pkg = NULL;
4377 struct access_info event;
4379 client = client_find_by_rpc_handle(handle);
4381 ErrPrint("Client %d is not exist\n", pid);
4382 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4386 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
4388 ErrPrint("Parameter is not matched\n");
4389 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4393 ret = validate_request(pkgname, id, &inst, &pkg);
4394 if (ret != DBOX_STATUS_ERROR_NONE) {
4398 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4399 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4401 * Enen if it fails to send packet,
4402 * The packet will be unref'd
4403 * So we don't need to check the ret value.
4405 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4406 struct script_info *script;
4408 script = instance_dbox_script(inst);
4410 ErrPrint("Instance has no script\n");
4411 ret = DBOX_STATUS_ERROR_FAULT;
4415 script_handler_update_pointer(script, event.x, event.y, event.type);
4416 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_OVER, timestamp);
4418 ret = send_delayed_access_status(inst, ret);
4421 ErrPrint("Unsupported package\n");
4422 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4426 result = packet_create_reply(packet, "i", ret);
4428 ErrPrint("Failed to create a reply packet\n");
4434 static struct packet *client_dbox_access_read(pid_t pid, int handle, const struct packet *packet)
4436 struct packet *result;
4437 struct client_node *client;
4438 const char *pkgname;
4442 struct inst_info *inst = NULL;
4443 const struct pkg_info *pkg = NULL;
4444 struct access_info event;
4446 client = client_find_by_rpc_handle(handle);
4448 ErrPrint("Client %d is not exist\n", pid);
4449 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4453 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
4455 ErrPrint("Parameter is not matched\n");
4456 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4460 ret = validate_request(pkgname, id, &inst, &pkg);
4461 if (ret != DBOX_STATUS_ERROR_NONE) {
4465 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4466 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4468 * Enen if it fails to send packet,
4469 * The packet will be unref'd
4470 * So we don't need to check the ret value.
4472 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4473 struct script_info *script;
4475 script = instance_dbox_script(inst);
4477 ErrPrint("Instance has no script\n");
4478 ret = DBOX_STATUS_ERROR_FAULT;
4482 script_handler_update_pointer(script, event.x, event.y, event.type);
4483 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_READ, timestamp);
4485 ret = send_delayed_access_status(inst, ret);
4488 ErrPrint("Unsupported package\n");
4489 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4493 result = packet_create_reply(packet, "i", ret);
4495 ErrPrint("Failed to create a reply packet\n");
4501 static struct packet *client_dbox_access_enable(pid_t pid, int handle, const struct packet *packet)
4503 struct packet *result;
4504 struct client_node *client;
4505 const char *pkgname;
4509 struct inst_info *inst = NULL;
4510 const struct pkg_info *pkg = NULL;
4511 struct access_info event;
4513 client = client_find_by_rpc_handle(handle);
4515 ErrPrint("Client %d is not exist\n", pid);
4516 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4520 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
4522 ErrPrint("Parameter is not matched\n");
4523 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4527 ret = validate_request(pkgname, id, &inst, &pkg);
4528 if (ret != DBOX_STATUS_ERROR_NONE) {
4532 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4533 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4535 * Enen if it fails to send packet,
4536 * The packet will be unref'd
4537 * So we don't need to check the ret value.
4539 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4540 struct script_info *script;
4543 script = instance_dbox_script(inst);
4545 ErrPrint("Instance has no script\n");
4546 ret = DBOX_STATUS_ERROR_FAULT;
4550 type = (event.type == 0) ? DBOX_SCRIPT_ACCESS_DISABLE : DBOX_SCRIPT_ACCESS_ENABLE;
4552 script_handler_update_pointer(script, event.x, event.y, event.type);
4553 ret = script_handler_feed_event(script, type, timestamp);
4555 ret = send_delayed_access_status(inst, ret);
4558 ErrPrint("Unsupported package\n");
4559 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4563 result = packet_create_reply(packet, "i", ret);
4565 ErrPrint("Failed to create a reply packet\n");
4571 static struct packet *client_dbox_access_activate(pid_t pid, int handle, const struct packet *packet)
4573 struct packet *result;
4574 struct client_node *client;
4575 const char *pkgname;
4579 struct access_info event;
4580 struct inst_info *inst = NULL;
4581 const struct pkg_info *pkg = NULL;
4583 client = client_find_by_rpc_handle(handle);
4585 ErrPrint("Client %d is not exists\n", pid);
4586 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4590 ret = packet_get(packet, "ssdiii", &pkgname, &id, ×tamp, &event.x, &event.y, &event.type);
4592 ErrPrint("Parameter is not matched\n");
4593 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4597 ret = validate_request(pkgname, id, &inst, &pkg);
4598 if (ret != DBOX_STATUS_ERROR_NONE) {
4602 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4603 ret = forward_dbox_access_packet(pkg, inst, packet_command(packet), timestamp, &event);
4604 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4605 struct script_info *script;
4607 script = instance_dbox_script(inst);
4609 ErrPrint("Instance has no script\n");
4610 ret = DBOX_STATUS_ERROR_FAULT;
4614 script_handler_update_pointer(script, event.x, event.y, event.type);
4615 ret = script_handler_feed_event(script, DBOX_SCRIPT_ACCESS_ACTIVATE, timestamp);
4617 ret = send_delayed_access_status(inst, ret);
4620 ErrPrint("Unsupported package\n");
4621 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4625 result = packet_create_reply(packet, "i", ret);
4627 ErrPrint("Failed to create a reply packet\n");
4633 static struct packet *client_dbox_key_down(pid_t pid, int handle, const struct packet *packet)
4635 struct client_node *client;
4636 const char *pkgname;
4640 unsigned int keycode;
4641 struct inst_info *inst;
4642 const struct pkg_info *pkg;
4643 struct packet *result;
4645 client = client_find_by_rpc_handle(handle);
4647 ErrPrint("Client %d is not exists\n", pid);
4648 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4652 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4654 ErrPrint("Parameter is not matched\n");
4655 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4659 ret = validate_request(pkgname, id, &inst, &pkg);
4660 if (ret != DBOX_STATUS_ERROR_NONE) {
4664 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4665 ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4666 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4667 struct script_info *script;
4669 script = instance_dbox_script(inst);
4671 ret = DBOX_STATUS_ERROR_FAULT;
4675 script_handler_update_keycode(script, keycode);
4676 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_DOWN, timestamp);
4678 ret = send_delayed_key_status(inst, ret);
4681 ErrPrint("Unsupported package\n");
4682 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4686 result = packet_create_reply(packet, "i", ret);
4688 ErrPrint("Failed to create a reply packet\n");
4694 static struct packet *client_dbox_key_focus_in(pid_t pid, int handle, const struct packet *packet)
4696 struct client_node *client;
4697 const char *pkgname;
4701 unsigned int keycode;
4702 struct inst_info *inst;
4703 const struct pkg_info *pkg;
4704 struct packet *result;
4706 client = client_find_by_rpc_handle(handle);
4708 ErrPrint("Client %d is not exists\n", pid);
4709 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4713 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4715 ErrPrint("Parameter is not matched\n");
4716 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4720 ret = validate_request(pkgname, id, &inst, &pkg);
4721 if (ret != DBOX_STATUS_ERROR_NONE) {
4725 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4726 ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4727 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4728 struct script_info *script;
4730 script = instance_dbox_script(inst);
4732 ret = DBOX_STATUS_ERROR_FAULT;
4736 script_handler_update_keycode(script, keycode);
4737 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_IN, timestamp);
4739 ret = send_delayed_key_status(inst, ret);
4742 ErrPrint("Unsupported package\n");
4743 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4747 result = packet_create_reply(packet, "i", ret);
4749 ErrPrint("Failed to create a reply packet\n");
4755 static struct packet *client_dbox_key_focus_out(pid_t pid, int handle, const struct packet *packet)
4757 struct client_node *client;
4758 const char *pkgname;
4762 unsigned int keycode;
4763 struct inst_info *inst;
4764 const struct pkg_info *pkg;
4765 struct packet *result;
4767 client = client_find_by_rpc_handle(handle);
4769 ErrPrint("Client %d is not exists\n", pid);
4770 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4774 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4776 ErrPrint("Parameter is not matched\n");
4777 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4781 ret = validate_request(pkgname, id, &inst, &pkg);
4782 if (ret != DBOX_STATUS_ERROR_NONE) {
4786 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4787 ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4788 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4789 struct script_info *script;
4791 script = instance_dbox_script(inst);
4793 ret = DBOX_STATUS_ERROR_FAULT;
4797 script_handler_update_keycode(script, keycode);
4798 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_FOCUS_OUT, timestamp);
4800 ret = send_delayed_key_status(inst, ret);
4803 ErrPrint("Unsupported package\n");
4804 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4808 result = packet_create_reply(packet, "i", ret);
4810 ErrPrint("Failed to create a reply packet\n");
4816 static struct packet *client_dbox_key_up(pid_t pid, int handle, const struct packet *packet)
4818 struct client_node *client;
4819 const char *pkgname;
4823 unsigned int keycode;
4824 struct inst_info *inst;
4825 const struct pkg_info *pkg;
4826 struct packet *result;
4828 client = client_find_by_rpc_handle(handle);
4830 ErrPrint("Client %d is not exists\n", pid);
4831 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4835 ret = packet_get(packet, "ssdi", &pkgname, &id, ×tamp, &keycode);
4837 ErrPrint("Parameter is not matched\n");
4838 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4842 ret = validate_request(pkgname, id, &inst, &pkg);
4843 if (ret != DBOX_STATUS_ERROR_NONE) {
4847 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
4848 ret = forward_dbox_key_packet(pkg, inst, packet_command(packet), timestamp, keycode);
4849 } else if (package_dbox_type(pkg) == DBOX_TYPE_SCRIPT) {
4850 struct script_info *script;
4852 script = instance_dbox_script(inst);
4854 ret = DBOX_STATUS_ERROR_FAULT;
4858 script_handler_update_keycode(script, keycode);
4859 ret = script_handler_feed_event(script, DBOX_SCRIPT_KEY_UP, timestamp);
4861 ret = send_delayed_key_status(inst, ret);
4864 ErrPrint("Unsupported package\n");
4865 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4869 result = packet_create_reply(packet, "i", ret);
4871 ErrPrint("Failed to create a reply packet\n");
4877 static int release_pixmap_cb(struct client_node *client, void *canvas)
4879 DbgPrint("Forcely unref the \"buffer\"\n");
4880 buffer_handler_pixmap_unref(canvas);
4881 return -1; /* Delete this callback */
4885 static struct packet *client_dbox_acquire_xpixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
4887 struct packet *result;
4888 const char *pkgname;
4890 struct client_node *client;
4891 struct inst_info *inst;
4895 struct buffer_info *buffer;
4898 client = client_find_by_rpc_handle(handle);
4900 ErrPrint("Client %d is not exists\n", pid);
4901 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4905 ret = packet_get(packet, "ssi", &pkgname, &id, &idx);
4907 ErrPrint("Parameter is not matched\n");
4908 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4912 if (idx >= DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT || idx < 0) {
4913 DbgPrint("Index is not valid: %d\n", idx);
4914 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4918 ret = validate_request(pkgname, id, &inst, NULL);
4919 if (ret != DBOX_STATUS_ERROR_NONE) {
4923 buffer = instance_dbox_extra_buffer(inst, idx);
4925 ErrPrint("Extra buffer for %d is not available\n", idx);
4929 buf_ptr = buffer_handler_pixmap_ref(buffer);
4931 ErrPrint("Failed to ref pixmap\n");
4932 ret = DBOX_STATUS_ERROR_NOT_EXIST;
4936 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
4938 ErrPrint("Failed to add a new client deactivate callback\n");
4939 buffer_handler_pixmap_unref(buf_ptr);
4941 pixmap = buffer_handler_pixmap(buffer);
4942 ret = DBOX_STATUS_ERROR_NONE;
4946 result = packet_create_reply(packet, "ii", pixmap, ret);
4948 ErrPrint("Failed to create a reply packet\n");
4954 static struct packet *client_dbox_acquire_pixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
4956 struct packet *result;
4957 const char *pkgname;
4959 struct client_node *client;
4960 struct inst_info *inst;
4964 struct buffer_info *buffer;
4966 client = client_find_by_rpc_handle(handle);
4968 ErrPrint("Client %d is not exists\n", pid);
4969 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4973 ret = packet_get(packet, "ss", &pkgname, &id);
4975 ErrPrint("Parameter is not matched\n");
4976 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
4980 ret = validate_request(pkgname, id, &inst, NULL);
4981 if (ret != DBOX_STATUS_ERROR_NONE) {
4985 buffer = instance_dbox_buffer(inst);
4987 struct script_info *script_info;
4989 script_info = instance_dbox_script(inst);
4991 ErrPrint("Unable to get DBOX buffer: %s\n", id);
4992 ret = DBOX_STATUS_ERROR_FAULT;
4996 buffer = script_handler_buffer_info(script_info);
4998 ErrPrint("Unable to get buffer_info: %s\n", id);
4999 ret = DBOX_STATUS_ERROR_FAULT;
5004 buf_ptr = buffer_handler_pixmap_ref(buffer);
5006 ErrPrint("Failed to ref pixmap\n");
5007 ret = DBOX_STATUS_ERROR_FAULT;
5011 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
5013 ErrPrint("Failed to add a new client deactivate callback\n");
5014 buffer_handler_pixmap_unref(buf_ptr);
5016 pixmap = buffer_handler_pixmap(buffer);
5017 ret = DBOX_STATUS_ERROR_NONE;
5021 result = packet_create_reply(packet, "ii", pixmap, ret);
5023 ErrPrint("Failed to create a reply packet\n");
5029 static struct packet *client_dbox_release_pixmap(pid_t pid, int handle, const struct packet *packet)
5031 const char *pkgname;
5033 struct client_node *client;
5038 client = client_find_by_rpc_handle(handle);
5040 ErrPrint("Client %d is not exists\n", pid);
5044 ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
5046 ErrPrint("Parameter is not matched\n");
5050 ret = validate_request(pkgname, id, NULL, NULL);
5051 if (ret != DBOX_STATUS_ERROR_NONE) {
5052 DbgPrint("It seems that the instance is already deleted: %s\n", id);
5055 buf_ptr = buffer_handler_pixmap_find(pixmap);
5057 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
5061 if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) {
5062 buffer_handler_pixmap_unref(buf_ptr);
5067 * @note No reply packet
5072 static struct packet *client_gbar_acquire_xpixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
5074 struct packet *result;
5075 const char *pkgname;
5077 struct client_node *client;
5078 struct inst_info *inst;
5082 struct buffer_info *buffer;
5085 client = client_find_by_rpc_handle(handle);
5087 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5088 ErrPrint("Client %d is not exists\n", pid);
5092 ret = packet_get(packet, "ssi", &pkgname, &id, &idx);
5094 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5095 ErrPrint("Parameter is not matched\n");
5099 if (idx >= DYNAMICBOX_CONF_EXTRA_BUFFER_COUNT || idx < 0) {
5100 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5104 ret = validate_request(pkgname, id, &inst, NULL);
5105 if (ret != DBOX_STATUS_ERROR_NONE) {
5109 buffer = instance_gbar_extra_buffer(inst, idx);
5111 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5115 buf_ptr = buffer_handler_pixmap_ref(buffer);
5117 ErrPrint("Failed to ref pixmap\n");
5118 ret = DBOX_STATUS_ERROR_FAULT;
5122 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
5124 ErrPrint("Failed to add a new client deactivate callback\n");
5125 buffer_handler_pixmap_unref(buf_ptr);
5127 pixmap = buffer_handler_pixmap(buffer);
5128 ret = DBOX_STATUS_ERROR_NONE;
5132 result = packet_create_reply(packet, "ii", pixmap, ret);
5134 ErrPrint("Failed to create a reply packet\n");
5140 static struct packet *client_gbar_acquire_pixmap(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
5142 struct packet *result;
5143 const char *pkgname;
5145 struct client_node *client;
5146 struct inst_info *inst;
5150 struct buffer_info *buffer;
5152 client = client_find_by_rpc_handle(handle);
5154 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5155 ErrPrint("Client %d is not exists\n", pid);
5159 ret = packet_get(packet, "ss", &pkgname, &id);
5161 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5162 ErrPrint("Parameter is not matched\n");
5166 ret = validate_request(pkgname, id, &inst, NULL);
5167 if (ret != DBOX_STATUS_ERROR_NONE) {
5171 if (instance_get_data(inst, GBAR_RESIZE_MONITOR_TAG)) {
5172 ret = DBOX_STATUS_ERROR_BUSY;
5176 buffer = instance_gbar_buffer(inst);
5178 struct script_info *script_info;
5180 script_info = instance_gbar_script(inst);
5182 ErrPrint("Unable to get DBOX buffer: %s\n", id);
5183 ret = DBOX_STATUS_ERROR_FAULT;
5187 buffer = script_handler_buffer_info(script_info);
5189 ErrPrint("Unable to get buffer_info: %s\n", id);
5190 ret = DBOX_STATUS_ERROR_FAULT;
5195 buf_ptr = buffer_handler_pixmap_ref(buffer);
5197 ErrPrint("Failed to ref pixmap\n");
5198 ret = DBOX_STATUS_ERROR_FAULT;
5202 ret = client_event_callback_add(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr);
5204 ErrPrint("Failed to add a new client deactivate callback\n");
5205 buffer_handler_pixmap_unref(buf_ptr);
5207 pixmap = buffer_handler_pixmap(buffer);
5208 ret = DBOX_STATUS_ERROR_NONE;
5212 result = packet_create_reply(packet, "ii", pixmap, ret);
5214 ErrPrint("Failed to create a reply packet\n");
5220 static struct packet *client_gbar_release_pixmap(pid_t pid, int handle, const struct packet *packet)
5222 const char *pkgname;
5224 struct client_node *client;
5229 client = client_find_by_rpc_handle(handle);
5231 ErrPrint("Client %d is not exists\n", pid);
5235 ret = packet_get(packet, "ssi", &pkgname, &id, &pixmap);
5237 ErrPrint("Parameter is not matched\n");
5241 ret = validate_request(pkgname, id, NULL, NULL);
5242 if (ret != DBOX_STATUS_ERROR_NONE) {
5243 DbgPrint("It seems that the instance is already deleted: %s\n", id);
5246 buf_ptr = buffer_handler_pixmap_find(pixmap);
5248 ErrPrint("Failed to find a buf_ptr of 0x%X\n", pixmap);
5252 if (client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, release_pixmap_cb, buf_ptr) == 0) {
5253 buffer_handler_pixmap_unref(buf_ptr);
5257 /*! \note No reply packet */
5261 static struct packet *client_pinup_changed(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, pinup, ret */
5263 struct client_node *client;
5264 struct packet *result;
5265 const char *pkgname;
5269 struct inst_info *inst;
5271 client = client_find_by_rpc_handle(handle);
5273 ErrPrint("Client %d is not exists\n", pid);
5274 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5279 ret = packet_get(packet, "ssi", &pkgname, &id, &pinup);
5281 ErrPrint("Parameter is not matched\n");
5282 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5287 ret = validate_request(pkgname, id, &inst, NULL);
5288 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
5289 ret = instance_set_pinup(inst, pinup);
5293 result = packet_create_reply(packet, "i", ret);
5295 ErrPrint("Failed to create a packet\n");
5301 static Eina_Bool lazy_gbar_created_cb(void *inst)
5303 struct pkg_info *pkg;
5305 if (!instance_del_data(inst, LAZY_GBAR_OPEN_TAG)) {
5306 ErrPrint("lazy,pd,open is already deleted.\n");
5307 return ECORE_CALLBACK_CANCEL;
5310 pkg = instance_package(inst);
5312 struct slave_node *slave;
5314 slave = package_slave(pkg);
5316 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst);
5321 * After unref instance first,
5322 * if the instance is not destroyed, try to notify the created GBAR event to the client.
5324 if (instance_unref(inst)) {
5326 ret = instance_client_gbar_created(inst, DBOX_STATUS_ERROR_NONE);
5328 DbgPrint("Send GBAR Create event (%d) to client\n", ret);
5332 return ECORE_CALLBACK_CANCEL;
5335 static Eina_Bool lazy_gbar_destroyed_cb(void *inst)
5337 struct pkg_info *pkg;
5338 struct slave_node *slave;
5340 if (!instance_del_data(inst, LAZY_GBAR_CLOSE_TAG)) {
5341 ErrPrint("lazy,pd,close is already deleted.\n");
5342 return ECORE_CALLBACK_CANCEL;
5345 pkg = instance_package(inst);
5347 slave = package_slave(pkg);
5349 if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
5350 DbgPrint("Delete script type close callback\n");
5351 (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst);
5352 } else if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
5353 DbgPrint("Delete buffer type close callback\n");
5354 (void)slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
5359 if (instance_unref(inst)) {
5363 * If the instance is not deleted, we should send pd-destroy event from here.
5365 ret = instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE);
5367 ErrPrint("Failed sending GBAR Destroy event (%d)\n", ret);
5371 return ECORE_CALLBACK_CANCEL;
5374 static struct packet *client_gbar_move(pid_t pid, int handle, const struct packet *packet) /* pkgname, id, x, y */
5376 struct client_node *client;
5377 struct inst_info *inst;
5378 const struct pkg_info *pkg;
5379 const char *pkgname;
5385 client = client_find_by_rpc_handle(handle);
5387 ErrPrint("Client %d is not exists\n", pid);
5388 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5392 ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
5394 ErrPrint("Parameter is not correct\n");
5395 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5399 ret = validate_request(pkgname, id, &inst, &pkg);
5400 if (ret != DBOX_STATUS_ERROR_NONE) {
5404 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
5405 instance_slave_set_gbar_pos(inst, x, y);
5406 ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
5407 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
5411 instance_slave_set_gbar_pos(inst, x, y);
5412 ix = x * instance_gbar_width(inst);
5413 iy = y * instance_gbar_height(inst);
5414 script_handler_update_pointer(instance_gbar_script(inst), ix, iy, 0);
5415 ret = instance_signal_emit(inst, "pd,move", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
5417 ErrPrint("Invalid GBAR type\n");
5418 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5421 DbgPrint("Update GBAR position: %d\n", ret);
5425 static Eina_Bool gbar_open_monitor_cb(void *inst)
5427 struct pkg_info *pkg;
5429 pkg = instance_package(inst);
5431 struct slave_node *slave;
5433 slave = package_slave(pkg);
5435 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst);
5439 (void)instance_slave_close_gbar(inst, instance_gbar_owner(inst), DBOX_CLOSE_GBAR_TIMEOUT);
5440 (void)instance_client_gbar_created(inst, DBOX_STATUS_ERROR_TIMEOUT);
5441 (void)instance_del_data(inst, GBAR_OPEN_MONITOR_TAG);
5442 (void)instance_unref(inst);
5443 ErrPrint("GBAR Open request is timed-out (%lf)\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT);
5444 return ECORE_CALLBACK_CANCEL;
5447 static Eina_Bool gbar_close_monitor_cb(void *inst)
5449 struct pkg_info *pkg;
5451 pkg = instance_package(inst);
5453 struct slave_node *slave;
5455 slave = package_slave(pkg);
5457 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
5461 (void)instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_TIMEOUT);
5462 (void)instance_del_data(inst, GBAR_CLOSE_MONITOR_TAG);
5463 (void)instance_unref(inst);
5464 ErrPrint("GBAR Close request is not processed in %lf seconds\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT);
5465 return ECORE_CALLBACK_CANCEL;
5468 static Eina_Bool gbar_resize_monitor_cb(void *inst)
5470 struct pkg_info *pkg;
5472 pkg = instance_package(inst);
5474 struct slave_node *slave;
5475 slave = package_slave(pkg);
5477 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst);
5481 (void)instance_slave_close_gbar(inst, instance_gbar_owner(inst), DBOX_CLOSE_GBAR_TIMEOUT);
5482 (void)instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_TIMEOUT);
5483 (void)instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG);
5484 (void)instance_unref(inst);
5485 ErrPrint("GBAR Resize request is not processed in %lf seconds\n", DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT);
5486 return ECORE_CALLBACK_CANCEL;
5489 static struct packet *client_create_gbar(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
5491 struct client_node *client;
5492 struct packet *result;
5493 const char *pkgname;
5496 struct inst_info *inst = NULL;
5497 const struct pkg_info *pkg = NULL;
5498 Ecore_Timer *gbar_monitor;
5502 DbgPrint("PERF_DBOX\n");
5504 client = client_find_by_rpc_handle(handle);
5506 ErrPrint("Client %d is not exists\n", pid);
5507 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5511 ret = packet_get(packet, "ssdd", &pkgname, &id, &x, &y);
5513 ErrPrint("Parameter is not matched\n");
5514 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5518 ret = validate_request(pkgname, id, &inst, &pkg);
5519 if (ret != DBOX_STATUS_ERROR_NONE) {
5523 if (instance_gbar_owner(inst)) {
5524 ErrPrint("GBAR is already owned\n");
5525 ret = DBOX_STATUS_ERROR_ALREADY;
5526 } else if (package_gbar_type(instance_package(inst)) == GBAR_TYPE_BUFFER) {
5527 gbar_monitor = instance_get_data(inst, LAZY_GBAR_CLOSE_TAG);
5529 ecore_timer_del(gbar_monitor);
5530 /* This timer attribute will be deleted */
5531 lazy_gbar_destroyed_cb(inst);
5534 if (instance_get_data(inst, GBAR_OPEN_MONITOR_TAG)) {
5535 DbgPrint("GBAR Open request is already processed\n");
5536 ret = DBOX_STATUS_ERROR_ALREADY;
5540 if (instance_get_data(inst, GBAR_CLOSE_MONITOR_TAG)) {
5541 DbgPrint("GBAR Close request is already in process\n");
5542 ret = DBOX_STATUS_ERROR_BUSY;
5546 if (instance_get_data(inst, GBAR_RESIZE_MONITOR_TAG)) {
5547 DbgPrint("GBAR resize request is already in process\n");
5548 ret = DBOX_STATUS_ERROR_BUSY;
5552 instance_slave_set_gbar_pos(inst, x, y);
5555 * Send request to the slave.
5556 * The SLAVE must has to repsonse this via "release_buffer" method.
5558 ret = instance_slave_open_gbar(inst, client);
5559 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
5560 ret = instance_signal_emit(inst, "gbar,show", instance_id(inst), 0.0, 0.0, 0.0, 0.0, x, y, 0);
5561 if (ret != DBOX_STATUS_ERROR_NONE) {
5564 tmp_ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_FAULT);
5566 ErrPrint("Unable to send script event for openning GBAR [%s], %d\n", pkgname, tmp_ret);
5569 gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_open_monitor_cb, instance_ref(inst));
5570 if (!gbar_monitor) {
5571 (void)instance_unref(inst);
5572 ErrPrint("Failed to create a timer for GBAR Open monitor\n");
5574 struct slave_node *slave;
5576 (void)instance_set_data(inst, GBAR_OPEN_MONITOR_TAG, gbar_monitor);
5578 slave = package_slave(pkg);
5580 ErrPrint("Failed to get slave(%s)\n", pkgname);
5584 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) != DBOX_STATUS_ERROR_NONE) {
5585 ErrPrint("Failed to add fault handler: %s\n");
5590 ErrPrint("Unable to send request for openning GBAR [%s]\n", pkgname);
5595 * GBAR craeted event will be send by the acquire_buffer function.
5596 * Because the slave will make request the acquire_buffer to
5599 * instance_client_gbar_created(inst);
5601 } else if (package_gbar_type(instance_package(inst)) == GBAR_TYPE_SCRIPT) {
5605 gbar_monitor = instance_get_data(inst, LAZY_GBAR_CLOSE_TAG);
5607 ecore_timer_del(gbar_monitor);
5608 /* lazy,pd,close will be deleted */
5609 lazy_gbar_destroyed_cb(inst);
5614 * ret value should be cared but in this case,
5615 * we ignore this for this moment, so we have to handle this error later.
5617 * if ret is less than 0, the slave has some problem.
5618 * but the script mode doesn't need slave for rendering default view of GBAR
5619 * so we can hanle it later.
5621 instance_slave_set_gbar_pos(inst, x, y);
5622 ix = x * instance_gbar_width(inst);
5623 iy = y * instance_gbar_height(inst);
5625 script_handler_update_pointer(instance_gbar_script(inst), ix, iy, 0);
5627 ret = instance_slave_open_gbar(inst, client);
5628 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
5629 ret = script_handler_load(instance_gbar_script(inst), 1);
5633 * Send the GBAR created event to the clients,
5635 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
5639 * But the created event has to be send afte return
5640 * from this function or the viewer couldn't care
5641 * the event correctly.
5643 inst = instance_ref(inst); /* To guarantee the inst */
5647 * At here, we don't need to rememeber the timer object.
5648 * Even if the timer callback is called, after the instance is destroyed.
5649 * lazy_gbar_created_cb will decrease the instance refcnt first.
5650 * At that time, if the instance is released, the timer callback will do nothing.
5653 * I change my mind. There is no requirements to keep the timer handler.
5654 * But I just add it to the tagged-data of the instance.
5655 * Just reserve for future-use.
5657 gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_created_cb, inst);
5658 if (!gbar_monitor) {
5659 ret = script_handler_unload(instance_gbar_script(inst), 1);
5660 ErrPrint("Unload script: %d\n", ret);
5662 ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL);
5663 ErrPrint("Close GBAR %d\n", ret);
5665 inst = instance_unref(inst);
5667 DbgPrint("Instance destroyed\n");
5670 ErrPrint("Instance: %s\n", pkgname);
5672 ret = DBOX_STATUS_ERROR_FAULT;
5674 struct slave_node *slave;
5676 (void)instance_set_data(inst, LAZY_GBAR_OPEN_TAG, gbar_monitor);
5678 slave = package_slave(pkg);
5680 ErrPrint("Failed to get slave: %s\n", pkgname);
5684 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_script_cb, inst) != DBOX_STATUS_ERROR_NONE) {
5685 ErrPrint("Failed to add fault callback: %s\n", pkgname);
5690 tmp_ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_FAULT);
5692 ErrPrint("Unable to load script: %d, (close: %d)\n", ret, tmp_ret);
5696 ErrPrint("Unable open GBAR(%s): %d\n", pkgname, ret);
5699 ErrPrint("Invalid GBAR TYPE\n");
5700 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5704 result = packet_create_reply(packet, "i", ret);
5706 ErrPrint("Failed to create a packet\n");
5712 static struct packet *client_destroy_gbar(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, filename, ret */
5714 struct client_node *client;
5715 struct packet *result;
5716 const char *pkgname;
5719 struct inst_info *inst = NULL;
5720 const struct pkg_info *pkg = NULL;
5721 Ecore_Timer *gbar_monitor;
5722 struct slave_node *slave;
5724 DbgPrint("PERF_DBOX\n");
5726 client = client_find_by_rpc_handle(handle);
5728 ErrPrint("Client %d is not exists\n", pid);
5729 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5733 ret = packet_get(packet, "ss", &pkgname, &id);
5735 ErrPrint("Parameter is not matched\n");
5736 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5740 ret = validate_request(pkgname, id, &inst, &pkg);
5741 if (ret != DBOX_STATUS_ERROR_NONE) {
5745 slave = package_slave(pkg);
5747 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5751 if (instance_gbar_owner(inst) != client) {
5752 if (instance_gbar_owner(inst) == NULL) {
5753 ErrPrint("GBAR looks already closed\n");
5754 ret = DBOX_STATUS_ERROR_ALREADY;
5756 ErrPrint("GBAR owner mimatched\n");
5757 ret = DBOX_STATUS_ERROR_PERMISSION_DENIED;
5759 } else if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
5760 DbgPrint("Buffer type GBAR\n");
5761 gbar_monitor = instance_del_data(inst, GBAR_OPEN_MONITOR_TAG);
5763 ErrPrint("GBAR Open request is found. cancel it [%s]\n", pkgname);
5765 if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst) < 0) {
5766 DbgPrint("Failed to delete a deactivate callback\n");
5771 * We should return negative value
5772 * Or we have to send "destroyed" event to the client.
5773 * If we didn't send destroyed event after return SUCCESS from here,
5774 * The client will permanently waiting destroyed event.
5775 * Because they understand that the destroy request is successfully processed.
5777 ret = instance_client_gbar_created(inst, DBOX_STATUS_ERROR_CANCEL);
5779 ErrPrint("GBAR client create event: %d\n", ret);
5782 ret = instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE);
5784 ErrPrint("GBAR client destroy event: %d\n", ret);
5787 ret = instance_signal_emit(inst, "gbar,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
5789 ErrPrint("GBAR close signal emit failed: %d\n", ret);
5792 ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL);
5794 ErrPrint("GBAR close request failed: %d\n", ret);
5797 ecore_timer_del(gbar_monitor);
5798 inst = instance_unref(inst);
5800 DbgPrint("Instance is deleted\n");
5802 } else if (instance_get_data(inst, LAZY_GBAR_CLOSE_TAG) || instance_get_data(inst, GBAR_CLOSE_MONITOR_TAG)) {
5803 DbgPrint("Close monitor is already fired\n");
5804 ret = DBOX_STATUS_ERROR_ALREADY;
5806 int resize_aborted = 0;
5808 gbar_monitor = instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG);
5810 ErrPrint("GBAR Resize request is found. clear it [%s]\n", pkgname);
5811 if (slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) < 0) {
5812 DbgPrint("Failed to delete a deactivate callback\n");
5815 ecore_timer_del(gbar_monitor);
5817 inst = instance_unref(inst);
5819 DbgPrint("Instance is destroyed while resizing\n");
5826 ret = instance_signal_emit(inst, "gbar,hide", instance_id(inst), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0);
5828 ErrPrint("GBAR close signal emit failed: %d\n", ret);
5831 ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL);
5833 ErrPrint("GBAR close request failed: %d\n", ret);
5834 } else if (resize_aborted) {
5835 gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_destroyed_cb, instance_ref(inst));
5836 if (!gbar_monitor) {
5837 ErrPrint("Failed to create a timer: %s\n", pkgname);
5838 inst = instance_unref(inst);
5840 DbgPrint("Instance is deleted\n");
5843 DbgPrint("Resize is aborted\n");
5844 (void)instance_set_data(inst, LAZY_GBAR_CLOSE_TAG, gbar_monitor);
5845 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) {
5846 ErrPrint("Failed to add a slave event callback\n");
5850 gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_close_monitor_cb, instance_ref(inst));
5851 if (!gbar_monitor) {
5852 ErrPrint("Failed to add pd close monitor\n");
5853 inst = instance_unref(inst);
5855 ErrPrint("Instance is deleted while closing GBAR\n");
5858 DbgPrint("Add close monitor\n");
5859 (void)instance_set_data(inst, GBAR_CLOSE_MONITOR_TAG, gbar_monitor);
5860 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst) < 0) {
5861 ErrPrint("Failed to add SLAVE EVENT callback\n");
5868 * release_buffer will be called by the slave after this routine.
5869 * It will send the "gbar_destroyed" event to the client
5871 * instance_client_gbar_destroyed(inst, DBOX_STATUS_ERROR_NONE);
5873 * Or the "gbar_close_monitor_cb" or "lazy_gbar_destroyed_cb" will be called.
5876 } else if (package_gbar_type(pkg) == GBAR_TYPE_SCRIPT) {
5877 DbgPrint("Script TYPE GBAR\n");
5878 gbar_monitor = instance_get_data(inst, LAZY_GBAR_OPEN_TAG);
5880 ecore_timer_del(gbar_monitor);
5881 (void)lazy_gbar_created_cb(inst);
5884 ret = script_handler_unload(instance_gbar_script(inst), 1);
5886 ErrPrint("Unable to unload the script: %s, %d\n", pkgname, ret);
5891 * Send request to the slave.
5892 * The SLAVE must has to repsonse this via "release_buffer" method.
5894 ret = instance_slave_close_gbar(inst, client, DBOX_CLOSE_GBAR_NORMAL);
5896 ErrPrint("Unable to close the GBAR: %s, %d\n", pkgname, ret);
5901 * Send the destroyed GBAR event to the client
5903 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
5907 * I've changed my mind. There is no requirements to keep the timer handler.
5908 * But I just add it to the tagged-data of the instance.
5909 * Just reserve for future-use.
5911 DbgPrint("Add lazy GBAR destroy timer\n");
5912 gbar_monitor = ecore_timer_add(DELAY_TIME, lazy_gbar_destroyed_cb, instance_ref(inst));
5913 if (!gbar_monitor) {
5914 ErrPrint("Failed to create a timer: %s\n", pkgname);
5915 inst = instance_unref(inst);
5917 DbgPrint("instance is deleted\n");
5920 (void)instance_set_data(inst, LAZY_GBAR_CLOSE_TAG, gbar_monitor);
5921 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_script_cb, inst) < 0) {
5922 ErrPrint("Failed to add a event callback for slave\n");
5927 ErrPrint("Invalid GBAR TYPE\n");
5928 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5932 result = packet_create_reply(packet, "i", ret);
5934 ErrPrint("Failed to create a packet\n");
5940 static struct packet *client_activate_package(pid_t pid, int handle, const struct packet *packet) /* pid, pkgname, ret */
5942 struct client_node *client;
5943 struct packet *result;
5944 const char *pkgname;
5946 struct pkg_info *info;
5948 client = client_find_by_rpc_handle(handle);
5950 ErrPrint("Client %d is not exists\n", pid);
5951 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5956 ret = packet_get(packet, "s", &pkgname);
5958 ErrPrint("Parameter is not matched\n");
5959 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5964 DbgPrint("pid[%d] pkgname[%s]\n", pid, pkgname);
5968 * Validate the dynamicbox package name.
5970 if (!package_is_dbox_pkgname(pkgname)) {
5971 ErrPrint("%s is not a valid dynamicbox package\n", pkgname);
5973 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
5977 info = package_find(pkgname);
5979 ret = DBOX_STATUS_ERROR_NOT_EXIST;
5981 ret = package_clear_fault(info);
5985 result = packet_create_reply(packet, "is", ret, pkgname);
5987 ErrPrint("Failed to create a packet\n");
5993 static struct packet *client_subscribed(pid_t pid, int handle, const struct packet *packet)
5995 const char *cluster;
5996 const char *category;
5997 struct client_node *client;
6000 client = client_find_by_rpc_handle(handle);
6002 ErrPrint("Client %d is not exists\n", pid);
6003 ret = DBOX_STATUS_ERROR_NOT_EXIST;
6007 ret = packet_get(packet, "ss", &cluster, &category);
6009 ErrPrint("Invalid argument\n");
6010 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6014 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
6015 if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) {
6016 ErrPrint("Invalid cluster name\n");
6022 * SUBSCRIBE cluster & sub-cluster for a client.
6024 ret = client_subscribe(client, cluster, category);
6026 package_alter_instances_to_client(client, ALTER_CREATE);
6030 /*! \note No reply packet */
6034 static struct packet *client_delete_cluster(pid_t pid, int handle, const struct packet *packet)
6036 const char *cluster;
6037 struct client_node *client;
6038 struct packet *result;
6041 client = client_find_by_rpc_handle(handle);
6043 ErrPrint("Client %d is not exists\n", pid);
6044 ret = DBOX_STATUS_ERROR_NOT_EXIST;
6048 ret = packet_get(packet, "s", &cluster);
6050 ErrPrint("Invalid parameters\n");
6051 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6055 DbgPrint("pid[%d] cluster[%s]\n", pid, cluster);
6057 if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) {
6058 ErrPrint("Invalid cluster: %s\n", cluster);
6059 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6066 ret = DBOX_STATUS_ERROR_NOT_IMPLEMENTED;
6069 result = packet_create_reply(packet, "i", ret);
6071 ErrPrint("Failed to create a packet\n");
6077 static inline int update_pkg_cb(struct category *category, const char *pkgname, int force)
6082 c_name = group_cluster_name_by_category(category);
6083 s_name = group_category_name(category);
6085 if (!c_name || !s_name || !pkgname) {
6086 ErrPrint("Name is not valid\n");
6087 return EXIT_FAILURE;
6090 DbgPrint("Send refresh request: %s (%s/%s)\n", pkgname, c_name, s_name);
6091 slave_rpc_request_update(pkgname, "", c_name, s_name, NULL, force);
6093 /* Just try to create a new package */
6094 if (util_free_space(DYNAMICBOX_CONF_IMAGE_PATH) > DYNAMICBOX_CONF_MINIMUM_SPACE) {
6096 struct inst_info *inst;
6098 timestamp = util_timestamp();
6101 * Don't need to check the subscribed clients.
6102 * Because this callback is called by the requests of clients.
6103 * It means. some clients wants to handle this instances ;)
6105 inst = instance_create(NULL, timestamp, pkgname, "", c_name, s_name, DYNAMICBOX_CONF_DEFAULT_PERIOD, 0, 0);
6107 ErrPrint("Failed to create a new instance\n");
6111 return EXIT_SUCCESS;
6114 static struct packet *client_update(pid_t pid, int handle, const struct packet *packet)
6116 struct inst_info *inst;
6117 struct client_node *client;
6118 const char *pkgname;
6123 client = client_find_by_rpc_handle(handle);
6125 ErrPrint("Cilent %d is not exists\n", pid);
6129 ret = packet_get(packet, "ssi", &pkgname, &id, &force);
6131 ErrPrint("Invalid argument\n");
6135 ret = validate_request(pkgname, id, &inst, NULL);
6136 if (ret != DBOX_STATUS_ERROR_NONE) {
6140 if (instance_client(inst) != client) {
6142 ErrPrint("Insufficient permissions [%s] - %d\n", pkgname, pid);
6144 slave_rpc_request_update(pkgname, id, instance_cluster(inst), instance_category(inst), NULL, force);
6148 /*! \note No reply packet */
6152 static struct packet *client_refresh_group(pid_t pid, int handle, const struct packet *packet)
6154 const char *cluster_id;
6155 const char *category_id;
6156 struct client_node *client;
6158 struct cluster *cluster;
6159 struct category *category;
6160 struct context_info *info;
6161 Eina_List *info_list;
6165 client = client_find_by_rpc_handle(handle);
6167 ErrPrint("Cilent %d is not exists\n", pid);
6171 ret = packet_get(packet, "ssi", &cluster_id, &category_id, &force);
6173 ErrPrint("Invalid parameter\n");
6177 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster_id, category_id);
6179 if (!strlen(cluster_id) || !strcasecmp(cluster_id, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) {
6180 ErrPrint("Invalid cluster name: %s\n", cluster_id);
6184 cluster = group_find_cluster(cluster_id);
6186 ErrPrint("Cluster [%s] is not registered\n", cluster_id);
6190 category = group_find_category(cluster, category_id);
6192 ErrPrint("Category [%s] is not registered\n", category_id);
6196 info_list = group_context_info_list(category);
6197 EINA_LIST_FOREACH(info_list, l, info) {
6198 update_pkg_cb(category, group_pkgname_from_context_info(info), force);
6202 /*! \note No reply packet */
6206 static struct packet *client_delete_category(pid_t pid, int handle, const struct packet *packet)
6208 const char *cluster;
6209 const char *category;
6210 struct client_node *client;
6211 struct packet *result;
6214 client = client_find_by_rpc_handle(handle);
6216 ErrPrint("Client %d is not exists\n", pid);
6217 ret = DBOX_STATUS_ERROR_NOT_EXIST;
6221 ret = packet_get(packet, "ss", &cluster, &category);
6223 ErrPrint("Invalid paramenters\n");
6224 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6228 DbgPrint("pid[%d] cluster[%s] category[%s]\n", pid, cluster, category);
6229 if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) {
6230 ErrPrint("Invalid cluster: %s\n", cluster);
6231 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6238 ret = DBOX_STATUS_ERROR_NOT_IMPLEMENTED;
6241 result = packet_create_reply(packet, "i", ret);
6243 ErrPrint("Failed to create a packet\n");
6249 static struct packet *client_unsubscribed(pid_t pid, int handle, const struct packet *packet)
6251 const char *cluster;
6252 const char *category;
6253 struct client_node *client;
6256 client = client_find_by_rpc_handle(handle);
6258 ErrPrint("Client %d is not exists\n", pid);
6259 ret = DBOX_STATUS_ERROR_NOT_EXIST;
6263 ret = packet_get(packet, "ss", &cluster, &category);
6265 ErrPrint("Invalid argument\n");
6266 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
6270 DbgPrint("[%d] cluster[%s] category[%s]\n", pid, cluster, category);
6272 if (!strlen(cluster) || !strcasecmp(cluster, DYNAMICBOX_CONF_DEFAULT_CLUSTER)) {
6273 ErrPrint("Invalid cluster name: %s\n", cluster);
6279 * UNSUBSCRIBE cluster & sub-cluster for a client.
6281 ret = client_unsubscribe(client, cluster, category);
6283 package_alter_instances_to_client(client, ALTER_DESTROY);
6287 /*! \note No reply packet */
6291 static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
6293 struct slave_node *slave;
6294 const char *slavename;
6297 ret = packet_get(packet, "s", &slavename);
6299 ErrPrint("Parameter is not matched\n");
6303 DbgPrint("New slave[%s](%d) is arrived\n", slavename, pid);
6305 slave = slave_find_by_name(slavename);
6307 if (!slave) { /* Try again to find a slave using pid */
6308 slave = slave_find_by_pid(pid);
6312 if (DYNAMICBOX_CONF_DEBUG_MODE || g_conf.debug_mode) {
6313 char pkgname[pathconf("/", _PC_PATH_MAX)];
6316 if (aul_app_get_pkgname_bypid(pid, pkgname, sizeof(pkgname)) != AUL_R_OK) {
6317 ErrPrint("pid[%d] is not authroized provider package, try to find it using its name[%s]\n", pid, slavename);
6318 slave = slave_find_by_name(slavename);
6319 pkgname[0] = '\0'; /* Reset the pkgname */
6321 slave = slave_find_by_pkgname(pkgname);
6325 abi = abi_find_by_pkgname(pkgname);
6327 abi = DYNAMICBOX_CONF_DEFAULT_ABI;
6328 DbgPrint("Slave pkgname is invalid, ABI is replaced with '%s'(default)\n", abi);
6331 slave = slave_create(slavename, 1, abi, pkgname, 0, NULL);
6333 ErrPrint("Failed to create a new slave for %s\n", slavename);
6337 DbgPrint("New slave is created (net: 0)\n");
6339 DbgPrint("Registered slave is replaced with this new one\n");
6340 abi = slave_abi(slave);
6342 ErrPrint("ABI is not valid: %s\n", slavename);
6343 abi = DYNAMICBOX_CONF_DEFAULT_ABI;
6347 slave_set_pid(slave, pid);
6348 DbgPrint("Provider is forcely activated, pkgname(%s), abi(%s), slavename(%s)\n", pkgname, abi, slavename);
6350 ErrPrint("Slave[%d, %s] is not exists\n", pid, slavename);
6354 if (slave_pid(slave) != pid) {
6355 if (slave_pid(slave) > 0) {
6356 CRITICAL_LOG("Slave(%s) is already assigned to %d\n", slave_name(slave), slave_pid(slave));
6358 ret = aul_terminate_pid_async(pid);
6359 CRITICAL_LOG("Terminate %d (ret: %d)\n", pid, ret);
6363 CRITICAL_LOG("PID of slave(%s) is updated (%d -> %d)\n", slave_name(slave), slave_pid(slave), pid);
6364 slave_set_pid(slave, pid);
6370 * After updating handle,
6371 * slave activated callback will be called.
6373 slave_rpc_update_handle(slave, handle);
6379 static struct packet *slave_ctrl(pid_t pid, int handle, const struct packet *packet)
6381 struct slave_node *slave;
6385 slave = slave_find_by_pid(pid);
6387 ErrPrint("Slave %d is not exists\n", pid);
6391 ret = packet_get(packet, "i", &ctrl);
6393 ErrPrint("Parameter is not matched\n");
6395 slave_set_control_option(slave, ctrl);
6402 static struct packet *slave_ping(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
6404 struct slave_node *slave;
6405 const char *slavename;
6408 slave = slave_find_by_pid(pid);
6410 ErrPrint("Slave %d is not exists\n", pid);
6414 ret = packet_get(packet, "s", &slavename);
6416 ErrPrint("Parameter is not matched\n");
6418 slave_rpc_ping(slave);
6425 static struct packet *slave_faulted(pid_t pid, int handle, const struct packet *packet)
6427 struct slave_node *slave;
6428 struct pkg_info *pkg;
6429 const char *pkgname;
6434 slave = slave_find_by_pid(pid);
6436 ErrPrint("Slave %d is not exists\n", pid);
6440 ret = packet_get(packet, "sss", &pkgname, &id, &func);
6442 ErrPrint("Parameter is not matched\n");
6446 ret = fault_info_set(slave, pkgname, id, func);
6447 DbgPrint("Slave Faulted: %s (%d)\n", slave_name(slave), ret);
6449 pkg = package_find(pkgname);
6451 ErrPrint("There is no package info found: %s\n", pkgname);
6453 package_faulted(pkg, 0);
6460 static struct packet *slave_dbox_update_begin(pid_t pid, int handle, const struct packet *packet)
6462 struct slave_node *slave;
6463 struct inst_info *inst;
6464 const struct pkg_info *pkg;
6465 const char *pkgname;
6468 const char *content;
6472 slave = slave_find_by_pid(pid);
6474 ErrPrint("Slave %d is not exists\n", pid);
6478 ret = packet_get(packet, "ssdss", &pkgname, &id, &priority, &content, &title);
6480 ErrPrint("Invalid parameters\n");
6484 ret = validate_request(pkgname, id, &inst, &pkg);
6485 if (ret != DBOX_STATUS_ERROR_NONE) {
6489 if (instance_state(inst) == INST_DESTROYED) {
6490 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6494 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
6495 ret = instance_dbox_update_begin(inst, priority, content, title);
6496 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6497 slave_freeze_ttl(slave);
6500 ErrPrint("Invalid request[%s]\n", id);
6507 static struct packet *slave_dbox_update_end(pid_t pid, int handle, const struct packet *packet)
6509 struct slave_node *slave;
6510 struct inst_info *inst;
6511 const struct pkg_info *pkg;
6512 const char *pkgname;
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("Invalid parameters\n");
6528 ret = validate_request(pkgname, id, &inst, &pkg);
6529 if (ret != DBOX_STATUS_ERROR_NONE) {
6533 if (instance_state(inst) == INST_DESTROYED) {
6534 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6538 if (package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
6539 ret = instance_dbox_update_end(inst);
6540 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6541 slave_thaw_ttl(slave);
6544 ErrPrint("Invalid request[%s]\n", id);
6551 static struct packet *slave_gbar_update_begin(pid_t pid, int handle, const struct packet *packet)
6553 struct slave_node *slave;
6554 const struct pkg_info *pkg;
6555 struct inst_info *inst;
6556 const char *pkgname;
6560 slave = slave_find_by_pid(pid);
6562 ErrPrint("Slave %d is not exists\n", pid);
6566 ret = packet_get(packet, "ss", &pkgname, &id);
6568 ErrPrint("Invalid parameters\n");
6572 ret = validate_request(pkgname, id, &inst, &pkg);
6573 if (ret != DBOX_STATUS_ERROR_NONE) {
6577 if (instance_state(inst) == INST_DESTROYED) {
6578 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6582 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
6583 (void)instance_gbar_update_begin(inst);
6585 ErrPrint("Invalid request[%s]\n", id);
6592 static struct packet *slave_key_status(pid_t pid, int handle, const struct packet *packet)
6594 struct slave_node *slave;
6595 struct inst_info *inst;
6596 const char *pkgname;
6601 slave = slave_find_by_pid(pid);
6603 ErrPrint("Slave %d is not exists\n", pid);
6607 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6609 ErrPrint("Invalid parameters\n");
6613 ret = validate_request(pkgname, id, &inst, NULL);
6614 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6615 if (instance_state(inst) == INST_DESTROYED) {
6616 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6618 (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6626 static struct packet *slave_access_status(pid_t pid, int handle, const struct packet *packet)
6628 struct slave_node *slave;
6629 struct inst_info *inst;
6630 const char *pkgname;
6635 slave = slave_find_by_pid(pid);
6637 ErrPrint("Slave %d is not exists\n", pid);
6641 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6643 ErrPrint("Invalid parameters\n");
6647 ret = validate_request(pkgname, id, &inst, NULL);
6648 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6649 if (instance_state(inst) == INST_DESTROYED) {
6650 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6652 (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6660 static struct packet *slave_close_gbar(pid_t pid, int handle, const struct packet *packet)
6662 struct slave_node *slave;
6663 struct inst_info *inst;
6664 const char *pkgname;
6669 slave = slave_find_by_pid(pid);
6671 ErrPrint("Slave %d is not exists\n", pid);
6675 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
6677 ErrPrint("Invalid parameters\n");
6681 ret = validate_request(pkgname, id, &inst, NULL);
6682 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6683 if (instance_state(inst) == INST_DESTROYED) {
6684 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6686 (void)instance_forward_packet(inst, packet_ref((struct packet *)packet));
6694 static struct packet *slave_gbar_update_end(pid_t pid, int handle, const struct packet *packet)
6696 struct slave_node *slave;
6697 const struct pkg_info *pkg;
6698 struct inst_info *inst;
6699 const char *pkgname;
6703 slave = slave_find_by_pid(pid);
6705 ErrPrint("Slave %d is not exists\n", pid);
6709 ret = packet_get(packet, "ss", &pkgname, &id);
6711 ErrPrint("Invalid parameters\n");
6715 ret = validate_request(pkgname, id, &inst, &pkg);
6716 if (ret != DBOX_STATUS_ERROR_NONE) {
6720 if (instance_state(inst) == INST_DESTROYED) {
6721 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6725 if (package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
6726 (void)instance_gbar_update_end(inst);
6728 ErrPrint("Invalid request[%s]\n", id);
6735 static struct packet *slave_call(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
6737 struct slave_node *slave;
6738 const char *pkgname;
6743 slave = slave_find_by_pid(pid);
6745 ErrPrint("Slave %d is not exists\n", pid);
6749 ret = packet_get(packet, "sss", &pkgname, &id, &func);
6751 ErrPrint("Parameter is not matched\n");
6755 ret = fault_func_call(slave, pkgname, id, func);
6756 slave_give_more_ttl(slave);
6762 static struct packet *slave_ret(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
6764 struct slave_node *slave;
6765 const char *pkgname;
6770 slave = slave_find_by_pid(pid);
6772 ErrPrint("Slave %d is not exists\n", pid);
6776 ret = packet_get(packet, "sss", &pkgname, &id, &func);
6778 ErrPrint("Parameter is not matched\n");
6782 ret = fault_func_ret(slave, pkgname, id, func);
6783 slave_give_more_ttl(slave);
6789 static struct packet *slave_extra_info(pid_t pid, int handle, const struct packet *packet)
6791 struct slave_node *slave;
6792 const char *pkgname;
6794 const char *content_info;
6800 struct inst_info *inst;
6802 slave = slave_find_by_pid(pid);
6804 ErrPrint("Slave %d is not exists\n", pid);
6808 ret = packet_get(packet, "ssssssd", &pkgname, &id, &content_info, &title, &icon, &name, &priority);
6810 ErrPrint("Parameter is not matchd\n");
6814 ret = validate_request(pkgname, id, &inst, NULL);
6815 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6816 if (instance_state(inst) == INST_DESTROYED) {
6817 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6821 instance_set_dbox_info(inst, priority, content_info, title);
6822 instance_set_alt_info(inst, icon, name);
6823 instance_extra_info_updated_by_instance(inst);
6824 slave_give_more_ttl(slave);
6831 static struct packet *slave_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, width, height, ret */
6833 struct slave_node *slave;
6834 const char *pkgname;
6835 const char *safe_filename;
6842 struct inst_info *inst;
6844 slave = slave_find_by_pid(pid);
6846 ErrPrint("Slave %d is not exists\n", pid);
6850 ret = packet_get(packet, "sssiiii", &pkgname, &id, &safe_filename, &x, &y, &w, &h);
6852 ErrPrint("Parameter is not matched\n");
6856 ret = validate_request(pkgname, id, &inst, NULL);
6857 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6858 if (instance_state(inst) == INST_DESTROYED) {
6859 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6863 switch (package_dbox_type(instance_package(inst))) {
6864 case DBOX_TYPE_SCRIPT:
6865 script_handler_resize(instance_dbox_script(inst), w, h);
6866 if (safe_filename) {
6867 (void)script_handler_parse_desc(inst, safe_filename, 0);
6869 safe_filename = util_uri_to_path(id);
6870 (void)script_handler_parse_desc(inst, safe_filename, 0);
6873 if (unlink(safe_filename) < 0) {
6874 ErrPrint("unlink: %s - %s\n", strerror(errno), safe_filename);
6877 case DBOX_TYPE_BUFFER:
6881 * text format (inst)
6883 instance_dbox_updated_by_instance(inst, safe_filename, x, y, w, h);
6887 slave_give_more_ttl(slave);
6894 static struct packet *slave_hold_scroll(pid_t pid, int handle, const struct packet *packet)
6896 struct slave_node *slave;
6897 struct inst_info *inst;
6898 const char *pkgname;
6903 slave = slave_find_by_pid(pid);
6905 ErrPrint("Slave %d is not exists\n", pid);
6909 ret = packet_get(packet, "ssi", &pkgname, &id, &seize);
6911 ErrPrint("Parameter is not matched\n");
6915 ret = validate_request(pkgname, id, &inst, NULL);
6916 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
6917 if (instance_state(inst) == INST_DESTROYED) {
6918 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6920 (void)instance_hold_scroll(inst, seize);
6928 static struct packet *slave_extra_updated(pid_t pid, int handle, const struct packet *packet)
6930 struct slave_node *slave;
6931 const char *pkgname;
6940 struct inst_info *inst;
6942 slave = slave_find_by_pid(pid);
6944 ErrPrint("Slave %d is not exists\n", pid);
6948 ret = packet_get(packet, "ssiiiiii", &pkgname, &id, &is_gbar, &idx, &x, &y, &w, &h);
6950 ErrPrint("Parameter is not matched\n");
6954 ret = validate_request(pkgname, id, &inst, NULL);
6955 if (ret != DBOX_STATUS_ERROR_NONE) {
6959 if (instance_state(inst) == INST_DESTROYED) {
6960 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
6964 (void)instance_extra_updated_by_instance(inst, is_gbar, idx, x, y, w, h);
6969 static struct packet *slave_desc_updated(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, decsfile, ret */
6971 struct slave_node *slave;
6972 const char *pkgname;
6974 const char *descfile;
6980 struct inst_info *inst;
6982 slave = slave_find_by_pid(pid);
6984 ErrPrint("Slave %d is not exists\n", pid);
6988 ret = packet_get(packet, "sssiiii", &pkgname, &id, &descfile, &x, &y, &w, &h);
6990 ErrPrint("Parameter is not matched\n");
6994 ret = validate_request(pkgname, id, &inst, NULL);
6995 if (ret != DBOX_STATUS_ERROR_NONE) {
6999 if (instance_state(inst) == INST_DESTROYED) {
7000 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
7004 switch (package_gbar_type(instance_package(inst))) {
7005 case GBAR_TYPE_SCRIPT:
7006 DbgPrint("%s updated (%s)\n", instance_id(inst), descfile);
7007 if (script_handler_is_loaded(instance_gbar_script(inst))) {
7008 (void)script_handler_parse_desc(inst, descfile, 1);
7011 case GBAR_TYPE_TEXT:
7012 instance_set_gbar_size(inst, 0, 0);
7013 case GBAR_TYPE_BUFFER:
7014 instance_gbar_updated(pkgname, id, descfile, x, y, w, h);
7017 DbgPrint("Ignore updated DESC(%s)\n", pkgname);
7025 static struct packet *slave_deleted(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, id, ret */
7027 struct slave_node *slave;
7028 const char *pkgname;
7031 struct inst_info *inst;
7033 slave = slave_find_by_pid(pid);
7035 ErrPrint("Slave %d is not exists\n", pid);
7039 ret = packet_get(packet, "ss", &pkgname, &id);
7041 ErrPrint("Parameter is not matched\n");
7045 ret = validate_request(pkgname, id, &inst, NULL);
7046 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
7047 ret = instance_destroyed(inst, DBOX_STATUS_ERROR_NONE);
7055 * \note for the BUFFER Type slave
7057 static struct packet *slave_acquire_buffer(pid_t pid, int handle, const struct packet *packet) /* type, id, w, h, size */
7059 enum target_type target;
7060 const char *pkgname;
7065 struct packet *result;
7066 struct slave_node *slave;
7067 struct inst_info *inst = NULL;
7068 const struct pkg_info *pkg = NULL;
7071 slave = slave_find_by_pid(pid);
7073 ErrPrint("Failed to find a slave\n");
7075 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7079 ret = packet_get(packet, "issiii", &target, &pkgname, &id, &w, &h, &pixel_size);
7081 ErrPrint("Invalid argument\n");
7083 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7087 ret = validate_request(pkgname, id, &inst, &pkg);
7090 if (ret != DBOX_STATUS_ERROR_NONE) {
7094 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7096 if (instance_state(inst) == INST_DESTROYED) {
7097 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
7101 if (target == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
7102 struct buffer_info *info;
7104 info = instance_dbox_buffer(inst);
7106 if (!instance_create_dbox_buffer(inst, pixel_size)) {
7107 ErrPrint("Failed to create a DBOX buffer\n");
7108 ret = DBOX_STATUS_ERROR_FAULT;
7112 info = instance_dbox_buffer(inst);
7114 ErrPrint("DBOX buffer is not valid\n");
7117 * ret value should not be changed.
7123 ret = buffer_handler_resize(info, w, h);
7124 ret = buffer_handler_load(info);
7126 instance_set_dbox_size(inst, w, h);
7127 instance_set_dbox_info(inst, DYNAMICBOX_CONF_PRIORITY_NO_CHANGE, DYNAMICBOX_CONF_CONTENT_NO_CHANGE, DYNAMICBOX_CONF_TITLE_NO_CHANGE);
7128 id = buffer_handler_id(info);
7130 ErrPrint("Failed to load a buffer(%d)\n", ret);
7132 } else if (target == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
7133 struct buffer_info *info;
7134 Ecore_Timer *gbar_monitor;
7138 gbar_monitor = instance_del_data(inst, GBAR_OPEN_MONITOR_TAG);
7139 if (!gbar_monitor) {
7140 gbar_monitor = instance_del_data(inst, GBAR_RESIZE_MONITOR_TAG);
7141 is_resize = !!gbar_monitor;
7143 /* Invalid request. Reject this */
7144 ErrPrint("Invalid request\n");
7148 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst);
7150 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_open_buffer_cb, inst);
7153 ecore_timer_del(gbar_monitor);
7154 inst = instance_unref(inst);
7156 ErrPrint("Instance refcnt is ZERO: %s\n", pkgname);
7160 info = instance_gbar_buffer(inst);
7162 if (!instance_create_gbar_buffer(inst, pixel_size)) {
7163 ErrPrint("Failed to create a GBAR buffer\n");
7164 ret = DBOX_STATUS_ERROR_FAULT;
7165 instance_client_gbar_created(inst, ret);
7169 info = instance_gbar_buffer(inst);
7171 ErrPrint("GBAR buffer is not valid\n");
7174 * ret value should not be changed.
7176 instance_client_gbar_created(inst, ret);
7181 ret = buffer_handler_resize(info, w, h);
7182 ret = buffer_handler_load(info);
7184 instance_set_gbar_size(inst, w, h);
7185 id = buffer_handler_id(info);
7187 ErrPrint("Failed to load a buffer (%d)\n", ret);
7191 * Send the GBAR created event to the client
7194 instance_client_gbar_created(inst, ret);
7199 result = packet_create_reply(packet, "is", ret, id);
7201 ErrPrint("Failed to create a reply packet\n");
7207 static struct packet *slave_acquire_extra_buffer(pid_t pid, int handle, const struct packet *packet)
7209 struct slave_node *slave;
7210 struct inst_info *inst;
7211 struct packet *result;
7212 const struct pkg_info *pkg;
7213 const char *pkgname;
7222 slave = slave_find_by_pid(pid);
7224 ErrPrint("Slave %d is not exists\n", pid);
7225 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7230 ret = packet_get(packet, "issiiii", &target, &pkgname, &id, &w, &h, &pixel_size, &idx);
7232 ErrPrint("Invalid parameters\n");
7233 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7238 ret = validate_request(pkgname, id, &inst, &pkg);
7241 if (ret != DBOX_STATUS_ERROR_NONE) {
7245 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7247 if (instance_state(inst) == INST_DESTROYED) {
7248 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
7252 if (target == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
7253 struct buffer_info *info;
7255 info = instance_dbox_extra_buffer(inst, idx);
7257 if (!instance_create_dbox_extra_buffer(inst, pixel_size, idx)) {
7258 ErrPrint("Failed to create a DBOX buffer\n");
7259 ret = DBOX_STATUS_ERROR_FAULT;
7263 info = instance_dbox_extra_buffer(inst, idx);
7265 ErrPrint("DBOX extra buffer is not valid\n");
7268 * ret value should not be changed.
7274 ret = buffer_handler_resize(info, w, h);
7275 ret = buffer_handler_load(info);
7279 * Send the extra buffer info to the viewer.
7280 * Then the viewer will try to acquire extra pixmap(aka, resource id) information
7282 id = buffer_handler_id(info);
7283 DbgPrint("Extra buffer is loaded: %s\n", id);
7284 (void)instance_client_dbox_extra_buffer_created(inst, idx);
7286 ErrPrint("Failed to load a buffer(%d)\n", ret);
7288 } else if (target == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
7289 struct buffer_info *info;
7291 info = instance_gbar_extra_buffer(inst, idx);
7293 if (!instance_create_gbar_extra_buffer(inst, pixel_size, idx)) {
7294 ErrPrint("Failed to create a GBAR buffer\n");
7295 ret = DBOX_STATUS_ERROR_FAULT;
7299 info = instance_gbar_extra_buffer(inst, idx);
7301 ErrPrint("GBAR buffer is not valid\n");
7304 * ret value should not be changed.
7310 ret = buffer_handler_resize(info, w, h);
7311 ret = buffer_handler_load(info);
7313 id = buffer_handler_id(info);
7316 * Send the extra buffer acquired event to the viewer
7318 DbgPrint("Extra buffer is loaded: %s\n", id);
7319 (void)instance_client_gbar_extra_buffer_created(inst, idx);
7321 ErrPrint("Failed to load a buffer (%d)\n", ret);
7326 result = packet_create_reply(packet, "is", ret, id);
7328 ErrPrint("Failed to create a reply packet\n");
7334 static struct packet *slave_resize_buffer(pid_t pid, int handle, const struct packet *packet)
7336 struct slave_node *slave;
7337 struct packet *result;
7338 enum target_type type;
7339 const char *pkgname;
7343 struct inst_info *inst = NULL;
7344 const struct pkg_info *pkg = NULL;
7347 slave = slave_find_by_pid(pid);
7349 ErrPrint("Failed to find a slave\n");
7350 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7355 ret = packet_get(packet, "issii", &type, &pkgname, &id, &w, &h);
7357 ErrPrint("Invalid argument\n");
7358 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7363 ret = validate_request(pkgname, id, &inst, &pkg);
7366 if (ret != DBOX_STATUS_ERROR_NONE) {
7370 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7373 * Reset "id", It will be re-used from here
7376 if (instance_state(inst) == INST_DESTROYED) {
7377 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
7381 if (type == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
7382 struct buffer_info *info;
7384 info = instance_dbox_buffer(inst);
7389 ret = buffer_handler_resize(info, w, h);
7392 * id is resued for newly assigned ID
7394 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
7395 id = buffer_handler_id(info);
7396 instance_set_dbox_size(inst, w, h);
7397 instance_set_dbox_info(inst, DYNAMICBOX_CONF_PRIORITY_NO_CHANGE, DYNAMICBOX_CONF_CONTENT_NO_CHANGE, DYNAMICBOX_CONF_TITLE_NO_CHANGE);
7399 } else if (type == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
7400 struct buffer_info *info;
7402 info = instance_gbar_buffer(inst);
7407 ret = buffer_handler_resize(info, w, h);
7410 * id is resued for newly assigned ID
7412 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
7413 id = buffer_handler_id(info);
7414 instance_set_gbar_size(inst, w, h);
7419 result = packet_create_reply(packet, "is", ret, id);
7421 ErrPrint("Failed to create a packet\n");
7427 static struct packet *slave_release_buffer(pid_t pid, int handle, const struct packet *packet)
7429 enum target_type type;
7430 const char *pkgname;
7432 struct packet *result;
7433 struct slave_node *slave;
7434 struct inst_info *inst;
7435 const struct pkg_info *pkg;
7438 slave = slave_find_by_pid(pid);
7440 ErrPrint("Failed to find a slave\n");
7441 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7445 if (packet_get(packet, "iss", &type, &pkgname, &id) != 3) {
7446 ErrPrint("Inavlid argument\n");
7447 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7451 ret = validate_request(pkgname, id, &inst, &pkg);
7452 if (ret != DBOX_STATUS_ERROR_NONE) {
7456 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7458 if (type == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
7459 struct buffer_info *info;
7461 info = instance_dbox_buffer(inst);
7462 ret = buffer_handler_unload(info);
7463 } else if (type == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
7464 struct buffer_info *info;
7465 Ecore_Timer *gbar_monitor;
7467 gbar_monitor = instance_del_data(inst, GBAR_CLOSE_MONITOR_TAG);
7468 if (!gbar_monitor && !package_is_fault(pkg)) {
7469 ErrPrint("Slave requests to release a buffer\n");
7472 * In this case just keep going to release buffer,
7473 * Even if a user(client) doesn't wants to destroy the GBAR.
7475 * If the slave tries to destroy GBAR buffer, it should be
7476 * released and reported to the client about its status.
7478 * Even if the pd is destroyed by timeout handler,
7479 * instance_client_gbar_destroyed function will be ignored
7480 * by pd.need_to_send_close_event flag.
7481 * which will be checked by instance_client_gbar_destroyed function.
7486 * provider can try to resize the buffer size.
7487 * in that case, it will release the buffer first.
7488 * Then even though the client doesn't request to close the GBAR,
7489 * the provider can release it.
7490 * If we send the close event to the client,
7491 * The client will not able to allocate GBAR again.
7492 * In this case, add the pd,monitor again. from here.
7493 * to wait the re-allocate buffer.
7494 * If the client doesn't request buffer reallocation,
7495 * Treat it as a fault. and close the GBAR.
7497 info = instance_gbar_buffer(inst);
7498 ret = buffer_handler_unload(info);
7500 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
7501 gbar_monitor = ecore_timer_add(DYNAMICBOX_CONF_GBAR_REQUEST_TIMEOUT, gbar_resize_monitor_cb, instance_ref(inst));
7502 if (!gbar_monitor) {
7503 ErrPrint("Failed to create a timer for GBAR Open monitor\n");
7504 inst = instance_unref(inst);
7506 DbgPrint("Instance is deleted\n");
7509 (void)instance_set_data(inst, GBAR_RESIZE_MONITOR_TAG, gbar_monitor);
7510 if (slave_event_callback_add(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_resize_buffer_cb, inst) != DBOX_STATUS_ERROR_NONE) {
7511 ErrPrint("Failed to add event handler: %s\n", pkgname);
7519 * If the instance has gbar_monitor, the pd close requested from client via client_destroy_gbar.
7521 slave_event_callback_del(slave, SLAVE_EVENT_DEACTIVATE, slave_fault_close_buffer_cb, inst);
7522 ecore_timer_del(gbar_monitor);
7524 inst = instance_unref(inst);
7526 ErrPrint("Instance is released: %s\n", pkgname);
7527 ret = DBOX_STATUS_ERROR_FAULT;
7532 This case means that the package is faulted so the service provider tries to release the buffer
7535 info = instance_gbar_buffer(inst);
7536 ret = buffer_handler_unload(info);
7540 * Send the GBAR destroyed event to the client
7542 instance_client_gbar_destroyed(inst, ret);
7547 result = packet_create_reply(packet, "i", ret);
7549 ErrPrint("Failed to create a packet\n");
7555 static struct packet *slave_release_extra_buffer(pid_t pid, int handle, const struct packet *packet)
7557 struct slave_node *slave;
7558 struct packet *result;
7560 struct buffer_info *info = NULL;
7564 const char *pkgname;
7565 struct inst_info *inst;
7566 const struct pkg_info *pkg;
7568 slave = slave_find_by_pid(pid);
7570 ErrPrint("Slave %d is not exists\n", pid);
7571 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7575 if (packet_get(packet, "issi", &type, &pkgname, &id, &idx) != 4) {
7576 ErrPrint("Inavlid argument\n");
7577 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7581 ret = validate_request(pkgname, id, &inst, &pkg);
7582 if (ret != DBOX_STATUS_ERROR_NONE) {
7586 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7588 if (type == TYPE_DBOX && package_dbox_type(pkg) == DBOX_TYPE_BUFFER) {
7589 info = instance_dbox_extra_buffer(inst, idx);
7590 (void)instance_client_dbox_extra_buffer_destroyed(inst, idx);
7591 } else if (type == TYPE_GBAR && package_gbar_type(pkg) == GBAR_TYPE_BUFFER) {
7592 info = instance_gbar_extra_buffer(inst, idx);
7593 (void)instance_client_gbar_extra_buffer_destroyed(inst, idx);
7597 ret = buffer_handler_unload(info);
7601 result = packet_create_reply(packet, "i", ret);
7603 ErrPrint("Failed to create a reply packet\n");
7609 static struct packet *service_instance_count(pid_t pid, int handle, const struct packet *packet)
7611 struct packet *result;
7612 struct pkg_info *pkg;
7614 const char *pkgname;
7615 const char *cluster;
7616 const char *category;
7617 Eina_List *pkg_list;
7619 Eina_List *inst_list;
7621 struct inst_info *inst;
7624 ret = packet_get(packet, "sssd", &pkgname, &cluster, &category, ×tamp);
7626 ErrPrint("Invalid packet\n");
7627 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7631 pkg_list = (Eina_List *)package_list();
7634 EINA_LIST_FOREACH(pkg_list, l, pkg) {
7635 if (pkgname && pkgname[0]) {
7636 if (strcmp(package_name(pkg), pkgname)) {
7641 inst_list = package_instance_list(pkg);
7642 EINA_LIST_FOREACH(inst_list, inst_l, inst) {
7643 if (cluster && cluster[0]) {
7644 if (strcmp(instance_cluster(inst), cluster)) {
7649 if (category && category[0]) {
7650 if (strcmp(instance_category(inst), category)) {
7660 result = packet_create_reply(packet, "i", ret);
7662 ErrPrint("Failed to create a packet\n");
7668 static struct packet *service_change_period(pid_t pid, int handle, const struct packet *packet)
7670 struct inst_info *inst;
7671 struct packet *result;
7672 const char *pkgname;
7677 ret = packet_get(packet, "ssd", &pkgname, &id, &period);
7679 ErrPrint("Invalid packet\n");
7680 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7685 struct pkg_info *pkg;
7687 pkg = package_find(pkgname);
7689 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7690 } else if (package_is_fault(pkg)) {
7691 ret = DBOX_STATUS_ERROR_FAULT;
7693 Eina_List *inst_list;
7696 inst_list = package_instance_list(pkg);
7697 EINA_LIST_FOREACH(inst_list, l, inst) {
7698 ret = instance_set_period(inst, period);
7700 ErrPrint("Failed to change the period of %s to (%lf)\n", pkgname, period);
7705 ret = validate_request(pkgname, id, &inst, NULL);
7706 if (ret == (int)DBOX_STATUS_ERROR_NONE) {
7707 if (instance_state(inst) == INST_DESTROYED) {
7708 ErrPrint("Package[%s] instance is already destroyed\n", pkgname);
7709 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7713 ret = instance_set_period(inst, period);
7717 DbgPrint("Change the update period: %s, %lf : %d\n", pkgname, period, ret);
7719 result = packet_create_reply(packet, "i", ret);
7721 ErrPrint("Failed to create a packet\n");
7727 static struct packet *service_update(pid_t pid, int handle, const struct packet *packet)
7729 Eina_List *inst_list;
7730 struct pkg_info *pkg;
7731 struct packet *result;
7732 const char *pkgname;
7734 const char *cluster;
7735 const char *category;
7736 const char *content;
7741 ret = packet_get(packet, "sssssi", &pkgname, &id, &cluster, &category, &content, &force);
7743 ErrPrint("Invalid Packet\n");
7744 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7748 lbid = package_dbox_pkgname(pkgname);
7750 ErrPrint("Invalid package %s\n", pkgname);
7751 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7755 pkg = package_find(lbid);
7757 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7762 if (package_is_fault(pkg)) {
7763 ret = DBOX_STATUS_ERROR_FAULT;
7768 inst_list = package_instance_list(pkg);
7769 if (!eina_list_count(inst_list)) {
7770 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7775 if (id && strlen(id)) {
7777 struct inst_info *inst;
7779 ret = DBOX_STATUS_ERROR_NOT_EXIST;
7780 EINA_LIST_FOREACH(inst_list, l, inst) {
7781 if (!strcmp(instance_id(inst), id)) {
7782 ret = DBOX_STATUS_ERROR_NONE;
7787 if (ret == (int)DBOX_STATUS_ERROR_NOT_EXIST) {
7795 * Validate the update requstor.
7797 slave_rpc_request_update(lbid, id, cluster, category, content, force);
7799 ret = DBOX_STATUS_ERROR_NONE;
7802 result = packet_create_reply(packet, "i", ret);
7804 ErrPrint("Failed to create a packet\n");
7810 static struct packet *liveinfo_hello(pid_t pid, int handle, const struct packet *packet)
7812 struct liveinfo *info;
7813 struct packet *result;
7815 const char *fifo_name;
7818 DbgPrint("Request arrived from %d\n", pid);
7820 if (packet_get(packet, "d", ×tamp) != 1) {
7821 ErrPrint("Invalid packet\n");
7823 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7827 info = liveinfo_create(pid, handle);
7829 ErrPrint("Failed to create a liveinfo object\n");
7831 ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
7836 fifo_name = liveinfo_filename(info);
7837 DbgPrint("FIFO Created: %s (Serve for %d)\n", fifo_name, pid);
7840 result = packet_create_reply(packet, "si", fifo_name, ret);
7842 ErrPrint("Failed to create a result packet\n");
7848 static Eina_Bool lazy_slave_list_cb(void *info)
7853 struct slave_node *slave;
7855 liveinfo_open_fifo(info);
7856 fp = liveinfo_fifo(info);
7858 liveinfo_close_fifo(info);
7859 return ECORE_CALLBACK_CANCEL;
7862 list = (Eina_List *)slave_list();
7863 EINA_LIST_FOREACH(list, l, slave) {
7864 fprintf(fp, "%d %s %s %s %d %d %d %s %d %d %lf\n",
7867 slave_pkgname(slave),
7869 slave_is_secured(slave),
7870 slave_refcnt(slave),
7871 slave_fault_count(slave),
7872 slave_state_string(slave),
7873 slave_loaded_instance(slave),
7874 slave_loaded_package(slave),
7879 fprintf(fp, "EOD\n");
7880 liveinfo_close_fifo(info);
7881 return ECORE_CALLBACK_CANCEL;
7884 static struct packet *liveinfo_slave_list(pid_t pid, int handle, const struct packet *packet)
7886 struct liveinfo *info;
7889 if (packet_get(packet, "d", ×tamp) != 1) {
7890 ErrPrint("Invalid argument\n");
7894 info = liveinfo_find_by_pid(pid);
7896 ErrPrint("Invalid request\n");
7900 lazy_slave_list_cb(info);
7905 static inline const char *visible_state_string(enum dynamicbox_visible_state state)
7912 case DBOX_HIDE_WITH_PAUSE:
7921 static Eina_Bool inst_list_cb(void *info)
7925 struct pkg_info *pkg;
7927 Eina_List *inst_list;
7928 struct inst_info *inst;
7930 pkgname = liveinfo_data(info);
7932 return ECORE_CALLBACK_CANCEL;
7935 liveinfo_open_fifo(info);
7936 fp = liveinfo_fifo(info);
7938 ErrPrint("Invalid fp\n");
7939 liveinfo_close_fifo(info);
7941 return ECORE_CALLBACK_CANCEL;
7944 if (!package_is_dbox_pkgname(pkgname)) {
7945 ErrPrint("Invalid package name\n");
7950 pkg = package_find(pkgname);
7953 ErrPrint("Package is not exists\n");
7957 inst_list = package_instance_list(pkg);
7958 EINA_LIST_FOREACH(inst_list, l, inst) {
7959 fprintf(fp, "%s %s %s %s %lf %s %d %d\n",
7961 buffer_handler_id(instance_dbox_buffer(inst)),
7962 instance_cluster(inst),
7963 instance_category(inst),
7964 instance_period(inst),
7965 visible_state_string(instance_visible_state(inst)),
7966 instance_dbox_width(inst),
7967 instance_dbox_height(inst));
7971 fprintf(fp, "EOD\n");
7972 liveinfo_close_fifo(info);
7974 return ECORE_CALLBACK_CANCEL;
7977 static struct packet *liveinfo_inst_list(pid_t pid, int handle, const struct packet *packet)
7979 const char *pkgname;
7981 struct liveinfo *info;
7983 if (packet_get(packet, "s", &pkgname) != 1) {
7984 ErrPrint("Invalid argument\n");
7988 info = liveinfo_find_by_pid(pid);
7990 ErrPrint("Invalid request\n");
7994 dup_pkgname = strdup(pkgname);
7996 ErrPrint("Invalid request\n");
8000 liveinfo_set_data(info, dup_pkgname);
8007 static Eina_Bool pkg_list_cb(void *info)
8012 Eina_List *inst_list;
8013 struct pkg_info *pkg;
8014 struct slave_node *slave;
8015 const char *slavename;
8018 liveinfo_open_fifo(info);
8019 fp = liveinfo_fifo(info);
8021 DbgPrint("Failed to open a pipe\n");
8022 liveinfo_close_fifo(info);
8023 return ECORE_CALLBACK_CANCEL;
8026 list = (Eina_List *)package_list();
8027 EINA_LIST_FOREACH(list, l, pkg) {
8028 slave = package_slave(pkg);
8031 slavename = slave_name(slave);
8032 pid = slave_pid(slave);
8038 inst_list = (Eina_List *)package_instance_list(pkg);
8039 fprintf(fp, "%d %s %s %s %d %d %d\n",
8041 strlen(slavename) ? slavename : "(none)",
8044 package_refcnt(pkg),
8045 package_fault_count(pkg),
8046 eina_list_count(inst_list)
8048 DbgPrint("%d %s %s %s %d %d %d\n",
8050 strlen(slavename) ? slavename : "(none)",
8053 package_refcnt(pkg),
8054 package_fault_count(pkg),
8055 eina_list_count(inst_list)
8059 fprintf(fp, "EOD\n");
8061 liveinfo_close_fifo(info);
8062 return ECORE_CALLBACK_CANCEL;
8065 static struct packet *liveinfo_pkg_list(pid_t pid, int handle, const struct packet *packet)
8067 struct liveinfo *info;
8070 if (packet_get(packet, "d", ×tamp) != 1) {
8071 ErrPrint("Invalid argument\n");
8075 DbgPrint("Package List: %lf\n", timestamp);
8077 info = liveinfo_find_by_pid(pid);
8079 ErrPrint("Invalid request\n");
8088 static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct packet *packet)
8093 static Eina_Bool pkg_ctrl_rmpack_cb(void *info)
8096 liveinfo_open_fifo(info);
8097 fp = liveinfo_fifo(info);
8099 liveinfo_close_fifo(info);
8100 return ECORE_CALLBACK_CANCEL;
8103 fprintf(fp, "%d\n", ENOSYS);
8104 fprintf(fp, "EOD\n");
8105 liveinfo_close_fifo(info);
8106 return ECORE_CALLBACK_CANCEL;
8109 static Eina_Bool pkg_ctrl_rminst_cb(void *info)
8113 liveinfo_open_fifo(info);
8114 fp = liveinfo_fifo(info);
8116 liveinfo_close_fifo(info);
8117 return ECORE_CALLBACK_CANCEL;
8120 fprintf(fp, "%d\n", (int)liveinfo_data(info));
8121 fprintf(fp, "EOD\n");
8122 liveinfo_close_fifo(info);
8123 return ECORE_CALLBACK_CANCEL;
8126 static Eina_Bool pkg_ctrl_faultinst_cb(void *info)
8130 liveinfo_open_fifo(info);
8131 fp = liveinfo_fifo(info);
8133 liveinfo_close_fifo(info);
8134 return ECORE_CALLBACK_CANCEL;
8137 fprintf(fp, "%d\n", (int)liveinfo_data(info));
8138 fprintf(fp, "EOD\n");
8139 liveinfo_close_fifo(info);
8140 return ECORE_CALLBACK_CANCEL;
8143 static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet)
8145 struct liveinfo *info;
8150 if (packet_get(packet, "sss", &cmd, &pkgname, &id) != 3) {
8151 ErrPrint("Invalid argument\n");
8155 info = liveinfo_find_by_pid(pid);
8157 ErrPrint("Invalid request\n");
8161 if (!strcmp(cmd, "rmpack")) {
8162 pkg_ctrl_rmpack_cb(info);
8163 } else if (!strcmp(cmd, "rminst")) {
8164 struct inst_info *inst;
8165 inst = package_find_instance_by_id(pkgname, id);
8167 liveinfo_set_data(info, (void *)ENOENT);
8169 (void)instance_destroy(inst, DBOX_DESTROY_TYPE_DEFAULT);
8170 liveinfo_set_data(info, (void *)0);
8173 pkg_ctrl_rminst_cb(info);
8174 } else if (!strcmp(cmd, "faultinst")) {
8175 struct inst_info *inst;
8176 inst = package_find_instance_by_id(pkgname, id);
8178 liveinfo_set_data(info, (void *)ENOENT);
8180 struct pkg_info *pkg;
8182 pkg = instance_package(inst);
8184 liveinfo_set_data(info, (void *)EFAULT);
8186 (void)package_faulted(pkg, 1);
8187 liveinfo_set_data(info, (void *)0);
8191 pkg_ctrl_faultinst_cb(info);
8198 static Eina_Bool master_ctrl_cb(void *info)
8202 liveinfo_open_fifo(info);
8203 fp = liveinfo_fifo(info);
8205 liveinfo_close_fifo(info);
8206 return ECORE_CALLBACK_CANCEL;
8208 fprintf(fp, "%d\nEOD\n", (int)liveinfo_data(info));
8209 liveinfo_close_fifo(info);
8211 return ECORE_CALLBACK_CANCEL;
8214 static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct packet *packet)
8216 struct liveinfo *info;
8220 int ret = DBOX_STATUS_ERROR_INVALID_PARAMETER;
8222 if (packet_get(packet, "sss", &cmd, &var, &val) != 3) {
8223 ErrPrint("Invalid argument\n");
8227 info = liveinfo_find_by_pid(pid);
8229 ErrPrint("Invalid request\n");
8233 if (!strcasecmp(var, "debug")) {
8234 if (!strcasecmp(cmd, "set")) {
8235 g_conf.debug_mode = !strcasecmp(val, "on");
8236 } else if (!strcasecmp(cmd, "get")) {
8238 ret = g_conf.debug_mode;
8239 } else if (!strcasecmp(var, "slave_max_load")) {
8240 if (!strcasecmp(cmd, "set")) {
8241 g_conf.slave_max_load = atoi(val);
8242 } else if (!strcasecmp(cmd, "get")) {
8244 ret = g_conf.slave_max_load;
8247 liveinfo_set_data(info, (void *)ret);
8248 master_ctrl_cb(info);
8254 static struct method s_info_table[] = {
8256 .cmd = CMD_STR_INFO_HELLO,
8257 .handler = liveinfo_hello,
8260 .cmd = CMD_STR_INFO_SLAVE_LIST,
8261 .handler = liveinfo_slave_list,
8264 .cmd = CMD_STR_INFO_PKG_LIST,
8265 .handler = liveinfo_pkg_list,
8268 .cmd = CMD_STR_INFO_INST_LIST,
8269 .handler = liveinfo_inst_list,
8272 .cmd = CMD_STR_INFO_SLAVE_CTRL,
8273 .handler = liveinfo_slave_ctrl,
8276 .cmd = CMD_STR_INFO_PKG_CTRL,
8277 .handler = liveinfo_pkg_ctrl,
8280 .cmd = CMD_STR_INFO_MASTER_CTRL,
8281 .handler = liveinfo_master_ctrl,
8289 static struct method s_client_table[] = {
8291 .cmd = CMD_STR_GBAR_MOUSE_MOVE,
8292 .handler = client_gbar_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8295 .cmd = CMD_STR_DBOX_MOUSE_MOVE,
8296 .handler = client_dbox_mouse_move, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8299 .cmd = CMD_STR_GBAR_MOUSE_DOWN,
8300 .handler = client_gbar_mouse_down, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
8303 .cmd = CMD_STR_GBAR_MOUSE_UP,
8304 .handler = client_gbar_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8307 .cmd = CMD_STR_DBOX_MOUSE_DOWN,
8308 .handler = client_dbox_mouse_down, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8311 .cmd = CMD_STR_DBOX_MOUSE_UP,
8312 .handler = client_dbox_mouse_up, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8315 .cmd = CMD_STR_GBAR_MOUSE_ENTER,
8316 .handler = client_gbar_mouse_enter, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
8319 .cmd = CMD_STR_GBAR_MOUSE_LEAVE,
8320 .handler = client_gbar_mouse_leave, /* pid, pkgname, id, width, height, timestamp, x, y, ret */
8323 .cmd = CMD_STR_DBOX_MOUSE_ENTER,
8324 .handler = client_dbox_mouse_enter, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8327 .cmd = CMD_STR_DBOX_MOUSE_LEAVE,
8328 .handler = client_dbox_mouse_leave, /* pid, pkgname, filename, width, height, timestamp, x, y, ret */
8331 .cmd = CMD_STR_DBOX_MOUSE_ON_SCROLL,
8332 .handler = client_dbox_mouse_on_scroll,
8335 .cmd = CMD_STR_DBOX_MOUSE_OFF_SCROLL,
8336 .handler = client_dbox_mouse_off_scroll,
8339 .cmd = CMD_STR_GBAR_MOUSE_ON_SCROLL,
8340 .handler = client_gbar_mouse_on_scroll,
8343 .cmd = CMD_STR_GBAR_MOUSE_OFF_SCROLL,
8344 .handler = client_gbar_mouse_off_scroll,
8347 .cmd = CMD_STR_DBOX_MOUSE_ON_HOLD,
8348 .handler = client_dbox_mouse_on_hold,
8351 .cmd = CMD_STR_DBOX_MOUSE_OFF_HOLD,
8352 .handler = client_dbox_mouse_off_hold,
8355 .cmd = CMD_STR_GBAR_MOUSE_ON_HOLD,
8356 .handler = client_gbar_mouse_on_hold,
8359 .cmd = CMD_STR_GBAR_MOUSE_OFF_HOLD,
8360 .handler = client_gbar_mouse_off_hold,
8363 .cmd = CMD_STR_CLICKED,
8364 .handler = client_clicked, /*!< pid, pkgname, filename, event, timestamp, x, y, ret */
8367 .cmd = CMD_STR_TEXT_SIGNAL,
8368 .handler = client_text_signal, /* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
8371 .cmd = CMD_STR_DELETE,
8372 .handler = client_delete, /* pid, pkgname, filename, ret */
8375 .cmd = CMD_STR_RESIZE,
8376 .handler = client_resize, /* pid, pkgname, filename, w, h, ret */
8380 .handler = client_new, /* pid, timestamp, pkgname, content, cluster, category, period, ret */
8383 .cmd = CMD_STR_SET_PERIOD,
8384 .handler = client_set_period, /* pid, pkgname, filename, period, ret, period */
8387 .cmd = CMD_STR_CHANGE_GROUP,
8388 .handler = client_change_group, /* pid, pkgname, filename, cluster, category, ret */
8391 .cmd = CMD_STR_GBAR_MOVE,
8392 .handler = client_gbar_move, /* pkgname, id, x, y */
8395 .cmd = CMD_STR_GBAR_ACCESS_HL,
8396 .handler = client_gbar_access_hl,
8399 .cmd = CMD_STR_GBAR_ACCESS_ACTIVATE,
8400 .handler = client_gbar_access_activate,
8403 .cmd = CMD_STR_GBAR_ACCESS_ACTION,
8404 .handler = client_gbar_access_action,
8407 .cmd = CMD_STR_GBAR_ACCESS_SCROLL,
8408 .handler = client_gbar_access_scroll,
8411 .cmd = CMD_STR_GBAR_ACCESS_VALUE_CHANGE,
8412 .handler = client_gbar_access_value_change,
8415 .cmd = CMD_STR_GBAR_ACCESS_MOUSE,
8416 .handler = client_gbar_access_mouse,
8419 .cmd = CMD_STR_GBAR_ACCESS_BACK,
8420 .handler = client_gbar_access_back,
8423 .cmd = CMD_STR_GBAR_ACCESS_OVER,
8424 .handler = client_gbar_access_over,
8427 .cmd = CMD_STR_GBAR_ACCESS_READ,
8428 .handler = client_gbar_access_read,
8431 .cmd = CMD_STR_GBAR_ACCESS_ENABLE,
8432 .handler = client_gbar_access_enable,
8436 .cmd = CMD_STR_DBOX_ACCESS_HL,
8437 .handler = client_dbox_access_hl,
8440 .cmd = CMD_STR_DBOX_ACCESS_ACTIVATE,
8441 .handler = client_dbox_access_activate,
8444 .cmd = CMD_STR_DBOX_ACCESS_ACTION,
8445 .handler = client_dbox_access_action,
8448 .cmd = CMD_STR_DBOX_ACCESS_SCROLL,
8449 .handler = client_dbox_access_scroll,
8452 .cmd = CMD_STR_DBOX_ACCESS_VALUE_CHANGE,
8453 .handler = client_dbox_access_value_change,
8456 .cmd = CMD_STR_DBOX_ACCESS_MOUSE,
8457 .handler = client_dbox_access_mouse,
8460 .cmd = CMD_STR_DBOX_ACCESS_BACK,
8461 .handler = client_dbox_access_back,
8464 .cmd = CMD_STR_DBOX_ACCESS_OVER,
8465 .handler = client_dbox_access_over,
8468 .cmd = CMD_STR_DBOX_ACCESS_READ,
8469 .handler = client_dbox_access_read,
8472 .cmd = CMD_STR_DBOX_ACCESS_ENABLE,
8473 .handler = client_dbox_access_enable,
8476 .cmd = CMD_STR_DBOX_KEY_DOWN,
8477 .handler = client_dbox_key_down,
8480 .cmd = CMD_STR_DBOX_KEY_UP,
8481 .handler = client_dbox_key_up,
8484 .cmd = CMD_STR_DBOX_KEY_FOCUS_IN,
8485 .handler = client_dbox_key_focus_in,
8488 .cmd = CMD_STR_DBOX_KEY_FOCUS_OUT,
8489 .handler = client_dbox_key_focus_out,
8492 .cmd = CMD_STR_GBAR_KEY_DOWN,
8493 .handler = client_gbar_key_down,
8496 .cmd = CMD_STR_GBAR_KEY_UP,
8497 .handler = client_gbar_key_up,
8500 .cmd = CMD_STR_GBAR_KEY_FOCUS_IN,
8501 .handler = client_gbar_key_focus_in,
8504 .cmd = CMD_STR_GBAR_KEY_FOCUS_OUT,
8505 .handler = client_gbar_key_focus_out,
8508 .cmd = CMD_STR_UPDATE_MODE,
8509 .handler = client_update_mode,
8511 // Cut HERE. Above list must be sync'd with provider list.
8514 .cmd = CMD_STR_DBOX_MOUSE_SET,
8515 .handler = client_dbox_mouse_set,
8518 .cmd = CMD_STR_DBOX_MOUSE_UNSET,
8519 .handler = client_dbox_mouse_unset,
8522 .cmd = CMD_STR_GBAR_MOUSE_SET,
8523 .handler = client_gbar_mouse_set,
8526 .cmd = CMD_STR_GBAR_MOUSE_UNSET,
8527 .handler = client_gbar_mouse_unset,
8530 .cmd = CMD_STR_CHANGE_VISIBILITY,
8531 .handler = client_change_visibility,
8534 .cmd = CMD_STR_DBOX_ACQUIRE_PIXMAP,
8535 .handler = client_dbox_acquire_pixmap,
8538 .cmd = CMD_STR_DBOX_RELEASE_PIXMAP,
8539 .handler = client_dbox_release_pixmap,
8542 .cmd = CMD_STR_GBAR_ACQUIRE_PIXMAP,
8543 .handler = client_gbar_acquire_pixmap,
8546 .cmd = CMD_STR_GBAR_RELEASE_PIXMAP,
8547 .handler = client_gbar_release_pixmap,
8550 .cmd = CMD_STR_ACQUIRE,
8551 .handler = client_acquire, /*!< pid, ret */
8554 .cmd = CMD_STR_RELEASE,
8555 .handler = cilent_release, /*!< pid, ret */
8558 .cmd = CMD_STR_PINUP_CHANGED,
8559 .handler = client_pinup_changed, /* pid, pkgname, filename, pinup, ret */
8562 .cmd = CMD_STR_CREATE_GBAR,
8563 .handler = client_create_gbar, /* pid, pkgname, filename, ret */
8566 .cmd = CMD_STR_DESTROY_GBAR,
8567 .handler = client_destroy_gbar, /* pid, pkgname, filename, ret */
8570 .cmd = CMD_STR_ACTIVATE_PACKAGE,
8571 .handler = client_activate_package, /* pid, pkgname, ret */
8574 .cmd = CMD_STR_SUBSCRIBE, /* pid, cluster, sub-cluster */
8575 .handler = client_subscribed,
8578 .cmd = CMD_STR_UNSUBSCRIBE, /* pid, cluster, sub-cluster */
8579 .handler = client_unsubscribed,
8582 .cmd = CMD_STR_DELETE_CLUSTER,
8583 .handler = client_delete_cluster,
8586 .cmd = CMD_STR_DELETE_CATEGORY,
8587 .handler = client_delete_category,
8590 .cmd = CMD_STR_REFRESH_GROUP,
8591 .handler = client_refresh_group,
8594 .cmd = CMD_STR_UPDATE,
8595 .handler = client_update,
8599 .cmd = CMD_STR_DBOX_KEY_SET,
8600 .handler = client_dbox_key_set,
8603 .cmd = CMD_STR_DBOX_KEY_UNSET,
8604 .handler = client_dbox_key_unset,
8608 .cmd = CMD_STR_GBAR_KEY_SET,
8609 .handler = client_gbar_key_set,
8612 .cmd = CMD_STR_GBAR_KEY_UNSET,
8613 .handler = client_gbar_key_unset,
8617 .cmd = CMD_STR_CLIENT_PAUSED,
8618 .handler = client_pause_request,
8621 .cmd = CMD_STR_CLIENT_RESUMED,
8622 .handler = client_resume_request,
8625 .cmd = CMD_STR_DBOX_ACQUIRE_XPIXMAP,
8626 .handler = client_dbox_acquire_xpixmap,
8629 .cmd = CMD_STR_GBAR_ACQUIRE_XPIXMAP,
8630 .handler = client_gbar_acquire_xpixmap,
8639 static struct method s_service_table[] = {
8641 .cmd = CMD_STR_SERVICE_UPDATE,
8642 .handler = service_update,
8645 .cmd = CMD_STR_SERVICE_CHANGE_PERIOD,
8646 .handler = service_change_period,
8649 .cmd = CMD_STR_SERVICE_INST_CNT,
8650 .handler = service_instance_count,
8658 static struct method s_slave_table[] = {
8660 .cmd = CMD_STR_UPDATED,
8661 .handler = slave_updated, /* slave_name, pkgname, filename, width, height, ret */
8664 .cmd = CMD_STR_DESC_UPDATED,
8665 .handler = slave_desc_updated, /* slave_name, pkgname, filename, decsfile, ret */
8668 .cmd = CMD_STR_EXTRA_UPDATED,
8669 .handler = slave_extra_updated,
8672 .cmd = CMD_STR_EXTRA_INFO,
8673 .handler = slave_extra_info, /* slave_name, pkgname, filename, priority, content_info, title, icon, name */
8676 .cmd = CMD_STR_DELETED,
8677 .handler = slave_deleted, /* slave_name, pkgname, filename, ret */
8680 .cmd = CMD_STR_FAULTED,
8681 .handler = slave_faulted, /* slave_name, pkgname, id, funcname */
8684 .cmd = CMD_STR_SCROLL,
8685 .handler = slave_hold_scroll, /* slave_name, pkgname, id, seize */
8689 .cmd = CMD_STR_DBOX_UPDATE_BEGIN,
8690 .handler = slave_dbox_update_begin,
8693 .cmd = CMD_STR_DBOX_UPDATE_END,
8694 .handler = slave_dbox_update_end,
8697 .cmd = CMD_STR_GBAR_UPDATE_BEGIN,
8698 .handler = slave_gbar_update_begin,
8701 .cmd = CMD_STR_GBAR_UPDATE_END,
8702 .handler = slave_gbar_update_end,
8706 .cmd = CMD_STR_ACCESS_STATUS,
8707 .handler = slave_access_status,
8710 .cmd = CMD_STR_KEY_STATUS,
8711 .handler = slave_key_status,
8714 .cmd = CMD_STR_CLOSE_GBAR,
8715 .handler = slave_close_gbar,
8719 .cmd = CMD_STR_CALL,
8720 .handler = slave_call, /* slave_name, pkgname, filename, function, ret */
8724 .handler = slave_ret, /* slave_name, pkgname, filename, function, ret */
8727 .cmd = CMD_STR_ACQUIRE_BUFFER,
8728 .handler = slave_acquire_buffer, /* slave_name, id, w, h, size, - out - type, shmid */
8731 .cmd = CMD_STR_RESIZE_BUFFER,
8732 .handler = slave_resize_buffer,
8735 .cmd = CMD_STR_RELEASE_BUFFER,
8736 .handler = slave_release_buffer, /* slave_name, id - ret */
8739 .cmd = CMD_STR_HELLO,
8740 .handler = slave_hello, /* slave_name, ret */
8743 .cmd = CMD_STR_PING,
8744 .handler = slave_ping, /* slave_name, ret */
8747 .cmd = CMD_STR_CTRL,
8748 .handler = slave_ctrl, /* control bits */
8752 .cmd = CMD_STR_ACQUIRE_XBUFFER,
8753 .handler = slave_acquire_extra_buffer,
8756 .cmd = CMD_STR_RELEASE_XBUFFER,
8757 .handler = slave_release_extra_buffer,
8766 HAPI int server_init(void)
8768 com_core_packet_use_thread(DYNAMICBOX_CONF_COM_CORE_THREAD);
8770 if (unlink(INFO_SOCKET) < 0) {
8771 ErrPrint("info socket: %s\n", strerror(errno));
8774 if (unlink(SLAVE_SOCKET) < 0) {
8775 ErrPrint("slave socket: %s\n", strerror(errno));
8778 if (unlink(CLIENT_SOCKET) < 0) {
8779 ErrPrint("client socket: %s\n", strerror(errno));
8782 if (unlink(SERVICE_SOCKET) < 0) {
8783 ErrPrint("service socket: %s\n", strerror(errno));
8786 s_info.info_fd = com_core_packet_server_init(INFO_SOCKET, s_info_table);
8787 if (s_info.info_fd < 0) {
8788 ErrPrint("Failed to create a info socket\n");
8791 s_info.slave_fd = com_core_packet_server_init(SLAVE_SOCKET, s_slave_table);
8792 if (s_info.slave_fd < 0) {
8793 ErrPrint("Failed to create a slave socket\n");
8796 smack_fsetlabel(s_info.slave_fd, "data-provider-master::provider", SMACK_LABEL_IPIN);
8797 smack_fsetlabel(s_info.slave_fd, "data-provider-master::provider", SMACK_LABEL_IPOUT);
8799 s_info.client_fd = com_core_packet_server_init(CLIENT_SOCKET, s_client_table);
8800 if (s_info.client_fd < 0) {
8801 ErrPrint("Failed to create a client socket\n");
8804 smack_fsetlabel(s_info.client_fd, "data-provider-master::client", SMACK_LABEL_IPIN);
8805 smack_fsetlabel(s_info.client_fd, "data-provider-master::client", SMACK_LABEL_IPOUT);
8810 * Skip address to use the NULL.
8812 s_info.remote_client_fd = com_core_packet_server_init("remote://:"CLIENT_PORT, s_client_table);
8813 if (s_info.client_fd < 0) {
8814 ErrPrint("Failed to create a remote client socket\n");
8817 smack_fsetlabel(s_info.remote_client_fd, "data-provider-master::client", SMACK_LABEL_IPIN);
8818 smack_fsetlabel(s_info.remote_client_fd, "data-provider-master::client", SMACK_LABEL_IPOUT);
8820 s_info.service_fd = com_core_packet_server_init(SERVICE_SOCKET, s_service_table);
8821 if (s_info.service_fd < 0) {
8822 ErrPrint("Faild to create a service socket\n");
8825 smack_fsetlabel(s_info.service_fd, "data-provider-master", SMACK_LABEL_IPIN);
8826 smack_fsetlabel(s_info.service_fd, "data-provider-master", SMACK_LABEL_IPOUT);
8828 if (chmod(INFO_SOCKET, 0600) < 0) {
8829 ErrPrint("info socket: %s\n", strerror(errno));
8832 if (chmod(SLAVE_SOCKET, 0666) < 0) {
8833 ErrPrint("slave socket: %s\n", strerror(errno));
8836 if (chmod(CLIENT_SOCKET, 0666) < 0) {
8837 ErrPrint("client socket: %s\n", strerror(errno));
8840 if (chmod(SERVICE_SOCKET, 0666) < 0) {
8841 ErrPrint("service socket: %s\n", strerror(errno));
8847 HAPI int server_fini(void)
8849 if (s_info.info_fd > 0) {
8850 com_core_packet_server_fini(s_info.info_fd);
8851 s_info.info_fd = -1;
8854 if (s_info.slave_fd > 0) {
8855 com_core_packet_server_fini(s_info.slave_fd);
8856 s_info.slave_fd = -1;
8859 if (s_info.client_fd > 0) {
8860 com_core_packet_server_fini(s_info.client_fd);
8861 s_info.client_fd = -1;
8864 if (s_info.remote_client_fd > 0) {
8865 com_core_packet_server_fini(s_info.remote_client_fd);
8866 s_info.remote_client_fd = -1;
8869 if (s_info.service_fd > 0) {
8870 com_core_packet_server_fini(s_info.service_fd);
8871 s_info.service_fd = -1;