summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Decavel2009-11-06 10:03:52 +0100
committerBenjamin Decavel2009-11-06 10:03:52 +0100
commitc03120a4424ab1c83a9138f4a588553930d6dd1c (patch)
tree5e442f8cf6f90fd23c69c60e403ae7271dbe5e1d
parent75feffe595db974b35db513103ee70915bd624ba (diff)
SNMP agent: indented properly eventListener file
-rw-r--r--application/agent/src/eventListener.cpp341
1 files changed, 166 insertions, 175 deletions
diff --git a/application/agent/src/eventListener.cpp b/application/agent/src/eventListener.cpp
index 2a0e1795c8..084f823134 100644
--- a/application/agent/src/eventListener.cpp
+++ b/application/agent/src/eventListener.cpp
@@ -86,18 +86,19 @@ eventListener* eventListener::m_instance_p = 0;
-eventListener::eventListener()
+eventListener::eventListener()
{
#ifdef EVENT_STIMULATOR
- m_socket = new eventListenerTcpSocket(5502);
+ m_socket = new eventListenerTcpSocket(5502);
#else
- m_socket = new eventListenerNetlinkSocket();
+ m_socket = new eventListenerNetlinkSocket();
#endif
}
-eventListener::~eventListener(){
- //this->notify();
- delete m_socket;
+eventListener::~eventListener()
+{
+ //this->notify();
+ delete m_socket;
}
@@ -105,129 +106,132 @@ eventListener::~eventListener(){
void eventListener::run()
{
-
- union mib_event *event;
+ union mib_event *event;
#ifdef _REMOVE
- fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_MIB);
- if (fd<0) {
- perror("socket");
- exit(1);
- }
-
- memset(&src_addr, 0, sizeof(src_addr));
- src_addr.nl_family = AF_NETLINK;
- src_addr.nl_pid = getpid(); /* self pid */
- src_addr.nl_groups = 1; /* mcast group 1<<0 */
- if (bind(fd, (struct sockaddr*)&src_addr, sizeof(src_addr))<0) {
- perror("bind");
- exit(2);
- }
-
- /* Read message from kernel */
- nlh=(struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD));
- memset(nlh, 0, NLMSG_SPACE(MAX_PAYLOAD));
- memset(&dest_addr, 0, sizeof(dest_addr));
- iov.iov_base = (void *)nlh;
- iov.iov_len = NLMSG_SPACE(MAX_PAYLOAD);
- msg.msg_name = (void *)&dest_addr;
- msg.msg_namelen = sizeof(dest_addr);
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
-
- bool result = false;
-
- while (1) {
- DEBUG("waiting message from kernel"<<endl);
- recvmsg(fd, &msg, 0);
- event = (union mib_event*)NLMSG_DATA(nlh);
- if (event==NULL)
- {
- DEBUG("event received in NETLINK is NULL"<<endl);
- }
- else {
- switch(event->event_id) {
- case EV_HOST_UP:
- DEBUG("host up: "<< event->host_up.host_id<<endl);
- result = buildHostUpDown(event->host_up.host_id, event->host_up.mac_addr, false);
- break;
- case EV_HOST_DOWN:
- DEBUG("host down: "<< event->host_down.host_id<<endl);
- result = buildHostUpDown(event->host_down.host_id, event->host_down.mac_addr, true);
- break;
- case EV_MAX_ATTENUATION:
- DEBUG("max attenuation: "<< event->max_attenuation.host_id<<endl);
- result = buildMaxAttenuation(event->max_attenuation.host_id,
- event->max_attenuation.mac_addr, true);
- break;
- case EV_MAX_NOISE:
- DEBUG("max noise: "<< event->max_noise.host_id<<endl);
- result = buildMaxNoise(event->max_noise.host_id,
- event->max_noise.mac_addr, true);
- break;
- default:
- DEBUG("unrecognized event: "<< event->event_id<<endl);
- DEBUG("nlh->nlmsg_len = "<< nlh->nlmsg_len<<endl);
- }
- }
- }
- DEBUG("run out for listener!"<<endl);
+ fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_MIB);
+ if (fd<0)
+ {
+ perror("socket");
+ exit(1);
+ }
+
+ memset(&src_addr, 0, sizeof(src_addr));
+ src_addr.nl_family = AF_NETLINK;
+ src_addr.nl_pid = getpid(); /* self pid */
+ src_addr.nl_groups = 1; /* mcast group 1<<0 */
+ if (bind(fd, (struct sockaddr*)&src_addr, sizeof(src_addr))<0)
+ {
+ perror("bind");
+ exit(2);
+ }
+
+ /* Read message from kernel */
+ nlh=(struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PAYLOAD));
+ memset(nlh, 0, NLMSG_SPACE(MAX_PAYLOAD));
+ memset(&dest_addr, 0, sizeof(dest_addr));
+ iov.iov_base = (void *)nlh;
+ iov.iov_len = NLMSG_SPACE(MAX_PAYLOAD);
+ msg.msg_name = (void *)&dest_addr;
+ msg.msg_namelen = sizeof(dest_addr);
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+
+ bool result = false;
+
+ while (1)
+ {
+ DEBUG("waiting message from kernel"<<endl);
+ recvmsg(fd, &msg, 0);
+ event = (union mib_event*)NLMSG_DATA(nlh);
+ if (event==NULL)
+ {
+ DEBUG("event received in NETLINK is NULL"<<endl);
+ }
+ else
+ {
+ switch(event->event_id)
+ {
+ case EV_HOST_UP:
+ DEBUG("host up: "<< event->host_up.host_id<<endl);
+ result = buildHostUpDown(event->host_up.host_id, event->host_up.mac_addr, false);
+ break;
+ case EV_HOST_DOWN:
+ DEBUG("host down: "<< event->host_down.host_id<<endl);
+ result = buildHostUpDown(event->host_down.host_id, event->host_down.mac_addr, true);
+ break;
+ case EV_MAX_ATTENUATION:
+ DEBUG("max attenuation: "<< event->max_attenuation.host_id<<endl);
+ result = buildMaxAttenuation(event->max_attenuation.host_id, event->max_attenuation.mac_addr, true);
+ break;
+ case EV_MAX_NOISE:
+ DEBUG("max noise: "<< event->max_noise.host_id<<endl);
+ result = buildMaxNoise(event->max_noise.host_id, event->max_noise.mac_addr, true);
+ break;
+ default:
+ DEBUG("unrecognized event: "<< event->event_id<<endl);
+ DEBUG("nlh->nlmsg_len = "<< nlh->nlmsg_len<<endl);
+ }
+ }
+ }
+ DEBUG("run out for listener!"<<endl);
/* Close Netlink Socket */
close(fd);
- #endif
-
- if ( ! m_socket->create() )
- exit(1);
-
+#endif
+
+ if ( ! m_socket->create() )
+ exit(1);
+
usleep(3000000);
- while (1) {
- DEBUG("waiting message from kernel"<<endl);
- event = m_socket->listen();
- if (event==NULL)
- {
- DEBUG("event received in NETLINK is NULL"<<endl);
- }
- else {
- switch(event->event_id) {
- case EV_HOST_UP:
- DEBUG("host up: "<< event->host_up.host_id<<endl);
- buildHostUpDown(event->host_up.host_id, event->host_up.mac_addr, false);
- break;
- case EV_HOST_DOWN:
- DEBUG("host down: "<< event->host_down.host_id<<endl);
- buildHostUpDown(event->host_down.host_id, event->host_down.mac_addr, true);
- break;
- case EV_MAX_ATT:
- DEBUG("max attenuation: "<< event->max_attenuation.host_id<<endl);
- buildMaxAttenuation(event->max_attenuation.host_id,
- event->max_attenuation.mac_addr, true);
- break;
- case EV_MAX_NOISE:
- DEBUG("max noise: "<< event->max_noise.host_id<<endl);
- buildMaxNoise(event->max_noise.host_id, event->max_noise.mac_addr, true);
- break;
- default:
- DEBUG("unrecognized event: "<< event->event_id<<endl);
- DEBUG("nlh->nlmsg_len = "<< nlh->nlmsg_len<<endl);
+ while (1)
+ {
+ DEBUG("waiting message from kernel"<<endl);
+ event = m_socket->listen();
+ if (event==NULL)
+ {
+ DEBUG("event received in NETLINK is NULL"<<endl);
+ }
+ else
+ {
+ switch(event->event_id)
+ {
+ case EV_HOST_UP:
+ DEBUG("host up: "<< event->host_up.host_id<<endl);
+ buildHostUpDown(event->host_up.host_id, event->host_up.mac_addr, false);
+ break;
+ case EV_HOST_DOWN:
+ DEBUG("host down: "<< event->host_down.host_id<<endl);
+ buildHostUpDown(event->host_down.host_id, event->host_down.mac_addr, true);
+ break;
+ case EV_MAX_ATT:
+ DEBUG("max attenuation: "<< event->max_attenuation.host_id<<endl);
+ buildMaxAttenuation(event->max_attenuation.host_id, event->max_attenuation.mac_addr, true);
+ break;
+ case EV_MAX_NOISE:
+ DEBUG("max noise: "<< event->max_noise.host_id<<endl);
+ buildMaxNoise(event->max_noise.host_id, event->max_noise.mac_addr, true);
+ break;
+ default:
+ DEBUG("unrecognized event: "<< event->event_id<<endl);
+ DEBUG("nlh->nlmsg_len = "<< nlh->nlmsg_len<<endl);
}
- }
- }
- DEBUG("run out for listener!"<<endl);
+ }
+ }
+ DEBUG("run out for listener!"<<endl);
/* Close Netlink Socket */
m_socket->close();
-}
+}
eventListener* eventListener::instance()
{
- if ( m_instance_p == 0 )
- {
- m_instance_p = new eventListener();
-
- }
- return m_instance_p;
+ if ( m_instance_p == 0 )
+ {
+ m_instance_p = new eventListener();
+ }
+ return m_instance_p;
}
@@ -297,8 +301,7 @@ bool eventListener::buildEventForTrap(unsigned int iHostId, uint8_t mac_addr[],
//If consumer producer: changes are here: put in queue instead of treating
//The update automatically save the alarms in the file
- const AlarmObjectModel* aALarmMod =
- AlarmListManager::instance()->updateAlarmList(aAlarmFromEvent);
+ const AlarmObjectModel* aALarmMod = AlarmListManager::instance()->updateAlarmList(aAlarmFromEvent);
if (0 != aALarmMod)
{
@@ -330,28 +333,25 @@ bool eventListener::buildEventForTrap(unsigned int iHostId, uint8_t mac_addr[],
bool eventListener::sendTrap(aManagedObject, aPbCause, aEvent, aAlarmStatus, aTime, aDescription )
{
-
-
- //Build the alarm Object
- AlarmObjectModel aAlarmFromEvent(aManagedObject, aPbCause, aEvent, 0 , aAlarmStatus, aTime, aDescription );
-
+ //Build the alarm Object
+ AlarmObjectModel aAlarmFromEvent(aManagedObject, aPbCause, aEvent, 0 , aAlarmStatus, aTime, aDescription );
+
//If consumer producer: changes are here: put in queue instead of treating
- //The update automatically save the alarms in the file
- const AlarmObjectModel* aALarmMod = AlarmListManager::instance()->updateAlarmList(aAlarmFromEvent);
-
-
- if (0 != aALarmMod)
- {
- trapBuilder aTrapBuilder;
- aTrapBuilder.sendTrap(*aALarmMod);
- DEBUG("Trap should be sent"<<endl);
- result = true;
- }
- else
+ //The update automatically save the alarms in the file
+ const AlarmObjectModel* aALarmMod = AlarmListManager::instance()->updateAlarmList(aAlarmFromEvent);
+
+ if (0 != aALarmMod)
+ {
+ trapBuilder aTrapBuilder;
+ aTrapBuilder.sendTrap(*aALarmMod);
+ DEBUG("Trap should be sent"<<endl);
+ result = true;
+ }
+ else
{
- DEBUG( "Alarm returned by udpate is NULL !!!"<<endl);
+ DEBUG( "Alarm returned by udpate is NULL !!!"<<endl);
}
- return result;
+ return result;
}
@@ -366,45 +366,36 @@ bool eventListener::sendTrap(aManagedObject, aPbCause, aEvent, aAlarmStatus, aTi
int listenEvent(void)
{
- int listenSocket;
-
- struct sockaddr_in serverAddress;
- serverAddress.sin_family = PF_INET;
- serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
- serverAddress.sin_port = htons(SERVER_LISTENING_PORT);
-
-
- // Create socket for listening for client connection requests.
- if (listenSocket = socket(AF_INET, SOCK_DGRAM, 0) < 0)
- {
- perror("socket");
- exit(1);
- }
-
-
- // Bind listen socket to listen port. First set various fields in
- // the serverAddress structure, then call bind().
- // htonl() and htons() convert long integers and short integers
- // (respectively) from host byte order (on x86 this is Least
- // Significant Byte first) to network byte order (Most Significant
- // Byte first).
- struct sockaddr_in serverAddress;
- serverAddress.sin_family = PF_INET;
- serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
- serverAddress.sin_port = htons(SERVER_LISTENING_PORT);
-
- if (bind(listenSocket, (struct sockaddr *) &serverAddress, sizeof(serverAddress)) < 0)
- {
- perror("bind");
- exit(1);
- }
-
-
-
-
-
-
-
+ int listenSocket;
+
+ struct sockaddr_in serverAddress;
+ serverAddress.sin_family = PF_INET;
+ serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
+ serverAddress.sin_port = htons(SERVER_LISTENING_PORT);
+
+ // Create socket for listening for client connection requests.
+ if (listenSocket = socket(AF_INET, SOCK_DGRAM, 0) < 0)
+ {
+ perror("socket");
+ exit(1);
+ }
+
+ // Bind listen socket to listen port. First set various fields in
+ // the serverAddress structure, then call bind().
+ // htonl() and htons() convert long integers and short integers
+ // (respectively) from host byte order (on x86 this is Least
+ // Significant Byte first) to network byte order (Most Significant
+ // Byte first).
+ struct sockaddr_in serverAddress;
+ serverAddress.sin_family = PF_INET;
+ serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
+ serverAddress.sin_port = htons(SERVER_LISTENING_PORT);
+
+ if (bind(listenSocket, (struct sockaddr *) &serverAddress, sizeof(serverAddress)) < 0)
+ {
+ perror("bind");
+ exit(1);
+ }
}
*/