<commit_before>/*
 * TcpIpAsyncClientSsl.hpp
 *
 * Copyright (C) 2009-18 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#ifndef CORE_HTTP_TCP_IP_ASYNC_CLIENT_SSL_HPP
#define CORE_HTTP_TCP_IP_ASYNC_CLIENT_SSL_HPP

#include <boost/scoped_ptr.hpp>

#include <boost/asio/ip/tcp.hpp>

#include "BoostAsioSsl.hpp"

#include <core/http/AsyncClient.hpp>
#include <core/http/TcpIpAsyncConnector.hpp>

namespace rstudio {
namespace core {
namespace http {

class TcpIpAsyncClientSsl
   : public AsyncClient<boost::asio::ssl::stream<boost::asio::ip::tcp::socket> >
{
public:
   TcpIpAsyncClientSsl(boost::asio::io_service& ioService,
                       std::string address,
                       std::string port,
                       bool verify,
                       const std::string& certificateAuthority = std::string(),
                       const boost::posix_time::time_duration& connectionTimeout =
                          boost::posix_time::time_duration(boost::posix_time::pos_infin),
                       const std::string& hostname = std::string() )
     : AsyncClient<boost::asio::ssl::stream<boost::asio::ip::tcp::socket> >(ioService),
       sslContext_(boost::asio::ssl::context::sslv23_client),
       address_(std::move(address)),
       port_(std::move(port)),
       verify_(verify),
       certificateAuthority_(certificateAuthority),
       connectionTimeout_(connectionTimeout)
   {
      if (verify_)
      {
         sslContext_.set_default_verify_paths();
         sslContext_.set_verify_mode(boost::asio::ssl::context::verify_peer);

         if (!certificateAuthority_.empty())
         {
            boost::asio::const_buffer buff(certificateAuthority_.data(), certificateAuthority_.size());
            boost::system::error_code ec;
            sslContext_.add_certificate_authority(buff, ec);
            if (ec)
               LOG_ERROR(Error(ec, ERROR_LOCATION));
         }
      }
      else
      {
         sslContext_.set_verify_mode(boost::asio::ssl::context::verify_none);
      }

      // use scoped ptr so we can call the constructor after we've configured
      // the ssl::context (immediately above)
      ptrSslStream_.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(ioService, sslContext_));

      // TLS v1.3 requires that the SNI be set, so set the SNI.
      if (!SSL_set_tlsext_host_name(
            ptrSslStream_->native_handle(),
            (hostname.empty() ? address_.c_str() : hostname.c_str())))
      {
         boost::system::error_code ec{ static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category() };
         LOG_ERROR(Error(ec, ERROR_LOCATION));
      }
   }

protected:

   virtual boost::asio::ssl::stream<boost::asio::ip::tcp::socket>& socket()
   {
      return *(ptrSslStream_);
   }

   virtual void connectAndWriteRequest()
   {
      boost::shared_ptr<TcpIpAsyncConnector> pAsyncConnector(
                  new TcpIpAsyncConnector(ioService(),
                                          &(ptrSslStream_->next_layer())));

      pAsyncConnector->connect(
            address_,
            port_,
            boost::bind(&TcpIpAsyncClientSsl::performHandshake,
                        TcpIpAsyncClientSsl::sharedFromThis()),
            boost::bind(&TcpIpAsyncClientSsl::handleConnectionError,
                        TcpIpAsyncClientSsl::sharedFromThis(),
                        _1),
            connectionTimeout_);
   }

private:

   void performHandshake()
   {
      if (verify_)
      {
         ptrSslStream_->set_verify_callback(
                            boost::asio::ssl::rfc2818_verification(address_));
      }
      ptrSslStream_->async_handshake(
            boost::asio::ssl::stream_base::client,
            boost::bind(&TcpIpAsyncClientSsl::handleHandshake,
                        sharedFromThis(),
                        boost::asio::placeholders::error));
   }

   void handleHandshake(const boost::system::error_code& ec)
   {
      try
      {
         if (!ec)
         {
            // finished handshake, commence with request
            writeRequest();
         }
         else
         {
            handleErrorCode(ec, ERROR_LOCATION);
         }
      }
      CATCH_UNEXPECTED_ASYNC_CLIENT_EXCEPTION
   }

   const boost::shared_ptr<TcpIpAsyncClientSsl> sharedFromThis()
   {
      boost::shared_ptr<AsyncClient<boost::asio::ssl::stream<boost::asio::ip::tcp::socket> > > ptrShared
                                                 = shared_from_this();

      return boost::static_pointer_cast<TcpIpAsyncClientSsl>(ptrShared);
   }

   virtual bool isShutdownError(const boost::system::error_code& ec)
   {
      return util::isSslShutdownError(ec);
   }

private:
   boost::asio::ssl::context sslContext_;
   boost::scoped_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket> > ptrSslStream_;
   std::string address_;
   std::string port_;
   bool verify_;
   std::string certificateAuthority_;
   boost::posix_time::time_duration connectionTimeout_;
};

} // namespace http
} // namespace core
} // namespace rstudio

#endif // CORE_HTTP_TCP_IP_ASYNC_CLIENT_SSL_HPP
<commit_msg>go back to const reference for consistency<commit_after>/*
 * TcpIpAsyncClientSsl.hpp
 *
 * Copyright (C) 2009-18 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#ifndef CORE_HTTP_TCP_IP_ASYNC_CLIENT_SSL_HPP
#define CORE_HTTP_TCP_IP_ASYNC_CLIENT_SSL_HPP

#include <boost/scoped_ptr.hpp>

#include <boost/asio/ip/tcp.hpp>

#include "BoostAsioSsl.hpp"

#include <core/http/AsyncClient.hpp>
#include <core/http/TcpIpAsyncConnector.hpp>

namespace rstudio {
namespace core {
namespace http {

class TcpIpAsyncClientSsl
   : public AsyncClient<boost::asio::ssl::stream<boost::asio::ip::tcp::socket> >
{
public:
   TcpIpAsyncClientSsl(boost::asio::io_service& ioService,
                       const std::string& address,
                       const std::string& port,
                       bool verify,
                       const std::string& certificateAuthority = std::string(),
                       const boost::posix_time::time_duration& connectionTimeout =
                          boost::posix_time::time_duration(boost::posix_time::pos_infin),
                       const std::string& hostname = std::string() )
     : AsyncClient<boost::asio::ssl::stream<boost::asio::ip::tcp::socket> >(ioService),
       sslContext_(boost::asio::ssl::context::sslv23_client),
       address_(address),
       port_(port),
       verify_(verify),
       certificateAuthority_(certificateAuthority),
       connectionTimeout_(connectionTimeout)
   {
      if (verify_)
      {
         sslContext_.set_default_verify_paths();
         sslContext_.set_verify_mode(boost::asio::ssl::context::verify_peer);

         if (!certificateAuthority_.empty())
         {
            boost::asio::const_buffer buff(certificateAuthority_.data(), certificateAuthority_.size());
            boost::system::error_code ec;
            sslContext_.add_certificate_authority(buff, ec);
            if (ec)
               LOG_ERROR(Error(ec, ERROR_LOCATION));
         }
      }
      else
      {
         sslContext_.set_verify_mode(boost::asio::ssl::context::verify_none);
      }

      // use scoped ptr so we can call the constructor after we've configured
      // the ssl::context (immediately above)
      ptrSslStream_.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(ioService, sslContext_));

      // TLS v1.3 requires that the SNI be set, so set the SNI.
      if (!SSL_set_tlsext_host_name(
            ptrSslStream_->native_handle(),
            (hostname.empty() ? address_.c_str() : hostname.c_str())))
      {
         boost::system::error_code ec{ static_cast<int>(::ERR_get_error()), boost::asio::error::get_ssl_category() };
         LOG_ERROR(Error(ec, ERROR_LOCATION));
      }
   }

protected:

   virtual boost::asio::ssl::stream<boost::asio::ip::tcp::socket>& socket()
   {
      return *(ptrSslStream_);
   }

   virtual void connectAndWriteRequest()
   {
      boost::shared_ptr<TcpIpAsyncConnector> pAsyncConnector(
                  new TcpIpAsyncConnector(ioService(),
                                          &(ptrSslStream_->next_layer())));

      pAsyncConnector->connect(
            address_,
            port_,
            boost::bind(&TcpIpAsyncClientSsl::performHandshake,
                        TcpIpAsyncClientSsl::sharedFromThis()),
            boost::bind(&TcpIpAsyncClientSsl::handleConnectionError,
                        TcpIpAsyncClientSsl::sharedFromThis(),
                        _1),
            connectionTimeout_);
   }

private:

   void performHandshake()
   {
      if (verify_)
      {
         ptrSslStream_->set_verify_callback(
                            boost::asio::ssl::rfc2818_verification(address_));
      }
      ptrSslStream_->async_handshake(
            boost::asio::ssl::stream_base::client,
            boost::bind(&TcpIpAsyncClientSsl::handleHandshake,
                        sharedFromThis(),
                        boost::asio::placeholders::error));
   }

   void handleHandshake(const boost::system::error_code& ec)
   {
      try
      {
         if (!ec)
         {
            // finished handshake, commence with request
            writeRequest();
         }
         else
         {
            handleErrorCode(ec, ERROR_LOCATION);
         }
      }
      CATCH_UNEXPECTED_ASYNC_CLIENT_EXCEPTION
   }

   const boost::shared_ptr<TcpIpAsyncClientSsl> sharedFromThis()
   {
      boost::shared_ptr<AsyncClient<boost::asio::ssl::stream<boost::asio::ip::tcp::socket> > > ptrShared
                                                 = shared_from_this();

      return boost::static_pointer_cast<TcpIpAsyncClientSsl>(ptrShared);
   }

   virtual bool isShutdownError(const boost::system::error_code& ec)
   {
      return util::isSslShutdownError(ec);
   }

private:
   boost::asio::ssl::context sslContext_;
   boost::scoped_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket> > ptrSslStream_;
   std::string address_;
   std::string port_;
   bool verify_;
   std::string certificateAuthority_;
   boost::posix_time::time_duration connectionTimeout_;
};

} // namespace http
} // namespace core
} // namespace rstudio

#endif // CORE_HTTP_TCP_IP_ASYNC_CLIENT_SSL_HPP
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: DomainMapperTableHandler.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: os $ $Date: 2007-05-07 06:19:52 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#include <iostream>
#include <DomainMapperTableHandler.hxx>

namespace dmapper {

using namespace ::com::sun::star;
using namespace ::std;

#ifdef DEBUG
static void lcl_printHandle(const Handle_t rHandle)
{
    rtl::OUString aOUStr = rHandle->getString();
    rtl::OString aOStr(aOUStr.getStr(), aOUStr.getLength(),  RTL_TEXTENCODING_ASCII_US );

    clog << aOStr.getStr() << endl;
}
static void  lcl_printProperties( PropertyMapPtr pProps )
{
    if( pProps.get() )
    {
        clog << "<properties>";
        PropertyMap::const_iterator aMapIter = pProps->begin();
        PropertyMap::const_iterator aEndIter = pProps->end();
        for( ; aMapIter != aEndIter; ++aMapIter )
        {
            rtl::OUString aOUStr = aMapIter->first;
            rtl::OString aOStr(aOUStr.getStr(), aOUStr.getLength(),  RTL_TEXTENCODING_ASCII_US );
            clog << aOStr.getStr() << '-';
        }
        clog << endl;
    }
}
#endif

void DomainMapperTableHandler::startTable(unsigned int nRows,
                                          unsigned int /*nDepth*/,
                                          PropertyMapPtr pProps)
{
    m_aTableProperties = pProps;
    m_pTableSeq = TableSequencePointer_t(new TableSequence_t(nRows));
    m_nRowIndex = 0;

#ifdef DEBUG
    char sBuffer[256];
    snprintf(sBuffer, sizeof(sBuffer), "%d", nRows);
    clog << "<table rows=\"" << sBuffer << "\">" << endl;
    lcl_printProperties( pProps );
#endif
}

void DomainMapperTableHandler::endTable()
{
#ifdef DEBUG
{
    clog << "
" << endl;
    sal_uInt32 nCells = 0;
    sal_uInt32 nRows = m_aRowProperties.size();
    if( nRows == m_aCellProperties.size() )
    {
        for( sal_uInt32 nRow = 0; nRow < nRows; ++nRow )
            nCells += m_aCellProperties[nRow].size();
    }
    sal_uInt32 nTblPropSize = m_aTableProperties.get() ? m_aTableProperties->size() : 0;
    (void)nTblPropSize;
}
#endif

    //  expands to uno::Sequence< Sequence< beans::PropertyValues > >
    CellPropertyValuesSeq_t     aCellProperties( m_aCellProperties.size() );

    // std::vector< std::vector<PropertyMapPtr> > m_aCellProperties
    PropertyMapVector2::const_iterator aRowOfCellsIterator = m_aCellProperties.begin();
    PropertyMapVector2::const_iterator aRowOfCellsIteratorEnd = m_aCellProperties.end();
    sal_Int32 nRow = 0;
    //it's a uno::Sequence< beans::PropertyValues >*
    RowPropertyValuesSeq_t* pCellProperties = aCellProperties.getArray();
    while( aRowOfCellsIterator != aRowOfCellsIteratorEnd )
    {
        //aRowOfCellsIterator points to a vector of PropertyMapPtr
        PropertyMapVector1::const_iterator aCellIterator = aRowOfCellsIterator->begin();
        PropertyMapVector1::const_iterator aCellIteratorEnd = aRowOfCellsIterator->end();

        sal_Int32 nCell = 0;
        pCellProperties[nRow].realloc( aRowOfCellsIterator->size() );
        beans::PropertyValues* pSingleCellProperties = pCellProperties->getArray();
        while( aCellIterator != aCellIteratorEnd )
        {
            //TODO: aCellIterator contains HorizontalBorder and VerticalBorder
            // they have to be removed, depending on the position of the cell they
            // have to be moved to BottomBorder/RightBorder respectively
            //aCellIterator points to a PropertyMapPtr;
            if( aCellIterator->get() )
            {

                PropertyNameSupplier& rPropSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
                const PropertyMap::iterator aVerticalIter =
                                aCellIterator->get()->find( rPropSupplier.GetName(META_PROP_VERTICAL_BORDER) );
                const PropertyMap::iterator aHorizontalIter =
                                aCellIterator->get()->find( rPropSupplier.GetName(META_PROP_HORIZONTAL_BORDER) );
                const PropertyMap::const_iterator aRightIter =
                                aCellIterator->get()->find( rPropSupplier.GetName(PROP_RIGHT_BORDER) );
                const PropertyMap::const_iterator aBottomIter =
                                aCellIterator->get()->find( rPropSupplier.GetName(PROP_BOTTOM_BORDER) );
                if( aVerticalIter != aCellIterator->get()->end())
                    aCellIterator->get()->erase( aVerticalIter );
                if( aHorizontalIter != aCellIterator->get()->end())
                    aCellIterator->get()->erase( aHorizontalIter );

                pSingleCellProperties[nCell] = aCellIterator->get()->GetPropertyValues();
            }
            ++nCell;
            ++aCellIterator;
        }
        ++nRow;
        ++aRowOfCellsIterator;
    }

    RowPropertyValuesSeq_t      aRowProperties( m_aRowProperties.size() );
    PropertyMapVector1::const_iterator aRowIter = m_aRowProperties.begin();
    PropertyMapVector1::const_iterator aRowIterEnd = m_aRowProperties.end();
    nRow = 0;
    while( aRowIter != aRowIterEnd )
    {
        if( aRowIter->get() )
            aRowProperties[nRow] = aRowIter->get()->GetPropertyValues();
        ++nRow;
        ++aRowIter;
    }

    TablePropertyValues_t       aTableProperties;
    if( m_aTableProperties.get() )
        aTableProperties = m_aTableProperties->GetPropertyValues();

    if (m_pTableSeq->getLength() > 0)
    {
        try
        {
#ifdef DEBUG
    {
        sal_Int32 nCellPropertiesRows = aCellProperties.getLength();
        sal_Int32 nCellPropertiesCells = aCellProperties[0].getLength();
        sal_Int32 nCellPropertiesProperties = aCellProperties[0][0].getLength();
        (void) nCellPropertiesRows;
        (void) nCellPropertiesCells;
        (void) nCellPropertiesProperties;
        ++nCellPropertiesProperties;
    }
#endif
            m_xText->convertToTable(*m_pTableSeq,
                                    aCellProperties,
                                    aRowProperties,
                                    aTableProperties);
        }
        catch (lang::IllegalArgumentException e)
        {
#ifdef DEBUG
            clog << "failed to import table!" << endl;
#endif
        }
    }
}

void DomainMapperTableHandler::startRow(unsigned int nCells,
                                        PropertyMapPtr pProps)
{
    m_aRowProperties.push_back( pProps );
    m_aCellProperties.push_back( PropertyMapVector1() );

#ifdef DEBUG
    char sBuffer[256];
    snprintf(sBuffer, sizeof(sBuffer), "%d", nCells);

    clog << "<table.row cells=\"" << sBuffer << "\">" << endl;
    lcl_printProperties( pProps );
#endif

    m_pRowSeq = RowSequencePointer_t(new RowSequence_t(nCells));
    m_nCellIndex = 0;
}

void DomainMapperTableHandler::endRow()
{
    (*m_pTableSeq)[m_nRowIndex] = *m_pRowSeq;
    ++m_nRowIndex;
    m_nCellIndex = 0;
#ifdef DEBUG
    clog << "
" << endl;
#endif
}

void DomainMapperTableHandler::startCell(const Handle_t & start,
                                         PropertyMapPtr pProps )
{
    sal_uInt32 nRow = m_aRowProperties.size();
    m_aCellProperties[nRow - 1].push_back( pProps );

#ifdef DEBUG
    clog << "
";
    lcl_printHandle(start);
    lcl_printProperties( pProps );
    clog << ",";
#endif

    //add a new 'row' of properties
//    if( m_pCellProperties.size() <= sal::static_int_cast< sal_uInt32, sal_Int32>(m_nRowIndex) )
//        m_pCellProperties.push_back( RowProperties_t() );
//    m_pCellProperties[m_nRowIndex].push_back( pProps );
    m_pCellSeq = CellSequencePointer_t(new CellSequence_t(2));
    (*m_pCellSeq)[0] = start->getStart();
}

void DomainMapperTableHandler::endCell(const Handle_t & end)
{
#ifdef DEBUG
    lcl_printHandle(end);
    clog << "
" << endl;
#endif

    (*m_pCellSeq)[1] = end->getEnd();
    (*m_pRowSeq)[m_nCellIndex] = *m_pCellSeq;
    ++m_nCellIndex;
}

}
<commit_msg>set defaults of HeaderRowCount and IsSplitAllowed<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: DomainMapperTableHandler.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: os $ $Date: 2007-05-07 12:06:09 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#include <iostream>
#include <DomainMapperTableHandler.hxx>

namespace dmapper {

using namespace ::com::sun::star;
using namespace ::std;

#ifdef DEBUG
static void lcl_printHandle(const Handle_t rHandle)
{
    rtl::OUString aOUStr = rHandle->getString();
    rtl::OString aOStr(aOUStr.getStr(), aOUStr.getLength(),  RTL_TEXTENCODING_ASCII_US );

    clog << aOStr.getStr() << endl;
}
static void  lcl_printProperties( PropertyMapPtr pProps )
{
    if( pProps.get() )
    {
        clog << "<properties>";
        PropertyMap::const_iterator aMapIter = pProps->begin();
        PropertyMap::const_iterator aEndIter = pProps->end();
        for( ; aMapIter != aEndIter; ++aMapIter )
        {
            rtl::OUString aOUStr = aMapIter->first;
            rtl::OString aOStr(aOUStr.getStr(), aOUStr.getLength(),  RTL_TEXTENCODING_ASCII_US );
            clog << aOStr.getStr() << '-';
        }
        clog << endl;
    }
}
#endif

void DomainMapperTableHandler::startTable(unsigned int nRows,
                                          unsigned int /*nDepth*/,
                                          PropertyMapPtr pProps)
{
    m_aTableProperties = pProps;
    m_pTableSeq = TableSequencePointer_t(new TableSequence_t(nRows));
    m_nRowIndex = 0;

#ifdef DEBUG
    char sBuffer[256];
    snprintf(sBuffer, sizeof(sBuffer), "%d", nRows);
    clog << "<table rows=\"" << sBuffer << "\">" << endl;
    lcl_printProperties( pProps );
#endif
}

void DomainMapperTableHandler::endTable()
{
#ifdef DEBUG
{
    clog << "
" << endl;
    sal_uInt32 nCells = 0;
    sal_uInt32 nRows = m_aRowProperties.size();
    if( nRows == m_aCellProperties.size() )
    {
        for( sal_uInt32 nRow = 0; nRow < nRows; ++nRow )
            nCells += m_aCellProperties[nRow].size();
    }
    sal_uInt32 nTblPropSize = m_aTableProperties.get() ? m_aTableProperties->size() : 0;
    (void)nTblPropSize;
}
#endif

    //  expands to uno::Sequence< Sequence< beans::PropertyValues > >
    CellPropertyValuesSeq_t     aCellProperties( m_aCellProperties.size() );

    // std::vector< std::vector<PropertyMapPtr> > m_aCellProperties
    PropertyMapVector2::const_iterator aRowOfCellsIterator = m_aCellProperties.begin();
    PropertyMapVector2::const_iterator aRowOfCellsIteratorEnd = m_aCellProperties.end();
    sal_Int32 nRow = 0;
    PropertyNameSupplier& rPropSupplier = PropertyNameSupplier::GetPropertyNameSupplier();

    //it's a uno::Sequence< beans::PropertyValues >*
    RowPropertyValuesSeq_t* pCellProperties = aCellProperties.getArray();
    while( aRowOfCellsIterator != aRowOfCellsIteratorEnd )
    {
        //aRowOfCellsIterator points to a vector of PropertyMapPtr
        PropertyMapVector1::const_iterator aCellIterator = aRowOfCellsIterator->begin();
        PropertyMapVector1::const_iterator aCellIteratorEnd = aRowOfCellsIterator->end();

        sal_Int32 nCell = 0;
        pCellProperties[nRow].realloc( aRowOfCellsIterator->size() );
        beans::PropertyValues* pSingleCellProperties = pCellProperties->getArray();
        while( aCellIterator != aCellIteratorEnd )
        {
            //TODO: aCellIterator contains HorizontalBorder and VerticalBorder
            // they have to be removed, depending on the position of the cell they
            // have to be moved to BottomBorder/RightBorder respectively
            //aCellIterator points to a PropertyMapPtr;
            if( aCellIterator->get() )
            {

                const PropertyMap::iterator aVerticalIter =
                                aCellIterator->get()->find( rPropSupplier.GetName(META_PROP_VERTICAL_BORDER) );
                const PropertyMap::iterator aHorizontalIter =
                                aCellIterator->get()->find( rPropSupplier.GetName(META_PROP_HORIZONTAL_BORDER) );
                const PropertyMap::const_iterator aRightIter =
                                aCellIterator->get()->find( rPropSupplier.GetName(PROP_RIGHT_BORDER) );
                const PropertyMap::const_iterator aBottomIter =
                                aCellIterator->get()->find( rPropSupplier.GetName(PROP_BOTTOM_BORDER) );
                if( aVerticalIter != aCellIterator->get()->end())
                    aCellIterator->get()->erase( aVerticalIter );
                if( aHorizontalIter != aCellIterator->get()->end())
                    aCellIterator->get()->erase( aHorizontalIter );

                pSingleCellProperties[nCell] = aCellIterator->get()->GetPropertyValues();
            }
            ++nCell;
            ++aCellIterator;
        }
        ++nRow;
        ++aRowOfCellsIterator;
    }

    RowPropertyValuesSeq_t      aRowProperties( m_aRowProperties.size() );
    PropertyMapVector1::const_iterator aRowIter = m_aRowProperties.begin();
    PropertyMapVector1::const_iterator aRowIterEnd = m_aRowProperties.end();
    nRow = 0;
    while( aRowIter != aRowIterEnd )
    {
        if( aRowIter->get() )
        {
            //set default to 'break across pages"
            if( aRowIter->get()->find(rPropSupplier.GetName(PROP_IS_SPLIT_ALLOWED)) == aRowIter->get()->end())
                aRowIter->get()->Insert( PROP_IS_SPLIT_ALLOWED, uno::makeAny(sal_True ) );

            aRowProperties[nRow] = aRowIter->get()->GetPropertyValues();
        }
        ++nRow;
        ++aRowIter;
    }

    TablePropertyValues_t       aTableProperties;
    if( m_aTableProperties.get() )
    {
        //fill default value - if not available
        const PropertyMap::const_iterator aRepeatIter =
                                m_aTableProperties->find( rPropSupplier.GetName(PROP_HEADER_ROW_COUNT) );
        if( aRepeatIter == m_aTableProperties->end() )
        {
            m_aTableProperties->Insert( PROP_HEADER_ROW_COUNT, uno::makeAny( (sal_Int32)0 ));
        }

        aTableProperties = m_aTableProperties->GetPropertyValues();
    }

    if (m_pTableSeq->getLength() > 0)
    {
        try
        {
#ifdef DEBUG
    {
        sal_Int32 nCellPropertiesRows = aCellProperties.getLength();
        sal_Int32 nCellPropertiesCells = aCellProperties[0].getLength();
        sal_Int32 nCellPropertiesProperties = aCellProperties[0][0].getLength();
        (void) nCellPropertiesRows;
        (void) nCellPropertiesCells;
        (void) nCellPropertiesProperties;
        ++nCellPropertiesProperties;
    }
#endif
            m_xText->convertToTable(*m_pTableSeq,
                                    aCellProperties,
                                    aRowProperties,
                                    aTableProperties);
        }
        catch (lang::IllegalArgumentException e)
        {
#ifdef DEBUG
            clog << "failed to import table!" << endl;
#endif
        }
    }
}

void DomainMapperTableHandler::startRow(unsigned int nCells,
                                        PropertyMapPtr pProps)
{
    m_aRowProperties.push_back( pProps );
    m_aCellProperties.push_back( PropertyMapVector1() );

#ifdef DEBUG
    char sBuffer[256];
    snprintf(sBuffer, sizeof(sBuffer), "%d", nCells);

    clog << "<table.row cells=\"" << sBuffer << "\">" << endl;
    lcl_printProperties( pProps );
#endif

    m_pRowSeq = RowSequencePointer_t(new RowSequence_t(nCells));
    m_nCellIndex = 0;
}

void DomainMapperTableHandler::endRow()
{
    (*m_pTableSeq)[m_nRowIndex] = *m_pRowSeq;
    ++m_nRowIndex;
    m_nCellIndex = 0;
#ifdef DEBUG
    clog << "
" << endl;
#endif
}

void DomainMapperTableHandler::startCell(const Handle_t & start,
                                         PropertyMapPtr pProps )
{
    sal_uInt32 nRow = m_aRowProperties.size();
    m_aCellProperties[nRow - 1].push_back( pProps );

#ifdef DEBUG
    clog << "
";
    lcl_printHandle(start);
    lcl_printProperties( pProps );
    clog << ",";
#endif

    //add a new 'row' of properties
//    if( m_pCellProperties.size() <= sal::static_int_cast< sal_uInt32, sal_Int32>(m_nRowIndex) )
//        m_pCellProperties.push_back( RowProperties_t() );
//    m_pCellProperties[m_nRowIndex].push_back( pProps );
    m_pCellSeq = CellSequencePointer_t(new CellSequence_t(2));
    (*m_pCellSeq)[0] = start->getStart();
}

void DomainMapperTableHandler::endCell(const Handle_t & end)
{
#ifdef DEBUG
    lcl_printHandle(end);
    clog << "
" << endl;
#endif

    (*m_pCellSeq)[1] = end->getEnd();
    (*m_pRowSeq)[m_nCellIndex] = *m_pCellSeq;
    ++m_nCellIndex;
}

}
<|endoftext|>


<commit_before>// Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-806117.
//
// This file is part of the MFEM library. For more information and source code
// availability visit https://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#ifndef MFEM_BLOCKOPERATOR
#define MFEM_BLOCKOPERATOR

#include "../config/config.hpp"
#include "../general/array.hpp"
#include "operator.hpp"
#include "blockvector.hpp"

namespace mfem
{

//! @class BlockOperator
/**
 * \brief A class to handle Block systems in a matrix-free implementation.
 *
 * Usage:
 * - Use one of the constructors to define the block structure.
 * - Use SetDiagonalBlock or SetBlock to fill the BlockOperator
 * - Use the method Mult and MultTranspose to apply the operator to a vector.
 *
 * If a block is not set, it is assumed to be a zero block.
 */
class BlockOperator : public Operator
{
public:
   //! Constructor for BlockOperators with the same block-structure for rows and
   //! columns.
   /**
    *  offsets: offsets that mark the start of each row/column block (size
    *  nRowBlocks+1).  Note: BlockOperator will not own/copy the data contained
    *  in offsets.
    */
   BlockOperator(const Array<int> & offsets);
   //! Constructor for general BlockOperators.
   /**
    *  row_offsets: offsets that mark the start of each row block (size
    *  nRowBlocks+1).  col_offsets: offsets that mark the start of each column
    *  block (size nColBlocks+1).  Note: BlockOperator will not own/copy the
    *  data contained in offsets.
    */
   BlockOperator(const Array<int> & row_offsets, const Array<int> & col_offsets);

   //! Add block op in the block-entry (iblock, iblock).
   /**
    * iblock: The block will be inserted in location (iblock, iblock).
    * op: the Operator to be inserted.
    * c: optional scalar multiple for this block.
    */
   void SetDiagonalBlock(int iblock, Operator *op, double c = 1.0);
   //! Add a block op in the block-entry (iblock, jblock).
   /**
    * irow, icol: The block will be inserted in location (irow, icol).
    * op: the Operator to be inserted.
    * c: optional scalar multiple for this block.
    */
   void SetBlock(int iRow, int iCol, Operator *op, double c = 1.0);

   //! Return the number of row blocks
   int NumRowBlocks() const { return nRowBlocks; }
   //! Return the number of column blocks
   int NumColBlocks() const { return nColBlocks; }

   //! Check if block (i,j) is a zero block
   int IsZeroBlock(int i, int j) const { return (op(i,j)==NULL) ? 1 : 0; }
   //! Return a reference to block i,j
   Operator & GetBlock(int i, int j)
   { MFEM_VERIFY(op(i,j), ""); return *op(i,j); }
   //! Return the coefficient for block i,j
   double GetBlockCoef(int i, int j) const
   { MFEM_VERIFY(op(i,j), ""); return coef(i,j); }
   //! Set the coefficient for block i,j
   void SetBlockCoef(int i, int j, double c)
   { MFEM_VERIFY(op(i,j), ""); coef(i,j) = c; }

   //! Return the row offsets for block starts
   Array<int> & RowOffsets() { return row_offsets; }
   //! Return the columns offsets for block starts
   Array<int> & ColOffsets() { return col_offsets; }

   /// Operator application
   virtual void Mult (const Vector & x, Vector & y) const;

   /// Action of the transpose operator
   virtual void MultTranspose (const Vector & x, Vector & y) const;

   ~BlockOperator();

   //! Controls the ownership of the blocks: if nonzero, BlockOperator will
   //! delete all blocks that are set (non-NULL); the default value is zero.
   int owns_blocks;

private:
   //! Number of block rows
   int nRowBlocks;
   //! Number of block columns
   int nColBlocks;
   //! Row offsets for the starting position of each block
   Array<int> row_offsets;
   //! Column offsets for the starting position of each block
   Array<int> col_offsets;
   //! 2D array that stores each block of the operator.
   Array2D<Operator *> op;
   //! 2D array that stores a coefficient for each block of the operator.
   Array2D<double> coef;

   //! Temporary Vectors used to efficiently apply the Mult and MultTranspose methods.
   mutable BlockVector xblock;
   mutable BlockVector yblock;
   mutable Vector tmp;
};

//! @class BlockDiagonalPreconditioner
/**
 * \brief A class to handle Block diagonal preconditioners in a matrix-free implementation.
 *
 * Usage:
 * - Use the constructors to define the block structure
 * - Use SetDiagonalBlock to fill the BlockOperator
 * - Use the method Mult and MultTranspose to apply the operator to a vector.
 *
 * If a block is not set, it is assumed to be an identity block.
 *
 */
class BlockDiagonalPreconditioner : public Solver
{
public:
   //! Constructor that specifies the block structure
   BlockDiagonalPreconditioner(const Array<int> & offsets);
   //! Add a square block op in the block-entry (iblock, iblock).
   /**
    * iblock: The block will be inserted in location (iblock, iblock).
    * op: the Operator to be inserted.
    */
   void SetDiagonalBlock(int iblock, Operator *op);
   //! This method is present since required by the abstract base class Solver
   virtual void SetOperator(const Operator &op) { }

   //! Return the number of blocks
   int NumBlocks() const { return nBlocks; }

   //! Return a reference to block i,i.
   Operator & GetDiagonalBlock(int iblock)
   { MFEM_VERIFY(op[iblock], ""); return *op[iblock]; }

   //! Return the offsets for block starts
   Array<int> & Offsets() { return offsets; }

   /// Operator application
   virtual void Mult (const Vector & x, Vector & y) const;

   /// Action of the transpose operator
   virtual void MultTranspose (const Vector & x, Vector & y) const;

   ~BlockDiagonalPreconditioner();

   //! Controls the ownership of the blocks: if nonzero,
   //! BlockDiagonalPreconditioner will delete all blocks that are set
   //! (non-NULL); the default value is zero.
   int owns_blocks;

private:
   //! Number of Blocks
   int nBlocks;
   //! Offsets for the starting position of each block
   Array<int> offsets;
   //! 1D array that stores each block of the operator.
   Array<Operator *> op;
   //! Temporary Vectors used to efficiently apply the Mult and MultTranspose
   //! methods.
   mutable BlockVector xblock;
   mutable BlockVector yblock;
};

//! @class BlockLowerTriangularPreconditioner
/**
 * \brief A class to handle Block lower triangular preconditioners in a
 * matrix-free implementation.
 *
 * Usage:
 * - Use the constructors to define the block structure
 * - Use SetBlock() to fill the BlockOperator
 * - Diagonal blocks of the preconditioner should approximate the inverses of
 *   the diagonal block of the matrix
 * - Off-diagonal blocks of the preconditioner should match/approximate those of
 *   the original matrix
 * - Use the method Mult() and MultTranspose() to apply the operator to a vector.
 *
 * If a diagonal block is not set, it is assumed to be an identity block, if an
 * off-diagonal block is not set, it is assumed to be a zero block.
 *
 */
class BlockLowerTriangularPreconditioner : public Solver
{
public:
   //! Constructor for BlockLowerTriangularPreconditioners with the same
   //! block-structure for rows and columns.
   /**
    *  @param offsets  Offsets that mark the start of each row/column block
    *                  (size nBlocks+1).
    *
    *  @note BlockLowerTriangularPreconditioner will not own/copy the data
    *  contained in @a offsets.
    */
   BlockLowerTriangularPreconditioner(const Array<int> & offsets);

   //! Add block op in the block-entry (iblock, iblock).
   /**
    * @param iblock  The block will be inserted in location (iblock, iblock).
    * @param op      The Operator to be inserted.
    */
   void SetDiagonalBlock(int iblock, Operator *op);
   //! Add a block op in the block-entry (iblock, jblock).
   /**
    * @param iRow, iCol  The block will be inserted in location (iRow, iCol).
    * @param op          The Operator to be inserted.
    */
   void SetBlock(int iRow, int iCol, Operator *op);
   //! This method is present since required by the abstract base class Solver
   virtual void SetOperator(const Operator &op) { }

   //! Return the number of blocks
   int NumBlocks() const { return nBlocks; }

   //! Return a reference to block i,j.
   Operator & GetBlock(int iblock, int jblock)
   { MFEM_VERIFY(op(iblock,jblock), ""); return *op(iblock,jblock); }

   //! Return the offsets for block starts
   Array<int> & Offsets() { return offsets; }

   /// Operator application
   virtual void Mult (const Vector & x, Vector & y) const;

   /// Action of the transpose operator
   virtual void MultTranspose (const Vector & x, Vector & y) const;

   ~BlockLowerTriangularPreconditioner();

   //! Controls the ownership of the blocks: if nonzero,
   //! BlockLowerTriangularPreconditioner will delete all blocks that are set
   //! (non-NULL); the default value is zero.
   int owns_blocks;

private:
   //! Number of block rows/columns
   int nBlocks;
   //! Offsets for the starting position of each block
   Array<int> offsets;
   //! 2D array that stores each block of the operator.
   Array2D<Operator *> op;

   //! Temporary Vectors used to efficiently apply the Mult and MultTranspose
   //! methods.
   mutable BlockVector xblock;
   mutable BlockVector yblock;
   mutable Vector tmp;
   mutable Vector tmp2;
};

}
#endif /* MFEM_BLOCKOPERATOR */
<commit_msg>add some handy const get functions for BlockOperator<commit_after>// Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
// LICENSE and NOTICE for details. LLNL-CODE-806117.
//
// This file is part of the MFEM library. For more information and source code
// availability visit https://mfem.org.
//
// MFEM is free software; you can redistribute it and/or modify it under the
// terms of the BSD-3 license. We welcome feedback and contributions, see file
// CONTRIBUTING.md for details.

#ifndef MFEM_BLOCKOPERATOR
#define MFEM_BLOCKOPERATOR

#include "../config/config.hpp"
#include "../general/array.hpp"
#include "operator.hpp"
#include "blockvector.hpp"

namespace mfem
{

//! @class BlockOperator
/**
 * \brief A class to handle Block systems in a matrix-free implementation.
 *
 * Usage:
 * - Use one of the constructors to define the block structure.
 * - Use SetDiagonalBlock or SetBlock to fill the BlockOperator
 * - Use the method Mult and MultTranspose to apply the operator to a vector.
 *
 * If a block is not set, it is assumed to be a zero block.
 */
class BlockOperator : public Operator
{
public:
   //! Constructor for BlockOperators with the same block-structure for rows and
   //! columns.
   /**
    *  offsets: offsets that mark the start of each row/column block (size
    *  nRowBlocks+1).  Note: BlockOperator will not own/copy the data contained
    *  in offsets.
    */
   BlockOperator(const Array<int> & offsets);
   //! Constructor for general BlockOperators.
   /**
    *  row_offsets: offsets that mark the start of each row block (size
    *  nRowBlocks+1).  col_offsets: offsets that mark the start of each column
    *  block (size nColBlocks+1).  Note: BlockOperator will not own/copy the
    *  data contained in offsets.
    */
   BlockOperator(const Array<int> & row_offsets, const Array<int> & col_offsets);

   //! Add block op in the block-entry (iblock, iblock).
   /**
    * iblock: The block will be inserted in location (iblock, iblock).
    * op: the Operator to be inserted.
    * c: optional scalar multiple for this block.
    */
   void SetDiagonalBlock(int iblock, Operator *op, double c = 1.0);
   //! Add a block op in the block-entry (iblock, jblock).
   /**
    * irow, icol: The block will be inserted in location (irow, icol).
    * op: the Operator to be inserted.
    * c: optional scalar multiple for this block.
    */
   void SetBlock(int iRow, int iCol, Operator *op, double c = 1.0);

   //! Return the number of row blocks
   int NumRowBlocks() const { return nRowBlocks; }
   //! Return the number of column blocks
   int NumColBlocks() const { return nColBlocks; }

   //! Check if block (i,j) is a zero block
   int IsZeroBlock(int i, int j) const { return (op(i,j)==NULL) ? 1 : 0; }
   //! Return a reference to block i,j
   Operator & GetBlock(int i, int j)
   { MFEM_VERIFY(op(i,j), ""); return *op(i,j); }
   //! Return a const reference to block i,j
   const Operator & GetBlock(int i, int j) const
   { MFEM_VERIFY(op(i,j), ""); return *op(i,j); }
   //! Return the coefficient for block i,j
   double GetBlockCoef(int i, int j) const
   { MFEM_VERIFY(op(i,j), ""); return coef(i,j); }
   //! Set the coefficient for block i,j
   void SetBlockCoef(int i, int j, double c)
   { MFEM_VERIFY(op(i,j), ""); coef(i,j) = c; }

   //! Return the row offsets for block starts
   Array<int> & RowOffsets() { return row_offsets; }
   //! Return the columns offsets for block starts
   Array<int> & ColOffsets() { return col_offsets; }
   //! Return the const row offsets for block starts
   const Array<int> & RowOffsets() const { return row_offsets; }
   //! Return the const columns offsets for block starts
   const Array<int> & ColOffsets() const { return col_offsets; }

   /// Operator application
   virtual void Mult (const Vector & x, Vector & y) const;

   /// Action of the transpose operator
   virtual void MultTranspose (const Vector & x, Vector & y) const;

   ~BlockOperator();

   //! Controls the ownership of the blocks: if nonzero, BlockOperator will
   //! delete all blocks that are set (non-NULL); the default value is zero.
   int owns_blocks;

private:
   //! Number of block rows
   int nRowBlocks;
   //! Number of block columns
   int nColBlocks;
   //! Row offsets for the starting position of each block
   Array<int> row_offsets;
   //! Column offsets for the starting position of each block
   Array<int> col_offsets;
   //! 2D array that stores each block of the operator.
   Array2D<Operator *> op;
   //! 2D array that stores a coefficient for each block of the operator.
   Array2D<double> coef;

   //! Temporary Vectors used to efficiently apply the Mult and MultTranspose methods.
   mutable BlockVector xblock;
   mutable BlockVector yblock;
   mutable Vector tmp;
};

//! @class BlockDiagonalPreconditioner
/**
 * \brief A class to handle Block diagonal preconditioners in a matrix-free implementation.
 *
 * Usage:
 * - Use the constructors to define the block structure
 * - Use SetDiagonalBlock to fill the BlockOperator
 * - Use the method Mult and MultTranspose to apply the operator to a vector.
 *
 * If a block is not set, it is assumed to be an identity block.
 *
 */
class BlockDiagonalPreconditioner : public Solver
{
public:
   //! Constructor that specifies the block structure
   BlockDiagonalPreconditioner(const Array<int> & offsets);
   //! Add a square block op in the block-entry (iblock, iblock).
   /**
    * iblock: The block will be inserted in location (iblock, iblock).
    * op: the Operator to be inserted.
    */
   void SetDiagonalBlock(int iblock, Operator *op);
   //! This method is present since required by the abstract base class Solver
   virtual void SetOperator(const Operator &op) { }

   //! Return the number of blocks
   int NumBlocks() const { return nBlocks; }

   //! Return a reference to block i,i.
   Operator & GetDiagonalBlock(int iblock)
   { MFEM_VERIFY(op[iblock], ""); return *op[iblock]; }

   //! Return the offsets for block starts
   Array<int> & Offsets() { return offsets; }

   /// Operator application
   virtual void Mult (const Vector & x, Vector & y) const;

   /// Action of the transpose operator
   virtual void MultTranspose (const Vector & x, Vector & y) const;

   ~BlockDiagonalPreconditioner();

   //! Controls the ownership of the blocks: if nonzero,
   //! BlockDiagonalPreconditioner will delete all blocks that are set
   //! (non-NULL); the default value is zero.
   int owns_blocks;

private:
   //! Number of Blocks
   int nBlocks;
   //! Offsets for the starting position of each block
   Array<int> offsets;
   //! 1D array that stores each block of the operator.
   Array<Operator *> op;
   //! Temporary Vectors used to efficiently apply the Mult and MultTranspose
   //! methods.
   mutable BlockVector xblock;
   mutable BlockVector yblock;
};

//! @class BlockLowerTriangularPreconditioner
/**
 * \brief A class to handle Block lower triangular preconditioners in a
 * matrix-free implementation.
 *
 * Usage:
 * - Use the constructors to define the block structure
 * - Use SetBlock() to fill the BlockOperator
 * - Diagonal blocks of the preconditioner should approximate the inverses of
 *   the diagonal block of the matrix
 * - Off-diagonal blocks of the preconditioner should match/approximate those of
 *   the original matrix
 * - Use the method Mult() and MultTranspose() to apply the operator to a vector.
 *
 * If a diagonal block is not set, it is assumed to be an identity block, if an
 * off-diagonal block is not set, it is assumed to be a zero block.
 *
 */
class BlockLowerTriangularPreconditioner : public Solver
{
public:
   //! Constructor for BlockLowerTriangularPreconditioners with the same
   //! block-structure for rows and columns.
   /**
    *  @param offsets  Offsets that mark the start of each row/column block
    *                  (size nBlocks+1).
    *
    *  @note BlockLowerTriangularPreconditioner will not own/copy the data
    *  contained in @a offsets.
    */
   BlockLowerTriangularPreconditioner(const Array<int> & offsets);

   //! Add block op in the block-entry (iblock, iblock).
   /**
    * @param iblock  The block will be inserted in location (iblock, iblock).
    * @param op      The Operator to be inserted.
    */
   void SetDiagonalBlock(int iblock, Operator *op);
   //! Add a block op in the block-entry (iblock, jblock).
   /**
    * @param iRow, iCol  The block will be inserted in location (iRow, iCol).
    * @param op          The Operator to be inserted.
    */
   void SetBlock(int iRow, int iCol, Operator *op);
   //! This method is present since required by the abstract base class Solver
   virtual void SetOperator(const Operator &op) { }

   //! Return the number of blocks
   int NumBlocks() const { return nBlocks; }

   //! Return a reference to block i,j.
   Operator & GetBlock(int iblock, int jblock)
   { MFEM_VERIFY(op(iblock,jblock), ""); return *op(iblock,jblock); }

   //! Return the offsets for block starts
   Array<int> & Offsets() { return offsets; }

   /// Operator application
   virtual void Mult (const Vector & x, Vector & y) const;

   /// Action of the transpose operator
   virtual void MultTranspose (const Vector & x, Vector & y) const;

   ~BlockLowerTriangularPreconditioner();

   //! Controls the ownership of the blocks: if nonzero,
   //! BlockLowerTriangularPreconditioner will delete all blocks that are set
   //! (non-NULL); the default value is zero.
   int owns_blocks;

private:
   //! Number of block rows/columns
   int nBlocks;
   //! Offsets for the starting position of each block
   Array<int> offsets;
   //! 2D array that stores each block of the operator.
   Array2D<Operator *> op;

   //! Temporary Vectors used to efficiently apply the Mult and MultTranspose
   //! methods.
   mutable BlockVector xblock;
   mutable BlockVector yblock;
   mutable Vector tmp;
   mutable Vector tmp2;
};

}
#endif /* MFEM_BLOCKOPERATOR */
<|endoftext|>


<commit_before>/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_ANDROID)

#include "gl/GrGLInterface.h"
#include "gl/GrGLAssembleInterface.h"
#include "gl/GrGLUtil.h"

#include <EGL/egl.h>
#include <GLES2/gl2.h>

static GrGLFuncPtr android_get_gl_proc(void* ctx, const char name[]) {
    SkASSERT(nullptr == ctx);
    // Some older drivers on Android have busted eglGetProcAdddress Functions that
    // will return the wrong pointer for built in GLES2 functions. This set of functions
    // was generated on a Xoom by finding mismatches between the function pulled in via gl2.h and
    // the address returned by eglGetProcAddress.
    if (0 == strcmp("glActiveTexture", name)) {
        return (GrGLFuncPtr) glActiveTexture;
    } else if (0 == strcmp("glAttachShader", name)) {
        return (GrGLFuncPtr) glAttachShader;
    } else if (0 == strcmp("glBindAttribLocation", name)) {
        return (GrGLFuncPtr) glBindAttribLocation;
    } else if (0 == strcmp("glBindBuffer", name)) {
        return (GrGLFuncPtr) glBindBuffer;
    } else if (0 == strcmp("glBindTexture", name)) {
        return (GrGLFuncPtr) glBindTexture;
    } else if (0 == strcmp("glBlendColor", name)) {
        return (GrGLFuncPtr) glBlendColor;
    } else if (0 == strcmp("glBlendEquation", name)) {
        return (GrGLFuncPtr) glBlendEquation;
    } else if (0 == strcmp("glBlendFunc", name)) {
        return (GrGLFuncPtr) glBlendFunc;
    } else if (0 == strcmp("glBufferData", name)) {
        return (GrGLFuncPtr) glBufferData;
    } else if (0 == strcmp("glBufferSubData", name)) {
        return (GrGLFuncPtr) glBufferSubData;
    } else if (0 == strcmp("glClear", name)) {
        return (GrGLFuncPtr) glClear;
    } else if (0 == strcmp("glClearColor", name)) {
        return (GrGLFuncPtr) glClearColor;
    } else if (0 == strcmp("glClearStencil", name)) {
        return (GrGLFuncPtr) glClearStencil;
    } else if (0 == strcmp("glColorMask", name)) {
        return (GrGLFuncPtr) glColorMask;
    } else if (0 == strcmp("glCompileShader", name)) {
        return (GrGLFuncPtr) glCompileShader;
    } else if (0 == strcmp("glCompressedTexImage2D", name)) {
        return (GrGLFuncPtr) glCompressedTexImage2D;
    } else if (0 == strcmp("glCompressedTexSubImage2D", name)) {
        return (GrGLFuncPtr) glCompressedTexSubImage2D;
    } else if (0 == strcmp("glCopyTexSubImage2D", name)) {
        return (GrGLFuncPtr) glCopyTexSubImage2D;
    } else if (0 == strcmp("glCreateProgram", name)) {
        return (GrGLFuncPtr) glCreateProgram;
    } else if (0 == strcmp("glCreateShader", name)) {
        return (GrGLFuncPtr) glCreateShader;
    } else if (0 == strcmp("glCullFace", name)) {
        return (GrGLFuncPtr) glCullFace;
    } else if (0 == strcmp("glDeleteBuffers", name)) {
        return (GrGLFuncPtr) glDeleteBuffers;
    } else if (0 == strcmp("glDeleteProgram", name)) {
        return (GrGLFuncPtr) glDeleteProgram;
    } else if (0 == strcmp("glDeleteShader", name)) {
        return (GrGLFuncPtr) glDeleteShader;
    } else if (0 == strcmp("glDeleteTextures", name)) {
        return (GrGLFuncPtr) glDeleteTextures;
    } else if (0 == strcmp("glDepthMask", name)) {
        return (GrGLFuncPtr) glDepthMask;
    } else if (0 == strcmp("glDisable", name)) {
        return (GrGLFuncPtr) glDisable;
    } else if (0 == strcmp("glDisableVertexAttribArray", name)) {
        return (GrGLFuncPtr) glDisableVertexAttribArray;
    } else if (0 == strcmp("glDrawArrays", name)) {
        return (GrGLFuncPtr) glDrawArrays;
    } else if (0 == strcmp("glDrawElements", name)) {
        return (GrGLFuncPtr) glDrawElements;
    } else if (0 == strcmp("glEnable", name)) {
        return (GrGLFuncPtr) glEnable;
    } else if (0 == strcmp("glEnableVertexAttribArray", name)) {
        return (GrGLFuncPtr) glEnableVertexAttribArray;
    } else if (0 == strcmp("glFinish", name)) {
        return (GrGLFuncPtr) glFinish;
    } else if (0 == strcmp("glFlush", name)) {
        return (GrGLFuncPtr) glFlush;
    } else if (0 == strcmp("glFrontFace", name)) {
        return (GrGLFuncPtr) glFrontFace;
    } else if (0 == strcmp("glGenBuffers", name)) {
        return (GrGLFuncPtr) glGenBuffers;
    } else if (0 == strcmp("glGenerateMipmap", name)) {
        return (GrGLFuncPtr) glGenerateMipmap;
    } else if (0 == strcmp("glGenTextures", name)) {
        return (GrGLFuncPtr) glGenTextures;
    } else if (0 == strcmp("glGetBufferParameteriv", name)) {
        return (GrGLFuncPtr) glGetBufferParameteriv;
    } else if (0 == strcmp("glGetError", name)) {
        return (GrGLFuncPtr) glGetError;
    } else if (0 == strcmp("glGetIntegerv", name)) {
        return (GrGLFuncPtr) glGetIntegerv;
    } else if (0 == strcmp("glGetProgramInfoLog", name)) {
        return (GrGLFuncPtr) glGetProgramInfoLog;
    } else if (0 == strcmp("glGetProgramiv", name)) {
        return (GrGLFuncPtr) glGetProgramiv;
    } else if (0 == strcmp("glGetShaderInfoLog", name)) {
        return (GrGLFuncPtr) glGetShaderInfoLog;
    } else if (0 == strcmp("glGetShaderiv", name)) {
        return (GrGLFuncPtr) glGetShaderiv;
    } else if (0 == strcmp("glGetShaderPrecisionFormat", name)) {
        return (GrGLFuncPtr) glGetShaderPrecisionFormat;
    } else if (0 == strcmp("glGetString", name)) {
        return (GrGLFuncPtr) glGetString;
    } else if (0 == strcmp("glGetUniformLocation", name)) {
        return (GrGLFuncPtr) glGetUniformLocation;
    } else if (0 == strcmp("glLineWidth", name)) {
        return (GrGLFuncPtr) glLineWidth;
    } else if (0 == strcmp("glLinkProgram", name)) {
        return (GrGLFuncPtr) glLinkProgram;
    } else if (0 == strcmp("glPixelStorei", name)) {
        return (GrGLFuncPtr) glPixelStorei;
    } else if (0 == strcmp("glReadPixels", name)) {
        return (GrGLFuncPtr) glReadPixels;
    } else if (0 == strcmp("glScissor", name)) {
        return (GrGLFuncPtr) glScissor;
    } else if (0 == strcmp("glShaderSource", name)) {
        return (GrGLFuncPtr) glShaderSource;
    } else if (0 == strcmp("glStencilFunc", name)) {
        return (GrGLFuncPtr) glStencilFunc;
    } else if (0 == strcmp("glStencilFuncSeparate", name)) {
        return (GrGLFuncPtr) glStencilFuncSeparate;
    } else if (0 == strcmp("glStencilMask", name)) {
        return (GrGLFuncPtr) glStencilMask;
    } else if (0 == strcmp("glStencilMaskSeparate", name)) {
        return (GrGLFuncPtr) glStencilMaskSeparate;
    } else if (0 == strcmp("glStencilOp", name)) {
        return (GrGLFuncPtr) glStencilOp;
    } else if (0 == strcmp("glStencilOpSeparate", name)) {
        return (GrGLFuncPtr) glStencilOpSeparate;
    } else if (0 == strcmp("glTexImage2D", name)) {
        return (GrGLFuncPtr) glTexImage2D;
    } else if (0 == strcmp("glTexParameteri", name)) {
        return (GrGLFuncPtr) glTexParameteri;
    } else if (0 == strcmp("glTexParameteriv", name)) {
        return (GrGLFuncPtr) glTexParameteriv;
    } else if (0 == strcmp("glTexSubImage2D", name)) {
        return (GrGLFuncPtr) glTexSubImage2D;
    } else if (0 == strcmp("glUniform1f", name)) {
        return (GrGLFuncPtr) glUniform1f;
    } else if (0 == strcmp("glUniform1i", name)) {
        return (GrGLFuncPtr) glUniform1i;
    } else if (0 == strcmp("glUniform1fv", name)) {
        return (GrGLFuncPtr) glUniform1fv;
    } else if (0 == strcmp("glUniform1iv", name)) {
        return (GrGLFuncPtr) glUniform1iv;
    } else if (0 == strcmp("glUniform2f", name)) {
        return (GrGLFuncPtr) glUniform2f;
    } else if (0 == strcmp("glUniform2i", name)) {
        return (GrGLFuncPtr) glUniform2i;
    } else if (0 == strcmp("glUniform2fv", name)) {
        return (GrGLFuncPtr) glUniform2fv;
    } else if (0 == strcmp("glUniform2iv", name)) {
        return (GrGLFuncPtr) glUniform2iv;
    } else if (0 == strcmp("glUniform3f", name)) {
        return (GrGLFuncPtr) glUniform3f;
    } else if (0 == strcmp("glUniform3i", name)) {
        return (GrGLFuncPtr) glUniform3i;
    } else if (0 == strcmp("glUniform3fv", name)) {
        return (GrGLFuncPtr) glUniform3fv;
    } else if (0 == strcmp("glUniform3iv", name)) {
        return (GrGLFuncPtr) glUniform3iv;
    } else if (0 == strcmp("glUniform4f", name)) {
        return (GrGLFuncPtr) glUniform4f;
    } else if (0 == strcmp("glUniform4i", name)) {
        return (GrGLFuncPtr) glUniform4i;
    } else if (0 == strcmp("glUniform4fv", name)) {
        return (GrGLFuncPtr) glUniform4fv;
    } else if (0 == strcmp("glUniform4iv", name)) {
        return (GrGLFuncPtr) glUniform4iv;
    } else if (0 == strcmp("glUniformMatrix2fv", name)) {
        return (GrGLFuncPtr) glUniformMatrix2fv;
    } else if (0 == strcmp("glUniformMatrix3fv", name)) {
        return (GrGLFuncPtr) glUniformMatrix3fv;
    } else if (0 == strcmp("glUniformMatrix4fv", name)) {
        return (GrGLFuncPtr) glUniformMatrix4fv;
    } else if (0 == strcmp("glUseProgram", name)) {
        return (GrGLFuncPtr) glUseProgram;
    } else if (0 == strcmp("glVertexAttrib1f", name)) {
        return (GrGLFuncPtr) glVertexAttrib1f;
    } else if (0 == strcmp("glVertexAttrib2fv", name)) {
        return (GrGLFuncPtr) glVertexAttrib2fv;
    } else if (0 == strcmp("glVertexAttrib3fv", name)) {
        return (GrGLFuncPtr) glVertexAttrib3fv;
    } else if (0 == strcmp("glVertexAttrib4fv", name)) {
        return (GrGLFuncPtr) glVertexAttrib4fv;
    } else if (0 == strcmp("glVertexAttribPointer", name)) {
        return (GrGLFuncPtr) glVertexAttribPointer;
    } else if (0 == strcmp("glViewport", name)) {
        return (GrGLFuncPtr) glViewport;
    } else if (0 == strcmp("glBindFramebuffer", name)) {
        return (GrGLFuncPtr) glBindFramebuffer;
    } else if (0 == strcmp("glBindRenderbuffer", name)) {
        return (GrGLFuncPtr) glBindRenderbuffer;
    } else if (0 == strcmp("glCheckFramebufferStatus", name)) {
        return (GrGLFuncPtr) glCheckFramebufferStatus;
    } else if (0 == strcmp("glDeleteFramebuffers", name)) {
        return (GrGLFuncPtr) glDeleteFramebuffers;
    } else if (0 == strcmp("glDeleteRenderbuffers", name)) {
        return (GrGLFuncPtr) glDeleteRenderbuffers;
    } else if (0 == strcmp("glFramebufferRenderbuffer", name)) {
        return (GrGLFuncPtr) glFramebufferRenderbuffer;
    } else if (0 == strcmp("glFramebufferTexture2D", name)) {
        return (GrGLFuncPtr) glFramebufferTexture2D;
    } else if (0 == strcmp("glGenFramebuffers", name)) {
        return (GrGLFuncPtr) glGenFramebuffers;
    } else if (0 == strcmp("glGenRenderbuffers", name)) {
        return (GrGLFuncPtr) glGenRenderbuffers;
    } else if (0 == strcmp("glGetFramebufferAttachmentParameteriv", name)) {
        return (GrGLFuncPtr) glGetFramebufferAttachmentParameteriv;
    } else if (0 == strcmp("glGetRenderbufferParameteriv", name)) {
        return (GrGLFuncPtr) glGetRenderbufferParameteriv;
    } else if (0 == strcmp("glRenderbufferStorage", name)) {
        return (GrGLFuncPtr) glRenderbufferStorage;
    } else if (0 == strcmp("eglQueryString", name)) {
        return (GrGLFuncPtr) eglQueryString;
    } else if (0 == strcmp("eglGetCurrentDisplay", name)) {
        return (GrGLFuncPtr) eglGetCurrentDisplay;
    }
    return eglGetProcAddress(name);
}

sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
    return GrGLMakeAssembledInterface(nullptr, android_get_gl_proc);
}

const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }

#endif//defined(SK_BUILD_FOR_ANDROID)
<commit_msg>GrGLES: clean up android_get_gl_proc<commit_after>/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#include "SkTypes.h"
#if defined(SK_BUILD_FOR_ANDROID)

#include "gl/GrGLInterface.h"
#include "gl/GrGLAssembleInterface.h"
#include "gl/GrGLUtil.h"

#include <EGL/egl.h>
#ifndef GL_GLEXT_PROTOTYPES
#define GL_GLEXT_PROTOTYPES
#endif
#include <GLES2/gl2.h>

static GrGLFuncPtr android_get_gl_proc(void* ctx, const char name[]) {
    SkASSERT(nullptr == ctx);
    // Some older drivers on Android have busted eglGetProcAdddress Functions that
    // will return the wrong pointer for built in GLES2 functions. This set of functions
    // was generated on a Xoom by finding mismatches between the function pulled in via gl2.h and
    // the address returned by eglGetProcAddress.

    #define M(X) if (0 == strcmp(#X, name)) { return (GrGLFuncPtr) X; }
    M(eglGetCurrentDisplay);
    M(eglQueryString);
    M(glActiveTexture);
    M(glAttachShader);
    M(glBindAttribLocation);
    M(glBindBuffer);
    M(glBindFramebuffer);
    M(glBindRenderbuffer);
    M(glBindTexture);
    M(glBlendColor);
    M(glBlendEquation);
    M(glBlendFunc);
    M(glBufferData);
    M(glBufferSubData);
    M(glCheckFramebufferStatus);
    M(glClear);
    M(glClearColor);
    M(glClearStencil);
    M(glColorMask);
    M(glCompileShader);
    M(glCompressedTexImage2D);
    M(glCompressedTexSubImage2D);
    M(glCopyTexSubImage2D);
    M(glCreateProgram);
    M(glCreateShader);
    M(glCullFace);
    M(glDeleteBuffers);
    M(glDeleteFramebuffers);
    M(glDeleteProgram);
    M(glDeleteRenderbuffers);
    M(glDeleteShader);
    M(glDeleteTextures);
    M(glDepthMask);
    M(glDisable);
    M(glDisableVertexAttribArray);
    M(glDrawArrays);
    M(glDrawElements);
    M(glEnable);
    M(glEnableVertexAttribArray);
    M(glFinish);
    M(glFlush);
    M(glFramebufferRenderbuffer);
    M(glFramebufferTexture2D);
    M(glFrontFace);
    M(glGenBuffers);
    M(glGenFramebuffers);
    M(glGenRenderbuffers);
    M(glGenTextures);
    M(glGenerateMipmap);
    M(glGetBufferParameteriv);
    M(glGetError);
    M(glGetFramebufferAttachmentParameteriv);
    M(glGetIntegerv);
    M(glGetProgramInfoLog);
    M(glGetProgramiv);
    M(glGetRenderbufferParameteriv);
    M(glGetShaderInfoLog);
    M(glGetShaderPrecisionFormat);
    M(glGetShaderiv);
    M(glGetString);
    M(glGetUniformLocation);
    M(glIsTexture);
    M(glLineWidth);
    M(glLinkProgram);
    M(glPixelStorei);
    M(glReadPixels);
    M(glRenderbufferStorage);
    M(glScissor);
    M(glShaderSource);
    M(glStencilFunc);
    M(glStencilFuncSeparate);
    M(glStencilMask);
    M(glStencilMaskSeparate);
    M(glStencilOp);
    M(glStencilOpSeparate);
    M(glTexImage2D);
    M(glTexParameteri);
    M(glTexParameteriv);
    M(glTexSubImage2D);
    M(glUniform1f);
    M(glUniform1fv);
    M(glUniform1i);
    M(glUniform1iv);
    M(glUniform2f);
    M(glUniform2fv);
    M(glUniform2i);
    M(glUniform2iv);
    M(glUniform3f);
    M(glUniform3fv);
    M(glUniform3i);
    M(glUniform3iv);
    M(glUniform4f);
    M(glUniform4fv);
    M(glUniform4i);
    M(glUniform4iv);
    M(glUniformMatrix2fv);
    M(glUniformMatrix3fv);
    M(glUniformMatrix4fv);
    M(glUseProgram);
    M(glVertexAttrib1f);
    M(glVertexAttrib2fv);
    M(glVertexAttrib3fv);
    M(glVertexAttrib4fv);
    M(glVertexAttribPointer);
    M(glViewport);
    #undef M
    return eglGetProcAddress(name);
}

sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
    return GrGLMakeAssembledInterface(nullptr, android_get_gl_proc);
}

const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }

#endif//defined(SK_BUILD_FOR_ANDROID)
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/lib/p9_hcd_common.H $      */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2017                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
///
/// @file p9_hcd_common.H
/// @brief common hcode includes
///

// *HWP HWP Owner          : David Du       <daviddu@us.ibm.com>
// *HWP Backup HWP Owner   : Greg Still     <stillgs@us.ibm.com>
// *HWP FW Owner           : Sangeetha T S  <sangeet2@in.ibm.com>
// *HWP Team               : PM
// *HWP Consumed by        : SBE:SGPE:CME
// *HWP Level              : 2

#ifndef __P9_HCD_COMMON_H__
#define __P9_HCD_COMMON_H__

//-------------------------
// Macros
//-------------------------

// Create a multi-bit mask of \a n bits starting at bit \a b
#define BITS64(b, n) ((0xffffffffffffffffull << (64 - (n))) >> (b))
#define BITS32(b, n) ((0xffffffff            << (32 - (n))) >> (b))
#define BITS16(b, n) ((0xffff                << (16 - (n))) >> (b))
#define BITS8(b, n)  ((0xff                  << (8  - (n))) >> (b))

// Create a single bit mask at bit \a b
#define BIT64(b) BITS64((b), 1)
#define BIT32(b) BITS32((b), 1)
#define BIT16(b) BITS16((b), 1)
#define BIT8(b)  BITS8((b), 1)

// Create a amount of shift to bit location \a b
#define SHIFT64(b) (63-b)
#define SHIFT32(b) (31-b)
#define SHIFT16(b) (15-b)
#define SHIFT8(b)  (7-b)

// The BUF_* macros apply operations to a newly constructed buffer
#define BUF_SET(bit)   fapi2::buffer<uint64_t>().setBit<bit>()
#define BUF_UNSET(bit) fapi2::buffer<uint64_t>().flush<1>().clearBit<bit>()
#define BUF_INSERT(start,size,val) \
    fapi2::buffer<uint64_t>().insertFromRight<start,size>(val)
#define BUF_REPLACE(start,size,val) \
    fapi2::buffer<uint64_t>().flush<1>().insertFromRight<start,size>(val)
// The following DATA_* and MASK_* macros assume you have
// "fapi2::buffer<uint64_t> l_data64" declared

// The DATA_* macros apply operations to a buffer contains existing data
#define DATA_BIT(buf,op,bit)             buf.op##Bit<bit>()
#define DATA_SET(bit)                    DATA_BIT(l_data64,set,bit)
#define DATA_UNSET(bit)                  DATA_BIT(l_data64,clear,bit)
#define DATA_FIELD(buf,start,size,val)   buf.insertFromRight<start,size>(val)
#define DATA_INSERT(start,size,val)      DATA_FIELD(l_data64,start,size,val)

// The MASK_* macros apply operations to a buffer to create a new data mask
// data previously stored in the buffer will be overwritten.
#define MASK_FLUSH(buf,mask)             buf.flush<mask>()
#define MASK_ZERO                        MASK_FLUSH(l_data64,0)
#define MASK_ALL                         MASK_FLUSH(l_data64,1)
#define MASK_BIT(buf,mask,op,bit)        buf.flush<mask>().op##Bit<bit>()
#define MASK_SET(bit)                    MASK_BIT(l_data64,0,set,bit)
#define MASK_UNSET(bit)                  MASK_BIT(l_data64,1,clear,bit)
#define MASK_FIELD(buf,mask,start,size,val) \
    buf.flush<mask>().insertFromRight<start,size>(val)
#define MASK_OR(start,size,val)          MASK_FIELD(l_data64,0,start,size,val)
#define MASK_AND(start,size,val)         MASK_FIELD(l_data64,1,start,size,val)
#define MASK_CLR(start,size,val)         MASK_FIELD(l_data64,0,start,size,val)

//-------------------------
// Constants
//-------------------------

namespace p9hcd
{

// Bit masks used by CME hcode
enum P9_HCD_CME_CORE_MASKS
{
    LEFT_CORE  = 0x2,
    RIGHT_CORE = 0x1,
    BOTH_CORES = 0x3,
    NO_CORE    = 0x0
};

// Control parameters for PCB Aribter
enum P9_HCD_PCB_ARBITER_CTRL
{
    REQUEST_ARBITER = 1,
    RELEASE_ARBITER = 0
};

// Constants to calculate hcd poll timeout intervals
enum P9_HCD_COMMON_TIMEOUT_CONSTANTS
{
    CYCLES_PER_MS       = 500000, // PPE FREQ 500MHZ
    INSTS_PER_POLL_LOOP = 8       //
};

// Init Vectors for Register Setup
enum P9_HCD_COMMON_INIT_VECTORS
{
    // 0     -  CHIPLET_ENABLE
    // 1     -  PCB_EP_RESET
    // 3     -  PLL_TEST_EN
    // 4     -  PLLRST
    // 5     -  PLLBYP
    // 12    -  VITL_MPW1
    // 13    -  VITL_MPW2
    // 14    -  VITL_MPW3
    // 18    -  FENCE_EN
    NET_CTRL0_INIT_VECTOR = (BIT64(0) | BIT64(1) | BITS64(3, 3) | BITS64(12, 3) | BIT64(18)),
    HANG_PULSE1_INIT_VECTOR = BIT64(5)
};

// Clock Control Constants
enum P9_HCD_COMMON_CLK_CTRL_CONSTANTS
{
    CLK_STOP_CMD                             = BIT64(0),
    CLK_START_CMD                            = BIT64(1),
    CLK_SLAVE_MODE                           = BIT64(2),
    CLK_MASTER_MODE                          = BIT64(3),
    CLK_REGION_ANEP                          = BIT64(10),
    CLK_REGION_DPLL                          = BIT64(14),
    CLK_REGION_L2                            = BITS64(8, 2),
    CLK_REGION_ALL_BUT_DPLL_L2               = BITS64(4, 4) | BITS64(10, 4),
    CLK_REGION_ALL                           = BITS64(4, 11),
    CLK_THOLD_ALL                            = BITS64(48, 3),
    CLK_THOLD_NSL_ARY                        = BITS64(49, 2)
};

// Clock Control Vectors
enum P9_HCD_COMMON_CLK_CTRL_VECTORS
{
    CLK_START_REGION_ALL_THOLD_NSL_ARY =
        (CLK_START_CMD | CLK_REGION_ALL | CLK_THOLD_NSL_ARY),
    CLK_START_REGION_ALL_THOLD_ALL =
        (CLK_START_CMD | CLK_REGION_ALL | CLK_THOLD_ALL),
    CLK_START_REGION_ALL_BUT_DPLL_L2_THOLD_NSL_ARY =
        (CLK_START_CMD | CLK_REGION_ALL_BUT_DPLL_L2 | CLK_THOLD_NSL_ARY),
    CLK_START_REGION_ALL_BUT_DPLL_L2_THOLD_ALL =
        (CLK_START_CMD | CLK_REGION_ALL_BUT_DPLL_L2 | CLK_THOLD_ALL),
    CLK_START_REGION_L2_THOLD_NSL_ARY =
        (CLK_START_CMD | CLK_REGION_L2 | CLK_THOLD_NSL_ARY),
    CLK_START_REGION_L2_THOLD_ALL =
        (CLK_START_CMD | CLK_REGION_L2 | CLK_THOLD_ALL),
    CLK_START_REGION_DPLL_THOLD_NSL_ARY =
        (CLK_START_CMD | CLK_REGION_DPLL | CLK_THOLD_NSL_ARY),
    CLK_START_REGION_DPLL_THOLD_ALL =
        (CLK_START_CMD | CLK_REGION_DPLL | CLK_THOLD_ALL),
    CLK_START_REGION_ANEP_THOLD_NSL_ARY =
        (CLK_START_CMD | CLK_REGION_ANEP | CLK_THOLD_NSL_ARY),
    CLK_START_REGION_ANEP_THOLD_ALL =
        (CLK_START_CMD | CLK_REGION_ANEP | CLK_THOLD_ALL)
};

// SCAN0 Constants
enum P9_HCD_COMMON_SCAN0_CONSTANTS
{
    SCAN0_REGION_ALL                         = 0x7FF,
    SCAN0_REGION_ALL_BUT_PLL                 = 0x7FE,
    SCAN0_REGION_ALL_BUT_ANEP_PLL            = 0x7EE,
    SCAN0_REGION_PLL                         = 0x001,
    SCAN0_REGION_DPLL_ANEP                   = 0x011,
    SCAN0_REGION_CORE_ONLY                   = 0x300,
    SCAN0_REGION_PERV_CORE                   = 0x700,
    SCAN0_TYPE_ALL_BUT_GPTR_REPR_TIME        = 0xDCF,
    SCAN0_TYPE_GPTR_REPR_TIME                = 0x230,
    SCAN0_TYPE_REPR_TIME                     = 0x030,
    SCAN0_TYPE_GPTR                          = 0x200,
    SCAN0_TYPE_FUNC                          = 0x800,
    SCAN0_TYPE_FUNC_BNDY                     = 0x808
};
//OCC FLag defines
enum PM_GPE_OCCFLG_DEFS
{
    SGPE_ACTIVE    = 8
};

// XSR defines
enum XSR_DEFS
{
    HALTED_STATE    = 0
};

// XCR defines
enum XCR_DEFS
{
    CLEAR_DEBUG_STATUS = 0,
    HALT               = 1,
    RESUME             = 2,
    SINGLE_STEP        = 3,
    TOGGLE_XSR_TRH     = 4,
    SOFT_RESET         = 5,
    HARD_RESET         = 6,
    FORCE_HALT         = 7
};

} // END OF NAMESPACE p9hcd

/// @todo needs to review this
/// SCAN Repeats(from P8)
/*
#define GENERIC_CC_SCAN0_MAXIMUM   8191
#define SCAN0_FUNC_FLUSH_LENGTH    8000
#define SCAN0_GPTR_FLUSH_LENGTH    14000
#define P9_HCD_SCAN_FUNC_REPEAT    \
    ((SCAN0_FUNC_FLUSH_LENGTH / GENERIC_CC_SCAN0_MAXIMUM)+1)
#define P9_HCD_SCAN_GPTR_REPEAT    \
    ((SCAN0_GPTR_FLUSH_LENGTH / GENERIC_CC_SCAN0_MAXIMUM)+1)
*/
#define P9_HCD_SCAN_FUNC_REPEAT 40
#define P9_HCD_SCAN_GPTR_REPEAT 40

/// @todo remove these once correct header contains them
/// Scom addresses missing from p9_quad_scom_addresses.H
#define EQ_QPPM_QCCR_WOR                 0x100F01BF
#define CME_LCL_SICR_OR                  0xc0000510
#define CME_LCL_SICR_CLR                 0xc0000518
#define CME_LCL_SISR                     0xc0000520

#endif  // __P9_HCD_COMMON_H__
<commit_msg>HWP-CACHE/CORE:istep4 procedures updates<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/lib/p9_hcd_common.H $      */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2017                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
///
/// @file p9_hcd_common.H
/// @brief common hcode includes

// *HWP HWP Owner          : David Du       <daviddu@us.ibm.com>
// *HWP Backup HWP Owner   : Greg Still     <stillgs@us.ibm.com>
// *HWP FW Owner           : Sangeetha T S  <sangeet2@in.ibm.com>
// *HWP Team               : PM
// *HWP Consumed by        : SBE:SGPE:CME
// *HWP Level              : 2

#ifndef __P9_HCD_COMMON_H__
#define __P9_HCD_COMMON_H__

//-------------------------
// Macros
//-------------------------

// Create a multi-bit mask of \a n bits starting at bit \a b
#define BITS64(b, n) ((0xffffffffffffffffull << (64 - (n))) >> (b))
#define BITS32(b, n) ((0xffffffff            << (32 - (n))) >> (b))
#define BITS16(b, n) ((0xffff                << (16 - (n))) >> (b))
#define BITS8(b, n)  ((0xff                  << (8  - (n))) >> (b))

// Create a single bit mask at bit \a b
#define BIT64(b) BITS64((b), 1)
#define BIT32(b) BITS32((b), 1)
#define BIT16(b) BITS16((b), 1)
#define BIT8(b)  BITS8((b), 1)

// Create a amount of shift to bit location \a b
#define SHIFT64(b) (63-b)
#define SHIFT32(b) (31-b)
#define SHIFT16(b) (15-b)
#define SHIFT8(b)  (7-b)

// The BUF_* macros apply operations to a newly constructed buffer
#define BUF_SET(bit)   fapi2::buffer<uint64_t>().setBit<bit>()
#define BUF_UNSET(bit) fapi2::buffer<uint64_t>().flush<1>().clearBit<bit>()
#define BUF_INSERT(start,size,val) \
    fapi2::buffer<uint64_t>().insertFromRight<start,size>(val)
#define BUF_REPLACE(start,size,val) \
    fapi2::buffer<uint64_t>().flush<1>().insertFromRight<start,size>(val)
// The following DATA_* and MASK_* macros assume you have
// "fapi2::buffer<uint64_t> l_data64" declared

// The DATA_* macros apply operations to a buffer contains existing data
#define DATA_BIT(buf,op,bit)             buf.op##Bit<bit>()
#define DATA_SET(bit)                    DATA_BIT(l_data64,set,bit)
#define DATA_UNSET(bit)                  DATA_BIT(l_data64,clear,bit)
#define DATA_FIELD(buf,start,size,val)   buf.insertFromRight<start,size>(val)
#define DATA_INSERT(start,size,val)      DATA_FIELD(l_data64,start,size,val)

// The MASK_* macros apply operations to a buffer to create a new data mask
// data previously stored in the buffer will be overwritten.
#define MASK_FLUSH(buf,mask)             buf.flush<mask>()
#define MASK_ZERO                        MASK_FLUSH(l_data64,0)
#define MASK_ALL                         MASK_FLUSH(l_data64,1)
#define MASK_BIT(buf,mask,op,bit)        buf.flush<mask>().op##Bit<bit>()
#define MASK_SET(bit)                    MASK_BIT(l_data64,0,set,bit)
#define MASK_UNSET(bit)                  MASK_BIT(l_data64,1,clear,bit)
#define MASK_FIELD(buf,mask,start,size,val) \
    buf.flush<mask>().insertFromRight<start,size>(val)
#define MASK_OR(start,size,val)          MASK_FIELD(l_data64,0,start,size,val)
#define MASK_AND(start,size,val)         MASK_FIELD(l_data64,1,start,size,val)
#define MASK_CLR(start,size,val)         MASK_FIELD(l_data64,0,start,size,val)

//-------------------------
// Constants
//-------------------------

namespace p9hcd
{

// Bit masks used by CME hcode
enum P9_HCD_CME_CORE_MASKS
{
    LEFT_CORE  = 0x2,
    RIGHT_CORE = 0x1,
    BOTH_CORES = 0x3,
    NO_CORE    = 0x0
};

// Control parameters for PCB Aribter
enum P9_HCD_PCB_ARBITER_CTRL
{
    REQUEST_ARBITER = 1,
    RELEASE_ARBITER = 0
};

// Constants to calculate hcd poll timeout intervals
enum P9_HCD_TIMEOUT_CONSTANTS
{
    CYCLES_PER_MS       = 500000, // PPE FREQ 500MHZ
    INSTS_PER_POLL_LOOP = 8       //
};

// Constants to work with fapi2target
enum P9_HCD_TARGET_CONSTANTS
{
    PERV_TO_EQ_POS_OFFSET   = 0x10,
    PERV_TO_CORE_POS_OFFSET = 0x20
};

// Init Vectors for Register Setup
enum P9_HCD_COMMON_INIT_VECTORS
{
    // 1     -  PCB_EP_RESET
    // 2     -  SKEW_ADJUST_RESET
    // 3     -  PLL_TEST_EN
    // 4     -  PLLRST
    // 5     -  PLLBYP
    // 11    -  EDIS
    // 12    -  VITL_MPW1
    // 13    -  VITL_MPW2
    // 14    -  VITL_MPW3
    // 18    -  FENCE_EN
    // 22    -  SKEW_ADJUST_FUNC_CLKSEL
    // 26    -  LVLTRANS_FENCE
    Q_NET_CTRL0_INIT_VECTOR = (BITS64(1, 5) | BITS64(11, 4) |
                               BIT64(18) | BIT64(22) | BIT64(26)),
    C_NET_CTRL0_INIT_VECTOR = (BIT64(1) | BITS64(3, 3) | BITS64(11, 4) |
                               BIT64(18) | BIT64(22) | BIT64(26)),
};

// Clock Control Constants
enum P9_HCD_COMMON_CLK_CTRL_CONSTANTS
{
    CLK_STOP_CMD                             = BIT64(0),
    CLK_START_CMD                            = BIT64(1),
    CLK_SLAVE_MODE                           = BIT64(2),
    CLK_MASTER_MODE                          = BIT64(3),
    CLK_REGION_ANEP                          = BIT64(10),
    CLK_REGION_DPLL                          = BIT64(14),
    CLK_REGION_ALL_BUT_EX_DPLL               = BITS64(4, 2) | BITS64(10, 2),
    CLK_REGION_EX0_L2_L3_REFR                = BIT64(6) | BIT64(8) | BIT64(12),
    CLK_REGION_EX1_L2_L3_REFR                = BIT64(7) | BIT64(9) | BIT64(13),
    CLK_REGION_ALL                           = BITS64(4, 11),
    CLK_REGION_NONE                          = 0,
    CLK_THOLD_ALL                            = BITS64(48, 3),
    CLK_THOLD_NSL_ARY                        = BITS64(49, 2)
};

// Clock Control Vectors
enum P9_HCD_COMMON_CLK_CTRL_VECTORS
{
    CLK_START_REGION_ALL_THOLD_NSL_ARY =
        (CLK_START_CMD | CLK_REGION_ALL | CLK_THOLD_NSL_ARY),
    CLK_START_REGION_ALL_THOLD_ALL =
        (CLK_START_CMD | CLK_REGION_ALL | CLK_THOLD_ALL),
    CLK_START_REGION_NONE_THOLD_NSL_ARY =
        (CLK_START_CMD | CLK_REGION_NONE | CLK_THOLD_NSL_ARY),
    CLK_START_REGION_NONE_THOLD_ALL =
        (CLK_START_CMD | CLK_REGION_NONE | CLK_THOLD_ALL),
    CLK_START_REGION_DPLL_THOLD_NSL_ARY =
        (CLK_START_CMD | CLK_REGION_DPLL | CLK_THOLD_NSL_ARY),
    CLK_START_REGION_DPLL_THOLD_ALL =
        (CLK_START_CMD | CLK_REGION_DPLL | CLK_THOLD_ALL),
    CLK_START_REGION_ANEP_THOLD_NSL_ARY =
        (CLK_START_CMD | CLK_REGION_ANEP | CLK_THOLD_NSL_ARY),
    CLK_START_REGION_ANEP_THOLD_ALL =
        (CLK_START_CMD | CLK_REGION_ANEP | CLK_THOLD_ALL)
};

// SCAN0 Constants
enum P9_HCD_COMMON_SCAN0_CONSTANTS
{
    SCAN0_REGION_ALL                         = 0x7FF,
    SCAN0_REGION_ALL_BUT_EX                  = 0x619,
    SCAN0_REGION_ALL_BUT_EX_DPLL             = 0x618,
    SCAN0_REGION_ALL_BUT_EX_ANEP_DPLL        = 0x608,
    SCAN0_REGION_EX0_L2_L3_REFR              = 0x144,
    SCAN0_REGION_EX1_L2_L3_REFR              = 0x0A2,
    SCAN0_REGION_DPLL                        = 0x001,
    SCAN0_REGION_ANEP_DPLL                   = 0x011,
    SCAN0_REGION_CORE_ONLY                   = 0x300,
    SCAN0_REGION_PERV_CORE                   = 0x700,
    SCAN0_TYPE_ALL_BUT_GPTR_REPR_TIME        = 0xDCF,
    SCAN0_TYPE_ALL_BUT_GPTR                  = 0xDFF,
    SCAN0_TYPE_GPTR_REPR_TIME                = 0x230,
    SCAN0_TYPE_REPR_TIME                     = 0x030,
    SCAN0_TYPE_GPTR                          = 0x200,
    SCAN0_TYPE_FUNC                          = 0x800,
    SCAN0_TYPE_FUNC_BNDY                     = 0x808
};

//OCC FLag defines
enum PM_GPE_OCCFLG_DEFS
{
    SGPE_ACTIVE    = 8
};

// XSR defines
enum XSR_DEFS
{
    HALTED_STATE    = 0
};

// XCR defines
enum XCR_DEFS
{
    CLEAR_DEBUG_STATUS = 0,
    HALT               = 1,
    RESUME             = 2,
    SINGLE_STEP        = 3,
    TOGGLE_XSR_TRH     = 4,
    SOFT_RESET         = 5,
    HARD_RESET         = 6,
    FORCE_HALT         = 7
};

} // END OF NAMESPACE p9hcd

/// @todo needs to review this
/// SCAN Repeats(from P8)
/*
#define GENERIC_CC_SCAN0_MAXIMUM   8191
#define SCAN0_FUNC_FLUSH_LENGTH    8000
#define SCAN0_GPTR_FLUSH_LENGTH    14000
#define P9_HCD_SCAN_FUNC_REPEAT    \
    ((SCAN0_FUNC_FLUSH_LENGTH / GENERIC_CC_SCAN0_MAXIMUM)+1)
#define P9_HCD_SCAN_GPTR_REPEAT    \
    ((SCAN0_GPTR_FLUSH_LENGTH / GENERIC_CC_SCAN0_MAXIMUM)+1)
*/
#define P9_HCD_SCAN_FUNC_REPEAT 40
#define P9_HCD_SCAN_GPTR_REPEAT 40

/// @todo remove these once correct header contains them
/// Scom addresses missing from p9_quad_scom_addresses.H
#define EQ_QPPM_QCCR_WOR                 0x100F01BF
#define CME_LCL_SICR_OR                  0xc0000510
#define CME_LCL_SICR_CLR                 0xc0000518
#define CME_LCL_SISR                     0xc0000520

#endif  // __P9_HCD_COMMON_H__
<|endoftext|>