xref: /AOO42X/main/vos/inc/vos/execabl.hxx (revision 9bce9b0d387299c68bd81d539e1478357a103de5)
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_EXECABL_HXX_
26 #define _VOS_EXECABL_HXX_
27 
28 #   include <vos/types.hxx>
29 #   include <vos/refernce.hxx>
30 
31 namespace vos
32 {
33 
34 
35 /** IExecutable
36 
37     The IExecutable-interface is to be understood as wrapper around
38     your application-code, which allows it to be executed asynchronously.
39 
40     Whether you want real asynchronous behaviour or just pseudo-multitasking
41     depends on which kind of execution-service you use to execute your executable.
42 
43     (E.g. Threadpool/Fiberpool)
44 
45     @author  Bernd Hofner
46     @version 0.1
47 */
48 
49 class IExecutable : public vos::IReference
50 {
51 public:
52 
53     /** Overload to implement your functionality.
54         Return True, if you want "execute()" to be called again.
55     */
56     virtual sal_Bool SAL_CALL execute()= 0;
57 
58 
59     /** If you use blocking calls within your execute-function,
60         you should provide here a means to unblock cleanly.
61         @Return False if you are not able to unblock the
62         thread.
63 
64     */
65     virtual sal_Bool SAL_CALL unblock()= 0;
66 
67     /**
68         STL demands this operators if you want to place
69         IExecutables per value in collections.
70     */
71     virtual sal_Bool SAL_CALL operator<(const IExecutable&) const= 0;
72     virtual sal_Bool SAL_CALL operator>(const IExecutable&) const= 0;
73     virtual sal_Bool SAL_CALL operator==(const IExecutable&) const= 0;
74     virtual sal_Bool SAL_CALL operator!=(const IExecutable&) const= 0;
75 };
76 
77 
78 /** OExecutable
79     added default impl. of IReferenceCounter
80 */
81 class OExecutable : public vos::IExecutable,
82                     public vos::OReference
83 
84 {
85 public:
86 
~OExecutable()87     virtual ~OExecutable()
88     {
89     }
90 
91     /*
92         Since the dominance of the OReferenceCounter impl.
93         of the IReferenceCounter is not granted, delegate
94         the methods to this branch of the diamond-shaped
95         inheritance tree.
96     */
97 
acquire()98     virtual RefCount SAL_CALL acquire()
99     {
100         return OReference::acquire();
101     }
release()102     virtual RefCount SAL_CALL release()
103     {
104         return OReference::release();
105     }
referenced() const106     virtual RefCount SAL_CALL referenced() const
107     {
108         return OReference::referenced();
109     }
110 
111 
112     /** Default implementation of unblock does nothing.
113     */
unblock()114     virtual sal_Bool SAL_CALL unblock() { return sal_True; }
115 
116 
117     /**
118         STL demands this operators if you want to place
119         IExecutables per value in collections.
120         Use a default implementation of the comparison-operators
121         here without a correct semantic.
122     */
operator <(const IExecutable &) const123     virtual sal_Bool SAL_CALL operator<(const IExecutable&) const
124     {
125         return sal_False;
126     }
127 
operator >(const IExecutable &) const128     virtual sal_Bool SAL_CALL operator>(const IExecutable&) const
129     {
130         return sal_False;
131     }
132 
operator ==(const IExecutable &) const133     virtual sal_Bool SAL_CALL operator==(const IExecutable&) const
134     {
135         return sal_True;
136     }
137 
operator !=(const IExecutable &) const138     virtual sal_Bool SAL_CALL operator!=(const IExecutable&) const
139     {
140         return sal_False;
141     }
142 };
143 
144 }
145 
146 
147 #endif  // _VOS_EXECABL_HXX_
148