Merge "Add the exception handling when using manual cert mode" into tizen_2.1
[platform/framework/native/net.git] / src / FNet_NetConnectionEvent.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_NetConnectionEvent.h
19  * @brief                       This is the header file for _NetConnectionEvent class.
20  * @version                     3.0
21  *
22  * This header file contains the declarations of _NetConnectionEvent class.
23  * The _NetConnectionEvent class can call listener's method. So, when an event is occurred,
24  * application can handle it appropriately.
25  */
26
27 #ifndef _FNET_INTERNAL_NET_CONNECTION_EVENT_H_
28 #define _FNET_INTERNAL_NET_CONNECTION_EVENT_H_
29
30 #include <FBaseDataType.h>
31 #include <FBaseColIHashCodeProviderT.h>
32 #include <FBaseColIComparerT.h>
33 #include <FNetNetTypes.h>
34 #include <FBaseRt_Event.h>
35 #include "FNet_NetTypes.h"
36
37 namespace Tizen { namespace Base
38 {
39 class Object;
40 } } // Tizen::Base
41
42 namespace Tizen { namespace Base { namespace Runtime
43 {
44 class IEventListener;
45 class IEventArg;
46 } } } // Tizen::Base::Runtime
47
48 namespace Tizen { namespace Net
49 {
50 class _SystemNetConnection;
51
52 enum _NetConnectionEventType
53 {
54         _NET_CONNECTION_EVENT_TYPE_NONE,
55         _NET_CONNECTION_EVENT_TYPE_STARTED,
56         _NET_CONNECTION_EVENT_TYPE_STOPPED,
57         _NET_CONNECTION_EVENT_TYPE_SUSPENDED,
58         _NET_CONNECTION_EVENT_TYPE_RESUMED,
59         _NET_CONNECTION_EVENT_TYPE_CHANGED
60 };
61
62 typedef Tizen::Base::Runtime::IEventListener* _NetListenerKey;
63
64 class _NetListenerHashCodeProvider
65 : public Tizen::Base::Collection::IHashCodeProviderT<_NetListenerKey>
66 {
67 public:
68         _NetListenerHashCodeProvider(void);
69         ~_NetListenerHashCodeProvider(void);
70
71         virtual int GetHashCode(const _NetListenerKey& obj) const;
72
73 private:
74         _NetListenerHashCodeProvider(const _NetListenerHashCodeProvider& rhs);
75         _NetListenerHashCodeProvider& operator =(const _NetListenerHashCodeProvider& rhs);
76 }; // _NetListenerHashCodeProvider
77
78 class _NetListenerComparer
79 : public Tizen::Base::Collection::IComparerT<_NetListenerKey>
80 {
81 public:
82         _NetListenerComparer(void);
83         ~_NetListenerComparer(void);
84
85         virtual result Compare(const _NetListenerKey& obj1, const _NetListenerKey& obj2, int& cmp) const;
86
87 private:
88         _NetListenerComparer(const _NetListenerComparer& rhs);
89         _NetListenerComparer& operator =(const _NetListenerComparer& rhs);
90 }; // _NetListenerComparer
91
92 class _NetConnectionEvent :
93         public Tizen::Base::Runtime::_Event
94 {
95 public:
96         _NetConnectionEvent(void);
97         virtual ~_NetConnectionEvent(void);
98
99         virtual result Construct(void);
100
101 public:
102         result AddNetConnectionEventListener(const Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Object* pConnection);
103         result RemoveNetConnectionEventListener(const Tizen::Base::Runtime::IEventListener& listener);
104         void RemoveAllNetConnectionEventListener(const Tizen::Base::Object* pConnection);
105
106         void SetConnectionState(NetConnectionState connectionState);
107         NetConnectionState GetConnectionState(void) const;
108
109         void SetSystemConnection(_SystemNetConnection* pConnection, bool isManaged = true);
110         bool IsManagedSystemConnection(void) const;
111
112         int AddRef(void);
113         int Release(void);
114
115 protected:
116         virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
117
118 private:
119         /**
120          * This is the copy constructor.
121          *
122          * @param[in]   rhs             An instance of _NetConnectionEvent
123          */
124         _NetConnectionEvent(const _NetConnectionEvent& rhs);
125
126         /**
127          * This is the assignment operator.
128          *
129          * @param[in]   rhs             An instance of _NetConnectionEvent
130          */
131         _NetConnectionEvent& operator =(const _NetConnectionEvent& rhs);
132
133 private:
134         int __refCount;
135         _NetListenerHashCodeProvider __hashCodeProvider;
136         _NetListenerComparer __comparer;
137         NetConnectionState __connectionState;
138         _SystemNetConnection* __pSystemConnection;
139         bool __isManagedSystemConnection;
140         Tizen::Base::Collection::HashMapT<_NetListenerKey, Tizen::Base::Object*>* __pListenerMap;
141 }; // _NetConnectionEvent
142
143 } } // Tizen::Net
144 #endif // _FNET_INTERNAL_NET_CONNECTION_EVENT_H_