| 1 | /****************************************************************************** |
| 2 | * Copyright (c) 2000-2016 Ericsson Telecom AB |
| 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 | * Contributors: |
| 9 | * |
| 10 | * Balasko, Jeno |
| 11 | * Baranyi, Botond |
| 12 | * Beres, Szabolcs |
| 13 | * Delic, Adam |
| 14 | * Forstner, Matyas |
| 15 | * Kovacs, Ferenc |
| 16 | * Raduly, Csaba |
| 17 | * Szabados, Kristof |
| 18 | * Szabo, Janos Zoltan – initial implementation |
| 19 | * |
| 20 | ******************************************************************************/ |
| 21 | #ifndef MODULE_LIST_HH |
| 22 | #define MODULE_LIST_HH |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include "Types.h" |
| 26 | |
| 27 | class Text_Buf; |
| 28 | class TTCN_Module; |
| 29 | class Module_Param; |
| 30 | class Module_Param_Name; |
| 31 | class ModuleVersion; |
| 32 | struct namespace_t; |
| 33 | |
| 34 | typedef void (*genericfunc_t)(void); |
| 35 | |
| 36 | class Module_List { |
| 37 | static TTCN_Module *list_head, *list_tail; |
| 38 | |
| 39 | public: |
| 40 | static void add_module(TTCN_Module *module_ptr); |
| 41 | static void remove_module(TTCN_Module *module_ptr); |
| 42 | static TTCN_Module *lookup_module(const char *module_name); |
| 43 | static TTCN_Module *single_control_part(); |
| 44 | |
| 45 | static void pre_init_modules(); |
| 46 | static void post_init_modules(); |
| 47 | |
| 48 | static void start_function(const char *module_name, |
| 49 | const char *function_name, Text_Buf& function_arguments); |
| 50 | |
| 51 | static void initialize_component(const char *module_name, |
| 52 | const char *component_type, boolean init_base_comps); |
| 53 | |
| 54 | static void set_param(Module_Param& param); |
| 55 | static Module_Param* get_param(Module_Param_Name& param_name); |
| 56 | static void log_param(); |
| 57 | |
| 58 | static void execute_control(const char *module_name); |
| 59 | static void execute_testcase(const char *module_name, |
| 60 | const char *testcase_name); |
| 61 | static void execute_all_testcases(const char *module_name); |
| 62 | |
| 63 | static void print_version(); |
| 64 | static void send_versions(); |
| 65 | static void list_testcases(); |
| 66 | static void push_version(Text_Buf& text_buf); |
| 67 | |
| 68 | static void encode_function(Text_Buf& text_buf, |
| 69 | genericfunc_t function_address); |
| 70 | static void decode_function(Text_Buf& text_buf, |
| 71 | genericfunc_t *function_addr_ptr); |
| 72 | static void log_function(genericfunc_t function_address); |
| 73 | static void encode_altstep(Text_Buf& text_buf, |
| 74 | genericfunc_t altstep_address); |
| 75 | static void decode_altstep(Text_Buf& text_buf, |
| 76 | genericfunc_t *altstep_addr_ptr); |
| 77 | static void log_altstep(genericfunc_t altstep_address); |
| 78 | static void encode_testcase(Text_Buf& text_buf, |
| 79 | genericfunc_t testcase_address); |
| 80 | static void decode_testcase(Text_Buf& text_buf, |
| 81 | genericfunc_t *testcase_addr_ptr); |
| 82 | static void log_testcase(genericfunc_t testcase_address); |
| 83 | |
| 84 | static genericfunc_t get_fat_null(); |
| 85 | |
| 86 | static genericfunc_t lookup_start_by_function_address( |
| 87 | genericfunc_t function_address); |
| 88 | static genericfunc_t lookup_standalone_address_by_altstep_address( |
| 89 | genericfunc_t altstep_address); |
| 90 | static genericfunc_t lookup_activate_address_by_altstep_address( |
| 91 | genericfunc_t altstep_address); |
| 92 | |
| 93 | private: |
| 94 | static boolean lookup_function_by_address(genericfunc_t function_address, |
| 95 | const char*& module_name, const char*& function_name); |
| 96 | static boolean lookup_altstep_by_address(genericfunc_t altstep_address, |
| 97 | const char*& module_name, const char*& altstep_name); |
| 98 | static boolean lookup_testcase_by_address(genericfunc_t testcase_address, |
| 99 | const char*& module_name, const char*& testcase_name); |
| 100 | }; |
| 101 | |
| 102 | class TTCN_Module { |
| 103 | friend class Module_List; |
| 104 | public: |
| 105 | enum module_type_enum { TTCN3_MODULE, ASN1_MODULE, CPLUSPLUS_MODULE }; |
| 106 | typedef void (*init_func_t)(); |
| 107 | typedef boolean (*set_param_func_t)(Module_Param& param); |
| 108 | typedef Module_Param* (*get_param_func_t)(Module_Param_Name& param_name); |
| 109 | typedef void (*log_param_func_t)(); |
| 110 | typedef boolean (*initialize_component_func_t)(const char *component_type, |
| 111 | boolean init_base_comps); |
| 112 | typedef boolean (*start_func_t)(const char *function_name, |
| 113 | Text_Buf& function_arguments); |
| 114 | typedef void (*control_func_t)(); |
| 115 | typedef verdicttype (*testcase_t)(boolean has_timer, double timer_value); |
| 116 | |
| 117 | private: |
| 118 | TTCN_Module *list_prev, *list_next; |
| 119 | module_type_enum module_type; |
| 120 | const char *module_name; |
| 121 | const char *compilation_date; |
| 122 | const char *compilation_time; |
| 123 | const unsigned char *md5_checksum; |
| 124 | const char* product_number; |
| 125 | unsigned int suffix; |
| 126 | unsigned int release; |
| 127 | unsigned int patch; |
| 128 | unsigned int build; |
| 129 | const char* extra; |
| 130 | size_t num_namespaces; |
| 131 | const namespace_t *xer_namespaces; |
| 132 | // FIXME instead of each module having its own list of namespaces with gaps, |
| 133 | // it may be better to have one global list in e.g. Module_list. |
| 134 | // Trouble is, Module_list is not really a class: there is no instance of it |
| 135 | // and it only has static members. |
| 136 | init_func_t pre_init_func, post_init_func; |
| 137 | boolean pre_init_called, post_init_called; |
| 138 | set_param_func_t set_param_func; |
| 139 | get_param_func_t get_param_func; |
| 140 | log_param_func_t log_param_func; |
| 141 | initialize_component_func_t initialize_component_func; |
| 142 | start_func_t start_func; |
| 143 | control_func_t control_func; |
| 144 | struct function_list_item; |
| 145 | function_list_item *function_head, *function_tail; |
| 146 | struct altstep_list_item; |
| 147 | altstep_list_item *altstep_head, *altstep_tail; |
| 148 | struct testcase_list_item; |
| 149 | testcase_list_item *testcase_head, *testcase_tail; |
| 150 | |
| 151 | /// Copy constructor disabled |
| 152 | TTCN_Module(const TTCN_Module&); |
| 153 | /// Assignment disabled |
| 154 | TTCN_Module& operator=(const TTCN_Module&); |
| 155 | public: |
| 156 | TTCN_Module(const char *par_module_name, |
| 157 | const char *par_compilation_date, |
| 158 | const char *par_compilation_time, |
| 159 | const unsigned char *par_md5_checksum, |
| 160 | init_func_t par_pre_init_func, |
| 161 | const char* par_product_number, |
| 162 | unsigned int par_suffix, |
| 163 | unsigned int par_release, |
| 164 | unsigned int par_patch, |
| 165 | unsigned int par_build, |
| 166 | const char* par_extra, |
| 167 | size_t par_num_namespace, |
| 168 | const namespace_t *par_namespaces, |
| 169 | init_func_t par_post_init_func, |
| 170 | set_param_func_t par_set_param_func, |
| 171 | get_param_func_t par_get_param_func, |
| 172 | log_param_func_t par_log_param_func, |
| 173 | initialize_component_func_t par_initialize_component_func, |
| 174 | start_func_t par_start_func, |
| 175 | control_func_t par_control_func); |
| 176 | TTCN_Module(const char *par_module_name, |
| 177 | const char *par_compilation_date, |
| 178 | const char *par_compilation_time, |
| 179 | const unsigned char *par_md5_checksum, |
| 180 | init_func_t par_init_func); |
| 181 | TTCN_Module(const char *par_module_name, |
| 182 | const char *par_compilation_date, |
| 183 | const char *par_compilation_time, |
| 184 | init_func_t par_init_func = NULL); |
| 185 | ~TTCN_Module(); |
| 186 | const char *get_name() const { return module_name; } |
| 187 | |
| 188 | void pre_init_module(); |
| 189 | void post_init_module(); |
| 190 | |
| 191 | void add_function(const char *function_name, genericfunc_t function_address, |
| 192 | genericfunc_t start_address); |
| 193 | void add_altstep(const char *altstep_name, genericfunc_t altstep_address, |
| 194 | genericfunc_t activate_address, genericfunc_t standalone_address); |
| 195 | void add_testcase_nonpard(const char *testcase_name, |
| 196 | testcase_t testcase_function); |
| 197 | void add_testcase_pard(const char *testcase_name, |
| 198 | genericfunc_t testcase_address); |
| 199 | |
| 200 | void execute_testcase(const char *testcase_name); |
| 201 | void execute_all_testcases(); |
| 202 | |
| 203 | const char *get_function_name_by_address(genericfunc_t function_address); |
| 204 | genericfunc_t get_function_address_by_name(const char *function_name); |
| 205 | genericfunc_t get_function_start_by_address(genericfunc_t function_address); |
| 206 | const char *get_altstep_name_by_address(genericfunc_t altstep_address); |
| 207 | genericfunc_t get_altstep_address_by_name(const char *altstep_name); |
| 208 | boolean get_altstep_data_by_address(genericfunc_t altstep_address, |
| 209 | genericfunc_t& standalone_address, genericfunc_t& activate_address); |
| 210 | const char *get_testcase_name_by_address(genericfunc_t testcase_address); |
| 211 | genericfunc_t get_testcase_address_by_name(const char *testcase_name); |
| 212 | |
| 213 | void print_version(); |
| 214 | ModuleVersion* get_version() const; |
| 215 | void list_testcases(); |
| 216 | size_t get_num_ns() const { return num_namespaces; } |
| 217 | const namespace_t *get_ns(size_t p_index) const; |
| 218 | const namespace_t *get_controlns() const; |
| 219 | }; |
| 220 | |
| 221 | #endif |