src/desc_parser.c
src/master_rpc.c
src/client.c
+ src/critical_log.c
)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
extern struct livebox *lb_ref(struct livebox *handler);
extern struct livebox *lb_unref(struct livebox *handler);
extern int lb_send_delete(struct livebox *handler);
+extern int lb_delete_all(void);
enum lb_type { /*!< Must have to be sync with data-provider-master */
_LB_TYPE_NONE = 0x0,
double timestamp;
struct livebox *handler;
struct packet *result;
+ int ret;
if (packet_get(packet, "ssd", &pkgname, &id, ×tamp) != 3) {
ErrPrint("Invalid arguemnt\n");
- result = packet_create_reply(packet, "i", -EINVAL);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ ret = -EINVAL;
+ goto out;
}
handler = lb_find_livebox_by_timestamp(timestamp);
* This can be happens only if the user delete a livebox
* right after create it before receive created event.
*/
- result = packet_create_reply(packet, "i", -ENOENT);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ ret = -ENOENT;
+ goto out;
}
DbgPrint("[%p] %s(%s) is deleted\n", handler, pkgname, id);
handler->created_cb(handler, -EFAULT, handler->created_cbdata);
} else if (handler->state == CREATE) {
lb_invoke_event_handler(handler, "lb,deleted");
+ } else if (handler->deleted_cb) {
+ handler->deleted_cb(handler, 0, handler->deleted_cbdata);
}
/* Just try to delete it, if a user didn't remove it from the live box list */
lb_unref(handler);
+ ret = 0;
- result = packet_create_reply(packet, "i", 0);
+out:
+ result = packet_create_reply(packet, "i", ret);
if (!result)
ErrPrint("Failed to create a reply packet\n");
return result;
ret = packet_get(packet, "sssiid", &pkgname, &id, &fbfile, &lb_w, &lb_h, &priority);
if (ret != 6) {
ErrPrint("Invalid argument\n");
- result = packet_create_reply(packet, "i", -EINVAL);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ ret = -EINVAL;
+ goto out;
}
DbgPrint("pkgname: %s, id: %s, fbfile: %s, lb_w: %d, lb_h: %d, priority: %lf\n",
handler = lb_find_livebox(pkgname, id);
if (!handler) {
- result = packet_create_reply(packet, "i", -ENOENT);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ ret = -ENOENT;
+ goto out;
}
if (handler->state != CREATE) {
* Don't try to notice anything with this, Just ignore all events
* Beacuse the user doesn't wants know about this anymore
*/
- result = packet_create_reply(packet, "i", 0);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ ret = -EPERM;
+ goto out;
}
lb_set_priority(handler, priority);
if (lb_text_lb(handler)) {
lb_set_size(handler, lb_w, lb_h);
ret = parse_desc(handler, URI_TO_PATH(id), 0);
- result = packet_create_reply(packet, "i", ret);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ goto out;
}
if (lb_get_lb_fb(handler)) {
if (ret == 0)
lb_invoke_event_handler(handler, "lb,updated");
+out:
result = packet_create_reply(packet, "i", ret);
if (!result)
ErrPrint("Failed to create a reply packet\n");
ret = packet_get(packet, "ssssii", &pkgname, &id, &descfile, &fbfile, &pd_w, &pd_h);
if (ret != 6) {
ErrPrint("Invalid argument\n");
- result = packet_create_reply(packet, "i", -EINVAL);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ ret = -EINVAL;
+ goto out;
}
handler = lb_find_livebox(pkgname, id);
if (!handler) {
- result = packet_create_reply(packet, "i", -ENOENT);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ ret = -ENOENT;
+ goto out;
}
if (handler->state != CREATE) {
* So don't try to notice anything about this anymore.
* Just ignore all events.
*/
- result = packet_create_reply(packet, "i", 0);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ ret = -EPERM;
+ goto out;
}
lb_set_pdsize(handler, pd_w, pd_h);
ret = fb_create_buffer(lb_get_pd_fb(handler));
if (ret < 0) {
ErrPrint("Error: %s\n", strerror(ret));
- result = packet_create_reply(packet, "i", ret);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ goto out;
}
}
ret = fb_sync(lb_get_pd_fb(handler));
if (ret < 0) {
ErrPrint("Failed to do sync FB (%s - %s)\n", pkgname, util_basename(URI_TO_PATH(id)));
- result = packet_create_reply(packet, "i", ret);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ goto out;
}
lb_invoke_event_handler(handler, "pd,updated");
ret = 0;
}
+out:
result = packet_create_reply(packet, "i", ret);
if (!result)
ErrPrint("Failed to create a reply packet\n");
&lb_type, &pd_type, &period);
if (ret != 20) {
ErrPrint("Invalid argument\n");
- result = packet_create_reply(packet, "i", -EINVAL);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ ret = -EINVAL;
+ goto out;
}
ErrPrint("[%lf] pkgname: %s, id: %s, content: %s, "
handler = lb_new_livebox(pkgname, id, timestamp);
if (!handler) {
ErrPrint("Failed to create a new livebox\n");
- result = packet_create_reply(packet, "i", -EFAULT);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ ret = -EFAULT;
+ goto out;
}
} else {
if (handler->is_created == 1) {
content, cluster, category,
lb_fname, pd_fname);
- result = packet_create_reply(packet, "i", 0);
- if (!result)
- ErrPrint("Failed to send a reply packet\n");
-
- return result;
+ ret = 0;
+ goto out;
}
lb_set_id(handler, id);
if (handler->state != CREATE) {
lb_send_delete(handler);
- result = packet_create_reply(packet, "i", 0);
- if (!result)
- ErrPrint("Failed to create a reply packet\n");
- return result;
+ ret = 0;
+ goto out;
}
}
lb_invoke_event_handler(handler, "lb,created");
handler->is_created = 1;
- result = packet_create_reply(packet, "i", 0);
+ ret = 0;
+
+out:
+ result = packet_create_reply(packet, "i", ret);
if (!result)
ErrPrint("Failed to create a reply packet\n");
return result;
return 0;
}
- s_info.reconnector = g_timeout_add(RECONNECT_PERIOD, connector_cb, NULL); /*!< After 10 secs later, try to connect again */
+ /*!< After 10 secs later, try to connect again */
+ s_info.reconnector = g_timeout_add(RECONNECT_PERIOD, connector_cb, NULL);
if (s_info.reconnector == 0) {
ErrPrint("Failed to fire the reconnector\n");
make_connection();
}
lb_invoke_fault_handler("provider,disconnected", MASTER_PKGNAME, "default", "disconnected");
+
+ lb_delete_all();
return 0;
}
#include "desc_parser.h"
#include "dlist.h"
#include "util.h"
+#include "critical_log.h"
#define TYPE_TEXT "text"
#define TYPE_IMAGE "image"
block = calloc(1, sizeof(*block));
if (!block) {
- ErrPrint("Heap: %s\n", strerror(errno));
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
update_end(handle, is_pd);
fclose(fp);
return -ENOMEM;
case VALUE_TYPE:
if (idx == block->type_len) {
block->type_len += 256;
- block->type =
- realloc(block->type, block->type_len);
- if (!block->type)
+ block->type = realloc(block->type, block->type_len);
+ if (!block->type) {
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
goto errout;
+ }
}
if (ch == '\n') {
case VALUE_PART:
if (idx == block->part_len) {
block->part_len += 256;
- block->part =
- realloc(block->part, block->part_len);
- if (!block->part)
+ block->part = realloc(block->part, block->part_len);
+ if (!block->part) {
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
goto errout;
+ }
}
if (ch == '\n') {
case VALUE_DATA:
if (idx == block->data_len) {
block->data_len += 256;
- block->data =
- realloc(block->data, block->data_len);
- if (!block->data)
+ block->data = realloc(block->data, block->data_len);
+ if (!block->data) {
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
goto errout;
+ }
}
if (ch == '\n') {
case VALUE_FILE:
if (idx == block->file_len) {
block->file_len += 256;
- block->file =
- realloc(block->file, block->file_len);
- if (!block->file)
+ block->file = realloc(block->file, block->file_len);
+ if (!block->file) {
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
goto errout;
+ }
}
if (ch == '\n') {
case VALUE_GROUP:
if (idx == block->group_len) {
block->group_len += 256;
- block->group = realloc(block->group,
- block->group_len);
- if (!block->group)
+ block->group = realloc(block->group, block->group_len);
+ if (!block->group) {
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
goto errout;
+ }
}
if (ch == '\n') {
if (idx == block->id_len) {
block->id_len += 256;
block->id = realloc(block->id, block->id_len);
- if (!block->id)
+ if (!block->id) {
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
goto errout;
+ }
}
if (ch == '\n') {
#include "debug.h"
#include "util.h"
#include "fb.h"
+#include "critical_log.h"
int errno;
info = calloc(1, sizeof(*info));
if (!info) {
- ErrPrint("Heap: %s\n", strerror(errno));
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
return NULL;
}
info->id = strdup(id);
if (!info->id) {
- ErrPrint("Heap: %s\n", strerror(errno));
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
free(info);
return NULL;
}
if (info->type == FB_TYPE_FILE || info->type == FB_TYPE_UNKNOWN) {
buffer = calloc(1, sizeof(*buffer) + info->bufsz);
if (!buffer) {
- ErrPrint("Heap: %s\n", strerror(errno));
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
info->bufsz = 0;
return -ENOMEM;
}
#include "util.h"
#include "master_rpc.h"
#include "client.h"
+#include "critical_log.h"
#define EAPI __attribute__((visibility("default")))
#define EVENT_INTERVAL 0.05f
struct cb_info *info;
info = malloc(sizeof(*info));
- if (!info)
+ if (!info) {
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
return NULL;
+ }
info->cb = cb;
info->data = data;
if (!packet)
return;
- if (packet_get(packet, "i", &ret) != 1)
+ if (packet_get(packet, "i", &ret) != 1) {
+ ErrPrint("Invalid argument\n");
return;
+ }
if (ret < 0)
lb_invoke_event_handler(handler, "event,ingored");
destroy_cb_info(info);
if (!result) {
- if (cb)
- cb(handler, -EFAULT, cbdata);
- return;
- }
-
- if (packet_get(result, "i", &ret) != 1) {
- if (cb)
- cb(handler, -EINVAL, cbdata);
- return;
+ ret = -EFAULT;
+ } else if (packet_get(result, "i", &ret) != 1) {
+ ErrPrint("Invalid argument\n");
+ ret = -EINVAL;
}
if (cb)
destroy_cb_info(info);
if (!result) {
- if (cb)
- cb(handler, -EFAULT, cbdata);
- return;
- }
-
- if (packet_get(result, "i", &ret) != 1) {
- if (cb)
- cb(handler, -EINVAL, cbdata);
- return;
+ ret = -EFAULT;
+ } else if (packet_get(result, "i", &ret) != 1) {
+ ErrPrint("Invalid argument\n");
+ ret = -EINVAL;
}
if (cb)
cb(handler, ret, cbdata);
-
return;
}
cb = info->cb;
if (!result) {
- if (cb)
- cb(handler, -EFAULT, cbdata);
- return;
- }
-
- if (packet_get(result, "i", &ret) != 1) {
- if (cb)
- cb(handler, -EINVAL, cbdata);
- return;
+ ret = -EFAULT;
+ } else if (packet_get(result, "i", &ret) != 1) {
+ ErrPrint("Invalid argument\n");
+ ret = -EINVAL;
}
if (cb)
destroy_cb_info(info);
if (!result) {
- if (cb)
- cb(handler, -EFAULT, cbdata);
- return;
- }
-
- if (packet_get(result, "id", &ret, &period) != 2) {
- if (cb)
- cb(handler, -EINVAL, cbdata);
- return;
+ ret = -EFAULT;
+ } else if (packet_get(result, "id", &ret, &period) != 2) {
+ ErrPrint("Invalid argument\n");
+ ret = -EINVAL;
}
if (ret == 0)
int ret;
if (!result) {
- if (handler->deleted_cb)
- handler->deleted_cb(handler, -EFAULT, handler->deleted_cbdata);
-
- return;
+ ret = -EFAULT;
+ } else if (packet_get(result, "i", &ret) != 1) {
+ ErrPrint("Invalid argument\n");
+ ret = -EINVAL;
}
- if (packet_get(result, "i", &ret) != 1) {
- if (handler->deleted_cb)
- handler->deleted_cb(handler, -EINVAL, handler->deleted_cbdata);
- return;
- }
+ DbgPrint("Returns %d (waiting deleted event)\n", ret);
- DbgPrint("Returns %d\n", ret);
+ /*!
+ * \note
+ * Do not call the deleted callback from here.
+ * master will send the "deleted" event.
+ * Then invoke this callback.
+ *
+ * if (handler->deleted_cb)
+ * handler->deleted_cb(handler, ret, handler->deleted_cbdata);
+ */
}
static void new_ret_cb(struct livebox *handler, const struct packet *result, void *data)
if (!__file_log_fp)
__file_log_fp = fdopen(1, "w+t");
#endif
+ critical_log_init();
client_init();
return 0;
info = malloc(sizeof(*info));
if (!info) {
- ErrPrint("Heap: %s\n", strerror(errno));
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
return -ENOMEM;
}
info = malloc(sizeof(*info));
if (!info) {
- ErrPrint("Heap: %s\n", strerror(errno));
+ CRITICAL_LOG("Heap: %s\n", strerror(errno));
return -ENOMEM;
}
if (cluster) {
pc = strdup(cluster);
if (!pc) {
- ErrPrint("Heap: %s\n", strerror(errno));
+ CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
return -ENOMEM;
}
}
if (category) {
ps = strdup(category);
if (!ps) {
- ErrPrint("Heap: %s\n", strerror(errno));
+ CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
free(pc);
return -ENOMEM;
}
return handler;
}
+int lb_delete_all(void)
+{
+ struct dlist *l;
+ struct dlist *n;
+ struct livebox *handler;
+
+ dlist_foreach_safe(s_info.livebox_list, l, n, handler) {
+ lb_invoke_event_handler(handler, "lb,deleted");
+ lb_unref(handler);
+ }
+
+ return 0;
+}
+
int lb_set_content(struct livebox *handler, const char *content)
{
if (handler->content) {
if (content) {
handler->content = strdup(content);
if (!handler->content) {
- ErrPrint("Heap: %s\n", strerror(errno));
+ CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
return -ENOMEM;
}
}