int disp_enabled_set(boolean enabled) { #if DEBUG_DISP LOG_DISP("disp_connected_set(): %d",enabled); #endif if((enabled == true)&&(disp_connected != true)) { LOGE("Error!Please connect extended display connection"); return -1; } disp_enabled = enabled; send_msg(enabled ? DISPD_EVT_DISP_ENABLED : DISPD_EVT_DISP_DISABLED); return 0; }
int disp_enabled_set(int fbid, boolean enabled) { #if DEBUG_DISP LOG_DISP("disp_connected_set(): %d",enabled); #endif if((enabled == true)&&(disp_class_list[fbid].disp_connected != true)) { LOGE("Error!Please connect extended display connection"); return -1; } disp_class_list[fbid].disp_enabled = enabled; send_msg_with_code(enabled ? InterfaceEnabled: InterfaceDisabled, enabled ? DISPD_EVT_DISP_ENABLED : DISPD_EVT_DISP_DISABLED, fbid); return 0; }
int disp_send_status(void) { int rc; #if DEBUG_DISP LOG_DISP("disp_send_status():"); #endif rc = send_msg(disp_connected_get() ? DISPD_EVT_DISP_CONNECTED : DISPD_EVT_DISP_DISCONNECTED); if (rc < 0) return rc; rc = send_msg(disp_enabled_get() ? DISPD_EVT_DISP_ENABLED : DISPD_EVT_DISP_DISABLED); return rc; }
int disp_send_status() { int rc = 0; int i; #if DEBUG_DISP LOG_DISP("disp_send_status():"); #endif for(i=0; i<MAX_DISP_DEVICE; i++) { rc = send_msg_with_code(disp_connected_get(i) ? InterfaceConnected: InterfaceDisconnected, disp_connected_get(i) ? DISPD_EVT_DISP_CONNECTED : DISPD_EVT_DISP_DISCONNECTED, i); if (rc < 0) return rc; rc = send_msg_with_code(disp_enabled_get(i) ? InterfaceEnabled: InterfaceDisabled, disp_enabled_get(i) ? DISPD_EVT_DISP_ENABLED : DISPD_EVT_DISP_DISABLED, i); if (rc < 0) return rc; } return rc; }
int main(int argc, char **argv) { int door_sock = -1; int uevent_sock = -1; struct sockaddr_nl nladdr; int uevent_sz = 64 * 1024; LOGI("Android Display Daemon version %d.%d", ver_major, ver_minor); /* * Create all the various sockets we'll need */ // Socket to listen on for incomming framework connections if ((door_sock = android_get_control_socket(DISPD_SOCKET)) < 0) { LOGE("Obtaining file descriptor socket '%s' failed: %s", DISPD_SOCKET, strerror(errno)); exit(1); } if (listen(door_sock, 4) < 0) { LOGE("Unable to listen on fd '%d' for socket '%s': %s", door_sock, DISPD_SOCKET, strerror(errno)); exit(1); } mkdir("/dev/block/dispd", 0755); // Socket to listen on for uevent changes memset(&nladdr, 0, sizeof(nladdr)); nladdr.nl_family = AF_NETLINK; nladdr.nl_pid = getpid(); nladdr.nl_groups = 0xffffffff; if ((uevent_sock = socket(PF_NETLINK, SOCK_DGRAM,NETLINK_KOBJECT_UEVENT)) < 0) { LOGE("Unable to create uevent socket: %s", strerror(errno)); exit(1); } if (setsockopt(uevent_sock, SOL_SOCKET, SO_RCVBUFFORCE, &uevent_sz, sizeof(uevent_sz)) < 0) { LOGE("Unable to set uevent socket options: %s", strerror(errno)); exit(1); } if (bind(uevent_sock, (struct sockaddr *) &nladdr, sizeof(nladdr)) < 0) { LOGE("Unable to bind uevent socket: %s", strerror(errno)); exit(1); } /* * Bootstrap */ bootstrap = 1; // Switch switch_bootstrap(); dvi_detection_bootstrap(); hdmi_detection_bootstrap(); bootstrap = 0; /* * Main loop */ LOG_DISP("Bootstrapping complete"); while(1) { fd_set read_fds; struct timeval to; int max = 0; int rc = 0; to.tv_sec = (60 * 60); to.tv_usec = 0; FD_ZERO(&read_fds); FD_SET(door_sock, &read_fds); if (door_sock > max) max = door_sock; FD_SET(uevent_sock, &read_fds); if (uevent_sock > max) max = uevent_sock; if (fw_sock != -1) { FD_SET(fw_sock, &read_fds); if (fw_sock > max) max = fw_sock; } if ((rc = select(max + 1, &read_fds, NULL, NULL, &to)) < 0) { LOGE("select() failed (%s)", strerror(errno)); sleep(1); continue; } if (!rc) { continue; } if (FD_ISSET(door_sock, &read_fds)) { struct sockaddr addr; socklen_t alen; alen = sizeof(addr); if (fw_sock != -1) { LOGE("Dropping duplicate framework connection"); int tmp = accept(door_sock, &addr, &alen); close(tmp); continue; } if ((fw_sock = accept(door_sock, &addr, &alen)) < 0) { LOGE("Unable to accept framework connection (%s)", strerror(errno)); } LOG_DISP("Accepted connection from framework"); //Send the states whether the disp already been connected through fw_sock if ((rc = dispmgr_send_status()) < 0) { LOGE("Unable to send dispmgr status to framework (%d)", rc); } } if (FD_ISSET(fw_sock, &read_fds)) { LOG_DISP("process cmd from framework"); if ((rc = process_framework_command(fw_sock)) < 0) { if (rc == -ECONNRESET) { LOGE("Framework disconnected"); close(fw_sock); fw_sock = -1; } else { LOGE("Error processing framework command (%s)", strerror(errno)); } } } if (FD_ISSET(uevent_sock, &read_fds)) { //LOG_DISP("process uevent from kernel"); if ((rc = process_uevent_message(uevent_sock)) < 0) { LOGE("Error processing uevent msg (%s)", strerror(errno)); } } } // while }