00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 #ifndef SCV_TR_H
00103 #define SCV_TR_H
00104
00105
00106
00107
00108
00109
00110
00111 struct _scv_tr_generator_default_data {
00112 int _default_field_;
00113 };
00114 SCV_EXTENSIONS(_scv_tr_generator_default_data) {
00115 public:
00116 scv_extensions<int> _default_field_;
00117 SCV_EXTENSIONS_CTOR(_scv_tr_generator_default_data) {
00118 SCV_FIELD(_default_field_);
00119 }
00120 };
00121
00122
00123
00124
00125
00126 extern void scv_tr_text_init();
00127
00128
00129
00130 class _scv_tr_db_core;
00131 class _scv_tr_stream_core;
00132 class _scv_tr_generator_core;
00133 class _scv_tr_handle_core;
00134
00135 class scv_tr_stream;
00136 class scv_tr_generator_base;
00137 template<class T1, class T2> class scv_tr_generator;
00138 class scv_tr_handle;
00139
00140 typedef long scv_tr_relation_handle_t;
00141
00142
00143
00144
00145 class scv_tr_db : public scv_object_if {
00146 public:
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 scv_tr_db(
00170 const char* recording_file_name,
00171 const sc_time_unit& = SC_FS);
00172
00173
00174
00175
00176 virtual ~scv_tr_db();
00177
00178
00179
00180
00181 static void set_default_db(scv_tr_db*);
00182 static scv_tr_db* get_default_db();
00183
00184
00185
00186
00187 enum callback_reason { CREATE, DELETE, SUSPEND, RESUME };
00188
00189 typedef int callback_h;
00190
00191
00192
00193 typedef void callback_function(
00194 const scv_tr_db& obj,
00195 callback_reason reason,
00196 void* user_data_p);
00197
00198
00199
00200 static callback_h register_class_cb(
00201 callback_function*,
00202 void* user_data_p = NULL);
00203
00204
00205
00206 static void remove_callback(callback_h);
00207
00208
00209
00210
00211
00212
00213 void set_recording(bool) const;
00214 bool get_recording() const;
00215
00216 void print(ostream& o, int details=0, int indent=0) const;
00217 void show(int details=0, int indent=0) const;
00218 static void set_debug(int debug);
00219 static int get_debug();
00220
00221 const char *get_name() const;
00222 const char *kind() const { return _kind; }
00223
00224
00225
00226
00227
00228
00229 scv_tr_relation_handle_t create_relation(
00230 const char* relation_name) const;
00231
00232
00233
00234
00235 const char* get_relation_name(
00236 scv_tr_relation_handle_t relation_handle) const;
00237
00238 private:
00239 friend class scv_tr_stream;
00240 _scv_tr_db_core* _scv_tr_db_core_p;
00241 static const char *_kind;
00242 };
00243
00244
00245
00246 class scv_tr_stream : public scv_object_if {
00247 public:
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 scv_tr_stream(
00264 const char* full_stream_name,
00265 const char* stream_kind,
00266 scv_tr_db* scv_tr_db_p = scv_tr_db::get_default_db());
00267
00268 scv_tr_stream() { this->_scv_tr_stream_core_p = NULL; }
00269
00270 virtual ~scv_tr_stream();
00271
00272
00273
00274
00275 enum callback_reason { CREATE, DELETE };
00276
00277 typedef int callback_h;
00278
00279 typedef void callback_function(
00280 const scv_tr_stream& obj,
00281 callback_reason reason,
00282 void* user_data_p);
00283
00284
00285
00286 static callback_h register_class_cb(
00287 callback_function*,
00288 void* user_data_p = NULL);
00289
00290
00291
00292 static void remove_callback(callback_h);
00293
00294 void print(ostream& o, int details=0, int indent=0) const;
00295 void show(int details=0, int indent=0) const;
00296 static void set_debug(int debug);
00297 static int get_debug();
00298
00299 const char *get_name() const;
00300 const char *kind() const { return _kind; }
00301
00302 uint64 get_id() const;
00303
00304 const char* get_stream_kind() const;
00305
00306
00307
00308
00309
00310 scv_tr_handle get_current_transaction_handle();
00311
00312
00313
00314 const scv_tr_db* get_scv_tr_db() const;
00315
00316 private:
00317 template<class T1, class T2> friend class scv_tr_generator;
00318 friend class scv_tr_generator_base;
00319 _scv_tr_stream_core* _scv_tr_stream_core_p;
00320 static const char *_kind;
00321 };
00322
00323
00324
00325 class scv_tr_handle : public scv_object_if {
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340 public:
00341
00342
00343
00344
00345 scv_tr_handle();
00346
00347 virtual ~scv_tr_handle();
00348
00349
00350
00351 scv_tr_handle &operator=(
00352 const scv_tr_handle& other);
00353
00354
00355
00356 scv_tr_handle(
00357 const scv_tr_handle& other);
00358
00359
00360
00361
00362
00363
00364
00365
00366 void end_transaction() {
00367 this->_end_transaction(NULL, sc_time_stamp());
00368 }
00369
00370
00371
00372
00373 template<class T_end> void end_transaction(
00374 const scv_tr_handle& t,
00375 const T_end& end_attribute_values)
00376 {
00377 scv_extensions<T_end> ext = scv_get_const_extensions(end_attribute_values);
00378 this->_end_transaction(&ext, sc_time_stamp());
00379 }
00380
00381
00382
00383
00384 template<class T_end> void end_transaction(
00385 const scv_tr_handle& t,
00386 const T_end& end_attribute_values,
00387 const sc_time& end_sc_time)
00388 {
00389 scv_extensions<T_end> ext = scv_get_const_extensions(end_attribute_values);
00390 this->_end_transaction(&ext, end_sc_time);
00391 }
00392
00393
00394
00395
00396
00397
00398 template <class T> void record_attribute(
00399 const char* attribute_name,
00400 const T& attribute_value) {
00401 scv_extensions<T> ext = scv_get_const_extensions(attribute_value);
00402 this->_record_attribute(attribute_name, &ext);
00403 }
00404
00405 template <class T> void record_attribute(
00406 const T& attribute_value) {
00407 scv_extensions<T> ext = scv_get_const_extensions(attribute_value);
00408 this->_record_attribute(0, &ext);
00409 }
00410
00411
00412
00413
00414 enum callback_reason { BEGIN, END, DELETE };
00415
00416 typedef int callback_h;
00417
00418
00419
00420 typedef void callback_function(
00421 const scv_tr_handle& obj,
00422 callback_reason reason,
00423 void* user_data_p);
00424
00425
00426
00427 static callback_h register_class_cb(
00428 callback_function*,
00429 void* user_data_p = NULL);
00430
00431
00432
00433
00434
00435 typedef void callback_record_attribute_function(
00436 const scv_tr_handle& obj,
00437 const char* attribute_name,
00438 const scv_extensions_if* exts_p,
00439 void* user_data_p);
00440
00441
00442
00443 static callback_h register_record_attribute_cb(
00444 callback_record_attribute_function*,
00445 void* user_data_p = NULL);
00446
00447
00448
00449
00450 typedef void callback_relation_function(
00451 const scv_tr_handle& transaction_1,
00452 const scv_tr_handle& transaction_2,
00453 void* user_data_p,
00454 scv_tr_relation_handle_t relation_handle);
00455
00456
00457
00458
00459 static callback_h register_relation_cb(
00460 callback_relation_function*,
00461 void* user_data_p = NULL);
00462
00463
00464
00465 static void remove_callback(callback_h);
00466
00467
00468
00469
00470
00471
00472 bool is_valid() const;
00473
00474
00475
00476
00477 bool is_active() const;
00478
00479
00480
00481 const scv_extensions_if* get_begin_exts_p() const;
00482 const scv_extensions_if* get_end_exts_p() const;
00483
00484
00485
00486 const scv_extensions_if* get_builtin_exts_p() const;
00487
00488
00489
00490 uint64 get_id() const;
00491
00492 void print(ostream& o, int details=0, int indent=0) const;
00493 void show(int details=0, int indent=0) const;
00494 static void set_debug(int debug);
00495 static int get_debug();
00496
00497 const char *get_name() const;
00498 const char *kind() const { return _kind; }
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511 bool add_relation(
00512 scv_tr_relation_handle_t relation_handle,
00513 const scv_tr_handle& other_transaction_handle);
00514
00515 bool add_relation(
00516 const char* relation_name,
00517 const scv_tr_handle& other_transaction_handle) {
00518 return add_relation(
00519 get_scv_tr_stream().get_scv_tr_db()->create_relation(relation_name),
00520 other_transaction_handle);
00521 };
00522
00523
00524
00525
00526
00527 const scv_tr_handle* get_immediate_related_transaction(
00528 scv_tr_relation_handle_t* relation_handle_p) const;
00529
00530
00531
00532 const sc_time& get_begin_sc_time() const;
00533 const sc_time& get_end_sc_time() const;
00534
00535
00536
00537 const scv_tr_stream& get_scv_tr_stream() const;
00538
00539
00540
00541
00542 const scv_tr_generator_base& get_scv_tr_generator_base() const;
00543
00544 private:
00545 _scv_tr_handle_core* _scv_tr_handle_core_p;
00546 friend class scv_tr_generator_base;
00547 template<class T1, class T2> friend class scv_tr_generator;
00548 void _end_transaction(const scv_extensions_if*,
00549 const sc_time& end_sc_time) const;
00550 static const char *_kind;
00551 void _record_attribute(const char* attribute_name, const scv_extensions_if*);
00552 };
00553
00554
00555
00556 class scv_tr_generator_base : public scv_object_if {
00557 friend class scv_tr_stream;
00558 friend class scv_tr_handle;
00559 public:
00560
00561 scv_tr_generator_base(
00562 const char* name,
00563 scv_tr_stream& s,
00564 const char* begin_attribute_name,
00565 const char* end_attribute_name);
00566
00567 scv_tr_generator_base() { this->_scv_tr_generator_core_p = NULL; }
00568
00569 virtual ~scv_tr_generator_base();
00570
00571
00572
00573
00574 const char* get_begin_attribute_name() const;
00575 const char* get_end_attribute_name() const;
00576
00577
00578
00579 enum callback_reason { CREATE, DELETE };
00580
00581 typedef int callback_h;
00582
00583 typedef void callback_function(
00584 const scv_tr_generator_base& obj,
00585 callback_reason reason,
00586 void* user_data_p);
00587
00588
00589
00590 static callback_h register_class_cb(
00591 callback_function*,
00592 void* user_data_p = NULL);
00593
00594
00595
00596 static void remove_callback(callback_h);
00597
00598
00599
00600
00601
00602 void print(ostream& o, int details=0, int indent=0) const;
00603 void show(int details=0, int indent=0) const;
00604 static void set_debug(int debug);
00605 static int get_debug();
00606
00607 const char *get_name() const;
00608 const char *kind() const { return "scv_tr_generator"; }
00609
00610 uint64 get_id() const;
00611
00612
00613
00614
00615
00616
00617 const scv_tr_stream& get_scv_tr_stream() const;
00618
00619
00620
00621
00622
00623
00624 const scv_extensions_if* get_begin_exts_p() const;
00625 const scv_extensions_if* get_end_exts_p() const;
00626
00627 private:
00628 _scv_tr_generator_core* _scv_tr_generator_core_p;
00629
00630 public:
00631 scv_tr_handle _begin_transaction(
00632 const scv_extensions_if*,
00633 const sc_time&,
00634 scv_tr_relation_handle_t relation_handle,
00635 const scv_tr_handle* other_handle_p = NULL) const;
00636
00637 void _end_transaction(
00638 const scv_tr_handle& t,
00639 const scv_extensions_if*,
00640 const sc_time& end_sc_time) const;
00641 public:
00642
00643 void _set_begin_exts_p(const scv_extensions_if*);
00644 void _set_end_exts_p(const scv_extensions_if*);
00645 void _process_callbacks();
00646 };
00647
00648
00649
00650 template < class T_begin = _scv_tr_generator_default_data,
00651 class T_end = _scv_tr_generator_default_data >
00652 class scv_tr_generator : public scv_tr_generator_base {
00653 public:
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689 scv_tr_generator(
00690 const char* name,
00691 scv_tr_stream& s,
00692 const char* begin_attribute_name = NULL,
00693 const char* end_attribute_name = NULL) :
00694 scv_tr_generator_base(
00695 name, s, begin_attribute_name, end_attribute_name),
00696 _begin_ext(scv_get_const_extensions(_tmp_begin_attributes)),
00697 _end_ext(scv_get_const_extensions(_tmp_end_attributes))
00698 {
00699 this->_set_begin_exts_p(&_begin_ext);
00700 this->_set_end_exts_p(&_end_ext);
00701 this->_process_callbacks();
00702 }
00703
00704 scv_tr_generator() {}
00705
00706 ~scv_tr_generator() {}
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734 scv_tr_handle begin_transaction()
00735 {
00736 return this->_begin_transaction(
00737 NULL,
00738 sc_time_stamp(),
00739 0);
00740 }
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757 scv_tr_handle begin_transaction(
00758 scv_tr_relation_handle_t relation_handle,
00759 const scv_tr_handle& other_transaction_handle)
00760 {
00761 return this->_begin_transaction(
00762 NULL,
00763 sc_time_stamp(),
00764 relation_handle,
00765 &other_transaction_handle);
00766 }
00767
00768 scv_tr_handle begin_transaction(
00769 const char* relation_name,
00770 const scv_tr_handle& other_transaction_handle)
00771 {
00772 return this->_begin_transaction(
00773 NULL,
00774 sc_time_stamp(),
00775 get_scv_tr_stream().get_scv_tr_db()->create_relation(relation_name),
00776 &other_transaction_handle);
00777 }
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787 scv_tr_handle begin_transaction(
00788 const T_begin& begin_attribute_values)
00789 {
00790 scv_extensions<T_begin> ext =
00791 scv_get_const_extensions(begin_attribute_values);
00792 return this->_begin_transaction(
00793 &ext,
00794 sc_time_stamp(),
00795 0);
00796 }
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808 scv_tr_handle begin_transaction(
00809 const T_begin& begin_attribute_values,
00810 scv_tr_relation_handle_t relation_handle,
00811 const scv_tr_handle& other_transaction_handle)
00812 {
00813 scv_extensions<T_begin> ext =
00814 scv_get_const_extensions(begin_attribute_values);
00815 return this->_begin_transaction(
00816 &ext,
00817 sc_time_stamp(),
00818 relation_handle,
00819 &other_transaction_handle);
00820 }
00821
00822 scv_tr_handle begin_transaction(
00823 const T_begin& begin_attribute_values,
00824 const char* relation_name,
00825 const scv_tr_handle& other_transaction_handle)
00826 {
00827 scv_extensions<T_begin> ext =
00828 scv_get_const_extensions(begin_attribute_values);
00829 return this->_begin_transaction(
00830 &ext,
00831 sc_time_stamp(),
00832 get_scv_tr_stream().get_scv_tr_db()->create_relation(relation_name),
00833 &other_transaction_handle);
00834 }
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850 scv_tr_handle begin_transaction(
00851 const sc_time& begin_sc_time)
00852 {
00853 return this->_begin_transaction(
00854 NULL,
00855 begin_sc_time,
00856 0);
00857 }
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875 scv_tr_handle begin_transaction(
00876 const sc_time& begin_sc_time,
00877 scv_tr_relation_handle_t relation_handle,
00878 const scv_tr_handle& other_transaction_handle)
00879 {
00880 return this->_begin_transaction(
00881 NULL,
00882 begin_sc_time,
00883 relation_handle,
00884 &other_transaction_handle);
00885 }
00886
00887 scv_tr_handle begin_transaction(
00888 const sc_time& begin_sc_time,
00889 const char* relation_name,
00890 const scv_tr_handle& other_transaction_handle)
00891 {
00892 return this->_begin_transaction(
00893 NULL,
00894 begin_sc_time,
00895 get_scv_tr_stream().get_scv_tr_db()->create_relation(relation_name),
00896 &other_transaction_handle);
00897 }
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909 scv_tr_handle begin_transaction(
00910 const T_begin& begin_attribute_values,
00911 const sc_time& begin_sc_time)
00912 {
00913 scv_extensions<T_begin> ext =
00914 scv_get_const_extensions(begin_attribute_values);
00915 return this->_begin_transaction(
00916 &ext,
00917 begin_sc_time,
00918 0);
00919 }
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931 scv_tr_handle begin_transaction(
00932 const T_begin& begin_attribute_values,
00933 const sc_time& begin_sc_time,
00934 scv_tr_relation_handle_t relation_handle,
00935 const scv_tr_handle& other_transaction_handle)
00936 {
00937 scv_extensions<T_begin> ext =
00938 scv_get_const_extensions(begin_attribute_values);
00939 return this->_begin_transaction(
00940 &ext,
00941 begin_sc_time,
00942 relation_handle,
00943 &other_transaction_handle);
00944 }
00945
00946 scv_tr_handle begin_transaction(
00947 const T_begin& begin_attribute_values,
00948 const sc_time& begin_sc_time,
00949 const char* relation_name,
00950 const scv_tr_handle& other_transaction_handle)
00951 {
00952 scv_extensions<T_begin> ext =
00953 scv_get_const_extensions(begin_attribute_values);
00954 return this->_begin_transaction(
00955 &ext,
00956 begin_sc_time,
00957 get_scv_tr_stream().get_scv_tr_db()->create_relation(relation_name),
00958 &other_transaction_handle);
00959 }
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969 void end_transaction(
00970 const scv_tr_handle& t)
00971 {
00972 this->_end_transaction(t, NULL, sc_time_stamp());
00973 }
00974
00975
00976
00977
00978 void end_transaction(
00979 const scv_tr_handle& t,
00980 const T_end& end_attribute_values)
00981 {
00982 scv_extensions<T_end> ext = scv_get_const_extensions(end_attribute_values);
00983 this->_end_transaction(t, &ext, sc_time_stamp());
00984 }
00985
00986
00987
00988
00989
00990
00991
00992 void end_transaction(
00993 const scv_tr_handle& t,
00994 const sc_time& end_sc_time)
00995 {
00996 this->_end_transaction(t, NULL, end_sc_time);
00997 }
00998
00999
01000
01001
01002 void end_transaction(
01003 const scv_tr_handle& t,
01004 const T_end& end_attribute_values,
01005 const sc_time& end_sc_time)
01006 {
01007 scv_extensions<T_end> ext = scv_get_const_extensions(end_attribute_values);
01008 this->_end_transaction(t, &ext, end_sc_time);
01009 }
01010
01011
01012
01013 private:
01014 friend class scv_tr_handle;
01015 T_begin _tmp_begin_attributes;
01016 T_end _tmp_end_attributes;
01017 scv_extensions<T_begin> _begin_ext;
01018 scv_extensions<T_end> _end_ext;
01019 };
01020
01021
01022
01023 #endif // SCV_TR_H
01024