summaryrefslogtreecommitdiff
path: root/mm_sound_keysound.c
blob: 0d7bf9ff5d30f395da42a4e19019394a7ed27150 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * libmm-sound
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: Seungbae Shin <seungbae.shin@samsung.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#include <stdlib.h>
#include <memory.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>

#include <sys/stat.h>
#include <errno.h>

#include <mm_types.h>
#include <mm_error.h>
#include <mm_message.h>
#include <mm_debug.h>
#include <mm_sound.h>
#include <mm_sound_private.h>

#define KEYTONE_PATH "/tmp/keytone"		/* Keytone pipe path */
#define FILE_FULL_PATH 1024				/* File path lenth */
typedef struct {
	char filename[1024];
	int vol_type;
}ipc_t;

EXPORT_API
int mm_sound_play_keysound(const char *filename, const volume_type_t vol_type)
{
	int err = MM_ERROR_NONE;
	int fd = -1;
	int size = 0;
	ipc_t data = {{0,},};

	debug_fenter();

	if(!filename)
		return MM_ERROR_SOUND_INVALID_FILE;

	/* Check whether file exists */
	fd = open(filename, O_RDONLY);
	if(fd == -1) {
		debug_error("file open failed with %s\n", strerror(errno));
		switch(errno)
		{
		case EACCES:
			return MM_ERROR_SOUND_FILE_NOT_FOUND;
		case EMFILE:
		case ENFILE:
			return MM_ERROR_SOUND_INVALID_STATE;
		default:
			return MM_ERROR_SOUND_INTERNAL;
		}
	}
	close(fd);
	fd = -1;

	/* Open PIPE */
	fd = open(KEYTONE_PATH, O_WRONLY | O_NONBLOCK);
	if (fd == -1) {
		debug_error("Fail to open pipe\n");
		return MM_ERROR_SOUND_FILE_NOT_FOUND;
	}
	data.vol_type = vol_type;
	strncpy(data.filename, filename, FILE_FULL_PATH);
	debug_msg("The file name [%s]\n", data.filename);
	size = sizeof(ipc_t);

	/* Write to PIPE */
	err = write(fd, &data, size);
	if(err < 0) {
		debug_error("Fail to write data: %s\n", strerror(err));
		close(fd);
		return MM_ERROR_SOUND_INTERNAL;
	}
	/* Close PIPE */
	close(fd);

	debug_fleave();
	return MM_ERROR_NONE;
}