#define OSM_RANGE_STEP (8192)
#define OSM_RANGE_STOP (65535)
+static sqlite3 *osmdb;
+
struct sql_select_stmt {
sqlite3_stmt *select_way;
sqlite3_stmt *select_way2;
static GtkProgressBar *dbpw=NULL;
/* Cache hash tables */
-static GHashTable *_place_cache;
+static GHashTable *place_cache;
static guint way_dist_range=OSM_RANGE_WAY;
return TRUE;
}
-gboolean
-osm_init(void)
-{
-_place_cache=g_hash_table_new(g_direct_hash, g_direct_equal);
-dbt=g_timer_new();
-return TRUE;
-}
-
void
osm_deinit(void)
{
-g_hash_table_destroy(_place_cache);
+osmdb=NULL;
+g_hash_table_destroy(place_cache);
g_timer_destroy(dbt);
}
+gboolean
+osm_init(sqlite3 **db)
+{
+if (!db || !*db)
+ return FALSE;
+
+osmdb=*db;
+if (osm_db_prepare(osmdb)==FALSE) {
+ g_printerr("Failed to prepare OSM SQL statements:");
+ g_printf("SQLITE: %s\n", sqlite3_errmsg(osmdb));
+ return FALSE;
+}
+place_cache=g_hash_table_new(g_direct_hash, g_direct_equal);
+dbt=g_timer_new();
+return TRUE;
+}
+
/*****************************************************************************/
osm_way_node *
static osm_place *
osm_place_cache_lookup(guint32 id)
{
-return g_hash_table_lookup(_place_cache, GINT_TO_POINTER(id));
+return g_hash_table_lookup(place_cache, GINT_TO_POINTER(id));
}
static void
osm_place_cache_add(osm_place *p)
{
if (osm_place_cache_lookup(p->id)==NULL)
- g_hash_table_insert(_place_cache, GINT_TO_POINTER(p->id), p);
+ g_hash_table_insert(place_cache, GINT_TO_POINTER(p->id), p);
}
static void
osm_place_cache_gc(void)
{
gint r;
-r=g_hash_table_foreach_remove(_place_cache, osm_place_remove, NULL);
+r=g_hash_table_foreach_remove(place_cache, osm_place_remove, NULL);
}
static void
n=NULL;
/* XXX: better place for this */
-if (g_hash_table_size(_place_cache)>OSM_PLACE_CACHE_MAX_ITEMS)
+if (g_hash_table_size(place_cache)>OSM_PLACE_CACHE_MAX_ITEMS)
osm_place_cache_gc();
sqlite3_clear_bindings(sql.select_place);
#include "osm.h"
#include "osm-db.h"
+static sqlite3 *poidb;
+
struct _poi_categories {
node_type_t type;
const gchar *name, *desc, *icon, *color;
}
gboolean
-mapper_db_disconnect(sqlite3 **db)
+poi_init(sqlite3 **db)
{
-if (db && *db) {
- /* XXX: Handle the prepared statements */
-#if 0
- poi_db_unprepare(*db);
- osm_db_unprepare(*db);
-#endif
- sqlite3_close(*db);
- return TRUE;
-}
-return FALSE;
-}
+if (!db || !*db)
+ return FALSE;
-gboolean
-mapper_db_connect(sqlite3 **db, const gchar *data_db)
-{
-if (db_connect(db, data_db)) {
- poi_db_create(*db);
- if (poi_db_prepare(*db)==FALSE) {
- g_printerr("Failed to prepare POI SQL statements:");
- g_printf("SQLITE: %s\n", sqlite3_errmsg(*db));
- return FALSE;
- }
- if (osm_db_prepare(*db)==FALSE) {
- g_printerr("Failed to prepare OSM SQL statements:");
- g_printf("SQLITE: %s\n", sqlite3_errmsg(*db));
- return FALSE;
- }
- return TRUE;
+poidb=*db;
+poi_db_create(poidb);
+if (poi_db_prepare(poidb)==FALSE) {
+ g_printerr("Failed to prepare POI SQL statements:");
+ g_printf("SQLITE: %s\n", sqlite3_errmsg(poidb));
+ return FALSE;
}
-return FALSE;
+return TRUE;
}
poi_info *
speak_set_parameters(_voice_speed, _voice_pitch);
if (_db) {
- mapper_db_disconnect(&_db);
+ db_close(&_db);
_db = NULL;
}
g_free(_mapper_db);
if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_mapper_db)))) {
_mapper_db = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_mapper_db)));
- mapper_db_connect(&_db, _mapper_db);
+ db_connect(&_db, _mapper_db);
} else {
_mapper_db = NULL;
}