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 "BSProtocolThreadInvoker.h"
21 @protocol MessageQueueDelegate
;
23 // MessageQueue operates a listening socket, that is connected to another
24 // program with which it exchanges UTF8 string messages. A message contains two
25 // parts, both terminated by '\0'. The first is an ASCII integer number that is
26 // the length of the second part. The second part is the actual string message.
27 @interface MessageQueue
: NSObject
29 // Creates a new MessasgeQueue that will listen on |port| and report information
31 - (id
)initWithPort
:(NSUInteger
)port delegate
:(id
<MessageQueueDelegate
>)delegate
;
33 // Whether or not the message queue has attached itself to a child.
36 // Opens a socket that will listen for connections.
39 // Closes either the listening or child socket and completely disconnects.
42 // Enqueues a |message| to be sent to the client. This may be called from any
44 - (void)sendMessage
:(NSString
*)message
;
48 // Delegate ////////////////////////////////////////////////////////////////////
50 // The delegate for the message queue. These methods are called from the thread
51 // on which the MessageQueue was initialized.
52 @protocol MessageQueueDelegate
<NSObject
>
53 // Callback for any errors that the MessageQueue encounters.
54 - (void)messageQueue
:(MessageQueue
*)queue error
:(NSError
*)error
;
56 // Called when the listening socket has accepted a child socket.
57 - (void)messageQueueDidConnect
:(MessageQueue
*)queue
;
59 // Called when the child socket has been disconnected.
60 - (void)messageQueueDidDisconnect
:(MessageQueue
*)queue
;
62 // Callback for when a message has been sent.
63 - (void)messageQueue
:(MessageQueue
*)queue didSendMessage
:(NSString
*)message
;
65 // Callback with the message content when one has been receieved.
66 - (void)messageQueue
:(MessageQueue
*)queue didReceiveMessage
:(NSString
*)message
;