4 * Copyright (c) 2000 - 2013 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.
24 * @desc Roaming persistent object. Due roaming changes not so often we can keep it in
25 * our memory and handle roaming changes.
26 * In this file we keep roaming state in global variable and change it in callback.
30 #include <telephony_network.h>
36 static resourced_roaming_type roaming_state;
38 /* for avoiding dependency in this file */
40 static GSList *roaming_callbacks;
42 static void invoke_roaming_callbacks(void)
44 GSList *func_iter = NULL;
45 gslist_for_each_item(func_iter, roaming_callbacks) {
46 if (func_iter && func_iter->data)
47 ((roaming_cb)func_iter->data)();
51 void regist_roaming_cb(roaming_cb cb)
53 roaming_callbacks = g_slist_prepend(roaming_callbacks, cb);
56 static void on_roaming_change(bool new_roaming,
57 void UNUSED *user_data)
59 _D("Roaming is changed %d", (int)new_roaming);
60 roaming_state = new_roaming ? RESOURCED_ROAMING_ENABLE : RESOURCED_ROAMING_DISABLE;
61 invoke_roaming_callbacks();
65 * @brief Get initial value for roaming and sets callback for handling roaming change
67 static void init_roaming_state(void)
71 if (network_info_set_roaming_state_changed_cb(on_roaming_change,
72 NULL) != NETWORK_INFO_ERROR_NONE)
73 _E("Can not register callback for handle roaming changes.");
75 if (network_info_is_roaming(&roaming) != NETWORK_INFO_ERROR_NONE)
76 _E("Failed to get initial roaming state!");
78 roaming_state = roaming ?
79 RESOURCED_ROAMING_ENABLE : RESOURCED_ROAMING_DISABLE;
82 resourced_roaming_type get_roaming(void)