/*! \brief Overrides the super class version to initialize the registrar services. */ void Registrar::ReadyToRun() { FUNCTION_START(); // create event queue fEventQueue = new EventQueue(kEventQueueName); // create roster fRoster = new TRoster; fRoster->Init(); // create clipboard handler fClipboardHandler = new ClipboardHandler; AddHandler(fClipboardHandler); // create MIME manager fMIMEManager = new MIMEManager; fMIMEManager->Run(); // create message runner manager fMessageRunnerManager = new MessageRunnerManager(fEventQueue); // init the global be_roster BRoster::Private().SetTo(be_app_messenger, BMessenger(NULL, fMIMEManager)); // create and schedule the sanity message event fSanityEvent = new MessageEvent(system_time() + kRosterSanityEventInterval, this, B_REG_ROSTER_SANITY_EVENT); fSanityEvent->SetAutoDelete(false); fEventQueue->AddEvent(fSanityEvent); FUNCTION_END(); }
static void ST_SRID(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_GEOM_ARG(geomblob); FUNCTION_START_STATIC(context, 256); spatialdb = (spatialdb_t *)sqlite3_user_data(context); FUNCTION_GET_GEOM_ARG_UNSAFE(context, spatialdb, geomblob, 0); if (nbArgs == 1) { sqlite3_result_int(context, geomblob.srid); } else { FUNCTION_GET_INT_ARG(geomblob.srid, 1); if (binstream_seek(&FUNCTION_GEOM_ARG_STREAM(geomblob), 0) != SQLITE_OK) { sqlite3_result_error(context, "Error writing geometry blob header", -1); goto exit; } if (spatialdb->write_blob_header(&FUNCTION_GEOM_ARG_STREAM(geomblob), &geomblob, FUNCTION_ERROR) != SQLITE_OK) { if (error_count(FUNCTION_ERROR) == 0) { error_append(FUNCTION_ERROR, "Error writing geometry blob header"); } goto exit; } binstream_seek(&FUNCTION_GEOM_ARG_STREAM(geomblob), 0); sqlite3_result_blob(context, binstream_data(&FUNCTION_GEOM_ARG_STREAM(geomblob)), (int) binstream_available(&FUNCTION_GEOM_ARG_STREAM(geomblob)), SQLITE_TRANSIENT); } FUNCTION_END(context); FUNCTION_FREE_GEOM_ARG(geomblob); }
static void GPKG_IsAssignable(sqlite3_context *context, int nbArgs, sqlite3_value **args) { FUNCTION_TEXT_ARG(expected_type_name); FUNCTION_TEXT_ARG(actual_type_name); FUNCTION_START(context); FUNCTION_GET_TEXT_ARG(context, expected_type_name, 0); FUNCTION_GET_TEXT_ARG(context, actual_type_name, 1); geom_type_t expected_type; FUNCTION_RESULT = geom_type_from_string(expected_type_name, &expected_type); if (FUNCTION_RESULT != SQLITE_OK) { error_append(FUNCTION_ERROR, "Invalid geometry type %s", expected_type_name); goto exit; } geom_type_t actual_type; FUNCTION_RESULT = geom_type_from_string(actual_type_name, &actual_type); if (FUNCTION_RESULT != SQLITE_OK) { error_append(FUNCTION_ERROR, "Invalid geometry type %s", actual_type_name); goto exit; } sqlite3_result_int(context, geom_is_assignable(expected_type, actual_type)); FUNCTION_END(context); FUNCTION_FREE_TEXT_ARG(expected_type_name); FUNCTION_FREE_TEXT_ARG(actual_type_name); }
static void GPKG_SpatialDBType(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_START(context); spatialdb = (spatialdb_t *)sqlite3_user_data(context); sqlite3_result_text(context, spatialdb->name, -1, SQLITE_STATIC); FUNCTION_END(context); }
static void ST_Is3d(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_WKB_ARG(wkb); FUNCTION_START_STATIC(context, 256); spatialdb = (spatialdb_t *)sqlite3_user_data(context); FUNCTION_GET_WKB_ARG_UNSAFE(context, spatialdb, wkb, 0); sqlite3_result_int(context, wkb.coord_type == GEOM_XYZ || wkb.coord_type == GEOM_XYZM); FUNCTION_END(context); FUNCTION_FREE_WKB_ARG(wkb); }
static void ST_IsEmpty(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_GEOM_ARG(geomblob); FUNCTION_START_STATIC(context, 256); spatialdb = (spatialdb_t *)sqlite3_user_data(context); FUNCTION_GET_GEOM_ARG_UNSAFE(context, spatialdb, geomblob, 0); sqlite3_result_int(context, geomblob.empty); FUNCTION_END(context); FUNCTION_FREE_GEOM_ARG(geomblob); }
/*! \brief Creates and runs the registrar application. The main thread is renamed. \return 0. */ int main() { FUNCTION_START(); // rename the main thread rename_thread(find_thread(NULL), kRosterThreadName); // create and run the registrar application Registrar *app = new Registrar(); PRINT(("app->Run()...\n")); app->Run(); PRINT(("delete app...\n")); delete app; FUNCTION_END(); return 0; }
static void GPKG_CreateSpatialIndex(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_TEXT_ARG(db_name); FUNCTION_TEXT_ARG(table_name); FUNCTION_TEXT_ARG(geometry_column_name); FUNCTION_TEXT_ARG(id_column_name); FUNCTION_START(context); spatialdb = (spatialdb_t *)sqlite3_user_data(context); if (nbArgs == 4) { FUNCTION_GET_TEXT_ARG(context, db_name, 0); FUNCTION_GET_TEXT_ARG(context, table_name, 1); FUNCTION_GET_TEXT_ARG(context, geometry_column_name, 2); FUNCTION_GET_TEXT_ARG(context, id_column_name, 3); } else { FUNCTION_SET_TEXT_ARG(db_name, "main"); FUNCTION_GET_TEXT_ARG(context, table_name, 0); FUNCTION_GET_TEXT_ARG(context, geometry_column_name, 1); FUNCTION_GET_TEXT_ARG(context, id_column_name, 2); } if (spatialdb->create_spatial_index == NULL) { error_append(FUNCTION_ERROR, "Spatial indexes are not supported in %s mode", spatialdb->name); goto exit; } FUNCTION_START_TRANSACTION(__create_spatial_index); FUNCTION_RESULT = spatialdb->init_meta(FUNCTION_DB_HANDLE, db_name, FUNCTION_ERROR); if (FUNCTION_RESULT == SQLITE_OK) { FUNCTION_RESULT = spatialdb->create_spatial_index(FUNCTION_DB_HANDLE, db_name, table_name, geometry_column_name, id_column_name, FUNCTION_ERROR); } FUNCTION_END_TRANSACTION(__create_spatial_index); if (FUNCTION_RESULT == SQLITE_OK) { sqlite3_result_null(context); } FUNCTION_END(context); FUNCTION_FREE_TEXT_ARG(db_name); FUNCTION_FREE_TEXT_ARG(table_name); FUNCTION_FREE_TEXT_ARG(geometry_column_name); FUNCTION_FREE_TEXT_ARG(id_column_name); }
/*! \brief Frees all resources associated with the registrar. All registrar services, that haven't been shut down earlier, are terminated. */ Registrar::~Registrar() { FUNCTION_START(); Lock(); fEventQueue->Die(); delete fMessageRunnerManager; delete fEventQueue; delete fSanityEvent; fMIMEManager->Lock(); fMIMEManager->Quit(); RemoveHandler(fClipboardHandler); delete fClipboardHandler; delete fRoster; // Invalidate the global be_roster, so that the BApplication destructor // won't dead-lock when sending a message to itself. BRoster::Private().SetTo(BMessenger(), BMessenger()); FUNCTION_END(); }
static void ST_GeometryType(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_WKB_ARG(wkb); FUNCTION_START_STATIC(context, 256); spatialdb = (spatialdb_t *)sqlite3_user_data(context); FUNCTION_GET_WKB_ARG_UNSAFE(context, spatialdb, wkb, 0); const char *type_name; if (geom_type_name(wkb.geom_type, &type_name) == SQLITE_OK) { sqlite3_result_text(context, type_name, -1, SQLITE_STATIC); } else { error_append(FUNCTION_ERROR, "Unknown geometry type: %d", wkb.geom_type); } FUNCTION_END(context); FUNCTION_FREE_WKB_ARG(wkb); }
static void geometry_constructor(sqlite3_context *context, const spatialdb_t *spatialdb, geometry_constructor_func constructor, void* user_data, geom_type_t requiredType, int nbArgs, sqlite3_value **args) { FUNCTION_START_STATIC(context, 256); geom_blob_auxdata *geom = (geom_blob_auxdata *)sqlite3_get_auxdata(context, 0); if (geom == NULL) { geom_blob_writer_t writer; if (sqlite3_value_type(args[nbArgs - 1]) == SQLITE_INTEGER) { spatialdb->writer_init_srid(&writer, sqlite3_value_int(args[nbArgs - 1])); nbArgs -= 1; } else { spatialdb->writer_init(&writer); } FUNCTION_RESULT = constructor(context, user_data, geom_blob_writer_geom_consumer(&writer), nbArgs, args, FUNCTION_ERROR); if (FUNCTION_RESULT == SQLITE_OK) { if (geometry_is_assignable(requiredType, writer.geom_type, FUNCTION_ERROR) == SQLITE_OK) { uint8_t *data = geom_blob_writer_getdata(&writer); int length = (int) geom_blob_writer_length(&writer); sqlite3_result_blob(context, data, length, SQLITE_TRANSIENT); spatialdb->writer_destroy(&writer, 0); geom = geom_blob_auxdata_malloc(); if (geom != NULL) { geom->data = data; geom->length = length; sqlite3_set_auxdata(context, 0, geom, geom_blob_auxdata_free); } } } else { spatialdb->writer_destroy(&writer, 1); } } else { sqlite3_result_blob(context, geom->data, geom->length, SQLITE_TRANSIENT); } FUNCTION_END(context); }
static void GPKG_CheckSpatialMetaData(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_TEXT_ARG(db_name); FUNCTION_INT_ARG(check); FUNCTION_INT_ARG(type); FUNCTION_START(context); spatialdb = (spatialdb_t *)sqlite3_user_data(context); if (nbArgs == 0) { FUNCTION_SET_TEXT_ARG(db_name, "main"); FUNCTION_SET_INT_ARG(check, 0); } else if (nbArgs == 1) { FUNCTION_GET_TYPE(type, 0); if (type == SQLITE_TEXT) { FUNCTION_GET_TEXT_ARG(context, db_name, 0); } else { FUNCTION_SET_TEXT_ARG(db_name, "main"); FUNCTION_GET_INT_ARG(check, 0); } } else { FUNCTION_GET_TEXT_ARG(context, db_name, 0); FUNCTION_GET_INT_ARG(check, 1); } if (check != 0) { check = SQL_CHECK_ALL; } FUNCTION_RESULT = spatialdb->check_meta(FUNCTION_DB_HANDLE, db_name, check, FUNCTION_ERROR); if (FUNCTION_RESULT == SQLITE_OK) { sqlite3_result_null(context); } FUNCTION_END(context); FUNCTION_FREE_TEXT_ARG(db_name); FUNCTION_FREE_INT_ARG(check); FUNCTION_FREE_INT_ARG(type); }
static void ST_AsText(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_GEOM_ARG(geomblob); FUNCTION_START_STATIC(context, 256); spatialdb = (spatialdb_t *)sqlite3_user_data(context); FUNCTION_GET_GEOM_ARG_UNSAFE(context, spatialdb, geomblob, 0); wkt_writer_t writer; wkt_writer_init(&writer); FUNCTION_RESULT = spatialdb->read_geometry(&FUNCTION_GEOM_ARG_STREAM(geomblob), wkt_writer_geom_consumer(&writer), FUNCTION_ERROR); if (FUNCTION_RESULT == SQLITE_OK) { sqlite3_result_text(context, wkt_writer_getwkt(&writer), (int) wkt_writer_length(&writer), SQLITE_TRANSIENT); } wkt_writer_destroy(&writer); FUNCTION_END(context); FUNCTION_FREE_GEOM_ARG(geomblob); }
static void GPKG_LoadGEOS(sqlite3_context *context, int nbArgs, sqlite3_value **args) { geos_context_t *ctx = NULL; spatialdb_t *spatialdb; FUNCTION_TEXT_ARG(lib_path); FUNCTION_START(context); spatialdb = (spatialdb_t *)sqlite3_user_data(context); if (sqlite3_value_type(args[0]) != SQLITE_NULL) { FUNCTION_GET_TEXT_ARG_UNSAFE(lib_path, 0); } ctx = geos_context_init(spatialdb, lib_path, FUNCTION_ERROR); if (ctx != NULL) { geom_func_register(FUNCTION_DB_HANDLE, FUNCTION_ERROR, ctx); } FUNCTION_END(context); FUNCTION_FREE_TEXT_ARG(lib_path); if (ctx != NULL) { geos_context_release(ctx); } }
static void GPKG_InitSpatialMetaData(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_TEXT_ARG(db_name); FUNCTION_START(context); spatialdb = (spatialdb_t *)sqlite3_user_data(context); if (nbArgs == 0) { FUNCTION_SET_TEXT_ARG(db_name, "main"); } else { FUNCTION_GET_TEXT_ARG(context, db_name, 0); } FUNCTION_START_TRANSACTION(__initspatialdb); FUNCTION_RESULT = spatialdb->init_meta(FUNCTION_DB_HANDLE, db_name, FUNCTION_ERROR); FUNCTION_END_TRANSACTION(__initspatialdb); if (FUNCTION_RESULT == SQLITE_OK) { sqlite3_result_null(context); } FUNCTION_END(context); FUNCTION_FREE_TEXT_ARG(db_name); }
/* * Supports the following parameter lists: * 4: table, column, type, srid * 5: db, table, column, type, srid * 6: table, column, type, srid, z, m * 7: db, table, column, type, srid, z, m */ static void GPKG_AddGeometryColumn(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_TEXT_ARG(db_name); FUNCTION_TEXT_ARG(table_name); FUNCTION_TEXT_ARG(column_name); FUNCTION_TEXT_ARG(geometry_type); FUNCTION_INT_ARG(srs_id); FUNCTION_INT_ARG(z); FUNCTION_INT_ARG(m); FUNCTION_START(context); spatialdb = (spatialdb_t *)sqlite3_user_data(context); if (nbArgs == 4) { FUNCTION_SET_TEXT_ARG(db_name, "main"); FUNCTION_GET_TEXT_ARG(context, table_name, 0); FUNCTION_GET_TEXT_ARG(context, column_name, 1); FUNCTION_GET_TEXT_ARG(context, geometry_type, 2); FUNCTION_GET_INT_ARG(srs_id, 3); FUNCTION_SET_INT_ARG(z, 2); FUNCTION_SET_INT_ARG(m, 2); } else if (nbArgs == 5) { FUNCTION_GET_TEXT_ARG(context, db_name, 0); FUNCTION_GET_TEXT_ARG(context, table_name, 1); FUNCTION_GET_TEXT_ARG(context, column_name, 2); FUNCTION_GET_TEXT_ARG(context, geometry_type, 3); FUNCTION_GET_INT_ARG(srs_id, 4); } else if (nbArgs == 6) { FUNCTION_SET_TEXT_ARG(db_name, "main"); FUNCTION_GET_TEXT_ARG(context, table_name, 0); FUNCTION_GET_TEXT_ARG(context, column_name, 1); FUNCTION_GET_TEXT_ARG(context, geometry_type, 2); FUNCTION_GET_INT_ARG(srs_id, 3); FUNCTION_GET_INT_ARG(z, 4); FUNCTION_GET_INT_ARG(m, 5); } else { FUNCTION_GET_TEXT_ARG(context, db_name, 0); FUNCTION_GET_TEXT_ARG(context, table_name, 1); FUNCTION_GET_TEXT_ARG(context, column_name, 2); FUNCTION_GET_TEXT_ARG(context, geometry_type, 3); FUNCTION_GET_INT_ARG(srs_id, 4); FUNCTION_GET_INT_ARG(z, 5); FUNCTION_GET_INT_ARG(m, 6); } FUNCTION_START_TRANSACTION(__add_geom_col); FUNCTION_RESULT = spatialdb->init_meta(FUNCTION_DB_HANDLE, db_name, FUNCTION_ERROR); if (FUNCTION_RESULT == SQLITE_OK) { FUNCTION_RESULT = spatialdb->add_geometry_column(FUNCTION_DB_HANDLE, db_name, table_name, column_name, geometry_type, srs_id, z, m, FUNCTION_ERROR); } FUNCTION_END_TRANSACTION(__add_geom_col); if (FUNCTION_RESULT == SQLITE_OK) { sqlite3_result_null(context); } FUNCTION_END(context); FUNCTION_FREE_TEXT_ARG(db_name); FUNCTION_FREE_TEXT_ARG(table_name); FUNCTION_FREE_TEXT_ARG(column_name); FUNCTION_FREE_TEXT_ARG(geometry_type); FUNCTION_FREE_INT_ARG(srid); FUNCTION_FREE_INT_ARG(z); FUNCTION_FREE_INT_ARG(m); }