4 * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #ifndef __MM_RADIO_UTILS_H__
21 #define __MM_RADIO_UTILS_H__
27 #include <mm_message.h>
30 #define MMRADIO_LOG_FENTER debug_fenter
31 #define MMRADIO_LOG_FLEAVE debug_fleave
32 #define MMRADIO_LOG_DEBUG debug_log
33 #define MMRADIO_LOG_ERROR debug_error
34 #define MMRADIO_LOG_WARNING debug_warning
35 #define MMRADIO_LOG_CRITICAL debug_critical
36 #define MMRADIO_SLOG_DEBUG debug_log /* secure_debug_log */
40 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
50 #define MMRADIO_MAX_INT (2147483647)
52 #define MMRADIO_FREEIF(x) \
60 #define MMRADIO_CHECK_INSTANCE(x_radio) \
63 debug_error("radio instance is NULL\n"); \
64 return MM_ERROR_RADIO_NOT_INITIALIZED; \
68 #define MMRADIO_CHECK_ARG(x_radio) \
71 debug_error("argument is NULL\n"); \
72 return MM_ERROR_COMMON_INVALID_ARGUMENT; \
77 #define MMRADIO_CHECK_INSTANCE_RETURN_VOID(x_radio) \
80 debug_error("radio instance is NULL\n"); \
85 #define MMRADIO_CHECK_DEVICE_STATE(x_radio) \
87 if (x_radio->radio_fd < 0) { \
88 debug_error("not available radio device\n"); \
89 return MM_ERROR_RADIO_NOT_INITIALIZED; \
93 /* command locking for multithreading */
94 #define MMRADIO_CMD_LOCK(x_radio) pthread_mutex_lock(&((mm_radio_t *)x_radio)->cmd_lock)
95 #define MMRADIO_CMD_UNLOCK(x_radio) pthread_mutex_unlock(&((mm_radio_t *)x_radio)->cmd_lock)
97 #define MMRADIO_VOLUME_LOCK(x_radio) pthread_mutex_lock(&((mm_radio_t *)x_radio)->volume_lock)
98 #define MMRADIO_VOLUME_UNLOCK(x_radio) pthread_mutex_unlock(&((mm_radio_t *)x_radio)->volume_lock)
100 /* message posting */
101 #define MMRADIO_POST_MSG(x_radio, x_msgtype, x_msg_param) \
103 debug_log("posting %s to application\n", #x_msgtype); \
104 __mmradio_post_message(x_radio, x_msgtype, x_msg_param); \
107 /* setting radio state */
108 #define MMRADIO_SET_STATE(x_radio, x_state) \
110 debug_log("setting mm-radio state to %d\n", x_state); \
111 __mmradio_set_state(x_radio, x_state); \
115 #define MMRADIO_CHECK_STATE_RETURN_IF_FAIL(x_radio, x_command) \
117 debug_log("checking radio state before doing %s\n", #x_command); \
118 switch (__mmradio_check_state(x_radio, x_command)) { \
119 case MM_ERROR_RADIO_INVALID_STATE: \
120 return MM_ERROR_RADIO_INVALID_STATE; \
122 /* NOTE : for robustness of mmfw. we won't treat it as an error */ \
123 case MM_ERROR_RADIO_NO_OP: \
124 return MM_ERROR_NONE; \
131 #define MMRADIO_CHECK_RETURN_IF_FAIL(x_ret, x_msg) \
134 debug_error("%s error\n", x_msg); \