summaryrefslogtreecommitdiff
path: root/src/include/mm_radio_utils.h
blob: 3f70f29584c59a7b751d0526e440451ebe658a71 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * mm_radio_utils.h
 *
 * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * 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.
 *
 */

#ifndef __MM_RADIO_UTILS_H__
#define __MM_RADIO_UTILS_H__

#include <assert.h>
#include <mm_types.h>
#include <mm_error.h>
#include <mm_debug.h>
#include <mm_message.h>

/* radio log */
#define MMRADIO_LOG_FENTER		debug_fenter
#define MMRADIO_LOG_FLEAVE		debug_fleave
#define MMRADIO_LOG_INFO		debug_msg
#define MMRADIO_LOG_DEBUG		debug_log
#define MMRADIO_LOG_ERROR		debug_error
#define MMRADIO_LOG_WARNING		debug_warning
#define MMRADIO_LOG_CRITICAL	debug_critical
#define MMRADIO_SLOG_DEBUG		debug_log /* secure_debug_log */

/* general */
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(arr)		(sizeof(arr) / sizeof((arr)[0]))
#endif

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

#define MMRADIO_MAX_INT	(2147483647)

#define MMRADIO_FREEIF(x)	\
do {						\
	if (x) {				\
		free(x);			\
		x = NULL;			\
	}						\
} while (0)

#define MMRADIO_CHECK_INSTANCE(x_radio)				\
do {												\
	if (!x_radio) {									\
		debug_error("radio instance is NULL\n");	\
		return MM_ERROR_RADIO_NOT_INITIALIZED;		\
	}												\
} while (0)

#define MMRADIO_CHECK_ARG(x_radio)					\
do {												\
	if (!x_radio) {									\
		debug_error("argument is NULL\n");			\
		return MM_ERROR_COMMON_INVALID_ARGUMENT;	\
	}												\
} while (0)


#define MMRADIO_CHECK_INSTANCE_RETURN_VOID(x_radio)	\
do {												\
	if (!x_radio) {									\
		debug_error("radio instance is NULL\n");	\
		return;										\
	}												\
} while (0)

#define MMRADIO_CHECK_DEVICE_STATE(x_radio)				\
do {													\
	if (x_radio->radio_fd < 0) {						\
		debug_error("not available radio device\n");	\
		return MM_ERROR_RADIO_NOT_INITIALIZED;			\
	}													\
} while (0)

/* command locking for multithreading */
#define MMRADIO_CMD_LOCK(x_radio)		pthread_mutex_lock(&((mm_radio_t *)x_radio)->cmd_lock)
#define MMRADIO_CMD_UNLOCK(x_radio)		pthread_mutex_unlock(&((mm_radio_t *)x_radio)->cmd_lock)

#define MMRADIO_VOLUME_LOCK(x_radio)		pthread_mutex_lock(&((mm_radio_t *)x_radio)->volume_lock)
#define MMRADIO_VOLUME_UNLOCK(x_radio)		pthread_mutex_unlock(&((mm_radio_t *)x_radio)->volume_lock)

/* message posting */
#define MMRADIO_POST_MSG(x_radio, x_msgtype, x_msg_param)		\
do {															\
	debug_log("posting %s to application\n", #x_msgtype);		\
	__mmradio_post_message(x_radio, x_msgtype, x_msg_param);	\
} while (0)

/* setting radio state */
#define MMRADIO_SET_STATE(x_radio, x_state)					\
do {														\
	debug_log("setting mm-radio state to %d\n", x_state);	\
	__mmradio_set_state(x_radio, x_state);					\
} while (0)

/* state */
#define MMRADIO_CHECK_STATE_RETURN_IF_FAIL(x_radio, x_command)			\
do {																	\
	debug_log("checking radio state before doing %s\n", #x_command);	\
	switch (__mmradio_check_state(x_radio, x_command)) {				\
	case MM_ERROR_RADIO_INVALID_STATE:									\
		return MM_ERROR_RADIO_INVALID_STATE;							\
		break;															\
	/* NOTE : for robustness of mmfw. we won't treat it as an error */	\
	case MM_ERROR_RADIO_NO_OP:											\
		return MM_ERROR_NONE;											\
		break;															\
	default:															\
		break;															\
	}																	\
} while (0)

#define MMRADIO_CHECK_RETURN_IF_FAIL(x_ret, x_msg)		\
do {													\
	if (x_ret < 0) {									\
		debug_error("%s error\n", x_msg);				\
		return x_ret;									\
	}													\
} while (0);

#endif