2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FNet_DnsEvent.cpp
19 * @brief This is the implementation file for the _DnsEvent Class.
21 * This file contains the implementation of the _DnsEvent Class.
24 #include <FNetNetTypes.h>
25 #include <FNetIDnsEventListener.h>
27 #include <FBaseSysLog.h>
28 #include "FNet_NetTypes.h"
29 #include "FNet_DnsEvent.h"
30 #include "FNet_DnsEventArg.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Runtime;
35 namespace Tizen { namespace Net
38 _DnsEvent::_DnsEvent(void)
42 _DnsEvent::~_DnsEvent(void)
47 _DnsEvent::Construct(void)
49 return _Event::Initialize();
53 _DnsEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
57 IpHostEntry* pIpHostEntry = null;
59 IDnsEventListener* pDnsEventListener = dynamic_cast <IDnsEventListener*>(&listener);
60 SysTryReturnVoidResult(NID_NET, pDnsEventListener != null, E_SYSTEM,
61 "[%s] A system error has been occurred. Listener argument is invalid.", GetErrorMessage(E_SYSTEM));
63 IEventArg* pEventArg = const_cast <IEventArg*>(&arg);
64 _DnsEventArg* pDnsEventArg = dynamic_cast <_DnsEventArg*>(pEventArg);
65 SysTryReturnVoidResult(NID_NET, pDnsEventArg != null, E_SYSTEM,
66 "[%s] A system error has been occurred. Event argument is invalid type.", GetErrorMessage(E_SYSTEM));
68 // check if DNS resolved successfully
69 r = pDnsEventArg->GetError();
70 SysTryCatch(NID_NET, r == E_SUCCESS, r = E_DNS_NOT_FOUND, r,
71 "[%s] Failed to lookup the DNS.", GetErrorMessage(E_DNS_NOT_FOUND));
73 // No error in DNS resolution
74 pIpHostEntry = pDnsEventArg->GetIpHostEntry();
75 SysTryCatch(NID_NET, pIpHostEntry != null, r = E_SYSTEM, r,
76 "[%s] A system error has been occurred. Event argument is invalid type.", GetErrorMessage(E_SYSTEM));
78 pDnsEventListener->OnDnsResolutionCompletedN(pIpHostEntry, r);
83 //error scenario callback with null
84 pDnsEventListener->OnDnsResolutionCompletedN(null, r);
86 // incase, we have reached here with pIpHostEntry not null, need to free pIpHostEntry
87 // pIpHostEntry can get deleted at the user end, but have to delete if not sent there
88 pIpHostEntry = pDnsEventArg->GetIpHostEntry();