Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief XATMI Typed buffer support
0003  *
0004  * @file typed_buf.h
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #ifndef TYPED_BUF_H
0035 #define TYPED_BUF_H
0036 
0037 #ifdef  __cplusplus
0038 extern "C" {
0039 #endif
0040 
0041 /*---------------------------Includes-----------------------------------*/
0042 #include <atmi_int.h> /* include ATMI internal structures       */
0043 #include <multibuf.h> /**< hash handling of pointers            */
0044 /*---------------------------Externs------------------------------------*/
0045 /*---------------------------Macros-------------------------------------*/
0046 
0047 #define BUF_TYPE_MIN        0 /* min buffer type, for integrity */
0048 #define BUF_TYPE_UBF        0
0049 #define BUF_TYPE_INIT       2 /* Keep the G_buf_descr indexes */
0050 #define BUF_TYPE_NULL       3
0051 #define BUF_TYPE_STRING     4
0052 #define BUF_TYPE_CARRAY     5 
0053 #define BUF_TYPE_JSON       6
0054 #define BUF_TYPE_VIEW       7
0055 #define BUF_TYPE_MAX        7 /* max buffer type, for integrity */
0056 
0057 #define BUF_TYPE_UBF_STR        "UBF"
0058 #define BUF_TYPE_INIT_STR       "INIT"
0059 #define BUF_TYPE_STRING_STR     "STRING"
0060 #define BUF_TYPE_CARRAY_STR     "CARRAY"
0061 #define BUF_TYPE_NULL_STR       "NULL"
0062 #define BUF_TYPE_JSON_STR       "JSON"
0063 #define BUF_TYPE_VIEW_STR       "VIEW"
0064 
0065 /**
0066  * Automatic buffer conversion:
0067  */
0068 #define BUF_CVT_INCOMING_JSON2UBF_STR           "JSON2UBF"
0069 #define BUF_CVT_INCOMING_UBF2JSON_STR           "UBF2JSON"
0070 #define BUF_CVT_INCOMING_JSON2VIEW_STR          "JSON2VIEW"
0071 #define BUF_CVT_INCOMING_VIEW2JSON_STR          "VIEW2JSON"
0072     
0073 
0074 /* others: VIEW X_COMMON X_C_TYPE X_OCTET FML32 VIEW32 - not supported currently */
0075 /* see G_buf_descr */
0076 #define BUF_IS_TYPEID_VALID(X) (BUF_TYPE_MIN<=X && X <= BUF_TYPE_MAX)
0077 /*---------------------------Enums--------------------------------------*/
0078 /*---------------------------Typedefs-----------------------------------*/
0079 
0080 /**
0081  * Free list used by recursive buffer free
0082  */
0083 typedef struct
0084 {
0085     ndrx_mbuf_ptrs_t *ptrs_hash;    /**< hash of pointer already freed */
0086     char *mainbuf;                  /**< ptr to main buf doing the whole free thing */
0087 } ndrx_buf_free_lists_t;
0088 
0089 /*---------------------------Globals------------------------------------*/
0090 extern NDRX_API buffer_obj_t *ndrx_G_buffers;
0091 extern NDRX_API typed_buffer_descr_t G_buf_descr[];
0092 /*---------------------------Statics------------------------------------*/
0093 /*---------------------------Prototypes---------------------------------*/
0094 /*extern NDRX_API typed_buffer_descr_t * get_buffer_descr(char *type, char *subtype);*/
0095 extern NDRX_API char * ndrx_tprealloc (char *buf, long len);
0096 extern NDRX_API char * ndrx_tpalloc (typed_buffer_descr_t *known_type,
0097                     char *type, char *subtype, long len);
0098 extern NDRX_API buffer_obj_t * ndrx_find_buffer(char *ptr);
0099 extern NDRX_API typed_buffer_descr_t * ndrx_get_buffer_descr(char *type, 
0100         char *subtype);
0101 
0102 extern NDRX_API int ndrx_buffer_list(ndrx_growlist_t *list);
0103 
0104 /*extern NDRX_API void free_up_buffers(void);*/
0105 
0106 /* UBF support */
0107 extern NDRX_API int UBF_prepare_outgoing (typed_buffer_descr_t *descr, 
0108         char *idata, long ilen, char *obuf, long *olen, long flags);
0109 extern NDRX_API int UBF_prepare_incoming (typed_buffer_descr_t *descr, 
0110         char *rcv_data, long rcv_len, char **odata, long *olen, long flags);
0111 extern NDRX_API char * UBF_tprealloc(typed_buffer_descr_t *descr, char *cur_ptr, long len);
0112 extern NDRX_API char    * UBF_tpalloc (typed_buffer_descr_t *descr, char *subtype, long *len);
0113 extern NDRX_API void UBF_tpfree(typed_buffer_descr_t *descr, char *buf);
0114 extern NDRX_API int UBF_test(typed_buffer_descr_t *descr, char *buf, BFLDLEN len, char *expr);
0115     
0116 /* Type buffer support */
0117 extern NDRX_API char * TPINIT_tpalloc (typed_buffer_descr_t *descr, char *subtype, long *len);
0118 extern NDRX_API void TPINIT_tpfree(typed_buffer_descr_t *descr, char *buf);
0119 /* Type null buffer */
0120 extern NDRX_API char * TPNULL_tpalloc (typed_buffer_descr_t *descr, char *subtype, long *len);
0121 extern NDRX_API void TPNULL_tpfree(typed_buffer_descr_t *descr, char *buf);
0122 extern NDRX_API int TPNULL_prepare_outgoing (typed_buffer_descr_t *descr, char *idata, long ilen, 
0123                     char *obuf, long *olen, long flags);
0124 
0125 extern NDRX_API int TPNULL_prepare_incoming (typed_buffer_descr_t *descr, char *rcv_data, 
0126                         long rcv_len, char **odata, long *olen, long flags);
0127 
0128 /* Automatic buffer convert: */
0129 extern NDRX_API int typed_xcvt(buffer_obj_t **buffer, long xcvtflags, int is_reverse);
0130 
0131 extern NDRX_API int typed_xcvt_json2ubf(buffer_obj_t **buffer);
0132 extern NDRX_API int typed_xcvt_ubf2json(buffer_obj_t **buffer);
0133 
0134 extern NDRX_API int typed_xcvt_json2view(buffer_obj_t **buffer);
0135 extern NDRX_API int typed_xcvt_view2json(buffer_obj_t **buffer, long flags);
0136 extern NDRX_API void ndrx_tpfree_inner (char *buf, buffer_obj_t *known_buffer, ndrx_buf_free_lists_t *flist);
0137 
0138     
0139 #ifdef  __cplusplus
0140 }
0141 #endif
0142 
0143 #endif  /* TYPED_BUF_H */
0144 
0145 /* vim: set ts=4 sw=4 et smartindent: */