-/* Copyright (C) 2003,2004,2005,2006 MORIOKA Tomohiko
+/* Copyright (C) 2003, 2004, 2005, 2006, 2011, 2013 MORIOKA Tomohiko
This file is part of the CONCORD Library.
The CONCORD Library is free software; you can redistribute it and/or
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
#include "sysdep.h"
#include "concord.h"
+#include "cos-i.h"
#include "concord-name.h"
+#include "cos-hash.h"
#include "concord-bdb.h"
+COS_Feature concord_opened_feature_list = NULL;
+COS_Feature concord_opened_feature_list_last = NULL;
+size_t concord_opened_feature_list_length = 0;
+size_t concord_opened_feature_list_limit = 96;
+
+COS_Feature_INDEX concord_opened_index_list = NULL;
+COS_Feature_INDEX concord_opened_index_list_last = NULL;
+size_t concord_opened_index_list_length = 0;
+size_t concord_opened_index_list_limit = 32;
+
int
CONCORD_String_size (const CONCORD_String s)
CONCORD_Genre concord_ds_open_genre (CONCORD_DS ds, const char* name);
-int concord_close_genre (CONCORD_Genre genre);
-
CONCORD_Feature
concord_genre_open_feature (CONCORD_Genre genre, const char* name);
-int concord_close_feature (CONCORD_Feature feature);
-
CONCORD_INDEX
concord_genre_open_index (CONCORD_Genre genre, const char* index);
CONCORD_Feature
concord_genre_get_feature_0 (CONCORD_Genre genre, const char* name);
-int concord_close_index (CONCORD_INDEX table);
-
CONCORD_Object
concord_default_read_object (const unsigned char* string, size_t length);
-struct CONCORD_DS_Table
+struct COS_DS_ent
{
+ COS_Object_Header header;
CONCORD_Backend_Type type;
char *location;
CONCORD_NAME_TABLE* genre_names;
return NULL;
strncpy ((char*)buf, (char*)str, length);
buf[length] = '\0';
- return buf;
+ return (CONCORD_Object)buf;
}
CONCORD_DS
concord_open_ds (CONCORD_Backend_Type type, const char* location,
int subtype, int modemask)
{
- CONCORD_DS ds = (CONCORD_DS)malloc (sizeof (CONCORD_DS_Table));
+ CONCORD_DS ds = COS_ALLOCATE_OBJECT (DS);
size_t len = strlen (location);
if (ds == NULL)
}
-struct CONCORD_Genre_Table
+struct COS_Genre_ent
{
+ COS_Object_Header header;
CONCORD_DS ds;
char *name;
CONCORD_NAME_TABLE* feature_names;
if (ds == NULL)
return NULL;
- genre = (CONCORD_Genre)malloc (sizeof (CONCORD_Genre_Table));
+ genre = COS_ALLOCATE_OBJECT (Genre);
if (genre == NULL)
return NULL;
}
-struct CONCORD_Feature_Table
-{
- CONCORD_Genre genre;
- char* name;
- DB* db;
- u_int32_t access;
-};
-
CONCORD_Feature
concord_genre_open_feature (CONCORD_Genre genre, const char* feature)
{
if (genre == NULL)
return NULL;
- table = (CONCORD_Feature)malloc (sizeof (CONCORD_Feature_Table));
+ table = COS_ALLOCATE_OBJECT (Feature);
if (table == NULL)
return NULL;
return NULL;
}
strcpy (table->name, feature);
+ table->value_table = NULL;
+ table->next = NULL;
return table;
}
{
CONCORD_Genre genre = feature->genre;
+ if ( concord_opened_feature_list_length
+ >= concord_opened_feature_list_limit )
+ {
+ CONCORD_Feature top_feature = concord_opened_feature_list;
+
+ CONCORD_BDB_close (top_feature->db);
+ top_feature->db = NULL;
+ concord_opened_feature_list = top_feature->next;
+ top_feature->next = NULL;
+ concord_opened_feature_list_length--;
+ }
feature->db
= CONCORD_BDB_open (genre->ds->location, genre->name,
"feature", feature->name,
if (feature->db == NULL)
return -1;
feature->access = access;
+ if ( concord_opened_feature_list == NULL )
+ {
+ concord_opened_feature_list = feature;
+ concord_opened_feature_list_last = feature;
+ }
+ else
+ {
+ concord_opened_feature_list_last->next = feature;
+ concord_opened_feature_list_last = feature;
+ }
+ concord_opened_feature_list_length++;
}
return 0;
}
}
-struct CONCORD_INDEX_Table
-{
- CONCORD_Genre genre;
- char *name;
- DB* db;
- u_int32_t access;
-};
-
CONCORD_INDEX
concord_genre_open_index (CONCORD_Genre genre, const char* index)
{
if (genre == NULL)
return NULL;
- table = (CONCORD_INDEX)malloc (sizeof (CONCORD_INDEX_Table));
+ table = COS_ALLOCATE_OBJECT (Feature_INDEX);
if (table == NULL)
return NULL;
return NULL;
}
strcpy (table->name, index);
+ table->decoding_table = NULL;
+ table->next = NULL;
return table;
}
return status;
}
+char*
+concord_index_get_name (CONCORD_INDEX index)
+{
+ return index->name;
+}
+
+CONCORD_Genre
+concord_index_get_genre (CONCORD_INDEX index)
+{
+ return index->genre;
+}
+
int
concord_index_setup_db (CONCORD_INDEX index, int writable)
{
{
CONCORD_Genre genre = index->genre;
+ if ( concord_opened_index_list_length
+ >= concord_opened_index_list_limit )
+ {
+ CONCORD_INDEX top_index = concord_opened_index_list;
+
+ CONCORD_BDB_close (top_index->db);
+ top_index->db = NULL;
+ concord_opened_index_list = top_index->next;
+ top_index->next = NULL;
+ concord_opened_index_list_length--;
+ }
index->db
= CONCORD_BDB_open (genre->ds->location, genre->name,
"index", index->name,
if (index->db == NULL)
return -1;
index->access = access;
+ if ( concord_opened_index_list == NULL )
+ {
+ concord_opened_index_list = index;
+ concord_opened_index_list_last = index;
+ }
+ else
+ {
+ concord_opened_index_list_last->next = index;
+ concord_opened_index_list_last = index;
+ }
+ concord_opened_index_list_length++;
}
return 0;
}