Changeset 978ccaf1 in mainline for uspace/app/bithenge/blob.h


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/blob.h

    r04a7435f r978ccaf1  
    5252typedef struct bithenge_random_access_blob_ops_t {
    5353        /** @copydoc bithenge_blob_t::bithenge_blob_size */
    54         int (*size)(bithenge_blob_t *blob, aoff64_t *size);
     54        int (*size)(bithenge_blob_t *self, aoff64_t *size);
    5555        /** @copydoc bithenge_blob_t::bithenge_blob_read */
    56         int (*read)(bithenge_blob_t *blob, aoff64_t offset, char *buffer,
     56        int (*read)(bithenge_blob_t *self, aoff64_t offset, char *buffer,
    5757            aoff64_t *size);
    5858        /** Destroy the blob.
    59          * @param blob The blob.
    60          * @return EOK on success or an error code from errno.h. */
    61         int (*destroy)(bithenge_blob_t *blob);
     59         * @param blob The blob. */
     60        void (*destroy)(bithenge_blob_t *self);
    6261} bithenge_random_access_blob_ops_t;
    6362
     
    8786         *
    8887         * @memberof bithenge_blob_t
    89          * @param blob The blob.
     88         * @param self The blob.
    9089         * @param[out] size Total size of the blob.
    9190         * @return EOK on success or an error code from errno.h.
    9291         */
    93         int (*size)(bithenge_sequential_blob_t *blob, aoff64_t *size);
     92        int (*size)(bithenge_sequential_blob_t *self, aoff64_t *size);
    9493
    9594        /** Read the next part of the blob. If the requested data extends
     
    9796         * will be read.
    9897         *
    99          * @param blob The blob.
     98         * @param self The blob.
    10099         * @param[out] buffer Buffer to read into. If an error occurs, the contents are
    101100         * undefined.
     
    105104         * @return EOK on success or an error code from errno.h.
    106105         */
    107         int (*read)(bithenge_sequential_blob_t *blob, char *buffer,
     106        int (*read)(bithenge_sequential_blob_t *self, char *buffer,
    108107            aoff64_t *size);
    109108
    110109        /** Destroy the blob.
    111          * @param blob The blob.
    112          * @return EOK on success or an error code from errno.h. */
    113         int (*destroy)(bithenge_sequential_blob_t *blob);
     110         * @param self The blob. */
     111        void (*destroy)(bithenge_sequential_blob_t *self);
    114112} bithenge_sequential_blob_ops_t;
    115113
     
    117115 *
    118116 * @memberof bithenge_blob_t
    119  * @param blob The blob.
     117 * @param self The blob.
    120118 * @param[out] size Total size of the blob.
    121119 * @return EOK on success or an error code from errno.h.
    122120 */
    123 static inline int bithenge_blob_size(bithenge_blob_t *blob, aoff64_t *size)
    124 {
    125         assert(blob);
    126         assert(blob->base.blob_ops);
    127         return blob->base.blob_ops->size(blob, size);
     121static inline int bithenge_blob_size(bithenge_blob_t *self, aoff64_t *size)
     122{
     123        assert(self);
     124        assert(self->base.blob_ops);
     125        return self->base.blob_ops->size(self, size);
    128126}
    129127
     
    134132 *
    135133 * @memberof bithenge_blob_t
    136  * @param blob The blob.
     134 * @param self The blob.
    137135 * @param offset Byte offset within the blob.
    138136 * @param[out] buffer Buffer to read into. If an error occurs, the contents are
     
    143141 * @return EOK on success or an error code from errno.h.
    144142 */
    145 static inline int bithenge_blob_read(bithenge_blob_t *blob, aoff64_t offset,
     143static inline int bithenge_blob_read(bithenge_blob_t *self, aoff64_t offset,
    146144    char *buffer, aoff64_t *size)
    147145{
    148         assert(blob);
    149         assert(blob->base.blob_ops);
    150         return blob->base.blob_ops->read(blob, offset, buffer, size);
     146        assert(self);
     147        assert(self->base.blob_ops);
     148        return self->base.blob_ops->read(self, offset, buffer, size);
    151149}
    152150
     
    170168}
    171169
    172 static inline int bithenge_blob_inc_ref(bithenge_blob_t *blob)
    173 {
    174         return bithenge_node_inc_ref(bithenge_blob_as_node(blob));
    175 }
    176 
    177 static inline int bithenge_blob_dec_ref(bithenge_blob_t *blob)
    178 {
    179         if (!blob)
    180                 return EOK;
    181         return bithenge_node_dec_ref(bithenge_blob_as_node(blob));
    182 }
    183 
    184 int bithenge_new_random_access_blob(bithenge_blob_t *blob,
    185     const bithenge_random_access_blob_ops_t *ops);
    186 
    187 int bithenge_new_sequential_blob(bithenge_sequential_blob_t *blob,
    188     const bithenge_sequential_blob_ops_t *ops);
    189 
    190 int bithenge_new_blob_from_data(bithenge_node_t **out, const void *data,
    191     size_t len);
    192 
    193 int bithenge_new_blob_from_buffer(bithenge_node_t **out, const void *buffer,
    194     size_t len, bool needs_free);
    195 
    196 int bithenge_new_offset_blob(bithenge_node_t **out, bithenge_blob_t *blob,
    197     aoff64_t offset);
    198 
    199 int bithenge_new_subblob(bithenge_node_t **out, bithenge_blob_t *blob,
    200     aoff64_t offset, aoff64_t size);
    201 
    202 bool bithenge_blob_equal(bithenge_blob_t *a, bithenge_blob_t *b);
     170/** Increment a blob's reference count.
     171 * @param blob The blob to reference. */
     172static inline void bithenge_blob_inc_ref(bithenge_blob_t *blob)
     173{
     174        bithenge_node_inc_ref(bithenge_blob_as_node(blob));
     175}
     176
     177/** Decrement a blob's reference count.
     178 * @param blob The blob to dereference, or NULL. */
     179static inline void bithenge_blob_dec_ref(bithenge_blob_t *blob)
     180{
     181        if (blob)
     182                bithenge_node_dec_ref(bithenge_blob_as_node(blob));
     183}
     184
     185int bithenge_init_random_access_blob(bithenge_blob_t *,
     186    const bithenge_random_access_blob_ops_t *);
     187int bithenge_init_sequential_blob(bithenge_sequential_blob_t *,
     188    const bithenge_sequential_blob_ops_t *);
     189int bithenge_new_blob_from_data(bithenge_node_t **, const void *, size_t);
     190int bithenge_new_blob_from_buffer(bithenge_node_t **, const void *, size_t,
     191    bool);
     192int bithenge_new_offset_blob(bithenge_node_t **, bithenge_blob_t *, aoff64_t);
     193int bithenge_new_subblob(bithenge_node_t **, bithenge_blob_t *, aoff64_t,
     194    aoff64_t);
     195bool bithenge_blob_equal(bithenge_blob_t *, bithenge_blob_t *);
    203196
    204197#endif
Note: See TracChangeset for help on using the changeset viewer.