Esempio n. 1
0
//------------------------------------------------------------------------------
void ctkDICOMDatabase::openDatabase(const QString databaseFile, const QString& connectionName )
{
  Q_D(ctkDICOMDatabase);
  d->DatabaseFileName = databaseFile;
  d->Database = QSqlDatabase::addDatabase("QSQLITE", connectionName);
  d->Database.setDatabaseName(databaseFile);
  if ( ! (d->Database.open()) )
    {
    d->LastError = d->Database.lastError().text();
    return;
    }
  if ( d->Database.tables().empty() )
    {
    if (!initializeDatabase())
      {
      d->LastError = QString("Unable to initialize DICOM database!");
      return;
      }
    }
  if (!isInMemory())
    {
    QFileSystemWatcher* watcher = new QFileSystemWatcher(QStringList(databaseFile),this);
    connect(watcher, SIGNAL(fileChanged(QString)),this, SIGNAL (databaseChanged()) );
    }
}
Esempio n. 2
0
/**
 * This function provides a means to programmatically create a Database object.
 *
 * @param  file A reference to a String containing the database file details.
 *
 * @return  A reference to the Database object created.
 *
 */
VALUE rb_database_new(VALUE file) {
  VALUE database     = allocateDatabase(cDatabase),
        parameters[] = {file};

  initializeDatabase(1, parameters, database);

  return(database);
}
Esempio n. 3
0
int main(int argc, char *argv[]){

    initializeDatabase();
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();

}
Esempio n. 4
0
int main(int argc, char *argv[]) {
    struct sigaction action;
    memset(&action, 0, sizeof(action));
    action.sa_handler = handler;
    if (sigaction(SIGUSR1, &action, nullptr) < 0) {
      perror("sigaction");
      return 1;
    }

    QApplication a(argc, argv);

    try {
        initializeDatabase();
        auto& retrieveUuid = retrieveUuidQ();
        retrieveUuid.execute();
        std::string strUuid;
        if (! retrieveUuid.next(strUuid))
        {
            strUuid = boost::lexical_cast<std::string>(boost::uuids::random_generator()());
            auto& insertUuid = insertUuidC();
            insertUuid.execute(strUuid);
        }
        std::cout << "UUID = " << strUuid << std::endl;
        Server server(std::move(strUuid), 10001);
        // server.start();

        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "KarbowyDb");
        db.setDatabaseName("StacjaSzefa.db");
        if (! db.open()) {
            QMessageBox::critical(0, "Błąd otwarcia bazy danych",
                                  db.lastError().text() + "\n\n" +
                                  "Kliknij OK aby wyjść.",
                                  QMessageBox::Ok);
            return 1;
        }
        db.close();

        MainWindow w(server);
        w.show();
        int res =  a.exec();
        server.stop();
        shutdownDatabase();
        return res;
    } catch (std::exception &ex)
    {
        QMessageBox::critical(0, "Wyjątek",
                              QString(ex.what()) + "\n\n" +
                              "Kliknij OK aby wyjść.",
                              QMessageBox::Ok);
        return 1;
    }
}
Esempio n. 5
0
//------------------------------------------------------------------------------
void ctkDICOMDatabase::openDatabase(const QString databaseFile, const QString& connectionName )
{
  Q_D(ctkDICOMDatabase);
  d->DatabaseFileName = databaseFile;
  d->Database = QSqlDatabase::addDatabase("QSQLITE",connectionName);
  d->Database.setDatabaseName(databaseFile);
  if ( ! (d->Database.open()) )
    {
    d->LastError = d->Database.lastError().text();
    throw std::runtime_error(qPrintable(d->LastError));
    }
  if ( d->Database.tables().empty() )
    {
      initializeDatabase();
    }
  if (databaseFile != ":memory")
  {
    QFileSystemWatcher* watcher = new QFileSystemWatcher(QStringList(databaseFile),this);
    connect(watcher, SIGNAL( fileChanged(const QString&)),this, SIGNAL ( databaseChanged() ) );
  }
Esempio n. 6
0
int main(int argc, char *argv[])
{
	initializeDatabase();

	wiringPiSetup();

	printTime();
	printf(LANG_PROGRAM_TITLE);

	while (1) {
		int level = digitalRead(RECIEVE_PIN);

		int bitLength = findEncodedBitLength(level);
		decodeBitLength(bitLength);

		delayMicroseconds(50);

		globalLevelsCounter++;
	}
	return 0;
}
Esempio n. 7
0
void LogBook::init()
{
	qDebug() << "LogBook plugin - press Command-L to toggle Log Book view mode. Press ALT-L for configuration.";
	initializeDatabase();
	//Load the module's custom style sheets
	QFile styleSheetFile;
	styleSheetFile.setFileName(":/logbook/normalStyle.css");
	if(styleSheetFile.open(QFile::ReadOnly|QFile::Text)){
		normalStyleSheet = styleSheetFile.readAll();
	}
	styleSheetFile.close();
	styleSheetFile.setFileName(":/logbook/nightStyle.css");
	if(styleSheetFile.open(QFile::ReadOnly|QFile::Text)){
		nightStyleSheet = styleSheetFile.readAll();
	}
	styleSheetFile.close();

	configDialog = new LogBookConfigDialog(tableModels);
	sessionsDialog = new SessionsDialog(tableModels);
	targetsDialog = new TargetsDialog(tableModels);
	flagShowLogBook = false;
	initializeActions();
}
Esempio n. 8
0
OCStackResult OCRDDatabaseCheckResources(const char *interfaceType, const char *resourceType,
    OCDiscoveryPayload *discPayload)
{
    if (initializeDatabase(NULL) != OC_STACK_OK)
    {
        return OC_STACK_INTERNAL_SERVER_ERROR;
    }
    if (!interfaceType && !resourceType)
    {
        return OC_STACK_INVALID_QUERY;
    }
    OCResourcePayload *resourcePayload = (OCResourcePayload *)OICCalloc(1, sizeof(OCResourcePayload));
    if (!resourcePayload)
    {
        return OC_STACK_NO_MEMORY;
    }

    if (resourceType)
    {
        sqlite3_stmt *stmt = 0;
        const char *input = "SELECT * FROM RD_DEVICE_LINK_LIST INNER JOIN RD_LINK_RT ON " \
        "RD_DEVICE_LINK_LIST.INS=RD_LINK_RT.LINK_ID WHERE RD_LINK_RT.rt LIKE ? ";

        VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, input, -1, &stmt, NULL));
        VERIFY_SQLITE(sqlite3_bind_text(stmt, 1, resourceType, strlen(resourceType) + 1, SQLITE_STATIC));

        int res = sqlite3_step (stmt);
        if (res == SQLITE_ROW || res == SQLITE_DONE)
        {
            int id = sqlite3_column_int(stmt, 0);
            const unsigned char *uri = sqlite3_column_text(stmt, uri_index - 1);
            int bitmap = sqlite3_column_int(stmt, p_index - 1);
            int deviceId = sqlite3_column_int(stmt, d_index - 1);
            OIC_LOG_V(DEBUG, TAG, " %s %d", uri, deviceId);
            resourcePayload->uri = OICStrdup((char *)uri);
            if (!resourcePayload->uri)
            {
                OCDiscoveryResourceDestroy(resourcePayload);
                return OC_STACK_NO_MEMORY;
            }
            res = sqlite3_reset(stmt);
            VERIFY_SQLITE(res);

            sqlite3_stmt *stmtRT = 0;
            const char *rt = "SELECT rt FROM RD_LINK_RT WHERE LINK_ID=?";
            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, rt, -1, &stmtRT, NULL));
            VERIFY_SQLITE(sqlite3_bind_int(stmtRT, 1, id));
            while (SQLITE_ROW == sqlite3_step(stmtRT))
            {
                const unsigned char *rt1 = sqlite3_column_text(stmtRT, (rt_value_index - 1));
                appendStringLL(&resourcePayload->types, rt1);
            }

            sqlite3_stmt *stmtIF = 0;
            const char *itf = "SELECT if FROM RD_LINK_IF WHERE LINK_ID=?";
            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, itf, -1, &stmtIF, NULL));
            VERIFY_SQLITE(sqlite3_bind_int(stmtIF, 1, id));
            while (SQLITE_ROW == sqlite3_step(stmtIF))
            {
                const unsigned char *itf = sqlite3_column_text(stmtIF, (if_value_index - 1));
                appendStringLL(&resourcePayload->interfaces, itf);
            }

            resourcePayload->bitmap = bitmap & (OC_OBSERVABLE | OC_DISCOVERABLE);
            resourcePayload->secure = (bitmap & OC_SECURE) != 0;

            const char *address = "SELECT di, address FROM RD_DEVICE_LIST INNER JOIN RD_DEVICE_LINK_LIST ON " \
            "RD_DEVICE_LINK_LIST.DEVICE_ID = RD_DEVICE_LIST.ID WHERE RD_DEVICE_LINK_LIST.DEVICE_ID=?";

            sqlite3_stmt *stmt1 = 0;
            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, address, -1, &stmt1, NULL));
            VERIFY_SQLITE(sqlite3_bind_int(stmt1, 1, deviceId));
            // TODO: Right now, we have a bug where discovery payload can only send one device information.
            res = sqlite3_step(stmt1);
            if (res == SQLITE_ROW || res == SQLITE_DONE)
            {
                const unsigned char *di = sqlite3_column_text(stmt1, 0);
                const unsigned char *address = sqlite3_column_text(stmt1, 1);
                OIC_LOG_V(DEBUG, TAG, " %s %s", di, address);
                (discPayload)->baseURI = OICStrdup((char *)address);
                (discPayload)->sid = OICStrdup((char *)di);
            }
            OCDiscoveryPayloadAddNewResource(discPayload, resourcePayload);
        }
    }
    if (interfaceType)
    {
        sqlite3_stmt *stmt = 0;
        const char *input = "SELECT * FROM RD_DEVICE_LINK_LIST INNER JOIN RD_LINK_IF ON " \
        "RD_DEVICE_LINK_LIST.INS=RD_LINK_IF.LINK_ID WHERE RD_LINK_IF.if LIKE ? ";

        VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, input, -1, &stmt, NULL));
        VERIFY_SQLITE(sqlite3_bind_text(stmt, 1, interfaceType, strlen(interfaceType) + 1, SQLITE_STATIC));

        int res = sqlite3_step (stmt);
        if (res == SQLITE_ROW || res == SQLITE_DONE)
        {
            int id = sqlite3_column_int(stmt, 0);
            const unsigned char *uri = sqlite3_column_text(stmt, uri_index - 1);
            int bitmap = sqlite3_column_int(stmt, p_index - 1);
            int deviceId = sqlite3_column_int(stmt, d_index - 1);
            OIC_LOG_V(DEBUG, TAG, " %s %d", uri, deviceId);
            resourcePayload->uri = OICStrdup((char *)uri);
            if (!resourcePayload->uri)
            {
                OCDiscoveryResourceDestroy(resourcePayload);
                return OC_STACK_NO_MEMORY;
            }
            VERIFY_SQLITE(sqlite3_reset(stmt));

            sqlite3_stmt *stmtRT = 0;
            const char *rt = "SELECT rt FROM RD_LINK_RT WHERE LINK_ID=?";
            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, rt, -1, &stmtRT, NULL));
            VERIFY_SQLITE(sqlite3_bind_int(stmtRT, 1, id));
            while (SQLITE_ROW == sqlite3_step(stmtRT))
            {
                const unsigned char *rt1 = sqlite3_column_text(stmtRT, (rt_value_index - 1));
                appendStringLL(&resourcePayload->types, rt1);
            }

            sqlite3_stmt *stmtIF = 0;
            const char *itf = "SELECT if FROM RD_LINK_IF WHERE LINK_ID=?";
            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, itf, -1, &stmtIF, NULL));
            VERIFY_SQLITE(sqlite3_bind_int(stmtIF, 1, id));
            while (SQLITE_ROW == sqlite3_step (stmtIF))
            {
                const unsigned char *itf = sqlite3_column_text(stmtIF, (if_value_index - 1));
                appendStringLL(&resourcePayload->interfaces, itf);
            }

            resourcePayload->bitmap = bitmap & (OC_OBSERVABLE | OC_DISCOVERABLE);
            resourcePayload->secure = ((bitmap & OC_SECURE) != 0);

            const char *address = "SELECT di, address FROM RD_DEVICE_LIST INNER JOIN RD_DEVICE_LINK_LIST ON " \
            "RD_DEVICE_LINK_LIST.DEVICE_ID = RD_DEVICE_LIST.ID WHERE RD_DEVICE_LINK_LIST.DEVICE_ID=?";

            sqlite3_stmt *stmt1 = 0;
            VERIFY_SQLITE(sqlite3_prepare_v2(gRDDB, address, -1, &stmt1, NULL));
            VERIFY_SQLITE(sqlite3_bind_int(stmt1, 1, deviceId));

            res = sqlite3_step(stmt1);
            if (res == SQLITE_ROW || res == SQLITE_DONE)
            {
                const unsigned char *di = sqlite3_column_text(stmt1, 0);
                const unsigned char *address = sqlite3_column_text(stmt1, 1);
                OIC_LOG_V(DEBUG, TAG, " %s %s", di, address);
                (discPayload)->baseURI = OICStrdup((char *)address);
                (discPayload)->sid = OICStrdup((char *)di);
            }
            OCDiscoveryPayloadAddNewResource(discPayload, resourcePayload);
        }
    }
    return OC_STACK_OK;
}