Changeset 978ccaf1 in mainline for uspace/app/bithenge/transform.c
- Timestamp:
- 2012-06-27T03:35:43Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 600f5d1
- Parents:
- 04a7435f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/transform.c
r04a7435f r978ccaf1 42 42 43 43 /** Initialize a new transform. 44 * @param[out] xformTransform to initialize.44 * @param[out] self Transform to initialize. 45 45 * @param[in] ops Operations provided by the transform. 46 46 * @return EOK or an error code from errno.h. */ 47 int bithenge_ new_transform(bithenge_transform_t *xform,47 int bithenge_init_transform(bithenge_transform_t *self, 48 48 const bithenge_transform_ops_t *ops) 49 49 { … … 51 51 assert(ops->apply); 52 52 assert(ops->destroy); 53 xform->ops = ops;54 xform->refs = 1;55 return EOK; 56 } 57 58 static int transform_indestructible(bithenge_transform_t *xform)53 self->ops = ops; 54 self->refs = 1; 55 return EOK; 56 } 57 58 static void transform_indestructible(bithenge_transform_t *self) 59 59 { 60 60 assert(false); 61 return EOK; 62 } 63 64 static int uint32le_apply(bithenge_transform_t *xform, bithenge_node_t *in, 61 } 62 63 static int uint32le_apply(bithenge_transform_t *self, bithenge_node_t *in, 65 64 bithenge_node_t **out) 66 65 { … … 82 81 } 83 82 84 static int uint32be_apply(bithenge_transform_t * xform, bithenge_node_t *in,83 static int uint32be_apply(bithenge_transform_t *self, bithenge_node_t *in, 85 84 bithenge_node_t **out) 86 85 { … … 102 101 } 103 102 104 static int prefix_length_4(bithenge_transform_t * xform, bithenge_blob_t *blob,103 static int prefix_length_4(bithenge_transform_t *self, bithenge_blob_t *blob, 105 104 aoff64_t *out) 106 105 { … … 266 265 } 267 266 268 static intstruct_node_destroy(bithenge_node_t *base)267 static void struct_node_destroy(bithenge_node_t *base) 269 268 { 270 269 struct_node_t *node = node_as_struct(base); … … 272 271 bithenge_blob_dec_ref(node->blob); 273 272 free(node); 274 return EOK;275 273 } 276 274 … … 280 278 }; 281 279 282 static int struct_transform_apply(bithenge_transform_t * xform,280 static int struct_transform_apply(bithenge_transform_t *base, 283 281 bithenge_node_t *in, bithenge_node_t **out) 284 282 { 285 struct_transform_t *s truct_transform = transform_as_struct(xform);283 struct_transform_t *self = transform_as_struct(base); 286 284 if (bithenge_node_type(in) != BITHENGE_NODE_BLOB) 287 285 return EINVAL; … … 295 293 return rc; 296 294 } 297 bithenge_transform_inc_ref( xform);298 node->transform = s truct_transform;295 bithenge_transform_inc_ref(base); 296 node->transform = self; 299 297 bithenge_node_inc_ref(in); 300 298 node->blob = bithenge_node_as_blob(in); … … 303 301 } 304 302 305 static int struct_transform_prefix_length(bithenge_transform_t * xform,303 static int struct_transform_prefix_length(bithenge_transform_t *base, 306 304 bithenge_blob_t *blob, aoff64_t *out) 307 305 { 308 struct_transform_t *s truct_transform = transform_as_struct(xform);306 struct_transform_t *self = transform_as_struct(base); 309 307 int rc = EOK; 310 308 bithenge_node_t *node; … … 316 314 blob = bithenge_node_as_blob(node); 317 315 *out = 0; 318 for (size_t i = 0; s truct_transform->subtransforms[i].transform; i++) {316 for (size_t i = 0; self->subtransforms[i].transform; i++) { 319 317 bithenge_transform_t *subxform = 320 s truct_transform->subtransforms[i].transform;318 self->subtransforms[i].transform; 321 319 aoff64_t sub_size; 322 320 rc = bithenge_transform_prefix_length(subxform, blob, &sub_size); … … 344 342 } 345 343 346 static int struct_transform_destroy(bithenge_transform_t *xform) 347 { 348 struct_transform_t *struct_transform = transform_as_struct(xform); 349 free_subtransforms(struct_transform->subtransforms); 350 free(struct_transform); 351 return EOK; 344 static void struct_transform_destroy(bithenge_transform_t *base) 345 { 346 struct_transform_t *self = transform_as_struct(base); 347 free_subtransforms(self->subtransforms); 348 free(self); 352 349 } 353 350 … … 370 367 { 371 368 int rc; 372 struct_transform_t *s truct_transform=373 malloc(sizeof(*s truct_transform));374 if (!s truct_transform) {369 struct_transform_t *self = 370 malloc(sizeof(*self)); 371 if (!self) { 375 372 rc = ENOMEM; 376 373 goto error; 377 374 } 378 rc = bithenge_ new_transform(struct_as_transform(struct_transform),375 rc = bithenge_init_transform(struct_as_transform(self), 379 376 &struct_transform_ops); 380 377 if (rc != EOK) 381 378 goto error; 382 s truct_transform->subtransforms = subtransforms;383 *out = struct_as_transform(s truct_transform);379 self->subtransforms = subtransforms; 380 *out = struct_as_transform(self); 384 381 return EOK; 385 382 error: 386 383 free_subtransforms(subtransforms); 387 free(s truct_transform);384 free(self); 388 385 return rc; 389 386 }
Note:
See TracChangeset
for help on using the changeset viewer.