Changeset 8375d0eb in mainline
- Timestamp:
- 2012-06-08T07:02:55Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8b36bf2
- Parents:
- 5c925ce
- Location:
- uspace/app/bithenge
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/blob.c
r5c925ce r8375d0eb 226 226 }; 227 227 228 /** Create a blob from data. Unlike with @a228 /** Create a blob node from data. Unlike with @a 229 229 * bithenge_blob_t::bithenge_new_blob_from_buffer, the data is copied into a 230 230 * new buffer and the original data can be changed after this call. The blob 231 * must be freed with @a bithenge_ blob_t::bithenge_blob_destroy after it is231 * must be freed with @a bithenge_node_t::bithenge_node_destroy after it is 232 232 * used. 233 233 * @memberof bithenge_blob_t 234 * @param[out] out Stores the created blob .234 * @param[out] out Stores the created blob node. 235 235 * @param[in] data The data. 236 236 * @param len The length of the data. … … 264 264 } 265 265 266 /** Create a blob from a buffer. The buffer must exist as long as the blob267 * does. The blob must be freed with @a bithenge_ blob_t::bithenge_blob_destroy266 /** Create a blob node from a buffer. The buffer must exist as long as the blob 267 * does. The blob must be freed with @a bithenge_node_t::bithenge_node_destroy 268 268 * after it is used. 269 269 * @memberof bithenge_blob_t 270 * @param[out] out Stores the created blob .270 * @param[out] out Stores the created blob node. 271 271 * @param[in] buffer The buffer, which must not be changed until the blob is 272 272 * destroyed. -
uspace/app/bithenge/blob.h
r5c925ce r8375d0eb 41 41 #include "tree.h" 42 42 43 /** A blob of raw binary data. */ 43 /** A blob of raw binary data. 44 * @implements bithenge_node_t */ 44 45 typedef struct { 45 46 /** @privatesection */ … … 55 56 int (*read)(bithenge_blob_t *blob, aoff64_t offset, char *buffer, 56 57 aoff64_t *size); 57 /** @copydoc bithenge_blob_t::bithenge_blob_destroy */ 58 /** Destroy the blob. 59 * @param blob The blob. 60 * @return EOK on success or an error code from errno.h. */ 58 61 int (*destroy)(bithenge_blob_t *blob); 59 62 } bithenge_random_access_blob_ops_t; … … 148 151 } 149 152 153 /** Cast a blob node to a generic node. 154 * @memberof bithenge_blob_t 155 * @param blob The blob to cast. 156 * @return The blob node as a generic node. */ 150 157 static inline bithenge_node_t *bithenge_blob_as_node(bithenge_blob_t *blob) 151 158 { … … 153 160 } 154 161 162 /** Cast a generic node to a blob node. 163 * @memberof bithenge_blob_t 164 * @param node The node to cast, which must be a blob node. 165 * @return The generic node as a blob node. */ 155 166 static inline bithenge_blob_t *bithenge_node_as_blob(bithenge_node_t *node) 156 167 { 168 assert(node->type == BITHENGE_NODE_BLOB); 157 169 return (bithenge_blob_t *)node; 158 170 } -
uspace/app/bithenge/block.c
r5c925ce r8375d0eb 93 93 94 94 /** Create a blob for a block device. The blob must be freed with 95 * @a bithenge_ blob_t::bithenge_blob_destroy after it is used.95 * @a bithenge_node_t::bithenge_node_destroy after it is used. 96 96 * @param[out] out Stores the created blob. 97 97 * @param service_id The service ID of the block device. -
uspace/app/bithenge/file.c
r5c925ce r8375d0eb 133 133 134 134 /** Create a blob for a file. The blob must be freed with @a 135 * bithenge_ blob_t::bithenge_blob_destroy after it is used.135 * bithenge_node_t::bithenge_node_destroy after it is used. 136 136 * @param[out] out Stores the created blob. 137 137 * @param filename The name of the file. … … 149 149 150 150 /** Create a blob for a file descriptor. The blob must be freed with @a 151 * bithenge_ blob_t::bithenge_blob_destroy after it is used.151 * bithenge_node_t::bithenge_node_destroy after it is used. 152 152 * @param[out] out Stores the created blob. 153 153 * @param fd The file descriptor. … … 159 159 160 160 /** Create a blob for a file pointer. The blob must be freed with @a 161 * bithenge_ blob_t::bithenge_blob_destroy after it is used.161 * bithenge_node_t::bithenge_node_destroy after it is used. 162 162 * @param[out] out Stores the created blob. 163 163 * @param file The file pointer. -
uspace/app/bithenge/print.c
r5c925ce r8375d0eb 141 141 } 142 142 143 /** Print a tree as text. 144 * @param type The format to use. 145 * @param tree The root node of the tree to print. 146 * @return EOK on success or an error code from errno.h. */ 143 147 int bithenge_print_node(bithenge_print_type_t type, bithenge_node_t *tree) 144 148 { 145 149 switch (bithenge_node_type(tree)) { 146 case BITHENGE_NODE_NONE:147 return EINVAL;148 150 case BITHENGE_NODE_INTERNAL: 149 151 return print_internal(type, tree); … … 159 161 return ENOTSUP; 160 162 } 163 164 /** @} 165 */ -
uspace/app/bithenge/print.h
r5c925ce r8375d0eb 40 40 #include "tree.h" 41 41 42 /** Specifies the format to be used when printing. */ 42 43 typedef enum { 44 /** Print a Python value. Note that internal nodes will be represented 45 * as unordered dictionaries. */ 43 46 BITHENGE_PRINT_PYTHON, 47 /** Print JSON. Due to the limitations of JSON, type information may be 48 * lost. */ 44 49 BITHENGE_PRINT_JSON, 45 50 } bithenge_print_type_t; -
uspace/app/bithenge/tree.c
r5c925ce r8375d0eb 47 47 } 48 48 49 /** Destroy a node. 50 * @memberof bithenge_node_t 51 * @param node The node to destroy. 52 * @return EOK on success or an error code from errno.h. */ 49 53 int bithenge_node_destroy(bithenge_node_t *node) 50 54 { … … 61 65 return EOK; // the boolean nodes are allocated statically below 62 66 case BITHENGE_NODE_INTEGER: /* pass-through */ 63 case BITHENGE_NODE_NONE:64 67 break; 65 68 } … … 81 84 } 82 85 83 static int simple_internal_node_for_each(bithenge_node_t *base, bithenge_for_each_func_t func, void *data) 86 static int simple_internal_node_for_each(bithenge_node_t *base, 87 bithenge_for_each_func_t func, void *data) 84 88 { 85 89 int rc; … … 121 125 } 122 126 123 int bithenge_new_simple_internal_node(bithenge_node_t **out, bithenge_node_t **nodes, bithenge_int_t len, bool needs_free) 127 /** Create an internal node from a set of keys and values. The node must be 128 * freed with @a bithenge_node_t::bithenge_node_destroy after it is used, which 129 * will also destroy all the key and value nodes. 130 * @memberof bithenge_node_t 131 * @param[out] out Stores the created internal node. 132 * @param nodes The array of key-value pairs. Keys are stored at even indices 133 * and values are stored at odd indices. 134 * @param len The number of key-value pairs in the node array. 135 * @param needs_free If true, when the internal node is destroyed it will free 136 * the nodes array as well as destroying each node inside it. 137 * @return EOK on success or an error code from errno.h. */ 138 int bithenge_new_simple_internal_node(bithenge_node_t **out, 139 bithenge_node_t **nodes, bithenge_int_t len, bool needs_free) 124 140 { 125 141 assert(out); … … 139 155 static bithenge_node_t true_node = { BITHENGE_NODE_BOOLEAN, .boolean_value = true }; 140 156 157 /** Create a boolean node. The node must be freed with @a 158 * bithenge_node_t::bithenge_node_destroy after it is used. 159 * @memberof bithenge_node_t 160 * @param[out] out Stores the created boolean node. 161 * @param value The value for the node to hold. 162 * @return EOK on success or an error code from errno.h. */ 141 163 int bithenge_new_boolean_node(bithenge_node_t **out, bool value) 142 164 { … … 146 168 } 147 169 170 /** Create an integer node. The node must be freed with @a 171 * bithenge_node_t::bithenge_node_destroy after it is used. 172 * @memberof bithenge_node_t 173 * @param[out] out Stores the created integer node. 174 * @param value The value for the node to hold. 175 * @return EOK on success or an error code from errno.h. */ 148 176 int bithenge_new_integer_node(bithenge_node_t **out, bithenge_int_t value) 149 177 { … … 158 186 } 159 187 188 /** Create a string node. The node must be freed with @a 189 * bithenge_node_t::bithenge_node_destroy after it is used. 190 * @memberof bithenge_node_t 191 * @param[out] out Stores the created string node. 192 * @param value The value for the node to hold. 193 * @param needs_free Whether the string should be freed when the node is 194 * destroyed. 195 * @return EOK on success or an error code from errno.h. */ 160 196 int bithenge_new_string_node(bithenge_node_t **out, const char *value, bool needs_free) 161 197 { … … 170 206 return EOK; 171 207 } 208 209 /** @} 210 */ -
uspace/app/bithenge/tree.h
r5c925ce r8375d0eb 51 51 #endif 52 52 53 /** Indicates the type of a tree node. */ 53 54 typedef enum { 54 BITHENGE_NODE_NONE, 55 BITHENGE_NODE_INTERNAL, 55 /** An internal node with labelled edges to other nodes. */ 56 BITHENGE_NODE_INTERNAL = 1, 57 /** A leaf node holding a boolean value. */ 56 58 BITHENGE_NODE_BOOLEAN, 59 /** A leaf node holding an integer. */ 57 60 BITHENGE_NODE_INTEGER, 61 /** A leaf node holding a string. */ 58 62 BITHENGE_NODE_STRING, 63 /** A leaf node holding a binary blob. */ 59 64 BITHENGE_NODE_BLOB, 60 65 } bithenge_node_type_t; 61 66 62 67 typedef struct bithenge_node_t { 68 /** @privatesection */ 63 69 bithenge_node_type_t type; 64 70 union { … … 74 80 } bithenge_node_t; 75 81 82 /** A callback function used to iterate over a node's children. 83 * @memberof bithenge_node_t 84 * @param key The key. 85 * @param value The value. 86 * @param data Data provided to @a bithenge_node_t::bithenge_node_for_each. 87 * @return EOK on success or an error code from errno.h. */ 88 typedef int (*bithenge_for_each_func_t)(bithenge_node_t *key, bithenge_node_t *value, void *data); 89 90 /** Operations providing access to an internal node. */ 91 typedef struct bithenge_internal_node_ops_t { 92 /** @copydoc bithenge_node_t::bithenge_node_for_each */ 93 int (*for_each)(bithenge_node_t *node, bithenge_for_each_func_t func, void *data); 94 /** @copydoc bithenge_node_t::bithenge_node_destroy */ 95 int (*destroy)(bithenge_node_t *node); 96 } bithenge_internal_node_ops_t; 97 98 /** Find the type of a node. 99 * @memberof bithenge_node_t 100 * @param node The node. 101 * @return The type of the node. */ 76 102 static inline bithenge_node_type_t bithenge_node_type(const bithenge_node_t *node) 77 103 { … … 79 105 } 80 106 81 typedef int (*bithenge_for_each_func_t)(bithenge_node_t *key, bithenge_node_t *value, void *data); 82 83 typedef struct bithenge_internal_node_ops_t { 84 int (*for_each)(bithenge_node_t *node, bithenge_for_each_func_t func, void *data); 85 int (*destroy)(bithenge_node_t *node); 86 } bithenge_internal_node_ops_t; 87 107 /** Iterate over a node's children. 108 * @memberof bithenge_node_t 109 * @param node The internal node to iterate over. 110 * @param func The callback function. 111 * @param data Data to provide to the callback function. 112 * @return EOK on success or an error code from errno.h. */ 88 113 static inline int bithenge_node_for_each(bithenge_node_t *node, bithenge_for_each_func_t func, void *data) 89 114 { … … 92 117 } 93 118 119 /** Get the value of a boolean node. 120 * @memberof bithenge_node_t 121 * @param node The boolean node. 122 * @return The node's value. */ 94 123 static inline bool bithenge_boolean_node_value(bithenge_node_t *node) 95 124 { … … 98 127 } 99 128 129 /** Get the value of an integer node. 130 * @memberof bithenge_node_t 131 * @param node The integer node. 132 * @return The node's value. */ 100 133 static inline bithenge_int_t bithenge_integer_node_value(bithenge_node_t *node) 101 134 { … … 104 137 } 105 138 139 /** Get the value of an string node. 140 * @memberof bithenge_node_t 141 * @param node The string node. 142 * @return The node's value. */ 106 143 static inline const char *bithenge_string_node_value(bithenge_node_t *node) 107 144 { … … 110 147 } 111 148 112 int bithenge_new_simple_internal_node(bithenge_node_t **, bithenge_node_t **, bithenge_int_t, bool needs_free); 149 int bithenge_new_simple_internal_node(bithenge_node_t **, bithenge_node_t **, 150 bithenge_int_t, bool needs_free); 113 151 int bithenge_new_boolean_node(bithenge_node_t **, bool); 114 152 int bithenge_new_integer_node(bithenge_node_t **, bithenge_int_t);
Note:
See TracChangeset
for help on using the changeset viewer.