1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski 25*b1cdbd2cSJim Jagielski #ifndef _VOS_EXECABL_HXX_ 26*b1cdbd2cSJim Jagielski #define _VOS_EXECABL_HXX_ 27*b1cdbd2cSJim Jagielski 28*b1cdbd2cSJim Jagielski # include <vos/types.hxx> 29*b1cdbd2cSJim Jagielski # include <vos/refernce.hxx> 30*b1cdbd2cSJim Jagielski 31*b1cdbd2cSJim Jagielski namespace vos 32*b1cdbd2cSJim Jagielski { 33*b1cdbd2cSJim Jagielski 34*b1cdbd2cSJim Jagielski 35*b1cdbd2cSJim Jagielski /** IExecutable 36*b1cdbd2cSJim Jagielski 37*b1cdbd2cSJim Jagielski The IExecutable-interface is to be understood as wrapper around 38*b1cdbd2cSJim Jagielski your application-code, which allows it to be executed asynchronously. 39*b1cdbd2cSJim Jagielski 40*b1cdbd2cSJim Jagielski Wether you want real asynchronous behaviour or just pseudo-multitasking 41*b1cdbd2cSJim Jagielski depends on which kind of execution-service you use to execute your executable. 42*b1cdbd2cSJim Jagielski 43*b1cdbd2cSJim Jagielski (E.g. Threadpool/Fiberpool) 44*b1cdbd2cSJim Jagielski 45*b1cdbd2cSJim Jagielski @author Bernd Hofner 46*b1cdbd2cSJim Jagielski @version 0.1 47*b1cdbd2cSJim Jagielski */ 48*b1cdbd2cSJim Jagielski 49*b1cdbd2cSJim Jagielski class IExecutable : public vos::IReference 50*b1cdbd2cSJim Jagielski { 51*b1cdbd2cSJim Jagielski public: 52*b1cdbd2cSJim Jagielski 53*b1cdbd2cSJim Jagielski /** Overload to implement your functionality. 54*b1cdbd2cSJim Jagielski Return True, if you want "execute()" to be called again. 55*b1cdbd2cSJim Jagielski */ 56*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL execute()= 0; 57*b1cdbd2cSJim Jagielski 58*b1cdbd2cSJim Jagielski 59*b1cdbd2cSJim Jagielski /** If you use blocking calls within your execute-function, 60*b1cdbd2cSJim Jagielski you should provide here a means to unblock cleanly. 61*b1cdbd2cSJim Jagielski @Return False if you are not able to unblock the 62*b1cdbd2cSJim Jagielski thread. 63*b1cdbd2cSJim Jagielski 64*b1cdbd2cSJim Jagielski */ 65*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL unblock()= 0; 66*b1cdbd2cSJim Jagielski 67*b1cdbd2cSJim Jagielski /** 68*b1cdbd2cSJim Jagielski STL demands this operators if you want to place 69*b1cdbd2cSJim Jagielski IExecutables per value in collections. 70*b1cdbd2cSJim Jagielski */ 71*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL operator<(const IExecutable&) const= 0; 72*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL operator>(const IExecutable&) const= 0; 73*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL operator==(const IExecutable&) const= 0; 74*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL operator!=(const IExecutable&) const= 0; 75*b1cdbd2cSJim Jagielski }; 76*b1cdbd2cSJim Jagielski 77*b1cdbd2cSJim Jagielski 78*b1cdbd2cSJim Jagielski /** OExecutable 79*b1cdbd2cSJim Jagielski added default impl. of IReferenceCounter 80*b1cdbd2cSJim Jagielski */ 81*b1cdbd2cSJim Jagielski class OExecutable : public vos::IExecutable, 82*b1cdbd2cSJim Jagielski public vos::OReference 83*b1cdbd2cSJim Jagielski 84*b1cdbd2cSJim Jagielski { 85*b1cdbd2cSJim Jagielski public: 86*b1cdbd2cSJim Jagielski ~OExecutable()87*b1cdbd2cSJim Jagielski virtual ~OExecutable() 88*b1cdbd2cSJim Jagielski { 89*b1cdbd2cSJim Jagielski } 90*b1cdbd2cSJim Jagielski 91*b1cdbd2cSJim Jagielski /* 92*b1cdbd2cSJim Jagielski Since the dominance of the OReferenceCounter impl. 93*b1cdbd2cSJim Jagielski of the IReferenceCounter is not granted, delegate 94*b1cdbd2cSJim Jagielski the methods to this branch of the diamond-shaped 95*b1cdbd2cSJim Jagielski inheritance tree. 96*b1cdbd2cSJim Jagielski */ 97*b1cdbd2cSJim Jagielski acquire()98*b1cdbd2cSJim Jagielski virtual RefCount SAL_CALL acquire() 99*b1cdbd2cSJim Jagielski { 100*b1cdbd2cSJim Jagielski return OReference::acquire(); 101*b1cdbd2cSJim Jagielski } release()102*b1cdbd2cSJim Jagielski virtual RefCount SAL_CALL release() 103*b1cdbd2cSJim Jagielski { 104*b1cdbd2cSJim Jagielski return OReference::release(); 105*b1cdbd2cSJim Jagielski } referenced() const106*b1cdbd2cSJim Jagielski virtual RefCount SAL_CALL referenced() const 107*b1cdbd2cSJim Jagielski { 108*b1cdbd2cSJim Jagielski return OReference::referenced(); 109*b1cdbd2cSJim Jagielski } 110*b1cdbd2cSJim Jagielski 111*b1cdbd2cSJim Jagielski 112*b1cdbd2cSJim Jagielski /** Default implementation of unblock does nothing. 113*b1cdbd2cSJim Jagielski */ unblock()114*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL unblock() { return sal_True; } 115*b1cdbd2cSJim Jagielski 116*b1cdbd2cSJim Jagielski 117*b1cdbd2cSJim Jagielski /** 118*b1cdbd2cSJim Jagielski STL demands this operators if you want to place 119*b1cdbd2cSJim Jagielski IExecutables per value in collections. 120*b1cdbd2cSJim Jagielski Use a default implementation of the comparison-operators 121*b1cdbd2cSJim Jagielski here without a correct semantic. 122*b1cdbd2cSJim Jagielski */ operator <(const IExecutable &) const123*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL operator<(const IExecutable&) const 124*b1cdbd2cSJim Jagielski { 125*b1cdbd2cSJim Jagielski return sal_False; 126*b1cdbd2cSJim Jagielski } 127*b1cdbd2cSJim Jagielski operator >(const IExecutable &) const128*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL operator>(const IExecutable&) const 129*b1cdbd2cSJim Jagielski { 130*b1cdbd2cSJim Jagielski return sal_False; 131*b1cdbd2cSJim Jagielski } 132*b1cdbd2cSJim Jagielski operator ==(const IExecutable &) const133*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL operator==(const IExecutable&) const 134*b1cdbd2cSJim Jagielski { 135*b1cdbd2cSJim Jagielski return sal_True; 136*b1cdbd2cSJim Jagielski } 137*b1cdbd2cSJim Jagielski operator !=(const IExecutable &) const138*b1cdbd2cSJim Jagielski virtual sal_Bool SAL_CALL operator!=(const IExecutable&) const 139*b1cdbd2cSJim Jagielski { 140*b1cdbd2cSJim Jagielski return sal_False; 141*b1cdbd2cSJim Jagielski } 142*b1cdbd2cSJim Jagielski }; 143*b1cdbd2cSJim Jagielski 144*b1cdbd2cSJim Jagielski } 145*b1cdbd2cSJim Jagielski 146*b1cdbd2cSJim Jagielski 147*b1cdbd2cSJim Jagielski #endif // _VOS_EXECABL_HXX_ 148*b1cdbd2cSJim Jagielski 149