int h;
};
+struct update_mode_cbdata {
+ struct inst_info *inst;
+ int active_update;
+};
+
struct change_group_cbdata {
struct inst_info *inst;
char *cluster;
return ret;
}
+static inline void instance_send_update_mode_event(struct inst_info *inst, int active_mode, int status)
+{
+ struct packet *packet;
+ const char *pkgname;
+
+ if (!inst->info) {
+ ErrPrint("Instance info is not ready to use\n");
+ return;
+ }
+
+ pkgname = package_name(inst->info);
+
+ packet = packet_create_noack("update_mode", "ssii", pkgname, inst->id, status, active_mode);
+ if (packet)
+ CLIENT_SEND_EVENT(inst, packet);
+ else
+ ErrPrint("Failed to send update mode event\n");
+}
+
static inline void instance_send_resized_event(struct inst_info *inst, int is_pd, int w, int h, int status)
{
struct packet *packet;
ErrPrint("Failed to send size changed event\n");
}
+static void update_mode_cb(struct slave_node *slave, const struct packet *packet, void *data)
+{
+ struct update_mode_cbdata *cbdata = data;
+ int ret;
+
+ if (!packet) {
+ ErrPrint("Invalid packet\n");
+ instance_send_update_mode_event(cbdata->inst, cbdata->active_update, LB_STATUS_ERROR_FAULT);
+ instance_unref(cbdata->inst);
+ DbgFree(cbdata);
+ return;
+ }
+
+ if (packet_get(packet, "i", &ret) != 1) {
+ ErrPrint("Invalid parameters\n");
+ instance_send_update_mode_event(cbdata->inst, cbdata->active_update, LB_STATUS_ERROR_INVALID);
+ instance_unref(cbdata->inst);
+ DbgFree(cbdata);
+ return;
+ }
+
+ if (ret == LB_STATUS_SUCCESS)
+ cbdata->inst->active_update = cbdata->active_update;
+
+ instance_send_update_mode_event(cbdata->inst, cbdata->active_update, ret);
+
+ instance_unref(cbdata->inst);
+ DbgFree(cbdata);
+}
+
HAPI int instance_unicast_created_event(struct inst_info *inst, struct client_node *client)
{
struct packet *packet;
return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, activate_cb, instance_ref(inst), 1);
}
+HAPI int instance_lb_update_begin(struct inst_info *inst, double priority, const char *content, const char *title)
+{
+ struct packet *packet;
+ const char *fbfile;
+
+ if (!inst->active_update) {
+ ErrPrint("Invalid request [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+
+ switch (package_lb_type(inst->info)) {
+ case LB_TYPE_BUFFER:
+ if (!inst->lb.canvas.buffer) {
+ ErrPrint("Buffer is null [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+ fbfile = buffer_handler_id(inst->lb.canvas.buffer);
+ break;
+ case LB_TYPE_SCRIPT:
+ if (!inst->lb.canvas.script) {
+ ErrPrint("Script is null [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+ fbfile = fb_id(script_handler_fb(inst->lb.canvas.script));
+ break;
+ default:
+ ErrPrint("Invalid request[%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+
+ packet = packet_create_noack("lb_update_begin", "ssdsss", package_name(inst->info), inst->id, priority, content, title, fbfile);
+ if (!packet) {
+ ErrPrint("Unable to create a packet\n");
+ return LB_STATUS_ERROR_FAULT;
+ }
+
+ return CLIENT_SEND_EVENT(inst, packet);
+}
+
+HAPI int instance_lb_update_end(struct inst_info *inst)
+{
+ struct packet *packet;
+
+ if (!inst->active_update) {
+ ErrPrint("Invalid request [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+
+ switch (package_lb_type(inst->info)) {
+ case LB_TYPE_BUFFER:
+ if (!inst->lb.canvas.buffer) {
+ ErrPrint("Buffer is null [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+ break;
+ case LB_TYPE_SCRIPT:
+ if (!inst->lb.canvas.script) {
+ ErrPrint("Script is null [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+ break;
+ default:
+ ErrPrint("Invalid request[%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+
+ packet = packet_create_noack("lb_update_end", "ss", package_name(inst->info), inst->id);
+ if (!packet) {
+ ErrPrint("Unable to create a packet\n");
+ return LB_STATUS_ERROR_FAULT;
+ }
+
+ return CLIENT_SEND_EVENT(inst, packet);
+}
+
+HAPI int instance_pd_update_begin(struct inst_info *inst)
+{
+ struct packet *packet;
+ const char *fbfile;
+
+ if (!inst->active_update) {
+ ErrPrint("Invalid request [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+
+ switch (package_pd_type(inst->info)) {
+ case PD_TYPE_BUFFER:
+ if (!inst->pd.canvas.buffer) {
+ ErrPrint("Buffer is null [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+ fbfile = buffer_handler_id(inst->pd.canvas.buffer);
+ break;
+ case PD_TYPE_SCRIPT:
+ if (!inst->pd.canvas.script) {
+ ErrPrint("Script is null [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+ fbfile = fb_id(script_handler_fb(inst->pd.canvas.script));
+ break;
+ default:
+ ErrPrint("Invalid request[%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+
+ packet = packet_create_noack("pd_update_begin", "sss", package_name(inst->info), inst->id, fbfile);
+ if (!packet) {
+ ErrPrint("Unable to create a packet\n");
+ return LB_STATUS_ERROR_FAULT;
+ }
+
+ return CLIENT_SEND_EVENT(inst, packet);
+}
+
+HAPI int instance_pd_update_end(struct inst_info *inst)
+{
+ struct packet *packet;
+
+ if (!inst->active_update) {
+ ErrPrint("Invalid request [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+
+ switch (package_pd_type(inst->info)) {
+ case PD_TYPE_BUFFER:
+ if (!inst->pd.canvas.buffer) {
+ ErrPrint("Buffer is null [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+ break;
+ case PD_TYPE_SCRIPT:
+ if (!inst->pd.canvas.script) {
+ ErrPrint("Script is null [%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+ break;
+ default:
+ ErrPrint("Invalid request[%s]\n", inst->id);
+ return LB_STATUS_ERROR_INVALID;
+ }
+
+ packet = packet_create_noack("pd_update_end", "ss", package_name(inst->info), inst->id);
+ if (!packet) {
+ ErrPrint("Unable to create a packet\n");
+ return LB_STATUS_ERROR_FAULT;
+ }
+
+ return CLIENT_SEND_EVENT(inst, packet);
+}
+
HAPI void instance_lb_updated(const char *pkgname, const char *id)
{
struct inst_info *inst;
HAPI int instance_set_update_mode(struct inst_info *inst, int active_update)
{
- int ret;
struct packet *packet;
+ struct update_mode_cbdata *cbdata;
if (package_is_fault(inst->info)) {
DbgPrint("Fault package [%s]\n", package_name(inst->info));
return LB_STATUS_ERROR_ALREADY;
}
+ cbdata = malloc(sizeof(*cbdata));
+ if (!cbdata) {
+ ErrPrint("Heap: %s\n", strerror(errno));
+ return LB_STATUS_ERROR_MEMORY;
+ }
+
+ cbdata->inst = instance_ref(inst);
+ cbdata->active_update = active_update;
+
/* NOTE: param is resued from here */
- packet = packet_create_noack("update_mode", "ssi", package_name(inst->info), inst->id, active_update);
+ packet = packet_create("update_mode", "ssi", package_name(inst->info), inst->id, active_update);
if (!packet) {
ErrPrint("Failed to build a packet for %s\n", package_name(inst->info));
+ instance_unref(cbdata->inst);
+ free(cbdata);
return LB_STATUS_ERROR_FAULT;
}
- ret = slave_rpc_request_only(package_slave(inst->info), package_name(inst->info), packet, 0);
-
- if (ret == LB_STATUS_SUCCESS)
- inst->active_update = active_update;
-
- return ret;
+ return slave_rpc_async_request(package_slave(inst->info), package_name(inst->info), packet, update_mode_cb, cbdata, 0);
}
HAPI int instance_active_update(struct inst_info *inst)
static struct packet *client_update_mode(pid_t pid, int handle, const struct packet *packet)
{
+ struct packet *result;
struct client_node *client;
int active_update;
const char *pkgname;
client = client_find_by_pid(pid);
if (!client) {
ErrPrint("Client %d is not exists\n", pid);
+ ret = LB_STATUS_ERROR_INVALID;
goto out;
}
ret = packet_get(packet, "ssi", &pkgname, &id, &active_update);
if (ret != 3) {
ErrPrint("Invalid argument\n");
+ ret = LB_STATUS_ERROR_INVALID;
goto out;
}
inst = package_find_instance_by_id(pkgname, id);
- if (!inst)
+ if (!inst) {
ErrPrint("Instance is not exists\n");
- else if (package_is_fault(instance_package(inst)))
+ ret = LB_STATUS_ERROR_NOT_EXIST;
+ } else if (package_is_fault(instance_package(inst))) {
ErrPrint("Fault package\n");
- else
- instance_set_update_mode(inst, active_update);
+ ret = LB_STATUS_ERROR_FAULT;
+ } else {
+ /*!
+ * \note
+ * Send change update mode request to a slave
+ */
+ ret = instance_set_update_mode(inst, active_update);
+ }
out:
- /*! \note No reply packet */
- return NULL;
+ result = packet_create_reply(packet, "i", ret);
+ if (!result)
+ ErrPrint("Failed to create a packet\n");
+
+ return result;
}
/* pid, pkgname, filename, emission, source, s, sy, ex, ey, ret */
return NULL;
}
+static struct packet *slave_lb_update_begin(pid_t pid, int handle, const struct packet *packet)
+{
+ struct slave_node *slave;
+ struct inst_info *inst;
+ struct pkg_info *pkg;
+ const char *pkgname;
+ const char *id;
+ double priority;
+ const char *content;
+ const char *title;
+ int ret;
+
+ slave = slave_find_by_pid(pid);
+ if (!slave) {
+ ErrPrint("Slave %d is not exists\n", pid);
+ goto out;
+ }
+
+ ret = packet_get(packet, "ssdss", &pkgname, &id, &priority, &content, &title);
+ if (ret != 5) {
+ ErrPrint("Invalid parameters\n");
+ goto out;
+ }
+
+ inst = package_find_instance_by_id(pkgname, id);
+ if (!inst) {
+ ErrPrint("Instance(%s) is not exists\n", id);
+ goto out;
+ } else if (instance_state(inst) == INST_DESTROYED) {
+ ErrPrint("Instance(%s) is already destroyed\n", id);
+ goto out;
+ }
+
+ pkg = instance_package(inst);
+ if (!pkg) {
+ ErrPrint("Invalid instance\n");
+ } else if (package_is_fault(pkg)) {
+ ErrPrint("Faulted instance %s.\n", id);
+ } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
+ ret = instance_lb_update_begin(inst, priority, content, title);
+ if (ret == LB_STATUS_SUCCESS)
+ slave_freeze_ttl(slave);
+ } else {
+ ErrPrint("Invalid request[%s]\n", id);
+ }
+
+out:
+ return NULL;
+}
+
+static struct packet *slave_lb_update_end(pid_t pid, int handle, const struct packet *packet)
+{
+ struct slave_node *slave;
+ struct inst_info *inst;
+ struct pkg_info *pkg;
+ const char *pkgname;
+ const char *id;
+ int ret;
+
+ slave = slave_find_by_pid(pid);
+ if (!slave) {
+ ErrPrint("Slave %d is not exists\n", pid);
+ goto out;
+ }
+
+ ret = packet_get(packet, "ss", &pkgname, &id);
+ if (ret != 2) {
+ ErrPrint("Invalid parameters\n");
+ goto out;
+ }
+
+ inst = package_find_instance_by_id(pkgname, id);
+ if (!inst) {
+ ErrPrint("Instance[%s] is not exists\n", id);
+ goto out;
+ } else if (instance_state(inst) == INST_DESTROYED) {
+ ErrPrint("Instance[%s] is already destroyed\n", id);
+ goto out;
+ }
+
+ pkg = instance_package(inst);
+ if (!pkg) {
+ ErrPrint("Invalid instance\n");
+ } else if (package_is_fault(pkg)) {
+ ErrPrint("Faulted instance %s\n", id);
+ } else if (package_lb_type(pkg) == LB_TYPE_BUFFER) {
+ ret = instance_lb_update_end(inst);
+ if (ret == LB_STATUS_SUCCESS)
+ slave_thaw_ttl(slave);
+ } else {
+ ErrPrint("Invalid request[%s]\n", id);
+ }
+
+out:
+ return NULL;
+}
+
+static struct packet *slave_pd_update_begin(pid_t pid, int handle, const struct packet *packet)
+{
+ struct slave_node *slave;
+ struct pkg_info *pkg;
+ struct inst_info *inst;
+ const char *pkgname;
+ const char *id;
+ int ret;
+
+ slave = slave_find_by_pid(pid);
+ if (!slave) {
+ ErrPrint("Slave %d is not exists\n", pid);
+ goto out;
+ }
+
+ ret = packet_get(packet, "ss", &pkgname, &id);
+ if (ret != 2) {
+ ErrPrint("Invalid parameters\n");
+ goto out;
+ }
+
+ inst = package_find_instance_by_id(pkgname, id);
+ if (!inst) {
+ ErrPrint("Instance[%s] is not exists\n", id);
+ goto out;
+ }
+
+ pkg = instance_package(inst);
+ if (!pkg) {
+ ErrPrint("Invalid package\n");
+ } else if (package_is_fault(pkg)) {
+ ErrPrint("Faulted instance %s\n", id);
+ } else if (instance_state(inst) == INST_DESTROYED) {
+ ErrPrint("Instance[%s] is already destroyed\n", id);
+ } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
+ (void)instance_pd_update_begin(inst);
+ } else {
+ ErrPrint("Invalid request[%s]\n", id);
+ }
+
+out:
+ return NULL;
+}
+
+static struct packet *slave_pd_update_end(pid_t pid, int handle, const struct packet *packet)
+{
+ struct slave_node *slave;
+ struct pkg_info *pkg;
+ struct inst_info *inst;
+ const char *pkgname;
+ const char *id;
+ int ret;
+
+ slave = slave_find_by_pid(pid);
+ if (!slave) {
+ ErrPrint("Slave %d is not exists\n", pid);
+ goto out;
+ }
+
+ ret = packet_get(packet, "ss", &pkgname, &id);
+ if (ret != 2) {
+ ErrPrint("Invalid parameters\n");
+ goto out;
+ }
+
+ inst = package_find_instance_by_id(pkgname, id);
+ if (!inst) {
+ ErrPrint("Instance[%s] is not exists\n", id);
+ goto out;
+ }
+
+ pkg = instance_package(inst);
+ if (!pkg) {
+ ErrPrint("Invalid package\n");
+ } else if (package_is_fault(pkg)) {
+ ErrPrint("Faulted instance %s\n", id);
+ } else if (instance_state(inst) == INST_DESTROYED) {
+ ErrPrint("Instance[%s] is already destroyed\n", id);
+ } else if (package_pd_type(pkg) == PD_TYPE_BUFFER) {
+ (void)instance_pd_update_end(inst);
+ } else {
+ ErrPrint("Invalid request[%s]\n", id);
+ }
+
+out:
+ return NULL;
+}
+
static struct packet *slave_call(pid_t pid, int handle, const struct packet *packet) /* slave_name, pkgname, filename, function, ret */
{
struct slave_node *slave;
.cmd = "scroll",
.handler = slave_hold_scroll, /* slave_name, pkgname, id, seize */
},
+
+ {
+ .cmd = "lb_update_begin",
+ .handler = slave_lb_update_begin,
+ },
+ {
+ .cmd = "lb_update_end",
+ .handler = slave_lb_update_end,
+ },
+ {
+ .cmd = "pd_update_begin",
+ .handler = slave_pd_update_begin,
+ },
+ {
+ .cmd = "pd_update_end",
+ .handler = slave_pd_update_end,
+ },
+
{
.cmd = NULL,
.handler = NULL,