tizen 2.3 release
[framework/web/wearable/wrt-security.git] / src / services / ace / logic / simple_roaming_agent.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file    simple_roaming_agent.cpp
18  * @author  Pawel Sikorski (p.sikorski@samsung.com)
19  * @author  Lukasz Marek (l.marek@samsung.com)
20  * @author  Lukasz Wrzosek (l.wrzosek@samsung.com)
21  * @version 1.0
22  * @brief   roaming agent
23  */
24
25 #include "simple_roaming_agent.h"
26 #include <vconf.h>
27 #include <dpl/log/log.h>
28 #include <dpl/singleton_impl.h>
29 IMPLEMENT_SINGLETON(SimpleRoamingAgent)
30
31 SimpleRoamingAgent::SimpleRoamingAgent()
32 {
33     if (vconf_notify_key_changed(
34             VCONFKEY_TELEPHONY_SVC_ROAM,
35             vConfChagedCallback, this) < 0)
36     {
37         LogError("Cannot add vconf callback [" <<
38                  VCONFKEY_TELEPHONY_SVC_ROAM << "]");
39         Assert(false && "Cannot add vconf callback");
40     }
41
42     int result = 0;
43     if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &result) != 0) {
44         LogError("Cannot get current roaming status");
45         Assert(false && "Cannot get current roaming status");
46     } else {
47         bool type = (result == VCONFKEY_TELEPHONY_SVC_ROAM_ON);
48         m_networkType = type ? ROAMING : HOME;
49         LogInfo("Network type is " << (type ? "ROAMING" : "HOME"));
50     }
51
52 }
53
54 SimpleRoamingAgent::~SimpleRoamingAgent()
55 {
56     if (vconf_ignore_key_changed(
57             VCONFKEY_TELEPHONY_SVC_ROAM,
58             vConfChagedCallback) < 0)
59     {
60         LogError("Cannot rm vconf callback [" <<
61                  VCONFKEY_TELEPHONY_SVC_ROAM << "]");
62         //Assert(false && "Cannot remove vconf callback");
63     }
64
65 }
66
67 void SimpleRoamingAgent::vConfChagedCallback(keynode_t *keyNode, void *data)
68 {
69     LogInfo("SimpleRoamingAgent::vConfChagedCallback ");
70     char *key = vconf_keynode_get_name(keyNode);
71
72     if (NULL == key) {
73         LogWarning("vconf key is null.");
74         return;
75     }
76     std::string keyString = key;
77     if (VCONFKEY_TELEPHONY_SVC_ROAM != keyString) {
78         LogError("Wrong key found");
79         Assert(false && "Wrong key found in vconf callback");
80         return;
81     }
82     SimpleRoamingAgent *agent = static_cast<SimpleRoamingAgent *>(data);
83     if (NULL == agent) {
84         LogError("Bad user arg from vconf lib");
85         Assert(false && "Bad user arg from vconf lib");
86         return;
87     }
88     int result = 0;
89     if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &result) != 0) {
90         LogError("Cannot get current roaming status");
91         Assert(false && "Cannot get current roaming status");
92     } else {
93         bool type = (result == VCONFKEY_TELEPHONY_SVC_ROAM_ON);
94         agent->m_networkType = type ? ROAMING : HOME;
95         LogInfo("Network type is " << (type ? "ROAMING" : "HOME"));
96     }
97 }