001package jmri.jmrit.logixng; 002 003import java.util.Collection; 004 005import jmri.NamedBean; 006import jmri.jmrit.logixng.SymbolTable.InitialValueType; 007import jmri.jmrit.logixng.SymbolTable.VariableData; 008 009/** 010 * Represent a LogixNG module. 011 * A module is similar to a ConditionalNG, except that it can be used by 012 * both ConditionalNGs and modules. 013 * 014 * @author Daniel Bergqvist Copyright (C) 2020 015 */ 016public interface Module extends Base, NamedBean { 017 018 /** 019 * Is the module visible to the user? 020 * @return true if the module is visible, false otherwise. 021 */ 022 boolean isVisible(); 023 024 /** 025 * Makes the module visible or not visible to the user. 026 * @param value true to make the module visible, false to make it invisible 027 */ 028 void setVisible(boolean value); 029 030 /** 031 * Is the module stored in the tables and panels file if the module is empty? 032 * @return true if it's always stored, false if it's not stored if empty 033 */ 034 boolean isStoreIfEmpty(); 035 036 /** 037 * Set whenether the module should be stored in the tables and panels file 038 * if the module is empty. 039 * @param value true if it's always stored, false if it's not stored if empty 040 */ 041 void setStoreIfEmpty(boolean value); 042 043 /** 044 * Get the type of the root socket of the module. 045 * @return the type 046 */ 047 FemaleSocketManager.SocketType getRootSocketType(); 048 049 /** 050 * Get the root socket of the module. 051 * @return the root socket 052 */ 053 FemaleSocket getRootSocket(); 054 055 /** 056 * Set the current ConditionalNG of the module. 057 * This method is called on all modules before a ConditionalNG is executed 058 * to let the modules know which ConditionalNG is running in which thread. 059 * 060 * @param conditionalNG the ConditionalNG 061 */ 062 void setCurrentConditionalNG(ConditionalNG conditionalNG); 063 064 void addParameter(String name, boolean isInput, boolean isOutput); 065 066 void addParameter(Parameter parameter); 067 068 void addLocalVariable( 069 String name, 070 SymbolTable.InitialValueType initialValueType, 071 String initialValueData); 072 073 Collection<Parameter> getParameters(); 074 075 Collection<VariableData> getLocalVariables(); 076 077 078 /** 079 * The definition of a parameter. 080 */ 081 interface Parameter { 082 083 /** 084 * The name of the parameter 085 * @return the name 086 */ 087 String getName(); 088 089 /** 090 * Answer whenether or not the parameter is input to the module. 091 * @return true if the parameter is input, false otherwise 092 */ 093 boolean isInput(); 094 095 /** 096 * Answer whenether or not the parameter is output to the module. 097 * @return true if the parameter is output, false otherwise 098 */ 099 boolean isOutput(); 100 101 } 102 103 104 /** 105 * Data for a parameter. 106 */ 107 public static class ParameterData extends VariableData { 108 109 public ReturnValueType _returnValueType = ReturnValueType.None; 110 public String _returnValueData; 111 112 public ParameterData( 113 String name, 114 InitialValueType initialValueType, 115 String initialValueData, 116 ReturnValueType returnValueType, 117 String returnValueData) { 118 119 super(name, initialValueType, initialValueData); 120 121 _returnValueType = returnValueType; 122 _returnValueData = returnValueData; 123 } 124 125 public ParameterData(ParameterData data) { 126 super(data._name, data._initialValueType, data._initialValueData); 127 _returnValueType = data._returnValueType; 128 _returnValueData = data._returnValueData; 129 } 130 131 public ReturnValueType getReturnValueType() { 132 return _returnValueType; 133 } 134 135 public String getReturnValueData() { 136 return _returnValueData; 137 } 138 139 } 140 141 142 /** 143 * An enum that defines the types of initial value. 144 */ 145 enum ReturnValueType { 146 147 None(Bundle.getMessage("ReturnValueType_None")), 148 LocalVariable(Bundle.getMessage("ReturnValueType_LocalVariable")), 149 Memory(Bundle.getMessage("ReturnValueType_Memory")); 150 151 private final String _descr; 152 153 private ReturnValueType(String descr) { 154 _descr = descr; 155 } 156 157 public String getDescr() { 158 return _descr; 159 } 160 } 161 162 163}