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

📄 subscriptionrepository.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//%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: Carol Ann Krug Graves, Hewlett-Packard Company//             (carolann_graves@hp.com)//// Modified By: David Dillard, VERITAS Software Corp.//                  (david.dillard@veritas.com)////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/Common/LanguageParser.h>#include "IndicationConstants.h"#include "SubscriptionRepository.h"PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGINSubscriptionRepository::SubscriptionRepository (    CIMRepository * repository)    : _repository (repository){}SubscriptionRepository::~SubscriptionRepository (){}CIMObjectPath SubscriptionRepository::createInstance (    CIMInstance instance,    const CIMNamespaceName & nameSpace,    const String & userName,    const AcceptLanguageList & acceptLanguages,    const ContentLanguageList & contentLanguages,    Boolean enabled){    PEG_METHOD_ENTER (TRC_INDICATION_SERVICE,        "SubscriptionRepository::createInstance");    CIMObjectPath instanceRef;    //    //  Add creator property to Instance    //  NOTE: userName is only set if authentication is turned on    //    String currentUser = userName;    if (instance.findProperty (PEGASUS_PROPERTYNAME_INDSUB_CREATOR) ==        PEG_NOT_FOUND)    {        instance.addProperty (CIMProperty            (PEGASUS_PROPERTYNAME_INDSUB_CREATOR, currentUser));    }    else    {        CIMProperty creator = instance.getProperty            (instance.findProperty            (PEGASUS_PROPERTYNAME_INDSUB_CREATOR));        creator.setValue (CIMValue (currentUser));    }    // l10n    // Add the language properties to the Instance    // Note:  These came from the Accept-Language and Content-Language    // headers in the HTTP message, and may be empty    AcceptLanguageList acceptLangs = acceptLanguages;    if (instance.findProperty (PEGASUS_PROPERTYNAME_INDSUB_ACCEPTLANGS) ==        PEG_NOT_FOUND)    {        instance.addProperty (CIMProperty            (PEGASUS_PROPERTYNAME_INDSUB_ACCEPTLANGS,            LanguageParser::buildAcceptLanguageHeader(acceptLangs)));    }    else    {        CIMProperty langs = instance.getProperty            (instance.findProperty            (PEGASUS_PROPERTYNAME_INDSUB_ACCEPTLANGS));        langs.setValue (CIMValue (            LanguageParser::buildAcceptLanguageHeader(acceptLangs)));    }    ContentLanguageList contentLangs = contentLanguages;    if (instance.findProperty (PEGASUS_PROPERTYNAME_INDSUB_CONTENTLANGS) ==        PEG_NOT_FOUND)    {        instance.addProperty (CIMProperty            (PEGASUS_PROPERTYNAME_INDSUB_CONTENTLANGS,            LanguageParser::buildContentLanguageHeader(contentLangs)));    }    else    {        CIMProperty langs = instance.getProperty            (instance.findProperty            (PEGASUS_PROPERTYNAME_INDSUB_CONTENTLANGS));        langs.setValue (CIMValue (            LanguageParser::buildContentLanguageHeader(contentLangs)));    }    // l10n -end    if ((instance.getClassName ().equal        (PEGASUS_CLASSNAME_INDSUBSCRIPTION)) ||        (instance.getClassName ().equal        (PEGASUS_CLASSNAME_FORMATTEDINDSUBSCRIPTION)))    {        //        //  Set Time of Last State Change to current date time        //        CIMDateTime currentDateTime =            CIMDateTime::getCurrentDateTime ();        if (instance.findProperty (_PROPERTY_LASTCHANGE) ==            PEG_NOT_FOUND)        {            instance.addProperty                (CIMProperty (_PROPERTY_LASTCHANGE, currentDateTime));        }        else        {            CIMProperty lastChange = instance.getProperty                (instance.findProperty (_PROPERTY_LASTCHANGE));            lastChange.setValue (CIMValue (currentDateTime));        }        CIMDateTime startDateTime;        if (enabled)        {            startDateTime = currentDateTime;        }        else        {            //            //  If subscription is not enabled, set Subscription            //  Start Time to null CIMDateTime value            //            startDateTime = CIMDateTime ();        }        //        //  Set Subscription Start Time        //        if (instance.findProperty (_PROPERTY_STARTTIME) ==            PEG_NOT_FOUND)        {            instance.addProperty                (CIMProperty (_PROPERTY_STARTTIME, startDateTime));        }        else        {            CIMProperty startTime = instance.getProperty                (instance.findProperty (_PROPERTY_STARTTIME));            startTime.setValue (CIMValue (startDateTime));        }    }    //    //  Create instance in repository    //    try    {        instanceRef = _repository->createInstance (nameSpace, instance);    }    catch (const CIMException &)    {        PEG_METHOD_EXIT ();        throw;    }    catch (const Exception & exception)    {        PEG_METHOD_EXIT ();        throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, exception.getMessage ());    }    PEG_METHOD_EXIT ();    return instanceRef;}Boolean SubscriptionRepository::getActiveSubscriptions (    Array <CIMInstance> & activeSubscriptions) const{    PEG_METHOD_ENTER (TRC_INDICATION_SERVICE,        "SubscriptionRepository::getActiveSubscriptions");    Array <CIMNamespaceName> nameSpaceNames;    Array <CIMInstance> subscriptions;    CIMValue subscriptionStateValue;    Uint16 subscriptionState;    Boolean invalidInstance = false;    activeSubscriptions.clear ();    //    //  Get list of namespaces in repository    //    nameSpaceNames = _repository->enumerateNameSpaces ();    //    //  Get existing subscriptions from each namespace in the repository    //    for (Uint32 i = 0; i < nameSpaceNames.size (); i++)    {        //        //  Get existing subscriptions in current namespace        //        subscriptions = getSubscriptions (nameSpaceNames [i]);        //        //  Process each subscription        //        for (Uint32 j = 0; j < subscriptions.size (); j++)        {            //            //  Get subscription state            //            if (!getState (subscriptions [j], subscriptionState))            {                //                //  This instance from the repository is corrupted                //  Skip it                //                invalidInstance = true;                break;            }            //            //  Process each enabled subscription            //            if ((subscriptionState == STATE_ENABLED) ||                (subscriptionState == STATE_ENABLEDDEGRADED))            {                //                //  CIMInstances returned from repository do not include                //  namespace                //  Set namespace here                //                CIMObjectPath instanceName = subscriptions [j].getPath ();                instanceName.setNameSpace (nameSpaceNames [i]);                subscriptions [j].setPath (instanceName);                activeSubscriptions.append (subscriptions [j]);            }  // if subscription is enabled        }  // for each subscription    }  // for each namespace    PEG_METHOD_EXIT ();    return invalidInstance;}Array <CIMInstance> SubscriptionRepository::getAllSubscriptions () const{    PEG_METHOD_ENTER (TRC_INDICATION_SERVICE,        "SubscriptionRepository::getAllSubscriptions");    Array <CIMNamespaceName> nameSpaceNames;    Array <CIMInstance> subscriptions;    Array <CIMInstance> allSubscriptions;    //    //  Get list of namespaces in repository    //    nameSpaceNames = _repository->enumerateNameSpaces ();    //    //  Get all subscriptions from each namespace in the repository    //    for (Uint32 i = 0; i < nameSpaceNames.size (); i++)    {        //        //  Get all subscriptions in current namespace        //        subscriptions = getSubscriptions (nameSpaceNames [i]);        //        //  Append subscriptions in current namespace to list of all        //  subscriptions        //        allSubscriptions.appendArray (subscriptions);    }    PEG_METHOD_EXIT ();    return allSubscriptions;}Array <CIMInstance> SubscriptionRepository::getSubscriptions (    const CIMNamespaceName & nameSpace) const{    PEG_METHOD_ENTER (TRC_INDICATION_SERVICE,        "SubscriptionRepository::getSubscriptions");    Array <CIMInstance> subscriptions;    //    //  Get the CIM_IndicationSubscription and    //  CIM_FormattedIndicationSubscription instances in specified namespace    //    try    {        subscriptions = _repository->enumerateInstancesForClass(            nameSpace, PEGASUS_CLASSNAME_INDSUBSCRIPTION);        subscriptions.appendArray(_repository->enumerateInstancesForClass(            nameSpace, PEGASUS_CLASSNAME_FORMATTEDINDSUBSCRIPTION));    }    catch (const CIMException& e)    {        //        //  Some namespaces may not include the subscription class        //  In that case, just return no subscriptions        //  Any other exception is an error        //        if (e.getCode () != CIM_ERR_INVALID_CLASS)        {            PEG_METHOD_EXIT ();            throw;        }    }    //    //  Process each subscription    //    for (Uint32 i = 0; i < subscriptions.size(); i++)    {        //        //  CIMInstances returned from repository do not include        //  namespace        //  Set namespace here        //        CIMObjectPath instanceName = subscriptions[i].getPath();        instanceName.setNameSpace(nameSpace);        subscriptions[i].setPath(instanceName);    }    PEG_METHOD_EXIT ();    return subscriptions;}Boolean SubscriptionRepository::getState (    const CIMInstance & instance,    Uint16 & state) const{    PEG_METHOD_ENTER (TRC_INDICATION_SERVICE,        "SubscriptionRepository::getState");    Uint32 stateIndex = instance.findProperty (PEGASUS_PROPERTYNAME_SUBSCRIPTION_STATE);    if (stateIndex != PEG_NOT_FOUND)

⌨️ 快捷键说明

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