<commit_before>// Copyright 2009, Google Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//  1. Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//  2. Redistributions in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//  3. Neither the name of Google Inc. nor the names of its contributors may be
//     used to endorse or promote products derived from this software without
//     specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// This file contains the implementation of the ZipFile class.

#include <exception>
#include "kml/base/zip_file.h"
#include "kml/base/file.h"
#include "minizip/unzip.h"
#include "minizip/zip.h"

namespace kmlbase {

// The maximum uncompressed file size we permit the underlying zip reader
// to attempt to handle by default. (2 GB, as per minizip/unzip.h.)
static const unsigned long kMaxUncompressedZipSize = ZIP_MAX_UNCOMPRESSED_SIZE;

// This class hides the use of minizip from the interface.
class MinizipFile {
 public:
  MinizipFile(zipFile zipfile) : zipfile_(zipfile) {}
  ~MinizipFile() {
    if (zipfile_) {
      zipClose(zipfile_, 0);
    }
  }
  zipFile get_zipfile() { return zipfile_; }
 private:
  zipFile zipfile_;
  LIBKML_DISALLOW_EVIL_CONSTRUCTORS(MinizipFile);
};

// Static.
ZipFile* ZipFile::OpenFromString(const string& zip_data) {
  return IsZipData(zip_data) ? new ZipFile(zip_data) : NULL;
}

// Static.
ZipFile* ZipFile::OpenFromFile(const char* file_path) {
  if (!File::Exists(file_path)) {
    return NULL;
  }
  string data;
  if (!File::ReadFileToString(file_path, &data)) {
    return NULL;
  }
  return OpenFromString(data);
}

// Static.
ZipFile* ZipFile::Create(const char* file_path) {
  zipFile zipfile = zipOpen(file_path, 0);
  if (!zipfile) {
    return NULL;
  }
  MinizipFile* minizipfile = new MinizipFile(zipfile);
  if (!minizipfile) {
    return NULL;
  }
  return new ZipFile(minizipfile);
}

// Private. Class constructed with static methods.
ZipFile::ZipFile(const string& data)
  : minizip_file_(NULL), data_(data),
    max_uncompressed_file_size_(kMaxUncompressedZipSize) {
  // Fill the table of contents for this zipfile.
  zlib_filefunc_def api;
  if (voidpf mem_stream = mem_simple_create_file(
      &api, const_cast<void*>(static_cast<const void*>(data.data())),
      data.size())) {
    unzFile zfile = libkml_unzAttach(mem_stream, &api);
    if (zfile) {
      unz_file_info finfo;
      do {
        static char buf[1024];
        if (libkml_unzGetCurrentFileInfo(zfile, &finfo, buf, sizeof(buf),
              0, 0, 0, 0) == UNZ_OK) {
          zipfile_toc_.push_back(buf);
        }
      } while (libkml_unzGoToNextFile(zfile) == UNZ_OK);
      libkml_unzClose(zfile);
    }
  }
}

// Private. Class constructed with static methods.
ZipFile::ZipFile(MinizipFile* minizip_file)
  : minizip_file_(minizip_file),
    max_uncompressed_file_size_(kMaxUncompressedZipSize) {}

ZipFile::~ZipFile() {
  // Scoped ptr takes care of minizip_file_.
}

// Static.
bool ZipFile::IsZipData(const string& zip_data) {
  return zip_data.substr(0, 4) == "PK\003\004" ? true : false;
}

bool ZipFile::FindFirstOf(const string& file_extension,
                          string* path_in_zip) const {
  if (!path_in_zip) {
    return false;
  }
  kmlbase::StringVector::const_iterator itr = zipfile_toc_.begin();
  for(; itr != zipfile_toc_.end(); ++itr) {
    if (kmlbase::StringEndsWith(*itr, file_extension)) {
      *path_in_zip = *itr;
      return true;
    }
  }
  return false;
}

bool ZipFile::GetToc(kmlbase::StringVector* subfiles) const {
  if (!subfiles) {
    return false;
  }
  *subfiles = zipfile_toc_;
  return true;
}

// Is the requested path in the Zip file's table of contents?
bool ZipFile::IsInToc(const string& path_in_zip) const {
  kmlbase::StringVector::const_iterator itr = zipfile_toc_.begin();
  for(; itr != zipfile_toc_.end(); ++itr) {
    if (*itr == path_in_zip) {
      return true;
    }
  }
  return false;
}

// This helper class owns the closing of the unzFile handle used in the
// GetEntry method.
class UnzFileHelper {
 public:
  UnzFileHelper(unzFile unzfile) : unzfile_(unzfile) {}
  ~UnzFileHelper() { libkml_unzClose(unzfile_); }
  unzFile get_unzfile() { return unzfile_; }
 private:
  unzFile unzfile_;
};

bool ZipFile::GetEntry(const string& path_in_zip,
                       string* output) const {
  // Check the TOC first.
  if (!IsInToc(path_in_zip)) {
    return false;
  }
  zlib_filefunc_def api;
  voidpf mem_stream = mem_simple_create_file(
      &api, const_cast<void*>(static_cast<const void*>(data_.data())),
      data_.size());
  if (!mem_stream) {
    return false;
  }
  unzFile unzfile = libkml_unzAttach(mem_stream, &api);
  if (!unzfile) {
    return false;
  }

  boost::scoped_ptr<UnzFileHelper> unzfilehelper(new UnzFileHelper(unzfile));
  unz_file_info finfo;
  if (libkml_unzLocateFile(unzfilehelper->get_unzfile(),
                    path_in_zip.c_str(), 0) != UNZ_OK ||
      libkml_unzOpenCurrentFile(unzfilehelper->get_unzfile()) != UNZ_OK ||
      libkml_unzGetCurrentFileInfo(unzfilehelper->get_unzfile(), &finfo, 0, 0,
                                   0, 0, 0, 0) != UNZ_OK) {
    return false;
  }
  unsigned long nbytes = finfo.uncompressed_size;
  if (nbytes == 0 || nbytes > max_uncompressed_file_size_) {
    // This is likely an imcompatibility between the library with which the
    // file was created and what the underlying minizip library can
    // uncompress. One such error is in the unit test for this file.
    return false;
  }
  // We permit output to be NULL.
  if (!output) {
    return true;
  }
  char* filedata = new char[nbytes];
  if (libkml_unzReadCurrentFile(unzfilehelper->get_unzfile(), filedata,
                         nbytes) == static_cast<int>(nbytes)) {
    output->assign(filedata, nbytes);
    delete [] filedata;
    return true;
  }
  delete [] filedata;
  return false;
}

bool ZipFile::AddEntry(const string& data,
                       const string& path_in_zip) {
  // The path must be relative to and below the archive.
  if (path_in_zip.substr(0, 1).find_first_of("/\\") != string::npos ||
      path_in_zip.substr(0, 2) == "..") {
    return false;
  }
  if (!minizip_file_) {
    return false;
  }
  zipFile zipfile = minizip_file_->get_zipfile();
  if (!zipfile) {
    return false;
  }
  zipOpenNewFileInZip(zipfile, path_in_zip.c_str(), 0, 0, 0, 0, 0, 0,
                      Z_DEFLATED, Z_DEFAULT_COMPRESSION);
  zipWriteInFileInZip(zipfile, static_cast<const void*>(data.data()),
                      static_cast<unsigned int>(data.size()));
  return zipCloseFileInZip(zipfile) == ZIP_OK;
}

}  // end namespace kmlbase
<commit_msg>include minizip from contrib. avoiding bundled copy<commit_after>// Copyright 2009, Google Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//  1. Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//  2. Redistributions in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//  3. Neither the name of Google Inc. nor the names of its contributors may be
//     used to endorse or promote products derived from this software without
//     specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// This file contains the implementation of the ZipFile class.

#include <exception>
#include "kml/base/zip_file.h"
#include "kml/base/file.h"

#include "kml/base/contrib/minizip/unzip.h"
#include "kml/base/contrib/minizip/iomem_simple.h"

#include <minizip/zip.h>

namespace kmlbase {

// The maximum uncompressed file size we permit the underlying zip reader
// to attempt to handle by default. (2 GB, as per minizip/unzip.h.)
static const unsigned long kMaxUncompressedZipSize = ZIP_MAX_UNCOMPRESSED_SIZE;

// This class hides the use of minizip from the interface.
class MinizipFile {
 public:
  MinizipFile(zipFile zipfile) : zipfile_(zipfile) {}
  ~MinizipFile() {
    if (zipfile_) {
      zipClose(zipfile_, 0);
    }
  }
  zipFile get_zipfile() { return zipfile_; }
 private:
  zipFile zipfile_;
  LIBKML_DISALLOW_EVIL_CONSTRUCTORS(MinizipFile);
};

// Static.
ZipFile* ZipFile::OpenFromString(const string& zip_data) {
  return IsZipData(zip_data) ? new ZipFile(zip_data) : NULL;
}

// Static.
ZipFile* ZipFile::OpenFromFile(const char* file_path) {
  if (!File::Exists(file_path)) {
    return NULL;
  }
  string data;
  if (!File::ReadFileToString(file_path, &data)) {
    return NULL;
  }
  return OpenFromString(data);
}

// Static.
ZipFile* ZipFile::Create(const char* file_path) {
  zipFile zipfile = zipOpen(file_path, 0);
  if (!zipfile) {
    return NULL;
  }
  MinizipFile* minizipfile = new MinizipFile(zipfile);
  if (!minizipfile) {
    return NULL;
  }
  return new ZipFile(minizipfile);
}

// Private. Class constructed with static methods.
ZipFile::ZipFile(const string& data)
  : minizip_file_(NULL), data_(data),
    max_uncompressed_file_size_(kMaxUncompressedZipSize) {
  // Fill the table of contents for this zipfile.
  zlib_filefunc_def api;
  if (voidpf mem_stream = mem_simple_create_file(
      &api, const_cast<void*>(static_cast<const void*>(data.data())),
      data.size())) {
    unzFile zfile = libkml_unzAttach(mem_stream, &api);
    if (zfile) {
      unz_file_info finfo;
      do {
        static char buf[1024];
        if (libkml_unzGetCurrentFileInfo(zfile, &finfo, buf, sizeof(buf),
              0, 0, 0, 0) == UNZ_OK) {
          zipfile_toc_.push_back(buf);
        }
      } while (libkml_unzGoToNextFile(zfile) == UNZ_OK);
      libkml_unzClose(zfile);
    }
  }
}

// Private. Class constructed with static methods.
ZipFile::ZipFile(MinizipFile* minizip_file)
  : minizip_file_(minizip_file),
    max_uncompressed_file_size_(kMaxUncompressedZipSize) {}

ZipFile::~ZipFile() {
  // Scoped ptr takes care of minizip_file_.
}

// Static.
bool ZipFile::IsZipData(const string& zip_data) {
  return zip_data.substr(0, 4) == "PK\003\004" ? true : false;
}

bool ZipFile::FindFirstOf(const string& file_extension,
                          string* path_in_zip) const {
  if (!path_in_zip) {
    return false;
  }
  kmlbase::StringVector::const_iterator itr = zipfile_toc_.begin();
  for(; itr != zipfile_toc_.end(); ++itr) {
    if (kmlbase::StringEndsWith(*itr, file_extension)) {
      *path_in_zip = *itr;
      return true;
    }
  }
  return false;
}

bool ZipFile::GetToc(kmlbase::StringVector* subfiles) const {
  if (!subfiles) {
    return false;
  }
  *subfiles = zipfile_toc_;
  return true;
}

// Is the requested path in the Zip file's table of contents?
bool ZipFile::IsInToc(const string& path_in_zip) const {
  kmlbase::StringVector::const_iterator itr = zipfile_toc_.begin();
  for(; itr != zipfile_toc_.end(); ++itr) {
    if (*itr == path_in_zip) {
      return true;
    }
  }
  return false;
}

// This helper class owns the closing of the unzFile handle used in the
// GetEntry method.
class UnzFileHelper {
 public:
  UnzFileHelper(unzFile unzfile) : unzfile_(unzfile) {}
  ~UnzFileHelper() { libkml_unzClose(unzfile_); }
  unzFile get_unzfile() { return unzfile_; }
 private:
  unzFile unzfile_;
};

bool ZipFile::GetEntry(const string& path_in_zip,
                       string* output) const {
  // Check the TOC first.
  if (!IsInToc(path_in_zip)) {
    return false;
  }
  zlib_filefunc_def api;
  voidpf mem_stream = mem_simple_create_file(
      &api, const_cast<void*>(static_cast<const void*>(data_.data())),
      data_.size());
  if (!mem_stream) {
    return false;
  }
  unzFile unzfile = libkml_unzAttach(mem_stream, &api);
  if (!unzfile) {
    return false;
  }

  boost::scoped_ptr<UnzFileHelper> unzfilehelper(new UnzFileHelper(unzfile));
  unz_file_info finfo;
  if (libkml_unzLocateFile(unzfilehelper->get_unzfile(),
                    path_in_zip.c_str(), 0) != UNZ_OK ||
      libkml_unzOpenCurrentFile(unzfilehelper->get_unzfile()) != UNZ_OK ||
      libkml_unzGetCurrentFileInfo(unzfilehelper->get_unzfile(), &finfo, 0, 0,
                                   0, 0, 0, 0) != UNZ_OK) {
    return false;
  }
  unsigned long nbytes = finfo.uncompressed_size;
  if (nbytes == 0 || nbytes > max_uncompressed_file_size_) {
    // This is likely an imcompatibility between the library with which the
    // file was created and what the underlying minizip library can
    // uncompress. One such error is in the unit test for this file.
    return false;
  }
  // We permit output to be NULL.
  if (!output) {
    return true;
  }
  char* filedata = new char[nbytes];
  if (libkml_unzReadCurrentFile(unzfilehelper->get_unzfile(), filedata,
                         nbytes) == static_cast<int>(nbytes)) {
    output->assign(filedata, nbytes);
    delete [] filedata;
    return true;
  }
  delete [] filedata;
  return false;
}

bool ZipFile::AddEntry(const string& data,
                       const string& path_in_zip) {
  // The path must be relative to and below the archive.
  if (path_in_zip.substr(0, 1).find_first_of("/\\") != string::npos ||
      path_in_zip.substr(0, 2) == "..") {
    return false;
  }
  if (!minizip_file_) {
    return false;
  }
  zipFile zipfile = minizip_file_->get_zipfile();
  if (!zipfile) {
    return false;
  }
  zipOpenNewFileInZip(zipfile, path_in_zip.c_str(), 0, 0, 0, 0, 0, 0,
                      Z_DEFLATED, Z_DEFAULT_COMPRESSION);
  zipWriteInFileInZip(zipfile, static_cast<const void*>(data.data()),
                      static_cast<unsigned int>(data.size()));
  return zipCloseFileInZip(zipfile) == ZIP_OK;
}

}  // end namespace kmlbase
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/fir/check.C $   */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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 check.C
/// @brief Subroutines for checking MSS FIR
///
// *HWP HWP Owner: Jacob Harvey <jlharvey@us.ibm.com>
// *HWP HWP Backup: Marc Gollub <gollub@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 3
// *HWP Consumed by: FSP:HB

#include <fapi2.H>
#include <p9_mc_scom_addresses.H>
#include <p9_mc_scom_addresses_fld.H>

#include <generic/memory/lib/utils/scom.H>
#include <lib/fir/fir.H>
#include <lib/fir/check.H>
#include <lib/utils/assert_noexit.H>
#include <generic/memory/lib/utils/find.H>

using fapi2::TARGET_TYPE_MCBIST;
using fapi2::TARGET_TYPE_MCA;

namespace mss
{

namespace check
{

///
/// @brief A small, local, class to hold some of the FFDC information we need from the ports
///
struct fir_ffdc
{
    ///
    /// @brief fir_ffdc ctor
    /// @param[in] the MCA target the FFDC was collected from
    /// @param[in] the cal FIR information
    /// @param[in] the phy FIR information
    ///
    fir_ffdc( const fapi2::Target<TARGET_TYPE_MCA>& i_target, const uint64_t i_calfir, const uint64_t i_phyfir ):
        iv_target(i_target),
        iv_calfir(i_calfir),
        iv_phyfir(i_phyfir)
    {}

    ~fir_ffdc() = default;
    fir_ffdc() = delete;

    fapi2::Target<TARGET_TYPE_MCA> iv_target;
    uint64_t iv_calfir;
    uint64_t iv_phyfir;
};

///
/// @brief Check FIR bits during PHY reset
/// @note For DDRPHYFIR and some MBACALFIR errors, up to and including phy reset, need to
/// handle within the phy reset procedure, since we may get errors from a 'non-functional'
/// magic port, which PRD can't analyze.
/// @param[in] i_target the fapi2::Target MCBIST
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS iff ok
///
template<>
fapi2::ReturnCode during_phy_reset( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target )
{
    // Save off the current current_err
    fapi2::ReturnCode l_current_err(fapi2::current_err);

    // Error path: if we hit error before FIR check (we can see that in current_err), and FIR check also
    // finds something, commit first error and exit phy reset with new error from FIR check
    // If bit on, call out MCA with deconfig and gard, including DDRPHYFIR and MBACALFIR in FFDC
    // Do FIR check on all ports, so we can log errors from multiple ports that happen to have FIR bits on

    // Create a mask from the bits Marc wants us to check
    fapi2::buffer<uint64_t> l_calfir_mask;
    l_calfir_mask.setBit<MCA_MBACALFIRQ_MBA_RECOVERABLE_ERROR>()
    .setBit<MCA_MBACALFIRQ_MBA_NONRECOVERABLE_ERROR>()
    .setBit<MCA_MBACALFIRQ_SM_1HOT_ERR>();

    fapi2::buffer<uint64_t> l_phyfir_mask;
    l_phyfir_mask.setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_0>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_1>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_2>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_3>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_4>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_5>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_6>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_7>();

    // Go grab the MCA_MBACALFIRQ for each port. We only save off some of the FFDC information for the ports which
    // have FIR set. This allows us to 1) see if we have any thing to do (empty vector means we don't) and 2) gives us
    // all the information we need to log all the proper errors.
    std::vector< fir_ffdc> l_fir_ffdc;

    for (const auto& p : mss::find_targets_with_magic<TARGET_TYPE_MCA>(i_target))
    {
        fapi2::buffer<uint64_t> l_calfir_data;
        fapi2::buffer<uint64_t> l_phyfir_data;
        fapi2::buffer<uint64_t> l_calfir_masked;
        fapi2::buffer<uint64_t> l_phyfir_masked;

        FAPI_TRY( mss::getScom(p, MCA_MBACALFIRQ, l_calfir_data) );
        FAPI_TRY( mss::getScom(p, MCA_IOM_PHY0_DDRPHY_FIR_REG, l_phyfir_data) );

        l_calfir_masked = l_calfir_data & l_calfir_mask;
        l_phyfir_masked = l_phyfir_data & l_phyfir_mask;

        // If either has set bits we make a little record in the vector
        if ((l_calfir_masked != 0) || (l_phyfir_masked != 0))
        {
            l_fir_ffdc.push_back( fir_ffdc(p, l_calfir_data, l_phyfir_data) );
        }

        // Clear the FIR
        FAPI_TRY( mss::putScom(p, MCA_MBACALFIRQ_AND, l_calfir_masked.invert()) );
        FAPI_TRY( mss::putScom(p, MCA_IOM_PHY0_DDRPHY_FIR_REG_AND, l_phyfir_masked.invert()) );
    }

    FAPI_INF("seeing FIRs set on %d ports", l_fir_ffdc.size());

    // Ok, we know if l_fir_ffdc is empty that we had no FIR bits set. In this case we just return fapi2::current_err
    // as it represents the error state of our caller. If there were no errors seen by the caller, this will be
    // SUCCESS, and our caller will return SUCCESS. If there was an error, we don't disturb it, we just return
    // is so the caller can pass it back to it's caller (if there are FIR we'll disrupt current_err ...)
    if (l_fir_ffdc.size() == 0)
    {
        return l_current_err;
    }

    // Ok so if we're here we have FIR bits set. Not sure it matters what they are, we're returning them in the FFDC
    // and calling out/deconfig the port. First thing we do is commit whatever was in fapi2::current_err, if it's not
    // success.
    if (l_current_err != fapi2::FAPI2_RC_SUCCESS)
    {
        fapi2::logError(l_current_err);
    }

    // Now log all the errors which represent all the errors found from the ports.
    for (const fir_ffdc& f : l_fir_ffdc)
    {
        MSS_ASSERT_NOEXIT(false,
                          fapi2::MSS_DDR_PHY_RESET_PORT_FIR()
                          .set_CAL_FIR(f.iv_calfir)
                          .set_PHY_FIR(f.iv_phyfir)
                          .set_MCA_TARGET(f.iv_target),
                          "Reporting FIR bits set for %s (cal: 0x%016lx phy: 0x%016lx",
                          mss::c_str(f.iv_target), f.iv_calfir, f.iv_phyfir);
    }

    // The last thing we want to do is to create a new error code noting there were FIR set for any of the ports
    // during PHY reset and pass that back so it goes upstream. This will jump right to the label ...
    FAPI_ASSERT(false, fapi2::MSS_DDR_PHY_RESET_PORT_FIRS_REPORTED().set_MCBIST_TARGET(i_target));

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Check FIR bits during draminit training
/// @param[in] i_target the dimm that was trained
/// @note We check for fir errors after training each rank
/// to see if there was a problem with the engine.
/// FFDC errors returned from this will be handled similar to other training errors:
/// Logged as informational if it affects less than a nibble and a bit.
/// Reported if it affects more than that
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS iff ok
///
template<>
fapi2::ReturnCode during_draminit_training( const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target)
{
    const auto& l_mca = mss::find_target<fapi2::TARGET_TYPE_MCA>(i_target);

    // Creating a mask to check for FIR errors.
    // These are DP16 parity errors that would be triggered in case of a general PHY error
    // During draminit_training, this would mean a training error dealing with the PHY
    fapi2::buffer<uint64_t> l_phyfir_mask;
    l_phyfir_mask.setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_0>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_1>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_2>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_3>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_4>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_5>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_6>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_7>();

    fapi2::buffer<uint64_t> l_phyfir_data;
    fapi2::buffer<uint64_t> l_phyfir_masked;

    FAPI_TRY( mss::getScom(l_mca, MCA_IOM_PHY0_DDRPHY_FIR_REG, l_phyfir_data) );

    l_phyfir_masked = l_phyfir_data & l_phyfir_mask;

    FAPI_ASSERT( l_phyfir_masked == 0,
                 fapi2::MSS_DRAMINIT_TRAINING_PORT_FIR()
                 .set_PHY_FIR(l_phyfir_masked)
                 .set_DIMM_TARGET(i_target)
                 .set_MCA_TARGET(l_mca),
                 "Initial CAL failed: Reporting FIR bits set for %s ( phy: 0x%016lx",
                 mss::c_str(i_target), l_phyfir_masked);

fapi_try_exit:
    return fapi2::current_err;
}

}
}
<commit_msg>Clear bit 56/ ddr_phy fir bit 2 after dram cal<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/memory/lib/fir/check.C $   */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,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 check.C
/// @brief Subroutines for checking MSS FIR
///
// *HWP HWP Owner: Jacob Harvey <jlharvey@us.ibm.com>
// *HWP HWP Backup: Marc Gollub <gollub@us.ibm.com>
// *HWP Team: Memory
// *HWP Level: 3
// *HWP Consumed by: FSP:HB

#include <fapi2.H>
#include <p9_mc_scom_addresses.H>
#include <p9_mc_scom_addresses_fld.H>

#include <generic/memory/lib/utils/scom.H>
#include <lib/fir/fir.H>
#include <lib/fir/check.H>
#include <lib/utils/assert_noexit.H>
#include <generic/memory/lib/utils/find.H>

using fapi2::TARGET_TYPE_MCBIST;
using fapi2::TARGET_TYPE_MCA;

namespace mss
{

namespace check
{

///
/// @brief A small, local, class to hold some of the FFDC information we need from the ports
///
struct fir_ffdc
{
    ///
    /// @brief fir_ffdc ctor
    /// @param[in] the MCA target the FFDC was collected from
    /// @param[in] the cal FIR information
    /// @param[in] the phy FIR information
    ///
    fir_ffdc( const fapi2::Target<TARGET_TYPE_MCA>& i_target, const uint64_t i_calfir, const uint64_t i_phyfir ):
        iv_target(i_target),
        iv_calfir(i_calfir),
        iv_phyfir(i_phyfir)
    {}

    ~fir_ffdc() = default;
    fir_ffdc() = delete;

    fapi2::Target<TARGET_TYPE_MCA> iv_target;
    uint64_t iv_calfir;
    uint64_t iv_phyfir;
};

///
/// @brief Check FIR bits during PHY reset
/// @note For DDRPHYFIR and some MBACALFIR errors, up to and including phy reset, need to
/// handle within the phy reset procedure, since we may get errors from a 'non-functional'
/// magic port, which PRD can't analyze.
/// @param[in] i_target the fapi2::Target MCBIST
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS iff ok
///
template<>
fapi2::ReturnCode during_phy_reset( const fapi2::Target<TARGET_TYPE_MCBIST>& i_target )
{
    // Save off the current current_err
    fapi2::ReturnCode l_current_err(fapi2::current_err);

    // Error path: if we hit error before FIR check (we can see that in current_err), and FIR check also
    // finds something, commit first error and exit phy reset with new error from FIR check
    // If bit on, call out MCA with deconfig and gard, including DDRPHYFIR and MBACALFIR in FFDC
    // Do FIR check on all ports, so we can log errors from multiple ports that happen to have FIR bits on

    // Create a mask from the bits Marc wants us to check
    fapi2::buffer<uint64_t> l_calfir_mask;
    l_calfir_mask.setBit<MCA_MBACALFIRQ_MBA_RECOVERABLE_ERROR>()
    .setBit<MCA_MBACALFIRQ_MBA_NONRECOVERABLE_ERROR>()
    .setBit<MCA_MBACALFIRQ_SM_1HOT_ERR>();

    fapi2::buffer<uint64_t> l_phyfir_mask;
    l_phyfir_mask.setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_0>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_1>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_2>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_3>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_4>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_5>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_6>()
    .setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_7>();

    // Go grab the MCA_MBACALFIRQ for each port. We only save off some of the FFDC information for the ports which
    // have FIR set. This allows us to 1) see if we have any thing to do (empty vector means we don't) and 2) gives us
    // all the information we need to log all the proper errors.
    std::vector< fir_ffdc> l_fir_ffdc;

    for (const auto& p : mss::find_targets_with_magic<TARGET_TYPE_MCA>(i_target))
    {
        fapi2::buffer<uint64_t> l_calfir_data;
        fapi2::buffer<uint64_t> l_phyfir_data;
        fapi2::buffer<uint64_t> l_calfir_masked;
        fapi2::buffer<uint64_t> l_phyfir_masked;

        FAPI_TRY( mss::getScom(p, MCA_MBACALFIRQ, l_calfir_data) );
        FAPI_TRY( mss::getScom(p, MCA_IOM_PHY0_DDRPHY_FIR_REG, l_phyfir_data) );

        l_calfir_masked = l_calfir_data & l_calfir_mask;
        l_phyfir_masked = l_phyfir_data & l_phyfir_mask;

        // If either has set bits we make a little record in the vector
        if ((l_calfir_masked != 0) || (l_phyfir_masked != 0))
        {
            l_fir_ffdc.push_back( fir_ffdc(p, l_calfir_data, l_phyfir_data) );
        }

        // Clear the FIR
        FAPI_TRY( mss::putScom(p, MCA_MBACALFIRQ_AND, l_calfir_masked.invert()) );
        FAPI_TRY( mss::putScom(p, MCA_IOM_PHY0_DDRPHY_FIR_REG_AND, l_phyfir_masked.invert()) );
    }

    FAPI_INF("seeing FIRs set on %d ports", l_fir_ffdc.size());

    // Ok, we know if l_fir_ffdc is empty that we had no FIR bits set. In this case we just return fapi2::current_err
    // as it represents the error state of our caller. If there were no errors seen by the caller, this will be
    // SUCCESS, and our caller will return SUCCESS. If there was an error, we don't disturb it, we just return
    // is so the caller can pass it back to it's caller (if there are FIR we'll disrupt current_err ...)
    if (l_fir_ffdc.size() == 0)
    {
        return l_current_err;
    }

    // Ok so if we're here we have FIR bits set. Not sure it matters what they are, we're returning them in the FFDC
    // and calling out/deconfig the port. First thing we do is commit whatever was in fapi2::current_err, if it's not
    // success.
    if (l_current_err != fapi2::FAPI2_RC_SUCCESS)
    {
        fapi2::logError(l_current_err);
    }

    // Now log all the errors which represent all the errors found from the ports.
    for (const fir_ffdc& f : l_fir_ffdc)
    {
        MSS_ASSERT_NOEXIT(false,
                          fapi2::MSS_DDR_PHY_RESET_PORT_FIR()
                          .set_CAL_FIR(f.iv_calfir)
                          .set_PHY_FIR(f.iv_phyfir)
                          .set_MCA_TARGET(f.iv_target),
                          "Reporting FIR bits set for %s (cal: 0x%016lx phy: 0x%016lx",
                          mss::c_str(f.iv_target), f.iv_calfir, f.iv_phyfir);
    }

    // The last thing we want to do is to create a new error code noting there were FIR set for any of the ports
    // during PHY reset and pass that back so it goes upstream. This will jump right to the label ...
    FAPI_ASSERT(false, fapi2::MSS_DDR_PHY_RESET_PORT_FIRS_REPORTED().set_MCBIST_TARGET(i_target));

fapi_try_exit:
    return fapi2::current_err;
}

///
/// @brief Check FIR bits during draminit training
/// @param[in] i_target the dimm that was trained
/// @note We check for fir errors after training each rank
/// to see if there was a problem with the engine.
/// FFDC errors returned from this will be handled similar to other training errors:
/// Logged as informational if it affects less than a nibble and a bit.
/// Reported if it affects more than that
/// @return fapi2::ReturnCode FAPI2_RC_SUCCESS iff ok
///
template<>
fapi2::ReturnCode during_draminit_training( const fapi2::Target<fapi2::TARGET_TYPE_DIMM>& i_target)
{
    const auto& l_mca = mss::find_target<fapi2::TARGET_TYPE_MCA>(i_target);

    // Creating a mask to check for FIR errors.
    // These are DP16 parity errors that would be triggered in case of an init cal error
    // During draminit_training, this would mean a training error dealing with the PHY
    fapi2::buffer<uint64_t> l_phyfir_mask;
    l_phyfir_mask.setBit<MCA_IOM_PHY0_DDRPHY_FIR_REG_ERROR_2>();

    fapi2::buffer<uint64_t> l_phyfir_data;
    fapi2::buffer<uint64_t> l_phyfir_masked;

    FAPI_TRY( mss::getScom(l_mca, MCA_IOM_PHY0_DDRPHY_FIR_REG, l_phyfir_data) );

    l_phyfir_masked = l_phyfir_data & l_phyfir_mask;

    // Clear the PHY FIR ERROR 2 bit so we don't keep failing training and training advance on this port
    // We'll have the error log to know what fir bit triggered and when, so we should be fine clearing here
    FAPI_TRY( mss::putScom(l_mca, MCA_IOM_PHY0_DDRPHY_FIR_REG_AND, l_phyfir_mask.invert()) );

    FAPI_ASSERT( l_phyfir_masked == 0,
                 fapi2::MSS_DRAMINIT_TRAINING_PORT_FIR()
                 .set_PHY_FIR(l_phyfir_masked)
                 .set_DIMM_TARGET(i_target)
                 .set_MCA_TARGET(l_mca),
                 "Initial CAL failed: Reporting FIR bits set for %s ( phy: 0x%016lx",
                 mss::c_str(i_target), l_phyfir_masked);

fapi_try_exit:
    return fapi2::current_err;
}

}
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: idxmrk.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: os $ $Date: 2002-10-15 11:57:37 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef _IDXMRK_HXX
#define _IDXMRK_HXX

#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _BASEDLGS_HXX
#include <sfx2/basedlgs.hxx>
#endif

#ifndef _FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif

#ifndef _SV_LSTBOX_HXX
#include <vcl/lstbox.hxx>
#endif
#ifndef _COMBOBOX_HXX //autogen
#include <vcl/combobox.hxx>
#endif
#ifndef _SVX_STDDLG_HXX
#include <svx/stddlg.hxx>
#endif

#ifndef _FIELD_HXX //autogen
#include <vcl/field.hxx>
#endif

#ifndef _GROUP_HXX //autogen
#include <vcl/group.hxx>
#endif

#ifndef _BUTTON_HXX //autogen
#include <vcl/button.hxx>
#endif

#ifndef _IMAGEBTN_HXX //autogen
#include <vcl/imagebtn.hxx>
#endif
#ifndef _SFX_CHILDWIN_HXX //autogen
#include <sfx2/childwin.hxx>
#endif
#ifndef _TOXE_HXX
#include "toxe.hxx"
#endif
#ifndef _STDCTRL_HXX
#include <svtools/stdctrl.hxx>
#endif
#ifndef  _COM_SUN_STAR_I18N_XEXTENDEDINDEXENTRYSUPPLIER_HPP_
#include <drafts/com/sun/star/i18n/XExtendedIndexEntrySupplier.hpp>
#endif
class SwWrtShell;
class SwTOXMgr;
class SwTOXMark;
/*--------------------------------------------------------------------
     Beschreibung:  Markierung fuer Verzeichniseintrag einfuegen
 --------------------------------------------------------------------*/
class SwIndexMarkFloatDlg;
class SwIndexMarkModalDlg;
class SwIndexMarkDlg : public Window //SvxStandardDialog
{
    friend class SwIndexMarkFloatDlg;
    friend class SwIndexMarkModalDlg;
    FixedText       aTypeFT;
    ListBox         aTypeDCB;
    ImageButton     aNewBT;

    FixedText       aEntryFT;
    Edit            aEntryED;
    FixedText       aPhoneticFT0;
    Edit            aPhoneticED0;

    FixedText       aKeyFT;
    ComboBox        aKeyDCB;
    FixedText       aPhoneticFT1;
    Edit            aPhoneticED1;

    FixedText       aKey2FT;
    ComboBox        aKey2DCB;
    FixedText       aPhoneticFT2;
    Edit            aPhoneticED2;

    FixedText       aLevelFT;
    NumericField    aLevelED;
     CheckBox       aMainEntryCB;
     CheckBox       aApplyToAllCB;
     CheckBox       aSearchCaseSensitiveCB;
     CheckBox       aSearchCaseWordOnlyCB;

    FixedLine       aIndexFL;

    OKButton        aOKBT;
    CancelButton    aCancelBT;
    HelpButton      aHelpBT;
    PushButton      aDelBT;
    //PushButton        aNewBT;

    ImageButton     aPrevSameBT;
    ImageButton     aNextSameBT;
    ImageButton     aPrevBT;
    ImageButton     aNextBT;

    String          aOrgStr;
    sal_Bool            bDel;
    sal_Bool            bNewMark;
    sal_Bool            bSelected;

    BOOL            bPhoneticED0_ChangedByUser;
    BOOL            bPhoneticED1_ChangedByUser;
    BOOL            bPhoneticED2_ChangedByUser;
    LanguageType    nLangForPhoneticReading; //Language of current text used for phonetic reading proposal
    BOOL            bIsPhoneticReadingEnabled; //this value states wether phopentic reading is enabled in principle dependend of global cjk settings and language of current entry
    com::sun::star::uno::Reference< drafts::com::sun::star::i18n::XExtendedIndexEntrySupplier >
                    xExtendedIndexEntrySupplier;

    SwTOXMgr*       pTOXMgr;
    SwWrtShell*     pSh;

    void            Apply();
    void            InitControls();
    void            InsertMark();
    void            UpdateMark();

    DECL_LINK( InsertHdl, Button * );
    DECL_LINK( CloseHdl, Button * );
    DECL_LINK( DelHdl, Button * );
    DECL_LINK( NextHdl, Button * );
    DECL_LINK( NextSameHdl, Button * );
    DECL_LINK( PrevHdl, Button * );
    DECL_LINK( PrevSameHdl, Button * );
    DECL_LINK( ModifyHdl, ListBox* pBox = 0 );
    DECL_LINK( KeyDCBModifyHdl, ComboBox * );
    DECL_LINK( NewUserIdxHdl, Button*);
    DECL_LINK( SearchTypeHdl, CheckBox*);
    DECL_LINK( PhoneticEDModifyHdl, Edit * );

    //this method updates the values from 'nLangForPhoneticReading' and 'bIsPhoneticReadingEnabled'
    //it needs to be called ones if this dialog is opened to create a new entry (in InitControls),
    //or otherwise it has to be called for each changed TOXMark (in UpdateDialog)
    void            UpdateLanguageDependenciesForPhoneticReading();
    String          GetDefaultPhoneticReading( const String& rText );

    void            UpdateKeyBoxes();

    void            UpdateDialog();
    void            InsertUpdate();

    virtual void    Activate();

public:

    SwIndexMarkDlg( Window *pParent,
                       sal_Bool bNewDlg,
                    const ResId& rResId);

    ~SwIndexMarkDlg();

    void    ReInitDlg(SwWrtShell& rWrtShell, SwTOXMark* pCurTOXMark = 0);
    sal_Bool    IsTOXType(const String& rName)
                {return LISTBOX_ENTRY_NOTFOUND != aTypeDCB.GetEntryPos(rName);}
};
/* -----------------06.10.99 10:11-------------------

 --------------------------------------------------*/
class SwIndexMarkFloatDlg : public SfxModelessDialog
{
    SwIndexMarkDlg      aDlg;
    virtual void    Activate();
    public:
        SwIndexMarkFloatDlg(    SfxBindings* pBindings,
                                   SfxChildWindow* pChild,
                                   Window *pParent,
                                   sal_Bool bNew=sal_True);

        SwIndexMarkDlg&     GetDlg() {return aDlg;}
};
/* -----------------06.10.99 10:33-------------------

 --------------------------------------------------*/
class SwIndexMarkModalDlg : public SvxStandardDialog
{
    SwIndexMarkDlg      aDlg;
public:
    SwIndexMarkModalDlg(Window *pParent, SwWrtShell& rSh, SwTOXMark* pCurTOXMark);

    SwIndexMarkDlg&     GetDlg() {return aDlg;}
    virtual void        Apply();
};

/* -----------------07.09.99 08:02-------------------

 --------------------------------------------------*/
class SwInsertIdxMarkWrapper : public SfxChildWindow
{
protected:
    SwInsertIdxMarkWrapper( Window *pParentWindow,
                            sal_uInt16 nId,
                            SfxBindings* pBindings,
                            SfxChildWinInfo* pInfo );

    SFX_DECL_CHILDWINDOW(SwInsertIdxMarkWrapper);

public:
    void    ReInitDlg(SwWrtShell& rWrtShell)
        {((SwIndexMarkFloatDlg*)pWindow)->GetDlg().ReInitDlg(rWrtShell);}

};

/* -----------------15.09.99 08:39-------------------

 --------------------------------------------------*/
class SwAuthMarkModalDlg;
class SwAuthMarkDlg : public Window
{
    static sal_Bool     bIsFromComponent;

    friend class SwAuthMarkModalDlg;
    friend class SwAuthMarkFloatDlg;

    RadioButton     aFromComponentRB;
    RadioButton     aFromDocContentRB;
    FixedText       aAuthorFT;
    FixedInfo       aAuthorFI;
    FixedText       aTitleFT;
    FixedInfo       aTitleFI;
    FixedText       aEntryFT;
    Edit            aEntryED;
    ListBox         aEntryLB;

    FixedLine       aEntryFL;

    OKButton        aOKBT;
    CancelButton    aCancelBT;
    HelpButton      aHelpBT;
    PushButton      aCreateEntryPB;
    PushButton      aEditEntryPB;

    String          sChangeST;
    sal_Bool            bNewEntry;
    sal_Bool            bBibAccessInitialized;

    SwWrtShell*     pSh;

    String          m_sColumnTitles[AUTH_FIELD_END];
    String          m_sFields[AUTH_FIELD_END];

    String          m_sCreatedEntry[AUTH_FIELD_END];

    ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >    xBibAccess;

    DECL_LINK(InsertHdl, PushButton*);
    DECL_LINK(CloseHdl, PushButton*);
    DECL_LINK(CreateEntryHdl, PushButton*);
    DECL_LINK(CompEntryHdl, ListBox*);
    DECL_LINK(ChangeSourceHdl, RadioButton*);
    DECL_LINK(IsEntryAllowedHdl, Edit*);
    DECL_LINK(EditModifyHdl, Edit*);

    void InitControls();
    virtual void    Activate();
public:

    SwAuthMarkDlg( Window *pParent,
                    const ResId& rResId,
                       sal_Bool bNew=sal_True);
    ~SwAuthMarkDlg();

    void    ReInitDlg(SwWrtShell& rWrtShell);
};
/* -----------------07.09.99 08:02-------------------

 --------------------------------------------------*/
class SwInsertAuthMarkWrapper : public SfxChildWindow
{
protected:
    SwInsertAuthMarkWrapper(    Window *pParentWindow,
                            sal_uInt16 nId,
                            SfxBindings* pBindings,
                            SfxChildWinInfo* pInfo );

    SFX_DECL_CHILDWINDOW(SwInsertAuthMarkWrapper);

public:
    void    ReInitDlg(SwWrtShell& rWrtShell);
};
/* -----------------06.10.99 10:11-------------------

 --------------------------------------------------*/
class SwAuthMarkFloatDlg : public SfxModelessDialog
{
    SwAuthMarkDlg       aDlg;
    virtual void    Activate();
    public:
        SwAuthMarkFloatDlg(     SfxBindings* pBindings,
                                   SfxChildWindow* pChild,
                                   Window *pParent,
                                   sal_Bool bNew=sal_True);

        SwAuthMarkDlg&      GetDlg() {return aDlg;}
};
/* -----------------06.10.99 10:33-------------------

 --------------------------------------------------*/
class SwAuthMarkModalDlg : public SvxStandardDialog
{
    SwAuthMarkDlg       aDlg;
public:
    SwAuthMarkModalDlg(Window *pParent, SwWrtShell& rSh);

    SwAuthMarkDlg&      GetDlg() {return aDlg;}
    virtual void        Apply();
};

#endif // _IDXMRK_HXX

<commit_msg>INTEGRATION: CWS os7 (1.7.130); FILE MERGED 2003/03/27 12:12:07 gt 1.7.130.1: #107750#<commit_after>/*************************************************************************
 *
 *  $RCSfile: idxmrk.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: hr $ $Date: 2003-04-04 18:16:13 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (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.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef _IDXMRK_HXX
#define _IDXMRK_HXX

#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _BASEDLGS_HXX
#include <sfx2/basedlgs.hxx>
#endif

#ifndef _FIXED_HXX //autogen
#include <vcl/fixed.hxx>
#endif

#ifndef _SV_LSTBOX_HXX
#include <vcl/lstbox.hxx>
#endif
#ifndef _COMBOBOX_HXX //autogen
#include <vcl/combobox.hxx>
#endif
#ifndef _SVX_STDDLG_HXX
#include <svx/stddlg.hxx>
#endif

#ifndef _FIELD_HXX //autogen
#include <vcl/field.hxx>
#endif

#ifndef _GROUP_HXX //autogen
#include <vcl/group.hxx>
#endif

#ifndef _BUTTON_HXX //autogen
#include <vcl/button.hxx>
#endif

#ifndef _IMAGEBTN_HXX //autogen
#include <vcl/imagebtn.hxx>
#endif
#ifndef _SFX_CHILDWIN_HXX //autogen
#include <sfx2/childwin.hxx>
#endif
#ifndef _TOXE_HXX
#include "toxe.hxx"
#endif
#ifndef _STDCTRL_HXX
#include <svtools/stdctrl.hxx>
#endif
#ifndef  _COM_SUN_STAR_I18N_XEXTENDEDINDEXENTRYSUPPLIER_HPP_
#include <drafts/com/sun/star/i18n/XExtendedIndexEntrySupplier.hpp>
#endif
class SwWrtShell;
class SwTOXMgr;
class SwTOXMark;
/*--------------------------------------------------------------------
     Beschreibung:  Markierung fuer Verzeichniseintrag einfuegen
 --------------------------------------------------------------------*/
class SwIndexMarkFloatDlg;
class SwIndexMarkModalDlg;
class SwIndexMarkDlg : public Window //SvxStandardDialog
{
    friend class SwIndexMarkFloatDlg;
    friend class SwIndexMarkModalDlg;
    FixedText       aTypeFT;
    ListBox         aTypeDCB;
    ImageButton     aNewBT;

    FixedText       aEntryFT;
    Edit            aEntryED;
    FixedText       aPhoneticFT0;
    Edit            aPhoneticED0;

    FixedText       aKeyFT;
    ComboBox        aKeyDCB;
    FixedText       aPhoneticFT1;
    Edit            aPhoneticED1;

    FixedText       aKey2FT;
    ComboBox        aKey2DCB;
    FixedText       aPhoneticFT2;
    Edit            aPhoneticED2;

    FixedText       aLevelFT;
    NumericField    aLevelED;
     CheckBox       aMainEntryCB;
     CheckBox       aApplyToAllCB;
     CheckBox       aSearchCaseSensitiveCB;
     CheckBox       aSearchCaseWordOnlyCB;

    FixedLine       aIndexFL;

    OKButton        aOKBT;
    CancelButton    aCancelBT;
    HelpButton      aHelpBT;
    PushButton      aDelBT;
    //PushButton        aNewBT;

    ImageButton     aPrevSameBT;
    ImageButton     aNextSameBT;
    ImageButton     aPrevBT;
    ImageButton     aNextBT;

    String          aOrgStr;
    sal_Int32       nOptionsId;
    sal_Bool            bDel;
    sal_Bool            bNewMark;
    sal_Bool            bSelected;

    BOOL            bPhoneticED0_ChangedByUser;
    BOOL            bPhoneticED1_ChangedByUser;
    BOOL            bPhoneticED2_ChangedByUser;
    LanguageType    nLangForPhoneticReading; //Language of current text used for phonetic reading proposal
    BOOL            bIsPhoneticReadingEnabled; //this value states wether phopentic reading is enabled in principle dependend of global cjk settings and language of current entry
    com::sun::star::uno::Reference< drafts::com::sun::star::i18n::XExtendedIndexEntrySupplier >
                    xExtendedIndexEntrySupplier;

    SwTOXMgr*       pTOXMgr;
    SwWrtShell*     pSh;

    void            Apply();
    void            InitControls();
    void            InsertMark();
    void            UpdateMark();

    DECL_LINK( InsertHdl, Button * );
    DECL_LINK( CloseHdl, Button * );
    DECL_LINK( DelHdl, Button * );
    DECL_LINK( NextHdl, Button * );
    DECL_LINK( NextSameHdl, Button * );
    DECL_LINK( PrevHdl, Button * );
    DECL_LINK( PrevSameHdl, Button * );
    DECL_LINK( ModifyHdl, ListBox* pBox = 0 );
    DECL_LINK( KeyDCBModifyHdl, ComboBox * );
    DECL_LINK( NewUserIdxHdl, Button*);
    DECL_LINK( SearchTypeHdl, CheckBox*);
    DECL_LINK( PhoneticEDModifyHdl, Edit * );

    //this method updates the values from 'nLangForPhoneticReading' and 'bIsPhoneticReadingEnabled'
    //it needs to be called ones if this dialog is opened to create a new entry (in InitControls),
    //or otherwise it has to be called for each changed TOXMark (in UpdateDialog)
    void            UpdateLanguageDependenciesForPhoneticReading();
    String          GetDefaultPhoneticReading( const String& rText );

    void            UpdateKeyBoxes();

    void            UpdateDialog();
    void            InsertUpdate();

    virtual void    Activate();

public:

    SwIndexMarkDlg( Window *pParent,
                       sal_Bool bNewDlg,
                    const ResId& rResId,
                    sal_Int32 _nOptionsId );

    ~SwIndexMarkDlg();

    void    ReInitDlg(SwWrtShell& rWrtShell, SwTOXMark* pCurTOXMark = 0);
    sal_Bool    IsTOXType(const String& rName)
                {return LISTBOX_ENTRY_NOTFOUND != aTypeDCB.GetEntryPos(rName);}
};
/* -----------------06.10.99 10:11-------------------

 --------------------------------------------------*/
class SwIndexMarkFloatDlg : public SfxModelessDialog
{
    SwIndexMarkDlg      aDlg;
    virtual void    Activate();
    public:
        SwIndexMarkFloatDlg(    SfxBindings* pBindings,
                                   SfxChildWindow* pChild,
                                   Window *pParent,
                                   sal_Bool bNew=sal_True);

        SwIndexMarkDlg&     GetDlg() {return aDlg;}
};
/* -----------------06.10.99 10:33-------------------

 --------------------------------------------------*/
class SwIndexMarkModalDlg : public SvxStandardDialog
{
    SwIndexMarkDlg      aDlg;
public:
    SwIndexMarkModalDlg(Window *pParent, SwWrtShell& rSh, SwTOXMark* pCurTOXMark);

    SwIndexMarkDlg&     GetDlg() {return aDlg;}
    virtual void        Apply();
};

/* -----------------07.09.99 08:02-------------------

 --------------------------------------------------*/
class SwInsertIdxMarkWrapper : public SfxChildWindow
{
protected:
    SwInsertIdxMarkWrapper( Window *pParentWindow,
                            sal_uInt16 nId,
                            SfxBindings* pBindings,
                            SfxChildWinInfo* pInfo );

    SFX_DECL_CHILDWINDOW(SwInsertIdxMarkWrapper);

public:
    void    ReInitDlg(SwWrtShell& rWrtShell)
        {((SwIndexMarkFloatDlg*)pWindow)->GetDlg().ReInitDlg(rWrtShell);}

};

/* -----------------15.09.99 08:39-------------------

 --------------------------------------------------*/
class SwAuthMarkModalDlg;
class SwAuthMarkDlg : public Window
{
    static sal_Bool     bIsFromComponent;

    friend class SwAuthMarkModalDlg;
    friend class SwAuthMarkFloatDlg;

    RadioButton     aFromComponentRB;
    RadioButton     aFromDocContentRB;
    FixedText       aAuthorFT;
    FixedInfo       aAuthorFI;
    FixedText       aTitleFT;
    FixedInfo       aTitleFI;
    FixedText       aEntryFT;
    Edit            aEntryED;
    ListBox         aEntryLB;

    FixedLine       aEntryFL;

    OKButton        aOKBT;
    CancelButton    aCancelBT;
    HelpButton      aHelpBT;
    PushButton      aCreateEntryPB;
    PushButton      aEditEntryPB;

    String          sChangeST;
    sal_Bool            bNewEntry;
    sal_Bool            bBibAccessInitialized;

    SwWrtShell*     pSh;

    String          m_sColumnTitles[AUTH_FIELD_END];
    String          m_sFields[AUTH_FIELD_END];

    String          m_sCreatedEntry[AUTH_FIELD_END];

    ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >    xBibAccess;

    DECL_LINK(InsertHdl, PushButton*);
    DECL_LINK(CloseHdl, PushButton*);
    DECL_LINK(CreateEntryHdl, PushButton*);
    DECL_LINK(CompEntryHdl, ListBox*);
    DECL_LINK(ChangeSourceHdl, RadioButton*);
    DECL_LINK(IsEntryAllowedHdl, Edit*);
    DECL_LINK(EditModifyHdl, Edit*);

    void InitControls();
    virtual void    Activate();
public:

    SwAuthMarkDlg( Window *pParent,
                    const ResId& rResId,
                       sal_Bool bNew=sal_True);
    ~SwAuthMarkDlg();

    void    ReInitDlg(SwWrtShell& rWrtShell);
};
/* -----------------07.09.99 08:02-------------------

 --------------------------------------------------*/
class SwInsertAuthMarkWrapper : public SfxChildWindow
{
protected:
    SwInsertAuthMarkWrapper(    Window *pParentWindow,
                            sal_uInt16 nId,
                            SfxBindings* pBindings,
                            SfxChildWinInfo* pInfo );

    SFX_DECL_CHILDWINDOW(SwInsertAuthMarkWrapper);

public:
    void    ReInitDlg(SwWrtShell& rWrtShell);
};
/* -----------------06.10.99 10:11-------------------

 --------------------------------------------------*/
class SwAuthMarkFloatDlg : public SfxModelessDialog
{
    SwAuthMarkDlg       aDlg;
    virtual void    Activate();
    public:
        SwAuthMarkFloatDlg(     SfxBindings* pBindings,
                                   SfxChildWindow* pChild,
                                   Window *pParent,
                                   sal_Bool bNew=sal_True);

        SwAuthMarkDlg&      GetDlg() {return aDlg;}
};
/* -----------------06.10.99 10:33-------------------

 --------------------------------------------------*/
class SwAuthMarkModalDlg : public SvxStandardDialog
{
    SwAuthMarkDlg       aDlg;
public:
    SwAuthMarkModalDlg(Window *pParent, SwWrtShell& rSh);

    SwAuthMarkDlg&      GetDlg() {return aDlg;}
    virtual void        Apply();
};

#endif // _IDXMRK_HXX

<|endoftext|>


<commit_before>/*

Copyright (c) 2011, Arvid Norberg
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

*/

#include "libtorrent/file.hpp"
#include "libtorrent/io.hpp"
#include <cstring>
#include <boost/bind.hpp>
#include <stdlib.h>
#include <map>

using namespace libtorrent;
using namespace libtorrent::detail; // for write_* and read_*

void print_usage()
{
	fprintf(stderr, "usage: parse_access_log log-file data-file\n\n"
		"prints a gnuplot readable data file to stdout\n");
	exit(1);
}

struct file_op
{
	boost::uint64_t timestamp;
	boost::uint64_t offset;
	boost::uint8_t event;
};

int main(int argc, char* argv[])
{
	if (argc != 3) print_usage();

	FILE* log_file = fopen(argv[1], "r");
	if (log_file == 0)
	{
		fprintf(stderr, "failed to open logfile: %s\n%d: %s\n"
			, argv[1], errno, strerror(errno));
		return 1;
	}

	FILE* writes_file = fopen("writes.log", "w+");
	FILE* reads_file = fopen("reads.log", "w+");

	FILE* writes_elev_file = fopen("writes_elevator.log", "w+");
	FILE* reads_elev_file = fopen("reads_elevator.log", "w+");

	// TODO: in order to generalize this, the filenames need to be
	// saved in the log itself

	error_code ec;
	file data_file(argv[2], file::read_only, ec);
	if (ec)
	{
		fprintf(stderr, "failed to open data file: %s\n", ec.message().c_str());
		return 1;
	}

	typedef std::map<boost::uint32_t, file_op> op_map;
	op_map outstanding_ops;

	boost::uint64_t first_timestamp = 0;

	for (;;)
	{
		char entry[29];
		char* ptr = entry;
		int ret = fread(&entry, 1, sizeof(entry), log_file);
		if (ret != sizeof(entry)) break;

		file_op op;
		op.timestamp = read_uint64(ptr);
		op.offset = read_uint64(ptr);
		boost::uint32_t event_id = read_uint32(ptr);
		op.event = read_uint8(ptr);

		if (first_timestamp == 0) first_timestamp = op.timestamp;

		bool write = op.event & 1;
		bool complete = op.event & 2;
		FILE* out_file = 0;
		if (complete)
		{
			op_map::iterator i = outstanding_ops.find(event_id);
			if (i != outstanding_ops.end())
			{
				if (i->second.timestamp > op.timestamp)
				{
					fprintf(stderr, "end-event stamped before "
						"start-event: %"PRId64" started at: %f\n"
						, op.offset, double(i->second.timestamp) / 1000000.f);
					i->second.timestamp = op.timestamp;
				}

				out_file = write ? writes_file : reads_file;
				double start_time = double(i->second.timestamp - first_timestamp) / 1000000.0;
				double end_time = double(op.timestamp - first_timestamp) / 1000000.0;
				double duration_time = double(op.timestamp - i->second.timestamp) / 1000000.0;
				fprintf(out_file, "%f\t%"PRId64"\t%f\n"
					, start_time, op.offset, duration_time);

				out_file = write ? writes_elev_file : reads_elev_file;
				fprintf(out_file, "%f\t%"PRId64"\n", end_time, op.offset);

				outstanding_ops.erase(i);
			}
			else
			{
				fprintf(stderr, "no start event for (%u): %"PRId64" ended at: %f\n"
					, event_id, op.offset, double(op.timestamp) / 1000000.f);
			}
		}
		else
		{
			op_map::iterator i = outstanding_ops.find(event_id);
			if (i != outstanding_ops.end())
			{
				fprintf(stderr, "duplicate start event for (%u): %"PRId64" at: %f"
					"(current start is at: %f)\n"
					, event_id, op.offset, double(i->second.timestamp - first_timestamp) / 1000000.f
					, double(op.timestamp - first_timestamp) / 1000000.f);
			}
			else
			{
				outstanding_ops[event_id] = op;
			}
		}
	}

	fclose(writes_file);
	fclose(reads_file);
	fclose(writes_elev_file);
	fclose(reads_elev_file);
	fclose(log_file);

	FILE* gnuplot = fopen("file_access.gnuplot", "w+");

	char const* gnuplot_file =
		"set term png size 1400,1024\n"
		"set output \"file_access.png\"\n"
		"set xlabel \"time (s)\"\n"
		"set ylabel \"file offset\"\n"
		"set style line 1 lc rgb \"#ff8888\"\n"
		"set style line 2 lc rgb \"#88ff88\"\n"
		"set style arrow 1 nohead ls 1\n"
		"set style arrow 2 nohead ls 2\n"
		"plot \"writes.log\" using 1:2:3:(0) title \"writes\" with vectors arrowstyle 1, "
			"\"reads.log\" using 1:2:3:(0) title \"reads\" with vectors arrowstyle 2\n";

	fwrite(gnuplot_file, strlen(gnuplot_file), 1, gnuplot);
	fclose(gnuplot);

	system("gnuplot file_access.gnuplot");

	assert(outstanding_ops.empty());

	return 0;
}

<commit_msg>fix access log parser<commit_after>/*

Copyright (c) 2011, Arvid Norberg
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

*/

#include "libtorrent/config.hpp"
#include "libtorrent/io.hpp"
#include <cstring>
#include <boost/bind.hpp>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <map>

using namespace libtorrent;
using namespace libtorrent::detail; // for write_* and read_*

void print_usage()
{
	fprintf(stderr, "usage: parse_access_log log-file\n\n"
		"prints a gnuplot readable data file to stdout\n");
	exit(1);
}

struct file_op
{
	boost::uint64_t timestamp;
	boost::uint64_t offset;
	boost::uint8_t event;
};

int main(int argc, char* argv[])
{
	if (argc != 2) print_usage();

	FILE* log_file = fopen(argv[1], "r");
	if (log_file == 0)
	{
		fprintf(stderr, "failed to open logfile: %s\n%d: %s\n"
			, argv[1], errno, strerror(errno));
		return 1;
	}

	FILE* writes_file = fopen("writes.log", "w+");
	FILE* reads_file = fopen("reads.log", "w+");

	FILE* writes_elev_file = fopen("writes_elevator.log", "w+");
	FILE* reads_elev_file = fopen("reads_elevator.log", "w+");

	typedef std::map<boost::uint32_t, file_op> op_map;
	op_map outstanding_ops;

	boost::uint64_t first_timestamp = 0;

	for (;;)
	{
		char entry[21];
		char* ptr = entry;
		int ret = fread(&entry, 1, sizeof(entry), log_file);
		if (ret != sizeof(entry)) break;

		file_op op;
		op.timestamp = read_uint64(ptr);
		op.offset = read_uint64(ptr);
		boost::uint32_t event_id = read_uint32(ptr);
		op.event = read_uint8(ptr);

		if (first_timestamp == 0) first_timestamp = op.timestamp;

		bool write = op.event & 1;
		bool complete = op.event & 2;
		FILE* out_file = 0;
		if (complete)
		{
			op_map::iterator i = outstanding_ops.find(event_id);
			if (i != outstanding_ops.end())
			{
				if (i->second.timestamp > op.timestamp)
				{
					fprintf(stderr, "end-event stamped before "
						"start-event: %"PRId64" started at: %f\n"
						, op.offset, double(i->second.timestamp) / 1000000.f);
					i->second.timestamp = op.timestamp;
				}

				out_file = write ? writes_file : reads_file;
				double start_time = double(i->second.timestamp - first_timestamp) / 1000000.0;
				double end_time = double(op.timestamp - first_timestamp) / 1000000.0;
				double duration_time = double(op.timestamp - i->second.timestamp) / 1000000.0;
				fprintf(out_file, "%f\t%"PRId64"\t%f\n"
					, start_time, op.offset, duration_time);

				out_file = write ? writes_elev_file : reads_elev_file;
				fprintf(out_file, "%f\t%"PRId64"\n", end_time, op.offset);

				outstanding_ops.erase(i);
			}
			else
			{
				fprintf(stderr, "no start event for (%u): %"PRId64" ended at: %f\n"
					, event_id, op.offset, double(op.timestamp) / 1000000.f);
			}
		}
		else
		{
			op_map::iterator i = outstanding_ops.find(event_id);
			if (i != outstanding_ops.end())
			{
				fprintf(stderr, "duplicate start event for (%u): %"PRId64" at: %f"
					"(current start is at: %f)\n"
					, event_id, op.offset, double(i->second.timestamp - first_timestamp) / 1000000.f
					, double(op.timestamp - first_timestamp) / 1000000.f);
			}
			else
			{
				outstanding_ops[event_id] = op;
			}
		}
	}

	fclose(writes_file);
	fclose(reads_file);
	fclose(writes_elev_file);
	fclose(reads_elev_file);
	fclose(log_file);

	FILE* gnuplot = fopen("file_access.gnuplot", "w+");

	char const* gnuplot_file =
		"set term png size 1400,1024\n"
		"set output \"file_access.png\"\n"
		"set xlabel \"time (s)\"\n"
		"set ylabel \"file offset\"\n"
		"set style line 1 lc rgb \"#ff8888\"\n"
		"set style line 2 lc rgb \"#88ff88\"\n"
		"set style arrow 1 nohead ls 1\n"
		"set style arrow 2 nohead ls 2\n"
		"plot \"writes.log\" using 1:2:3:(0) title \"writes\" with vectors arrowstyle 1, "
			"\"reads.log\" using 1:2:3:(0) title \"reads\" with vectors arrowstyle 2\n";

	fwrite(gnuplot_file, strlen(gnuplot_file), 1, gnuplot);
	fclose(gnuplot);

	system("gnuplot file_access.gnuplot");

	assert(outstanding_ops.empty());

	return 0;
}

<|endoftext|>


<commit_before>#include "catch.hpp"
#include <mapnik/text/icu_shaper.hpp>
#include <mapnik/text/harfbuzz_shaper.hpp>
#include <mapnik/text/font_library.hpp>
#include <mapnik/unicode.hpp>

namespace {

void test_shaping( mapnik::font_set const& fontset, mapnik::face_manager& fm,
                   std::vector<std::tuple<unsigned, unsigned>> const& expected, char const* str, bool debug = false)
{
    mapnik::transcoder tr("utf8");
    std::map<unsigned,double> width_map;
    mapnik::text_itemizer itemizer;
    auto props = std::make_unique<mapnik::detail::evaluated_format_properties>();
    props->fontset = fontset;
    props->text_size = 32;

    double scale_factor = 1;
    auto ustr = tr.transcode(str);
    auto length = ustr.length();
    itemizer.add_text(ustr, props);

    mapnik::text_line line(0, length);
    mapnik::harfbuzz_shaper::shape_text(line, itemizer,
                                        width_map,
                                        fm,
                                        scale_factor);

    std::size_t index = 0;
    for (auto const& g : line)
    {
        if (debug)
        {
            if (index++ > 0) std::cerr << ",";
            std::cerr << "{" << g.glyph_index << ", " << g.char_index
                //<< ", " << g.face->family_name() << ":" << g.face->style_name()
                      <<  "}";
        }
        else
        {
            unsigned glyph_index, char_index;
            CHECK(index < expected.size());
            std::tie(glyph_index, char_index) = expected[index++];
            REQUIRE(glyph_index == g.glyph_index);
            REQUIRE(char_index == g.char_index);
        }
    }
}
}

TEST_CASE("shaping")
{
    mapnik::freetype_engine::register_font("test/data/fonts/NotoSans-Regular.ttc");
    mapnik::freetype_engine::register_fonts("test/data/fonts/Noto");
    mapnik::font_set fontset("fontset");
    for (auto const& name : mapnik::freetype_engine::face_names())
    {
        fontset.add_face_name(name);
    }

    mapnik::font_library fl;
    mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
    mapnik::freetype_engine::font_memory_cache_type font_memory_cache;
    mapnik::face_manager fm(fl, font_file_mapping, font_memory_cache);

    {
        auto const& expected =
            {std::tuple<unsigned, unsigned>(0, 0), {0, 3}, {0, 4}, {0, 7}, {3, 8}, {11, 9}, {68, 10}, {69, 11}, {70, 12}, {12, 13}};
        // with default NotoSans-Regular.ttc and NotoNaskhArabic-Regular.ttf ^^^
        //std::vector<std::pair<unsigned, unsigned>> expected =
        //  {{977,0}, {1094,3}, {1038,4}, {1168,4}, {9,7}, {3,8}, {11,9}, {68,10}, {69,11}, {70,12}, {12,13}};
        // expected results if "NotoSansTibetan-Regular.ttf is registered^^
        test_shaping(fontset, fm, expected, u8"སྤུ་ཧྲེང (abc)");
    }

    {
        auto const& expected =
            {std::tuple<unsigned, unsigned>(0, 0), {0, 3}, {0, 4}, {0, 7}, {3, 8}, {11, 9}, {0, 10}, {0, 11}, {0, 12}, {12, 13}};
        test_shaping(fontset, fm, expected, u8"སྤུ་ཧྲེང (普兰镇)");
    }

    {
        auto const& expected =
            {std::tuple<unsigned, unsigned>(68, 0), {69, 1}, {70, 2}, {3, 3}, {11, 4}, {0, 5}, {0, 6}, {0, 7}, {12, 8}};
        test_shaping(fontset, fm, expected, u8"abc (普兰镇)");
    }

    {
        auto const& expected =
            {std::tuple<unsigned, unsigned>(68, 0), {69, 1}, {70, 2}, {3, 3}, {11, 4}, {68, 5}, {69, 6}, {70, 7}, {12, 8}};
        test_shaping(fontset, fm, expected, "abc (abc)");
    }

    {
        //    "ⵃⴰⵢ ⵚⵉⵏⴰⵄⵉ الحي الصناعي"
        auto const& expected =
            {std::tuple<unsigned, unsigned>(0, 0), {0, 1}, {0, 2}, {3, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7},
              {0, 8}, {0, 9}, {3, 10}, {509, 22}, {481, 21}, {438, 20}, {503, 19},
              {470, 18}, {496, 17}, {43, 16}, {3, 15}, {509, 14}, {454, 13}, {496, 12}, {43, 11}};
        test_shaping(fontset, fm, expected, u8"ⵃⴰⵢ ⵚⵉⵏⴰⵄⵉ الحي الصناعي");
    }

}
<commit_msg>one more time.<commit_after>#include "catch.hpp"
#include <mapnik/text/icu_shaper.hpp>
#include <mapnik/text/harfbuzz_shaper.hpp>
#include <mapnik/text/font_library.hpp>
#include <mapnik/unicode.hpp>

namespace {

void test_shaping( mapnik::font_set const& fontset, mapnik::face_manager& fm,
                   std::vector<std::tuple<unsigned, unsigned>> expected,
                   char const* str, bool debug = false)
{
    mapnik::transcoder tr("utf8");
    std::map<unsigned,double> width_map;
    mapnik::text_itemizer itemizer;
    auto props = std::make_unique<mapnik::detail::evaluated_format_properties>();
    props->fontset = fontset;
    props->text_size = 32;

    double scale_factor = 1;
    auto ustr = tr.transcode(str);
    auto length = ustr.length();
    itemizer.add_text(ustr, props);

    mapnik::text_line line(0, length);
    mapnik::harfbuzz_shaper::shape_text(line, itemizer,
                                        width_map,
                                        fm,
                                        scale_factor);

    std::size_t index = 0;
    for (auto const& g : line)
    {
        if (debug)
        {
            if (index++ > 0) std::cerr << ",";
            std::cerr << "{" << g.glyph_index << ", " << g.char_index
                //<< ", " << g.face->family_name() << ":" << g.face->style_name()
                      <<  "}";
        }
        else
        {
            unsigned glyph_index, char_index;
            CHECK(index < expected.size());
            std::tie(glyph_index, char_index) = expected[index++];
            REQUIRE(glyph_index == g.glyph_index);
            REQUIRE(char_index == g.char_index);
        }
    }
}
}

TEST_CASE("shaping")
{
    mapnik::freetype_engine::register_font("test/data/fonts/NotoSans-Regular.ttc");
    mapnik::freetype_engine::register_fonts("test/data/fonts/Noto");
    mapnik::font_set fontset("fontset");
    for (auto const& name : mapnik::freetype_engine::face_names())
    {
        fontset.add_face_name(name);
    }

    mapnik::font_library fl;
    mapnik::freetype_engine::font_file_mapping_type font_file_mapping;
    mapnik::freetype_engine::font_memory_cache_type font_memory_cache;
    mapnik::face_manager fm(fl, font_file_mapping, font_memory_cache);

    {
        auto expected =
            {std::tuple<unsigned, unsigned>(0, 0), {0, 3}, {0, 4}, {0, 7}, {3, 8}, {11, 9}, {68, 10}, {69, 11}, {70, 12}, {12, 13}};
        // with default NotoSans-Regular.ttc and NotoNaskhArabic-Regular.ttf ^^^
        //std::vector<std::pair<unsigned, unsigned>> expected =
        //  {{977,0}, {1094,3}, {1038,4}, {1168,4}, {9,7}, {3,8}, {11,9}, {68,10}, {69,11}, {70,12}, {12,13}};
        // expected results if "NotoSansTibetan-Regular.ttf is registered^^
        test_shaping(fontset, fm, expected, u8"སྤུ་ཧྲེང (abc)");
    }

    {
        auto expected =
            {std::tuple<unsigned, unsigned>(0, 0), {0, 3}, {0, 4}, {0, 7}, {3, 8}, {11, 9}, {0, 10}, {0, 11}, {0, 12}, {12, 13}};
        test_shaping(fontset, fm, expected, u8"སྤུ་ཧྲེང (普兰镇)");
    }

    {
        auto expected =
            {std::tuple<unsigned, unsigned>(68, 0), {69, 1}, {70, 2}, {3, 3}, {11, 4}, {0, 5}, {0, 6}, {0, 7}, {12, 8}};
        test_shaping(fontset, fm, expected, u8"abc (普兰镇)");
    }

    {
        auto expected =
            {std::tuple<unsigned, unsigned>(68, 0), {69, 1}, {70, 2}, {3, 3}, {11, 4}, {68, 5}, {69, 6}, {70, 7}, {12, 8}};
        test_shaping(fontset, fm, expected, "abc (abc)");
    }

    {
        //    "ⵃⴰⵢ ⵚⵉⵏⴰⵄⵉ الحي الصناعي"
        auto expected =
            {std::tuple<unsigned, unsigned>(0, 0), {0, 1}, {0, 2}, {3, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7},
             {0, 8}, {0, 9}, {3, 10}, {509, 22}, {481, 21}, {438, 20}, {503, 19},
             {470, 18}, {496, 17}, {43, 16}, {3, 15}, {509, 14}, {454, 13}, {496, 12}, {43, 11}};
        test_shaping(fontset, fm, expected, u8"ⵃⴰⵢ ⵚⵉⵏⴰⵄⵉ الحي الصناعي");
    }

}
<|endoftext|>


<commit_before>//===----------------------------------------------------------------------===//
//
//                         PelotonDB
//
// mapper_lock_rows.cpp
//
// Identification: src/backend/bridge/dml/mapper/mapper_lock_rows.cpp
//
// Copyright (c) 2015, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include "backend/bridge/dml/mapper/mapper.h"

namespace peloton {
namespace bridge {

//===--------------------------------------------------------------------===//
// Seq Scan
//===--------------------------------------------------------------------===//

/**
 * @brief Convert a Postgres LockRow into a Peloton Node.
 *
 *    currently, we just ignore the lock step, and return the
 *    underlying node
 *
 * @return Pointer to the constructed AbstractPlanNode.
 *
 */
planner::AbstractPlanNode *PlanTransformer::TransformLockRows(
    const LockRowsState *lr_plan_state) {
  assert(nodeTag(lr_plan_state) == T_LockRowsState);

  LOG_INFO("Handle LockRows");

  /* get the underlying plan */
  PlanState *outer_plan_state = outerPlanState(lr_plan_state);

  TransformOptions options = kDefaultOptions;
  options.use_projInfo = false;

  return PlanTransformer::TransformPlan(outer_plan_state, options);
}

}  // namespace bridge
}  // namespace peloton
<commit_msg>fix lock row disables projection problem<commit_after>//===----------------------------------------------------------------------===//
//
//                         PelotonDB
//
// mapper_lock_rows.cpp
//
// Identification: src/backend/bridge/dml/mapper/mapper_lock_rows.cpp
//
// Copyright (c) 2015, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//

#include "backend/bridge/dml/mapper/mapper.h"

namespace peloton {
namespace bridge {

//===--------------------------------------------------------------------===//
// Seq Scan
//===--------------------------------------------------------------------===//

/**
 * @brief Convert a Postgres LockRow into a Peloton Node.
 *
 *    currently, we just ignore the lock step, and return the
 *    underlying node
 *
 * @return Pointer to the constructed AbstractPlanNode.
 *
 */
planner::AbstractPlanNode *PlanTransformer::TransformLockRows(
    const LockRowsState *lr_plan_state) {
  assert(nodeTag(lr_plan_state) == T_LockRowsState);

  LOG_INFO("Handle LockRows");

  /* get the underlying plan */
  PlanState *outer_plan_state = outerPlanState(lr_plan_state);

  return PlanTransformer::TransformPlan(outer_plan_state);
}

}  // namespace bridge
}  // namespace peloton
<|endoftext|>


<commit_before>#pragma once

#include <ostream>
#include <string>

namespace elasticsearch {

namespace utils {

namespace aux {

inline void substitute(std::ostringstream&) {}

template<typename... Args>
inline void substitute(std::ostringstream& stream,
                       const std::string& arg,
                       const Args&... args) {
    if (!arg.empty()) {
        stream << "/";

        if (arg != "/") {
            stream << arg;
        }
    }

    substitute(stream, args...);
}

} // namespace aux

template<typename... Args>
inline std::string make_path(const Args&... args) {
    std::ostringstream stream;
    aux::substitute(stream, args...);
    return stream.str();
}

} // namespace utils

} // namespace elasticsearch
<commit_msg>[Aux] Forgotten include added.<commit_after>#pragma once

#include <ostream>
#include <sstream>
#include <string>

namespace elasticsearch {

namespace utils {

namespace aux {

inline void substitute(std::ostringstream&) {}

template<typename... Args>
inline void substitute(std::ostringstream& stream,
                       const std::string& arg,
                       const Args&... args) {
    if (!arg.empty()) {
        stream << "/";

        if (arg != "/") {
            stream << arg;
        }
    }

    substitute(stream, args...);
}

} // namespace aux

template<typename... Args>
inline std::string make_path(const Args&... args) {
    std::ostringstream stream;
    aux::substitute(stream, args...);
    return stream.str();
}

} // namespace utils

} // namespace elasticsearch
<|endoftext|>


<commit_before>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: service.cxx,v $
 * $Revision: 1.5 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_extensions.hxx"

#if STLPORT_VERSION>=321
#include <cstdarg>
#endif

#include <plugin/impl.hxx>
#include <tools/debug.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/container/XSet.hpp>
#include <com/sun/star/registry/XRegistryKey.hpp>

#include <uno/dispatcher.h> // declaration of generic uno interface
#include <uno/mapping.hxx> // mapping stuff

#include <cppuhelper/factory.hxx>

using namespace cppu;

//==================================================================================================
void registerPluginService( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & xMgr )
{
    if (! xMgr.is())
        return;

    Reference< ::com::sun::star::container::XSet >  xReg( xMgr, UNO_QUERY );
    if(xReg.is())
    {
        Any aAny;
        Reference< ::com::sun::star::lang::XSingleServiceFactory >  xF;
        xF = createSingleFactory( xMgr, PluginModel::getImplementationName_Static(),

                                        PluginModel_CreateInstance,
                                        PluginModel::getSupportedServiceNames_Static() );
        aAny <<= xF;
        xReg->insert( aAny );
        xF = createSingleFactory( xMgr, XPluginManager_Impl::getImplementationName_Static(),

                                        PluginManager_CreateInstance,
                                        XPluginManager_Impl::getSupportedServiceNames_Static() );
        aAny <<= xF;
        xReg->insert( aAny );
    }
}

extern "C" {
    void SAL_CALL component_getImplementationEnvironment(
        const sal_Char** ppEnvTypeName,
        uno_Environment** /*ppEnv*/ )
    {
        *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
    }

    sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pXUnoKey )
    {
        if( pXUnoKey )
        {
            try
            {
                Reference< ::com::sun::star::registry::XRegistryKey > xKey( reinterpret_cast< ::com::sun::star::registry::XRegistryKey* >( pXUnoKey ) );

                ::rtl::OUString aImplName = ::rtl::OUString::createFromAscii( "/" );
                aImplName += XPluginManager_Impl::getImplementationName_Static();
                aImplName += ::rtl::OUString::createFromAscii( "/UNO/SERVICES/com.sun.star.plugin.PluginManager" );
                xKey->createKey( aImplName );

                aImplName = ::rtl::OUString::createFromAscii( "/" );
                aImplName += PluginModel::getImplementationName_Static();
                aImplName += ::rtl::OUString::createFromAscii( "/UNO/SERVICES/com.sun.star.plugin.PluginModel" );
                xKey->createKey( aImplName );

                return sal_True;
            }
            catch( ::com::sun::star::registry::InvalidRegistryException& )
            {
            }
        }
        return sal_False;
    }

    void* SAL_CALL component_getFactory(
        const sal_Char* pImplementationName,
        void* pXUnoSMgr,
        void* /*pXUnoKey*/
        )
    {
        void* pRet = 0;

        ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplementationName ) );

        if( pXUnoSMgr )
        {
            Reference< ::com::sun::star::lang::XMultiServiceFactory > xMgr(
                reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pXUnoSMgr )
                );
            Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory;
            if( aImplName.equals( XPluginManager_Impl::getImplementationName_Static() ) )
            {
                xFactory = ::cppu::createSingleFactory(
                    xMgr, aImplName, PluginManager_CreateInstance,
                    XPluginManager_Impl::getSupportedServiceNames_Static() );
            }
            else if( aImplName.equals( PluginModel::getImplementationName_Static() ) )
            {
                xFactory = ::cppu::createSingleFactory(
                    xMgr, aImplName, PluginModel_CreateInstance,
                    PluginModel::getSupportedServiceNames_Static() );
            }
            if( xFactory.is() )
            {
                xFactory->acquire();
                pRet = xFactory.get();
            }
        }
        return pRet;
    }

/** special registration procedure for the staroffice player */
    void SAL_CALL exService_getSmartFactory( const sal_Char* implementationName, const Reference< ::com::sun::star::lang::XMultiServiceFactory >  & rSMgr, Reference< ::com::sun::star::lang::XSingleServiceFactory > & xFactory )
    {
        ::rtl::OUString                 aImplementationName( ::rtl::OUString::createFromAscii(implementationName));

        if (aImplementationName == PluginModel::getImplementationName_Static() )

        {
            xFactory = createSingleFactory( rSMgr, aImplementationName,
                                            PluginModel_CreateInstance,
                                            PluginModel::getSupportedServiceNames_Static() );
        }
        else if (aImplementationName == XPluginManager_Impl::getImplementationName_Static() )

        {
            xFactory = createSingleFactory( rSMgr, aImplementationName,
                                            PluginManager_CreateInstance,
                                            XPluginManager_Impl::getSupportedServiceNames_Static() );
        }
    }
} /* extern "C" */
<commit_msg>INTEGRATION: CWS mba30patches01 (1.4.40); FILE MERGED 2008/04/23 10:49:05 mba 1.4.40.2: RESYNC: (1.4-1.5); FILE MERGED 2008/03/18 15:40:56 mba 1.4.40.1: #i86365#: remove unused code<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: service.cxx,v $
 * $Revision: 1.6 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_extensions.hxx"

#if STLPORT_VERSION>=321
#include <cstdarg>
#endif

#include <plugin/impl.hxx>
#include <tools/debug.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/container/XSet.hpp>
#include <com/sun/star/registry/XRegistryKey.hpp>

#include <uno/dispatcher.h> // declaration of generic uno interface
#include <uno/mapping.hxx> // mapping stuff

#include <cppuhelper/factory.hxx>

using namespace cppu;

extern "C" {
    void SAL_CALL component_getImplementationEnvironment(
        const sal_Char** ppEnvTypeName,
        uno_Environment** /*ppEnv*/ )
    {
        *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
    }

    sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pXUnoKey )
    {
        if( pXUnoKey )
        {
            try
            {
                Reference< ::com::sun::star::registry::XRegistryKey > xKey( reinterpret_cast< ::com::sun::star::registry::XRegistryKey* >( pXUnoKey ) );

                ::rtl::OUString aImplName = ::rtl::OUString::createFromAscii( "/" );
                aImplName += XPluginManager_Impl::getImplementationName_Static();
                aImplName += ::rtl::OUString::createFromAscii( "/UNO/SERVICES/com.sun.star.plugin.PluginManager" );
                xKey->createKey( aImplName );

                aImplName = ::rtl::OUString::createFromAscii( "/" );
                aImplName += PluginModel::getImplementationName_Static();
                aImplName += ::rtl::OUString::createFromAscii( "/UNO/SERVICES/com.sun.star.plugin.PluginModel" );
                xKey->createKey( aImplName );

                return sal_True;
            }
            catch( ::com::sun::star::registry::InvalidRegistryException& )
            {
            }
        }
        return sal_False;
    }

    void* SAL_CALL component_getFactory(
        const sal_Char* pImplementationName,
        void* pXUnoSMgr,
        void* /*pXUnoKey*/
        )
    {
        void* pRet = 0;

        ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplementationName ) );

        if( pXUnoSMgr )
        {
            Reference< ::com::sun::star::lang::XMultiServiceFactory > xMgr(
                reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pXUnoSMgr )
                );
            Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory;
            if( aImplName.equals( XPluginManager_Impl::getImplementationName_Static() ) )
            {
                xFactory = ::cppu::createSingleFactory(
                    xMgr, aImplName, PluginManager_CreateInstance,
                    XPluginManager_Impl::getSupportedServiceNames_Static() );
            }
            else if( aImplName.equals( PluginModel::getImplementationName_Static() ) )
            {
                xFactory = ::cppu::createSingleFactory(
                    xMgr, aImplName, PluginModel_CreateInstance,
                    PluginModel::getSupportedServiceNames_Static() );
            }
            if( xFactory.is() )
            {
                xFactory->acquire();
                pRet = xFactory.get();
            }
        }
        return pRet;
    }
} /* extern "C" */
<|endoftext|>