Remove unused headers and functions
[platform/core/multimedia/libmm-sound.git] / common / mm_sound_utils.c
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungbae Shin <seungbae.shin@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <sys/types.h>
23 #include <fcntl.h>
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <errno.h>
27 #include <glib.h>
28
29 #include <vconf.h>
30 #include <mm_types.h>
31 #include <mm_error.h>
32 #include <mm_debug.h>
33 #include "../include/mm_sound_private.h"
34 #include "../include/mm_sound_utils.h"
35
36 #define VCONF_KEY_VOLUME_PREFIX                         "file/private/sound/volume"
37 #define VCONF_KEY_VOLUME_TYPE_SYSTEM            VCONF_KEY_VOLUME_PREFIX"/system"
38 #define VCONF_KEY_VOLUME_TYPE_NOTIFICATION      VCONF_KEY_VOLUME_PREFIX"/notification"
39 #define VCONF_KEY_VOLUME_TYPE_ALARM                     VCONF_KEY_VOLUME_PREFIX"/alarm"
40 #define VCONF_KEY_VOLUME_TYPE_RINGTONE          VCONF_KEY_VOLUME_PREFIX"/ringtone"
41 #define VCONF_KEY_VOLUME_TYPE_MEDIA                     VCONF_KEY_VOLUME_PREFIX"/media"
42 #define VCONF_KEY_VOLUME_TYPE_CALL                      VCONF_KEY_VOLUME_PREFIX"/call"
43 #define VCONF_KEY_VOLUME_TYPE_VOIP                      VCONF_KEY_VOLUME_PREFIX"/voip"
44 #define VCONF_KEY_VOLUME_TYPE_VOICE             VCONF_KEY_VOLUME_PREFIX"/voice"
45 #define VCONF_KEY_VOLUME_TYPE_ANDROID           VCONF_KEY_VOLUME_PREFIX"/fixed"
46
47 static char *g_volume_vconf[VOLUME_TYPE_MAX] = {
48         VCONF_KEY_VOLUME_TYPE_SYSTEM,           /* VOLUME_TYPE_SYSTEM */
49         VCONF_KEY_VOLUME_TYPE_NOTIFICATION,     /* VOLUME_TYPE_NOTIFICATION */
50         VCONF_KEY_VOLUME_TYPE_ALARM,            /* VOLUME_TYPE_ALARM */
51         VCONF_KEY_VOLUME_TYPE_RINGTONE,         /* VOLUME_TYPE_RINGTONE */
52         VCONF_KEY_VOLUME_TYPE_MEDIA,            /* VOLUME_TYPE_MEDIA */
53         VCONF_KEY_VOLUME_TYPE_CALL,                     /* VOLUME_TYPE_CALL */
54         VCONF_KEY_VOLUME_TYPE_VOIP,                     /* VOLUME_TYPE_VOIP */
55         VCONF_KEY_VOLUME_TYPE_VOICE,            /* VOLUME_TYPE_VOICE */
56         VCONF_KEY_VOLUME_TYPE_ANDROID           /* VOLUME_TYPE_FIXED */
57 };
58 static char *g_volume_str[VOLUME_TYPE_MAX] = {
59         "SYSTEM",
60         "NOTIFICATION",
61         "ALARM",
62         "RINGTONE",
63         "MEDIA",
64         "CALL",
65         "VOIP",
66         "VOICE",
67         "FIXED",
68 };
69
70 EXPORT_API
71 int mm_sound_util_volume_get_value_by_type(volume_type_t type, unsigned int *value)
72 {
73         int ret = MM_ERROR_NONE;
74         int vconf_value = 0;
75
76         /* Get volume value from VCONF */
77         if (vconf_get_int(g_volume_vconf[type], &vconf_value)) {
78                 debug_error ("vconf_get_int(%s) failed..\n", g_volume_vconf[type]);
79                 return MM_ERROR_SOUND_INTERNAL;
80         }
81
82         *value = vconf_value;
83         if (ret == MM_ERROR_NONE)
84                 debug_log("volume_get_value %s %d",  g_volume_str[type], *value);
85
86         return ret;
87 }
88
89 EXPORT_API
90 int mm_sound_util_volume_set_value_by_type(volume_type_t type, unsigned int value)
91 {
92         int ret = MM_ERROR_NONE;
93         int vconf_value = 0;
94
95         vconf_value = value;
96         debug_log("volume_set_value %s %d",  g_volume_str[type], value);
97
98         /* Set volume value to VCONF */
99         if ((ret = vconf_set_int(g_volume_vconf[type], vconf_value)) != 0) {
100                 int vconf_errno;
101                 vconf_errno = vconf_get_ext_errno();
102                 debug_error ("vconf_set_int(%s) failed..ret[%d] errno[%d]\n", g_volume_vconf[type], ret, vconf_errno);
103                 if (vconf_errno == VCONF_ERROR_FILE_PERM)
104                         return MM_ERROR_SOUND_PERMISSION_DENIED;
105                 else
106                         return MM_ERROR_SOUND_INTERNAL;
107         }
108         return ret;
109 }
110
111 EXPORT_API
112 bool mm_sound_util_is_process_alive(pid_t pid)
113 {
114         gchar *tmp = NULL;
115         int ret = -1;
116
117         if (pid > 999999 || pid < 2)
118                 return false;
119
120         if ((tmp = g_strdup_printf("/proc/%d", pid))) {
121                 ret = access(tmp, F_OK);
122                 g_free(tmp);
123         }
124
125         if (ret == -1) {
126                 if (errno == ENOENT) {
127                         debug_warning ("/proc/%d not exist", pid);
128                         return false;
129                 } else {
130                         debug_error ("/proc/%d access errno[%d]", pid, errno);
131
132                         /* FIXME: error occured but file exists */
133                         return true;
134                 }
135         }
136
137         return true;
138 }