Reworked obiview code and added more comments
This commit is contained in:
@ -10,20 +10,15 @@
|
||||
*/
|
||||
|
||||
|
||||
// TODO
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "obidms.h"
|
||||
#include "obiview.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obidms.h"
|
||||
#include "obidmscolumn.h"
|
||||
#include "utils.h"
|
||||
#include "obilittlebigman.h"
|
||||
#include "obidmscolumn_idx.h"
|
||||
#include "obidmscolumn_bool.h"
|
||||
#include "obidmscolumn_char.h"
|
||||
@ -31,6 +26,10 @@
|
||||
#include "obidmscolumn_int.h"
|
||||
#include "obidmscolumn_seq.h"
|
||||
#include "obidmscolumn_str.h"
|
||||
#include "obierrno.h"
|
||||
#include "obidebug.h"
|
||||
#include "obilittlebigman.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
#define DEBUG_LEVEL 0 // TODO has to be defined somewhere else (cython compil flag?)
|
||||
@ -59,7 +58,7 @@
|
||||
static char* build_obiview_file_name();
|
||||
|
||||
|
||||
/** TODO public
|
||||
/** TODO public?
|
||||
* Internal function creating the file containing basic informations on the OBIDMS.
|
||||
*
|
||||
* This file contains:
|
||||
@ -99,6 +98,12 @@ static char* build_obiview_file_name()
|
||||
|
||||
// Build file name
|
||||
file_name = (char*) malloc((strlen(OBIVIEW_FILE_NAME) + 1)*sizeof(char));
|
||||
if (file_name == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR);
|
||||
obidebug(1, "\nError allocating memory for a view file name");
|
||||
return NULL;
|
||||
}
|
||||
if (sprintf(file_name, OBIVIEW_FILE_NAME) < 0)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
@ -147,7 +152,6 @@ int create_obiview_file(int dms_file_descriptor)
|
||||
char* file_name;
|
||||
int obiview_file_descriptor;
|
||||
size_t header_size;
|
||||
// size_t view_size;
|
||||
size_t file_size;
|
||||
Obiviews_header_p header;
|
||||
|
||||
@ -170,8 +174,7 @@ int create_obiview_file(int dms_file_descriptor)
|
||||
|
||||
// Truncate file to the right size
|
||||
header_size = get_platform_header_size();
|
||||
//view_size = get_platform_views_size(1);
|
||||
file_size = header_size; // + view_size;
|
||||
file_size = header_size;
|
||||
|
||||
if (ftruncate(obiview_file_descriptor, file_size) < 0)
|
||||
{
|
||||
@ -281,7 +284,7 @@ Obiview_p obi_new_view_nuc_seqs(OBIDMS_p dms, const char* view_name, Obiview_p v
|
||||
Obiview_p view;
|
||||
|
||||
if (view_to_clone != NULL)
|
||||
{ // TODO check that the view to clone is already a NUC_SEQS view (discuss possibility of transforming type of a view)
|
||||
{ // Check that the view to clone is already a NUC_SEQS view (TODO discuss possibility of transforming type of a view)
|
||||
if (strcmp(view_to_clone->view_type, VIEW_TYPE_NUC_SEQS))
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
@ -329,7 +332,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
|
||||
index_t line_nb;
|
||||
Obiviews_infos_all_p views_infos;
|
||||
|
||||
// Check uniqueness of name TODO but problem if view not written yet has the same name
|
||||
// Check uniqueness of name TODO but problem if view not written yet has the same name. Save lists of open views in DMS ?
|
||||
views_infos = obi_read_views(dms);
|
||||
if (views_infos != NULL)
|
||||
{
|
||||
@ -367,13 +370,16 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
|
||||
|
||||
view->dms = dms;
|
||||
view->column_count = view_to_clone->column_count;
|
||||
if ((view_to_clone->line_selection != NULL) && (line_selection == NULL)) // reorder conditions
|
||||
|
||||
// If the view to clone has an associated line selection and there is no new line selection, open the associated line selection
|
||||
if ((view_to_clone->line_selection != NULL) && (line_selection == NULL))
|
||||
{
|
||||
view->line_selection = obi_open_column(dms, ((view_to_clone->line_selection)->header)->name, ((view_to_clone->line_selection)->header)->version);
|
||||
if (view->line_selection == NULL)
|
||||
return NULL;
|
||||
view->line_count = view_to_clone->line_count;
|
||||
}
|
||||
// If there is a new line selection, build it by combining it with the pre-existing one if there is one
|
||||
else if (line_selection != NULL)
|
||||
{
|
||||
view->line_selection = obi_create_column(view->dms, LINES_COLUMN_NAME, OBI_IDX, 0, 1, LINES_COLUMN_NAME, NULL, NULL);
|
||||
@ -411,7 +417,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
|
||||
(view->line_count)++;
|
||||
}
|
||||
}
|
||||
else
|
||||
else // If there is no line selection associated with the view to clone or the new view
|
||||
{
|
||||
view->line_selection = NULL;
|
||||
view->line_count = view_to_clone->line_count;
|
||||
@ -442,7 +448,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
|
||||
view->new_line_selection = NULL;
|
||||
(view->created_from)[0] = '\0';
|
||||
(view->view_type)[0] = '\0';
|
||||
//view->columns = NULL; TODO
|
||||
//view->columns = NULL; // TODO
|
||||
}
|
||||
|
||||
strcpy(view->name, view_name);
|
||||
@ -639,7 +645,7 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name)
|
||||
view->column_count++;
|
||||
}
|
||||
|
||||
// Munmap and close things TODO
|
||||
// Munmap and close things
|
||||
munmap(views, header->views_size);
|
||||
munmap(header, header_size);
|
||||
close(obiview_file_descriptor);
|
||||
@ -648,7 +654,7 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name)
|
||||
}
|
||||
|
||||
|
||||
Obiviews_infos_all_p obi_read_views(OBIDMS_p dms)
|
||||
Obiviews_infos_all_p obi_read_view_infos(OBIDMS_p dms)
|
||||
{
|
||||
char* view_file_name;
|
||||
int obiview_file_descriptor;
|
||||
@ -733,7 +739,7 @@ Obiviews_infos_all_p obi_read_views(OBIDMS_p dms)
|
||||
}
|
||||
|
||||
|
||||
int obi_unmap_read_views(Obiviews_infos_all_p views)
|
||||
int obi_close_view_infos(Obiviews_infos_all_p views)
|
||||
{
|
||||
if (munmap(views->view_infos, (views->header)->views_size) < 0)
|
||||
{
|
||||
@ -822,7 +828,7 @@ OBIDMS_column_p obi_view_clone_column(Obiview_p view, const char* column_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (view->new_line_selection != NULL) // TODO Probably shouldn't happen
|
||||
if (view->new_line_selection != NULL) // TODO Probably shouldn't happen, trigger error?
|
||||
current_line_selection = view->new_line_selection;
|
||||
else
|
||||
current_line_selection = view->line_selection;
|
||||
@ -830,8 +836,12 @@ OBIDMS_column_p obi_view_clone_column(Obiview_p view, const char* column_name)
|
||||
for (i=0; i<(view->column_count); i++)
|
||||
{
|
||||
if ((current_line_selection != NULL) || (!(strcmp((((view->columns)[i])->header)->name, column_name))))
|
||||
{ // Clone with the right line selection and replace
|
||||
{ // Clone with the right line selection and replace (for all columns if there is a line selection)
|
||||
|
||||
// Save pointer to close column after cloning
|
||||
column_buffer = (view->columns)[i];
|
||||
|
||||
// Clone and replace the column in the view
|
||||
(view->columns)[i] = obi_clone_column(view->dms, current_line_selection, (((view->columns)[i])->header)->name, (((view->columns)[i])->header)->version, 1);
|
||||
if ((view->columns)[i] == NULL)
|
||||
{
|
||||
@ -839,14 +849,17 @@ OBIDMS_column_p obi_view_clone_column(Obiview_p view, const char* column_name)
|
||||
obidebug(1, "\nError cloning a column to replace in a view");
|
||||
return NULL;
|
||||
}
|
||||
// Found the column to return
|
||||
|
||||
// Close old cloned column
|
||||
obi_close_column(column_buffer);
|
||||
|
||||
if (!(strcmp((((view->columns)[i])->header)->name, column_name)))
|
||||
// Found the column to return
|
||||
column = (view->columns)[i];
|
||||
else
|
||||
obi_close_column(column_buffer); // TODO weird closing after cloning but can't think of cleaner yet
|
||||
}
|
||||
}
|
||||
|
||||
// Close old line selections
|
||||
if (view->line_selection != NULL)
|
||||
{
|
||||
obi_close_column(view->line_selection);
|
||||
@ -1204,7 +1217,7 @@ int obi_close_view(Obiview_p view)
|
||||
|
||||
int obi_save_and_close_view(Obiview_p view)
|
||||
{
|
||||
if (!(view->read_only)) // TODO discuss
|
||||
if (!(view->read_only))
|
||||
{
|
||||
if (obi_save_view(view) < 0)
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user