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.
29 #include "user_request.h"
33 struct private_object_data {
34 struct tcore_modem_operations *ops;
40 static void _free_hook(CoreObject *o)
42 struct private_object_data *po = NULL;
44 po = tcore_object_ref_object(o);
47 tcore_object_link_object(o, NULL);
51 static void _clone_hook(CoreObject *src, CoreObject *dest)
53 struct private_object_data *src_po = NULL;
54 struct private_object_data *dest_po = NULL;
59 dest_po = calloc(sizeof(struct private_object_data), 1);
61 tcore_object_link_object(dest, NULL);
65 src_po = tcore_object_ref_object(src);
66 dest_po->ops = src_po->ops;
68 tcore_object_link_object(dest, dest_po);
71 static TReturn _dispatcher(CoreObject *o, UserRequest *ur)
73 enum tcore_request_command command;
74 struct private_object_data *po = NULL;
76 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_MODEM, TCORE_RETURN_EINVAL);
78 po = tcore_object_ref_object(o);
80 return TCORE_RETURN_ENOSYS;
82 command = tcore_user_request_get_command(ur);
84 case TREQ_MODEM_POWER_ON:
85 if (!po->ops->power_on)
86 return TCORE_RETURN_ENOSYS;
88 return po->ops->power_on(o, ur);
91 case TREQ_MODEM_POWER_OFF:
92 if (!po->ops->power_off)
93 return TCORE_RETURN_ENOSYS;
95 return po->ops->power_off(o, ur);
98 case TREQ_MODEM_POWER_RESET:
99 if (!po->ops->power_reset)
100 return TCORE_RETURN_ENOSYS;
102 return po->ops->power_reset(o, ur);
105 case TREQ_MODEM_SET_FLIGHTMODE:
106 if (!po->ops->set_flight_mode)
107 return TCORE_RETURN_ENOSYS;
109 return po->ops->set_flight_mode(o, ur);
112 case TREQ_MODEM_GET_IMEI:
113 if (!po->ops->get_imei)
114 return TCORE_RETURN_ENOSYS;
116 return po->ops->get_imei(o, ur);
119 case TREQ_MODEM_GET_VERSION:
120 if (!po->ops->get_version)
121 return TCORE_RETURN_ENOSYS;
123 return po->ops->get_version(o, ur);
126 case TREQ_MODEM_GET_SN:
127 if (!po->ops->get_sn)
128 return TCORE_RETURN_ENOSYS;
130 return po->ops->get_sn(o, ur);
133 case TREQ_MODEM_SET_DUN_PIN_CONTROL:
134 if (!po->ops->dun_pin_ctrl)
135 return TCORE_RETURN_ENOSYS;
137 return po->ops->dun_pin_ctrl(o, ur);
141 return TCORE_RETURN_EINVAL;
144 return TCORE_RETURN_SUCCESS;
147 CoreObject *tcore_modem_new(TcorePlugin *p, const char *name,
148 struct tcore_modem_operations *ops, TcoreHal *hal)
150 CoreObject *o = NULL;
151 struct private_object_data *po = NULL;
156 o = tcore_object_new(p, name, hal);
160 po = calloc(sizeof(struct private_object_data), 1);
162 tcore_object_free(o);
168 tcore_object_set_type(o, CORE_OBJECT_TYPE_MODEM);
169 tcore_object_link_object(o, po);
170 tcore_object_set_free_hook(o, _free_hook);
171 tcore_object_set_clone_hook(o, _clone_hook);
172 tcore_object_set_dispatcher(o, _dispatcher);
177 void tcore_modem_free(CoreObject *o)
179 struct private_object_data *po = NULL;
181 CORE_OBJECT_CHECK(o, CORE_OBJECT_TYPE_MODEM);
183 po = tcore_object_ref_object(o);
188 tcore_object_free(o);
191 TReturn tcore_modem_set_flight_mode_state(CoreObject *o, gboolean flag)
193 struct private_object_data *po = NULL;
195 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_MODEM, TCORE_RETURN_EINVAL);
197 po = tcore_object_ref_object(o);
199 return TCORE_RETURN_EINVAL;
201 po->flight_mode = flag;
206 gboolean tcore_modem_get_flight_mode_state(CoreObject *o)
208 struct private_object_data *po = NULL;
210 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_MODEM, FALSE);
212 po = tcore_object_ref_object(o);
216 return po->flight_mode;
219 TReturn tcore_modem_set_powered(CoreObject *o, gboolean pwr)
223 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_MODEM, TCORE_RETURN_EINVAL);
225 h = tcore_object_get_hal(o);
227 return TCORE_RETURN_FAILURE;
229 tcore_hal_set_power_state(h, pwr);
234 gboolean tcore_modem_get_powered(CoreObject *o)
238 CORE_OBJECT_CHECK_RETURN(o, CORE_OBJECT_TYPE_MODEM, FALSE);
240 h = tcore_object_get_hal(o);
244 return tcore_hal_get_power_state(h);