WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZioDevice.h
Go to the documentation of this file.
1 /*
2 * Zuble - A run-time system for QML/Javascript applications
3 * Copyright (C) 2013, 2014 Bob Dinitto
4 *
5 * Filename: ZioDevice.h
6 * Created on: 11/9/2014
7 * Author: Bob Dinitto
8 *
9 * Zuble is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 */
24 
25 #ifndef ZIODEVICE_H
26 #define ZIODEVICE_H
27 
28 #include <QObject>
29 #include <QIODevice>
30 #include <QVariant>
31 #include "zblcore_global.h"
32 
33 namespace Zbl {
34 
40 class ZioDevice : public QObject
41 {
42  Q_OBJECT
43  Q_ENUMS(OpenMode)
44 public:
45 
46  enum OpenMode {
47  NotOpen = QIODevice::NotOpen,
48  ReadOnly = QIODevice::ReadOnly,
49  WriteOnly = QIODevice::WriteOnly,
50  ReadWrite = QIODevice::ReadWrite,
51  Append = QIODevice::Append,
52  Truncate = QIODevice::Truncate,
53  Text = QIODevice::Text,
54  Unbuffered = QIODevice::Unbuffered
55  };
56  Q_DECLARE_FLAGS(OpenModes, OpenMode)
57 
58 
59  explicit ZioDevice(QObject *parent = 0);
60 
61 
66  static void registerType();
67 
71  Q_PROPERTY(bool isOpen READ isOpen)
72 
73 
77  Q_PROPERTY(int openMode READ openMode)
78 
84  Q_PROPERTY(bool textMode READ getTextMode WRITE setTextMode)
85 
86 
87  Q_PROPERTY(bool isSequential READ isSequential)
88 
92  Q_PROPERTY(bool writable READ isWritable)
93 
97  Q_PROPERTY(bool readable READ isReadable)
98 
103  Q_PROPERTY(bool atEnd READ atEnd)
104 
105 
106 
115  Q_PROPERTY(qint64 size READ size)
116 
120  Q_PROPERTY(qint64 pos READ pos)
121 
125  Q_PROPERTY(qint64 bytesAvailable READ bytesAvailable)
126 
130  Q_PROPERTY(qint64 bytesToWrite READ bytesToWrite)
131 
132 
133  Q_PROPERTY(QString errorString READ getErrorString)
134  Q_PROPERTY(QVariant tags READ getTags CONSTANT)
135 
136 
137  bool isOpen() const;
138  int openMode() const;
139  bool getTextMode() const;
140  void setTextMode(bool textModeEnabled);
141  bool isSequential();
142  bool isWritable() const;
143  bool isReadable() const;
144  bool atEnd() const;
145 
146  qint64 size() const;
147  qint64 pos() const;
148  qint64 bytesAvailable() const;
149  qint64 bytesToWrite() const;
150 
151  QVariant getTags();
152 
153  QString getErrorString();
154 
155  Q_INVOKABLE bool seek(qint64 pos);
156 
161  Q_INVOKABLE qint64 writeString(const QString& text);
162 
167  Q_INVOKABLE qint64 writeBytes(const QObject* data);
168 
169 
170  Q_INVOKABLE bool waitForBytesWritten(int msecs);
171 
172  Q_INVOKABLE bool waitForReadyRead(int msecs);
173 
174  Q_INVOKABLE void reset();
175 
176  Q_INVOKABLE void close();
177 
178 
179 signals:
180 
201  void getCurrentDevice(QIODevice** device) const;
202 
203 public slots:
204 
205 
206 protected:
207 
216  QIODevice* connectedDevice() const;
217 
222  void createTags();
223 
233  static QVariant m_tags;
234 };
235 
236 } // Zbl
237 
238 #endif // ZIODEVICE_H
QVariant getTags()
Definition: ZioDevice.cpp:305
QString getErrorString()
Definition: ZioDevice.cpp:203
static void registerType()
Registers ZioDevice as a QML type.
Definition: ZioDevice.cpp:48
qint64 size() const
qint64 bytesAvailable() const
ZioDevice(QObject *parent=0)
Definition: ZioDevice.cpp:36
Q_INVOKABLE qint64 writeString(const QString &text)
Write a string to the device.
Definition: ZioDevice.cpp:263
QString errorString
Definition: ZioDevice.h:133
QIODevice * connectedDevice() const
Emits the getCurrentDevice signal and returns the resulting device, or else throws an exception if a ...
Definition: ZioDevice.cpp:192
bool isOpen() const
bool writable
Returns true if the device is writable, false otherwise.
Definition: ZioDevice.h:92
bool readable
Returns true if the device is readable, false otherwise.
Definition: ZioDevice.h:97
bool textMode
Sets and gets the text mode flag. When set sequences are converted to/from when reading/writing t...
Definition: ZioDevice.h:84
bool isReadable() const
Definition: ZioDevice.cpp:173
Q_INVOKABLE bool seek(qint64 pos)
Definition: ZioDevice.cpp:239
bool atEnd() const
static QVariant m_tags
A QVariant containing a QVariantMap of QIODevice enumerations for use by background Javascript thread...
Definition: ZioDevice.h:233
Q_INVOKABLE qint64 writeBytes(const QObject *data)
Write the contents of a ZByteArray to the device.
Definition: ZioDevice.cpp:280
Q_INVOKABLE bool waitForReadyRead(int msecs)
Definition: ZioDevice.cpp:255
A javascript wrapper for QIODevice.
Definition: ZioDevice.h:40
Definition: ZAndGate.cpp:6
bool isWritable() const
Definition: ZioDevice.cpp:163
Q_INVOKABLE void close()
Definition: ZioDevice.cpp:227
Q_INVOKABLE void reset()
Definition: ZioDevice.cpp:215
Q_INVOKABLE bool waitForBytesWritten(int msecs)
Definition: ZioDevice.cpp:247
int openMode() const
void getCurrentDevice(QIODevice **device) const
Connected devices should listen to this signal and respond by returning a pointer to the QIODevice ob...
qint64 pos() const
void createTags()
Initializes QIODevice enumeration tags.
Definition: ZioDevice.cpp:56
bool getTextMode() const
Definition: ZioDevice.cpp:96
bool isSequential()
QVariant tags
Definition: ZioDevice.h:134
void setTextMode(bool textModeEnabled)
Definition: ZioDevice.cpp:105
qint64 bytesToWrite() const