Changeset c54f5d0 in mainline for uspace/app/bithenge/compound.c


Ignore:
Timestamp:
2012-08-09T05:23:54Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
71450c8
Parents:
3c70376
Message:

Bithenge: partial transforms

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bithenge/compound.c

    r3c70376 rc54f5d0  
    260260}
    261261
     262
     263
     264/***************** partial_transform                         *****************/
     265
     266typedef struct {
     267        bithenge_transform_t base;
     268        bithenge_transform_t *xform;
     269} partial_transform_t;
     270
     271static inline bithenge_transform_t *partial_as_transform(
     272    partial_transform_t *self)
     273{
     274        return &self->base;
     275}
     276
     277static inline partial_transform_t *transform_as_partial(
     278    bithenge_transform_t *base)
     279{
     280        return (partial_transform_t *)base;
     281}
     282
     283static int partial_transform_apply(bithenge_transform_t *base,
     284    bithenge_scope_t *scope, bithenge_node_t *in, bithenge_node_t **out)
     285{
     286        partial_transform_t *self = transform_as_partial(base);
     287        if (bithenge_node_type(in) != BITHENGE_NODE_BLOB)
     288                return EINVAL;
     289        uint64_t size;
     290        return bithenge_transform_prefix_apply(self->xform, scope,
     291            bithenge_node_as_blob(in), out, &size);
     292}
     293
     294static void partial_transform_destroy(bithenge_transform_t *base)
     295{
     296        partial_transform_t *self = transform_as_partial(base);
     297        bithenge_transform_dec_ref(self->xform);
     298        free(self);
     299}
     300
     301static const bithenge_transform_ops_t partial_transform_ops = {
     302        .apply = partial_transform_apply,
     303        .destroy = partial_transform_destroy,
     304};
     305
     306/** Create a transform that doesn't require its subtransform to use the whole
     307 * input. Takes a reference to @a xform.
     308 * @param[out] out Holds the new transform.
     309 * @param xform The subtransform to apply.
     310 * @return EOK on success or an error code from errno.h. */
     311int bithenge_partial_transform(bithenge_transform_t **out,
     312    bithenge_transform_t *xform)
     313{
     314        int rc;
     315        partial_transform_t *self = malloc(sizeof(*self));
     316        if (!self) {
     317                rc = ENOMEM;
     318                goto error;
     319        }
     320
     321        rc = bithenge_init_transform(partial_as_transform(self),
     322            &partial_transform_ops, 0);
     323        if (rc != EOK)
     324                goto error;
     325
     326        self->xform = xform;
     327        *out = partial_as_transform(self);
     328        return EOK;
     329
     330error:
     331        free(self);
     332        bithenge_transform_dec_ref(xform);
     333        return rc;
     334}
     335
    262336/** @}
    263337 */
Note: See TracChangeset for help on using the changeset viewer.