cbbcdbed84eddedd1d314a2234928e68402ecbc2
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.core / src / net / sourceforge / phpdt / internal / debug / core / PHPDBGPacket.java
1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
7
8 Contributors:
9         Vicente Fernando - www.alfersoft.com.ar - Initial implementation
10 **********************************************************************/
11 package net.sourceforge.phpdt.internal.debug.core;
12
13 import java.io.IOException;
14 import java.io.OutputStream;
15 import java.util.Vector;
16 public class PHPDBGPacket {
17
18         private static final int        PACKET_HEADER_SIZE      = 16;
19         private char[]                  packetHeader            = new char[PACKET_HEADER_SIZE];
20         private int                             packetSize;
21         private Vector                          frames                          = new Vector ();
22
23         public PHPDBGPacket (char[] packetType) {
24                 PHPDBGBase.copyChars (packetHeader, PHPDBGBase.DBGSYNC, 4);
25                 PHPDBGBase.copyCharsTo (packetHeader, packetType, 4, 4);
26         }
27
28         public void addFrame (PHPDBGFrame frame) {
29                 frames.add (frame);
30                 packetSize += frame.getSize ();
31         }
32
33         public void sendPacket (OutputStream out) throws IOException {
34                 int             i;
35                 PHPDBGFrame frame;
36
37                 PHPDBGBase.copyCharsTo (packetHeader, PHPDBGBase.IntToChar4 (packetSize), 4, 12);
38
39                 out.write (PHPDBGBase.CharArrayToByteArray (packetHeader));                             // Send packet header
40                 out.flush ();                                                               //
41
42                 for (i = 0; i < frames.size (); i++) {                                                  // Send Frames
43                         frame = (PHPDBGFrame) frames.get (i);                                                   // Header of frame
44
45                         out.write (PHPDBGBase.CharArrayToByteArray (frame.getHeader ()));       // Convert the char buffer to a byte buffer and send
46                         out.flush ();
47
48                         if (frame.getSizeOfData () > 0) {                                       // If there is a data frame
49                                 out.write (PHPDBGBase.CharArrayToByteArray (frame.getFrameData ()));// Convert the data char buffer to a byte buffer and send
50                                 out.flush ();
51                         }
52                 }
53         }
54 }