void EventPlugin::emitDbEvent(const QString &domain, const QVariant &payload, bool loopback) { qfLogFuncFrame() << "domain:" << domain << "payload:" << payload; if(loopback) { // emit queued //emit dbEventNotify(domain, payload); QMetaObject::invokeMethod(this, "dbEventNotify", Qt::QueuedConnection, Q_ARG(QString, domain), Q_ARG(QVariant, payload)); } if(connectionType() == ConnectionType::SingleFile) return; //QVariantMap m; QJsonObject jso; jso[QLatin1String("event")] = eventName(); jso[QLatin1String("domain")] = domain; jso[QLatin1String("payload")] = QJsonValue::fromVariant(payload); QJsonDocument jsd(jso); QString payload_str = QString::fromUtf8(jsd.toJson(QJsonDocument::Compact)); payload_str = qf::core::sql::Connection::escapeJsonForSql(payload_str); qf::core::sql::Connection conn = qf::core::sql::Connection::forName(); QString qs = QString("NOTIFY ") + DBEVENT_NOTIFY_NAME + ", '" + payload_str + "'"; qfDebug() << conn.driver() << "executing SQL:" << qs; QSqlQuery q(conn); if(!q.exec(qs)) { qfError() << "emitDbEventNotify Error:" << qs << q.lastError().text(); } }
char* AdafruitIO::userAgent() { if(!_user_agent) { _user_agent = (char *)malloc(sizeof(char) * (strlen(version()) + strlen(boardType()) + strlen(connectionType()) + 24)); strcpy(_user_agent, "AdafruitIO-Arduino/"); strcat(_user_agent, version()); strcat(_user_agent, " ("); strcat(_user_agent, boardType()); strcat(_user_agent, "-"); strcat(_user_agent, connectionType()); strcat(_user_agent, ")"); } return _user_agent; }
void Bindable::callSlotObject(Detail::Binding binding, void **args) { if (connectionType(binding.m_receiver) == Qt::BlockingQueuedConnection) { QSemaphore semaphore; QMetaCallEvent *ev = new QMetaCallEvent(binding.m_object, nullptr, -1, 0, 0, args, &semaphore); QCoreApplication::postEvent(const_cast<QObject *>(binding.m_receiver), ev); semaphore.acquire(); } else { binding.m_object->call(const_cast<QObject *>(binding.m_receiver), args); } }
void EventPlugin::importEvent_qbe() { qfLogFuncFrame(); qff::MainWindow *fwk = qff::MainWindow::frameWork(); /* if(connectionType() != ConnectionType::SqlServer) { qfd::MessageBox::showError(fwk, tr("Data file can be imported to SQL server only!")); return; } */ QString ext = ".qbe"; QString fn = qf::qmlwidgets::dialogs::FileDialog::getOpenFileName (fwk, tr("Import as Quick Event"), QString(), "Quick Event files *.qbe (*.qbe)"); if(fn.isEmpty()) return; QString event_name = QInputDialog::getText(fwk, tr("Query"), tr("Event will be imported as ID:")).trimmed(); if(event_name.isEmpty()) return; QStringList existing_events = (connectionType() == ConnectionType::SingleFile)? existingFileEventNames(): existingSqlEventNames(); if(existing_events.contains(event_name)) { qfd::MessageBox::showError(fwk, tr("Event ID '%1' exists already!").arg(event_name)); return; } QString err_str; QString import_connection_name = QStringLiteral("qe_import_connection"); QString export_connection_name = QStringLiteral("qe_export_connection"); do { qfs::Connection current_conn = qfs::Connection::forName(); qfs::Connection imp_conn(QSqlDatabase::addDatabase("QSQLITE", import_connection_name)); imp_conn.setDatabaseName(fn); qfInfo() << "Opening import database file" << fn; if(!imp_conn.open()) { qfd::MessageBox::showError(fwk, tr("Open Database Error: %1").arg(imp_conn.errorString())); return; } qfs::Connection exp_conn(QSqlDatabase::addDatabase(current_conn.driverName(), export_connection_name)); if(connectionType() == ConnectionType::SingleFile) { exp_conn.setDatabaseName(eventNameToFileName(event_name)); } else { exp_conn.setHostName(current_conn.hostName()); exp_conn.setPort(current_conn.port()); exp_conn.setUserName(current_conn.userName()); exp_conn.setPassword(current_conn.password()); exp_conn.setDatabaseName(current_conn.databaseName()); } qfInfo() << "Opening export database:" << exp_conn.databaseName(); if(!exp_conn.open()) { qfd::MessageBox::showError(fwk, tr("Open Database Error: %1").arg(exp_conn.errorString())); return; } qfs::Transaction transaction(exp_conn); DbSchema db_schema = dbSchema(); auto tables = db_schema.tables(); int step_cnt = tables.count() + 1; int step_no = 0; fwk->showProgress(tr("Creating database"), ++step_no, step_cnt); { DbSchema::CreateDbSqlScriptOptions create_options; create_options.setDriverName(exp_conn.driverName()); create_options.setSchemaName(event_name); QStringList create_script = db_schema.createDbSqlScript(create_options); qfs::Query ex_q(exp_conn); if(!run_sql_script(ex_q, create_script)) { err_str = tr("Create Database Error: %1").arg(ex_q.lastError().text()); break; } } exp_conn.setCurrentSchema(event_name); for(QObject *table : tables) { QString table_name = table->property("name").toString(); qfDebug() << "Copying table" << table_name; fwk->showProgress(tr("Copying table %1").arg(table_name), ++step_no, step_cnt); QSqlRecord rec = db_schema.sqlRecord(table, true); err_str = copy_sql_table(table_name, rec, imp_conn, exp_conn); if(!err_str.isEmpty()) break; } if(!err_str.isEmpty()) break; transaction.commit(); } while(false); QSqlDatabase::removeDatabase(import_connection_name); QSqlDatabase::removeDatabase(export_connection_name); fwk->hideProgress(); if(!err_str.isEmpty()) { qfd::MessageBox::showError(fwk, err_str); return; } if(qfd::MessageBox::askYesNo(fwk, tr("Open imported event '%1'?").arg(event_name))) { openEvent(event_name); } }
bool EventPlugin::createEvent(const QString &event_name, const QVariantMap &event_params) { qfLogFuncFrame(); closeEvent(); qff::MainWindow *fwk = qff::MainWindow::frameWork(); EventPlugin::ConnectionType connection_type = connectionType(); QStringList existing_event_ids; if(connection_type == ConnectionType::SingleFile) existing_event_ids = existingFileEventNames(); else existing_event_ids = existingSqlEventNames(); QString event_id = event_name; QVariantMap new_params = event_params; do { qfd::Dialog dlg(fwk); dlg.setButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); EventDialogWidget *event_w = new EventDialogWidget(); event_w->setEventId(event_id); event_w->loadParams(new_params); dlg.setCentralWidget(event_w); if(!dlg.exec()) return false; event_id = event_w->eventId(); new_params = event_w->saveParams(); if(event_id.isEmpty()) { qf::qmlwidgets::dialogs::MessageBox::showError(fwk, tr("Event ID cannot be empty.")); continue; } if(existing_event_ids.contains(event_id)) { qf::qmlwidgets::dialogs::MessageBox::showError(fwk, tr("Event ID %1 exists already.").arg(event_id)); continue; } break; } while(true); bool ok = false; Event::EventConfig event_config; //ConnectionSettings connection_settings; event_config.setValue("event", new_params); int stage_count = event_params.value("stageCount").toInt(); if(stage_count == 0) stage_count = event_config.stageCount(); qfInfo() << "createEvent, stage_count:" << stage_count; QF_ASSERT(stage_count > 0, "Stage count have to be greater than 0", return false); qfInfo() << "will create:" << event_id; qfs::Connection conn = qfs::Connection::forName(); //QF_ASSERT(conn.isOpen(), "Connection is not open", return false); if(connection_type == ConnectionType::SingleFile) { QString event_fn = eventNameToFileName(event_id); conn.close(); conn.setDatabaseName(event_fn); conn.open(); } if(conn.isOpen()) { QVariantMap create_options; create_options["schemaName"] = event_id; create_options["driverName"] = conn.driverName(); QVariant ret_val; QMetaObject::invokeMethod(this, "createDbSqlScript", Qt::DirectConnection, Q_RETURN_ARG(QVariant, ret_val), Q_ARG(QVariant, create_options)); QStringList create_script = ret_val.toStringList(); qfInfo().nospace() << create_script.join(";\n") << ';'; qfs::Query q(conn); do { qfs::Transaction transaction(conn); ok = run_sql_script(q, create_script); if(!ok) break; qfDebug() << "creating stages:" << stage_count; QString stage_table_name = "stages"; if(connection_type == ConnectionType::SqlServer) stage_table_name = event_id + '.' + stage_table_name; q.prepare("INSERT INTO " + stage_table_name + " (id) VALUES (:id)"); for(int i=0; i<stage_count; i++) { q.bindValue(":id", i+1); ok = q.exec(); if(!ok) { break; } } if(!ok) break; conn.setCurrentSchema(event_id); event_config.save(); transaction.commit(); } while(false); if(!ok) { qfd::MessageBox::showError(fwk, tr("Create Database Error: %1").arg(q.lastError().text())); } } else { qfd::MessageBox::showError(fwk, tr("Cannot create event, database is not open: %1").arg(conn.lastError().text())); } if(ok) { ok = openEvent(event_id); } return ok; }
QgsNewHttpConnection::QgsNewHttpConnection( QWidget *parent, ConnectionTypes types, const QString &baseKey, const QString &connectionName, QgsNewHttpConnection::Flags flags, Qt::WindowFlags fl ) : QDialog( parent, fl ) , mTypes( types ) , mBaseKey( baseKey ) , mOriginalConnName( connectionName ) { setupUi( this ); connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsNewHttpConnection::showHelp ); QRegExp rx( "/connections-([^/]+)/" ); if ( rx.indexIn( baseKey ) != -1 ) { QString connectionType( rx.cap( 1 ).toUpper() ); if ( connectionType == QLatin1String( "WMS" ) ) { connectionType = QStringLiteral( "WMS/WMTS" ); } setWindowTitle( tr( "Create a New %1 Connection" ).arg( connectionType ) ); } // It would be obviously much better to use mBaseKey also for credentials, // but for some strange reason a different hardcoded key was used instead. // WFS and WMS credentials were mixed with the same key WMS. // Only WMS and WFS providers are using QgsNewHttpConnection at this moment // using connection-wms and connection-wfs -> parse credential key fro it. mCredentialsBaseKey = mBaseKey.split( '-' ).last().toUpper(); txtName->setValidator( new QRegExpValidator( QRegExp( "[^\\/]+" ), txtName ) ); cmbDpiMode->clear(); cmbDpiMode->addItem( tr( "all" ) ); cmbDpiMode->addItem( tr( "off" ) ); cmbDpiMode->addItem( tr( "QGIS" ) ); cmbDpiMode->addItem( tr( "UMN" ) ); cmbDpiMode->addItem( tr( "GeoServer" ) ); cmbVersion->clear(); cmbVersion->addItem( tr( "Maximum" ) ); cmbVersion->addItem( tr( "1.0" ) ); cmbVersion->addItem( tr( "1.1" ) ); cmbVersion->addItem( tr( "2.0" ) ); connect( cmbVersion, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsNewHttpConnection::wfsVersionCurrentIndexChanged ); connect( cbxWfsFeaturePaging, &QCheckBox::stateChanged, this, &QgsNewHttpConnection::wfsFeaturePagingStateChanged ); if ( !connectionName.isEmpty() ) { // populate the dialog with the information stored for the connection // populate the fields with the stored setting parameters QgsSettings settings; QString key = mBaseKey + connectionName; QString credentialsKey = "qgis/" + mCredentialsBaseKey + '/' + connectionName; txtName->setText( connectionName ); txtUrl->setText( settings.value( key + "/url" ).toString() ); updateServiceSpecificSettings(); // Authentication mAuthSettings->setUsername( settings.value( credentialsKey + "/username" ).toString() ); mAuthSettings->setPassword( settings.value( credentialsKey + "/password" ).toString() ); mAuthSettings->setConfigId( settings.value( credentialsKey + "/authcfg" ).toString() ); } mWfsVersionDetectButton->setDisabled( txtUrl->text().isEmpty() ); if ( !( mTypes & ConnectionWms ) && !( mTypes & ConnectionWcs ) ) { mWmsOptionsGroupBox->setVisible( false ); mGroupBox->layout()->removeWidget( mWmsOptionsGroupBox ); } if ( !( mTypes & ConnectionWfs ) ) { mWfsOptionsGroupBox->setVisible( false ); mGroupBox->layout()->removeWidget( mWfsOptionsGroupBox ); } if ( mTypes & ConnectionWcs ) { cbxIgnoreGetMapURI->setText( tr( "Ignore GetCoverage URI reported in capabilities" ) ); cbxWmsIgnoreAxisOrientation->setText( tr( "Ignore axis orientation" ) ); if ( !( mTypes & ConnectionWms ) ) { mWmsOptionsGroupBox->setTitle( tr( "WCS Options" ) ); cbxIgnoreGetFeatureInfoURI->setVisible( false ); mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI ); cmbDpiMode->setVisible( false ); mGroupBox->layout()->removeWidget( cmbDpiMode ); lblDpiMode->setVisible( false ); mGroupBox->layout()->removeWidget( lblDpiMode ); txtReferer->setVisible( false ); mGroupBox->layout()->removeWidget( txtReferer ); lblReferer->setVisible( false ); mGroupBox->layout()->removeWidget( lblReferer ); } } if ( !( flags & FlagShowTestConnection ) ) { mTestConnectionButton->hide(); mGroupBox->layout()->removeWidget( mTestConnectionButton ); } if ( flags & FlagHideAuthenticationGroup ) { mAuthGroupBox->hide(); mGroupBox->layout()->removeWidget( mAuthGroupBox ); } // Adjust height int w = width(); adjustSize(); resize( w, height() ); connect( txtName, &QLineEdit::textChanged, this, &QgsNewHttpConnection::nameChanged ); connect( txtUrl, &QLineEdit::textChanged, this, &QgsNewHttpConnection::urlChanged ); buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true ); connect( txtName, &QLineEdit::textChanged, this, &QgsNewHttpConnection::updateOkButtonState ); connect( txtUrl, &QLineEdit::textChanged, this, &QgsNewHttpConnection::updateOkButtonState ); nameChanged( connectionName ); }
bool KMSmtpClient::connectToHost() { //Check out the socket pointer. if(socket()==nullptr) { qCritical()<<"Socket pointer is NULL."; return false; } //Check out the connection type. switch (connectionType()) { case TlsConnection: case TcpConnection: qDebug()<<"Start normal link, host:"<<host()<<"port:"<<port(); //Simply call the connect to host function. socket()->connectToHost(host(), port()); break; case SslConnection: qDebug()<<"Start SSL link, host:"<<host()<<"port:"<<port(); //Recast socket as a QSslSocket. static_cast<QSslSocket *>(socket())->connectToHostEncrypted(host(), port()); break; } qDebug()<<"Start to connect."; //Tries to connect to server if(!socket()->waitForConnected(connectionTimeout())) { //Emit the error. emit clientError(ConnectionTimeoutError); //Failed to connect. return false; } // If the response code is not 220 (Service ready) // means that is something wrong with the server //The response code needs to be 220. if(!waitAndCheckResponse(220, ServerError)) { //Failed to login. return false; } qDebug()<<"Start EHLO"; // Send a EHLO/HELO message to the server // The client's first command must be EHLO/HELO sendMessage("EHLO " + userName()); //The response code needs to be 250. if(!waitAndCheckResponse(250, ServerError)) { //Failed to login. return false; } //If the connection type is TLS connection, we have to start TLS. if(connectionType() == TlsConnection) { //Send a request to start TLS handshake. sendMessage("STARTTLS"); //The response code needs to be 220. if(!waitAndCheckResponse(220, ServerError)) { //Failed to login. return false; } //Recast the socket into ssl socket. QSslSocket *sslSocket=static_cast<QSslSocket *>(socket()); //Start encryption. qDebug()<<"Start encryption."; sslSocket->startClientEncryption(); sslSocket->ignoreSslErrors(); //Check out result. if(!sslSocket->waitForEncrypted(connectionTimeout())) { //Print out the error information. qCritical()<<sslSocket->errorString(); //Emit the smtp error. emit clientError(ConnectionTimeoutError); //Failed to connect. return false; } qDebug()<<"Start EHLO again"; // Send ELHO one more time sendMessage("EHLO " + userName()); //The response code needs to be 250. if(!waitAndCheckResponse(250, ServerError)) { //Failed to login. return false; } } //Mission complete. return true; }
// Initialize GLUT & OpenSG and start the cluster server int main(int argc,char **argv) { #ifdef WIN32 OSG::preloadSharedObject("OSGFileIO"); OSG::preloadSharedObject("OSGImageFileIO"); OSG::preloadSharedObject("OSGEffectGroups"); #endif ChangeList::setReadWriteDefault(); osgInit(argc, argv); std::string name("ClusterServer"); std::string connectionType("StreamSock"); std::string address("127.0.0.1"); bool fullscreen = true; bool always_on_top = false; bool stereo = false; WindowGeometry geometry = {0,0,500,500}; if (!parseCmdLineArgs(argc, argv, name, connectionType, address, geometry, fullscreen, always_on_top, stereo)) return 0; printConfiguration(name, address, connectionType, stereo, fullscreen, always_on_top); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (stereo ? GLUT_STEREO : 0)); glutInitWindowPosition(geometry.x, geometry.y); glutInitWindowSize(geometry.w, geometry.h); int winid = glutCreateWindow(name.c_str()); if(fullscreen) { glutFullScreen(); } if (always_on_top) { setAlwaysOnTop(name); } glutDisplayFunc(display); glutIdleFunc(display); glutReshapeFunc(reshape); glutSetCursor(GLUT_CURSOR_NONE); ract = RenderAction::create(); window = GLUTWindow::create(); OSGCompat::setGlutId(window, winid); window->init(); bool failed = false; do { try { delete server; server = new ClusterServer(window, name, connectionType, address); server->start(); failed = false; } catch (OSG_STDEXCEPTION_NAMESPACE::exception& e) { SLOG << "ERROR: " << e.what() << endLog; SLOG << "Attempting to restart ClusterServer..." << endLog; failed = true; } } while (failed); glutMainLoop(); return 0; }