Add subject to key/value chunks in RDFF (i.e. store triples).
git-svn-id: svn://localhost/ardour2/branches/3.0@9224 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
b502bbc618
commit
02d551d183
@ -367,10 +367,8 @@ LV2Plugin::lv2_persist_store_callback(void* callback_data,
|
|||||||
uint32_t type,
|
uint32_t type,
|
||||||
bool pod)
|
bool pod)
|
||||||
{
|
{
|
||||||
cout << "LV2 PERSIST STORE " << key
|
DEBUG_TRACE(DEBUG::LV2, string_compose("persist store %1\n",
|
||||||
<< " = " << value
|
_uri_map.id_to_uri(NULL, key)));
|
||||||
<< " :: " << type
|
|
||||||
<< " POD: " << pod << endl;
|
|
||||||
|
|
||||||
PersistState* state = (PersistState*)callback_data;
|
PersistState* state = (PersistState*)callback_data;
|
||||||
state->add_uri(key, _uri_map.id_to_uri(NULL, key));
|
state->add_uri(key, _uri_map.id_to_uri(NULL, key));
|
||||||
@ -385,7 +383,8 @@ LV2Plugin::lv2_persist_retrieve_callback(void* callback_data,
|
|||||||
uint32_t* type,
|
uint32_t* type,
|
||||||
bool* pod)
|
bool* pod)
|
||||||
{
|
{
|
||||||
cout << "LV2 PERSIST RETRIEVE " << _uri_map.id_to_uri(NULL, key) << endl;
|
DEBUG_TRACE(DEBUG::LV2, string_compose("persist retrieve %1\n",
|
||||||
|
_uri_map.id_to_uri(NULL, key)));
|
||||||
|
|
||||||
PersistState* state = (PersistState*)callback_data;
|
PersistState* state = (PersistState*)callback_data;
|
||||||
PersistState::Values::const_iterator i = state->values.find(key);
|
PersistState::Values::const_iterator i = state->values.find(key);
|
||||||
@ -447,8 +446,10 @@ LV2Plugin::add_state(XMLNode* root) const
|
|||||||
// Write all referenced URIs to state file
|
// Write all referenced URIs to state file
|
||||||
for (PersistState::URIs::const_iterator i = state.uris.begin();
|
for (PersistState::URIs::const_iterator i = state.uris.begin();
|
||||||
i != state.uris.end(); ++i) {
|
i != state.uris.end(); ++i) {
|
||||||
rdff_write_uri(file, i->first,
|
rdff_write_uri(file,
|
||||||
i->second.c_str(), i->second.length() + 1);
|
i->first,
|
||||||
|
i->second.length(),
|
||||||
|
i->second.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write all values to state file
|
// Write all values to state file
|
||||||
@ -456,11 +457,12 @@ LV2Plugin::add_state(XMLNode* root) const
|
|||||||
i != state.values.end(); ++i) {
|
i != state.values.end(); ++i) {
|
||||||
const uint32_t key = i->first;
|
const uint32_t key = i->first;
|
||||||
const PersistValue& val = i->second;
|
const PersistValue& val = i->second;
|
||||||
rdff_write_value(file,
|
rdff_write_triple(file,
|
||||||
key,
|
0,
|
||||||
val.value,
|
key,
|
||||||
val.size,
|
val.type,
|
||||||
val.type);
|
val.size,
|
||||||
|
val.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close state file
|
// Close state file
|
||||||
@ -644,13 +646,14 @@ LV2Plugin::set_state(const XMLNode& node, int version)
|
|||||||
printf("READ URI %u: %s\n", body->id, body->uri);
|
printf("READ URI %u: %s\n", body->id, body->uri);
|
||||||
state.add_uri(body->id, body->uri);
|
state.add_uri(body->id, body->uri);
|
||||||
} else if (!strncmp(chunk->type, "KVAL", 4)) {
|
} else if (!strncmp(chunk->type, "KVAL", 4)) {
|
||||||
RDFFValueChunk* body = (RDFFValueChunk*)chunk->data;
|
RDFFTripleChunk* body = (RDFFTripleChunk*)chunk->data;
|
||||||
printf("READ VAL %u = %s (size: %u type: %u)\n",
|
printf("READ VAL %u = %s (size: %u type: %u)\n",
|
||||||
body->key, body->value, body->size, body->type);
|
body->predicate, body->object,
|
||||||
state.add_value(body->key,
|
body->object_size, body->object_type);
|
||||||
body->value,
|
state.add_value(body->predicate,
|
||||||
body->size,
|
body->object,
|
||||||
body->type,
|
body->object_size,
|
||||||
|
body->object_type,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,8 @@
|
|||||||
#define CHUNK_ID_LEN 4
|
#define CHUNK_ID_LEN 4
|
||||||
|
|
||||||
static const char FILE_TYPE[CHUNK_ID_LEN] = "RDFF"; /* RDFF File ID */
|
static const char FILE_TYPE[CHUNK_ID_LEN] = "RDFF"; /* RDFF File ID */
|
||||||
static const char CHUNK_KVAL[CHUNK_ID_LEN] = "KVAL"; /* Key/Value Chunk ID */
|
static const char CHUNK_TRIP[CHUNK_ID_LEN] = "trip"; /* Triple Chunk ID */
|
||||||
static const char CHUNK_URID[CHUNK_ID_LEN] = "URID"; /* URI-ID Chunk ID*/
|
static const char CHUNK_URID[CHUNK_ID_LEN] = "urid"; /* URI-ID Chunk ID*/
|
||||||
|
|
||||||
struct _RDFF {
|
struct _RDFF {
|
||||||
FILE* fd;
|
FILE* fd;
|
||||||
@ -98,8 +98,8 @@ rdff_open(const char* path, bool write)
|
|||||||
RDFFStatus
|
RDFFStatus
|
||||||
rdff_write_uri(RDFF file,
|
rdff_write_uri(RDFF file,
|
||||||
uint32_t id,
|
uint32_t id,
|
||||||
const char* uri,
|
uint32_t len,
|
||||||
uint32_t len)
|
const char* uri)
|
||||||
{
|
{
|
||||||
const uint32_t chunk_size = sizeof(id) + len + 1;
|
const uint32_t chunk_size = sizeof(id) + len + 1;
|
||||||
WRITE(CHUNK_URID, CHUNK_ID_LEN, 1, file->fd);
|
WRITE(CHUNK_URID, CHUNK_ID_LEN, 1, file->fd);
|
||||||
@ -114,20 +114,22 @@ rdff_write_uri(RDFF file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
RDFFStatus
|
RDFFStatus
|
||||||
rdff_write_value(RDFF file,
|
rdff_write_triple(RDFF file,
|
||||||
uint32_t key,
|
uint32_t subject,
|
||||||
const void* value,
|
uint32_t predicate,
|
||||||
uint32_t size,
|
uint32_t object_type,
|
||||||
uint32_t type)
|
uint32_t object_size,
|
||||||
|
const void* object)
|
||||||
{
|
{
|
||||||
const uint32_t chunk_size = sizeof(key) + sizeof(type) + sizeof(size) + size;
|
const uint32_t chunk_size = sizeof(RDFFTripleChunk) + object_size;
|
||||||
WRITE(CHUNK_KVAL, CHUNK_ID_LEN, 1, file->fd);
|
WRITE(CHUNK_TRIP, CHUNK_ID_LEN, 1, file->fd);
|
||||||
WRITE(&chunk_size, sizeof(chunk_size), 1, file->fd);
|
WRITE(&chunk_size, sizeof(chunk_size), 1, file->fd);
|
||||||
WRITE(&key, sizeof(key), 1, file->fd);
|
WRITE(&subject, sizeof(subject), 1, file->fd);
|
||||||
WRITE(&type, sizeof(type), 1, file->fd);
|
WRITE(&predicate, sizeof(predicate), 1, file->fd);
|
||||||
WRITE(&size, sizeof(size), 1, file->fd);
|
WRITE(&object_type, sizeof(object_type), 1, file->fd);
|
||||||
WRITE(value, size, 1, file->fd);
|
WRITE(&object_size, sizeof(object_size), 1, file->fd);
|
||||||
if ((size % 2)) {
|
WRITE(object, object_size, 1, file->fd);
|
||||||
|
if ((object_size % 2)) {
|
||||||
WRITE("", 1, 1, file->fd); /* write pad */
|
WRITE("", 1, 1, file->fd); /* write pad */
|
||||||
}
|
}
|
||||||
file->size += 8 + chunk_size;
|
file->size += 8 + chunk_size;
|
||||||
@ -199,17 +201,18 @@ main(int argc, char** argv)
|
|||||||
char uri[64];
|
char uri[64];
|
||||||
for (int i = 0; i < N_URIS; ++i) {
|
for (int i = 0; i < N_URIS; ++i) {
|
||||||
snprintf(uri, sizeof(uri), "http://example.org/uri%02d", i + 1);
|
snprintf(uri, sizeof(uri), "http://example.org/uri%02d", i + 1);
|
||||||
rdff_write_uri(file, i + 1, uri, strlen(uri) + 1);
|
rdff_write_uri(file, i + 1, strlen(uri), uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
char val[6];
|
char val[6];
|
||||||
for (int i = 0; i < N_RECORDS; ++i) {
|
for (int i = 0; i < N_RECORDS; ++i) {
|
||||||
snprintf(val, sizeof(val), "VAL%02d", i);
|
snprintf(val, sizeof(val), "VAL%02d", i);
|
||||||
rdff_write_value(file,
|
rdff_write_triple(file,
|
||||||
rand() % N_URIS,
|
0,
|
||||||
val,
|
rand() % N_URIS,
|
||||||
sizeof(val),
|
0,
|
||||||
0);
|
sizeof(val),
|
||||||
|
val);
|
||||||
}
|
}
|
||||||
|
|
||||||
rdff_close(file);
|
rdff_close(file);
|
||||||
@ -222,8 +225,8 @@ main(int argc, char** argv)
|
|||||||
chunk->size = 0;
|
chunk->size = 0;
|
||||||
for (int i = 0; i < N_URIS; ++i) {
|
for (int i = 0; i < N_URIS; ++i) {
|
||||||
if (rdff_read_chunk(file, &chunk)
|
if (rdff_read_chunk(file, &chunk)
|
||||||
|| strncmp(chunk->type, "URID", 4)) {
|
|| strncmp(chunk->type, CHUNK_URID, 4)) {
|
||||||
fprintf(stderr, "error: expected URID chunk\n");
|
fprintf(stderr, "error: expected %s chunk\n", CHUNK_URID);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
RDFFURIChunk* body = (RDFFURIChunk*)chunk->data;
|
RDFFURIChunk* body = (RDFFURIChunk*)chunk->data;
|
||||||
@ -232,12 +235,12 @@ main(int argc, char** argv)
|
|||||||
|
|
||||||
for (int i = 0; i < N_RECORDS; ++i) {
|
for (int i = 0; i < N_RECORDS; ++i) {
|
||||||
if (rdff_read_chunk(file, &chunk)
|
if (rdff_read_chunk(file, &chunk)
|
||||||
|| strncmp(chunk->type, "KVAL", 4)) {
|
|| strncmp(chunk->type, CHUNK_TRIP, 4)) {
|
||||||
fprintf(stderr, "error: expected KVAL chunk\n");
|
fprintf(stderr, "error: expected %s chunk\n", CHUNK_TRIP);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
RDFFValueChunk* body = (RDFFValueChunk*)chunk->data;
|
RDFFTripleChunk* body = (RDFFTripleChunk*)chunk->data;
|
||||||
printf("KEY %d = %s\n", body->key, body->value);
|
printf("KEY %d = %s\n", body->predicate, body->object);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(chunk);
|
free(chunk);
|
||||||
|
@ -65,7 +65,7 @@ typedef struct {
|
|||||||
} PACKED RDFFChunk;
|
} PACKED RDFFChunk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Body of a URID chunk.
|
Body of a RDFF "urid" chunk.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t id; /**< Numeric ID of URI in this RDFF. */
|
uint32_t id; /**< Numeric ID of URI in this RDFF. */
|
||||||
@ -73,14 +73,15 @@ typedef struct {
|
|||||||
} PACKED RDFFURIChunk;
|
} PACKED RDFFURIChunk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Body of a KVAL chunk.
|
Body of a RDFF "trip" chunk.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t key; /**< Predicate URI ID. */
|
uint32_t subject; /**< Subject URI ID. */
|
||||||
uint32_t type; /**< Type URI ID. */
|
uint32_t predicate; /**< Predicate URI ID. */
|
||||||
uint32_t size; /**< Size of object data. */
|
uint32_t object_type; /**< Object type URI ID. */
|
||||||
char value[]; /**< Object data. */
|
uint32_t object_size; /**< Size of object data. */
|
||||||
} PACKED RDFFValueChunk;
|
char object[]; /**< Object data. */
|
||||||
|
} PACKED RDFFTripleChunk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Open/Create a new RDFF file.
|
Open/Create a new RDFF file.
|
||||||
@ -94,18 +95,19 @@ rdff_open(const char* path, bool write);
|
|||||||
RDFFStatus
|
RDFFStatus
|
||||||
rdff_write_uri(RDFF file,
|
rdff_write_uri(RDFF file,
|
||||||
uint32_t id,
|
uint32_t id,
|
||||||
const char* uri,
|
uint32_t len,
|
||||||
uint32_t len);
|
const char* uri);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Write a key/value record to @a file.
|
Write a key/value record to @a file.
|
||||||
*/
|
*/
|
||||||
RDFFStatus
|
RDFFStatus
|
||||||
rdff_write_value(RDFF file,
|
rdff_write_triple(RDFF file,
|
||||||
uint32_t key,
|
uint32_t subject,
|
||||||
const void* value,
|
uint32_t predicate,
|
||||||
uint32_t size,
|
uint32_t object_type,
|
||||||
uint32_t type);
|
uint32_t object_size,
|
||||||
|
const void* object);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Read a chunk from @a file.
|
Read a chunk from @a file.
|
||||||
|
Loading…
Reference in New Issue
Block a user