#include <stdlib.h> /* malloc */
#include <string.h> /* strdup */
#include <math.h>
+#include <unistd.h>
#include <aul.h>
#include <dlog.h>
static void lb_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data)
{
int pixmap;
- int ret;
+ int ret = LB_STATUS_ERROR_INVALID;
ret_cb_t cb;
void *cbdata;
struct cb_info *info = data;
return master_rpc_request_only(handler, packet);
}
+static void initialize_livebox(void *disp)
+{
+#if defined(FLOG)
+ char filename[BUFSIZ];
+ snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
+ __file_log_fp = fopen(filename, "w+t");
+ if (!__file_log_fp) {
+ __file_log_fp = fdopen(1, "w+t");
+ }
+#endif
+ critical_log_init("viewer");
+ livebox_service_init();
+ fb_init(disp);
+
+ client_init();
+
+ s_info.init_count++;
+}
+
+EAPI int livebox_init_with_options(void *disp, int prevent_overwrite, double event_filter)
+{
+ if (s_info.init_count > 0) {
+ s_info.init_count++;
+ return LB_STATUS_SUCCESS;
+ }
+
+ /*!
+ * \note
+ * Some application doesn't want to use the environment value.
+ * So set them using arguments.
+ */
+ s_info.prevent_overwrite = prevent_overwrite;
+ MINIMUM_EVENT = event_filter;
+
+ initialize_livebox(disp);
+ return LB_STATUS_SUCCESS;
+}
+
EAPI int livebox_init(void *disp)
{
const char *env;
s_info.init_count++;
return LB_STATUS_SUCCESS;
}
+
env = getenv("PROVIDER_DISABLE_PREVENT_OVERWRITE");
if (env && !strcasecmp(env, "true")) {
s_info.prevent_overwrite = 1;
sscanf(env, "%lf", &MINIMUM_EVENT);
}
-#if defined(FLOG)
- char filename[BUFSIZ];
- snprintf(filename, sizeof(filename), "/tmp/%d.box.log", getpid());
- __file_log_fp = fopen(filename, "w+t");
- if (!__file_log_fp) {
- __file_log_fp = fdopen(1, "w+t");
- }
-#endif
- critical_log_init("viewer");
- livebox_service_init();
- fb_init(disp);
-
- client_init();
-
- s_info.init_count++;
+ initialize_livebox(disp);
return LB_STATUS_SUCCESS;
}
return NULL;
}
- if (content) {
+ if (content && strlen(content)) {
handler->content = strdup(content);
if (!handler->content) {
ErrPrint("Error: %s\n", strerror(errno));
if (handler->lb.width == w && handler->lb.height == h) {
DbgPrint("No changes\n");
- return LB_STATUS_ERROR_ALREADY;;
+ return LB_STATUS_ERROR_ALREADY;
}
packet = packet_create("resize", "ssii", handler->pkgname, handler->id, w, h);
destroy_cb_info(cbinfo);
}
- return LB_STATUS_ERROR_FAULT;
+ return ret;
}
EAPI int livebox_subscribe_group(const char *cluster, const char *category)
struct packet *packet;
/*!
- * \TODO
+ * \todo
* Validate the group info using DB
* If the group info is not valid, do not send this request
*/
struct packet *packet;
/*!
- * \TODO
+ * \todo
* Validate the group info using DB
* If the group info is not valid, do not send this request
* AND Check the subscribed or not too
return NULL;
}
-static inline char *get_file_kept_in_safe(const char *id)
-{
- const char *path;
- char *new_path;
- int len;
- int base_idx;
-
- path = util_uri_to_path(id);
- if (!path) {
- ErrPrint("Invalid URI(%s)\n", id);
- return NULL;
- }
-
- /*!
- * \TODO: REMOVE ME
- */
- if (s_info.prevent_overwrite) {
- new_path = strdup(path);
- if (!new_path) {
- ErrPrint("Heap: %s\n", strerror(errno));
- }
-
- return new_path;
- }
-
-
- len = strlen(path);
- base_idx = len - 1;
-
- while (base_idx > 0 && path[base_idx] != '/') base_idx--;
- base_idx += (path[base_idx] == '/');
-
- new_path = malloc(len + 10);
- if (!new_path) {
- ErrPrint("Heap: %s\n", strerror(errno));
- return NULL;
- }
-
- strncpy(new_path, path, base_idx);
- snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
- return new_path;
-}
-
struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
{
struct livebox *handler;
return NULL;
}
- handler->filename = get_file_kept_in_safe(id);
- if (!handler->filename) {
- handler->filename = strdup(util_uri_to_path(id));
- if (!handler->filename) {
- ErrPrint("Error: %s\n", strerror(errno));
- }
- }
-
handler->timestamp = timestamp;
handler->lb.type = _LB_TYPE_FILE;
handler->pd.type = _PD_TYPE_SCRIPT;
if (!handler->id) {
ErrPrint("Error: %s\n", strerror(errno));
}
+}
+void lb_set_filename(struct livebox *handler, const char *filename)
+{
if (handler->filename) {
+ if (unlink(handler->filename) < 0) {
+ ErrPrint("unlink: %s\n", strerror(errno));
+ }
+
free(handler->filename);
}
- handler->filename = get_file_kept_in_safe(id);
+ handler->filename = strdup(filename);
if (!handler->filename) {
- handler->filename = strdup(util_uri_to_path(id));
- if (!handler->filename) {
- ErrPrint("Error: %s\n", strerror(errno));
- }
+ ErrPrint("Heap: %s\n", strerror(errno));
+ return;
}
}
}
if (handler->filename) {
- util_unlink(handler->filename);
+ (void)util_unlink(handler->filename);
}
dlist_remove_data(s_info.livebox_list, handler);