Merge "Add the exception handling when using manual cert mode" into tizen_2.1
[platform/framework/native/net.git] / src / FNet_DnsManagedNetConnectionEventListener.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_FNet_DnsManagedNetConnectionEventListener.cpp
19  * @brief       This is the implementation file for _DnsManagedNetConnectionEventListener class.
20  * @version     3.0
21  *
22  * This file contains the implementation of _DnsManagedNetConnectionEventListener class.
23  */
24
25 #include <unique_ptr.h>
26 #include <FBaseObject.h>
27 #include <FBaseResult.h>
28 #include <FBaseString.h>
29 #include <FNetManagedNetConnection.h>
30 #include <FBaseSysLog.h>
31 #include "FNet_NetTypes.h"
32 #include "FNet_DnsRequestHandler.h"
33 #include "FNet_DnsManagedNetConnectionEventListener.h"
34
35 using namespace std;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38
39 namespace Tizen { namespace Net
40 {
41
42 //DnsManagedNetConnectionEventListener -listener for network connection events.
43
44 _DnsManagedNetConnectionEventListener::_DnsManagedNetConnectionEventListener(ArrayList* pDnsRequestHandlerList)
45         :__pDnsRequestHandlerList(pDnsRequestHandlerList)
46         ,__isConnected(false)
47 {
48 }
49
50 _DnsManagedNetConnectionEventListener::~_DnsManagedNetConnectionEventListener(void)
51 {
52 }
53
54 void
55 _DnsManagedNetConnectionEventListener::OnManagedNetConnectionBearerChanged(ManagedNetConnection& managedNetConnection)
56 {
57         SysLog(NID_NET, "DnsManagedNetConnectionEventListener received an event, OnManagedNetConnectionBearerChanged.");
58 }
59
60 void
61 _DnsManagedNetConnectionEventListener::OnManagedNetConnectionStarted(ManagedNetConnection& managedNetConnection)
62 {
63         SysLog(NID_NET, "DnsManagedNetConnectionEventListener received an event, OnManagedNetConnectionStarted.");
64         result r = E_SUCCESS;
65
66         __isConnected = true;
67
68         unique_ptr<IEnumerator> pEnumerator(__pDnsRequestHandlerList->GetEnumeratorN());
69         SysTryReturnVoidResult(NID_NET, pEnumerator != null, E_SYSTEM,
70                         "[%s] A system error occurred. Failed to get enumerator from DnsRequestHandlerList.", GetErrorMessage(E_SYSTEM));
71
72         while (pEnumerator->MoveNext() == E_SUCCESS)
73         {
74                 _DnsRequestHandler* pDnsRequestHandler = null;
75                 pDnsRequestHandler = dynamic_cast<_DnsRequestHandler*>(pEnumerator->GetCurrent());
76                 SysTryReturnVoidResult(NID_NET, pDnsRequestHandler != null, E_SYSTEM,
77                                 "[%s] A system error occurred. Failed to cast DnsRequestHandler dynamically.", GetErrorMessage(E_SYSTEM));
78                 
79                 // start processing request
80                 if (!pDnsRequestHandler->IsRequestStarted())
81                 {
82                         r = pDnsRequestHandler->Start();
83                         SysTryReturnVoidResult(NID_NET, r ==  E_SUCCESS, E_SYSTEM,
84                                         "[%s] A system error occurred. Failed to start DnsRequestHandler.", GetErrorMessage(E_SYSTEM));
85                 }
86         }
87 }
88
89 void
90 _DnsManagedNetConnectionEventListener::OnManagedNetConnectionStopped(ManagedNetConnection& managedNetConnection,
91                 NetConnectionStoppedReason reason)
92 {
93         SysLog(NID_NET, "DnsManagedNetConnectionEventListener received an event, OnManagedNetConnectionStopped.");
94         result r = E_SUCCESS;
95
96         __isConnected = false;
97
98         unique_ptr<IEnumerator> pEnumerator(__pDnsRequestHandlerList->GetEnumeratorN());
99         SysTryReturnVoidResult(NID_NET, pEnumerator != null, E_SYSTEM,
100                         "[%s] A system error occurred. Failed to get enumerator from DnsRequestHandlerList.", GetErrorMessage(E_SYSTEM));
101
102         while (pEnumerator->MoveNext() == E_SUCCESS)
103         {
104                 _DnsRequestHandler* pDnsRequestHandler = null;
105                 pDnsRequestHandler = dynamic_cast<_DnsRequestHandler*>(pEnumerator->GetCurrent());
106                 SysTryCatch(NID_NET, pDnsRequestHandler != null, r = E_SYSTEM, r,
107                                 "[%s] A system error occurred. Failed to cast DnsRequestHandler dynamically.", GetErrorMessage(E_SYSTEM));
108         
109                 // start processing request
110                 if (!pDnsRequestHandler->IsRequestStarted())
111                 {
112                         // call event for operation failed
113                         r = pDnsRequestHandler->FireNetworkStoppedEvent();
114                         SysTryCatch(NID_NET, r != E_SUCCESS, r = E_SYSTEM, r,
115                                         "[%s] A system error occurred. Failed to fire NetWorkStoppedEvent.", GetErrorMessage(E_SYSTEM));
116                 }                                       
117         }
118
119         // Fall through
120         
121 CATCH:
122         // Operation is complete, cleanup list
123         __pDnsRequestHandlerList->RemoveAll(true);
124 }
125
126 void
127 _DnsManagedNetConnectionEventListener::OnManagedNetConnectionSuspended(ManagedNetConnection& managedNetConnection)
128 {
129         SysLog(NID_NET, "DnsManagedNetConnectionEventListener received an event, OnManagedNetConnectionSuspended.");
130 }
131
132 void
133 _DnsManagedNetConnectionEventListener::OnManagedNetConnectionResumed(ManagedNetConnection& managedNetConnection)
134 {
135         SysLog(NID_NET, "DnsManagedNetConnectionEventListener received an event, OnManagedNetConnectionResumed.");
136 }
137
138 } } // Tizen::Net
139