• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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()13 const 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)21 int 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 	default:
42 		return -EINVAL;
43 	}
44 
45 	snprintf(sock_path, CRAS_MAX_SOCKET_PATH_SIZE, "%s/%s", sock_dir,
46 		 sock_file);
47 
48 	return 0;
49 }
50