terom@30: #ifndef CACHE_ENGINE_H terom@30: #define CACHE_ENGINE_H terom@30: terom@30: struct cache_engine { terom@30: /* terom@30: * Allocate a `struct cache`-compatible struct and return it via cache_ptr. terom@30: */ terom@31: int (*fn_init) (struct cache_engine *, struct cache **); terom@30: terom@30: /* terom@30: * Allocate a `struct cache_op`-compatible struct and return it via cache_ptr. terom@30: * terom@30: * Begin the index lookup. terom@30: */ terom@31: int (*fn_op_start) (struct cache *, struct cache_op **, struct cache_key *); terom@33: terom@33: /* terom@33: * Return some information about the available data. terom@33: */ terom@36: int (*fn_op_available) (struct cache_op *, size_t *size, size_t *offset); terom@36: terom@36: /* terom@36: * Prepare to read from this cache entry. terom@36: */ terom@36: int (*fn_op_begin_read) (struct cache_op *); terom@31: terom@31: /* terom@36: * Prepare to write to this cache entry. terom@31: * terom@31: * size_hint, if nonzero, provides a guess at the size of the cache entry that can be used to optimize stuff terom@31: */ terom@31: int (*fn_op_begin_write) (struct cache_op *, size_t size_hint); terom@33: terom@33: /* terom@33: * Read some data from the given fd into this cache entry. Size may contain a non-zero value to hint at how many terom@33: * bytes should be read, or zero to just read a suitable amount. Should be updated to how many bytes were actually terom@33: * written (may be zero if writes are currently paused). terom@33: */ terom@36: int (*fn_op_push) (struct cache_op *, int fd, size_t *size); terom@37: terom@37: /* terom@37: * Write some data into the given fd from this cache entry. Size either specifies how many bytes to read (and terom@37: * should not be more than is available), or zero to read as much as possible. Offset is the offset from the terom@37: * beginning of the cache entry, and should be updated to what the next unread byte would be. Size should be terom@37: * updated to how many bytes was read. terom@37: */ terom@37: int (*fn_op_pull) (struct cache_op *, int fd, size_t *offset, size_t *size); terom@31: terom@33: /* terom@33: * No more calls to fn_op_push will take place. The cache entry now contains the complete data. terom@33: */ terom@36: int (*fn_op_done) (struct cache_op *); terom@33: terom@33: /* terom@33: * The op is not needed for any operations anymore. Free any resources and memory associated with this op, terom@33: * including the op itself. terom@33: */ terom@36: int (*fn_op_close) (struct cache_op *); terom@30: }; terom@30: terom@30: #endif /* CACHE_ENGINE_H */ terom@30: