00001 /******************************************************************************* 00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * 00007 * - Redistributions of source code must retain the above copyright notice, 00008 * this list of conditions and the following disclaimer. 00009 * 00010 * - Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 00014 * - Neither the name of Vintela, Inc. nor the names of its 00015 * contributors may be used to endorse or promote products derived from this 00016 * software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS 00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00028 * POSSIBILITY OF SUCH DAMAGE. 00029 *******************************************************************************/ 00030 00036 #ifndef OW_POLLING_MANAGER_HPP_ 00037 #define OW_POLLING_MANAGER_HPP_ 00038 #include "OW_config.h" 00039 #include "OW_CIMFwd.hpp" 00040 #include "OW_Thread.hpp" 00041 #include "OW_Runnable.hpp" 00042 #include "OW_List.hpp" 00043 #include "OW_Array.hpp" 00044 #include "OW_CIMInstance.hpp" 00045 #include "OW_CIMValue.hpp" 00046 #include "OW_CIMProperty.hpp" 00047 #include "OW_PolledProviderIFC.hpp" 00048 #include "OW_Condition.hpp" 00049 #include "OW_ThreadBarrier.hpp" 00050 #include "OW_ThreadPool.hpp" 00051 #include "OW_CimomCommonFwd.hpp" 00052 #include "OW_ServiceIFC.hpp" 00053 00054 namespace OW_NAMESPACE 00055 { 00056 class PollingManagerThread; 00057 00058 class OW_CIMOMCOMMON_API PollingManager : public ServiceIFC 00059 { 00060 public: 00061 PollingManager(const ProviderManagerRef& providerManager); 00062 virtual ~PollingManager(); 00063 00064 virtual String getName() const; 00065 virtual StringArray getDependencies() const; 00066 virtual void init(const ServiceEnvironmentIFCRef& env); 00067 virtual void start(); 00068 virtual void shutdown(); 00069 00070 void addPolledProvider(const PolledProviderIFCRef& p); 00071 private: 00072 IntrusiveReference<PollingManagerThread> m_pollingManagerThread; 00073 }; 00074 00075 class OW_CIMOMCOMMON_API PollingManagerThread : public Thread 00076 { 00077 public: 00078 PollingManagerThread(const ProviderManagerRef& providerManager); 00079 virtual ~PollingManagerThread(); 00080 void init(const ServiceEnvironmentIFCRef& env); 00081 void shutdown(); 00082 void waitUntilReady() 00083 { 00084 m_startedBarrier.wait(); 00085 } 00086 void addPolledProvider(const PolledProviderIFCRef& p); 00087 protected: 00088 virtual Int32 run(); 00089 private: 00090 class TriggerRunner : public Runnable 00091 { 00092 public: 00093 TriggerRunner(PollingManagerThread* svr, 00094 ServiceEnvironmentIFCRef env); 00095 virtual void run(); 00096 PolledProviderIFCRef m_itp; 00097 time_t m_nextPoll; 00098 bool m_isRunning; 00099 Int32 m_pollInterval; 00100 PollingManagerThread* m_pollMan; 00101 ServiceEnvironmentIFCRef m_env; 00102 LoggerRef m_logger; 00103 private: 00104 void doCooperativeCancel(); 00105 void doDefinitiveCancel(); 00106 }; 00107 typedef IntrusiveReference<TriggerRunner> TriggerRunnerRef; 00108 Array<TriggerRunnerRef> m_triggerRunners; 00109 bool m_shuttingDown; 00110 NonRecursiveMutex m_triggerGuard; 00111 Condition m_triggerCondition; 00112 ServiceEnvironmentIFCRef m_env; 00113 ProviderManagerRef m_providerManager; 00114 LoggerRef m_logger; 00115 ThreadBarrier m_startedBarrier; 00116 ThreadPoolRef m_triggerRunnerThreadPool; 00117 00118 // m_triggerGuard must be locked before calling this function. 00119 UInt32 calcSleepTime(bool& rightNow, bool doInit); 00120 // m_triggerGuard must be locked before calling this function. 00121 void processTriggers(); 00122 friend class TriggerRunner; 00123 00124 virtual void doCooperativeCancel(); 00125 }; 00126 00127 } // end namespace OW_NAMESPACE 00128 00129 #endif