Replace -[ProtocolClient sendCustomCommandWithFormat:...] with a block-based
[macgdbp.git] / Source / ProtocolClient.h
1 /*
2 * MacGDBp
3 * Copyright (c) 2013, Blue Static <http://www.bluestatic.org>
4 *
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.
8 *
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.
12 *
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
15 */
16
17 #import <Foundation/Foundation.h>
18
19 #import "MessageQueue.h"
20
21 @protocol ProtocolClientDelegate;
22
23 typedef void (^ProtocolClientMessageHandler)(NSXMLDocument*);
24
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>
29
30 - (id)initWithDelegate:(id<ProtocolClientDelegate>)delegate;
31
32 - (BOOL)isConnected;
33
34 - (void)connectOnPort:(NSUInteger)port;
35 - (void)disconnect;
36
37 // This sends the given command format to the debugger. This method is thread
38 // safe and schedules the request on the |runLoop_|.
39 - (NSNumber*)sendCommandWithFormat:(NSString*)format, ...;
40
41 // Sends a command with the given |format| to the debugger. When a response is
42 // received, |handler| is invoked. If an error occurs or the connection is
43 // interrupted, the delegate will be notified.
44 - (void)sendCommandWithFormat:(NSString*)format
45 handler:(ProtocolClientMessageHandler)handler,
46 ...;
47
48 // Sends a command to the debugger. The command must have a substring |{txn}|
49 // within it, which will be replaced with the transaction ID. Use this if
50 // |-sendCommandWithFormat:|'s insertion of the transaction ID is incorrect.
51 - (void)sendCustomCommandWithFormat:(NSString*)format
52 handler:(ProtocolClientMessageHandler)handler,
53 ...;
54
55 - (NSInteger)transactionIDFromResponse:(NSXMLDocument*)response;
56 - (NSInteger)transactionIDFromCommand:(NSString*)command;
57
58 // Given a path to a file, creates a URI for it that is suitable for sending to
59 // the debugger engine.
60 + (NSString*)escapedFilePathURI:(NSString*)path;
61
62 @end
63
64 // Delegate ////////////////////////////////////////////////////////////////////
65
66 // All methods of the protocol client are dispatched to the thread on which the
67 // ProtocolClient was created.
68 @protocol ProtocolClientDelegate
69 - (void)debuggerEngineConnected:(ProtocolClient*)client;
70 - (void)debuggerEngineDisconnected:(ProtocolClient*)client;
71 - (void)protocolClient:(ProtocolClient*)client receivedInitialMessage:(NSXMLDocument*)message;
72 - (void)protocolClient:(ProtocolClient*)client receivedErrorMessage:(NSXMLDocument*)message;
73 - (void)debuggerEngine:(ProtocolClient*)client receivedMessage:(NSXMLDocument*)message;
74 @end