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//    public void setRootSocketType(FemaleSocketManager.SocketType socketType);
019    
020    public FemaleSocketManager.SocketType getRootSocketType();
021    
022    public FemaleSocket getRootSocket();
023    
024    public void setCurrentConditionalNG(ConditionalNG conditionalNG);
025    
026    public void addParameter(String name, boolean isInput, boolean isOutput);
027    
028    public void addParameter(Parameter parameter);
029    
030//    public void removeParameter(String name);
031    
032    public void addLocalVariable(
033            String name,
034            SymbolTable.InitialValueType initialValueType,
035            String initialValueData);
036    
037//    public void removeLocalVariable(String name);
038    
039    public Collection<Parameter> getParameters();
040    
041    public Collection<VariableData> getLocalVariables();
042    
043    
044    /**
045     * The definition of a parameter.
046     */
047    public interface Parameter {
048        
049        /**
050         * The name of the parameter
051         * @return the name
052         */
053        public String getName();
054        
055        /**
056         * Answer whenether or not the parameter is input to the module.
057         * @return true if the parameter is input, false otherwise
058         */
059        public boolean isInput();
060        
061        /**
062         * Answer whenether or not the parameter is output to the module.
063         * @return true if the parameter is output, false otherwise
064         */
065        public boolean isOutput();
066        
067    }
068    
069    
070    /**
071     * Data for a parameter.
072     */
073    public static class ParameterData extends VariableData {
074        
075        public ReturnValueType _returnValueType = ReturnValueType.None;
076        public String _returnValueData;
077        
078        public ParameterData(
079                String name,
080                InitialValueType initialValueType,
081                String initialValueData,
082                ReturnValueType returnValueType,
083                String returnValueData) {
084            
085            super(name, initialValueType, initialValueData);
086            
087            _returnValueType = returnValueType;
088            _returnValueData = returnValueData;
089        }
090        
091        public ParameterData(ParameterData data) {
092            super(data._name, data._initialValueType, data._initialValueData);
093            _returnValueType = data._returnValueType;
094            _returnValueData = data._returnValueData;
095        }
096        
097        public ReturnValueType getReturnValueType() {
098            return _returnValueType;
099        }
100        
101        public String getReturnValueData() {
102            return _returnValueData;
103        }
104        
105    }
106    
107    
108    /**
109     * An enum that defines the types of initial value.
110     */
111    public enum ReturnValueType {
112        
113        None(Bundle.getMessage("ReturnValueType_None")),
114        LocalVariable(Bundle.getMessage("ReturnValueType_LocalVariable")),
115        Memory(Bundle.getMessage("ReturnValueType_Memory"));
116        
117        private final String _descr;
118        
119        private ReturnValueType(String descr) {
120            _descr = descr;
121        }
122        
123        public String getDescr() {
124            return _descr;
125        }
126    }
127    
128    
129}