1) Reintroduced finishedBuilding
[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
17 /**
18  *
19  * TODO: Added a try catch block in sendPacket to avoid an execption in case the PHP script
20  * has finished and DBG isn't ready for receiving any new frame.
21  * (This happens when mouse is hovering over variable or user switches to watch expression)
22  * It is not clear why DBG isn't sending any SCRIPT_END event (or something similar),
23  * or whether there is another way to check whether DBG is listening or not.
24  * For the moment this is only a workaround.
25  *
26  */
27 public class PHPDBGPacket {
28
29         private static final int        PACKET_HEADER_SIZE      = 16;
30         private char[]                  packetHeader            = new char[PACKET_HEADER_SIZE];
31         private int                             packetSize;
32         private Vector                          frames                          = new Vector ();
33
34         public PHPDBGPacket (char[] packetType) {
35                 PHPDBGBase.copyChars (packetHeader, PHPDBGBase.DBGSYNC, 4);
36                 PHPDBGBase.copyCharsTo (packetHeader, packetType, 4, 4);
37         }
38
39         public void addFrame (PHPDBGFrame frame) {
40                 frames.add (frame);
41                 packetSize += frame.getSize ();
42         }
43
44         public void sendPacket (OutputStream out) throws IOException {
45                 int             i;
46                 PHPDBGFrame frame;
47
48                 PHPDBGBase.copyCharsTo (packetHeader, PHPDBGBase.IntToChar4 (packetSize), 4, 12);
49
50                 try {
51                         out.write (PHPDBGBase.CharArrayToByteArray (packetHeader));                             // Send packet header
52                         out.flush ();                                                               //
53
54                         for (i = 0; i < frames.size (); i++) {                                                  // Send Frames
55                                 frame = (PHPDBGFrame) frames.get (i);                                                   // Header of frame
56
57                                 out.write (PHPDBGBase.CharArrayToByteArray (frame.getHeader ()));       // Convert the char buffer to a byte buffer and send
58                                 out.flush ();
59
60                                 if (frame.getSizeOfData () > 0) {                                       // If there is a data frame
61                                         out.write (PHPDBGBase.CharArrayToByteArray (frame.getFrameData ()));// Convert the data char buffer to a byte buffer and send
62                                         out.flush ();
63                                 }
64                         }
65                 }
66                 catch (Exception e) {
67                 }
68         }
69 }