Line data Source code
1 : /* File: ctrl_controller.c; Copyright and License: see below */
2 :
3 : #include "ctrl_controller.h"
4 : #include "u8/u8_trace.h"
5 : #include "u8/u8_log.h"
6 :
7 47 : void ctrl_controller_init ( ctrl_controller_t *this_, data_database_t *database )
8 : {
9 47 : U8_TRACE_BEGIN();
10 :
11 : /* init member attributes */
12 47 : (*this_).database = database;
13 47 : data_database_reader_init( &((*this_).db_reader), database );
14 47 : data_database_writer_init( &((*this_).db_writer), &((*this_).db_reader), database );
15 47 : ctrl_undo_redo_list_init( &((*this_).undo_redo_list), &((*this_).db_reader), &((*this_).db_writer) );
16 47 : consistency_classifier_init( &((*this_).consistency_classifier), &((*this_).db_reader), &((*this_).classifiers) );
17 47 : consistency_feature_init( &((*this_).consistency_feature), &((*this_).db_reader), &((*this_).classifiers) );
18 47 : consistency_lifeline_init( &((*this_).consistency_lifeline), &((*this_).db_reader), &((*this_).classifiers), &((*this_).diagrams) );
19 47 : consistency_relationship_init( &((*this_).consistency_relationship), &((*this_).db_reader), &((*this_).classifiers) );
20 47 : ctrl_classifier_trigger_init( &((*this_).classifier_trigger),
21 : &((*this_).consistency_feature),
22 : &((*this_).consistency_lifeline),
23 : &((*this_).consistency_relationship)
24 : );
25 47 : ctrl_diagram_trigger_init( &((*this_).diagram_trigger),
26 : &((*this_).consistency_classifier),
27 : &((*this_).consistency_feature),
28 : &((*this_).consistency_lifeline),
29 : &((*this_).consistency_relationship)
30 : );
31 47 : ctrl_classifier_controller_init ( &((*this_).classifiers),
32 : &((*this_).undo_redo_list),
33 : &((*this_).classifier_trigger),
34 : database,
35 : &((*this_).db_reader),
36 : &((*this_).db_writer)
37 : );
38 47 : ctrl_diagram_controller_init ( &((*this_).diagrams),
39 : &((*this_).undo_redo_list),
40 : &((*this_).diagram_trigger),
41 : database,
42 : &((*this_).db_reader),
43 : &((*this_).db_writer)
44 : );
45 47 : consistency_checker_init ( &((*this_).consistency_checker), database, &((*this_).db_reader), &((*this_).db_writer) );
46 :
47 : /* listen on db open and prepare_close events: */
48 47 : data_database_listener_init ( &((*this_).me_as_listener),
49 : this_,
50 : (void (*)(void*,data_database_listener_signal_t)) &ctrl_controller_db_change_callback
51 : );
52 47 : data_database_add_db_listener( (*this_).database, &((*this_).me_as_listener) );
53 :
54 47 : U8_TRACE_END();
55 47 : }
56 :
57 47 : void ctrl_controller_destroy ( ctrl_controller_t *this_ )
58 : {
59 47 : U8_TRACE_BEGIN();
60 :
61 : /* stop listening on db open and prepare_close events: */
62 47 : data_database_remove_db_listener( (*this_).database, &((*this_).me_as_listener) );
63 :
64 : /* destroy member attributes */
65 47 : ctrl_classifier_trigger_destroy( &((*this_).classifier_trigger) );
66 47 : ctrl_diagram_trigger_destroy( &((*this_).diagram_trigger) );
67 47 : consistency_checker_destroy ( &((*this_).consistency_checker) );
68 47 : ctrl_diagram_controller_destroy ( &((*this_).diagrams) );
69 47 : ctrl_classifier_controller_destroy ( &((*this_).classifiers) );
70 47 : consistency_classifier_destroy ( &((*this_).consistency_classifier) );
71 47 : consistency_feature_destroy ( &((*this_).consistency_feature) );
72 47 : consistency_lifeline_destroy ( &((*this_).consistency_lifeline) );
73 47 : consistency_relationship_destroy ( &((*this_).consistency_relationship) );
74 47 : ctrl_undo_redo_list_destroy ( &((*this_).undo_redo_list) );
75 47 : data_database_writer_destroy( &((*this_).db_writer) );
76 47 : data_database_reader_destroy( &((*this_).db_reader) );
77 :
78 47 : U8_TRACE_END();
79 47 : }
80 :
81 : /* ================================ interface for database file ================================ */
82 :
83 7 : void ctrl_controller_db_change_callback ( ctrl_controller_t *this_, data_database_listener_signal_t signal_id )
84 : {
85 7 : U8_TRACE_BEGIN();
86 :
87 : /* for any db event, clear the undo history */
88 7 : ctrl_undo_redo_list_clear( &((*this_).undo_redo_list) );
89 :
90 7 : U8_TRACE_END();
91 7 : }
92 :
93 :
94 : /*
95 : Copyright 2016-2026 Andreas Warnke
96 :
97 : Licensed under the Apache License, Version 2.0 (the "License");
98 : you may not use this file except in compliance with the License.
99 : You may obtain a copy of the License at
100 :
101 : http://www.apache.org/licenses/LICENSE-2.0
102 :
103 : Unless required by applicable law or agreed to in writing, software
104 : distributed under the License is distributed on an "AS IS" BASIS,
105 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
106 : See the License for the specific language governing permissions and
107 : limitations under the License.
108 : */
|