• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

acsNotificationServiceImpHandlerImpl.h

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 *    ALMA - Atacama Large Millimiter Array
00006 *    (c) European Southern Observatory, 2002
00007 *    Copyright by ESO (in the framework of the ALMA collaboration)
00008 *    and Cosylab 2002, All rights reserved
00009 *
00010 *    This library is free software; you can redistribute it and/or
00011 *    modify it under the terms of the GNU Lesser General Public
00012 *    License as published by the Free Software Foundation; either
00013 *    version 2.1 of the License, or (at your option) any later version.
00014 *
00015 *    This library is distributed in the hope that it will be useful,
00016 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 *    Lesser General Public License for more details.
00019 *
00020 *    You should have received a copy of the GNU Lesser General Public
00021 *    License along with this library; if not, write to the Free Software
00022 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00023 *
00024 * "@(#) $Id: acsNotificationServiceImpHandlerImpl.h,v 1.8 2009/12/22 10:46:43 msekoran Exp $"
00025 *
00026 * who       when      what
00027 * --------  --------  ----------------------------------------------
00028 * azagar   2008-09-30 created
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     /*************************** CORBA interface *****************************/
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     // add NOTIFY_FACTORY_NAME_STRING postfix, is not already there
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     // destroy check 
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     // do not monitor alarm notification service
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) { // no response
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) { // > 200ms
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

Generated on Thu Jan 12 2012 23:13:50 for ACS-10.0 C++ API by  doxygen 1.7.0