* Copyright (c) 2018 Philippe Proulx <pproulx@efficios.com>
*/
-#ifndef BABELTRACE_COMMON_INTERNAL_H
-#define BABELTRACE_COMMON_INTERNAL_H
+#ifndef BABELTRACE_COMMON_COMMON_H
+#define BABELTRACE_COMMON_COMMON_H
#include <errno.h>
#include <glib.h>
bt_common_handle_custom_specifier_func handle_specifier,
void *priv_data, const char *fmt, va_list *args);
-/*
- * Variadic form of bt_common_custom_vsnprintf().
- */
-void bt_common_custom_snprintf(char *buf, size_t buf_size,
- char intro,
- bt_common_handle_custom_specifier_func handle_specifier,
- void *priv_data, const char *fmt, ...);
-
/*
* Returns the system page size.
*/
void bt_common_abort(void) __attribute__((noreturn));
-#if (!defined(BT_LOG_WRITE_CUR_LVL) && !defined(BT_LOG_WRITE_ERRNO_CUR_LVL))
-#define BT_LOG_LEVEL_UNUSED_ATTR __attribute__((unused))
-#else
-#define BT_LOG_LEVEL_UNUSED_ATTR
-#endif
-
-/*
- * Wraps read() function to handle EINTR and partial reads.
- * On success, it returns `count` received as parameter. On error, it returns a
- * value smaller than the requested `count`.
- */
-static inline
-ssize_t bt_common_read(int fd, void *buf, size_t count,
- int log_level BT_LOG_LEVEL_UNUSED_ATTR)
-{
- size_t i = 0;
- ssize_t ret;
-
- BT_ASSERT_DBG(buf);
-
- /* Never return an overflow value. */
- BT_ASSERT_DBG(count <= SSIZE_MAX);
-
- do {
- ret = read(fd, ((char *) buf) + i, count - i);
- if (ret < 0) {
- if (errno == EINTR) {
-#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_LOG_WRITE_ERRNO_PRINTF_CUR_LVL
- BT_LOG_WRITE_ERRNO_PRINTF_CUR_LVL(BT_LOG_ERROR,
- log_level, BT_LOG_TAG,
- "Error while reading", ": fd=%d", fd);
-#endif
- goto end;
- }
- }
- i += ret;
- BT_ASSERT_DBG(i <= count);
- } while (count - i > 0 && ret > 0);
-
-end:
- if (ret >= 0) {
- if (i == 0) {
- ret = -1;
- } else {
- ret = i;
- }
- }
-
- return ret;
-}
-
static inline
const char *bt_common_field_class_type_string(enum bt_field_class_type class_type)
{
return "VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD";
case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD:
return "VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD";
+ case BT_FIELD_CLASS_TYPE_BLOB:
+ return "BT_FIELD_CLASS_TYPE_BLOB";
+ case BT_FIELD_CLASS_TYPE_STATIC_BLOB:
+ return "BT_FIELD_CLASS_TYPE_STATIC_BLOB";
+ case BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB:
+ return "BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB";
+ case BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITHOUT_LENGTH_FIELD:
+ return "BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITHOUT_LENGTH_FIELD";
+ case BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITH_LENGTH_FIELD:
+ return "BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITH_LENGTH_FIELD";
case __BT_FIELD_CLASS_TYPE_BIG_VALUE:
bt_common_abort ();
}
}
static inline
-const char *bt_common_scope_string(enum bt_field_path_scope scope)
+const char *bt_common_field_path_scope_string(enum bt_field_path_scope scope)
{
switch (scope) {
case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT:
bt_common_abort();
}
+static inline
+const char *bt_common_field_location_scope_string(enum bt_field_location_scope scope)
+{
+ switch (scope) {
+ case BT_FIELD_LOCATION_SCOPE_PACKET_CONTEXT:
+ return "PACKET_CONTEXT";
+ case BT_FIELD_LOCATION_SCOPE_EVENT_COMMON_CONTEXT:
+ return "EVENT_COMMON_CONTEXT";
+ case BT_FIELD_LOCATION_SCOPE_EVENT_SPECIFIC_CONTEXT:
+ return "EVENT_SPECIFIC_CONTEXT";
+ case BT_FIELD_LOCATION_SCOPE_EVENT_PAYLOAD:
+ return "EVENT_PAYLOAD";
+ }
+
+ bt_common_abort();
+}
+
static inline
const char *bt_common_event_class_log_level_string(
enum bt_event_class_log_level level)
goto end;
}
- g_string_append_printf(str, "[%s", bt_common_scope_string(
+ g_string_append_printf(str, "[%s", bt_common_field_path_scope_string(
bt_field_path_get_root_scope(path)));
for (i = 0; i < bt_field_path_get_item_count(path); i++) {
}
#endif
-#endif /* BABELTRACE_COMMON_INTERNAL_H */
+#endif /* BABELTRACE_COMMON_COMMON_H */