ostinato/common/pdml_p.h

231 lines
6.4 KiB
C
Raw Normal View History

2011-01-30 06:08:03 -06:00
/*
Copyright (C) 2010 Srivats P.
This file is part of "Ostinato"
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef _PDML_P_H
#define _PDML_P_H
#include "protocol.pb.h"
#include <QByteArray>
2011-01-30 06:08:03 -06:00
#include <QMap>
#include <QObject>
#include <QString>
#include <QXmlDefaultHandler>
2011-02-18 12:02:57 -06:00
#include <QXmlStreamReader>
2011-01-30 06:08:03 -06:00
// TODO: add const where possible
2011-01-30 06:08:03 -06:00
class QXmlSimpleReader;
class QXmlInputSource;
class PdmlDefaultProtocol
{
public:
2011-02-18 12:02:57 -06:00
PdmlDefaultProtocol(); // TODO: make private
2011-01-30 06:08:03 -06:00
virtual ~PdmlDefaultProtocol();
2011-02-18 12:02:57 -06:00
static PdmlDefaultProtocol* createInstance();
2011-01-30 06:08:03 -06:00
QString pdmlProtoName() const;
int ostProtoId() const;
bool hasField(QString name) const;
int fieldId(QString name) const;
virtual void preProtocolHandler(QString name,
2011-02-18 12:02:57 -06:00
const QXmlStreamAttributes &attributes, OstProto::Stream *stream);
virtual void prematureEndHandler(int pos, OstProto::Stream *stream);
2011-01-30 06:08:03 -06:00
virtual void postProtocolHandler(OstProto::Stream *stream);
virtual void unknownFieldHandler(QString name, int pos, int size,
2011-02-18 12:02:57 -06:00
const QXmlStreamAttributes &attributes, OstProto::Stream *stream);
2011-01-30 06:08:03 -06:00
protected:
QString pdmlProtoName_; // TODO: needed? duplicated in protocolMap_
int ostProtoId_;
QMap<QString, int> fieldMap_;
};
2011-02-18 12:02:57 -06:00
#if 0
2011-01-30 06:08:03 -06:00
class PdmlParser : public QXmlDefaultHandler
{
public:
PdmlParser(OstProto::StreamConfigList *streams);
~PdmlParser();
bool startElement(const QString &namespaceURI,
const QString &localName,
const QString &qName,
const QXmlAttributes &attributes);
bool endElement(const QString &namespaceURI,
const QString &localName,
const QString &qName);
bool characters(const QString &str);
bool fatalError(const QXmlParseException &exception);
private:
void initProtocolMaps();
QMap<QString, PdmlDefaultProtocol*> protocolMap_;
PdmlDefaultProtocol *currentPdmlProtocol_;
int skipCount_;
int packetCount_;
OstProto::StreamConfigList *streams_;
OstProto::Stream *currentStream_;
google::protobuf::Message *currentProtocolMsg_;
};
2011-02-18 12:02:57 -06:00
#endif
class PdmlReader : public QXmlStreamReader
{
public:
PdmlReader(OstProto::StreamConfigList *streams);
~PdmlReader();
bool read(QIODevice *device);
private:
PdmlDefaultProtocol* allocPdmlProtocol(QString protoName);
void freePdmlProtocol(PdmlDefaultProtocol *proto);
bool isDontCareProto();
void readPdml();
void skipElement();
void readUnexpectedElement();
void readPacket();
void readProto();
void readField(PdmlDefaultProtocol *pdmlProto,
google::protobuf::Message *pbProto);
typedef PdmlDefaultProtocol* (*FactoryMethod)();
QMap<QString, FactoryMethod> factory_;
OstProto::StreamConfigList *streams_;
int packetCount_;
OstProto::Stream *currentStream_;
//PdmlDefaultProtocol *currentPdmlProtocol_;
//google::protobuf::Message *currentProtocolMsg_;
};
2011-01-30 06:08:03 -06:00
class PdmlUnknownProtocol : public PdmlDefaultProtocol
{
public:
PdmlUnknownProtocol();
2011-02-18 12:02:57 -06:00
static PdmlDefaultProtocol* createInstance();
2011-01-30 06:08:03 -06:00
virtual void preProtocolHandler(QString name,
2011-02-18 12:02:57 -06:00
const QXmlStreamAttributes &attributes, OstProto::Stream *stream);
virtual void prematureEndHandler(int pos, OstProto::Stream *stream);
2011-01-30 06:08:03 -06:00
virtual void postProtocolHandler(OstProto::Stream *stream);
virtual void unknownFieldHandler(QString name, int pos, int size,
2011-02-18 12:02:57 -06:00
const QXmlStreamAttributes &attributes, OstProto::Stream *stream);
2011-01-30 06:08:03 -06:00
private:
int endPos_;
int expPos_;
};
class PdmlGenInfoProtocol : public PdmlDefaultProtocol
{
public:
PdmlGenInfoProtocol();
2011-02-18 12:02:57 -06:00
static PdmlDefaultProtocol* createInstance();
2011-01-30 06:08:03 -06:00
virtual void unknownFieldHandler(QString name, int pos, int size,
2011-02-18 12:02:57 -06:00
const QXmlStreamAttributes &attributes, OstProto::Stream *stream);
2011-01-30 06:08:03 -06:00
};
class PdmlFrameProtocol : public PdmlDefaultProtocol
{
public:
PdmlFrameProtocol();
2011-02-18 12:02:57 -06:00
static PdmlDefaultProtocol* createInstance();
2011-01-30 06:08:03 -06:00
};
#if 1
class PdmlFakeFieldWrapperProtocol : public PdmlDefaultProtocol
{
public:
PdmlFakeFieldWrapperProtocol();
2011-02-18 12:02:57 -06:00
static PdmlDefaultProtocol* createInstance();
virtual void preProtocolHandler(QString name,
2011-02-18 12:02:57 -06:00
const QXmlStreamAttributes &attributes, OstProto::Stream *stream);
virtual void postProtocolHandler(OstProto::Stream *stream);
virtual void unknownFieldHandler(QString name, int pos, int size,
2011-02-18 12:02:57 -06:00
const QXmlStreamAttributes &attributes, OstProto::Stream *stream);
private:
int expPos_;
};
#endif
2011-01-30 06:08:03 -06:00
class PdmlEthProtocol : public PdmlDefaultProtocol
{
public:
PdmlEthProtocol();
2011-02-18 12:02:57 -06:00
static PdmlDefaultProtocol* createInstance();
2011-01-30 06:08:03 -06:00
virtual void unknownFieldHandler(QString name, int pos, int size,
2011-02-18 12:02:57 -06:00
const QXmlStreamAttributes &attributes, OstProto::Stream *stream);
2011-01-30 06:08:03 -06:00
};
class PdmlIp4Protocol : public PdmlDefaultProtocol
{
public:
PdmlIp4Protocol();
2011-02-18 12:02:57 -06:00
static PdmlDefaultProtocol* createInstance();
2011-01-30 06:08:03 -06:00
virtual void unknownFieldHandler(QString name, int pos, int size,
2011-02-18 12:02:57 -06:00
const QXmlStreamAttributes &attributes, OstProto::Stream *stream);
2011-01-30 06:08:03 -06:00
virtual void postProtocolHandler(OstProto::Stream *stream);
};
class PdmlIp6Protocol : public PdmlDefaultProtocol
{
public:
PdmlIp6Protocol();
2011-02-18 12:02:57 -06:00
static PdmlDefaultProtocol* createInstance();
virtual void unknownFieldHandler(QString name, int pos, int size,
2011-02-18 12:02:57 -06:00
const QXmlStreamAttributes &attributes, OstProto::Stream *stream);
virtual void postProtocolHandler(OstProto::Stream *stream);
};
class PdmlTcpProtocol : public PdmlDefaultProtocol
{
public:
PdmlTcpProtocol();
2011-02-18 12:02:57 -06:00
static PdmlDefaultProtocol* createInstance();
virtual void unknownFieldHandler(QString name, int pos, int size,
2011-02-18 12:02:57 -06:00
const QXmlStreamAttributes &attributes, OstProto::Stream *stream);
virtual void postProtocolHandler(OstProto::Stream *stream);
private:
QByteArray options_;
QByteArray segmentData_;
};
2011-01-30 06:08:03 -06:00
#endif