package com.cisdi.data.AMETEKSurfaceVision.gateway;

import com.cisdi.data.sdk.gateway.netty.SessionFactory;
import com.cisdi.data.sdk.gateway.netty.impl.AbstractChannelInitializer;
import com.cisdi.data.sdk.gateway.netty.impl.AbstractIoChannelHandler;
import com.cisdi.data.sdk.gateway.netty.impl.DefaultIoChannelHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.handler.timeout.IdleStateHandler;
import java.util.ArrayList;
import java.util.List;

/**
 * 表检仪协议通道初始化
 *
 * @author tzz
 */
public class SurfaceVisionChannelInitializer<I> extends AbstractChannelInitializer<I> {
    private SessionFactory factory;

    /**
     * 构造通道初始化器对象
     * @param factory 会话工厂
     */
    public SurfaceVisionChannelInitializer(SessionFactory factory) {
        this.factory = factory;
    }

    @SuppressWarnings("unchecked")
    @Override
    protected AbstractIoChannelHandler<I> getTailHandler() {
        return new DefaultIoChannelHandler(factory);
    }

    @Override
    protected List<ChannelHandler> getHandlers() {
        List<ChannelHandler> handlers = new ArrayList<ChannelHandler>();
        handlers.add(new SurfaceVisionFrameDecoder());
        return handlers;
    }

    @Override
    protected IdleStateHandler getIdleStateHandler() {
        return new IdleStateHandler(15, 15, 30);
    }

    @Override
    protected ChannelHandler getSslChannelHandler(Channel socketChannel) {
        return null;
    }
}
