3 * Copyright (c) 2013, Blue Static <http://www.bluestatic.org>
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 #import <Foundation/Foundation.h>
19 #import "MessageQueue.h"
21 @protocol ProtocolClientDelegate
;
23 typedef void (^ProtocolClientMessageHandler
)(NSXMLDocument
*);
25 // ProtocolClient sends string commands to a DBGP <http://www.xdebug.org/docs-dbgp.php>
26 // debugger engine and receives XML packets in response. This class ensures
27 // proper sequencing of the messages.
28 @interface ProtocolClient
: NSObject
<MessageQueueDelegate
>
30 - (id
)initWithDelegate
:(id
<ProtocolClientDelegate
>)delegate
;
34 - (void)connectOnPort
:(NSUInteger
)port
;
37 // Sends a one-way command to the debugger, when no response is required.
38 - (void)sendCommandWithFormat
:(NSString
*)format
, ...;
40 // Sends a command with the given |format| to the debugger. When a response is
41 // received, |handler| is invoked. If an error occurs or the connection is
42 // interrupted, the delegate will be notified.
43 - (void)sendCommandWithFormat
:(NSString
*)format
44 handler
:(ProtocolClientMessageHandler
)handler
,
47 // Sends a command to the debugger. The command must have a substring |{txn}|
48 // within it, which will be replaced with the transaction ID. Use this if
49 // |-sendCommandWithFormat:|'s insertion of the transaction ID is incorrect.
50 - (void)sendCustomCommandWithFormat
:(NSString
*)format
51 handler
:(ProtocolClientMessageHandler
)handler
,
54 - (NSInteger
)transactionIDFromResponse
:(NSXMLDocument
*)response
;
55 - (NSInteger
)transactionIDFromCommand
:(NSString
*)command
;
57 // Given a path to a file, creates a URI for it that is suitable for sending to
58 // the debugger engine.
59 + (NSString
*)escapedFilePathURI
:(NSString
*)path
;
63 // Delegate ////////////////////////////////////////////////////////////////////
65 // All methods of the protocol client are dispatched to the thread on which the
66 // ProtocolClient was created.
67 @protocol ProtocolClientDelegate
68 - (void)debuggerEngineConnected
:(ProtocolClient
*)client
;
69 - (void)debuggerEngineDisconnected
:(ProtocolClient
*)client
;
70 - (void)protocolClient
:(ProtocolClient
*)client receivedInitialMessage
:(NSXMLDocument
*)message
;
71 - (void)protocolClient
:(ProtocolClient
*)client receivedErrorMessage
:(NSXMLDocument
*)message
;