cache.h
author Tero Marttila <terom@fixme.fi>
Sat, 30 Aug 2008 19:13:15 +0300
changeset 49 10c7dce1a043
parent 36 b4023990811e
permissions -rw-r--r--
autogenerate the memcache_test help output, and pipeline memcache requests
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_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_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
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     4
#include <sys/types.h>
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     5
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
     6
/*
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
 * The interface to the internal caching mechanism.
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
     8
 *
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
 * This presents a pretty generic API, which allows the actual implementation to change, or to compare multiple
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
 * different implementations.
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
 *
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
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
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
    15
/*
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
    16
 * The handle used to access the global cache.
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
    17
 */
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
    18
struct cache;
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
    19
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
    20
/*
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
    21
 * A cache request/operation.
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
    22
 */
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
    23
struct cache_req;
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
    24
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
    25
/*
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
    26
 * The actual implementation of the cache.
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
    27
 */
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
    28
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
    29
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
    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
    31
 * What we use as keys in the cache. Key is a pointer to an arbitrary char buffer, length is the size of the key
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
    32
 * in bytes. If this is given as zero, it will be calcuated using strlen(). Zero-length keys are invalid.
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
    33
 */
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    34
struct cache_key {
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    35
    char *buf;
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
    36
    size_t length;
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
    37
};
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
    38
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
    39
/*
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
    40
 * The various states that a cache request can be in
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
    41
 */
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
    42
enum cache_req_state {
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
    43
    CACHE_STATE_INVALID,
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
    44
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
    45
    CACHE_STATE_LOOKUP,
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    46
    CACHE_STATE_HIT,
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    47
    CACHE_STATE_MISS,
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    48
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    49
    CACHE_STATE_OPEN_READ,
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    50
    CACHE_STATE_READ,
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    51
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    52
    CACHE_STATE_OPEN_WRITE,
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
    53
    CACHE_STATE_WRITE,
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
    54
    CACHE_STATE_WRITE_PAUSE,
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
    55
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
    56
    CACHE_STATE_ERROR,
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
    57
};
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
    58
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
/*
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    60
/ *
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
    61
 * Transitions between states
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    62
 * /
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
    63
enum cache_req_event {
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
    64
    // LOOKUP -> OPEN
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
    65
    CACHE_EVENT_HIT,
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
    66
    CACHE_EVENT_MISS,
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    67
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
    68
    // OPEN -> WRITE
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
    69
    CACHE_EVENT_BEGIN_WRITE,
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
    70
    
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
    71
    // OPEN -> READ
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
    72
    CACHE_EVENT_BEGIN_READ,
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
    73
    
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
    74
    // WRITE -> PAUSE_WRITE
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
    75
    CACHE_EVENT_PAUSE_WRITE,
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
    76
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
    77
    // PAUSE_WRITE -> WRITE
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
    78
    CACHE_EVENT_RESUME_WRITE,
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
    79
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
    80
    // READ -> READ
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
    81
    CACHE_EVENT_DATA_AVAILABLE,
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
    82
    
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
    83
    // READ -> DONE
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
    84
    CACHE_EVENT_DONE,
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
    85
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
    86
    // * -> ERROR
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
    87
    CACHE_EVENT_ERROR,
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
    88
};
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    89
*/
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
    90
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
    91
/*
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
    92
 * The callback used for cache_reqs
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
    93
 */
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    94
//typedef int (*cache_callback) (struct cache_req *, enum cache_req_event, void *arg);
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    95
typedef int (*cache_callback) (struct cache_req *, void *arg);
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
    96
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
    97
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
    98
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
    99
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
   100
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
   101
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
   102
/*
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
   103
 * Open up a cache using the given engine (which can be configured with engine-specific params).
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
   104
 */
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
   105
struct cache *cache_open (struct cache_engine *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
   106
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
   107
/*
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
   108
 * Create a new request. The given callback function will be called at the various stages in the request, and can then
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
   109
 * drive the request forward.
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
   110
 */
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   111
struct cache_req *cache_req (struct cache *cache, const struct cache_key *key, cache_callback cb_func, void *cb_data);
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
   112
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
   113
/*
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
   114
 * Get the request's state.
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
   115
 */ 
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   116
enum cache_req_state cache_req_state (struct cache_req *req);
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   117
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   118
/*
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   119
 * Get the rquest's key
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   120
 */
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   121
const struct cache_key *cache_req_key (struct cache_req *req);
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
   122
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
   123
/*
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
   124
 * Get information about the amount of data in this cache entry.
34
f3ab8656b6a0 update cache.h to reflect changes, empty cache entries are illegal, and unknown-size is returned as 0
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   125
 *      size        - the total size of the cache entry. 0 if unknown
f3ab8656b6a0 update cache.h to reflect changes, empty cache entries are illegal, and unknown-size is returned as 0
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   126
 *      offset      - how many bytes of data the cache entry contains. May be 0
f3ab8656b6a0 update cache.h to reflect changes, empty cache entries are illegal, and unknown-size is returned as 0
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   127
 *      available   - how many unread bytes are available. May be 0
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
   128
 */
34
f3ab8656b6a0 update cache.h to reflect changes, empty cache entries are illegal, and unknown-size is returned as 0
Tero Marttila <terom@fixme.fi>
parents: 31
diff changeset
   129
int cache_req_available (struct cache_req *req, size_t *size, size_t *offset, size_t *available);
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
   130
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
   131
/*
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   132
 * Prepare this cache req for writing in the data. Hint, if nonzero, is used to pre-allocate resources for the entry.
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   133
 */
36
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
   134
int cache_req_begin_write (struct cache_req *req, size_t hint);
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
   135
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
   136
/*
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
   137
 * Prepare this cache req for use with cache_req_pull.
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
   138
 */
b4023990811e rename/clean up states slightly and add lots of documentation
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
   139
int cache_req_begin_read (struct cache_req *req);
31
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   140
12d5361e7472 req/write/push implemented
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   141
/*
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
   142
 * Add some data into this cache entry, reading from the given fd. This is only valid for cache_req's in
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
   143
 * CACHE_REQ_WRITE mode.
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
   144
 *
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
   145
 * If you know the amount of data that should be pushed, you can supply it in size. If size is given as 0, all
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
   146
 * available data will be consumed. Size will be updated to the number of bytes pushed into the cache.
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
   147
 *
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
   148
 * (size == 0) is valid if req is in the WRITE_PAUSE state (either before or after the call).
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
   149
 */
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
   150
int cache_req_push (struct cache_req *req, int fd, size_t *size);
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
   151
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
   152
/*
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
   153
 * Get some data from this cache entry, writing it into the given fd. This is valid for all cache_req's in
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
   154
 * CACHE_REQ_READ and CACHE_REQ_WRITE mode.
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
   155
 *
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
   156
 * If the value of size is given (nonzero), then the given amount of data will be written to the fd from the cache.
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
   157
 * If the cache contains less data than given, this is an error. If the value of size is zero, as much data as possible
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
   158
 * will be written to the fd. Size will be updated to the number of bytes pulled from the cache.
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
   159
 */
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
   160
int cache_req_pull (struct cache_req *req, int fd, size_t *size);
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
   161
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
   162
/*
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
   163
 * Abort the given cache request (external failure). This is only needed for CACHE_REQ_WRITE requests, and is invalid
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
   164
 * for other requests. Any dependant cache requests will fail.
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
   165
 */
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
   166
void cache_req_abort (struct cache_req *req);
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
   167
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
   168
/*
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
   169
 * Indicate that the given cache write request is complete. This is only valid for CACHE_REQ_WRITE requests, and is
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
   170
 * invalid for other requests. Any dependant cache requests will complete.
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
   171
 */
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
   172
int cache_req_done (struct cache_req *req);
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
   173
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
   174
/*
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
   175
 * Release the given cache request. Only valid after calling req_abort/req_done, or getting EVENT_DONE/EVENT_ERROR.
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
   176
 */
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
   177
void cache_req_release (struct cache_req *req);
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
   178
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
   179
#endif /* CACHE_H */