Skip to content

Commit

Permalink
Added doxygen-style comments
Browse files Browse the repository at this point in the history
  • Loading branch information
p-ranav committed Mar 17, 2016
1 parent 5f3bdf3 commit 6e03795
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 24 deletions.
62 changes: 47 additions & 15 deletions src/node/include/node/Component.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#ifndef COMPONENT_HPP
/** @file Component.hpp
* @author William Emfinger
* @author Pranav Srinivas Kumar
* @date <%- Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') %>
* @brief This file declares the Component class
*/

#ifndef COMPONENT_HPP
#define COMPONENT_HPP

#include <iostream>
Expand All @@ -17,35 +24,60 @@
#endif
#endif

/**
* @brief Component class
*/
class Component {
public:
// Constructor
/**
* @brief Component Constructor.
* @param _config Component configuration parsed from deployment XML
* @param[in] argc command-line argument count
* @param[in] argv command-line arguments of the actor process
*/
Component(ComponentConfig &_config, int argc, char **argv);

// Start up
/**
* @brief Component startup function
*
* This function configures all the component ports and timers
*/
virtual void startUp() = 0;

// Initialization
/**
* @brief Component Initializer
* This operation is executed immediately after startup.
* @param[in] event a oneshot timer event
* @see startUp()
*/
virtual void init_timer_operation(const NAMESPACE::TimerEvent& event);

// Synchronization
/**
* @brief Component Synchronization
* This operation establishing a sync point with other components
* @param[in] received_data Notification message from other components
*/
virtual void component_sync_operation(const std_msgs::Bool::ConstPtr& received_data);

// Callback Queue Handler
/**
* @brief Component Message Queue handler
*/
void process_queue();

// Destructor
/**
* @brief Component Destructor
*/
~Component();

protected:
ComponentConfig config;
int node_argc;
char **node_argv;
NAMESPACE::Publisher comp_sync_pub;
NAMESPACE::Subscriber comp_sync_sub;
NAMESPACE::Timer init_timer;
NAMESPACE::CallbackQueue comp_queue;
std::unique_ptr<Logger> logger;
ComponentConfig config; /*!< Component Configuration */
int node_argc; /*!< argc received by the actor process */
char **node_argv; /*!< argv received by the actor process */
NAMESPACE::Publisher comp_sync_pub; /*!< Synchronization publisher */
NAMESPACE::Subscriber comp_sync_sub; /*!< Synchronization subscriber */
NAMESPACE::Timer init_timer; /*!< Initialization timer */
NAMESPACE::CallbackQueue comp_queue; /*!< Component Message Queue */
std::unique_ptr<Logger> logger; /*!< Component logger object */
};

#endif
65 changes: 56 additions & 9 deletions src/node/include/node/Logger.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/** @brief Logger.hpp
* @author Pranav Srinivas Kumar
* @date <%- Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') %>
* @brief This file declares the Component Logger class
*/

#ifndef LOGGER_HPP
#define LOGGER_HPP

Expand All @@ -9,42 +15,69 @@
#include <chrono>
#include <typeinfo>

/**
* @brief Logger class
*/
class Logger
{

public:

/**
* @brief Logger Constructor.
*/
Logger() {
logs_to_file_ = false;
is_periodic_ = true;
max_log_unit_ = 1;
log_content_ = "=================================================================\n";
}

/**
* @brief Makes Logging Periodic.
* @param[in] is_periodic boolean indicating whether logging is periodic.
*/
void set_is_periodic(bool is_periodic) {
is_periodic_ = is_periodic;
}

/**
* @brief Set maximum log unit in bytes during periodic logging.
* @param[in] max_log_unit maximum periodic logging unit in bytes.
*/
void set_max_log_unit(int max_log_unit) {
max_log_unit_ = max_log_unit;
}

/**
* @brief Log to file instead of stdout.
* @param[in] logs_to_file boolean requiring logging on file.
*/
void set_logs_to_file(bool logs_to_file) {
logs_to_file_ = logs_to_file;
}

/**
* @brief Writes out the remainder of the logs and closes logfile.
*/
~Logger() {
write();
log_stream_.close();
}

/**
* @brief Create log file
* @param[in] log_path path to log file.
*/
bool create_file(std::string log_path) {
log_path_ = log_path;
log_stream_.open(log_path_, std::ios::out | std::ios::app);
logs_to_file_ = true;
return true;
}


/**
* @brief Write logged bytes to file
*/
bool write() {
if (logs_to_file_) {
log_stream_ << log_content_;
Expand All @@ -55,6 +88,9 @@ class Logger
return true;
}

/**
* @brief Flush out to file.
*/
bool flush() {
if (is_periodic_ && size() > max_log_unit_) {
write();
Expand All @@ -64,6 +100,11 @@ class Logger
return false;
}

/**
* @brief Log to file with specific log_level.
* @param[in] log_level string indicating logging level.
* @param[in] format varargs input to logger.
*/
bool log(std::string log_level, const char * format, ...) {
va_list args;
va_start (args, format);
Expand All @@ -76,24 +117,30 @@ class Logger
flush();
}

/**
* @brief Return the current size of the log in bytes.
*/
int size() {
return log_content_.size();
}

/**
* @brief Return the current clock value.
*/
std::string clock() {
std::stringstream clock_string;
clock_string << clock_.now().time_since_epoch().count();
return clock_string.str();
}

private:
std::ofstream log_stream_;
std::string log_content_;
std::string log_path_;
bool is_periodic_;
bool logs_to_file_;
int max_log_unit_;
std::chrono::high_resolution_clock clock_;
std::ofstream log_stream_; /*!< Output log stream */
std::string log_content_; /*!< Log contents */
std::string log_path_; /*!< Log file path */
bool is_periodic_; /*!< Is logging periodic? */
bool logs_to_file_; /*!< Is logging to file? */
int max_log_unit_; /*!< Maximum log unit in bytes */
std::chrono::high_resolution_clock clock_; /*!< High resolution clock */
};

#endif
7 changes: 7 additions & 0 deletions src/node/src/node/Component.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/** @file Component.cpp
* @author William Emfinger
* @author Pranav Srinivas Kumar
* @date <%- Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') %>
* @brief This file contains definitions for the base Component class
*/

#include "node/Component.hpp"

// Constructor
Expand Down
10 changes: 10 additions & 0 deletions src/node/src/node/node_main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/** @file node_main.cpp
* @author William Emfinger
* @date <%- Date().toISOString().replace(/T/, ' ').replace(/\..+/, '') %>
* @brief This file contains the main function for a ROSMOD actor/node.
*/

#include <cstdlib>
#include <string.h>
#include <dlfcn.h>
Expand Down Expand Up @@ -25,6 +31,10 @@ void componentThreadFunc(Component* compPtr)

std::vector<boost::thread*> compThreads;

/**
* @brief Parses node configuration and spawns component executor threads.
*
*/
int main(int argc, char **argv)
{
std::string nodeName = "node";
Expand Down

0 comments on commit 6e03795

Please sign in to comment.