Guilherme:
- fix config parser:
-- Documentation of the functions (doxygen)
-
- The interval between each ping to the same host is 1 second later than in the
configuration file. For example, a ping configured to be performed each 5
seconds takes 6.
{
}
+/**
+ * @brief Parses the command line and configuration file.
+ *
+ * @param argc the number of arguments in command line.
+ * @param argv a vector containing the command line elements.
+ *
+ * @return true if the parsing was successful, otherwise returns false.
+ */
bool ConfigurationReader::parse(
const int argc,
char *argv[]
}
}
+/**
+ * @return the object containing the configuration data parsed by this object.
+ */
Configuration ConfigurationReader::get_configuration() const
{
return Config;
}
+/**
+ * @return which options must abort the application. Like the --version.
+ */
bool ConfigurationReader::halt_on_generic_options( const variables_map &vm ) const
{
bool is_help = ( vm.count( HelpCmdStr ) > 0 );
return true;
}
+/**
+ * @brief Reads and parses the command line, storing the parsed tokens in the
+ * variables_map.
+ *
+ * @param argc the number of arguments in command line.
+ * @param argv a vector containing the command line elements.
+ * @param vm the variables_map object to store configuration tokens.
+ */
bool ConfigurationReader::process_command_line(
const int argc,
char *argv[],
}
}
+/**
+ * @brief Reads and parses the configuration file. The file name is retrieved
+ * from the variables_map object.
+ *
+ * @param vm the variables_map object to store configuration tokens.
+ */
bool ConfigurationReader::process_configuration_file( variables_map &vm )
{
string config_file_name = "";
return process_configuration_file( config_file_name, vm );
}
+/**
+ * @brief Reads and parses the configuration file.
+ *
+ * @param config_file_name the configuration file name to be parsed.
+ * @param vm the variables_map object to store configuration tokens.
+ */
bool ConfigurationReader::process_configuration_file(
const string &config_file_name,
variables_map &vm
// ConfigurationReader
//-----------------------------------------------------------------------------
+/**
+ * @brief This class represents the configuration parsing process.
+ */
class ConfigurationReader
{
public:
Host::Host( string address ) :
Address( address ),
Port( 0 ),
- IntervalInSec( 0 ),
- Options()
+ IntervalInSec( 0 )
{
}
{
}
+/**
+ * @return a string representing the host address.
+ */
string Host::get_address() const
{
return Address;
}
+/**
+ * @param address a string representing the host address.
+ */
void Host::set_address( const string &address )
{
BOOST_ASSERT( !address.empty() );
this->Address = address;
}
+/**
+ * @return the destination port number to ping the host.
+ */
uint16_t Host::get_port() const
{
return Port;
}
+/**
+ * @param port the destination port number to ping the host.
+ */
void Host::set_port( const uint16_t port )
{
BOOST_ASSERT( ( 0 < port ) && ( port < numeric_limits<uint16_t>::max() ) );
this->Port = port;
}
+/**
+ * @return the interval between each ping to the host.
+ */
int Host::get_interval_in_sec() const
{
return IntervalInSec;
}
+/**
+ * @param interval_in_sec the interval between each ping to the host.
+ */
void Host::set_interval_in_sec( const int interval_in_sec )
{
BOOST_ASSERT( ( 0 < interval_in_sec ) && ( interval_in_sec < numeric_limits<int>::max() ) );
this->IntervalInSec = interval_in_sec;
}
-
-vector<string> Host::get_options() const
-{
- return Options;
-}
-
-void Host::set_options( const vector<string> &options )
-{
- BOOST_ASSERT( 0 < options.size() );
-
- this->Options = options;
-}
int get_interval_in_sec() const;
void set_interval_in_sec( const int interval_in_sec );
- std::vector<std::string> get_options() const;
- void set_options( const std::vector<std::string> &options );
-
private:
/// the address of the host
std::string Address;
uint16_t Port;
/// the interval between each ping to the host
int IntervalInSec;
- /// options
- std::vector<std::string> Options;
};
}
/**
- * Resolve the IPs from this DNS and build a list of these IPs.
+ * @brief Resolve the IPs from this DNS and build a list of these IPs.
*
* @return true if the host address could be resolved, or false otherwise.
*/
{
}
+/**
+ * @return the original time-to-live value, as specified by the set method.
+ */
int TimeToLive::get_value() const
{
return Ttl;
}
+/**
+ * @param ttl the time-to-live value.
+ */
void TimeToLive::set_value( const int ttl )
{
BOOST_ASSERT( 0 < ttl );
TtlSetTime = microsec_clock::universal_time();
}
+/**
+ * @return the value of the time-to-live updated since the last set was called.
+ */
int TimeToLive::get_updated_value() const
{
ptime now = microsec_clock::universal_time();
// IcmpMessagePayload
//-----------------------------------------------------------------------------
+/**
+ * @param payload_size_in_bytes the size of the payload (ie the internal buffer)
+ */
IcmpMessagePayload::IcmpMessagePayload(
const std::size_t &payload_size_in_bytes
) :
// Payload automatically delete by smart pointer scope end
}
+/**
+ * @brief The element access operator to provide access syntax like regular
+ * arrays.
+ */
const uint8_t& IcmpMessagePayload::operator[]( size_t offset ) const
{
BOOST_ASSERT( offset < PayloadSizeInBytes );
return Payload[ offset ];
}
+/**
+ * @brief The element access operator to provide access syntax like regular
+ * arrays.
+ */
uint8_t& IcmpMessagePayload::operator[]( size_t offset )
{
BOOST_ASSERT( offset < PayloadSizeInBytes );
return Payload[ offset ];
}
+/**
+ * @brief Retrieve 16 bits from the payload buffer.
+ *
+ * @param left_byte the index of the left byte
+ * @param right_byte the index of the right byte
+ *
+ * @return a concatenation of the byte indexed by left_byte with the byte
+ * indexed by right_byte
+ */
uint16_t IcmpMessagePayload::decode(
const int left_byte,
const int right_byte
return static_cast<uint16_t> ( value );
}
+/**
+ * @brief Store 16 bits in the payload buffer.
+ *
+ * @param left_byte the index of the left byte
+ * @param right_byte the index of the right byte
+ *
+ * @param value a 16 bits data be saved in the bytes indexed by left_byte and
+ * right_byte.
+ */
void IcmpMessagePayload::encode(
const int left_byte,
const int right_byte,
Payload[ right_byte ] = static_cast<uint8_t> ( value & 0xFF );
}
+/**
+ * @brief Read all the data from the payload and stores in the istream.
+ */
istream& IcmpMessagePayload::read( istream &is )
{
char *data_array = reinterpret_cast<char *> ( Payload.get() );
return is;
}
+/**
+ * @brief Writes all the data present in the ostream to the payload buffer.
+ */
ostream& IcmpMessagePayload::write( ostream &os ) const
{
const char *data_array = reinterpret_cast<const char *> ( Payload.get() );
// IcmpMessagePayload
//-----------------------------------------------------------------------------
+/**
+ * @brief This class represents the contents of the network messages. It
+ * provides means for encode and decode, and also can be treated like an
+ * ordinary array.
+ */
class IcmpMessagePayload
{
public:
// LinkStatusAnalyzer
//-----------------------------------------------------------------------------
+/**
+ * @brief Creates a link status object.
+ *
+ * @param hosts_down_limit the maximum amount of different hosts that can be
+ * down before the system take any action.
+ * @param link_up_interval_in_min the amount of time required to the link to
+ * stay up before notify.
+ * @param link_down_interval_in_min the amount of time required to the link to
+ * stay down before notify.
+ * @param status_notifier_cmd the command used to notify about link status
+ * changes.
+ */
LinkStatusAnalyzer::LinkStatusAnalyzer(
const int hosts_down_limit,
const int link_up_interval_in_min,
{
}
+/**
+ * @brief Notify the system that a given host is up. The object takes an
+ * appropriated action to deal with that.
+ * Note: this object does not resolves IPs, thus you have to send the same host
+ * address in order to the object to consider the same host.
+ *
+ * @param host_address the DNS/IP address of the host that is up.
+ */
void LinkStatusAnalyzer::notify_host_up( const string &host_address )
{
BOOST_ASSERT( !host_address.empty() );
BOOST_ASSERT( HostsDownList.count( host_address ) == 0 );
}
+/**
+ * @brief Notify the system that a given host is down. The object takes an
+ * appropriated action to deal with that.
+ * Note: this object does not resolves IPs, thus you have to send the same host
+ * address in order to the object to consider the same host.
+ *
+ * @param host_address the DNS/IP address of the host that is down.
+ */
void LinkStatusAnalyzer::notify_host_down( const string &host_address )
{
BOOST_ASSERT( !host_address.empty() );
{
}
+/**
+ * @brief Replaces the token by the value in the notifier command.
+ *
+ * @param token actual string in the command.
+ * @param value string to replace the token.
+ *
+ * @return true if the token was find and replaced, or false if it was not
+ * found, neither replaced.
+ */
bool StatusNotifierCommand::set_token_value(
const string &token,
const string &value
return true;
}
+/**
+ * @brief Tries to execute the notify command.
+ *
+ * @return true if the command could be executed. false otherwise.
+ */
bool StatusNotifierCommand::execute() const
{
// Check if users wants notification at all