configure.ac: Don't allow UNIX IPC to be configured for a native Windows build.
[mpd-mk.git] / src / input_stream.h
blob056d008a7715c0fb1e6298fcd2887e821ac86cdd
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef MPD_INPUT_STREAM_H
21 #define MPD_INPUT_STREAM_H
23 #include "check.h"
25 #include <glib.h>
27 #include <stddef.h>
28 #include <stdbool.h>
29 #include <sys/types.h>
31 #if !GLIB_CHECK_VERSION(2,14,0)
32 typedef gint64 goffset;
33 #endif
35 struct input_stream {
36 /**
37 * the plugin which implements this input stream
39 const struct input_plugin *plugin;
41 /**
42 * The absolute URI which was used to open this stream. May
43 * be NULL if this is unknown.
45 char *uri;
47 /**
48 * indicates whether the stream is ready for reading and
49 * whether the other attributes in this struct are valid
51 bool ready;
53 /**
54 * if true, then the stream is fully seekable
56 bool seekable;
58 /**
59 * the size of the resource, or -1 if unknown
61 goffset size;
63 /**
64 * the current offset within the stream
66 goffset offset;
68 /**
69 * the MIME content type of the resource, or NULL if unknown
71 char *mime;
74 static inline void
75 input_stream_init(struct input_stream *is, const struct input_plugin *plugin,
76 const char *uri)
78 is->plugin = plugin;
79 is->uri = g_strdup(uri);
80 is->ready = false;
81 is->seekable = false;
82 is->size = -1;
83 is->offset = 0;
84 is->mime = NULL;
87 static inline void
88 input_stream_deinit(struct input_stream *is)
90 g_free(is->uri);
91 g_free(is->mime);
94 /**
95 * Opens a new input stream. You may not access it until the "ready"
96 * flag is set.
98 * @return an #input_stream object on success, NULL on error
100 struct input_stream *
101 input_stream_open(const char *uri, GError **error_r);
104 * Close the input stream and free resources.
106 void
107 input_stream_close(struct input_stream *is);
110 * Seeks to the specified position in the stream. This will most
111 * likely fail if the "seekable" flag is false.
113 * @param is the input_stream object
114 * @param offset the relative offset
115 * @param whence the base of the seek, one of SEEK_SET, SEEK_CUR, SEEK_END
117 bool
118 input_stream_seek(struct input_stream *is, goffset offset, int whence,
119 GError **error_r);
122 * Returns true if the stream has reached end-of-file.
124 bool input_stream_eof(struct input_stream *is);
127 * Reads the tag from the stream.
129 * @return a tag object which must be freed with tag_free(), or NULL
130 * if the tag has not changed since the last call
132 struct tag *
133 input_stream_tag(struct input_stream *is);
136 * Reads some of the stream into its buffer. The following return
137 * codes are defined: -1 = error, 1 = something was buffered, 0 =
138 * nothing was buffered.
140 * The semantics of this function are not well-defined, and it will
141 * eventually be removed.
143 int input_stream_buffer(struct input_stream *is, GError **error_r);
146 * Reads data from the stream into the caller-supplied buffer.
147 * Returns 0 on error or eof (check with input_stream_eof()).
149 * @param is the input_stream object
150 * @param ptr the buffer to read into
151 * @param size the maximum number of bytes to read
152 * @return the number of bytes read
154 size_t
155 input_stream_read(struct input_stream *is, void *ptr, size_t size,
156 GError **error_r);
158 #endif