tizen beta release
[framework/web/wrt-installer.git] / src / security / 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/fast_delegate.h>
28 #include <dpl/log/log.h>
29 #include <dpl/singleton_impl.h>
30 IMPLEMENT_SINGLETON(SimpleRoamingAgent)
31
32 SimpleRoamingAgent::SimpleRoamingAgent()
33 {
34     if (vconf_notify_key_changed(
35             VCONFKEY_TELEPHONY_SVC_ROAM,
36             vConfChagedCallback, this) < 0)
37     {
38         LogError("Cannot add vconf callback [" <<
39                  VCONFKEY_TELEPHONY_SVC_ROAM << "]");
40         Assert(false && "Cannot add vconf callback");
41     }
42
43     int result = 0;
44     if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &result) != 0) {
45         LogError("Cannot get current roaming status");
46         Assert(false && "Cannot get current roaming status");
47     } else {
48         bool type = (result == VCONFKEY_TELEPHONY_SVC_ROAM_ON);
49         m_networkType = type ? ROAMING : HOME;
50         LogInfo("Network type is " << (type ? "ROAMING" : "HOME"));
51     }
52
53 }
54
55 SimpleRoamingAgent::~SimpleRoamingAgent()
56 {
57     if (vconf_ignore_key_changed(
58             VCONFKEY_TELEPHONY_SVC_ROAM,
59             vConfChagedCallback) < 0)
60     {
61         LogError("Cannot rm vconf callback [" <<
62                  VCONFKEY_TELEPHONY_SVC_ROAM << "]");
63         Assert(false && "Cannot remove vconf callback");
64     }
65
66 }
67
68 void SimpleRoamingAgent::vConfChagedCallback(keynode_t *keyNode, void *data)
69 {
70     LogInfo("SimpleRoamingAgent::vConfChagedCallback ");
71     char *key = vconf_keynode_get_name(keyNode);
72
73     if (NULL == key) {
74         LogWarning("vconf key is null.");
75         return;
76     }
77     SimpleRoamingAgent *agent = static_cast<SimpleRoamingAgent *>(data);
78     if (NULL == agent) {
79         LogError("Bad user arg from vconf lib");
80         Assert(false && "Bad user arg from vconf lib");
81         return;
82     }
83     int result = 0;
84     if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &result) != 0) {
85         LogError("Cannot get current roaming status");
86         Assert(false && "Cannot get current roaming status");
87     } else {
88         bool type = (result == VCONFKEY_TELEPHONY_SVC_ROAM_ON);
89         agent->m_networkType = type ? ROAMING : HOME;
90         LogInfo("Network type is " << (type ? "ROAMING" : "HOME"));
91     }
92 }