lib: strictly type function return status enumerations
[babeltrace.git] / src / common / common.h
index c62da1a3b80d214c03c7e1014541549327cfb941..809c2e5063556a3ec500d60694794a9bf8264ce4 100644 (file)
 #include <stdlib.h>
 #include <unistd.h>
 
-#include <babeltrace2/graph/self-message-iterator.h>
 #include <babeltrace2/trace-ir/event-class-const.h>
 #include <babeltrace2/trace-ir/field-class-const.h>
 #include <babeltrace2/trace-ir/field-path-const.h>
 #include <babeltrace2/logging.h>
 #include <babeltrace2/value.h>
 
+#define __BT_FUNC_STATUS_ENABLE
+#include <babeltrace2/func-status.h>
+#undef __BT_FUNC_STATUS_ENABLE
+
 #include "common/assert.h"
 #include "common/macros.h"
 #include "common/safe.h"
@@ -93,7 +96,7 @@ const char *bt_common_get_system_plugin_path(void);
  * return value.
  */
 BT_HIDDEN
-char *bt_common_get_home_plugin_path(void);
+char *bt_common_get_home_plugin_path(int log_level);
 
 /*
  * Appends the list of directories in `paths` to the array `dirs`.
@@ -310,7 +313,7 @@ void bt_common_custom_snprintf(char *buf, size_t buf_size,
  * Returns the system page size.
  */
 BT_HIDDEN
-size_t bt_common_get_page_size(void);
+size_t bt_common_get_page_size(int log_level);
 
 /*
  * Adds the digit separator `sep` as many times as needed to form groups
@@ -334,7 +337,7 @@ void bt_common_sep_digits(char *str, unsigned int digits_per_group, char sep);
  * value smaller than the requested `count`.
  */
 static inline
-ssize_t bt_common_read(int fd, void *buf, size_t count)
+ssize_t bt_common_read(int fd, void *buf, size_t count, int log_level)
 {
        size_t i = 0;
        ssize_t ret;
@@ -348,15 +351,18 @@ ssize_t bt_common_read(int fd, void *buf, size_t count)
                ret = read(fd, buf + i, count - i);
                if (ret < 0) {
                        if (errno == EINTR) {
-#ifdef BT_LOGD_STR
-                               BT_LOGD_STR("read() call interrupted; retrying...");
+#ifdef BT_LOG_WRITE_CUR_LVL
+                               BT_LOG_WRITE_CUR_LVL(BT_LOG_DEBUG, log_level,
+                                       BT_LOG_TAG,
+                                       "read() call interrupted; retrying...");
 #endif
                                /* retry operation */
                                continue;
                        } else {
-#ifdef BT_LOGE_ERRNO
-                               BT_LOGE_ERRNO("Error while reading", ": fd=%d",
-                                       fd);
+#ifdef BT_LOG_WRITE_ERRNO_CUR_LVL
+                               BT_LOG_WRITE_ERRNO_CUR_LVL(BT_LOG_ERROR,
+                                       log_level, BT_LOG_TAG,
+                                       "Error while reading", ": fd=%d", fd);
 #endif
                                goto end;
                        }
@@ -543,33 +549,13 @@ end:
        return str;
 }
 
-static inline
-const char *bt_common_self_message_iterator_status_string(
-               enum bt_self_message_iterator_status status)
-{
-       switch (status) {
-       case BT_SELF_MESSAGE_ITERATOR_STATUS_AGAIN:
-               return "BT_SELF_MESSAGE_ITERATOR_STATUS_AGAIN";
-       case BT_SELF_MESSAGE_ITERATOR_STATUS_END:
-               return "BT_SELF_MESSAGE_ITERATOR_STATUS_END";
-       case BT_SELF_MESSAGE_ITERATOR_STATUS_OK:
-               return "BT_SELF_MESSAGE_ITERATOR_STATUS_OK";
-       case BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR:
-               return "BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR";
-       case BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM:
-               return "BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM";
-       default:
-               return "(unknown)";
-       }
-};
-
 static inline
 const char *bt_common_logging_level_string(
                enum bt_logging_level level)
 {
        switch (level) {
-       case BT_LOGGING_LEVEL_VERBOSE:
-               return "BT_LOGGING_LEVEL_VERBOSE";
+       case BT_LOGGING_LEVEL_TRACE:
+               return "BT_LOGGING_LEVEL_TRACE";
        case BT_LOGGING_LEVEL_DEBUG:
                return "BT_LOGGING_LEVEL_DEBUG";
        case BT_LOGGING_LEVEL_INFO:
@@ -587,6 +573,39 @@ const char *bt_common_logging_level_string(
        }
 };
 
+static inline
+const char *bt_common_func_status_string(int status)
+{
+       switch (status) {
+       case __BT_FUNC_STATUS_OVERFLOW:
+               return "OVERFLOW";
+       case __BT_FUNC_STATUS_INVALID_PARAMS:
+               return "INVALID_PARAMS";
+       case __BT_FUNC_STATUS_INVALID_OBJECT:
+               return "INVALID_OBJECT";
+       case __BT_FUNC_STATUS_MEMORY_ERROR:
+               return "MEMORY_ERROR";
+       case __BT_FUNC_STATUS_LOADING_ERROR:
+               return "LOADING_ERROR";
+       case __BT_FUNC_STATUS_ERROR:
+               return "ERROR";
+       case __BT_FUNC_STATUS_OK:
+               return "OK";
+       case __BT_FUNC_STATUS_END:
+               return "END";
+       case __BT_FUNC_STATUS_NOT_FOUND:
+               return "NOT_FOUND";
+       case __BT_FUNC_STATUS_AGAIN:
+               return "AGAIN";
+       case __BT_FUNC_STATUS_UNSUPPORTED:
+               return "UNSUPPORTED";
+       case __BT_FUNC_STATUS_CANCELED:
+               return "CANCELED";
+       default:
+               return "(unknown)";
+       }
+}
+
 #define NS_PER_S_I     INT64_C(1000000000)
 #define NS_PER_S_U     UINT64_C(1000000000)
 
@@ -678,11 +697,6 @@ end:
        return ret;
 }
 
-static inline
-enum bt_self_message_iterator_status bt_common_message_iterator_status_to_self(
-               enum bt_message_iterator_status status)
-{
-       return (int) status;
-}
+#include <babeltrace2/undef-func-status.h>
 
 #endif /* BABELTRACE_COMMON_INTERNAL_H */
This page took 0.025444 seconds and 4 git commands to generate.