001package jmri.jmrix.openlcb; 002 003import java.util.List; 004 005import jmri.AddressedProgrammer; 006import jmri.GlobalProgrammerManager; 007import jmri.InstanceManager; 008import jmri.Programmer; 009import jmri.ProgrammingMode; 010import jmri.SystemConnectionMemo; 011import org.openlcb.OlcbInterface; 012 013import javax.annotation.Nonnull; 014 015/** 016 * Get access to available {@link Programmer} objects. 017 * <p> 018 * Programmers come in two types: 019 * <ul> 020 * <li>Global, previously "Service Mode" or on a programming track. Request 021 * these from an instance of {@link GlobalProgrammerManager}. 022 * <li>Addressed, previously "Ops Mode" also known as "programming on the main". Request 023 * these from an instance of this interface. 024 * </ul> 025 * You get a {@link Programmer} object from a ProgrammerManager, which in turn 026 * can be located from the {@link InstanceManager}. 027 * <p> 028 * This interface also provides a reserve/release system for tools that want to 029 * pretend they have exclusive use of a Programmer. This is a cooperative 030 * reservation; both tools (first and second reserver) must be using the 031 * reserve/release interface. 032 * <p> 033 * This file is part of JMRI. 034 * <p> 035 * JMRI is free software; you can redistribute it and/or modify it under the 036 * terms of version 2 of the GNU General Public License as published by the Free 037 * Software Foundation. See the "COPYING" file for a copy of this license. 038 * <p> 039 * JMRI is distributed in the hope that it will be useful, but WITHOUT ANY 040 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 041 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 042 * 043 * @see jmri.Programmer 044 * @author Bob Jacobsen Copyright (C) 2015 045 * @since 4.1.1 046 */ 047public class OlcbProgrammerManager extends jmri.managers.DefaultProgrammerManager { 048 049 private final SystemConnectionMemo system; 050 051 public OlcbProgrammerManager(SystemConnectionMemo system) { 052 super(new OlcbProgrammer(system.get(OlcbInterface.class), null)); 053 this.system = system; 054 } 055 056 public static final ProgrammingMode OPENLCBMODE = new ProgrammingMode("OPENLCBMODE", Bundle.getMessage("OPENLCBMODE")); 057 058 /** 059 * Gain access to a Addressed Mode Programmer without reservation. 060 * 061 * @param pLongAddress true if this is a long (14 bit) address, else false 062 * @param pAddress Specific decoder address to use. 063 * @return null only if there isn't an Ops Mode Programmer in the system 064 */ 065 @Override 066 public AddressedProgrammer getAddressedProgrammer(boolean pLongAddress, int pAddress) { 067 return new OlcbProgrammer(system.get(OlcbInterface.class), pLongAddress, pAddress); 068 } 069 070 /** 071 * Gain access to a (the) Addressed Mode Programmer, in the process 072 * reserving it for yourself. 073 * 074 * @param pLongAddress true if this is a long (14 bit) address, else false 075 * @param pAddress Specific decoder address to use. 076 * @return null if the address is in use by a reserved programmer 077 */ 078 @Override 079 public AddressedProgrammer reserveAddressedProgrammer(boolean pLongAddress, int pAddress) { return null; } 080 081 /** 082 * Return access to an Addressed Mode Programmer, so that it can be used 083 * elsewhere. 084 */ 085 @Override 086 public void releaseAddressedProgrammer(@Nonnull AddressedProgrammer p) {} 087 088 /** 089 * Convenience method to check whether you'll be able to get an Addressed 090 * Mode programmer. 091 * 092 * @return false if there's no chance of getting one 093 */ 094 @Override 095 public boolean isAddressedModePossible() { return true; } 096 097 /** 098 * Get the list of {@link ProgrammingMode} (generally) supported by 099 * Programmers provided by this Manager. 100 * <p> 101 * Use this to enquire about modes before you're ready to request a specific 102 * programmer. 103 * <p> 104 * If the order is significant, earlier modes are better. 105 */ 106 @Nonnull 107 @Override 108 public List<ProgrammingMode> getDefaultModes() { return new java.util.ArrayList<>(); } 109 110 /** 111 * Provides the human-readable representation for including 112 * ProgrammerManagers directly in user interface components, so it should return a 113 * user-provided name for this particular one. 114 */ 115 @Nonnull 116 @Override 117 public String getUserName() { return "OpenLCB"; } 118 119 /** 120 * toString() provides the human-readable representation for including 121 * ProgrammerManagers directly in user interface components, so it should return a 122 * user-provided name for this particular one. 123 */ 124 @Nonnull 125 @Override 126 public String toString() { return "OlcbProgrammerManager"; } 127}