bake.h 4.13 KB
Newer Older
Philip Carns's avatar
Philip Carns committed
1
2
/*
 * (C) 2016 The University of Chicago
Philip Carns's avatar
Philip Carns committed
3
 *
Philip Carns's avatar
Philip Carns committed
4
5
6
 * See COPYRIGHT in top-level directory.
 */

7
8
#ifndef __BAKE_H
#define __BAKE_H
9

Shane Snyder's avatar
Shane Snyder committed
10
#include <uuid/uuid.h>
Philip Carns's avatar
Philip Carns committed
11
#include <stdint.h>
12
13
14
15
16

#ifdef __cplusplus
extern "C" {
#endif

Philip Carns's avatar
Philip Carns committed
17
18
19
20
21
22
23
24
25
#define BAKE_TRACE(_mid, _format, f...) margo_trace(_mid, "bake: " _format, ##f)
#define BAKE_DEBUG(_mid, _format, f...) margo_debug(_mid, "bake: " _format, ##f)
#define BAKE_INFO(_mid, _format, f...)  margo_info(_mid, "bake: " _format, ##f)
#define BAKE_WARNING(_mid, _format, f...) \
    margo_warning(_mid, "bake: " _format, ##f)
#define BAKE_ERROR(_mid, _format, f...) margo_error(_mid, "bake: " _format, ##f)
#define BAKE_CRITICAL(_mid, _format, f...) \
    margo_critical(_mid, "bake: " _format, ##f)

26
27
typedef struct {
    uuid_t id;
28
} bake_target_id_t;
Philip Carns's avatar
Philip Carns committed
29
/**
30
 * Persistent, opaque identifier for a region within a BAKE target.
Philip Carns's avatar
Philip Carns committed
31
 */
32
#define BAKE_REGION_ID_DATA_SIZE 16
Philip Carns's avatar
Philip Carns committed
33
typedef struct {
Philip Carns's avatar
Philip Carns committed
34
    uint32_t type;
Philip Carns's avatar
Philip Carns committed
35
    char     data[BAKE_REGION_ID_DATA_SIZE];
36
} bake_region_id_t;
Philip Carns's avatar
Philip Carns committed
37

Philip Carns's avatar
Philip Carns committed
38
39
40
#define BAKE_SUCCESS         0    /* Success */
#define BAKE_ERR_ALLOCATION  (-1) /* Error allocating something */
#define BAKE_ERR_INVALID_ARG (-2) /* An argument is invalid */
41
42
43
#define BAKE_ERR_MERCURY                                 \
    (-3) /* An error happened calling a Mercury function \
          */
Philip Carns's avatar
Philip Carns committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#define BAKE_ERR_ARGOBOTS \
    (-4)                   /* An error happened calling an Argobots function */
#define BAKE_ERR_PMEM (-5) /* An error happened calling a pmem function */
#define BAKE_ERR_UNKNOWN_TARGET \
    (-6) /* Target refered to by id is not known to provider */
#define BAKE_ERR_UNKNOWN_PROVIDER \
    (-7) /* Provider id could not be matched with a provider */
#define BAKE_ERR_UNKNOWN_REGION (-8)  /* Region id could not be found */
#define BAKE_ERR_OUT_OF_BOUNDS  (-9)  /* Attempting an out of bound access */
#define BAKE_ERR_REMI           (-10) /* Error related to REMI */
#define BAKE_ERR_OP_UNSUPPORTED (-11) /* Operation not supported */
#define BAKE_ERR_FORBIDDEN      (-12) /* Forbidden operation */
#define BAKE_ERR_BACKEND_TYPE   (-13) /* Unknown backend type */
#define BAKE_ERR_IO             (-14) /* Back-end I/O error */
58
59
60
#define BAKE_ERR_NOENT          (-15) /* entry does not exist */
#define BAKE_ERR_EXIST          (-16) /* entry already exists */
#define BAKE_ERR_END            (-17) /* End of valid bake error codes */
Matthieu Dorier's avatar
Matthieu Dorier committed
61

62
63
64
65
66
67
/**
 * Print bake errors in human-friendly form
 *
 * @param a string to print out before the error
 * @param ret error code from a bake routine
 */
Philip Carns's avatar
Philip Carns committed
68
void bake_perror(const char* s, int ret);
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
 * @brief Converts a target id into an ASCII readable string.
 *
 * @param tid Target id to convert into a string.
 * @param str Resulting string (must be allocated to at least 37 bytes)
 * @param size size of the allocated string.
 *
 * @return error code.
 */
int bake_target_id_to_string(bake_target_id_t tid, char* str, size_t size);

/**
 * @brief Converts an ASCI readable representation of the target id into
 * and actual target id.
 *
 * @param str Null-terminated string to read from.
 * @param tid Resulting target id.
 *
 * @return error code.
 */
int bake_target_id_from_string(const char* str, bake_target_id_t* tid);

/**
 * @brief Converts the region id into an ASCII readable representation.
 *
 * @param rid Region id.
 * @param str Resulting string, should be preallocated wirg sufficient size.
 * @param size size of the preallocated string.
 *
 * @return error code.
 */
int bake_region_id_to_string(bake_region_id_t rid, char* str, size_t size);

/**
 * @brief Converts a string back into a region id.
 *
 * @param str String to convert.
 * @param rid Resulting region id.
 *
 * @return error code.
 */
int bake_region_id_from_string(const char* str, bake_region_id_t* rid);

113
114
115
116
117
118
119
120
/**
 * Convert region id into printable string for debugging purposes
 *
 * @param[in] str string to fill in
 * @param[in] size length of string, not including terminator.  If rid
 *                 string is longer than this it will be truncated.
 * @param[in] rid region_id
 */
Philip Carns's avatar
Philip Carns committed
121
void bake_print_dbg_region_id_t(char* str, size_t size, bake_region_id_t rid)
122
    __attribute__((deprecated("use bake_region_id_to_string instead")));
123

124
125
#ifdef __cplusplus
}
Philip Carns's avatar
Philip Carns committed
126
#endif
127

128
#endif /* __BAKE_H */