fastapi.h

Go to the documentation of this file.
00001 // $Id: fastapi_8h-source.html,v 1.2 2006/02/09 19:12:40 Daniel.May Exp $
00002 //
00003 // FIX Adapted for STreaming (sm) (FAST Protocol (sm)) 
00004 //
00005 // Copyright (c) 2005-2006, Pantor Engineering AB (http://www.pantor.com)
00006 // Copyright (c) 2005-2006, SpryWare LLC (http://www.spryware.com)
00007 // Copyright (c) 2005-2006, FIX Protocol Ltd (http://www.fixprotocol.org)
00008 // All Rights Reserved.
00009 //
00010 // This work is distributed under the W3C® Software License [1] in the
00011 // hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
00012 // implied warranty of MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS 
00013 // FOR A PARTICULAR PURPOSE.
00014 //
00015 // [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
00016 // [FPL's Intellectual Property details] http://www.fixprotocol.org/ip
00017 // [FAST Protocol details] http://www.fixprotocol.org/fast
00018 // [FAST Protocol credits] http://fixprotocol.org/fastcredits
00019 
00020 #ifndef _fastapi_h_
00021 #define _fastapi_h_ 1
00022 
00023 #include "types.h"
00024 
00025 #define STR_ARGS(_x) _x, sizeof (_x)
00026 
00028 
00029 typedef enum fast_op_t
00030 {
00031    FAST_OP_NONE = 0,
00032    FAST_OP_COPY,
00033    FAST_OP_INCR,
00034    FAST_OP_DELTA,
00035 }
00036 fast_op_t;
00037 
00038 typedef enum fast_type_t
00039 {
00040    FAST_TYPE_NULL = 0,
00041    FAST_TYPE_U32,
00042    FAST_TYPE_I32,
00043    FAST_TYPE_STR,
00044 }
00045 fast_type_t;
00046 
00047 typedef enum fast_error_t
00048 {
00049    FAST_ERR_NONE       =  0,
00050    FAST_ERR_CODEC      = -1,
00051    FAST_ERR_SIZE       = -2,
00052    FAST_ERR_VALUE      = -3,
00053    FAST_ERR_TAG_OP     = -4,
00054    FAST_ERR_TAG_TYPE   = -5,
00055    FAST_ERR_CALL_SEQ   = -6,
00056    FAST_ERR_IO         = -7,
00057 }
00058 fast_error_t;
00059 
00061 
00062 #define TAG_MAX_SLOT     0xff // extendable to 0xfff
00063 #define TAG_MAX_TID      0xf  // extendable to 0xfff
00064 #define TAG_MAX_OP       0xf
00065 #define TAG_MAX_TYPE     0xf
00066 
00067 #define TAG_SHIFT_SLOT    0
00068 #define TAG_SHIFT_TID    12
00069 #define TAG_SHIFT_OP     24
00070 #define TAG_SHIFT_TYPE   28
00071 
00072 #define MAKE_TAG(type,op,tid,slot) \
00073    (((type) << TAG_SHIFT_TYPE) | ((op)   << TAG_SHIFT_OP) | \
00074     ((tid)  << TAG_SHIFT_TID)  | ((slot) << TAG_SHIFT_SLOT))
00075 
00077 
00078 #define MAX_TAG 64
00079 #define MAX_TID  4
00080 
00081 #define MAX_PMAP_BYTES 8
00082 #define MAX_PMAP_BITS  (7 * MAX_PMAP_BYTES)
00083 #define MAX_MSG_SIZE  2048
00084 
00085 typedef unsigned int fast_tag_t;
00086 
00088 
00089 typedef struct fast_cv_t
00090 {
00091    i32 i32_values [MAX_TAG];
00092    u32 u32_values [MAX_TAG];
00093    u8* str_values [MAX_TAG];
00094    u32 valid      [MAX_TAG];
00095 }
00096 fast_cv_t;
00097 
00099 
00100 typedef struct fast_pmap_t
00101 {
00102    u8  bits [MAX_PMAP_BITS];
00103    u32 size;
00104    u32 max_pos;
00105 }
00106 fast_pmap_t;
00107 
00108 typedef struct fast_buffer_t
00109 {
00110    int fd;
00111 
00112    u8* head;
00113    u8* tail;
00114    u8* end;
00115 
00116    u8  data [MAX_MSG_SIZE];
00117 }
00118 fast_buffer_t;
00119 
00120 typedef struct fast_codec_error_t
00121 {
00122    const char*  fn;
00123    char*        text;
00124 
00125    fast_tag_t   tag;
00126    fast_error_t code;
00127 }
00128 fast_codec_error_t;
00129 
00131 
00132 #define FAST_CODEC_MAGIC 0xC0DEC
00133 
00134 typedef struct fast_codec_t
00135 {
00136    u32 magic;
00137 
00138    const char* name;
00139 
00140    fast_pmap_t pmap [1];
00141 
00142    fast_buffer_t msg    [1];
00143    fast_buffer_t input  [1];
00144    fast_buffer_t output [1];
00145 
00146    fast_cv_t cv [TAG_MAX_TID];
00147 
00148    // Config variables
00149    int count;
00150    int skip_io;
00151    int verbose;
00152 
00153    // State variables
00154    int curr_tag;
00155    int in_message;
00156 
00157    fast_codec_error_t error [1];
00158 }
00159 fast_codec_t;
00160 
00162 
00163 #ifdef __cplusplus
00164 extern "C" {
00165 #endif 
00166 
00180 fast_codec_t* fast_create_codec (void);
00181 
00189 int  fast_destroy_codec    (fast_codec_t* codec);
00190 
00198 void fast_reset_state      (fast_codec_t* codec, fast_tag_t tag);
00199 
00207 int  fast_set_codec_input  (fast_codec_t* codec, FILE* fptr);
00208 
00216 int  fast_set_codec_output (fast_codec_t* codec, FILE* fptr);
00217 
00221 fast_tag_t fast_make_tag   (fast_op_t, fast_type_t, u32 tid, u32 slot);
00222 
00231 int fast_decode_new_msg    (fast_codec_t* codec, fast_tag_t tag);
00232 
00240 int fast_decode_end_msg    (fast_codec_t* codec, fast_tag_t tag);
00241 
00249 int fast_decode_i32        (fast_codec_t* codec, fast_tag_t tag, i32* data);
00250 
00258 int fast_decode_u32        (fast_codec_t* codec, fast_tag_t tag, u32* data);
00259 
00270 int fast_decode_str        (fast_codec_t* codec, fast_tag_t tag, u8* data, int size);
00271 
00280 int fast_encode_new_msg    (fast_codec_t* codec, fast_tag_t tag);
00281 
00289 int fast_encode_end_msg    (fast_codec_t* codec, fast_tag_t tag);
00290 
00298 int fast_encode_i32        (fast_codec_t* codec, fast_tag_t tag, i32 data);
00299 
00307 int fast_encode_u32        (fast_codec_t* codec, fast_tag_t tag, u32 data);
00308 
00319 int fast_encode_str        (fast_codec_t* codec, fast_tag_t tag, u8* data, int size);
00320 
00328 int fast_print_error       (fast_codec_t* codec, FILE* fptr);
00329 
00336 const char* fast_error_string (fast_codec_t* codec);
00337 
00347 u32 fast_ascii_to_u32 (u8* data, int size);
00348 
00350 #ifdef __cplusplus
00351 }
00352 #endif
00353 
00354 #endif // _fastapi_h_

Generated on Thu Feb 9 13:11:33 2006 for fastapi by doxygen 1.4.6-NO    FAST ProtocolSM