00001 /*========================================================================= 00002 00003 Program: The OpenIGTLink Library 00004 Module: $HeadURL: $ 00005 Language: C 00006 Date: $Date: 2010-11-23 14:47:40 -0500 (Tue, 23 Nov 2010) $ 00007 Version: $Revision: 6958 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 00011 This software is distributed WITHOUT ANY WARRANTY; without even 00012 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 PURPOSE. See the above copyright notices for more information. 00014 00015 =========================================================================*/ 00016 00017 #ifndef __IGTL_BIND_H 00018 #define __IGTL_BIND_H 00019 00020 #include "igtl_win32header.h" 00021 #include "igtl_header.h" 00022 #include "igtl_util.h" 00023 #include "igtl_types.h" 00024 #include "igtl_win32header.h" 00025 00026 #ifdef __cplusplus 00027 extern "C" { 00028 #endif 00029 00030 00031 /* 00032 * The igtl_bind_info structure holds information about a child message in an OpenIGTLink 00033 * BIND message. The structure is used for functions defined in igtl_bind.h 00034 */ 00035 00036 typedef struct { 00037 char type[IGTL_HEADER_TYPE_SIZE+1]; /* Data type (OpenIGTLink Device Type string) */ 00038 char name[IGTL_HEADER_NAME_SIZE+1]; /* Device name */ 00039 igtl_uint64 size; /* Data size */ 00040 void* ptr; /* Pointer to the child message */ 00041 } igtl_bind_child_info; 00042 00043 typedef struct { 00044 igtl_uint16 ncmessages; /* Number of child message */ 00045 igtl_bind_child_info * child_info_array; /* Array of igtl_bind_child_info */ 00046 igtl_uint64 resol; /* Time resolution (used for STT_BIND) */ 00047 igtl_uint8 request_all; /* Flag to request all available data 00048 (used for GET_BIND and STT_BIND) */ 00049 igtl_uint8 status; /* Status for RTS message */ 00050 } igtl_bind_info; 00051 00052 00053 /* 00054 * Initialize igtl_bind_info 00055 */ 00056 void igtl_export igtl_bind_init_info(igtl_bind_info * bind_info); 00057 00058 /* 00059 * Allocate / free an array of igtl_bind_info structure 00060 * 00061 * Allocate / free an array of igtl_bind_child_info in bind_info with length of 'ncmessages.' 00062 * Return 1 if the array is successfully allocated/freed 00063 */ 00064 00065 int igtl_export igtl_bind_alloc_info(igtl_bind_info * bind_info, igtl_uint16 ncmessages); 00066 int igtl_export igtl_bind_free_info(igtl_bind_info * bind_info); 00067 00068 /* 00069 * Unpack BIND message 00070 * 00071 * Extract information about child messages in a byte array of BIND messages and store 00072 * it in a igtl_bind_info structure. 'type' argument specifies a message type prefix 00073 * (none, GET_, STT_, STP_ or RTS_) by IGTL_TYPE_PREFIX_* macro. 00074 * Returns 1 if success, otherwise 0. 00075 */ 00076 00077 int igtl_export igtl_bind_unpack(int type, void * byte_array, igtl_bind_info * info, igtl_uint64 size); 00078 00079 /* 00080 * Pack BIND message 00081 * 00082 * Convert an igtl_bind_info structure to a byte array. 00083 * 'byte_array' should be allocated prior to calling igtl_bind_pack() with memory size 00084 * calculated by igtl_bind_get_size(). 'type' argument specifies a message type prefix 00085 * (none, GET_, STT_, STP_ or RTS_) by IGTL_TYPE_PREFIX_* macro. 00086 * Returns 1 if success, otherwise 0. 00087 */ 00088 00089 int igtl_export igtl_bind_pack(igtl_bind_info * info, void * byte_array, int type); 00090 00091 /* 00092 * Bind data size 00093 * 00094 * igtl_bind_get_size() calculates the size of bind header, consisting of 00095 * BIND hearder section (including number of child messages) and 00096 * name table section based on a igtl_bind_header. 00097 * The size returned from this function does not include size of child message data. 00098 * 'type' argument specifies a message type prefix 00099 * (none, GET_, STT_, STP_ or RTS_) by IGTL_TYPE_PREFIX_* macro. 00100 */ 00101 00102 igtl_uint64 igtl_export igtl_bind_get_size(igtl_bind_info * info, int type); 00103 00104 00105 /* 00106 * CRC calculation 00107 * 00108 * This function calculates CRC of BIND message. Note that 'info' is used only for 00109 * getting size of the message. 00110 * 00111 */ 00112 00113 igtl_uint64 igtl_export igtl_bind_get_crc(igtl_bind_info * info, int type, void* bind_message); 00114 00115 #ifdef __cplusplus 00116 } 00117 #endif 00118 00119 #endif /* __IGTL_BIND_H */ 00120 00121 00122