int main(int argc, char *argv[]) { QApplication::setGraphicsSystem("raster"); QApplication a(argc, argv); QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); QString privatePathQt(QApplication::applicationDirPath()); QString path(privatePathQt); path = QDir::toNativeSeparators(path); Server server; if (!server.listen(QHostAddress::Any, 6177)) { std::cerr << "Failed to bind to port" << std::endl; return 1; } QDeclarativeView view; view.engine()->setOfflineStoragePath(path); QObject::connect((QObject*)view.engine(), SIGNAL(quit()), &a, SLOT(quit())); view.setSource(QUrl("qrc:/qml/main.qml")); view.show(); QString md5; QString dbname="DemoDB"; QByteArray ba; ba = QCryptographicHash::hash (dbname.toAscii(), QCryptographicHash::Md5); md5.append(ba.toHex()); md5.append(".sqlite"); path.append(QDir::separator()).append("Databases"); path.append(QDir::separator()).append(md5); QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(path); if (!db.open()) { std::cerr << "Cannot open database" << std::endl; return 1; } OrderManager orderManager; view.rootContext()->setContextProperty("server", &server); view.rootContext()->setContextProperty("orderManager", &orderManager); Client client; QObject::connect(&orderManager, SIGNAL(send()), &client, SLOT(sendOrder())); QObject::connect(&server, SIGNAL(paied(quint32)), &orderManager, SLOT(payOrder(quint32))); DeviceManager deviceManager; QObject::connect(&deviceManager, SIGNAL(registerSignal()), &client, SLOT(sendRegistration())); view.rootContext()->setContextProperty("deviceManager", &deviceManager); deviceManager.registerDevice(); return a.exec(); }
int main( int argc, char *argv[] ) { struct sigaction sigact; int rval = 0; sigact.sa_handler = sighandler; sigemptyset(&sigact.sa_mask); sigact.sa_flags = 0; sigaction(SIGINT, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); sigaction(SIGQUIT, &sigact, NULL); using namespace USB; DeviceManager mgr; theMgr = &mgr; try { mgr.registerDevice( SpacePilotDevice::VendorID, SpacePilotDevice::ProductID, &SpacePilotDevice::factory ); mgr.start(); if ( argc > 1 ) { std::shared_ptr<Device> sppro = mgr.findDevice( SpacePilotDevice::VendorID, SpacePilotDevice::ProductID ); if ( sppro ) { SpacePilotDevice *dev = reinterpret_cast<SpacePilotDevice *>( sppro.get() ); dev->setLCD( std::string( argv[1] ) ); } } mgr.processEventLoop(); } catch ( usb_error &e ) { int err = e.getUSBError(); libusb_error ec = (libusb_error)( err ); std::cerr << "ERROR: " << libusb_error_name( err ) << " - " << libusb_strerror( ec ) << std::endl; rval = -1; } catch ( ... ) { rval = -1; } mgr.shutdown(); theMgr = nullptr; return rval; }
void Device::registerDevice() { DeviceManager* manager = DeviceManager::getInstance(); return manager->registerDevice(this); }