Go to the documentation of this file.00001 #ifndef _ACS_NOTIFICATION_SERVICE_IMP_HANDLER_IMPL_H_
00002 #define _ACS_NOTIFICATION_SERVICE_IMP_HANDLER_IMPL_H_
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 #ifndef __cplusplus
00032 #error This is a C++ include file and cannot be used from plain C
00033 #endif
00034 
00035 #include "acsImpBaseHandlerImpl.h"
00036 #include "acsNotificationServiceMonitor.h"
00037 
00038 #include <map>
00039 
00040 typedef std::map<ACSServiceRequestDescription*, NotificationServiceMonitor*> MonitorMap;
00041 
00042 class ACSNotificationServiceImpHandlerImpl : public ACSImpBaseHandlerImpl<ACSNotificationServiceImpHandlerImpl>, public POA_acsdaemon::NotificationServiceImp {
00043 private:
00044   MonitorMap monitorMap;
00045   int intervalCount;
00046 public:
00047 
00048     ACSNotificationServiceImpHandlerImpl() : ACSImpBaseHandlerImpl<ACSNotificationServiceImpHandlerImpl>(NOTIFICATION_SERVICE) {}
00049    
00050     virtual ~ACSNotificationServiceImpHandlerImpl()
00051     {  
00052       MonitorMap::iterator iter = monitorMap.begin();
00053       for (; iter != monitorMap.end(); iter++)
00054       {
00055         NotificationServiceMonitor* nsm = iter->second;
00056         nsm->destroy();
00057         delete nsm;
00058       }
00059     } 
00060 
00061     
00062 
00063     void start_notification_service (
00064         const char * name,
00065         acsdaemon::DaemonCallback_ptr callback,
00066         CORBA::Short instance_number)
00067       ACE_THROW_SPEC ((
00068         ACSErrTypeCommon::BadParameterEx,
00069         acsdaemonErrType::ServiceAlreadyRunningEx
00070       )) {
00071         if (name != NULL && strlen(name) == 0) name = NULL;
00072         ACS_SHORT_LOG ((LM_INFO, "Starting '%s' Notification Service on Imp (instance %d).", name == NULL ? "default" : name, instance_number));
00073         ACSServiceRequestDescription *desc = new ACSServiceRequestDescription(NOTIFICATION_SERVICE, instance_number);
00074         desc->setName(name);
00075     #define NOTIFY_FACTORY_NAME_STRING "NotifyEventChannelFactory"
00076     
00077     if (name != NULL) {
00078         int lendiff = (int)strlen(name) - strlen(NOTIFY_FACTORY_NAME_STRING);
00079         if (lendiff < 0 || strcmp(name + lendiff, NOTIFY_FACTORY_NAME_STRING) != 0)
00080             desc->setCorbalocName((ACE_CString(name) + NOTIFY_FACTORY_NAME_STRING).c_str());
00081 
00082     }
00083         context->processRequest(LOCAL, START_SERVICE, desc, callback);
00084     }
00085 
00086     void stop_notification_service (
00087         const char * name,
00088         acsdaemon::DaemonCallback_ptr callback,
00089         CORBA::Short instance_number)
00090       ACE_THROW_SPEC ((
00091         ACSErrTypeCommon::BadParameterEx,
00092         acsdaemonErrType::ServiceNotRunningEx
00093       )) {
00094         if (name != NULL && strlen(name) == 0) name = NULL;
00095         ACS_SHORT_LOG ((LM_INFO, "Stopping '%s' Notification Service on Imp (instance %d).", name == NULL ? "default" : name, instance_number));
00096         ACSServiceRequestDescription *desc = new ACSServiceRequestDescription(NOTIFICATION_SERVICE, instance_number);
00097         desc->setName(name);
00098         context->processRequest(LOCAL, STOP_SERVICE, desc, callback);
00099     }
00100 
00101     acsdaemon::ServiceState get_service_status(const char * name, CORBA::Short instance_number)
00102       ACE_THROW_SPEC ((
00103         ACSErrTypeCommon::BadParameterEx
00104       )) {
00105         return context->getACSServiceState(instance_number, name);
00106     }
00107 
00108     virtual acsdaemon::ServiceState getDetailedServiceState(ACSServiceRequestDescription *desc, CORBA::Object_ptr obj) {
00109 
00110     
00111     if (obj == 0)
00112     { 
00113       if (monitorMap.find(desc) != monitorMap.end())
00114       {  
00115         NotificationServiceMonitor* nsm = monitorMap[desc];
00116         nsm->destroy();
00117         monitorMap.erase(desc);
00118         delete nsm;
00119       }
00120       return acsdaemon::DEFUNCT;
00121     }
00122 
00123     bool isRightNCType = obj->_is_a("IDL:sandia.gov/NotifyMonitoringExt/EventChannelFactory:1.0");
00124     if (!isRightNCType) {
00125                 ACS_SHORT_LOG((LM_ERROR, "%s does not extend required interface, reported as defunctional.", desc->getName()));
00126                 return acsdaemon::DEFUNCT;
00127     }
00128     
00129     
00130     if (ACE_OS::strcmp(desc->getName(), "AlarmNotifyEventChannelFactory") == 0 ||
00131         ACE_OS::strcmp(desc->getName(), "Alarm") == 0)
00132       return acsdaemon::RUNNING;
00133     
00134     if (monitorMap.find(desc) == monitorMap.end())
00135     {
00136       CosNotifyChannelAdmin::EventChannelFactory_var ecf = CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj);
00137       NotificationServiceMonitor* nsm = new NotificationServiceMonitor(ecf.in());
00138       nsm->init();
00139       monitorMap[desc] = nsm;
00140       nsm->issuePingEvent();
00141       return acsdaemon::RUNNING;
00142     }
00143     else
00144     {
00145       NotificationServiceMonitor* nsm = monitorMap[desc];
00146       CORBA::ULongLong rtt = nsm->getAndResetRTT();
00147       nsm->issuePingEvent();
00148       if (rtt < 0) { 
00149         ACS_SHORT_LOG((LM_DEBUG, "%s is not responsive, reported as defunctional.", desc->getName()));
00150         return acsdaemon::DEFUNCT;
00151       }
00152       else if (rtt > 200000) { 
00153         ACS_SHORT_LOG((LM_DEBUG, "%s response time is slow, reported as degraded.", desc->getName()));
00154         return acsdaemon::DEGRADED;
00155       }
00156       else
00157         return acsdaemon::RUNNING;
00158     }
00159 
00160   }
00161 
00162 };
00163 
00164 
00165 #endif