<commit_before>#include "painter.hpp"

#include <iostream>

// Shader sources
const GLchar* vertexSource = R"(
    #version 300 es
    in vec2 position;
    in vec2 texcoord;
    out vec2 Texcoord;
    void main() {
      Texcoord = texcoord;
      gl_Position = vec4(position, 0.0, 1.0);
    }
)";
const GLchar* fragmentSource = R"(
    #version 300 es
    precision mediump float;
    in vec2 Texcoord;
    out vec4 outColor;
    uniform sampler2D image;
    uniform mat3 H;

    void main() {
       vec3 newPos = H*vec3(Texcoord, 1.0);
       vec2 newPosNormalized = newPos.xy/newPos.z;
       if (newPosNormalized.x > 1.0 || newPosNormalized.y > 1.0 || newPosNormalized.x < 0.0 || newPosNormalized.y < 0.0)
       {
         discard;
         return;
       }
       outColor = vec4(texture(image, newPosNormalized).bgr, 1.0);
    }
)";

Painter::Painter()
{
  m_H1 = cv::Mat::eye(3, 3, CV_32FC1);
  m_H2 = cv::Mat::eye(3, 3, CV_32FC1);
}

Painter::~Painter()
{

}

void Painter::updateImage1(cv::Mat image)
{
  m_image1 = image;
}

void Painter::updateImage2(cv::Mat image)
{
  m_image2 = image;
}

void Painter::updateHomography1(cv::Mat H)
{
  m_H1 = H;
}

void Painter::updateHomography2(cv::Mat H)
{
  m_H2 = H;
}

void _check_gl_error(const char* file, int line) {
        GLenum err (glGetError());

        while(err!=GL_NO_ERROR) {
                std::string error;

                switch(err) {
                        case GL_INVALID_OPERATION:      error="INVALID_OPERATION";      break;
                        case GL_INVALID_ENUM:           error="INVALID_ENUM";           break;
                        case GL_INVALID_VALUE:          error="INVALID_VALUE";          break;
                        case GL_OUT_OF_MEMORY:          error="OUT_OF_MEMORY";          break;
                        case GL_INVALID_FRAMEBUFFER_OPERATION:  error="INVALID_FRAMEBUFFER_OPERATION";  break;
                }

                std::cerr << "GL_" << error.c_str() <<" - "<<file<<":"<<line<<std::endl;
                err=glGetError();
        }
}

#define GL_CHECK() _check_gl_error(__FILE__,__LINE__)

void Painter::setupOpenGL(int w, int h)
{
  std::lock_guard<std::mutex> lock(m_mutex);

  // Create Vertex Array Object
  GLuint vao;
  glGenVertexArrays(1, &vao);
  glBindVertexArray(vao);

  // Create a Vertex Buffer Object and copy the vertex data to it
  GLuint vbo;
  glGenBuffers(1, &vbo);

  GLfloat vertices[] = {
    // Position   Texcoords
    -1.0f,  1.0f, 0.0f, 0.0f, // Top-left
     1.0f,  1.0f, 1.0f, 0.0f, // Top-right
     1.0f, -1.0f, 1.0f, 1.0f, // Bottom-right
    -1.0f, -1.0f, 0.0f, 1.0f  // Bottom-left
  };

  glBindBuffer(GL_ARRAY_BUFFER, vbo);
  glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

  // Create an element array
  GLuint ebo;
  glGenBuffers(1, &ebo);

  GLuint elements[] = {
    0, 1, 2,
    2, 3, 0
  };

  GL_CHECK();

  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);

  // Create and compile the vertex shader
  GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
  glShaderSource(vertexShader, 1, &vertexSource, NULL);
  glCompileShader(vertexShader);

  GLint status;
  glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);

  if (status == GL_FALSE)
  {
    GLint infoLogLength;
    glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &infoLogLength);

    GLchar* strInfoLog = new GLchar[infoLogLength + 1];
    glGetShaderInfoLog(vertexShader, infoLogLength, NULL, strInfoLog);

    printf("Compilation error in shader: %s\n", strInfoLog);
    delete[] strInfoLog;
  }

  GL_CHECK();

  // Create and compile the fragment shader
  GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
  glShaderSource(fragmentShader, 1, &fragmentSource, NULL);
  glCompileShader(fragmentShader);

  glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &status);

  if (status == GL_FALSE)
  {
    GLint infoLogLength;
    glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &infoLogLength);

    GLchar* strInfoLog = new GLchar[infoLogLength + 1];
    glGetShaderInfoLog(fragmentShader, infoLogLength, NULL, strInfoLog);

    printf("Compilation error in shader: %s\n", strInfoLog);
    delete[] strInfoLog;
  }

  GL_CHECK();

  // Link the vertex and fragment shader into a shader program
  m_shaderProgram = glCreateProgram();
  glAttachShader(m_shaderProgram, vertexShader);
  glAttachShader(m_shaderProgram, fragmentShader);
  glLinkProgram(m_shaderProgram);

    GL_CHECK();

  GLint isLinked = 0;
  glGetProgramiv(m_shaderProgram, GL_LINK_STATUS, &isLinked);
  if(isLinked == GL_FALSE)
  {
    GLint maxLength = 0;
    glGetProgramiv(m_shaderProgram, GL_INFO_LOG_LENGTH, &maxLength);

    //The maxLength includes the NULL character
    std::vector<GLchar> infoLog(maxLength);
    glGetProgramInfoLog(m_shaderProgram, maxLength, &maxLength, &infoLog[0]);

    printf("Error: %s\n", &infoLog[0]);

    //The program is useless now. So delete it.
    glDeleteProgram(m_shaderProgram);

    //Provide the infolog in whatever manor you deem best.
    //Exit with failure.
    exit(3);
  }

  glUseProgram(m_shaderProgram);

  GL_CHECK();

  // Specify the layout of the vertex data
  GLint posAttrib = glGetAttribLocation(m_shaderProgram, "position");
  glEnableVertexAttribArray(posAttrib);
  glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 0);

  GL_CHECK();

  GLint texAttrib = glGetAttribLocation(m_shaderProgram, "texcoord");
  glEnableVertexAttribArray(texAttrib);
  glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));

  GL_CHECK();

  // Load textures
  glGenTextures(2, m_textures);

  glUniform1i(glGetUniformLocation(m_shaderProgram, "image"), 0);

  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, m_textures[0]);

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

  GL_CHECK();

  glActiveTexture(GL_TEXTURE1);
  glBindTexture(GL_TEXTURE_2D, m_textures[1]);

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

  GL_CHECK();
}

void Painter::draw()
{
  std::lock_guard<std::mutex> lock(m_mutex);

  // Clear the screen to black
  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  glClear(GL_COLOR_BUFFER_BIT);

  glActiveTexture(GL_TEXTURE0);

  if (!m_image1.empty())
  {
    glBindTexture(GL_TEXTURE_2D, m_textures[0]);
    GL_CHECK();

    if (m_texture1Created)
    {
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_image1.size().width, m_image1.size().height, m_image1.channels() == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, m_image1.data);
      GL_CHECK();
    }
    else
    {
      glTexImage2D(GL_TEXTURE_2D, 0, m_image1.channels() == 3 ? GL_RGB : GL_RGBA, m_image1.size().width, m_image1.size().height, 0, m_image1.channels() == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, m_image1.data);

      GL_CHECK();

      m_texture1Created = true;
    }

    GLint location = glGetUniformLocation(m_shaderProgram, "H");
    if (location == -1)
    {
    }
    else
    {
      glUniformMatrix3fv(location, 1 /*only setting 1 matrix*/, true /*transpose?*/, (float*)convert(m_H1, m_image1.size().width, m_image1.size().height).data);
    }

    // Draw a rectangle from the 2 triangles using 6 indices
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
  }

  if (!m_image2.empty())
  {
    glBindTexture(GL_TEXTURE_2D, m_textures[1]);

    GL_CHECK();
    if (m_texture2Created)
    {
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_image2.size().width, m_image2.size().height, m_image2.channels() == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, m_image2.data);
      GL_CHECK();
    }
    else
    {
      glTexImage2D(GL_TEXTURE_2D, 0, m_image2.channels() == 3 ? GL_RGB : GL_RGBA, m_image2.size().width, m_image2.size().height, 0, m_image2.channels() == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, m_image2.data);
      m_texture2Created = true;
    }

    GLint location = glGetUniformLocation(m_shaderProgram, "H");
    if (location == -1)
    {
      std::cout << "Cannot get H" << std::endl;
    }
    else
    {
      glUniformMatrix3fv(location, 1 /*only setting 1 matrix*/, true /*transpose?*/, (float*)convert(m_H2, m_image2.size().width, m_image2.size().height).data);
    }

    // Draw a rectangle from the 2 triangles using 6 indices
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
  }

  GL_CHECK();
}

void Painter::cleanupOpenGL()
{
  std::lock_guard<std::mutex> lock(m_mutex);
}

cv::Mat Painter::convert(cv::Mat input, int width, int height)
{
  float data[9] = {1.f/width, 0, 0,
                  0, 1.f/height, 0,
                  0, 0, 1};

  cv::Mat inputFloat;
  input.convertTo(inputFloat, CV_32FC1);
  cv::Mat imageToGl(3, 3, CV_32FC1, &data);

  return imageToGl * inputFloat.inv() * imageToGl.inv();
}
<commit_msg>Draw smaller<commit_after>#include "painter.hpp"

#include <iostream>

// Shader sources
const GLchar* vertexSource = R"(
    #version 300 es
    in vec2 position;
    in vec2 texcoord;
    out vec2 Texcoord;
    void main() {
      Texcoord = texcoord;
      gl_Position = vec4(position, 0.0, 1.0);
    }
)";
const GLchar* fragmentSource = R"(
    #version 300 es
    precision mediump float;
    in vec2 Texcoord;
    out vec4 outColor;
    uniform sampler2D image;
    uniform mat3 H;

    void main() {
       vec3 newPos = H*vec3(Texcoord, 1.0);
       vec2 newPosNormalized = newPos.xy/newPos.z;
       if (newPosNormalized.x > 1.0 || newPosNormalized.y > 1.0 || newPosNormalized.x < 0.0 || newPosNormalized.y < 0.0)
       {
         discard;
         return;
       }
       outColor = vec4(texture(image, newPosNormalized).bgr, 1.0);
    }
)";

Painter::Painter()
{
  m_H1 = cv::Mat::eye(3, 3, CV_32FC1);
  m_H2 = cv::Mat::eye(3, 3, CV_32FC1);
}

Painter::~Painter()
{

}

void Painter::updateImage1(cv::Mat image)
{
  m_image1 = image;
}

void Painter::updateImage2(cv::Mat image)
{
  m_image2 = image;
}

void Painter::updateHomography1(cv::Mat H)
{
  m_H1 = H;
}

void Painter::updateHomography2(cv::Mat H)
{
  m_H2 = H;
}

void _check_gl_error(const char* file, int line) {
        GLenum err (glGetError());

        while(err!=GL_NO_ERROR) {
                std::string error;

                switch(err) {
                        case GL_INVALID_OPERATION:      error="INVALID_OPERATION";      break;
                        case GL_INVALID_ENUM:           error="INVALID_ENUM";           break;
                        case GL_INVALID_VALUE:          error="INVALID_VALUE";          break;
                        case GL_OUT_OF_MEMORY:          error="OUT_OF_MEMORY";          break;
                        case GL_INVALID_FRAMEBUFFER_OPERATION:  error="INVALID_FRAMEBUFFER_OPERATION";  break;
                }

                std::cerr << "GL_" << error.c_str() <<" - "<<file<<":"<<line<<std::endl;
                err=glGetError();
        }
}

#define GL_CHECK() _check_gl_error(__FILE__,__LINE__)

void Painter::setupOpenGL(int w, int h)
{
  std::lock_guard<std::mutex> lock(m_mutex);

  // Create Vertex Array Object
  GLuint vao;
  glGenVertexArrays(1, &vao);
  glBindVertexArray(vao);

  // Create a Vertex Buffer Object and copy the vertex data to it
  GLuint vbo;
  glGenBuffers(1, &vbo);

  GLfloat vertices[] = {
    // Position   Texcoords
    -1.0f,  1.0f, 0.0f, 0.0f, // Top-left
     1.0f,  1.0f, 1.0f, 0.0f, // Top-right
     1.0f, -1.0f, 1.0f, 1.0f, // Bottom-right
    -1.0f, -1.0f, 0.0f, 1.0f  // Bottom-left
  };

  glBindBuffer(GL_ARRAY_BUFFER, vbo);
  glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

  // Create an element array
  GLuint ebo;
  glGenBuffers(1, &ebo);

  GLuint elements[] = {
    0, 1, 2,
    2, 3, 0
  };

  GL_CHECK();

  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
  glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);

  // Create and compile the vertex shader
  GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
  glShaderSource(vertexShader, 1, &vertexSource, NULL);
  glCompileShader(vertexShader);

  GLint status;
  glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);

  if (status == GL_FALSE)
  {
    GLint infoLogLength;
    glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &infoLogLength);

    GLchar* strInfoLog = new GLchar[infoLogLength + 1];
    glGetShaderInfoLog(vertexShader, infoLogLength, NULL, strInfoLog);

    printf("Compilation error in shader: %s\n", strInfoLog);
    delete[] strInfoLog;
  }

  GL_CHECK();

  // Create and compile the fragment shader
  GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
  glShaderSource(fragmentShader, 1, &fragmentSource, NULL);
  glCompileShader(fragmentShader);

  glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &status);

  if (status == GL_FALSE)
  {
    GLint infoLogLength;
    glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &infoLogLength);

    GLchar* strInfoLog = new GLchar[infoLogLength + 1];
    glGetShaderInfoLog(fragmentShader, infoLogLength, NULL, strInfoLog);

    printf("Compilation error in shader: %s\n", strInfoLog);
    delete[] strInfoLog;
  }

  GL_CHECK();

  // Link the vertex and fragment shader into a shader program
  m_shaderProgram = glCreateProgram();
  glAttachShader(m_shaderProgram, vertexShader);
  glAttachShader(m_shaderProgram, fragmentShader);
  glLinkProgram(m_shaderProgram);

    GL_CHECK();

  GLint isLinked = 0;
  glGetProgramiv(m_shaderProgram, GL_LINK_STATUS, &isLinked);
  if(isLinked == GL_FALSE)
  {
    GLint maxLength = 0;
    glGetProgramiv(m_shaderProgram, GL_INFO_LOG_LENGTH, &maxLength);

    //The maxLength includes the NULL character
    std::vector<GLchar> infoLog(maxLength);
    glGetProgramInfoLog(m_shaderProgram, maxLength, &maxLength, &infoLog[0]);

    printf("Error: %s\n", &infoLog[0]);

    //The program is useless now. So delete it.
    glDeleteProgram(m_shaderProgram);

    //Provide the infolog in whatever manor you deem best.
    //Exit with failure.
    exit(3);
  }

  glUseProgram(m_shaderProgram);

  GL_CHECK();

  // Specify the layout of the vertex data
  GLint posAttrib = glGetAttribLocation(m_shaderProgram, "position");
  glEnableVertexAttribArray(posAttrib);
  glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 0);

  GL_CHECK();

  GLint texAttrib = glGetAttribLocation(m_shaderProgram, "texcoord");
  glEnableVertexAttribArray(texAttrib);
  glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));

  GL_CHECK();

  // Load textures
  glGenTextures(2, m_textures);

  glUniform1i(glGetUniformLocation(m_shaderProgram, "image"), 0);

  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, m_textures[0]);

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

  GL_CHECK();

  glActiveTexture(GL_TEXTURE1);
  glBindTexture(GL_TEXTURE_2D, m_textures[1]);

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

  GL_CHECK();
}

void Painter::draw()
{
  std::lock_guard<std::mutex> lock(m_mutex);

  // Clear the screen to black
  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  glClear(GL_COLOR_BUFFER_BIT);

  glActiveTexture(GL_TEXTURE0);

  if (!m_image1.empty())
  {
    glBindTexture(GL_TEXTURE_2D, m_textures[0]);
    GL_CHECK();

    if (m_texture1Created)
    {
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_image1.size().width, m_image1.size().height, m_image1.channels() == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, m_image1.data);
      GL_CHECK();
    }
    else
    {
      glTexImage2D(GL_TEXTURE_2D, 0, m_image1.channels() == 3 ? GL_RGB : GL_RGBA, m_image1.size().width, m_image1.size().height, 0, m_image1.channels() == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, m_image1.data);

      GL_CHECK();

      m_texture1Created = true;
    }

    GLint location = glGetUniformLocation(m_shaderProgram, "H");
    if (location == -1)
    {
    }
    else
    {
      glUniformMatrix3fv(location, 1 /*only setting 1 matrix*/, true /*transpose?*/, (float*)convert(m_H1, m_image1.size().width, m_image1.size().height).data);
    }

    // Draw a rectangle from the 2 triangles using 6 indices
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
  }

  if (!m_image2.empty())
  {
    glBindTexture(GL_TEXTURE_2D, m_textures[1]);

    GL_CHECK();
    if (m_texture2Created)
    {
      glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_image2.size().width, m_image2.size().height, m_image2.channels() == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, m_image2.data);
      GL_CHECK();
    }
    else
    {
      glTexImage2D(GL_TEXTURE_2D, 0, m_image2.channels() == 3 ? GL_RGB : GL_RGBA, m_image2.size().width, m_image2.size().height, 0, m_image2.channels() == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, m_image2.data);
      m_texture2Created = true;
    }

    GLint location = glGetUniformLocation(m_shaderProgram, "H");
    if (location == -1)
    {
      std::cout << "Cannot get H" << std::endl;
    }
    else
    {
      glUniformMatrix3fv(location, 1 /*only setting 1 matrix*/, true /*transpose?*/, (float*)convert(m_H2, m_image2.size().width, m_image2.size().height).data);
    }

    // Draw a rectangle from the 2 triangles using 6 indices
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
  }

  GL_CHECK();
}

void Painter::cleanupOpenGL()
{
  std::lock_guard<std::mutex> lock(m_mutex);
}

cv::Mat Painter::convert(cv::Mat input, int width, int height)
{
  float dataTextureScale[9] = {2.0, 0, -0.5,
                  0, 2.0, -0.5,
                  0, 0, 1};
  cv::Mat textureScale(3, 3, CV_32FC1, &dataTextureScale);

  float dataImageToTexture[9] = {1.f/width, 0, 0,
                  0, 1.f/height, 0,
                  0, 0, 1};
  cv::Mat imageToTexture(3, 3, CV_32FC1, &dataImageToTexture);

  cv::Mat inputFloat;
  input.convertTo(inputFloat, CV_32FC1);

  return textureScale * imageToTexture * inputFloat.inv() * imageToTexture.inv();
}
<|endoftext|>


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

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

#ifndef _SAL_TYPES_H_
#include <sal/types.h>
#endif

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif

#include <toolkit/helper/servicenames.hxx>

const sal_Char __FAR_DATA szServiceName_Toolkit[] = "stardiv.vcl.VclToolkit", szServiceName2_Toolkit[] = "com.sun.star.awt.Toolkit";
const sal_Char __FAR_DATA szServiceName_PopupMenu[] = "stardiv.vcl.PopupMenu", szServiceName2_PopupMenu[] = "com.sun.star.awt.PopupMenu";
const sal_Char __FAR_DATA szServiceName_MenuBar[] = "stardiv.vcl.MenuBar", szServiceName2_MenuBar[] = "com.sun.star.awt.MenuBar";
const sal_Char __FAR_DATA szServiceName_Pointer[] = "stardiv.vcl.Pointer", szServiceName2_Pointer[] = "com.sun.star.awt.Pointer";
const sal_Char __FAR_DATA szServiceName_UnoControlContainer[] = "stardiv.vcl.control.ControlContainer", szServiceName2_UnoControlContainer[] = "com.sun.star.awt.UnoControlContainer";
const sal_Char __FAR_DATA szServiceName_UnoControlContainerModel[] = "stardiv.vcl.controlmodel.ControlContainer", szServiceName2_UnoControlContainerModel[] = "com.sun.star.awt.UnoControlContainerModel";
const sal_Char __FAR_DATA szServiceName_TabController[] = "stardiv.vcl.control.TabController", szServiceName2_TabController[] = "com.sun.star.awt.TabController";
const sal_Char __FAR_DATA szServiceName_TabControllerModel[] = "stardiv.vcl.controlmodel.TabController", szServiceName2_TabControllerModel[] = "com.sun.star.awt.TabControllerModel";
const sal_Char __FAR_DATA szServiceName_UnoControlDialog[] = "stardiv.vcl.control.Dialog", szServiceName2_UnoControlDialog[] = "com.sun.star.awt.UnoControlDialog";
const sal_Char __FAR_DATA szServiceName_UnoControlDialogModel[] = "stardiv.vcl.controlmodel.Dialog", szServiceName2_UnoControlDialogModel[] = "com.sun.star.awt.UnoControlDialogModel";
const sal_Char __FAR_DATA szServiceName_UnoControlEdit[] = "stardiv.vcl.control.Edit", szServiceName2_UnoControlEdit[] = "com.sun.star.awt.UnoControlEdit";
const sal_Char __FAR_DATA szServiceName_UnoControlEditModel[] = "stardiv.vcl.controlmodel.Edit", szServiceName2_UnoControlEditModel[] = "com.sun.star.awt.UnoControlEditModel";
const sal_Char __FAR_DATA szServiceName_UnoControlFileControl[] = "stardiv.vcl.control.FileControl", szServiceName2_UnoControlFileControl[] = "com.sun.star.awt.UnoControlFileControl";
const sal_Char __FAR_DATA szServiceName_UnoControlFileControlModel[] = "stardiv.vcl.controlmodel.FileControl", szServiceName2_UnoControlFileControlModel[] = "com.sun.star.awt.UnoControlFileControlModel";
const sal_Char __FAR_DATA szServiceName_UnoControlButton[] = "stardiv.vcl.control.Button", szServiceName2_UnoControlButton[] = "com.sun.star.awt.UnoControlButton";
const sal_Char __FAR_DATA szServiceName_UnoControlButtonModel[] = "stardiv.vcl.controlmodel.Button", szServiceName2_UnoControlButtonModel[] = "com.sun.star.awt.UnoControlButtonModel";
const sal_Char __FAR_DATA szServiceName_UnoControlImageButton[] = "stardiv.vcl.control.ImageButton", szServiceName2_UnoControlImageButton[] = "com.sun.star.awt.UnoControlImageButton";
const sal_Char __FAR_DATA szServiceName_UnoControlImageButtonModel[] = "stardiv.vcl.controlmodel.ImageButton", szServiceName2_UnoControlImageButtonModel[] = "com.sun.star.awt.UnoControlImageButtonModel";
const sal_Char __FAR_DATA szServiceName_UnoControlImageControl[] = "stardiv.vcl.control.ImageControl", szServiceName2_UnoControlImageControl[] = "com.sun.star.awt.UnoControlImageControl";
const sal_Char __FAR_DATA szServiceName_UnoControlImageControlModel[] = "stardiv.vcl.controlmodel.ImageControl", szServiceName2_UnoControlImageControlModel[] = "com.sun.star.awt.UnoControlImageControlModel";
const sal_Char __FAR_DATA szServiceName_UnoControlRadioButton[] = "stardiv.vcl.control.RadioButton", szServiceName2_UnoControlRadioButton[] = "com.sun.star.awt.UnoControlRadioButton";
const sal_Char __FAR_DATA szServiceName_UnoControlRadioButtonModel[] = "stardiv.vcl.controlmodel.RadioButton", szServiceName2_UnoControlRadioButtonModel[] = "com.sun.star.awt.UnoControlRadioButtonModel";
const sal_Char __FAR_DATA szServiceName_UnoControlCheckBox[] = "stardiv.vcl.control.CheckBox", szServiceName2_UnoControlCheckBox[] = "com.sun.star.awt.UnoControlCheckBox";
const sal_Char __FAR_DATA szServiceName_UnoControlCheckBoxModel[] = "stardiv.vcl.controlmodel.CheckBox", szServiceName2_UnoControlCheckBoxModel[] = "com.sun.star.awt.UnoControlCheckBoxModel";
const sal_Char __FAR_DATA szServiceName_UnoControlListBox[] = "stardiv.vcl.control.ListBox", szServiceName2_UnoControlListBox[] = "com.sun.star.awt.UnoControlListBox";
const sal_Char __FAR_DATA szServiceName_UnoControlListBoxModel[] = "stardiv.vcl.controlmodel.ListBox", szServiceName2_UnoControlListBoxModel[] = "com.sun.star.awt.UnoControlListBoxModel";
const sal_Char __FAR_DATA szServiceName_UnoControlComboBox[] = "stardiv.vcl.control.ComboBox", szServiceName2_UnoControlComboBox[] = "com.sun.star.awt.UnoControlComboBox";
const sal_Char __FAR_DATA szServiceName_UnoControlComboBoxModel[] = "stardiv.vcl.controlmodel.ComboBox", szServiceName2_UnoControlComboBoxModel[] = "com.sun.star.awt.UnoControlComboBoxModel";
const sal_Char __FAR_DATA szServiceName_UnoControlFixedText[] = "stardiv.vcl.control.FixedText", szServiceName2_UnoControlFixedText[] = "com.sun.star.awt.UnoControlFixedText";
const sal_Char __FAR_DATA szServiceName_UnoControlFixedTextModel[] = "stardiv.vcl.controlmodel.FixedText", szServiceName2_UnoControlFixedTextModel[] = "com.sun.star.awt.UnoControlFixedTextModel";
const sal_Char __FAR_DATA szServiceName_UnoControlGroupBox[] = "stardiv.vcl.control.GroupBox", szServiceName2_UnoControlGroupBox[] = "com.sun.star.awt.UnoControlGroupBox";
const sal_Char __FAR_DATA szServiceName_UnoControlGroupBoxModel[] = "stardiv.vcl.controlmodel.GroupBox", szServiceName2_UnoControlGroupBoxModel[] = "com.sun.star.awt.UnoControlGroupBoxModel";
const sal_Char __FAR_DATA szServiceName_UnoControlDateField[] = "stardiv.vcl.control.DateField", szServiceName2_UnoControlDateField[] = "com.sun.star.awt.UnoControlDateField";
const sal_Char __FAR_DATA szServiceName_UnoControlDateFieldModel[] = "stardiv.vcl.controlmodel.DateField", szServiceName2_UnoControlDateFieldModel[] = "com.sun.star.awt.UnoControlDateFieldModel";
const sal_Char __FAR_DATA szServiceName_UnoControlTimeField[] = "stardiv.vcl.control.TimeField", szServiceName2_UnoControlTimeField[] = "com.sun.star.awt.UnoControlTimeField";
const sal_Char __FAR_DATA szServiceName_UnoControlTimeFieldModel[] = "stardiv.vcl.controlmodel.TimeField", szServiceName2_UnoControlTimeFieldModel[] = "com.sun.star.awt.UnoControlTimeFieldModel";
const sal_Char __FAR_DATA szServiceName_UnoControlNumericField[] = "stardiv.vcl.control.NumericField", szServiceName2_UnoControlNumericField[] = "com.sun.star.awt.UnoControlNumericField";
const sal_Char __FAR_DATA szServiceName_UnoControlNumericFieldModel[] = "stardiv.vcl.controlmodel.NumericField", szServiceName2_UnoControlNumericFieldModel[] = "com.sun.star.awt.UnoControlNumericFieldModel";
const sal_Char __FAR_DATA szServiceName_UnoControlCurrencyField[] = "stardiv.vcl.control.CurrencyField", szServiceName2_UnoControlCurrencyField[] = "com.sun.star.awt.UnoControlCurrencyField";
const sal_Char __FAR_DATA szServiceName_UnoControlCurrencyFieldModel[] = "stardiv.vcl.controlmodel.CurrencyField", szServiceName2_UnoControlCurrencyFieldModel[] = "com.sun.star.awt.UnoControlCurrencyFieldModel";
const sal_Char __FAR_DATA szServiceName_UnoControlPatternField[] = "stardiv.vcl.control.PatternField", szServiceName2_UnoControlPatternField[] = "com.sun.star.awt.UnoControlPatternField";
const sal_Char __FAR_DATA szServiceName_UnoControlPatternFieldModel[] = "stardiv.vcl.controlmodel.PatternField", szServiceName2_UnoControlPatternFieldModel[] = "com.sun.star.awt.UnoControlPatternFieldModel";
const sal_Char __FAR_DATA szServiceName_UnoControlFormattedField[] = "stardiv.vcl.control.FormattedField", szServiceName2_UnoControlFormattedField[] = "com.sun.star.awt.UnoControlFormattedField";
const sal_Char __FAR_DATA szServiceName_UnoControlFormattedFieldModel[] = "stardiv.vcl.controlmodel.FormattedField", szServiceName2_UnoControlFormattedFieldModel[] = "com.sun.star.awt.UnoControlFormattedFieldModel";
const sal_Char __FAR_DATA szServiceName_MVCIntrospection[] = "stardiv.vcl.MVCIntrospection", szServiceName2_MVCIntrospection[] = "com.sun.star.awt.MVCIntrospection";
const sal_Char __FAR_DATA szServiceName_ImageProducer[] = "stardiv.vcl.ImageProducer", szServiceName2_ImageProducer[] = "com.sun.star.awt.ImageProducer";
const sal_Char __FAR_DATA szServiceName_PrinterServer[] = "stardiv.vcl.PrinterServer", szServiceName2_PrinterServer[] = "com.sun.star.awt.PrinterServer";
const sal_Char __FAR_DATA szServiceName_UnoControlProgressBar[] = "stardiv.vcl.control.ProgressBar", szServiceName2_UnoControlProgressBar[] = "com.sun.star.awt.UnoControlProgressBar";
const sal_Char __FAR_DATA szServiceName_UnoControlProgressBarModel[] = "stardiv.vcl.controlmodel.ProgressBar", szServiceName2_UnoControlProgressBarModel[] = "com.sun.star.awt.UnoControlProgressBarModel";
const sal_Char __FAR_DATA szServiceName_UnoControlScrollBar[] = "stardiv.vcl.control.ScrollBar", szServiceName2_UnoControlScrollBar[] = "com.sun.star.awt.UnoControlScrollBar";
const sal_Char __FAR_DATA szServiceName_UnoControlScrollBarModel[] = "stardiv.vcl.controlmodel.ScrollBar", szServiceName2_UnoControlScrollBarModel[] = "com.sun.star.awt.UnoControlScrollBarModel";
const sal_Char __FAR_DATA szServiceName_UnoControlFixedLine[] = "stardiv.vcl.control.FixedLine", szServiceName2_UnoControlFixedLine[] = "com.sun.star.awt.UnoControlFixedLine";
const sal_Char __FAR_DATA szServiceName_UnoControlFixedLineModel[] = "stardiv.vcl.controlmodel.FixedLine", szServiceName2_UnoControlFixedLineModel[] = "com.sun.star.awt.UnoControlFixedLineModel";
const sal_Char __FAR_DATA szServiceName_UnoControlRoadmap[] = "stardiv.vcl.control.Roadmap", szServiceName2_UnoControlRoadmap[] = "com.sun.star.awt.UnoControlRoadmap";
const sal_Char __FAR_DATA szServiceName_UnoControlRoadmapModel[] = "stardiv.vcl.controlmodel.Roadmap", szServiceName2_UnoControlRoadmapModel[] = "com.sun.star.awt.UnoControlRoadmapModel";
const sal_Char __FAR_DATA szServiceName_UnoSpinButtonControl[] = "com.sun.star.awt.UnoControlSpinButton";
const sal_Char __FAR_DATA szServiceName_UnoSpinButtonModel[] = "com.sun.star.awt.UnoControlSpinButtonModel";
const sal_Char __FAR_DATA szServiceName_TreeControl[] = "com.sun.star.awt.tree.TreeControl";
const sal_Char __FAR_DATA szServiceName_TreeControlModel[] = "com.sun.star.awt.tree.TreeControlModel";
const sal_Char __FAR_DATA szServiceName_MutableTreeDataModel[] = "com.sun.star.awt.tree.MutableTreeDataModel";
const sal_Char __FAR_DATA szServiceName_UnoSimpleAnimationControlModel[] = "com.sun.star.awt.UnoSimpleAnimationControlModel";
const sal_Char __FAR_DATA szServiceName_UnoSimpleAnimationControl[] = "com.sun.star.awt.UnoSimpleAnimationControl";
const sal_Char __FAR_DATA szServiceName_UnoThrobberControlModel[] = "com.sun.star.awt.UnoThrobberControlModel";
const sal_Char __FAR_DATA szServiceName_UnoThrobberControl[] = "com.sun.star.awt.UnoThrobberControl";
<commit_msg>INTEGRATION: CWS fwk80_SRC680 (1.11.62); FILE MERGED 2008/01/11 15:00:07 pb 1.11.62.1: fix: #i83756# szServiceName_UnoControlFixedHyperlink[], szServiceName_UnoControlFixedHyperlinkModel[]<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: servicenames.cxx,v $
 *
 *  $Revision: 1.12 $
 *
 *  last change: $Author: rt $ $Date: 2008-01-29 15:07:48 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

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

#ifndef _SAL_TYPES_H_
#include <sal/types.h>
#endif

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif

#include <toolkit/helper/servicenames.hxx>

const sal_Char __FAR_DATA szServiceName_Toolkit[] = "stardiv.vcl.VclToolkit", szServiceName2_Toolkit[] = "com.sun.star.awt.Toolkit";
const sal_Char __FAR_DATA szServiceName_PopupMenu[] = "stardiv.vcl.PopupMenu", szServiceName2_PopupMenu[] = "com.sun.star.awt.PopupMenu";
const sal_Char __FAR_DATA szServiceName_MenuBar[] = "stardiv.vcl.MenuBar", szServiceName2_MenuBar[] = "com.sun.star.awt.MenuBar";
const sal_Char __FAR_DATA szServiceName_Pointer[] = "stardiv.vcl.Pointer", szServiceName2_Pointer[] = "com.sun.star.awt.Pointer";
const sal_Char __FAR_DATA szServiceName_UnoControlContainer[] = "stardiv.vcl.control.ControlContainer", szServiceName2_UnoControlContainer[] = "com.sun.star.awt.UnoControlContainer";
const sal_Char __FAR_DATA szServiceName_UnoControlContainerModel[] = "stardiv.vcl.controlmodel.ControlContainer", szServiceName2_UnoControlContainerModel[] = "com.sun.star.awt.UnoControlContainerModel";
const sal_Char __FAR_DATA szServiceName_TabController[] = "stardiv.vcl.control.TabController", szServiceName2_TabController[] = "com.sun.star.awt.TabController";
const sal_Char __FAR_DATA szServiceName_TabControllerModel[] = "stardiv.vcl.controlmodel.TabController", szServiceName2_TabControllerModel[] = "com.sun.star.awt.TabControllerModel";
const sal_Char __FAR_DATA szServiceName_UnoControlDialog[] = "stardiv.vcl.control.Dialog", szServiceName2_UnoControlDialog[] = "com.sun.star.awt.UnoControlDialog";
const sal_Char __FAR_DATA szServiceName_UnoControlDialogModel[] = "stardiv.vcl.controlmodel.Dialog", szServiceName2_UnoControlDialogModel[] = "com.sun.star.awt.UnoControlDialogModel";
const sal_Char __FAR_DATA szServiceName_UnoControlEdit[] = "stardiv.vcl.control.Edit", szServiceName2_UnoControlEdit[] = "com.sun.star.awt.UnoControlEdit";
const sal_Char __FAR_DATA szServiceName_UnoControlEditModel[] = "stardiv.vcl.controlmodel.Edit", szServiceName2_UnoControlEditModel[] = "com.sun.star.awt.UnoControlEditModel";
const sal_Char __FAR_DATA szServiceName_UnoControlFileControl[] = "stardiv.vcl.control.FileControl", szServiceName2_UnoControlFileControl[] = "com.sun.star.awt.UnoControlFileControl";
const sal_Char __FAR_DATA szServiceName_UnoControlFileControlModel[] = "stardiv.vcl.controlmodel.FileControl", szServiceName2_UnoControlFileControlModel[] = "com.sun.star.awt.UnoControlFileControlModel";
const sal_Char __FAR_DATA szServiceName_UnoControlButton[] = "stardiv.vcl.control.Button", szServiceName2_UnoControlButton[] = "com.sun.star.awt.UnoControlButton";
const sal_Char __FAR_DATA szServiceName_UnoControlButtonModel[] = "stardiv.vcl.controlmodel.Button", szServiceName2_UnoControlButtonModel[] = "com.sun.star.awt.UnoControlButtonModel";
const sal_Char __FAR_DATA szServiceName_UnoControlImageButton[] = "stardiv.vcl.control.ImageButton", szServiceName2_UnoControlImageButton[] = "com.sun.star.awt.UnoControlImageButton";
const sal_Char __FAR_DATA szServiceName_UnoControlImageButtonModel[] = "stardiv.vcl.controlmodel.ImageButton", szServiceName2_UnoControlImageButtonModel[] = "com.sun.star.awt.UnoControlImageButtonModel";
const sal_Char __FAR_DATA szServiceName_UnoControlImageControl[] = "stardiv.vcl.control.ImageControl", szServiceName2_UnoControlImageControl[] = "com.sun.star.awt.UnoControlImageControl";
const sal_Char __FAR_DATA szServiceName_UnoControlImageControlModel[] = "stardiv.vcl.controlmodel.ImageControl", szServiceName2_UnoControlImageControlModel[] = "com.sun.star.awt.UnoControlImageControlModel";
const sal_Char __FAR_DATA szServiceName_UnoControlRadioButton[] = "stardiv.vcl.control.RadioButton", szServiceName2_UnoControlRadioButton[] = "com.sun.star.awt.UnoControlRadioButton";
const sal_Char __FAR_DATA szServiceName_UnoControlRadioButtonModel[] = "stardiv.vcl.controlmodel.RadioButton", szServiceName2_UnoControlRadioButtonModel[] = "com.sun.star.awt.UnoControlRadioButtonModel";
const sal_Char __FAR_DATA szServiceName_UnoControlCheckBox[] = "stardiv.vcl.control.CheckBox", szServiceName2_UnoControlCheckBox[] = "com.sun.star.awt.UnoControlCheckBox";
const sal_Char __FAR_DATA szServiceName_UnoControlCheckBoxModel[] = "stardiv.vcl.controlmodel.CheckBox", szServiceName2_UnoControlCheckBoxModel[] = "com.sun.star.awt.UnoControlCheckBoxModel";
const sal_Char __FAR_DATA szServiceName_UnoControlListBox[] = "stardiv.vcl.control.ListBox", szServiceName2_UnoControlListBox[] = "com.sun.star.awt.UnoControlListBox";
const sal_Char __FAR_DATA szServiceName_UnoControlListBoxModel[] = "stardiv.vcl.controlmodel.ListBox", szServiceName2_UnoControlListBoxModel[] = "com.sun.star.awt.UnoControlListBoxModel";
const sal_Char __FAR_DATA szServiceName_UnoControlComboBox[] = "stardiv.vcl.control.ComboBox", szServiceName2_UnoControlComboBox[] = "com.sun.star.awt.UnoControlComboBox";
const sal_Char __FAR_DATA szServiceName_UnoControlComboBoxModel[] = "stardiv.vcl.controlmodel.ComboBox", szServiceName2_UnoControlComboBoxModel[] = "com.sun.star.awt.UnoControlComboBoxModel";
const sal_Char __FAR_DATA szServiceName_UnoControlFixedText[] = "stardiv.vcl.control.FixedText", szServiceName2_UnoControlFixedText[] = "com.sun.star.awt.UnoControlFixedText";
const sal_Char __FAR_DATA szServiceName_UnoControlFixedTextModel[] = "stardiv.vcl.controlmodel.FixedText", szServiceName2_UnoControlFixedTextModel[] = "com.sun.star.awt.UnoControlFixedTextModel";
const sal_Char __FAR_DATA szServiceName_UnoControlGroupBox[] = "stardiv.vcl.control.GroupBox", szServiceName2_UnoControlGroupBox[] = "com.sun.star.awt.UnoControlGroupBox";
const sal_Char __FAR_DATA szServiceName_UnoControlGroupBoxModel[] = "stardiv.vcl.controlmodel.GroupBox", szServiceName2_UnoControlGroupBoxModel[] = "com.sun.star.awt.UnoControlGroupBoxModel";
const sal_Char __FAR_DATA szServiceName_UnoControlDateField[] = "stardiv.vcl.control.DateField", szServiceName2_UnoControlDateField[] = "com.sun.star.awt.UnoControlDateField";
const sal_Char __FAR_DATA szServiceName_UnoControlDateFieldModel[] = "stardiv.vcl.controlmodel.DateField", szServiceName2_UnoControlDateFieldModel[] = "com.sun.star.awt.UnoControlDateFieldModel";
const sal_Char __FAR_DATA szServiceName_UnoControlTimeField[] = "stardiv.vcl.control.TimeField", szServiceName2_UnoControlTimeField[] = "com.sun.star.awt.UnoControlTimeField";
const sal_Char __FAR_DATA szServiceName_UnoControlTimeFieldModel[] = "stardiv.vcl.controlmodel.TimeField", szServiceName2_UnoControlTimeFieldModel[] = "com.sun.star.awt.UnoControlTimeFieldModel";
const sal_Char __FAR_DATA szServiceName_UnoControlNumericField[] = "stardiv.vcl.control.NumericField", szServiceName2_UnoControlNumericField[] = "com.sun.star.awt.UnoControlNumericField";
const sal_Char __FAR_DATA szServiceName_UnoControlNumericFieldModel[] = "stardiv.vcl.controlmodel.NumericField", szServiceName2_UnoControlNumericFieldModel[] = "com.sun.star.awt.UnoControlNumericFieldModel";
const sal_Char __FAR_DATA szServiceName_UnoControlCurrencyField[] = "stardiv.vcl.control.CurrencyField", szServiceName2_UnoControlCurrencyField[] = "com.sun.star.awt.UnoControlCurrencyField";
const sal_Char __FAR_DATA szServiceName_UnoControlCurrencyFieldModel[] = "stardiv.vcl.controlmodel.CurrencyField", szServiceName2_UnoControlCurrencyFieldModel[] = "com.sun.star.awt.UnoControlCurrencyFieldModel";
const sal_Char __FAR_DATA szServiceName_UnoControlPatternField[] = "stardiv.vcl.control.PatternField", szServiceName2_UnoControlPatternField[] = "com.sun.star.awt.UnoControlPatternField";
const sal_Char __FAR_DATA szServiceName_UnoControlPatternFieldModel[] = "stardiv.vcl.controlmodel.PatternField", szServiceName2_UnoControlPatternFieldModel[] = "com.sun.star.awt.UnoControlPatternFieldModel";
const sal_Char __FAR_DATA szServiceName_UnoControlFormattedField[] = "stardiv.vcl.control.FormattedField", szServiceName2_UnoControlFormattedField[] = "com.sun.star.awt.UnoControlFormattedField";
const sal_Char __FAR_DATA szServiceName_UnoControlFormattedFieldModel[] = "stardiv.vcl.controlmodel.FormattedField", szServiceName2_UnoControlFormattedFieldModel[] = "com.sun.star.awt.UnoControlFormattedFieldModel";
const sal_Char __FAR_DATA szServiceName_MVCIntrospection[] = "stardiv.vcl.MVCIntrospection", szServiceName2_MVCIntrospection[] = "com.sun.star.awt.MVCIntrospection";
const sal_Char __FAR_DATA szServiceName_ImageProducer[] = "stardiv.vcl.ImageProducer", szServiceName2_ImageProducer[] = "com.sun.star.awt.ImageProducer";
const sal_Char __FAR_DATA szServiceName_PrinterServer[] = "stardiv.vcl.PrinterServer", szServiceName2_PrinterServer[] = "com.sun.star.awt.PrinterServer";
const sal_Char __FAR_DATA szServiceName_UnoControlProgressBar[] = "stardiv.vcl.control.ProgressBar", szServiceName2_UnoControlProgressBar[] = "com.sun.star.awt.UnoControlProgressBar";
const sal_Char __FAR_DATA szServiceName_UnoControlProgressBarModel[] = "stardiv.vcl.controlmodel.ProgressBar", szServiceName2_UnoControlProgressBarModel[] = "com.sun.star.awt.UnoControlProgressBarModel";
const sal_Char __FAR_DATA szServiceName_UnoControlScrollBar[] = "stardiv.vcl.control.ScrollBar", szServiceName2_UnoControlScrollBar[] = "com.sun.star.awt.UnoControlScrollBar";
const sal_Char __FAR_DATA szServiceName_UnoControlScrollBarModel[] = "stardiv.vcl.controlmodel.ScrollBar", szServiceName2_UnoControlScrollBarModel[] = "com.sun.star.awt.UnoControlScrollBarModel";
const sal_Char __FAR_DATA szServiceName_UnoControlFixedLine[] = "stardiv.vcl.control.FixedLine", szServiceName2_UnoControlFixedLine[] = "com.sun.star.awt.UnoControlFixedLine";
const sal_Char __FAR_DATA szServiceName_UnoControlFixedLineModel[] = "stardiv.vcl.controlmodel.FixedLine", szServiceName2_UnoControlFixedLineModel[] = "com.sun.star.awt.UnoControlFixedLineModel";
const sal_Char __FAR_DATA szServiceName_UnoControlRoadmap[] = "stardiv.vcl.control.Roadmap", szServiceName2_UnoControlRoadmap[] = "com.sun.star.awt.UnoControlRoadmap";
const sal_Char __FAR_DATA szServiceName_UnoControlRoadmapModel[] = "stardiv.vcl.controlmodel.Roadmap", szServiceName2_UnoControlRoadmapModel[] = "com.sun.star.awt.UnoControlRoadmapModel";
const sal_Char __FAR_DATA szServiceName_UnoSpinButtonControl[] = "com.sun.star.awt.UnoControlSpinButton";
const sal_Char __FAR_DATA szServiceName_UnoSpinButtonModel[] = "com.sun.star.awt.UnoControlSpinButtonModel";
const sal_Char __FAR_DATA szServiceName_TreeControl[] = "com.sun.star.awt.tree.TreeControl";
const sal_Char __FAR_DATA szServiceName_TreeControlModel[] = "com.sun.star.awt.tree.TreeControlModel";
const sal_Char __FAR_DATA szServiceName_MutableTreeDataModel[] = "com.sun.star.awt.tree.MutableTreeDataModel";
const sal_Char __FAR_DATA szServiceName_UnoSimpleAnimationControlModel[] = "com.sun.star.awt.UnoSimpleAnimationControlModel";
const sal_Char __FAR_DATA szServiceName_UnoSimpleAnimationControl[] = "com.sun.star.awt.UnoSimpleAnimationControl";
const sal_Char __FAR_DATA szServiceName_UnoThrobberControlModel[] = "com.sun.star.awt.UnoThrobberControlModel";
const sal_Char __FAR_DATA szServiceName_UnoThrobberControl[] = "com.sun.star.awt.UnoThrobberControl";
const sal_Char __FAR_DATA szServiceName_UnoControlFixedHyperlink[] = "com.sun.star.awt.UnoControlFixedHyperlink";
const sal_Char __FAR_DATA szServiceName_UnoControlFixedHyperlinkModel[] = "com.sun.star.awt.UnoControlFixedHyperlinkModel";

<|endoftext|>


<commit_before>// Copyright (c) 2011-2013 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "sendcoinsentry.h"
#include "ui_sendcoinsentry.h"

#include "addressbookpage.h"
#include "addresstablemodel.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "walletmodel.h"

#include <QApplication>
#include <QClipboard>

SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
    QStackedWidget(parent),
    ui(new Ui::SendCoinsEntry),
    model(0)
{
    ui->setupUi(this);

    setCurrentWidget(ui->SendCoins);

#ifdef Q_OS_MAC
    ui->payToLayout->setSpacing(4);
#endif
#if QT_VERSION >= 0x040700
    ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
    ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
#endif
    setFocusProxy(ui->payTo);

    // normal bitcoin address field
    GUIUtil::setupAddressWidget(ui->payTo, this);
    // just a label for displaying bitcoin address(es)
    ui->payTo_is->setFont(GUIUtil::bitcoinAddressFont());
}

SendCoinsEntry::~SendCoinsEntry()
{
    delete ui;
}

void SendCoinsEntry::on_pasteButton_clicked()
{
    // Paste text from clipboard into recipient field
    ui->payTo->setText(QApplication::clipboard()->text());
}

void SendCoinsEntry::on_addressBookButton_clicked()
{
    if(!model)
        return;
    AddressBookPage dlg(AddressBookPage::ForSelection, AddressBookPage::SendingTab, this);
    dlg.setModel(model->getAddressTableModel());
    if(dlg.exec())
    {
        ui->payTo->setText(dlg.getReturnValue());
        ui->payAmount->setFocus();
    }
}

void SendCoinsEntry::on_payTo_textChanged(const QString &address)
{
    updateLabel(address);
}

void SendCoinsEntry::setModel(WalletModel *model)
{
    this->model = model;

    if (model && model->getOptionsModel())
        connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));

    connect(ui->payAmount, SIGNAL(textChanged()), this, SIGNAL(payAmountChanged()));
    connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
    connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked()));
    connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked()));

    clear();
}

void SendCoinsEntry::clear()
{
    // clear UI elements for normal payment
    ui->payTo->clear();
    ui->addAsLabel->clear();
    ui->payAmount->clear();
    // clear UI elements for insecure payment request
    ui->payTo_is->clear();
    ui->memoTextLabel_is->clear();
    ui->payAmount_is->clear();
    // clear UI elements for secure payment request
    ui->payTo_s->clear();
    ui->memoTextLabel_s->clear();
    ui->payAmount_s->clear();

    // update the display unit, to not use the default ("BTC")
    updateDisplayUnit();
}

void SendCoinsEntry::deleteClicked()
{
    emit removeEntry(this);
}

bool SendCoinsEntry::validate()
{
    if (!model)
        return false;

    // Check input validity
    bool retval = true;

    // Skip checks for payment request
    if (recipient.paymentRequest.IsInitialized())
        return retval;

    if (!ui->payTo->hasAcceptableInput() || !model->validateAddress(ui->payTo->text()))
    {
        ui->payTo->setValid(false);
        retval = false;
    }

    if (!ui->payAmount->validate())
    {
        retval = false;
    }

    // Reject dust outputs:
    if (retval && GUIUtil::isDust(ui->payTo->text(), ui->payAmount->value())) {
        ui->payAmount->setValid(false);
        retval = false;
    }

    return retval;
}

SendCoinsRecipient SendCoinsEntry::getValue()
{
    // Payment request
    if (recipient.paymentRequest.IsInitialized())
        return recipient;

    // Normal payment
    recipient.address = ui->payTo->text();
    recipient.label = ui->addAsLabel->text();
    recipient.amount = ui->payAmount->value();

    return recipient;
}

QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
{
    QWidget::setTabOrder(prev, ui->payTo);
    QWidget::setTabOrder(ui->payTo, ui->addressBookButton);
    QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
    QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
    QWidget::setTabOrder(ui->deleteButton, ui->addAsLabel);
    return ui->payAmount->setupTabChain(ui->addAsLabel);
}

void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
{
    recipient = value;

    if (recipient.paymentRequest.IsInitialized()) // payment request
    {
        if (recipient.authenticatedMerchant.isEmpty()) // insecure
        {
            ui->payTo_is->setText(recipient.address);
            ui->memoTextLabel_is->setText(recipient.message);
            ui->payAmount_is->setValue(recipient.amount);
            ui->payAmount_is->setReadOnly(true);
            setCurrentWidget(ui->SendCoins_InsecurePaymentRequest);
        }
        else // secure
        {
            ui->payTo_s->setText(recipient.authenticatedMerchant);
            ui->memoTextLabel_s->setText(recipient.message);
            ui->payAmount_s->setValue(recipient.amount);
            ui->payAmount_s->setReadOnly(true);
            setCurrentWidget(ui->SendCoins_SecurePaymentRequest);
        }
    }
    else // normal payment
    {
        ui->payTo->setText(recipient.address);
        ui->addAsLabel->setText(recipient.label);
        ui->payAmount->setValue(recipient.amount);
    }
}

void SendCoinsEntry::setAddress(const QString &address)
{
    ui->payTo->setText(address);
    ui->payAmount->setFocus();
}

bool SendCoinsEntry::isClear()
{
    return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
}

void SendCoinsEntry::setFocus()
{
    ui->payTo->setFocus();
}

void SendCoinsEntry::updateDisplayUnit()
{
    if(model && model->getOptionsModel())
    {
        // Update payAmount with the current unit
        ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
        ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
        ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
    }
}

bool SendCoinsEntry::updateLabel(const QString &address)
{
    if(!model)
        return false;

    // Fill in label from address book, if address has an associated label
    QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
    if(!associatedLabel.isEmpty())
    {
        ui->addAsLabel->setText(associatedLabel);
        return true;
    }

    return false;
}
<commit_msg>ui: Better tab order in send coins entry<commit_after>// Copyright (c) 2011-2013 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "sendcoinsentry.h"
#include "ui_sendcoinsentry.h"

#include "addressbookpage.h"
#include "addresstablemodel.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "walletmodel.h"

#include <QApplication>
#include <QClipboard>

SendCoinsEntry::SendCoinsEntry(QWidget *parent) :
    QStackedWidget(parent),
    ui(new Ui::SendCoinsEntry),
    model(0)
{
    ui->setupUi(this);

    setCurrentWidget(ui->SendCoins);

#ifdef Q_OS_MAC
    ui->payToLayout->setSpacing(4);
#endif
#if QT_VERSION >= 0x040700
    ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
    ui->payTo->setPlaceholderText(tr("Enter a Bitcoin address (e.g. 1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L)"));
#endif
    setFocusProxy(ui->payTo);

    // normal bitcoin address field
    GUIUtil::setupAddressWidget(ui->payTo, this);
    // just a label for displaying bitcoin address(es)
    ui->payTo_is->setFont(GUIUtil::bitcoinAddressFont());
}

SendCoinsEntry::~SendCoinsEntry()
{
    delete ui;
}

void SendCoinsEntry::on_pasteButton_clicked()
{
    // Paste text from clipboard into recipient field
    ui->payTo->setText(QApplication::clipboard()->text());
}

void SendCoinsEntry::on_addressBookButton_clicked()
{
    if(!model)
        return;
    AddressBookPage dlg(AddressBookPage::ForSelection, AddressBookPage::SendingTab, this);
    dlg.setModel(model->getAddressTableModel());
    if(dlg.exec())
    {
        ui->payTo->setText(dlg.getReturnValue());
        ui->payAmount->setFocus();
    }
}

void SendCoinsEntry::on_payTo_textChanged(const QString &address)
{
    updateLabel(address);
}

void SendCoinsEntry::setModel(WalletModel *model)
{
    this->model = model;

    if (model && model->getOptionsModel())
        connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));

    connect(ui->payAmount, SIGNAL(textChanged()), this, SIGNAL(payAmountChanged()));
    connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
    connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked()));
    connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked()));

    clear();
}

void SendCoinsEntry::clear()
{
    // clear UI elements for normal payment
    ui->payTo->clear();
    ui->addAsLabel->clear();
    ui->payAmount->clear();
    // clear UI elements for insecure payment request
    ui->payTo_is->clear();
    ui->memoTextLabel_is->clear();
    ui->payAmount_is->clear();
    // clear UI elements for secure payment request
    ui->payTo_s->clear();
    ui->memoTextLabel_s->clear();
    ui->payAmount_s->clear();

    // update the display unit, to not use the default ("BTC")
    updateDisplayUnit();
}

void SendCoinsEntry::deleteClicked()
{
    emit removeEntry(this);
}

bool SendCoinsEntry::validate()
{
    if (!model)
        return false;

    // Check input validity
    bool retval = true;

    // Skip checks for payment request
    if (recipient.paymentRequest.IsInitialized())
        return retval;

    if (!ui->payTo->hasAcceptableInput() || !model->validateAddress(ui->payTo->text()))
    {
        ui->payTo->setValid(false);
        retval = false;
    }

    if (!ui->payAmount->validate())
    {
        retval = false;
    }

    // Reject dust outputs:
    if (retval && GUIUtil::isDust(ui->payTo->text(), ui->payAmount->value())) {
        ui->payAmount->setValid(false);
        retval = false;
    }

    return retval;
}

SendCoinsRecipient SendCoinsEntry::getValue()
{
    // Payment request
    if (recipient.paymentRequest.IsInitialized())
        return recipient;

    // Normal payment
    recipient.address = ui->payTo->text();
    recipient.label = ui->addAsLabel->text();
    recipient.amount = ui->payAmount->value();

    return recipient;
}

QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
{
    QWidget::setTabOrder(prev, ui->payTo);
    QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
    QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel);
    QWidget::setTabOrder(w, ui->addressBookButton);
    QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
    QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
    return ui->deleteButton;
}

void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
{
    recipient = value;

    if (recipient.paymentRequest.IsInitialized()) // payment request
    {
        if (recipient.authenticatedMerchant.isEmpty()) // insecure
        {
            ui->payTo_is->setText(recipient.address);
            ui->memoTextLabel_is->setText(recipient.message);
            ui->payAmount_is->setValue(recipient.amount);
            ui->payAmount_is->setReadOnly(true);
            setCurrentWidget(ui->SendCoins_InsecurePaymentRequest);
        }
        else // secure
        {
            ui->payTo_s->setText(recipient.authenticatedMerchant);
            ui->memoTextLabel_s->setText(recipient.message);
            ui->payAmount_s->setValue(recipient.amount);
            ui->payAmount_s->setReadOnly(true);
            setCurrentWidget(ui->SendCoins_SecurePaymentRequest);
        }
    }
    else // normal payment
    {
        ui->payTo->setText(recipient.address);
        ui->addAsLabel->setText(recipient.label);
        ui->payAmount->setValue(recipient.amount);
    }
}

void SendCoinsEntry::setAddress(const QString &address)
{
    ui->payTo->setText(address);
    ui->payAmount->setFocus();
}

bool SendCoinsEntry::isClear()
{
    return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
}

void SendCoinsEntry::setFocus()
{
    ui->payTo->setFocus();
}

void SendCoinsEntry::updateDisplayUnit()
{
    if(model && model->getOptionsModel())
    {
        // Update payAmount with the current unit
        ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
        ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
        ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
    }
}

bool SendCoinsEntry::updateLabel(const QString &address)
{
    if(!model)
        return false;

    // Fill in label from address book, if address has an associated label
    QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
    if(!associatedLabel.isEmpty())
    {
        ui->addAsLabel->setText(associatedLabel);
        return true;
    }

    return false;
}
<|endoftext|>


<commit_before>#ifndef SRC_CONFIGURATION_H_
#define SRC_CONFIGURATION_H_

#include <horsewhisperer/horsewhisperer.h>

#include <map>

namespace PXPAgent {

namespace HW = HorseWhisperer;

extern const std::string DEFAULT_SPOOL_DIR;     // used by unit tests
extern const std::string LOGFILE_NAME;          // not configurable

enum Types { Integer, String, Bool, Double };

struct EntryBase {
    // config option name. must match one of the flag names and config file option
    std::string name;
    // cli flag aliases (e.g. --server --serv -s)
    std::string aliases;
    // help string to be displayed by --help flag
    std::string help;
    // Value type
    Types type;
    bool configured = false;
    EntryBase(std::string Name, std::string Aliases,
              std::string Help, Types Type) : name(Name),
                                              aliases(Aliases),
                                              help(Help),
                                              type(Type) {}
};

template <typename T>
struct Entry : EntryBase {
    Entry<T>(std::string Name, std::string Aliases,
             std::string Help, Types Type, T Value) : EntryBase(Name, Aliases, Help, Type),
                                                      value(Value) {}
    // default value (can be empty)
    T value;
};

using Base_ptr = std::unique_ptr<EntryBase>;

class Configuration {
  public:
    struct Error : public std::runtime_error {
        explicit Error(std::string const& msg) : std::runtime_error(msg) {}
    };

    static Configuration& Instance() {
        static Configuration instance {};
        return instance;
    }

    struct Agent {
        std::string modules_dir;
        std::string server_url;
        std::string ca;
        std::string crt;
        std::string key;
        std::string spool_dir;
        std::string modules_config_dir;
        std::string client_type;
    };

    /// Set the configuration entries to their default values.
    /// Unset the initialized_ flag.
    void reset();

    /// Define the default configuration values that depend on the
    /// location of the executable.
    /// Parse the command line arguments and, if specified, the
    /// configuration file, in order to obtain the configuration
    /// values; validate and normalize them.
    /// Enable logging if flagged (flag useful for prevent logging
    /// during testing).
    /// Return a HorseWhisperer::ParseResult value indicating the
    /// parsing outcome (refer to HorseWhisperer).
    /// Throw a HorseWhisperer::flag_validation_error in case such
    /// exception is thrown by a flag validation callback.
    /// Throw a Configuration::Error: if it fails to parse the CLI
    /// arguments; in case of a missing or invalid configuration
    /// value; if the specified config file cannot be parsed or has
    /// any invalid JSON entry.
    HW::ParseResult initialize(int argc, char *argv[],
                               bool enable_logging = true);

    /// Set the start function that will be executed when calling
    /// HorseWhisperer::Start().
    void setStartFunction(std::function<int(std::vector<std::string>)> start_function);

    /// If Configuration was already initialized, return the value
    /// set for the specified flag (NB: the value can be a default);
    /// throw a Configuration::Error such flag is unknown.
    /// If Configuration was not initialized so far, but the
    /// requested flag is known, return the default value; throw a
    /// Configuration::Error otherwise.
    template <typename T>
    T get(std::string flagname) {
        if (initialized_) {
            try {
                return HW::GetFlag<T>(flagname);
            } catch (HW::undefined_flag_error& e) {
                throw Configuration::Error { std::string { e.what() } };
            }
        }

        // Configuration instance not initialized; get default
        auto entry = defaults_.find(flagname);
        if (entry == defaults_.end()) {
            throw Configuration::Error { "no default value for " + flagname };
        } else {
            Entry<T>* entry_ptr = (Entry<T>*) entry->second.get();
            return entry_ptr->value;
        }
    }

    /// Set the specified value for a given configuration flag.
    /// Throw an Configuration::Error in case the Configuration was
    /// not initialized so far.
    /// Throw a Configuration::Error in case the specified flag is
    /// unknown or the value is invalid.
    template<typename T>
    void set(std::string flagname, T value) {
        if (!initialized_) {
            throw Configuration::Error { "cannot set configuration value until "
                                         "initialized" };
        }

        try {
            HW::SetFlag<T>(flagname, value);
        } catch (HW::flag_validation_error) {
            throw Configuration::Error { "invalid value for " + flagname };
        } catch (HW::undefined_flag_error) {
            throw Configuration::Error { "unknown flag name: " + flagname };
        }
    }

    /// Ensure all required values are valid. If necessary, expand
    /// file paths to the expected format.
    /// Throw a Configuration::Error if any required file path is
    /// missing or in case of invalid values.
    void validateAndNormalizeConfiguration();

    /// Return the whole agent configuration
    const Agent& getAgentConfiguration() const;

  private:
    bool initialized_;
    std::map<std::string, Base_ptr> defaults_;
    std::string config_file_;
    std::function<int(std::vector<std::string>)> start_function_;
    Agent agent_configuration_;

    Configuration();
    void defineDefaultValues();
    void setDefaultValues();
    void parseConfigFile();
    void setupLogging();
    void setAgentConfiguration();
    void setNonExposedOptions();
};

}  // namespace PXPAgent

#endif  // SRC_CONFIGURATION_H_
<commit_msg>(maint) Add missing stdexcept include<commit_after>#ifndef SRC_CONFIGURATION_H_
#define SRC_CONFIGURATION_H_

#include <horsewhisperer/horsewhisperer.h>

#include <map>
#include <stdexcept>

namespace PXPAgent {

namespace HW = HorseWhisperer;

extern const std::string DEFAULT_SPOOL_DIR;     // used by unit tests
extern const std::string LOGFILE_NAME;          // not configurable

enum Types { Integer, String, Bool, Double };

struct EntryBase {
    // config option name. must match one of the flag names and config file option
    std::string name;
    // cli flag aliases (e.g. --server --serv -s)
    std::string aliases;
    // help string to be displayed by --help flag
    std::string help;
    // Value type
    Types type;
    bool configured = false;
    EntryBase(std::string Name, std::string Aliases,
              std::string Help, Types Type) : name(Name),
                                              aliases(Aliases),
                                              help(Help),
                                              type(Type) {}
};

template <typename T>
struct Entry : EntryBase {
    Entry<T>(std::string Name, std::string Aliases,
             std::string Help, Types Type, T Value) : EntryBase(Name, Aliases, Help, Type),
                                                      value(Value) {}
    // default value (can be empty)
    T value;
};

using Base_ptr = std::unique_ptr<EntryBase>;

class Configuration {
  public:
    struct Error : public std::runtime_error {
        explicit Error(std::string const& msg) : std::runtime_error(msg) {}
    };

    static Configuration& Instance() {
        static Configuration instance {};
        return instance;
    }

    struct Agent {
        std::string modules_dir;
        std::string server_url;
        std::string ca;
        std::string crt;
        std::string key;
        std::string spool_dir;
        std::string modules_config_dir;
        std::string client_type;
    };

    /// Set the configuration entries to their default values.
    /// Unset the initialized_ flag.
    void reset();

    /// Define the default configuration values that depend on the
    /// location of the executable.
    /// Parse the command line arguments and, if specified, the
    /// configuration file, in order to obtain the configuration
    /// values; validate and normalize them.
    /// Enable logging if flagged (flag useful for prevent logging
    /// during testing).
    /// Return a HorseWhisperer::ParseResult value indicating the
    /// parsing outcome (refer to HorseWhisperer).
    /// Throw a HorseWhisperer::flag_validation_error in case such
    /// exception is thrown by a flag validation callback.
    /// Throw a Configuration::Error: if it fails to parse the CLI
    /// arguments; in case of a missing or invalid configuration
    /// value; if the specified config file cannot be parsed or has
    /// any invalid JSON entry.
    HW::ParseResult initialize(int argc, char *argv[],
                               bool enable_logging = true);

    /// Set the start function that will be executed when calling
    /// HorseWhisperer::Start().
    void setStartFunction(std::function<int(std::vector<std::string>)> start_function);

    /// If Configuration was already initialized, return the value
    /// set for the specified flag (NB: the value can be a default);
    /// throw a Configuration::Error such flag is unknown.
    /// If Configuration was not initialized so far, but the
    /// requested flag is known, return the default value; throw a
    /// Configuration::Error otherwise.
    template <typename T>
    T get(std::string flagname) {
        if (initialized_) {
            try {
                return HW::GetFlag<T>(flagname);
            } catch (HW::undefined_flag_error& e) {
                throw Configuration::Error { std::string { e.what() } };
            }
        }

        // Configuration instance not initialized; get default
        auto entry = defaults_.find(flagname);
        if (entry == defaults_.end()) {
            throw Configuration::Error { "no default value for " + flagname };
        } else {
            Entry<T>* entry_ptr = (Entry<T>*) entry->second.get();
            return entry_ptr->value;
        }
    }

    /// Set the specified value for a given configuration flag.
    /// Throw an Configuration::Error in case the Configuration was
    /// not initialized so far.
    /// Throw a Configuration::Error in case the specified flag is
    /// unknown or the value is invalid.
    template<typename T>
    void set(std::string flagname, T value) {
        if (!initialized_) {
            throw Configuration::Error { "cannot set configuration value until "
                                         "initialized" };
        }

        try {
            HW::SetFlag<T>(flagname, value);
        } catch (HW::flag_validation_error) {
            throw Configuration::Error { "invalid value for " + flagname };
        } catch (HW::undefined_flag_error) {
            throw Configuration::Error { "unknown flag name: " + flagname };
        }
    }

    /// Ensure all required values are valid. If necessary, expand
    /// file paths to the expected format.
    /// Throw a Configuration::Error if any required file path is
    /// missing or in case of invalid values.
    void validateAndNormalizeConfiguration();

    /// Return the whole agent configuration
    const Agent& getAgentConfiguration() const;

  private:
    bool initialized_;
    std::map<std::string, Base_ptr> defaults_;
    std::string config_file_;
    std::function<int(std::vector<std::string>)> start_function_;
    Agent agent_configuration_;

    Configuration();
    void defineDefaultValues();
    void setDefaultValues();
    void parseConfigFile();
    void setupLogging();
    void setAgentConfiguration();
    void setNonExposedOptions();
};

}  // namespace PXPAgent

#endif  // SRC_CONFIGURATION_H_
<|endoftext|>


<commit_before>#include <debugger/impl.h>
#include <debugger/io/helper.h>
#include <debugger/io/base.h>
#include <rapidjson/schema.h>
#include <rapidjson/error/en.h>
#include <fstream>

#if 1
#	define log(...)
#else

#include <base/util/format.h>
#include <Windows.h>

template <class... Args>
static void log(const char* fmt, const Args& ... args)
{
	auto s = base::format(fmt, args...);
	OutputDebugStringA(s.c_str());
}

#endif

namespace vscode {

	class file {
	public:
		file(const wchar_t* filename, std::ios_base::openmode mode) {
			file_.open(filename, std::ios::binary | mode);
		}
		~file() {
			file_.close();
		}
		bool is_open() const {
			return !!file_;
		}
		template <class SequenceT>
		SequenceT read() {
			return std::move(SequenceT((std::istreambuf_iterator<char>(file_)), (std::istreambuf_iterator<char>())));
		}
		template <class SequenceT>
		void write(SequenceT buf) {
			std::copy(buf.begin(), buf.end(), std::ostreambuf_iterator<char>(file_));
		}
	private:
		file();
		std::fstream file_;
	};

	bool schema::open(const std::wstring& path)
	{
		file file(path.c_str(), std::ios_base::in);
		if (!file.is_open()) {
			return false;
		}
		std::string buf = file.read<std::string>();
		rapidjson::Document sd;
		if (sd.Parse(buf.data(), buf.size()).HasParseError()) {
			log("Input is not a valid JSON\n");
			log("Error(offset %u): %s\n", static_cast<unsigned>(sd.GetErrorOffset()), rapidjson::GetParseError_En(sd.GetParseError()));
			return false;
		}
		doc.reset(new rapidjson::SchemaDocument(sd));
		return true;
	}

	bool schema::accept(const rapidjson::Document& d) {
		if (!doc) {
			return true;
		}
		rapidjson::SchemaValidator validator(*doc);
		if (!d.Accept(validator))
		{
			rapidjson::StringBuffer sb;
			validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
			log("Invalid schema: %s\n", sb.GetString());
			log("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());
			sb.Clear();
			validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
			log("Invalid document: %s\n", sb.GetString());
			return false;
		}
		return true;
	}

	schema::operator bool() const
	{
		return !!doc;
	}

	rprotocol io_input(io::base* io, schema* schema)
	{
		std::string buf;
		if (!io->input(buf)) {
			return rprotocol();
		}
		rapidjson::Document	d;
		if (d.Parse(buf.data(), buf.size()).HasParseError())
		{
			log("Input is not a valid JSON\n");
			log("Error(offset %u): %s\n", static_cast<unsigned>(d.GetErrorOffset()), rapidjson::GetParseError_En(d.GetParseError()));
			io->close();
			return rprotocol();
		}
		if (schema && !schema->accept(d))
		{
			io->close();
			return rprotocol();
		}
		log("%s\n", buf.data());
		return rprotocol(std::move(d));
	}

	void io_output(io::base* io, const wprotocol& wp)
	{
		if (!wp.IsComplete())
			return;
		if (!io->output(wp.data(), wp.size()))
			return;
		log("%s\n", wp.data());
	}

	void io_output(io::base* io, const rprotocol& rp)
	{
		rapidjson::StringBuffer buffer;
		rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
		rp.Accept(writer);
		io->output(buffer.GetString(), buffer.GetSize());
	}

}
<commit_msg>不需要这个头文件<commit_after>#include <debugger/io/helper.h>
#include <debugger/io/base.h>
#include <rapidjson/schema.h>
#include <rapidjson/error/en.h>
#include <fstream>

#if 1
#	define log(...)
#else

#include <base/util/format.h>
#include <Windows.h>

template <class... Args>
static void log(const char* fmt, const Args& ... args)
{
	auto s = base::format(fmt, args...);
	OutputDebugStringA(s.c_str());
}

#endif

namespace vscode {

	class file {
	public:
		file(const wchar_t* filename, std::ios_base::openmode mode) {
			file_.open(filename, std::ios::binary | mode);
		}
		~file() {
			file_.close();
		}
		bool is_open() const {
			return !!file_;
		}
		template <class SequenceT>
		SequenceT read() {
			return std::move(SequenceT((std::istreambuf_iterator<char>(file_)), (std::istreambuf_iterator<char>())));
		}
		template <class SequenceT>
		void write(SequenceT buf) {
			std::copy(buf.begin(), buf.end(), std::ostreambuf_iterator<char>(file_));
		}
	private:
		file();
		std::fstream file_;
	};

	bool schema::open(const std::wstring& path)
	{
		file file(path.c_str(), std::ios_base::in);
		if (!file.is_open()) {
			return false;
		}
		std::string buf = file.read<std::string>();
		rapidjson::Document sd;
		if (sd.Parse(buf.data(), buf.size()).HasParseError()) {
			log("Input is not a valid JSON\n");
			log("Error(offset %u): %s\n", static_cast<unsigned>(sd.GetErrorOffset()), rapidjson::GetParseError_En(sd.GetParseError()));
			return false;
		}
		doc.reset(new rapidjson::SchemaDocument(sd));
		return true;
	}

	bool schema::accept(const rapidjson::Document& d) {
		if (!doc) {
			return true;
		}
		rapidjson::SchemaValidator validator(*doc);
		if (!d.Accept(validator))
		{
			rapidjson::StringBuffer sb;
			validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
			log("Invalid schema: %s\n", sb.GetString());
			log("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());
			sb.Clear();
			validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
			log("Invalid document: %s\n", sb.GetString());
			return false;
		}
		return true;
	}

	schema::operator bool() const
	{
		return !!doc;
	}

	rprotocol io_input(io::base* io, schema* schema)
	{
		std::string buf;
		if (!io->input(buf)) {
			return rprotocol();
		}
		rapidjson::Document	d;
		if (d.Parse(buf.data(), buf.size()).HasParseError())
		{
			log("Input is not a valid JSON\n");
			log("Error(offset %u): %s\n", static_cast<unsigned>(d.GetErrorOffset()), rapidjson::GetParseError_En(d.GetParseError()));
			io->close();
			return rprotocol();
		}
		if (schema && !schema->accept(d))
		{
			io->close();
			return rprotocol();
		}
		log("%s\n", buf.data());
		return rprotocol(std::move(d));
	}

	void io_output(io::base* io, const wprotocol& wp)
	{
		if (!wp.IsComplete())
			return;
		if (!io->output(wp.data(), wp.size()))
			return;
		log("%s\n", wp.data());
	}

	void io_output(io::base* io, const rprotocol& rp)
	{
		rapidjson::StringBuffer buffer;
		rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
		rp.Accept(writer);
		io->output(buffer.GetString(), buffer.GetSize());
	}

}
<|endoftext|>


<commit_before>// Jubatus: Online machine learning framework for distributed environment
// Copyright (C) 2011 Preferred Infrastructure and Nippon Telegraph and Telephone Corporation.
//
// 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#ifndef JUBATUS_CORE_STORAGE_LOCAL_STORAGE_HPP_
#define JUBATUS_CORE_STORAGE_LOCAL_STORAGE_HPP_

#include <map>
#include <string>
#include <pficommon/data/serialization.h>
#include <pficommon/data/serialization/unordered_map.h>
#include <pficommon/data/unordered_map.h>
#include "storage_base.hpp"
#include "../common/key_manager.hpp"

namespace jubatus {
namespace core {
namespace storage {

typedef pfi::data::unordered_map<uint64_t, val3_t> id_feature_val3_t;
typedef pfi::data::unordered_map<std::string, id_feature_val3_t> id_features3_t;

class local_storage : public storage_base {
 public:
  local_storage();
  ~local_storage();

  void get(const std::string &feature, feature_val1_t& ret);
  void get2(const std::string &feature, feature_val2_t& ret);
  void get3(const std::string &feature, feature_val3_t& ret);

  void inp(const common::sfv_t& sfv, map_feature_val1_t& ret);  // inner product

  void set(
      const std::string& feature,
      const std::string& klass,
      const val1_t& w);
  void set2(
      const std::string& feature,
      const std::string& klass,
      const val2_t& w);
  void set3(
      const std::string& feature,
      const std::string& klass,
      const val3_t& w);

  void get_status(std::map<std::string, std::string>&);

  void update(
      const std::string& feature,
      const std::string& inc_class,
      const std::string& dec_class,
      const val1_t& v);
  void bulk_update(
      const common::sfv_t& sfv,
      float step_width,
      const std::string& inc_class,
      const std::string& dec_class);

  void clear();

  bool save(std::ostream&);
  bool load(std::istream&);
  std::string type() const;

 protected:
  // map_features3_t tbl_;
  id_features3_t tbl_;
  common::key_manager class2id_;

 protected:
  friend class pfi::data::serialization::access;
  template <class Ar>
  void serialize(Ar& ar) {
    ar & MEMBER(tbl_) & MEMBER(class2id_);
  }
};

}  // namespace storage
}  // namespace core
}  // namespace jubatus

#endif  // JUBATUS_CORE_STORAGE_LOCAL_STORAGE_HPP_
<commit_msg>Replaced protected with private in jubatus/core/storage/local_storage.hpp (#347).<commit_after>// Jubatus: Online machine learning framework for distributed environment
// Copyright (C) 2011 Preferred Infrastructure and Nippon Telegraph and Telephone Corporation.
//
// 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#ifndef JUBATUS_CORE_STORAGE_LOCAL_STORAGE_HPP_
#define JUBATUS_CORE_STORAGE_LOCAL_STORAGE_HPP_

#include <map>
#include <string>
#include <pficommon/data/serialization.h>
#include <pficommon/data/serialization/unordered_map.h>
#include <pficommon/data/unordered_map.h>
#include "storage_base.hpp"
#include "../common/key_manager.hpp"

namespace jubatus {
namespace core {
namespace storage {

typedef pfi::data::unordered_map<uint64_t, val3_t> id_feature_val3_t;
typedef pfi::data::unordered_map<std::string, id_feature_val3_t> id_features3_t;

class local_storage : public storage_base {
 public:
  local_storage();
  ~local_storage();

  void get(const std::string &feature, feature_val1_t& ret);
  void get2(const std::string &feature, feature_val2_t& ret);
  void get3(const std::string &feature, feature_val3_t& ret);

  void inp(const common::sfv_t& sfv, map_feature_val1_t& ret);  // inner product

  void set(
      const std::string& feature,
      const std::string& klass,
      const val1_t& w);
  void set2(
      const std::string& feature,
      const std::string& klass,
      const val2_t& w);
  void set3(
      const std::string& feature,
      const std::string& klass,
      const val3_t& w);

  void get_status(std::map<std::string, std::string>&);

  void update(
      const std::string& feature,
      const std::string& inc_class,
      const std::string& dec_class,
      const val1_t& v);
  void bulk_update(
      const common::sfv_t& sfv,
      float step_width,
      const std::string& inc_class,
      const std::string& dec_class);

  void clear();

  bool save(std::ostream&);
  bool load(std::istream&);
  std::string type() const;

 protected:
  // map_features3_t tbl_;
  id_features3_t tbl_;
  common::key_manager class2id_;

 private:
  friend class pfi::data::serialization::access;
  template <class Ar>
  void serialize(Ar& ar) {
    ar & MEMBER(tbl_) & MEMBER(class2id_);
  }
};

}  // namespace storage
}  // namespace core
}  // namespace jubatus

#endif  // JUBATUS_CORE_STORAGE_LOCAL_STORAGE_HPP_
<|endoftext|>


<commit_before>// Copyright (C) 2011 Oliver Schulz <oliver.schulz@tu-dortmund.de>

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>

#include <TROOT.h>
#include <TFile.h>
#include <THashList.h>

#include "../config.h"

#include "util.h"
#include "Selector.h"
#include "Settings.h"
#include "JSON.h"

using namespace std;
using namespace froast;

int settings(int argc, char *argv[], char *envp[]) {
	int nargs = argc-1;
	char **args = argv+1;

	bool jsonOutput = false;
	if ((nargs >= 1) && (string(args[0]) == "-j")) {
		--nargs; ++args;
		jsonOutput = true;
	}

	if (nargs == 0) {
		if (jsonOutput) {
			THashList *nested = Settings::global().exportNested();
			JSON::write(cout, nested) << endl;
			delete nested;
		} else Settings::global().write(cout);
		return 0;
	} else if (nargs == 1) {
		Settings settings;
		TString inFileName(args[0]);
		TString objSpecSep(".root/");
		if (inFileName.EndsWith(".root") || inFileName.Contains(objSpecSep)) {
			TString rootFileName = inFileName;
			TString settingsName = "";
			int idx = inFileName.Index(objSpecSep);
			if (idx >= 0) {
				rootFileName = inFileName(0, idx + objSpecSep.Length() - 1);
				settingsName = inFileName(idx + objSpecSep.Length(), inFileName.Length() - idx - objSpecSep.Length());
			}
			TFile inFile(rootFileName.Data(), "read");
			if (settingsName.Length() > 0) settings.read(&inFile, settingsName.Data());
			else settings.read(&inFile);
		} else if (inFileName.EndsWith(".rootrc")) {
			settings.read(inFileName.Data());
		} else if (inFileName.EndsWith(".json")) {
			ifstream in(inFileName.Data());
			THashList *nested = JSON::read(in);
			settings.importNested(nested);
			delete nested;
		} else {
			cerr << "Unknown file extension, can't read settings from \"" << inFileName << "\"." << endl;
			return 1;
		}
		if (jsonOutput) {
			THashList *nested = settings.exportNested();
			JSON::write(cout, nested) << endl;
			delete nested;
		} else settings.write(cout);
		return 0;
	} else {
		cerr << "Syntax: " << args[0] << " [-j] ROOT_FILE SETTINGS" << endl;
		return 1;
	}
}

int map_single(int argc, char *argv[], char *envp[]) {
	if (argc != 4) {
		cerr << "Syntax: " << argv[0] << " INPUT_FILE MAPPER OUTPUT_FILE" << endl;
		return 1;
	}
	string inFileName = argv[1];
	string mappers = argv[2];
	string outFileName = argv[3];
	Selector::mapSingle(inFileName, mappers, outFileName);

	return 0;
}

int map_multi(int argc, char *argv[], char *envp[]) {
	const size_t firstInputArg = 3;
	if (argc < firstInputArg) {
		cerr << "Syntax: " << argv[0] << " MAPPERS TAG [INPUT]..." << endl;
		return 1;
	}
	string mappers = argv[1];
	string tag = argv[2];
	for (size_t arg = firstInputArg; arg < argc; ++arg) {
		Selector::mapMulti(argv[arg], mappers, tag, arg > firstInputArg);
	}

	return 0;
}

int tabulate(int argc, char *argv[], char *envp[]) {
	int nargs = argc-1;
	char **args = argv+1;

	if (nargs < 2) {
		cerr << "Syntax: " << args[0] << " [-j] ROOT_FILE/TREENAME VAREXP [SELECTION [NENTRIES [STARTENTRY]]]" << endl;
		return 1;
	}

	TString input(args[0]);
	ssize_t splitPos = input.Last('/');
	if ((splitPos < 0) || (splitPos >= input.Length()-1)) {
		cerr << "Error: No tree name specified."  << endl;
		return 1;
	}
	TString inFileName = input(0, splitPos);
	TString treeName = input(splitPos + 1, input.Length() - splitPos - 1);
	TChain chain(treeName);
	chain.Add(inFileName);

	TString varexp(args[1]);
	const TString selection = (nargs > 2) ? args[2] : "";
	ssize_t nEntries = (nargs > 3) ? atol(args[3]) : -1;
	ssize_t startEntry = (nargs > 4) ? atol(args[4]) : 0;
	Selector::tabulate(&chain, cout, varexp, selection, nEntries, startEntry);

	return 0;
}

int main(int argc, char *argv[], char *envp[]) {
	try {
		// Have to tell ROOT to load vector dlls, otherwise ROOT will produce
		// "is not of a class known to ROOT" errors on creation of STL vector
		// branches:
		gROOT->ProcessLine("#include <vector>");

		gSystem->SetProgname(PACKAGE_TARNAME);

		string progName(argv[0]);

		if (argc < 2) {
			cerr << "Syntax: " << progName << " COMMAND ..." << endl << endl;
			cerr << "Commands: " << endl;
			cerr << "  settings" << endl;
			cerr << "  map-single" << endl;
			cerr << "  map-multi" << endl;
			cerr << "  tabulate" << endl;
			return 1;
		}

		string cmd(argv[1]);

		int cmd_argc = argc - 1;
		char **cmd_argv = new char*[cmd_argc];
		cmd_argv[0] = strdup((progName + " " + cmd).c_str());
		for (int i = 1; i < cmd_argc; ++i) cmd_argv[i] = strdup(argv[i+1]);
		cmd_argv = argv + 1;

		if (cmd == "settings") return settings(cmd_argc, cmd_argv, envp);
		else if (cmd == "map-single") return map_single(cmd_argc, cmd_argv, envp);
		else if (cmd == "map-multi") return map_multi(cmd_argc, cmd_argv, envp);
		else if (cmd == "tabulate") return tabulate(cmd_argc, cmd_argv, envp);
		else {
			cerr << "ERROR: " << progName << " does not support command \"" << cmd << "\"" << endl;
		}

		for (int i = 0; i < cmd_argc; ++i) ::free(cmd_argv[i]);
		delete [] cmd_argv;
	}
	catch(std::exception &e) {
		cerr << endl << endl << "Exception: " << e.what() << endl << endl;

		return 1;
	}
}
<commit_msg>Documentation of usage of manticore<commit_after>// Copyright (C) 2011 Oliver Schulz <oliver.schulz@tu-dortmund.de>

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>

#include <TROOT.h>
#include <TFile.h>
#include <THashList.h>

#include "../config.h"

#include "util.h"
#include "Selector.h"
#include "Settings.h"
#include "JSON.h"

/*!	\mainpage	Programme to evaluate CPG pulse shape data
	*
	* Syntax: froast COMMAND ... \n
	* Commands:
	*	- settings [-j] INPUTFILE
	*	- map-single INPUT_FILE MAPPERS OUTPUTFILE
	*	- map-multi MAPPER OUTPUTFILE_TAG INPUTFILES
	*	- tabulate ROOT_FILE/TREENAME VAREXP [SELECTION [NENTRIES [STARTENTRY]]]
	*
	* With the settings option the settings from processed ROOT files or .rootrc can be read
	* out and with the -j option converted to json (output on the screen). \n
	* With the map-multi option one input file can be processed. See froast::Selector::mapSingle for
	* more information on the input parameters. \n
	* With the map-multi option several input files can be processed. See froast::Selector::mapSingle for
	* more information on the input parameters. \n
*/

using namespace std;
using namespace froast;

int settings(int argc, char *argv[], char *envp[]) {

	int nargs = argc-1;
	char **args = argv+1;

	bool jsonOutput = false;
	if ((nargs >= 1) && (string(args[0]) == "-j")) {
		--nargs; ++args;
		jsonOutput = true;
	}

	if (nargs == 0) {
		if (jsonOutput) {
			THashList *nested = Settings::global().exportNested();
			JSON::write(cout, nested) << endl;
			delete nested;
		} else Settings::global().write(cout);
		return 0;
	} else if (nargs == 1) {
		Settings settings;
		TString inFileName(args[0]);
		TString objSpecSep(".root/");
		if (inFileName.EndsWith(".root") || inFileName.Contains(objSpecSep)) {
			TString rootFileName = inFileName;
			TString settingsName = "";
			int idx = inFileName.Index(objSpecSep);
			if (idx >= 0) {
				rootFileName = inFileName(0, idx + objSpecSep.Length() - 1);
				settingsName = inFileName(idx + objSpecSep.Length(), inFileName.Length() - idx - objSpecSep.Length());
			}
			TFile inFile(rootFileName.Data(), "read");
			if (settingsName.Length() > 0) settings.read(&inFile, settingsName.Data());
			else settings.read(&inFile);
		} else if (inFileName.EndsWith(".rootrc")) {
			settings.read(inFileName.Data());
		} else if (inFileName.EndsWith(".json")) {
			ifstream in(inFileName.Data());
			THashList *nested = JSON::read(in);
			settings.importNested(nested);
			delete nested;
		} else {
			cerr << "Unknown file extension, can't read settings from \"" << inFileName << "\"." << endl;
			return 1;
		}
		if (jsonOutput) {
			THashList *nested = settings.exportNested();
			JSON::write(cout, nested) << endl;
			delete nested;
		} else settings.write(cout);
		return 0;
	} else {
		cerr << "Syntax: " << args[0] << " [-j] ROOT_FILE SETTINGS" << endl;
		return 1;
	}
}

int map_single(int argc, char *argv[], char *envp[]) {
	if (argc != 4) {
		cerr << "Syntax: " << argv[0] << " INPUT_FILE MAPPER OUTPUT_FILE" << endl;
		return 1;
	}
	string inFileName = argv[1];
	string mappers = argv[2];
	string outFileName = argv[3];
	Selector::mapSingle(inFileName, mappers, outFileName);

	return 0;
}

int map_multi(int argc, char *argv[], char *envp[]) {
	const size_t firstInputArg = 3;
	if (argc < firstInputArg) {
		cerr << "Syntax: " << argv[0] << " MAPPERS TAG [INPUT]..." << endl;
		return 1;
	}
	string mappers = argv[1];
	string tag = argv[2];
	for (size_t arg = firstInputArg; arg < argc; ++arg) {
		// -> inputfilename(s), mappers, filename extension tag, bool noRecompile
		// By default the selector is compiled (++ ROOT compile option).
		// If there are more than one inputfile, the selector is not recompiled
		Selector::mapMulti(argv[arg], mappers, tag, arg > firstInputArg);
	}

	return 0;
}

int tabulate(int argc, char *argv[], char *envp[]) {
	int nargs = argc-1;
	char **args = argv+1;

	if (nargs < 2) {
		cerr << "Syntax: " << args[0] << " [-j] ROOT_FILE/TREENAME VAREXP [SELECTION [NENTRIES [STARTENTRY]]]" << endl;
		return 1;
	}

	TString input(args[0]);
	ssize_t splitPos = input.Last('/');
	if ((splitPos < 0) || (splitPos >= input.Length()-1)) {
		cerr << "Error: No tree name specified."  << endl;
		return 1;
	}
	TString inFileName = input(0, splitPos);
	TString treeName = input(splitPos + 1, input.Length() - splitPos - 1);
	TChain chain(treeName);
	chain.Add(inFileName);

	TString varexp(args[1]);
	const TString selection = (nargs > 2) ? args[2] : "";
	ssize_t nEntries = (nargs > 3) ? atol(args[3]) : -1;
	ssize_t startEntry = (nargs > 4) ? atol(args[4]) : 0;
	Selector::tabulate(&chain, cout, varexp, selection, nEntries, startEntry);

	return 0;
}

int main(int argc, char *argv[], char *envp[]) {
	try {
		// Have to tell ROOT to load vector dlls, otherwise ROOT will produce
		// "is not of a class known to ROOT" errors on creation of STL vector
		// branches:
		gROOT->ProcessLine("#include <vector>");

		gSystem->SetProgname(PACKAGE_TARNAME);

		string progName(argv[0]);

		if (argc < 2) {
			cerr << "Syntax: " << progName << " COMMAND ..." << endl << endl;
			cerr << "Commands: " << endl;
			cerr << "  settings" << endl;
			cerr << "  map-single" << endl;
			cerr << "  map-multi" << endl;
			cerr << "  tabulate" << endl;
			return 1;
		}

		string cmd(argv[1]);

		int cmd_argc = argc - 1;
		char **cmd_argv = new char*[cmd_argc];
		cmd_argv[0] = strdup((progName + " " + cmd).c_str());
		for (int i = 1; i < cmd_argc; ++i) cmd_argv[i] = strdup(argv[i+1]);
		cmd_argv = argv + 1;

		if (cmd == "settings") return settings(cmd_argc, cmd_argv, envp);
		else if (cmd == "map-single") return map_single(cmd_argc, cmd_argv, envp);
		else if (cmd == "map-multi") return map_multi(cmd_argc, cmd_argv, envp);
		else if (cmd == "tabulate") return tabulate(cmd_argc, cmd_argv, envp);
		else {
			cerr << "ERROR: " << progName << " does not support command \"" << cmd << "\"" << endl;
		}

		for (int i = 0; i < cmd_argc; ++i) ::free(cmd_argv[i]);
		delete [] cmd_argv;
	}
	catch(std::exception &e) {
		cerr << endl << endl << "Exception: " << e.what() << endl << endl;

		return 1;
	}
}
<|endoftext|>


<commit_before><commit_msg>INTEGRATION: CWS changefileheader (1.11.124); FILE MERGED 2008/03/31 17:15:32 rt 1.11.124.1: #i87441# Change license header to LPGL v3.<commit_after><|endoftext|>


<commit_before>// StateSensor.cc

#include "lib.h"
#include "StateSensor.h"

using namespace std;

StateSensor::StateSensor()
  : state(INITIAL)
{
  logWrite(SENSOR, "State change to INITIAL");
}

StateSensor::~StateSensor()
{
}

int StateSensor::getState(void) const
{
  if (sendValid || ackValid)
  {
    return state;
  }
  else
  {
    logWrite(ERROR,
             "StateSensor::getState() called with invalid data");
    return INITIAL;

  }
}

bool StateSensor::isSaturated(void) const
{
  if (sendValid || ackValid)
  {
    return saturated;
  }
  else
  {
    logWrite(ERROR,
             "StateSensor::isSaturated() called with invalid data");
    return false;
  }
}

void StateSensor::localSend(PacketInfo * packet)
{
  ackValid = false;
  sendValid = true;
  if (packet->tcp->syn && state == INITIAL)
  {
    state = AFTER_SYN;
    logWrite(SENSOR, "State change to AFTER_SYN");
  }
  else if (packet->tcp->syn)
  {
    logWrite(ERROR, "Sent a SYN packet out of order");
    sendValid = false;
  }
  else if (! packet->tcp->syn && state == AFTER_SYN_ACK)
  {
    state = ESTABLISHED;
    logWrite(SENSOR, "State change to ESTABLISHED");
  }
  calculateSaturated(packet);
}

void StateSensor::localAck(PacketInfo * packet)
{
  sendValid = false;
  ackValid = true;
  if (packet->tcp->syn && packet->tcp->ack && state == AFTER_SYN)
  {
    state = AFTER_SYN_ACK;
    logWrite(SENSOR, "State change to AFTER_SYN_ACK");
  }
  else if (packet->tcp->syn && packet->tcp->ack)
  {
    logWrite(ERROR, "Received a SYNACK packet out of order");
    ackValid = false;
  }
  calculateSaturated(packet);
}

void StateSensor::calculateSaturated(PacketInfo * packet)
{
  unsigned int snd_cwnd = packet->kernel->tcpi_snd_cwnd;
  unsigned int snd_ssthresh = packet->kernel->tcpi_snd_ssthresh;
  unsigned int window = (static_cast<unsigned int>(htons(packet->tcp->window))
    << packet->kernel->tcpi_rcv_wscale);
  unsigned int unacked = packet->kernel->tcpi_unacked * 1448;
  logWrite(SENSOR, "stateEstablished=%d,bufferFull=%d", state == ESTABLISHED,
           packet->bufferFull);
  logWrite(SENSOR, "snd_cwnd=%u,snd_ssthresh=%u,window=%u,unacked=%u",
           snd_cwnd, snd_ssthresh, window, unacked);
  saturated = (state == ESTABLISHED
               && packet->bufferFull
               // and *not* in slow start
               && !(snd_cwnd < snd_ssthresh || window <= unacked));
}
<commit_msg>If we seem to have gotten a SYNACK out of order, treat it as okay and just set the state to ESTABLISHED.<commit_after>// StateSensor.cc

#include "lib.h"
#include "StateSensor.h"

using namespace std;

StateSensor::StateSensor()
  : state(INITIAL)
{
  logWrite(SENSOR, "State change to INITIAL");
}

StateSensor::~StateSensor()
{
}

int StateSensor::getState(void) const
{
  if (sendValid || ackValid)
  {
    return state;
  }
  else
  {
    logWrite(ERROR,
             "StateSensor::getState() called with invalid data");
    return INITIAL;

  }
}

bool StateSensor::isSaturated(void) const
{
  if (sendValid || ackValid)
  {
    return saturated;
  }
  else
  {
    logWrite(ERROR,
             "StateSensor::isSaturated() called with invalid data");
    return false;
  }
}

void StateSensor::localSend(PacketInfo * packet)
{
  ackValid = false;
  sendValid = true;
  if (packet->tcp->syn && state == INITIAL)
  {
    state = AFTER_SYN;
    logWrite(SENSOR, "State change to AFTER_SYN");
  }
  else if (packet->tcp->syn)
  {
    logWrite(ERROR, "Sent a SYN packet out of order");
    sendValid = false;
  }
  else if (! packet->tcp->syn && state == AFTER_SYN_ACK)
  {
    state = ESTABLISHED;
    logWrite(SENSOR, "State change to ESTABLISHED");
  }
  calculateSaturated(packet);
}

void StateSensor::localAck(PacketInfo * packet)
{
  sendValid = false;
  ackValid = true;
  if (packet->tcp->syn && packet->tcp->ack && state == AFTER_SYN)
  {
    state = AFTER_SYN_ACK;
    logWrite(SENSOR, "State change to AFTER_SYN_ACK");
  }
  else if (packet->tcp->syn && packet->tcp->ack)
  {
    logWrite(ERROR, "Received a SYNACK packet out of order");
    //ackValid = false;
    state = ESTABLISHED;
  }
  calculateSaturated(packet);
}

void StateSensor::calculateSaturated(PacketInfo * packet)
{
  unsigned int snd_cwnd = packet->kernel->tcpi_snd_cwnd;
  unsigned int snd_ssthresh = packet->kernel->tcpi_snd_ssthresh;
  unsigned int window = (static_cast<unsigned int>(htons(packet->tcp->window))
    << packet->kernel->tcpi_rcv_wscale);
  unsigned int unacked = packet->kernel->tcpi_unacked * 1448;
  logWrite(SENSOR, "stateEstablished=%d,bufferFull=%d", state == ESTABLISHED,
           packet->bufferFull);
  logWrite(SENSOR, "snd_cwnd=%u,snd_ssthresh=%u,window=%u,unacked=%u",
           snd_cwnd, snd_ssthresh, window, unacked);
  saturated = (state == ESTABLISHED
               && packet->bufferFull
               // and *not* in slow start
               && !(snd_cwnd < snd_ssthresh || window <= unacked));
}
<|endoftext|>