qiodevice.sip 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. // qiodevice.sip generated by MetaSIP
  2. //
  3. // This file is part of the QtCore Python extension module.
  4. //
  5. // Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of PyQt6.
  8. //
  9. // This file may be used under the terms of the GNU General Public License
  10. // version 3.0 as published by the Free Software Foundation and appearing in
  11. // the file LICENSE included in the packaging of this file. Please review the
  12. // following information to ensure the GNU General Public License version 3.0
  13. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  14. //
  15. // If you do not wish to use this file under the terms of the GPL version 3.0
  16. // then you may purchase a commercial license. For more information contact
  17. // info@riverbankcomputing.com.
  18. //
  19. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. class QIODevice : public QObject, public QIODeviceBase
  22. {
  23. %TypeHeaderCode
  24. #include <qiodevice.h>
  25. %End
  26. public:
  27. QIODevice();
  28. explicit QIODevice(QObject *parent /TransferThis/);
  29. virtual ~QIODevice();
  30. QIODeviceBase::OpenMode openMode() const;
  31. void setTextModeEnabled(bool enabled);
  32. bool isTextModeEnabled() const;
  33. bool isOpen() const;
  34. bool isReadable() const;
  35. bool isWritable() const;
  36. virtual bool isSequential() const;
  37. int readChannelCount() const;
  38. int writeChannelCount() const;
  39. int currentReadChannel() const;
  40. void setCurrentReadChannel(int channel);
  41. int currentWriteChannel() const;
  42. void setCurrentWriteChannel(int channel);
  43. virtual bool open(QIODeviceBase::OpenMode mode) /ReleaseGIL/;
  44. virtual void close() /ReleaseGIL/;
  45. virtual qint64 pos() const;
  46. virtual qint64 size() const;
  47. virtual bool seek(qint64 pos) /ReleaseGIL/;
  48. virtual bool atEnd() const;
  49. virtual bool reset();
  50. virtual qint64 bytesAvailable() const;
  51. virtual qint64 bytesToWrite() const;
  52. SIP_PYOBJECT read(qint64 maxlen) /ReleaseGIL,TypeHint="bytes"/;
  53. %MethodCode
  54. // Return the data read or None if there was an error.
  55. if (a0 < 0)
  56. {
  57. PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
  58. sipIsErr = 1;
  59. }
  60. else
  61. {
  62. char *s = new char[a0];
  63. qint64 len;
  64. Py_BEGIN_ALLOW_THREADS
  65. len = sipCpp->read(s, a0);
  66. Py_END_ALLOW_THREADS
  67. if (len < 0)
  68. {
  69. Py_INCREF(Py_None);
  70. sipRes = Py_None;
  71. }
  72. else
  73. {
  74. sipRes = PyBytes_FromStringAndSize(s, len);
  75. if (!sipRes)
  76. sipIsErr = 1;
  77. }
  78. delete[] s;
  79. }
  80. %End
  81. SIP_PYOBJECT readLine(qint64 maxlen) /ReleaseGIL,TypeHint="bytes"/;
  82. %MethodCode
  83. // Return a bytes object or None if there was an error.
  84. if (a0 < 0)
  85. {
  86. PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
  87. sipIsErr = 1;
  88. }
  89. else
  90. {
  91. char *s = new char[a0];
  92. qint64 len;
  93. Py_BEGIN_ALLOW_THREADS
  94. len = sipCpp->readLine(s, a0);
  95. Py_END_ALLOW_THREADS
  96. if (len < 0)
  97. {
  98. Py_INCREF(Py_None);
  99. sipRes = Py_None;
  100. }
  101. else
  102. {
  103. sipRes = PyBytes_FromStringAndSize(s, len);
  104. if (!sipRes)
  105. sipIsErr = 1;
  106. }
  107. delete[] s;
  108. }
  109. %End
  110. QByteArray readLine() /ReleaseGIL/;
  111. %MethodCode
  112. Py_BEGIN_ALLOW_THREADS
  113. sipRes = new QByteArray(sipCpp->readLine());
  114. Py_END_ALLOW_THREADS
  115. %End
  116. %If (Qt_6_9_0 -)
  117. bool readLineInto(QByteArray *result, qint64 maxSize = 0) /ReleaseGIL/;
  118. %End
  119. QByteArray readAll() /ReleaseGIL/;
  120. virtual bool canReadLine() const;
  121. void startTransaction();
  122. void commitTransaction();
  123. void rollbackTransaction();
  124. bool isTransactionStarted() const;
  125. qint64 write(SIP_PYBUFFER) /ReleaseGIL/;
  126. %MethodCode
  127. sipBufferInfoDef bi;
  128. if (sipGetBufferInfo(a0, &bi) > 0)
  129. {
  130. Py_BEGIN_ALLOW_THREADS
  131. sipRes = sipCpp->write(reinterpret_cast<char *>(bi.bi_buf), bi.bi_len);
  132. Py_END_ALLOW_THREADS
  133. sipReleaseBufferInfo(&bi);
  134. }
  135. else
  136. {
  137. sipIsErr = 1;
  138. }
  139. %End
  140. SIP_PYOBJECT peek(qint64 maxlen) /ReleaseGIL,TypeHint="bytes"/;
  141. %MethodCode
  142. // Return the data read or None if there was an error.
  143. if (a0 < 0)
  144. {
  145. PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
  146. sipIsErr = 1;
  147. }
  148. else
  149. {
  150. char *s = new char[a0];
  151. qint64 len;
  152. Py_BEGIN_ALLOW_THREADS
  153. len = sipCpp->peek(s, a0);
  154. Py_END_ALLOW_THREADS
  155. if (len < 0)
  156. {
  157. Py_INCREF(Py_None);
  158. sipRes = Py_None;
  159. }
  160. else
  161. {
  162. sipRes = PyBytes_FromStringAndSize(s, len);
  163. if (!sipRes)
  164. sipIsErr = 1;
  165. }
  166. delete[] s;
  167. }
  168. %End
  169. qint64 skip(qint64 maxSize) /ReleaseGIL/;
  170. virtual bool waitForReadyRead(int msecs) /ReleaseGIL/;
  171. virtual bool waitForBytesWritten(int msecs) /ReleaseGIL/;
  172. void ungetChar(char c /Encoding="None"/);
  173. bool putChar(char c /Encoding="None"/) /ReleaseGIL/;
  174. bool getChar(char *c /Encoding="None",Out/) /ReleaseGIL/;
  175. QString errorString() const;
  176. signals:
  177. void aboutToClose();
  178. void bytesWritten(qint64 bytes);
  179. void channelBytesWritten(int channel, qint64 bytes);
  180. void channelReadyRead(int channel);
  181. void readChannelFinished();
  182. void readyRead();
  183. protected:
  184. virtual SIP_PYOBJECT readData(qint64 maxlen) = 0 /ReleaseGIL,TypeHint="bytes"/ [qint64 (char *data, qint64 maxlen)];
  185. %MethodCode
  186. // Return the data read or None if there was an error.
  187. if (a0 < 0)
  188. {
  189. PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
  190. sipIsErr = 1;
  191. }
  192. else
  193. {
  194. char *s = new char[a0];
  195. qint64 len;
  196. Py_BEGIN_ALLOW_THREADS
  197. #if defined(SIP_PROTECTED_IS_PUBLIC)
  198. len = sipCpp->readData(s, a0);
  199. #else
  200. len = sipCpp->sipProtect_readData(s, a0);
  201. #endif
  202. Py_END_ALLOW_THREADS
  203. if (len < 0)
  204. {
  205. Py_INCREF(Py_None);
  206. sipRes = Py_None;
  207. }
  208. else
  209. {
  210. sipRes = PyBytes_FromStringAndSize(s, len);
  211. if (!sipRes)
  212. sipIsErr = 1;
  213. }
  214. delete[] s;
  215. }
  216. %End
  217. %VirtualCatcherCode
  218. PyObject *result = sipCallMethod(&sipIsErr, sipMethod, "n", a1);
  219. if (result)
  220. {
  221. PyObject *buf;
  222. if (sipParseResult(&sipIsErr, sipMethod, result, "$", &buf) == 0)
  223. {
  224. if (buf == Py_None)
  225. {
  226. sipRes = -1L;
  227. }
  228. else
  229. {
  230. sipBufferInfoDef bi;
  231. if (sipGetBufferInfo(buf, &bi) < 0)
  232. {
  233. sipBadCatcherResult(sipMethod);
  234. sipIsErr = 1;
  235. }
  236. else
  237. {
  238. sipRes = (a1 < bi.bi_len) ? a1 : bi.bi_len;
  239. memcpy(a0, bi.bi_buf, sipRes);
  240. sipReleaseBufferInfo(&bi);
  241. }
  242. }
  243. Py_DECREF(buf);
  244. }
  245. Py_DECREF(result);
  246. }
  247. %End
  248. virtual SIP_PYOBJECT readLineData(qint64 maxlen) /ReleaseGIL,TypeHint="bytes"/ [qint64 (char *data, qint64 maxlen)];
  249. %MethodCode
  250. // Return the data read or None if there was an error.
  251. if (a0 < 0)
  252. {
  253. PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
  254. sipIsErr = 1;
  255. }
  256. else
  257. {
  258. char *s = new char[a0];
  259. qint64 len;
  260. Py_BEGIN_ALLOW_THREADS
  261. #if defined(SIP_PROTECTED_IS_PUBLIC)
  262. len = sipSelfWasArg ? sipCpp->QIODevice::readLineData(s, a0) : sipCpp->readLineData(s, a0);
  263. #else
  264. len = sipCpp->sipProtectVirt_readLineData(sipSelfWasArg, s, a0);
  265. #endif
  266. Py_END_ALLOW_THREADS
  267. if (len < 0)
  268. {
  269. Py_INCREF(Py_None);
  270. sipRes = Py_None;
  271. }
  272. else
  273. {
  274. sipRes = PyBytes_FromStringAndSize(s, len);
  275. if (!sipRes)
  276. sipIsErr = 1;
  277. }
  278. delete[] s;
  279. }
  280. %End
  281. %VirtualCatcherCode
  282. PyObject *result = sipCallMethod(&sipIsErr, sipMethod, "n", a1);
  283. if (result)
  284. {
  285. PyObject *buf;
  286. if (sipParseResult(&sipIsErr, sipMethod, result, "$", &buf) == 0)
  287. {
  288. if (buf == Py_None)
  289. {
  290. sipRes = -1L;
  291. }
  292. else
  293. {
  294. sipBufferInfoDef bi;
  295. if (sipGetBufferInfo(buf, &bi) < 0)
  296. {
  297. sipBadCatcherResult(sipMethod);
  298. sipIsErr = 1;
  299. }
  300. else
  301. {
  302. sipRes = (a1 < bi.bi_len) ? a1 : bi.bi_len;
  303. memcpy(a0, bi.bi_buf, sipRes);
  304. sipReleaseBufferInfo(&bi);
  305. }
  306. }
  307. Py_DECREF(buf);
  308. }
  309. Py_DECREF(result);
  310. }
  311. %End
  312. virtual qint64 writeData(SIP_PYBUFFER) = 0 /ReleaseGIL/ [qint64 (const char *data, qint64 len)];
  313. %MethodCode
  314. sipBufferInfoDef bi;
  315. if (sipGetBufferInfo(a0, &bi) > 0)
  316. {
  317. Py_BEGIN_ALLOW_THREADS
  318. #if defined(SIP_PROTECTED_IS_PUBLIC)
  319. sipRes = sipCpp->writeData(reinterpret_cast<char *>(bi.bi_buf), bi.bi_len);
  320. #else
  321. sipRes = sipCpp->sipProtect_writeData(reinterpret_cast<char *>(bi.bi_buf),
  322. bi.bi_len);
  323. #endif
  324. Py_END_ALLOW_THREADS
  325. sipReleaseBufferInfo(&bi);
  326. }
  327. else
  328. {
  329. sipIsErr = 1;
  330. }
  331. %End
  332. %VirtualCatcherCode
  333. PyObject *result = sipCallMethod(&sipIsErr, sipMethod, "n", a1);
  334. if (result)
  335. {
  336. PyObject *buf;
  337. if (sipParseResult(&sipIsErr, sipMethod, result, "$", &buf) == 0)
  338. {
  339. if (buf == Py_None)
  340. {
  341. sipRes = -1L;
  342. }
  343. else
  344. {
  345. sipBufferInfoDef bi;
  346. if (sipGetBufferInfo(buf, &bi) < 0)
  347. {
  348. sipBadCatcherResult(sipMethod);
  349. sipIsErr = 1;
  350. }
  351. else
  352. {
  353. if (bi.bi_readonly)
  354. {
  355. sipBadCatcherResult(sipMethod);
  356. sipIsErr = 1;
  357. }
  358. else
  359. {
  360. sipRes = (a1 < bi.bi_len) ? a1 : bi.bi_len;
  361. memcpy(bi.bi_buf, a0, sipRes);
  362. }
  363. sipReleaseBufferInfo(&bi);
  364. }
  365. }
  366. Py_DECREF(buf);
  367. }
  368. Py_DECREF(result);
  369. }
  370. %End
  371. virtual qint64 skipData(qint64 maxSize) /ReleaseGIL/;
  372. void setOpenMode(QIODeviceBase::OpenMode openMode);
  373. void setErrorString(const QString &errorString);
  374. };