<commit_before>/*
 * Copyright (C) 2008-2010 The QXmpp developers
 *
 * Author:
 *	Manjeet Dahiya
 *
 * Source:
 *	http://code.google.com/p/qxmpp
 *
 * This file is a part of QXmpp library.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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.
 *
 */

#include "chatMsgGraphicsItem.h"
#include <QPainter>
#include <QTextDocument>
#include <QFontMetrics>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QTime>

QLinearGradient getGradient(const QColor &col, const QRectF &rect)
{
    QLinearGradient g(rect.topLeft(), rect.bottomLeft());

    qreal hue = col.hueF();
    qreal value = col.valueF();
    qreal saturation = col.saturationF();

    QColor c = col;
    c.setHsvF(hue, 0.42 * saturation, 0.98 * value);
    g.setColorAt(0, c);
    c.setHsvF(hue, 0.58 * saturation, 0.95 * value);
    g.setColorAt(0.25, c);
    c.setHsvF(hue, 0.70 * saturation, 0.93 * value);
    g.setColorAt(0.5, c);

    c.setHsvF(hue, 0.95 * saturation, 0.9 * value);
    g.setColorAt(0.501, c);
    c.setHsvF(hue * 0.95, 0.95 * saturation, 0.95 * value);
    g.setColorAt(0.75, c);
    c.setHsvF(hue * 0.90, 0.95 * saturation, 1 * value);
    g.setColorAt(1.0, c);

    return g;
}

QLinearGradient darken(const QLinearGradient &gradient)
{
    QGradientStops stops = gradient.stops();
    for (int i = 0; i < stops.size(); ++i) {
        QColor color = stops.at(i).second;
        stops[i].second = color.darker(160);
    }

    QLinearGradient g = gradient;
    g.setStops(stops);
    return g;
}

void drawPath(QPainter *p, const QPainterPath &path,
              const QColor &col, const QString &name, int textWidth,
              bool dark = false)
{
    const QRectF pathRect = path.boundingRect();

    const QLinearGradient baseGradient = getGradient(col, pathRect);
    const QLinearGradient darkGradient = darken(baseGradient);

    p->save();

   // p->setOpacity(0.25);

    //glow
//    if (dark)
//        p->strokePath(path, QPen(darkGradient, 6));
//    else
//        p->strokePath(path, QPen(baseGradient, 6));

    p->setOpacity(1.0);

    //fill
    if (dark)
        p->fillPath(path, darkGradient);
    else
        p->fillPath(path, baseGradient);

    QLinearGradient g(pathRect.topLeft(), pathRect.topRight());
    g.setCoordinateMode(QGradient::ObjectBoundingMode);

    p->setOpacity(0.2);
    p->fillPath(path, g);

    p->setOpacity(0.5);

    // highlight
//    if (dark)
//        p->strokePath(path, QPen(col.lighter(160).darker(160), 2));
//    else
//        p->strokePath(path, QPen(col.lighter(160), 2));

    p->setOpacity(1.0);

    p->restore();
}

chatMsgGraphicsItem::chatMsgGraphicsItem(QGraphicsItem * parent):QGraphicsPathItem(parent),
            m_spikeWidth(9),
            m_spikeHeight(6),
            m_cornerRadius(10),
            m_textSpacing(4), m_color(Qt::yellow)
{
    setPath(createPath());
//    setFlags(QGraphicsItem::ItemIsMovable);

    QFont font;
    QFontMetrics fm(font);
    m_timeStampWidth = fm.width(getTime()) + 4;
}

void chatMsgGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->setRenderHint(QPainter::Antialiasing);
    drawPath(painter, path(), m_color, getText(), getTextWidth());

//    int spike_x = m_spikeWidth;
//    int spike_y = m_spikeHeight;
//    int corner = m_cornerRadius;
//    int length = m_width - spike_x;
//    int offset = spike_x;
    QFont font;
    font.setBold(true);
    QTextDocument textDoc(getText());
    QTextOption textOp;
    textOp.setWrapMode(QTextOption::WrapAnywhere);
    textOp.setAlignment(Qt::AlignLeft);
    textDoc.setDefaultTextOption(textOp);
    textDoc.setTextWidth(getTextWidth());
    textDoc.setDefaultFont(font);

    painter->setPen(Qt::white);
    painter->setFont(font);
    int height = (int) textDoc.size().height();
    painter->drawText(m_spikeWidth + m_cornerRadius, 4, getTextWidth(), height,
                      Qt::AlignLeft|Qt::TextWrapAnywhere, getText());

//    painter->setPen(Qt::gray);
    painter->setPen(Qt::black);

//    font.setBold(false);
    painter->setFont(font);
    painter->drawText(-m_boxStartLength, 0, m_boxStartLength, m_height,
                      Qt::AlignRight|Qt::AlignBottom, getName());

    font.setBold(false);
    painter->setPen(Qt::gray);
    painter->setFont(font);

    int timeWidth;
    if(m_timeStampWidth > m_boxStartLength)
        timeWidth = m_timeStampWidth;
    else
        timeWidth = m_boxStartLength;

    painter->drawText(getMaxWidth() + 6, 0, timeWidth - 6, m_height,
                      Qt::AlignBottom|Qt::AlignLeft, getTime());
}

void chatMsgGraphicsItem::setText(const QString& text)
{
    m_text = text;
    calculateWidth();
    setPath(createPath());
}

void chatMsgGraphicsItem::setMaxWidth(int width)
{
    m_maxWidth = width;
    setPath(createPath());
}

void chatMsgGraphicsItem::setViewWidth(int width)
{
    //25 for scrollbar
    setMaxWidth(width - getBoxStartLength() - 25);
}

int chatMsgGraphicsItem::getMaxWidth() const
{
    return m_maxWidth;
}

void chatMsgGraphicsItem::setAlignment(Alignment align)
{
    m_alignment = align;
    setPath(createPath());
}

QPainterPath chatMsgGraphicsItem::createPath()
{
    calculateWidth();
    int spike_x = m_spikeWidth;
    int spike_y = m_spikeHeight;
    int corner = m_cornerRadius;
    int length = m_width - spike_x;
    int offset = spike_x;

    QPainterPath messageBoxPath;
    messageBoxPath.moveTo(0 + offset, m_height - corner);
    QRectF rect(offset - 2*spike_x, m_height - corner - spike_y, 2*spike_x, 2*spike_y);
    messageBoxPath.arcMoveTo(rect, -90.0);
    messageBoxPath.arcTo(rect, 270, 90.0);
    messageBoxPath.lineTo(0 + offset, corner);
    messageBoxPath.arcTo(0 + offset, 0, 2*corner, 2*corner, 180, -90.0);
    messageBoxPath.lineTo(length - corner, 0);
    messageBoxPath.arcTo(length + offset - corner*2, 0, 2*corner, 2*corner, 90, -90.0);
    messageBoxPath.lineTo(length + offset, m_height - corner);
    messageBoxPath.arcTo(length + offset - corner*2, m_height - 2*corner, 2*corner, 2*corner, 0, -90.0);
    messageBoxPath.lineTo(offset + corner, m_height);
    messageBoxPath.arcTo(offset, m_height - 2*corner, 2*corner, 2*corner, 270, -45.0);
    messageBoxPath.closeSubpath();

    return messageBoxPath;
}

QString chatMsgGraphicsItem::getText() const
{
    return m_text;
}

int chatMsgGraphicsItem::getTextWidth() const
{
    return getMaxWidth() - m_spikeWidth - m_cornerRadius*2;
}

void chatMsgGraphicsItem::calculateWidth()
{
    QFont font;
    font.setBold(true);
    QTextDocument textDoc(m_text);
    textDoc.setDefaultFont(font);
    int idealWidth = (int)textDoc.size().width();
    textDoc.setTextWidth(getTextWidth());
    m_height = (int)textDoc.size().height();

    if(idealWidth < getTextWidth())
    {
        m_width = idealWidth + m_spikeWidth + m_cornerRadius;
    }
    else
        m_width = getMaxWidth();
}

void chatMsgGraphicsItem::setName(const QString& name)
{
    m_name = name;
    if(name != "Me")
        m_color = QColor(0, 210, 250);
    else
        m_color = QColor(250, 188, 239);
}

QString chatMsgGraphicsItem::getName() const
{
    return m_name;
}

QString chatMsgGraphicsItem::getTime() const
{
    return QTime::currentTime().toString("hh:mm");
}

void chatMsgGraphicsItem::setBoxStartLength(int length)
{
    m_boxStartLength = length;
}

int chatMsgGraphicsItem::getBoxStartLength() const
{
    return m_boxStartLength;
}

void chatMsgGraphicsItem::setColor(const QColor& color)
{
    m_color = color;
}

QRectF chatMsgGraphicsItem::boundingRect() const
{
    QRectF rect = QGraphicsPathItem::boundingRect();
    rect.setLeft(-getBoxStartLength());

    int timeWidth;
    if(m_timeStampWidth > m_boxStartLength)
        timeWidth = m_timeStampWidth;
    else
        timeWidth = m_boxStartLength;
    rect.setRight(getMaxWidth() + timeWidth);
    return rect;
}
<commit_msg>remove unnecessary includes<commit_after>/*
 * Copyright (C) 2008-2010 The QXmpp developers
 *
 * Author:
 *	Manjeet Dahiya
 *
 * Source:
 *	http://code.google.com/p/qxmpp
 *
 * This file is a part of QXmpp library.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * 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.
 *
 */

#include "chatMsgGraphicsItem.h"

#include <QPainter>
#include <QTextDocument>
#include <QTime>

QLinearGradient getGradient(const QColor &col, const QRectF &rect)
{
    QLinearGradient g(rect.topLeft(), rect.bottomLeft());

    qreal hue = col.hueF();
    qreal value = col.valueF();
    qreal saturation = col.saturationF();

    QColor c = col;
    c.setHsvF(hue, 0.42 * saturation, 0.98 * value);
    g.setColorAt(0, c);
    c.setHsvF(hue, 0.58 * saturation, 0.95 * value);
    g.setColorAt(0.25, c);
    c.setHsvF(hue, 0.70 * saturation, 0.93 * value);
    g.setColorAt(0.5, c);

    c.setHsvF(hue, 0.95 * saturation, 0.9 * value);
    g.setColorAt(0.501, c);
    c.setHsvF(hue * 0.95, 0.95 * saturation, 0.95 * value);
    g.setColorAt(0.75, c);
    c.setHsvF(hue * 0.90, 0.95 * saturation, 1 * value);
    g.setColorAt(1.0, c);

    return g;
}

QLinearGradient darken(const QLinearGradient &gradient)
{
    QGradientStops stops = gradient.stops();
    for (int i = 0; i < stops.size(); ++i) {
        QColor color = stops.at(i).second;
        stops[i].second = color.darker(160);
    }

    QLinearGradient g = gradient;
    g.setStops(stops);
    return g;
}

void drawPath(QPainter *p, const QPainterPath &path,
              const QColor &col, const QString &name, int textWidth,
              bool dark = false)
{
    const QRectF pathRect = path.boundingRect();

    const QLinearGradient baseGradient = getGradient(col, pathRect);
    const QLinearGradient darkGradient = darken(baseGradient);

    p->save();

   // p->setOpacity(0.25);

    //glow
//    if (dark)
//        p->strokePath(path, QPen(darkGradient, 6));
//    else
//        p->strokePath(path, QPen(baseGradient, 6));

    p->setOpacity(1.0);

    //fill
    if (dark)
        p->fillPath(path, darkGradient);
    else
        p->fillPath(path, baseGradient);

    QLinearGradient g(pathRect.topLeft(), pathRect.topRight());
    g.setCoordinateMode(QGradient::ObjectBoundingMode);

    p->setOpacity(0.2);
    p->fillPath(path, g);

    p->setOpacity(0.5);

    // highlight
//    if (dark)
//        p->strokePath(path, QPen(col.lighter(160).darker(160), 2));
//    else
//        p->strokePath(path, QPen(col.lighter(160), 2));

    p->setOpacity(1.0);

    p->restore();
}

chatMsgGraphicsItem::chatMsgGraphicsItem(QGraphicsItem * parent):QGraphicsPathItem(parent),
            m_spikeWidth(9),
            m_spikeHeight(6),
            m_cornerRadius(10),
            m_textSpacing(4), m_color(Qt::yellow)
{
    setPath(createPath());
//    setFlags(QGraphicsItem::ItemIsMovable);

    QFont font;
    QFontMetrics fm(font);
    m_timeStampWidth = fm.width(getTime()) + 4;
}

void chatMsgGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->setRenderHint(QPainter::Antialiasing);
    drawPath(painter, path(), m_color, getText(), getTextWidth());

//    int spike_x = m_spikeWidth;
//    int spike_y = m_spikeHeight;
//    int corner = m_cornerRadius;
//    int length = m_width - spike_x;
//    int offset = spike_x;
    QFont font;
    font.setBold(true);
    QTextDocument textDoc(getText());
    QTextOption textOp;
    textOp.setWrapMode(QTextOption::WrapAnywhere);
    textOp.setAlignment(Qt::AlignLeft);
    textDoc.setDefaultTextOption(textOp);
    textDoc.setTextWidth(getTextWidth());
    textDoc.setDefaultFont(font);

    painter->setPen(Qt::white);
    painter->setFont(font);
    int height = (int) textDoc.size().height();
    painter->drawText(m_spikeWidth + m_cornerRadius, 4, getTextWidth(), height,
                      Qt::AlignLeft|Qt::TextWrapAnywhere, getText());

//    painter->setPen(Qt::gray);
    painter->setPen(Qt::black);

//    font.setBold(false);
    painter->setFont(font);
    painter->drawText(-m_boxStartLength, 0, m_boxStartLength, m_height,
                      Qt::AlignRight|Qt::AlignBottom, getName());

    font.setBold(false);
    painter->setPen(Qt::gray);
    painter->setFont(font);

    int timeWidth;
    if(m_timeStampWidth > m_boxStartLength)
        timeWidth = m_timeStampWidth;
    else
        timeWidth = m_boxStartLength;

    painter->drawText(getMaxWidth() + 6, 0, timeWidth - 6, m_height,
                      Qt::AlignBottom|Qt::AlignLeft, getTime());
}

void chatMsgGraphicsItem::setText(const QString& text)
{
    m_text = text;
    calculateWidth();
    setPath(createPath());
}

void chatMsgGraphicsItem::setMaxWidth(int width)
{
    m_maxWidth = width;
    setPath(createPath());
}

void chatMsgGraphicsItem::setViewWidth(int width)
{
    //25 for scrollbar
    setMaxWidth(width - getBoxStartLength() - 25);
}

int chatMsgGraphicsItem::getMaxWidth() const
{
    return m_maxWidth;
}

void chatMsgGraphicsItem::setAlignment(Alignment align)
{
    m_alignment = align;
    setPath(createPath());
}

QPainterPath chatMsgGraphicsItem::createPath()
{
    calculateWidth();
    int spike_x = m_spikeWidth;
    int spike_y = m_spikeHeight;
    int corner = m_cornerRadius;
    int length = m_width - spike_x;
    int offset = spike_x;

    QPainterPath messageBoxPath;
    messageBoxPath.moveTo(0 + offset, m_height - corner);
    QRectF rect(offset - 2*spike_x, m_height - corner - spike_y, 2*spike_x, 2*spike_y);
    messageBoxPath.arcMoveTo(rect, -90.0);
    messageBoxPath.arcTo(rect, 270, 90.0);
    messageBoxPath.lineTo(0 + offset, corner);
    messageBoxPath.arcTo(0 + offset, 0, 2*corner, 2*corner, 180, -90.0);
    messageBoxPath.lineTo(length - corner, 0);
    messageBoxPath.arcTo(length + offset - corner*2, 0, 2*corner, 2*corner, 90, -90.0);
    messageBoxPath.lineTo(length + offset, m_height - corner);
    messageBoxPath.arcTo(length + offset - corner*2, m_height - 2*corner, 2*corner, 2*corner, 0, -90.0);
    messageBoxPath.lineTo(offset + corner, m_height);
    messageBoxPath.arcTo(offset, m_height - 2*corner, 2*corner, 2*corner, 270, -45.0);
    messageBoxPath.closeSubpath();

    return messageBoxPath;
}

QString chatMsgGraphicsItem::getText() const
{
    return m_text;
}

int chatMsgGraphicsItem::getTextWidth() const
{
    return getMaxWidth() - m_spikeWidth - m_cornerRadius*2;
}

void chatMsgGraphicsItem::calculateWidth()
{
    QFont font;
    font.setBold(true);
    QTextDocument textDoc(m_text);
    textDoc.setDefaultFont(font);
    int idealWidth = (int)textDoc.size().width();
    textDoc.setTextWidth(getTextWidth());
    m_height = (int)textDoc.size().height();

    if(idealWidth < getTextWidth())
    {
        m_width = idealWidth + m_spikeWidth + m_cornerRadius;
    }
    else
        m_width = getMaxWidth();
}

void chatMsgGraphicsItem::setName(const QString& name)
{
    m_name = name;
    if(name != "Me")
        m_color = QColor(0, 210, 250);
    else
        m_color = QColor(250, 188, 239);
}

QString chatMsgGraphicsItem::getName() const
{
    return m_name;
}

QString chatMsgGraphicsItem::getTime() const
{
    return QTime::currentTime().toString("hh:mm");
}

void chatMsgGraphicsItem::setBoxStartLength(int length)
{
    m_boxStartLength = length;
}

int chatMsgGraphicsItem::getBoxStartLength() const
{
    return m_boxStartLength;
}

void chatMsgGraphicsItem::setColor(const QColor& color)
{
    m_color = color;
}

QRectF chatMsgGraphicsItem::boundingRect() const
{
    QRectF rect = QGraphicsPathItem::boundingRect();
    rect.setLeft(-getBoxStartLength());

    int timeWidth;
    if(m_timeStampWidth > m_boxStartLength)
        timeWidth = m_timeStampWidth;
    else
        timeWidth = m_boxStartLength;
    rect.setRight(getMaxWidth() + timeWidth);
    return rect;
}
<|endoftext|>


<commit_before>#include "CSpaceWarpFilter.hpp"
#include "Graphics/CGraphics.hpp"
#include "Graphics/CBooRenderer.hpp"

#define WARP_RAMP_RES 32

namespace urde
{

void CSpaceWarpFilter::GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& ctx)
{
    u8 data[WARP_RAMP_RES+1][WARP_RAMP_RES+1][4] = {};
    float halfRes = WARP_RAMP_RES / 2.f;
    for (int y=0 ; y<WARP_RAMP_RES+1 ; ++y)
    {
        for (int x=0 ; x<WARP_RAMP_RES+1 ; ++x)
        {
            zeus::CVector2f vec((x - halfRes) / halfRes, (y - halfRes) / halfRes);
            float mag = vec.magnitude();
            if (mag < 1.f && vec.canBeNormalized())
            {
                vec.normalize();
                vec *= std::sqrt(mag);
            }
            data[y][x][0] = zeus::clamp(0, int((((vec.x / 2.f + 0.5f) - x / float(WARP_RAMP_RES)) + 0.5f) * 255), 255);
            data[y][x][1] = zeus::clamp(0, int((((vec.y / 2.f + 0.5f) - y / float(WARP_RAMP_RES)) + 0.5f) * 255), 255);
        }
    }
    m_warpTex = ctx.newStaticTexture(WARP_RAMP_RES+1, WARP_RAMP_RES+1, 1,
                                     boo::TextureFormat::RGBA8, data[0],
                                     (WARP_RAMP_RES+1) * (WARP_RAMP_RES+1) * 4);
}

CSpaceWarpFilter::CSpaceWarpFilter()
{
    m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
    {
        GenerateWarpRampTex(ctx);
        struct Vert
        {
            zeus::CVector2f m_pos;
            zeus::CVector2f m_uv;
        } verts[4] =
        {
        {{-1.0, -1.0}, {0.0, 0.0}},
        {{-1.0,  1.0}, {0.0, 1.0}},
        {{ 1.0, -1.0}, {1.0, 0.0}},
        {{ 1.0,  1.0}, {1.0, 1.0}},
        };
        m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4);
        m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
        m_dataBind = TShader<CSpaceWarpFilter>::BuildShaderDataBinding(ctx, *this);
        return true;
    });
}

void CSpaceWarpFilter::draw(const zeus::CVector2f& pt)
{
    /* Indirect coords are full-texture sampling when warp is completely in viewport */
    m_uniform.m_indXf[1][1] = 1.f;
    m_uniform.m_indXf[0][0] = 1.f;
    m_uniform.m_indXf[2][0] = 0.f;
    m_uniform.m_indXf[2][1] = 0.f;

    /* Warp effect is fixed at 192x192 rectangle in original (1/2.5 viewport height) */
    m_uniform.m_matrix[1][1] = 1.f / 2.5f;
    m_uniform.m_matrix[0][0] = m_uniform.m_matrix[1][1] / CGraphics::g_ProjAspect;

    SClipScreenRect clipRect = {};
    clipRect.x4_left = ((pt[0] - m_uniform.m_matrix[0][0]) / 2.f + 0.5f) * CGraphics::g_ViewportResolution.x;
    if (clipRect.x4_left >= CGraphics::g_ViewportResolution.x)
        return;
    clipRect.x8_top = ((pt[1] - m_uniform.m_matrix[1][1]) / 2.f + 0.5f) * CGraphics::g_ViewportResolution.y;
    if (clipRect.x8_top >= CGraphics::g_ViewportResolution.y)
        return;
    clipRect.xc_width = CGraphics::g_ViewportResolution.x * m_uniform.m_matrix[0][0];
    if (clipRect.x4_left + clipRect.xc_width <= 0)
        return;
    clipRect.x10_height = CGraphics::g_ViewportResolution.y * m_uniform.m_matrix[1][1];
    if (clipRect.x8_top + clipRect.x10_height <= 0)
        return;

    float oldW = clipRect.xc_width;
    if (clipRect.x4_left < 0)
    {
        clipRect.xc_width += clipRect.x4_left;
        m_uniform.m_indXf[0][0] = clipRect.xc_width / oldW;
        m_uniform.m_indXf[2][0] = -clipRect.x4_left / oldW;
        clipRect.x4_left = 0;
    }

    float oldH = clipRect.x10_height;
    if (clipRect.x8_top < 0)
    {
        clipRect.x10_height += clipRect.x8_top;
        m_uniform.m_indXf[1][1] = clipRect.x10_height / oldH;
        m_uniform.m_indXf[2][1] = -clipRect.x8_top / oldH;
        clipRect.x8_top = 0;
    }

    float tmp = clipRect.x4_left + clipRect.xc_width;
    if (tmp >= CGraphics::g_ViewportResolution.x)
    {
        clipRect.xc_width = CGraphics::g_ViewportResolution.x - clipRect.x4_left;
        m_uniform.m_indXf[0][0] = clipRect.xc_width / oldW;
    }

    tmp = clipRect.x8_top + clipRect.x10_height;
    if (tmp >= CGraphics::g_ViewportResolution.y)
    {
        clipRect.x10_height = CGraphics::g_ViewportResolution.y - clipRect.x8_top;
        m_uniform.m_indXf[1][1] = clipRect.x10_height / oldH;
    }

    /* Transform UV coordinates of rectangle within viewport and sampled scene texels (clamped to viewport bounds) */
    zeus::CVector2f vp{CGraphics::g_ViewportResolution.x, CGraphics::g_ViewportResolution.y};
    m_uniform.m_matrix[0][0] = clipRect.xc_width / vp.x;
    m_uniform.m_matrix[1][1] = clipRect.x10_height / vp.y;
    m_uniform.m_matrix[2][0] = pt.x + (1.f / vp.x);
    m_uniform.m_matrix[2][1] = pt.y + (1.f / vp.y);

    if (clipRect.x4_left + clipRect.xc_width < CGraphics::g_ViewportResolution.x)
        clipRect.xc_width += 1;
    if (clipRect.x8_top + clipRect.x10_height < CGraphics::g_ViewportResolution.y)
        clipRect.x10_height += 1;
    CGraphics::ResolveSpareTexture(clipRect);

    m_uniform.m_strength.x = m_uniform.m_matrix[1][1] * m_strength * 0.5f;
    m_uniform.m_strength.y = m_uniform.m_matrix[1][1] * m_strength * 0.5f;
    m_uniBuf->load(&m_uniform, sizeof(m_uniform));

    CGraphics::g_BooMainCommandQueue->setShaderDataBinding(m_dataBind);
    CGraphics::g_BooMainCommandQueue->draw(0, 4);
}

URDE_SPECIALIZE_SHADER(CSpaceWarpFilter)

}
<commit_msg>Minor coordinate fix<commit_after>#include "CSpaceWarpFilter.hpp"
#include "Graphics/CGraphics.hpp"
#include "Graphics/CBooRenderer.hpp"

#define WARP_RAMP_RES 32

namespace urde
{

void CSpaceWarpFilter::GenerateWarpRampTex(boo::IGraphicsDataFactory::Context& ctx)
{
    u8 data[WARP_RAMP_RES+1][WARP_RAMP_RES+1][4] = {};
    float halfRes = WARP_RAMP_RES / 2.f;
    for (int y=0 ; y<WARP_RAMP_RES+1 ; ++y)
    {
        for (int x=0 ; x<WARP_RAMP_RES+1 ; ++x)
        {
            zeus::CVector2f vec((x - halfRes) / halfRes, (y - halfRes) / halfRes);
            float mag = vec.magnitude();
            if (mag < 1.f && vec.canBeNormalized())
            {
                vec.normalize();
                vec *= std::sqrt(mag);
            }
            data[y][x][0] = zeus::clamp(0, int((((vec.x / 2.f + 0.5f) - x / float(WARP_RAMP_RES)) + 0.5f) * 255), 255);
            data[y][x][1] = zeus::clamp(0, int((((vec.y / 2.f + 0.5f) - y / float(WARP_RAMP_RES)) + 0.5f) * 255), 255);
        }
    }
    m_warpTex = ctx.newStaticTexture(WARP_RAMP_RES+1, WARP_RAMP_RES+1, 1,
                                     boo::TextureFormat::RGBA8, data[0],
                                     (WARP_RAMP_RES+1) * (WARP_RAMP_RES+1) * 4);
}

CSpaceWarpFilter::CSpaceWarpFilter()
{
    m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
    {
        GenerateWarpRampTex(ctx);
        struct Vert
        {
            zeus::CVector2f m_pos;
            zeus::CVector2f m_uv;
        } verts[4] =
        {
        {{-1.0, -1.0}, {0.0, 0.0}},
        {{-1.0,  1.0}, {0.0, 1.0}},
        {{ 1.0, -1.0}, {1.0, 0.0}},
        {{ 1.0,  1.0}, {1.0, 1.0}},
        };
        m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4);
        m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
        m_dataBind = TShader<CSpaceWarpFilter>::BuildShaderDataBinding(ctx, *this);
        return true;
    });
}

void CSpaceWarpFilter::draw(const zeus::CVector2f& pt)
{
    /* Indirect coords are full-texture sampling when warp is completely in viewport */
    m_uniform.m_indXf[1][1] = 1.f;
    m_uniform.m_indXf[0][0] = 1.f;
    m_uniform.m_indXf[2][0] = 0.f;
    m_uniform.m_indXf[2][1] = 0.f;

    /* Warp effect is fixed at 192x192 rectangle in original (1/2.5 viewport height) */
    m_uniform.m_matrix[1][1] = 1.f / 2.5f;
    m_uniform.m_matrix[0][0] = m_uniform.m_matrix[1][1] / CGraphics::g_ProjAspect;

    SClipScreenRect clipRect = {};
    clipRect.x4_left = ((pt[0] - m_uniform.m_matrix[0][0]) / 2.f + 0.5f) * CGraphics::g_ViewportResolution.x;
    if (clipRect.x4_left >= CGraphics::g_ViewportResolution.x)
        return;
    clipRect.x8_top = ((pt[1] - m_uniform.m_matrix[1][1]) / 2.f + 0.5f) * CGraphics::g_ViewportResolution.y;
    if (clipRect.x8_top >= CGraphics::g_ViewportResolution.y)
        return;
    clipRect.xc_width = CGraphics::g_ViewportResolution.x * m_uniform.m_matrix[0][0];
    if (clipRect.x4_left + clipRect.xc_width <= 0)
        return;
    clipRect.x10_height = CGraphics::g_ViewportResolution.y * m_uniform.m_matrix[1][1];
    if (clipRect.x8_top + clipRect.x10_height <= 0)
        return;

    float oldW = clipRect.xc_width;
    if (clipRect.x4_left < 0)
    {
        clipRect.xc_width += clipRect.x4_left;
        m_uniform.m_indXf[0][0] = clipRect.xc_width / oldW;
        m_uniform.m_indXf[2][0] = -clipRect.x4_left / oldW;
        clipRect.x4_left = 0;
    }

    float oldH = clipRect.x10_height;
    if (clipRect.x8_top < 0)
    {
        clipRect.x10_height += clipRect.x8_top;
        m_uniform.m_indXf[1][1] = clipRect.x10_height / oldH;
        m_uniform.m_indXf[2][1] = -clipRect.x8_top / oldH;
        clipRect.x8_top = 0;
    }

    float tmp = clipRect.x4_left + clipRect.xc_width;
    if (tmp >= CGraphics::g_ViewportResolution.x)
    {
        clipRect.xc_width = CGraphics::g_ViewportResolution.x - clipRect.x4_left;
        m_uniform.m_indXf[0][0] = clipRect.xc_width / oldW;
    }

    tmp = clipRect.x8_top + clipRect.x10_height;
    if (tmp >= CGraphics::g_ViewportResolution.y)
    {
        clipRect.x10_height = CGraphics::g_ViewportResolution.y - clipRect.x8_top;
        m_uniform.m_indXf[1][1] = clipRect.x10_height / oldH;
    }

    /* Transform UV coordinates of rectangle within viewport and sampled scene texels (clamped to viewport bounds) */
    zeus::CVector2f vp{CGraphics::g_ViewportResolution.x, CGraphics::g_ViewportResolution.y};
    m_uniform.m_matrix[0][0] = clipRect.xc_width / vp.x;
    m_uniform.m_matrix[1][1] = clipRect.x10_height / vp.y;
    m_uniform.m_matrix[2][0] = pt.x + (1.f / vp.x);
    m_uniform.m_matrix[2][1] = pt.y + (1.f / vp.y);

    if (clipRect.x4_left + clipRect.xc_width < CGraphics::g_ViewportResolution.x)
        clipRect.xc_width += 1;
    if (clipRect.x8_top + clipRect.x10_height < CGraphics::g_ViewportResolution.y)
        clipRect.x10_height += 1;
    CGraphics::ResolveSpareTexture(clipRect);

    m_uniform.m_strength.x = m_uniform.m_matrix[0][0] * m_strength * 0.5f;
    m_uniform.m_strength.y = m_uniform.m_matrix[1][1] * m_strength * 0.5f;
    m_uniBuf->load(&m_uniform, sizeof(m_uniform));

    CGraphics::g_BooMainCommandQueue->setShaderDataBinding(m_dataBind);
    CGraphics::g_BooMainCommandQueue->draw(0, 4);
}

URDE_SPECIALIZE_SHADER(CSpaceWarpFilter)

}
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/nest/p9_pcie_config.C $    */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
//-----------------------------------------------------------------------------------
//
/// @file p9_pcie_config.C
/// @brief Configure the PHBs
///
// *HWP HWP Owner: Christina Graves clgraves@us.ibm.com
// *HWP FW Owner: Thi Tran thi@us.ibm.com
// *HWP Team: Nest
// *HWP Level: 1
// *HWP Consumed by:
//-----------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------------
#include <p9_pcie_config.H>

extern "C" {

//-----------------------------------------------------------------------------------
// HWP entry point
//-----------------------------------------------------------------------------------
    fapi2::ReturnCode p9_pcie_config(const
                                     fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& i_target)
    {
        //return code
        fapi2::ReturnCode rc;

        //mark HWP entry
        FAPI_INF("p9_pcie_config: Entering...\n");

        do
        {

        }
        while(0);

        return rc;
    }

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

// *HWP HWP Owner: Christina Graves clgraves@us.ibm.com
// *HWP FW Owner: Thi Tran thi@us.ibm.com
// *HWP Team: Nest
// *HWP Level: 1
// *HWP Consumed by: HB

//-----------------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------------
#include <p9_pcie_config.H>

//-----------------------------------------------------------------------------------
// Function definitions
//-----------------------------------------------------------------------------------
fapi2::ReturnCode p9_pcie_config(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& i_target)
{
    FAPI_INF("Start");
    FAPI_INF("End");
    return fapi2::current_err;
}
<|endoftext|>


<commit_before>#include "<%= $cur_module.name %>Base.h"

#include "logging/RhoLog.h"
#undef DEFAULT_LOGCATEGORY
#define DEFAULT_LOGCATEGORY "<%= $cur_module.name %>"

#include "ruby/ext/rho/rhoruby.h"
#include "common/StringConverter.h"
#include "common/AutoPointer.h"

using namespace rho;
using namespace rho::common;

extern "C"
{

void rho_wm_impl_performOnUiThread(rho::common::IRhoRunnable* pTask);
VALUE getRuby_<%= $cur_module.name %>_Module();

<% if $cur_module.is_template_default_instance %>
VALUE rb_<%= $cur_module.name %>_s_default(VALUE klass)
{
    rho::String strDefaultID = <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()->getDefaultID();

    return rho_ruby_create_object_with_id( klass, strDefaultID.c_str() );
}

VALUE rb_<%= $cur_module.name %>_s_setDefault(VALUE klass, VALUE valObj)
{
    const char* szID = rho_ruby_get_object_id( valObj );
    <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()->setDefaultID(szID);

    return rho_ruby_get_NIL();
}
<% end %>

extern "C" static void
string_iter(const char* szVal, void* par)
{
    rho::Vector<rho::String>& ar = *((rho::Vector<rho::String>*)(par));
    ar.addElement( szVal );
}

static void getStringArrayFromValue(VALUE val, rho::Vector<rho::String>& res)
{
    rho_ruby_enum_strary(val, string_iter, &res);
}

extern "C" static void hash_eachstr(const char* szName, const char* szVal, void* par)
{
    rho::Hashtable<rho::String, rho::String>& hash = *((rho::Hashtable<rho::String, rho::String>*)(par));
    hash.put( szName, szVal );
}

static void getStringHashFromValue(VALUE val, rho::Hashtable<rho::String, rho::String>& res)
{
    rho_ruby_enum_strhash(val, hash_eachstr, &res);
}

<% $cur_module.methods.each do |module_method|
   if module_method.access == ModuleMethod::ACCESS_STATIC %>
<%= api_generator_MakeRubyMethodDecl($cur_module.name, module_method, true)%><%
else %>
static VALUE _api_generator_<%= $cur_module.name %>_<%= module_method.native_name %>(int argc, VALUE *argv, <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>I<%= $cur_module.name %>* pObj)<%
end %>
{
    rho::apiGenerator::CMethodResult oRes;
<% if module_method.result != nil
    result_type = nil
    if MethodParam::BASE_TYPES.include?(module_method.result.type)
      result_type = module_method.result.item_type
    else
      result_type = module_method.result.type;
    end

if api_generator_isSelfModule( $cur_module, result_type) %>
    oRes.setRubyObjectClass( getRuby_<%= $cur_module.name %>_Module() );<%
elsif result_type && result_type.length()>0 && !MethodParam::BASE_TYPES.include?(result_type) %>
    oRes.setRubyObjectClassPath( "<%= result_type %>" );<%
end; end %>
    rho::common::IRhoRunnable* pFunctor = 0;
    bool bUseCallback = false;
    int nCallbackArg = 0;<%

functor_params = ""; first_arg = 0;
module_method.params.each do |param| %>
    nCallbackArg = <%= first_arg + 1 %>;<%
if !param.can_be_nil %>
    if ( argc == <%= first_arg %> )
    {
        oRes.setArgError("Wrong number of arguments: " + convertToStringA(argc) + " instead of " + convertToStringA(<%= module_method.params.size() %>) );
        return oRes.toRuby();
    }<%
end

if param.type == MethodParam::TYPE_STRING %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_string(argv[<%= first_arg %>]) )
        {
            arg<%= first_arg %> = getStringFromValue(argv[<%= first_arg %>]);
<% if first_arg == 0 %>
            oRes.setStringParam(getStringFromValue(argv[<%= first_arg %>]));
<% end %>
        }
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if param.type == MethodParam::TYPE_INT %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_integer(argv[<%= first_arg %>]) )
            arg<%= first_arg %> = rho_ruby_get_int(argv[<%= first_arg %>]);
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if param.type == MethodParam::TYPE_BOOL %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_boolean(argv[<%= first_arg %>]) )
            arg<%= first_arg %> = rho_ruby_get_bool(argv[<%= first_arg %>]) ? true : false;
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if param.type == MethodParam::TYPE_DOUBLE %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_double(argv[<%= first_arg %>]) )
            arg<%= first_arg %> = rho_ruby_get_double(argv[<%= first_arg %>]);
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if param.type == MethodParam::TYPE_ARRAY %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_array(argv[<%= first_arg %>]) )
            getStringArrayFromValue(argv[<%= first_arg %>], arg<%= first_arg %>);
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if param.type == MethodParam::TYPE_HASH %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_hash(argv[<%= first_arg %>]) )
            getStringHashFromValue(argv[<%= first_arg %>], arg<%= first_arg %>);
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if !MethodParam::BASE_TYPES.include?(param.type) %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        <%  type_name = param.type;
            if api_generator_isSelfModule( $cur_module, param.type); type_name = api_generator_getRubyModuleFullName($cur_module); %>
            if ( rho_ruby_is_object_of_class(argv[<%= first_arg %>], getRuby_<%= $cur_module.name %>_Module()) )<%
        else %>
            if ( rho_ruby_is_object_of_class(argv[<%= first_arg %>], rho_ruby_get_class_byname("<%=param.type%>") ) )<%
        end %>
            arg<%= first_arg %> = rho_ruby_get_object_id( argv[<%= first_arg %>] );
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{type_name}\"" %> );
            return oRes.toRuby();
        }
    }<%
end
functor_params += "arg#{first_arg}, "
first_arg = first_arg+1
end %>
    if ( argc > nCallbackArg )
    {
<% if module_method.has_callback == ModuleMethod::CALLBACK_NONE %>
        oRes.setArgError("Wrong number of arguments: " + convertToStringA(argc) + " instead of " + convertToStringA(<%= module_method.params.size() %>) );
        return oRes.toRuby();<%
else %>
        if ( rho_ruby_is_proc(argv[nCallbackArg]) || rho_ruby_is_method(argv[nCallbackArg]) )
        {
            oRes.setRubyCallbackProc( argv[nCallbackArg] );
        }else if ( rho_ruby_is_string(argv[nCallbackArg]) )
        {
            oRes.setRubyCallback( getStringFromValue(argv[nCallbackArg]) );
        }else
        {
            oRes.setArgError("Type error: callback should be String");
            return oRes.toRuby();
        }

        oRes.setCallInUIThread(<%= (module_method.run_in_thread == ModuleMethod::RUN_IN_THREAD_UI) ? "true" : "false" %>);
        if ( argc > nCallbackArg + 1 )
        {
            if ( !rho_ruby_is_string(argv[nCallbackArg + 1]) )
            {
                oRes.setArgError("Type error: callback parameter should be String");
                return oRes.toRuby();
            }

            oRes.setCallbackParam( getStringFromValue(argv[nCallbackArg + 1]) );
        }

        bUseCallback = true;<%
end %>
    }<%
if module_method.has_callback == ModuleMethod::CALLBACK_MANDATORY%>
    else
    {
        oRes.setArgError("Wrong number of arguments: " + convertToStringA(argc) + " instead of " + convertToStringA(<%= module_method.params.size()+1 %>) + ".Mandatory Callback parameter is mised." );
        return oRes.toRuby();
    }<%
end

if module_method.access != ModuleMethod::ACCESS_STATIC %>
    pFunctor = rho_makeInstanceClassFunctor<%= module_method.params.size()+1%>( pObj, &<%= api_generator_cpp_MakeNamespace($cur_module.parents)%>I<%= $cur_module.name %>::<%= module_method.native_name %>, <%= functor_params %> oRes );<%
else %>
    pFunctor = rho_makeInstanceClassFunctor<%= module_method.params.size()+1%>( <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS(), &<%= api_generator_cpp_MakeNamespace($cur_module.parents)%>I<%= $cur_module.name %>Singleton::<%= module_method.native_name %>, <%= functor_params %> oRes );<%
end

if module_method.run_in_thread == ModuleMethod::RUN_IN_THREAD_UI %>
    rho_wm_impl_performOnUiThread( pFunctor );<%
elsif (module_method.run_in_thread == ModuleMethod::RUN_IN_THREAD_MODULE) || (module_method.run_in_thread == ModuleMethod::RUN_IN_THREAD_SEPARATED) %>
    <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()->addCommandToQueue( pFunctor );<%
else if module_method.run_in_thread != ModuleMethod::RUN_IN_THREAD_NONE %>

    if ( bUseCallback )
        <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()->addCommandToQueue( pFunctor );
    else <%
end %>
    {
        delete pFunctor;

<% if module_method.access != ModuleMethod::ACCESS_STATIC %>
        pObj-><%= module_method.native_name %>( <%= functor_params %> oRes );<%
else %>
        <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()-><%= module_method.native_name %>( <%= functor_params %> oRes );<%
end %>

    }<%
end %>
    return oRes.toRuby();
}

<% if module_method.access != ModuleMethod::ACCESS_STATIC %>
<%= api_generator_MakeRubyMethodDecl($cur_module.name, module_method, module_method.access == ModuleMethod::ACCESS_STATIC)%>
{
    const char* szID = rho_ruby_get_object_id( obj );
    <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>I<%= $cur_module.name %>* pObj =  <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::getInstance()->getModuleByID(szID);

    return _api_generator_<%= $cur_module.name %>_<%= module_method.native_name %>(argc, argv, pObj);
}
<% end %>

<% if $cur_module.is_template_default_instance && module_method.access == ModuleMethod::ACCESS_INSTANCE%>
<%= api_generator_MakeRubyMethodDecl($cur_module.name + "_def", module_method, true)%>
{
    rho::String strDefaultID = <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()->getDefaultID();
    <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>I<%= $cur_module.name %>* pObj = <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::getInstance()->getModuleByID(strDefaultID);

    return _api_generator_<%= $cur_module.name %>_<%= module_method.native_name %>(argc, argv, pObj);
}
<% end %>
<% end %>

}<commit_msg>fix compile errors on XCode<commit_after>#include "<%= $cur_module.name %>Base.h"

#include "logging/RhoLog.h"
#undef DEFAULT_LOGCATEGORY
#define DEFAULT_LOGCATEGORY "<%= $cur_module.name %>"

#include "ruby/ext/rho/rhoruby.h"
#include "common/StringConverter.h"
#include "common/AutoPointer.h"

using namespace rho;
using namespace rho::common;

extern "C"
{

void rho_wm_impl_performOnUiThread(rho::common::IRhoRunnable* pTask);
VALUE getRuby_<%= $cur_module.name %>_Module();

<% if $cur_module.is_template_default_instance %>
VALUE rb_<%= $cur_module.name %>_s_default(VALUE klass)
{
    rho::String strDefaultID = <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()->getDefaultID();

    return rho_ruby_create_object_with_id( klass, strDefaultID.c_str() );
}

VALUE rb_<%= $cur_module.name %>_s_setDefault(VALUE klass, VALUE valObj)
{
    const char* szID = rho_ruby_get_object_id( valObj );
    <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()->setDefaultID(szID);

    return rho_ruby_get_NIL();
}
<% end %>

static void string_iter(const char* szVal, void* par)
{
    rho::Vector<rho::String>& ar = *((rho::Vector<rho::String>*)(par));
    ar.addElement( szVal );
}

static void getStringArrayFromValue(VALUE val, rho::Vector<rho::String>& res)
{
    rho_ruby_enum_strary(val, string_iter, &res);
}

static void hash_eachstr(const char* szName, const char* szVal, void* par)
{
    rho::Hashtable<rho::String, rho::String>& hash = *((rho::Hashtable<rho::String, rho::String>*)(par));
    hash.put( szName, szVal );
}

static void getStringHashFromValue(VALUE val, rho::Hashtable<rho::String, rho::String>& res)
{
    rho_ruby_enum_strhash(val, hash_eachstr, &res);
}

<% $cur_module.methods.each do |module_method|
   if module_method.access == ModuleMethod::ACCESS_STATIC %>
<%= api_generator_MakeRubyMethodDecl($cur_module.name, module_method, true)%><%
else %>
static VALUE _api_generator_<%= $cur_module.name %>_<%= module_method.native_name %>(int argc, VALUE *argv, <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>I<%= $cur_module.name %>* pObj)<%
end %>
{
    rho::apiGenerator::CMethodResult oRes;
<% if module_method.result != nil
    result_type = nil
    if MethodParam::BASE_TYPES.include?(module_method.result.type)
      result_type = module_method.result.item_type
    else
      result_type = module_method.result.type;
    end

if api_generator_isSelfModule( $cur_module, result_type) %>
    oRes.setRubyObjectClass( getRuby_<%= $cur_module.name %>_Module() );<%
elsif result_type && result_type.length()>0 && !MethodParam::BASE_TYPES.include?(result_type) %>
    oRes.setRubyObjectClassPath( "<%= result_type %>" );<%
end; end %>
    rho::common::IRhoRunnable* pFunctor = 0;
    bool bUseCallback = false;
    int nCallbackArg = 0;<%

functor_params = ""; first_arg = 0;
module_method.params.each do |param| %>
    nCallbackArg = <%= first_arg + 1 %>;<%
if !param.can_be_nil %>
    if ( argc == <%= first_arg %> )
    {
        oRes.setArgError("Wrong number of arguments: " + convertToStringA(argc) + " instead of " + convertToStringA(<%= module_method.params.size() %>) );
        return oRes.toRuby();
    }<%
end

if param.type == MethodParam::TYPE_STRING %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_string(argv[<%= first_arg %>]) )
        {
            arg<%= first_arg %> = getStringFromValue(argv[<%= first_arg %>]);
<% if first_arg == 0 %>
            oRes.setStringParam(getStringFromValue(argv[<%= first_arg %>]));
<% end %>
        }
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if param.type == MethodParam::TYPE_INT %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_integer(argv[<%= first_arg %>]) )
            arg<%= first_arg %> = rho_ruby_get_int(argv[<%= first_arg %>]);
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if param.type == MethodParam::TYPE_BOOL %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_boolean(argv[<%= first_arg %>]) )
            arg<%= first_arg %> = rho_ruby_get_bool(argv[<%= first_arg %>]) ? true : false;
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if param.type == MethodParam::TYPE_DOUBLE %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_double(argv[<%= first_arg %>]) )
            arg<%= first_arg %> = rho_ruby_get_double(argv[<%= first_arg %>]);
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if param.type == MethodParam::TYPE_ARRAY %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_array(argv[<%= first_arg %>]) )
            getStringArrayFromValue(argv[<%= first_arg %>], arg<%= first_arg %>);
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if param.type == MethodParam::TYPE_HASH %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        if ( rho_ruby_is_hash(argv[<%= first_arg %>]) )
            getStringHashFromValue(argv[<%= first_arg %>], arg<%= first_arg %>);
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{param.type.downcase}\"" %> );
            return oRes.toRuby();
        }
    }
<% end

if !MethodParam::BASE_TYPES.include?(param.type) %>
    <%= api_generator_cpp_makeNativeType(param.type) %> arg<%= first_arg %>;
    if ( argc > <%= first_arg %> )
    {
        <%  type_name = param.type;
            if api_generator_isSelfModule( $cur_module, param.type); type_name = api_generator_getRubyModuleFullName($cur_module); %>
            if ( rho_ruby_is_object_of_class(argv[<%= first_arg %>], getRuby_<%= $cur_module.name %>_Module()) )<%
        else %>
            if ( rho_ruby_is_object_of_class(argv[<%= first_arg %>], rho_ruby_get_class_byname("<%=param.type%>") ) )<%
        end %>
            arg<%= first_arg %> = rho_ruby_get_object_id( argv[<%= first_arg %>] );
        else if (!rho_ruby_is_NIL(argv[<%= first_arg %>]))
        {
            oRes.setArgError("Type error: argument " <%= "\"#{first_arg}\"" %> " should be " <%= "\"#{type_name}\"" %> );
            return oRes.toRuby();
        }
    }<%
end
functor_params += "arg#{first_arg}, "
first_arg = first_arg+1
end %>
    if ( argc > nCallbackArg )
    {
<% if module_method.has_callback == ModuleMethod::CALLBACK_NONE %>
        oRes.setArgError("Wrong number of arguments: " + convertToStringA(argc) + " instead of " + convertToStringA(<%= module_method.params.size() %>) );
        return oRes.toRuby();<%
else %>
        if ( rho_ruby_is_proc(argv[nCallbackArg]) || rho_ruby_is_method(argv[nCallbackArg]) )
        {
            oRes.setRubyCallbackProc( argv[nCallbackArg] );
        }else if ( rho_ruby_is_string(argv[nCallbackArg]) )
        {
            oRes.setRubyCallback( getStringFromValue(argv[nCallbackArg]) );
        }else
        {
            oRes.setArgError("Type error: callback should be String");
            return oRes.toRuby();
        }

        oRes.setCallInUIThread(<%= (module_method.run_in_thread == ModuleMethod::RUN_IN_THREAD_UI) ? "true" : "false" %>);
        if ( argc > nCallbackArg + 1 )
        {
            if ( !rho_ruby_is_string(argv[nCallbackArg + 1]) )
            {
                oRes.setArgError("Type error: callback parameter should be String");
                return oRes.toRuby();
            }

            oRes.setCallbackParam( getStringFromValue(argv[nCallbackArg + 1]) );
        }

        bUseCallback = true;<%
end %>
    }<%
if module_method.has_callback == ModuleMethod::CALLBACK_MANDATORY%>
    else
    {
        oRes.setArgError("Wrong number of arguments: " + convertToStringA(argc) + " instead of " + convertToStringA(<%= module_method.params.size()+1 %>) + ".Mandatory Callback parameter is mised." );
        return oRes.toRuby();
    }<%
end

if module_method.access != ModuleMethod::ACCESS_STATIC %>
    pFunctor = rho_makeInstanceClassFunctor<%= module_method.params.size()+1%>( pObj, &<%= api_generator_cpp_MakeNamespace($cur_module.parents)%>I<%= $cur_module.name %>::<%= module_method.native_name %>, <%= functor_params %> oRes );<%
else %>
    pFunctor = rho_makeInstanceClassFunctor<%= module_method.params.size()+1%>( <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS(), &<%= api_generator_cpp_MakeNamespace($cur_module.parents)%>I<%= $cur_module.name %>Singleton::<%= module_method.native_name %>, <%= functor_params %> oRes );<%
end

if module_method.run_in_thread == ModuleMethod::RUN_IN_THREAD_UI %>
    rho_wm_impl_performOnUiThread( pFunctor );<%
elsif (module_method.run_in_thread == ModuleMethod::RUN_IN_THREAD_MODULE) || (module_method.run_in_thread == ModuleMethod::RUN_IN_THREAD_SEPARATED) %>
    <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()->addCommandToQueue( pFunctor );<%
else if module_method.run_in_thread != ModuleMethod::RUN_IN_THREAD_NONE %>

    if ( bUseCallback )
        <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()->addCommandToQueue( pFunctor );
    else <%
end %>
    {
        delete pFunctor;

<% if module_method.access != ModuleMethod::ACCESS_STATIC %>
        pObj-><%= module_method.native_name %>( <%= functor_params %> oRes );<%
else %>
        <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()-><%= module_method.native_name %>( <%= functor_params %> oRes );<%
end %>

    }<%
end %>
    return oRes.toRuby();
}

<% if module_method.access != ModuleMethod::ACCESS_STATIC %>
<%= api_generator_MakeRubyMethodDecl($cur_module.name, module_method, module_method.access == ModuleMethod::ACCESS_STATIC)%>
{
    const char* szID = rho_ruby_get_object_id( obj );
    <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>I<%= $cur_module.name %>* pObj =  <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::getInstance()->getModuleByID(szID);

    return _api_generator_<%= $cur_module.name %>_<%= module_method.native_name %>(argc, argv, pObj);
}
<% end %>

<% if $cur_module.is_template_default_instance && module_method.access == ModuleMethod::ACCESS_INSTANCE%>
<%= api_generator_MakeRubyMethodDecl($cur_module.name + "_def", module_method, true)%>
{
    rho::String strDefaultID = <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::get<%= $cur_module.name %>SingletonS()->getDefaultID();
    <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>I<%= $cur_module.name %>* pObj = <%= api_generator_cpp_MakeNamespace($cur_module.parents)%>C<%= $cur_module.name %>FactoryBase::getInstance()->getModuleByID(strDefaultID);

    return _api_generator_<%= $cur_module.name %>_<%= module_method.native_name %>(argc, argv, pObj);
}
<% end %>
<% end %>

}<|endoftext|>


<commit_before><commit_msg>Since we do such a large amount of string comparisions (mainly in ReactWith involving 3 elements, I changed it so we're doing comparisons on the Symbol of the element rather than the name.  Should cut down on cost quite significantly<commit_after><|endoftext|>


<commit_before>#pragma once

#include <inttypes.h>
#include <time.h>

uint64_t nanotime();

/**
   Base class for benchmarks. Includes stuff for automatically
   running, making statistics, etc.
 */
class Benchmark {
public:
	Benchmark(int num_trials = 10);

	void run();

	virtual void setup();
	virtual void cleanup();

	double timePerIteration() const;
	double timePerIterationMicros() const;

	void setNumTrials(int num_trials);
	int getNumTrials() const;

protected:
	// These are the things that each benchmark needs to implement.

	virtual void run_iteration() = 0;
	virtual void finish_iteration() = 0;

private:
	int mNumTrials;
	int64_t mTotalTime;
};

#include "cppbench-impl.hpp"
<commit_msg>Providing a default finish_iteration implementation.<commit_after>#pragma once

#include <inttypes.h>
#include <time.h>

uint64_t nanotime();

/**
   Base class for benchmarks. Includes stuff for automatically
   running, making statistics, etc.
 */
class Benchmark {
public:
	Benchmark(int num_trials = 10);

	void run();

	virtual void setup();
	virtual void cleanup();

	double timePerIteration() const;
	double timePerIterationMicros() const;

	void setNumTrials(int num_trials);
	int getNumTrials() const;

protected:
	// These are the things that each benchmark needs to implement.

	virtual void run_iteration() = 0;
	virtual void finish_iteration() {};

private:
	int mNumTrials;
	int64_t mTotalTime;
};

#include "cppbench-impl.hpp"
<|endoftext|>


<commit_before>/**
 * Copyright (c) 2016-2018 mvs developers
 *
 * This file is part of metaverse-explorer.
 *
 * metaverse-explorer is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License with
 * additional permissions to the one published by the Free Software
 * Foundation, either version 3 of the License, or (at your option)
 * any later version. For more information see LICENSE.
 *
 * 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include <metaverse/explorer/json_helper.hpp>
#include <metaverse/explorer/dispatch.hpp>
#include <metaverse/explorer/extensions/commands/getaddressasset.hpp>
#include <metaverse/explorer/extensions/command_extension_func.hpp>
#include <metaverse/explorer/extensions/command_assistant.hpp>
#include <metaverse/explorer/extensions/exception.hpp>

namespace libbitcoin {
namespace explorer {
namespace commands {
using namespace bc::explorer::config;

/************************ getaddressasset *************************/

console_result getaddressasset::invoke (Json::Value& jv_output,
         libbitcoin::server::server_node& node)
{
    auto& aroot = jv_output;
    Json::Value assets;
    std::string symbol;

    auto& blockchain = node.chain_impl();
    if(!blockchain.is_valid_address(argument_.address))
        throw address_invalid_exception{"invalid address!"};

    // 1. get asset in blockchain
    auto kind = business_kind::asset_transfer;
    std::set<std::string> symbol_set;
    std::vector<asset_detail> asset_vec; // just used asset_detail class

    // make all asset kind vector
    std::vector<business_kind> kind_vec;
    kind_vec.push_back(business_kind::asset_transfer);
    kind_vec.push_back(business_kind::asset_issue);

    for (auto kind : kind_vec) {
        // get address unspent asset balance
        auto sh_vec = blockchain.get_address_business_history(argument_.address, kind, business_status::unspent);
        const auto sum = [&](const business_history& bh)
        {
            // get asset info
            std::string symbol;
            uint64_t num;
            if(kind == business_kind::asset_transfer) {
                auto transfer_info = boost::get<chain::asset_transfer>(bh.data.get_data());
                symbol = transfer_info.get_address();
                num = transfer_info.get_quantity();
            } else { // asset issued
                auto asset_info = boost::get<asset_detail>(bh.data.get_data());
                symbol = asset_info.get_symbol();
                num = asset_info.get_maximum_supply();
            }

            // update asset quantity
            auto r = symbol_set.insert(symbol);
            if(r.second) { // new symbol
                asset_vec.push_back(asset_detail(symbol, num, 0, "", argument_.address, ""));
            } else { // already exist
                const auto add_num = [&](asset_detail& elem)
                {
                    if( 0 == symbol.compare(elem.get_symbol()) )
                        elem.set_maximum_supply(elem.get_maximum_supply()+num);
                };
                std::for_each(asset_vec.begin(), asset_vec.end(), add_num);
            }
        };
        std::for_each(sh_vec->begin(), sh_vec->end(), sum);
    }

    for (auto& elem: asset_vec) {
        Json::Value asset_data;
        asset_data["symbol"] = elem.get_symbol();
        symbol = elem.get_symbol();
        if (get_api_version() == 1) {
            asset_data["quantity"] += elem.get_maximum_supply();
        } else {
            asset_data["quantity"] = elem.get_maximum_supply();
        }
        auto issued_asset = blockchain.get_issued_asset(symbol);
        if(issued_asset && get_api_version() == 1) {
            asset_data["decimal_number"] += issued_asset->get_decimal_number();
        }
        if(issued_asset && get_api_version() == 2) {
            asset_data["decimal_number"] = issued_asset->get_decimal_number();
        }
        //asset_data["asset_type"] = elem.detail.get_asset_type();
        //asset_data["issuer"] = elem.detail.get_issuer();
        //asset_data["address"] = elem.detail.get_address();
        //asset_data["description"] = elem.detail.get_description();
        asset_data["address"] = elem.get_address();
        asset_data["status"] = "unspent";
        assets.append(asset_data);
    }
    if (get_api_version() == 1 && assets.isNull()) { //compatible for v1
        aroot["assets"] = "";
    }
    else {
        aroot["assets"] = assets;
    }

    return console_result::okay;
}

} // namespace commands
} // namespace explorer
} // namespace libbitcoin

<commit_msg>fix: getaddressasset add info for secondissue_assetshare_threshold<commit_after>/**
 * Copyright (c) 2016-2018 mvs developers
 *
 * This file is part of metaverse-explorer.
 *
 * metaverse-explorer is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License with
 * additional permissions to the one published by the Free Software
 * Foundation, either version 3 of the License, or (at your option)
 * any later version. For more information see LICENSE.
 *
 * 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include <metaverse/explorer/json_helper.hpp>
#include <metaverse/explorer/dispatch.hpp>
#include <metaverse/explorer/extensions/commands/getaddressasset.hpp>
#include <metaverse/explorer/extensions/command_extension_func.hpp>
#include <metaverse/explorer/extensions/command_assistant.hpp>
#include <metaverse/explorer/extensions/exception.hpp>

namespace libbitcoin {
namespace explorer {
namespace commands {
using namespace bc::explorer::config;

/************************ getaddressasset *************************/

console_result getaddressasset::invoke (Json::Value& jv_output,
         libbitcoin::server::server_node& node)
{
    auto& aroot = jv_output;
    Json::Value assets;
    std::string symbol;

    auto& blockchain = node.chain_impl();
    if(!blockchain.is_valid_address(argument_.address))
        throw address_invalid_exception{"invalid address!"};

    // 1. get asset in blockchain
    auto kind = business_kind::asset_transfer;
    std::set<std::string> symbol_set;
    std::vector<asset_detail> asset_vec; // just used asset_detail class

    // make all asset kind vector
    std::vector<business_kind> kind_vec;
    kind_vec.push_back(business_kind::asset_transfer);
    kind_vec.push_back(business_kind::asset_issue);

    for (auto kind : kind_vec) {
        // get address unspent asset balance
        auto sh_vec = blockchain.get_address_business_history(argument_.address, kind, business_status::unspent);
        const auto sum = [&](const business_history& bh)
        {
            // get asset info
            uint64_t num;
            if(kind == business_kind::asset_transfer) {
                auto transfer_info = boost::get<chain::asset_transfer>(bh.data.get_data());
                symbol = transfer_info.get_address();
                num = transfer_info.get_quantity();
            } else { // asset issued
                auto asset_info = boost::get<asset_detail>(bh.data.get_data());
                symbol = asset_info.get_symbol();
                num = asset_info.get_maximum_supply();
            }

            // update asset quantity
            auto r = symbol_set.insert(symbol);
            if(r.second) { // new symbol
                asset_vec.push_back(asset_detail(symbol, num, 0, "", argument_.address, ""));
            } else { // already exist
                const auto add_num = [&](asset_detail& elem)
                {
                    if( 0 == symbol.compare(elem.get_symbol()) )
                        elem.set_maximum_supply(elem.get_maximum_supply()+num);
                };
                std::for_each(asset_vec.begin(), asset_vec.end(), add_num);
            }
        };
        std::for_each(sh_vec->begin(), sh_vec->end(), sum);
    }

    for (auto& elem: asset_vec) {
        Json::Value asset_data;
        symbol = elem.get_symbol();
        auto issued_asset = blockchain.get_issued_asset(symbol);
        if (!issued_asset) {
            continue;
        }
        if (get_api_version() == 1) {
            asset_data["quantity"] += elem.get_maximum_supply();
            asset_data["decimal_number"] += issued_asset->get_decimal_number();
            asset_data["secondissue_assetshare_threshold"] += elem.get_secondissue_assetshare_threshold();
        } else {
            asset_data["quantity"] = elem.get_maximum_supply();
            asset_data["decimal_number"] = issued_asset->get_decimal_number();
            asset_data["secondissue_assetshare_threshold"] = elem.get_secondissue_assetshare_threshold();
        }
        asset_data["symbol"] = symbol;
        asset_data["address"] = elem.get_address();
        asset_data["status"] = "unspent";
        assets.append(asset_data);
    }
    if (get_api_version() == 1 && assets.isNull()) { //compatible for v1
        aroot["assets"] = "";
    }
    else {
        aroot["assets"] = assets;
    }

    return console_result::okay;
}

} // namespace commands
} // namespace explorer
} // namespace libbitcoin

<|endoftext|>


<commit_before>/*
 * Glue code for the logging protocol.
 *
 * author: Max Kellermann <mk@cm4all.com>
 */

#include "log_glue.hxx"
#include "log_launch.hxx"
#include "log_client.hxx"

#include <glib.h>

#include <assert.h>
#include <string.h>

static bool global_log_enabled;
static LogClient *global_log_client;

void
log_global_init(const char *program, const struct daemon_user *user)
{
    assert(global_log_client == nullptr);

    if (program == nullptr || *program == 0 || strcmp(program, "internal") == 0) {
        global_log_enabled = false;
        return;
    }

    if (strcmp(program, "null") == 0) {
        global_log_enabled = true;
        return;
    }

    auto lp = log_launch(program, user);
    assert(lp.fd.IsDefined());

    global_log_client = log_client_new(std::move(lp.fd));
    assert(global_log_client != nullptr);
    global_log_enabled = global_log_client != nullptr;
}

void
log_global_deinit(void)
{
    if (global_log_client != nullptr)
        log_client_free(global_log_client);
}

bool
log_global_enabled(void)
{
    return global_log_enabled;
}

bool
log_http_request(uint64_t timestamp, http_method_t method, const char *uri,
                 const char *remote_host, const char *site,
                 const char *referer, const char *user_agent,
                 http_status_t status, int64_t length,
                 uint64_t traffic_received, uint64_t traffic_sent,
                 uint64_t duration)
{
    assert(http_method_is_valid(method));
    assert(uri != nullptr);
    assert(http_status_is_valid(status));

    if (global_log_client == nullptr)
        return true;

    log_client_begin(global_log_client);
    log_client_append_u64(global_log_client, LOG_TIMESTAMP, timestamp);
    if (remote_host != nullptr)
        log_client_append_string(global_log_client, LOG_REMOTE_HOST,
                                 remote_host);
    if (site != nullptr)
        log_client_append_string(global_log_client, LOG_SITE, site);
    log_client_append_u8(global_log_client, LOG_HTTP_METHOD, method);
    log_client_append_string(global_log_client, LOG_HTTP_URI, uri);
    if (referer != nullptr)
        log_client_append_string(global_log_client, LOG_HTTP_REFERER, referer);
    if (user_agent != nullptr)
        log_client_append_string(global_log_client, LOG_USER_AGENT,
                                 user_agent);
    log_client_append_u16(global_log_client, LOG_HTTP_STATUS, status);

    if (length >= 0)
        log_client_append_u64(global_log_client, LOG_LENGTH, length);

    struct {
        uint64_t received, sent;
    } traffic = {
        .received = GUINT64_TO_BE(traffic_received),
        .sent = GUINT64_TO_BE(traffic_sent),
    };

    log_client_append_attribute(global_log_client, LOG_TRAFFIC,
                                &traffic, sizeof(traffic));

    if (duration > 0)
        log_client_append_u64(global_log_client, LOG_DURATION, duration);

    return log_client_commit(global_log_client);
}
<commit_msg>log_glue: use util/ByteOrder.hxx instead of GLib<commit_after>/*
 * Glue code for the logging protocol.
 *
 * author: Max Kellermann <mk@cm4all.com>
 */

#include "log_glue.hxx"
#include "log_launch.hxx"
#include "log_client.hxx"
#include "util/ByteOrder.hxx"

#include <assert.h>
#include <string.h>

static bool global_log_enabled;
static LogClient *global_log_client;

void
log_global_init(const char *program, const struct daemon_user *user)
{
    assert(global_log_client == nullptr);

    if (program == nullptr || *program == 0 || strcmp(program, "internal") == 0) {
        global_log_enabled = false;
        return;
    }

    if (strcmp(program, "null") == 0) {
        global_log_enabled = true;
        return;
    }

    auto lp = log_launch(program, user);
    assert(lp.fd.IsDefined());

    global_log_client = log_client_new(std::move(lp.fd));
    assert(global_log_client != nullptr);
    global_log_enabled = global_log_client != nullptr;
}

void
log_global_deinit(void)
{
    if (global_log_client != nullptr)
        log_client_free(global_log_client);
}

bool
log_global_enabled(void)
{
    return global_log_enabled;
}

bool
log_http_request(uint64_t timestamp, http_method_t method, const char *uri,
                 const char *remote_host, const char *site,
                 const char *referer, const char *user_agent,
                 http_status_t status, int64_t length,
                 uint64_t traffic_received, uint64_t traffic_sent,
                 uint64_t duration)
{
    assert(http_method_is_valid(method));
    assert(uri != nullptr);
    assert(http_status_is_valid(status));

    if (global_log_client == nullptr)
        return true;

    log_client_begin(global_log_client);
    log_client_append_u64(global_log_client, LOG_TIMESTAMP, timestamp);
    if (remote_host != nullptr)
        log_client_append_string(global_log_client, LOG_REMOTE_HOST,
                                 remote_host);
    if (site != nullptr)
        log_client_append_string(global_log_client, LOG_SITE, site);
    log_client_append_u8(global_log_client, LOG_HTTP_METHOD, method);
    log_client_append_string(global_log_client, LOG_HTTP_URI, uri);
    if (referer != nullptr)
        log_client_append_string(global_log_client, LOG_HTTP_REFERER, referer);
    if (user_agent != nullptr)
        log_client_append_string(global_log_client, LOG_USER_AGENT,
                                 user_agent);
    log_client_append_u16(global_log_client, LOG_HTTP_STATUS, status);

    if (length >= 0)
        log_client_append_u64(global_log_client, LOG_LENGTH, length);

    struct {
        uint64_t received, sent;
    } traffic = {
        .received = ToBE64(traffic_received),
        .sent = ToBE64(traffic_sent),
    };

    log_client_append_attribute(global_log_client, LOG_TRAFFIC,
                                &traffic, sizeof(traffic));

    if (duration > 0)
        log_client_append_u64(global_log_client, LOG_DURATION, duration);

    return log_client_commit(global_log_client);
}
<|endoftext|>


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

/**
 * @file objects_common.cpp
 *
 * Common object definitions without a better home.
 */

/**
 * @defgroup topics List of all uORB topics.
 */

#include <px4_config.h>

#include <drivers/drv_orb_dev.h>

#include <drivers/drv_mag.h>
ORB_DEFINE(sensor_mag, struct mag_report);

#include <drivers/drv_accel.h>
ORB_DEFINE(sensor_accel, struct accel_report);

#include <drivers/drv_gyro.h>
ORB_DEFINE(sensor_gyro, struct gyro_report);

#include <drivers/drv_baro.h>
ORB_DEFINE(sensor_baro, struct baro_report);

#include <drivers/drv_range_finder.h>
ORB_DEFINE(sensor_range_finder, struct range_finder_report);

#include <drivers/drv_pwm_output.h>
ORB_DEFINE(output_pwm, struct pwm_output_values);

#include <drivers/drv_rc_input.h>
ORB_DEFINE(input_rc, struct rc_input_values);

#include "topics/vehicle_attitude.h"
ORB_DEFINE(vehicle_attitude, struct vehicle_attitude_s);

#include "topics/sensor_combined.h"
ORB_DEFINE(sensor_combined, struct sensor_combined_s);

#include "topics/vehicle_gps_position.h"
ORB_DEFINE(vehicle_gps_position, struct vehicle_gps_position_s);

#include "topics/vehicle_land_detected.h"
ORB_DEFINE(vehicle_land_detected, struct vehicle_land_detected_s);

#include "topics/satellite_info.h"
ORB_DEFINE(satellite_info, struct satellite_info_s);

#include "topics/home_position.h"
ORB_DEFINE(home_position, struct home_position_s);

#include "topics/vehicle_status.h"
ORB_DEFINE(vehicle_status, struct vehicle_status_s);

#include "topics/vtol_vehicle_status.h"
ORB_DEFINE(vtol_vehicle_status, struct vtol_vehicle_status_s);

#include "topics/safety.h"
ORB_DEFINE(safety, struct safety_s);

#include "topics/battery_status.h"
ORB_DEFINE(battery_status, struct battery_status_s);

#include "topics/servorail_status.h"
ORB_DEFINE(servorail_status, struct servorail_status_s);

#include "topics/system_power.h"
ORB_DEFINE(system_power, struct system_power_s);

#include "topics/vehicle_global_position.h"
ORB_DEFINE(vehicle_global_position, struct vehicle_global_position_s);

#include "topics/vehicle_local_position.h"
ORB_DEFINE(vehicle_local_position, struct vehicle_local_position_s);

#include "topics/vehicle_vicon_position.h"
ORB_DEFINE(vehicle_vicon_position, struct vehicle_vicon_position_s);

#include "topics/vehicle_rates_setpoint.h"
ORB_DEFINE(vehicle_rates_setpoint, struct vehicle_rates_setpoint_s);
#include "topics/mc_virtual_rates_setpoint.h"
ORB_DEFINE(mc_virtual_rates_setpoint, struct mc_virtual_rates_setpoint_s);
#include "topics/fw_virtual_rates_setpoint.h"
ORB_DEFINE(fw_virtual_rates_setpoint, struct fw_virtual_rates_setpoint_s);

#include "topics/rc_channels.h"
ORB_DEFINE(rc_channels, struct rc_channels_s);

#include "topics/vehicle_command.h"
ORB_DEFINE(vehicle_command, struct vehicle_command_s);

#include "topics/vehicle_control_mode.h"
ORB_DEFINE(vehicle_control_mode, struct vehicle_control_mode_s);

#include "topics/vehicle_local_position_setpoint.h"
ORB_DEFINE(vehicle_local_position_setpoint, struct vehicle_local_position_setpoint_s);

#include "topics/vehicle_bodyframe_speed_setpoint.h"
ORB_DEFINE(vehicle_bodyframe_speed_setpoint, struct vehicle_bodyframe_speed_setpoint_s);

#include "topics/position_setpoint_triplet.h"
ORB_DEFINE(position_setpoint_triplet, struct position_setpoint_triplet_s);

#include "topics/vehicle_global_velocity_setpoint.h"
ORB_DEFINE(vehicle_global_velocity_setpoint, struct vehicle_global_velocity_setpoint_s);

#include "topics/mission.h"
ORB_DEFINE(offboard_mission, struct mission_s);
ORB_DEFINE(onboard_mission, struct mission_s);

#include "topics/mission_result.h"
ORB_DEFINE(mission_result, struct mission_result_s);

#include "topics/geofence_result.h"
ORB_DEFINE(geofence_result, struct geofence_result_s);

#include "topics/fence.h"
ORB_DEFINE(fence, unsigned);

#include "topics/vehicle_attitude_setpoint.h"
ORB_DEFINE(vehicle_attitude_setpoint, struct vehicle_attitude_setpoint_s);
ORB_DEFINE(mc_virtual_attitude_setpoint, struct vehicle_attitude_setpoint_s);
ORB_DEFINE(fw_virtual_attitude_setpoint, struct vehicle_attitude_setpoint_s);

#include "topics/manual_control_setpoint.h"
ORB_DEFINE(manual_control_setpoint, struct manual_control_setpoint_s);

#include "topics/vehicle_control_debug.h"
ORB_DEFINE(vehicle_control_debug, struct vehicle_control_debug_s);

#include "topics/offboard_control_mode.h"
ORB_DEFINE(offboard_control_mode, struct offboard_control_mode_s);

#include "topics/optical_flow.h"
ORB_DEFINE(optical_flow, struct optical_flow_s);

#include "topics/filtered_bottom_flow.h"
ORB_DEFINE(filtered_bottom_flow, struct filtered_bottom_flow_s);

#include "topics/omnidirectional_flow.h"
ORB_DEFINE(omnidirectional_flow, struct omnidirectional_flow_s);

#include "topics/airspeed.h"
ORB_DEFINE(airspeed, struct airspeed_s);

#include "topics/differential_pressure.h"
ORB_DEFINE(differential_pressure, struct differential_pressure_s);

#include "topics/subsystem_info.h"
ORB_DEFINE(subsystem_info, struct subsystem_info_s);

/* actuator controls, as requested by controller */
#include "topics/actuator_controls.h"
#include "topics/actuator_controls_0.h"
ORB_DEFINE(actuator_controls_0, struct actuator_controls_0_s);
#include "topics/actuator_controls_1.h"
ORB_DEFINE(actuator_controls_1, struct actuator_controls_1_s);
#include "topics/actuator_controls_2.h"
ORB_DEFINE(actuator_controls_2, struct actuator_controls_2_s);
#include "topics/actuator_controls_3.h"
ORB_DEFINE(actuator_controls_3, struct actuator_controls_3_s);
//Virtual control groups, used for VTOL operation
#include "topics/actuator_controls_virtual_mc.h"
ORB_DEFINE(actuator_controls_virtual_mc, struct actuator_controls_virtual_mc_s);
#include "topics/actuator_controls_virtual_fw.h"
ORB_DEFINE(actuator_controls_virtual_fw, struct actuator_controls_virtual_fw_s);

#include "topics/actuator_armed.h"
ORB_DEFINE(actuator_armed, struct actuator_armed_s);

#include "topics/actuator_outputs.h"
ORB_DEFINE(actuator_outputs, struct actuator_outputs_s);

#include "topics/actuator_direct.h"
ORB_DEFINE(actuator_direct, struct actuator_direct_s);

#include "topics/multirotor_motor_limits.h"
ORB_DEFINE(multirotor_motor_limits, struct multirotor_motor_limits_s);

#include "topics/telemetry_status.h"
ORB_DEFINE(telemetry_status_0, struct telemetry_status_s);
ORB_DEFINE(telemetry_status_1, struct telemetry_status_s);
ORB_DEFINE(telemetry_status_2, struct telemetry_status_s);
ORB_DEFINE(telemetry_status_3, struct telemetry_status_s);

#include "topics/test_motor.h"
ORB_DEFINE(test_motor, struct test_motor_s);

#include "topics/debug_key_value.h"
ORB_DEFINE(debug_key_value, struct debug_key_value_s);

#include "topics/navigation_capabilities.h"
ORB_DEFINE(navigation_capabilities, struct navigation_capabilities_s);

#include "topics/esc_status.h"
ORB_DEFINE(esc_status, struct esc_status_s);

#include "topics/encoders.h"
ORB_DEFINE(encoders, struct encoders_s);

#include "topics/estimator_status.h"
ORB_DEFINE(estimator_status, struct estimator_status_report);

#include "topics/vision_position_estimate.h"
ORB_DEFINE(vision_position_estimate, struct vision_position_estimate);

#include "topics/vehicle_force_setpoint.h"
ORB_DEFINE(vehicle_force_setpoint, struct vehicle_force_setpoint_s);

#include "topics/tecs_status.h"
ORB_DEFINE(tecs_status, struct tecs_status_s);

#include "topics/wind_estimate.h"
ORB_DEFINE(wind_estimate, struct wind_estimate_s);

#include "topics/rc_parameter_map.h"
ORB_DEFINE(rc_parameter_map, struct rc_parameter_map_s);

#include "topics/time_offset.h"
ORB_DEFINE(time_offset, struct time_offset_s);

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

/**
 * @file objects_common.cpp
 *
 * Common object definitions without a better home.
 */

/**
 * @defgroup topics List of all uORB topics.
 */

#include <px4_config.h>

#include <drivers/drv_orb_dev.h>

#include <drivers/drv_mag.h>
ORB_DEFINE(sensor_mag, struct mag_report);

#include <drivers/drv_accel.h>
ORB_DEFINE(sensor_accel, struct accel_report);

#include <drivers/drv_gyro.h>
ORB_DEFINE(sensor_gyro, struct gyro_report);

#include <drivers/drv_baro.h>
ORB_DEFINE(sensor_baro, struct baro_report);

#include <drivers/drv_range_finder.h>
ORB_DEFINE(sensor_range_finder, struct range_finder_report);

#include <drivers/drv_pwm_output.h>
ORB_DEFINE(output_pwm, struct pwm_output_values);

#include <drivers/drv_rc_input.h>
ORB_DEFINE(input_rc, struct rc_input_values);

#include "topics/vehicle_attitude.h"
ORB_DEFINE(vehicle_attitude, struct vehicle_attitude_s);

#include "topics/sensor_combined.h"
ORB_DEFINE(sensor_combined, struct sensor_combined_s);

#include "topics/vehicle_gps_position.h"
ORB_DEFINE(vehicle_gps_position, struct vehicle_gps_position_s);

#include "topics/vehicle_land_detected.h"
ORB_DEFINE(vehicle_land_detected, struct vehicle_land_detected_s);

#include "topics/satellite_info.h"
ORB_DEFINE(satellite_info, struct satellite_info_s);

#include "topics/home_position.h"
ORB_DEFINE(home_position, struct home_position_s);

#include "topics/vehicle_status.h"
ORB_DEFINE(vehicle_status, struct vehicle_status_s);

#include "topics/vtol_vehicle_status.h"
ORB_DEFINE(vtol_vehicle_status, struct vtol_vehicle_status_s);

#include "topics/safety.h"
ORB_DEFINE(safety, struct safety_s);

#include "topics/battery_status.h"
ORB_DEFINE(battery_status, struct battery_status_s);

#include "topics/servorail_status.h"
ORB_DEFINE(servorail_status, struct servorail_status_s);

#include "topics/system_power.h"
ORB_DEFINE(system_power, struct system_power_s);

#include "topics/vehicle_global_position.h"
ORB_DEFINE(vehicle_global_position, struct vehicle_global_position_s);

#include "topics/vehicle_local_position.h"
ORB_DEFINE(vehicle_local_position, struct vehicle_local_position_s);

#include "topics/vehicle_vicon_position.h"
ORB_DEFINE(vehicle_vicon_position, struct vehicle_vicon_position_s);

#include "topics/vehicle_rates_setpoint.h"
ORB_DEFINE(vehicle_rates_setpoint, struct vehicle_rates_setpoint_s);
#include "topics/mc_virtual_rates_setpoint.h"
ORB_DEFINE(mc_virtual_rates_setpoint, struct mc_virtual_rates_setpoint_s);
#include "topics/fw_virtual_rates_setpoint.h"
ORB_DEFINE(fw_virtual_rates_setpoint, struct fw_virtual_rates_setpoint_s);

#include "topics/rc_channels.h"
ORB_DEFINE(rc_channels, struct rc_channels_s);

#include "topics/vehicle_command.h"
ORB_DEFINE(vehicle_command, struct vehicle_command_s);

#include "topics/vehicle_control_mode.h"
ORB_DEFINE(vehicle_control_mode, struct vehicle_control_mode_s);

#include "topics/vehicle_local_position_setpoint.h"
ORB_DEFINE(vehicle_local_position_setpoint, struct vehicle_local_position_setpoint_s);

#include "topics/vehicle_bodyframe_speed_setpoint.h"
ORB_DEFINE(vehicle_bodyframe_speed_setpoint, struct vehicle_bodyframe_speed_setpoint_s);

#include "topics/position_setpoint_triplet.h"
ORB_DEFINE(position_setpoint_triplet, struct position_setpoint_triplet_s);

#include "topics/vehicle_global_velocity_setpoint.h"
ORB_DEFINE(vehicle_global_velocity_setpoint, struct vehicle_global_velocity_setpoint_s);

#include "topics/mission.h"
ORB_DEFINE(offboard_mission, struct mission_s);
ORB_DEFINE(onboard_mission, struct mission_s);

#include "topics/mission_result.h"
ORB_DEFINE(mission_result, struct mission_result_s);

#include "topics/geofence_result.h"
ORB_DEFINE(geofence_result, struct geofence_result_s);

#include "topics/fence.h"
ORB_DEFINE(fence, unsigned);

#include "topics/vehicle_attitude_setpoint.h"
ORB_DEFINE(vehicle_attitude_setpoint, struct vehicle_attitude_setpoint_s);
ORB_DEFINE(mc_virtual_attitude_setpoint, struct vehicle_attitude_setpoint_s);
ORB_DEFINE(fw_virtual_attitude_setpoint, struct vehicle_attitude_setpoint_s);

#include "topics/manual_control_setpoint.h"
ORB_DEFINE(manual_control_setpoint, struct manual_control_setpoint_s);

#include "topics/vehicle_control_debug.h"
ORB_DEFINE(vehicle_control_debug, struct vehicle_control_debug_s);

#include "topics/offboard_control_mode.h"
ORB_DEFINE(offboard_control_mode, struct offboard_control_mode_s);

#include "topics/optical_flow.h"
ORB_DEFINE(optical_flow, struct optical_flow_s);

#include "topics/filtered_bottom_flow.h"
ORB_DEFINE(filtered_bottom_flow, struct filtered_bottom_flow_s);

#include "topics/omnidirectional_flow.h"
ORB_DEFINE(omnidirectional_flow, struct omnidirectional_flow_s);

#include "topics/airspeed.h"
ORB_DEFINE(airspeed, struct airspeed_s);

#include "topics/differential_pressure.h"
ORB_DEFINE(differential_pressure, struct differential_pressure_s);

#include "topics/subsystem_info.h"
ORB_DEFINE(subsystem_info, struct subsystem_info_s);

/* actuator controls, as requested by controller */
#include "topics/actuator_controls.h"
#include "topics/actuator_controls_0.h"
ORB_DEFINE(actuator_controls_0, struct actuator_controls_0_s);
#include "topics/actuator_controls_1.h"
ORB_DEFINE(actuator_controls_1, struct actuator_controls_1_s);
#include "topics/actuator_controls_2.h"
ORB_DEFINE(actuator_controls_2, struct actuator_controls_2_s);
#include "topics/actuator_controls_3.h"
ORB_DEFINE(actuator_controls_3, struct actuator_controls_3_s);
//Virtual control groups, used for VTOL operation
#include "topics/actuator_controls_virtual_mc.h"
ORB_DEFINE(actuator_controls_virtual_mc, struct actuator_controls_virtual_mc_s);
#include "topics/actuator_controls_virtual_fw.h"
ORB_DEFINE(actuator_controls_virtual_fw, struct actuator_controls_virtual_fw_s);

#include "topics/actuator_armed.h"
ORB_DEFINE(actuator_armed, struct actuator_armed_s);

#include "topics/actuator_outputs.h"
ORB_DEFINE(actuator_outputs, struct actuator_outputs_s);

#include "topics/actuator_direct.h"
ORB_DEFINE(actuator_direct, struct actuator_direct_s);

#include "topics/multirotor_motor_limits.h"
ORB_DEFINE(multirotor_motor_limits, struct multirotor_motor_limits_s);

#include "topics/telemetry_status.h"
ORB_DEFINE(telemetry_status_0, struct telemetry_status_s);
ORB_DEFINE(telemetry_status_1, struct telemetry_status_s);
ORB_DEFINE(telemetry_status_2, struct telemetry_status_s);
ORB_DEFINE(telemetry_status_3, struct telemetry_status_s);

#include "topics/test_motor.h"
ORB_DEFINE(test_motor, struct test_motor_s);

#include "topics/debug_key_value.h"
ORB_DEFINE(debug_key_value, struct debug_key_value_s);

#include "topics/navigation_capabilities.h"
ORB_DEFINE(navigation_capabilities, struct navigation_capabilities_s);

#include "topics/esc_status.h"
ORB_DEFINE(esc_status, struct esc_status_s);

#include "topics/encoders.h"
ORB_DEFINE(encoders, struct encoders_s);

#include "topics/estimator_status.h"
ORB_DEFINE(estimator_status, struct estimator_status_report);

#include "topics/vision_position_estimate.h"
ORB_DEFINE(vision_position_estimate, struct vision_position_estimate);

#include "topics/vehicle_force_setpoint.h"
ORB_DEFINE(vehicle_force_setpoint, struct vehicle_force_setpoint_s);

#include "topics/tecs_status.h"
ORB_DEFINE(tecs_status, struct tecs_status_s);

#include "topics/wind_estimate.h"
ORB_DEFINE(wind_estimate, struct wind_estimate_s);

#include "topics/rc_parameter_map.h"
ORB_DEFINE(rc_parameter_map, struct rc_parameter_map_s);

#include "topics/time_offset.h"
ORB_DEFINE(time_offset, struct time_offset_s);

#include "topics/mc_att_ctrl_status.h"
ORB_DEFINE(mc_att_ctrl_status, struct mc_att_ctrl_status_s);

#include "topics/distance_sensor.h"
ORB_DEFINE(distance_sensor, struct distance_sensor_s);<|endoftext|>