Add new API livebox_del_NEW
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 13 Dec 2013 08:40:30 +0000 (17:40 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 13 Dec 2013 08:40:30 +0000 (17:40 +0900)
1. Add new API
2. Remove critical log
3. Vadlidate handle first

Change-Id: Id160b070ebd5297394afa456bdfe260b865064af

CMakeLists.txt
include/conf.h
include/critical_log.h [deleted file]
include/livebox.h
include/livebox_internal.h
packaging/liblivebox-viewer.spec
src/client.c
src/critical_log.c [deleted file]
src/desc_parser.c
src/fb.c
src/livebox.c

index 980e8b2..6505dee 100644 (file)
@@ -54,7 +54,6 @@ ADD_LIBRARY(${PROJECT_NAME} SHARED
        src/desc_parser.c
        src/master_rpc.c
        src/client.c
-       src/critical_log.c
        src/file_service.c
        src/conf.c
 )
index 7258093..f134310 100644 (file)
@@ -20,7 +20,7 @@
  */
 #define MAX_LOG_FILE   3
 #define MAX_LOG_LINE   1000
-#define SLAVE_LOG_PATH "/opt/usr/share/live_magazine/log"
+#define SLAVE_LOG_PATH "/tmp/.dbox.service/log/"
 
 #if !defined(VCONFKEY_MASTER_STARTED)
 #define VCONFKEY_MASTER_STARTED        "memory/data-provider-master/started"
diff --git a/include/critical_log.h b/include/critical_log.h
deleted file mode 100644 (file)
index 4c6c23c..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright 2013  Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-extern int critical_log(const char *func, int line, const char *fmt, ...);
-extern int critical_log_init(const char *tag);
-extern int critical_log_fini(void);
-
-#define CRITICAL_LOG(args...) critical_log(__func__, __LINE__, args)
-
-/* End of a file */
index bd9cb85..3daa98a 100644 (file)
@@ -430,6 +430,7 @@ extern struct livebox *livebox_add_with_size(const char *pkgname, const char *co
  * \see ret_cb_t
  */
 extern int livebox_del(struct livebox *handler, ret_cb_t cb, void *data);
+extern int livebox_del_NEW(struct livebox *handler, int type, ret_cb_t cb, void *data);
 
 /*!
  * \brief Set a livebox events callback
index 4222b10..dadc625 100644 (file)
@@ -82,6 +82,7 @@ struct livebox {
        double timestamp;
 
        enum livebox_visible_state visible;
+       enum livebox_delete_type delete_type;
 
        int is_user;
        int is_pd_created;
index c2305be..fe8f7d5 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-viewer
 Summary: Library for developing the application.
-Version: 0.16.0
+Version: 0.17.0
 Release: 1
 Group: HomeTF/Livebox
 License: Flora
index 8ce8114..c365659 100644 (file)
@@ -42,7 +42,6 @@
 #include "util.h"
 #include "master_rpc.h"
 #include "conf.h"
-#include "critical_log.h"
 #include "file_service.h"
 
 int errno;
@@ -185,7 +184,7 @@ static struct packet *master_deleted(pid_t pid, int handle, const struct packet
                         * \note
                         * This is not possible
                         */
-                       CRITICAL_LOG("Already deleted handler (%s - %s)\n", pkgname, id);
+                       ErrPrint("Already deleted handler (%s - %s)\n", pkgname, id);
                        return NULL;
                }
        }
@@ -1256,7 +1255,7 @@ static struct packet *master_created(pid_t pid, int handle, const struct packet
 
 out:
        if (ret == 0 && old_state == DELETE) {
-               lb_send_delete(handler, handler->created_cb, handler->created_cbdata);
+               lb_send_delete(handler, handler->delete_type, handler->created_cb, handler->created_cbdata);
 
                /*!
                 * \note
diff --git a/src/critical_log.c b/src/critical_log.c
deleted file mode 100644 (file)
index 12fd8a1..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright 2013  Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <string.h>
-#include <libgen.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <dlog.h>
-
-#include "conf.h"
-#include "debug.h"
-#include "util.h"
-#include "critical_log.h"
-#include "livebox-errno.h" /* For error code */
-
-static struct {
-       FILE *fp;
-       int file_id;
-       int nr_of_lines;
-       char *filename;
-} s_info = {
-       .fp = NULL,
-       .file_id = 0,
-       .nr_of_lines = 0,
-       .filename = NULL,
-};
-
-
-
-int critical_log(const char *func, int line, const char *fmt, ...)
-{
-       va_list ap;
-       int ret;
-
-       if (!s_info.fp) {
-               return LB_STATUS_ERROR_IO;
-       }
-
-#if defined(_USE_ECORE_TIME_GET)
-       double tv;
-       tv = util_timestamp();
-       fprintf(s_info.fp, "%d %lf [%s:%d] ", getpid(), tv, util_basename((char *)func), line);
-#else
-       struct timeval tv;
-       gettimeofday(&tv, NULL);
-       fprintf(s_info.fp, "%d %lu.%lu [%s:%d] ", getpid(), tv.tv_sec, tv.tv_usec, util_basename((char *)func), line);
-#endif
-
-       va_start(ap, fmt);
-       ret = vfprintf(s_info.fp, fmt, ap);
-       va_end(ap);
-
-       s_info.nr_of_lines++;
-       if (s_info.nr_of_lines == MAX_LOG_LINE) {
-               char *filename;
-               int namelen;
-
-               s_info.file_id = (s_info.file_id + 1) % MAX_LOG_FILE;
-
-               namelen = strlen(s_info.filename) + strlen(SLAVE_LOG_PATH) + 20;
-               filename = malloc(namelen);
-               if (filename) {
-                       snprintf(filename, namelen, "%s/%d_%s", SLAVE_LOG_PATH, s_info.file_id, s_info.filename);
-
-                       if (s_info.fp) {
-                               if (fclose(s_info.fp) != 0) {
-                                       ErrPrint("fclose: %s\n", strerror(errno));
-                               }
-                       }
-
-                       s_info.fp = fopen(filename, "w+");
-                       if (!s_info.fp) {
-                               ErrPrint("Failed to open a file: %s\n", filename);
-                       }
-
-                       free(filename);
-               }
-
-               s_info.nr_of_lines = 0;
-       }
-       return ret;
-}
-
-
-
-int critical_log_init(const char *name)
-{
-       int namelen;
-       char *filename;
-
-       if (s_info.fp) {
-               return 0;
-       }
-
-       s_info.filename = strdup(name);
-       if (!s_info.filename) {
-               ErrPrint("Failed to create a log file\n");
-               return LB_STATUS_ERROR_MEMORY;
-       }
-
-       namelen = strlen(name) + strlen(SLAVE_LOG_PATH) + 20;
-
-       filename = malloc(namelen);
-       if (!filename) {
-               ErrPrint("Failed to create a log file\n");
-               free(s_info.filename);
-               s_info.filename = NULL;
-               return LB_STATUS_ERROR_MEMORY;
-       }
-
-       snprintf(filename, namelen, "%s/%d_%s", SLAVE_LOG_PATH, s_info.file_id, name);
-
-       s_info.fp = fopen(filename, "w+");
-       if (!s_info.fp) {
-               ErrPrint("Failed to open log: %s\n", strerror(errno));
-               free(s_info.filename);
-               s_info.filename = NULL;
-               free(filename);
-               return LB_STATUS_ERROR_IO;
-       }
-
-       free(filename);
-       return 0;
-}
-
-
-
-int critical_log_fini(void)
-{
-       if (s_info.filename) {
-               free(s_info.filename);
-               s_info.filename = NULL;
-       }
-
-       if (s_info.fp) {
-               if (fclose(s_info.fp) != 0) {
-                       ErrPrint("fclose: %s\n", strerror(errno));
-               }
-               s_info.fp = NULL;
-       }
-
-       return 0;
-}
-
-
-
-/* End of a file */
index b5abe7d..02a346f 100644 (file)
@@ -29,7 +29,6 @@
 #include "desc_parser.h"
 #include "dlist.h"
 #include "util.h"
-#include "critical_log.h"
 
 #define TYPE_TEXT "text"
 #define TYPE_IMAGE "image"
@@ -360,7 +359,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
 
                        block = calloc(1, sizeof(*block));
                        if (!block) {
-                               CRITICAL_LOG("Heap: %s\n", strerror(errno));
+                               ErrPrint("Heap: %s\n", strerror(errno));
                                update_end(handle, is_pd);
                                if (fclose(fp) != 0) {
                                        ErrPrint("fclose: %s\n", strerror(errno));
@@ -482,7 +481,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
                                block->type_len += 256;
                                block->type = realloc(block->type, block->type_len);
                                if (!block->type) {
-                                       CRITICAL_LOG("Heap: %s\n", strerror(errno));
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -504,7 +503,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
                                block->part_len += 256;
                                block->part = realloc(block->part, block->part_len);
                                if (!block->part) {
-                                       CRITICAL_LOG("Heap: %s\n", strerror(errno));
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -526,7 +525,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
                                block->data_len += 256;
                                block->data = realloc(block->data, block->data_len);
                                if (!block->data) {
-                                       CRITICAL_LOG("Heap: %s\n", strerror(errno));
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -548,7 +547,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
                                block->file_len += 256;
                                block->file = realloc(block->file, block->file_len);
                                if (!block->file) {
-                                       CRITICAL_LOG("Heap: %s\n", strerror(errno));
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -570,7 +569,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
                                block->option_len += 256;
                                block->option = realloc(block->option, block->option_len);
                                if (!block->option) {
-                                       CRITICAL_LOG("Heap: %s\n", strerror(errno));
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -591,7 +590,7 @@ int parse_desc(struct livebox *handle, const char *descfile, int is_pd)
                                block->id_len += 256;
                                block->id = realloc(block->id, block->id_len);
                                if (!block->id) {
-                                       CRITICAL_LOG("Heap: %s\n", strerror(errno));
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
index 20bffc9..0cf9217 100644 (file)
--- a/src/fb.c
+++ b/src/fb.c
@@ -37,7 +37,6 @@
 #include "debug.h"
 #include "util.h"
 #include "fb.h"
-#include "critical_log.h"
 
 int errno;
 
@@ -316,13 +315,13 @@ struct fb_info *fb_create(const char *id, int w, int h)
 
        info = calloc(1, sizeof(*info));
        if (!info) {
-               CRITICAL_LOG("Heap: %s\n", strerror(errno));
+               ErrPrint("Heap: %s\n", strerror(errno));
                return NULL;
        }
 
        info->id = strdup(id);
        if (!info->id) {
-               CRITICAL_LOG("Heap: %s\n", strerror(errno));
+               ErrPrint("Heap: %s\n", strerror(errno));
                free(info);
                return NULL;
        }
@@ -401,7 +400,7 @@ void *fb_acquire_buffer(struct fb_info *info)
 
                        buffer = calloc(1, sizeof(*buffer) + info->bufsz);
                        if (!buffer) {
-                               CRITICAL_LOG("Heap: %s\n", strerror(errno));
+                               ErrPrint("Heap: %s\n", strerror(errno));
                                info->bufsz = 0;
                                return NULL;
                        }
@@ -422,7 +421,7 @@ void *fb_acquire_buffer(struct fb_info *info)
 
                        buffer = calloc(1, sizeof(*buffer) + info->bufsz);
                        if (!buffer) {
-                               CRITICAL_LOG("Heap: %s\n", strerror(errno));
+                               ErrPrint("Heap: %s\n", strerror(errno));
                                info->bufsz = 0;
                                return NULL;
                        }
index 348fdd3..fd7f2c3 100644 (file)
@@ -37,7 +37,6 @@
 #include "util.h"
 #include "master_rpc.h"
 #include "client.h"
-#include "critical_log.h"
 #include "conf.h"
 
 #define EAPI __attribute__((visibility("default")))
@@ -139,7 +138,7 @@ static inline __attribute__((always_inline)) struct cb_info *create_cb_info(ret_
 
        info = malloc(sizeof(*info));
        if (!info) {
-               CRITICAL_LOG("Heap: %s\n", strerror(errno));
+               ErrPrint("Heap: %s\n", strerror(errno));
                return NULL;
        }
 
@@ -678,7 +677,6 @@ static void initialize_livebox(void *disp)
                __file_log_fp = fdopen(1, "w+t");
        }
 #endif
-       critical_log_init("viewer");
        livebox_service_init();
        fb_init(disp);
 
@@ -745,7 +743,6 @@ EAPI int livebox_fini(void)
        client_fini();
        fb_fini();
        livebox_service_fini();
-       critical_log_fini();
        return LB_STATUS_SUCCESS;
 }
 
@@ -858,6 +855,7 @@ EAPI struct livebox *livebox_add_with_size(const char *pkgname, const char *cont
        handler->timestamp = util_timestamp();
        handler->is_user = 1;
        handler->visible = LB_SHOW;
+       handler->delete_type = LB_DELETE_PERMANENTLY;
 
        s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
 
@@ -954,6 +952,44 @@ EAPI int livebox_set_period(struct livebox *handler, double period, ret_cb_t cb,
        return ret;
 }
 
+EAPI int livebox_del_NEW(struct livebox *handler, int type, ret_cb_t cb, void *data)
+{
+       if (!handler) {
+               ErrPrint("Handler is NIL\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       if (handler->state != CREATE) {
+               ErrPrint("Handler is already deleted\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       handler->state = DELETE;
+       handler->delete_type = type;
+
+       if (!handler->id) {
+               /*!
+                * \note
+                * The id is not determined yet.
+                * It means a user didn't receive created event yet.
+                * Then just stop to delete procedure from here.
+                * Because the "created" event handler will release this.
+                * By the way, if the user adds any callback for getting return status of this,
+                * call it at here.
+                */
+               if (cb) {
+                       cb(handler, 0, data);
+               }
+               return LB_STATUS_SUCCESS;
+       }
+
+       if (!cb) {
+               cb = default_delete_cb;
+       }
+
+       return lb_send_delete(handler, type, cb, data);
+}
+
 EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
 {
        if (!handler) {
@@ -967,6 +1003,7 @@ EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
        }
 
        handler->state = DELETE;
+       handler->delete_type = LB_DELETE_PERMANENTLY;
 
        if (!handler->id) {
                /*!
@@ -988,7 +1025,7 @@ EAPI int livebox_del(struct livebox *handler, ret_cb_t cb, void *data)
                cb = default_delete_cb;
        }
 
-       return lb_send_delete(handler, cb, data);
+       return lb_send_delete(handler, LB_DELETE_PERMANENTLY, cb, data);
 }
 
 EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char *, const char *, const char *, void *), void *data)
@@ -1001,7 +1038,7 @@ EAPI int livebox_set_fault_handler(int (*cb)(enum livebox_fault_type, const char
 
        info = malloc(sizeof(*info));
        if (!info) {
-               CRITICAL_LOG("Heap: %s\n", strerror(errno));
+               ErrPrint("Heap: %s\n", strerror(errno));
                return LB_STATUS_ERROR_MEMORY;
        }
 
@@ -1043,7 +1080,7 @@ EAPI int livebox_set_event_handler(int (*cb)(struct livebox *, enum livebox_even
 
        info = malloc(sizeof(*info));
        if (!info) {
-               CRITICAL_LOG("Heap: %s\n", strerror(errno));
+               ErrPrint("Heap: %s\n", strerror(errno));
                return LB_STATUS_ERROR_MEMORY;
        }
 
@@ -1266,7 +1303,7 @@ EAPI int livebox_pd_is_created(struct livebox *handler)
                return LB_STATUS_ERROR_INVALID;
        }
 
-       if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
+       if (handler->state != CREATE || !handler->pd.data.fb || !handler->id) {
                ErrPrint("Handler is not valid\n");
                return LB_STATUS_ERROR_INVALID;
        }
@@ -1289,7 +1326,7 @@ EAPI int livebox_create_pd_with_position(struct livebox *handler, double x, doub
                return LB_STATUS_ERROR_INVALID;
        }
 
-       if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
+       if (handler->state != CREATE || !handler->pd.data.fb || !handler->id) {
                ErrPrint("Handler is not valid\n");
                return LB_STATUS_ERROR_INVALID;
        }
@@ -1333,7 +1370,7 @@ EAPI int livebox_move_pd(struct livebox *handler, double x, double y)
                return LB_STATUS_ERROR_INVALID;
        }
 
-       if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
+       if (handler->state != CREATE || !handler->pd.data.fb || !handler->id) {
                ErrPrint("Handler is not valid\n");
                return LB_STATUS_ERROR_INVALID;
        }
@@ -1394,7 +1431,7 @@ EAPI int livebox_destroy_pd(struct livebox *handler, ret_cb_t cb, void *data)
                return LB_STATUS_ERROR_INVALID;
        }
 
-       if (!handler->pd.data.fb || handler->state != CREATE || !handler->id) {
+       if (handler->state != CREATE || !handler->pd.data.fb || !handler->id) {
                ErrPrint("Handler is not valid\n");
                return LB_STATUS_ERROR_INVALID;
        }
@@ -2581,7 +2618,7 @@ EAPI int livebox_emit_text_signal(struct livebox *handler, const char *emission,
                return LB_STATUS_ERROR_INVALID;
        }
 
-       if ((handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || handler->state != CREATE || !handler->id) {
+       if (handler->state != CREATE || (handler->lb.type != _LB_TYPE_TEXT && handler->pd.type != _PD_TYPE_TEXT) || !handler->id) {
                ErrPrint("Handler is not valid\n");
                return LB_STATUS_ERROR_INVALID;
        }
@@ -2756,7 +2793,7 @@ int lb_set_group(struct livebox *handler, const char *cluster, const char *categ
        if (cluster) {
                pc = strdup(cluster);
                if (!pc) {
-                       CRITICAL_LOG("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
+                       ErrPrint("Heap: %s (cluster: %s)\n", strerror(errno), cluster);
                        return LB_STATUS_ERROR_MEMORY;
                }
        }
@@ -2764,7 +2801,7 @@ int lb_set_group(struct livebox *handler, const char *cluster, const char *categ
        if (category) {
                ps = strdup(category);
                if (!ps) {
-                       CRITICAL_LOG("Heap: %s (category: %s)\n", strerror(errno), category);
+                       ErrPrint("Heap: %s (category: %s)\n", strerror(errno), category);
                        free(pc);
                        return LB_STATUS_ERROR_MEMORY;
                }
@@ -2895,6 +2932,7 @@ struct livebox *lb_new_livebox(const char *pkgname, const char *id, double times
        handler->pd.type = _PD_TYPE_SCRIPT;
        handler->state = CREATE;
        handler->visible = LB_SHOW;
+       handler->delete_type = LB_DELETE_PERMANENTLY;
 
        s_info.livebox_list = dlist_append(s_info.livebox_list, handler);
        lb_ref(handler);
@@ -2925,7 +2963,7 @@ int lb_set_content(struct livebox *handler, const char *content)
        if (content) {
                handler->content = strdup(content);
                if (!handler->content) {
-                       CRITICAL_LOG("Heap: %s (content: %s)\n", strerror(errno), content);
+                       ErrPrint("Heap: %s (content: %s)\n", strerror(errno), content);
                        return LB_STATUS_ERROR_MEMORY;
                }
        }
@@ -2943,7 +2981,7 @@ int lb_set_title(struct livebox *handler, const char *title)
        if (title) {
                handler->title = strdup(title);
                if (!handler->title) {
-                       CRITICAL_LOG("Heap: %s (title: %s)\n", strerror(errno), title);
+                       ErrPrint("Heap: %s (title: %s)\n", strerror(errno), title);
                        return LB_STATUS_ERROR_MEMORY;
                }
        }
@@ -3237,7 +3275,7 @@ struct livebox *lb_unref(struct livebox *handler)
        return NULL;
 }
 
-int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
+int lb_send_delete(struct livebox *handler, int type, ret_cb_t cb, void *data)
 {
        struct packet *packet;
        struct cb_info *cbinfo;
@@ -3253,7 +3291,7 @@ int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data)
                return LB_STATUS_ERROR_BUSY;
        }
 
-       packet = packet_create("delete", "ss", handler->pkgname, handler->id);
+       packet = packet_create("delete", "ssi", handler->pkgname, handler->id, type);
        if (!packet) {
                ErrPrint("Failed to build a param\n");
                if (cb) {