Update User Agent String
[framework/web/wrt-commons.git] / modules / socket / include / dpl / socket / waitable_input_output_execution_context_support.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file        waitable_input_output_execution_context_support.h
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the header file for waitable input-output execution context support
21  */
22 #ifndef DPL_WAITABLE_INPUT_OUTPUT_EXECUTION_CONTEXT_SUPPORT_H
23 #define DPL_WAITABLE_INPUT_OUTPUT_EXECUTION_CONTEXT_SUPPORT_H
24
25 #include <dpl/abstract_waitable_input_output.h>
26 #include <dpl/waitable_handle_watch_support.h>
27 #include <dpl/binary_queue.h>
28
29 namespace DPL
30 {
31 namespace Socket
32 {
33
34 class WaitableInputOutputExecutionContextSupport
35     : private WaitableHandleWatchSupport::WaitableHandleListener
36 {
37 public:
38     class Exception
39     {
40     public:
41         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
42         DECLARE_EXCEPTION_TYPE(Base, AlreadyOpened)
43         DECLARE_EXCEPTION_TYPE(Base, NotOpened)
44         DECLARE_EXCEPTION_TYPE(Base, OpenFailed)
45         DECLARE_EXCEPTION_TYPE(Base, CloseFailed)
46     };
47
48 private:
49     bool m_opened;
50     AbstractWaitableInputOutput *m_waitableInputOutput;
51
52     // Watch state
53     bool m_hasReadWatch;
54     bool m_hasWriteWatch;
55
56     void AddReadWatch();
57     void RemoveReadWatch();
58     void AddWriteWatch();
59     void RemoveWriteWatch();
60
61     void ReadInput();
62
63     void CheckedRemoveReadWatch();
64     void CheckedRemoveWriteWatch();
65
66     void CheckedRemoveReadWriteWatch();
67
68     virtual void OnWaitableHandleEvent(WaitableHandle waitableHandle, WaitMode::Type mode);
69
70 protected:
71     // Incoming/Outgoing streams
72     BinaryQueue m_inputStream;
73     BinaryQueue m_outputStream;
74
75     // Support calbback methods
76     virtual void OnInputStreamRead() = 0;
77     virtual void OnInputStreamClosed() = 0;
78     virtual void OnInputStreamBroken() = 0;
79
80     // Trigger feeding output - after updating output stream
81     void FeedOutput();
82
83     // Open/Close destination waitable input-output
84     void Open(AbstractWaitableInputOutput *waitableInputOutput);
85     void Close();
86
87 public:
88     /**
89      * Constructor
90      */
91     explicit WaitableInputOutputExecutionContextSupport();
92
93     /**
94      * Destructor
95      */
96     virtual ~WaitableInputOutputExecutionContextSupport();
97 };
98
99 }
100 } // namespace DPL
101
102 #endif // DPL_WAITABLE_INPUT_OUTPUT_EXECUTION_CONTEXT_SUPPORT_H