driver_state.c

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <grass/dbmi.h>
00003 #include "dbstubs.h"
00004 
00005 
00006 static dbDriverState state;
00007 
00008 
00009 void
00010 db__init_driver_state(void)
00011 {
00012     db_zero((void *)&state, sizeof(state));
00013 }
00014 
00015 
00016 dbDriverState *
00017 db__get_driver_state(void)
00018 {
00019     return &state;
00020 }
00021 
00022 
00023 int
00024 db__test_database_open (void)
00025 {
00026     return state.open ? 1 : 0 ;
00027 }
00028 
00029 
00030 void
00031 db__mark_database_open (char *dbname, char *dbschema)
00032 {
00033     state.dbname = dbname;
00034     state.dbschema = dbschema;
00035     state.open = 1;
00036 }
00037 
00038 
00039 void
00040 db__mark_database_closed (void)
00041 {
00042     free(state.dbname);
00043     free(state.dbschema);
00044     state.open = 0;
00045 }
00046 
00047 
00048 void
00049 db__add_cursor_to_driver_state (dbCursor *cursor)
00050 
00051 {
00052     dbCursor **list;
00053     int i;
00054 
00055     /* find an empty slot in the cursor list */
00056     list = state.cursor_list;
00057     for (i = 0; i < state.ncursors; i++)
00058         if (list[i] == NULL)
00059             break;
00060 
00061     /* if not found, extend list */
00062     if (i >= state.ncursors)
00063     {
00064         list = (dbCursor **) db_realloc ((void *)list, (i+1) * sizeof(dbCursor *));
00065         if (list == NULL)
00066             return;
00067         state.cursor_list = list;
00068         state.ncursors    = i+1;
00069     }
00070 
00071     /* add it in */
00072     list[i] = cursor;
00073 }
00074 
00075 
00076 void
00077 db__drop_cursor_from_driver_state(dbCursor *cursor)
00078 {
00079     int i;
00080 
00081     for (i = 0; i < state.ncursors; i++)
00082         if (state.cursor_list[i] == cursor)
00083             state.cursor_list[i] = NULL;
00084 }
00085 
00086 
00087 void
00088 db__close_all_cursors(void)
00089 {
00090     int i;
00091 
00092     for (i = 0; i < state.ncursors; i++)
00093         if (state.cursor_list[i])
00094             db_driver_close_cursor (state.cursor_list[i]);
00095     
00096     if (state.cursor_list)
00097         free (state.cursor_list);
00098     
00099     state.ncursors = 0;
00100     state.cursor_list = NULL;
00101 }

Generated on Sun Apr 6 17:31:38 2008 for GRASS by  doxygen 1.5.5