4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
28 #include "internal/tcore_types.h"
30 #include "user_request.h"
34 struct private_object_data {
35 struct tcore_modem_operations *ops[TCORE_OPS_TYPE_MAX];
41 static void _free_hook(CoreObject *o)
43 struct private_object_data *po = NULL;
45 po = tcore_object_ref_object(o);
48 tcore_object_link_object(o, NULL);
52 static TReturn _dispatcher(CoreObject *o, UserRequest *ur, enum tcore_ops_type ops_type)
54 enum tcore_request_command command;
55 struct private_object_data *po = tcore_object_ref_object(o);
56 struct tcore_modem_operations *ops = NULL;
58 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_MODEM, TCORE_RETURN_EINVAL);
59 CORE_OBJECT_VALIDATE_OPS_RETURN_VAL(ops_type, TCORE_RETURN_EINVAL);
61 tcore_check_null_ret_err("po", po, TCORE_RETURN_EINVAL);
62 tcore_check_null_ret_err("ur", ur, TCORE_RETURN_EINVAL);
64 ops = po->ops[ops_type];
65 tcore_check_null_ret_err("ops", ops, TCORE_RETURN_FAILURE);
67 command = tcore_user_request_get_command(ur);
69 case TREQ_MODEM_POWER_ON:
70 tcore_check_null_ret_err("ops->power_on",
71 ops->power_on, TCORE_RETURN_ENOSYS);
73 return ops->power_on(o, ur);
75 case TREQ_MODEM_POWER_OFF:
76 tcore_check_null_ret_err("ops->power_off",
77 ops->power_off, TCORE_RETURN_ENOSYS);
79 return ops->power_off(o, ur);
81 case TREQ_MODEM_POWER_RESET:
82 tcore_check_null_ret_err("ops->power_reset",
83 ops->power_reset, TCORE_RETURN_ENOSYS);
85 return ops->power_reset(o, ur);
87 case TREQ_MODEM_POWER_LOW:
88 tcore_check_null_ret_err("ops->power_low",
89 ops->power_low, TCORE_RETURN_ENOSYS);
91 return ops->power_low(o, ur);
93 case TREQ_MODEM_SET_FLIGHTMODE:
94 tcore_check_null_ret_err("ops->set_flight_mode",
95 ops->set_flight_mode, TCORE_RETURN_ENOSYS);
97 return ops->set_flight_mode(o, ur);
99 case TREQ_MODEM_GET_IMEI:
100 tcore_check_null_ret_err("ops->get_imei",
101 ops->get_imei, TCORE_RETURN_ENOSYS);
103 return ops->get_imei(o, ur);
105 case TREQ_MODEM_GET_VERSION:
106 tcore_check_null_ret_err("ops->get_version",
107 ops->get_version, TCORE_RETURN_ENOSYS);
109 return ops->get_version(o, ur);
111 case TREQ_MODEM_GET_SN:
112 tcore_check_null_ret_err("ops->get_sn",
113 ops->get_sn, TCORE_RETURN_ENOSYS);
115 return ops->get_sn(o, ur);
117 case TREQ_MODEM_SET_DUN_PIN_CONTROL:
118 tcore_check_null_ret_err("ops->dun_pin_ctrl",
119 ops->dun_pin_ctrl, TCORE_RETURN_ENOSYS);
121 return ops->dun_pin_ctrl(o, ur);
123 case TREQ_MODEM_GET_FLIGHTMODE:
124 tcore_check_null_ret_err("ops->get_flight_mode",
125 ops->get_flight_mode, TCORE_RETURN_ENOSYS);
127 return ops->get_flight_mode(o, ur);
129 case TREQ_MODEM_GET_DEVICE_INFO:
130 tcore_check_null_ret_err("ops->get_device_info",
131 ops->get_device_info, TCORE_RETURN_ENOSYS);
133 return ops->get_device_info(o, ur);
136 return TCORE_RETURN_EINVAL;
139 return TCORE_RETURN_SUCCESS;
142 CoreObject *tcore_modem_new(TcorePlugin *p, const char *name,
143 struct tcore_modem_operations *ops, TcoreHal *hal)
145 CoreObject *o = NULL;
146 struct private_object_data *po = NULL;
151 o = tcore_object_new(p, name, hal);
155 po = calloc(1, sizeof(struct private_object_data));
157 tcore_object_free(o);
161 /* set ops to default type when core object is created. */
162 po->ops[TCORE_OPS_TYPE_CP] = ops;
164 tcore_object_set_type(o, CORE_OBJECT_TYPE_MODEM);
165 tcore_object_link_object(o, po);
166 tcore_object_set_free_hook(o, _free_hook);
167 tcore_object_set_dispatcher(o, _dispatcher);
172 void tcore_modem_free(CoreObject *o)
174 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_MODEM);
175 tcore_object_free(o);
178 void tcore_modem_set_ops(CoreObject *o, struct tcore_modem_operations *ops, enum tcore_ops_type ops_type)
180 struct private_object_data *po = NULL;
182 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_MODEM);
183 CORE_OBJECT_VALIDATE_OPS_RETURN(ops_type);
185 po = (struct private_object_data *)tcore_object_ref_object(o);
191 po->ops[ops_type] = ops;
194 TReturn tcore_modem_set_flight_mode_state(CoreObject *o, gboolean flag)
196 struct private_object_data *po = NULL;
198 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_MODEM, TCORE_RETURN_EINVAL);
200 po = tcore_object_ref_object(o);
202 return TCORE_RETURN_EINVAL;
204 po->flight_mode = flag;
206 return TCORE_RETURN_SUCCESS;
209 gboolean tcore_modem_get_flight_mode_state(CoreObject *o)
211 struct private_object_data *po = NULL;
213 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_MODEM, FALSE);
215 po = tcore_object_ref_object(o);
219 return po->flight_mode;
222 TReturn tcore_modem_set_powered(CoreObject *o, gboolean pwr)
226 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_MODEM, TCORE_RETURN_EINVAL);
228 h = tcore_object_get_hal(o);
230 return TCORE_RETURN_FAILURE;
232 tcore_hal_set_power_state(h, pwr);
234 return TCORE_RETURN_SUCCESS;
237 gboolean tcore_modem_get_powered(CoreObject *o)
241 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_MODEM, FALSE);
243 h = tcore_object_get_hal(o);
247 return tcore_hal_get_power_state(h);