OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [libcdl/] [transact.cxx] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//{{{  Banner                                   
2
 
3
//============================================================================
4
//
5
//      transaction.cxx
6
//
7
//      Implementation of the CdlTransaction class
8
//
9
//============================================================================
10
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
11
// -------------------------------------------                              
12
// This file is part of the eCos host tools.                                
13
// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.      
14
//
15
// This program is free software; you can redistribute it and/or modify     
16
// it under the terms of the GNU General Public License as published by     
17
// the Free Software Foundation; either version 2 or (at your option) any   
18
// later version.                                                           
19
//
20
// This program is distributed in the hope that it will be useful, but      
21
// WITHOUT ANY WARRANTY; without even the implied warranty of               
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
23
// General Public License for more details.                                 
24
//
25
// You should have received a copy of the GNU General Public License        
26
// along with this program; if not, write to the                            
27
// Free Software Foundation, Inc., 51 Franklin Street,                      
28
// Fifth Floor, Boston, MA  02110-1301, USA.                                
29
// -------------------------------------------                              
30
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
31
//============================================================================
32
//#####DESCRIPTIONBEGIN####
33
//
34
// Author(s):   bartv
35
// Contact(s):  bartv
36
// Date:        1999/07/16
37
// Version:     0.01
38
//
39
//####DESCRIPTIONEND####
40
//============================================================================
41
 
42
//}}}
43
//{{{  #include's                               
44
 
45
// ----------------------------------------------------------------------------
46
#include "cdlconfig.h"
47
 
48
// Get the infrastructure types, assertions, tracing and similar
49
// facilities.
50
#include <cyg/infra/cyg_ass.h>
51
#include <cyg/infra/cyg_trac.h>
52
 
53
// <cdlcore.hxx> defines everything implemented in this module.
54
// It implicitly supplies <string>, <vector> and <map> because
55
// the class definitions rely on these headers.
56
#include <cdlcore.hxx>
57
 
58
//}}}
59
 
60
//{{{  CdlTransactionCallback class             
61
 
62
// ----------------------------------------------------------------------------
63
// The callback class is very straightforward. The hard work is done in
64
// the transaction class.
65
 
66
CdlTransactionCallback::CdlTransactionCallback(CdlTransaction transact_arg)
67
{
68
    CYG_REPORT_FUNCNAME("CdlTransactionCallback:: constructor");
69
    CYG_REPORT_FUNCARG2XV(this, transact_arg);
70
    CYG_PRECONDITION_CLASSC(transact_arg);
71
 
72
    // The vectors etc. will take care of themselves.
73
    transact = transact_arg;
74
    cdltransactioncallback_cookie = CdlTransactionCallback_Magic;
75
 
76
    CYG_POSTCONDITION_THISC();
77
    CYG_REPORT_RETURN();
78
}
79
 
80
CdlTransactionCallback::~CdlTransactionCallback()
81
{
82
    CYG_REPORT_FUNCNAME("CdlTransactionCallback:: destructor");
83
    CYG_REPORT_FUNCARG1XV(this);
84
    CYG_PRECONDITION_THISC();
85
 
86
    cdltransactioncallback_cookie = CdlTransactionCallback_Invalid;
87
    transact = 0;
88
    value_changes.clear();
89
    active_changes.clear();
90
    legal_values_changes.clear();
91
    value_source_changes.clear();
92
    new_conflicts.clear();
93
    new_structural_conflicts.clear();
94
    nodes_with_resolved_conflicts.clear();
95
    nodes_with_resolved_structural_conflicts.clear();
96
 
97
    CYG_REPORT_RETURN();
98
}
99
 
100
void
101
CdlTransactionCallback::set_callback_fn(void (*fn)(const CdlTransactionCallback&))
102
{
103
    CYG_REPORT_FUNCNAME("CdlTransactionCallback::set_callback_fn");
104
    CYG_REPORT_FUNCARG1XV(fn);
105
 
106
    CdlTransactionBody::set_callback_fn(fn);
107
 
108
    CYG_REPORT_RETURN();
109
}
110
 
111
void (*CdlTransactionCallback::get_callback_fn())(const CdlTransactionCallback&)
112
{
113
    CYG_REPORT_FUNCNAMETYPE("CdlTransactionCallback::get_callback_fn", "result %p");
114
 
115
    void (*result)(const CdlTransactionCallback&) = CdlTransactionBody::get_callback_fn();
116
 
117
    CYG_REPORT_RETVAL(result);
118
    return result;
119
}
120
 
121
CdlTransaction
122
CdlTransactionCallback::get_transaction() const
123
{
124
    CYG_REPORT_FUNCNAMETYPE("CdlTransactionCallback::get_transaction", "result %p");
125
    CYG_PRECONDITION_THISC();
126
 
127
    CdlTransaction result = transact;
128
    CYG_POSTCONDITION_CLASSC(result);
129
 
130
    CYG_REPORT_RETVAL(result);
131
    return result;
132
}
133
 
134
CdlToplevel
135
CdlTransactionCallback::get_toplevel() const
136
{
137
    CYG_REPORT_FUNCNAMETYPE("CdlTransactionCallback::get_toplevel", "result %p");
138
    CYG_PRECONDITION_THISC();
139
 
140
    CdlToplevel result = transact->get_toplevel();
141
    CYG_POSTCONDITION_CLASSC(result);
142
 
143
    CYG_REPORT_RETVAL(result);
144
    return result;
145
}
146
 
147
bool
148
CdlTransactionCallback::check_this(cyg_assert_class_zeal zeal) const
149
{
150
    if (CdlTransactionCallback_Magic != cdltransactioncallback_cookie) {
151
        return false;
152
    }
153
    return true;
154
}
155
 
156
//}}}
157
//{{{  CdlTransaction statics                   
158
 
159
// ----------------------------------------------------------------------------
160
void (*CdlTransactionBody::callback_fn)(const CdlTransactionCallback&)  = 0;
161
CdlInferenceCallback    CdlTransactionBody::inference_callback          = 0;
162
bool                    CdlTransactionBody::inference_enabled           = true;
163
int                     CdlTransactionBody::inference_recursion_limit   = 3;
164
CdlValueSource          CdlTransactionBody::inference_override          = CdlValueSource_Inferred;
165
CYGDBG_DEFINE_MEMLEAK_COUNTER(CdlTransactionBody);
166
 
167
//}}}
168
//{{{  Transaction creation and destruction     
169
 
170
// ----------------------------------------------------------------------------
171
CdlTransaction
172
CdlTransactionBody::make(CdlToplevel toplevel)
173
{
174
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::make", "result %p");
175
    CYG_REPORT_FUNCARG1XV(toplevel);
176
    CYG_PRECONDITION_CLASSC(toplevel);
177
    CYG_PRECONDITIONC(0 == toplevel->transaction);
178
 
179
    CdlTransaction result = new CdlTransactionBody(toplevel, 0, 0);
180
    toplevel->transaction = result;
181
 
182
    CYG_REPORT_RETVAL(result);
183
    return result;
184
}
185
 
186
CdlTransaction
187
CdlTransactionBody::make(CdlConflict conflict)
188
{
189
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::make (sub-transaction)", "result %p");
190
    CYG_REPORT_FUNCARG2XV(this, conflict);
191
    CYG_PRECONDITION_THISC();
192
    CYG_PRECONDITION_ZERO_OR_CLASSC(conflict);
193
 
194
    CdlTransaction result = new CdlTransactionBody(0, this, conflict);
195
 
196
    CYG_REPORT_RETVAL(result);
197
    return result;
198
}
199
 
200
CdlTransactionBody::CdlTransactionBody(CdlToplevel toplevel_arg, CdlTransaction parent_arg, CdlConflict conflict_arg)
201
{
202
    CYG_REPORT_FUNCNAME("CdlTransaction:: constructor");
203
    CYG_REPORT_FUNCARG4XV(this, toplevel_arg, parent_arg, conflict_arg);
204
    CYG_PRECONDITION_ZERO_OR_CLASSC(toplevel_arg);
205
    CYG_PRECONDITION_ZERO_OR_CLASSC(parent_arg);
206
    CYG_PRECONDITION_ZERO_OR_CLASSC(conflict_arg);
207
    CYG_PRECONDITIONC( ((0 == toplevel_arg) && (0 != parent_arg)) || ((0 == parent_arg) && (0 != toplevel_arg)));
208
 
209
    // The containers will take care of themselves, as will all_changes
210
    toplevel    = toplevel_arg;
211
    parent      = parent_arg;
212
    conflict    = conflict_arg;
213
    dirty       = false;
214
    cdltransactionbody_cookie   = CdlTransactionBody_Magic;
215
    CYGDBG_MEMLEAK_CONSTRUCTOR();
216
 
217
    CYG_POSTCONDITION_THISC();
218
    CYG_REPORT_RETURN();
219
}
220
 
221
// ----------------------------------------------------------------------------
222
CdlTransactionBody::~CdlTransactionBody()
223
{
224
    CYG_REPORT_FUNCNAME("CdlTransaction:: destructor");
225
    CYG_REPORT_FUNCARG1XV(this);
226
    CYG_PRECONDITION_THISC();
227
 
228
    // The transaction must have been either committed or cancelled.
229
    // This means that various of the STL containers should be empty
230
    CYG_ASSERTC(0 == commit_cancel_ops.size());
231
    CYG_ASSERTC(0 == changes.size());
232
    CYG_ASSERTC(0 == deleted_conflicts.size());
233
    CYG_ASSERTC(0 == deleted_structural_conflicts.size());
234
    CYG_ASSERTC(0 == new_conflicts.size());
235
    CYG_ASSERTC(0 == new_structural_conflicts.size());
236
    CYG_ASSERTC(0 == resolved_conflicts.size());
237
    CYG_ASSERTC(0 == global_conflicts_with_solutions.size());
238
    CYG_ASSERTC(0 == activated.size());
239
    CYG_ASSERTC(0 == deactivated.size());
240
    CYG_ASSERTC(0 == legal_values_changes.size());
241
    CYG_ASSERTC(0 == value_changes.size());
242
    CYG_ASSERTC(0 == active_changes.size());
243
 
244
    // If this was a toplevel transaction, the toplevel knows
245
    // about the transaction.
246
    if (0 != toplevel) {
247
        CYG_ASSERTC(toplevel->transaction == this);
248
        toplevel->transaction = 0;
249
    }
250
    cdltransactionbody_cookie   = CdlTransactionBody_Invalid;
251
    toplevel    = 0;
252
    parent      = 0;
253
    conflict    = 0;
254
    dirty       = false;
255
 
256
    CYGDBG_MEMLEAK_DESTRUCTOR();
257
 
258
    CYG_REPORT_RETURN();
259
}
260
 
261
//}}}
262
//{{{  check_this()                             
263
 
264
// ----------------------------------------------------------------------------
265
 
266
bool
267
CdlTransactionBody::check_this(cyg_assert_class_zeal zeal) const
268
{
269
    if (CdlTransactionBody_Magic != cdltransactionbody_cookie) {
270
        return false;
271
    }
272
    CYGDBG_MEMLEAK_CHECKTHIS();
273
 
274
    //zeal = cyg_extreme;
275
    switch(zeal) {
276
      case cyg_system_test:
277
      case cyg_extreme :
278
      {
279
          std::map<CdlValuable,CdlValue>::const_iterator map_i;
280
          for (map_i = changes.begin(); map_i != changes.end(); map_i++) {
281
              if (!map_i->first->check_this(cyg_quick) || !map_i->second.check_this(cyg_quick)) {
282
                  return false;
283
              }
284
          }
285
 
286
          std::list<CdlConflict>::const_iterator conf_i;
287
          for (conf_i = new_conflicts.begin(); conf_i != new_conflicts.end(); conf_i++) {
288
              if (!(*conf_i)->check_this(cyg_quick)) {
289
                  return false;
290
              }
291
          }
292
          for (conf_i = new_structural_conflicts.begin(); conf_i != new_structural_conflicts.end(); conf_i++) {
293
              if (!(*conf_i)->check_this(cyg_quick)) {
294
                  return false;
295
              }
296
          }
297
 
298
          std::vector<CdlConflict>::const_iterator conf_i2;
299
          for (conf_i2 = deleted_conflicts.begin(); conf_i2 != deleted_conflicts.end(); conf_i2++) {
300
              if (!(*conf_i2)->check_this(cyg_quick)) {
301
                  return false;
302
              }
303
          }
304
          for (conf_i2 = resolved_conflicts.begin(); conf_i2 != resolved_conflicts.end(); conf_i2++) {
305
              if (!(*conf_i2)->check_this(cyg_quick)) {
306
                  return false;
307
              }
308
          }
309
          for (conf_i2 = deleted_structural_conflicts.begin(); conf_i2 != deleted_structural_conflicts.end(); conf_i2++) {
310
              if (!(*conf_i2)->check_this(cyg_quick)) {
311
                  return false;
312
              }
313
          }
314
          for (conf_i = global_conflicts_with_solutions.begin(); conf_i != global_conflicts_with_solutions.end(); conf_i++) {
315
              if (!(*conf_i)->check_this(cyg_quick)) {
316
                  return false;
317
              }
318
              if (0 != (*conf_i)->transaction) {
319
                  return false;
320
              }
321
          }
322
 
323
          // Nodes cannot have been both activated and deactivated in one transaction
324
          std::set<CdlNode>::const_iterator node_i;
325
          for (node_i = activated.begin(); node_i != activated.end(); node_i++) {
326
              if (!(*node_i)->check_this(cyg_quick)) {
327
                  return false;
328
              }
329
              if (deactivated.end() != deactivated.find(*node_i)) {
330
                  return false;
331
              }
332
          }
333
          for (node_i = deactivated.begin(); node_i != deactivated.end(); node_i++) {
334
              if (!(*node_i)->check_this(cyg_quick)) {
335
                  return false;
336
              }
337
              if (activated.end() != activated.find(*node_i)) {
338
                  return false;
339
              }
340
          }
341
          std::set<CdlValuable>::const_iterator val_i;
342
          for (val_i = legal_values_changes.begin(); val_i != legal_values_changes.end(); val_i++) {
343
              if (!(*val_i)->check_this(cyg_quick)) {
344
                  return false;
345
              }
346
          }
347
 
348
          std::deque<CdlValuable>::const_iterator val_i2;
349
          for (val_i2 = value_changes.begin(); val_i2 != value_changes.end(); val_i2++) {
350
              if (!(*val_i2)->check_this(cyg_quick)) {
351
                  return false;
352
              }
353
          }
354
 
355
          std::deque<CdlNode>::const_iterator active_i;
356
          for (active_i = active_changes.begin(); active_i != active_changes.end(); active_i++) {
357
              if (!(*active_i)->check_this(cyg_quick)) {
358
                  return false;
359
              }
360
          }
361
      }
362
      case cyg_thorough:
363
          if ((0 != toplevel) && !toplevel->check_this(cyg_quick)) {
364
              return false;
365
          }
366
          if ((0 != parent) && !parent->check_this(cyg_quick)) {
367
              return false;
368
          }
369
          if ((0 != conflict) && !conflict->check_this(cyg_quick)) {
370
              return false;
371
          }
372
 
373
      case cyg_quick:
374
      case cyg_trivial :
375
          if ((0 == toplevel) && (0 == parent)) {
376
              return false;
377
          }
378
          if (this == parent) {
379
              return false;
380
          }
381
 
382
      case cyg_none :
383
        break;
384
    }
385
 
386
    return true;
387
}
388
 
389
//}}}
390
//{{{  Misc                                     
391
 
392
// ----------------------------------------------------------------------------
393
CdlToplevel
394
CdlTransactionBody::get_toplevel() const
395
{
396
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_toplevel", "result %p");
397
    CYG_REPORT_FUNCARG1XV(this);
398
    CYG_PRECONDITION_THISC();
399
 
400
    CdlToplevel result = toplevel;
401
 
402
    CYG_REPORT_RETVAL(result);
403
    return result;
404
}
405
 
406
CdlTransaction
407
CdlTransactionBody::get_parent() const
408
{
409
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_parent", "result %p");
410
    CYG_REPORT_FUNCARG1XV(this);
411
    CYG_PRECONDITION_THISC();
412
 
413
    CdlTransaction result = parent;
414
 
415
    CYG_REPORT_RETVAL(result);
416
    return result;
417
}
418
 
419
CdlConflict
420
CdlTransactionBody::get_conflict() const
421
{
422
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_conflict", "result %p");
423
    CYG_REPORT_FUNCARG1XV(this);
424
    CYG_PRECONDITION_THISC();
425
 
426
    CdlConflict result = conflict;
427
 
428
    CYG_REPORT_RETVAL(result);
429
    return result;
430
}
431
 
432
 
433
// ----------------------------------------------------------------------------
434
void (*CdlTransactionBody::get_callback_fn())(const CdlTransactionCallback&)
435
{
436
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_callback_fn", "result %p");
437
 
438
    void (*result)(const CdlTransactionCallback&) = callback_fn;
439
 
440
    CYG_REPORT_RETVAL(result);
441
    return result;
442
}
443
 
444
void
445
CdlTransactionBody::set_callback_fn(void (*fn)(const CdlTransactionCallback&))
446
{
447
    CYG_REPORT_FUNCNAME("CdlTransaction::set_callback_fn");
448
    CYG_REPORT_FUNCARG1XV(fn);
449
 
450
    callback_fn = fn;
451
 
452
    CYG_REPORT_RETURN();
453
}
454
 
455
CdlInferenceCallback
456
CdlTransactionBody::get_inference_callback_fn()
457
{
458
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_inference_callback_fn", "result %p");
459
 
460
    CdlInferenceCallback result = inference_callback;
461
 
462
    CYG_REPORT_RETVAL(result);
463
    return result;
464
}
465
 
466
void
467
CdlTransactionBody::set_inference_callback_fn(CdlInferenceCallback fn)
468
{
469
    CYG_REPORT_FUNCNAME("CdlTransaction::set_inference_callback");
470
    CYG_REPORT_FUNCARG1XV(fn);
471
 
472
    inference_callback = fn;
473
 
474
    CYG_REPORT_RETURN();
475
}
476
 
477
void
478
CdlTransactionBody::enable_automatic_inference()
479
{
480
    CYG_REPORT_FUNCNAME("CdlTransaction::enable_automatic_inference");
481
 
482
    inference_enabled = true;
483
 
484
    CYG_REPORT_RETURN();
485
}
486
 
487
void
488
CdlTransactionBody::disable_automatic_inference()
489
{
490
    CYG_REPORT_FUNCNAME("CdlTransaction::disable_automatic_inference");
491
 
492
    inference_enabled = false;
493
 
494
    CYG_REPORT_RETURN();
495
}
496
 
497
bool
498
CdlTransactionBody::is_automatic_inference_enabled()
499
{
500
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::is_automatic_inference_enabled", "result %d");
501
 
502
    bool result = inference_enabled;
503
 
504
    CYG_REPORT_RETVAL(result);
505
    return result;
506
}
507
 
508
void
509
CdlTransactionBody::set_inference_recursion_limit(int limit)
510
{
511
    CYG_REPORT_FUNCNAME("CdlTransaction::set_inference_recursion_limit");
512
    CYG_REPORT_FUNCARG1XV(limit);
513
    CYG_PRECONDITIONC(0 < limit);
514
    CYG_PRECONDITIONC(limit < 16);    // arbitrary number
515
 
516
    inference_recursion_limit = limit;
517
 
518
    CYG_REPORT_RETURN();
519
}
520
 
521
int
522
CdlTransactionBody::get_inference_recursion_limit()
523
{
524
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_inference_recursion_limit", "result %d");
525
 
526
    int result = inference_recursion_limit;
527
 
528
    CYG_REPORT_RETVAL(result);
529
    return result;
530
}
531
 
532
void
533
CdlTransactionBody::set_inference_override(CdlValueSource source)
534
{
535
    CYG_REPORT_FUNCNAME("CdlTransaction::set_inference_override");
536
    CYG_REPORT_FUNCARG1XV(source);
537
    CYG_PRECONDITIONC((CdlValueSource_Invalid == source) || Cdl::is_valid_value_source(source));
538
 
539
    inference_override = source;
540
 
541
    CYG_REPORT_RETURN();
542
}
543
 
544
CdlValueSource
545
CdlTransactionBody::get_inference_override()
546
{
547
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_inference_override", "result %d");
548
 
549
    CdlValueSource result = inference_override;
550
 
551
    CYG_REPORT_RETVAL((int) result);
552
    return result;
553
}
554
 
555
//}}}
556
//{{{  Value access and updates                 
557
 
558
// ----------------------------------------------------------------------------
559
const CdlValue&
560
CdlTransactionBody::get_whole_value(CdlConstValuable valuable_arg) const
561
{
562
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_whole_value", "result %p");
563
    CYG_REPORT_FUNCARG2XV(this, valuable_arg);
564
    CYG_PRECONDITION_THISC();
565
    CYG_PRECONDITION_CLASSC(valuable_arg);
566
 
567
    // Unfortunately I need a valuable rather than a const-valuable when
568
    // accessing the STL containers.
569
    CdlValuable valuable = const_cast<CdlValuable>(valuable_arg);
570
 
571
    // If we are trying to find a solution, keep track of all valuables
572
    // that were accessed.
573
    const CdlValue* result = 0;
574
    if (0 != conflict) {
575
        conflict->solution_references.insert(valuable);
576
    }
577
 
578
    std::map<CdlValuable,CdlValue>::const_iterator val_i;
579
    val_i = changes.find(valuable);
580
    if (val_i != changes.end()) {
581
        result = &(val_i->second);
582
    } else if (0 != parent) {
583
        result = &(parent->get_whole_value(valuable));
584
    } else {
585
        result = &(valuable->get_whole_value());
586
    }
587
 
588
    CYG_REPORT_RETVAL(result);
589
    return *result;
590
}
591
 
592
void
593
CdlTransactionBody::set_whole_value(CdlValuable valuable, const CdlValue& old_value, const CdlValue& new_value)
594
{
595
    CYG_REPORT_FUNCNAME("CdlTransaction::set_whole_value");
596
    CYG_REPORT_FUNCARG3XV(this, valuable, &new_value);
597
    CYG_PRECONDITION_THISC();
598
    CYG_PRECONDITION_CLASSC(valuable);
599
    CYG_PRECONDITION_CLASSOC(old_value);
600
    CYG_PRECONDITION_CLASSOC(new_value);
601
    CYG_PRECONDITIONC(&old_value != &new_value);
602
 
603
    CdlValueFlavor flavor = old_value.get_flavor();
604
    CYG_ASSERTC(flavor == new_value.get_flavor());
605
    CYG_ASSERTC(CdlValueFlavor_None != flavor);
606
 
607
    bool value_changed = false;
608
    bool bool_changed  = false;
609
 
610
    if ((CdlValueFlavor_Bool == flavor) || (CdlValueFlavor_BoolData == flavor)) {
611
        if (old_value.is_enabled() != new_value.is_enabled()) {
612
            value_changed = true;
613
            bool_changed  = true;
614
        }
615
    }
616
    if (!value_changed && ((CdlValueFlavor_BoolData == flavor) || (CdlValueFlavor_Data == flavor))) {
617
        if (old_value.get_simple_value() != new_value.get_simple_value()) {
618
            value_changed = true;
619
        }
620
    }
621
    if (value_changed) {
622
        std::deque<CdlValuable>::const_iterator change_i;
623
        change_i = std::find(value_changes.begin(), value_changes.end(), valuable);
624
        if (change_i == value_changes.end()) {
625
            value_changes.push_back(valuable);
626
        }
627
    }
628
 
629
    // Actually do the update. This may modify old_value, so has to be
630
    // left to the end.
631
    changes[valuable] = new_value;
632
 
633
    // If there was a change to the boolean part of the value and the valuable
634
    // implements an interface, the interface value needs to be recalculated.
635
    if (bool_changed && valuable->has_property(CdlPropertyId_Implements)) {
636
        std::vector<CdlInterface> interfaces;
637
        std::vector<CdlInterface>::const_iterator interface_i;
638
        valuable->get_implemented_interfaces(interfaces);
639
        for (interface_i = interfaces.begin(); interface_i != interfaces.end(); interface_i++) {
640
            (*interface_i)->recalculate(this);
641
        }
642
    }
643
 
644
    CYG_REPORT_RETURN();
645
}
646
 
647
const std::map<CdlValuable, CdlValue>&
648
CdlTransactionBody::get_changes() const
649
{
650
    CYG_REPORT_FUNCNAME("CdlTransaction::get_changes");
651
    CYG_REPORT_FUNCARG1XV(this);
652
    CYG_PRECONDITION_THISC();
653
 
654
    CYG_REPORT_RETURN();
655
    return changes;
656
}
657
 
658
//}}}
659
//{{{  Active access and updates                
660
 
661
// ----------------------------------------------------------------------------
662
// Nodes can become active or inactive during transactions, and this affects
663
// propagation and expression evaluation
664
 
665
bool
666
CdlTransactionBody::is_active(CdlNode node) const
667
{
668
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::is_active", "result %d");
669
    CYG_REPORT_FUNCARG2XV(this, node);
670
    CYG_PRECONDITION_THISC();
671
    CYG_PRECONDITION_CLASSC(node);
672
 
673
    bool result = false;
674
    if (activated.end() != activated.find(node)) {
675
        result = true;
676
    } else if (deactivated.end() != deactivated.find(node)) {
677
        result = false;
678
    } else if (0 != parent) {
679
        result = parent->is_active(node);
680
    } else {
681
        result = node->is_active();
682
    }
683
 
684
    CYG_REPORT_RETVAL(result);
685
    return result;
686
}
687
 
688
void
689
CdlTransactionBody::set_active(CdlNode node, bool state)
690
{
691
    CYG_REPORT_FUNCNAME("CdlTransaction::set_active");
692
    CYG_REPORT_FUNCARG3XV(this, node, state);
693
    CYG_PRECONDITION_THISC();
694
    CYG_PRECONDITION_CLASSC(node);
695
 
696
    if (state) {
697
        activated.insert(node);
698
        std::set<CdlNode>::iterator node_i = deactivated.find(node);
699
        if (deactivated.end() != node_i) {
700
            deactivated.erase(node_i);
701
        }
702
    } else {
703
        deactivated.insert(node);
704
        std::set<CdlNode>::iterator node_i = activated.find(node);
705
        if (activated.end() != node_i) {
706
            activated.erase(node_i);
707
        }
708
    }
709
    active_changes.push_back(node);
710
 
711
    CdlValuable valuable = dynamic_cast<CdlValuable>(node);
712
    if ((0 != valuable) && valuable->has_property(CdlPropertyId_Implements)) {
713
        std::vector<CdlInterface> interfaces;
714
        std::vector<CdlInterface>::const_iterator interface_i;
715
        valuable->get_implemented_interfaces(interfaces);
716
        for (interface_i = interfaces.begin(); interface_i != interfaces.end(); interface_i++) {
717
            (*interface_i)->recalculate(this);
718
        }
719
    }
720
 
721
    CYG_REPORT_RETURN();
722
}
723
 
724
//}}}
725
//{{{  Conflict access and updates              
726
 
727
//{{{  get_conflict() etc.                      
728
 
729
// ----------------------------------------------------------------------------
730
bool
731
CdlTransactionBody::has_conflict(CdlNode node, bool (*pFn)(CdlConflict))
732
{
733
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::has_conflict", "result %d");
734
    CYG_REPORT_FUNCARG3XV(this, node, pFn);
735
    CYG_PRECONDITION_THISC();
736
    CYG_PRECONDITION_CLASSC(node);
737
 
738
    // Because it is necessary to check whether or not any given
739
    // conflict has been cleared in the current transaction or any
740
    // parent transaction, recursion into the parent is not
741
    // appropriate.
742
    bool result = false;
743
    std::list<CdlConflict>::const_iterator conf_i;
744
    CdlTransaction current_transaction = this;
745
    CdlToplevel    toplevel            = this->toplevel;
746
    do {
747
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
748
 
749
        for (conf_i = current_transaction->new_conflicts.begin();
750
             conf_i != current_transaction->new_conflicts.end();
751
             conf_i++) {
752
 
753
            if ((node == (*conf_i)->get_node()) &&
754
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
755
                result = true;
756
                break;
757
            }
758
        }
759
 
760
        toplevel            = current_transaction->toplevel;
761
        current_transaction = current_transaction->parent;
762
    } while (!result && (0 != current_transaction));
763
 
764
    if (!result) {
765
        CYG_ASSERT_CLASSC(toplevel);
766
        for (conf_i = toplevel->conflicts.begin(); conf_i != toplevel->conflicts.end(); conf_i++) {
767
            if ((node == (*conf_i)->get_node()) && !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
768
                result = true;
769
                break;
770
            }
771
        }
772
    }
773
 
774
    CYG_REPORT_RETVAL(result);
775
    return result;
776
}
777
 
778
CdlConflict
779
CdlTransactionBody::get_conflict(CdlNode node, bool (*pFn)(CdlConflict))
780
{
781
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_conflict", "result %p");
782
    CYG_REPORT_FUNCARG3XV(this, node, pFn);
783
    CYG_PRECONDITION_THISC();
784
    CYG_PRECONDITION_CLASSC(node);
785
 
786
    CdlConflict result = 0;
787
    std::list<CdlConflict>::const_iterator conf_i;
788
    CdlTransaction current_transaction = this;
789
    CdlToplevel    toplevel            = this->toplevel;
790
    do {
791
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
792
 
793
        for (conf_i = current_transaction->new_conflicts.begin();
794
             conf_i != current_transaction->new_conflicts.end();
795
             conf_i++) {
796
 
797
            if ((node == (*conf_i)->get_node()) &&
798
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
799
                result = *conf_i;
800
                break;
801
            }
802
        }
803
 
804
        toplevel            = current_transaction->toplevel;
805
        current_transaction = current_transaction->parent;
806
    } while ((0 == result) && (0 != current_transaction));
807
 
808
    if (0 == result) {
809
        CYG_ASSERT_CLASSC(toplevel);
810
        for (conf_i = toplevel->conflicts.begin(); conf_i != toplevel->conflicts.end(); conf_i++) {
811
            if ((node == (*conf_i)->get_node()) && !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
812
                result = *conf_i;
813
                break;
814
            }
815
        }
816
    }
817
 
818
    CYG_REPORT_RETVAL(result);
819
    return result;
820
}
821
 
822
void
823
CdlTransactionBody::get_conflicts(CdlNode node, bool (*pFn)(CdlConflict), std::vector<CdlConflict>& result)
824
{
825
    CYG_REPORT_FUNCNAME("CdlTransaction::get_conflicts");
826
    CYG_REPORT_FUNCARG3XV(this, node, pFn);
827
    CYG_PRECONDITION_THISC();
828
    CYG_PRECONDITION_CLASSC(node);
829
 
830
    std::list<CdlConflict>::const_iterator conf_i;
831
    CdlTransaction current_transaction = this;
832
    CdlToplevel    toplevel            = this->toplevel;
833
    do {
834
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
835
 
836
        for (conf_i = current_transaction->new_conflicts.begin();
837
             conf_i != current_transaction->new_conflicts.end();
838
             conf_i++) {
839
 
840
            if ((node == (*conf_i)->get_node()) &&
841
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
842
                result.push_back(*conf_i);
843
            }
844
        }
845
 
846
        toplevel            = current_transaction->toplevel;
847
        current_transaction = current_transaction->parent;
848
    } while (0 != current_transaction);
849
 
850
    CYG_ASSERT_CLASSC(toplevel);
851
    for (conf_i = toplevel->conflicts.begin(); conf_i != toplevel->conflicts.end(); conf_i++) {
852
        if ((node == (*conf_i)->get_node()) && !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
853
            result.push_back(*conf_i);
854
        }
855
    }
856
 
857
    CYG_REPORT_RETURN();
858
}
859
 
860
bool
861
CdlTransactionBody::has_conflict(CdlNode node, CdlProperty prop, bool (*pFn)(CdlConflict))
862
{
863
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::has_conflict", "result %d");
864
    CYG_REPORT_FUNCARG4XV(this, node, prop, pFn);
865
    CYG_PRECONDITION_THISC();
866
    CYG_PRECONDITION_CLASSC(node);
867
    CYG_PRECONDITION_CLASSC(prop);
868
 
869
    bool result = false;
870
    std::list<CdlConflict>::const_iterator conf_i;
871
    CdlTransaction current_transaction = this;
872
    CdlToplevel    toplevel            = this->toplevel;
873
    do {
874
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
875
 
876
        for (conf_i = current_transaction->new_conflicts.begin();
877
             conf_i != current_transaction->new_conflicts.end();
878
             conf_i++) {
879
 
880
            if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
881
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
882
 
883
                result = true;
884
                break;
885
            }
886
        }
887
 
888
        toplevel            = current_transaction->toplevel;
889
        current_transaction = current_transaction->parent;
890
    } while (!result && (0 != current_transaction));
891
 
892
    if (!result) {
893
        CYG_ASSERT_CLASSC(toplevel);
894
        for (conf_i = toplevel->conflicts.begin(); conf_i != toplevel->conflicts.end(); conf_i++) {
895
            if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
896
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
897
 
898
                result = true;
899
                break;
900
            }
901
        }
902
    }
903
 
904
    CYG_REPORT_RETVAL(result);
905
    return result;
906
}
907
 
908
CdlConflict
909
CdlTransactionBody::get_conflict(CdlNode node, CdlProperty prop, bool (*pFn)(CdlConflict))
910
{
911
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_conflict", "result %p");
912
    CYG_REPORT_FUNCARG4XV(this, node, prop, pFn);
913
    CYG_PRECONDITION_THISC();
914
    CYG_PRECONDITION_CLASSC(node);
915
    CYG_PRECONDITION_CLASSC(prop);
916
 
917
    CdlConflict result = 0;
918
    std::list<CdlConflict>::const_iterator conf_i;
919
    CdlTransaction current_transaction = this;
920
    CdlToplevel    toplevel            = this->toplevel;
921
    do {
922
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
923
 
924
        for (conf_i = current_transaction->new_conflicts.begin();
925
             conf_i != current_transaction->new_conflicts.end();
926
             conf_i++) {
927
 
928
            if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
929
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
930
                result = *conf_i;
931
                break;
932
            }
933
        }
934
 
935
        toplevel            = current_transaction->toplevel;
936
        current_transaction = current_transaction->parent;
937
    } while ((0 == result) && (0 != current_transaction));
938
 
939
    if (0 == result) {
940
        CYG_ASSERT_CLASSC(toplevel);
941
        for (conf_i = toplevel->conflicts.begin(); conf_i != toplevel->conflicts.end(); conf_i++) {
942
            if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
943
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
944
 
945
                result = *conf_i;
946
                break;
947
            }
948
        }
949
    }
950
 
951
    CYG_REPORT_RETVAL(result);
952
    return result;
953
}
954
 
955
void
956
CdlTransactionBody::get_conflicts(CdlNode node, CdlProperty prop, bool (*pFn)(CdlConflict), std::vector<CdlConflict>& result)
957
{
958
    CYG_REPORT_FUNCNAME("CdlTransaction::get_conflict");
959
    CYG_REPORT_FUNCARG4XV(this, node, prop, pFn);
960
    CYG_PRECONDITION_THISC();
961
    CYG_PRECONDITION_CLASSC(node);
962
    CYG_PRECONDITION_CLASSC(prop);
963
 
964
    std::list<CdlConflict>::const_iterator conf_i;
965
    CdlTransaction current_transaction = this;
966
    CdlToplevel    toplevel            = this->toplevel;
967
    do {
968
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
969
 
970
        for (conf_i = current_transaction->new_conflicts.begin();
971
             conf_i != current_transaction->new_conflicts.end();
972
             conf_i++) {
973
 
974
            if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
975
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
976
                result.push_back(*conf_i);
977
            }
978
        }
979
 
980
        toplevel            = current_transaction->toplevel;
981
        current_transaction = current_transaction->parent;
982
    } while (0 != current_transaction);
983
 
984
    CYG_ASSERT_CLASSC(toplevel);
985
    for (conf_i = toplevel->conflicts.begin(); conf_i != toplevel->conflicts.end(); conf_i++) {
986
        if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
987
            !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
988
 
989
            result.push_back(*conf_i);
990
        }
991
    }
992
 
993
    CYG_REPORT_RETURN();
994
}
995
 
996
//}}}
997
//{{{  get_structural_conflict() etc            
998
 
999
// ----------------------------------------------------------------------------
1000
bool
1001
CdlTransactionBody::has_structural_conflict(CdlNode node, bool (*pFn)(CdlConflict))
1002
{
1003
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::has_structural_conflict", "result %d");
1004
    CYG_REPORT_FUNCARG3XV(this, node, pFn);
1005
    CYG_PRECONDITION_THISC();
1006
    CYG_PRECONDITION_CLASSC(node);
1007
 
1008
    // Because it is necessary to check whether or not any given
1009
    // conflict has been cleared in the current transaction or any
1010
    // parent transaction, recursion into the parent is not
1011
    // appropriate.
1012
    bool result = false;
1013
    std::list<CdlConflict>::const_iterator conf_i;
1014
    CdlTransaction current_transaction = this;
1015
    CdlToplevel    toplevel            = this->toplevel;
1016
    do {
1017
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
1018
 
1019
        for (conf_i = current_transaction->new_structural_conflicts.begin();
1020
             conf_i != current_transaction->new_structural_conflicts.end();
1021
             conf_i++) {
1022
 
1023
            if ((node == (*conf_i)->get_node()) &&
1024
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1025
                result = true;
1026
                break;
1027
            }
1028
        }
1029
 
1030
        toplevel            = current_transaction->toplevel;
1031
        current_transaction = current_transaction->parent;
1032
    } while (!result && (0 != current_transaction));
1033
 
1034
    if (!result) {
1035
        CYG_ASSERT_CLASSC(toplevel);
1036
        for (conf_i = toplevel->structural_conflicts.begin(); conf_i != toplevel->structural_conflicts.end(); conf_i++) {
1037
            if ((node == (*conf_i)->get_node()) && !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1038
                result = true;
1039
                break;
1040
            }
1041
        }
1042
    }
1043
 
1044
    CYG_REPORT_RETVAL(result);
1045
    return result;
1046
}
1047
 
1048
CdlConflict
1049
CdlTransactionBody::get_structural_conflict(CdlNode node, bool (*pFn)(CdlConflict))
1050
{
1051
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_structural_conflict", "result %p");
1052
    CYG_REPORT_FUNCARG3XV(this, node, pFn);
1053
    CYG_PRECONDITION_THISC();
1054
    CYG_PRECONDITION_CLASSC(node);
1055
 
1056
    CdlConflict result = 0;
1057
    std::list<CdlConflict>::const_iterator conf_i;
1058
    CdlTransaction current_transaction = this;
1059
    CdlToplevel    toplevel            = this->toplevel;
1060
    do {
1061
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
1062
 
1063
        for (conf_i = current_transaction->new_structural_conflicts.begin();
1064
             conf_i != current_transaction->new_structural_conflicts.end();
1065
             conf_i++) {
1066
 
1067
            if ((node == (*conf_i)->get_node()) &&
1068
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1069
                result = *conf_i;
1070
                break;
1071
            }
1072
        }
1073
 
1074
        toplevel            = current_transaction->toplevel;
1075
        current_transaction = current_transaction->parent;
1076
    } while ((0 == result) && (0 != current_transaction));
1077
 
1078
    if (0 == result) {
1079
        CYG_ASSERT_CLASSC(toplevel);
1080
        for (conf_i = toplevel->structural_conflicts.begin(); conf_i != toplevel->structural_conflicts.end(); conf_i++) {
1081
            if ((node == (*conf_i)->get_node()) && !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1082
                result = *conf_i;
1083
                break;
1084
            }
1085
        }
1086
    }
1087
 
1088
    CYG_REPORT_RETVAL(result);
1089
    return result;
1090
}
1091
 
1092
void
1093
CdlTransactionBody::get_structural_conflicts(CdlNode node, bool (*pFn)(CdlConflict), std::vector<CdlConflict>& result)
1094
{
1095
    CYG_REPORT_FUNCNAME("CdlTransaction::get_structural_conflicts");
1096
    CYG_REPORT_FUNCARG3XV(this, node, pFn);
1097
    CYG_PRECONDITION_THISC();
1098
    CYG_PRECONDITION_CLASSC(node);
1099
 
1100
    std::list<CdlConflict>::const_iterator conf_i;
1101
    CdlTransaction current_transaction = this;
1102
    CdlToplevel    toplevel            = this->toplevel;
1103
    do {
1104
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
1105
 
1106
        for (conf_i = current_transaction->new_structural_conflicts.begin();
1107
             conf_i != current_transaction->new_structural_conflicts.end();
1108
             conf_i++) {
1109
 
1110
            if ((node == (*conf_i)->get_node()) &&
1111
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1112
                result.push_back(*conf_i);
1113
            }
1114
        }
1115
 
1116
        toplevel            = current_transaction->toplevel;
1117
        current_transaction = current_transaction->parent;
1118
    } while (0 != current_transaction);
1119
 
1120
    CYG_ASSERT_CLASSC(toplevel);
1121
    for (conf_i = toplevel->structural_conflicts.begin(); conf_i != toplevel->structural_conflicts.end(); conf_i++) {
1122
        if ((node == (*conf_i)->get_node()) && !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1123
            result.push_back(*conf_i);
1124
        }
1125
    }
1126
 
1127
    CYG_REPORT_RETURN();
1128
}
1129
 
1130
bool
1131
CdlTransactionBody::has_structural_conflict(CdlNode node, CdlProperty prop, bool (*pFn)(CdlConflict))
1132
{
1133
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::has_structural_conflict", "result %d");
1134
    CYG_REPORT_FUNCARG4XV(this, node, prop, pFn);
1135
    CYG_PRECONDITION_THISC();
1136
    CYG_PRECONDITION_CLASSC(node);
1137
    CYG_PRECONDITION_CLASSC(prop);
1138
 
1139
    bool result = false;
1140
    std::list<CdlConflict>::const_iterator conf_i;
1141
    CdlTransaction current_transaction = this;
1142
    CdlToplevel    toplevel            = this->toplevel;
1143
    do {
1144
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
1145
 
1146
        for (conf_i = current_transaction->new_structural_conflicts.begin();
1147
             conf_i != current_transaction->new_structural_conflicts.end();
1148
             conf_i++) {
1149
 
1150
            if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
1151
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1152
 
1153
                result = true;
1154
                break;
1155
            }
1156
        }
1157
 
1158
        toplevel            = current_transaction->toplevel;
1159
        current_transaction = current_transaction->parent;
1160
    } while (!result && (0 != current_transaction));
1161
 
1162
    if (!result) {
1163
        CYG_ASSERT_CLASSC(toplevel);
1164
        for (conf_i = toplevel->structural_conflicts.begin(); conf_i != toplevel->structural_conflicts.end(); conf_i++) {
1165
            if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
1166
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1167
 
1168
                result = true;
1169
                break;
1170
            }
1171
        }
1172
    }
1173
 
1174
    CYG_REPORT_RETVAL(result);
1175
    return result;
1176
}
1177
 
1178
CdlConflict
1179
CdlTransactionBody::get_structural_conflict(CdlNode node, CdlProperty prop, bool (*pFn)(CdlConflict))
1180
{
1181
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_structural_conflict", "result %p");
1182
    CYG_REPORT_FUNCARG4XV(this, node, prop, pFn);
1183
    CYG_PRECONDITION_THISC();
1184
    CYG_PRECONDITION_CLASSC(node);
1185
    CYG_PRECONDITION_CLASSC(prop);
1186
 
1187
    CdlConflict result = 0;
1188
    std::list<CdlConflict>::const_iterator conf_i;
1189
    CdlTransaction current_transaction = this;
1190
    CdlToplevel    toplevel            = this->toplevel;
1191
    do {
1192
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
1193
 
1194
        for (conf_i = current_transaction->new_structural_conflicts.begin();
1195
             conf_i != current_transaction->new_structural_conflicts.end();
1196
             conf_i++) {
1197
 
1198
            if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
1199
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1200
                result = *conf_i;
1201
                break;
1202
            }
1203
        }
1204
 
1205
        toplevel            = current_transaction->toplevel;
1206
        current_transaction = current_transaction->parent;
1207
    } while ((0 == result) && (0 != current_transaction));
1208
 
1209
    if (0 == result) {
1210
        CYG_ASSERT_CLASSC(toplevel);
1211
        for (conf_i = toplevel->structural_conflicts.begin(); conf_i != toplevel->structural_conflicts.end(); conf_i++) {
1212
            if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
1213
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1214
 
1215
                result = *conf_i;
1216
                break;
1217
            }
1218
        }
1219
    }
1220
 
1221
    CYG_REPORT_RETVAL(result);
1222
    return result;
1223
}
1224
 
1225
void
1226
CdlTransactionBody::get_structural_conflicts(CdlNode node, CdlProperty prop, bool (*pFn)(CdlConflict),
1227
                                             std::vector<CdlConflict>& result)
1228
{
1229
    CYG_REPORT_FUNCNAME("CdlTransaction::get_structural_conflict");
1230
    CYG_REPORT_FUNCARG4XV(this, node, prop, pFn);
1231
    CYG_PRECONDITION_THISC();
1232
    CYG_PRECONDITION_CLASSC(node);
1233
    CYG_PRECONDITION_CLASSC(prop);
1234
 
1235
    std::list<CdlConflict>::const_iterator conf_i;
1236
    CdlTransaction current_transaction = this;
1237
    CdlToplevel    toplevel            = this->toplevel;
1238
    do {
1239
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
1240
 
1241
        for (conf_i = current_transaction->new_structural_conflicts.begin();
1242
             conf_i != current_transaction->new_structural_conflicts.end();
1243
             conf_i++) {
1244
 
1245
            if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
1246
                !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1247
                result.push_back(*conf_i);
1248
            }
1249
        }
1250
 
1251
        toplevel            = current_transaction->toplevel;
1252
        current_transaction = current_transaction->parent;
1253
    } while (0 != current_transaction);
1254
 
1255
    CYG_ASSERT_CLASSC(toplevel);
1256
    for (conf_i = toplevel->structural_conflicts.begin(); conf_i != toplevel->structural_conflicts.end(); conf_i++) {
1257
        if ((node == (*conf_i)->get_node()) && (prop == (*conf_i)->get_property()) &&
1258
            !(this->has_conflict_been_cleared(*conf_i)) && (*pFn)(*conf_i)) {
1259
 
1260
            result.push_back(*conf_i);
1261
        }
1262
    }
1263
 
1264
    CYG_REPORT_RETURN();
1265
}
1266
 
1267
//}}}
1268
//{{{  clear_conflicts()                        
1269
 
1270
// ----------------------------------------------------------------------------
1271
// Clearing a conflict. This can only happen in the context of a
1272
// transaction.
1273
void
1274
CdlTransactionBody::clear_conflicts(CdlNode node, bool (*pFn)(CdlConflict))
1275
{
1276
    CYG_REPORT_FUNCNAME("CdlTransaction::clear_conflicts");
1277
    CYG_REPORT_FUNCARG3XV(this, node, pFn);
1278
    CYG_PRECONDITION_THISC();
1279
    CYG_PRECONDITION_CLASSC(node);
1280
 
1281
    // Recursing into the parent is the wrong thing to do here, it
1282
    // would result in the conflict being cleared in the parent rather
1283
    // than in the current transaction.
1284
    std::list<CdlConflict>::iterator conf_i;
1285
    CdlTransaction current_transaction = this;
1286
    CdlToplevel    toplevel            = this->toplevel;
1287
    do {
1288
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
1289
 
1290
        for (conf_i = current_transaction->new_conflicts.begin(); conf_i != current_transaction->new_conflicts.end(); ) {
1291
            CdlConflict conflict = *conf_i++;
1292
            if ((node == conflict->get_node()) && !(this->has_conflict_been_cleared(conflict)) && (*pFn)(conflict)) {
1293
                this->clear_conflict(conflict);
1294
            }
1295
        }
1296
        toplevel = current_transaction->toplevel;
1297
        current_transaction = current_transaction->parent;
1298
    } while (0 != current_transaction);
1299
 
1300
    CYG_ASSERT_CLASSC(toplevel);
1301
    for (conf_i = toplevel->conflicts.begin(); conf_i != toplevel->conflicts.end(); ) {
1302
        CdlConflict conflict = *conf_i++;
1303
        if ((node == conflict->get_node()) && !(this->has_conflict_been_cleared(conflict)) && (*pFn)(conflict)) {
1304
            this->clear_conflict(conflict);
1305
        }
1306
    }
1307
 
1308
    CYG_REPORT_RETURN();
1309
}
1310
 
1311
void
1312
CdlTransactionBody::clear_conflicts(CdlNode node, CdlProperty prop, bool (*pFn)(CdlConflict))
1313
{
1314
    CYG_REPORT_FUNCNAME("CdlTransaction::clear_conflicts");
1315
    CYG_REPORT_FUNCARG4XV(this, node, prop, pFn);
1316
    CYG_PRECONDITION_THISC();
1317
    CYG_PRECONDITION_CLASSC(node);
1318
 
1319
    std::list<CdlConflict>::iterator conf_i;
1320
    CdlTransaction current_transaction = this;
1321
    CdlToplevel    toplevel            = this->toplevel;
1322
    do {
1323
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
1324
 
1325
        for (conf_i = current_transaction->new_conflicts.begin(); conf_i != current_transaction->new_conflicts.end(); ) {
1326
            CdlConflict conflict = *conf_i++;
1327
            if ((node == conflict->get_node()) && (prop == conflict->get_property()) &&
1328
                !(this->has_conflict_been_cleared(conflict)) && (*pFn)(conflict)) {
1329
                this->clear_conflict(conflict);
1330
            }
1331
        }
1332
        toplevel = current_transaction->toplevel;
1333
        current_transaction = current_transaction->parent;
1334
    } while (0 != current_transaction);
1335
 
1336
    CYG_ASSERT_CLASSC(toplevel);
1337
    for (conf_i = toplevel->conflicts.begin(); conf_i != toplevel->conflicts.end(); ) {
1338
        CdlConflict conflict = *conf_i++;
1339
        if ((node == conflict->get_node()) && (prop == conflict->get_property()) &&
1340
            !(this->has_conflict_been_cleared(conflict)) && (*pFn)(conflict)) {
1341
            this->clear_conflict(conflict);
1342
        }
1343
    }
1344
 
1345
    CYG_REPORT_RETURN();
1346
}
1347
 
1348
void
1349
CdlTransactionBody::clear_structural_conflicts(CdlNode node, bool (*pFn)(CdlConflict))
1350
{
1351
    CYG_REPORT_FUNCNAME("CdlTransaction::clear_structural_conflicts");
1352
    CYG_REPORT_FUNCARG3XV(this, node, pFn);
1353
    CYG_PRECONDITION_THISC();
1354
    CYG_PRECONDITION_CLASSC(node);
1355
 
1356
    std::list<CdlConflict>::iterator conf_i;
1357
    CdlTransaction current_transaction = this;
1358
    CdlToplevel    toplevel            = this->toplevel;
1359
    do {
1360
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
1361
 
1362
        for (conf_i = current_transaction->new_structural_conflicts.begin();
1363
             conf_i != current_transaction->new_structural_conflicts.end();
1364
            ) {
1365
 
1366
            CdlConflict conflict = *conf_i++;
1367
            if ((node == conflict->get_node()) && !(this->has_conflict_been_cleared(conflict)) && (*pFn)(conflict)) {
1368
                this->clear_conflict(conflict);
1369
            }
1370
        }
1371
        toplevel = current_transaction->toplevel;
1372
        current_transaction = current_transaction->parent;
1373
    } while (0 != current_transaction);
1374
 
1375
    CYG_ASSERT_CLASSC(toplevel);
1376
    for (conf_i = toplevel->structural_conflicts.begin(); conf_i != toplevel->structural_conflicts.end(); ) {
1377
        CdlConflict conflict = *conf_i++;
1378
        if ((node == conflict->get_node()) && !(this->has_conflict_been_cleared(conflict)) && (*pFn)(conflict)) {
1379
            this->clear_conflict(conflict);
1380
        }
1381
    }
1382
 
1383
    CYG_REPORT_RETURN();
1384
}
1385
 
1386
void
1387
CdlTransactionBody::clear_structural_conflicts(CdlNode node, CdlProperty prop, bool (*pFn)(CdlConflict))
1388
{
1389
    CYG_REPORT_FUNCNAME("CdlTransaction::clear_structural_conflicts");
1390
    CYG_REPORT_FUNCARG4XV(this, node, prop, pFn);
1391
    CYG_PRECONDITION_THISC();
1392
    CYG_PRECONDITION_CLASSC(node);
1393
 
1394
    std::list<CdlConflict>::iterator conf_i;
1395
    CdlTransaction current_transaction = this;
1396
    CdlToplevel    toplevel            = this->toplevel;
1397
    do {
1398
        CYG_LOOP_INVARIANT_CLASSC(current_transaction);
1399
 
1400
        for (conf_i = current_transaction->new_structural_conflicts.begin();
1401
             conf_i != current_transaction->new_structural_conflicts.end();
1402
            ) {
1403
 
1404
            CdlConflict conflict = *conf_i++;
1405
            if ((node == conflict->get_node()) && (prop == conflict->get_property()) &&
1406
                !(this->has_conflict_been_cleared(conflict)) && (*pFn)(conflict)) {
1407
 
1408
                this->clear_conflict(conflict);
1409
            }
1410
        }
1411
        toplevel = current_transaction->toplevel;
1412
        current_transaction = current_transaction->parent;
1413
    } while (0 != current_transaction);
1414
 
1415
    CYG_ASSERT_CLASSC(toplevel);
1416
    for (conf_i = toplevel->structural_conflicts.begin(); conf_i != toplevel->structural_conflicts.end(); ) {
1417
        CdlConflict conflict = *conf_i++;
1418
        if ((node == conflict->get_node()) && (prop == conflict->get_property()) &&
1419
            !(this->has_conflict_been_cleared(conflict)) && (*pFn)(conflict)) {
1420
            this->clear_conflict(conflict);
1421
        }
1422
    }
1423
 
1424
    CYG_REPORT_RETURN();
1425
}
1426
 
1427
//}}}
1428
//{{{  clear_conflict()                         
1429
 
1430
// ----------------------------------------------------------------------------
1431
void
1432
CdlTransactionBody::clear_conflict(CdlConflict conflict)
1433
{
1434
    CYG_REPORT_FUNCNAME("CdlTransaction::clear_conflict");
1435
    CYG_REPORT_FUNCARG2XV(this, conflict);
1436
    CYG_PRECONDITION_THISC();
1437
    CYG_PRECONDITION_CLASSC(conflict);
1438
 
1439
    // If this conflict was created during the transaction, it should
1440
    // be on the new_conflicts or new_structural_conflicts container
1441
    if (this == conflict->transaction) {
1442
        // The conflict should be on one of the two new_conflicts deques.
1443
        if (conflict->structural) {
1444
            std::list<CdlConflict>::iterator conf_i = std::find(new_structural_conflicts.begin(),
1445
                                                                  new_structural_conflicts.end(), conflict);
1446
            CYG_ASSERTC(conf_i != new_structural_conflicts.end());
1447
            new_structural_conflicts.erase(conf_i);
1448
        } else {
1449
            std::list<CdlConflict>::iterator conf_i = std::find(new_conflicts.begin(), new_conflicts.end(), conflict);
1450
            CYG_ASSERTC(conf_i != new_conflicts.end());
1451
            new_conflicts.erase(conf_i);
1452
        }
1453
        delete conflict;
1454
 
1455
    } else {
1456
        if (conflict->structural) {
1457
            deleted_structural_conflicts.push_back(conflict);
1458
        } else {
1459
            deleted_conflicts.push_back(conflict);
1460
        }
1461
    }
1462
 
1463
    CYG_REPORT_RETURN();
1464
}
1465
 
1466
// ----------------------------------------------------------------------------
1467
bool
1468
CdlTransactionBody::has_conflict_been_cleared(CdlConflict conf)
1469
{
1470
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::has_conflict_been_cleared", "result %d");
1471
    CYG_REPORT_FUNCARG2XV(this, conf);
1472
    CYG_PRECONDITION_THISC();
1473
    CYG_PRECONDITION_CLASSC(conf);
1474
 
1475
    bool result = false;
1476
    CdlTransaction current_transaction = this;
1477
    do {
1478
        if (conf->structural) {
1479
            if (std::find(current_transaction->deleted_structural_conflicts.begin(),
1480
                          current_transaction->deleted_structural_conflicts.end(), conf) !=
1481
                current_transaction->deleted_structural_conflicts.end()) {
1482
 
1483
                result = true;
1484
            }
1485
        } else {
1486
            if (std::find(current_transaction->deleted_conflicts.begin(), current_transaction->deleted_conflicts.end(),
1487
                          conf) != current_transaction->deleted_conflicts.end()) {
1488
                result = true;
1489
            }
1490
        }
1491
 
1492
        current_transaction = current_transaction->parent;
1493
    } while (!result && (0 != current_transaction));
1494
 
1495
    CYG_REPORT_RETVAL(result);
1496
    return result;
1497
}
1498
 
1499
//}}}
1500
//{{{  per-transaction data                     
1501
 
1502
// ----------------------------------------------------------------------------
1503
// Accessing the per-transaction conflict data.
1504
 
1505
const std::list<CdlConflict>&
1506
CdlTransactionBody::get_new_conflicts() const
1507
{
1508
    CYG_REPORT_FUNCNAME("CdlTransaction::get_new_conflicts");
1509
    CYG_REPORT_FUNCARG1XV(this);
1510
    CYG_PRECONDITION_THISC();
1511
 
1512
    CYG_REPORT_RETURN();
1513
    return new_conflicts;
1514
}
1515
 
1516
const std::list<CdlConflict>&
1517
CdlTransactionBody::get_new_structural_conflicts() const
1518
{
1519
    CYG_REPORT_FUNCNAME("CdlTransaction::get_new_structural_conflicts");
1520
    CYG_REPORT_FUNCARG1XV(this);
1521
    CYG_PRECONDITION_THISC();
1522
 
1523
    CYG_REPORT_RETURN();
1524
    return new_structural_conflicts;
1525
}
1526
 
1527
const std::vector<CdlConflict>&
1528
CdlTransactionBody::get_deleted_conflicts() const
1529
{
1530
    CYG_REPORT_FUNCNAME("CdlTransaction::get_deleted_conflicts");
1531
    CYG_REPORT_FUNCARG1XV(this);
1532
    CYG_PRECONDITION_THISC();
1533
 
1534
    CYG_REPORT_RETURN();
1535
    return deleted_conflicts;
1536
}
1537
 
1538
const std::vector<CdlConflict>&
1539
CdlTransactionBody::get_deleted_structural_conflicts() const
1540
{
1541
    CYG_REPORT_FUNCNAME("CdlTransaction::get_deleted_structural_conflicts");
1542
    CYG_REPORT_FUNCARG1XV(this);
1543
    CYG_PRECONDITION_THISC();
1544
 
1545
    CYG_REPORT_RETURN();
1546
    return deleted_structural_conflicts;
1547
}
1548
 
1549
const std::vector<CdlConflict>&
1550
CdlTransactionBody::get_resolved_conflicts() const
1551
{
1552
    CYG_REPORT_FUNCNAME("CdlTransaction::get_resolved_conflicts");
1553
    CYG_REPORT_FUNCARG1XV(this);
1554
    CYG_PRECONDITION_THISC();
1555
 
1556
    CYG_REPORT_RETURN();
1557
    return resolved_conflicts;
1558
}
1559
 
1560
const std::list<CdlConflict>&
1561
CdlTransactionBody::get_global_conflicts_with_solutions() const
1562
{
1563
    CYG_REPORT_FUNCNAME("CdlTransaction::get_global_conflicts_with_solutions");
1564
    CYG_REPORT_FUNCARG1XV(this);
1565
    CYG_PRECONDITION_THISC();
1566
 
1567
    CYG_REPORT_RETURN();
1568
    return global_conflicts_with_solutions;
1569
}
1570
 
1571
//}}}
1572
 
1573
//}}}
1574
//{{{  Commit/cancel operations                 
1575
 
1576
// ----------------------------------------------------------------------------
1577
void
1578
CdlTransactionBody::add_commit_cancel_op(CdlTransactionCommitCancelOp* op)
1579
{
1580
    CYG_REPORT_FUNCNAME("CdlTransaction::add_commit_cancel_op");
1581
    CYG_REPORT_FUNCARG2XV(this, op);
1582
    CYG_PRECONDITION_THISC();
1583
    CYG_PRECONDITIONC(0 != op);
1584
 
1585
    commit_cancel_ops.push_back(op);
1586
 
1587
    CYG_REPORT_RETURN();
1588
}
1589
 
1590
void
1591
CdlTransactionBody::cancel_last_commit_cancel_op()
1592
{
1593
    CYG_REPORT_FUNCNAME("CdlTransaction::cancel_last_commit_cancel_op");
1594
    CYG_REPORT_FUNCARG1XV(this);
1595
    CYG_PRECONDITION_THISC();
1596
 
1597
    CdlTransactionCommitCancelOp* op = *(commit_cancel_ops.rbegin());
1598
    commit_cancel_ops.pop_back();
1599
    op->cancel(this);
1600
    delete op;
1601
 
1602
    CYG_REPORT_RETURN();
1603
}
1604
 
1605
CdlTransactionCommitCancelOp*
1606
CdlTransactionBody::get_last_commit_cancel_op() const
1607
{
1608
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::get_last_commit_cancel_op", "result %p");
1609
    CYG_REPORT_FUNCARG1XV(this);
1610
    CYG_PRECONDITION_THISC();
1611
 
1612
    CdlTransactionCommitCancelOp* op = *(commit_cancel_ops.rbegin());
1613
 
1614
    CYG_REPORT_RETVAL(op);
1615
    return op;
1616
}
1617
 
1618
const std::vector<CdlTransactionCommitCancelOp*>&
1619
CdlTransactionBody::get_commit_cancel_ops() const
1620
{
1621
    CYG_REPORT_FUNCNAME("CdlTransaction::get_commit_cancel_ops");
1622
    CYG_REPORT_FUNCARG1XV(this);
1623
    CYG_PRECONDITION_THISC();
1624
 
1625
    CYG_REPORT_RETURN();
1626
    return commit_cancel_ops;
1627
}
1628
 
1629
//}}}
1630
//{{{  Propagation                              
1631
 
1632
// ----------------------------------------------------------------------------
1633
// Propagation should happen whenever one or more changes have been applied,
1634
// so that the impact of these changes on other parts of the configuration
1635
// can be fully assessed. The transaction keeps track of all the changes
1636
// to date and invokes appropriate node and property update handlers.
1637
 
1638
void
1639
CdlTransactionBody::propagate()
1640
{
1641
    CYG_REPORT_FUNCNAME("CdlTransaction::propagate");
1642
    CYG_REPORT_FUNCARG1XV(this);
1643
    CYG_INVARIANT_THISC(CdlTransactionBody);
1644
 
1645
    // Now it is time to worry about value and active changes.
1646
    // Propagation may result in new entries, so only the
1647
    // front item of one of the vectors is modified.
1648
    while ((0 < value_changes.size()) || (0 < active_changes.size())) {
1649
 
1650
        if (0 != value_changes.size()) {
1651
 
1652
            CdlValuable valuable = value_changes.front();
1653
            value_changes.pop_front();
1654
 
1655
            // A value change may invalidate one or more solutions.
1656
            // This happens during propagation rather than at the time
1657
            // that the value is actually changed, so that multiple
1658
            // solutions can be applied in one go.
1659
            std::list<CdlConflict>::iterator conf_i, conf_j;
1660
            for (conf_i = new_conflicts.begin(); conf_i != new_conflicts.end(); conf_i++) {
1661
                CYG_LOOP_INVARIANT_CLASSC(*conf_i);
1662
                (*conf_i)->update_solution_validity(valuable);
1663
            }
1664
            for (conf_i = global_conflicts_with_solutions.begin();
1665
                 conf_i != global_conflicts_with_solutions.end();
1666
                 ) {
1667
 
1668
                CYG_LOOP_INVARIANT_CLASSC(*conf_i);
1669
                conf_j = conf_i++;
1670
 
1671
                (*conf_j)->update_solution_validity(valuable);
1672
                if (!(*conf_j)->has_known_solution()) {
1673
                    global_conflicts_with_solutions.erase(conf_j);
1674
                }
1675
            }
1676
 
1677
            // If the valuable is no longer loaded then there is
1678
            // no need to worry about propagation
1679
            if (0 != valuable->get_toplevel()) {
1680
 
1681
                // Inform the valuable itself about the update, so that
1682
                // e.g. the value can be checked against legal_values
1683
                valuable->update(this, CdlUpdate_ValueChange);
1684
 
1685
                std::vector<CdlReferrer>& referrers = valuable->referrers;
1686
                std::vector<CdlReferrer>::iterator ref_i;
1687
                for (ref_i = referrers.begin(); ref_i != referrers.end(); ref_i++) {
1688
                    ref_i->update(this, valuable, CdlUpdate_ValueChange);
1689
                }
1690
            }
1691
 
1692
        } else {
1693
 
1694
            CdlNode node = active_changes.front();
1695
            active_changes.pop_front();
1696
 
1697
            if (0 != node->get_toplevel()) {
1698
                node->update(this, CdlUpdate_ActiveChange);
1699
 
1700
                std::vector<CdlReferrer>& referrers = node->referrers;
1701
                std::vector<CdlReferrer>::iterator ref_i;
1702
                for (ref_i = referrers.begin(); ref_i != referrers.end(); ref_i++) {
1703
                    ref_i->update(this, node, CdlUpdate_ActiveChange);
1704
                }
1705
            }
1706
        }
1707
    }
1708
 
1709
    CYG_REPORT_RETURN();
1710
}
1711
 
1712
// ----------------------------------------------------------------------------
1713
bool
1714
CdlTransactionBody::is_propagation_required() const
1715
{
1716
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::is_propagation_required", "result %d");
1717
    CYG_REPORT_FUNCARG1XV(this);
1718
    CYG_PRECONDITION_THISC();
1719
 
1720
    bool result = false;
1721
 
1722
    if ((0 != value_changes.size()) || (0 != active_changes.size())) {
1723
        result = true;
1724
    }
1725
 
1726
    CYG_REPORT_RETVAL(result);
1727
    return result;
1728
}
1729
 
1730
 
1731
// ----------------------------------------------------------------------------
1732
void
1733
CdlTransactionBody::add_legal_values_change(CdlValuable valuable)
1734
{
1735
    CYG_REPORT_FUNCNAME("CdlTransaction::add_legal_values_change");
1736
    CYG_REPORT_FUNCARG2XV(this, valuable);
1737
    CYG_PRECONDITION_THISC();
1738
    CYG_PRECONDITION_CLASSC(valuable);
1739
 
1740
    legal_values_changes.insert(valuable);
1741
 
1742
    CYG_REPORT_RETURN();
1743
}
1744
 
1745
const std::set<CdlValuable>&
1746
CdlTransactionBody::get_legal_values_changes() const
1747
{
1748
    CYG_REPORT_FUNCNAME("CdlTransaction::get_legal_values_changes");
1749
    CYG_REPORT_FUNCARG1XV(this);
1750
    CYG_PRECONDITION_THISC();
1751
 
1752
    CYG_REPORT_RETURN();
1753
    return legal_values_changes;
1754
}
1755
 
1756
//}}}
1757
//{{{  Cancel                                   
1758
 
1759
// ----------------------------------------------------------------------------
1760
// Cancellation is straightforward, essentially it just involves clearing
1761
// out all of the STL containers. The transaction object can then be-used,
1762
// so fields like parent and toplevel must not change.
1763
void
1764
CdlTransactionBody::cancel()
1765
{
1766
    CYG_REPORT_FUNCNAME("CdlTransaction::cancel");
1767
    CYG_REPORT_FUNCARG1XV(this);
1768
    CYG_INVARIANT_THISC(CdlTransactionBody);
1769
 
1770
    // First take care of the cancel ops, if any, in case a cancel op
1771
    // depends on some of the other transaction state.
1772
    std::vector<CdlTransactionCommitCancelOp*>::reverse_iterator cancel_i;
1773
    for (cancel_i = commit_cancel_ops.rbegin(); cancel_i != commit_cancel_ops.rend(); cancel_i++) {
1774
        (*cancel_i)->cancel(this);
1775
        delete *cancel_i;
1776
        *cancel_i = 0;
1777
    }
1778
    commit_cancel_ops.clear();
1779
 
1780
    this->changes.clear();
1781
    std::list<CdlConflict>::iterator conf_i;
1782
    for (conf_i = this->new_conflicts.begin(); conf_i != this->new_conflicts.end(); conf_i++) {
1783
        CYG_LOOP_INVARIANT_CLASSC(*conf_i);
1784
        delete *conf_i;
1785
    }
1786
    this->new_conflicts.clear();
1787
    for (conf_i = this->new_structural_conflicts.begin(); conf_i != this->new_structural_conflicts.end(); conf_i++) {
1788
        CYG_LOOP_INVARIANT_CLASSC(*conf_i);
1789
        delete *conf_i;
1790
    }
1791
    this->new_structural_conflicts.clear();
1792
 
1793
    this->deleted_structural_conflicts.clear();
1794
    this->deleted_conflicts.clear();
1795
 
1796
    // Any conflicts created and resolved during this transaction will
1797
    // still be present in resolved_conflicts. Some global conflicts
1798
    // may be there as well.
1799
    std::vector<CdlConflict>::iterator conf_i2;
1800
    for (conf_i2 = this->resolved_conflicts.begin(); conf_i2 != this->resolved_conflicts.end(); conf_i2++) {
1801
        if (this == (*conf_i2)->transaction) {
1802
            delete (*conf_i2);
1803
        }
1804
    }
1805
    this->resolved_conflicts.clear();
1806
 
1807
    // Any global conflicts which have been updated with a solution need
1808
    // to have that solution cleared. Currently no attempt is made to
1809
    // keep solutions valid for global conflicts.
1810
    for (conf_i = this->global_conflicts_with_solutions.begin();
1811
         conf_i != this->global_conflicts_with_solutions.end();
1812
         conf_i++) {
1813
 
1814
        CYG_LOOP_INVARIANT_CLASSC(*conf_i);
1815
        (*conf_i)->clear_solution();
1816
    }
1817
    this->global_conflicts_with_solutions.clear();
1818
 
1819
    this->activated.clear();
1820
    this->deactivated.clear();
1821
    this->legal_values_changes.clear();
1822
    this->value_changes.clear();
1823
    this->active_changes.clear();
1824
 
1825
    CYG_REPORT_RETURN();
1826
}
1827
 
1828
//}}}
1829
//{{{  Commit                                   
1830
 
1831
// ----------------------------------------------------------------------------
1832
// The commit operation. There are two main branches for this code. The
1833
// first branch deals with sub-transactions, and basically involves
1834
// transferring changes from the sub-transaction to the parent. It is
1835
// assumed that the sub-transaction has been fully propagated, so
1836
// data can just be transferred from the child to the parent.
1837
//
1838
// The second branch involves committing changes from a transaction to
1839
// the toplevel, invoking the transaction callback if necessary.
1840
 
1841
void
1842
CdlTransactionBody::commit()
1843
{
1844
    CYG_REPORT_FUNCNAME("CdlTransaction::commit");
1845
    CYG_REPORT_FUNCARG1XV(this);
1846
    CYG_INVARIANT_THISC(CdlTransactionBody);
1847
 
1848
    std::map<CdlValuable, CdlValue>::iterator map_i;
1849
    std::list<CdlConflict>::iterator conf_i, conf_j;
1850
    std::vector<CdlConflict>::const_iterator conf_i2, conf_j2;
1851
    std::set<CdlNode>::iterator set_i, set_j, set_k;
1852
    std::set<CdlValuable>::iterator set_i2, set_j2;
1853
 
1854
    if (0 != parent) {
1855
        // Any conflicts that were solved by the inference engine further
1856
        // down are still resolved.
1857
        // Great care has to be taken with conflict ownership. The following
1858
        // cases have to be considered.
1859
        // 1) the resolved conflict is global, its transaction is zero, this
1860
        //    conflict must only be destroyed if the toplevel transaction
1861
        //    is committed - at which time time the conflict should appear
1862
        //    on the deleted_conflicts lists.
1863
        // 2) the conflict belongs to a higher level transaction, we have
1864
        //    recursed a certain amount trying to resolve it e.g. to explore
1865
        //    OR branches of the tree. Again the resolved conflict can only
1866
        //    be destroyed when the appropriate higher-level commit happens,
1867
        //    and should appear on the deleted conflicts list.
1868
        // 3) the conflict was created and resolved further down the tree.
1869
        //    We are keeping it around for informational purposes only.
1870
        //    Associating it with this transaction allows the code to
1871
        //    distinguish this case from (1) and (2).
1872
        for (conf_i2 = resolved_conflicts.begin(); conf_i2 != resolved_conflicts.end(); conf_i2++) {
1873
            CdlConflict conf = *conf_i2;
1874
            CYG_LOOP_INVARIANT_CLASSC(conf);
1875
            CYG_LOOP_INVARIANTC(parent->resolved_conflicts.end() == \
1876
                                std::find(parent->resolved_conflicts.begin(), \
1877
                                          parent->resolved_conflicts.end(), conf));
1878
            parent->resolved_conflicts.push_back(conf);
1879
            parent->dirty = true;
1880
            if (this == conf->transaction) {
1881
                conf->transaction = parent;
1882
            }
1883
        }
1884
        resolved_conflicts.clear();
1885
 
1886
        // Any global conflicts for which solutions were found in the
1887
        // sub-transaction still have solutions in the parent.
1888
        for (conf_i = global_conflicts_with_solutions.begin(); conf_i != global_conflicts_with_solutions.end(); conf_i++) {
1889
 
1890
            CdlConflict conf = *conf_i;
1891
            CYG_LOOP_INVARIANT_CLASSC(conf);
1892
 
1893
            // It is not clear that this search is actually useful, especially
1894
            // given that the solution is currently stored with the conflict
1895
            // rather than with the transaction.
1896
            conf_j = std::find(parent->global_conflicts_with_solutions.begin(),
1897
                                parent->global_conflicts_with_solutions.end(),
1898
                                conf);
1899
            if (conf_j == parent->global_conflicts_with_solutions.end()) {
1900
                parent->global_conflicts_with_solutions.push_back(conf);
1901
                parent->dirty = true;
1902
            }
1903
        }
1904
        global_conflicts_with_solutions.clear();
1905
 
1906
        // Now take care of deleted conflicts.
1907
        for (conf_i2 = deleted_conflicts.begin(); conf_i2 != deleted_conflicts.end(); conf_i2++) {
1908
            CdlConflict conf = *conf_i2;
1909
            CYG_LOOP_INVARIANT_CLASSC(conf);
1910
            // Possibilities to consider:
1911
            // 1) the conflict may have been local to the parent transaction,
1912
            //    in which case it can be deleted.
1913
            // 2) the conflict may have been created in a higher-level
1914
            //    transaction, in which case it has to be moved to the
1915
            //    parent's deleted_conflicts vector.
1916
            // 3) the conflict may also have been global, again it needs
1917
            //    to be propagated into the parent's deleted_conflicts vector.
1918
            //
1919
            // But that is not the whole story. If this sub-transaction was
1920
            // created specifically to resolve the conflict then the latter
1921
            // should appear on the resolved vector and not be destroyed
1922
            // immediately. This is true for both global and per-transaction
1923
            // conflicts.
1924
            //
1925
            // For global conflicts it is also necessary to worry about
1926
            // the global_conflicts_with_solutions list, that has to be
1927
            // kept in synch with the rest of the world.
1928
            conf_i = std::find(parent->new_conflicts.begin(), parent->new_conflicts.end(), conf);
1929
            bool can_delete = false;
1930
            if (conf_i != parent->new_conflicts.end()) {
1931
                parent->new_conflicts.erase(conf_i);
1932
                can_delete = true;
1933
            } else {
1934
                parent->deleted_conflicts.push_back(conf);
1935
            }
1936
            if (0 == conf->transaction) {
1937
                conf_j = std::find(parent->global_conflicts_with_solutions.begin(),
1938
                                   parent->global_conflicts_with_solutions.end(),
1939
                                   conf);
1940
                if (conf_j != parent->global_conflicts_with_solutions.end()) {
1941
                    parent->global_conflicts_with_solutions.erase(conf_j);
1942
                }
1943
            }
1944
            if (conf == this->conflict) {
1945
                // The conflict may have been fortuitously resolved lower down,
1946
                // in which case it will have appeared in this->resolved_conflicts()
1947
                // and copied already.
1948
                conf_j2 = std::find(parent->resolved_conflicts.begin(), parent->resolved_conflicts.end(), conf);
1949
                if (conf_j2 == parent->resolved_conflicts.end()) {
1950
                    parent->resolved_conflicts.push_back(conf);
1951
                    parent->dirty = true;
1952
                }
1953
            } else if (can_delete) {
1954
                delete conf;
1955
            }
1956
        }
1957
        // Unnecessary, but let's keep things clean.
1958
        deleted_conflicts.clear();
1959
 
1960
        // Deleted structural conflicts. For now the inference engine can do nothing with
1961
        // these so they are a bit simpler.
1962
        for (conf_i2 = deleted_structural_conflicts.begin(); conf_i2 != deleted_structural_conflicts.end(); conf_i2++) {
1963
 
1964
            CdlConflict conf = *conf_i2;
1965
            CYG_LOOP_INVARIANT_CLASSC(conf);
1966
            conf_i = std::find(parent->new_structural_conflicts.begin(), parent->new_structural_conflicts.end(), conf);
1967
            if (conf_i != parent->new_structural_conflicts.end()) {
1968
                parent->new_structural_conflicts.erase(conf_i);
1969
                delete conf;
1970
            } else {
1971
                parent->deleted_structural_conflicts.push_back(conf);
1972
            }
1973
        }
1974
        deleted_structural_conflicts.clear();
1975
 
1976
        // All value changes need to be propagated from the child to the parent.
1977
        // Also, these value changes may invalidate existing solutions.
1978
        for (map_i = changes.begin(); map_i != changes.end(); map_i++) {
1979
            CYG_LOOP_INVARIANT_CLASSC(map_i->first);
1980
            CYG_LOOP_INVARIANT_CLASSOC(map_i->second);
1981
            parent->changes[map_i->first] = map_i->second;
1982
            for (conf_i = parent->new_conflicts.begin(); conf_i != parent->new_conflicts.end(); conf_i++) {
1983
                CYG_LOOP_INVARIANT_CLASSC(*conf_i);
1984
                (*conf_i)->update_solution_validity(map_i->first);
1985
            }
1986
            for (conf_i = parent->global_conflicts_with_solutions.begin();
1987
                 conf_i != parent->global_conflicts_with_solutions.end();
1988
                 ) {
1989
 
1990
                conf_j = conf_i++;
1991
                CYG_LOOP_INVARIANT_CLASSC(*conf_j);
1992
 
1993
                (*conf_j)->update_solution_validity(map_i->first);
1994
                if (!(*conf_j)->has_known_solution()) {
1995
                    parent->global_conflicts_with_solutions.erase(conf_j);
1996
                }
1997
            }
1998
        }
1999
        changes.clear();
2000
 
2001
        // Continue propagating the conflicts.New conflicts can just
2002
        // be added.
2003
        for (conf_i = new_conflicts.begin(); conf_i != new_conflicts.end(); conf_i++) {
2004
            CYG_LOOP_INVARIANT_CLASSC(*conf_i);
2005
            parent->new_conflicts.push_back(*conf_i);
2006
            parent->dirty = true;
2007
            (*conf_i)->transaction = parent;
2008
        }
2009
        for (conf_i = new_structural_conflicts.begin(); conf_i != new_structural_conflicts.end(); conf_i++) {
2010
            CYG_LOOP_INVARIANT_CLASSC(*conf_i);
2011
            parent->new_structural_conflicts.push_back(*conf_i);
2012
            parent->dirty = true;
2013
            (*conf_i)->transaction = parent;
2014
        }
2015
        // The cancel operation at the end will delete new conflicts, so the
2016
        // containers had better be cleared here.
2017
        new_conflicts.clear();
2018
        new_structural_conflicts.clear();
2019
 
2020
 
2021
        // Also keep track of nodes that have become active or inactive.
2022
        set_j = parent->activated.begin();
2023
        for (set_i = activated.begin(); set_i != activated.end(); set_i++) {
2024
            set_j = parent->activated.insert(set_j, *set_i);
2025
            set_k = parent->deactivated.find(*set_i);
2026
            if (set_k != parent->deactivated.end()) {
2027
                parent->deactivated.erase(set_k);
2028
            }
2029
        }
2030
 
2031
        set_j = parent->deactivated.begin();
2032
        for (set_i = deactivated.begin(); set_i != deactivated.end(); set_i++) {
2033
            set_j = parent->deactivated.insert(set_j, *set_i);
2034
            set_k = parent->activated.find(*set_i);
2035
            if (set_k != parent->activated.end()) {
2036
                parent->activated.erase(set_k);
2037
            }
2038
        }
2039
        activated.clear();
2040
        deactivated.clear();
2041
 
2042
        // Keep track of other property changes.
2043
        set_j2 = parent->legal_values_changes.begin();
2044
        for (set_i2 = legal_values_changes.begin(); set_i2 != legal_values_changes.end(); set_i2++) {
2045
            set_j2 = parent->legal_values_changes.insert(set_j2, *set_i2);
2046
        }
2047
        legal_values_changes.clear();
2048
 
2049
        // Any pending commit/cancel ops needs to be transferred to the parent
2050
        parent->commit_cancel_ops.insert(parent->commit_cancel_ops.end(),
2051
                                         this->commit_cancel_ops.begin(), this->commit_cancel_ops.end());
2052
        this->commit_cancel_ops.clear();
2053
 
2054
    } else {
2055
 
2056
        CYG_ASSERT_CLASSC(toplevel);
2057
 
2058
        // If there is a registered callback function, it is necessary to fill
2059
        // in the remaining fields of the all_changes callback structure. This
2060
        // should happen before any conflicts get deleted. The actual callback
2061
        // is invoked at the end, once all the changes have been moved to
2062
        // the toplevel.
2063
        CdlTransactionCallback all_changes(this);
2064
        if (0 != callback_fn) {
2065
 
2066
            for (map_i = changes.begin(); map_i != changes.end(); map_i++) {
2067
                if (0 == map_i->first->get_toplevel()) {
2068
                    continue;
2069
                }
2070
                CdlValueFlavor flavor = map_i->second.get_flavor();
2071
                const CdlValue& old_value = map_i->first->get_whole_value();
2072
                CYG_LOOP_INVARIANTC(flavor == old_value.get_flavor());
2073
                bool value_changed = false;
2074
 
2075
                if (old_value.get_source() != map_i->second.get_source()) {
2076
                    all_changes.value_source_changes.push_back(map_i->first);
2077
                }
2078
                if ((CdlValueFlavor_Bool == flavor) || (CdlValueFlavor_BoolData == flavor)) {
2079
                    if (old_value.is_enabled() != map_i->second.is_enabled()) {
2080
                        value_changed = true;
2081
                    }
2082
                }
2083
                if (!value_changed && ((CdlValueFlavor_BoolData == flavor) || (CdlValueFlavor_Data == flavor))) {
2084
                    if (old_value.get_simple_value() != map_i->second.get_simple_value()) {
2085
                        value_changed = true;
2086
                    }
2087
                }
2088
                if (value_changed) {
2089
                    all_changes.value_changes.push_back(map_i->first);
2090
                }
2091
            }
2092
            for (conf_i = new_conflicts.begin(); conf_i != new_conflicts.end(); conf_i++) {
2093
                all_changes.new_conflicts.push_back(*conf_i);
2094
            }
2095
            for (conf_i = new_structural_conflicts.begin(); conf_i != new_structural_conflicts.end(); conf_i++) {
2096
                all_changes.new_structural_conflicts.push_back(*conf_i);
2097
            }
2098
            for (conf_i2 = deleted_conflicts.begin(); conf_i2 != deleted_conflicts.end(); conf_i2++) {
2099
                CdlNode node = (*conf_i2)->get_node();
2100
                CYG_LOOP_INVARIANT_CLASSC(node);
2101
 
2102
                all_changes.nodes_with_resolved_conflicts.push_back(node);
2103
            }
2104
            for (conf_i2 = deleted_structural_conflicts.begin(); conf_i2 != deleted_structural_conflicts.end(); conf_i2++) {
2105
                CdlNode node = (*conf_i2)->get_node();
2106
                CYG_LOOP_INVARIANT_CLASSC(node);
2107
 
2108
                all_changes.nodes_with_resolved_structural_conflicts.push_back(node);
2109
            }
2110
            for (set_i = activated.begin(); set_i != activated.end(); set_i++) {
2111
                if (0 != (*set_i)->get_toplevel()) {
2112
                    all_changes.active_changes.push_back(*set_i);
2113
                }
2114
            }
2115
            for (set_i = deactivated.begin(); set_i != deactivated.end(); set_i++) {
2116
                if (0 != (*set_i)->get_toplevel()) {
2117
                    all_changes.active_changes.push_back(*set_i);
2118
                }
2119
            }
2120
            for (set_i2 = legal_values_changes.begin(); set_i2 != legal_values_changes.end(); set_i2++) {
2121
                if (0 != (*set_i)->get_toplevel()) {
2122
                    all_changes.legal_values_changes.push_back(*set_i2);
2123
                }
2124
            }
2125
            legal_values_changes.clear();
2126
        }
2127
 
2128
        // All new values need to be installed in the appropriate valuable.
2129
        for (map_i = changes.begin(); map_i != changes.end(); map_i++) {
2130
            CYG_LOOP_INVARIANT_CLASSC(map_i->first);
2131
            CYG_LOOP_INVARIANT_CLASSOC(map_i->second);
2132
            map_i->first->value = map_i->second;
2133
        }
2134
        changes.clear();
2135
 
2136
        // Sort out the conflicts. New conflicts can just be added, although
2137
        // care has to be taken to clear state - currently no attempt is
2138
        // made to check solution validity for global conflicts.
2139
        for (conf_i = new_conflicts.begin(); conf_i != new_conflicts.end(); conf_i++) {
2140
            CYG_LOOP_INVARIANT_CLASSC(*conf_i);
2141
            toplevel->conflicts.push_back(*conf_i);
2142
            (*conf_i)->transaction = 0;
2143
            (*conf_i)->clear_solution();
2144
        }
2145
        new_conflicts.clear();
2146
        for (conf_i = new_structural_conflicts.begin(); conf_i != new_structural_conflicts.end(); conf_i++) {
2147
            CYG_LOOP_INVARIANT_CLASSC(*conf_i);
2148
            toplevel->structural_conflicts.push_back(*conf_i);
2149
            (*conf_i)->transaction = 0;
2150
            (*conf_i)->clear_solution();
2151
        }
2152
        new_structural_conflicts.clear();
2153
 
2154
        // Resolved conflicts can be either global or per-transaction
2155
        // ones. If the former then the conflict will also be present
2156
        // in deleted_conflicts and will get deleted shortly.
2157
        for (conf_i2 = resolved_conflicts.begin(); conf_i2 != resolved_conflicts.end(); conf_i2++) {
2158
            CYG_LOOP_INVARIANT_CLASSC(*conf_i2);
2159
            if (0 != (*conf_i2)->transaction) {
2160
                delete *conf_i2;
2161
            }
2162
        }
2163
        resolved_conflicts.clear();
2164
 
2165
        // Now process conflicts that have gone away. These must actually
2166
        // be deleted.
2167
        for (conf_i2 = deleted_conflicts.begin(); conf_i2 != deleted_conflicts.end(); conf_i2++) {
2168
            CYG_LOOP_INVARIANT_CLASSC(*conf_i2);
2169
            std::list<CdlConflict>::iterator tmp;
2170
            tmp = std::find(toplevel->conflicts.begin(), toplevel->conflicts.end(), *conf_i2);
2171
            CYG_LOOP_INVARIANTC(tmp != toplevel->conflicts.end());
2172
            toplevel->conflicts.erase(tmp);
2173
            delete *conf_i2;
2174
        }
2175
        deleted_conflicts.clear();
2176
        for (conf_i2 = deleted_structural_conflicts.begin(); conf_i2 != deleted_structural_conflicts.end(); conf_i2++) {
2177
            CYG_LOOP_INVARIANT_CLASSC(*conf_i2);
2178
            std::list<CdlConflict>::iterator tmp;
2179
            tmp = std::find(toplevel->structural_conflicts.begin(), toplevel->structural_conflicts.end(), *conf_i2);
2180
            CYG_LOOP_INVARIANTC(tmp != toplevel->structural_conflicts.end());
2181
            toplevel->structural_conflicts.erase(tmp);
2182
            delete *conf_i2;
2183
        }
2184
        deleted_structural_conflicts.clear();
2185
 
2186
        // Any global conflicts with solutions need to have their solutions cleared,
2187
        // since currently no attempt is made to preserve their accuracy.
2188
        for (conf_i = global_conflicts_with_solutions.begin(); conf_i != global_conflicts_with_solutions.end(); conf_i++) {
2189
            CYG_LOOP_INVARIANT_CLASSC(*conf_i);
2190
            (*conf_i)->clear_solution();
2191
        }
2192
        global_conflicts_with_solutions.clear();
2193
 
2194
        for (set_i = activated.begin(); set_i != activated.end(); set_i++) {
2195
            (*set_i)->active = true;
2196
        }
2197
        for (set_i = deactivated.begin(); set_i != deactivated.end(); set_i++) {
2198
            (*set_i)->active = false;
2199
        }
2200
        activated.clear();
2201
        deactivated.clear();
2202
 
2203
        // Invoke all pending commit operations
2204
        std::vector<CdlTransactionCommitCancelOp*>::iterator commit_i;
2205
        for (commit_i = commit_cancel_ops.begin(); commit_i != commit_cancel_ops.end(); commit_i++) {
2206
            (*commit_i)->commit(this);
2207
            delete *commit_i;
2208
            *commit_i = 0;
2209
        }
2210
        commit_cancel_ops.clear();
2211
 
2212
        // Finally take care of the callback.
2213
        if (0 != callback_fn) {
2214
            (*callback_fn)(all_changes);
2215
        }
2216
    }
2217
 
2218
    CYG_REPORT_RETURN();
2219
}
2220
 
2221
//}}}
2222
//{{{  Solution support                         
2223
 
2224
// ----------------------------------------------------------------------------
2225
// Saving a solution basically involves remembering what changes took place
2226
// in the corresponding sub-transaction. There is no need to worry about
2227
// other data in the sub-transaction such as conflicts, because there
2228
// are no actual value changes.
2229
 
2230
void
2231
CdlTransactionBody::save_solution()
2232
{
2233
    CYG_REPORT_FUNCNAME("CdlTransaction::save_solution");
2234
    CYG_REPORT_FUNCARG1XV(this);
2235
    CYG_PRECONDITION_THISC();
2236
    // Solutions should only be applicable to sub-transactions immediately
2237
    // below the main transaction, since that is the only level at which
2238
    // inference callbacks occur
2239
    CYG_PRECONDITIONC((0 != parent) && (0 == parent->parent));
2240
 
2241
    CYG_PRECONDITION_CLASSC(conflict);
2242
    CYG_PRECONDITIONC(0 == conflict->solution.size());
2243
 
2244
    std::map<CdlValuable, CdlValue>::const_iterator map_i;
2245
    for (map_i = changes.begin(); map_i != changes.end(); map_i++) {
2246
        // If the valuable was calculated or is otherwise non-modifiable,
2247
        // there is no point in storing it with the solution since the
2248
        // information is unlikely to be of interest to the user.
2249
        CdlValuable valuable = map_i->first;
2250
        if (valuable->is_modifiable()) {
2251
            conflict->solution.push_back(*map_i);
2252
        }
2253
    }
2254
 
2255
    // save_solution() should operate like commit() or cancel(), i.e.
2256
    // it leaves an empty sub-transaction. This sub-transaction cannot
2257
    // actually be re-used at present because it still references a
2258
    // conflict for which a solution is now already in place, but that
2259
    // may get cleaned up in future.
2260
    this->cancel();
2261
    CYG_REPORT_RETURN();
2262
}
2263
 
2264
// ----------------------------------------------------------------------------
2265
// Can a solution be applied without e.g. overwriting a user value with
2266
// an inferred value. There is a setting inference_override which controls
2267
// this. Making a previously enabled option inactive also requires
2268
// user confirmation, thus preventing the inference engine from disabling
2269
// entire components.
2270
bool
2271
CdlTransactionBody::user_confirmation_required() const
2272
{
2273
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::user_confirmation_required", "result %d");
2274
    CYG_REPORT_FUNCARG1XV(this);
2275
    CYG_PRECONDITION_THISC();
2276
    CYG_PRECONDITION_CLASSC(this->parent);
2277
 
2278
    bool result = false;
2279
 
2280
    std::map<CdlValuable, CdlValue>::const_iterator val_i;
2281
    for (val_i = changes.begin(); val_i != changes.end(); val_i++) {
2282
        const CdlValue& old_value = parent->get_whole_value(val_i->first);
2283
        if (old_value.get_source() > CdlTransactionBody::inference_override) {
2284
            result = true;
2285
            break;
2286
        }
2287
    }
2288
    std::set<CdlNode>::const_iterator val_j;
2289
    for (val_j = deactivated.begin(); val_j != deactivated.end(); val_j++) {
2290
        CdlValuable valuable = dynamic_cast<CdlValuable>(*val_j);
2291
        if (0 != valuable) {
2292
            const CdlValue& old_value = parent->get_whole_value(valuable);
2293
            if ((old_value.get_source() > CdlTransactionBody::inference_override) && old_value.is_enabled()) {
2294
                result = true;
2295
                break;
2296
            }
2297
        }
2298
    }
2299
 
2300
    CYG_REPORT_RETVAL(result);
2301
    return result;
2302
}
2303
 
2304
// ----------------------------------------------------------------------------
2305
// The inference engine is considering modifying a particular valuable. If
2306
// the user has explicitly changed this valuable during the transaction then
2307
// it would be inappropriate to suggest changing it again.
2308
bool
2309
CdlTransactionBody::changed_by_user(CdlValuable valuable) const
2310
{
2311
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::changed_by_user", "result %d");
2312
    CYG_REPORT_FUNCARG2XV(this, valuable);
2313
    CYG_PRECONDITION_THISC();
2314
    CYG_PRECONDITION_CLASSC(valuable);
2315
 
2316
    bool result = false;
2317
    std::map<CdlValuable, CdlValue>::const_iterator change_i = changes.find(valuable);
2318
    if (change_i != changes.end()) {
2319
        CdlValueSource source = change_i->second.get_source();
2320
        if (CdlValueSource_User == source) {
2321
            result = true;
2322
        }
2323
    }
2324
    if (!result && (0 != parent)) {
2325
        result = parent->changed_by_user(valuable);
2326
    }
2327
 
2328
    CYG_REPORT_RETVAL(result);
2329
    return result;
2330
}
2331
 
2332
// ----------------------------------------------------------------------------
2333
// A variant which takes into account the hierarchy: disabling a container
2334
// when a sub-node has just been changed by the user is also a no-no.
2335
bool
2336
CdlTransactionBody::subnode_changed_by_user(CdlContainer container) const
2337
{
2338
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::subnode_changed_by_user", "result %d");
2339
    CYG_REPORT_FUNCARG2XV(this, container);
2340
    CYG_PRECONDITION_THISC();
2341
    CYG_PRECONDITION_CLASSC(container);
2342
 
2343
    bool result = false;
2344
 
2345
    const std::vector<CdlNode>& contents = container->get_contents();
2346
    std::vector<CdlNode>::const_iterator node_i;
2347
    for (node_i = contents.begin(); node_i != contents.end(); node_i++) {
2348
        CdlValuable valuable = dynamic_cast<CdlValuable>(*node_i);
2349
        if ((0 != valuable) && this->changed_by_user(valuable)) {
2350
            result = true;
2351
            break;
2352
        }
2353
        CdlContainer container = dynamic_cast<CdlContainer>(*node_i);
2354
        if ((0 != container) && this->subnode_changed_by_user(container)) {
2355
            result = true;
2356
            break;
2357
        }
2358
    }
2359
 
2360
    CYG_REPORT_RETVAL(result);
2361
    return result;
2362
}
2363
 
2364
// ----------------------------------------------------------------------------
2365
// Is one solution preferable to another? This code assumes that
2366
// user_confirmation_required() and changed_by_user() have already
2367
// been considered, so the only issue at stake here is the changes
2368
// themselves.
2369
//
2370
// For now a simple metric of the number of changes is used. A more
2371
// intelligent approach would take into account how much of the
2372
// hierarchy is affected, e.g. how many other items would end
2373
// up being disabled. Arguably the calling code should be able to
2374
// supply an additional weighting.
2375
 
2376
bool
2377
CdlTransactionBody::is_preferable_to(CdlTransaction other) const
2378
{
2379
    CYG_REPORT_FUNCNAMETYPE("CdlTransactionBody::preferable_to", "result %d");
2380
    CYG_REPORT_FUNCARG2XV(this, other);
2381
    CYG_PRECONDITION_THISC();
2382
    CYG_PRECONDITION_CLASSC(other);
2383
    CYG_PRECONDITIONC(this != other);
2384
 
2385
    bool result = false;
2386
    unsigned int this_changes  = this->changes.size()  + this->activated.size()  + this->deactivated.size();
2387
    unsigned int other_changes = other->changes.size() + other->activated.size() + other->deactivated.size();
2388
 
2389
    if (this_changes <= other_changes) {
2390
        result = true;
2391
    }
2392
 
2393
    CYG_REPORT_RETVAL(result);
2394
    return result;
2395
}
2396
 
2397
// ----------------------------------------------------------------------------
2398
// Applying solutions. Multiple solutions can be applied in one go. If there
2399
// is any overlap, tough. Propagation needs to happen after solutions are
2400
// applied.
2401
 
2402
void
2403
CdlTransactionBody::apply_solution(CdlConflict conflict)
2404
{
2405
    CYG_REPORT_FUNCNAME("CdlTransaction::apply_solution");
2406
    CYG_REPORT_FUNCARG2XV(this, conflict);
2407
    CYG_PRECONDITION_THISC();
2408
    CYG_PRECONDITION_CLASSC(conflict);
2409
 
2410
    // The solution can be for either a per-transaction conflict
2411
    // or a global one. There are two lists to search.
2412
    std::list<CdlConflict>::const_iterator conf_i;
2413
    conf_i = std::find(this->new_conflicts.begin(), this->new_conflicts.end(), conflict);
2414
    if (conf_i == this->new_conflicts.end()) {
2415
        conf_i = std::find(this->global_conflicts_with_solutions.begin(),
2416
                           this->global_conflicts_with_solutions.end(),
2417
                           conflict);
2418
        CYG_ASSERTC(conf_i != this->global_conflicts_with_solutions.end());
2419
    }
2420
 
2421
    std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator val_i;
2422
    for (val_i = conflict->solution.begin(); val_i != conflict->solution.end(); val_i++) {
2423
        CdlValuable valuable = val_i->first;
2424
        CYG_LOOP_INVARIANT_CLASSC(valuable);
2425
 
2426
        const CdlValue& old_value = this->get_whole_value(valuable);
2427
        this->set_whole_value(valuable, old_value, val_i->second);
2428
    }
2429
 
2430
    CYG_REPORT_RETURN();
2431
}
2432
 
2433
void
2434
CdlTransactionBody::apply_solutions(const std::vector<CdlConflict>& solutions)
2435
{
2436
    CYG_REPORT_FUNCNAME("CdlTransaction::apply_solutions");
2437
    CYG_REPORT_FUNCARG1XV(this);
2438
    CYG_PRECONDITION_THISC();
2439
 
2440
    std::vector<CdlConflict>::const_iterator conf_i;
2441
    for (conf_i = solutions.begin(); conf_i != solutions.end(); conf_i++) {
2442
 
2443
        std::list<CdlConflict>::const_iterator conf_j;
2444
        conf_j = std::find(this->new_conflicts.begin(), this->new_conflicts.end(), conflict);
2445
        if (conf_j == this->new_conflicts.end()) {
2446
            conf_j = std::find(this->global_conflicts_with_solutions.begin(),
2447
                               this->global_conflicts_with_solutions.end(),
2448
                               conflict);
2449
            CYG_ASSERTC(conf_j != this->global_conflicts_with_solutions.end());
2450
        }
2451
 
2452
        std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator val_i;
2453
        for (val_i = conflict->solution.begin(); val_i != conflict->solution.end(); val_i++) {
2454
            CdlValuable valuable = val_i->first;
2455
            CYG_LOOP_INVARIANT_CLASSC(valuable);
2456
            const CdlValue& old_value = this->get_whole_value(valuable);
2457
            this->set_whole_value(valuable, old_value, val_i->second);
2458
        }
2459
    }
2460
 
2461
    CYG_REPORT_RETURN();
2462
}
2463
 
2464
void
2465
CdlTransactionBody::apply_all_solutions()
2466
{
2467
    CYG_REPORT_FUNCNAME("CdlTransaction::apply_all_solutions");
2468
    CYG_REPORT_FUNCARG1XV(this);
2469
    CYG_PRECONDITION_THISC();
2470
 
2471
    std::list<CdlConflict>::const_iterator conf_i;
2472
    for (conf_i = this->new_conflicts.begin(); conf_i != this->new_conflicts.end(); conf_i++) {
2473
        if ((*conf_i)->has_known_solution()) {
2474
 
2475
            std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator val_i;
2476
            for (val_i = conflict->solution.begin(); val_i != conflict->solution.end(); val_i++) {
2477
                CdlValuable valuable = val_i->first;
2478
                CYG_LOOP_INVARIANT_CLASSC(valuable);
2479
                const CdlValue& old_value = this->get_whole_value(valuable);
2480
                this->set_whole_value(valuable, old_value, val_i->second);
2481
            }
2482
        }
2483
    }
2484
    for (conf_i = this->global_conflicts_with_solutions.begin();
2485
         conf_i != this->global_conflicts_with_solutions.end();
2486
         conf_i++) {
2487
 
2488
        CYG_ASSERTC((*conf_i)->has_known_solution());
2489
 
2490
        std::vector<std::pair<CdlValuable, CdlValue> >::const_iterator val_i;
2491
        for (val_i = conflict->solution.begin(); val_i != conflict->solution.end(); val_i++) {
2492
            CdlValuable valuable = val_i->first;
2493
            CYG_LOOP_INVARIANT_CLASSC(valuable);
2494
            const CdlValue& old_value = this->get_whole_value(valuable);
2495
            this->set_whole_value(valuable, old_value, val_i->second);
2496
        }
2497
    }
2498
 
2499
    CYG_REPORT_RETURN();
2500
}
2501
 
2502
//}}}
2503
//{{{  Inference                                
2504
 
2505
// ----------------------------------------------------------------------------
2506
//{{{  resolve() - all per-transaction conflicts        
2507
 
2508
void
2509
CdlTransactionBody::resolve(int level)
2510
{
2511
    CYG_REPORT_FUNCNAME("CdlTransaction::resolve");
2512
    CYG_REPORT_FUNCARG2XV(this, level);
2513
    CYG_PRECONDITION_THISC();
2514
 
2515
    while(1) {
2516
        // Resolving one conflict may affect others, so iterating down the list
2517
        // is not safe. Instead we need to loop as long as there are conflicts
2518
        // to be considered.
2519
        std::list<CdlConflict>::iterator conf_i;
2520
        for (conf_i = new_conflicts.begin(); conf_i != new_conflicts.end(); conf_i++) {
2521
            CYG_LOOP_INVARIANT_CLASSC(*conf_i);
2522
 
2523
            // Is there any point in attempt to resolve this conflict?
2524
            if ((*conf_i)->has_known_solution() ||
2525
                (*conf_i)->has_no_solution()    ||
2526
                !(*conf_i)->resolution_implemented()) {
2527
                continue;
2528
            }
2529
            this->resolve(*conf_i, level);
2530
            break;
2531
        }
2532
        if (conf_i == new_conflicts.end()) {
2533
            break;
2534
        }
2535
    }
2536
 
2537
    CYG_REPORT_RETURN();
2538
}
2539
 
2540
//}}}
2541
//{{{  resolve() - vector                               
2542
 
2543
// ----------------------------------------------------------------------------
2544
void
2545
CdlTransactionBody::resolve(const std::vector<CdlConflict>& conflicts, int level)
2546
{
2547
    CYG_REPORT_FUNCNAME("CdlTransaction::resolve");
2548
    CYG_REPORT_FUNCARG2XV(this, level);
2549
    CYG_PRECONDITION_THISC();
2550
 
2551
    std::vector<CdlConflict>::const_iterator conf_i;
2552
    for (conf_i = conflicts.begin(); conf_i != conflicts.end(); conf_i++) {
2553
        CYG_LOOP_INVARIANT_CLASSC(*conf_i);
2554
 
2555
        // Is there any point in attempt to resolve this conflict?
2556
        if (!(*conf_i)->has_known_solution() &&
2557
            !(*conf_i)->has_no_solution()    &&
2558
            (*conf_i)->resolution_implemented()) {
2559
            this->resolve(*conf_i, level);
2560
        }
2561
    }
2562
 
2563
    CYG_REPORT_RETURN();
2564
}
2565
 
2566
//}}}
2567
//{{{  resolve() - single conflict                      
2568
 
2569
// ----------------------------------------------------------------------------
2570
// There is a conflict that may have a solution. The resolution
2571
// attempt needs to happen in the context of a sub-transaction
2572
//
2573
// The conflict may have been created during this transaction,
2574
// or it may be a global conflict left over from a previous
2575
// transaction. This can be detected using the conflict's
2576
// transaction field. The commit() code, amongst others, needs
2577
// to handle global and per-transaction conflicts differently.
2578
 
2579
void
2580
CdlTransactionBody::resolve(CdlConflict conflict, int level)
2581
{
2582
    CYG_REPORT_FUNCNAME("CdlTransaction::resolve");
2583
    CYG_REPORT_FUNCARG3XV(this, conflict, level);
2584
    CYG_PRECONDITION_THISC();
2585
    CYG_PRECONDITION_CLASSC(conflict);
2586
    CYG_PRECONDITIONC(0 == conflict->solution.size());
2587
    CYG_PRECONDITIONC((0 <= level) && (level <= inference_recursion_limit));
2588
 
2589
    CdlTransaction sub_transaction = this->make(conflict);
2590
    CYG_PRECONDITION_CLASSC(sub_transaction);
2591
    if (!conflict->inner_resolve(sub_transaction, level)) {
2592
        CYG_ASSERTC(0 == sub_transaction->changes.size());
2593
        sub_transaction->cancel();
2594
        delete sub_transaction;
2595
        conflict->no_solution = true;
2596
        CYG_REPORT_RETURN();
2597
        return;
2598
    }
2599
    // Is the inference engine lying? The conflict should be resolved
2600
    // in the sub-transaction.
2601
    if (conflict->is_structural()) {
2602
        if (std::find(sub_transaction->deleted_structural_conflicts.begin(),
2603
                      sub_transaction->deleted_structural_conflicts.end(),
2604
                      conflict) == sub_transaction->deleted_structural_conflicts.end()) {
2605
 
2606
            CYG_FAIL("The inference engine has proved too optimistic.");
2607
            sub_transaction->cancel();
2608
            delete sub_transaction;
2609
            conflict->no_solution = true;
2610
            CYG_REPORT_RETURN();
2611
            return;
2612
        }
2613
    } else {
2614
        if (std::find(sub_transaction->deleted_conflicts.begin(), sub_transaction->deleted_conflicts.end(), conflict)
2615
            == sub_transaction->deleted_conflicts.end()) {
2616
 
2617
            CYG_FAIL("The inference engine has proved too optimistic.");
2618
            sub_transaction->cancel();
2619
            delete sub_transaction;
2620
            conflict->no_solution = true;
2621
            CYG_REPORT_RETURN();
2622
            return;
2623
        }
2624
    }
2625
 
2626
    // Even if there is a solution it cannot always be applied
2627
    // automatically because that would affect existing user
2628
    // values. Instead the solution needs to be saved so that
2629
    // the user can inspect it later. This should only happen
2630
    // at level 0. If we have recursed into the inference
2631
    // engine then we should only worry about this right at
2632
    // the end, not at every stage (although internally the
2633
    // inference code may worry about this when choosing
2634
    // between alternatives).
2635
    if ((0 == level) && sub_transaction->user_confirmation_required()) {
2636
        sub_transaction->save_solution();
2637
        sub_transaction->cancel();
2638
        delete sub_transaction;
2639
        this->dirty = true;
2640
 
2641
        if (0 == conflict->transaction) {
2642
            // This is a global conflict, not a per-transaction one.
2643
            // There is a separate list of these conflicts.
2644
            std::list<CdlConflict>::const_iterator conf_i;
2645
            conf_i = std::find(this->global_conflicts_with_solutions.begin(),
2646
                               this->global_conflicts_with_solutions.end(),
2647
                               conflict);
2648
            if (conf_i == this->global_conflicts_with_solutions.end()) {
2649
                this->global_conflicts_with_solutions.push_back(conflict);
2650
            }
2651
        }
2652
    } else {
2653
 
2654
        // This sub-transaction is safe, it can be applied
2655
        // immediately. The commit code detects that the
2656
        // solution being committed is for a particular
2657
        // resolved conflict and will take care of moving that
2658
        // conflict to the resolved list.
2659
        conflict->solution_references.clear();     // No point in preserving this information
2660
        conflict->no_solution = false;             // Redundant
2661
        std::map<CdlValuable, CdlValue>::const_iterator soln_i;
2662
        for (soln_i = sub_transaction->changes.begin(); soln_i != sub_transaction->changes.end(); soln_i++) {
2663
            conflict->solution.push_back(*soln_i);
2664
        }
2665
        sub_transaction->commit();
2666
        delete sub_transaction;
2667
    }
2668
 
2669
    CYG_REPORT_RETURN();
2670
}
2671
 
2672
//}}}
2673
//{{{  resolve_recursion()                              
2674
 
2675
// ----------------------------------------------------------------------------
2676
// resolve_recursion()
2677
//
2678
// The inference engine has tried one or more changes in the context of
2679
// a sub-transaction. It is now necessary to check whether these changes
2680
// are beneficial, i.e. whether or not any new problems are introduced
2681
// that cannot be resolved.
2682
bool
2683
CdlTransactionBody::resolve_recursion(int level)
2684
{
2685
    CYG_REPORT_FUNCNAMETYPE("CdlTransaction::resolve_recursion", "result %d");
2686
    CYG_REPORT_FUNCARG2XV(this, level);
2687
    CYG_PRECONDITION_THISC();
2688
 
2689
    bool result = false;
2690
    this->propagate();
2691
    if (0 == new_conflicts.size()) {
2692
        result = true;
2693
        CYG_REPORT_RETVAL(result);
2694
        return result;
2695
    }
2696
    if (level >= inference_recursion_limit) {
2697
        result = false;
2698
        CYG_REPORT_RETVAL(result);
2699
        return result;
2700
    }
2701
 
2702
    // There are new conflicts, but it may be possible to resolve them
2703
    // by a recursive invocation of the inference engine.
2704
    bool solutions_possible = false;
2705
    do {
2706
        this->resolve(level + 1);
2707
        std::list<CdlConflict>::const_iterator conf_i;
2708
        solutions_possible = false;
2709
        for (conf_i = this->new_conflicts.begin(); conf_i != this->new_conflicts.end(); conf_i++) {
2710
            if (!(*conf_i)->has_no_solution()) {
2711
                solutions_possible = true;
2712
            }
2713
        }
2714
    } while(solutions_possible);
2715
 
2716
    result = (0 == new_conflicts.size());
2717
    CYG_REPORT_RETVAL(result);
2718
    return result;
2719
}
2720
 
2721
//}}}
2722
 
2723
//}}}
2724
//{{{  Body                                     
2725
 
2726
// ----------------------------------------------------------------------------
2727
// The majority of transactions involve the same set of steps. First one
2728
// or more values are modified. Then there has to be propagation, inference,
2729
// an inference callback, ... There may be a number of iterations. It is
2730
// convenient to have a single transaction body function which takes care
2731
// of all of that.
2732
//
2733
// If automatic inference is disabled then life is pretty simple, there
2734
// should be one propagate() operation followed by a commit.
2735
//
2736
// If automatic inference is enabled but there is no inference callback
2737
// then we need a loop consisting of propagation and inference, while
2738
// progress is made. Progress can be detected by value changes.
2739
//
2740
// If there is an inference callback then life gets pretty complicated.
2741
// The problem is figuring out exactly when the inference callback
2742
// should be invoked:
2743
//
2744
// 1) any new conflicts should certainly result in a callback, to give
2745
//    the user a chance to cancel the changes.
2746
// 2) any new solutions that have been applied automatically need to
2747
//    be shown to the user, again so that it is possible to cancel
2748
//    the changes.
2749
// 3) any existing conflicts with a new solution, albeit one that cannot
2750
//    be applied automatically, should result in a callback. This is
2751
//    somewhat problematical since the new solution may in fact be
2752
//    identical to a previous one that the user has already decided
2753
//    against committing.
2754
//
2755
// It is not easy to keep track of when new conflicts or solutions get
2756
// added to a transaction. Simply counting the entries in the
2757
// appropriate STL containers is insufficient, as conflicts come and
2758
// go. Instead it is necessary to have a "dirty" flag. Unfortunately
2759
// this too is not fool-proof: a new conflict may have been created,
2760
// resulting in the dirty flag being set, and then the conflict may
2761
// have disappeared.
2762
 
2763
void
2764
CdlTransactionBody::body()
2765
{
2766
    CYG_REPORT_FUNCNAME("CdlTransaction::body");
2767
    CYG_REPORT_FUNCARG1XV(this);
2768
    CYG_PRECONDITION_THISC();
2769
 
2770
    // The Body() member function can only be applied to a toplevel
2771
    // transaction, it does not really make sense to apply it to
2772
    // a sub-transaction (at least, not yet);
2773
    CYG_PRECONDITIONC((0 == parent) && (0 != toplevel));
2774
 
2775
    if (!inference_enabled) {
2776
        this->propagate();
2777
        this->commit();
2778
        CYG_REPORT_RETURN();
2779
        return;
2780
    }
2781
 
2782
    if (0 == inference_callback) {
2783
        bool progress = false;
2784
        do {
2785
            progress = false;
2786
            this->propagate();
2787
            CYG_LOOP_INVARIANTC(0 == value_changes.size());
2788
            this->resolve();
2789
            if (0 != value_changes.size()) {
2790
                progress = true;
2791
            }
2792
        } while(progress);
2793
 
2794
        this->commit();
2795
        CYG_REPORT_RETURN();
2796
        return;
2797
    }
2798
 
2799
    bool cancel = false;
2800
 
2801
    unsigned int resolved_size = 0;
2802
    unsigned int globals_with_solutions_size = 0;
2803
 
2804
    do {
2805
        bool progress = false;
2806
        do {
2807
            progress = false;
2808
            this->propagate();
2809
            CYG_LOOP_INVARIANTC(0 == value_changes.size());
2810
            this->resolve();
2811
            if (0 != value_changes.size()) {
2812
                progress = true;
2813
            }
2814
        } while(progress);
2815
 
2816
        // Sanity check: if there are no conflicts and no new entries in
2817
        // the resolved vector, then stop here. The user has already seen
2818
        // and taken care of everything of interest.
2819
        if ((0 == new_conflicts.size()) &&
2820
            (resolved_size == resolved_conflicts.size()) &&
2821
            (globals_with_solutions_size == global_conflicts_with_solutions.size())) {
2822
            cancel = false;
2823
            break;
2824
        }
2825
 
2826
        // Also, if no conflicts have been added, no new solutions
2827
        // have been identified, and no new solutions have been applied,
2828
        // then there is no point in asking for user feedback.
2829
        if (!this->dirty) {
2830
            cancel = false;
2831
            break;
2832
        }
2833
 
2834
        // Clear state before invoking the callback. If the user does not
2835
        // change anything else then we should get out of the loop next
2836
        // time around.
2837
        this->dirty = false;
2838
        resolved_size = resolved_conflicts.size();
2839
        globals_with_solutions_size = global_conflicts_with_solutions.size();
2840
 
2841
        // Invoke the callback. If the result is cancel, do so. Otherwise
2842
        // we need to spin while things are changing.
2843
        if (CdlInferenceCallbackResult_Cancel == (*inference_callback)(this)) {
2844
            cancel = true;
2845
        }
2846
    } while(!cancel);
2847
 
2848
    if (cancel) {
2849
        this->cancel();
2850
    } else {
2851
        this->commit();
2852
    }
2853
 
2854
    CYG_REPORT_RETURN();
2855
}
2856
 
2857
//}}}
2858
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.