Merge "Add the exception handling when using manual cert mode" into tizen_2.1
[platform/framework/native/net.git] / src / FNet_DnsEvent.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17 /**
18  * @file                FNet_DnsEvent.cpp
19  * @brief               This is the implementation file for the _DnsEvent Class.
20  *
21  * This file contains the implementation of the _DnsEvent Class.
22  */
23
24 #include <FNetNetTypes.h>
25 #include <FNetIDnsEventListener.h>
26 #include <FNetDns.h>
27 #include <FBaseSysLog.h>
28 #include "FNet_NetTypes.h"
29 #include "FNet_DnsEvent.h"
30 #include "FNet_DnsEventArg.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Runtime;
34
35 namespace Tizen { namespace Net
36 {
37
38 _DnsEvent::_DnsEvent(void)
39 {
40 }
41
42 _DnsEvent::~_DnsEvent(void)
43 {
44 }
45
46 result
47 _DnsEvent::Construct(void)
48 {
49         return _Event::Initialize();
50 }
51
52 void
53 _DnsEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
54 {
55         result r = E_SUCCESS;
56
57         IpHostEntry* pIpHostEntry = null;
58
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));
62
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));
67
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));
72
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));
77
78         pDnsEventListener->OnDnsResolutionCompletedN(pIpHostEntry, r);
79         
80         return;
81
82 CATCH:
83         //error scenario callback with null
84         pDnsEventListener->OnDnsResolutionCompletedN(null, r);
85
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();
89         delete pIpHostEntry;
90
91         return;
92 }
93
94 } } // Tizen::Net