List of usage examples for io.netty.channel ChannelHandlerContext pipeline
ChannelPipeline pipeline();
From source file:org.jfxvnc.net.rfb.codec.decoder.FramebufferUpdateRectDecoder.java
License:Apache License
@Override public boolean decode(ChannelHandlerContext ctx, ByteBuf m, List<Object> out) throws Exception { if (state == State.INIT) { logger.debug("init readable {} bytes", m.readableBytes()); if (!m.isReadable()) { return false; }/*from ww w . j av a 2 s .com*/ if (m.getByte(0) != ServerEvent.FRAMEBUFFER_UPDATE.getType()) { logger.error("no FBU type!!! {}", m.getByte(0)); ctx.pipeline().fireChannelReadComplete(); return false; } if (!m.isReadable(4)) { return false; } m.skipBytes(2); // padding numberRects = m.readUnsignedShort(); currentRect = 0; logger.debug("number of rectangles: {}", numberRects); if (numberRects < 1) { return true; } state = State.NEW_RECT; } if (state == State.NEW_RECT) { if (!readRect(ctx, m, out)) { return false; } state = State.READ_RECT; } FrameRectDecoder dec = frameRectDecoder.get(rect.getEncoding()); if (dec == null) { throw new ProtocolException("Encoding not supported: " + rect.getEncoding()); } dec.setRect(rect); if (!dec.decode(ctx, m, out)) { return false; } if (currentRect == numberRects) { state = State.INIT; ctx.pipeline().fireUserEventTriggered(ProtocolState.FBU_REQUEST); return true; } if (!readRect(ctx, m, out)) { state = State.NEW_RECT; } return false; }
From source file:org.jfxvnc.net.rfb.codec.decoder.FramebufferUpdateRectDecoder.java
License:Apache License
private boolean readRect(ChannelHandlerContext ctx, ByteBuf m, List<Object> out) { if (!m.isReadable(12)) { return false; }//from w w w. j a v a 2 s . co m int x = m.readUnsignedShort(); int y = m.readUnsignedShort(); int w = m.readUnsignedShort(); int h = m.readUnsignedShort(); int enc = m.readInt(); rect = new FrameRect(x, y, w, h, Encoding.valueOf(enc)); currentRect++; logger.debug("{}of{} - ({}) {}", currentRect, numberRects, rect, enc); if (w == 0 || h == 0) { if (currentRect == numberRects) { state = State.INIT; ctx.pipeline().fireUserEventTriggered(ProtocolState.FBU_REQUEST); return true; } return false; } return true; }
From source file:org.jfxvnc.net.rfb.codec.decoder.ProtocolVersionDecoder.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (!in.isReadable(length)) { return;/*from w w w .j av a 2s .c o m*/ } byte[] rfb = new byte[length]; in.readBytes(rfb); String rfbVersion = new String(rfb, ASCII); out.add(new ProtocolVersion(rfbVersion)); ctx.pipeline().remove(this); }
From source file:org.jfxvnc.net.rfb.codec.encoder.PixelFormatEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, PixelFormat pf, ByteBuf out) throws Exception { out.writeByte(ClientEventType.SET_PIXEL_FORMAT); out.writeZero(3); // padding out.writeByte(pf.getBitPerPixel());/* w w w . j a v a 2s . c o m*/ out.writeByte(pf.getDepth()); out.writeBoolean(pf.isBigEndian()); out.writeBoolean(pf.isTrueColor()); out.writeShort(pf.getRedMax()); out.writeShort(pf.getGreenMax()); out.writeShort(pf.getBlueMax()); out.writeByte(pf.getRedShift()); out.writeByte(pf.getGreenShift()); out.writeByte(pf.getBlueShift()); out.writeZero(3); // padding ctx.pipeline().remove(this); }
From source file:org.jfxvnc.net.rfb.codec.encoder.PreferedEncodingEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, PreferedEncoding enc, ByteBuf out) throws Exception { out.writeByte(ClientEventType.SET_ENCODINGS); out.writeZero(1); // padding out.writeShort(enc.getEncodings().length); Arrays.stream(enc.getEncodings()).forEach(e -> out.writeInt(e.getType())); ctx.pipeline().remove(this); }
From source file:org.jfxvnc.net.rfb.codec.ProtocolHandler.java
License:Apache License
@Override public void channelRegistered(ChannelHandlerContext ctx) throws Exception { if (config.sslProperty().get()) { if (sslContext == null) { sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE) .build();//from w w w .j a v a 2s . com } ctx.pipeline().addFirst("ssl-handler", sslContext.newHandler(ctx.channel().alloc())); } super.channelRegistered(ctx); }
From source file:org.jfxvnc.net.rfb.codec.ProtocolHandler.java
License:Apache License
@Override protected void decode(final ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception { if (msg instanceof ImageRect) { render.render((ImageRect) msg, () -> { // logger.debug("render completed"); // sendFramebufferUpdateRequest(ctx, true, 0, 0, // serverInit.getFrameBufferWidth(), // serverInit.getFrameBufferHeight()); });/*from w w w .jav a 2 s .c o m*/ return; } if (msg instanceof ServerDecoderEvent) { render.eventReceived((ServerDecoderEvent) msg); return; } if (!(msg instanceof ServerInitEvent)) { logger.error("unknown message: {}", msg); ctx.fireChannelRead(msg); return; } serverInit = (ServerInitEvent) msg; logger.debug("handshake completed with {}", serverInit); FrameDecoderHandler frameHandler = new FrameDecoderHandler(serverInit.getPixelFormat()); if (!frameHandler.isPixelFormatSupported()) { ProtocolException e = new ProtocolException(String.format("pixelformat: (%s bpp) not supported yet", serverInit.getPixelFormat().getBitPerPixel())); exceptionCaught(ctx, e); return; } ChannelPipeline cp = ctx.pipeline(); cp.addBefore(ctx.name(), "rfb-encoding-encoder", new PreferedEncodingEncoder()); PreferedEncoding prefEncodings = getPreferedEncodings(frameHandler.getSupportedEncodings()); ctx.write(prefEncodings); cp.addBefore(ctx.name(), "rfb-pixelformat-encoder", new PixelFormatEncoder()); ctx.write(serverInit.getPixelFormat()); ctx.flush(); cp.addBefore(ctx.name(), "rfb-frame-handler", frameHandler); cp.addBefore(ctx.name(), "rfb-keyevent-encoder", new KeyButtonEventEncoder()); cp.addBefore(ctx.name(), "rfb-pointerevent-encoder", new PointerEventEncoder()); cp.addBefore(ctx.name(), "rfb-cuttext-encoder", new ClientCutTextEncoder()); render.eventReceived(getConnectInfoEvent(ctx, prefEncodings)); render.registerInputEventListener(event -> ctx.writeAndFlush(event, ctx.voidPromise())); logger.debug("request full framebuffer update"); sendFramebufferUpdateRequest(ctx, false, 0, 0, serverInit.getFrameBufferWidth(), serverInit.getFrameBufferHeight()); logger.trace("channel pipeline: {}", cp.toMap().keySet()); }
From source file:org.jfxvnc.net.rfb.codec.ProtocolHandler.java
License:Apache License
@Override public void handlerAdded(ChannelHandlerContext ctx) { ChannelPipeline cp = ctx.pipeline(); if (cp.get(ProtocolHandshakeHandler.class) == null) { cp.addBefore(ctx.name(), "rfb-handshake-handler", new ProtocolHandshakeHandler(config)); }/* w w w.j a v a2 s.c om*/ }
From source file:org.jfxvnc.net.rfb.codec.ProtocolHandshakeHandler.java
License:Apache License
@Override public void channelActive(final ChannelHandlerContext ctx) throws Exception { ctx.pipeline().addBefore(ctx.name(), "rfb-version-decoder", new ProtocolVersionDecoder()); }
From source file:org.jfxvnc.net.rfb.codec.ProtocolHandshakeHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof ProtocolVersion) { handleServerVersion(ctx, (ProtocolVersion) msg); return;//from w w w. j a v a 2 s . co m } if (msg instanceof SecurityTypesEvent) { handleSecurityTypes(ctx, (SecurityTypesEvent) msg); return; } if (msg instanceof RfbSecurityMessage) { handleSecurityMessage(ctx, (RfbSecurityMessage) msg); return; } if (msg instanceof SecurityResultEvent) { handleSecurityResult(ctx, (SecurityResultEvent) msg); return; } if (msg instanceof ServerInitEvent) { handshaker.finishHandshake(ctx.channel(), config.versionProperty().get()); ChannelPipeline cp = ctx.pipeline(); cp.fireUserEventTriggered(ProtocolState.HANDSHAKE_COMPLETE); cp.remove(this); cp.fireChannelRead(msg); return; } throw new ProtocolException("unknown message occurred: " + msg); }