1 | /* Copyright (C) 2001 Marc Casaldaliga Albisu <casaldaliga@ifae.es>
|
---|
2 | ================================================================
|
---|
3 |
|
---|
4 | This code is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This code is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with Emacs (which is required to make this stuff work); if
|
---|
16 | not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
---|
17 | Cambridge, MA 02139, USA.
|
---|
18 | ==================================================================
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "PeriodicAction.hxx"
|
---|
22 | //for signals
|
---|
23 | #include <sigc++/signal_system.h>
|
---|
24 | using namespace SigC;
|
---|
25 | PeriodicAction::PeriodicAction( unsigned int period_)
|
---|
26 | : period(period_),periodic(period_)
|
---|
27 | {
|
---|
28 | }
|
---|
29 |
|
---|
30 |
|
---|
31 | PeriodicAction::PeriodicAction ( unsigned int period_, const Slot0<bool> & doWhileData, const Slot0<void> & finallyData )
|
---|
32 | : period(period_), periodic(period_)
|
---|
33 | {
|
---|
34 |
|
---|
35 | this->DoWhile(doWhileData);
|
---|
36 | this->FinallyDo(finallyData);
|
---|
37 | }
|
---|
38 |
|
---|
39 | void PeriodicAction::DoWhileNot( const Slot0<bool> & s)
|
---|
40 | {
|
---|
41 | // if( doWhileNot || doWhile){
|
---|
42 | // //doWhile actions were defined before, redefining them
|
---|
43 | // if(doWhileNot) delete doWhileNot;
|
---|
44 | // else delete doWhile;
|
---|
45 | // actionConn.disconnect();
|
---|
46 |
|
---|
47 | // }else{
|
---|
48 | actionConn=doWhileNot.connect(s);
|
---|
49 | // }
|
---|
50 |
|
---|
51 | periodConn=periodic.signal.connect(slot(this,&PeriodicAction::DoItOnceAndCheckContinuance_Not));
|
---|
52 | }
|
---|
53 | void PeriodicAction::DoWhile(const Slot0<bool> &s)
|
---|
54 | {
|
---|
55 | // if( doWhileNot || doWhile){
|
---|
56 | // //doWhile actions were defined before, redefining them
|
---|
57 | // if(doWhileNot) delete doWhileNot;
|
---|
58 | // else delete doWhile;
|
---|
59 | // actionConn.disconnect();
|
---|
60 |
|
---|
61 | // }else{
|
---|
62 | actionConn=doWhile.connect(s);
|
---|
63 | // }
|
---|
64 |
|
---|
65 | periodConn=periodic.signal.connect(slot(this,&PeriodicAction::DoItOnceAndCheckContinuance));
|
---|
66 | }
|
---|
67 | void PeriodicAction::FinallyDo( const Slot0<void> & s)
|
---|
68 | {
|
---|
69 | finally.connect(s);
|
---|
70 | }
|
---|
71 |
|
---|
72 | void PeriodicAction::DoItOnceAndCheckContinuance()
|
---|
73 | {
|
---|
74 | if ( ! doWhile.emit() ){
|
---|
75 | periodic.Stop();
|
---|
76 | finally.emit();
|
---|
77 | }
|
---|
78 | }
|
---|
79 | void PeriodicAction::DoItOnceAndCheckContinuance_Not()
|
---|
80 | {
|
---|
81 | if ( doWhileNot.emit() ){
|
---|
82 | periodic.Stop();
|
---|
83 | finally.emit();
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | // public method isRunning { } {
|
---|
90 | // if { "$scheduledId" == "" } {
|
---|
91 | // return 0
|
---|
92 | // } else {
|
---|
93 | // return 1
|
---|
94 | // }
|
---|
95 | // }
|
---|
96 |
|
---|
97 | void PeriodicAction::Start () {
|
---|
98 | // if(! periodic.isRunning ){
|
---|
99 | periodic.Start();
|
---|
100 | // }
|
---|
101 | //we don't want to launch it twice
|
---|
102 | };
|
---|
103 |
|
---|
104 |
|
---|
105 | void PeriodicAction::Stop () {
|
---|
106 | // if(! periodic.isRunning ){
|
---|
107 | periodic.Stop();
|
---|
108 | // }
|
---|
109 | };
|
---|
110 |
|
---|
111 |
|
---|
112 | // public method SetPeriod { period_ } {
|
---|
113 | // set period $period_
|
---|
114 | // }
|
---|
115 |
|
---|
116 |
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|