Tizen 2.1 base
[platform/framework/web/wrt-plugins-common.git] / src / modules / tizen / Radio / Source.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  * @author        Zbigniew Kostrzewa <z.kostrzewa@samsung.com>
18  */
19
20 #include "Source.h"
21 #include <Commons/Exception.h>
22
23 namespace WrtDeviceApis {
24 namespace Radio {
25 bool Source::isConnected() const
26 {
27     return (m_serviceType.getInt() > VCONFKEY_TELEPHONY_SVCTYPE_SEARCH);
28 }
29
30 Api::SourceType Source::getType() const
31 {
32     Try {
33         switch (m_serviceType.getInt()) {
34         case VCONFKEY_TELEPHONY_SVCTYPE_2G:
35         case VCONFKEY_TELEPHONY_SVCTYPE_2_5G:
36         case VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE:
37             return Api::ST_GSM;
38         case VCONFKEY_TELEPHONY_SVCTYPE_3G:
39         case VCONFKEY_TELEPHONY_SVCTYPE_HSDPA:
40             return Api::ST_WCDMA;
41         default:
42             return Api::ST_UNKNOWN;
43         }
44     }
45     Catch(Commons::ConversionException) {
46         ReThrow(Commons::PlatformException);
47     }
48 }
49
50 void Source::addOnTypeChange(
51         const Api::EventSourceTypeChangeEmitterPtr& emitter)
52 {
53     m_onSourceTypeChange.attach(emitter);
54     SourceTypeChangeEmitters::LockType lock = m_onSourceTypeChange.getLock();
55     if (m_onSourceTypeChange.size() == 1) {
56         m_serviceType.attachCallback(onTypeChange, this);
57     }
58 }
59
60 void Source::removeOnTypeChange(
61         Api::EventSourceTypeChangeEmitter::IdType id)
62 {
63     m_onSourceTypeChange.detach(id);
64     SourceTypeChangeEmitters::LockType lock = m_onSourceTypeChange.getLock();
65     if (m_onSourceTypeChange.size() == 0) {
66         m_serviceType.detachCallback();
67     }
68 }
69
70 Source::Source() :
71     m_serviceType(VCONFKEY_TELEPHONY_SVCTYPE)
72 {
73 }
74
75 void Source::onTypeChange(const VConf::Node* /* node */,
76         void* data)
77 {
78     Source* this_ = static_cast<Source*>(data);
79     if (this_) {
80         Api::EventSourceTypeChangePtr event(
81             new Api::EventSourceTypeChange());
82         Try {
83             event->setType(this_->getType());
84         }
85         Catch(Commons::PlatformException) {
86             event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
87         }
88         this_->m_onSourceTypeChange.emit(event);
89     }
90 }
91 } // Radio
92 } // WrtDeviceApis