AlarmNotifications
PANDA Slow Control Alarm Daemon
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
alarmconfiguration.cpp
Go to the documentation of this file.
1 
34 #include <iostream>
35 #include <stdexcept>
36 #include <QtCore/QList>
37 
38 #include "alarmconfiguration.h"
39 #include "exceptionhandler.h"
40 #include "configfilelocation.inc"
41 
42 using namespace AlarmNotifications;
43 
45 {
46  try {
47  static AlarmConfiguration global_instance;
48  return global_instance;
49  }
50  catch ( std::exception& e )
51  {
52  ExceptionHandler ( e, "while instanciating AlarmConfiguration.", true );
53  exit ( 1 ); // ExceptionHandler will also call exit(), but g++ does not know when compiling this
54  // so it will complain about a missing return value
55  }
56  catch ( ... )
57  {
58  ExceptionHandler ( "while instanciating AlarmConfiguration.", true );
59  exit ( 1 ); // ExceptionHandler will also call exit(), but g++ does not know when compiling this
60  // so it will complain about a missing return value
61  }
62 }
63 
65  : _configfilelocation ( CreateConfigFileLocation() ),
66  _backend ( KSharedConfig::openConfig ( QString::fromUtf8 ( _configfilelocation.c_str() ) , KConfig::SimpleConfig ) ),
67  _skeleton ( _backend )
68 {
70 }
71 
73 {
74  _backend->sync();
75 }
76 
78 {
79  return _configfilelocation;
80 }
81 
83 {
84  _backend->markAsClean();
85  _backend->reparseConfiguration();
86  _skeleton.readConfig();
87 }
88 
90 {
91  _skeleton.writeConfig();
92  _backend->sync();
93 }
94 
96 {
97  _skeleton.setCurrentGroup ( QString::fromUtf8 ( "ActiveMQConnectivity" ) );
98  _activemquriitem = _skeleton.addItemString ( "ActiveMQURI", _activemquri, "failover:(tcp://localhost:61616)" );
99  _activemqusernameitem = _skeleton.addItemString ( "ActiveMQUsername", _activemqusername );
100  _activemqpassworditem = _skeleton.addItemString ( "ActiveMQPassword", _activemqpassword );
101  _activemqtopicnameitem = _skeleton.addItemString ( "ActiveMQTopicName", _activemqtopicname );
102  _laboratorynotificationtimeoutitem = _skeleton.addItemUInt ( "LaboratoryNotificationTimeout", _laboratorynotificationtimeout, 0 );
103  _desktopnotificationtimeoutitem = _skeleton.addItemUInt ( "DesktopNotificationTimeout", _desktopnotificationtimeout, 0 );
104  _emailnotificationtimeoutitem = _skeleton.addItemUInt ( "EMailNotificationTimeout", _emailnotificationtimeout, 0 );
105  _emailnotificationfromitem = _skeleton.addItemString ( "EMailNotificationFrom", _emailnotificationfrom );
106  _emailnotificationtoitem = _skeleton.addItemString ( "EMailNotificationTo", _emailnotificationto );
107  _emailnotificationservernameitem = _skeleton.addItemString ( "EMailNotificationServerName", _emailnotificationservername );
108  _emailnotificationserverportitem = _skeleton.addItemUInt ( "EMailNotificationServerPort", _emailnotificationserverport );
109  _emailnotificationserverportitem->setMinValue ( 0 ); // Minimum port number in TCP standard
110  _emailnotificationserverportitem->setMaxValue ( 65535 ); // Maximum port number in TCP standard
111  _flashlightrelaisdevicenodeitem = _skeleton.addItemString ( "FlashLightRelaisDeviceNode", _flashlightrelaisdevicenode );
112 }
113 
115 {
116  return std::string ( _activemquri.toUtf8().data() );
117 }
118 
119 void AlarmConfiguration::setActiveMQURI ( const std::string& newSetting )
120 {
121  _activemquriitem->setValue ( QString::fromUtf8 ( newSetting.c_str() ) );
122 }
123 
125 {
126  return std::string ( _activemqusername.toUtf8().data() );
127 }
128 
129 void AlarmConfiguration::setActiveMQUsername ( const std::string& newSetting )
130 {
131  _activemqusernameitem->setValue ( QString::fromUtf8 ( newSetting.c_str() ) );
132 }
133 
135 {
136  return std::string ( _activemqpassword.toUtf8().data() );
137 }
138 
139 void AlarmConfiguration::setActiveMQPassword ( const std::string& newSetting )
140 {
141  _activemqpassworditem->setValue ( QString::fromUtf8 ( newSetting.c_str() ) );
142 }
143 
145 {
146  return std::string ( _activemqtopicname.toUtf8().data() );
147 }
148 
149 void AlarmConfiguration::setActiveMQTopicName ( const std::string& newSetting )
150 {
151  _activemqtopicnameitem->setValue ( QString::fromUtf8 ( newSetting.c_str() ) );
152 }
153 
155 {
157 }
158 
159 void AlarmConfiguration::setLaboratoryNotificationTimeout ( const unsigned int newSetting )
160 {
161  _laboratorynotificationtimeoutitem->setValue ( newSetting );
162 }
163 
165 {
167 }
168 
169 void AlarmConfiguration::setDesktopNotificationTimeout ( const unsigned int newSetting )
170 {
171  _desktopnotificationtimeoutitem->setValue ( newSetting );
172 }
173 
175 {
177 }
178 
179 void AlarmConfiguration::setEMailNotificationTimeout ( const unsigned int newSetting )
180 {
181  _emailnotificationtimeoutitem->setValue ( newSetting );
182 }
183 
185 {
186  return std::string ( _emailnotificationfrom.toUtf8().data() );
187 }
188 
189 void AlarmConfiguration::setEMailNotificationFrom ( const std::string& newSetting )
190 {
191  _emailnotificationfromitem->setValue ( QString::fromUtf8 ( newSetting.c_str() ) );
192 }
193 
195 {
196  return std::string ( _emailnotificationto.toUtf8().data() );
197 }
198 
199 void AlarmConfiguration::setEMailNotificationTo ( const std::string& newSetting )
200 {
201  _emailnotificationtoitem->setValue ( QString::fromUtf8 ( newSetting.c_str() ) );
202 }
203 
205 {
206  return std::string ( _emailnotificationservername.toUtf8().data() );
207 }
208 
209 void AlarmConfiguration::setEMailNotificationServerName ( const std::string& newSetting )
210 {
211  _emailnotificationservernameitem->setValue ( QString::fromUtf8 ( newSetting.c_str() ) );
212 }
213 
215 {
217 }
218 
219 void AlarmConfiguration::setEMailNotificationServerPort ( const unsigned int newSetting )
220 {
221  _emailnotificationserverportitem->setValue ( newSetting );
222 }
223 
225 {
226  return std::string ( _flashlightrelaisdevicenode.toUtf8().data() );
227 }
228 
229 void AlarmConfiguration::setFlashLightRelaisDevideNode ( const std::string& newSetting )
230 {
231  _flashlightrelaisdevicenodeitem->setValue ( QString::fromUtf8 ( newSetting.c_str() ) );
232 }
233 
235 {
236  return _backend;
237 }
238 
240 {
241  return &_skeleton;
242 }
243 
245 {
246  const char*const envvar = getenv ( "ALARMNOTIFICATIONSCONFIG" );
247  if ( envvar == nullptr )
248  if ( getenv ( "HOME" ) != nullptr )
249  {
250  std::string conffile ( CONFIGFILELOCATION );
251  if ( conffile.find ( "~" ) != std::string::npos )
252  conffile.replace ( conffile.find ( "~" ), 1, getenv ( "HOME" ) );
253  return conffile;
254  }
255  else
256  {
257  return std::string ( CONFIGFILELOCATION );
258  }
259  else
260  return std::string ( envvar );
261 }
KConfigSkeleton _skeleton
KConfig skeleton.
std::string getEMailNotificationTo() const noexcept
Recipient address for alarm e-mail notifications.
unsigned int _desktopnotificationtimeout
Timeout for sending a desktop notification.
KConfigSkeleton * internal_skel()
INTERNAL METHOD: Skeleton of the configuration.
QString _emailnotificationservername
Name of the SMTP server.
QString _activemqpassword
ActiveMQ password.
unsigned int getEMailNotificationTimeout() const noexcept
Timeout for sending an e-mail notification.
unsigned int getEMailNotificationServerPort() const noexcept
Port of SMTP server.
void ReReadConfiguration()
Read configuration again from disk.
KConfigSkeleton::ItemUInt * _emailnotificationserverportitem
KConfig item for _emailnotificationserverport setting.
unsigned int getLaboratoryNotificationTimeout() const noexcept
Timeout for starting alarm notification in the laboratory.
void setActiveMQTopicName(const std::string &newSetting)
Change JMS topic used by the CSS Alarm Server.
void setEMailNotificationTo(const std::string &newSetting)
Change the recipient address for alarm e-mail notifications.
void setFlashLightRelaisDevideNode(const std::string &newSetting)
Change the device node of the USB relais for the alarm flash light.
KConfigSkeleton::ItemString * _activemquriitem
KConfig item for _activemquri setting.
QString _emailnotificationto
Recipient address for alarm e-mail notifications.
QString _flashlightrelaisdevicenode
Device node of the USB relais for the alarm flash light.
std::string getActiveMQUsername() const noexcept
ActiveMQ connection username.
KConfigSkeleton::ItemUInt * _emailnotificationtimeoutitem
KConfig item for _emailnotificationtimeout setting.
QString _activemqtopicname
JMS topic name used by CSS Alarm Server.
KConfigSkeleton::ItemString * _activemqpassworditem
KConfig item for _activemqpassword setting.
void setEMailNotificationServerName(const std::string &newSetting)
Change the name of the STMP server.
void WriteConfiguration()
Write configuration to disk.
std::string getEMailNotificationFrom() const noexcept
Sender address for alarm e-mail notifications.
void setEMailNotificationFrom(const std::string &newSetting)
Change the Sender address for alarm e-mail notifications.
void CreateActiveMQConnectivitySettings()
Create ActiveMQ connectivity settings.
std::string getActiveMQTopicName() const noexcept
JMS topic used by the CSS Alarm Server.
KConfigSkeleton::ItemString * _activemqtopicnameitem
KConfig item for _activemqtopicname setting.
void setEMailNotificationTimeout(const unsigned int newSetting)
Change the timeout for sending an e-mail notification.
void setEMailNotificationServerPort(const unsigned int newSetting)
Change the port of SMTP server.
unsigned int _emailnotificationserverport
Port of SMTP server.
const std::string & getConfigFileLocation() const noexcept
Query config file location.
void setLaboratoryNotificationTimeout(const unsigned int newSetting)
Change the timeout for starting alarm notification in the laboratory.
Namespace for Alarm Notifications application.
#define CONFIGFILELOCATION
Default path for the AlarmWatcher configuration file.
Macro for the default path of the configuration file.
KSharedConfigPtr internal()
INTERNAL METHOD: Shared pointer to KConfig instance.
const std::string _configfilelocation
Path to the configuration file.
unsigned int _emailnotificationtimeout
Timeout for sending an e-mail notification.
QString _activemqusername
ActiveMQ username.
KConfigSkeleton::ItemString * _activemqusernameitem
KConfig item for _activemqusername setting.
static std::string CreateConfigFileLocation()
Establish location of the configuration file.
void setActiveMQUsername(const std::string &newSetting)
Change ActiveMQ connection username.
KConfigSkeleton::ItemString * _emailnotificationservernameitem
KConfig item for _emailnotificationservername setting.
void setActiveMQURI(const std::string &newSetting)
Change ActiveMQ connection URI.
std::string getEMailNotificationServerName() const noexcept
Name of the SMTP server.
#define noexcept
Allow using the noexcept keyword with GCC < 4.6.
Definition: oldgcccompat.h:52
void ExceptionHandler(std::exception &e, std::string location, const bool quit=false) noexcept
Generic exception handler for known exceptions.
KSharedConfigPtr _backend
KConfig backend.
unsigned int getDesktopNotificationTimeout() const noexcept
Timeout for sending a desktop notification.
void setActiveMQPassword(const std::string &newSetting)
Change ActiveMQ connection password.
KConfigSkeleton::ItemUInt * _laboratorynotificationtimeoutitem
KConfig item for _laboratorynotificationtimeout setting.
Generic functions for exception handling.
void setDesktopNotificationTimeout(const unsigned int newSetting)
Change the timeout for sending a desktop notification.
KConfigSkeleton::ItemUInt * _desktopnotificationtimeoutitem
KConfig item for _desktopnotificationtimeout setting.
std::string getActiveMQPassword() const noexcept
ActiveMQ connection password.
std::string getActiveMQURI() const noexcept
ActiveMQ connection URI.
KConfigSkeleton::ItemString * _emailnotificationfromitem
KConfig item for _emailnotificationfrom setting.
KConfigSkeleton::ItemString * _flashlightrelaisdevicenodeitem
KConfig item for _flashlightrelaisdevicenode setting.
Singleton to read and change the configuration of this application.
QString _emailnotificationfrom
Sender address for alarm e-mail notifications.
static AlarmConfiguration & instance() noexcept
Get singleton instance.
KConfigSkeleton::ItemString * _emailnotificationtoitem
KConfig item for _emailnotificationto setting.
Configuration of the AlarmNotifications application.
std::string getFlashLightRelaisDeviceNode() const noexcept
Device node of the USB relais for the alarm flash light.
unsigned int _laboratorynotificationtimeout
Timeout for starting alarm notification in the laboratory.