2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (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.
28 #include <com-core_packet.h>
29 #include <livebox-errno.h>
34 #include "livebox_internal.h"
35 #include "desc_parser.h"
38 #include "master_rpc.h"
40 #include "critical_log.h"
42 static inline void make_connection(void);
52 static struct packet *master_fault_package(pid_t pid, int handle, const struct packet *packet)
58 if (packet_get(packet, "sss", &pkgname, &id, &function) != 3) {
59 ErrPrint("Invalid arguments\n");
63 master_rpc_clear_fault_package(pkgname);
64 lb_invoke_fault_handler(LB_FAULT_DEACTIVATED, pkgname, id, function);
65 DbgPrint("%s(%s) is deactivated\n", pkgname, id);
69 static struct packet *master_hold_scroll(pid_t pid, int handle, const struct packet *packet)
71 struct livebox *handler;
77 ret = packet_get(packet, "ssi", &pkgname, &id, &seize);
79 ErrPrint("Invalid argument\n");
83 handler = lb_find_livebox(pkgname, id);
85 ErrPrint("Instance(%s) is not exists\n", id);
89 DbgPrint("[HOLD] %s %d\n", id, seize);
90 lb_invoke_event_handler(handler, seize ? LB_EVENT_HOLD_SCROLL : LB_EVENT_RELEASE_SCROLL);
96 static struct packet *master_pinup(pid_t pid, int handle, const struct packet *packet)
101 struct livebox *handler;
107 ret = packet_get(packet, "iisss", &status, &pinup, &pkgname, &id, &content);
109 ErrPrint("Invalid argument\n");
113 handler = lb_find_livebox(pkgname, id);
115 ErrPrint("Instance (%s) is not exists\n", id);
120 new_content = strdup(content);
122 free(handler->content);
123 handler->content = new_content;
124 handler->is_pinned_up = pinup;
126 ErrPrint("Heap: %s\n", strerror(errno));
127 status = LB_STATUS_ERROR_MEMORY;
131 if (handler->pinup_cb) {
135 /* Make sure that user can call pinup API in its result callback */
136 cb = handler->pinup_cb;
137 cbdata = handler->pinup_cbdata;
139 handler->pinup_cb = NULL;
140 handler->pinup_cbdata = NULL;
142 cb(handler, status, cbdata);
143 } else if (status == 0) {
144 lb_invoke_event_handler(handler, LB_EVENT_PINUP_CHANGED);
151 static struct packet *master_deleted(pid_t pid, int handle, const struct packet *packet)
156 struct livebox *handler;
158 if (packet_get(packet, "ssd", &pkgname, &id, ×tamp) != 3) {
159 ErrPrint("Invalid arguemnt\n");
163 handler = lb_find_livebox_by_timestamp(timestamp);
167 * This can be happens only if the user delete a livebox
168 * right after create it before receive created event.
173 /*!< Check validity of this "handler" */
174 if (handler->state != CREATE) {
175 if (handler->state != DELETE) {
178 * This is not possible
180 CRITICAL_LOG("Already deleted handler (%s - %s)\n", pkgname, id);
185 if (handler->created_cb) {
191 * "if (handler->id == NULL)"
193 * The instance is not created yet.
194 * But the master forcely destroy it and send destroyed event to this
195 * without the created event.
197 * It could be destroyed when a slave has critical error(fault)
198 * before creating an instance successfully.
200 if (handler->created_cb == handler->deleted_cb) {
201 if (handler->created_cbdata != handler->deleted_cbdata)
202 DbgPrint("cb is same but cbdata is different (%s - %s)\n", pkgname, id);
204 handler->deleted_cb = NULL;
205 handler->deleted_cbdata = NULL;
208 DbgPrint("Call the created cb with LB_STATUS_ERROR_CANCEL\n");
209 cb = handler->created_cb;
210 cbdata = handler->created_cbdata;
212 handler->created_cb = NULL;
213 handler->created_cbdata = NULL;
215 cb(handler, LB_STATUS_ERROR_CANCEL, cbdata);
216 } else if (handler->id) {
217 if (handler->deleted_cb) {
221 cb = handler->deleted_cb;
222 cbdata = handler->deleted_cbdata;
224 handler->deleted_cb = NULL;
225 handler->deleted_cbdata = NULL;
227 DbgPrint("Call the deleted cb\n");
228 cb(handler, LB_STATUS_SUCCESS, cbdata);
230 DbgPrint("Call the lb,deleted\n");
231 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
235 DbgPrint("[%p] %s(%s) is deleted\n", handler, pkgname, id);
237 /* Just try to delete it, if a user didn't remove it from the live box list */
244 static struct packet *master_lb_update_begin(pid_t pid, int handle, const struct packet *packet)
246 struct livebox *handler;
255 ret = packet_get(packet, "ssdsss", &pkgname, &id, &priority, &content, &title, &fbfile);
257 ErrPrint("Invalid argument\n");
261 handler = lb_find_livebox(pkgname, id);
263 ErrPrint("Instance[%s] is not exists\n", id);
267 if (handler->state != CREATE) {
268 DbgPrint("(%s) is not created\n", id);
272 lb_set_priority(handler, priority);
273 lb_set_content(handler, content);
274 lb_set_title(handler, title);
278 * Width & Height is not changed in this case.
279 * If the active update is began, the size should not be changed,
280 * And if the size is changed, the provider should finish the updating first.
281 * And then begin updating again after change its size.
283 if (lb_get_lb_fb(handler)) {
284 lb_set_lb_fb(handler, fbfile);
286 ret = fb_sync(lb_get_lb_fb(handler));
287 if (ret != LB_STATUS_SUCCESS)
288 ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret);
290 lb_invoke_event_handler(handler, LB_EVENT_LB_UPDATE_BEGIN);
292 ErrPrint("Invalid request[%s], %s\n", id, fbfile);
299 static struct packet *master_pd_update_begin(pid_t pid, int handle, const struct packet *packet)
301 struct livebox *handler;
307 ret = packet_get(packet, "sss", &pkgname, &id, &fbfile);
309 ErrPrint("Invalid argument\n");
313 handler = lb_find_livebox(pkgname, id);
315 ErrPrint("Instance[%s] is not exists\n", id);
319 if (handler->state != CREATE) {
320 DbgPrint("[%s] is not created\n", id);
324 if (lb_get_pd_fb(handler)) {
325 lb_set_lb_fb(handler, fbfile);
327 ret = fb_sync(lb_get_lb_fb(handler));
328 if (ret != LB_STATUS_SUCCESS)
329 ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret);
331 lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATE_BEGIN);
333 ErrPrint("Invalid request[%s], %s\n", id, fbfile);
340 static struct packet *master_lb_update_end(pid_t pid, int handle, const struct packet *packet)
342 struct livebox *handler;
347 ret = packet_get(packet, "ss", &pkgname, &id);
349 ErrPrint("Invalid argument\n");
353 handler = lb_find_livebox(pkgname, id);
355 ErrPrint("Instance[%s] is not exists\n", id);
359 if (handler->state != CREATE) {
360 DbgPrint("[%s] is not created\n", id);
364 if (lb_get_lb_fb(handler)) {
365 lb_invoke_event_handler(handler, LB_EVENT_LB_UPDATE_END);
367 ErrPrint("Invalid request[%s]\n", id);
374 static struct packet *master_access_status(pid_t pid, int handle, const struct packet *packet)
376 struct livebox *handler;
382 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
384 ErrPrint("Invalid argument\n");
388 handler = lb_find_livebox(pkgname, id);
390 ErrPrint("Instance[%s] is not exists\n", id);
394 if (handler->state != CREATE) {
395 DbgPrint("[%s] is not created\n", id);
399 DbgPrint("Access status: %d\n", status);
401 if (handler->access_event_cb) {
405 cb = handler->access_event_cb;
406 cbdata = handler->access_event_cbdata;
408 handler->access_event_cb = NULL;
409 handler->access_event_cbdata = NULL;
411 cb(handler, status, cbdata);
413 ErrPrint("Invalid event[%s]\n", id);
419 static struct packet *master_pd_update_end(pid_t pid, int handle, const struct packet *packet)
421 struct livebox *handler;
426 ret = packet_get(packet, "ss", &pkgname, &id);
428 ErrPrint("Invalid argument\n");
432 handler = lb_find_livebox(pkgname, id);
434 ErrPrint("Instance[%s] is not exists\n", id);
438 if (handler->state != CREATE) {
439 DbgPrint("[%s] is not created\n", id);
443 if (lb_get_lb_fb(handler)) {
444 lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATE_END);
446 ErrPrint("Invalid request[%s]", id);
453 static struct packet *master_lb_updated(pid_t pid, int handle, const struct packet *packet)
460 struct livebox *handler;
466 ret = packet_get(packet, "sssiidss",
468 &fbfile, &lb_w, &lb_h,
469 &priority, &content, &title);
471 ErrPrint("Invalid argument\n");
475 handler = lb_find_livebox(pkgname, id);
477 ErrPrint("instance(%s) is not exists\n", id);
481 if (handler->state != CREATE) {
484 * Already deleted by the user.
485 * Don't try to notice anything with this, Just ignore all events
486 * Beacuse the user doesn't wants know about this anymore
488 DbgPrint("(%s) is not exists, but updated\n", id);
492 lb_set_priority(handler, priority);
493 lb_set_content(handler, content);
494 lb_set_title(handler, title);
495 lb_set_size(handler, lb_w, lb_h);
497 if (lb_text_lb(handler)) {
498 (void)parse_desc(handler, livebox_filename(handler), 0);
501 * DESC parser will call the "text event callback".
502 * Don't need to call global event callback in this case.
505 } else if (lb_get_lb_fb(handler)) {
506 lb_set_lb_fb(handler, fbfile);
507 ret = fb_sync(lb_get_lb_fb(handler));
508 if (ret != LB_STATUS_SUCCESS)
509 ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, util_basename(util_uri_to_path(id)), ret);
511 ret = LB_STATUS_SUCCESS;
514 if (ret == LB_STATUS_SUCCESS)
515 lb_invoke_event_handler(handler, LB_EVENT_LB_UPDATED);
521 static struct packet *master_pd_created(pid_t pid, int handle, const struct packet *packet)
523 struct livebox *handler;
532 ret = packet_get(packet, "sssiii", &pkgname, &id, &buf_id, &width, &height, &status);
534 ErrPrint("Invalid argument\n");
538 handler = lb_find_livebox(pkgname, id);
540 ErrPrint("Instance(%s) is not exists\n", id);
544 if (handler->state != CREATE) {
545 ErrPrint("Instance(%s) is not created\n", id);
549 lb_set_pdsize(handler, width, height);
550 if (lb_text_pd(handler)) {
551 DbgPrint("Text TYPE does not need to handle this\n");
553 (void)lb_set_pd_fb(handler, buf_id);
554 ret = fb_sync(lb_get_pd_fb(handler));
556 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
559 handler->is_pd_created = (status == 0);
561 if (handler->pd_created_cb) {
565 cb = handler->pd_created_cb;
566 cbdata = handler->pd_created_cbdata;
568 handler->pd_created_cb = NULL;
569 handler->pd_created_cbdata = NULL;
571 DbgPrint("pd_created_cb (%s) - %d\n", buf_id, status);
572 cb(handler, status, cbdata);
573 } else if (status == 0) {
574 DbgPrint("LB_EVENT_PD_CREATED (%s) - %d\n", buf_id, status);
575 lb_invoke_event_handler(handler, LB_EVENT_PD_CREATED);
582 static struct packet *master_pd_destroyed(pid_t pid, int handle, const struct packet *packet)
584 struct livebox *handler;
590 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
592 ErrPrint("Invalid argument\n");
596 handler = lb_find_livebox(pkgname, id);
598 ErrPrint("Instance(%s) is not exists\n", id);
602 if (handler->state != CREATE) {
603 ErrPrint("Instance(%s) is not created\n", id);
607 handler->is_pd_created = 0;
609 if (handler->pd_destroyed_cb) {
613 cb = handler->pd_destroyed_cb;
614 cbdata = handler->pd_destroyed_cbdata;
616 handler->pd_destroyed_cb = NULL;
617 handler->pd_destroyed_cbdata = NULL;
619 DbgPrint("Invoke the PD Destroyed CB\n");
620 cb(handler, status, cbdata);
621 } else if (status == 0) {
622 DbgPrint("Invoke the LB_EVENT_PD_DESTROYED event\n");
623 lb_invoke_event_handler(handler, LB_EVENT_PD_DESTROYED);
630 static struct packet *master_pd_updated(pid_t pid, int handle, const struct packet *packet)
634 const char *descfile;
637 struct livebox *handler;
641 ret = packet_get(packet, "ssssii",
646 ErrPrint("Invalid argument\n");
650 handler = lb_find_livebox(pkgname, id);
652 ErrPrint("Instance(%s) is not exists\n", id);
656 if (handler->state != CREATE) {
659 * This handler is already deleted by the user.
660 * So don't try to notice anything about this anymore.
661 * Just ignore all events.
663 ErrPrint("Instance(%s) is not created\n", id);
667 lb_set_pdsize(handler, pd_w, pd_h);
669 if (lb_text_pd(handler)) {
670 (void)parse_desc(handler, descfile, 1);
672 (void)lb_set_pd_fb(handler, fbfile);
674 ret = fb_sync(lb_get_pd_fb(handler));
676 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
678 lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATED);
685 static struct packet *master_update_mode(pid_t pid, int handle, const struct packet *packet)
687 struct livebox *handler;
695 ErrPrint("Invalid packet\n");
699 ret = packet_get(packet, "ssii", &pkgname, &id, &status, &active_mode);
701 ErrPrint("Invalid argument\n");
705 DbgPrint("Update mode is changed: %d, %d, %s\n", status, active_mode, id);
707 handler = lb_find_livebox(pkgname, id);
709 ErrPrint("Livebox(%s) is not found\n", id);
713 if (handler->state != CREATE) {
714 ErrPrint("Livebox(%s) is not created yet\n", id);
718 if (status == LB_STATUS_SUCCESS)
719 lb_set_update_mode(handler, active_mode);
721 if (handler->update_mode_cb) {
725 cb = handler->update_mode_cb;
726 cbdata = handler->update_mode_cbdata;
728 handler->update_mode_cb = NULL;
729 handler->update_mode_cbdata = NULL;
731 cb(handler, status, cbdata);
733 lb_invoke_event_handler(handler, LB_EVENT_UPDATE_MODE_CHANGED);
740 static struct packet *master_size_changed(pid_t pid, int handle, const struct packet *packet)
742 struct livebox *handler;
753 ErrPrint("Invalid packet\n");
757 ret = packet_get(packet, "sssiiii", &pkgname, &id, &fbfile, &is_pd, &w, &h, &status);
759 ErrPrint("Invalid argument\n");
763 DbgPrint("Size is changed: %dx%d (%s), fb: [%s]\n", w, h, id, fbfile);
765 handler = lb_find_livebox(pkgname, id);
767 ErrPrint("Livebox(%s) is not found\n", id);
771 if (handler->state != CREATE) {
772 ErrPrint("Livebox(%s) is not created yet\n", id);
777 DbgPrint("PD is resized\n");
780 * PD is not able to resized by the client.
781 * PD is only can be managed by the provider.
782 * So the PD has no private resized event handler.
783 * Notify it via global event handler only.
786 lb_set_pdsize(handler, w, h);
787 lb_invoke_event_handler(handler, LB_EVENT_PD_SIZE_CHANGED);
789 ErrPrint("This is not possible. PD Size is changed but the return value is not ZERO (%d)\n", status);
793 DbgPrint("LB is successfully resized (%dx%d)\n", w, h);
794 lb_set_size(handler, w, h);
798 * If there is a created LB FB,
801 if (lb_get_lb_fb(handler)) {
802 lb_set_lb_fb(handler, fbfile);
804 ret = fb_sync(lb_get_lb_fb(handler));
806 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
808 /* Just update the size info only. */
813 * I cannot believe client.
814 * So I added some log before & after call the user callback.
816 if (handler->size_changed_cb) {
820 cb = handler->size_changed_cb;
821 cbdata = handler->size_cbdata;
823 handler->size_changed_cb = NULL;
824 handler->size_cbdata = NULL;
826 cb(handler, status, cbdata);
828 lb_invoke_event_handler(handler, LB_EVENT_LB_SIZE_CHANGED);
831 DbgPrint("LB is not resized: %dx%d (%d)\n", w, h, status);
832 if (handler->size_changed_cb) {
836 cb = handler->size_changed_cb;
837 cbdata = handler->size_cbdata;
839 handler->size_changed_cb = NULL;
840 handler->size_cbdata = NULL;
842 cb(handler, status, cbdata);
851 static struct packet *master_period_changed(pid_t pid, int handle, const struct packet *packet)
853 struct livebox *handler;
860 ret = packet_get(packet, "idss", &status, &period, &pkgname, &id);
862 ErrPrint("Invalid argument\n");
866 handler = lb_find_livebox(pkgname, id);
868 ErrPrint("Livebox(%s) is not found\n", id);
872 if (handler->state != CREATE) {
873 ErrPrint("Livebox(%s) is not created\n", id);
877 DbgPrint("Update period is changed? %lf (%d)\n", period, status);
879 lb_set_period(handler, period);
881 if (handler->period_changed_cb) {
885 cb = handler->period_changed_cb;
886 cbdata = handler->period_cbdata;
888 handler->period_changed_cb = NULL;
889 handler->period_cbdata = NULL;
891 cb(handler, status, cbdata);
892 } else if (status == 0) {
893 lb_invoke_event_handler(handler, LB_EVENT_PERIOD_CHANGED);
900 static struct packet *master_group_changed(pid_t pid, int handle, const struct packet *packet)
902 struct livebox *handler;
907 const char *category;
910 ret = packet_get(packet, "ssiss", &pkgname, &id, &status, &cluster, &category);
912 ErrPrint("Invalid argument\n");
916 handler = lb_find_livebox(pkgname, id);
918 ErrPrint("Livebox(%s) is not exists\n", id);
922 if (handler->state != CREATE) {
925 * Do no access this handler,
926 * You cannot believe this handler anymore.
928 ErrPrint("Livebox(%s) is not created\n", id);
932 DbgPrint("Group is changed? [%s] / [%s] (%d)\n", cluster, category, status);
934 (void)lb_set_group(handler, cluster, category);
936 if (handler->group_changed_cb) {
940 cb = handler->group_changed_cb;
941 cbdata = handler->group_cbdata;
943 handler->group_changed_cb = NULL;
944 handler->group_cbdata = NULL;
946 cb(handler, status, cbdata);
947 } else if (status == 0) {
948 lb_invoke_event_handler(handler, LB_EVENT_GROUP_CHANGED);
955 static struct packet *master_created(pid_t pid, int handle, const struct packet *packet)
957 struct livebox *handler;
968 const char *category;
969 const char *lb_fname;
970 const char *pd_fname;
974 const char *auto_launch;
979 enum lb_type lb_type;
980 enum pd_type pd_type;
984 int old_state = DESTROYED;
988 ret = packet_get(packet, "dsssiiiisssssdiiiiidsi",
990 &pkgname, &id, &content,
991 &lb_w, &lb_h, &pd_w, &pd_h,
992 &cluster, &category, &lb_fname, &pd_fname,
993 &auto_launch, &priority, &size_list, &user, &pinup_supported,
994 &lb_type, &pd_type, &period, &title, &is_pinned_up);
996 ErrPrint("Invalid argument\n");
997 ret = LB_STATUS_ERROR_INVALID;
1001 ErrPrint("[%lf] pkgname: %s, id: %s, content: %s, "
1002 "pd_w: %d, pd_h: %d, lb_w: %d, lb_h: %d, "
1003 "cluster: %s, category: %s, lb_fname: \"%s\", pd_fname: \"%s\", "
1004 "auto_launch: %s, priority: %lf, size_list: %d, user: %d, pinup: %d, "
1005 "lb_type: %d, pd_type: %d, period: %lf, title: [%s], is_pinned_up: %d\n",
1006 timestamp, pkgname, id, content,
1007 pd_w, pd_h, lb_w, lb_h,
1008 cluster, category, lb_fname, pd_fname,
1009 auto_launch, priority, size_list, user, pinup_supported,
1010 lb_type, pd_type, period, title, is_pinned_up);
1012 handler = lb_find_livebox_by_timestamp(timestamp);
1014 handler = lb_new_livebox(pkgname, id, timestamp);
1016 ErrPrint("Failed to create a new livebox\n");
1017 ret = LB_STATUS_ERROR_FAULT;
1021 old_state = handler->state;
1023 if (handler->state != CREATE) {
1024 if (handler->state != DELETE) {
1027 * This is not possible!!!
1029 ErrPrint("Invalid handler\n");
1030 ret = LB_STATUS_ERROR_INVALID;
1036 * After get the delete states,
1037 * call the create callback with deleted result.
1041 old_state = handler->state;
1044 ErrPrint("Already created: timestamp[%lf] "
1045 "pkgname[%s], id[%s] content[%s] "
1046 "cluster[%s] category[%s] lb_fname[%s] pd_fname[%s]\n",
1047 timestamp, pkgname, id,
1048 content, cluster, category,
1049 lb_fname, pd_fname);
1051 ret = LB_STATUS_ERROR_ALREADY;
1055 lb_set_id(handler, id);
1058 lb_set_size(handler, lb_w, lb_h);
1059 handler->lb.type = lb_type;
1060 handler->is_pinned_up = is_pinned_up;
1065 case _LB_TYPE_SCRIPT:
1066 case _LB_TYPE_BUFFER:
1067 if (!strlen(lb_fname))
1069 lb_set_lb_fb(handler, lb_fname);
1070 ret = fb_sync(lb_get_lb_fb(handler));
1072 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
1075 lb_set_text_lb(handler);
1081 handler->pd.type = pd_type;
1082 lb_set_pdsize(handler, pd_w, pd_h);
1083 lb_set_default_pdsize(handler, pd_w, pd_h);
1085 case _PD_TYPE_SCRIPT:
1086 case _PD_TYPE_BUFFER:
1087 if (!strlen(pd_fname))
1090 lb_set_pd_fb(handler, pd_fname);
1091 ret = fb_sync(lb_get_pd_fb(handler));
1093 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
1096 lb_set_text_pd(handler);
1102 lb_set_priority(handler, priority);
1104 lb_set_size_list(handler, size_list);
1105 lb_set_group(handler, cluster, category);
1107 lb_set_content(handler, content);
1108 lb_set_title(handler, title);
1110 lb_set_user(handler, user);
1112 lb_set_auto_launch(handler, auto_launch);
1113 lb_set_pinup(handler, pinup_supported);
1115 lb_set_period(handler, period);
1119 if (handler->state == CREATE) {
1122 * These callback can change the handler->state.
1123 * So we have to use the "old_state" which stored state before call these callbacks
1126 if (handler->created_cb) {
1130 cb = handler->created_cb;
1131 cbdata = handler->created_cbdata;
1133 handler->created_cb = NULL;
1134 handler->created_cbdata = NULL;
1136 DbgPrint("Invoke the created_cb\n");
1137 cb(handler, ret, cbdata);
1139 DbgPrint("Invoke the lb,created\n");
1140 lb_invoke_event_handler(handler, LB_EVENT_CREATED);
1145 if (ret == 0 && old_state == DELETE) {
1146 DbgPrint("Send the delete request\n");
1147 lb_send_delete(handler, handler->created_cb, handler->created_cbdata);
1151 * handler->created_cb = NULL;
1152 * handler->created_cbdata = NULL;
1154 * Do not clear this to use this from the deleted event callback.
1155 * if this value is not cleared when the deleted event callback check it,
1156 * it means that the created function is not called yet.
1157 * Then the call the deleted event callback with LB_STATUS_ERROR_CANCEL errno.
1164 static struct method s_table[] = {
1166 .cmd = "lb_updated", /* pkgname, id, lb_w, lb_h, priority, ret */
1167 .handler = master_lb_updated,
1170 .cmd = "pd_updated", /* pkgname, id, descfile, pd_w, pd_h, ret */
1171 .handler = master_pd_updated,
1174 .cmd = "pd_created",
1175 .handler = master_pd_created,
1178 .cmd = "pd_destroyed",
1179 .handler = master_pd_destroyed,
1182 .cmd = "fault_package", /* pkgname, id, function, ret */
1183 .handler = master_fault_package,
1186 .cmd = "deleted", /* pkgname, id, timestamp, ret */
1187 .handler = master_deleted,
1190 .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 */
1191 .handler = master_created,
1194 .cmd = "group_changed",
1195 .handler = master_group_changed,
1198 .cmd = "period_changed",
1199 .handler = master_period_changed,
1202 .cmd = "size_changed",
1203 .handler = master_size_changed,
1207 .handler = master_pinup,
1211 .handler = master_hold_scroll,
1215 .cmd = "update_mode",
1216 .handler = master_update_mode,
1220 .cmd = "lb_update_begin",
1221 .handler = master_lb_update_begin,
1224 .cmd = "lb_update_end",
1225 .handler = master_lb_update_end,
1229 .cmd = "pd_update_begin",
1230 .handler = master_pd_update_begin,
1233 .cmd = "pd_update_end",
1234 .handler = master_pd_update_end,
1238 .cmd = "access_status",
1239 .handler = master_access_status,
1248 static void acquire_cb(struct livebox *handler, const struct packet *result, void *data)
1251 DbgPrint("Result packet is not valid\n");
1255 if (packet_get(result, "i", &ret) != 1)
1256 ErrPrint("Invalid argument\n");
1258 DbgPrint("Acquire returns: %d\n", ret);
1264 static gboolean connector_cb(gpointer user_data)
1266 s_info.reconnector = 0;
1268 if (s_info.fd > 0) {
1269 DbgPrint("Connection is already made\n");
1277 static inline void make_connection(void)
1279 struct packet *packet;
1282 DbgPrint("Let's making connection!\n");
1284 s_info.fd = com_core_packet_client_init(CLIENT_SOCKET, 0, s_table);
1285 if (s_info.fd < 0) {
1286 /*!< After 10 secs later, try to connect again */
1287 s_info.reconnector = g_timeout_add(RECONNECT_PERIOD, connector_cb, NULL);
1288 if (s_info.reconnector == 0)
1289 ErrPrint("Failed to fire the reconnector\n");
1291 ErrPrint("Try this again A sec later\n");
1295 packet = packet_create("acquire", "d", util_timestamp());
1297 com_core_packet_client_fini(s_info.fd);
1302 ret = master_rpc_async_request(NULL, packet, 1, acquire_cb, NULL);
1304 ErrPrint("Master RPC returns %d\n", ret);
1305 com_core_packet_client_fini(s_info.fd);
1311 static int connected_cb(int handle, void *data)
1313 master_rpc_check_and_fire_consumer();
1317 static int disconnected_cb(int handle, void *data)
1319 if (s_info.fd != handle) {
1320 /*!< This handle is not my favor */
1324 s_info.fd = -1; /*!< Disconnected */
1326 if (s_info.reconnector > 0) {
1327 DbgPrint("Reconnector already fired\n");
1331 /*!< After 10 secs later, try to connect again */
1332 s_info.reconnector = g_timeout_add(RECONNECT_PERIOD, connector_cb, NULL);
1333 if (s_info.reconnector == 0) {
1334 ErrPrint("Failed to fire the reconnector\n");
1338 master_rpc_clear_all_request();
1339 lb_invoke_fault_handler(LB_FAULT_PROVIDER_DISCONNECTED, MASTER_PKGNAME, "default", "disconnected");
1345 int client_init(void)
1347 com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
1348 com_core_add_event_callback(CONNECTOR_CONNECTED, connected_cb, NULL);
1358 const char *client_addr(void)
1360 return CLIENT_SOCKET;
1363 int client_fini(void)
1365 com_core_packet_client_fini(s_info.fd);
1366 com_core_del_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
1367 com_core_del_event_callback(CONNECTOR_CONNECTED, connected_cb, NULL);