Document libbabeltrace2's C API
[babeltrace.git] / src / fd-cache / fd-cache.c
index 6d62518997665a743ce9dcf6cad716e876964400..c2907a04cb3880029f45bbfd4fbe9337f5757371 100644 (file)
@@ -26,8 +26,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_OUTPUT_LEVEL (fdc->log_level)
 #define BT_LOG_TAG "FD-CACHE"
-#include "logging.h"
+#include "logging/log.h"
 
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -102,10 +103,11 @@ void file_key_destroy(gpointer data)
 }
 
 BT_HIDDEN
-int bt_fd_cache_init(struct bt_fd_cache *fdc)
+int bt_fd_cache_init(struct bt_fd_cache *fdc, int log_level)
 {
        int ret = 0;
 
+       fdc->log_level = log_level;
        fdc->cache = g_hash_table_new_full(file_key_hash, file_key_equal,
                file_key_destroy, (GDestroyNotify) fd_cache_handle_internal_destroy);
        if (!fdc->cache) {
@@ -118,13 +120,17 @@ int bt_fd_cache_init(struct bt_fd_cache *fdc)
 BT_HIDDEN
 void bt_fd_cache_fini(struct bt_fd_cache *fdc)
 {
-       BT_ASSERT(fdc->cache);
+       if (!fdc->cache) {
+               goto end;
+       }
+
        /*
         * All handle should have been removed for the hashtable at this point.
         */
        BT_ASSERT(g_hash_table_size(fdc->cache) == 0);
        g_hash_table_destroy(fdc->cache);
 
+end:
        return;
 }
 
@@ -169,13 +175,13 @@ struct bt_fd_cache_handle *bt_fd_cache_get_handle(struct bt_fd_cache *fdc,
 
                fd_internal = g_new0(struct fd_handle_internal, 1);
                if (!fd_internal) {
-                       BT_LOGE("Failed to allocate fd internal handle");
+                       BT_LOGE_STR("Failed to allocate internal FD handle.");
                        goto error;
                }
 
                file_key = g_new0(struct file_key, 1);
                if (!fd_internal) {
-                       BT_LOGE("Failed to allocate file key");
+                       BT_LOGE_STR("Failed to allocate file key.");
                        goto error;
                }
 
@@ -233,7 +239,7 @@ void bt_fd_cache_put_handle(struct bt_fd_cache *fdc,
 
                close_ret = close(fd_internal->fd_handle.fd);
                if (close_ret == -1) {
-                       BT_LOGW_ERRNO("Failed to close file descriptor",
+                       BT_LOGE_ERRNO("Failed to close file descriptor",
                                ": fd=%d", fd_internal->fd_handle.fd);
                }
                ret = g_hash_table_remove(fdc->cache, fd_internal->key);
This page took 0.044372 seconds and 4 git commands to generate.