xref: /trunk/main/vos/inc/vos/conditn.hxx (revision d98e0520)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 #ifndef _VOS_CONDITN_HXX_
26 #define _VOS_CONDITN_HXX_
27 
28 #ifndef _OSL_CONDITN_H_
29 #	include <osl/conditn.h>
30 #endif
31 #include <osl/time.h>
32 #	include <vos/object.hxx>
33 #	include <vos/vosdllapi.h>
34 
35 namespace vos
36 {
37 
38 /** ICondition
39 
40 	Interface for a thread-spanning condition. If a condition-object
41 	is created, its initial condition is False. You can check the
42 	condition nonblocking with "check()" or wait for it to become set
43 	with "wait()". The methods "set()" and "reset()" are used to change
44 	the conditions state.
45 
46     @author  Bernd Hofner
47 	@version 1.0
48 */
49 class ICondition
50 {
51 public:
52 
ICondition()53     ICondition() { }
~ICondition()54     virtual ~ICondition() { }
55 
56 
57 
58 	enum TResult
59     {
60 	    result_ok          = osl_cond_result_ok,
61 	    result_error       = osl_cond_result_error,
62 		result_timeout     = osl_cond_result_timeout
63 	};
64 
65 	/** set condition to True =>
66 		wait() will not block, check() returns True
67 	*/
68 	virtual void SAL_CALL set()= 0;
69 
70 	/** set condition to False =>
71 		wait() will block, check() returns False
72 	*/
73 	virtual void SAL_CALL reset()= 0;
74 
75 	/** Blocks if condition is not set<BR>
76 		If condition has been destroyed prematurely, wait() will
77 		return with False.
78 	*/
79 	virtual TResult SAL_CALL wait(const TimeValue* pTimeout = 0)= 0;
80 
81 	/** True: condition is set <BR>
82 		False: condition is not set <BR>
83 		does not block
84 	*/
85 	virtual sal_Bool SAL_CALL check()= 0;
86 };
87 
88 
89 /** OCondition
90 
91 	Implements the ICondition interface.
92 
93     @author  Bernd Hofner
94 	@version 1.0
95 
96 */
97 class VOS_DLLPUBLIC OCondition : public OObject, public ICondition
98 {
99 
100 	VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OCondition, vos));
101 
102 public:
103 
104 	/// initial state of condition is not set
105 	OCondition();
106 	virtual ~OCondition();
107 
108 	/// set condition to True => wait() will not block, check() returns True
109 	virtual void SAL_CALL set();
110 
111 	/// set condition to False => wait() will block, check() returns False
112 	virtual void SAL_CALL reset();
113 
114 	/** Blocks if condition is not set<BR>
115 		If condition has been destroyed prematurely, wait() will
116 		return with False.
117 	*/
118 	TResult SAL_CALL wait(const TimeValue* pTimeout = 0);
119 
120 	/** True: condition is set <BR>
121 		False: condition is not set <BR>
122 		does not block
123 	*/
124 	virtual sal_Bool SAL_CALL check();
125 
126 protected:
127 
128 	oslCondition	m_Condition;
129 
130 };
131 
132 }
133 
134 #endif	// _VOS_CONDITN_HXX_
135 
136