BLIP/BLIP_Internal.h
author Jens Alfke <jens@mooseyard.com>
Sun May 10 19:05:52 2009 -0700 (2009-05-10)
changeset 46 50dc5502ef46
parent 18 3be241de1630
permissions -rw-r--r--
Unnecessary self-merge (I'm just being confused with hg. Sorry.)
jens@0
     1
//
jens@0
     2
//  BLIP_Internal.h
jens@0
     3
//  MYNetwork
jens@0
     4
//
jens@0
     5
//  Created by Jens Alfke on 5/10/08.
jens@0
     6
//  Copyright 2008 Jens Alfke. All rights reserved.
jens@0
     7
//
jens@0
     8
jens@0
     9
#import "BLIPConnection.h"
jens@0
    10
#import "BLIPRequest.h"
jens@0
    11
#import "BLIPProperties.h"
jens@0
    12
@class BLIPWriter;
jens@0
    13
jens@0
    14
jens@0
    15
/* Private declarations and APIs for BLIP implementation. Not for use by clients! */
jens@0
    16
jens@0
    17
jens@0
    18
/* BLIP message types; encoded in each frame's header. */
jens@0
    19
typedef enum {
jens@0
    20
    kBLIP_MSG,                      // initiating message
jens@0
    21
    kBLIP_RPY,                      // response to a MSG
jens@0
    22
    kBLIP_ERR                       // error response to a MSG
jens@0
    23
} BLIPMessageType;
jens@0
    24
jens@0
    25
/* Flag bits in a BLIP frame header */
jens@0
    26
enum {
jens@0
    27
    kBLIP_TypeMask  = 0x000F,       // bits reserved for storing message type
jens@0
    28
    kBLIP_Compressed= 0x0010,       // data is gzipped
jens@0
    29
    kBLIP_Urgent    = 0x0020,       // please send sooner/faster
jens@0
    30
    kBLIP_NoReply   = 0x0040,       // no RPY needed
jens@0
    31
    kBLIP_MoreComing= 0x0080,       // More frames coming (Applies only to individual frame)
jens@18
    32
    kBLIP_Meta      = 0x0100,       // Special message type, handled internally (hello, bye, ...)
jens@0
    33
};
jens@0
    34
typedef UInt16 BLIPMessageFlags;
jens@0
    35
jens@0
    36
jens@0
    37
/** Header of a BLIP frame as sent across the wire. All fields are big-endian. */
jens@0
    38
typedef struct {
jens@0
    39
    UInt32           magic;         // magic number (kBLIPFrameHeaderMagicNumber)
jens@0
    40
    UInt32           number;        // serial number of MSG
jens@0
    41
    BLIPMessageFlags flags;         // encodes frame type, "more" flag, and other delivery options
jens@0
    42
    UInt16           size;          // total size of frame, _including_ this header
jens@0
    43
} BLIPFrameHeader;
jens@0
    44
jens@19
    45
#define kBLIPFrameHeaderMagicNumber 0x9B34F206
jens@0
    46
jens@18
    47
#define kBLIPProfile_Hi  @"Hi"      // Used for Profile header in meta greeting message
jens@18
    48
#define kBLIPProfile_Bye @"Bye"     // Used for Profile header in meta close-request message
jens@18
    49
jens@0
    50
jens@0
    51
@interface BLIPConnection ()
jens@0
    52
- (void) _dispatchRequest: (BLIPRequest*)request;
jens@0
    53
- (void) _dispatchResponse: (BLIPResponse*)response;
jens@0
    54
@end
jens@0
    55
jens@0
    56
jens@0
    57
@interface BLIPMessage ()
jens@0
    58
@property BOOL sent, propertiesAvailable, complete;
jens@18
    59
- (BLIPMessageFlags) _flags;
jens@0
    60
- (void) _setFlag: (BLIPMessageFlags)flag value: (BOOL)value;
jens@0
    61
- (void) _encode;
jens@0
    62
@end
jens@0
    63
jens@0
    64
jens@0
    65
@interface BLIPMessage ()
jens@0
    66
- (id) _initWithConnection: (BLIPConnection*)connection
jens@0
    67
                    isMine: (BOOL)isMine
jens@0
    68
                     flags: (BLIPMessageFlags)flags
jens@0
    69
                    number: (UInt32)msgNo
jens@0
    70
                      body: (NSData*)body;
jens@0
    71
- (BOOL) _writeFrameTo: (BLIPWriter*)writer maxSize: (UInt16)maxSize;
jens@0
    72
@property (readonly) SInt32 _bytesWritten;
jens@0
    73
- (void) _assignedNumber: (UInt32)number;
jens@0
    74
- (BOOL) _receivedFrameWithHeader: (const BLIPFrameHeader*)header body: (NSData*)body;
jens@0
    75
- (void) _connectionClosed;
jens@0
    76
@end
jens@0
    77
jens@0
    78
jens@0
    79
@interface BLIPRequest ()
jens@0
    80
- (id) _initWithConnection: (BLIPConnection*)connection
jens@0
    81
                      body: (NSData*)body 
jens@0
    82
                properties: (NSDictionary*)properties;
jens@0
    83
@end
jens@0
    84
jens@0
    85
jens@0
    86
@interface BLIPResponse ()
jens@0
    87
- (id) _initWithRequest: (BLIPRequest*)request;
jens@0
    88
@end