xref: /AOO41X/main/salhelper/inc/salhelper/condition.hxx (revision 8a25e0a89046e766b2f8dcc3b5f33bc291c2c738)
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 _SALHELPER_CONDITION_HXX_
26 #define _SALHELPER_CONDITION_HXX_
27 
28 
29 #include <osl/conditn.h>
30 #include <osl/mutex.hxx>
31 
32 
33 namespace salhelper
34 {
35     class ConditionModifier;
36     class ConditionWaiter;
37 
38 
39     class Condition
40     {
41         friend class ConditionModifier;
42         friend class ConditionWaiter;
43 
44     public:
45 
46         Condition(osl::Mutex& aMutex);
47 
48         virtual ~Condition();
49 
50 
51     protected:
52 
53         virtual bool applies() const = 0;
54 
55 
56     private:
57         Condition(Condition &); // not defined
58         void operator =(Condition &); // not defined
59 
60         osl::Mutex&  m_aMutex;
61         oslCondition m_aCondition;
62     };
63 
64 
65 
66     class ConditionModifier
67     {
68     public:
69 
70         ConditionModifier(Condition& aCond);
71 
72         ~ConditionModifier();
73 
74 
75     private:
76         ConditionModifier(ConditionModifier &); // not defined
77         void operator =(ConditionModifier &); // not defined
78 
79         Condition& m_aCond;
80     };
81 
82 
83 
84     class ConditionWaiter
85     {
86     public:
87 
88         ConditionWaiter(Condition& aCond);
89 
90         struct timedout {
91             timedout();
92 
93             timedout(timedout const &);
94 
95             virtual ~timedout();
96 
97             timedout & operator =(timedout const &);
98         };
99 
100         ConditionWaiter(Condition& aCond,sal_uInt32 milliSec)
101             throw(
102                 timedout
103             );
104 
105 
106         ~ConditionWaiter();
107 
108 
109     private:
110         ConditionWaiter(ConditionWaiter &); // not defined
111         void operator =(ConditionWaiter &); // not defined
112 
113         Condition& m_aCond;
114     };
115 
116 
117 }   // namespace salhelper
118 
119 
120 #endif
121