symbian-qemu-0.9.1-12/qemu-symbian-svp/qemu-char.c
branchphonesim-integ
changeset 36 a587897e3bb2
parent 1 2fb8b9db1c86
child 71 5158c0d3bde3
equal deleted inserted replaced
22:3bf560f85513 36:a587897e3bb2
   119 {
   119 {
   120     if (s->bh == NULL) {
   120     if (s->bh == NULL) {
   121 	s->bh = qemu_bh_new(qemu_chr_reset_bh, s);
   121 	s->bh = qemu_bh_new(qemu_chr_reset_bh, s);
   122 	qemu_bh_schedule(s->bh);
   122 	qemu_bh_schedule(s->bh);
   123     }
   123     }
       
   124 }
       
   125 
       
   126 void qemu_chr_connect(CharDriverState *s)
       
   127 {
       
   128     if (s->chr_connect)
       
   129         s->chr_connect(s);
   124 }
   130 }
   125 
   131 
   126 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len)
   132 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len)
   127 {
   133 {
   128     return s->chr_write(s, buf, len);
   134     return s->chr_write(s, buf, len);
   603     if (fd_out < 0)
   609     if (fd_out < 0)
   604         return NULL;
   610         return NULL;
   605     return qemu_chr_open_fd(-1, fd_out);
   611     return qemu_chr_open_fd(-1, fd_out);
   606 }
   612 }
   607 
   613 
       
   614 static CharDriverState *qemu_chr_open_tempfile_out(const char *temp_file)
       
   615 {
       
   616     CharDriverState *ret = NULL;
       
   617     const char *temp_format = "/tmp/%s";
       
   618     char *fname = qemu_mallocz(sizeof(char) * (strlen(temp_path) + strlen(temp_file)));
       
   619     if (fname)
       
   620     {
       
   621         sprintf(fname, temp_format, temp_file);
       
   622         ret = qemu_chr_open_file_out(fname);
       
   623         qemu_free(fname);
       
   624     }
       
   625     return ret;
       
   626 }
       
   627 
   608 static CharDriverState *qemu_chr_open_pipe(const char *filename)
   628 static CharDriverState *qemu_chr_open_pipe(const char *filename)
   609 {
   629 {
   610     int fd_in, fd_out;
   630     int fd_in, fd_out;
   611     char filename_in[256], filename_out[256];
   631     char filename_in[256], filename_out[256];
   612 
   632 
  1755     if (fd_out == INVALID_HANDLE_VALUE)
  1775     if (fd_out == INVALID_HANDLE_VALUE)
  1756         return NULL;
  1776         return NULL;
  1757 
  1777 
  1758     return qemu_chr_open_win_file(fd_out);
  1778     return qemu_chr_open_win_file(fd_out);
  1759 }
  1779 }
       
  1780 
       
  1781 static CharDriverState *qemu_chr_open_win_tempfile_out(const char *temp_file)
       
  1782 {
       
  1783     CharDriverState *ret = NULL;
       
  1784     char* fname;
       
  1785     const char* temp_format = "%s\\%s";
       
  1786     const char* temp_path;
       
  1787     
       
  1788     temp_path = getenv("TEMP");
       
  1789     if (temp_path)
       
  1790     {
       
  1791         fname = qemu_mallocz(sizeof(char) * (strlen(temp_path) + strlen(temp_file) + strlen(temp_format)));
       
  1792         if (fname)
       
  1793         {
       
  1794             sprintf(fname, temp_format, temp_path, temp_file);
       
  1795             ret = qemu_chr_open_win_file_out(fname);
       
  1796             qemu_free(fname);
       
  1797         }
       
  1798     }
       
  1799 
       
  1800     return ret;
       
  1801 }
       
  1802 
  1760 #endif /* !_WIN32 */
  1803 #endif /* !_WIN32 */
  1761 
  1804 
  1762 /***********************************************************/
  1805 /***********************************************************/
  1763 /* UDP Net console */
  1806 /* UDP Net console */
  1764 
  1807 
  1884     int connected;
  1927     int connected;
  1885     int max_size;
  1928     int max_size;
  1886     int do_telnetopt;
  1929     int do_telnetopt;
  1887     int do_nodelay;
  1930     int do_nodelay;
  1888     int is_unix;
  1931     int is_unix;
       
  1932     int wait_connect;
       
  1933     int device_handles_connect;
  1889 } TCPCharDriver;
  1934 } TCPCharDriver;
  1890 
  1935 
  1891 static void tcp_chr_accept(void *opaque);
  1936 static void tcp_chr_accept(void *opaque);
  1892 
  1937 
  1893 static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
  1938 static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)
  2061     s->fd = fd;
  2106     s->fd = fd;
  2062     qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
  2107     qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL);
  2063     tcp_chr_connect(chr);
  2108     tcp_chr_connect(chr);
  2064 }
  2109 }
  2065 
  2110 
       
  2111 static void tcp_chr_do_connect(CharDriverState* chr)
       
  2112 {
       
  2113     TCPCharDriver *driver = (TCPCharDriver*)chr->opaque;
       
  2114     if (driver->device_handles_connect)
       
  2115     {
       
  2116         if (-1 != driver->listen_fd)
       
  2117         {
       
  2118             printf("QEMU waiting for connection...\n");
       
  2119             tcp_chr_accept(chr);
       
  2120             socket_set_nonblock(driver->listen_fd);
       
  2121         }
       
  2122         else
       
  2123         {
       
  2124             driver->connected = 1;
       
  2125             socket_set_nodelay(driver->fd);
       
  2126             tcp_chr_connect(chr);
       
  2127         }
       
  2128     }
       
  2129 }
       
  2130 
  2066 static void tcp_chr_close(CharDriverState *chr)
  2131 static void tcp_chr_close(CharDriverState *chr)
  2067 {
  2132 {
  2068     TCPCharDriver *s = chr->opaque;
  2133     TCPCharDriver *s = chr->opaque;
  2069     if (s->fd >= 0)
  2134     if (s->fd >= 0)
  2070         closesocket(s->fd);
  2135         closesocket(s->fd);
  2081     TCPCharDriver *s = NULL;
  2146     TCPCharDriver *s = NULL;
  2082     int fd = -1, offset = 0;
  2147     int fd = -1, offset = 0;
  2083     int is_listen = 0;
  2148     int is_listen = 0;
  2084     int is_waitconnect = 1;
  2149     int is_waitconnect = 1;
  2085     int do_nodelay = 0;
  2150     int do_nodelay = 0;
       
  2151     int is_device_handles_connect = 0;
  2086     const char *ptr;
  2152     const char *ptr;
  2087 
  2153 
  2088     ptr = host_str;
  2154     ptr = host_str;
  2089     while((ptr = strchr(ptr,','))) {
  2155     while((ptr = strchr(ptr,','))) {
  2090         ptr++;
  2156         ptr++;
  2094             is_waitconnect = 0;
  2160             is_waitconnect = 0;
  2095         } else if (!strncmp(ptr,"nodelay",6)) {
  2161         } else if (!strncmp(ptr,"nodelay",6)) {
  2096             do_nodelay = 1;
  2162             do_nodelay = 1;
  2097         } else if (!strncmp(ptr,"to=",3)) {
  2163         } else if (!strncmp(ptr,"to=",3)) {
  2098             /* nothing, inet_listen() parses this one */;
  2164             /* nothing, inet_listen() parses this one */;
       
  2165         } else if (!strncmp(ptr, "devicehandlesconnect", 20) && !is_unix) {
       
  2166             is_device_handles_connect = 1;
  2099         } else {
  2167         } else {
  2100             printf("Unknown option: %s\n", ptr);
  2168             printf("Unknown option: %s\n", ptr);
  2101             goto fail;
  2169             goto fail;
  2102         }
  2170         }
  2103     }
  2171     }
  2105         is_waitconnect = 0;
  2173         is_waitconnect = 0;
  2106 
  2174 
  2107     chr = qemu_mallocz(sizeof(CharDriverState));
  2175     chr = qemu_mallocz(sizeof(CharDriverState));
  2108     if (!chr)
  2176     if (!chr)
  2109         goto fail;
  2177         goto fail;
       
  2178         
  2110     s = qemu_mallocz(sizeof(TCPCharDriver));
  2179     s = qemu_mallocz(sizeof(TCPCharDriver));
  2111     if (!s)
  2180     if (!s)
  2112         goto fail;
  2181         goto fail;
  2113 
  2182 
  2114     if (is_listen) {
  2183     if (is_listen) {
  2145     s->connected = 0;
  2214     s->connected = 0;
  2146     s->fd = -1;
  2215     s->fd = -1;
  2147     s->listen_fd = -1;
  2216     s->listen_fd = -1;
  2148     s->is_unix = is_unix;
  2217     s->is_unix = is_unix;
  2149     s->do_nodelay = do_nodelay && !is_unix;
  2218     s->do_nodelay = do_nodelay && !is_unix;
       
  2219     s->wait_connect = is_waitconnect;
       
  2220     s->device_handles_connect = is_device_handles_connect;
  2150 
  2221 
  2151     chr->opaque = s;
  2222     chr->opaque = s;
  2152     chr->chr_write = tcp_chr_write;
  2223     chr->chr_write = tcp_chr_write;
  2153     chr->chr_close = tcp_chr_close;
  2224     chr->chr_close = tcp_chr_close;
       
  2225     chr->chr_connect = tcp_chr_do_connect;
  2154 
  2226 
  2155     if (is_listen) {
  2227     if (is_listen) {
  2156         s->listen_fd = fd;
  2228         s->listen_fd = fd;
  2157         qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);
  2229         qemu_set_fd_handler(s->listen_fd, tcp_chr_accept, NULL, chr);
  2158         if (is_telnet)
  2230         if (is_telnet)
  2159             s->do_telnetopt = 1;
  2231             s->do_telnetopt = 1;
  2160     } else {
  2232     } else {
  2161         s->connected = 1;
       
  2162         s->fd = fd;
  2233         s->fd = fd;
  2163         socket_set_nodelay(fd);
  2234         
  2164         tcp_chr_connect(chr);
  2235         if (!is_device_handles_connect)
  2165     }
  2236         {
  2166 
  2237             s->connected = 1;
  2167     if (is_listen && is_waitconnect) {
  2238             socket_set_nodelay(fd);
       
  2239             tcp_chr_connect(chr);
       
  2240         }
       
  2241     }
       
  2242 
       
  2243     if (is_listen && is_waitconnect && !is_device_handles_connect) {
  2168         printf("QEMU waiting for connection on: %s\n",
  2244         printf("QEMU waiting for connection on: %s\n",
  2169                chr->filename ? chr->filename : host_str);
  2245                chr->filename ? chr->filename : host_str);
  2170         tcp_chr_accept(chr);
  2246         tcp_chr_accept(chr);
  2171         socket_set_nonblock(s->listen_fd);
  2247         socket_set_nonblock(s->listen_fd);
  2172     }
  2248     }
  2218 #ifndef _WIN32
  2294 #ifndef _WIN32
  2219     if (strstart(filename, "unix:", &p)) {
  2295     if (strstart(filename, "unix:", &p)) {
  2220 	chr = qemu_chr_open_tcp(p, 0, 1);
  2296 	chr = qemu_chr_open_tcp(p, 0, 1);
  2221     } else if (strstart(filename, "file:", &p)) {
  2297     } else if (strstart(filename, "file:", &p)) {
  2222         chr = qemu_chr_open_file_out(p);
  2298         chr = qemu_chr_open_file_out(p);
       
  2299     } else if (strstart(filename, "tempfile:", &p)) {
       
  2300         chr = qemu_chr_open_tempfile_out(p);
  2223     } else if (strstart(filename, "pipe:", &p)) {
  2301     } else if (strstart(filename, "pipe:", &p)) {
  2224         chr = qemu_chr_open_pipe(p);
  2302         chr = qemu_chr_open_pipe(p);
  2225     } else if (!strcmp(filename, "pty")) {
  2303     } else if (!strcmp(filename, "pty")) {
  2226         chr = qemu_chr_open_pty();
  2304         chr = qemu_chr_open_pty();
  2227     } else if (!strcmp(filename, "stdio")) {
  2305     } else if (!strcmp(filename, "stdio")) {
  2250         chr = qemu_chr_open_win_pipe(p);
  2328         chr = qemu_chr_open_win_pipe(p);
  2251     } else
  2329     } else
  2252     if (strstart(filename, "file:", &p)) {
  2330     if (strstart(filename, "file:", &p)) {
  2253         chr = qemu_chr_open_win_file_out(p);
  2331         chr = qemu_chr_open_win_file_out(p);
  2254     } else
  2332     } else
       
  2333     if (strstart(filename, "tempfile:", &p)) {
       
  2334         chr = qemu_chr_open_win_tempfile_out(p);
       
  2335     } else
  2255     if (strstart(filename, "stdio", &p)) {
  2336     if (strstart(filename, "stdio", &p)) {
  2256         return qemu_chr_open_win_stdio(filename);
  2337         return qemu_chr_open_win_stdio(filename);
  2257     } else
  2338     } else
  2258 #endif
  2339 #endif
  2259 #ifdef CONFIG_BRLAPI
  2340 #ifdef CONFIG_BRLAPI