• 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.9 2012/12/12 07:27:31 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) throw(ACSErrTypeCommon::BadParameterEx, acsdaemonErrType::ServiceAlreadyRunningEx) {
00067         if (name != NULL && strlen(name) == 0) name = NULL;
00068         ACS_SHORT_LOG ((LM_INFO, "Starting '%s' Notification Service on Imp (instance %d).", name == NULL ? "default" : name, instance_number));
00069         ACSServiceRequestDescription *desc = new ACSServiceRequestDescription(NOTIFICATION_SERVICE, instance_number);
00070         desc->setName(name);
00071     #define NOTIFY_FACTORY_NAME_STRING "NotifyEventChannelFactory"
00072     // add NOTIFY_FACTORY_NAME_STRING postfix, is not already there
00073     if (name != NULL) {
00074         int lendiff = (int)strlen(name) - strlen(NOTIFY_FACTORY_NAME_STRING);
00075         if (lendiff < 0 || strcmp(name + lendiff, NOTIFY_FACTORY_NAME_STRING) != 0)
00076             desc->setCorbalocName((ACE_CString(name) + NOTIFY_FACTORY_NAME_STRING).c_str());
00077 
00078     }
00079         context->processRequest(LOCAL, START_SERVICE, desc, callback);
00080     }
00081 
00082     void stop_notification_service (
00083         const char * name,
00084         acsdaemon::DaemonCallback_ptr callback,
00085         CORBA::Short instance_number) throw(ACSErrTypeCommon::BadParameterEx, acsdaemonErrType::ServiceNotRunningEx) {
00086         if (name != NULL && strlen(name) == 0) name = NULL;
00087         ACS_SHORT_LOG ((LM_INFO, "Stopping '%s' Notification Service on Imp (instance %d).", name == NULL ? "default" : name, instance_number));
00088         ACSServiceRequestDescription *desc = new ACSServiceRequestDescription(NOTIFICATION_SERVICE, instance_number);
00089         desc->setName(name);
00090         context->processRequest(LOCAL, STOP_SERVICE, desc, callback);
00091     }
00092 
00093     acsdaemon::ServiceState get_service_status(const char * name, CORBA::Short instance_number) throw(ACSErrTypeCommon::BadParameterEx) {
00094         return context->getACSServiceState(instance_number, name);
00095     }
00096 
00097     virtual acsdaemon::ServiceState getDetailedServiceState(ACSServiceRequestDescription *desc, CORBA::Object_ptr obj) {
00098 
00099     // destroy check 
00100     if (obj == 0)
00101     { 
00102       if (monitorMap.find(desc) != monitorMap.end())
00103       {  
00104         NotificationServiceMonitor* nsm = monitorMap[desc];
00105         nsm->destroy();
00106         monitorMap.erase(desc);
00107         delete nsm;
00108       }
00109       return acsdaemon::DEFUNCT;
00110     }
00111 
00112     bool isRightNCType = obj->_is_a("IDL:sandia.gov/NotifyMonitoringExt/EventChannelFactory:1.0");
00113     if (!isRightNCType) {
00114                 ACS_SHORT_LOG((LM_ERROR, "%s does not extend required interface, reported as defunctional.", desc->getName()));
00115                 return acsdaemon::DEFUNCT;
00116     }
00117     
00118     if (monitorMap.find(desc) == monitorMap.end())
00119     {
00120       CosNotifyChannelAdmin::EventChannelFactory_var ecf = CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj);
00121       NotificationServiceMonitor* nsm = new NotificationServiceMonitor(ecf.in());
00122       nsm->init();
00123       monitorMap[desc] = nsm;
00124       nsm->issuePingEvent();
00125       return acsdaemon::RUNNING;
00126     }
00127     else
00128     {
00129       NotificationServiceMonitor* nsm = monitorMap[desc];
00130       CORBA::ULongLong rtt = nsm->getAndResetRTT();
00131       nsm->issuePingEvent();
00132       if (rtt < 0) { // no response
00133         ACS_SHORT_LOG((LM_ERROR, "%s is not responsive, reported as defunctional.", desc->getName()));
00134         return acsdaemon::DEFUNCT;
00135       }
00136       else if (rtt > 200000) { // > 200ms
00137         ACS_SHORT_LOG((LM_WARNING, "%s response time is slow, reported as degraded.", desc->getName()));
00138         return acsdaemon::DEGRADED;
00139       }
00140       else
00141         return acsdaemon::RUNNING;
00142     }
00143 
00144   }
00145 
00146 };
00147 
00148 
00149 #endif

Generated on Mon May 4 2015 08:27:41 for ACS-2015.4 C++ API by  doxygen 1.7.0