OW_CppIndicationExportXMLHTTPProvider.cpp

Go to the documentation of this file.
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 
00035 #include "OW_config.h"
00036 #include "OW_CppIndicationExportXMLHTTPProvider.hpp"
00037 #include "OW_HTTPClient.hpp"
00038 #include "OW_ConfigOpts.hpp"
00039 #include "OW_IndicationExporter.hpp"
00040 #include "OW_Format.hpp"
00041 #include "OW_CIMInstance.hpp"
00042 #include "OW_CIMProperty.hpp"
00043 #include "OW_CIMValue.hpp"
00044 #include "OW_MutexLock.hpp"
00045 #include "OW_Logger.hpp"
00046 
00047 namespace OW_NAMESPACE
00048 {
00049 
00050 using namespace WBEMFlags;
00051       
00052 namespace
00053 {
00054    const String COMPONENT_NAME("ow.provider.CppIndicationExportXMLHTTP");
00055 
00056    class HTTPClientListJanitor
00057    {
00058    public:
00059       HTTPClientListJanitor(std::list<HTTPClientRef>::iterator httpClient, std::list<HTTPClientRef>& list, Mutex& guard)
00060          : m_httpClient(httpClient)
00061          , m_list(list)
00062          , m_guard(guard)
00063       {
00064       }
00065 
00066       ~HTTPClientListJanitor()
00067       {
00068          MutexLock lock(m_guard);
00069          m_list.erase(m_httpClient);
00070       }
00071    private:
00072       std::list<HTTPClientRef>::iterator m_httpClient;
00073       std::list<HTTPClientRef>& m_list;
00074       Mutex& m_guard;
00075    };
00076 }
00077 
00079 CppIndicationExportXMLHTTPProvider::CppIndicationExportXMLHTTPProvider()
00080    : m_cancelled(false)
00081 {
00082 }
00083 
00085 CppIndicationExportXMLHTTPProvider::~CppIndicationExportXMLHTTPProvider()
00086 {
00087 }
00088 
00090 // Export the given indication
00091 void
00092 CppIndicationExportXMLHTTPProvider::exportIndication(
00093    const ProviderEnvironmentIFCRef& env,
00094    const String& ns,
00095    const CIMInstance &indHandlerInst,
00096    const CIMInstance &indicationInst_)
00097 {
00098    // get rid of any qualifiers.
00099    CIMInstance indicationInst(indicationInst_.clone(E_NOT_LOCAL_ONLY, E_EXCLUDE_QUALIFIERS, E_INCLUDE_CLASS_ORIGIN));
00100 
00101    LoggerRef logger = env->getLogger(COMPONENT_NAME);
00102    OW_LOG_DEBUG(logger, Format("CppIndicationExportXMLHTTPProvider "
00103       "exporting indication.  Handler = %1, Indication = %2",
00104       indHandlerInst.toString(), indicationInst.toString()));
00105 
00106    String listenerUrl;
00107    indHandlerInst.getProperty("Destination").getValue().get(listenerUrl);
00108 
00109    // this guy parses it out.
00110    URL url(listenerUrl);
00111 
00112    if (indHandlerInst.getClassName().equalsIgnoreCase("CIM_IndicationHandlerXMLHTTPS"))
00113    {
00114       if (!url.scheme.equals(URL::CIMXML_WBEMS))
00115       {
00116          url.scheme = URL::CIMXML_WBEMS;
00117          listenerUrl = url.toString();
00118       }
00119    }
00120 
00121    HTTPClientRef httpClient = new HTTPClient(listenerUrl);
00122    IndicationExporter exporter = IndicationExporter(httpClient);
00123 
00124    // the OW 2.0 HTTPXMLCIMListener uses the HTTP path to differentiate different
00125    // subscriptions.  This is stored in namespace name of the URL.
00126    if (!url.namespaceName.empty())
00127    {
00128       httpClient->setHTTPPath('/' + url.namespaceName);
00129    }
00130 
00131    // now add httpClient to the list in case we get cancelled, also check for cancellation while we're at it.
00132    MutexLock lock(m_guard);
00133    if (m_cancelled)
00134    {
00135       return;
00136    }
00137    m_httpClients.push_back(httpClient);
00138    HTTPClientListJanitor janitor(--m_httpClients.end(), m_httpClients, m_guard);
00139    lock.release();
00140 
00141    exporter.exportIndication(ns, indicationInst);
00142 }
00144 // @return The class names of all the CIM_IndicationHandler sub-classes
00145 // this IndicationExportProvider handles.
00146 StringArray
00147 CppIndicationExportXMLHTTPProvider::getHandlerClassNames()
00148 {
00149    StringArray rv;
00150    rv.append("CIM_IndicationHandlerXMLHTTP"); // name in the 2.5 schema
00151    rv.append("CIM_IndicationHandlerXMLHTTPS"); // used by OW 2.0 for HTTPS indications
00152    rv.append("CIM_IndicationHandlerCIMXML"); // new name in the 2.6 schema
00153    // new in the 2.8 schema
00154    rv.append("CIM_ListenerDestinationCIMXML");
00155 
00156    return rv;
00157 }
00158 
00160 void
00161 CppIndicationExportXMLHTTPProvider::doCooperativeCancel()
00162 {
00163    MutexLock lock(m_guard);
00164    m_cancelled = true;
00165    for (std::list<HTTPClientRef>::iterator iter = m_httpClients.begin(); iter != m_httpClients.end(); ++iter)
00166    {
00167       (*iter)->close();
00168    }
00169 }
00170 
00171 
00172 } // end namespace OW_NAMESPACE
00173 
00175 OW_PROVIDERFACTORY(OpenWBEM::CppIndicationExportXMLHTTPProvider, cppindicationexportxmlhttpprovider);
00176 

Generated on Thu Feb 9 08:47:57 2006 for openwbem by  doxygen 1.4.6