Made the handling of listing and unlisting opened columns and indexers
functions in the obidms files.
This commit is contained in:
165
src/obidms.c
165
src/obidms.c
@ -23,6 +23,7 @@
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obidmscolumn.h"
|
||||
#include "obiblob_indexer.h"
|
||||
#include "utils.h"
|
||||
#include "obilittlebigman.h"
|
||||
|
||||
@ -417,12 +418,10 @@ OBIDMS_p obi_open_dms(const char* dms_name)
|
||||
|
||||
// Initialize the list of opened columns
|
||||
dms->opened_columns = (Opened_columns_list_p) malloc(sizeof(Opened_columns_list_t));
|
||||
(dms->opened_columns)->columns = (OBIDMS_column_p*) malloc(MAX_NB_OPENED_COLUMNS*sizeof(OBIDMS_column_p));
|
||||
(dms->opened_columns)->nb_opened_columns = 0;
|
||||
|
||||
// Initialize the list of opened indexers // TODO should be handled somewhere else?
|
||||
dms->opened_indexers = (Opened_indexers_list_p) malloc(sizeof(Opened_indexers_list_t));
|
||||
(dms->opened_indexers)->indexers = (OBIDMS_avl_p*) malloc(MAX_NB_OPENED_INDEXERS*sizeof(OBIDMS_avl_p)); // TODO idk how to handle this
|
||||
(dms->opened_indexers)->nb_opened_indexers = 0;
|
||||
|
||||
return dms;
|
||||
@ -477,3 +476,165 @@ int obi_close_dms(OBIDMS_p dms)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int obi_dms_is_column_name_in_list(OBIDMS_p dms, const char* column_name)
|
||||
{
|
||||
int i;
|
||||
Opened_columns_list_p columns_list;
|
||||
|
||||
columns_list = dms->opened_columns;
|
||||
|
||||
for (i=0; i < (columns_list->nb_opened_columns); i++)
|
||||
{
|
||||
if (!strcmp(((*((columns_list->columns)+i))->header)->name, column_name))
|
||||
{ // Found it
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
OBIDMS_column_p obi_dms_get_column_from_list(OBIDMS_p dms, const char* column_name, obiversion_t version)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < ((dms->opened_columns)->nb_opened_columns); i++)
|
||||
{
|
||||
if (!strcmp(((*(((dms->opened_columns)->columns)+i))->header)->name, column_name)
|
||||
&& (((*(((dms->opened_columns)->columns)+i))->header)->version == version))
|
||||
{ // Found the column already opened, return it
|
||||
return *(((dms->opened_columns)->columns)+i);
|
||||
}
|
||||
}
|
||||
// Didn't find the column
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void obi_dms_list_column(OBIDMS_p dms, OBIDMS_column_p column)
|
||||
{
|
||||
*(((dms->opened_columns)->columns)+((dms->opened_columns)->nb_opened_columns)) = column;
|
||||
((dms->opened_columns)->nb_opened_columns)++;
|
||||
}
|
||||
|
||||
|
||||
int obi_dms_unlist_column(OBIDMS_p dms, OBIDMS_column_p column)
|
||||
{
|
||||
int i;
|
||||
Opened_columns_list_p columns_list;
|
||||
|
||||
columns_list = dms->opened_columns;
|
||||
|
||||
for (i=0; i < columns_list->nb_opened_columns; i++)
|
||||
{
|
||||
if (!strcmp(((*((columns_list->columns)+i))->header)->name, (column->header)->name)
|
||||
&& (((*((columns_list->columns)+i))->header)->version == (column->header)->version))
|
||||
{ // Found the column. Rearrange list
|
||||
(columns_list->nb_opened_columns)--;
|
||||
(columns_list->columns)[i] = (columns_list->columns)[columns_list->nb_opened_columns];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
obidebug(1, "\nCould not find the column to delete from list of open columns");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Obi_indexer_p obi_dms_get_indexer_from_list(OBIDMS_p dms, const char* indexer_name)
|
||||
{
|
||||
int i;
|
||||
Opened_indexers_list_p indexers_list;
|
||||
|
||||
indexers_list = dms->opened_indexers;
|
||||
|
||||
for (i=0; i < (indexers_list->nb_opened_indexers); i++)
|
||||
{
|
||||
if (!strcmp(((indexers_list->indexers)[i])->name, indexer_name)) // TODO it references something in AVL_group struct
|
||||
{ // Found the indexer already opened, return it
|
||||
return (indexers_list->indexers)[i];
|
||||
}
|
||||
}
|
||||
// Didn't find the indexer
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void obi_dms_list_indexer(OBIDMS_p dms, Obi_indexer_p indexer)
|
||||
{
|
||||
*(((dms->opened_indexers)->indexers)+((dms->opened_indexers)->nb_opened_indexers)) = indexer;
|
||||
((dms->opened_indexers)->nb_opened_indexers)++;
|
||||
}
|
||||
|
||||
|
||||
int obi_dms_unlist_indexer(OBIDMS_p dms, Obi_indexer_p indexer)
|
||||
{
|
||||
int i;
|
||||
Opened_indexers_list_p indexers_list;
|
||||
|
||||
indexers_list = dms->opened_indexers;
|
||||
|
||||
for (i=0; i < indexers_list->nb_opened_indexers; i++)
|
||||
{
|
||||
if (!strcmp(((indexers_list->indexers)[i])->name, indexer->name)) // TODO it references something in AVL_group struct
|
||||
{ // Found the indexer. Rearrange list
|
||||
(indexers_list->nb_opened_indexers)--;
|
||||
(indexers_list->indexers)[i] = (indexers_list->indexers)[indexers_list->nb_opened_indexers];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
obidebug(1, "\nCould not find the indexer to delete from list of open indexers");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
char* get_full_path(OBIDMS_p dms, const char* path_name)
|
||||
{
|
||||
char* full_path;
|
||||
|
||||
full_path = (char*) malloc((MAX_PATH_LEN)*sizeof(char));
|
||||
if (full_path == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR);
|
||||
obidebug(1, "\nError allocating memory for the char* path to a file or directory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (getcwd(full_path, MAX_PATH_LEN) == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_UTILS_ERROR);
|
||||
obidebug(1, "\nError getting the path to a file or directory");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcat(full_path, "/");
|
||||
strcat(full_path, dms->directory_name);
|
||||
strcat(full_path, "/");
|
||||
strcat(full_path, path_name);
|
||||
|
||||
return full_path;
|
||||
}
|
||||
|
||||
|
||||
DIR* opendir_in_dms(OBIDMS_p dms, const char* path_name)
|
||||
{
|
||||
char* full_path;
|
||||
DIR* directory;
|
||||
|
||||
full_path = get_full_path(dms, path_name);
|
||||
if (full_path == NULL)
|
||||
return NULL;
|
||||
|
||||
directory = opendir(full_path);
|
||||
if (directory == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_UTILS_ERROR);
|
||||
obidebug(1, "\nError opening a directory");
|
||||
}
|
||||
|
||||
free(full_path);
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
Reference in New Issue
Block a user