Initialize Tizen 2.3
[framework/osp/net.git] / src / FNet_DnsRequestHandler.h
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_DnsRequestHandler.h
19  * @brief               This is the header file for the _DnsRequestHandler Class.
20  *
21  * This header file contains declaration of the _DnsRequestHandler Class.
22  */
23 #ifndef _FNET_INTERNAL_DNS_REQUEST_HANDLER_H_
24 #define _FNET_INTERNAL_DNS_REQUEST_HANDLER_H_
25
26 #include <unique_ptr.h>
27 #include <FBaseDataType.h>
28 #include <FBaseObject.h>
29 #include <FBaseRtThread.h>
30 #include "FNet_DnsEventArg.h"
31
32 namespace Tizen { namespace Net
33 {
34
35 class _DnsRequest;
36 class _IpHostEntryImpl;
37 class _DnsEvent;
38
39 class _DnsRequestHandler
40         : public Tizen::Base::Object
41         , public Tizen::Base::Runtime::IRunnable
42 {
43
44 public:
45         /*
46          * Constructor
47          * @param[in]   pDnsRequest     _DnsRequest
48          */
49         _DnsRequestHandler(_DnsRequest* pDnsRequest);
50
51         /*
52          * Destructor
53          */
54         ~_DnsRequestHandler();
55
56         /*
57          * Two-Phase Constructor
58          */
59         result Construct();
60
61         /*
62          * Rnn() - Runnable implementation
63          */
64         Object* Run();
65
66         /*
67          * Start the Event Handler
68          * @return  A result code.
69          */
70         result Start();
71
72         /*
73          * Check the DNS request operation state
74          */
75         bool IsRequestStarted();
76
77         /*
78          * Fire network stopped  event
79          */
80         result FireNetworkStoppedEvent();
81
82 public:
83         /*
84          * DNS Callback
85          *
86          * @since 2.1
87          * @param[in]   pHostent                        A pointer to struct hostent
88          * @param[in]   dnsId                           ID of DNS call
89          * @param[in]   dnsEvent                        DNS Event
90          * @return                                      An error code
91          */
92         static result DnsCallBack(struct hostent* pHostent, int dnsId, _DnsEvent& dnsEvent);
93
94         /*
95          * SetAddressList
96          *
97          * @since 2.1
98          * @param[in]   pHostent                        A pointer to struct hostent
99          * @param[in]   ipHostEntryImpl                 A reference to _IpHostEntryImpl
100          * @return                                      An error code
101          */
102         static result SetAddressList(const struct hostent* pHostent, _IpHostEntryImpl& ipHostEntryImpl);
103
104         /*
105          * SetAliasList
106          *
107          * @since 2.1
108          * @param[in]   pHostent                        A pointer to struct hostent
109          * @param[in]   ipHostEntryImpl                 A reference to _IpHostEntryImpl
110          * @return                                      An error code
111          */
112         static result SetAliasList(const struct hostent* pHostent, _IpHostEntryImpl& ipHostEntryImpl);
113
114 private:
115         /*
116          *
117          * Default ctor
118          */     
119         _DnsRequestHandler(void);
120
121         /*
122          * This is the copy constructor for this class. @n
123          * Do @b not use directly.
124          *
125          */
126         _DnsRequestHandler(const _DnsRequestHandler& rhs);
127
128         /*
129          * This is the assignment operator for this class. @n
130          * Do @b not use directly.
131          *
132          */
133         _DnsRequestHandler& operator =(const _DnsRequestHandler& rhs);
134
135 private:
136         std::unique_ptr<_DnsRequest> __pDnsRequest; // Request, Own
137         std::unique_ptr<Tizen::Base::Runtime::Thread> __pThread;      // Thread to process request
138         bool __isStarted; // state of dns operation, started.
139 };//_DnsRequestHandler
140
141 /**
142 * @class _DnsRequest
143 * @brief _DnsRequest contains the event details to be processed by _DnsRequestHandler
144 * @since 2.1
145 */
146
147 class _DnsRequest
148         : public Tizen::Base::Object
149 {
150 public:
151         /*
152          * Constructor
153          * @param[in]   type            Event-type
154          * @param[in]   pMsg            Message Data
155          * @param[in]   event           _DnsEvent
156          */
157         _DnsRequest(_NetDnsEventType msgType, char* pMsgData, _DnsEvent& event);
158
159         /*
160          * Destructor
161          */
162         ~_DnsRequest();
163
164         /*
165          * Execute() - Process the message
166          */
167         void Execute();
168
169         /*
170          * Get the _DnsEvent object
171          */
172         _DnsEvent& GetDnsEvent();
173
174 private:
175         /*
176          *
177          * Default ctor
178          */     
179         _DnsRequest(void);
180
181         /*
182          * This is the copy constructor for this class. @n
183          * Do @b not use directly.
184          *
185          */
186         _DnsRequest(const _DnsRequest& rhs);
187
188         /*
189          * This is the assignment operator for this class. @n
190          * Do @b not use directly.
191          *
192          */
193         _DnsRequest& operator =(const _DnsRequest& rhs);
194
195 //Attributes
196 private:
197         _NetDnsEventType __msgType;  //event type
198         std::unique_ptr<char[]> __pMsgData; // event data, Owned
199         _DnsEvent& __dnsEvent;     // Event, has listener reference for callback.
200 };//_DnsRequest
201
202 } } //Tizen::Net
203
204 #endif // _FNET_INTERNAL_DNS_REQUEST_HANDLER_H_