// Path: src/main/java/com/ceridwen/circulation/SIP/netty/codec/SIPMessageDecoder.java
// @Sharable
// public class SIPMessageDecoder extends MessageToMessageDecoder<String> {
// 	private boolean strictChecksumChecking = false; 
// 
// 	public SIPMessageDecoder() {}
// 
// 	public SIPMessageDecoder(boolean strictChecksumChecking) 
// 	{
// 		this.strictChecksumChecking = strictChecksumChecking;
// 	}
// 
// 	@Override
// 	protected void decode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception {
// 		out.add(Message.decode(msg, null, strictChecksumChecking));
// 	}
// }
// 
// Path: src/main/java/com/ceridwen/circulation/SIP/netty/codec/SIPMessageEncoder.java
// @Sharable
// public class SIPMessageEncoder extends MessageToMessageEncoder<Message> {
// 	
// 	public SIPMessageEncoder() {}
// 
// 	@Override
// 	protected void encode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
// 		out.add(msg.encode() + "\r");
// 	}
// }
// 
// Path: src/main/java/com/ceridwen/circulation/SIP/netty/server/channel/SIPChannelHandler.java
// @Sharable
// public class SIPChannelHandler extends SimpleChannelInboundHandler<Message> {
//     private static Log logger = LogFactory.getLog(SIPChannelHandler.class);
// 
// 	private com.ceridwen.circulation.SIP.netty.server.driver.DriverFactory driverFactory;
// 	
// 	public SIPChannelHandler(DriverFactory driverFactory)
// 	{
// 		this.driverFactory = driverFactory;
// 	}
// 
//     @Override
//     public void channelActive(ChannelHandlerContext ctx) throws Exception {
// //        ctx.flush();
//     }
// 
//     private Message process(Message request) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, MessageNotUnderstood, InstantiationException {
//         Driver driver = driverFactory.getDriver();
// 
//         Method[] handlerMethods = driver.getClass().getMethods();
// 
//         for (Method handlerMethod : handlerMethods) {
//             Class<?> types[] = handlerMethod.getParameterTypes();
//             if (types.length == 1) {
//                 if (request.getClass() == types[0]) {
//                     return (Message) handlerMethod.invoke(driver, new Object[] { request });
//                 }
//             }
//         }
//         throw new MessageNotUnderstood();
//     }
// 
//     
// 	Message response = null;
//     
//     @Override
//     public void channelRead0(ChannelHandlerContext ctx, Message request) throws Exception {
//         if (!(request instanceof ACSResend)) {
//         	response = process(request);
//         } else if (response == null) {
//         	response = new SCResend();
//         }
// 
//         response.setSequenceCharacter(request.getSequenceCharacter());
//         
//         ChannelFuture future = ctx.write(response);
//     }
// 
//     @Override
//     public void channelReadComplete(ChannelHandlerContext ctx) {
//         ctx.flush();
//     }
// 
//     @Override
//     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
//     	if (cause instanceof java.io.IOException) {
//     		logger.debug(cause.getMessage());
//     	} else {
// 	    	logger.error("Transient communications error", cause);
// //	        cause.printStackTrace();
// 	        try {
// 	            ctx.write(new SCResend().encode(null));
// 	            ctx.flush();
// 	        } catch (Exception e1) {
// 	        	logger.error("Transient communications error", e1);
// 	            ctx.close();
// 	        }
// 	    }
//     }
// }
// 
// Path: src/main/java/com/ceridwen/circulation/SIP/netty/server/driver/DriverFactory.java
// public interface DriverFactory {
// 	Driver getDriver();
// }


import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.ssl.SslContext;
import com.ceridwen.circulation.SIP.netty.codec.SIPMessageDecoder;
import com.ceridwen.circulation.SIP.netty.codec.SIPMessageEncoder;
import com.ceridwen.circulation.SIP.netty.server.channel.SIPChannelHandler;
import com.ceridwen.circulation.SIP.netty.server.driver.DriverFactory;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.logging.LogLevel;
/* 
 * Copyright (C) 2020 Ceridwen Limited
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.ceridwen.circulation.SIP.netty.server;




public class SIPServerInitializer extends ChannelInitializer<SocketChannel> {
	
    private final StringDecoder DECODER = new StringDecoder();
    private final StringEncoder ENCODER = new StringEncoder();
    private SIPMessageDecoder SIPDECODER;
// Path: src/main/java/com/ceridwen/circulation/SIP/netty/codec/SIPMessageDecoder.java
// @Sharable
// public class SIPMessageDecoder extends MessageToMessageDecoder<String> {
// 	private boolean strictChecksumChecking = false; 
// 
// 	public SIPMessageDecoder() {}
// 
// 	public SIPMessageDecoder(boolean strictChecksumChecking) 
// 	{
// 		this.strictChecksumChecking = strictChecksumChecking;
// 	}
// 
// 	@Override
// 	protected void decode(ChannelHandlerContext ctx, String msg, List<Object> out) throws Exception {
// 		out.add(Message.decode(msg, null, strictChecksumChecking));
// 	}
// }
// 
// Path: src/main/java/com/ceridwen/circulation/SIP/netty/codec/SIPMessageEncoder.java
// @Sharable
// public class SIPMessageEncoder extends MessageToMessageEncoder<Message> {
// 	
// 	public SIPMessageEncoder() {}
// 
// 	@Override
// 	protected void encode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
// 		out.add(msg.encode() + "\r");
// 	}
// }
// 
// Path: src/main/java/com/ceridwen/circulation/SIP/netty/server/channel/SIPChannelHandler.java
// @Sharable
// public class SIPChannelHandler extends SimpleChannelInboundHandler<Message> {
//     private static Log logger = LogFactory.getLog(SIPChannelHandler.class);
// 
// 	private com.ceridwen.circulation.SIP.netty.server.driver.DriverFactory driverFactory;
// 	
// 	public SIPChannelHandler(DriverFactory driverFactory)
// 	{
// 		this.driverFactory = driverFactory;
// 	}
// 
//     @Override
//     public void channelActive(ChannelHandlerContext ctx) throws Exception {
// //        ctx.flush();
//     }
// 
//     private Message process(Message request) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, MessageNotUnderstood, InstantiationException {
//         Driver driver = driverFactory.getDriver();
// 
//         Method[] handlerMethods = driver.getClass().getMethods();
// 
//         for (Method handlerMethod : handlerMethods) {
//             Class<?> types[] = handlerMethod.getParameterTypes();
//             if (types.length == 1) {
//                 if (request.getClass() == types[0]) {
//                     return (Message) handlerMethod.invoke(driver, new Object[] { request });
//                 }
//             }
//         }
//         throw new MessageNotUnderstood();
//     }
// 
//     
// 	Message response = null;
//     
//     @Override
//     public void channelRead0(ChannelHandlerContext ctx, Message request) throws Exception {
//         if (!(request instanceof ACSResend)) {
//         	response = process(request);
//         } else if (response == null) {
//         	response = new SCResend();
//         }
// 
//         response.setSequenceCharacter(request.getSequenceCharacter());
//         
//         ChannelFuture future = ctx.write(response);
//     }
// 
//     @Override
//     public void channelReadComplete(ChannelHandlerContext ctx) {
//         ctx.flush();
//     }
// 
//     @Override
//     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
//     	if (cause instanceof java.io.IOException) {
//     		logger.debug(cause.getMessage());
//     	} else {
// 	    	logger.error("Transient communications error", cause);
// //	        cause.printStackTrace();
// 	        try {
// 	            ctx.write(new SCResend().encode(null));
// 	            ctx.flush();
// 	        } catch (Exception e1) {
// 	        	logger.error("Transient communications error", e1);
// 	            ctx.close();
// 	        }
// 	    }
//     }
// }
// 
// Path: src/main/java/com/ceridwen/circulation/SIP/netty/server/driver/DriverFactory.java
// public interface DriverFactory {
// 	Driver getDriver();
// }


// Path: src/main/java/com/ceridwen/circulation/SIP/netty/server/SIPServerInitializer.java
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.ssl.SslContext;
import com.ceridwen.circulation.SIP.netty.codec.SIPMessageDecoder;
import com.ceridwen.circulation.SIP.netty.codec.SIPMessageEncoder;
import com.ceridwen.circulation.SIP.netty.server.channel.SIPChannelHandler;
import com.ceridwen.circulation.SIP.netty.server.driver.DriverFactory;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.logging.LogLevel;

/* 
 * Copyright (C) 2020 Ceridwen Limited
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.ceridwen.circulation.SIP.netty.server;




public class SIPServerInitializer extends ChannelInitializer<SocketChannel> {
	
    private final StringDecoder DECODER = new StringDecoder();
    private final StringEncoder ENCODER = new StringEncoder();
    private SIPMessageDecoder SIPDECODER;
    private final SIPMessageEncoder SIPENCODER = new SIPMessageEncoder();