/*
    PIQt Utils - Qt utilites for PIP

    Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef QPICONNECTION_H
#define QPICONNECTION_H

#include "piconnection.h"
#include "piqt.h"
#include "qad_piqt_export.h"
#include "qpiconfig.h"

#include <QMetaObject>
#include <QObject>


class QAD_PIQT_EXPORT QPIConnection
	: public QObject
	, public PIConnection {
	Q_OBJECT
	PIOBJECT_SUBCLASS(QPIConnection, PIConnection);

public:
	QPIConnection(const QString & name = QString());

	bool loadFromCMFile(const QString & file);

protected:
#if PIP_VERSION >= PIP_MAKE_VERSION(2, 38, 0)
	void propertyChanged(const char *) override { setObjectName(PI2QString(name())); }
#else
	void propertyChanged(const PIString &) override { setObjectName(PI2QString(name())); }
#endif
	EVENT_HANDLER2(void, piDataRec, const PIString &, from, const PIByteArray &, data);
	EVENT_HANDLER2(void, piPacketRec, const PIString &, from, const PIByteArray &, data);

public slots:

signals:
	void qDataReceivedEvent(QString from, QByteArray data);
	void qPacketReceivedEvent(QString from, QByteArray data);
};

#endif // QPICONNECTION_H
