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) \
57 #define MMRADIO_CHECK_INSTANCE( x_radio ) \
60 debug_error("radio instance is NULL\n"); \
61 return MM_ERROR_RADIO_NOT_INITIALIZED; \
64 #define MMRADIO_CHECK_ARG( x_radio ) \
67 debug_error("argument is NULL\n"); \
68 return MM_ERROR_COMMON_INVALID_ARGUMENT; \
72 #define MMRADIO_CHECK_INSTANCE_RETURN_VOID( x_radio ) \
75 debug_error("radio instance is NULL\n"); \
79 #define MMRADIO_CHECK_DEVICE_STATE( x_radio ) \
80 if ( x_radio->radio_fd < 0 ) \
82 debug_error("not available radio device\n"); \
83 return MM_ERROR_RADIO_NOT_INITIALIZED;\
86 /* command locking for multithreading */
87 #define MMRADIO_CMD_LOCK(x_radio) pthread_mutex_lock(&((mm_radio_t *)x_radio)->cmd_lock)
88 #define MMRADIO_CMD_UNLOCK(x_radio) pthread_mutex_unlock(&((mm_radio_t *)x_radio)->cmd_lock)
90 #define MMRADIO_VOLUME_LOCK(x_radio) pthread_mutex_lock(&((mm_radio_t *)x_radio)->volume_lock)
91 #define MMRADIO_VOLUME_UNLOCK(x_radio) pthread_mutex_unlock(&((mm_radio_t *)x_radio)->volume_lock)
94 #define MMRADIO_POST_MSG( x_radio, x_msgtype, x_msg_param ) \
95 debug_log("posting %s to application\n", #x_msgtype); \
96 __mmradio_post_message(x_radio, x_msgtype, x_msg_param);
98 /* setting radio state */
99 #define MMRADIO_SET_STATE( x_radio, x_state ) \
100 debug_log("setting mm-radio state to %d\n", x_state); \
101 __mmradio_set_state(x_radio, x_state);
104 #define MMRADIO_CHECK_STATE_RETURN_IF_FAIL( x_radio, x_command ) \
105 debug_log("checking radio state before doing %s\n", #x_command); \
106 switch ( __mmradio_check_state(x_radio, x_command) ) \
108 case MM_ERROR_RADIO_INVALID_STATE: \
109 return MM_ERROR_RADIO_INVALID_STATE; \
111 /* NOTE : for robustness of mmfw. we won't treat it as an error */ \
112 case MM_ERROR_RADIO_NO_OP: \
113 return MM_ERROR_NONE; \
119 #define MMRADIO_CHECK_RETURN_IF_FAIL( x_ret, x_msg ) \
124 debug_error("%s error\n", x_msg);\