Changeset 978ccaf1 in mainline for uspace/app/bithenge/transform.c


Ignore:
Timestamp:
2012-06-27T03:35:43Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
600f5d1
Parents:
04a7435f
Message:

Bithenge: various cleanup and tweaks

File:
1 edited

Legend:

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

    r04a7435f r978ccaf1  
    4242
    4343/** Initialize a new transform.
    44  * @param[out] xform Transform to initialize.
     44 * @param[out] self Transform to initialize.
    4545 * @param[in] ops Operations provided by the transform.
    4646 * @return EOK or an error code from errno.h. */
    47 int bithenge_new_transform(bithenge_transform_t *xform,
     47int bithenge_init_transform(bithenge_transform_t *self,
    4848    const bithenge_transform_ops_t *ops)
    4949{
     
    5151        assert(ops->apply);
    5252        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
     58static void transform_indestructible(bithenge_transform_t *self)
    5959{
    6060        assert(false);
    61         return EOK;
    62 }
    63 
    64 static int uint32le_apply(bithenge_transform_t *xform, bithenge_node_t *in,
     61}
     62
     63static int uint32le_apply(bithenge_transform_t *self, bithenge_node_t *in,
    6564    bithenge_node_t **out)
    6665{
     
    8281}
    8382
    84 static int uint32be_apply(bithenge_transform_t *xform, bithenge_node_t *in,
     83static int uint32be_apply(bithenge_transform_t *self, bithenge_node_t *in,
    8584    bithenge_node_t **out)
    8685{
     
    102101}
    103102
    104 static int prefix_length_4(bithenge_transform_t *xform, bithenge_blob_t *blob,
     103static int prefix_length_4(bithenge_transform_t *self, bithenge_blob_t *blob,
    105104    aoff64_t *out)
    106105{
     
    266265}
    267266
    268 static int struct_node_destroy(bithenge_node_t *base)
     267static void struct_node_destroy(bithenge_node_t *base)
    269268{
    270269        struct_node_t *node = node_as_struct(base);
     
    272271        bithenge_blob_dec_ref(node->blob);
    273272        free(node);
    274         return EOK;
    275273}
    276274
     
    280278};
    281279
    282 static int struct_transform_apply(bithenge_transform_t *xform,
     280static int struct_transform_apply(bithenge_transform_t *base,
    283281    bithenge_node_t *in, bithenge_node_t **out)
    284282{
    285         struct_transform_t *struct_transform = transform_as_struct(xform);
     283        struct_transform_t *self = transform_as_struct(base);
    286284        if (bithenge_node_type(in) != BITHENGE_NODE_BLOB)
    287285                return EINVAL;
     
    295293                return rc;
    296294        }
    297         bithenge_transform_inc_ref(xform);
    298         node->transform = struct_transform;
     295        bithenge_transform_inc_ref(base);
     296        node->transform = self;
    299297        bithenge_node_inc_ref(in);
    300298        node->blob = bithenge_node_as_blob(in);
     
    303301}
    304302
    305 static int struct_transform_prefix_length(bithenge_transform_t *xform,
     303static int struct_transform_prefix_length(bithenge_transform_t *base,
    306304    bithenge_blob_t *blob, aoff64_t *out)
    307305{
    308         struct_transform_t *struct_transform = transform_as_struct(xform);
     306        struct_transform_t *self = transform_as_struct(base);
    309307        int rc = EOK;
    310308        bithenge_node_t *node;
     
    316314        blob = bithenge_node_as_blob(node);
    317315        *out = 0;
    318         for (size_t i = 0; struct_transform->subtransforms[i].transform; i++) {
     316        for (size_t i = 0; self->subtransforms[i].transform; i++) {
    319317                bithenge_transform_t *subxform =
    320                     struct_transform->subtransforms[i].transform;
     318                    self->subtransforms[i].transform;
    321319                aoff64_t sub_size;
    322320                rc = bithenge_transform_prefix_length(subxform, blob, &sub_size);
     
    344342}
    345343
    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;
     344static 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);
    352349}
    353350
     
    370367{
    371368        int rc;
    372         struct_transform_t *struct_transform =
    373             malloc(sizeof(*struct_transform));
    374         if (!struct_transform) {
     369        struct_transform_t *self =
     370            malloc(sizeof(*self));
     371        if (!self) {
    375372                rc = ENOMEM;
    376373                goto error;
    377374        }
    378         rc = bithenge_new_transform(struct_as_transform(struct_transform),
     375        rc = bithenge_init_transform(struct_as_transform(self),
    379376            &struct_transform_ops);
    380377        if (rc != EOK)
    381378                goto error;
    382         struct_transform->subtransforms = subtransforms;
    383         *out = struct_as_transform(struct_transform);
     379        self->subtransforms = subtransforms;
     380        *out = struct_as_transform(self);
    384381        return EOK;
    385382error:
    386383        free_subtransforms(subtransforms);
    387         free(struct_transform);
     384        free(self);
    388385        return rc;
    389386}
Note: See TracChangeset for help on using the changeset viewer.