Skip to content
Snippets Groups Projects
Commit 710dfe08 authored by Karsten Suehring's avatar Karsten Suehring
Browse files

Merge branch 'clean47' into 'master'

Fix indentation and braces

See merge request !1995
parents 080c7d23 c35e230e
No related branches found
No related tags found
1 merge request!1995Fix indentation and braces
Pipeline #6040 passed
......@@ -47,83 +47,88 @@
#include "dtrace_next.h"
void Channel::update( std::map< CType, int > state )
{
for( std::list<Rule>::iterator rules_iter = rule_list.begin();
rules_iter != rule_list.end();
++rules_iter ) {
/* iterate over conditions, get the state of the condition type
* and check if contion is met:
* if not -> go to next rule
* yes -> go to next condition
* if all conditions are met: set channel active and return */
bool probe = true;
for( Rule::iterator cond_iter = rules_iter->begin();
cond_iter != rules_iter->end();
++cond_iter ) {
int sVal = state[cond_iter->type];
if( !cond_iter->eval( cond_iter->rval, sVal ) ) {
probe = false;
break;
}
}
if( probe ) {
_active = true;
return;
}
for (std::list<Rule>::iterator rules_iter = rule_list.begin(); rules_iter != rule_list.end(); ++rules_iter)
{
/* iterate over conditions, get the state of the condition type
* and check if contion is met:
* if not -> go to next rule
* yes -> go to next condition
* if all conditions are met: set channel active and return */
bool probe = true;
for (Rule::iterator cond_iter = rules_iter->begin(); cond_iter != rules_iter->end(); ++cond_iter)
{
int sVal = state[cond_iter->type];
if (!cond_iter->eval(cond_iter->rval, sVal))
{
probe = false;
break;
}
}
if (probe)
{
_active = true;
return;
}
}
_active = false;
_active = false;
}
void Channel::add( std::vector<Condition> rule )
{
rule_list.push_back( rule );
rule_list.push_back(rule);
}
static inline
std::vector<std::string> &split( const std::string &s, char delim, std::vector<std::string> &elems )
{
std::stringstream ss( s );
std::string item;
while ( std::getline( ss, item, delim ) ) {
elems.push_back( item );
}
return elems;
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim))
{
elems.push_back(item);
}
return elems;
}
static inline
std::vector<std::string> split( const std::string &s, char delim )
{
std::vector<std::string> elems;
split( s, delim, elems );
return elems;
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}
CDTrace::CDTrace( const char *filename, vstring channel_names )
: copy(false), m_trace_file(NULL), m_error_code( 0 )
{
if( filename )
m_trace_file = fopen( filename, "w" );
if (filename)
{
m_trace_file = fopen(filename, "w");
}
int i = 0;
for( vstring::iterator ci = channel_names.begin(); ci != channel_names.end(); ++ci ) {
deserializationTable[*ci] = i++;
chanRules.push_back( Channel() );
}
int i = 0;
for (vstring::iterator ci = channel_names.begin(); ci != channel_names.end(); ++ci)
{
deserializationTable[*ci] = i++;
chanRules.push_back(Channel());
}
}
CDTrace::CDTrace( const char *filename, const dtrace_channels_t& channels )
: copy( false ), m_trace_file( NULL ), m_error_code( 0 )
{
if( filename )
{
m_trace_file = fopen( filename, "w" );
}
//int i = 0;
for( dtrace_channels_t::const_iterator ci = channels.begin(); ci != channels.end(); ++ci ) {
for (dtrace_channels_t::const_iterator ci = channels.begin(); ci != channels.end(); ++ci)
{
deserializationTable[ci->channel_name] = ci->channel_number/*i++*/;
chanRules.push_back( Channel() );
}
......@@ -131,13 +136,13 @@ CDTrace::CDTrace( const char *filename, const dtrace_channels_t& channels )
CDTrace::CDTrace( const CDTrace& other )
{
copy = true;
m_trace_file = other.m_trace_file;
chanRules = other.chanRules;
condition_types = other.condition_types;
state = other.state;
deserializationTable = other.deserializationTable;
m_error_code = other.m_error_code;
copy = true;
m_trace_file = other.m_trace_file;
chanRules = other.chanRules;
condition_types = other.condition_types;
state = other.state;
deserializationTable = other.deserializationTable;
m_error_code = other.m_error_code;
}
CDTrace::CDTrace( const std::string& sTracingFile, const std::string& sTracingRule, const dtrace_channels_t& channels )
......@@ -152,28 +157,30 @@ CDTrace::CDTrace( const std::string& sTracingFile, const std::string& sTracingRu
void CDTrace::swap( CDTrace& other )
{
using std::swap;
CDTrace& first = *this;
CDTrace& second = other;
swap(first.copy,second.copy);
swap(first.m_trace_file,second.m_trace_file);
swap(first.chanRules,second.chanRules);
swap(first.condition_types,second.condition_types);
swap(first.state,second.state);
swap(first.deserializationTable,second.deserializationTable);
using std::swap;
CDTrace &first = *this;
CDTrace &second = other;
swap(first.copy, second.copy);
swap(first.m_trace_file, second.m_trace_file);
swap(first.chanRules, second.chanRules);
swap(first.condition_types, second.condition_types);
swap(first.state, second.state);
swap(first.deserializationTable, second.deserializationTable);
}
CDTrace& CDTrace::operator=( const CDTrace& other )
{
CDTrace tmp(other);
swap( tmp );
return *this;
CDTrace tmp(other);
swap(tmp);
return *this;
}
CDTrace::~CDTrace()
{
if( !copy && m_trace_file )
fclose( m_trace_file );
if (!copy && m_trace_file)
{
fclose(m_trace_file);
}
}
bool _cf_eq ( int bound, int val ) { return ( val==bound ); }
......@@ -183,65 +190,93 @@ bool _cf_ge ( int bound, int val ) { return ( val>=bound ); }
int CDTrace::addRule( std::string rulestring )
{
vstring chans_conds = split( rulestring, ':' );
vstring channels = split( chans_conds[0], ',' );
vstring conditions = split( chans_conds[1], ',' );
/* parse the rules first */
std::vector<Condition> rule;
for( vstring::iterator ci = conditions.begin(); ci != conditions.end(); ++ci ) {
/* find one of "==", "!=", "<=", ">=" */
const char *ops_[] = { "==", "!=", "<=", ">=" };
vstring operators( ops_,&ops_[sizeof( ops_ )/sizeof( ops_[0] )] );
vstring::iterator oi = operators.begin();
std::size_t pos = std::string::npos;
do {
if( ( pos = ci->find( *oi ) ) != std::string::npos ) break;
} while( ++oi != operators.end() );
/* No operator found, malformed rules string -> abort */
if( pos == std::string::npos ) return -2;
CType ctype( *ci,0,pos );
int value = std::atoi( ci->substr( pos+2, ci->length()-( pos+2 ) ).c_str() );
//if( condition_types.find( ctype ) == condition_types.end() ) return 0;
/* partially apply the condition value to the associated
* condtion function and append it to the rule */
bool ( *cfunc )( int,int );
if( "==" == *oi ) cfunc = _cf_eq;
else if( "!=" == *oi ) cfunc = _cf_neq;
else if( "<=" == *oi ) cfunc = _cf_le;
else if( ">=" == *oi ) cfunc = _cf_ge;
else return 0; // this is already taken care of
rule.push_back( Condition( ctype, cfunc, value ) );
vstring chans_conds = split(rulestring, ':');
vstring channels = split(chans_conds[0], ',');
vstring conditions = split(chans_conds[1], ',');
/* parse the rules first */
std::vector<Condition> rule;
for (vstring::iterator ci = conditions.begin(); ci != conditions.end(); ++ci)
{
/* find one of "==", "!=", "<=", ">=" */
const char * ops_[] = { "==", "!=", "<=", ">=" };
vstring operators(ops_, &ops_[sizeof(ops_) / sizeof(ops_[0])]);
vstring::iterator oi = operators.begin();
std::size_t pos = std::string::npos;
do
{
if ((pos = ci->find(*oi)) != std::string::npos)
{
break;
}
} while (++oi != operators.end());
/* No operator found, malformed rules string -> abort */
if (pos == std::string::npos)
{
return -2;
}
CType ctype(*ci, 0, pos);
int value = std::atoi(ci->substr(pos + 2, ci->length() - (pos + 2)).c_str());
// if( condition_types.find( ctype ) == condition_types.end() ) return 0;
/* partially apply the condition value to the associated
* condtion function and append it to the rule */
bool (*cfunc)(int, int);
if ("==" == *oi)
{
cfunc = _cf_eq;
}
else if ("!=" == *oi)
{
cfunc = _cf_neq;
}
else if ("<=" == *oi)
{
cfunc = _cf_le;
}
else if (">=" == *oi)
{
cfunc = _cf_ge;
}
else
{
return 0; // this is already taken care of
}
/* add the rule to each channel */
for( vstring::iterator chan_iter = channels.begin(); chan_iter != channels.end(); ++chan_iter ) {
std::map< Key, int>::iterator ichan = deserializationTable.find(*chan_iter);
if( ichan != deserializationTable.end() )
chanRules[ichan->second].add( rule );
else
return -3;
rule.push_back(Condition(ctype, cfunc, value));
}
/* add the rule to each channel */
for (vstring::iterator chan_iter = channels.begin(); chan_iter != channels.end(); ++chan_iter)
{
std::map<Key, int>::iterator ichan = deserializationTable.find(*chan_iter);
if (ichan != deserializationTable.end())
{
chanRules[ichan->second].add(rule);
}
else
{
return -3;
}
}
//return (int)channels.size();
return 0;
// return (int)channels.size();
return 0;
}
bool CDTrace::update( state_type stateval )
{
state[stateval.first] = stateval.second;
state[stateval.first] = stateval.second;
/* pass over all the channel rules */
for( std::vector< Channel >::iterator citer = chanRules.begin(); citer != chanRules.end(); ++citer )
{
citer->update( state );
}
/* pass over all the channel rules */
for (std::vector<Channel>::iterator citer = chanRules.begin(); citer != chanRules.end(); ++citer)
{
citer->update(state);
}
return true;
return true;
}
void CDTrace::getChannelsList( std::string& sChannels )
......@@ -251,7 +286,9 @@ void CDTrace::getChannelsList( std::string& sChannels )
if( deserializationTable.size() > 0 )
{
for( channel_map_t::iterator it = deserializationTable.begin(); it != deserializationTable.end(); ++it )
{
sChannels += it->first + "\n";
}
}
}
......@@ -261,8 +298,12 @@ const char* CDTrace::getChannelName( int channel_number )
if( deserializationTable.size() > 0 )
{
for( channel_map_t::iterator it = deserializationTable.begin(); it != deserializationTable.end(); ++it )
{
if( it->second == channel_number )
{
return it->first.c_str();
}
}
}
return not_found;
}
......@@ -273,9 +314,13 @@ std::string CDTrace::getErrMessage()
if( m_error_code )
{
if( m_error_code == -2 )
{
str = ( " - DTrace ERROR: Add tracing rule failed: DECERR_DTRACE_BAD_RULE" );
}
else if( m_error_code == -3 )
{
str = ( " - DTrace ERROR: Add tracing rule failed: DECERR_DTRACE_UNKNOWN_CHANNEL" );
}
else
{
str = " - DTrace ERROR: Undefined error";
......@@ -296,7 +341,9 @@ void CDTrace::dtrace( int k, const char *format, /*va_list args*/... )
fflush( m_trace_file );
va_end ( args );
if( bCount )
{
chanRules[k].incrementCounter();
}
}
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment