int main(int argc, char* argv[]) { int result = -1; MainLogDispatcher logDispatcher; _LOG->attachDispatcher(&logDispatcher); _LOG_EMPTYLINE(); _LOG_INFO(TR("%1 started").arg(APPLICATION_NAME)); QApplication a(argc, argv); QApplication::setApplicationName(APPLICATION_NAME); QApplication::setApplicationVersion(APPLICATION_VERSION); QApplication::setOrganizationName("Daniel Müller @ Hasso-Plattner-Institut"); QApplication::setOrganizationDomain("http://code.google.com/p/osghimmel/"); MainWindow w; #if defined(Q_WS_S60) w.showMaximized(); #else w.show(); #endif result = a.exec(); _LOG_INFO(TR("%1 exited").arg(APPLICATION_NAME)); _LOG_EMPTYLINE(); return result; }
bool MySQLConnection::_HandleMySQLErrno(uint32 errNo) { switch (errNo) { case CR_SERVER_GONE_ERROR: case CR_SERVER_LOST: case CR_INVALID_CONN_HANDLE: case CR_SERVER_LOST_EXTENDED: { m_reconnecting = true; uint64 oldThreadId = mysql_thread_id(GetHandle()); mysql_close(GetHandle()); if (this->Open()) // Don't remove 'this' pointer unless you want to skip loading all prepared statements.... { _LOG_INFO(LOG_FILTER_SQL, "Connection to the MySQL server is active."); if (oldThreadId != mysql_thread_id(GetHandle())) _LOG_INFO(LOG_FILTER_SQL, "Successfully reconnected to %s @%s:%s (%s).", m_connectionInfo.database.c_str(), m_connectionInfo.host.c_str(), m_connectionInfo.port_or_socket.c_str(), (m_connectionFlags & CONNECTION_ASYNC) ? "asynchronous" : "synchronous"); m_reconnecting = false; return true; } uint32 lErrno = mysql_errno(GetHandle()); // It's possible this attempted reconnect throws 2006 at us. To prevent crazy recursive calls, sleep here. boost::thread::sleep(boost::get_system_time()+boost::posix_time::seconds(3)); // Sleep 3 seconds return _HandleMySQLErrno(lErrno); // Call self (recursive) } case ER_LOCK_DEADLOCK: return false; // Implemented in TransactionTask::Execute and DatabaseWorkerPool<T>::DirectCommitTransaction // Query related errors - skip query case ER_WRONG_VALUE_COUNT: case ER_DUP_ENTRY: return false; // Outdated table or database structure - terminate core case ER_BAD_FIELD_ERROR: case ER_NO_SUCH_TABLE: _LOG_ERROR(LOG_FILTER_SQL, "Your database structure is not up to date. Please make sure you've executed all queries in the sql/updates folders."); boost::thread::sleep(boost::get_system_time()+boost::posix_time::seconds(10)); std::abort(); return false; case ER_PARSE_ERROR: _LOG_ERROR(LOG_FILTER_SQL, "Error while parsing SQL. Core fix required."); boost::thread::sleep(boost::get_system_time()+boost::posix_time::seconds(10)); std::abort(); return false; default: _LOG_ERROR(LOG_FILTER_SQL, "Unhandled MySQL errno %u. Unexpected behaviour possible.", errNo); return false; } }
bool MySQLConnection::Execute(const char* sql) { if (!m_Mysql) return false; { boost::timer _s; if (mysql_query(m_Mysql, sql)) { uint32 lErrno = mysql_errno(m_Mysql); _LOG_INFO(LOG_FILTER_SQL, "SQL: %s", sql); _LOG_ERROR(LOG_FILTER_SQL, "[%u] %s", lErrno, mysql_error(m_Mysql)); if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled successfully (i.e. reconnection) return Execute(sql); // Try again return false; } else _LOG_DEBUG(LOG_FILTER_SQL, "[%u ms] SQL: %s",(uint32) _s.elapsed(), sql); } return true; }
State::Ptr_t StateStack::CreateState(States::ID_t stateID) { _LOG_INFO( "Create state id = " + std::to_string(stateID)); auto found = m_factories.find(stateID); assert(found != m_factories.end()); return found->second(); }
void PrefixUpdateProcessor::withdraw(const std::shared_ptr<const ndn::Interest>& request, const ndn::nfd::ControlParameters& parameters) { WithdrawPrefixCommand command; if (!validateParameters(command, parameters)) { sendResponse(request, 400, "Malformed command"); return; } _LOG_INFO("Withdrawing name: " << parameters.getName()); if (m_namePrefixList.remove(parameters.getName())) { // Only build a Name LSA if a name was actually removed m_lsdb.buildAndInstallOwnNameLsa(); m_sync.publishRoutingUpdate(); } }
void PrefixUpdateProcessor::advertise(const std::shared_ptr<const ndn::Interest>& request, const ndn::nfd::ControlParameters& parameters) { AdvertisePrefixCommand command; if (!validateParameters(command, parameters)) { sendResponse(request, 400, "Malformed command"); return; } _LOG_INFO("Advertising name: " << parameters.getName()); if (m_namePrefixList.insert(parameters.getName())) { // Only build a Name LSA if the added name is new m_lsdb.buildAndInstallOwnNameLsa(); m_sync.publishRoutingUpdate(); } }
bool MySQLConnection::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount) { if (!m_Mysql) return false; { boost::timer _s; if (mysql_query(m_Mysql, sql)) { uint32 lErrno = mysql_errno(m_Mysql); _LOG_INFO(LOG_FILTER_SQL, "SQL: %s", sql); _LOG_ERROR(LOG_FILTER_SQL, "[%u] %s", lErrno, mysql_error(m_Mysql)); if (_HandleMySQLErrno(lErrno)) // If it returns true, an error was handled successfully (i.e. reconnection) return _Query(sql, pResult, pFields, pRowCount, pFieldCount); // We try again return false; } else _LOG_DEBUG(LOG_FILTER_SQL, "[%u ms] SQL: %s",(uint32)_s.elapsed(), sql); *pResult = mysql_store_result(m_Mysql); *pRowCount = mysql_affected_rows(m_Mysql); *pFieldCount = mysql_field_count(m_Mysql); } if (!*pResult ) return false; if (!*pRowCount) { mysql_free_result(*pResult); return false; } *pFields = mysql_fetch_fields(*pResult); return true; }
bool MySQLConnection::Open() { MYSQL *mysqlInit; mysqlInit = mysql_init(NULL); if (!mysqlInit) { _LOG_ERROR(LOG_FILTER_SQL, "Could not initialize Mysql connection to database `%s`", m_connectionInfo.database.c_str()); return false; } int port; char const* unix_socket; //unsigned int timeout = 10; mysql_options(mysqlInit, MYSQL_SET_CHARSET_NAME, "utf8"); //mysql_options(mysqlInit, MYSQL_OPT_READ_TIMEOUT, (char const*)&timeout); #ifdef _WIN32 if (m_connectionInfo.host == ".") // named pipe use option (Windows) { unsigned int opt = MYSQL_PROTOCOL_PIPE; mysql_options(mysqlInit, MYSQL_OPT_PROTOCOL, (char const*)&opt); port = 0; unix_socket = 0; } else // generic case { port = atoi(m_connectionInfo.port_or_socket.c_str()); unix_socket = 0; } #else if (m_connectionInfo.host == ".") // socket use option (Unix/Linux) { unsigned int opt = MYSQL_PROTOCOL_SOCKET; mysql_options(mysqlInit, MYSQL_OPT_PROTOCOL, (char const*)&opt); m_connectionInfo.host = "localhost"; port = 0; unix_socket = m_connectionInfo.port_or_socket.c_str(); } else // generic case { port = atoi(m_connectionInfo.port_or_socket.c_str()); unix_socket = 0; } #endif m_Mysql = mysql_real_connect(mysqlInit, m_connectionInfo.host.c_str(), m_connectionInfo.user.c_str(), m_connectionInfo.password.c_str(), m_connectionInfo.database.c_str(), port, unix_socket, 0); if (m_Mysql) { if (!m_reconnecting) { _LOG_INFO(LOG_FILTER_SQL, "MySQL client library: %s", mysql_get_client_info()); _LOG_INFO(LOG_FILTER_SQL, "MySQL server ver: %s ", mysql_get_server_info(m_Mysql)); // MySQL version above 5.1 IS required in both client and server and there is no known issue with different versions above 5.1 // if (mysql_get_server_version(m_Mysql) != mysql_get_client_version()) // _LOG_INFO(LOG_FILTER_SQL, "[WARNING] MySQL client/server version mismatch; may conflict with behaviour of prepared statements."); } _LOG_INFO(LOG_FILTER_SQL, "Connected to MySQL database at %s", m_connectionInfo.host.c_str()); mysql_autocommit(m_Mysql, 1); // set connection properties to UTF8 to properly handle locales for different // server configs - core sends data in UTF8, so MySQL must expect UTF8 too mysql_set_character_set(m_Mysql, "utf8"); return PrepareStatements(); } else { _LOG_ERROR(LOG_FILTER_SQL, "Could not connect to MySQL database at %s: %s\n", m_connectionInfo.host.c_str(), mysql_error(mysqlInit)); mysql_close(mysqlInit); return false; } }
void NlsrRunner::run() { ConfFileProcessor configProcessor(m_nlsr, m_nlsr.getConfFileName()); if (!configProcessor.processConfFile()) { throw Error("Error in configuration file processing! Exiting from NLSR"); } if (m_nlsr.getConfParameter().isLog4CxxConfAvailable()) { INIT_LOG4CXX(m_nlsr.getConfParameter().getLog4CxxConfPath()); } else { INIT_LOGGERS(m_nlsr.getConfParameter().getLogDir(), m_nlsr.getConfParameter().getLogLevel()); } m_nlsr.initialize(); if (m_nlsr.getIsSetDaemonProcess()) { m_nlsr.daemonize(); } try { m_nlsr.startEventLoop(); } catch (std::exception& e) { _LOG_FATAL("ERROR: " << e.what()); std::cerr << "ERROR: " << e.what() << std::endl; m_nlsr.getFib().clean(); m_nlsr.destroyFaces(); } _LOG_INFO("After catch"); /* STATISTICS COUNT Data collection printed on file SENT_HELLO_INTEREST = 1, SENT_SYNC_INTEREST, SENT_RE_SYNC_INTEREST, SENT_LSA_INTEREST, SENT_HELLO_DATA, SENT_SYNC_DATA, SENT_LSA_ADJ_DATA, SENT_LSA_COORD_DATA, SENT_LSA_NAME_DATA, RCV_HELLO_INTEREST, RCV_SYNC_INTEREST, RCV_RE_SYNC_INTEREST, RCV_LSA_INTEREST, RCV_HELLO_DATA, RCV_SYNC_DATA, RCV_LSA_ADJ_DATA, RCV_LSA_COORD_DATA, RCV_LSA_NAME_DATA, */ _LOG_INFO("StatisticsCollection" << m_nlsr.getStatistics()); //m_nlsr.getStatistics().printStatistics(); /* _LOG_INFO("\n\tHello Interest: " << m_nlsr.getStatistics().get(Statistics::PacketType::SENT_HELLO_INTEREST)); _LOG_INFO("\n\tHello Data: " << m_nlsr.getStatistics().get(Statistics::PacketType::SENT_HELLO_DATA)); _LOG_INFO("\n\tSync Interest: " << m_nlsr.getStatistics().get(Statistics::PacketType::SENT_SYNC_INTEREST)); _LOG_INFO("\n\tRe Sync Interest: " << m_nlsr.getStatistics().get(Statistics::PacketType::SENT_RE_SYNC_INTEREST)); _LOG_INFO("\n\tSync Data: " << m_nlsr.getStatistics().get(Statistics::PacketType::RCV_SYNC_DATA)); _LOG_INFO("\n\tLSA Interest " << m_nlsr.getStatistics().get(Statistics::PacketType::SENT_LSA_INTEREST)); _LOG_INFO("\n\tAdj Data: " << m_nlsr.getStatistics().get(Statistics::PacketType::SENT_LSA_ADJ_DATA)); _LOG_INFO("\nCoord Data " << m_nlsr.getStatistics().get(Statistics::PacketType::SENT_LSA_COORD_DATA)); _LOG_INFO("\nName Data " << m_nlsr.getStatistics().get(Statistics::PacketType::SENT_LSA_NAME_DATA)); _LOG_INFO("\n\n\tHello Interest RCV: " << m_nlsr.getStatistics().get(Statistics::PacketType::RCV_HELLO_INTEREST)); _LOG_INFO("\n\tHello Data RCV: " << m_nlsr.getStatistics().get(Statistics::PacketType::RCV_HELLO_DATA)); _LOG_INFO("\n\tSync Interest RCV: " << m_nlsr.getStatistics().get(Statistics::PacketType::RCV_SYNC_INTEREST)); _LOG_INFO("\n\tRe Sync Interest RCV: " << m_nlsr.getStatistics().get(Statistics::PacketType::RCV_RE_SYNC_INTEREST)); _LOG_INFO("\n\tSync Data RCV: " << m_nlsr.getStatistics().get(Statistics::PacketType::RCV_SYNC_DATA)); _LOG_INFO("\n\tLSA Interest RCV: " << m_nlsr.getStatistics().get(Statistics::PacketType::RCV_LSA_INTEREST)); _LOG_INFO("\n\tAdj Data RCV: " << m_nlsr.getStatistics().get(Statistics::PacketType::RCV_LSA_ADJ_DATA)); _LOG_INFO("\n\tCoord Data RCV: " << m_nlsr.getStatistics().get(Statistics::PacketType::RCV_LSA_COORD_DATA)); _LOG_INFO("\n\tName Data RCV: " << m_nlsr.getStatistics().get(Statistics::PacketType::RCV_LSA_NAME_DATA)); */ }