#include <rmr/RIC_message_types.h>
#ifndef RIC_ALARM
- #define RIC_ALARM 110
+ // this _should_ come from the message types header, but if not ensure we have something
+ constexpr int ric_alarm_value = 110;
+ #define RIC_ALARM ric_alarm_value
#endif
#include <iostream>
#include "message.hpp"
#include "alarm.hpp"
-extern char* __progname; // runtime lib supplied since we don't get argv[0]
+extern const char* __progname; // runtime lib supplied since we don't get argv[0]
namespace xapp {
then we assume 4560 (the defacto RMR listen port).
*/
static std::string endpoint_addr( ) {
- char* et; // environment token
+ const char* et; // environment token
std::string addr = "localhost";
std::string port = "4560";
Returns the length of the payload inserted.
*/
int xapp::Alarm::build_alarm( int action_id, xapp::Msg_component payload, int payload_len ) {
- //char wbuf[4096];
- std::string action;
+ std::string maction; // message action is a text string
int used;
if( app_id.compare( "" ) == 0 ) {
switch( action_id ) {
case Alarm::ACT_CLEAR:
- action = "CLEAR";
+ maction = "CLEAR";
break;
case Alarm::ACT_CLEAR_ALL:
- action = "CLEARALL";
+ maction = "CLEARALL";
break;
default:
- action = "RAISE";
+ maction = "RAISE";
break;
}
- //memset( wbuf, 0, sizeof( wbuf ) );
- //snprintf( wbuf, sizeof( wbuf ),
used = snprintf( (char *) payload.get(), payload_len,
"{ "
"\"managedObjectId\": \"%s\", "
severity.c_str(),
info.c_str(),
add_info.c_str(),
- action.c_str(),
+ maction.c_str(),
now()
);
*/
xapp::Alarm::Alarm( std::shared_ptr<Message> msg ) :
msg( msg ),
- endpoint( endpoint_addr() ),
- whid( -1 ),
- app_id( "" ),
- me_id( "" ),
- problem_id( -1 ),
- info( "" ),
- add_info( "" ),
- action( "" )
+ endpoint( endpoint_addr() )
{ /* empty body */ }
/*
Parameterised constructor (avoids calling setters after creation).
*/
-xapp::Alarm::Alarm( std::shared_ptr<Message> msg, int prob_id, std::string meid ) :
+xapp::Alarm::Alarm( std::shared_ptr<Message> msg, int prob_id, const std::string& meid ) :
msg( msg ),
endpoint( endpoint_addr() ),
- whid( -1 ),
- app_id( "" ),
me_id( meid ),
- problem_id( prob_id ),
- info( "" ),
- add_info( "" ),
- action( "" )
+ problem_id( prob_id )
{ /* empty body */ }
-xapp::Alarm::Alarm( std::shared_ptr<Message> msg, std::string meid ) :
+xapp::Alarm::Alarm( std::shared_ptr<Message> msg, const std::string& meid ) :
msg( msg ),
endpoint( endpoint_addr() ),
- whid( -1 ),
- app_id( "" ),
- me_id( meid ),
- problem_id( -1 ),
- info( "" ),
- add_info( "" ),
- action( "" )
+ me_id( meid )
{ /* empty body */ }
Copy builder. Given a source object instance (soi), create a copy.
Creating a copy should be avoided as it can be SLOW!
*/
-xapp::Alarm::Alarm( const Alarm& soi ) {
- msg = soi.msg;
- endpoint = soi.endpoint;
- whid = soi.whid;
-
- me_id = soi.me_id; // user stuff
- app_id = soi.app_id;
- problem_id = soi.problem_id;
- severity = soi.severity;
- info = soi.info;
- add_info = soi.add_info;
-}
+xapp::Alarm::Alarm( const Alarm& soi ) :
+ msg( soi.msg ),
+ endpoint( soi.endpoint ),
+ whid( soi.whid ),
+
+ me_id( soi.me_id ), // user stuff
+ app_id( soi.app_id ),
+ problem_id( soi.problem_id ),
+ severity( soi.severity ),
+ info( soi.info ),
+ add_info( soi.add_info )
+{ /* empty body */ }
/*
Assignment operator. Simiolar to the copycat, but "this" object exists and
msg = soi.msg;
endpoint = soi.endpoint;
whid = soi.whid;
-
me_id = soi.me_id;
app_id = soi.app_id;
problem_id = soi.problem_id;
the soi ensuring that the destriction of the soi doesn't trash things from
under us.
*/
-xapp::Alarm::Alarm( Alarm&& soi ) {
- msg = soi.msg; // capture pointers and copy data before setting soruce things to nil
- endpoint = soi.endpoint;
- whid = soi.whid;
-
- me_id = soi.me_id;
- app_id = soi.app_id;
- problem_id = soi.problem_id;
- severity = soi.severity;
- info = soi.info;
- add_info = soi.add_info;
+xapp::Alarm::Alarm( Alarm&& soi ) :
+ msg( soi.msg ), // order must match .hpp else sonar complains
+ endpoint( soi.endpoint ),
+ whid( soi.whid ),
+ me_id( soi.me_id ),
+ app_id( soi.app_id ),
+ problem_id( soi.problem_id ),
+ severity( soi.severity ),
+ info( soi.info ),
+ add_info( soi.add_info )
+{
soi.msg = NULL; // prevent closing of RMR stuff on soi destroy
}
// ---- setters -------------------------------------------------
-void xapp::Alarm::Set_meid( std::string new_meid ) {
+void xapp::Alarm::Set_meid( const std::string& new_meid ) {
me_id = new_meid;
}
}
}
-void xapp::Alarm::Set_appid( std::string new_id ) {
+void xapp::Alarm::Set_appid( const std::string& new_id ) {
app_id = new_id;
}
problem_id = new_id;
}
-void xapp::Alarm::Set_info( std::string new_info ) {
+void xapp::Alarm::Set_info( const std::string& new_info ) {
info = new_info;
}
-void xapp::Alarm::Set_additional( std::string new_info ) {
+void xapp::Alarm::Set_additional( const std::string& new_info ) {
add_info = new_info;
}
whid = new_whid;
}
-void xapp::Alarm::Dump() {
+const void xapp::Alarm::Dump() {
fprintf( stderr, "Alarm: prob id: %d\n", problem_id );
fprintf( stderr, "Alarm: meid: %s\n", me_id.c_str() );
fprintf( stderr, "Alarm: app: %s\n", app_id.c_str() );
/*
Return the enpoint address string we have.
*/
-std::string xapp::Alarm::Get_endpoint( ) {
+const std::string xapp::Alarm::Get_endpoint( ) {
return endpoint;
}
problem ID. Info and addional_info are user supplied data that is just passed
through.
*/
-bool xapp::Alarm::Raise( int severity, int problem, std::string info ) {
- this->severity = severity;
+bool xapp::Alarm::Raise( int new_severity, int problem, const std::string& info ) {
+ Set_severity( new_severity );
problem_id = problem;
this->info = info;
Raise();
}
-bool xapp::Alarm::Raise( int severity, int problem, std::string info, std::string additional_info ) {
- this->severity = severity;
+bool xapp::Alarm::Raise( int new_severity, int problem, const std::string& info, const std::string& additional_info ) {
+ Set_severity( new_severity );
problem_id = problem;
this->info = info;
this->add_info = additional_info;
problem ID. Info and addional_info are user supplied data that is just passed
through.
*/
-bool xapp::Alarm::Clear( int severity, int problem, std::string info ) {
- this->severity = severity;
+bool xapp::Alarm::Clear( int new_severity, int problem, const std::string& info ) {
+ Set_severity( new_severity );
problem_id = problem;
this->info = info;
Clear();
}
-bool xapp::Alarm::Clear( int severity, int problem, std::string info, std::string additional_info ) {
- this->severity = severity;
+bool xapp::Alarm::Clear( int new_severity, int problem, const std::string& info, const std::string& additional_info ) {
+ Set_severity( new_severity );
problem_id = problem;
this->info = info;
this->add_info = additional_info;