Commit | Line | Data |
---|---|---|
970ed795 | 1 | /////////////////////////////////////////////////////////////////////////////// |
3abe9331 | 2 | // Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
3 | // All rights reserved. This program and the accompanying materials |
4 | // are made available under the terms of the Eclipse Public License v1.0 | |
5 | // which accompanies this distribution, and is available at | |
6 | // http://www.eclipse.org/legal/epl-v10.html | |
7 | /////////////////////////////////////////////////////////////////////////////// | |
8 | #ifndef COMPONENT_HH | |
9 | #define COMPONENT_HH | |
10 | ||
11 | #include "Types.h" | |
12 | #include "Basetype.hh" | |
13 | #include "Template.hh" | |
14 | #include "Optional.hh" | |
15 | ||
16 | class Module_Param; | |
17 | ||
18 | // value class for all component types | |
19 | ||
20 | class COMPONENT : public Base_Type { | |
21 | friend class COMPONENT_template; | |
22 | friend boolean operator==(component component_value, | |
23 | const COMPONENT& other_value); | |
24 | ||
25 | static unsigned int n_component_names; | |
26 | struct component_name_struct; | |
27 | static component_name_struct *component_names; | |
28 | ||
29 | component component_value; | |
30 | ||
31 | public: | |
32 | COMPONENT(); | |
33 | COMPONENT(component other_value); | |
34 | COMPONENT(const COMPONENT& other_value); | |
35 | ||
36 | COMPONENT& operator=(component other_value); | |
37 | COMPONENT& operator=(const COMPONENT& other_value); | |
38 | ||
39 | boolean operator==(component other_value) const; | |
40 | boolean operator==(const COMPONENT& other_value) const; | |
41 | ||
42 | inline boolean operator!=(component other_value) const | |
43 | { return !(*this == other_value); } | |
44 | inline boolean operator!=(const COMPONENT& other_value) const | |
45 | { return !(*this == other_value); } | |
46 | ||
47 | operator component() const; | |
48 | ||
49 | inline boolean is_bound() const | |
50 | { return component_value != UNBOUND_COMPREF; } | |
51 | inline boolean is_value() const | |
52 | { return component_value != UNBOUND_COMPREF; } | |
53 | inline void clean_up() { component_value = UNBOUND_COMPREF; } | |
54 | void must_bound(const char*) const; | |
55 | ||
56 | void log() const; | |
57 | ||
58 | #ifdef TITAN_RUNTIME_2 | |
59 | boolean is_equal(const Base_Type* other_value) const { return *this == *(static_cast<const COMPONENT*>(other_value)); } | |
60 | void set_value(const Base_Type* other_value) { *this = *(static_cast<const COMPONENT*>(other_value)); } | |
61 | Base_Type* clone() const { return new COMPONENT(*this); } | |
62 | const TTCN_Typedescriptor_t* get_descriptor() const { return &COMPONENT_descr_; } | |
63 | #else | |
64 | inline boolean is_present() const { return is_bound(); } | |
65 | #endif | |
66 | ||
67 | alt_status done() const; | |
68 | alt_status killed() const; | |
69 | ||
70 | boolean running() const; | |
71 | boolean alive() const; | |
72 | ||
73 | void stop() const; | |
74 | void kill() const; | |
75 | ||
76 | void set_param(Module_Param& param); | |
3abe9331 | 77 | Module_Param* get_param(Module_Param_Name& param_name) const; |
970ed795 EL |
78 | |
79 | void encode_text(Text_Buf& text_buf) const; | |
80 | void decode_text(Text_Buf& text_buf); | |
81 | ||
82 | static void register_component_name(component component_reference, | |
83 | const char *component_name); | |
84 | static const char *get_component_name(component component_reference); | |
85 | static void clear_component_names(); | |
86 | static void log_component_reference(component component_reference); | |
87 | /** Returns the symbolic value of \p component_reference | |
88 | * | |
89 | * If it's a special value, it returns its name ("null","mtc" or "system"). | |
90 | * If it has a name, it returns "name(number)" | |
91 | * Else returns "number" | |
92 | * | |
93 | * @param component_reference | |
94 | * @return a string which must be Free()'d | |
95 | */ | |
96 | static char *get_component_string(component component_reference); | |
97 | ||
98 | inline boolean is_component() { return TRUE; } | |
99 | }; | |
100 | ||
101 | extern boolean operator==(component component_value, | |
102 | const COMPONENT& other_value); | |
103 | ||
104 | inline boolean operator!=(component component_value, | |
105 | const COMPONENT& other_value) | |
106 | { | |
107 | return !(component_value == other_value); | |
108 | } | |
109 | ||
110 | extern COMPONENT self; | |
111 | ||
112 | ||
113 | // template for all component types | |
114 | ||
115 | class COMPONENT_template : public Base_Template { | |
116 | private: | |
117 | union { | |
118 | component single_value; | |
119 | struct { | |
120 | unsigned int n_values; | |
121 | COMPONENT_template *list_value; | |
122 | } value_list; | |
123 | }; | |
124 | ||
125 | void copy_template(const COMPONENT_template& other_value); | |
126 | ||
127 | public: | |
128 | COMPONENT_template(); | |
129 | COMPONENT_template(template_sel other_value); | |
130 | COMPONENT_template(component other_value); | |
131 | COMPONENT_template(const COMPONENT& other_value); | |
132 | COMPONENT_template(const OPTIONAL<COMPONENT>& other_value); | |
133 | COMPONENT_template(const COMPONENT_template& other_value); | |
134 | ||
135 | ~COMPONENT_template(); | |
136 | void clean_up(); | |
137 | ||
138 | COMPONENT_template& operator=(template_sel other_value); | |
139 | COMPONENT_template& operator=(component other_value); | |
140 | COMPONENT_template& operator=(const COMPONENT& other_value); | |
141 | COMPONENT_template& operator=(const OPTIONAL<COMPONENT>& other_value); | |
142 | COMPONENT_template& operator=(const COMPONENT_template& other_value); | |
143 | ||
3abe9331 | 144 | boolean match(component other_value, boolean legacy = FALSE) const; |
145 | boolean match(const COMPONENT& other_value, boolean legacy = FALSE) const; | |
970ed795 EL |
146 | component valueof() const; |
147 | ||
148 | void set_type(template_sel template_type, unsigned int list_length); | |
149 | COMPONENT_template& list_item(unsigned int list_index); | |
150 | ||
151 | void log() const; | |
3abe9331 | 152 | void log_match(const COMPONENT& match_value, boolean legacy = FALSE) const; |
970ed795 EL |
153 | |
154 | void set_param(Module_Param& param); | |
3abe9331 | 155 | Module_Param* get_param(Module_Param_Name& param_name) const; |
970ed795 EL |
156 | |
157 | void encode_text(Text_Buf& text_buf) const; | |
158 | void decode_text(Text_Buf& text_buf); | |
159 | ||
3abe9331 | 160 | boolean is_present(boolean legacy = FALSE) const; |
161 | boolean match_omit(boolean legacy = FALSE) const; | |
970ed795 EL |
162 | #ifdef TITAN_RUNTIME_2 |
163 | void valueofv(Base_Type* value) const { *(static_cast<COMPONENT*>(value)) = valueof(); } | |
164 | void set_value(template_sel other_value) { *this = other_value; } | |
165 | void copy_value(const Base_Type* other_value) { *this = *(static_cast<const COMPONENT*>(other_value)); } | |
166 | Base_Template* clone() const { return new COMPONENT_template(*this); } | |
167 | const TTCN_Typedescriptor_t* get_descriptor() const { return &COMPONENT_descr_; } | |
3abe9331 | 168 | boolean matchv(const Base_Type* other_value, boolean legacy) const { return match(*(static_cast<const COMPONENT*>(other_value)), legacy); } |
169 | void log_matchv(const Base_Type* match_value, boolean legacy) const { log_match(*(static_cast<const COMPONENT*>(match_value)), legacy); } | |
970ed795 | 170 | #else |
3abe9331 | 171 | void check_restriction(template_res t_res, const char* t_name=NULL, boolean legacy = FALSE) const; |
970ed795 EL |
172 | #endif |
173 | ||
174 | inline boolean is_component() { return TRUE; } | |
175 | }; | |
176 | ||
177 | extern const COMPONENT_template& any_compref; | |
178 | ||
179 | #endif |