1 /* 2 * Copyright (C) 2013 4th Line GmbH, Switzerland 3 * 4 * The contents of this file are subject to the terms of either the GNU 5 * Lesser General Public License Version 2 or later ("LGPL") or the 6 * Common Development and Distribution License Version 1 or later 7 * ("CDDL") (collectively, the "License"). You may not use this file 8 * except in compliance with the License. See LICENSE.txt for more 9 * information. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 */ 15 16 package org.fourthline.cling.transport.spi; 17 18 19 import org.fourthline.cling.model.UnsupportedDataException; 20 import org.fourthline.cling.model.message.IncomingDatagramMessage; 21 import org.fourthline.cling.model.message.OutgoingDatagramMessage; 22 23 import java.net.DatagramPacket; 24 import java.net.InetAddress; 25 26 /** 27 * Reads and creates UDP datagrams from and into UPnP messages. 28 * <p> 29 * An implementation of this interface has to be thread-safe. 30 * </p> 31 * 32 * @author Christian Bauer 33 */ 34 public interface DatagramProcessor { 35 36 /** 37 * Reads the datagram and instantiates a message. 38 * <p> 39 * The message is either a {@link org.fourthline.cling.model.message.UpnpRequest} or 40 * a {@link org.fourthline.cling.model.message.UpnpResponse} operation type. 41 * </p> 42 * 43 * @param receivedOnAddress The address of the socket on which this datagram was received. 44 * @param datagram The received UDP datagram. 45 * @return The populated instance. 46 * @throws org.fourthline.cling.model.UnsupportedDataException If the datagram could not be read, or didn't contain required data. 47 */ 48 public IncomingDatagramMessage read(InetAddress receivedOnAddress, DatagramPacket datagram) throws UnsupportedDataException; 49 50 /** 51 * Creates a UDP datagram with the content of a message. 52 * <p> 53 * The outgoing message might be a {@link org.fourthline.cling.model.message.UpnpRequest} or a 54 * {@link org.fourthline.cling.model.message.UpnpResponse}. 55 * </p> 56 * 57 * @param message The outgoing datagram message. 58 * @return An actual UDP datagram. 59 * @throws UnsupportedDataException If the datagram could not be created. 60 */ 61 public DatagramPacket write(OutgoingDatagramMessage message) throws UnsupportedDataException; 62 63 } 64 65