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