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

📄 processindication.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)////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Common/InternalException.h>#include <Pegasus/Client/CIMClient.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;// Interop namespace used with PEGASUS_NAMESPACENAME_INTEROP in Constants.hconst CIMNamespaceName SOURCENAMESPACE =     CIMNamespaceName ("root/SampleProvider");void _createHandlerInstance     (CIMClient & client,      const String & name,     const String & destination){    CIMInstance handlerInstance (PEGASUS_CLASSNAME_INDHANDLER_CIMXML);    handlerInstance.addProperty (CIMProperty (CIMName         ("SystemCreationClassName"), System::getSystemCreationClassName ()));    handlerInstance.addProperty (CIMProperty (CIMName ("SystemName"),        System::getFullyQualifiedHostName ()));    handlerInstance.addProperty (CIMProperty (CIMName ("CreationClassName"),        PEGASUS_CLASSNAME_INDHANDLER_CIMXML.getString ()));    handlerInstance.addProperty (CIMProperty (CIMName ("Name"), name));    handlerInstance.addProperty (CIMProperty (CIMName ("Destination"),        destination));    CIMObjectPath path = client.createInstance (PEGASUS_NAMESPACENAME_INTEROP,        handlerInstance);}void _createFilterInstance     (CIMClient & client,      const String & name,     const String & query,     const String & qlang){    CIMInstance filterInstance (PEGASUS_CLASSNAME_INDFILTER);    filterInstance.addProperty (CIMProperty (CIMName         ("SystemCreationClassName"), System::getSystemCreationClassName ()));    filterInstance.addProperty (CIMProperty (CIMName ("SystemName"),        System::getFullyQualifiedHostName ()));    filterInstance.addProperty (CIMProperty (CIMName ("CreationClassName"),        PEGASUS_CLASSNAME_INDFILTER.getString ()));    filterInstance.addProperty (CIMProperty (CIMName ("Name"), name));    filterInstance.addProperty (CIMProperty (CIMName ("Query"), query));    filterInstance.addProperty (CIMProperty (CIMName ("QueryLanguage"),        String (qlang)));    filterInstance.addProperty (CIMProperty (CIMName ("SourceNamespace"),        SOURCENAMESPACE.getString ()));    CIMObjectPath path = client.createInstance (PEGASUS_NAMESPACENAME_INTEROP,        filterInstance);}void _createSubscriptionInstance     (CIMClient & client,     const CIMObjectPath & filterPath,     const CIMObjectPath & handlerPath){    CIMInstance subscriptionInstance (PEGASUS_CLASSNAME_INDSUBSCRIPTION);    subscriptionInstance.addProperty (CIMProperty (CIMName ("Filter"),        filterPath, 0, PEGASUS_CLASSNAME_INDFILTER));    subscriptionInstance.addProperty (CIMProperty (CIMName ("Handler"),        handlerPath, 0, PEGASUS_CLASSNAME_INDHANDLER_CIMXML));    subscriptionInstance.addProperty (CIMProperty        (CIMName ("SubscriptionState"), CIMValue ((Uint16) 2)));    CIMObjectPath path = client.createInstance (PEGASUS_NAMESPACENAME_INTEROP,         subscriptionInstance);}void _renameLogFile (const String & indicationLogFileName){    String indicationLogFailedFileName;    //    //  Rename the indication log file upon verification failure    //    indicationLogFailedFileName = INDICATION_DIR;    indicationLogFailedFileName.append ("/indicationLog_FAILED");    FileSystem::renameFile (indicationLogFileName, indicationLogFailedFileName);}Boolean _checkIndicationLog    (Uint32 id,     const String & methodName,     Boolean allProperties,     Boolean noIndications,     const String & qlang){    String indicationLogFileName;    indicationLogFileName = INDICATION_DIR;    indicationLogFileName.append ("/indicationLog");    if (FileSystem::exists (indicationLogFileName))    {        if (noIndications)        {            _renameLogFile (indicationLogFileName);            return false;        }        try        {            Buffer contents;            FileSystem::loadFileToMemory (contents, indicationLogFileName);            contents.append ('\0');            const char * theLog = contents.getData ();            String log (theLog);            Uint32 newline;            newline = log.find ('\n');            if (newline == PEG_NOT_FOUND)            {                _renameLogFile (indicationLogFileName);                return false;            }            String header = log.subString (0, newline);            if (header [header.size () - 1] == '\r')            {                header = header.subString (0, newline - 1);            }            if (!String::equal (header,                 "++++++++++++++ Received Indication +++++++++++++++++"))            {                _renameLogFile (indicationLogFileName);                return false;            }            if (log.size () > (newline + 1))            {                log = log.subString (newline + 1);            }            else            {                _renameLogFile (indicationLogFileName);                return false;            }            Uint32 numProperties;            if (allProperties)            {                numProperties = 4;            }            else            {                numProperties = 3;            }            if (String::equal (methodName,                 String ("SendTestIndicationMissingProperty")))            {                //                //  indication instance will contain one fewer property                //                numProperties--;            }            String propertyName;            String propertyValue;            for (Uint32 i = 0; i < numProperties; i++)            {                newline = log.find ('\n');                if (newline == PEG_NOT_FOUND)                {                    _renameLogFile (indicationLogFileName);                    return false;                }                String line = log.subString (0, newline);                if (line [line.size () - 1] == '\r')                {                    line = line.subString (0, newline - 1);                }                Uint32 eq = line.find (String (" = "));                if (eq == PEG_NOT_FOUND)                {                    _renameLogFile (indicationLogFileName);                    return false;                }                propertyName.clear ();                propertyValue.clear ();                propertyName = line.subString (0, eq);                if (line.size () > (eq + 3))                {                    propertyValue = line.subString (eq + 3);                }                if (String::equalNoCase (propertyName, "IndicationIdentifier"))                {                    if (qlang == "DMTF:CQL")                    {                      id += 10;                    }                    char idStr[10];                    sprintf(idStr, "%d", id);                                         if (!String::equal (propertyValue, idStr))                    {                        _renameLogFile (indicationLogFileName);                        return false;                    }                }                else if (String::equalNoCase (propertyName,                     "CorrelatedIndications"))                {                    //                    //  CorrelatedIndications property should not be present for                    //  SendTestIndicationMissingProperty method                    //                    if (String::equal (methodName,                        String ("SendTestIndicationMissingProperty")))                    {                        _renameLogFile (indicationLogFileName);                        return false;                    }                    else if (propertyValue.size () != 0)                    {                        _renameLogFile (indicationLogFileName);                        return false;                    }                }                else if (String::equalNoCase (propertyName,                     "MethodName"))                {                    if (!String::equal (propertyValue, methodName))                    {                        _renameLogFile (indicationLogFileName);                        return false;                    }                }                else if (String::equalNoCase (propertyName, "IndicationTime"))                {                    if (!allProperties)                    {                        _renameLogFile (indicationLogFileName);                        return false;                    }                }                else                {                    _renameLogFile (indicationLogFileName);                    return false;                }                if (log.size () > (newline + 1))                {                    log = log.subString (newline + 1);                }                else                {                    _renameLogFile (indicationLogFileName);                    return false;                }            }            newline = log.find ('\n');            if (newline == PEG_NOT_FOUND)            {                _renameLogFile (indicationLogFileName);                return false;            }            String footer = log.subString (0, newline);            if (footer [footer.size () - 1] == '\r')            {                footer = footer.subString (0, newline - 1);            }            if (!String::equal (footer,                "++++++++++++++++++++++++++++++++++++++++++++++++++++"))            {                _renameLogFile (indicationLogFileName);                return false;            }            if (log.size () > newline + 1)            {                log = log.subString (newline + 1);                if (log [0] == '\r')                {                    log = log.subString (1);                }                if ((log.size () != 1) || (log [0] != '\n'))                {                    _renameLogFile (indicationLogFileName);                    return false;                }            }            else            {                _renameLogFile (indicationLogFileName);                return false;            }            //            //  Remove the indication log file on successful verification            //            FileSystem::removeFile (indicationLogFileName);            return true;        }        catch (CannotOpenFile &)        {            _renameLogFile (indicationLogFileName);            return false;        }        catch (...)        {            _renameLogFile (indicationLogFileName);            return false;        }    }    else if (noIndications)    {        return true;    }    else    {        return false;    }}void _sendTestIndication     (CIMClient & client,    const CIMName & methodName){    //    //  Remove previous indication log file, if there    //    String previousIndicationFile, oldIndicationFile;    previousIndicationFile = INDICATION_DIR;    previousIndicationFile.append ("/indicationLog");    if (FileSystem::exists (previousIndicationFile))    {        oldIndicationFile = INDICATION_DIR;        oldIndicationFile.append ("/oldIndicationFile");        if (FileSystem::exists (oldIndicationFile))        {            FileSystem::removeFile (oldIndicationFile);        }        if (!FileSystem::renameFile (previousIndicationFile, oldIndicationFile))        {            FileSystem::removeFile (previousIndicationFile);        }    }    //    //  Invoke method to send test indication    //    Array <CIMParamValue> inParams;    Array <CIMParamValue> outParams;    Array <CIMKeyBinding> keyBindings;    Sint32 result;    CIMValue retValue;    if (methodName.equal ("SendTestIndicationSubclass"))    {        CIMObjectPath className (String::EMPTY, CIMNamespaceName (),            CIMName ("RT_TestIndicationSubclass"), keyBindings);        retValue = client.invokeMethod            (SOURCENAMESPACE,            className,            methodName,            inParams,            outParams);    }    else    {        CIMObjectPath className (String::EMPTY, CIMNamespaceName (),             CIMName ("RT_TestIndication"), keyBindings);        retValue = client.invokeMethod             (SOURCENAMESPACE,            className,            methodName,            inParams,            outParams);    }    retValue.get (result);    PEGASUS_TEST_ASSERT (result == 0);    //

⌨️ 快捷键说明

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