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 34 namespace vos 35 { 36 37 /** ICondition 38 39 Interface for a thread-spanning condition. If a condition-object 40 is created, its initial condition is False. You can check the 41 condition nonblocking with "check()" or wait for it to become set 42 with "wait()". The methods "set()" and "reset()" are used to change 43 the conditions state. 44 45 @author Bernd Hofner 46 @version 1.0 47 */ 48 class ICondition 49 { 50 public: 51 ICondition()52 ICondition() { } ~ICondition()53 virtual ~ICondition() { } 54 55 56 57 enum TResult 58 { 59 result_ok = osl_cond_result_ok, 60 result_error = osl_cond_result_error, 61 result_timeout = osl_cond_result_timeout 62 }; 63 64 /** set condition to True => 65 wait() will not block, check() returns True 66 */ 67 virtual void SAL_CALL set()= 0; 68 69 /** set condition to False => 70 wait() will block, check() returns False 71 */ 72 virtual void SAL_CALL reset()= 0; 73 74 /** Blocks if condition is not set<BR> 75 If condition has been destroyed prematurely, wait() will 76 return with False. 77 */ 78 virtual TResult SAL_CALL wait(const TimeValue* pTimeout = 0)= 0; 79 80 /** True: condition is set <BR> 81 False: condition is not set <BR> 82 does not block 83 */ 84 virtual sal_Bool SAL_CALL check()= 0; 85 }; 86 87 88 /** OCondition 89 90 Implements the ICondition interface. 91 92 @author Bernd Hofner 93 @version 1.0 94 95 */ 96 class OCondition : public OObject, public ICondition 97 { 98 99 VOS_DECLARE_CLASSINFO(VOS_NAMESPACE(OCondition, vos)); 100 101 public: 102 103 /// initial state of condition is not set 104 OCondition(); 105 virtual ~OCondition(); 106 107 /// set condition to True => wait() will not block, check() returns True 108 virtual void SAL_CALL set(); 109 110 /// set condition to False => wait() will block, check() returns False 111 virtual void SAL_CALL reset(); 112 113 /** Blocks if condition is not set<BR> 114 If condition has been destroyed prematurely, wait() will 115 return with False. 116 */ 117 TResult SAL_CALL wait(const TimeValue* pTimeout = 0); 118 119 /** True: condition is set <BR> 120 False: condition is not set <BR> 121 does not block 122 */ 123 virtual sal_Bool SAL_CALL check(); 124 125 protected: 126 127 oslCondition m_Condition; 128 129 }; 130 131 } 132 133 #endif // _VOS_CONDITN_HXX_ 134 135