bool K3b::TranscodeProgram::scanFeatures( ExternalBin& bin ) const { // // Check features // QString modInfoBin = buildProgramPath( QFileInfo( bin.path() ).absolutePath(), QLatin1String( "tcmodinfo" ) ); Process modp; modp.setOutputChannelMode( KProcess::MergedChannels ); modp << modInfoBin << "-p"; if( !modp.execute() ) { QString modPath = QString::fromLocal8Bit( modp.readAll() ).simplified(); QDir modDir( modPath ); if( !modDir.entryList( QStringList() << "*export_xvid*", QDir::Files ).isEmpty() ) bin.addFeature( "xvid" ); if( !modDir.entryList( QStringList() << "*export_lame*", QDir::Files ).isEmpty() ) bin.addFeature( "lame" ); if( !modDir.entryList( QStringList() << "*export_ffmpeg*", QDir::Files ).isEmpty() ) bin.addFeature( "ffmpeg" ); if( !modDir.entryList( QStringList() << "*export_ac3*", QDir::Files ).isEmpty() ) bin.addFeature( "ac3" ); return true; } else { qDebug() << "Failed to start" << modp.program(); return false; } }
void Instance::LoadModListFromDir(const wxFileName& dir, bool mlMod) { ModList *list; if (mlMod) list = &mlModList; else list = &modList; wxDir modDir(dir.GetFullPath()); if (!modDir.IsOpened()) { wxLogError(_("Failed to open directory: ") + dir.GetFullPath()); return; } wxString currentFile; if (modDir.GetFirst(¤tFile)) { do { currentFile = Path::Combine(modDir.GetName(), currentFile); if (wxFileExists(currentFile) || mlMod) { Mod mod(currentFile); if (mlMod || !Any(list->begin(), list->end(), [¤tFile] (Mod mod) -> bool { return mod.GetFileName().SameAs(wxFileName(currentFile)); })) { if (!mlMod) SetNeedsRebuild(); list->push_back(mod); } } else if (wxDirExists(currentFile)) { LoadModListFromDir(wxFileName(currentFile), mlMod); } } while (modDir.GetNext(¤tFile)); } }
int _Wolframe_winMain( int argc, char* argv[] ) { try { // create initial console logger, so we see things going wrong _Wolframe::log::LogBackend::instance().setConsoleLevel( _Wolframe::log::LogLevel::LOGLEVEL_WARNING ); _Wolframe::ApplicationInfo& appInfo = _Wolframe::ApplicationInfo::instance(); appInfo.version( _Wolframe::Version( _Wolframe::applicationVersion() )); _Wolframe::config::CmdLineConfig cmdLineCfg; const char *configFile = NULL; if ( !cmdLineCfg.parse( argc, argv )) { // there was an error parsing the command line LOG_ERROR << cmdLineCfg.errMsg(); cmdLineCfg.usage( std::cerr ); std::cerr << std::endl; return _Wolframe::ErrorCode::FAILURE; } // command line has been parsed successfully // reset log level to the command line one, if specified if ( cmdLineCfg.debugLevel != _Wolframe::log::LogLevel::LOGLEVEL_UNDEFINED ) { _Wolframe::log::LogBackend::instance().setConsoleLevel( cmdLineCfg.debugLevel ); // if in a service the -d flag can be specified in the 'ImagePath' of the service description in order // to debug lowlevel via 'OutputDebugString' winDbgLevel = cmdLineCfg.debugLevel; } else { winDbgLevel = _Wolframe::log::LogLevel::LOGLEVEL_UNDEFINED; } // if cmdLineCfg.errMsg() is not empty than we have a warning if ( !cmdLineCfg.errMsg().empty() ) // there was a warning parsing the command line LOG_WARNING << cmdLineCfg.errMsg(); // if we have to print the version or the help do it and exit if ( cmdLineCfg.command == _Wolframe::config::CmdLineConfig::PRINT_VERSION ) { std::cout << _Wolframe::applicationName() << " version " << appInfo.version().toString() << std::endl << std::endl; return _Wolframe::ErrorCode::OK; } if ( cmdLineCfg.command == _Wolframe::config::CmdLineConfig::PRINT_HELP ) { cmdLineCfg.usage( std::cout ); std::cout << std::endl; return _Wolframe::ErrorCode::OK; } // decide what configuration file to use if ( !cmdLineCfg.cfgFile.empty() ) // if it has been specified than that's The One ! (and only) configFile = cmdLineCfg.cfgFile.c_str(); if ( configFile == NULL ) { // there is no configuration file LOG_FATAL << "no configuration file found !"; return _Wolframe::ErrorCode::FAILURE; } std::string configurationPath = boost::filesystem::path( configFile).branch_path().string(); _Wolframe::module::ModulesDirectory modDir( configurationPath); _Wolframe::config::ApplicationConfiguration conf; conf.addModules( &modDir ); _Wolframe::config::ApplicationConfiguration::ConfigFileType cfgType = _Wolframe::config::ApplicationConfiguration::fileType( configFile, cmdLineCfg.cfgType ); if ( cfgType == _Wolframe::config::ApplicationConfiguration::CONFIG_UNDEFINED ) return _Wolframe::ErrorCode::FAILURE; if ( !conf.parseModules( configFile, cfgType )) return _Wolframe::ErrorCode::FAILURE; if ( ! modDir.loadModules( conf.moduleList() )) return _Wolframe::ErrorCode::FAILURE; if ( !conf.parse( configFile, cfgType )) return _Wolframe::ErrorCode::FAILURE; // configuration file has been parsed successfully // build the final configuration conf.finalize( cmdLineCfg ); // Check the configuration if ( cmdLineCfg.command == _Wolframe::config::CmdLineConfig::CHECK_CONFIG ) { if ( conf.check() ) { std::cout << "Configuration OK" << std::endl << std::endl; return _Wolframe::ErrorCode::OK; } else { return _Wolframe::ErrorCode::OK; } } if ( cmdLineCfg.command == _Wolframe::config::CmdLineConfig::PRINT_CONFIG ) { conf.print( std::cout ); std::cout << std::endl; return _Wolframe::ErrorCode::OK; } if ( cmdLineCfg.command == _Wolframe::config::CmdLineConfig::TEST_CONFIG ) { std::cout << "Not implemented yet" << std::endl << std::endl; return _Wolframe::ErrorCode::OK; } if ( cmdLineCfg.command == _Wolframe::config::CmdLineConfig::INSTALL_SERVICE ) { if( !registerEventlog( conf ) ) return _Wolframe::ErrorCode::FAILURE; if( !installAsService( conf ) ) return _Wolframe::ErrorCode::FAILURE; LOG_INFO << "Installed as Windows service '" << conf.serviceCfg->serviceName.c_str( ) << "'"; return _Wolframe::ErrorCode::OK; } if ( cmdLineCfg.command == _Wolframe::config::CmdLineConfig::REMOVE_SERVICE ) { if( !removeAsService( conf ) ) return _Wolframe::ErrorCode::FAILURE; (void)deregisterEventlog( conf ); LOG_INFO << "Removed as Windows service '" << conf.serviceCfg->serviceName.c_str( ) << "'"; return _Wolframe::ErrorCode::OK; } if( cmdLineCfg.command == _Wolframe::config::CmdLineConfig::RUN_SERVICE ) { // if started as service we dispatch the service thread now SERVICE_TABLE_ENTRY dispatch_table[2] = { { const_cast<char *>( conf.serviceCfg->serviceName.c_str( ) ), service_main }, { NULL, NULL } }; // pass configuration to service main serviceConfig = conf.configFile; if( !StartServiceCtrlDispatcher( dispatch_table ) ) { if( GetLastError( ) == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT ) { // not called as service, continue as console application conf.foreground = true; } else { // TODO: mmh? what are we doing here? No longer here LOG_FATAL << "Unable to dispatch service control dispatcher: " << _Wolframe::log::LogError::LogWinerror; return _Wolframe::ErrorCode::FAILURE; } } else { // here we get if the service has been stopped, so we terminate here return _Wolframe::ErrorCode::OK; } } // Create the final logger based on the configuration, this is the // foreground mode in a console, so we start only the stderr logger _Wolframe::log::LogBackend::instance().setConsoleLevel( conf.loggerCfg->stderrLogLevel ); LOG_NOTICE << "Starting server"; _Wolframe::ServerHandler handler( conf.handlerCfg, &modDir ); _Wolframe::net::server s( conf.serverCfg, handler ); // Set console control handler to allow server to be stopped. consoleCtrlFunction = boost::bind(&_Wolframe::net::server::stop, &s); SetConsoleCtrlHandler(consoleCtrlHandler, TRUE); // Run the server until stopped. s.run(); } catch (std::exception& e) { LOG_ERROR << "Got exception: " << e.what( ); return _Wolframe::ErrorCode::FAILURE; } LOG_NOTICE << "Server stopped"; return _Wolframe::ErrorCode::OK; }
static void WINAPI service_main( DWORD argc, LPTSTR *argv ) { try { // set an emergency logger (debug view), is set in 'ImagePath' in the registry of the service description _Wolframe::log::LogBackend::instance().setWinDebugLevel( winDbgLevel ); // read configuration (from the location passed in the command line arguments of the main, not the service_main) _Wolframe::config::CmdLineConfig cmdLineCfg; // empty for a service with --service cmdLineCfg.command = _Wolframe::config::CmdLineConfig::RUN_SERVICE; const char *configFile = serviceConfig.c_str( ); // configuration comes from main thread std::string configurationPath = boost::filesystem::path( configFile).branch_path().string(); _Wolframe::module::ModulesDirectory modDir( configurationPath); _Wolframe::config::ApplicationConfiguration conf; conf.addModules( &modDir ); _Wolframe::config::ApplicationConfiguration::ConfigFileType cfgType = _Wolframe::config::ApplicationConfiguration::fileType( configFile, cmdLineCfg.cfgType ); if ( cfgType == _Wolframe::config::ApplicationConfiguration::CONFIG_UNDEFINED ) return; if ( !conf.parseModules( configFile, cfgType )) return; if ( ! modDir.loadModules( conf.moduleList() )) return; if ( !conf.parse( configFile, cfgType )) return; // configuration file has been parsed successfully // build the final configuration conf.finalize( cmdLineCfg ); // create the final logger based on the configuration _Wolframe::log::LogBackend::instance().setConsoleLevel( conf.loggerCfg->stderrLogLevel ); _Wolframe::log::LogBackend::instance().setLogfileLevel( conf.loggerCfg->logFileLogLevel ); _Wolframe::log::LogBackend::instance().setLogfileName( conf.loggerCfg->logFile ); _Wolframe::log::LogBackend::instance().setSyslogLevel( conf.loggerCfg->syslogLogLevel ); _Wolframe::log::LogBackend::instance().setSyslogFacility( conf.loggerCfg->syslogFacility ); _Wolframe::log::LogBackend::instance().setSyslogIdent( conf.loggerCfg->syslogIdent ); _Wolframe::log::LogBackend::instance().setEventlogLevel( conf.loggerCfg->eventlogLogLevel ); _Wolframe::log::LogBackend::instance().setEventlogLog( conf.loggerCfg->eventlogLogName ); _Wolframe::log::LogBackend::instance().setEventlogSource( conf.loggerCfg->eventlogSource ); // register the event callback where we get called by Windows and the SCM serviceStatusHandle = RegisterServiceCtrlHandler( conf.serviceCfg->serviceName.c_str( ), serviceCtrlFunction ); if( serviceStatusHandle == 0 ) { LOG_FATAL << "Unable to register service control handler function: " << _Wolframe::log::LogError::LogWinerror; return; } // send "we are starting up now" to the SCM service_report_status( SERVICE_START_PENDING, NO_ERROR, DEFAULT_SERVICE_TIMEOUT ); // register a stop event serviceStopEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); if( serviceStopEvent == NULL ) { LOG_FATAL << "Unable to create the stop event for the termination of the service: " << _Wolframe::log::LogError::LogWinerror; service_report_status( SERVICE_STOPPED, NO_ERROR, DEFAULT_SERVICE_TIMEOUT ); return; } LOG_NOTICE << "Starting service"; // run server in background thread(s). _Wolframe::ServerHandler handler( conf.handlerCfg, &modDir ); _Wolframe::net::server s( conf.serverCfg, handler ); boost::thread t( boost::bind( &_Wolframe::net::server::run, &s )); // we are up and running now (hopefully), signal this to the SCM service_report_status( SERVICE_RUNNING, NO_ERROR, DEFAULT_SERVICE_TIMEOUT ); // Sit and wait here for the stop event to happen, terminate then WAIT_FOR_STOP_EVENT: DWORD res = WaitForSingleObject( serviceStopEvent, DEFAULT_SERVICE_TIMEOUT ); switch( res ) { case WAIT_OBJECT_0: s.stop( ); // stop signal received, signal "going to stop" to SCM service_report_status( SERVICE_STOP_PENDING, NO_ERROR, DEFAULT_SERVICE_TIMEOUT ); break; case WAIT_TIMEOUT: // we could do something periodic here goto WAIT_FOR_STOP_EVENT; case WAIT_ABANDONED: // this is bad, not really sure how we could recover from this one. For // now let's assume that stopping here is safer, so treat it like a successful // event, but log the fact we run into that state LOG_CRITICAL << "Waiting for stop event in service main resulted in WAIT_ABANDONED!"; break; case WAIT_FAILED: // error, stop now immediatelly LOG_FATAL << "Waiting for stop event in service main failed, stopping now" << _Wolframe::log::LogError::LogWinerror; s.stop( ); service_report_status( SERVICE_STOPPED, NO_ERROR, DEFAULT_SERVICE_TIMEOUT ); return; } // signal the SCM that we are done LOG_NOTICE << "Stopped service"; service_report_status( SERVICE_STOPPED, NO_ERROR, DEFAULT_SERVICE_TIMEOUT ); } catch (std::exception& e) { LOG_FATAL << e.what( ); // any exception should signal the SCM that the service is down now service_report_status( SERVICE_STOPPED, NO_ERROR, DEFAULT_SERVICE_TIMEOUT ); } }