|
| 1 | +/* |
| 2 | + * Copyright (c) 2022 The University of Tennessee and The University |
| 3 | + * of Tennessee Research Foundation. All rights |
| 4 | + * reserved. |
| 5 | + * |
| 6 | + * $COPYRIGHT$ |
| 7 | + * |
| 8 | + * Additional copyrights may follow |
| 9 | + * |
| 10 | + * $HEADER$ |
| 11 | + */ |
| 12 | + |
| 13 | +/** |
| 14 | + * @file |
| 15 | + * |
| 16 | + * Generic routines for "info" handling. This is a sinple key-value store that |
| 17 | + * is independent from the main MCA param key-value store. Helpful for creating |
| 18 | + * info strings without affecting MCA params. |
| 19 | + */ |
| 20 | + |
| 21 | +#ifndef PARSEC_INFO_H |
| 22 | +#define PARSEC_INFO_H |
| 23 | + |
| 24 | +#include "parsec/parsec_config.h" |
| 25 | + |
| 26 | +#ifdef PARSEC_HAVE_SYS_TYPES_H |
| 27 | +#include <sys/types.h> |
| 28 | +#endif |
| 29 | +#ifdef PARSEC_HAVE_STDBOOL_H |
| 30 | +#include <stdbool.h> |
| 31 | +#endif |
| 32 | + |
| 33 | +BEGIN_C_DECLS |
| 34 | + |
| 35 | + |
| 36 | +typedef char* parsec_info_key_t; |
| 37 | +typedef char* parsec_info_value_t; |
| 38 | + |
| 39 | + |
| 40 | +struct parsec_info_value_s { |
| 41 | + char val[PARSEC_INFO_VALUE_LEN]; |
| 42 | +} parsec_info_value_t; |
| 43 | + |
| 44 | + |
| 45 | +struct parsec_info_s { |
| 46 | + parsec_hashtable_t super; |
| 47 | +} parsec_info_t; |
| 48 | + |
| 49 | +PARSEC_OBJ_CLASS(parsec_info_t); |
| 50 | + |
| 51 | +} parsec_info_t; |
| 52 | + |
| 53 | +#define PARSEC_INFO_VALUE_NULL NULL |
| 54 | + |
| 55 | + |
| 56 | +/** |
| 57 | + * Set the key-value pair in the target info object. |
| 58 | + * |
| 59 | + * @param info Pointer to the target info object. Must not be |
| 60 | + * NULL. |
| 61 | + * @param key String for the key, max length PARSEC_INFO_KEY_LEN. |
| 62 | + * @param value String for the value to attache to the key, max |
| 63 | + * length PARSEC_INFO_VALUE_LEN. |
| 64 | + * |
| 65 | + * @retval PARSEC_SUCCESS On success |
| 66 | + * @retval PARSEC_ERROR On failure, values lower than PARSEC_ERROR may |
| 67 | + * elaborate on the particular error type. |
| 68 | + * |
| 69 | + * This function associates a string value to the string key in the |
| 70 | + * key-value store info. The value string is copied to the internal |
| 71 | + * storage of the key-value store. To reiterate, there is no need to |
| 72 | + * keep a copy of the value. |
| 73 | + * |
| 74 | + * If the key is already set to a value, the previous value is |
| 75 | + * overwritten for te key. In particular, if the value is |
| 76 | + * PARSEC_INFO_VALUE_NULL, the previous key-value pair is removed |
| 77 | + * from the info. |
| 78 | + */ |
| 79 | +parsec_info_set(parsec_info_t *info, const char *key, const char *value); |
| 80 | + |
| 81 | +/** |
| 82 | + * Get the value associated with the key in the target info object. |
| 83 | + * |
| 84 | + * @param info Pointer to the target info object. Must not be |
| 85 | + * NULL. |
| 86 | + * @param key String for the key, max length PARSEC_INFO_KEY_LEN. |
| 87 | + * @param value Pointer to the string of the value to retrieve; |
| 88 | + * |
| 89 | + * @retval PARSEC_SUCCESS On success |
| 90 | + * @retval PARSEC_ERROR On failure, values lower than PARSEC_ERROR may |
| 91 | + * elaborate on the particular error type. |
| 92 | + * |
| 93 | + * This function obtains the string value associated with the string |
| 94 | + * key in the key-value store info. A pointer to the internal value |
| 95 | + * string is returned. To reiterate, the value is shared with the |
| 96 | + * internal storage of the info object and must not be freed. |
| 97 | + * |
| 98 | + * If the key is not set to a value, the value is set to |
| 99 | + * PARSEC_INFO_VALUE_NULL. |
| 100 | + */ |
| 101 | +parsec_info_get(parsec_info_t *info, const char *key, char **value); |
| 102 | + |
| 103 | +/** |
| 104 | + * Clear all key-values from the target info object. |
| 105 | + * |
| 106 | + * @param info Pointer to the target info object. Must not be |
| 107 | + * NULL. |
| 108 | + * |
| 109 | + * @retval PARSEC_SUCCESS On success |
| 110 | + * @retcal PARSEC_ERROR On failure, values lower than PARSEC_ERROR may |
| 111 | + * elaborate on the particular error type. |
| 112 | + * |
| 113 | + * This function clears all previously set key-values from the target |
| 114 | + * key-value store object; that is, it is equivalent to calling |
| 115 | + * parsec_info_set with the value PARSEC_INFO_VALUE_NULL, for any key |
| 116 | + * previously set on the info. |
| 117 | + */ |
| 118 | +parsec_info_clear(parserc_info_t *info); |
| 119 | + |
| 120 | +/** |
| 121 | + * Obtain the info object associated with the givent context |
| 122 | + * |
| 123 | + * @param ctx The context to query |
| 124 | + * @param info Pointer to the info object associated with the context |
| 125 | + * |
| 126 | + * @retval PARSEC_SUCCESS On success |
| 127 | + * @retval PARSEC_ERROR On failure |
| 128 | + * |
| 129 | + * The returned info object may be empty (that is, it has no values |
| 130 | + * associated with any keys), but is always returns a reference to a |
| 131 | + * valid info object. |
| 132 | + * |
| 133 | + * Key-values added to the info object will be implicitly applied to |
| 134 | + * the context, that is, the info is a reference to the info object |
| 135 | + * internally held by the context. |
| 136 | + */ |
| 137 | +parsec_context_get_info(parsec_context_t *ctx, parsec_info_t **info); |
| 138 | + |
| 139 | +/** |
| 140 | + * Obtain the info object associated with the givent taskpool |
| 141 | + * |
| 142 | + * @param tp The taskpool to query |
| 143 | + * @param info Pointer to the info object associated with the context |
| 144 | + * |
| 145 | + * @retval PARSEC_SUCCESS On success |
| 146 | + * @retval PARSEC_ERROR On failure |
| 147 | + * |
| 148 | + * The returned info object may be empty (that is, it has no values |
| 149 | + * associated with any keys), but is always returns a reference to a |
| 150 | + * valid info object. |
| 151 | + * |
| 152 | + * Key-values added to the info object will be implicitly applied to |
| 153 | + * the taskpool, that is, the info is a reference to the info object |
| 154 | + * internally held by the taskpool. |
| 155 | + */ |
| 156 | +parsec_taskpool_get_info(parsec_taskpool_t *tp, parsec_info_t **info); |
| 157 | + |
| 158 | +END_C_DECLS |
| 159 | + |
| 160 | +#endif /* PARSEC_INFO_H */ |
0 commit comments