<commit_before>//=============================================================================================================
/**
* @file     babymegclient.cpp
* @author   Limin Sun <liminsun@nmr.mgh.harvard.edu>;
*           Christoph Dinh <chdinh@nmr.mgh.harvard.edu>;
*           Matti Hamalainen <msh@nmr.mgh.harvard.edu>
* @version  1.0
* @date     April, 2013
*
* @section  LICENSE
*
* Copyright (C) 2013, Limin Sun, Christoph Dinh and Matti Hamalainen. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that
* the following conditions are met:
*     * Redistributions of source code must retain the above copyright notice, this list of conditions and the
*       following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
*       the following disclaimer in the documentation and/or other materials provided with the distribution.
*     * Neither the name of the Massachusetts General Hospital 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 MASSACHUSETTS GENERAL HOSPITAL 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.
*
*
* @brief     implementation of the BabyMEGClient Class.
*
*/

//*************************************************************************************************************
//=============================================================================================================
// INCLUDES
//=============================================================================================================

#include "babymegclient.h"

//*************************************************************************************************************
//=============================================================================================================
// QT INCLUDES
//=============================================================================================================

#include <QDebug>
#include <QtNetwork/QtNetwork>
#include <QtEndian>

//*************************************************************************************************************

BabyMEGClient::BabyMEGClient(int myPort, QObject *parent) :
    QThread(parent)
{
    connect(this,SIGNAL(DataAcq()),this,SLOT(run()));
    tcpSocket = new QTcpSocket(this);

    connect(tcpSocket,SIGNAL(readyRead()),this,SLOT(ReadToBuffer()));

    connect(this, SIGNAL(error(int,QString)),
                 this, SLOT(DisplayError(int,QString)));     //find out name of this machine
    name = QHostInfo::localHostName();
    if(!name.isEmpty())
    {
        QString domain = QHostInfo::localDomainName();
        if (!domain.isEmpty())
            name = name + QChar('.') + domain;
    }
    if (name!=QString("localhost"))
        name = QString("localhost");
    qDebug()<< "- " + name;
    port = myPort;//6340;
    SocketIsConnected = false;
    SkipLoop = false;
    DataAcqStartFlag = false;
    numBlock = 0;
    DataACK = false;

}

//*************************************************************************************************************

void BabyMEGClient::SetInfo(BabyMEGInfo *pInfo)
{
    myBabyMEGInfo = pInfo;
}

//*************************************************************************************************************

void BabyMEGClient::DisplayError(int socketError, const QString &message)
{
    switch (socketError){
    case QAbstractSocket::RemoteHostClosedError:
            break;
    case QAbstractSocket::HostNotFoundError:
        qDebug()<< "The host was not found. Please check the host name and the port number";
        break;
    case QAbstractSocket::ConnectionRefusedError:
        qDebug()<< "The connection was refused by the peer. Make sure the server is running?";
        break;
    default:
        qDebug()<< "Error: " << message;
    }
}

//*************************************************************************************************************

int BabyMEGClient::MGH_LM_Byte2Int(QByteArray b)
{
    int value= 0;
    for (int i=0;i<2;i++)
    {
        QByteArray t;
        t[0] = b[i];
        b[i] = b[3-i];
        b[3-i] = t[0];
    }
    memcpy((char *)&value,b,4);
    return value;
}

//*************************************************************************************************************

QByteArray BabyMEGClient::MGH_LM_Int2Byte(int a)
{
    QByteArray b = QByteArray::fromRawData((char *)&a,4);

    for (int i=0;i<2;i++)
    {
        QByteArray t;
        t[0] = b[i];
        b[i] = b[3-i];
        b[3-i] = t[0];
    }
    return b;
}

//*************************************************************************************************************

double BabyMEGClient::MGH_LM_Byte2Double(QByteArray b)
{
    double value= 1.0;
    // reverse the byte order
    for (int i=0;i<4;i++)
    {
        QByteArray t;
        t[0] = b[i];
        b[i] = b[7-i];
        b[7-i] = t[0];
    }
    memcpy((char *)&value,b,8);

    return value;
}

//*************************************************************************************************************

void BabyMEGClient::HexDisplay(double a)
{
    QByteArray data = QByteArray::fromRawData((char *)&a,8);
    qDebug() << data.toHex();
}

//*************************************************************************************************************

void BabyMEGClient::ConnectToBabyMEG()
{
    // return true: sucessfully connect to babyMEG server
    //        false: fail.
    SocketIsConnected = false;
    // Connect to the server of babyMEG [labview]
    qDebug()<< "Client is started!";

    if (!this->isRunning())
    {
        this->start();
    }

    for(int i=0;i<5;i++){
        tcpSocket->connectToHost(name,port,QIODevice::ReadWrite);
        if (tcpSocket->waitForConnected(10000))
        {
            SocketIsConnected = true;
            qDebug("Connect to BabyMEG Server ... Ok");
            //download parameters
            qDebug()<< "Send the initial parameter request";
            if (tcpSocket->state()==QAbstractSocket::ConnectedState)
            {
                buffer.clear();
                SendCommand("INFO");
            }
            return;
        }
        else{
            qDebug("Connect to BabyMEG Server ... Fail");
            qDebug("Try another time connection");
        }
        qDebug("Please check the babyMEG server: if started");
    }
    return;
}

//*************************************************************************************************************

void BabyMEGClient::DisConnectBabyMEG()
{
    if(SocketIsConnected && tcpSocket->state()==QAbstractSocket::ConnectedState)
        SendCommand("QUIT");
}

//*************************************************************************************************************

void BabyMEGClient::SendCommandToBabyMEGShortConnection()
{
    qDebug() << "SendCommandToBabyMEGShortConnection";
    tcpSocket->connectToHost(name,port,QIODevice::ReadWrite);
    if (tcpSocket->waitForConnected(10000))
    {

        qDebug()<<"Connection is built.";

        if(tcpSocket->state()==QAbstractSocket::ConnectedState)
        {
            qDebug()<<"Send Command [COMS]";
            tcpSocket->write("COMS");
            int strlen = 3;
            QByteArray Scmd = MGH_LM_Int2Byte(strlen);

            tcpSocket->write(Scmd);
            tcpSocket->write("SLM");
            tcpSocket->waitForBytesWritten();
        }
    }

}

//*************************************************************************************************************

void BabyMEGClient::SendCommandToBabyMEG()
{
    qDebug()<<"Send Command";
    if(SocketIsConnected && tcpSocket->state()==QAbstractSocket::ConnectedState)
    {
        m_qMutex.lock();
        tcpSocket->write("COMD");
        tcpSocket->waitForBytesWritten();

        int strlen = 3;
        QByteArray Scmd = MGH_LM_Int2Byte(strlen);

        tcpSocket->write(Scmd);
        tcpSocket->write("SLM");
        tcpSocket->waitForBytesWritten();
        m_qMutex.unlock();
    }

}

//*************************************************************************************************************

void BabyMEGClient::ReadToBuffer()
{

    QByteArray dat;

    int numBytes = tcpSocket->bytesAvailable();
//    qDebug() << "1.byte available: " << numBytes;
    if (numBytes > 0){
        dat = tcpSocket->read(numBytes); // read all pending data
//        qDebug()<<"[dat Size]"<<dat.size();
        if (!dat.isEmpty()){
            buffer.append(dat); // and append it to your own buffer
//            qDebug()<<"[ReadToBuffer: Buffer Size]"<<buffer.size();
        }
        else
        {
            qDebug()<<"[Empty dat: error]"<<tcpSocket->errorString();
        }
    }
//    qDebug()<<"read buffer is done!";

    handleBuffer();
    return;
}

//*************************************************************************************************************

void BabyMEGClient::handleBuffer()
{
    if(buffer.size()>= 8){
        QByteArray CMD = buffer.left(4);
        QByteArray DLEN = buffer.mid(4,4);
        int tmp = MGH_LM_Byte2Int(DLEN);
//        qDebug() << "First 4 bytes + length" << CMD << "["<<CMD.toHex()<<"]";
//        qDebug() << "Command[" << CMD <<"]";
//        qDebug() << "Body Length[" << tmp << "]";

        if (tmp <= (buffer.size() - 8))
        {
            buffer.remove(0,8);

            int OPT = 0;

            if (CMD == "INFO")
                OPT = 1;
            else if (CMD == "DATR")
                OPT = 2;
            else if (CMD == "COMD")
                OPT = 3;
            else if (CMD == "QUIT")
                OPT = 4;
            else if (CMD == "COMS")
                OPT = 5;
            else if (CMD == "QUIS")
                OPT = 6;

            switch (OPT){
            case 1:
                // from buffer get data package
                {
                QByteArray PARA = buffer.left(tmp);
                qDebug()<<"[INFO]"<<PARA;
                //Parse parameters from PARA string
                myBabyMEGInfo->MGH_LM_Parse_Para(PARA);
                buffer.remove(0,tmp);
                qDebug()<<"ACQ Start";
                SendCommand("DATA");
                }
                break;
            case 2:
                // read data package from buffer
                // Ask for the next data block

                SendCommand("DATA");
                DispatchDataPackage(tmp);

                break;
            case 3:
                {
                QByteArray RESP = buffer.left(tmp);
                qDebug()<< "5.Readbytes:"<<RESP.size();
                qDebug() << RESP;
                }
                buffer.remove(0,tmp);

                break;
            case 4:  //quit
                qDebug()<<"Quit";

                SendCommand("QREL");
                tcpSocket->disconnectFromHost();
                if(tcpSocket->state() != QAbstractSocket::UnconnectedState)
                            tcpSocket->waitForDisconnected();
                SocketIsConnected = false;
                qDebug()<< "Disconnect Server";
                qDebug()<< "Client is End!";
                qDebug()<< "You can close this application or restart to connect Server.";

                break;
            case 5://command short connection
                {
                QByteArray RESP = buffer.left(tmp);
                qDebug()<< "5.Readbytes:"<<RESP.size();
                qDebug() << RESP;
                }
                buffer.remove(0,tmp);
                SendCommand("QUIT");
                break;
            case 6:  //quit
                qDebug()<<"Quit";

                SendCommand("QREL");
                tcpSocket->disconnectFromHost();
                if(tcpSocket->state() != QAbstractSocket::UnconnectedState)
                            tcpSocket->waitForDisconnected();
                SocketIsConnected = false;
                qDebug()<< "Disconnect Server";
                break;

            default:
                qDebug()<< "Unknow Type";
                break;
            }
        }
    }// buffer is not empty and larger than 8 bytes

}

//*************************************************************************************************************

void BabyMEGClient::DispatchDataPackage(int tmp)
{

//    qDebug()<<"Acq data from buffer  [buffer size() =" << buffer.size()<<"]";
    QByteArray DATA = buffer.left(tmp);
    qDebug()<< "5.Readbytes:"<<DATA.size();
//    myBabyMEGInfo->EnQueue(DATA);
    buffer.remove(0,tmp);
//    qDebug()<<"Rest buffer  [buffer size() =" << buffer.size()<<"]";
    numBlock ++;
    qDebug()<< "Next Block ..." << numBlock;
//    DATA.clear();

//    ReadNextBlock(tmp);
}

//*************************************************************************************************************

void BabyMEGClient::ReadNextBlock(int tmp)
{
    QByteArray CMD1;
    QByteArray DLEN1;
    QByteArray DATA1;
    int tmp1;
    while (buffer.size()>=(tmp+8))
    { // process the extra data block to reduce the load of data buffer
        CMD1 = buffer.left(4);
        qDebug()<<"CMD"<< CMD1;
        if (CMD1 == "DATR")
        {
            DLEN1 = buffer.mid(4,4);
            tmp1 = MGH_LM_Byte2Int(DLEN1);
            qDebug() << "[2]First 4 bytes + length" << CMD1 << "["<<CMD1.toHex()<<"]";
            qDebug() << "[2]Command[" << CMD1 <<"]";
            qDebug() << "[2]Body Length[" << tmp1 << "]";

            buffer.remove(0,8);
            DATA1 = buffer.left(tmp1);
            myBabyMEGInfo->EnQueue(DATA1);
            buffer.remove(0,tmp1);
            qDebug()<<"End of DataPackeage" << buffer.left(3);
            qDebug()<<"[2]Rest buffer  [buffer size() =" << buffer.size()<<"]";
            numBlock ++;
            qDebug()<< "[2]Next Block ..." << numBlock;
        }
        else
        {
            qDebug()<<"[CMD1]"<<CMD1.toHex();
            break;
        }
        qDebug()<<"[ReadNextBlock:buffer size]"<<buffer.size();
    }
    DATA1.clear();
    CMD1.clear();
    DLEN1.clear();
}

//*************************************************************************************************************

void BabyMEGClient::SendCommand(QString s)
{
    QByteArray array;
    array.append(s);

    int WrtNum;

    if (tcpSocket->state()==QAbstractSocket::ConnectedState)
    {
        m_qMutex.lock();

//    qDebug()<<"[Send Command]"<<array;
        WrtNum = tcpSocket->write(array,4);
        if(WrtNum==-1)
        {
            qDebug()<<"Error for sending a command";
        }
        if(WrtNum != array.size())
        {
            qDebug()<<"Uncorrectly sending";
        }
        tcpSocket->flush();
        tcpSocket->waitForBytesWritten();
        m_qMutex.unlock();
        qDebug()<<"[Done: Send Command]"<<array<<"[Send bytes]"<<WrtNum;

        }
        else
        {
            qDebug()<<"Not in Connected state";
            //re-connect to server
            ConnectToBabyMEG();
            buffer.clear();
            SendCommand("DATA");
        }
//    sleep(1);
}

//*************************************************************************************************************

void BabyMEGClient::run()
{

}
<commit_msg>comments<commit_after>//=============================================================================================================
/**
* @file     babymegclient.cpp
* @author   Limin Sun <liminsun@nmr.mgh.harvard.edu>;
*           Christoph Dinh <chdinh@nmr.mgh.harvard.edu>;
*           Matti Hamalainen <msh@nmr.mgh.harvard.edu>
* @version  1.0
* @date     April, 2013
*
* @section  LICENSE
*
* Copyright (C) 2013, Limin Sun, Christoph Dinh and Matti Hamalainen. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that
* the following conditions are met:
*     * Redistributions of source code must retain the above copyright notice, this list of conditions and the
*       following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
*       the following disclaimer in the documentation and/or other materials provided with the distribution.
*     * Neither the name of the Massachusetts General Hospital nor the names of its contributors may be used
*       to endorse or promote products derived from this software without specific prior written permission.
*
* 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.
*
*
* @brief     implementation of the BabyMEGClient Class.
*
* 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 MASSACHUSETTS GENERAL HOSPITAL BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
*/

//*************************************************************************************************************
//=============================================================================================================
// INCLUDES
//=============================================================================================================

#include "babymegclient.h"

//*************************************************************************************************************
//=============================================================================================================
// QT INCLUDES
//=============================================================================================================

#include <QDebug>
#include <QtNetwork/QtNetwork>
#include <QtEndian>

//*************************************************************************************************************

BabyMEGClient::BabyMEGClient(int myPort, QObject *parent) :
    QThread(parent)
{
    connect(this,SIGNAL(DataAcq()),this,SLOT(run()));
    tcpSocket = new QTcpSocket(this);

    connect(tcpSocket,SIGNAL(readyRead()),this,SLOT(ReadToBuffer()));

    connect(this, SIGNAL(error(int,QString)),
                 this, SLOT(DisplayError(int,QString)));     //find out name of this machine
    name = QHostInfo::localHostName();
    if(!name.isEmpty())
    {
        QString domain = QHostInfo::localDomainName();
        if (!domain.isEmpty())
            name = name + QChar('.') + domain;
    }
    if (name!=QString("localhost"))
        name = QString("localhost");
    qDebug()<< "- " + name;
    port = myPort;//6340;
    SocketIsConnected = false;
    SkipLoop = false;
    DataAcqStartFlag = false;
    numBlock = 0;
    DataACK = false;

}

//*************************************************************************************************************

void BabyMEGClient::SetInfo(BabyMEGInfo *pInfo)
{
    myBabyMEGInfo = pInfo;
}

//*************************************************************************************************************

void BabyMEGClient::DisplayError(int socketError, const QString &message)
{
    switch (socketError){
    case QAbstractSocket::RemoteHostClosedError:
            break;
    case QAbstractSocket::HostNotFoundError:
        qDebug()<< "The host was not found. Please check the host name and the port number";
        break;
    case QAbstractSocket::ConnectionRefusedError:
        qDebug()<< "The connection was refused by the peer. Make sure the server is running?";
        break;
    default:
        qDebug()<< "Error: " << message;
    }
}

//*************************************************************************************************************

int BabyMEGClient::MGH_LM_Byte2Int(QByteArray b)
{
    int value= 0;
    for (int i=0;i<2;i++)
    {
        QByteArray t;
        t[0] = b[i];
        b[i] = b[3-i];
        b[3-i] = t[0];
    }
    memcpy((char *)&value,b,4);
    return value;
}

//*************************************************************************************************************

QByteArray BabyMEGClient::MGH_LM_Int2Byte(int a)
{
    QByteArray b = QByteArray::fromRawData((char *)&a,4);

    for (int i=0;i<2;i++)
    {
        QByteArray t;
        t[0] = b[i];
        b[i] = b[3-i];
        b[3-i] = t[0];
    }
    return b;
}

//*************************************************************************************************************

double BabyMEGClient::MGH_LM_Byte2Double(QByteArray b)
{
    double value= 1.0;
    // reverse the byte order
    for (int i=0;i<4;i++)
    {
        QByteArray t;
        t[0] = b[i];
        b[i] = b[7-i];
        b[7-i] = t[0];
    }
    memcpy((char *)&value,b,8);

    return value;
}

//*************************************************************************************************************

void BabyMEGClient::HexDisplay(double a)
{
    QByteArray data = QByteArray::fromRawData((char *)&a,8);
    qDebug() << data.toHex();
}

//*************************************************************************************************************

void BabyMEGClient::ConnectToBabyMEG()
{
    // return true: sucessfully connect to babyMEG server
    //        false: fail.
    SocketIsConnected = false;
    // Connect to the server of babyMEG [labview]
    qDebug()<< "Client is started!";

    if (!this->isRunning())
    {
        this->start();
    }

    for(int i=0;i<5;i++){
        tcpSocket->connectToHost(name,port,QIODevice::ReadWrite);
        if (tcpSocket->waitForConnected(10000))
        {
            SocketIsConnected = true;
            qDebug("Connect to BabyMEG Server ... Ok");
            //download parameters
            qDebug()<< "Send the initial parameter request";
            if (tcpSocket->state()==QAbstractSocket::ConnectedState)
            {
                buffer.clear();
                SendCommand("INFO");
            }
            return;
        }
        else{
            qDebug("Connect to BabyMEG Server ... Fail");
            qDebug("Try another time connection");
        }
        qDebug("Please check the babyMEG server: if started");
    }
    return;
}

//*************************************************************************************************************

void BabyMEGClient::DisConnectBabyMEG()
{
    if(SocketIsConnected && tcpSocket->state()==QAbstractSocket::ConnectedState)
        SendCommand("QUIT");
}

//*************************************************************************************************************

void BabyMEGClient::SendCommandToBabyMEGShortConnection()
{
    qDebug() << "SendCommandToBabyMEGShortConnection";
    tcpSocket->connectToHost(name,port,QIODevice::ReadWrite);
    if (tcpSocket->waitForConnected(10000))
    {

        qDebug()<<"Connection is built.";

        if(tcpSocket->state()==QAbstractSocket::ConnectedState)
        {
            qDebug()<<"Send Command [COMS]";
            tcpSocket->write("COMS");
            int strlen = 3;
            QByteArray Scmd = MGH_LM_Int2Byte(strlen);

            tcpSocket->write(Scmd);
            tcpSocket->write("SLM");
            tcpSocket->waitForBytesWritten();
        }
    }

}

//*************************************************************************************************************

void BabyMEGClient::SendCommandToBabyMEG()
{
    qDebug()<<"Send Command";
    if(SocketIsConnected && tcpSocket->state()==QAbstractSocket::ConnectedState)
    {
        m_qMutex.lock();
        tcpSocket->write("COMD");
        tcpSocket->waitForBytesWritten();

        int strlen = 3;
        QByteArray Scmd = MGH_LM_Int2Byte(strlen);

        tcpSocket->write(Scmd);
        tcpSocket->write("SLM");
        tcpSocket->waitForBytesWritten();
        m_qMutex.unlock();
    }

}

//*************************************************************************************************************

void BabyMEGClient::ReadToBuffer()
{

    QByteArray dat;

    int numBytes = tcpSocket->bytesAvailable();
//    qDebug() << "1.byte available: " << numBytes;
    if (numBytes > 0){
        dat = tcpSocket->read(numBytes); // read all pending data
//        qDebug()<<"[dat Size]"<<dat.size();
        if (!dat.isEmpty()){
            buffer.append(dat); // and append it to your own buffer
//            qDebug()<<"[ReadToBuffer: Buffer Size]"<<buffer.size();
        }
        else
        {
            qDebug()<<"[Empty dat: error]"<<tcpSocket->errorString();
        }
    }
//    qDebug()<<"read buffer is done!";

    handleBuffer();
    return;
}

//*************************************************************************************************************

void BabyMEGClient::handleBuffer()
{
    if(buffer.size()>= 8){
        QByteArray CMD = buffer.left(4);
        QByteArray DLEN = buffer.mid(4,4);
        int tmp = MGH_LM_Byte2Int(DLEN);
//        qDebug() << "First 4 bytes + length" << CMD << "["<<CMD.toHex()<<"]";
//        qDebug() << "Command[" << CMD <<"]";
//        qDebug() << "Body Length[" << tmp << "]";

        if (tmp <= (buffer.size() - 8))
        {
            buffer.remove(0,8);

            int OPT = 0;

            if (CMD == "INFO")
                OPT = 1;
            else if (CMD == "DATR")
                OPT = 2;
            else if (CMD == "COMD")
                OPT = 3;
            else if (CMD == "QUIT")
                OPT = 4;
            else if (CMD == "COMS")
                OPT = 5;
            else if (CMD == "QUIS")
                OPT = 6;

            switch (OPT){
            case 1:
                // from buffer get data package
                {
                QByteArray PARA = buffer.left(tmp);
                qDebug()<<"[INFO]"<<PARA;
                //Parse parameters from PARA string
                myBabyMEGInfo->MGH_LM_Parse_Para(PARA);
                buffer.remove(0,tmp);
                qDebug()<<"ACQ Start";
                SendCommand("DATA");
                }
                break;
            case 2:
                // read data package from buffer
                // Ask for the next data block

                SendCommand("DATA");
                DispatchDataPackage(tmp);

                break;
            case 3:
                {
                QByteArray RESP = buffer.left(tmp);
                qDebug()<< "5.Readbytes:"<<RESP.size();
                qDebug() << RESP;
                }
                buffer.remove(0,tmp);

                break;
            case 4:  //quit
                qDebug()<<"Quit";

                SendCommand("QREL");
                tcpSocket->disconnectFromHost();
                if(tcpSocket->state() != QAbstractSocket::UnconnectedState)
                            tcpSocket->waitForDisconnected();
                SocketIsConnected = false;
                qDebug()<< "Disconnect Server";
                qDebug()<< "Client is End!";
                qDebug()<< "You can close this application or restart to connect Server.";

                break;
            case 5://command short connection
                {
                QByteArray RESP = buffer.left(tmp);
                qDebug()<< "5.Readbytes:"<<RESP.size();
                qDebug() << RESP;
                }
                buffer.remove(0,tmp);
                SendCommand("QUIT");
                break;
            case 6:  //quit
                qDebug()<<"Quit";

                SendCommand("QREL");
                tcpSocket->disconnectFromHost();
                if(tcpSocket->state() != QAbstractSocket::UnconnectedState)
                            tcpSocket->waitForDisconnected();
                SocketIsConnected = false;
                qDebug()<< "Disconnect Server";
                break;

            default:
                qDebug()<< "Unknow Type";
                break;
            }
        }
    }// buffer is not empty and larger than 8 bytes

}

//*************************************************************************************************************

void BabyMEGClient::DispatchDataPackage(int tmp)
{

//    qDebug()<<"Acq data from buffer  [buffer size() =" << buffer.size()<<"]";
    QByteArray DATA = buffer.left(tmp);
    qDebug()<< "5.Readbytes:"<<DATA.size();
//    myBabyMEGInfo->EnQueue(DATA);
    buffer.remove(0,tmp);
//    qDebug()<<"Rest buffer  [buffer size() =" << buffer.size()<<"]";
    numBlock ++;
    qDebug()<< "Next Block ..." << numBlock;
//    DATA.clear();

//    ReadNextBlock(tmp);
}

//*************************************************************************************************************

void BabyMEGClient::ReadNextBlock(int tmp)
{
    QByteArray CMD1;
    QByteArray DLEN1;
    QByteArray DATA1;
    int tmp1;
    while (buffer.size()>=(tmp+8))
    { // process the extra data block to reduce the load of data buffer
        CMD1 = buffer.left(4);
        qDebug()<<"CMD"<< CMD1;
        if (CMD1 == "DATR")
        {
            DLEN1 = buffer.mid(4,4);
            tmp1 = MGH_LM_Byte2Int(DLEN1);
            qDebug() << "[2]First 4 bytes + length" << CMD1 << "["<<CMD1.toHex()<<"]";
            qDebug() << "[2]Command[" << CMD1 <<"]";
            qDebug() << "[2]Body Length[" << tmp1 << "]";

            buffer.remove(0,8);
            DATA1 = buffer.left(tmp1);
            myBabyMEGInfo->EnQueue(DATA1);
            buffer.remove(0,tmp1);
            qDebug()<<"End of DataPackeage" << buffer.left(3);
            qDebug()<<"[2]Rest buffer  [buffer size() =" << buffer.size()<<"]";
            numBlock ++;
            qDebug()<< "[2]Next Block ..." << numBlock;
        }
        else
        {
            qDebug()<<"[CMD1]"<<CMD1.toHex();
            break;
        }
        qDebug()<<"[ReadNextBlock:buffer size]"<<buffer.size();
    }
    DATA1.clear();
    CMD1.clear();
    DLEN1.clear();
}

//*************************************************************************************************************

void BabyMEGClient::SendCommand(QString s)
{
    QByteArray array;
    array.append(s);

    int WrtNum;

    if (tcpSocket->state()==QAbstractSocket::ConnectedState)
    {
        m_qMutex.lock();

//    qDebug()<<"[Send Command]"<<array;
        WrtNum = tcpSocket->write(array,4);
        if(WrtNum==-1)
        {
            qDebug()<<"Error for sending a command";
        }
        if(WrtNum != array.size())
        {
            qDebug()<<"Uncorrectly sending";
        }
        tcpSocket->flush();
        tcpSocket->waitForBytesWritten();
        m_qMutex.unlock();
        qDebug()<<"[Done: Send Command]"<<array<<"[Send bytes]"<<WrtNum;

        }
        else
        {
            qDebug()<<"Not in Connected state";
            //re-connect to server
            ConnectToBabyMEG();
            buffer.clear();
            SendCommand("DATA");
        }
//    sleep(1);
}

//*************************************************************************************************************

void BabyMEGClient::run()
{

}
<|endoftext|>


<commit_before>#include "GL/glew.h"

#include <stdlib.h>
#include <stdio.h>

#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/rotate_vector.hpp>

#include "photon_opengl.h"
#include "photon_window_managment.h"
#include "photon_core.h"
#include "photon_blocks.h"
#include "photon_texture.h"

#include <physfs.h>
#include <SOIL.h>

namespace photon{

namespace opengl{
photon_shader shader_scene;
photon_shader shader_laser;
photon_shader shader_light;
photon_shader shader_fx;
photon_shader shader_text;

GLuint photon_texture;
GLuint background;

void InitOpenGL(photon_window &window){
    PrintToLog("INFO: Initializing OpenGL.");
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    GLuint glewstatus = glewInit();
    if(glewstatus != GLEW_OK){
        PrintToLog("GLEW ERROR: %s", glewGetErrorString(glewstatus));
        return;
    }
    if(GLEW_VERSION_2_0){
        PrintToLog("INFO: OpenGL 2.0 support detected, things should work fine.");
    }else{
        PrintToLog("WARNING: OpenGL 2.0 support NOT detected, things probably won't work.");
    }

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    glGenTextures(1, &window.light_buffer_texture);
    glBindTexture(GL_TEXTURE_2D, window.light_buffer_texture);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    // texture size is 1x1 because it will get resized properly later (on resized event from window creation)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

    glBindTexture(GL_TEXTURE_2D, 0);

    glGenFramebuffers(1, &window.light_buffer);
    glBindFramebuffer(GL_FRAMEBUFFER, window.light_buffer);

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, window.light_buffer_texture, 0);

    GLenum buffer = GL_COLOR_ATTACHMENT0;
    glDrawBuffers(1, &buffer);

    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
        PrintToLog("ERROR: Frambuffer creation failed!");
        // TODO - proper error handling.
        throw;
    }
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glDisable(GL_CULL_FACE);
    glEnable(GL_MULTISAMPLE);

    glEnableVertexAttribArray(PHOTON_VERTEX_LOCATION_ATTRIBUTE);
    glEnableVertexAttribArray(PHOTON_VERTEX_UV_ATTRIBUTE);

    shader_scene = LoadShaderXML("/shaders/scene.xml");
    glUniform1f(glGetUniformLocation(shader_scene.program, "zoom"), 1.0f);

    shader_laser = LoadShaderXML("/shaders/laser.xml");
    glUniform1f(glGetUniformLocation(shader_laser.program, "zoom"), 1.0f);

    shader_light = LoadShaderXML("/shaders/light.xml");
    glUniform1f(glGetUniformLocation(shader_light.program, "zoom"), 1.0f);

    shader_fx = LoadShaderXML("/shaders/fx.xml");
    glUniform1f(glGetUniformLocation(shader_fx.program, "zoom"), 1.0f);

    shader_text = LoadShaderXML("/shaders/text.xml");

    blocks::LoadTextures();

    photon_texture = texture::Load("/textures/photon.png");
    background = texture::Load("/textures/background.png");

    if(!opengl::CheckOpenGLErrors()){
        PrintToLog("INFO: OpenGL succesfully initilized.");
    }
}

void GarbageCollect(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    CheckOpenGLErrors();

    texture::GarbageCollect();

    DeleteShader(shader_scene);

    PrintToLog("INFO: OpenGL garbage collection complete.");
}

void OnResize(uint32_t width, uint32_t height, photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    PrintToLog("INFO: Resizing window to %ix%i.", width, height);

    float aspect = (float)width/(float)height;

    glUseProgram(shader_scene.program);

    glUniform1f(glGetUniformLocation(shader_scene.program, "aspect"), aspect);
    glUseProgram(shader_laser.program);
    glUniform1f(glGetUniformLocation(shader_laser.program, "aspect"), aspect);
    glUseProgram(shader_light.program);
    glUniform1f(glGetUniformLocation(shader_light.program, "aspect"), aspect);
    glUseProgram(shader_fx.program);
    glUniform1f(glGetUniformLocation(shader_fx.program, "aspect"), aspect);
    glUseProgram(shader_text.program);
    glUniform1f(glGetUniformLocation(shader_text.program, "aspect"), aspect);

    glViewport(0, 0, width, height);

    window.width = width;
    window.height = height;

    glBindTexture(GL_TEXTURE_2D, window.light_buffer_texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
}

GLenum CheckOpenGLErrors(){
    GLenum err = glGetError();

    switch(err){
    case GL_INVALID_ENUM:
        PrintToLog("OPENGL ERROR: Invalid Enum.");
        break;
    case GL_INVALID_VALUE:
        PrintToLog("OPENGL ERROR: Invalid Value.");
        break;
    case GL_INVALID_OPERATION:
        PrintToLog("OPENGL ERROR: Invalid Operation.");
        break;
    case GL_INVALID_FRAMEBUFFER_OPERATION:
        PrintToLog("OPENGL ERROR: Invalid Framebuffer Operation.");
        break;
    case GL_OUT_OF_MEMORY:
        PrintToLog("OPENGL ERROR: Out Of Memory.");
        break;
    case GL_NO_ERROR:
        break;
    }

    return err;
}

void UpdateZoom(const float &zoom){
    glUseProgram(shader_scene.program);
    glUniform1f(glGetUniformLocation(shader_scene.program, "zoom"), 1.0f / zoom);
    glUseProgram(shader_laser.program);
    glUniform1f(glGetUniformLocation(shader_laser.program, "zoom"), 1.0f / zoom);
    glUseProgram(shader_light.program);
    glUniform1f(glGetUniformLocation(shader_light.program, "zoom"), 1.0f / zoom);
    glUseProgram(shader_fx.program);
    glUniform1f(glGetUniformLocation(shader_fx.program, "zoom"),    1.0f / zoom);
}

void UpdateCenter(const glm::vec2 &center){
    glUseProgram(shader_scene.program);
    glUniform2fv(glGetUniformLocation(shader_scene.program, "center"), 1, glm::value_ptr(center));
    glUseProgram(shader_laser.program);
    glUniform2fv(glGetUniformLocation(shader_laser.program, "center"), 1, glm::value_ptr(center));
    glUseProgram(shader_light.program);
    glUniform2fv(glGetUniformLocation(shader_light.program, "center"), 1, glm::value_ptr(center));
    glUseProgram(shader_fx.program);
    glUniform2fv(glGetUniformLocation(shader_fx.program, "center"),    1, glm::value_ptr(center));
}

void DrawModeScene(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glClear(GL_COLOR_BUFFER_BIT);

    glDisable(GL_BLEND);

    glActiveTexture(PHOTON_TEXTURE_UNIT_LIGHT);
    glBindTexture(GL_TEXTURE_2D, window.light_buffer_texture);
    glActiveTexture(PHOTON_TEXTURE_UNIT_COLOR);
}

void DrawModeLaser(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE);

    glUseProgram(shader_laser.program);
}

void DrawModeLevel(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);

    glUseProgram(shader_scene.program);

    glActiveTexture(PHOTON_TEXTURE_UNIT_LIGHT);
    glBindTexture(GL_TEXTURE_2D, window.light_buffer_texture);
    glActiveTexture(PHOTON_TEXTURE_UNIT_COLOR);
}

void DrawModeLight(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glBindFramebuffer(GL_FRAMEBUFFER, window.light_buffer);

    glClear(GL_COLOR_BUFFER_BIT);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE);

    glUseProgram(shader_light.program);

    glActiveTexture(PHOTON_TEXTURE_UNIT_LIGHT);
    glBindTexture(GL_TEXTURE_2D, 0);
    glActiveTexture(PHOTON_TEXTURE_UNIT_COLOR);
}

void DrawPhoton(const glm::vec2 &location){
    glBindTexture(GL_TEXTURE_2D, photon_texture);

    SetFacFX(1.0f);
    static const float verts[] = { 0.2f, 0.2f,
                                  -0.2f, 0.2f,
                                  -0.2f,-0.2f,
                                   0.2f,-0.2f};

    static const float uv[] = {1.0f, 1.0f,
                               0.0f, 1.0f,
                               0.0f, 0.0f,
                               1.0f, 0.0f};

    opengl::SetModelMatrix(glm::mat3(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, location.x, location.y, 1.0f));

    glVertexAttribPointer(PHOTON_VERTEX_LOCATION_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, 0, verts);
    glVertexAttribPointer(PHOTON_VERTEX_UV_ATTRIBUTE,       2, GL_FLOAT, GL_FALSE, 0, uv);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}

void DrawPhotonLight(const glm::vec2 &location){
    static const float verts[] = { 16.0f, 16.0f,
                                  -16.0f, 16.0f,
                                  -16.0f,-16.0f,
                                   16.0f,-16.0f};

    static const float uv[] = {  1.0f, 1.0f,
                                -1.0f, 1.0f,
                                -1.0f,-1.0f,
                                 1.0f,-1.0f};

    opengl::SetModelMatrix(glm::mat3(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, location.x, location.y, 1.0f));

    glVertexAttribPointer(PHOTON_VERTEX_LOCATION_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, 0, verts);
    glVertexAttribPointer(PHOTON_VERTEX_UV_ATTRIBUTE,       2, GL_FLOAT, GL_FALSE, 0, uv);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}

void DrawModeGUI(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

    glUseProgram(shader_text.program);
}

void SetColorGUI(const glm::vec4 &color){
    glUseProgram(shader_text.program);
    glUniform4fv(glGetUniformLocation(shader_text.program, "color"), 1, glm::value_ptr(color));
}

void SetCenterGUI(const glm::vec2 &center){
    glUseProgram(shader_text.program);
    glUniform2fv(glGetUniformLocation(shader_text.program, "center"), 1, glm::value_ptr(center));
}

void SetFacFX(const float &fac){
    glUniform1f(glGetUniformLocation(shader_fx.program, "fac"), fac);
}

void SetLaserColor(const glm::vec3 &color){
    glUniform3fv(glGetUniformLocation(shader_laser.program, "color"), 1, glm::value_ptr(color));
    glUniform3fv(glGetUniformLocation(shader_light.program, "color"), 1, glm::value_ptr(color));
}

void SetModelMatrix(const glm::mat3 &matrix){
    GLint program = 0;
    glGetIntegerv(GL_CURRENT_PROGRAM, &program);
    GLint uniform = glGetUniformLocation(program, "model");
    if(uniform > -1){
        glUniformMatrix3fv(uniform, 1, GL_FALSE, glm::value_ptr(matrix));
    }
}

void DrawModeFX(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE);

    glUseProgram(shader_fx.program);

    glActiveTexture(PHOTON_TEXTURE_UNIT_LIGHT);
    glBindTexture(GL_TEXTURE_2D, 0);
    glActiveTexture(PHOTON_TEXTURE_UNIT_COLOR);
}

void DrawBackground(photon_instance &instance){
    static const float verts[] = { 1.0f, 1.0f,
                                   1.0f,-1.0f,
                                   -1.0f,-1.0f,
                                   -1.0f, 1.0f};

    static const float uv[] = {1.0f, 1.0f,
                               1.0f, 0.0f,
                               0.0f, 0.0f,
                               0.0f, 1.0f};
    DrawModeLevel(instance.window);

    glBindTexture(GL_TEXTURE_2D, background);

    glm::mat3 matrix(instance.zoom);

    float aspect = float(instance.window.width) / float(instance.window.height);
    if(aspect > 1.0f){
        matrix *= aspect;
    }else if(aspect < 1.0f){
        matrix /= aspect;
    }
    matrix[2] = glm::vec3(instance.player.location, 1.0f);

    opengl::SetModelMatrix(matrix);

    glVertexAttribPointer(PHOTON_VERTEX_LOCATION_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, 0, verts);
    glVertexAttribPointer(PHOTON_VERTEX_UV_ATTRIBUTE,       2, GL_FLOAT, GL_FALSE, 0, uv);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}

}
}
<commit_msg>draw background with some flat lighting.<commit_after>#include "GL/glew.h"

#include <stdlib.h>
#include <stdio.h>

#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/rotate_vector.hpp>

#include "photon_opengl.h"
#include "photon_window_managment.h"
#include "photon_core.h"
#include "photon_blocks.h"
#include "photon_texture.h"

#include <physfs.h>
#include <SOIL.h>

namespace photon{

namespace opengl{
photon_shader shader_scene;
photon_shader shader_laser;
photon_shader shader_light;
photon_shader shader_fx;
photon_shader shader_text;

GLuint photon_texture;
GLuint background;

void InitOpenGL(photon_window &window){
    PrintToLog("INFO: Initializing OpenGL.");
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    GLuint glewstatus = glewInit();
    if(glewstatus != GLEW_OK){
        PrintToLog("GLEW ERROR: %s", glewGetErrorString(glewstatus));
        return;
    }
    if(GLEW_VERSION_2_0){
        PrintToLog("INFO: OpenGL 2.0 support detected, things should work fine.");
    }else{
        PrintToLog("WARNING: OpenGL 2.0 support NOT detected, things probably won't work.");
    }

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    glGenTextures(1, &window.light_buffer_texture);
    glBindTexture(GL_TEXTURE_2D, window.light_buffer_texture);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    // texture size is 1x1 because it will get resized properly later (on resized event from window creation)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

    glBindTexture(GL_TEXTURE_2D, 0);

    glGenFramebuffers(1, &window.light_buffer);
    glBindFramebuffer(GL_FRAMEBUFFER, window.light_buffer);

    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, window.light_buffer_texture, 0);

    GLenum buffer = GL_COLOR_ATTACHMENT0;
    glDrawBuffers(1, &buffer);

    if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
        PrintToLog("ERROR: Frambuffer creation failed!");
        // TODO - proper error handling.
        throw;
    }
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glDisable(GL_CULL_FACE);
    glEnable(GL_MULTISAMPLE);

    glEnableVertexAttribArray(PHOTON_VERTEX_LOCATION_ATTRIBUTE);
    glEnableVertexAttribArray(PHOTON_VERTEX_UV_ATTRIBUTE);

    shader_scene = LoadShaderXML("/shaders/scene.xml");
    glUniform1f(glGetUniformLocation(shader_scene.program, "zoom"), 1.0f);

    shader_laser = LoadShaderXML("/shaders/laser.xml");
    glUniform1f(glGetUniformLocation(shader_laser.program, "zoom"), 1.0f);

    shader_light = LoadShaderXML("/shaders/light.xml");
    glUniform1f(glGetUniformLocation(shader_light.program, "zoom"), 1.0f);

    shader_fx = LoadShaderXML("/shaders/fx.xml");
    glUniform1f(glGetUniformLocation(shader_fx.program, "zoom"), 1.0f);

    shader_text = LoadShaderXML("/shaders/text.xml");

    blocks::LoadTextures();

    photon_texture = texture::Load("/textures/photon.png");
    background = texture::Load("/textures/background.png");

    if(!opengl::CheckOpenGLErrors()){
        PrintToLog("INFO: OpenGL succesfully initilized.");
    }
}

void GarbageCollect(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    CheckOpenGLErrors();

    texture::GarbageCollect();

    DeleteShader(shader_scene);

    PrintToLog("INFO: OpenGL garbage collection complete.");
}

void OnResize(uint32_t width, uint32_t height, photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    PrintToLog("INFO: Resizing window to %ix%i.", width, height);

    float aspect = (float)width/(float)height;

    glUseProgram(shader_scene.program);

    glUniform1f(glGetUniformLocation(shader_scene.program, "aspect"), aspect);
    glUseProgram(shader_laser.program);
    glUniform1f(glGetUniformLocation(shader_laser.program, "aspect"), aspect);
    glUseProgram(shader_light.program);
    glUniform1f(glGetUniformLocation(shader_light.program, "aspect"), aspect);
    glUseProgram(shader_fx.program);
    glUniform1f(glGetUniformLocation(shader_fx.program, "aspect"), aspect);
    glUseProgram(shader_text.program);
    glUniform1f(glGetUniformLocation(shader_text.program, "aspect"), aspect);

    glViewport(0, 0, width, height);

    window.width = width;
    window.height = height;

    glBindTexture(GL_TEXTURE_2D, window.light_buffer_texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
}

GLenum CheckOpenGLErrors(){
    GLenum err = glGetError();

    switch(err){
    case GL_INVALID_ENUM:
        PrintToLog("OPENGL ERROR: Invalid Enum.");
        break;
    case GL_INVALID_VALUE:
        PrintToLog("OPENGL ERROR: Invalid Value.");
        break;
    case GL_INVALID_OPERATION:
        PrintToLog("OPENGL ERROR: Invalid Operation.");
        break;
    case GL_INVALID_FRAMEBUFFER_OPERATION:
        PrintToLog("OPENGL ERROR: Invalid Framebuffer Operation.");
        break;
    case GL_OUT_OF_MEMORY:
        PrintToLog("OPENGL ERROR: Out Of Memory.");
        break;
    case GL_NO_ERROR:
        break;
    }

    return err;
}

void UpdateZoom(const float &zoom){
    glUseProgram(shader_scene.program);
    glUniform1f(glGetUniformLocation(shader_scene.program, "zoom"), 1.0f / zoom);
    glUseProgram(shader_laser.program);
    glUniform1f(glGetUniformLocation(shader_laser.program, "zoom"), 1.0f / zoom);
    glUseProgram(shader_light.program);
    glUniform1f(glGetUniformLocation(shader_light.program, "zoom"), 1.0f / zoom);
    glUseProgram(shader_fx.program);
    glUniform1f(glGetUniformLocation(shader_fx.program, "zoom"),    1.0f / zoom);
}

void UpdateCenter(const glm::vec2 &center){
    glUseProgram(shader_scene.program);
    glUniform2fv(glGetUniformLocation(shader_scene.program, "center"), 1, glm::value_ptr(center));
    glUseProgram(shader_laser.program);
    glUniform2fv(glGetUniformLocation(shader_laser.program, "center"), 1, glm::value_ptr(center));
    glUseProgram(shader_light.program);
    glUniform2fv(glGetUniformLocation(shader_light.program, "center"), 1, glm::value_ptr(center));
    glUseProgram(shader_fx.program);
    glUniform2fv(glGetUniformLocation(shader_fx.program, "center"),    1, glm::value_ptr(center));
}

void DrawModeScene(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glClear(GL_COLOR_BUFFER_BIT);

    glDisable(GL_BLEND);

    glActiveTexture(PHOTON_TEXTURE_UNIT_LIGHT);
    glBindTexture(GL_TEXTURE_2D, window.light_buffer_texture);
    glActiveTexture(PHOTON_TEXTURE_UNIT_COLOR);
}

void DrawModeLaser(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE);

    glUseProgram(shader_laser.program);
}

void DrawModeLevel(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);

    glUseProgram(shader_scene.program);

    glActiveTexture(PHOTON_TEXTURE_UNIT_LIGHT);
    glBindTexture(GL_TEXTURE_2D, window.light_buffer_texture);
    glActiveTexture(PHOTON_TEXTURE_UNIT_COLOR);
}

void DrawModeLight(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glBindFramebuffer(GL_FRAMEBUFFER, window.light_buffer);

    glClear(GL_COLOR_BUFFER_BIT);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE);

    glUseProgram(shader_light.program);

    glActiveTexture(PHOTON_TEXTURE_UNIT_LIGHT);
    glBindTexture(GL_TEXTURE_2D, 0);
    glActiveTexture(PHOTON_TEXTURE_UNIT_COLOR);
}

void DrawPhoton(const glm::vec2 &location){
    glBindTexture(GL_TEXTURE_2D, photon_texture);

    SetFacFX(1.0f);
    static const float verts[] = { 0.2f, 0.2f,
                                  -0.2f, 0.2f,
                                  -0.2f,-0.2f,
                                   0.2f,-0.2f};

    static const float uv[] = {1.0f, 1.0f,
                               0.0f, 1.0f,
                               0.0f, 0.0f,
                               1.0f, 0.0f};

    opengl::SetModelMatrix(glm::mat3(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, location.x, location.y, 1.0f));

    glVertexAttribPointer(PHOTON_VERTEX_LOCATION_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, 0, verts);
    glVertexAttribPointer(PHOTON_VERTEX_UV_ATTRIBUTE,       2, GL_FLOAT, GL_FALSE, 0, uv);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}

void DrawPhotonLight(const glm::vec2 &location){
    static const float verts[] = { 16.0f, 16.0f,
                                  -16.0f, 16.0f,
                                  -16.0f,-16.0f,
                                   16.0f,-16.0f};

    static const float uv[] = {  1.0f, 1.0f,
                                -1.0f, 1.0f,
                                -1.0f,-1.0f,
                                 1.0f,-1.0f};

    opengl::SetModelMatrix(glm::mat3(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, location.x, location.y, 1.0f));

    glVertexAttribPointer(PHOTON_VERTEX_LOCATION_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, 0, verts);
    glVertexAttribPointer(PHOTON_VERTEX_UV_ATTRIBUTE,       2, GL_FLOAT, GL_FALSE, 0, uv);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}

void DrawModeGUI(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

    glUseProgram(shader_text.program);
}

void SetColorGUI(const glm::vec4 &color){
    glUseProgram(shader_text.program);
    glUniform4fv(glGetUniformLocation(shader_text.program, "color"), 1, glm::value_ptr(color));
}

void SetCenterGUI(const glm::vec2 &center){
    glUseProgram(shader_text.program);
    glUniform2fv(glGetUniformLocation(shader_text.program, "center"), 1, glm::value_ptr(center));
}

void SetFacFX(const float &fac){
    glUniform1f(glGetUniformLocation(shader_fx.program, "fac"), fac);
}

void SetLaserColor(const glm::vec3 &color){
    glUniform3fv(glGetUniformLocation(shader_laser.program, "color"), 1, glm::value_ptr(color));
    glUniform3fv(glGetUniformLocation(shader_light.program, "color"), 1, glm::value_ptr(color));
}

void SetModelMatrix(const glm::mat3 &matrix){
    GLint program = 0;
    glGetIntegerv(GL_CURRENT_PROGRAM, &program);
    GLint uniform = glGetUniformLocation(program, "model");
    if(uniform > -1){
        glUniformMatrix3fv(uniform, 1, GL_FALSE, glm::value_ptr(matrix));
    }
}

void DrawModeFX(photon_window &window){
    SDL_GL_MakeCurrent(window.window_SDL, window.context_SDL);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE,GL_ONE);

    glUseProgram(shader_fx.program);

    glActiveTexture(PHOTON_TEXTURE_UNIT_LIGHT);
    glBindTexture(GL_TEXTURE_2D, 0);
    glActiveTexture(PHOTON_TEXTURE_UNIT_COLOR);
}

void DrawBackground(photon_instance &instance){
    static const float verts[] = { 1.0f, 1.0f,
                                   1.0f,-1.0f,
                                   -1.0f,-1.0f,
                                   -1.0f, 1.0f};

    static const float uv[] = {1.0f, 1.0f,
                               1.0f, 0.0f,
                               0.0f, 0.0f,
                               0.0f, 1.0f};

    DrawModeLevel(instance.window);

    glBindTexture(GL_TEXTURE_2D, background);

    glm::mat3 matrix(instance.zoom);

    float aspect = float(instance.window.width) / float(instance.window.height);
    if(aspect > 1.0f){
        matrix *= aspect;
    }else if(aspect < 1.0f){
        matrix /= aspect;
    }
    matrix[2] = glm::vec3(instance.player.location, 1.0f);

    opengl::SetModelMatrix(matrix);

    glVertexAttribPointer(PHOTON_VERTEX_LOCATION_ATTRIBUTE, 2, GL_FLOAT, GL_FALSE, 0, verts);
    glVertexAttribPointer(PHOTON_VERTEX_UV_ATTRIBUTE,       2, GL_FLOAT, GL_FALSE, 0, uv);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

    DrawModeFX(instance.window);
    SetFacFX(0.4f);
    opengl::SetModelMatrix(matrix);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}

}
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: provider.cxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: abi $ $Date: 2001-06-06 14:48:47 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

/**************************************************************************
                                TODO
 **************************************************************************

 *************************************************************************/

#ifndef _VOS_DIAGNOSE_HXX_
#include <vos/diagnose.hxx>
#endif
#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX
#include <ucbhelper/contentidentifier.hxx>
#endif
#ifndef _DATABASES_HXX_
#include <provider/databases.hxx>
#endif
#ifndef _PROVIDER_HXX
#include <provider/provider.hxx>
#endif
#ifndef _CONTENT_HXX
#include <provider/content.hxx>
#endif
#ifndef _DATABASES_HXX_
#include <provider/databases.hxx>
#endif
#ifndef COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XCONFIGMANAGER_HPP_
#include <com/sun/star/frame/XConfigManager.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_
#include <com/sun/star/beans/PropertyAttribute.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
#include <com/sun/star/beans/PropertyValue.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATE_HPP_
#include <com/sun/star/beans/PropertyState.hpp>
#endif

using namespace com::sun::star::frame;
using namespace com::sun::star::beans;
using namespace com::sun::star::container;
using namespace com::sun::star::lang;
using namespace com::sun::star::ucb;
using namespace com::sun::star::uno;
using namespace rtl;

using namespace chelp;

//=========================================================================
//=========================================================================
//
// ContentProvider Implementation.
//
//=========================================================================
//=========================================================================

ContentProvider::ContentProvider( const Reference< XMultiServiceFactory >& rSMgr )
    : ::ucb::ContentProviderImplHelper( rSMgr ),
             isInitialized( false ),
             m_aScheme( OUString::createFromAscii( MYUCP_URL_SCHEME ) ),
             m_pDatabases( 0 )
{
}

//=========================================================================
// virtual
ContentProvider::~ContentProvider()
{
    delete m_pDatabases;
}

//=========================================================================
//
// XInterface methods.
//
//=========================================================================

XINTERFACE_IMPL_3( ContentProvider,
                   XTypeProvider,
                   XServiceInfo,
                   XContentProvider );

//=========================================================================
//
// XTypeProvider methods.
//
//=========================================================================

XTYPEPROVIDER_IMPL_3( ContentProvider,
                         XTypeProvider,
                         XServiceInfo,
                         XContentProvider );

//=========================================================================
//
// XServiceInfo methods.
//
//=========================================================================

XSERVICEINFO_IMPL_1( ContentProvider,
                     OUString::createFromAscii(
                             "CHelpContentProvider" ),
                     OUString::createFromAscii(
                             MYUCP_CONTENT_PROVIDER_SERVICE_NAME ) );

//=========================================================================
//
// Service factory implementation.
//
//=========================================================================

ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );

//=========================================================================
//
// XContentProvider methods.
//
//=========================================================================

// virtual
Reference< XContent > SAL_CALL ContentProvider::queryContent( const Reference< XContentIdentifier >& xCanonicId )
    throw( IllegalIdentifierException, RuntimeException )
{
    if ( ! xCanonicId->getContentProviderScheme().equalsIgnoreAsciiCase( m_aScheme ) )
    {   // Wrong URL-scheme
        throw IllegalIdentifierException();
    }

    {
        osl::MutexGuard aGuard( m_aMutex );
        if( ! isInitialized )
            init();
    }

    if( ! m_pDatabases )
        throw RuntimeException();

    // Check, if a content with given id already exists...
    Reference< XContent > xContent
        = queryExistingContent( xCanonicId ).getBodyPtr();
    if ( xContent.is() )
        return xContent;

    xContent = new Content( m_xSMgr,this,xCanonicId,m_pDatabases );

    // Further checks

    if ( !xContent->getIdentifier().is() )
        throw IllegalIdentifierException();

    return xContent;
}

void ContentProvider::init()
{
    rtl::OUString sProviderService =
        rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" );

    // New access to configuration
    Any aAny;
    aAny <<= rtl::OUString::createFromAscii( "plugin" );
    PropertyValue aProp( rtl::OUString::createFromAscii( "servertype" ),
                         -1,
                         aAny,
                         PropertyState_DIRECT_VALUE );

    Sequence< Any > seq(1);
    seq[0] <<= aProp;

    Reference< XMultiServiceFactory >
        sProvider(
            m_xSMgr->createInstanceWithArguments( sProviderService,seq ),
            UNO_QUERY );

    rtl::OUString sReaderService =
        rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationAccess" );

    seq[0] <<= rtl::OUString::createFromAscii( "org.openoffice.Office.Common" );

    Reference< XHierarchicalNameAccess > xHierAccess(
        sProvider->createInstanceWithArguments( sReaderService,seq ),UNO_QUERY );

    aAny =
        xHierAccess->getByHierarchicalName( rtl::OUString::createFromAscii("Path/Current/Help") );

    rtl::OUString instPath;
    if( ! ( aAny >>= instPath ) )
        ;
    else
        instPath = rtl::OUString::createFromAscii( "$(instpath)/help" );

    Reference< XConfigManager > xCfgMgr(
        m_xSMgr->createInstance( rtl::OUString::createFromAscii( "com.sun.star.config.SpecialConfigManager" ) ),
        UNO_QUERY );

    VOS_ENSURE( xCfgMgr.is(),
                "HelpProvider::init - No Config Manager!" );

    if( xCfgMgr.is() )
        instPath = xCfgMgr->substituteVariables( instPath );

    m_pDatabases = new Databases( instPath,m_xSMgr );
    isInitialized = true;
}
<commit_msg>now only runtime exception if configuration can't be instantiated<commit_after>/*************************************************************************
 *
 *  $RCSfile: provider.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: abi $ $Date: 2001-07-06 13:32:50 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

/**************************************************************************
                                TODO
 **************************************************************************

 *************************************************************************/

#ifndef _VOS_DIAGNOSE_HXX_
#include <vos/diagnose.hxx>
#endif
#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX
#include <ucbhelper/contentidentifier.hxx>
#endif
#ifndef _DATABASES_HXX_
#include <provider/databases.hxx>
#endif
#ifndef _PROVIDER_HXX
#include <provider/provider.hxx>
#endif
#ifndef _CONTENT_HXX
#include <provider/content.hxx>
#endif
#ifndef _DATABASES_HXX_
#include <provider/databases.hxx>
#endif
#ifndef COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XCONFIGMANAGER_HPP_
#include <com/sun/star/frame/XConfigManager.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBBUTE_HPP_
#include <com/sun/star/beans/PropertyAttribute.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
#include <com/sun/star/beans/PropertyValue.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATE_HPP_
#include <com/sun/star/beans/PropertyState.hpp>
#endif

using namespace com::sun::star::frame;
using namespace com::sun::star::beans;
using namespace com::sun::star::container;
using namespace com::sun::star::lang;
using namespace com::sun::star::ucb;
using namespace com::sun::star::uno;
using namespace rtl;

using namespace chelp;

//=========================================================================
//=========================================================================
//
// ContentProvider Implementation.
//
//=========================================================================
//=========================================================================

ContentProvider::ContentProvider( const Reference< XMultiServiceFactory >& rSMgr )
  : ::ucb::ContentProviderImplHelper( rSMgr ),
                   isInitialized( false ),
                   m_aScheme( OUString::createFromAscii( MYUCP_URL_SCHEME ) ),
                   m_pDatabases( 0 )
{
}

//=========================================================================
// virtual
ContentProvider::~ContentProvider()
{
    delete m_pDatabases;
}

//=========================================================================
//
// XInterface methods.
//
//=========================================================================

XINTERFACE_IMPL_3( ContentProvider,
                   XTypeProvider,
                   XServiceInfo,
                   XContentProvider );

//=========================================================================
//
// XTypeProvider methods.
//
//=========================================================================

XTYPEPROVIDER_IMPL_3( ContentProvider,
                         XTypeProvider,
                         XServiceInfo,
                         XContentProvider );

//=========================================================================
//
// XServiceInfo methods.
//
//=========================================================================

XSERVICEINFO_IMPL_1( ContentProvider,
                     OUString::createFromAscii(
                             "CHelpContentProvider" ),
                     OUString::createFromAscii(
                             MYUCP_CONTENT_PROVIDER_SERVICE_NAME ) );

//=========================================================================
//
// Service factory implementation.
//
//=========================================================================

ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );

//=========================================================================
//
// XContentProvider methods.
//
//=========================================================================

// virtual
Reference< XContent > SAL_CALL ContentProvider::queryContent( const Reference< XContentIdentifier >& xCanonicId )
  throw( IllegalIdentifierException, RuntimeException )
{
  if ( ! xCanonicId->getContentProviderScheme().equalsIgnoreAsciiCase( m_aScheme ) )
    {   // Wrong URL-scheme
      throw IllegalIdentifierException();
    }

  {
    osl::MutexGuard aGuard( m_aMutex );
    if( ! isInitialized )
      init();
  }

  if( ! m_pDatabases )
    throw RuntimeException();

  // Check, if a content with given id already exists...
  Reference< XContent > xContent
    = queryExistingContent( xCanonicId ).getBodyPtr();
  if ( xContent.is() )
    return xContent;

  xContent = new Content( m_xSMgr,this,xCanonicId,m_pDatabases );

  // Further checks

  if ( !xContent->getIdentifier().is() )
    throw IllegalIdentifierException();

  return xContent;
}

void ContentProvider::init()
{
  isInitialized = true;

  rtl::OUString sProviderService =
    rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" );

  Any aAny;
  aAny <<= rtl::OUString::createFromAscii( "local" );
  PropertyValue aProp( rtl::OUString::createFromAscii( "servertype" ),
               -1,
               aAny,
               PropertyState_DIRECT_VALUE );

  Sequence< Any > seq(1);
  seq[0] <<= aProp;

  Reference< XMultiServiceFactory > sProvider;
  try
    {
      sProvider =
    Reference< XMultiServiceFactory >(
                      m_xSMgr->createInstanceWithArguments( sProviderService,seq ),
                      UNO_QUERY );
    }
  catch( const com::sun::star::uno::Exception& e )
    {
      VOS_ENSHURE( sProvider.is()," cant instantiate the multiservicefactory " );
    }

  if( ! sProvider.is() )
    {
      return;
    }

  rtl::OUString sReaderService =
    rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationAccess" );

  seq[0] <<= rtl::OUString::createFromAscii( "org.openoffice.Office.Common" );

  Reference< XHierarchicalNameAccess > xHierAccess;
  try
    {
      xHierAccess =
    Reference< XHierarchicalNameAccess >
    ( sProvider->createInstanceWithArguments( sReaderService,seq ),
      UNO_QUERY );
    }
  catch( const com::sun::star::uno::Exception& e )
    {
      VOS_ENSHURE( xHierAccess.is()," cant instantiate the reader service " );
    }

  if( ! xHierAccess.is() )
    return;

  try
    {
      aAny =
    xHierAccess->getByHierarchicalName( rtl::OUString::createFromAscii("Path/Current/Help") );
    }
  catch( const com::sun::star::container::NoSuchElementException& e )
    {
      VOS_ENSHURE( false," path to help files could not be determined " );
      return;
    }

  rtl::OUString instPath;
  bool err = ! ( aAny >>= instPath );

  if( err )
    {
      VOS_ENSHURE( false," path to help files could not be determined " );
      return;
    }

  instPath = rtl::OUString::createFromAscii( "$(instpath)/help" );

  Reference< XConfigManager >  xCfgMgr;
  try
    {
      xCfgMgr =
    Reference< XConfigManager >(
                    m_xSMgr->createInstance( rtl::OUString::createFromAscii( "com.sun.star.config.SpecialConfigManager" ) ),
                    UNO_QUERY );
    }
  catch( const com::sun::star::uno::Exception& e )
    {
      VOS_ENSHURE( xCfgMgr.is()," cant instantiate the special config manager " );
    }

  if( ! xCfgMgr.is() )
    return;

  instPath = xCfgMgr->substituteVariables( instPath );
  m_pDatabases = new Databases( instPath,m_xSMgr );

}
<|endoftext|>


<commit_before>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3475
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3475 to 3476<commit_after>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3476
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3477
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3477 to 3478<commit_after>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3478
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3501
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3501 to 3502<commit_after>/* Copyright (c) 2010 - 2021 Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3502
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3166
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>SWDEV-2 - Change OpenCL version number from  3166 to 3167<commit_after>/* Copyright (c) 2010-present Advanced Micro Devices, Inc.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE. */

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3167
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>