1
//////////////////////////////////////////////////////////////////////////////////
2
// This file is part of Toolkit for Conceptual Modeling (TCM).
3
// (c) copyright 2001, Universiteit Twente.
4
// Author: Rik Eshuis (eshuis@cs.utwente.nl).
6
// TCM is free software; you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation; either version 2 of the License, or
9
// (at your option) any later version.
11
// TCM is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with TCM; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20
////////////////////////////////////////////////////////////////////////////////
21
#include "adsclockmanager.h"
22
#include "adsclockconstraint.h"
23
#include "outputfile.h"
28
ClockManager::ClockManager(){
31
integer_timespent[i]=0;
32
fraction_timespent[i]=0;
38
ClockManager::~ClockManager(){
42
ClockManager::ClockManager(const ClockManager &c){
44
int clistlen=cl.count();
46
for (i=0;i<clistlen ;i++){
47
integer_timespent[i]=c.integer_timespent[i];
48
fraction_timespent[i]=c.fraction_timespent[i];
55
bool ClockManager::operator==( ClockManager comp){
56
int clistlen=cl.count();
57
int compclistlen=comp.cl.count();
60
for (i=0;i<clistlen;i++){
62
for (j=0;j<compclistlen;j++){
63
if ( (cl[i]==comp.cl[j]) && (integer_timespent[i]==comp.integer_timespent[j])&& (fraction_timespent[i]==comp.fraction_timespent[j]) ){
68
if (!found) return False;
70
for (j=0;j<compclistlen;j++){
72
for (i=0;i<clistlen;i++){
73
if ((cl[i] == comp.cl[j] ) && (integer_timespent[i]==comp.integer_timespent[j]) && (fraction_timespent[i]==comp.fraction_timespent[j]) ) {
78
if (!found) return False;
85
bool ClockManager::ExistScheduled(){
86
return (cl.count()>0);
90
bool ClockManager::ExistTimeouts(){
91
int clistlen=cl.count();
92
for (int i=0;i<clistlen;i++){
93
if ((integer_timespent[i]==0) && (fraction_timespent[i]==0)){
103
// Get all clockconstraints that must be responded to NOW
104
void ClockManager::GetTimeouts(List <ClockConstraint *> *l){
105
if (!ExistScheduled()) {
106
error("There are no timeouts scheduled!\n");
110
int clistlen=cl.count();
111
for (i=0;i<clistlen;i++){
112
if ((integer_timespent[i]==0) && (fraction_timespent[i]==0)){
122
bool ClockManager::Update(List <ClockConstraint *> *zero,
123
List <ClockConstraint *> *off){
127
// locate timers in cl
128
for (off->first();!off->done();off->next()){
129
int index=cl.find(off->cur()); // must exists due to assumption
131
error("I cannot turn off a clock constraint that is not turned on!\n");
134
integer_timespent[index]=-1; // used below to update array integer_timespent
136
int nrtimer=cl.count();
138
// remove timers from cl
139
for (off->first();!off->done();off->next()){
140
cl.remove(off->cur()); // off->cur() must exist due to assumption
145
// remove off timers from array timespent
147
for (i=0;i<nrtimer;i++){
148
if (integer_timespent[i]==-1){
152
// remove from timespent
153
for (j=i;j<nrtimer-1;j++){
154
integer_timespent[j]=integer_timespent[j+1];
155
fraction_timespent[j]=fraction_timespent[j+1];
162
for (zero->first();!zero->done();zero->next()){
163
//zero->cur()->Write();
164
if (cl.find(zero->cur())>-1){
165
error("Warning: hyperedge ");
166
string str= cl[cl.find(zero->cur())]->GetLimit();
168
error(" multiple times enabled!\n");
173
integer_timespent[cl.count()-1]=zero->cur()->GetLimit();
174
fraction_timespent[cl.count()-1]=0;
185
bool ClockManager::Tick(){
188
for (i=0;i<clen;i++){
189
if (fraction_timespent[i]==0){
190
if (integer_timespent[i]>0){
191
integer_timespent[i]--;
193
else{ // (integer_timespent[i]==0)
194
error("A timeout is not responded to in time!\n");
197
fraction_timespent[i]=interval-1;
199
else{ // fraction_timespent[i]>0
200
fraction_timespent[i]--;
211
void ClockManager::Write(OutputFile *ofile){
212
(*ofile) << "Status of clock manager:\n";
213
for (cl.first();!cl.done();cl.next()){
214
cl.cur()->Write(ofile);
217
for (i=0;i<cl.count();i++){
218
(*ofile) << "Time spent " << integer_timespent[i] <<"\t"<<
219
fraction_timespent[i] << "/"<< interval << "!\n";
224
void ClockManager::Write(){
225
std::cout << "Status of clock manager:\n";
226
for (cl.first();!cl.done();cl.next()){
230
for (i=0;i<cl.count();i++){
231
std::cout << "Time spent " << integer_timespent[i] <<"\t"<<
232
fraction_timespent[i] << "/"<< interval << "!\n";