Merge "Add the exception handling when using manual cert mode" into tizen_2.1
[platform/framework/native/net.git] / src / FNet_LocalDhcpServerImpl.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_LocalDhcpServerImpl.h
19  * @brief               This is the header file for the LocalDhcpServerImpl class.
20  *
21  * This header file contains declaration of the  LocalDhcpServerImpl class.
22  */
23
24 #ifndef _FNET_INTERNAL_LOCAL_DHCP_SERVER_IMPL_H_
25 #define _FNET_INTERNAL_LOCAL_DHCP_SERVER_IMPL_H_
26
27 #include <tethering.h>
28 #include <wifi-direct.h>
29 #include <FBaseDataType.h>
30 #include <FBaseObject.h>
31 #include <FNetWifiIWifiDirectGroupOwnerListener.h>
32 #include "FNet_NetUtility.h"
33
34 namespace Tizen { namespace Base
35 {
36 class String;
37 } } // Tizen::Base
38
39 namespace Tizen { namespace Base { namespace Collection
40 {
41 class IList;
42 } } } // Tizen::Base::Collection
43
44 namespace Tizen { namespace Net { namespace Wifi
45 {
46 class WifiDirectDevice;
47 class WifiDirectDeviceInfo;
48 } } } // Tizen::Net::Wifi
49
50 namespace Tizen { namespace Net
51 {
52 class ILocalDhcpServerEventListener;
53 class NetConnection;
54 class DhcpClientInfo;
55 class LocalDhcpServer;
56 class _LocalDhcpServerEvent;
57 class _DhcpNetConnectionEventListenerImpl;
58
59 /**
60  * @class   _LocalDhcpServerImpl
61  * @brief       This class provides methods for managing local DHCP server.
62  * @since   2.0
63  *
64  * The LocalDhcpServer class provides methods for managing local DHCP server.
65  * The Wi-Fi Direct or USB NDIS required DHCP server for data communication.
66  */
67 class _LocalDhcpServerImpl
68         : public Tizen::Base::Object
69         , public Tizen::Net::Wifi::IWifiDirectGroupOwnerListener
70 {
71
72 public:
73         /**
74          * This is the constructor for this class.
75          *
76          */
77         _LocalDhcpServerImpl(void);
78
79         /**
80          * This is the destructor for this class.
81          *
82          */
83         virtual ~_LocalDhcpServerImpl(void);
84
85         /**
86          * @see                 LocalDhcpServer::Construct()
87          */
88         result Construct(const LocalDhcpServer* pLocalDhcpServer, const NetConnection& netConnection);
89
90 public:
91         /**
92          * @see                 LocalDhcpServer::GetLocalDhcpServer()
93          */
94         static LocalDhcpServer* GetLocalDhcpServer(const Tizen::Base::Collection::IList* pLocalDhcpServerList,
95                                                                                 const NetConnection& netConnection);
96
97         /**
98          * @see                 LocalDhcpServer::SetLocalDhcpServerEventListener()
99          */
100         result SetLocalDhcpServerEventListener(ILocalDhcpServerEventListener* pListener);
101
102         /**
103          * GetDhcpClientInfoListN(), all = true includes local server details, all = false is only connected peers
104          */
105         Tizen::Base::Collection::IList* GetDhcpClientInfoListN(bool all = true);
106
107 public:
108     /**
109      * Gets the Impl instance.
110      *
111      * @since 2.1
112      * @return              The pointer to _LocalDhcpServerImpl
113         * @param[in]   localDhcpServer            An instance of LocalDhcpServer
114      */
115         static _LocalDhcpServerImpl* GetInstance(LocalDhcpServer& localDhcpServer);
116
117     /**
118      * Gets the Impl instance.
119      *
120      * @since 2.1
121      * @return              The pointer to  _LocalDhcpServerImpl
122         * @param[in]   localDhcpServer     An instance of LocalDhcpServer
123      */
124         static const _LocalDhcpServerImpl* GetInstance(const LocalDhcpServer& localDhcpServer);
125
126 private:
127         
128         virtual void OnWifiDirectClientAssociated(Tizen::Net::Wifi::WifiDirectDeviceId localDeviceId, const Tizen::Net::Wifi::WifiDirectDeviceInfo& wifiDirectClientInfo);
129         virtual void OnWifiDirectClientDisassociated(Tizen::Net::Wifi::WifiDirectDeviceId localDeviceId, const Tizen::Net::Wifi::WifiDirectDeviceInfo& wifiDirectClientInfo, Tizen::Net::Wifi::WifiDirectAssociationTerminationReason reason);
130         virtual void OnWifiDirectGroupDestroyed(Tizen::Net::Wifi::WifiDirectDeviceId localDeviceId, result r);
131         virtual void OnWifiDirectGroupMemberInfoServiceStarted(Tizen::Net::Wifi::WifiDirectDeviceId localDeviceId, const NetConnection* pNetConnection, result r);
132         virtual void OnWifiDirectGroupMemberInfoServiceStopped(Tizen::Net::Wifi::WifiDirectDeviceId localDeviceId, result r);
133         
134 private:
135         
136         /*
137          * Callback received for wifi-direct connected peer devices
138          *
139          * @return            true to continue next loop, false to exit the loop
140          * @param[in]   pInfo                   The information of connected peer
141          * @param[in]   pUserData               The user data passed on callback registration
142          */
143         static bool OnWifiDirectPeerConnected(wifi_direct_connected_peer_info_s* pPeerInfo, void* pUserData);
144
145         /*
146          * Callback received for USB connected peer devices
147          *
148          * @param[in]   client                  The client of which connection is changed
149          * @param[in]   pUserData               The user data passed on callback registration
150          */
151         static bool OnUsbPeerConnected(tethering_client_h client, void* pUserdata);
152
153         /*
154          * Converts wifi_direct_connected_peer_info_s to DhcpClientInfo
155          */
156         static result ConvertDhcpClientInfo(const wifi_direct_connected_peer_info_s* pPeerInfo, DhcpClientInfo& dhcpClientInfo);
157
158         /*
159          *  Convert MAC address to formatted address
160          */
161         static Tizen::Base::String ConvertMacAddress(char* pMacAddress);
162
163         /*
164          * Gets Local dHCP server info
165          */
166         result GetLocalDhcpServerInfo(DhcpClientInfo& dhcpClientInfo);
167         
168         /*
169          * Get usb connected Client info
170          *
171          */
172         static result ConvertDhcpClientInfo(tethering_client_h clientHandle, DhcpClientInfo& dhcpClientInfo);
173
174         /*
175          * Converts WifiDirectDeviceInfo to DhcpClientInfo
176          *
177          */
178         result  ConvertDhcpClientInfo(const Tizen::Net::Wifi::WifiDirectDeviceInfo& wifiDirectdeviceInfo, DhcpClientInfo& dhcpClientInfo);
179         
180         /*
181          * Get peer info from local list based on mac-address
182          *
183          */
184         DhcpClientInfo* GetDhcpConnectedPeerInfo(const Tizen::Base::String& macAddress, bool remove = false);
185
186         /*
187          * Add connected peer info into local dhcp info list
188          */
189         result AddDhcpConnectedPeerInfo(const DhcpClientInfo& dhcpClientInfo);
190
191         /*
192          * Set connected peer local dhcp info list
193          */     
194         void SetDhcpConnectedPeerInfoList(Tizen::Base::Collection::IList* pList);
195
196         /*
197          * Get connected peer local dhcp info list
198          */
199         Tizen::Base::Collection::IList* GetDhcpConnectedPeerInfoList();
200         
201 private:
202         /*
203          * This is the copy constructor for this class. @n
204          * Do @b not use directly.
205          *
206          * @param[in]   rhs                     An instance of _LocalDhcpServerImpl
207          */
208         _LocalDhcpServerImpl(const _LocalDhcpServerImpl& rhs);
209
210         /*
211          * This is the assignment operator. Do @b not use directly.
212          *
213          * @param[in]   rhs             An instance of _LocalDhcpServerImpl
214          */
215         _LocalDhcpServerImpl& operator =(const _LocalDhcpServerImpl& rhs);
216
217 private:
218         std::unique_ptr<_LocalDhcpServerEvent> __pLocalDhcpServerEvent;         // event pointer
219         NetConnection* __pNetConnection;                        // refernce, no ownership
220         std::unique_ptr<NetConnection> __pNetConnectionClone;                   // cloned net connection, for events
221         std::unique_ptr<_DhcpNetConnectionEventListenerImpl> __pNetConnectionListener; // Net Conncetion event Listener
222         tethering_h     __pUsbTetheringHandle;             // access point handle
223         std::unique_ptr<Tizen::Base::Collection::ArrayList, _CollectionDeleter> __pDhcpConnectedPeerInfoList;      // list of connected peer info
224         Tizen::Net::Wifi::WifiDirectDevice* __pDevice;
225         void* __pDllHandle;
226         bool __isConstructed;                       // status
227         bool __isConnectedNetwork;
228
229         friend class _DhcpNetConnectionEventListenerImpl;
230 }; // _LocalDhcpServerImpl
231
232 }} // Tizen::Net
233
234 #endif // _FNET_INTERNAL_LOCAL_DHCP_SERVER_IMPL_H_