2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
27 #include <vconf-keys.h>
31 #include <com-core_packet.h>
32 #include <livebox-errno.h>
37 #include "livebox_internal.h"
38 #include "desc_parser.h"
41 #include "master_rpc.h"
43 #include "critical_log.h"
51 static struct packet *master_fault_package(pid_t pid, int handle, const struct packet *packet)
57 if (packet_get(packet, "sss", &pkgname, &id, &function) != 3) {
58 ErrPrint("Invalid arguments\n");
62 master_rpc_clear_fault_package(pkgname);
63 lb_invoke_fault_handler(LB_FAULT_DEACTIVATED, pkgname, id, function);
64 DbgPrint("%s(%s) is deactivated\n", pkgname, id);
68 static struct packet *master_hold_scroll(pid_t pid, int handle, const struct packet *packet)
70 struct livebox *handler;
76 ret = packet_get(packet, "ssi", &pkgname, &id, &seize);
78 ErrPrint("Invalid argument\n");
82 handler = lb_find_livebox(pkgname, id);
84 ErrPrint("Instance(%s) is not exists\n", id);
88 DbgPrint("[HOLD] %s %d\n", id, seize);
89 lb_invoke_event_handler(handler, seize ? LB_EVENT_HOLD_SCROLL : LB_EVENT_RELEASE_SCROLL);
95 static struct packet *master_pinup(pid_t pid, int handle, const struct packet *packet)
100 struct livebox *handler;
106 ret = packet_get(packet, "iisss", &status, &pinup, &pkgname, &id, &content);
108 ErrPrint("Invalid argument\n");
112 handler = lb_find_livebox(pkgname, id);
114 ErrPrint("Instance (%s) is not exists\n", id);
119 new_content = strdup(content);
121 free(handler->content);
122 handler->content = new_content;
123 handler->is_pinned_up = pinup;
125 ErrPrint("Heap: %s\n", strerror(errno));
126 status = LB_STATUS_ERROR_MEMORY;
130 if (handler->pinup_cb) {
134 /* Make sure that user can call pinup API in its result callback */
135 cb = handler->pinup_cb;
136 cbdata = handler->pinup_cbdata;
138 handler->pinup_cb = NULL;
139 handler->pinup_cbdata = NULL;
141 cb(handler, status, cbdata);
142 } else if (status == 0) {
143 lb_invoke_event_handler(handler, LB_EVENT_PINUP_CHANGED);
150 static struct packet *master_deleted(pid_t pid, int handle, const struct packet *packet)
155 struct livebox *handler;
157 if (packet_get(packet, "ssd", &pkgname, &id, ×tamp) != 3) {
158 ErrPrint("Invalid arguemnt\n");
162 handler = lb_find_livebox_by_timestamp(timestamp);
166 * This can be happens only if the user delete a livebox
167 * right after create it before receive created event.
172 /*!< Check validity of this "handler" */
173 if (handler->state != CREATE) {
174 if (handler->state != DELETE) {
177 * This is not possible
179 CRITICAL_LOG("Already deleted handler (%s - %s)\n", pkgname, id);
184 if (handler->created_cb) {
190 * "if (handler->id == NULL)"
192 * The instance is not created yet.
193 * But the master forcely destroy it and send destroyed event to this
194 * without the created event.
196 * It could be destroyed when a slave has critical error(fault)
197 * before creating an instance successfully.
199 if (handler->created_cb == handler->deleted_cb) {
200 if (handler->created_cbdata != handler->deleted_cbdata)
201 DbgPrint("cb is same but cbdata is different (%s - %s)\n", pkgname, id);
203 handler->deleted_cb = NULL;
204 handler->deleted_cbdata = NULL;
207 DbgPrint("Call the created cb with LB_STATUS_ERROR_CANCEL\n");
208 cb = handler->created_cb;
209 cbdata = handler->created_cbdata;
211 handler->created_cb = NULL;
212 handler->created_cbdata = NULL;
214 cb(handler, LB_STATUS_ERROR_CANCEL, cbdata);
215 } else if (handler->id) {
216 if (handler->deleted_cb) {
220 cb = handler->deleted_cb;
221 cbdata = handler->deleted_cbdata;
223 handler->deleted_cb = NULL;
224 handler->deleted_cbdata = NULL;
226 DbgPrint("Call the deleted cb\n");
227 cb(handler, LB_STATUS_SUCCESS, cbdata);
229 DbgPrint("Call the lb,deleted\n");
230 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
234 DbgPrint("[%p] %s(%s) is deleted\n", handler, pkgname, id);
236 /* Just try to delete it, if a user didn't remove it from the live box list */
243 static struct packet *master_lb_update_begin(pid_t pid, int handle, const struct packet *packet)
245 struct livebox *handler;
254 ret = packet_get(packet, "ssdsss", &pkgname, &id, &priority, &content, &title, &fbfile);
256 ErrPrint("Invalid argument\n");
260 handler = lb_find_livebox(pkgname, id);
262 ErrPrint("Instance[%s] is not exists\n", id);
266 if (handler->state != CREATE) {
267 DbgPrint("(%s) is not created\n", id);
271 lb_set_priority(handler, priority);
272 lb_set_content(handler, content);
273 lb_set_title(handler, title);
277 * Width & Height is not changed in this case.
278 * If the active update is began, the size should not be changed,
279 * And if the size is changed, the provider should finish the updating first.
280 * And then begin updating again after change its size.
282 if (lb_get_lb_fb(handler)) {
283 lb_set_lb_fb(handler, fbfile);
285 ret = fb_sync(lb_get_lb_fb(handler));
286 if (ret != LB_STATUS_SUCCESS)
287 ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret);
289 lb_invoke_event_handler(handler, LB_EVENT_LB_UPDATE_BEGIN);
291 ErrPrint("Invalid request[%s], %s\n", id, fbfile);
298 static struct packet *master_pd_update_begin(pid_t pid, int handle, const struct packet *packet)
300 struct livebox *handler;
306 ret = packet_get(packet, "sss", &pkgname, &id, &fbfile);
308 ErrPrint("Invalid argument\n");
312 handler = lb_find_livebox(pkgname, id);
314 ErrPrint("Instance[%s] is not exists\n", id);
318 if (handler->state != CREATE) {
319 DbgPrint("[%s] is not created\n", id);
323 if (lb_get_pd_fb(handler)) {
324 lb_set_lb_fb(handler, fbfile);
326 ret = fb_sync(lb_get_lb_fb(handler));
327 if (ret != LB_STATUS_SUCCESS)
328 ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret);
330 lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATE_BEGIN);
332 ErrPrint("Invalid request[%s], %s\n", id, fbfile);
339 static struct packet *master_lb_update_end(pid_t pid, int handle, const struct packet *packet)
341 struct livebox *handler;
346 ret = packet_get(packet, "ss", &pkgname, &id);
348 ErrPrint("Invalid argument\n");
352 handler = lb_find_livebox(pkgname, id);
354 ErrPrint("Instance[%s] is not exists\n", id);
358 if (handler->state != CREATE) {
359 DbgPrint("[%s] is not created\n", id);
363 if (lb_get_lb_fb(handler)) {
364 lb_invoke_event_handler(handler, LB_EVENT_LB_UPDATE_END);
366 ErrPrint("Invalid request[%s]\n", id);
373 static struct packet *master_access_status(pid_t pid, int handle, const struct packet *packet)
375 struct livebox *handler;
381 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
383 ErrPrint("Invalid argument\n");
387 handler = lb_find_livebox(pkgname, id);
389 ErrPrint("Instance[%s] is not exists\n", id);
393 if (handler->state != CREATE) {
394 DbgPrint("[%s] is not created\n", id);
398 DbgPrint("Access status: %d\n", status);
400 if (handler->access_event_cb) {
404 cb = handler->access_event_cb;
405 cbdata = handler->access_event_cbdata;
407 handler->access_event_cb = NULL;
408 handler->access_event_cbdata = NULL;
410 cb(handler, status, cbdata);
412 ErrPrint("Invalid event[%s]\n", id);
418 static struct packet *master_pd_update_end(pid_t pid, int handle, const struct packet *packet)
420 struct livebox *handler;
425 ret = packet_get(packet, "ss", &pkgname, &id);
427 ErrPrint("Invalid argument\n");
431 handler = lb_find_livebox(pkgname, id);
433 ErrPrint("Instance[%s] is not exists\n", id);
437 if (handler->state != CREATE) {
438 DbgPrint("[%s] is not created\n", id);
442 if (lb_get_lb_fb(handler)) {
443 lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATE_END);
445 ErrPrint("Invalid request[%s]", id);
452 static struct packet *master_lb_updated(pid_t pid, int handle, const struct packet *packet)
459 struct livebox *handler;
465 ret = packet_get(packet, "sssiidss",
467 &fbfile, &lb_w, &lb_h,
468 &priority, &content, &title);
470 ErrPrint("Invalid argument\n");
474 handler = lb_find_livebox(pkgname, id);
476 ErrPrint("instance(%s) is not exists\n", id);
480 if (handler->state != CREATE) {
483 * Already deleted by the user.
484 * Don't try to notice anything with this, Just ignore all events
485 * Beacuse the user doesn't wants know about this anymore
487 DbgPrint("(%s) is not exists, but updated\n", id);
491 lb_set_priority(handler, priority);
492 lb_set_content(handler, content);
493 lb_set_title(handler, title);
494 lb_set_size(handler, lb_w, lb_h);
496 if (lb_text_lb(handler)) {
497 (void)parse_desc(handler, livebox_filename(handler), 0);
500 * DESC parser will call the "text event callback".
501 * Don't need to call global event callback in this case.
504 } else if (lb_get_lb_fb(handler)) {
505 lb_set_lb_fb(handler, fbfile);
506 ret = fb_sync(lb_get_lb_fb(handler));
507 if (ret != LB_STATUS_SUCCESS)
508 ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, util_basename(util_uri_to_path(id)), ret);
510 ret = LB_STATUS_SUCCESS;
513 if (ret == LB_STATUS_SUCCESS)
514 lb_invoke_event_handler(handler, LB_EVENT_LB_UPDATED);
520 static struct packet *master_pd_created(pid_t pid, int handle, const struct packet *packet)
522 struct livebox *handler;
531 ret = packet_get(packet, "sssiii", &pkgname, &id, &buf_id, &width, &height, &status);
533 ErrPrint("Invalid argument\n");
537 handler = lb_find_livebox(pkgname, id);
539 ErrPrint("Instance(%s) is not exists\n", id);
543 if (handler->state != CREATE) {
544 ErrPrint("Instance(%s) is not created\n", id);
548 lb_set_pdsize(handler, width, height);
549 if (lb_text_pd(handler)) {
550 DbgPrint("Text TYPE does not need to handle this\n");
552 (void)lb_set_pd_fb(handler, buf_id);
553 ret = fb_sync(lb_get_pd_fb(handler));
555 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
558 handler->is_pd_created = (status == 0);
560 if (handler->pd_created_cb) {
564 cb = handler->pd_created_cb;
565 cbdata = handler->pd_created_cbdata;
567 handler->pd_created_cb = NULL;
568 handler->pd_created_cbdata = NULL;
570 DbgPrint("pd_created_cb (%s) - %d\n", buf_id, status);
571 cb(handler, status, cbdata);
572 } else if (status == 0) {
573 DbgPrint("LB_EVENT_PD_CREATED (%s) - %d\n", buf_id, status);
574 lb_invoke_event_handler(handler, LB_EVENT_PD_CREATED);
581 static struct packet *master_pd_destroyed(pid_t pid, int handle, const struct packet *packet)
583 struct livebox *handler;
589 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
591 ErrPrint("Invalid argument\n");
595 handler = lb_find_livebox(pkgname, id);
597 ErrPrint("Instance(%s) is not exists\n", id);
601 if (handler->state != CREATE) {
602 ErrPrint("Instance(%s) is not created\n", id);
606 handler->is_pd_created = 0;
608 if (handler->pd_destroyed_cb) {
612 cb = handler->pd_destroyed_cb;
613 cbdata = handler->pd_destroyed_cbdata;
615 handler->pd_destroyed_cb = NULL;
616 handler->pd_destroyed_cbdata = NULL;
618 DbgPrint("Invoke the PD Destroyed CB\n");
619 cb(handler, status, cbdata);
620 } else if (status == 0) {
621 DbgPrint("Invoke the LB_EVENT_PD_DESTROYED event\n");
622 lb_invoke_event_handler(handler, LB_EVENT_PD_DESTROYED);
629 static struct packet *master_pd_updated(pid_t pid, int handle, const struct packet *packet)
633 const char *descfile;
636 struct livebox *handler;
640 ret = packet_get(packet, "ssssii",
645 ErrPrint("Invalid argument\n");
649 handler = lb_find_livebox(pkgname, id);
651 ErrPrint("Instance(%s) is not exists\n", id);
655 if (handler->state != CREATE) {
658 * This handler is already deleted by the user.
659 * So don't try to notice anything about this anymore.
660 * Just ignore all events.
662 ErrPrint("Instance(%s) is not created\n", id);
666 lb_set_pdsize(handler, pd_w, pd_h);
668 if (lb_text_pd(handler)) {
669 (void)parse_desc(handler, descfile, 1);
671 (void)lb_set_pd_fb(handler, fbfile);
673 ret = fb_sync(lb_get_pd_fb(handler));
675 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
677 lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATED);
684 static struct packet *master_update_mode(pid_t pid, int handle, const struct packet *packet)
686 struct livebox *handler;
694 ErrPrint("Invalid packet\n");
698 ret = packet_get(packet, "ssii", &pkgname, &id, &status, &active_mode);
700 ErrPrint("Invalid argument\n");
704 DbgPrint("Update mode is changed: %d, %d, %s\n", status, active_mode, id);
706 handler = lb_find_livebox(pkgname, id);
708 ErrPrint("Livebox(%s) is not found\n", id);
712 if (handler->state != CREATE) {
713 ErrPrint("Livebox(%s) is not created yet\n", id);
717 if (status == LB_STATUS_SUCCESS)
718 lb_set_update_mode(handler, active_mode);
720 if (handler->update_mode_cb) {
724 cb = handler->update_mode_cb;
725 cbdata = handler->update_mode_cbdata;
727 handler->update_mode_cb = NULL;
728 handler->update_mode_cbdata = NULL;
730 cb(handler, status, cbdata);
732 lb_invoke_event_handler(handler, LB_EVENT_UPDATE_MODE_CHANGED);
739 static struct packet *master_size_changed(pid_t pid, int handle, const struct packet *packet)
741 struct livebox *handler;
752 ErrPrint("Invalid packet\n");
756 ret = packet_get(packet, "sssiiii", &pkgname, &id, &fbfile, &is_pd, &w, &h, &status);
758 ErrPrint("Invalid argument\n");
762 DbgPrint("Size is changed: %dx%d (%s), fb: [%s]\n", w, h, id, fbfile);
764 handler = lb_find_livebox(pkgname, id);
766 ErrPrint("Livebox(%s) is not found\n", id);
770 if (handler->state != CREATE) {
771 ErrPrint("Livebox(%s) is not created yet\n", id);
776 DbgPrint("PD is resized\n");
779 * PD is not able to resized by the client.
780 * PD is only can be managed by the provider.
781 * So the PD has no private resized event handler.
782 * Notify it via global event handler only.
785 lb_set_pdsize(handler, w, h);
786 lb_invoke_event_handler(handler, LB_EVENT_PD_SIZE_CHANGED);
788 ErrPrint("This is not possible. PD Size is changed but the return value is not ZERO (%d)\n", status);
792 DbgPrint("LB is successfully resized (%dx%d)\n", w, h);
793 lb_set_size(handler, w, h);
797 * If there is a created LB FB,
800 if (lb_get_lb_fb(handler)) {
801 lb_set_lb_fb(handler, fbfile);
803 ret = fb_sync(lb_get_lb_fb(handler));
805 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
807 /* Just update the size info only. */
812 * I cannot believe client.
813 * So I added some log before & after call the user callback.
815 if (handler->size_changed_cb) {
819 cb = handler->size_changed_cb;
820 cbdata = handler->size_cbdata;
822 handler->size_changed_cb = NULL;
823 handler->size_cbdata = NULL;
825 cb(handler, status, cbdata);
827 lb_invoke_event_handler(handler, LB_EVENT_LB_SIZE_CHANGED);
830 DbgPrint("LB is not resized: %dx%d (%d)\n", w, h, status);
831 if (handler->size_changed_cb) {
835 cb = handler->size_changed_cb;
836 cbdata = handler->size_cbdata;
838 handler->size_changed_cb = NULL;
839 handler->size_cbdata = NULL;
841 cb(handler, status, cbdata);
850 static struct packet *master_period_changed(pid_t pid, int handle, const struct packet *packet)
852 struct livebox *handler;
859 ret = packet_get(packet, "idss", &status, &period, &pkgname, &id);
861 ErrPrint("Invalid argument\n");
865 handler = lb_find_livebox(pkgname, id);
867 ErrPrint("Livebox(%s) is not found\n", id);
871 if (handler->state != CREATE) {
872 ErrPrint("Livebox(%s) is not created\n", id);
876 DbgPrint("Update period is changed? %lf (%d)\n", period, status);
878 lb_set_period(handler, period);
880 if (handler->period_changed_cb) {
884 cb = handler->period_changed_cb;
885 cbdata = handler->period_cbdata;
887 handler->period_changed_cb = NULL;
888 handler->period_cbdata = NULL;
890 cb(handler, status, cbdata);
891 } else if (status == 0) {
892 lb_invoke_event_handler(handler, LB_EVENT_PERIOD_CHANGED);
899 static struct packet *master_group_changed(pid_t pid, int handle, const struct packet *packet)
901 struct livebox *handler;
906 const char *category;
909 ret = packet_get(packet, "ssiss", &pkgname, &id, &status, &cluster, &category);
911 ErrPrint("Invalid argument\n");
915 handler = lb_find_livebox(pkgname, id);
917 ErrPrint("Livebox(%s) is not exists\n", id);
921 if (handler->state != CREATE) {
924 * Do no access this handler,
925 * You cannot believe this handler anymore.
927 ErrPrint("Livebox(%s) is not created\n", id);
931 DbgPrint("Group is changed? [%s] / [%s] (%d)\n", cluster, category, status);
933 (void)lb_set_group(handler, cluster, category);
935 if (handler->group_changed_cb) {
939 cb = handler->group_changed_cb;
940 cbdata = handler->group_cbdata;
942 handler->group_changed_cb = NULL;
943 handler->group_cbdata = NULL;
945 cb(handler, status, cbdata);
946 } else if (status == 0) {
947 lb_invoke_event_handler(handler, LB_EVENT_GROUP_CHANGED);
954 static struct packet *master_created(pid_t pid, int handle, const struct packet *packet)
956 struct livebox *handler;
967 const char *category;
968 const char *lb_fname;
969 const char *pd_fname;
973 const char *auto_launch;
978 enum lb_type lb_type;
979 enum pd_type pd_type;
983 int old_state = DESTROYED;
987 ret = packet_get(packet, "dsssiiiisssssdiiiiidsi",
989 &pkgname, &id, &content,
990 &lb_w, &lb_h, &pd_w, &pd_h,
991 &cluster, &category, &lb_fname, &pd_fname,
992 &auto_launch, &priority, &size_list, &user, &pinup_supported,
993 &lb_type, &pd_type, &period, &title, &is_pinned_up);
995 ErrPrint("Invalid argument\n");
996 ret = LB_STATUS_ERROR_INVALID;
1000 ErrPrint("[%lf] pkgname: %s, id: %s, content: %s, "
1001 "pd_w: %d, pd_h: %d, lb_w: %d, lb_h: %d, "
1002 "cluster: %s, category: %s, lb_fname: \"%s\", pd_fname: \"%s\", "
1003 "auto_launch: %s, priority: %lf, size_list: %d, user: %d, pinup: %d, "
1004 "lb_type: %d, pd_type: %d, period: %lf, title: [%s], is_pinned_up: %d\n",
1005 timestamp, pkgname, id, content,
1006 pd_w, pd_h, lb_w, lb_h,
1007 cluster, category, lb_fname, pd_fname,
1008 auto_launch, priority, size_list, user, pinup_supported,
1009 lb_type, pd_type, period, title, is_pinned_up);
1011 handler = lb_find_livebox_by_timestamp(timestamp);
1013 handler = lb_new_livebox(pkgname, id, timestamp);
1015 ErrPrint("Failed to create a new livebox\n");
1016 ret = LB_STATUS_ERROR_FAULT;
1020 old_state = handler->state;
1022 if (handler->state != CREATE) {
1023 if (handler->state != DELETE) {
1026 * This is not possible!!!
1028 ErrPrint("Invalid handler\n");
1029 ret = LB_STATUS_ERROR_INVALID;
1035 * After get the delete states,
1036 * call the create callback with deleted result.
1040 old_state = handler->state;
1043 ErrPrint("Already created: timestamp[%lf] "
1044 "pkgname[%s], id[%s] content[%s] "
1045 "cluster[%s] category[%s] lb_fname[%s] pd_fname[%s]\n",
1046 timestamp, pkgname, id,
1047 content, cluster, category,
1048 lb_fname, pd_fname);
1050 ret = LB_STATUS_ERROR_ALREADY;
1054 lb_set_id(handler, id);
1057 lb_set_size(handler, lb_w, lb_h);
1058 handler->lb.type = lb_type;
1059 handler->is_pinned_up = is_pinned_up;
1064 case _LB_TYPE_SCRIPT:
1065 case _LB_TYPE_BUFFER:
1066 if (!strlen(lb_fname))
1068 lb_set_lb_fb(handler, lb_fname);
1069 ret = fb_sync(lb_get_lb_fb(handler));
1071 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
1074 lb_set_text_lb(handler);
1080 handler->pd.type = pd_type;
1081 lb_set_pdsize(handler, pd_w, pd_h);
1082 lb_set_default_pdsize(handler, pd_w, pd_h);
1084 case _PD_TYPE_SCRIPT:
1085 case _PD_TYPE_BUFFER:
1086 if (!strlen(pd_fname))
1089 lb_set_pd_fb(handler, pd_fname);
1090 ret = fb_sync(lb_get_pd_fb(handler));
1092 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
1095 lb_set_text_pd(handler);
1101 lb_set_priority(handler, priority);
1103 lb_set_size_list(handler, size_list);
1104 lb_set_group(handler, cluster, category);
1106 lb_set_content(handler, content);
1107 lb_set_title(handler, title);
1109 lb_set_user(handler, user);
1111 lb_set_auto_launch(handler, auto_launch);
1112 lb_set_pinup(handler, pinup_supported);
1114 lb_set_period(handler, period);
1118 if (handler->state == CREATE) {
1121 * These callback can change the handler->state.
1122 * So we have to use the "old_state" which stored state before call these callbacks
1125 if (handler->created_cb) {
1129 cb = handler->created_cb;
1130 cbdata = handler->created_cbdata;
1132 handler->created_cb = NULL;
1133 handler->created_cbdata = NULL;
1135 DbgPrint("Invoke the created_cb\n");
1136 cb(handler, ret, cbdata);
1138 DbgPrint("Invoke the lb,created\n");
1139 lb_invoke_event_handler(handler, LB_EVENT_CREATED);
1144 if (ret == 0 && old_state == DELETE) {
1145 DbgPrint("Send the delete request\n");
1146 lb_send_delete(handler, handler->created_cb, handler->created_cbdata);
1150 * handler->created_cb = NULL;
1151 * handler->created_cbdata = NULL;
1153 * Do not clear this to use this from the deleted event callback.
1154 * if this value is not cleared when the deleted event callback check it,
1155 * it means that the created function is not called yet.
1156 * Then the call the deleted event callback with LB_STATUS_ERROR_CANCEL errno.
1163 static struct method s_table[] = {
1165 .cmd = "lb_updated", /* pkgname, id, lb_w, lb_h, priority, ret */
1166 .handler = master_lb_updated,
1169 .cmd = "pd_updated", /* pkgname, id, descfile, pd_w, pd_h, ret */
1170 .handler = master_pd_updated,
1173 .cmd = "pd_created",
1174 .handler = master_pd_created,
1177 .cmd = "pd_destroyed",
1178 .handler = master_pd_destroyed,
1181 .cmd = "fault_package", /* pkgname, id, function, ret */
1182 .handler = master_fault_package,
1185 .cmd = "deleted", /* pkgname, id, timestamp, ret */
1186 .handler = master_deleted,
1189 .cmd = "created", /* timestamp, pkgname, id, content, lb_w, lb_h, pd_w, pd_h, cluster, category, lb_file, pd_file, auto_launch, priority, size_list, is_user, pinup_supported, text_lb, text_pd, period, ret */
1190 .handler = master_created,
1193 .cmd = "group_changed",
1194 .handler = master_group_changed,
1197 .cmd = "period_changed",
1198 .handler = master_period_changed,
1201 .cmd = "size_changed",
1202 .handler = master_size_changed,
1206 .handler = master_pinup,
1210 .handler = master_hold_scroll,
1214 .cmd = "update_mode",
1215 .handler = master_update_mode,
1219 .cmd = "lb_update_begin",
1220 .handler = master_lb_update_begin,
1223 .cmd = "lb_update_end",
1224 .handler = master_lb_update_end,
1228 .cmd = "pd_update_begin",
1229 .handler = master_pd_update_begin,
1232 .cmd = "pd_update_end",
1233 .handler = master_pd_update_end,
1237 .cmd = "access_status",
1238 .handler = master_access_status,
1247 static void acquire_cb(struct livebox *handler, const struct packet *result, void *data)
1250 DbgPrint("Result packet is not valid\n");
1254 if (packet_get(result, "i", &ret) != 1)
1255 ErrPrint("Invalid argument\n");
1257 DbgPrint("Acquire returns: %d\n", ret);
1263 static inline int make_connection(void)
1265 struct packet *packet;
1268 DbgPrint("Let's making connection!\n");
1270 s_info.fd = com_core_packet_client_init(CLIENT_SOCKET, 0, s_table);
1271 if (s_info.fd < 0) {
1272 ErrPrint("Try this again later\n");
1273 return LB_STATUS_ERROR_IO;
1276 packet = packet_create("acquire", "d", util_timestamp());
1278 com_core_packet_client_fini(s_info.fd);
1280 return LB_STATUS_ERROR_FAULT;
1283 ret = master_rpc_async_request(NULL, packet, 1, acquire_cb, NULL);
1285 ErrPrint("Master RPC returns %d\n", ret);
1286 com_core_packet_client_fini(s_info.fd);
1288 return LB_STATUS_ERROR_IO;
1291 return LB_STATUS_SUCCESS;
1294 static int connected_cb(int handle, void *data)
1296 master_rpc_check_and_fire_consumer();
1300 static void master_started_cb(keynode_t *node, void *data)
1304 if (vconf_get_bool(VCONFKEY_MASTER_STARTED, &state) < 0)
1305 ErrPrint("Unable to get [%s]\n", VCONFKEY_MASTER_STARTED);
1307 DbgPrint("Master state: %d\n", state);
1308 if (state == 1 && make_connection() == LB_STATUS_SUCCESS) {
1310 ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb);
1311 DbgPrint("master_started vconf key de-registered [%d]\n", ret);
1315 static int disconnected_cb(int handle, void *data)
1317 if (s_info.fd != handle) {
1318 /*!< This handle is not my favor */
1322 s_info.fd = -1; /*!< Disconnected */
1324 master_rpc_clear_all_request();
1325 lb_invoke_fault_handler(LB_FAULT_PROVIDER_DISCONNECTED, MASTER_PKGNAME, "default", "disconnected");
1329 if (vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb, NULL) < 0)
1330 ErrPrint("Failed to add vconf for monitoring service state\n");
1332 DbgPrint("vconf event callback is registered\n");
1334 master_started_cb(NULL, NULL);
1338 int client_init(void)
1340 com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
1341 com_core_add_event_callback(CONNECTOR_CONNECTED, connected_cb, NULL);
1342 if (vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb, NULL) < 0)
1343 ErrPrint("Failed to add vconf for service state\n");
1345 DbgPrint("vconf event callback is registered\n");
1347 master_started_cb(NULL, NULL);
1356 const char *client_addr(void)
1358 return CLIENT_SOCKET;
1361 int client_fini(void)
1364 ret = vconf_ignore_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb);
1366 DbgPrint("Ignore vconf key: %d\n", ret);
1367 com_core_packet_client_fini(s_info.fd);
1368 com_core_del_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
1369 com_core_del_event_callback(CONNECTOR_CONNECTED, connected_cb, NULL);
1371 return LB_STATUS_SUCCESS;