Skip to content
GUIBridgeComponent1.tmpl 5.01 KiB
Newer Older
Gino Tosti's avatar
Gino Tosti committed
/*
 * ASTRI - Template based on ALMA Software Templates
 * (c) INAF/UNIPG, 2014
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY, without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307  USA
 *
 * WARNING! DO NOT MODIFY THIS FILE!
 *  ---------------------------------------------------------
 * | This is generated code!  Do not modify this file.       |
 * | Any changes will be lost when the file is re-generated. |
 *  ---------------------------------------------------------
 *
 *  Generated by: $Author
 *  Date: $Date
 *  Description: $Description
 *
 */

package astri.acceptance.generated;

import astri.acceptance.gui.ACSConnector;
import org.omg.CORBA.LongHolder;
import astri.TCSControlExceptions.OPCUAErrorEx;
import astri.TCSControlExceptions.INACTErrorEx;

import java.util.Optional;
import alma.acs.logging.AcsLogger;
import java.util.logging.Level;


import astri.tcs.${Assembly}Helper;
import astri.tcs.${Assembly};
Gino Tosti's avatar
Gino Tosti committed

public class ${Assembly}GUIBridgeComponent {

	public  static ${Assembly} component;
	private static final String COMPONENTNAME = "${Assembly}";
	private ACSConnector connector;
	private AcsLogger logger;

	public ${Assembly}GUIBridgeComponent(ACSConnector connector) throws Exception{
	
	    this.connector=connector;
	}
	
	public void connect(){
		try{
			component = ${Assembly}Helper.narrow(connector.getComponent(COMPONENTNAME));
			logger = connector.getLogger();
			logger.info("Connected to "+COMPONENTNAME);
		}catch(Exception e){
			logger.log(Level.SEVERE, "Error connecting to component "+COMPONENTNAME, e);
		}
	}
	
	public void release(){
		try{
			logger.info("Trying to release "+COMPONENTNAME);
			connector.releaseComponent(COMPONENTNAME);
			logger.info(COMPONENTNAME+" released");
		}catch(Exception e){
			logger.log(Level.SEVERE, "Error releasing "+COMPONENTNAME, e);
		}
	}
	
	#for  $idx in $range(0,$x.GetSheet["NRows"])
	#if ($x.GetSheet["OPC UA Data type"][$idx]).upper()[-1]==']' ## test for arrays
      #set $type=($x.GetSheet["OPC UA Data type"][$idx].upper()).split("[")[0]+"[]"
    #else
      #set $type=$x.GetSheet["OPC UA Data type"][$idx].upper()
    #end if
public Optional<${y[$type][6]}> get${x.GetSheet["Short name"][$idx]}() {
		logger.log(Level.FINEST, "Calling "+COMPONENTNAME+".get${x.GetSheet["Short name"][$idx]}()");
		try {
			return Optional.ofNullable(component.${x.GetSheet["Name of command"][$idx]}(new LongHolder()));
		} catch (OPCUAErrorEx | INACTErrorEx e) {
			logger.log(Level.SEVERE, "Error calling "+COMPONENTNAME+".get${x.GetSheet["Short name"][$idx]}()", e);
			return Optional.empty();
		}
	}

	#end for

	#for  $idx in $range(0,$x.SetSheet["NRows"])
	#if ($x.SetSheet["OPC UA Data type"][$idx]).upper()[-1]==']' ## test for arrays
         #set $type=($x.SetSheet["OPC UA Data type"][$idx].upper()).split("[")[0]+"[]"
	 public void ${x.SetSheet["Short name"][$idx]}(${y[$type][6]} param) throws Exception {
	        logger.log(Level.INFO, "Calling "+COMPONENTNAME+".${x.SetSheet["Name of command"][$idx]}("+param+")");
			component.${x.SetSheet["Name of command"][$idx]}(param);
	 }
       #else
        #set $type=$x.SetSheet["OPC UA Data type"][$idx].upper()
	public void ${x.SetSheet["Short name"][$idx]}(${y[$type][4]} param) throws Exception {
	        logger.log(Level.INFO, "Calling "+COMPONENTNAME+".${x.SetSheet["Name of command"][$idx]}("+param+")");
			component.${x.SetSheet["Name of command"][$idx]}(param);
	}
       #end if
  
    public Optional<${y[$type][6]}> get${x.SetSheet["Short name"][$idx]}() {
		logger.log(Level.FINEST, "Calling "+COMPONENTNAME+".get${x.SetSheet["Short name"][$idx]}()");
		try {
			return Optional.ofNullable(component.G${x.SetSheet["Name of command"][$idx][1:]}(new LongHolder()));
		} catch (OPCUAErrorEx | INACTErrorEx e) {
			logger.log(Level.SEVERE, "Error calling "+COMPONENTNAME+".get${x.SetSheet["Short name"][$idx]}()", e);
			return Optional.empty();
		}
	}
	#end for

	#for  $idx in $range(0,$x.CmdSheet["NRows"])
		public void ${x.CmdSheet["Short name"][$idx]}() throws Exception {
		    logger.log(Level.INFO, "Calling "+COMPONENTNAME+".${x.CmdSheet["Name of command"][$idx]}()");
			component.${x.CmdSheet["Name of command"][$idx]}();
		}
	#end for

	#for  $idx in $range(0,$x.ModeSheet["NRows"])
		public void ${x.ModeSheet["Short name"][$idx]}() throws Exception {
		    logger.log(Level.INFO, "Calling "+COMPONENTNAME+".${x.ModeSheet["Name of command"][$idx]}()");
			component.${x.ModeSheet["Name of command"][$idx]}();
		}
	#end for
}