Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules_wearable / core / include / dpl / waitable_handle.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_handle.h
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the header file of waitable handle
21  */
22 #ifndef DPL_WAITABLE_HANDLE_H
23 #define DPL_WAITABLE_HANDLE_H
24
25 #include <dpl/noncopyable.h>
26 #include <dpl/exception.h>
27 #include <vector>
28
29 namespace DPL {
30 /**
31  * Waitable unix wait handle definition
32  */
33 typedef int WaitableHandle;
34
35 /**
36  * Waitable handle list
37  */
38 typedef std::vector<WaitableHandle> WaitableHandleList;
39
40 /**
41  * Wait mode
42  */
43 class WaitMode
44 {
45   public:
46     enum Type
47     {
48         Read,  ///< Wait for readability state changes
49         Write  ///< Wait for writability state changes
50     };
51 };
52
53 /**
54  * Waitable handle list ex
55  */
56 typedef std::vector<std::pair<WaitableHandle,
57                               WaitMode::Type> > WaitableHandleListEx;
58
59 /**
60  * Waitable handle index list
61  */
62 typedef std::vector<size_t> WaitableHandleIndexList;
63
64 /**
65  * Wait exceptions
66  */
67 DECLARE_EXCEPTION_TYPE(DPL::Exception, WaitFailed)
68
69 /**
70  * Wait for single handle readability
71  * Convience function.
72  *
73  * @return Signaled waitable handle index list
74  * @throw WaitFailed Fatal error occurred while waiting for signal
75  */
76 WaitableHandleIndexList WaitForSingleHandle(
77     WaitableHandle handle,
78     unsigned long miliseconds =
79         0xFFFFFFFF);
80
81 /**
82  * Wait for single handle
83  * Convience function.
84  *
85  * @return Signaled waitable handle index list
86  * @throw WaitFailed Fatal error occurred while waiting for signal
87  */
88 WaitableHandleIndexList WaitForSingleHandle(
89     WaitableHandle handle,
90     WaitMode::Type mode,
91     unsigned long miliseconds =
92         0xFFFFFFFF);
93
94 /**
95  * Wait for multiple handles readability
96  *
97  * @return Signaled waitable handle index list
98  * @throw WaitFailed Fatal error occurred while waiting for signal
99  */
100 WaitableHandleIndexList WaitForMultipleHandles(
101     const WaitableHandleList &handleList,
102     unsigned long miliseconds = 0xFFFFFFFF);
103
104 /**
105  * Wait for multiple handles readability
106  *
107  * @return Signaled waitable handle index list
108  * @throw WaitFailed Fatal error occurred while waiting for signal
109  */
110 WaitableHandleIndexList WaitForMultipleHandles(
111     const WaitableHandleListEx &handleListEx,
112     unsigned long miliseconds = 0xFFFFFFFF);
113 } // namespace DPL
114
115 #endif // DPL_WAITABLE_HANDLE_H