//---------------------------------------------------------------------------- void ctkPluginStorageSQL::open() { createDatabaseDirectory(); QSqlDatabase database = getConnection(); //Check if the sqlite version supports foreign key constraints QSqlQuery query(database); if (!query.exec("PRAGMA foreign_keys")) { close(); throw ctkPluginDatabaseException(QString("Check for foreign key support failed."), ctkPluginDatabaseException::DB_SQL_ERROR); } if (!query.next()) { close(); throw ctkPluginDatabaseException(QString("SQLite db does not support foreign keys. It is either older than 3.6.19 or was compiled with SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER"), ctkPluginDatabaseException::DB_SQL_ERROR); } query.finish(); query.clear(); //Enable foreign key support if (!query.exec("PRAGMA foreign_keys = ON")) { close(); throw ctkPluginDatabaseException(QString("Enabling foreign key support failed."), ctkPluginDatabaseException::DB_SQL_ERROR); } query.finish(); //Check database structure (tables) and recreate tables if neccessary //If one of the tables is missing remove all tables and recreate them //This operation is required in order to avoid data coruption if (!checkTables()) { if (dropTables()) { createTables(); } else { //dropTables() should've handled error message //and warning close(); } } // silently remove any plugin marked as uninstalled cleanupDB(); //Update database based on the recorded timestamps updateDB(); initNextFreeIds(); }
void testApp::tuioCursorUpdated(TuioCursor & tcur){ cout << " cursor updated: " + ofToString(tcur.getCursorID())+ " X: "+ofToString(tcur.getXSpeed())+ " Y: "+ofToString(tcur.getYSpeed()) << endl; updateDB(tcur.getCursorID(), time(NULL), tcur.getX(), tcur.getY()); //forward the touch events to ofxMultiTouch for the InteractiveObjects // ofxMultiTouch.touchMoved(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); }
void testApp::tuioCursorRemoved(TuioCursor & tcur){ // cout << " cursor removed: " + ofToString(tcur.getCursorID())+ // " X: "+ofToString(tcur.getX())+ // " Y: "+ofToString(tcur.getY()) // << endl; updateDB(tcur.getCursorID(), time(NULL), tcur.getX(), tcur.getY()); //forward the touch events to ofxMultiTouch for the InteractiveObjects // ofxMultiTouch.touchUp(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); }
void testApp::tuioCursorAdded(TuioCursor & tcur){ cout << " cursor added: " + ofToString(tcur.getCursorID())+ " X: "+ofToString(tcur.getX())+ " Y: "+ofToString(tcur.getY()) << endl; // cout << ofToString(touch.id) << ofToString((int)time(NULL)) << ofToString(touch.x) << endl; updateDB(tcur.getCursorID(), time(NULL), tcur.getX(), tcur.getY()); //forward the touch events to ofxMultiTouch for the InteractiveObjects // ofxMultiTouch.touchDown(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); }
/************************************************************************** * Function: UpdateItem * Functionality: update the database item * @IN : zDB: database handle Item: the database item name value: the item value * @OUT: * Used description: this function check the database and update or insert the item. * Date: 20080117 * Changed history: * Date Who Reason * 20080117 sandy First creation ***************************************************************************/ void UpdateItem(PZDB_HANDLE zDB, char *Item, char * value) { char *TmpVal = NULL; int ret = -1; if(value) { ret = GetValueFromDB(zDB, Item , &TmpVal); if(TmpVal == NULL || strcmp(value, TmpVal) != 0) updateDB(zDB, Item , value); } z_free(TmpVal); }
void GameScannerThread::run(void) { RunProlog(); LOG(VB_GENERAL, LOG_INFO, QString("Beginning Game Scan.")); m_files.clear(); m_remove.clear(); m_dbgames = RomInfo::GetAllRomInfo(); buildFileList(); verifyFiles(); updateDB(); RunEpilog(); }
void VideoScannerThread::run() { RunProlog(); VideoMetadataListManager::metadata_list ml; VideoMetadataListManager::loadAllFromDatabase(ml); m_dbmetadata->setList(ml); QList<QByteArray> image_types = QImageReader::supportedImageFormats(); QStringList imageExtensions; for (QList<QByteArray>::const_iterator p = image_types.begin(); p != image_types.end(); ++p) { imageExtensions.push_back(QString(*p)); } LOG(VB_GENERAL, LOG_INFO, QString("Beginning Video Scan.")); uint counter = 0; FileCheckList fs_files; if (m_HasGUI) SendProgressEvent(counter, (uint)m_directories.size(), tr("Searching for video files")); for (QStringList::const_iterator iter = m_directories.begin(); iter != m_directories.end(); ++iter) { if (!buildFileList(*iter, imageExtensions, fs_files)) { if (iter->startsWith("myth://")) { QUrl sgurl = *iter; QString host = sgurl.host().toLower(); QString path = sgurl.path(); m_liveSGHosts.removeAll(host); LOG(VB_GENERAL, LOG_ERR, QString("Failed to scan :%1:").arg(*iter)); } } if (m_HasGUI) SendProgressEvent(++counter); } PurgeList db_remove; verifyFiles(fs_files, db_remove); m_DBDataChanged = updateDB(fs_files, db_remove); if (m_DBDataChanged) { QCoreApplication::postEvent(m_parent, new VideoScanChanges(m_addList, m_movList, m_delList)); QStringList slist; QList<int>::const_iterator i; for (i = m_addList.begin(); i != m_addList.end(); ++i) slist << QString("added::%1").arg(*i); for (i = m_movList.begin(); i != m_movList.end(); ++i) slist << QString("moved::%1").arg(*i); for (i = m_delList.begin(); i != m_delList.end(); ++i) slist << QString("deleted::%1").arg(*i); MythEvent me("VIDEO_LIST_CHANGE", slist); gCoreContext->SendEvent(me); } else gCoreContext->SendMessage("VIDEO_LIST_NO_CHANGE"); RunEpilog(); }
int writequeue(char slavetype, char slavename, char addresstype, int address, int value) { //First update internal DB updateDB(slavetype,slavename, addresstype,address,value); //This needs to be written to slaves switch (slavetype) { case ENVIRONMENTAL_CONTROL: switch (slavename) { case BEDROOM: setmodbusslave(4); switch (addresstype) { case REGISTERS: write_single_register(address - 1,value); return 1; case COILS: write_single_coil(address - 1,value); return 1; break; } case SALOON: setmodbusslave(3); switch (addresstype) { case REGISTERS: write_single_register(address - 1,value); return 1; case COILS: write_single_coil(address - 1,value); return 1; break; } } case GENERAL_BOARD: switch (slavename){ case GENERAL_ENGINE: setmodbusslave(0); switch (addresstype) { case REGISTERS: write_single_register(address - 1,value); return 1; case COILS: write_single_coil(address - 1,value); return 1; break; } break; } case LCD_CONTROL: setmodbusslave(1); switch (addresstype) { case ALARM: write_single_coil(address - 1,value); break; case WARNING: write_single_coil(address - 1, value); break; default: write_single_register(address - 1,value); break; break; } setmodbusslave(2); switch (addresstype) { case ALARM: write_single_coil(address - 1,value); break; case WARNING: write_single_coil(address - 1, value); break; default: write_single_register(address - 1,value); break; break; } } return 0; }
int managelcdalarms() { //Alarms also need to be monitored. Check Alarm States, then changed value on DB and in registers //Currently untested uint buffer, buffer2; // Engine Temperature Coils buffer = senddatatoGUI(LCD_CONTROL,SALOON,ENGINE,REG_ENG_TEMPSENSOR); buffer2 = senddatatoGUI(LCD_CONTROL,SALOON,ENGINE,REG_ENG_HITEMPWARN); updateDB(LCD_CONTROL,SALOON,WARNING,COIL_WARN_HIGHTEMP,(buffer > buffer2)); getqueuedata(LCD_CONTROL,SALOON,WARNING,COIL_WARN_HIGHTEMP, (buffer > buffer2)); buffer2 = senddatatoGUI(LCD_CONTROL,SALOON,ENGINE,REG_ENG_HITEMPALRM); updateDB(LCD_CONTROL,SALOON,ALARM,COIL_ALRM_HIGHTEMP,(buffer > buffer2)); getqueuedata(LCD_CONTROL,SALOON,ALARM,COIL_ALRM_HIGHTEMP, (buffer > buffer2)); // Portable Water Coils buffer = senddatatoGUI(LCD_CONTROL,SALOON,TANKS,REG_TANKS_POTWATSTATUS); buffer2 = senddatatoGUI(LCD_CONTROL,SALOON,TANKS,REG_TANKS_POTWATWARN); updateDB(LCD_CONTROL,SALOON,WARNING,COIL_WARN_POTWATERLOW, (buffer < buffer2)); getqueuedata(LCD_CONTROL,SALOON,WARNING,COIL_WARN_POTWATERLOW, (buffer < buffer2)); buffer2 = senddatatoGUI(LCD_CONTROL,SALOON,TANKS,REG_TANKS_POTWATALARM); updateDB(LCD_CONTROL,SALOON,WARNING,COIL_ALRM_POTWATERLOW, (buffer < buffer2)); getqueuedata(LCD_CONTROL,SALOON,WARNING,COIL_ALRM_POTWATERLOW, (buffer < buffer2)); // Waste Water Coil buffer = senddatatoGUI(LCD_CONTROL,SALOON,TANKS,REG_TANKS_WSWATSTATUS); buffer2 = senddatatoGUI(LCD_CONTROL,SALOON,TANKS,REG_TANKS_WSWATALARM); updateDB(LCD_CONTROL,SALOON,WARNING,COIL_ALRM_WASTEWATHIGH, (buffer > buffer2)); getqueuedata(LCD_CONTROL,SALOON,WARNING,COIL_ALRM_WASTEWATHIGH, (buffer > buffer2)); // Waste Filler Coil buffer = senddatatoGUI(LCD_CONTROL,SALOON,TANKS,REG_TANKS_WSFILLSTATUS); buffer2 = senddatatoGUI(LCD_CONTROL,SALOON,TANKS,REG_TANKS_WSFILLALARM); updateDB(LCD_CONTROL,SALOON,WARNING,COIL_ALRM_WASTEFILLLOW, (buffer < buffer2)); getqueuedata(LCD_CONTROL,SALOON,WARNING,COIL_ALRM_WASTEFILLLOW, (buffer < buffer2)); //Inverter Fault Coil buffer = senddatatoGUI(LCD_CONTROL,SALOON,DCSYS,REG_DCSYS_INVERTERFAULT); updateDB(LCD_CONTROL,SALOON,ALARM,COIL_ALRM_INVFAULT, (buffer > 0)); getqueuedata(LCD_CONTROL, SALOON,ALARM,COIL_ALRM_INVFAULT, (buffer > 0)); //Inverter Low Battery buffer = senddatatoGUI(LCD_CONTROL,SALOON,DCSYS, REG_DCSYS_INVERTLOWBATT); updateDB(LCD_CONTROL,SALOON,ALARM,COIL_ALRM_INVLOWBAT, (buffer > 0)); getqueuedata(LCD_CONTROL,SALOON,ALARM,COIL_ALRM_INVLOWBAT, (buffer > 0)); //Inverter Overload buffer = senddatatoGUI(LCD_CONTROL,SALOON,DCSYS,REG_DCSYS_INVERTOVERLOAD); updateDB(LCD_CONTROL,SALOON,ALARM,COIL_ALRM_INVOVERLOAD, (buffer > 0)); getqueuedata(LCD_CONTROL,SALOON,ALARM,COIL_ALRM_INVOVERLOAD, (buffer > 0)); //Inverter Overtemp buffer = senddatatoGUI(LCD_CONTROL,SALOON,DCSYS,REG_DCSYS_INVERTOVERTEMP); updateDB(LCD_CONTROL,SALOON,ALARM,COIL_ALRM_INVOVERTEMP, (buffer > 0)); getqueuedata(LCD_CONTROL,SALOON,ALARM,COIL_ALRM_INVOVERLOAD, (buffer > 0)); //Bilge Pump Run Long // Uhh whats the condition for this? return 1; }
static int SetFriendlyName(char *file, char *newname, int status) { int iRet = 0; IXML_Document * doc = NULL; IXML_NodeList * nodelist = NULL; IXML_Node * node = NULL; char * escapeStr = NULL; void * zdbhandle = NULL; if(ZDBOpen(Z_UTIL_ZQDEV,DBfile,&zdbhandle) != Z_SUCCESS){ fprintf(stderr,"open db error\n"); return 0; } if(!newname || !file){ iRet = -3; goto FuncOut; } doc = ixmlLoadDocument(file); if(!doc){ fprintf(stderr, "Document not parsed successfully."); iRet = -1; goto FuncOut; } if((nodelist = ixmlDocument_getElementsByTagName(doc, "friendlyName"))!= NULL){ node = ixmlNodeList_item(nodelist, 0); node = ixmlNode_getFirstChild(node); if(node != NULL) { if(strlen(newname) > 0) iRet = ixmlNode_setNodeValue(node, newname); if(iRet == IXML_SUCCESS){ iRet = 0; if(ixmlUpdateDocument(doc, file)==0) { //update the zconfig database by jyan 09-06-08 if(!strcmp(file,DMSCFGFILE)) updateDB(zdbhandle,"LocalDMSName",newname); else updateDB(zdbhandle,"LocalDMRName",newname); } else fprintf(stderr,"Update Document fail!!"); goto FuncOut; } else { iRet = -32; goto FuncOut; } } } FuncOut: if(escapeStr) { free(escapeStr); escapeStr = NULL; } if(nodelist) ixmlNodeList_free(nodelist); if(doc) ixmlDocument_free(doc); ZDBClose(zdbhandle); return iRet; }
/************************************************************************** * Function: BringUpNetwork * Functionality: start the network. * @IN :zDB: the database handle IPConfig : the struct contain the ip address needed by setup network NETWORK: render start wired or wifi network. * @OUT: 0 OK else error * Used description: start the wifi or wired network * Date: 20080117 * Changed history: * Date Who Reason * 20080117 sandy First creation ***************************************************************************/ int BringUpNetwork(PZDB_HANDLE zDB , PIPConfig IPConfig, NETWORK_TYPE NETWORK, PWifiConfig WifiParam) { int ret = -1; char exec[512] = {0}; //WifiConfig WifiParam; if(NETWORK == WIRE_NETWORK) { if(isRunning(WIFIDEVICE) == RUNNING) { if(downNetwork(WIFIDEVICE)) { fprintf(stderr,"down the network wired error\n"); return ret; } DHCPDisable(1); } if(isRunning(WIREDEVICE) == DOWN) { if(upNetwork(WIREDEVICE)) { fprintf(stderr,"up the network wired error\n"); return ret; } } if(isRunning(WIREDEVICE) == RUNNING){ if(strcmp(IPConfig->DHCPEnable, "1") == 0){ ret = DHCPEnable(0,""); UpdateItem(zDB,"DHCPStatus","1"); } else if(strcmp(IPConfig->DHCPEnable, "0") == 0){ ret = UpStaticNet(IPConfig, 0); UpdateItem(zDB,"DHCPStatus","0"); } } updateDB(zDB, "WiEnable", "0"); return ret; } else if(NETWORK == WIFI_NETWORK) { if(isRunning(WIREDEVICE) == RUNNING) { if(downNetwork(WIREDEVICE)) { fprintf(stderr,"down the network mwl0 error\n"); return ret; } DHCPDisable(0); } /*********************************************************** if the wifi is down excute singal join or autojoin else if wifi is up, just excute singal join ***********************************************************/ if(isRunning(WIFIDEVICE) == DOWN) { if(upNetwork(WIFIDEVICE)) { fprintf(stderr,"Up the network mwl0 error\n"); return ret; } if(isRunning(WIFIDEVICE) == RUNNING) { //first signal join, if failed excute the auto join ret = StartWifiWithConfig(zDB, WifiParam); if(ret) { sprintf(exec,"%s/AutoJoin >/dev/null 2>&1 &",COMMAND_PATH); ret = OpenPipe(exec); } if(strcmp(IPConfig->DHCPEnable, "1") == 0){ ret = DHCPEnable(1,""); UpdateItem(zDB,"DHCPStatus","1"); } else if( strcmp(IPConfig->DHCPEnable, "0") == 0){ ret = UpStaticNet(IPConfig, 1); UpdateItem(zDB,"DHCPStatus","0"); } } } else if(isRunning(WIFIDEVICE) == RUNNING) { //just excute signal join. ret = StartWifiWithConfig(zDB, WifiParam); if(strcmp(IPConfig->DHCPEnable, "1") == 0){ ret = DHCPEnable(1,""); UpdateItem(zDB,"DHCPStatus","1"); } else if( strcmp(IPConfig->DHCPEnable, "0") == 0){ ret = UpStaticNet(IPConfig, 1); UpdateItem(zDB,"DHCPStatus","0"); } } updateDB(zDB, "WireEnable", "0"); return ret; } else { fprintf(stderr, "unknown network type\n"); return ret; } return 0; }
//---------------------------------------------------------------------------- void ctkPluginStorageSQL::open() { if (m_isDatabaseOpen) return; QString path; //Create full path to database if(m_databasePath.isEmpty ()) m_databasePath = getDatabasePath(); path = m_databasePath; QFileInfo dbFileInfo(path); if (!dbFileInfo.dir().exists()) { if(!QDir::root().mkpath(dbFileInfo.path())) { close(); QString errorText("Could not create database directory: %1"); throw ctkPluginDatabaseException(errorText.arg(dbFileInfo.path()), ctkPluginDatabaseException::DB_CREATE_DIR_ERROR); } } m_connectionName = dbFileInfo.completeBaseName(); QSqlDatabase database; if (QSqlDatabase::contains(m_connectionName)) { database = QSqlDatabase::database(m_connectionName); } else { database = QSqlDatabase::addDatabase("QSQLITE", m_connectionName); database.setDatabaseName(path); } if (!database.isValid()) { close(); throw ctkPluginDatabaseException(QString("Invalid database connection: %1").arg(m_connectionName), ctkPluginDatabaseException::DB_CONNECTION_INVALID); } //Create or open database if (!database.isOpen()) { if (!database.open()) { close(); throw ctkPluginDatabaseException(QString("Could not open database. ") + database.lastError().text(), ctkPluginDatabaseException::DB_SQL_ERROR); } } m_isDatabaseOpen = true; //Check if the sqlite version supports foreign key constraints QSqlQuery query(database); if (!query.exec("PRAGMA foreign_keys")) { close(); throw ctkPluginDatabaseException(QString("Check for foreign key support failed."), ctkPluginDatabaseException::DB_SQL_ERROR); } if (!query.next()) { close(); throw ctkPluginDatabaseException(QString("SQLite db does not support foreign keys. It is either older than 3.6.19 or was compiled with SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER"), ctkPluginDatabaseException::DB_SQL_ERROR); } query.finish(); query.clear(); //Enable foreign key support if (!query.exec("PRAGMA foreign_keys = ON")) { close(); throw ctkPluginDatabaseException(QString("Enabling foreign key support failed."), ctkPluginDatabaseException::DB_SQL_ERROR); } query.finish(); //Check database structure (tables) and recreate tables if neccessary //If one of the tables is missing remove all tables and recreate them //This operation is required in order to avoid data coruption if (!checkTables()) { if (dropTables()) { createTables(); } else { //dropTables() should've handled error message //and warning close(); } } // silently remove any plugin marked as uninstalled cleanupDB(); //Update database based on the recorded timestamps updateDB(); initNextFreeIds(); }