-
Notifications
You must be signed in to change notification settings - Fork 0
/
DSInput.cpp
705 lines (594 loc) · 17.4 KB
/
DSInput.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
/****************************************************************************
* Modul: $RCSfile: DSInput.cpp,v $
*
* $Author: md $
* $Date: 1997/10/30 11:06:45 $
* $Revision: 1.3 $
*
* Aufgabe: Dieser Modul stellt die Funktionen fuer das SDL-Input-Konstrukt
* zur Verfuegung
*
* Funktionen:
****************************************************************************/
#ifdef USE_PRAGMA
#pragma interface
#endif
/****************************************************************************
* Konstanten
****************************************************************************/
/****************************************************************************
* Include-Anweisungen
****************************************************************************/
#include "DSInput.h"
#include "DSState.h" // wegen parent
#include "DSProcess.h" // wegen valid input set
#include "DSTransition.h"
#include "DSInputSignal.h"
#include "DSInputTimerSignal.h"
#include "DSExpression.h"
#include "DSString.h"
#include "DSTimer.h"
#include "DSSignal.h"
#ifdef DEBUG
#include <dmalloc.h>
#endif
/****************************************************************************
* Externe Variablen
****************************************************************************/
/****************************************************************************
* Globale Variablen
****************************************************************************/
/****************************************************************************
* Konstruktoren
****************************************************************************/
DSInput::DSInput(DSObject *father,
DSBoolean has_prio,
DSBoolean asterisk,
DSBoolean spontanous,
DSInputSignalList *s_list,
DSInputTimerSignalList *t_list,
DSExpression *enabling,
DSTransition *trans) :
DSObject(DS_INPUT, father),
has_priority(has_prio),
is_asterisk(asterisk),
is_spontanous(spontanous),
signal_list(s_list),
timer_list(t_list),
enabling_condition(enabling),
transition(trans)
{
// probability = NULL;
priority = NULL;
if (father)
{
switch(father->GetType())
{
case DS_STATE:
((DSState*)father)->InsertInput(this);
break;
default:
assert(DS_FALSE);
break;
}
}
if (enabling_condition)
{
if (enabling_condition->GetParent() == NULL) // Vater noch nicht gesetzt ?
{
enabling_condition->SetParent(this);
}
}
if (transition)
{
if (transition->GetParent() == NULL) // Vater noch nicht gesetzt ?
{
transition->SetParent(this);
}
}
}
/****************************************************************************
* Destruktor
****************************************************************************/
DSInput::~DSInput(void)
{
if (signal_list) delete signal_list;
if (timer_list) delete timer_list;
if (enabling_condition) delete enabling_condition;
if (transition) delete transition;
// if (probability) delete probability;
if (priority) delete priority;
}
/****************************************************************************
* Virtueller Konstruktor
****************************************************************************/
DSObject *DSInput::New(DSObject *father) const
{
return new DSInput(father);
}
DSBoolean DSInput::GetHasPriority(void) const
{
return has_priority;
}
/****************************************************************************
* GetIsAsterisk(): Liefert Flagwert zurueck
* Ergebnis: Boolscher Typ
* Seiteneffekte: keine
****************************************************************************/
DSBoolean DSInput::GetIsAsterisk(void) const
{
return is_asterisk;
}
/****************************************************************************
* GetIsSpontanous(): Liefert Flagwert zurueck
* Ergebnis: Boolscher Typ
* Seiteneffekte: keine
****************************************************************************/
DSBoolean DSInput::GetIsSpontanous(void) const
{
return is_spontanous;
}
/****************************************************************************
* GetPriority(): Liefert Prioritaet von continuous signals
* Ergebnis: String (Integer Literal)
* Seiteneffekte: keine
****************************************************************************/
DSString *DSInput::GetPriority(void) const
{
return priority;
}
/****************************************************************************
* GetInputSignalList(): Liefert den Zeiger auf Signalliste zurueck
* Ergebnis: Zeiger auf eine Liste
* Seiteneffekte: keine
****************************************************************************/
DSInputSignalList *DSInput::GetInputSignalList(void) const
{
return signal_list;
}
DSInputSignal *DSInput::GetFirstInputSignal(void) const
{
if (signal_list == NULL)
{
return NULL;
}
if (signal_list->MoveFirst() != DS_OK)
{
return NULL;
}
return signal_list->GetCurrentData();
}
DSInputSignal *DSInput::GetNextInputSignal(void) const
{
if (signal_list == NULL)
{
return NULL;
}
if (signal_list->MoveNext() != DS_OK)
{
return NULL;
}
return signal_list->GetCurrentData();
}
/****************************************************************************
* GetInputTimerSignalList(): Liefert Zeiger auf Timerliste zurueck
* Ergebnis: Zeiger auf eine Liste
* Seiteneffekte: keine
****************************************************************************/
DSInputTimerSignalList *DSInput::GetInputTimerSignalList(void) const
{
return timer_list;
}
DSInputTimerSignal *DSInput::GetFirstInputTimerSignal(void) const
{
if (timer_list == NULL)
{
return NULL;
}
if (timer_list->MoveFirst() != DS_OK)
{
return NULL;
}
return timer_list->GetCurrentData();
}
DSInputTimerSignal *DSInput::GetNextInputTimerSignal(void) const
{
if (timer_list == NULL)
{
return NULL;
}
if (timer_list->MoveNext() != DS_OK)
{
return NULL;
}
return timer_list->GetCurrentData();
}
DSExpression *DSInput::GetEnablingCondition(void) const
{
return enabling_condition;
}
DSTransition *DSInput::GetTransition(void) const
{
return transition;
}
DSResult DSInput::GetSignalSet(DSSignalRefList *signal_ref_list) const
{
DSInputSignal *input_signal;
DSSignalRef signal;
assert(signal_ref_list);
for (input_signal = GetFirstInputSignal();
input_signal;
input_signal = GetNextInputSignal())
{
signal = input_signal->GetSignalRef();
if (!signal_ref_list->IsInList(signal))
{
assert(signal_ref_list->Append(signal) == DS_OK);
}
}
return DS_OK;
}
DSResult DSInput::GetTimerSet(DSTimerRefList *timer_ref_list) const
{
DSInputTimerSignal *input_timer;
DSTimerRef timer;
assert(timer_ref_list);
for (input_timer = GetFirstInputTimerSignal();
input_timer;
input_timer = GetNextInputTimerSignal())
{
timer = input_timer->GetTimerRef();
if (!timer_ref_list->IsInList(timer))
{
assert(timer_ref_list->Append(timer) == DS_OK);
}
}
return DS_OK;
}
/****************************************************************************
* GetAsteriskSet(): Liefert input-Set fuer ein 'input *'
* Ergebnis: DS_OK,falls Aktion erfolgreich
* war, sonst enthaelt DSResult
* das Ergebnis
* Seiteneffekte: Zieldatei wird gefuellt
****************************************************************************/
DSResult DSInput::GetAsteriskSet(DSSignalRefList *signal_ref_list,
DSTimerRefList *timer_ref_list) const
{
DSResult result, status;
DSProcess *process;
DSSignalItemList *valid_input_set;
DSSignalRefList *signal_set;
DSTimerRefList *timer_set;
DSState *state;
DSInput *input;
DSSignalRef signal_ref;
DSTimerRef timer_ref;
assert(GetIsAsterisk());
assert(signal_ref_list);
assert(timer_ref_list);
state = (DSState *)GetParent();
assert(state);
process = (DSProcess *)GetThisProcess();
assert(process);
valid_input_set = process->GetValidSignalSet();
if (!valid_input_set) // Prozess nur aktiv, d.h.
{ // er kann keine Signale
// empfangen?
return DS_OK;
}
signal_set = new DSSignalRefList;
assert(signal_set);
timer_set = new DSTimerRefList;
assert(timer_set);
// Stimuli die in anderen Inputs vorkommen duerfen
// nicht in 'input *' verwendet werden:
for (input = state->GetFirstInput();
input;
input = state->GetNextInput())
{
if (input->GetIsAsterisk() || input->GetIsSpontanous() ||
(input->GetInputSignalList() == NULL &&
input->GetInputTimerSignalList() == NULL))
{
continue;
}
input->GetSignalSet(signal_set);
input->GetTimerSet(timer_set);
}
result = valid_input_set->GetSignals(signal_ref_list);
if (result != DS_OK) return result;
status = signal_ref_list->MoveFirst();
while (status == DS_OK)
{
signal_ref = signal_ref_list->GetCurrentData();
assert(signal_ref);
if (signal_set->IsInList(signal_ref))
{
status = signal_ref_list->DeleteElement(); // bewegt Zeiger weiter!
}
else
{
status = signal_ref_list->MoveNext();
}
}
result = valid_input_set->GetTimers(timer_ref_list);
if (result != DS_OK) return result;
status = timer_ref_list->MoveFirst();
while (status == DS_OK)
{
timer_ref = timer_ref_list->GetCurrentData();
assert(timer_ref);
if (timer_set->IsInList(timer_ref))
{
status = timer_ref_list->DeleteElement(); // bewegt Zeiger weiter!
}
else
{
status = timer_ref_list->MoveNext();
}
}
return DS_OK;
}
/****************************************************************************
* SetIsAsterisk(): Setzt das Flag
* -> accepts: Boolscher Typ
* Ergebnis: TRUE
* Seiteneffekte: keine
****************************************************************************/
DSResult DSInput::SetIsAsterisk(DSBoolean asterisk)
{
is_asterisk = asterisk;
return DS_OK;
}
/****************************************************************************
* SetIsSpontanous(): Setzt das Flag
* -> spontanous: Boolscher Typ
* Ergebnis: TRUE
* Seiteneffekte: keine
****************************************************************************/
DSResult DSInput::SetIsSpontanous(DSBoolean spontanous)
{
is_spontanous = spontanous;
return DS_OK;
}
DSResult DSInput::SetPriority(DSString *new_priority)
{
if (priority == new_priority) return DS_OK;
if (priority) delete priority;
priority = new_priority;
if (priority)
{
if (priority->GetParent() == NULL) // Vater noch nicht gesetzt ?
{
priority->SetParent(this);
}
}
return DS_OK;
}
DSResult DSInput::SetPriority(DSString &new_priority)
{
if (priority == &new_priority) return DS_OK;
if (priority) delete priority;
priority = &new_priority;
if (priority->GetParent() == NULL) // Vater noch nicht gesetzt ?
{
priority->SetParent(this);
}
return DS_OK;
}
DSResult DSInput::SetPriority(const char *new_priority)
{
if (priority) delete priority;
priority = new DSString(this, new_priority);
assert(priority);
return DS_OK;
}
/****************************************************************************
* SetInputSignalList(): Speichert den uebergebenen Zeiger
* -> sig_ref: Zeiger auf eine Liste
* Ergebnis: TRUE
* Seiteneffekte: keine
****************************************************************************/
DSResult DSInput::SetInputSignalList(DSInputSignalList *list)
{
if (signal_list == list) return DS_OK;
if (signal_list) delete signal_list;
signal_list = list;
return DS_OK;
}
DSResult DSInput::InsertInputSignal(DSInputSignal* signal)
{
assert(signal != NULL);
if (signal_list == NULL)
{
signal_list = new DSInputSignalList;
assert(signal_list != NULL);
}
if (signal->GetParent() == NULL) // Vater noch nicht gesetzt ?
{
signal->SetParent(this);
}
return signal_list->Append(signal);
}
/****************************************************************************
* SetInputTimerSignalList(): Speichert den uebergebenen Zeiger
* -> timer_ref: Zeiger auf eine Liste
* Ergebnis: TRUE
* Seiteneffekte: keine
****************************************************************************/
DSResult DSInput::SetInputTimerSignalList(DSInputTimerSignalList *list)
{
if (timer_list == list) return DS_OK;
if (timer_list) delete timer_list;
timer_list = list;
return DS_OK;
}
DSResult DSInput::InsertInputTimerSignal(DSInputTimerSignal* timer)
{
assert(timer != NULL);
if (timer_list == NULL)
{
timer_list = new DSInputTimerSignalList;
assert(timer_list != NULL);
}
if (timer->GetParent() == NULL) // Vater noch nicht gesetzt ?
{
timer->SetParent(this);
}
return timer_list->Append(timer);
}
DSResult DSInput::SetEnablingCondition(DSExpression *condition)
{
if (enabling_condition == condition) return DS_OK;
if (enabling_condition) delete enabling_condition;
enabling_condition = condition;
if (enabling_condition != NULL)
{
if (enabling_condition->GetParent() == NULL) // Vater noch nicht gesetzt ?
{
enabling_condition->SetParent(this);
}
}
return DS_OK;
}
DSResult DSInput::SetHasPriority(DSBoolean has_prio)
{
has_priority = has_prio;
return DS_OK;
}
DSResult DSInput::SetTransition(DSTransition *trans)
{
if (transition == trans) return DS_OK;
if (transition) delete transition;
transition = trans;
if (transition != NULL)
{
if (transition->GetParent() == NULL) // Vater noch nicht gesetzt ?
{
transition->SetParent(this);
}
}
return DS_OK;
}
DSBoolean DSInput::HasInputData(void) const
{
if (HasInputSignalData() || HasInputTimerSignalData())
{
return DS_TRUE;
}
return DS_FALSE;
}
DSBoolean DSInput::HasInputSignalData(void) const
{
DSInputSignal *input_signal;
for (input_signal = GetFirstInputSignal();
input_signal;
input_signal = GetNextInputSignal())
{
if (input_signal->GetVariableAccessList() != NULL) return DS_TRUE;
}
return DS_FALSE;
}
DSBoolean DSInput::HasInputTimerSignalData(void) const
{
DSInputTimerSignal *input_timer_signal;
for (input_timer_signal = GetFirstInputTimerSignal();
input_timer_signal;
input_timer_signal = GetNextInputTimerSignal())
{
if (input_timer_signal->GetVariableAccessList() != NULL) return DS_TRUE;
}
return DS_FALSE;
}
DSObject *DSInput::Clone(DSObject *father, DSObject *fill_this) const
{
DSInput *new_input;
if (fill_this == NULL)
{
new_input = (DSInput *)New(father);
assert(new_input);
}
else
{
assert(fill_this->GetType() == DS_INPUT);
new_input = (DSInput *)fill_this;
}
new_input->SetHasPriority(GetHasPriority());
new_input->SetIsAsterisk(GetIsAsterisk());
new_input->SetIsSpontanous(GetIsSpontanous());
if (GetInputSignalList())
{
new_input->SetInputSignalList(GetInputSignalList()->Clone((DSObject *)new_input));
}
if (GetInputTimerSignalList())
{
new_input->SetInputTimerSignalList(GetInputTimerSignalList()->Clone((DSObject *)new_input));
}
if (GetEnablingCondition())
{
new_input->SetEnablingCondition((DSExpression *)GetEnablingCondition()->Clone((DSObject *)new_input));
}
if (GetTransition())
{
new_input->SetTransition((DSTransition *)GetTransition()->Clone((DSObject *)new_input));
}
/* if (GetProbability())
{
new_input->SetProbability((DSExpression *)GetProbability()->Clone((DSObject *)new_input));
}
*/
if (GetPriority())
{
new_input->SetPriority((DSString *)GetPriority()->Clone((DSObject *)new_input));
}
return new_input;
}
DSResult DSInput::Write(DSWriter *writer, DSCardinal what) const
{
assert(writer);
Run(writer, DS_INPUTSIGNAL);
Run(writer, DS_INPUTTIMERSIGNAL);
if (enabling_condition) enabling_condition->Write(writer, what);
return DS_OK;
}
DSResult DSInput::Run(DSWriter *writer, DSType object_type,
DSCardinal what) const
{
DSResult result;
DSInputSignalRef input_signal;
DSInputTimerSignalRef input_timer_signal;
assert(writer);
switch(object_type)
{
case DS_INPUTSIGNAL:
for (input_signal = GetFirstInputSignal();
input_signal;
input_signal = GetNextInputSignal())
{
result = input_signal->Write(writer, what);
if (result != DS_OK)
{
return DS_ERROR;
}
}
break;
case DS_INPUTTIMERSIGNAL:
for (input_timer_signal = GetFirstInputTimerSignal();
input_timer_signal;
input_timer_signal = GetNextInputTimerSignal())
{
result = input_timer_signal->Write(writer, what);
if (result != DS_OK)
{
return DS_ERROR;
}
}
break;
default:
std::cerr << "Illegal Run on input!" << std::endl;
assert(DS_FALSE);
break;
}
return DS_OK;
}