driver_state.c

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

Generated on Mon Jan 1 19:49:04 2007 for GRASS by  doxygen 1.5.1