Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief VIEW buffer type support - generate view object file
0003  *
0004  * @file view_plot.c
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 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <errno.h>
0039 #include <dirent.h>
0040 #include <limits.h>
0041 
0042 #include <ndrstandard.h>
0043 #include <ubfview.h>
0044 #include <ndebug.h>
0045 
0046 #include <userlog.h>
0047 #include <view_cmn.h>
0048 #include <atmi_tls.h>
0049 #include "Exfields.h"
0050 /*---------------------------Externs------------------------------------*/
0051 /*---------------------------Macros-------------------------------------*/
0052 #define API_ENTRY {ndrx_Bunset_error(); \
0053 }\
0054 
0055 /*---------------------------Enums--------------------------------------*/
0056 /*---------------------------Typedefs-----------------------------------*/
0057 /*---------------------------Globals------------------------------------*/
0058 /*---------------------------Statics------------------------------------*/
0059 /*---------------------------Prototypes---------------------------------*/
0060 /**
0061  * This will plot the object file from the compiled data in the memory..
0062  * @param f file open for writting
0063  * @return EXSUCCEED/EXFAIL
0064  */
0065 expublic int ndrx_view_plot_object(FILE *f)
0066 {
0067     int ret = EXSUCCEED;
0068     ndrx_typedview_t * views = ndrx_view_get_handle();
0069     ndrx_typedview_t * vel, *velt;
0070     ndrx_typedview_field_t * fld;
0071     char tmp_count[32];
0072     char tmp_size[32];
0073     char tmp_null[NDRX_VIEW_NULL_LEN+3];
0074     int err;
0075     API_ENTRY;
0076     
0077 #define WRITE_ERR \
0078                 err = errno;\
0079                 UBF_LOG(log_error, "Failed to write to file: %s", strerror(err));\
0080                 ndrx_Bset_error_fmt(TPEOS, "Failed to write to file: %s", strerror(err));\
0081                 EXFAIL_OUT(ret);
0082                 
0083     if (0>fprintf(f, "#Compiled VIEW file %s %s %d bit, compiler: %s\n", 
0084             NDRX_VERSION, NDRX_BUILD_OS_NAME, (int)sizeof(void *)*8, NDRX_COMPILER))
0085     {
0086         WRITE_ERR;
0087     }
0088     
0089     if (0>fprintf(f, "#Time stamp: %s %s\n", __DATE__, __TIME__))
0090     {
0091         WRITE_ERR;
0092     }
0093     
0094     if (0>fprintf(f, "#It is possible to use this file as source of the "
0095             "view and recompile it\n"))
0096     {
0097         WRITE_ERR;
0098     }
0099     
0100     if (0>fprintf(f, "#that will basically update the offsets and sizes of "
0101             "target platform\n"))
0102     {
0103         WRITE_ERR;
0104     }
0105     
0106     if (0>fprintf(f, "#@__platform=%s;@__arch=%s;@__wsize=%d\n\n", 
0107             NDRX_BUILD_OS_NAME, NDRX_CPUARCH, (int)sizeof(void *)*8))
0108     {
0109         WRITE_ERR;
0110     }
0111     
0112         
0113     EXHASH_ITER(hh, views, vel, velt)
0114     {
0115         /* Open view... */
0116         if (0>fprintf(f, "\nVIEW %s\n", vel->vname))
0117         {
0118             WRITE_ERR;
0119         }
0120             
0121         if (0>fprintf(f, "#type  cname                fbname          count flag    size  null                 compiled_data\n"))
0122         {
0123             WRITE_ERR;
0124         }
0125         
0126         DL_FOREACH(vel->fields, fld)
0127         {
0128             char L_offs[256]="";
0129             char C_offs[256]="";
0130             snprintf(tmp_count, sizeof(tmp_count), "%d", fld->count);
0131             
0132             if (BFLD_CARRAY==fld->typecode || BFLD_STRING==fld->typecode)
0133             {
0134                 snprintf(tmp_size, sizeof(tmp_size), "%d", fld->size);
0135             }
0136             else
0137             {
0138                 NDRX_STRCPY_SAFE(tmp_size, "-");
0139             }
0140             
0141             if (fld->flags & NDRX_VIEW_FLAG_ELEMCNT_IND_C)
0142             {
0143                 snprintf(C_offs, sizeof(C_offs), "coffs=%ld;", fld->count_fld_offset);
0144             }
0145             
0146             if (fld->flags & NDRX_VIEW_FLAG_LEN_INDICATOR_L)
0147             {
0148                 snprintf(L_offs, sizeof(L_offs), "loffs=%ld;", fld->length_fld_offset);
0149             }
0150             
0151             if (NDRX_VIEW_QUOTES_SINGLE==fld->nullval_quotes)
0152             {
0153                 snprintf(tmp_null, sizeof(tmp_null), "'%s'", fld->nullval);
0154             }
0155             else if (NDRX_VIEW_QUOTES_DOUBLE==fld->nullval_quotes)
0156             {
0157                 snprintf(tmp_null, sizeof(tmp_null), "\"%s\"", fld->nullval);
0158             }
0159             else
0160             {
0161                 snprintf(tmp_null, sizeof(tmp_null), "%s", fld->nullval);
0162             }
0163             
0164             if (0>fprintf(f, "%-6s %-20s %-15s %-5s %-7s %-5s %-20s offset=%ld;fldsize=%ld;%s%s\n", 
0165                         fld->type_name, 
0166                         fld->cname,
0167                         fld->fbname,
0168                         tmp_count,
0169                         fld->flagsstr,
0170                         tmp_size,
0171                         tmp_null,
0172                         fld->offset,
0173                         fld->fldsize,
0174                         C_offs,
0175                         L_offs
0176                     ))
0177             {
0178                 WRITE_ERR;
0179             }
0180         }
0181 
0182         /* print stats.. */
0183         if (0>fprintf(f, "#@__ssize=%ld;@__cksum=%lu\n", vel->ssize, 
0184                 (unsigned long)vel->cksum))
0185         {
0186             WRITE_ERR;
0187         }
0188         
0189         /* close view */
0190         if (0>fprintf(f, "END\n\n"))
0191         {
0192             WRITE_ERR;
0193         }
0194     }
0195     
0196 out:
0197     UBF_LOG(log_debug, "%s terminates %d", __func__, ret);
0198     return ret;
0199 }
0200 /* vim: set ts=4 sw=4 et smartindent: */