EMMA Coverage Report (generated Tue Dec 18 20:38:46 CET 2007)
[all classes][cz.vutbr.feec.session.rtprtcp.internal]

## COVERAGE SUMMARY FOR SOURCE FILE [SocketStrategy.java]

name | class, % | method, % | block, % | line, %
--- | --- | --- | --- | ---
SocketStrategy.java | 0% (0/1) | 0% (0/9) | 0% (0/203) | 0% (0/53)

### COVERAGE BREAKDOWN BY CLASS AND METHOD

name | class, % | method, % | block, % | line, %
--- | --- | --- | --- | ---
class SocketStrategy | 0% (0/1) | 0% (0/9) | 0% (0/203) | 0% (0/53)
<static initializer> |  | 0% (0/1) | 0% (0/5) | 0% (0/2)
SocketStrategy (DatagramSocket, InetAddress, int): void |  | 0% (0/1) | 0% (0/21) | 0% (0/8)
SocketStrategy (Socket, int): void |  | 0% (0/1) | 0% (0/18) | 0% (0/7)
close (): void |  | 0% (0/1) | 0% (0/11) | 0% (0/4)
getBindedPort (): int |  | 0% (0/1) | 0% (0/11) | 0% (0/3)
isMulticastSocket (): boolean |  | 0% (0/1) | 0% (0/7) | 0% (0/1)
printStatus (): void |  | 0% (0/1) | 0% (0/36) | 0% (0/5)
receiveFrom (DatagramPacket): int |  | 0% (0/1) | 0% (0/59) | 0% (0/15)
send (DatagramPacket, int): void |  | 0% (0/1) | 0% (0/35) | 0% (0/10)

1 | package cz.vutbr.feec.session.rtprtcp.internal;
2 |
3 | import java.io.IOException;
4 | import java.net.DatagramPacket;
5 | import java.net.DatagramSocket;
6 | import java.net.InetAddress;
7 | import java.net.UnknownHostException;
8 |
9 | import org.apache.log4j.Logger;
10 |
11 | import net.java.dev.jssm.Socket;
12 |
13 | /**
14 | * The Class SocketStrategy.
15 | */
16 | public class SocketStrategy {
17 |
18 | /** The mc sock. */
19 | private Socket mcSock = null;
20 |
21 | /** The uc sock. */
22 | private DatagramSocket ucSock = null;
23 |
24 | /** The target address. */
25 | private InetAddress targetAddress;
26 |
27 | /** The logger. */
28 | private static Logger logger = Logger.getLogger(SocketStrategy.class.getName());
29 |
30 | /** The target port. */
31 | private int targetPort;
32 |
33 | /**
34 | * The Constructor.
35 | *
36 | * @param targetPort the target port
37 | * @param sock the sock
38 | */
39 | public SocketStrategy(Socket sock, int targetPort) {
40 | logger.debug("Creating multicast socket.");
41 | mcSock = sock;
42 | this.targetPort = targetPort;
43 | }
44 |
45 | /**
46 | * The Constructor.
47 | *
48 | * @param targetPort the target port
49 | * @param targetAddress the target address
50 | * @param sock the sock
51 | */
52 | public SocketStrategy(DatagramSocket sock, InetAddress targetAddress, int targetPort){
53 | logger.debug("Creating unicast socket.");
54 | ucSock = sock;
55 | this.targetAddress = targetAddress;
56 | this.targetPort = targetPort;
57 | }
58 |
59 | /**
60 | * Checks if is multicast socket.
61 | *
62 | * @return true, if is multicast socket
63 | */
64 | public boolean isMulticastSocket() {
65 | return ucSock == null;
66 | }
67 |
68 | /**
69 | * Prints the status.
70 | */
71 | public void printStatus() {
72 | String res;
73 | if (isMulticastSocket()){
74 | res = "In mode of Multicast socket ("+targetPort+");";
75 | } else {
76 | res = "In mode of Unicast socket ("+targetAddress.toString()+", "+targetPort+");";
77 | }
78 | System.out.println(res);
79 | }
80 |
81 | /**
82 | * Receive.
83 | *
84 | * @param packet the packet
85 | *
86 | * @return the int
87 | */
88 | public int receiveFrom(DatagramPacket packet) {
89 | int res = 100;
90 | if(isMulticastSocket()) {
91 | // set data
92 | res = mcSock.receiveFrom(packet.getData());
93 | logger.debug("receive from "+packet.getAddress());
94 |
95 | // set address
96 | byte[] addr = mcSock.getRemoteAddress();
97 | try {
98 | packet.setAddress(InetAddress.getByAddress(addr));
99 | } catch (UnknownHostException e) {
100 | e.printStackTrace();
101 | System.exit(-1);
102 | }
103 | } else {
104 | try {
105 | ucSock.receive(packet);
106 | logger.debug("receive from "+packet.getAddress());
107 | res = packet.getLength();
108 | } catch (IOException e) {
109 | return -1;
110 | }
111 | }
112 | return res;
113 | }
114 |
115 | /**
116 | * Send.
117 | *
118 | * @param packet the packet
119 | * @param port the port
120 | */
121 | public void send(DatagramPacket packet, int port) {
122 | packet.setPort(port);
123 |
124 | if(isMulticastSocket()) {
125 | mcSock.sendTo(packet.getData(), packet.getData().length, port);
126 | } else {
127 | packet.setAddress(targetAddress);
128 | packet.setPort(targetPort);
129 | try {
130 | ucSock.send(packet);
131 | // System.out.println("SocketStrategy - RTCP SENT (uc)"+targetAddress+" "+ucSock.getPort());
132 | } catch (IOException e) {
133 | e.printStackTrace();
134 | System.exit(-1);
135 | }
136 | }
137 | }
138 |
139 | /**
140 | * Close.
141 | */
142 | public void close() {
143 | if(isMulticastSocket()) {
144 | mcSock.close();
145 | } else {
146 | ucSock.close();
147 | }
148 | }
149 |
150 | /**
151 | * Gets the binded port.
152 | *
153 | * @return the binded port
154 | */
155 | public int getBindedPort() {
156 | if(isMulticastSocket()) {
157 | return mcSock.getBindedPort();
158 | } else {
159 | return ucSock.getPort();
160 | }
161 | }
162 | }

[all classes][cz.vutbr.feec.session.rtprtcp.internal]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov