Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


e06535dbc2d26823cfb6de41606ad7a3eb36dace
[palacios.git] / palacios / include / interfaces / vmm_keyed_stream.h
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2011, Peter Dinda <pdinda@northwestern.edu> 
11  * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Peter Dinda <pdinda@northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #ifndef __VMM_KEYED_STREAM_H__
22 #define __VMM_KEYED_STREAM_H__
23
24 #include <palacios/vmm.h>
25
26
27 /*
28   A keyed stream essentially supports this:
29
30   URL => {collection of key->stream pairs}
31
32   If you open a key for reading, you get the read pointer set to its beginning.   
33   You can then make repeated reads to advance the read pointer.  You cannot seek.
34
35   Writing works similarly.
36
37   You cannot both read and write. 
38
39 */
40
41 /* A keyed stream and its components are opaque to palacios */
42 typedef void * v3_keyed_stream_t;
43 typedef void * v3_keyed_stream_key_t;
44
45 typedef enum {V3_KS_RD_ONLY,V3_KS_WR_ONLY,V3_KS_WR_ONLY_CREATE} v3_keyed_stream_open_t;
46
47 #ifdef __V3VEE__
48
49
50 v3_keyed_stream_t     v3_keyed_stream_open(char *url, v3_keyed_stream_open_t open_type);
51 void                  v3_keyed_stream_close(v3_keyed_stream_t stream);
52 v3_keyed_stream_key_t v3_keyed_stream_open_key(v3_keyed_stream_t stream, char *key);
53 void                  v3_keyed_stream_close_key(v3_keyed_stream_t stream,  char *key);
54 sint64_t              v3_keyed_stream_write_key(v3_keyed_stream_t stream,  
55                                                 v3_keyed_stream_key_t key,
56                                                 void *buf, 
57                                                 sint64_t len);
58 sint64_t              v3_keyed_stream_read_key(v3_keyed_stream_t stream,
59                                                v3_keyed_stream_key_t key,
60                                                void *buf, 
61                                                sint64_t len);
62
63 #define STD_SAVE(stream,ks,x)                   \
64     do { \
65         if (sizeof((x)) != v3_keyed_stream_write_key((stream), (ks), &(x), sizeof((x)))) { \
66             v3_keyed_stream_close_key((stream),(ks)); \
67             return -1;                                \
68         } \
69     } while (0)
70
71 #define STD_LOAD(stream,ks,x)                   \
72     do {                                                                \
73         if (sizeof((x)) != v3_keyed_stream_read_key((stream), (ks), &(x), sizeof((x)))) { \
74             v3_keyed_stream_close_key((stream),(ks)); \
75             return -1;                                 \
76         } \
77     } while (0)
78 #endif
79
80
81 struct v3_keyed_stream_hooks {
82     // url is meaningful only to the host implementation
83     v3_keyed_stream_t (*open)(char *url,
84                               v3_keyed_stream_open_t open_type);
85                               
86     void (*close)(v3_keyed_stream_t stream);
87
88     v3_keyed_stream_key_t (*open_key)(v3_keyed_stream_t stream,
89                                       char *key);
90
91     void (*close_key)(v3_keyed_stream_t stream, 
92                       v3_keyed_stream_key_t key);
93     
94
95     sint64_t (*write_key)(v3_keyed_stream_t stream,
96                           v3_keyed_stream_key_t key,
97                           void *buf, 
98                           sint64_t len);
99
100     sint64_t (*read_key)(v3_keyed_stream_t stream,
101                          v3_keyed_stream_key_t key,
102                          void *buf, 
103                          sint64_t len);
104     
105 };
106
107
108 extern void V3_Init_Keyed_Streams(struct v3_keyed_stream_hooks *hooks);
109
110 #endif