/src/wrappers/glib/library/core/g_io_channel.e

http://github.com/tybor/Liberty · Specman e · 750 lines · 146 code · 152 blank · 452 comment · 6 complexity · 76c32c2f209925469de28f18ebd87a9f MD5 · raw file

  1. indexing
  2. copyright: "(C) 2005 Paolo Redaelli, 2007 Soluciones Informaticas Libres S.A. (Except)"
  3. license: "LGPL v2 or later"
  4. date: "$Date:$"
  5. revision: "$REvision:$"
  6. class G_IO_CHANNEL
  7. -- IO Channels -- portable support for using files, pipes and sockets.
  8. inherit
  9. C_STRUCT
  10. REFERENCE_COUNTED redefine dispose end
  11. insert
  12. GLIB_TYPES
  13. SHARED_G_ERROR
  14. GIOCHANNEL_EXTERNALS
  15. GIOCHANNEL_STRUCT
  16. create
  17. from_unix_fd --, from_win32_fd, from_win32_socket
  18. feature {} -- Creation
  19. -- TODO: provide OS-specfic heirs for Unix and Win32.
  20. from_unix_fd (fd: INTEGER) is
  21. -- Creates from file descriptor `fd'. On UNIX systems this
  22. -- works for plain files, pipes, and sockets.
  23. do
  24. handle := g_io_channel_unix_new (fd)
  25. ensure
  26. encoding.is_equal (once "UTF-8")
  27. end
  28. -- from_win32_fd (fd: INTEGER) is
  29. -- -- Creates from file descriptor `fd' on Windows. This works for
  30. -- -- file descriptors as returned by the open(), creat(), pipe()
  31. -- -- and fileno() calls in the Microsoft C runtime. In order to
  32. -- -- meaningfully use this routine your code should use the same
  33. -- -- C runtime as GLib uses, which is msvcrt.dll.
  34. -- -- This function is available only in GLib on Windows.
  35. -- do
  36. -- handle := g_io_channel_win32_new_fd (fd)
  37. -- end
  38. -- from_win32_socket (socket: INTEGER) is
  39. -- -- Creates from socket handle `socket'
  40. -- do
  41. -- handle := g_io_channel_win32_new_socket (socket)
  42. -- end
  43. new_file (a_file_name, a_mode: STRING) is
  44. -- Open a file named `a_file_name' as a GIOChannel using `a_mode'. This channel
  45. -- will be closed when the last reference to it is dropped, so there is
  46. -- no need to call `close' (though doing so will not cause
  47. -- problems, as long as no attempt is made to access the channel after
  48. -- it is closed).
  49. -- mode shall be one of "r", "w", "a", "r+", "w+", "a+". These have the
  50. -- same meaning as in fopen().
  51. -- `error' will be updated.
  52. local p: POINTER
  53. do
  54. p := g_io_channel_new_file
  55. (a_file_name.to_external, a_mode.to_external, error.reference)
  56. if p.is_not_null then
  57. is_successful:=True
  58. from_external_pointer(p)
  59. end
  60. ensure
  61. not is_successful implies error/=Void
  62. end
  63. feature -- Memory handling
  64. ref is
  65. -- Increments the reference count of a GIOChannel.
  66. local p: POINTER
  67. do
  68. p:=g_io_channel_ref(handle)
  69. check p=handle end
  70. end
  71. unref is
  72. do
  73. g_io_channel_unref (handle)
  74. end
  75. dispose is
  76. do
  77. Precursor
  78. watch_list := Void
  79. end
  80. feature -- Access
  81. encoding: STRING is
  82. -- Encoding for the input/output of the channel. The internal
  83. -- encoding is always UTF-8. The encoding Void makes the
  84. -- channel safe for binary data.
  85. local
  86. enc: POINTER
  87. do
  88. enc := g_io_channel_get_encoding (handle)
  89. if enc.is_not_null then
  90. create Result.from_external_copy (enc)
  91. end
  92. end
  93. flags: GIOFLAGS_ENUM is
  94. -- Flags for Current channel.
  95. do
  96. Result.change_value(g_io_channel_get_flags(handle))
  97. end
  98. is_buffered: BOOLEAN is
  99. -- Is the channel buffered?
  100. do
  101. Result:=g_io_channel_get_buffered(handle).to_boolean
  102. end
  103. last_event_source: NATURAL_32
  104. -- glib id of last g_io_add_watch
  105. last_status: GIOSTATUS_ENUM
  106. -- Status code of last operation
  107. last_failed: BOOLEAN is
  108. -- Error status of last operation
  109. do
  110. Result := not last_status.is_normal
  111. end
  112. last_written: INTEGER
  113. -- Number of bytes read/written by last operation
  114. feature -- Operations
  115. add_watch (condition: GIOCONDITION_ENUM; action: FUNCTION [TUPLE [G_IO_CHANNEL, INTEGER], BOOLEAN]) is
  116. -- Adds into the main event loop with the default priority.
  117. require
  118. action /= Void
  119. local
  120. callback: G_IO_FUNC
  121. do
  122. create callback.make (Current, action)
  123. if watch_list = Void then
  124. create watch_list.make (0)
  125. end
  126. watch_list.add_last (callback)
  127. last_event_source := g_io_add_watch (handle, condition.value, callback.function, callback.data)
  128. end
  129. set_blocking (block: BOOLEAN) is
  130. do
  131. last_status.change_value
  132. (g_io_channel_set_flags(handle, flags.value, default_pointer))
  133. end
  134. set_buffered (buffered: BOOLEAN) is
  135. -- Enable/disable channel buffering.
  136. -- Default state is buffered
  137. require
  138. no_encoding_set: encoding = Void
  139. -- The buffering state can only be set if the channel's
  140. -- encoding is Void. For any other encoding, the channel
  141. -- must be buffered.
  142. no_buffered_data: -- No way to query this from GIOChannel
  143. -- A buffered channel can only be set unbuffered if the
  144. -- channel's internal buffers have been flushed. Newly
  145. -- created channels or channels which have returned
  146. -- G_IO_STATUS_EOF not require such a flush.
  147. -- For write-only channels, a call to g_io_channel_flush()
  148. -- is sufficient. For all other channels,
  149. -- the buffers may be flushed by a call to
  150. -- g_io_channel_seek_position(). This includes the possibility
  151. -- of seeking with seek type G_SEEK_CUR and an offset
  152. -- of zero. Note that this means that socket-based channels
  153. -- cannot be set unbuffered once they have had data
  154. -- read from them.
  155. -- On unbuffered channels, it is safe to mix read and
  156. -- write calls from the new and old APIs, if this is
  157. -- necessary for maintaining old code.
  158. do
  159. g_io_channel_set_buffered (handle, buffered.to_integer)
  160. ensure
  161. is_buffered = buffered
  162. end
  163. -- guint g_io_add_watch_full (GIOChannel *channel,
  164. -- gint priority,
  165. -- GIOCondition condition,
  166. -- GIOFunc func,
  167. -- gpointer user_data,
  168. -- GDestroyNotify notify);
  169. -- enum GIOCondition;
  170. -- gboolean (*GIOFunc) (GIOChannel *source,
  171. -- GIOCondition condition,
  172. -- gpointer data);
  173. -- GIOFuncs;
  174. -- gsize g_io_channel_get_buffer_size (GIOChannel *channel);
  175. -- void g_io_channel_set_buffer_size (GIOChannel *channel,
  176. -- gsize size);
  177. -- GIOCondition g_io_channel_get_buffer_condition
  178. -- (GIOChannel *channel);
  179. -- GIOFlags g_io_channel_get_flags (GIOChannel *channel);
  180. -- GIOStatus g_io_channel_set_flags (GIOChannel *channel,
  181. -- GIOFlags flags,
  182. -- GError **error);
  183. -- enum GIOFlags;
  184. -- const gchar* g_io_channel_get_line_term (GIOChannel *channel,
  185. -- gint *length);
  186. -- void g_io_channel_set_line_term (GIOChannel *channel,
  187. -- const gchar *line_term,
  188. -- gint length);
  189. -- gboolean g_io_channel_get_close_on_unref (GIOChannel *channel);
  190. -- void g_io_channel_set_close_on_unref (GIOChannel *channel,
  191. -- gboolean do_close);
  192. -- GIOError g_io_channel_read (GIOChannel *channel,
  193. -- gchar *buf,
  194. -- gsize count,
  195. -- gsize *bytes_read);
  196. -- enum GIOError;
  197. -- GIOError g_io_channel_write (GIOChannel *channel,
  198. -- const gchar *buf,
  199. -- gsize count,
  200. -- gsize *bytes_written);
  201. -- GIOError g_io_channel_seek (GIOChannel *channel,
  202. -- gint64 offset,
  203. -- GSeekType type);
  204. -- void g_io_channel_close (GIOChannel *channel);
  205. -- Description
  206. -- The GIOChannel data type aims to provide a portable method for using file descriptors, pipes, and sockets, and integrating them into the main event loop. Currently full support is available on UNIX platforms, support for Windows is only partially complete.
  207. -- To create a new GIOChannel on UNIX systems use g_io_channel_unix_new(). This works for plain file descriptors, pipes and sockets. Alternatively, a channel can be created for a file in a system independent manner using g_io_channel_new_file().
  208. -- Once a GIOChannel has been created, it can be used in a generic manner with the functions g_io_channel_read_chars(), g_io_channel_write_chars(), g_io_channel_seek_position(), and g_io_channel_shutdown().
  209. -- To add a GIOChannel to the main event loop use g_io_add_watch() or g_io_add_watch_full(). Here you specify which events you are interested in on the GIOChannel, and provide a function to be called whenever these events occur.
  210. -- GIOChannel instances are created with an initial reference count of 1. g_io_channel_ref() and g_io_channel_unref() can be used to increment or decrement the reference count respectively. When the reference count falls to 0, the GIOChannel is freed. (Though it isn't closed automatically, unless it was created using g_io_channel_new_from_file().) Using g_io_add_watch() or g_io_add_watch_full() increments a channel's reference count.
  211. -- The new functions g_io_channel_read_chars(), g_io_channel_read_line(), g_io_channel_read_line_string(), g_io_channel_read_to_end(), g_io_channel_write_chars(), g_io_channel_seek_position(), and g_io_channel_flush() should not be mixed with the deprecated functions g_io_channel_read(), g_io_channel_write(), and g_io_channel_seek() on the same channel.
  212. -- Details
  213. -- GIOChannel
  214. -- typedef struct {
  215. -- } GIOChannel;
  216. -- A data structure representing an IO Channel. The fields should be considered private and should only be accessed with the following functions.
  217. -- g_io_channel_unix_new ()
  218. feature -- Queries
  219. file_descriptor: like gint is
  220. -- the file descriptor of the GIOChannel.
  221. do
  222. Result := g_io_channel_unix_get_fd (handle)
  223. end
  224. -- g_io_channel_init ()
  225. -- void g_io_channel_init (GIOChannel *channel);
  226. -- Initializes a GIOChannel struct. This is called by each of the above functions when creating a GIOChannel, and so is not often needed by the application programmer (unless you are creating a new type of GIOChannel).
  227. -- channel : a GIOChannel.
  228. -- g_io_channel_read_chars ()
  229. -- GIOStatus g_io_channel_read_chars (GIOChannel *channel,
  230. -- gchar *buf,
  231. -- gsize count,
  232. -- gsize *bytes_read,
  233. -- GError **error);
  234. -- Replacement for g_io_channel_read() with the new API.
  235. -- channel : a GIOChannel
  236. -- buf : a buffer to read data into
  237. -- count : the size of the buffer. Note that the buffer may not be complelely filled even if there is data in the buffer if the remaining data is not a complete character.
  238. -- bytes_read : The number of bytes read. This may be zero even on success if count < 6 and the channel's encoding is non-NULL. This indicates that the next UTF-8 character is too wide for the buffer.
  239. -- error : A location to return an error of type GConvertError or GIOChannelError.
  240. -- Returns : the status of the operation.
  241. -- g_io_channel_read_unichar ()
  242. -- GIOStatus g_io_channel_read_unichar (GIOChannel *channel,
  243. -- gunichar *thechar,
  244. -- GError **error);
  245. -- This function cannot be called on a channel with NULL encoding.
  246. -- channel : a GIOChannel
  247. -- thechar : a location to return a character
  248. -- error : A location to return an error of type GConvertError or GIOChannelError
  249. -- Returns : a GIOStatus
  250. -- g_io_channel_read_line ()
  251. -- GIOStatus g_io_channel_read_line (GIOChannel *channel,
  252. -- gchar **str_return,
  253. -- gsize *length,
  254. -- gsize *terminator_pos,
  255. -- GError **error);
  256. -- Reads a line, including the terminating character(s), from a GIOChannel into a newly-allocated string. str_return will contain allocated memory if the return is G_IO_STATUS_NORMAL.
  257. -- channel : a GIOChannel
  258. -- str_return : The line read from the GIOChannel, including the line terminator. This data should be freed with g_free() when no longer needed. This is a nul-terminated string. If a length of zero is returned, this will be NULL instead.
  259. -- length : location to store length of the read data, or NULL
  260. -- terminator_pos : location to store position of line terminator, or NULL
  261. -- error : A location to return an error of type GConvertError or GIOChannelError
  262. -- Returns : the status of the operation.
  263. -- g_io_channel_read_line_string ()
  264. -- GIOStatus g_io_channel_read_line_string (GIOChannel *channel,
  265. -- GString *buffer,
  266. -- gsize *terminator_pos,
  267. -- GError **error);
  268. -- Reads a line from a GIOChannel, using a GString as a buffer.
  269. -- channel : a GIOChannel
  270. -- buffer : a GString into which the line will be written. If buffer already contains data, the old data will be overwritten.
  271. -- terminator_pos : location to store position of line terminator, or NULL
  272. -- error : a location to store an error of type GConvertError or GIOChannelError
  273. -- Returns : the status of the operation.
  274. -- g_io_channel_read_to_end ()
  275. -- GIOStatus g_io_channel_read_to_end (GIOChannel *channel,
  276. -- gchar **str_return,
  277. -- gsize *length,
  278. -- GError **error);
  279. -- Reads all the remaining data from the file.
  280. -- channel : a GIOChannel
  281. -- str_return : Location to store a pointer to a string holding the remaining data in the GIOChannel. This data should be freed with g_free() when no longer needed. This data is terminated by an extra nul character, but there may be other nuls in the intervening data.
  282. -- length : Location to store length of the data
  283. -- error : A location to return an error of type GConvertError or GIOChannelError
  284. -- Returns : G_IO_STATUS_NORMAL on success. This function never returns G_IO_STATUS_EOF.
  285. -- g_io_channel_write_chars ()
  286. write_chars (chars: ABSTRACT_STRING) is
  287. -- Replacement for g_io_channel_write() with the new API.
  288. -- On seekable channels with encodings other than NULL or
  289. -- UTF-8, generic mixing of reading and writing is not
  290. -- allowed. A call to g_io_channel_write_chars() may only
  291. -- be made on a channel from which data has been read in
  292. -- the cases described in the documentation for
  293. -- g_io_channel_set_encoding().
  294. do
  295. debug
  296. print (once "Flags ") print(g_io_channel_get_flags (handle).to_string) print("%N")
  297. if chars.count <= 512 then chars.print_on(std_output) print(once "%N")
  298. else print (once "Writing ") print(chars.count.to_string) print(once " chars...%N")
  299. end
  300. end
  301. last_status.change_value
  302. (g_io_channel_write_chars (handle, chars.to_external,
  303. chars.count, $last_written, default_pointer))
  304. debug
  305. print (once "failed=") print(last_failed.to_string) print(once "%N")
  306. end
  307. end
  308. -- GIOStatus g_io_channel_write_chars (GIOChannel *channel,
  309. -- const gchar *buf,
  310. -- gssize count,
  311. -- gsize *bytes_written,
  312. -- GError **error);
  313. -- Replacement for g_io_channel_write() with the new API.
  314. -- On seekable channels with encodings other than NULL or UTF-8, generic mixing of reading and writing is not allowed. A call to g_io_channel_write_chars() may only be made on a channel from which data has been read in the cases described in the documentation for g_io_channel_set_encoding().
  315. -- channel : a GIOChannel
  316. -- buf : a buffer to write data from
  317. -- count : the size of the buffer. If -1, the buffer is taken to be a nul-terminated string.
  318. -- bytes_written : The number of bytes written. This can be nonzero even if the return value is not G_IO_STATUS_NORMAL. If the return value is G_IO_STATUS_NORMAL and the channel is blocking, this will always be equal to count if count >= 0.
  319. -- error : A location to return an error of type GConvertError or GIOChannelError
  320. -- Returns : the status of the operation.
  321. -- g_io_channel_write_unichar ()
  322. -- GIOStatus g_io_channel_write_unichar (GIOChannel *channel,
  323. -- gunichar thechar,
  324. -- GError **error);
  325. -- This function cannot be called on a channel with NULL encoding.
  326. -- channel : a GIOChannel
  327. -- thechar : a character
  328. -- error : A location to return an error of type GConvertError or GIOChannelError
  329. -- Returns : a GIOStatus
  330. flush is
  331. -- Flushes the write buffer for the GIOChannel.
  332. do
  333. last_status.change_value(g_io_channel_flush (handle, default_pointer))
  334. --TODO: error handling
  335. end
  336. -- g_io_channel_seek_position ()
  337. -- GIOStatus g_io_channel_seek_position (GIOChannel *channel,
  338. -- gint64 offset,
  339. -- GSeekType type,
  340. -- GError **error);
  341. -- Replacement for g_io_channel_seek() with the new API.
  342. -- channel : a GIOChannel
  343. -- offset : The offset in bytes from the position specified by type
  344. -- type : a GSeekType. The type G_SEEK_CUR is only allowed in those cases where a call to g_io_channel_set_encoding() is allowed. See the documentation for g_io_channel_set_encoding() for details.
  345. -- error : A location to return an error of type GIOChannelError
  346. -- Returns : the status of the operation.
  347. -- enum GSeekType
  348. -- typedef enum
  349. -- {
  350. -- G_SEEK_CUR,
  351. -- G_SEEK_SET,
  352. -- G_SEEK_END
  353. -- } GSeekType;
  354. -- An enumeration specifying the base position for a g_io_channel_seek_position() operation.
  355. -- G_SEEK_CUR the current position in the file.
  356. -- G_SEEK_SET the start of the file.
  357. -- G_SEEK_END the end of the file.
  358. shutdown (after_flush: BOOLEAN) is
  359. -- Close an IO channel. Any pending data to be written will be
  360. -- flushed if flush is TRUE. The channel will not be freed until the
  361. -- last reference is dropped using g_io_channel_unref().
  362. do
  363. last_status.change_value(g_io_channel_shutdown(handle, after_flush.to_integer, default_pointer))
  364. end
  365. set_encoding (new_encoding: ABSTRACT_STRING) is
  366. -- Sets the encoding for the input/output of the channel.
  367. -- The internal encoding is always "UTF-8". The default encoding
  368. -- for the external file is "UTF-8". encoding=Void sets binary
  369. -- encoding.
  370. require
  371. -- The encoding can only be set if one of the following conditions
  372. -- is true:
  373. -- 1. The channel was just created, and has not been written to
  374. -- or read from yet.
  375. -- 2. The channel is write-only.
  376. -- 3. The channel is a file, and the file pointer was just
  377. -- repositioned by a call to g_io_channel_seek_position().
  378. -- (This flushes all the internal buffers.)
  379. -- 4. The current `encoding' is Void or "UTF-8".
  380. -- 5. One of the (new API) read functions has just returned
  381. -- G_IO_STATUS_EOF (or, in the case of
  382. -- g_io_channel_read_to_end(), G_IO_STATUS_NORMAL).
  383. -- 6. One of the functions g_io_channel_read_chars() or
  384. -- g_io_channel_read_unichar() has returned G_IO_STATUS_AGAIN
  385. -- or G_IO_STATUS_ERROR. This may be useful in the case of
  386. -- G_CONVERT_ERROR_ILLEGAL_SEQUENCE. Returning one of these
  387. -- statuses from g_io_channel_read_line(),
  388. -- g_io_channel_read_line_string(), or
  389. -- g_io_channel_read_to_end() does not guarantee that the
  390. -- encoding can be changed.
  391. --
  392. -- Channels which do not meet one of the above conditions
  393. -- cannot call g_io_channel_seek_position() with an offset
  394. -- of G_SEEK_CUR, and, if they are "seekable", cannot call
  395. -- g_io_channel_write_chars() after calling one of the API
  396. -- "read" functions.
  397. local
  398. p_encoding: POINTER
  399. do
  400. if new_encoding /= Void then
  401. p_encoding := new_encoding.to_external
  402. end
  403. last_status.change_value(g_io_channel_set_encoding
  404. (handle, p_encoding, default_pointer))
  405. -- TODO: GError Handling
  406. end
  407. -- #define G_IO_CHANNEL_ERROR g_io_channel_error_quark()
  408. -- Error domain for GIOChannel operations. Errors in this domain will be from the GIOChannelError enumeration. See GError for information on error domains.
  409. -- g_io_channel_error_from_errno ()
  410. -- GIOChannelError g_io_channel_error_from_errno
  411. -- (gint en);
  412. -- Converts an errno error number to a GIOChannelError.
  413. -- en : an errno error number, e.g. EINVAL.
  414. -- Returns : a GIOChannelError error number, e.g. G_IO_CHANNEL_ERROR_INVAL.
  415. -- g_io_create_watch ()
  416. -- GSource* g_io_create_watch (GIOChannel *channel,
  417. -- GIOCondition condition);
  418. -- Creates a GSource that's dispatched when condition is met for the given channel. For example, if condition is G_IO_IN, the source will be dispatched when there's data available for reading. g_io_add_watch() is a simpler interface to this same functionality, for the case where you want to add the source to the default main loop at the default priority.
  419. -- channel : a GIOChannel to watch
  420. -- condition : conditions to watch for
  421. -- Returns : a new GSource
  422. -- g_io_add_watch_full ()
  423. -- guint g_io_add_watch_full (GIOChannel *channel,
  424. -- gint priority,
  425. -- GIOCondition condition,
  426. -- GIOFunc func,
  427. -- gpointer user_data,
  428. -- GDestroyNotify notify);
  429. -- Adds the GIOChannel into the main event loop with the given priority.
  430. -- channel : a GIOChannel.
  431. -- priority : the priority of the GIOChannel source.
  432. -- condition : the condition to watch for.
  433. -- func : the function to call when the condition is satisfied.
  434. -- user_data : user data to pass to func.
  435. -- notify : the function to call when the source is removed.
  436. -- Returns : the event source id.
  437. -- enum GIOCondition
  438. -- typedef enum
  439. -- {
  440. -- G_IO_IN GLIB_SYSDEF_POLLIN,
  441. -- G_IO_OUT GLIB_SYSDEF_POLLOUT,
  442. -- G_IO_PRI GLIB_SYSDEF_POLLPRI,
  443. -- G_IO_ERR GLIB_SYSDEF_POLLERR,
  444. -- G_IO_HUP GLIB_SYSDEF_POLLHUP,
  445. -- G_IO_NVAL GLIB_SYSDEF_POLLNVAL
  446. -- } GIOCondition;
  447. -- A bitwise combination representing a condition to watch for on an event source.
  448. -- G_IO_IN There is data to read.
  449. -- G_IO_OUT Data can be written (without blocking).
  450. -- G_IO_PRI There is urgent data to read.
  451. -- G_IO_ERR Error condition.
  452. -- G_IO_HUP Hung up (the connection has been broken, usually for pipes and sockets).
  453. -- G_IO_NVAL Invalid request. The file descriptor is not open.
  454. -- GIOFunc ()
  455. -- gboolean (*GIOFunc) (GIOChannel *source,
  456. -- GIOCondition condition,
  457. -- gpointer data);
  458. -- Specifies the type of function passed to g_io_add_watch() or g_io_add_watch_full(), which is called when the requested condition on a GIOChannel is satisfied.
  459. -- source : the GIOChannel event source.
  460. -- condition : the condition which has been satisfied.
  461. -- data : user data set in g_io_add_watch() or g_io_add_watch_full().
  462. -- Returns : the function should return FALSE if the event source should be removed.
  463. -- GIOFuncs
  464. -- typedef struct {
  465. -- GIOStatus (*io_read) (GIOChannel *channel,
  466. -- gchar *buf,
  467. -- gsize count,
  468. -- gsize *bytes_read,
  469. -- GError **err);
  470. -- GIOStatus (*io_write) (GIOChannel *channel,
  471. -- const gchar *buf,
  472. -- gsize count,
  473. -- gsize *bytes_written,
  474. -- GError **err);
  475. -- GIOStatus (*io_seek) (GIOChannel *channel,
  476. -- gint64 offset,
  477. -- GSeekType type,
  478. -- GError **err);
  479. -- GIOStatus (*io_close) (GIOChannel *channel,
  480. -- GError **err);
  481. -- GSource* (*io_create_watch) (GIOChannel *channel,
  482. -- GIOCondition condition);
  483. -- void (*io_free) (GIOChannel *channel);
  484. -- GIOStatus (*io_set_flags) (GIOChannel *channel,
  485. -- GIOFlags flags,
  486. -- GError **err);
  487. -- GIOFlags (*io_get_flags) (GIOChannel *channel);
  488. -- } GIOFuncs;
  489. -- A table of functions used to handle different types of GIOChannel in a generic way.
  490. -- g_io_channel_get_buffer_size ()
  491. -- gsize g_io_channel_get_buffer_size (GIOChannel *channel);
  492. -- Gets the buffer size.
  493. -- channel : a GIOChannel
  494. -- Returns : the size of the buffer.
  495. -- g_io_channel_set_buffer_size ()
  496. -- void g_io_channel_set_buffer_size (GIOChannel *channel,
  497. -- gsize size);
  498. -- Sets the buffer size.
  499. -- channel : a GIOChannel
  500. -- size : the size of the buffer. 0 == pick a good size
  501. -- g_io_channel_get_buffer_condition ()
  502. -- GIOCondition g_io_channel_get_buffer_condition
  503. -- (GIOChannel *channel);
  504. -- This function returns a GIOCondition depending on whether there is data to be read/space to write data in the internal buffers in the GIOChannel. Only the flags G_IO_IN and G_IO_OUT may be set.
  505. -- channel : A GIOChannel
  506. -- Returns : A GIOCondition
  507. -- g_io_channel_get_flags ()
  508. -- GIOFlags g_io_channel_get_flags (GIOChannel *channel);
  509. -- Gets the current flags for a GIOChannel, including read-only flags such as G_IO_FLAG_IS_READABLE.
  510. -- The values of the flags G_IO_FLAG_IS_READABLE and G_IO_FLAG_IS_WRITEABLE are cached for internal use by the channel when it is created. If they should change at some later point (e.g. partial shutdown of a socket with the UNIX shutdown() function), the user should immediately call g_io_channel_get_flags() to update the internal values of these flags.
  511. -- channel : a GIOChannel
  512. -- Returns : the flags which are set on the channel
  513. -- g_io_channel_set_flags ()
  514. -- GIOStatus g_io_channel_set_flags (GIOChannel *channel,
  515. -- GIOFlags flags,
  516. -- GError **error);
  517. -- Sets the (writeable) flags in channel to (flags & G_IO_CHANNEL_SET_MASK).
  518. -- channel : a GIOChannel.
  519. -- flags : the flags to set on the IO channel.
  520. -- error : A location to return an error of type GIOChannelError.
  521. -- Returns : the status of the operation.
  522. -- enum GIOFlags
  523. -- g_io_channel_get_line_term ()
  524. -- const gchar* g_io_channel_get_line_term (GIOChannel *channel,
  525. -- gint *length);
  526. -- This returns the string that GIOChannel uses to determine where in the file a line break occurs. A value of NULL indicates auto detection.
  527. -- channel : a GIOChannel
  528. -- length : a location to return the length of the line terminator
  529. -- Returns : The line termination string. This value is owned by GLib and must not be freed.
  530. -- g_io_channel_set_line_term ()
  531. -- void g_io_channel_set_line_term (GIOChannel *channel,
  532. -- const gchar *line_term,
  533. -- gint length);
  534. -- This sets the string that GIOChannel uses to determine where in the file a line break occurs.
  535. -- channel : a GIOChannel
  536. -- line_term : The line termination string. Use NULL for auto detect. Auto detection breaks on "\n", "\r\n", "\r", "\0", and the Unicode paragraph separator. Auto detection should not be used for anything other than file-based channels.
  537. -- length : The length of the termination string. If -1 is passed, the string is assumed to be nul-terminated. This option allows termination strings with embeded nuls.
  538. -- g_io_channel_get_close_on_unref ()
  539. -- gboolean g_io_channel_get_close_on_unref (GIOChannel *channel);
  540. -- Returns whether the file/socket/whatever associated with channel will be closed when channel receives its final unref and is destroyed. The default value of this is TRUE for channels created by g_io_channel_new_file(), and FALSE for all other channels.
  541. -- channel : a GIOChannel.
  542. -- Returns : Whether the channel will be closed on the final unref of the GIOChannel data structure.
  543. -- g_io_channel_set_close_on_unref ()
  544. -- void g_io_channel_set_close_on_unref (GIOChannel *channel,
  545. -- gboolean do_close);
  546. -- Setting this flag to TRUE for a channel you have already closed can cause problems.
  547. -- channel : a GIOChannel
  548. -- do_close : Whether to close the channel on the final unref of the GIOChannel data structure. The default value of this is TRUE for channels created by g_io_channel_new_file(), and FALSE for all other channels.
  549. -- g_io_channel_read ()
  550. -- GIOError g_io_channel_read (GIOChannel *channel,
  551. -- gchar *buf,
  552. -- gsize count,
  553. -- gsize *bytes_read);
  554. -- Warning
  555. -- g_io_channel_read is deprecated and should not be used in newly-written code. Use g_io_channel_read_chars() instead.
  556. -- Reads data from a GIOChannel.
  557. -- channel : a GIOChannel.
  558. -- buf : a buffer to read the data into (which should be at least count bytes long).
  559. -- count : the number of bytes to read from the GIOChannel.
  560. -- bytes_read : returns the number of bytes actually read.
  561. -- Returns : G_IO_ERROR_NONE if the operation was successful.
  562. -- g_io_channel_write ()
  563. -- GIOError g_io_channel_write (GIOChannel *channel,
  564. -- const gchar *buf,
  565. -- gsize count,
  566. -- gsize *bytes_written);
  567. -- Warning
  568. -- g_io_channel_write is deprecated and should not be used in newly-written code. Use g_io_channel_write_chars() instead.
  569. -- Writes data to a GIOChannel.
  570. -- channel : a GIOChannel.
  571. -- buf : the buffer containing the data to write.
  572. -- count : the number of bytes to write.
  573. -- bytes_written : the number of bytes actually written.
  574. -- Returns : G_IO_ERROR_NONE if the operation was successful.
  575. -- g_io_channel_seek ()
  576. -- GIOError g_io_channel_seek (GIOChannel *channel,
  577. -- gint64 offset,
  578. -- GSeekType type);
  579. -- Warning
  580. -- g_io_channel_seek is deprecated and should not be used in newly-written code. Use g_io_channel_seek_position() instead.
  581. -- Sets the current position in the GIOChannel, similar to the standard library function fseek().
  582. -- channel : a GIOChannel.
  583. -- offset : an offset, in bytes, which is added to the position specified by type
  584. -- type : the position in the file, which can be G_SEEK_CUR (the current position), G_SEEK_SET (the start of the file), or G_SEEK_END (the end of the file).
  585. -- Returns : G_IO_ERROR_NONE if the operation was successful.
  586. -- g_io_channel_close ()
  587. -- void g_io_channel_close (GIOChannel *channel);
  588. -- Warning
  589. -- g_io_channel_close is deprecated and should not be used in newly-written code. Use g_io_channel_shutdown() instead.
  590. -- Close an IO channel. Any pending data to be written will be flushed, ignoring errors. The channel will not be freed until the last reference is dropped using g_io_channel_unref().
  591. -- channel : A GIOChannel
  592. -- See Also
  593. -- gtk_input_add_full(), gtk_input_remove(), gdk_input_add(), gdk_input_add_full(), gdk_input_remove()
  594. -- Convenience functions for creating GIOChannel instances and adding them to the main event loop.
  595. feature {} -- Internal
  596. watch_list: FAST_ARRAY [G_IO_FUNC]
  597. -- We keep g_io_funcs here, to save them from the GC
  598. end -- class G_IO_CHANNEL