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://www.tizenopensource.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;
106 ret = packet_get(packet, "iisss", &ret, &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 ret = LB_STATUS_ERROR_MEMORY;
130 if (handler->pinup_cb) {
131 handler->pinup_cb(handler, ret, handler->pinup_cbdata);
133 handler->pinup_cb = NULL; /*!< Reset pinup cb */
134 handler->pinup_cbdata = NULL;
135 } else if (ret == 0) {
136 lb_invoke_event_handler(handler, LB_EVENT_PINUP_CHANGED);
143 static struct packet *master_deleted(pid_t pid, int handle, const struct packet *packet)
148 struct livebox *handler;
150 if (packet_get(packet, "ssd", &pkgname, &id, ×tamp) != 3) {
151 ErrPrint("Invalid arguemnt\n");
155 handler = lb_find_livebox_by_timestamp(timestamp);
159 * This can be happens only if the user delete a livebox
160 * right after create it before receive created event.
165 /*!< Check validity of this "handler" */
166 if (handler->state != CREATE) {
167 if (handler->state != DELETE) {
170 * This is not possible
172 CRITICAL_LOG("Already deleted handler (%s - %s)\n", pkgname, id);
177 if (handler->created_cb) {
181 * "if (handler->id == NULL)"
183 * The instance is not created yet.
184 * But the master forcely destroy it and send destroyed event to this
185 * without the created event.
187 * It could be destroyed when a slave has critical error(fault)
188 * before creating an instance successfully.
190 if (handler->created_cb == handler->deleted_cb) {
191 if (handler->created_cbdata != handler->deleted_cbdata)
192 DbgPrint("cb is same but cbdata is different (%s - %s)\n", pkgname, id);
194 handler->deleted_cb = NULL;
195 handler->deleted_cbdata = NULL;
198 DbgPrint("Call the created cb with LB_STATUS_ERROR_CANCEL\n");
199 handler->created_cb(handler, LB_STATUS_ERROR_CANCEL, handler->created_cbdata);
200 handler->created_cb = NULL;
201 handler->created_cbdata = NULL;
202 } else if (handler->id) {
203 if (handler->deleted_cb) {
204 DbgPrint("Call the deleted cb\n");
205 handler->deleted_cb(handler, LB_STATUS_SUCCESS, handler->deleted_cbdata);
207 handler->deleted_cb = NULL;
208 handler->deleted_cbdata = NULL;
210 DbgPrint("Call the lb,deleted\n");
211 lb_invoke_event_handler(handler, LB_EVENT_DELETED);
215 DbgPrint("[%p] %s(%s) is deleted\n", handler, pkgname, id);
217 /* Just try to delete it, if a user didn't remove it from the live box list */
224 static struct packet *master_lb_update_begin(pid_t pid, int handle, const struct packet *packet)
226 struct livebox *handler;
235 ret = packet_get(packet, "ssdsss", &pkgname, &id, &priority, &content, &title, &fbfile);
237 ErrPrint("Invalid argument\n");
241 handler = lb_find_livebox(pkgname, id);
243 ErrPrint("Instance[%s] is not exists\n", id);
247 if (handler->state != CREATE) {
248 DbgPrint("(%s) is not created\n", id);
252 lb_set_priority(handler, priority);
253 lb_set_content(handler, content);
254 lb_set_title(handler, title);
258 * Width & Height is not changed in this case.
259 * If the active update is began, the size should not be changed,
260 * And if the size is changed, the provider should finish the updating first.
261 * And then begin updating again after change its size.
263 if (lb_get_lb_fb(handler)) {
264 lb_set_lb_fb(handler, fbfile);
266 ret = fb_sync(lb_get_lb_fb(handler));
267 if (ret != LB_STATUS_SUCCESS)
268 ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret);
270 lb_invoke_event_handler(handler, LB_EVENT_LB_UPDATE_BEGIN);
272 ErrPrint("Invalid request[%s], %s\n", id, fbfile);
279 static struct packet *master_pd_update_begin(pid_t pid, int handle, const struct packet *packet)
281 struct livebox *handler;
287 ret = packet_get(packet, "sss", &pkgname, &id, &fbfile);
289 ErrPrint("Invalid argument\n");
293 handler = lb_find_livebox(pkgname, id);
295 ErrPrint("Instance[%s] is not exists\n", id);
299 if (handler->state != CREATE) {
300 DbgPrint("[%s] is not created\n", id);
304 if (lb_get_pd_fb(handler)) {
305 lb_set_lb_fb(handler, fbfile);
307 ret = fb_sync(lb_get_lb_fb(handler));
308 if (ret != LB_STATUS_SUCCESS)
309 ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, fbfile, ret);
311 lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATE_BEGIN);
313 ErrPrint("Invalid request[%s], %s\n", id, fbfile);
320 static struct packet *master_lb_update_end(pid_t pid, int handle, const struct packet *packet)
322 struct livebox *handler;
327 ret = packet_get(packet, "ss", &pkgname, &id);
329 ErrPrint("Invalid argument\n");
333 handler = lb_find_livebox(pkgname, id);
335 ErrPrint("Instance[%s] is not exists\n", id);
339 if (handler->state != CREATE) {
340 DbgPrint("[%s] is not created\n", id);
344 if (lb_get_lb_fb(handler)) {
345 lb_invoke_event_handler(handler, LB_EVENT_LB_UPDATE_END);
347 ErrPrint("Invalid request[%s]\n", id);
354 static struct packet *master_access_status(pid_t pid, int handle, const struct packet *packet)
356 struct livebox *handler;
362 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
364 ErrPrint("Invalid argument\n");
368 handler = lb_find_livebox(pkgname, id);
370 ErrPrint("Instance[%s] is not exists\n", id);
374 if (handler->state != CREATE) {
375 DbgPrint("[%s] is not created\n", id);
379 DbgPrint("Access status: %d\n", status);
381 if (handler->access_event_cb) {
382 handler->access_event_cb(handler, status, handler->access_event_cbdata);
383 handler->access_event_cb = NULL;
384 handler->access_event_cbdata = NULL;
386 ErrPrint("Invalid event[%s]\n", id);
392 static struct packet *master_pd_update_end(pid_t pid, int handle, const struct packet *packet)
394 struct livebox *handler;
399 ret = packet_get(packet, "ss", &pkgname, &id);
401 ErrPrint("Invalid argument\n");
405 handler = lb_find_livebox(pkgname, id);
407 ErrPrint("Instance[%s] is not exists\n", id);
411 if (handler->state != CREATE) {
412 DbgPrint("[%s] is not created\n", id);
416 if (lb_get_lb_fb(handler)) {
417 lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATE_END);
419 ErrPrint("Invalid request[%s]", id);
426 static struct packet *master_lb_updated(pid_t pid, int handle, const struct packet *packet)
433 struct livebox *handler;
439 ret = packet_get(packet, "sssiidss",
441 &fbfile, &lb_w, &lb_h,
442 &priority, &content, &title);
444 ErrPrint("Invalid argument\n");
448 handler = lb_find_livebox(pkgname, id);
450 ErrPrint("instance(%s) is not exists\n", id);
454 if (handler->state != CREATE) {
457 * Already deleted by the user.
458 * Don't try to notice anything with this, Just ignore all events
459 * Beacuse the user doesn't wants know about this anymore
461 DbgPrint("(%s) is not exists, but updated\n", id);
465 lb_set_priority(handler, priority);
466 lb_set_content(handler, content);
467 lb_set_title(handler, title);
468 lb_set_size(handler, lb_w, lb_h);
470 if (lb_text_lb(handler)) {
471 (void)parse_desc(handler, livebox_filename(handler), 0);
474 * DESC parser will call the "text event callback".
475 * Don't need to call global event callback in this case.
478 } else if (lb_get_lb_fb(handler)) {
479 lb_set_lb_fb(handler, fbfile);
480 ret = fb_sync(lb_get_lb_fb(handler));
481 if (ret != LB_STATUS_SUCCESS)
482 ErrPrint("Failed to do sync FB (%s - %s) (%d)\n", pkgname, util_basename(util_uri_to_path(id)), ret);
484 ret = LB_STATUS_SUCCESS;
487 if (ret == LB_STATUS_SUCCESS)
488 lb_invoke_event_handler(handler, LB_EVENT_LB_UPDATED);
494 static struct packet *master_pd_created(pid_t pid, int handle, const struct packet *packet)
496 struct livebox *handler;
505 ret = packet_get(packet, "sssiii", &pkgname, &id, &buf_id, &width, &height, &status);
507 ErrPrint("Invalid argument\n");
511 handler = lb_find_livebox(pkgname, id);
513 ErrPrint("Instance(%s) is not exists\n", id);
517 if (handler->state != CREATE) {
518 ErrPrint("Instance(%s) is not created\n", id);
522 lb_set_pdsize(handler, width, height);
523 if (lb_text_pd(handler)) {
524 DbgPrint("Text TYPE does not need to handle this\n");
526 (void)lb_set_pd_fb(handler, buf_id);
527 ret = fb_sync(lb_get_pd_fb(handler));
529 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
532 handler->is_pd_created = (status == 0);
534 if (handler->pd_created_cb) {
535 DbgPrint("pd_created_cb (%s) - %d\n", buf_id, status);
536 handler->pd_created_cb(handler, status, handler->pd_created_cbdata);
538 handler->pd_created_cb = NULL;
539 handler->pd_created_cbdata = NULL;
540 } else if (status == 0) {
541 DbgPrint("LB_EVENT_PD_CREATED (%s) - %d\n", buf_id, status);
542 lb_invoke_event_handler(handler, LB_EVENT_PD_CREATED);
549 static struct packet *master_pd_destroyed(pid_t pid, int handle, const struct packet *packet)
551 struct livebox *handler;
557 ret = packet_get(packet, "ssi", &pkgname, &id, &status);
559 ErrPrint("Invalid argument\n");
563 handler = lb_find_livebox(pkgname, id);
565 ErrPrint("Instance(%s) is not exists\n", id);
569 if (handler->state != CREATE) {
570 ErrPrint("Instance(%s) is not created\n", id);
574 handler->is_pd_created = 0;
576 if (handler->pd_destroyed_cb) {
577 DbgPrint("Invoke the PD Destroyed CB\n");
578 handler->pd_destroyed_cb(handler, status, handler->pd_destroyed_cbdata);
580 handler->pd_destroyed_cb = NULL;
581 handler->pd_destroyed_cbdata = NULL;
582 } else if (status == 0) {
583 DbgPrint("Invoke the LB_EVENT_PD_DESTROYED event\n");
584 lb_invoke_event_handler(handler, LB_EVENT_PD_DESTROYED);
591 static struct packet *master_pd_updated(pid_t pid, int handle, const struct packet *packet)
595 const char *descfile;
598 struct livebox *handler;
602 ret = packet_get(packet, "ssssii",
607 ErrPrint("Invalid argument\n");
611 handler = lb_find_livebox(pkgname, id);
613 ErrPrint("Instance(%s) is not exists\n", id);
617 if (handler->state != CREATE) {
620 * This handler is already deleted by the user.
621 * So don't try to notice anything about this anymore.
622 * Just ignore all events.
624 ErrPrint("Instance(%s) is not created\n", id);
628 lb_set_pdsize(handler, pd_w, pd_h);
630 if (lb_text_pd(handler)) {
631 (void)parse_desc(handler, descfile, 1);
633 (void)lb_set_pd_fb(handler, fbfile);
635 ret = fb_sync(lb_get_pd_fb(handler));
637 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
639 lb_invoke_event_handler(handler, LB_EVENT_PD_UPDATED);
646 static struct packet *master_update_mode(pid_t pid, int handle, const struct packet *packet)
648 struct livebox *handler;
656 ErrPrint("Invalid packet\n");
660 ret = packet_get(packet, "ssii", &pkgname, &id, &status, &active_mode);
662 ErrPrint("Invalid argument\n");
666 DbgPrint("Update mode is changed: %d, %d, %s\n", status, active_mode, id);
668 handler = lb_find_livebox(pkgname, id);
670 ErrPrint("Livebox(%s) is not found\n", id);
674 if (handler->state != CREATE) {
675 ErrPrint("Livebox(%s) is not created yet\n", id);
679 if (status == LB_STATUS_SUCCESS)
680 lb_set_update_mode(handler, active_mode);
682 if (handler->update_mode_cb) {
683 handler->update_mode_cb(handler, status, handler->update_mode_cbdata);
685 handler->update_mode_cb = NULL;
686 handler->update_mode_cbdata = NULL;
688 lb_invoke_event_handler(handler, LB_EVENT_UPDATE_MODE_CHANGED);
695 static struct packet *master_size_changed(pid_t pid, int handle, const struct packet *packet)
697 struct livebox *handler;
708 ErrPrint("Invalid packet\n");
712 ret = packet_get(packet, "sssiiii", &pkgname, &id, &fbfile, &is_pd, &w, &h, &status);
714 ErrPrint("Invalid argument\n");
718 DbgPrint("Size is changed: %dx%d (%s), fb: [%s]\n", w, h, id, fbfile);
720 handler = lb_find_livebox(pkgname, id);
722 ErrPrint("Livebox(%s) is not found\n", id);
726 if (handler->state != CREATE) {
727 ErrPrint("Livebox(%s) is not created yet\n", id);
732 DbgPrint("PD is resized\n");
735 * PD is not able to resized by the client.
736 * PD is only can be managed by the provider.
737 * So the PD has no private resized event handler.
738 * Notify it via global event handler only.
741 lb_set_pdsize(handler, w, h);
742 lb_invoke_event_handler(handler, LB_EVENT_PD_SIZE_CHANGED);
744 ErrPrint("This is not possible. PD Size is changed but the return value is not ZERO (%d)\n", status);
748 DbgPrint("LB is successfully resized (%dx%d)\n", w, h);
749 lb_set_size(handler, w, h);
753 * If there is a created LB FB,
756 if (lb_get_lb_fb(handler)) {
757 lb_set_lb_fb(handler, fbfile);
759 ret = fb_sync(lb_get_lb_fb(handler));
761 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
763 /* Just update the size info only. */
768 * I cannot believe client.
769 * So I added some log before & after call the user callback.
771 if (handler->size_changed_cb) {
772 handler->size_changed_cb(handler, status, handler->size_cbdata);
774 handler->size_changed_cb = NULL;
775 handler->size_cbdata = NULL;
777 lb_invoke_event_handler(handler, LB_EVENT_LB_SIZE_CHANGED);
780 DbgPrint("LB is not resized: %dx%d (%d)\n", w, h, status);
781 if (handler->size_changed_cb) {
782 handler->size_changed_cb(handler, status, handler->size_cbdata);
784 handler->size_changed_cb = NULL;
785 handler->size_cbdata = NULL;
794 static struct packet *master_period_changed(pid_t pid, int handle, const struct packet *packet)
796 struct livebox *handler;
803 ret = packet_get(packet, "idss", &status, &period, &pkgname, &id);
805 ErrPrint("Invalid argument\n");
809 handler = lb_find_livebox(pkgname, id);
811 ErrPrint("Livebox(%s) is not found\n", id);
815 if (handler->state != CREATE) {
816 ErrPrint("Livebox(%s) is not created\n", id);
820 DbgPrint("Update period is changed? %lf (%d)\n", period, status);
822 lb_set_period(handler, period);
824 if (handler->period_changed_cb) {
825 handler->period_changed_cb(handler, status, handler->group_cbdata);
827 handler->period_changed_cb = NULL;
828 handler->period_cbdata = NULL;
829 } else if (status == 0) {
830 lb_invoke_event_handler(handler, LB_EVENT_PERIOD_CHANGED);
837 static struct packet *master_group_changed(pid_t pid, int handle, const struct packet *packet)
839 struct livebox *handler;
844 const char *category;
847 ret = packet_get(packet, "ssiss", &pkgname, &id, &status, &cluster, &category);
849 ErrPrint("Invalid argument\n");
853 handler = lb_find_livebox(pkgname, id);
855 ErrPrint("Livebox(%s) is not exists\n", id);
859 if (handler->state != CREATE) {
862 * Do no access this handler,
863 * You cannot believe this handler anymore.
865 ErrPrint("Livebox(%s) is not created\n", id);
869 DbgPrint("Group is changed? [%s] / [%s] (%d)\n", cluster, category, status);
871 (void)lb_set_group(handler, cluster, category);
873 if (handler->group_changed_cb) {
874 handler->group_changed_cb(handler, status, handler->group_cbdata);
876 handler->group_changed_cb = NULL;
877 handler->group_cbdata = NULL;
878 } else if (status == 0) {
879 lb_invoke_event_handler(handler, LB_EVENT_GROUP_CHANGED);
886 static struct packet *master_created(pid_t pid, int handle, const struct packet *packet)
888 struct livebox *handler;
899 const char *category;
900 const char *lb_fname;
901 const char *pd_fname;
905 const char *auto_launch;
910 enum lb_type lb_type;
911 enum pd_type pd_type;
915 int old_state = DESTROYED;
919 ret = packet_get(packet, "dsssiiiisssssdiiiiidsi",
921 &pkgname, &id, &content,
922 &lb_w, &lb_h, &pd_w, &pd_h,
923 &cluster, &category, &lb_fname, &pd_fname,
924 &auto_launch, &priority, &size_list, &user, &pinup_supported,
925 &lb_type, &pd_type, &period, &title, &is_pinned_up);
927 ErrPrint("Invalid argument\n");
928 ret = LB_STATUS_ERROR_INVALID;
932 ErrPrint("[%lf] pkgname: %s, id: %s, content: %s, "
933 "pd_w: %d, pd_h: %d, lb_w: %d, lb_h: %d, "
934 "cluster: %s, category: %s, lb_fname: \"%s\", pd_fname: \"%s\", "
935 "auto_launch: %s, priority: %lf, size_list: %d, user: %d, pinup: %d, "
936 "lb_type: %d, pd_type: %d, period: %lf, title: [%s], is_pinned_up: %d\n",
937 timestamp, pkgname, id, content,
938 pd_w, pd_h, lb_w, lb_h,
939 cluster, category, lb_fname, pd_fname,
940 auto_launch, priority, size_list, user, pinup_supported,
941 lb_type, pd_type, period, title, is_pinned_up);
943 handler = lb_find_livebox_by_timestamp(timestamp);
945 handler = lb_new_livebox(pkgname, id, timestamp);
947 ErrPrint("Failed to create a new livebox\n");
948 ret = LB_STATUS_ERROR_FAULT;
952 old_state = handler->state;
954 if (handler->state != CREATE) {
955 if (handler->state != DELETE) {
958 * This is not possible!!!
960 ErrPrint("Invalid handler\n");
961 ret = LB_STATUS_ERROR_INVALID;
967 * After get the delete states,
968 * call the create callback with deleted result.
972 old_state = handler->state;
975 ErrPrint("Already created: timestamp[%lf] "
976 "pkgname[%s], id[%s] content[%s] "
977 "cluster[%s] category[%s] lb_fname[%s] pd_fname[%s]\n",
978 timestamp, pkgname, id,
979 content, cluster, category,
982 ret = LB_STATUS_ERROR_ALREADY;
986 lb_set_id(handler, id);
989 lb_set_size(handler, lb_w, lb_h);
990 handler->lb.type = lb_type;
991 handler->is_pinned_up = is_pinned_up;
996 case _LB_TYPE_SCRIPT:
997 case _LB_TYPE_BUFFER:
998 if (!strlen(lb_fname))
1000 lb_set_lb_fb(handler, lb_fname);
1001 ret = fb_sync(lb_get_lb_fb(handler));
1003 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
1006 lb_set_text_lb(handler);
1012 handler->pd.type = pd_type;
1013 lb_set_pdsize(handler, pd_w, pd_h);
1014 lb_set_default_pdsize(handler, pd_w, pd_h);
1016 case _PD_TYPE_SCRIPT:
1017 case _PD_TYPE_BUFFER:
1018 if (!strlen(pd_fname))
1021 lb_set_pd_fb(handler, pd_fname);
1022 ret = fb_sync(lb_get_pd_fb(handler));
1024 ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(util_uri_to_path(id)));
1027 lb_set_text_pd(handler);
1033 lb_set_priority(handler, priority);
1035 lb_set_size_list(handler, size_list);
1036 lb_set_group(handler, cluster, category);
1038 lb_set_content(handler, content);
1039 lb_set_title(handler, title);
1041 lb_set_user(handler, user);
1043 lb_set_auto_launch(handler, auto_launch);
1044 lb_set_pinup(handler, pinup_supported);
1046 lb_set_period(handler, period);
1050 if (handler->state == CREATE) {
1053 * These callback can change the handler->state.
1054 * So we have to use the "old_state" which stored state before call these callbacks
1057 if (handler->created_cb) {
1058 DbgPrint("Invoke the created_cb\n");
1059 handler->created_cb(handler, ret, handler->created_cbdata);
1061 handler->created_cb = NULL;
1062 handler->created_cbdata = NULL;
1064 DbgPrint("Invoke the lb,created\n");
1065 lb_invoke_event_handler(handler, LB_EVENT_CREATED);
1070 if (ret == 0 && old_state == DELETE) {
1071 DbgPrint("Send the delete request\n");
1072 lb_send_delete(handler, handler->created_cb, handler->created_cbdata);
1076 * handler->created_cb = NULL;
1077 * handler->created_cbdata = NULL;
1079 * Do not clear this to use this from the deleted event callback.
1080 * if this value is not cleared when the deleted event callback check it,
1081 * it means that the created function is not called yet.
1082 * Then the call the deleted event callback with LB_STATUS_ERROR_CANCEL errno.
1089 static struct method s_table[] = {
1091 .cmd = "lb_updated", /* pkgname, id, lb_w, lb_h, priority, ret */
1092 .handler = master_lb_updated,
1095 .cmd = "pd_updated", /* pkgname, id, descfile, pd_w, pd_h, ret */
1096 .handler = master_pd_updated,
1099 .cmd = "pd_created",
1100 .handler = master_pd_created,
1103 .cmd = "pd_destroyed",
1104 .handler = master_pd_destroyed,
1107 .cmd = "fault_package", /* pkgname, id, function, ret */
1108 .handler = master_fault_package,
1111 .cmd = "deleted", /* pkgname, id, timestamp, ret */
1112 .handler = master_deleted,
1115 .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 */
1116 .handler = master_created,
1119 .cmd = "group_changed",
1120 .handler = master_group_changed,
1123 .cmd = "period_changed",
1124 .handler = master_period_changed,
1127 .cmd = "size_changed",
1128 .handler = master_size_changed,
1132 .handler = master_pinup,
1136 .handler = master_hold_scroll,
1140 .cmd = "update_mode",
1141 .handler = master_update_mode,
1145 .cmd = "lb_update_begin",
1146 .handler = master_lb_update_begin,
1149 .cmd = "lb_update_end",
1150 .handler = master_lb_update_end,
1154 .cmd = "pd_update_begin",
1155 .handler = master_pd_update_begin,
1158 .cmd = "pd_update_end",
1159 .handler = master_pd_update_end,
1163 .cmd = "access_status",
1164 .handler = master_access_status,
1173 static void acquire_cb(struct livebox *handler, const struct packet *result, void *data)
1176 DbgPrint("Result packet is not valid\n");
1180 if (packet_get(result, "i", &ret) != 1)
1181 ErrPrint("Invalid argument\n");
1183 DbgPrint("Acquire returns: %d\n", ret);
1189 static gboolean connector_cb(gpointer user_data)
1191 s_info.reconnector = 0;
1193 if (s_info.fd > 0) {
1194 DbgPrint("Connection is already made\n");
1202 static inline void make_connection(void)
1204 struct packet *packet;
1207 DbgPrint("Let's making connection!\n");
1209 s_info.fd = com_core_packet_client_init(CLIENT_SOCKET, 0, s_table);
1210 if (s_info.fd < 0) {
1211 /*!< After 10 secs later, try to connect again */
1212 s_info.reconnector = g_timeout_add(RECONNECT_PERIOD, connector_cb, NULL);
1213 if (s_info.reconnector == 0)
1214 ErrPrint("Failed to fire the reconnector\n");
1216 ErrPrint("Try this again A sec later\n");
1220 packet = packet_create("acquire", "d", util_timestamp());
1222 com_core_packet_client_fini(s_info.fd);
1227 ret = master_rpc_async_request(NULL, packet, 1, acquire_cb, NULL);
1229 ErrPrint("Master RPC returns %d\n", ret);
1230 com_core_packet_client_fini(s_info.fd);
1236 static int connected_cb(int handle, void *data)
1238 master_rpc_check_and_fire_consumer();
1242 static int disconnected_cb(int handle, void *data)
1244 if (s_info.fd != handle) {
1245 /*!< This handle is not my favor */
1249 s_info.fd = -1; /*!< Disconnected */
1251 if (s_info.reconnector > 0) {
1252 DbgPrint("Reconnector already fired\n");
1256 /*!< After 10 secs later, try to connect again */
1257 s_info.reconnector = g_timeout_add(RECONNECT_PERIOD, connector_cb, NULL);
1258 if (s_info.reconnector == 0) {
1259 ErrPrint("Failed to fire the reconnector\n");
1263 master_rpc_clear_all_request();
1264 lb_invoke_fault_handler(LB_FAULT_PROVIDER_DISCONNECTED, MASTER_PKGNAME, "default", "disconnected");
1270 int client_init(void)
1272 com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
1273 com_core_add_event_callback(CONNECTOR_CONNECTED, connected_cb, NULL);
1283 const char *client_addr(void)
1285 return CLIENT_SOCKET;
1288 int client_fini(void)
1290 com_core_packet_client_fini(s_info.fd);
1291 com_core_del_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
1292 com_core_del_event_callback(CONNECTOR_CONNECTED, connected_cb, NULL);