AsyncSocketConnector* async_socket_connector_new(const SockAddress* address, int retry_to, asc_event_cb cb, void* cb_opaque, Looper* looper) { AsyncSocketConnector* connector; if (cb == NULL) { W("No callback for AsyncSocketConnector for socket '%s'", sock_address_to_string(address)); errno = EINVAL; return NULL; } ANEW0(connector); connector->fd = -1; connector->retry_to = retry_to; connector->on_connected_cb = cb; connector->on_connected_cb_opaque = cb_opaque; connector->ref_count = 1; /* Copy socket address. */ #ifdef _WIN32 connector->address = *address; #else if (sock_address_get_family(address) == SOCKET_UNIX) { sock_address_init_unix(&connector->address, sock_address_get_path(address)); } else { connector->address = *address; } #endif /* Create a looper for asynchronous I/O. */ if (looper == NULL) { connector->looper = looper_newCore(); if (connector->looper == NULL) { E("Unable to create I/O looper for AsyncSocketConnector for socket '%s'", _asc_socket_string(connector)); cb(cb_opaque, connector, ASIO_STATE_FAILED); _async_socket_connector_free(connector); return NULL; } connector->owns_looper = 1; } else { connector->looper = looper; connector->owns_looper = 0; } /* Create a timer that will be used for connection retries. */ loopTimer_init(connector->connector_timer, connector->looper, _on_async_socket_connector_retry, connector); T("ASC %s: New connector object", _asc_socket_string(connector)); return connector; }
void android_net_pipes_init(void) { Looper* looper = looper_newCore(); goldfish_pipe_add_type( "tcp", looper, &netPipeTcp_funcs ); #ifndef _WIN32 goldfish_pipe_add_type( "unix", looper, &netPipeUnix_funcs ); #endif goldfish_pipe_add_type( "opengles", looper, &openglesPipe_funcs ); }
int attachUiProxy_create(int fd) { // Initialize the only AttachUIProxy instance. _attachUiProxy.sock = fd; _attachUiProxy.looper = looper_newCore(); loopIo_init(&_attachUiProxy.io, _attachUiProxy.looper, _attachUiProxy.sock, _attachUiProxy_io_func, &_attachUiProxy); loopIo_wantRead(&_attachUiProxy.io); return 0; }
int userEventsImpl_create(int fd) { _UserEventsImpl.sock = fd; _UserEventsImpl.event_header.event_type = -1; _UserEventsImpl.state = EXPECTS_HEADER; _UserEventsImpl.looper = looper_newCore(); loopIo_init(&_UserEventsImpl.io, _UserEventsImpl.looper, _UserEventsImpl.sock, _userEventsImpl_io_func, &_UserEventsImpl); asyncReader_init(&_UserEventsImpl.user_events_reader, &_UserEventsImpl.event_header, sizeof(_UserEventsImpl.event_header), &_UserEventsImpl.io); return 0; }
/******************************************************************************** * ADB server API *******************************************************************************/ int adb_server_init(int port) { if (!_adb_server_initialized) { /* Initialize the descriptor. */ memset(&_adb_server, 0, sizeof(_adb_server)); alist_init(&_adb_server.adb_hosts); alist_init(&_adb_server.adb_guests); alist_init(&_adb_server.pending_hosts); alist_init(&_adb_server.pending_guests); _adb_server.port = port; /* Create looper for an async I/O on the server. */ _adb_server.looper = looper_newCore(); if (_adb_server.looper == NULL) { E("Unable to create I/O looper for ADB server"); return -1; } /* Create loopback server socket for the ADB port. */ sock_address_init_inet(&_adb_server.socket_address, SOCK_ADDRESS_INET_LOOPBACK, port); _adb_server.so = socket_loopback_server(port, SOCKET_STREAM); if (_adb_server.so < 0) { E("Unable to create ADB server socket: %s", strerror(errno)); return -1; } /* Prepare server socket for I/O */ socket_set_nonblock(_adb_server.so); loopIo_init(_adb_server.io, _adb_server.looper, _adb_server.so, _on_server_socket_io, &_adb_server); loopIo_wantRead(_adb_server.io); D("ADB server has been initialized for port %d. Socket: %d", port, _adb_server.so); _adb_server_initialized = 1; } return 0; }
int coreCmdImpl_create(int fd) { _coreCmdImpl.sock = fd; _coreCmdImpl.looper = looper_newCore(); loopIo_init(&_coreCmdImpl.io, _coreCmdImpl.looper, _coreCmdImpl.sock, _coreCmdImpl_io_func, &_coreCmdImpl); _coreCmdImpl.cmd_state = EXPECTS_HEADER; _coreCmdImpl.cmd_param_buf = &_coreCmdImpl.cmd_param[0]; asyncReader_init(&_coreCmdImpl.async_reader, &_coreCmdImpl.cmd_header, sizeof(_coreCmdImpl.cmd_header), &_coreCmdImpl.io); _coreCmdImpl.sync_writer = syncsocket_init(fd); if (_coreCmdImpl.sync_writer == NULL) { derror("Unable to create writer for CoreCmdImpl instance: %s\n", errno_str); coreCmdImpl_destroy(); return -1; } return 0; }
int uiCmdProxy_create(int fd) { _uiCmdProxy.sock = fd; _uiCmdProxy.looper = looper_newCore(); loopIo_init(&_uiCmdProxy.io, _uiCmdProxy.looper, _uiCmdProxy.sock, _uiCmdProxy_io_func, &_uiCmdProxy); loopIo_wantRead(&_uiCmdProxy.io); _uiCmdProxy.sync_writer = syncsocket_init(fd); if (_uiCmdProxy.sync_writer == NULL) { derror("Unable to initialize UICmdProxy writer: %s\n", errno_str); uiCmdProxy_destroy(); return -1; } { AndroidHwControlFuncs funcs; funcs.light_brightness = _uiCmdProxy_brightness_change_callback; android_hw_control_set(&_uiCmdProxy, &funcs); } return 0; }
static void emulator_window_setup( EmulatorWindow* emulator ) { static const SkinWindowFuncs my_window_funcs = { .key_event = &emulator_window_window_key_event, .mouse_event = &emulator_window_window_mouse_event, .generic_event = &emulator_window_window_generic_event, .opengles_show = &emulator_window_opengles_show_window, .opengles_hide = &emulator_window_opengles_hide_window, .opengles_redraw = &emulator_window_opengles_redraw_window, .opengles_free = &android_stopOpenglesRenderer, }; static const SkinTrackBallParameters my_trackball_params = { .diameter = 30, .ring = 2, .ball_color = 0xffe0e0e0, .dot_color = 0xff202020, .ring_color = 0xff000000, .event_func = &emulator_window_trackball_event, }; if (emulator->opts->no_window || emulator->ui) { return; } SkinUIParams my_ui_params = { .enable_touch = !androidHwConfig_isScreenNoTouch(android_hw), .enable_dpad = android_hw->hw_dPad != 0, .enable_keyboard = android_hw->hw_keyboard != 0, .enable_trackball = android_hw->hw_trackBall != 0, .window_x = emulator->win_x, .window_y = emulator->win_y, .window_scale = get_default_scale(emulator->opts), .keyboard_charmap = emulator->opts->charmap, .keyboard_raw_keys = emulator->opts->raw_keys != 0, #if CONFIG_QT .win32_ignore_events = true, #else .win32_ignore_events = false, #endif }; write_window_name(my_ui_params.window_name, sizeof(my_ui_params.window_name), android_base_port, avdInfo_getName(android_avdInfo)); static const SkinUIFuncs my_ui_funcs = { .window_funcs = &my_window_funcs, .trackball_params = &my_trackball_params, .keyboard_event = &emulator_window_keyboard_event, //user_event_key, .keyboard_flush = &user_event_keycodes, .network_toggle = &emulator_window_network_toggle, .framebuffer_invalidate = &emulator_window_framebuffer_invalidate, }; // Determine whether to use an EmuGL sub-window or not. const char* env = getenv("ANDROID_GL_SOFTWARE_RENDERER"); s_use_emugl_subwindow = !env || !env[0] || env[0] == '0'; if (s_use_emugl_subwindow) { VERBOSE_PRINT(gles, "Using EmuGL sub-window for GPU display"); } else { VERBOSE_PRINT(gles, "Using glReadPixels() for GPU display"); } emulator->ui = skin_ui_create(emulator->layout_file, android_hw->hw_initialOrientation, &my_ui_funcs, &my_ui_params); if (!emulator->ui) { return; } if (emulator->onion) { skin_ui_set_onion(emulator->ui, emulator->onion, emulator->onion_rotation, emulator->onion_alpha); } // Determine whether to use an EmuGL sub-window or not. if (!s_use_emugl_subwindow) { gpu_frame_set_post_callback(looper_newCore(), emulator, _emulator_window_on_gpu_frame); } skin_ui_reset_title(emulator->ui); } static void emulator_window_fb_update( void* _emulator, int x, int y, int w, int h ) { EmulatorWindow* emulator = _emulator; if (emulator->opts->no_window) { return; } if (!emulator->ui) { emulator_window_setup(emulator); } skin_ui_update_display(emulator->ui, x, y, w, h); } static void emulator_window_fb_rotate( void* _emulator, int rotation ) { EmulatorWindow* emulator = _emulator; emulator_window_setup( emulator ); }
static void* openglesPipe_init( void* hwpipe, void* _looper, const char* args ) { NetPipe *pipe; if (!_opengles_init) { /* This should never happen, unless there is a bug in the * emulator's initialization, or the system image. */ D("Trying to open the OpenGLES pipe without GPU emulation!"); return NULL; } char server_addr[PATH_MAX]; android_gles_server_path(server_addr, sizeof(server_addr)); #ifndef _WIN32 if (android_gles_fast_pipes) { pipe = (NetPipe *)netPipe_initUnix(hwpipe, _looper, server_addr); D("Creating Unix OpenGLES pipe for GPU emulation: %s", server_addr); } else { #else /* _WIN32 */ { #endif /* Connect through TCP as a fallback */ pipe = (NetPipe *)netPipe_initTcp(hwpipe, _looper, server_addr); D("Creating TCP OpenGLES pipe for GPU emulation!"); } if (pipe != NULL) { // Disable TCP nagle algorithm to improve throughput of small packets socket_set_nodelay(pipe->io->fd); // On Win32, adjust buffer sizes #ifdef _WIN32 { int sndbuf = 128 * 1024; int len = sizeof(sndbuf); if (setsockopt(pipe->io->fd, SOL_SOCKET, SO_SNDBUF, (char*)&sndbuf, len) == SOCKET_ERROR) { D("Failed to set SO_SNDBUF to %d error=0x%x\n", sndbuf, WSAGetLastError()); } } #endif /* _WIN32 */ } return pipe; } static const GoldfishPipeFuncs openglesPipe_funcs = { openglesPipe_init, netPipe_closeFromGuest, netPipe_sendBuffers, netPipe_recvBuffers, netPipe_poll, netPipe_wakeOn, NULL, /* we can't save these */ NULL, /* we can't load these */ }; void android_net_pipes_init(void) { Looper* looper = looper_newCore(); goldfish_pipe_add_type( "tcp", looper, &netPipeTcp_funcs ); #ifndef _WIN32 goldfish_pipe_add_type( "unix", looper, &netPipeUnix_funcs ); #endif goldfish_pipe_add_type( "opengles", looper, &openglesPipe_funcs ); }