Qt 4.8
Public Slots | Signals | Public Functions | Public Variables | List of all members
QPacketProtocolPrivate Class Reference
Inheritance diagram for QPacketProtocolPrivate:
QObject

Public Slots

void aboutToClose ()
 
void bytesWritten (qint64 bytes)
 
void readyToRead ()
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void invalidPacket ()
 
void packetWritten ()
 
void readyRead ()
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

 QPacketProtocolPrivate (QPacketProtocol *parent, QIODevice *_dev)
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Public Variables

QIODevicedev
 
QByteArray inProgress
 
qint32 inProgressSize
 
qint32 maxPacketSize
 
QList< QByteArraypackets
 
QList< qint64sendingPackets
 
bool waitingForPacket
 

Additional Inherited Members

- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 115 of file qpacketprotocol.cpp.

Constructors and Destructors

◆ QPacketProtocolPrivate()

QPacketProtocolPrivate::QPacketProtocolPrivate ( QPacketProtocol parent,
QIODevice _dev 
)
inline

Definition at line 119 of file qpacketprotocol.cpp.

121  waitingForPacket(false), dev(_dev)
122  {
123  Q_ASSERT(4 == sizeof(qint32));
124 
126  parent, SIGNAL(readyRead()));
128  parent, SIGNAL(packetWritten()));
130  parent, SIGNAL(invalidPacket()));
132  this, SLOT(readyToRead()));
134  this, SLOT(aboutToClose()));
136  this, SLOT(bytesWritten(qint64)));
137  }
int qint32
Definition: qglobal.h:937
#define SLOT(a)
Definition: qobjectdefs.h:226
#define MAX_PACKET_SIZE
void bytesWritten(qint64 bytes)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
__int64 qint64
Definition: qglobal.h:942
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

Functions

◆ aboutToClose

void QPacketProtocolPrivate::aboutToClose ( )
inlineslot

Definition at line 145 of file qpacketprotocol.cpp.

Referenced by QPacketProtocolPrivate(), and readyToRead().

146  {
147  inProgress.clear();
149  inProgressSize = -1;
150  }
void clear()
Removes all items from the list.
Definition: qlist.h:764
QList< qint64 > sendingPackets
void clear()
Clears the contents of the byte array and makes it empty.

◆ bytesWritten

void QPacketProtocolPrivate::bytesWritten ( qint64  bytes)
inlineslot

Definition at line 152 of file qpacketprotocol.cpp.

Referenced by QPacketProtocolPrivate(), and readyToRead().

153  {
155 
156  while(bytes) {
157  if(sendingPackets.at(0) > bytes) {
158  sendingPackets[0] -= bytes;
159  bytes = 0;
160  } else {
161  bytes -= sendingPackets.at(0);
164  }
165  }
166  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
void removeFirst()
Removes the first item in the list.
Definition: qlist.h:286
QList< qint64 > sendingPackets

◆ invalidPacket

void QPacketProtocolPrivate::invalidPacket ( )
signal

◆ packetWritten

void QPacketProtocolPrivate::packetWritten ( )
signal

◆ readyRead

void QPacketProtocolPrivate::readyRead ( )
signal

◆ readyToRead

void QPacketProtocolPrivate::readyToRead ( )
inlineslot

Definition at line 168 of file qpacketprotocol.cpp.

Referenced by QPacketProtocolPrivate().

169  {
170  bool gotPackets = false;
171  while (true) {
172  // Get size header (if not in progress)
173  if (-1 == inProgressSize) {
174  // We need a size header of sizeof(qint32)
175  if (sizeof(qint32) > (uint)dev->bytesAvailable()) {
176  if (gotPackets)
177  emit readyRead();
178  return; // no more data available
179  }
180 
181  // Read size header
182  int read = dev->read((char *)&inProgressSize, sizeof(qint32));
183  Q_ASSERT(read == sizeof(qint32));
184  Q_UNUSED(read);
185 
186  // Check sizing constraints
187  if (inProgressSize > maxPacketSize) {
189  this, SLOT(readyToRead()));
191  this, SLOT(aboutToClose()));
193  this, SLOT(bytesWritten(qint64)));
194  dev = 0;
196  return;
197  }
198 
199  inProgressSize -= sizeof(qint32);
200  } else {
201  inProgress.append(dev->read(inProgressSize - inProgress.size()));
202 
203  if (inProgressSize == inProgress.size()) {
204  // Packet has arrived!
206  inProgressSize = -1;
207  inProgress.clear();
208 
209  waitingForPacket = false;
210  gotPackets = true;
211  } else {
212  if (gotPackets)
213  emit readyRead();
214  return; // packet in progress is not yet complete
215  }
216  }
217  }
218  }
int qint32
Definition: qglobal.h:937
QByteArray & append(char c)
Appends the character ch to this byte array.
#define SLOT(a)
Definition: qobjectdefs.h:226
void bytesWritten(qint64 bytes)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define emit
Definition: qobjectdefs.h:76
unsigned int uint
Definition: qglobal.h:996
__int64 qint64
Definition: qglobal.h:942
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
QList< QByteArray > packets
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Definition: qiodevice.cpp:752
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void clear()
Clears the contents of the byte array and makes it empty.

Properties

◆ dev

QIODevice* QPacketProtocolPrivate::dev

◆ inProgress

QByteArray QPacketProtocolPrivate::inProgress

Definition at line 223 of file qpacketprotocol.cpp.

Referenced by aboutToClose(), and readyToRead().

◆ inProgressSize

qint32 QPacketProtocolPrivate::inProgressSize

Definition at line 224 of file qpacketprotocol.cpp.

Referenced by aboutToClose(), and readyToRead().

◆ maxPacketSize

qint32 QPacketProtocolPrivate::maxPacketSize

◆ packets

QList<QByteArray> QPacketProtocolPrivate::packets

◆ sendingPackets

QList<qint64> QPacketProtocolPrivate::sendingPackets

Definition at line 221 of file qpacketprotocol.cpp.

Referenced by aboutToClose(), bytesWritten(), and QPacketProtocol::send().

◆ waitingForPacket

bool QPacketProtocolPrivate::waitingForPacket

Definition at line 226 of file qpacketprotocol.cpp.

Referenced by readyToRead(), and QPacketProtocol::waitForReadyRead().


The documentation for this class was generated from the following file: