GPSGridClient::~GPSGridClient() { QSettings settings( "MoNavClient" ); settings.beginGroup( "GPS Grid" ); settings.setValue( "cacheSize", cacheSize ); UnloadData(); }
bool ContractionHierarchiesClient::LoadData() { QString filename = fileInDirectory( m_directory,"Contraction Hierarchies" ); UnloadData(); if ( !m_graph.loadGraph( filename, 1024 * 1024 * 4 ) ) return false; m_namesFile.setFileName( filename + "_names" ); if ( !openQFile( &m_namesFile, QIODevice::ReadOnly ) ) return false; m_names = ( const char* ) m_namesFile.map( 0, m_namesFile.size() ); if ( m_names == NULL ) return false; m_namesFile.close(); m_heapForward = new Heap( m_graph.numberOfNodes() ); m_heapBackward = new Heap( m_graph.numberOfNodes() ); QFile typeFile( filename + "_types" ); if ( !openQFile( &typeFile, QIODevice::ReadOnly ) ) return false; QByteArray buffer = typeFile.readAll(); QString types = QString::fromUtf8( buffer.constData() ); m_types = types.split( ';' ); return true; }
bool UnicodeTournamentTrieClient::LoadData() { UnloadData(); QString filename = fileInDirectory( directory, "Unicode Tournament Trie" ); trieFile = new QFile( filename + "_main" ); subTrieFile = new QFile( filename + "_sub" ); dataFile = new QFile( filename + "_ways" ); if ( !openQFile( trieFile, QIODevice::ReadOnly ) ) return false; if ( !openQFile( subTrieFile, QIODevice::ReadOnly ) ) return false; if ( !openQFile( dataFile, QIODevice::ReadOnly ) ) return false; trieData = ( char* ) trieFile->map( 0, trieFile->size() ); subTrieData = ( char* ) subTrieFile->map( 0, subTrieFile->size() ); if ( trieData == NULL ) { qDebug( "Failed to Memory Map trie data" ); return false; } if ( subTrieData == NULL ) { qDebug( "Failed to Memory Map sub trie data" ); return false; } return true; }
int main(int argc, char *argv[]) { InitOpenAL(); // 初始化openal LoadData(); // 载入WAV数据 Play(); // 播放 UnloadData(); // 卸载WAV数据 ShutdownOpenAL(); // 关闭openal return 0; }
void CDataFileReader::Close() { if(!m_pDataFile) return; free(m_pDataFile->m_Info.m_pData); for(int i = 0; i < m_pDataFile->m_Header.m_NumRawData; i++) UnloadData(i); delete m_pDataFile->m_pData; m_pDataFile->m_File.close(); delete m_pDataFile; m_pDataFile = NULL; }
void Intermission::End() { UnloadData(); if (cv_deathmatch.value) { for (int i=0; i<4; i++) delete [] dm_score[i]; } else { cnt.clear(); plrs.clear(); } state = Inactive; game.EndIntermission(); }
bool GPSGridClient::LoadData() { UnloadData(); QString filename = fileInDirectory( directory, "GPSGrid" ); QFile configFile( filename + "_config" ); if ( !openQFile( &configFile, QIODevice::ReadOnly ) ) return false; index = new gg::Index( filename + "_index" ); index->SetCacheSize( 1024 * 1024 * cacheSize / 4 ); gridFile = new QFile( filename + "_grid" ); if ( !gridFile->open( QIODevice::ReadOnly ) ) { qCritical() << "failed to open file: " << gridFile->fileName(); return false; } return true; }
int main(int argc, char **argv) { bool bAllQueriesDump = true; if (argc < 2) PrintUsage(); else if (argc == 2) { if ( !strcmp (argv[0], "-h") || !strcmp (argv[0], "-help") || !strcmp (argv[0], "/h") || !strcmp (argv[0], "/help") ) PrintUsage(); } else { if (!strcmp(argv [2], "--no-query-dump")) { bAllQueriesDump = false; fprintf(stderr, "no dump of all queries \n"); } else PrintUsage(); }; string LockFileName; if (!GetLockName(LockFileName)) { return 1; }; string Action = argv[1]; if ( (Action != "start") && (Action != "start_cli") && (Action != "stop") ) PrintUsage(); if (Action == "stop") { if (access(LockFileName.c_str(), 04) != 0) { printf("Seman Daemon was not started!\n"); return 1; }; FILE* fp = fopen (LockFileName.c_str(), "r"); if (!fp) { printf("Cannot open file %s!\n", LockFileName.c_str()); return 1; }; pid_t pid; fscanf(fp, "%i", &pid); fclose (fp); if (kill (pid, SIGTERM) == 0) { printf ("Seman Daemon was stopped\n"); remove (LockFileName.c_str()); } else printf ("Cannot send a SIGTERM to the process\n"); return 1; }; seman_daemon_log ("Entering Seman Daemon"); if (Action == "start_cli") { fprintf (stderr, "removing %s\n",LockFileName.c_str()); remove(LockFileName.c_str()); }; if (access(LockFileName.c_str(), 04) == 0) { printf("Daemon already started!\n"); return 1; }; if (Action == "start") { // working as a daemon int fd; int i; struct rlimit flim; if (getppid()!=1) { signal(SIGTTOU,SIG_IGN); signal(SIGTTIN,SIG_IGN); signal(SIGTSTP,SIG_IGN); if(fork()!=0) { exit(0); }; setsid(); } getrlimit(RLIMIT_NOFILE, &flim); for(fd=0;fd<flim.rlim_max;fd++) close(fd); chdir("/"); openlog("Seman Server", LOG_PID| LOG_CONS, LOG_DAEMON ); } try{ if (Action == "start_cli") { fprintf (stderr, "Open a lock file %s\n", LockFileName.c_str()); } syslog(LOG_ALERT, "Open a lock file %s\n", LockFileName.c_str()); FILE* fp = fopen (LockFileName.c_str(), "w"); if (!fp) { syslog(LOG_ALERT, "Cannot open file %s!\n", LockFileName.c_str()); return 1; }; fprintf(fp, "%i", getpid()); fclose (fp); if (Action == "start_cli") { fprintf (stderr, "SocketInitialize...\n"); } seman_daemon_log ("SocketInitialize..."); SocketInitialize(false); if (Action == "start_cli") { fprintf (stderr, "LoadTranslator...\n"); } if (!LoadTranslator ()) { seman_daemon_log ("Cannot load Seman"); if (Action == "start_cli") { fprintf (stderr, "Cannot load Seman\n"); } SocketDeinitialize(); return 1; }; if (signal (SIGTERM, termination_handler) == SIG_IGN) signal (SIGTERM, SIG_IGN); if (Action == "start_cli") fprintf (stderr, "\nWaiting for accept ... \n"); while (1) { sleep(40); } } catch(...) { if (Action == "start_cli") { fprintf (stderr, "An exception occurred!\n"); } syslog(LOG_ALERT, "An exception occurred! "); UnloadData(); SocketDeinitialize(); return -1; }; SocketDeinitialize(); return 1; }
void termination_handler(int signum) { UnloadData(); syslog(LOG_ALERT, "Exiting from concordance "); exit(1); };
ContractionHierarchiesClient::~ContractionHierarchiesClient() { UnloadData(); }
EXPORT int MM_hs_foosball(int action, Imodman *_mm, Arena *arena) { if (action == MM_LOAD) { mm = _mm; lm = mm->GetInterface(I_LOGMAN, ALLARENAS); net = mm->GetInterface(I_NET, ALLARENAS); mapdata = mm->GetInterface(I_MAPDATA, ALLARENAS); pd = mm->GetInterface(I_PLAYERDATA, ALLARENAS); aman = mm->GetInterface(I_ARENAMAN, ALLARENAS); game = mm->GetInterface(I_GAME, ALLARENAS); selfpos = mm->GetInterface(I_SELFPOS, ALLARENAS); if (!lm || !net || !mapdata || !pd || !aman || !game || !selfpos) return MM_FAIL; adkey = aman->AllocateArenaData(sizeof(struct adata)); if (adkey == -1) return MM_FAIL; pdkey = pd->AllocatePlayerData(sizeof(struct pdata)); if (pdkey == -1) return MM_FAIL; net->AddPacket(C2S_POSITION, Pppk); return MM_OK; } else if (action == MM_UNLOAD) { net->RemovePacket(C2S_POSITION, Pppk); aman->FreeArenaData(adkey); pd->FreePlayerData(pdkey); mm->ReleaseInterface(lm); mm->ReleaseInterface(net); mm->ReleaseInterface(mapdata); mm->ReleaseInterface(pd); mm->ReleaseInterface(aman); mm->ReleaseInterface(game); mm->ReleaseInterface(selfpos); return MM_OK; } else if (action == MM_ATTACH) { struct adata *ad = P_ARENA_DATA(arena, adkey); ad->on = 1; LoadData(arena); return MM_OK; } else if (action == MM_DETACH) { struct adata *ad = P_ARENA_DATA(arena, adkey); ad->on = 0; UnloadData(arena); return MM_OK; } return MM_FAIL; }