1 | /* |
2 | * |
3 | * Copyright 1994-2014 The MathWorks, Inc. |
4 | * |
5 | * File: rt_logging_mmi.c |
6 | * |
7 | * Abstract: |
8 | */ |
9 | |
10 | #ifndef rt_logging_c |
11 | #define rt_logging_c |
12 | |
13 | #include <stdlib.h> |
14 | #include <stddef.h> |
15 | #include "rtwtypes.h" |
16 | #include "builtin_typeid_types.h" |
17 | #include "rtw_matlogging.h" |
18 | #include "rtw_modelmap.h" |
19 | |
20 | /* Logical definitions */ |
21 | #if (!defined(__cplusplus)) |
22 | # ifndef false |
23 | # define false (0U) |
24 | # endif |
25 | # ifndef true |
26 | # define true (1U) |
27 | # endif |
28 | #endif |
29 | |
30 | static const char_T rtMemAllocError[] = "Memory allocation error"; |
31 | #define FREE(m) if (m != NULL) free(m) |
32 | |
33 | #define ACCESS_C_API_FOR_RTW_LOGGING true |
34 | |
35 | /* Function: rt_FillStateSigInfoFromMMI ======================================= |
36 | * Abstract: |
37 | * |
38 | * Returns: |
39 | * == NULL => success. |
40 | * ~= NULL => failure, the return value is a pointer to the error |
41 | * message, which is also set in the simstruct. |
42 | */ |
43 | const char_T * rt_FillStateSigInfoFromMMI(RTWLogInfo *li, |
44 | const char_T **errStatus) |
45 | { |
46 | int_T i; |
47 | int_T nSignals = 0; |
48 | int_T *dims = NULL; |
49 | BuiltInDTypeId *dTypes = NULL; |
50 | int_T *cSgnls = NULL; |
51 | char_T **labels = NULL; |
52 | char_T **blockNames = NULL; |
53 | char_T **stateNames = NULL; |
54 | boolean_T *crossMdlRef = NULL; |
55 | void **sigDataAddr = NULL; |
56 | RTWLoggingFcnPtr *RTWLoggingPtrs = NULL; |
57 | int_T *logDataType = NULL; |
58 | boolean_T *isVarDims = NULL; |
59 | |
60 | |
61 | const rtwCAPI_ModelMappingInfo *mmi = (const rtwCAPI_ModelMappingInfo *)rtliGetMMI(li); |
62 | |
63 | int_T sigIdx = 0; |
64 | |
65 | RTWLogSignalInfo * sigInfo; |
66 | /* reset error status */ |
67 | *errStatus = NULL; |
68 | |
69 | sigInfo = (RTWLogSignalInfo *)calloc(1,sizeof(RTWLogSignalInfo)); |
70 | if (sigInfo == NULL) goto ERROR_EXIT; |
71 | |
72 | nSignals = rtwCAPI_GetNumStateRecordsForRTWLogging(mmi); |
73 | |
74 | if (nSignals >0) { |
75 | /* These are all freed before exiting this function */ |
76 | dims = (int_T *)calloc(nSignals,sizeof(int_T)); |
77 | if (dims == NULL) goto ERROR_EXIT; |
78 | dTypes = (BuiltInDTypeId *)calloc(nSignals,sizeof(BuiltInDTypeId)); |
79 | if (dTypes == NULL) goto ERROR_EXIT; |
80 | cSgnls = (int_T *)calloc(nSignals,sizeof(int_T)); |
81 | if (cSgnls == NULL) goto ERROR_EXIT; |
82 | labels = (char_T **)calloc(nSignals, sizeof(char_T*)); |
83 | if (labels == NULL) goto ERROR_EXIT; |
84 | blockNames = (char_T**)calloc(nSignals, sizeof(char_T*)); |
85 | if (blockNames == NULL) goto ERROR_EXIT; |
86 | stateNames = (char_T**)calloc(nSignals, sizeof(char_T*)); |
87 | if (stateNames == NULL) goto ERROR_EXIT; |
88 | crossMdlRef = (boolean_T*)calloc(nSignals, sizeof(boolean_T)); |
89 | if (crossMdlRef == NULL) goto ERROR_EXIT; |
90 | logDataType = (int_T *)calloc(nSignals,sizeof(int_T)); |
91 | if (logDataType == NULL) goto ERROR_EXIT; |
92 | /* Allocate memory for isVarDims pointer and set all elements to 0's */ |
93 | isVarDims = (boolean_T *)calloc(nSignals,sizeof(boolean_T)); |
94 | if (isVarDims == NULL) goto ERROR_EXIT; |
95 | |
96 | /* These are freed in stopDataLogging (they're needed in the meantime) */ |
97 | sigDataAddr = (void **)calloc(nSignals,sizeof(void *)); |
98 | if (sigDataAddr == NULL) goto ERROR_EXIT; |
99 | RTWLoggingPtrs = (RTWLoggingFcnPtr *)calloc(nSignals, sizeof(RTWLoggingFcnPtr)); |
100 | if (RTWLoggingPtrs == NULL) goto ERROR_EXIT; |
101 | |
102 | *errStatus = rtwCAPI_GetStateRecordInfo(mmi, |
103 | (const char_T**) blockNames, |
104 | (const char_T**) labels, |
105 | (const char_T**) stateNames, |
106 | dims, |
107 | (int_T*)dTypes, |
108 | logDataType, |
109 | cSgnls, |
110 | sigDataAddr, |
111 | RTWLoggingPtrs, |
112 | crossMdlRef, |
113 | NULL, /* sigInProtectedMdl */ |
114 | NULL, |
115 | NULL, /* sigSampleTime */ |
116 | NULL, /* sigHierInfoIdx */ |
117 | NULL, /* sigFlatElemIdx */ |
118 | NULL, /* sigMMI */ |
119 | &sigIdx, |
120 | false, /* crossingModel */ |
121 | false, /* isInProtectedMdl */ |
122 | NULL, /* stateDerivVector */ |
123 | ACCESS_C_API_FOR_RTW_LOGGING); |
124 | |
125 | if (*errStatus != NULL) goto ERROR_EXIT; |
126 | |
127 | rtliSetLogXSignalPtrs(li,(LogSignalPtrsType)sigDataAddr); |
128 | } |
129 | |
130 | sigInfo->numSignals = nSignals; |
131 | sigInfo->numCols = dims; |
132 | sigInfo->numDims = NULL; |
133 | sigInfo->dims = dims; |
134 | sigInfo->dataTypes = dTypes; |
135 | sigInfo->complexSignals = cSgnls; |
136 | sigInfo->frameData = NULL; |
137 | sigInfo->preprocessingPtrs = (RTWPreprocessingFcnPtr*) RTWLoggingPtrs; |
138 | sigInfo->labels.ptr = labels; |
139 | sigInfo->titles = NULL; |
140 | sigInfo->titleLengths = NULL; |
141 | sigInfo->plotStyles = NULL; |
142 | sigInfo->blockNames.ptr = blockNames; |
143 | sigInfo->stateNames.ptr = stateNames; |
144 | sigInfo->crossMdlRef = crossMdlRef; |
145 | sigInfo->dataTypeConvert = NULL; |
146 | |
147 | sigInfo->isVarDims = isVarDims; |
148 | sigInfo->currSigDims = NULL; |
149 | |
150 | rtliSetLogXSignalInfo(li,sigInfo); |
151 | |
152 | /* Free logDataType it's not needed any more, |
153 | * the rest of them will be freed later */ |
154 | FREE(logDataType); |
155 | return(NULL); /* NORMAL_EXIT */ |
156 | |
157 | ERROR_EXIT: |
158 | if (*errStatus == NULL) { |
159 | *errStatus = rtMemAllocError; |
160 | } |
161 | /* Free local stuff that was allocated. It is no longer needed */ |
162 | for (i = 0; i < nSignals; ++i) utFree(blockNames[i]); |
163 | FREE(blockNames); |
164 | for (i = 0; i < nSignals; ++i) utFree(stateNames[i]); |
165 | FREE(stateNames); |
166 | FREE(labels); |
167 | FREE(dims); |
168 | FREE(dTypes); |
169 | FREE(logDataType); |
170 | FREE(cSgnls); |
171 | FREE(isVarDims); |
172 | return(*errStatus); |
173 | |
174 | } /* end rt_InitSignalsStruct */ |
175 | |
176 | void rt_CleanUpForStateLogWithMMI(RTWLogInfo *li) |
177 | { |
178 | int_T i; |
179 | RTWLogSignalInfo *sigInfo = _rtliGetLogXSignalInfo(li); /* get the non-const ptr */ |
180 | int_T nSignals = sigInfo->numSignals; |
181 | |
182 | if ( nSignals > 0 ) { |
183 | |
184 | for (i = 0; i < nSignals; ++i) utFree(sigInfo->blockNames.ptr[i]); |
185 | FREE(sigInfo->blockNames.ptr); |
186 | FREE(sigInfo->labels.ptr); |
187 | FREE(sigInfo->crossMdlRef); |
188 | FREE(sigInfo->dims); |
189 | FREE(sigInfo->dataTypes); |
190 | FREE(sigInfo->complexSignals); |
191 | FREE(sigInfo->isVarDims); |
192 | |
193 | FREE(sigInfo); |
194 | rtliSetLogXSignalInfo(li, NULL); |
195 | |
196 | FREE(_rtliGetLogXSignalPtrs(li)); /* get the non-const ptr */ |
197 | rtliSetLogXSignalPtrs(li,NULL); |
198 | } |
199 | } |
200 | |
201 | #endif /* rt_logging_mmi_c */ |
202 | |
203 | /* LocalWords: Hier Deriv |
204 | */ |
205 | |