//---------------------------------------------------------------------------- // // Copyright (C) Intel Corporation, 2007 - 2008. // // File: DynamicConfiguration.cpp // // Contents: A timer which goes off on a set time, which reads the // dynamic configuration file, // and updates its elements accordingly // // Notes: //---------------------------------------------------------------------------- #include "DynamicConfiguration.h" #include "Options.h" #include "global.h" DynamicConfiguration::DynamicConfiguration(void) : _timer_id(-1) { } DynamicConfiguration::~DynamicConfiguration(void) { } STATUS DynamicConfiguration::start (const ACE_Time_Value &initialDelay, const ACE_Time_Value &interval) { long retValue = ACE_Reactor::instance ()->schedule_timer(this, NULL, initialDelay, interval); _timer_id = retValue; if (retValue == STATUS_FAILURE) { return STATUS_FAILURE; } return STATUS_SUCCESS; } STATUS DynamicConfiguration::close(void) { ACE_Reactor * reactor = ACE_Reactor::instance(); if (reactor == NULL) { return STATUS_FAILURE; } int retVal = reactor->cancel_timer(_timer_id); // IMPORTANT: cancel_timer returns 0 if it does not find the _timer_id. // Therefore I return STATUS_FAILURE (-1) for it! // If it does succeed it returns 1, therefore I return STATUS_SUCCESS (0) if (retVal == 0) { return STATUS_FAILURE; } return STATUS_SUCCESS; } int DynamicConfiguration::handle_timeout(const ACE_Time_Value ¤t_time, const void * arg) { int tcp_count=TCP_COUNTER.GetCounterValue(); int tunnel_count=TUNNEL_COUNTER.GetCounterValue(); ACE_DEBUG((MY_DEBUG ACE_TEXT("Handler counters:\n\tTUNNEL_COUNTER = %d\n\tTCP_COUNTER = %d\n"), tunnel_count, tcp_count)); int readRet; if ((Options::instance() == NULL) || ((readRet = Options::instance() -> read_dynamic_file()) == STATUS_FAILURE)) { #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_SERVICES) && defined (_SERVICE) m_pLogger.LogErrorEvent(MPS_ERROR, MPS_CONFIG_DYNAMIC_FAIL_MESSAGE); #endif /* ACE_WIN32 && !(ACE_LACKS_WIN32_SERVICES) && (_SERVICE)*/ ACE_ERROR ((MY_ERROR ACE_TEXT ("Error while reading dynamic configuration file.\n"))); } else { // if 1 <= readRet <= 2 than the dynamic config file was changed. if ((readRet >= 1) && (readRet <= 2)) { notify(); } } return 0; }