summaryrefslogtreecommitdiff
path: root/cras/src/common/cras_config.c
blob: 75fa24e703d823a25e0ff28e157e7c71a05e7553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <pwd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

#include "cras_config.h"

const char *cras_config_get_system_socket_file_dir()
{
	/* This directory is created by the upstart script, eventually it would
	 * be nice to make this more dynamic, but it isn't needed right now for
	 * Chrome OS. */
	return CRAS_SOCKET_FILE_DIR;
}

int cras_fill_socket_path(enum CRAS_CONNECTION_TYPE conn_type, char *sock_path)
{
	const char *sock_file;
	const char *sock_dir;

	sock_dir = cras_config_get_system_socket_file_dir();
	if (sock_dir == NULL) {
		return -ENOTDIR;
	}

	switch (conn_type) {
	case CRAS_CONTROL:
		sock_file = CRAS_SOCKET_FILE;
		break;
	case CRAS_PLAYBACK:
		sock_file = CRAS_PLAYBACK_SOCKET_FILE;
		break;
	case CRAS_CAPTURE:
		sock_file = CRAS_CAPTURE_SOCKET_FILE;
		break;
	case CRAS_VMS_LEGACY:
		sock_file = CRAS_VMS_LEGACY_SOCKET_FILE;
		break;
	case CRAS_VMS_UNIFIED:
		sock_file = CRAS_VMS_UNIFIED_SOCKET_FILE;
		break;
	case CRAS_PLUGIN_PLAYBACK:
		sock_file = CRAS_PLUGIN_PLAYBACK_SOCKET_FILE;
		break;
	case CRAS_PLUGIN_UNIFIED:
		sock_file = CRAS_PLUGIN_UNIFIED_SOCKET_FILE;
		break;
	default:
		return -EINVAL;
	}

	snprintf(sock_path, CRAS_MAX_SOCKET_PATH_SIZE, "%s/%s", sock_dir,
		 sock_file);

	return 0;
}