1 /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 #include <pwd.h> 7 #include <stdlib.h> 8 #include <sys/types.h> 9 #include <unistd.h> 10 11 #include "cras_config.h" 12 cras_config_get_system_socket_file_dir()13const char *cras_config_get_system_socket_file_dir() 14 { 15 /* This directory is created by the upstart script, eventually it would 16 * be nice to make this more dynamic, but it isn't needed right now for 17 * Chrome OS. */ 18 return CRAS_SOCKET_FILE_DIR; 19 } 20 cras_fill_socket_path(enum CRAS_CONNECTION_TYPE conn_type,char * sock_path)21int cras_fill_socket_path(enum CRAS_CONNECTION_TYPE conn_type, char *sock_path) 22 { 23 const char *sock_file; 24 const char *sock_dir; 25 26 sock_dir = cras_config_get_system_socket_file_dir(); 27 if (sock_dir == NULL) { 28 return -ENOTDIR; 29 } 30 31 switch (conn_type) { 32 case CRAS_CONTROL: 33 sock_file = CRAS_SOCKET_FILE; 34 break; 35 case CRAS_PLAYBACK: 36 sock_file = CRAS_PLAYBACK_SOCKET_FILE; 37 break; 38 case CRAS_CAPTURE: 39 sock_file = CRAS_CAPTURE_SOCKET_FILE; 40 break; 41 case CRAS_VMS_LEGACY: 42 sock_file = CRAS_VMS_LEGACY_SOCKET_FILE; 43 break; 44 case CRAS_VMS_UNIFIED: 45 sock_file = CRAS_VMS_UNIFIED_SOCKET_FILE; 46 break; 47 case CRAS_PLUGIN_PLAYBACK: 48 sock_file = CRAS_PLUGIN_PLAYBACK_SOCKET_FILE; 49 break; 50 case CRAS_PLUGIN_UNIFIED: 51 sock_file = CRAS_PLUGIN_UNIFIED_SOCKET_FILE; 52 break; 53 default: 54 return -EINVAL; 55 } 56 57 snprintf(sock_path, CRAS_MAX_SOCKET_PATH_SIZE, "%s/%s", sock_dir, 58 sock_file); 59 60 return 0; 61 } 62