cache/engine.h
author Tero Marttila <terom@fixme.fi>
Thu, 28 Aug 2008 00:29:39 +0300
changeset 43 e5b714190dee
parent 37 f0188b445c84
permissions -rw-r--r--
the request/reply code should be complete now, but still needs testing
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
     1
#ifndef CACHE_ENGINE_H
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
     2
#define CACHE_ENGINE_H
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
     3
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
     4
struct cache_engine {
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
     5
    /*
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
     6
     * Allocate a `struct cache`-compatible struct and return it via cache_ptr.
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
     7
     */
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     8
    int (*fn_init) (struct cache_engine *, struct cache **);
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
     9
    
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    10
    /*
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    11
     * Allocate a `struct cache_op`-compatible struct and return it via cache_ptr.
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    12
     *
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    13
     * Begin the index lookup.
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    14
     */
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    15
    int (*fn_op_start) (struct cache *, struct cache_op **, struct cache_key *);
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    16
    
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    17
    /*
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    18
     * Return some information about the available data.
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    19
     */
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
    20
    int (*fn_op_available) (struct cache_op *, size_t *size, size_t *offset);
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
    21
    
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
    22
    /*
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
    23
     * Prepare to read from this cache entry.
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
    24
     */
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
    25
    int (*fn_op_begin_read) (struct cache_op *);
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    26
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    27
    /*
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
    28
     * Prepare to write to this cache entry.
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    29
     *
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    30
     * size_hint, if nonzero, provides a guess at the size of the cache entry that can be used to optimize stuff
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    31
     */
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    32
    int (*fn_op_begin_write) (struct cache_op *, size_t size_hint);
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    33
    
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    34
    /*
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    35
     * Read some data from the given fd into this cache entry. Size may contain a non-zero value to hint at how many
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    36
     * bytes should be read, or zero to just read a suitable amount. Should be updated to how many bytes were actually
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    37
     * written (may be zero if writes are currently paused).
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    38
     */
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
    39
    int (*fn_op_push) (struct cache_op *, int fd, size_t *size);
37
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    40
    
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    41
    /*
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    42
     * Write some data into the given fd from this cache entry. Size either specifies how many bytes to read (and
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    43
     * should not be more than is available), or zero to read as much as possible. Offset is the offset from the
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    44
     * beginning of the cache entry, and should be updated to what the next unread byte would be. Size should be
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    45
     * updated to how many bytes was read.
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    46
     */
f0188b445c84 read/pull support
Tero Marttila <terom@fixme.fi>
parents: 36
diff changeset
    47
    int (*fn_op_pull) (struct cache_op *, int fd, size_t *offset, size_t *size);
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    48
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    49
    /*
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    50
     * No more calls to fn_op_push will take place. The cache entry now contains the complete data.
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    51
     */
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
    52
    int (*fn_op_done) (struct cache_op *);
33
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    53
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    54
    /*
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    55
     * The op is not needed for any operations anymore. Free any resources and memory associated with this op,
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    56
     * including the op itself.
b750e8865127 working write cycle support
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
    57
     */
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 33
diff changeset
    58
    int (*fn_op_close) (struct cache_op *);
30
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    59
};
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    60
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    61
#endif /* CACHE_ENGINE_H */
33e464fd6773 my hg working dir managed to break itself somehow... my attempt to fix that, and add some cache code :)
terom@cl-543.hel-01.fi.sixxs.net
parents:
diff changeset
    62