⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dynamicconsumer.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================//// Author: Heather Sterling (hsterl@us.ibm.com)//// Modified By: ////%/////////////////////////////////////////////////////////////////////////////#include "DynamicConsumer.h"#include "DynamicConsumerFacade.h"#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Time.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/XmlReader.h>#include <Pegasus/Common/XmlParser.h>#include <Pegasus/Common/FileSystem.h>PEGASUS_NAMESPACE_BEGINPEGASUS_USING_STD;DynamicConsumer::DynamicConsumer(): Base(0){}DynamicConsumer::DynamicConsumer(const String& name): Base(0),_module(0),_eventqueue(),_name(name),_initialized(false),_dieNow(0),_no_unload(0){    _check_queue = new Semaphore(0);    _shutdownSemaphore = new Semaphore(0);    _listeningSemaphore = new Semaphore(0);}//ATTN: For migration from old listener -- do we want to support it?DynamicConsumer::DynamicConsumer(const String & name,                                 ConsumerModule* consumerModule,                                 CIMIndicationConsumerProvider* consumerRef) :Base(consumerRef),_module(consumerModule),_eventqueue(),_name(name),_initialized(false),_dieNow(0),_no_unload(0){    _check_queue = new Semaphore(0);    _shutdownSemaphore = new Semaphore(0);    _listeningSemaphore = new Semaphore(0);}DynamicConsumer::~DynamicConsumer(void){    //delete any outstanding events    IndicationDispatchEvent* event;    while (_eventqueue.size())    {        event = _eventqueue.remove_front();        delete event;    }    //delete semaphores    delete _check_queue;    delete _shutdownSemaphore;    delete _listeningSemaphore;}CIMIndicationConsumerProvider* DynamicConsumer::getConsumer(){    return(_consumer);}ConsumerModule* DynamicConsumer::getModule(void) const{    return(_module);}String DynamicConsumer::getName(void) const{    return(_name);}Boolean DynamicConsumer::isLoaded(void) const{    return(_module == 0 ? false : true);}Boolean DynamicConsumer::isInitialized(void) const{    return(_initialized);}/** Initializes the consumer. *  Caller assumes responsibility for catching exceptions thrown by this method. */ void DynamicConsumer::initialize(){    PEG_METHOD_ENTER(TRC_LISTENER, "DynamicConsumer::initialize");    if (!_initialized)    {        // yield before a potentially lengthy operation.        Threads::yield();        try        {            //there is no cimom handle in the listener, so pass null            CIMOMHandle* handle = 0;            DynamicConsumerFacade::initialize(*(handle));            updateIdleTimer();            _initialized = true;            PEG_TRACE_STRING(TRC_LISTENER, Tracer::LEVEL3, "Successfully initialized consumer.");        } catch (...)        {            PEG_TRACE_STRING(TRC_LISTENER, Tracer::LEVEL4,                             "Exception caught in DynamicConsumerFacade::initialize for " +                             _name);            throw;        }    }    PEG_METHOD_EXIT();}void DynamicConsumer::setShutdownSemaphore(Semaphore* shutdownSemaphore){    PEG_METHOD_ENTER(TRC_LISTENER, "DynamicConsumer::setShutdownSemaphore");    _shutdownSemaphore = shutdownSemaphore;    PEG_METHOD_EXIT();}Semaphore* DynamicConsumer::getShutdownSemaphore(){    return _shutdownSemaphore;}void DynamicConsumer::sendShutdownSignal(){    PEG_METHOD_ENTER(TRC_LISTENER, "DynamicConsumer::sendShutdownSignal");    _dieNow = true;    _check_queue->signal();    PEG_METHOD_EXIT();}void DynamicConsumer::terminate(void){    PEG_METHOD_ENTER(TRC_LISTENER, "DynamicConsumer::terminate");    if (_initialized)    {        // yield before a potentially lengthy operation.        Threads::yield();        //terminate consumer        try        {            DynamicConsumerFacade::terminate();        } catch (...)        {            PEG_TRACE_STRING(TRC_LISTENER, Tracer::LEVEL4,                             "Exception caught in DynamicConsumerFacade::Terminate for " +                             _name);            throw;        }        //update status        _initialized = false;        _dieNow = false;    }    PEG_METHOD_EXIT();}/** This method should be called after the physical consumer is loaded and before initialization.   */ void DynamicConsumer::set(ConsumerModule* consumerModule,                          CIMIndicationConsumerProvider* consumerRef){    PEG_METHOD_ENTER(TRC_LISTENER, "DynamicConsumer::set");    if (_initialized)    {        throw Exception(MessageLoaderParms("DynListener.DynamicConsumer.CONSUMER_INVALID_STATE",                                           "Error: The consumer is not in the correct state to perform the operation."));    }    _module = consumerModule;    _consumer = consumerRef;    PEG_METHOD_EXIT();}/** This method should be called after the consumer is terminated and the module is unloaded.  Note that we cannot test * for a loaded condition, since the _module reference here may still exist (if more than one consumer is using the module). * Simply test whether the consumer is initialized.  If it was terminated properly, initialized will be false and the _module * ref count will be decremented. */void DynamicConsumer::reset(){    PEG_METHOD_ENTER(TRC_LISTENER, "DynamicConsumer::reset");    if (_initialized)    {        throw Exception(MessageLoaderParms("DynListener.DynamicConsumer.CONSUMER_INVALID_STATE",                                           "Error: The consumer is not in the correct state to perform the operation."));    }    _module = 0;    // do not delete it, that is taken care of in ConsumerModule itself     _consumer = 0;  // ATTN: attempting to delete this causes an exception -- why??    Tracer::trace(__FILE__,__LINE__,TRC_LISTENER,Tracer::LEVEL4,                  "Deleting %d outstanding requests for %s",                  _eventqueue.size(),                  (const char*)_name.getCString());    //delete outstanding requests    IndicationDispatchEvent* event = 0;    for (Uint32 i = 0; i < _eventqueue.size(); i++)    {        event = _eventqueue.remove_front();        delete event;    }    PEG_METHOD_EXIT();}void DynamicConsumer::enqueueEvent(IndicationDispatchEvent* event){    PEG_METHOD_ENTER(TRC_LISTENER, "DynamicConsumer::enqueueEvent");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -