lv2_pfile => rdff.
[ardour.git] / libs / ardour / rdff.h
1 /*
2   RDFF - RDF in RIFF
3   Copyright 2011 David Robillard <http://drobilla.net>
4  
5   This is free software; you can redistribute it and/or modify it
6   under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 2 of the License, or
8   (at your option) any later version.
9  
10   This software is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13   General Public License for more details.
14  
15   You should have received a copy of the GNU General Public License
16   along with this sofware; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18   02110-1301 USA.
19 */
20
21 #ifndef RDFF_RDFF_H
22 #define RDFF_RDFF_H
23
24 #include <stdbool.h>
25 #include <stdint.h>
26
27 #ifdef __GNUC__
28 #    define PACKED __attribute__((__packed__))
29 #else
30 #    define PACKED
31 #endif
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 typedef struct _RDFF* RDFF;
38
39 typedef enum {
40         RDFF_STATUS_OK            = 0,
41         RDFF_STATUS_UNKNOWN_ERROR = 1,
42         RDFF_STATUS_EOF           = 2,
43         RDFF_STATUS_CORRUPT       = 3
44 } RDFFStatus;
45
46 /**
47    Generic RIFF chunk header.
48 */
49 typedef struct {
50         char     type[4];
51         uint32_t size;
52         char     data[];
53 } PACKED RDFFChunk;
54
55 /**
56    Body of a URID chunk.
57 */
58 typedef struct {
59         uint32_t id;
60         char     uri[];
61 } PACKED RDFFURIChunk;
62
63 /**
64    Body of a KVAL chunk.
65 */
66 typedef struct {
67         uint32_t key;
68         uint32_t type;
69         uint32_t size;
70         char     value[];
71 } PACKED RDFFValueChunk;
72                 
73 /**
74    Open/Create a new RDFF file.
75 */
76 RDFF
77 rdff_open(const char* path, bool write);
78
79 /**
80    Write a URI ID to @a file.
81 */
82 RDFFStatus
83 rdff_write_uri(RDFF        file,
84                uint32_t    id,
85                const char* uri,
86                uint32_t    len);
87
88 /**
89    Write a key/value record to @a file.
90 */
91 RDFFStatus
92 rdff_write_value(RDFF        file,
93                  uint32_t    key,
94                  const void* value,
95                  uint32_t    size,
96                  uint32_t    type);
97
98 /**
99    Read a chunk from @a file.
100
101    @param buf MUST point to an RDFFChunk dynamically allocated with malloc.
102    The @a size field (i.e. (*buf)->size) MUST be set to the amount of available
103    memory in the chunk (not including the header). If this is insufficient,
104    *buf will be resized using realloc.
105 */
106 RDFFStatus
107 rdff_read_chunk(RDFF        file,
108                 RDFFChunk** buf);
109
110 /**
111    Close @a file.
112    After this call, @a file is invalid.
113 */
114 void
115 rdff_close(RDFF file);
116
117 #ifdef __cplusplus
118 } /* extern "C" */
119 #endif
120
121 #endif /* RDFF_RDFF_H */