Fixed issue(DCM-1110)
[platform/framework/native/net.git] / src / FNet_SystemNetConnection.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_SystemNetConnection.h
19  * @brief       This is the header file for the %_SystemNetConnection class.
20  *
21  * This header file contains the declarations of the %_SystemNetConnection class.
22  */
23
24 #ifndef _FNET_INTERNAL_SYSTEM_NET_CONNECTION_H_
25 #define _FNET_INTERNAL_SYSTEM_NET_CONNECTION_H_
26
27 #include <unique_ptr.h>
28 #include <FBaseDataType.h>
29 #include <FBaseObject.h>
30 #include <FBaseString.h>
31 #include <FNetNetTypes.h>
32
33 namespace Tizen { namespace Base { namespace Collection
34 {
35 class ArrayList;
36 class HashMap;
37 } } } // Tizen::Base::Collection
38
39 namespace Tizen { namespace Base { namespace Runtime
40 {
41 class Mutex;
42 } } } // Tizen::Base::Runtime
43
44 namespace Tizen { namespace Net
45 {
46 class NetConnectionInfo;
47 class _NetConnectionEvent;
48 class _NetConnectionInfoImpl;
49 class _DefaultSystemNetConnection;
50 class _WifiSystemNetConnection;
51 class _WifiDirectSystemNetConnection;
52 class _UsbSystemNetConnection;
53
54 /**
55  * @class       _SystemNetConnection
56  * @brief       This class provides methods for a system network connection.
57  *
58  * @since 2.1
59  *
60  * This class provides methods for a system network connection.
61  */
62 class _SystemNetConnection
63         : public Tizen::Base::Object
64 {
65 public:
66         /**
67          *      Adds an event.
68          *
69          * @since 2.1
70          *      @param[in]      event                   A reference to _NetConnectionEvent
71          *      @return                 An error code
72          *      @exception      E_SUCCESS                               The method was successful.
73          *      @exception      E_INVALID_STATE         This instance has not been constructed as yet or it may be closed.
74          */
75         result AddEvent(_NetConnectionEvent& event);
76
77         /**
78          *      Removes an event.
79          *
80          *      @since 2.1
81          *      @param[in]      event                   A reference to _NetConnectionEvent
82          *      @return                 An error code
83          *      @exception      E_SUCCESS                               The method was successful.
84          *      @exception      E_INVALID_STATE         This instance has not been constructed as yet or it may be closed.
85          * @exception   E_OBJ_NOT_FOUND The EventListener was not found.
86          */
87         result RemoveEvent(_NetConnectionEvent& event);
88
89         /**
90          * Starts the network connection.
91          *
92          * @since 2.1
93          *
94          * @return                      An error code
95          * @exception   E_SUCCESS                               The method was successful.
96          * @exception   E_INVALID_STATE         This instance is in an invalid state.
97          * @exception   E_SYSTEM                                        An internal error occurred.
98          * @see                 Stop()
99          */
100         virtual result Start(_NetConnectionEvent& event);
101
102         /**
103          * Stops the network connection.
104          *
105          * @since 2.1
106          *
107          * @return                      An error code
108          * @exception   E_SUCCESS                               The method was successful.
109          * @exception   E_INVALID_STATE         This instance is in an invalid state.
110          * @exception   E_SYSTEM                                        An internal error occurred.
111          * @see                 Start()
112          */
113         virtual result Stop(_NetConnectionEvent& event, bool waitingEvent = true);
114
115         virtual void HandleStartResponse(result error, void* pData);
116         virtual void HandleStopResponse(void);
117         virtual void HandleStartEvent(void);
118         virtual void HandleStopEvent(result error);
119
120         virtual NetConnectionState QueryConnectionState(Tizen::Base::String& devName) const;
121
122         NetBearerType GetBearerType(void) const;
123         NetConnectionState GetConnectionState(void) const;
124         Tizen::Base::String GetProxyAddress(void) const;
125
126         void GetConnectionInfo(NetConnectionInfo& netConnectionInfo);
127
128 public:
129         static void InitializeNetworkFramework(void);
130
131         static _SystemNetConnection* GetPsInstance(NetAccountId netAccountId);
132         static _SystemNetConnection* GetDefaultInstance(void);
133         static _SystemNetConnection* GetWifiInstance(void);
134         static _SystemNetConnection* GetWifiDirectInstance(void);
135         static _SystemNetConnection* GetUsbInstance(void);
136
137 //      static result ConvertError(int ret);
138
139 protected:
140         /**
141          * This is the default constructor for this class.
142          */
143         _SystemNetConnection(void);
144
145         /**
146          * This is the destructor for this class.
147          */
148         virtual ~_SystemNetConnection(void);
149
150         result Initialize(const Tizen::Base::String& name);
151         void Deinitialize(void);
152
153 private:
154         static void InitializeNetworkFrameworkOnce(void);
155
156         /**
157          * This is the copy constructor for this class.
158          *
159          * @param[in]   rhs                     An instance of _SystemNetConnection
160          */
161         _SystemNetConnection(const _SystemNetConnection& rhs);
162
163         /**
164          * This is the assignment operator. Do @b not use directly.
165          *
166          * @param[in]   rhs                             An instance of _SystemNetConnection
167          */
168         _SystemNetConnection& operator =(const _SystemNetConnection& rhs);
169
170 protected:
171         NetBearerType _bearerType;
172         NetConnectionState _connectionState;
173         Tizen::Base::String _name;
174         std::unique_ptr<_NetConnectionInfoImpl> _pConnectionInfo;
175         std::unique_ptr<Tizen::Base::Collection::ArrayList> _pEventList; // Don't use collector deleter because this list doesn't take entries ownership.
176         std::unique_ptr<Tizen::Base::Runtime::Mutex> _pLock;
177         int _refCount;
178
179 private:
180         static bool __isInitialized;
181         static Tizen::Base::Collection::HashMap* __pPsSystemConnectionMap;
182         static _DefaultSystemNetConnection* __pDefaultConnection;
183         static _WifiSystemNetConnection* __pWifiConnection;
184         static _WifiDirectSystemNetConnection* __pWifiDirectConnection;
185         static _UsbSystemNetConnection* __pUsbConnection;
186
187 }; // _SystemNetConnection
188
189 } }  // Tizen::Net
190 #endif // _FNET_INTERNAL_SYSTEM_NET_CONNECTION_H_
191