Debian Codegraph @

src/win32_support.h

raw
1 /*
2 Win32 support helper file
3
4 This file is only for use with the mpg123 frontend.
5 win32 support helpers for libmpg123 are in src/libmpg123/compat.h
6 */
7 #ifndef MPG123_WIN32_SUPPORT_H
8 #define MPG123_WIN32_SUPPORT_H
9
10 #include "config.h"
11 #include "mpg123.h"
12 #ifdef HAVE_WINDOWS_H
13
14 #define WIN32_LEAN_AND_MEAN 1
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <wchar.h>
19 #include <windows.h>
20 #include <winnls.h>
21 #include <shellapi.h>
22 #include <mmsystem.h>
23
24 #if defined (HAVE_WS2TCPIP_H) && !defined (__CYGWIN__)
25 #include <winsock2.h>
26 #include <ws2tcpip.h>
27 #endif
28
29 #if defined (WANT_WIN32_SOCKETS) /*conflict with gethostname and select in select.h and unistd.h */
30 /*
31 Note: Do not treat return values as valid file/socket handles, they only indicate success/failure.
32 file descriptors are ignored, only the local ws.local_socket is used for storing socket handle,
33 so the socket handle is always associated with the last call to win32_net_http_open
34
35 TODO: Move the socket descriptor/state struct into streamdump.c, which wraps all network
36 connections. Stored in in nh->parts, it enables multiple sockets being opened.
37 */
38
39 /**
40 * Opens an http URL
41 * @param[in] host to connect to
42 * @param[in] port to use
43 * @return -1 for failure, 1 for success
44 */
45 int win32_net_open_connection(mpg123_string *host, mpg123_string *port);
46
47 /**
48 * Reads from network socket
49 * @param[in] filedes Value is ignored, last open connection is used.
50 * @param[out] buf buffer to store data.
51 * @param[in] nbyte bytes to read.
52 * @return bytes read successfully from socket
53 */
54 mpg123_ssize_t win32_net_read (int fildes, void *buf, size_t nbyte);
55
56 /**
57 * Writes to network socket
58 * @param[in] filedes Value is ignored, last open connection is used.
59 * @param[in] buf buffer to read data from.
60 * @param[in] nbyte bytes to write.
61 * @return bytes written successfully to socket
62 */
63 mpg123_ssize_t win32_net_write (int fildes, const void *buf, size_t nbyte);
64
65 /**
66 * Writes a whole mpg123_string to the network socket
67 * @param[in] filedes Value is ignored, last open connection is used.
68 * @param[in] string the string to write
69 * @return TRUE if successful, FALS on error
70 */
71 int win32_net_writestring (int filedes, mpg123_string *string);
72
73 /**
74 * Initialize Winsock 2.2.
75 */
76 void win32_net_init (void);
77
78 /**
79 * Shutdown all win32 sockets.
80 */
81 void win32_net_deinit (void);
82
83 /**
84 * Close last open socket.
85 * @param[in] sock value is ignored.
86 */
87 void win32_net_close (int sock);
88 #endif
89
90 #ifdef WANT_WIN32_UNICODE
91 /**
92 * Put the windows command line into argv / argc, encoded in UTF-8.
93 * You are supposed to free up resources by calling win32_cmdline_free with the values you got from this one.
94 * @return 0 on success, -1 on error */
95 int win32_cmdline_utf8(int * argc, char *** argv);
96
97 /**
98 * Free up cmdline memory (the argv itself, theoretically hidden resources, too).
99 */
100 void win32_cmdline_free(int argc, char **argv);
101
102 #endif /* WIN32_WANT_UNICODE */
103
104 /**
105 * Set process priority
106 * @param arg -2: Idle, -1, bellow normal, 0, normal (ignored), 1 above normal, 2 highest, 3 realtime
107 */
108 void win32_set_priority (const int arg);
109
110 #ifdef WANT_WIN32_FIFO
111 /**
112 * win32_fifo_mkfifo
113 * Creates a named pipe of path.
114 * Should be closed with win32_fifo_close.
115 * @param[in] path Path of pipe, should be in form of "\\.\pipe\pipename".
116 * @return -1 on failure, 0 otherwise.
117 * @see win32_fifo_close
118 */
119 int win32_fifo_mkfifo(const char *path);
120
121 /**
122 *win32_fifo_close
123 * Closes previously open pipe
124 */
125 void win32_fifo_close(void);
126
127 /**
128 * win32_fifo_read_peek
129 * Checks how many bytes in fifo is pending read operation
130 * Only the tv_sec member in timeval is evaluated! No microsecond precision.
131 * @param[in] tv contains information on block duration
132 * @return bytes available
133 */
134 DWORD win32_fifo_read_peek(struct timeval *tv);
135
136 /***
137 * win32_fifo_read
138 * Read up to nbyte of data from open pipe into buf
139 * @param[in] buf Pointer to buffer.
140 * @param[in] nbyte Number of bytes to read up to.
141 * @return Number of bytes actually read.
142 */
143 mpg123_ssize_t win32_fifo_read(void *buf, size_t nbyte);
144 #endif /* #ifdef WANT_WIN32_FIFO */
145
146 #endif /* HAVE_WINDOWS_H */
147 #endif /* MPG123_WIN32_SUPPORT_H */
148