Pointwise Plugin SDK
apiGRDPUtils.cxx
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Pointwise Plugin utility functions
4  *
5  * (C) 2021 Cadence Design Systems, Inc. All rights reserved worldwide.
6  *
7  ***************************************************************************/
8 
9 #include <string.h>
10 
11 #include "apiPWP.h"
12 #include "apiGRDPUtils.h"
13 #include "apiGridModel.h"
14 #include "pwpPlatform.h"
15 
16 
19 {
20  GRDP_RTITEM *ret = 0;
21  PWP_UINT32 ii;
22  for (ii=0; ii < grdpFormatCnt; ++ii) {
23  if (id == grdpRtItem[ii].FormatInfo.id) {
24  ret = &(grdpRtItem[ii]);
25  break;
26  }
27  }
28  return ret;
29 }
30 
31 
33 grdpFindFormatByName (const char name[])
34 {
35  GRDP_RTITEM *ret = 0;
36  PWP_UINT32 ii;
37  for (ii=0; ii < grdpFormatCnt; ++ii) {
38  if (0 == strcmp(grdpRtItem[ii].FormatInfo.name, name)) {
39  ret = &(grdpRtItem[ii]);
40  break;
41  }
42  }
43  return ret;
44 }
45 
46 
49 {
50  PWP_BOOL ret = PWP_FALSE;
51  if (pRti) {
52  pRti->progTotal = 0;
53  pRti->progComplete = 0;
54  pRti->clocks[GRDP_CLKS_PROGUPDATE] =
55  pRti->clocks[GRDP_CLKS_PROGINIT] = clock();
56  pRti->opAborted = PWP_FALSE;
57  ret = PwuProgressBegin(pRti->pApiData->apiInfo.name, cnt);
58  pRti->opAborted |= !ret;
59  }
60  return ret;
61 }
62 
63 
66 {
67  PWP_BOOL ret = PWP_FALSE;
68  if (pRti && (total > 0)) {
69  pRti->progComplete = 0;
70  pRti->progTotal = total;
71  ret = !pRti->opAborted;
72  pRti->clocks[GRDP_CLKS_BEGSTEP] = clock();
73  }
74  return ret;
75 }
76 
77 
80 {
81  PWP_BOOL ret = PWP_FALSE;
82  if (pRti && !pRti->opAborted) {
83  // send update a max of 2 times per second
84  const clock_t DELAY = (CLOCKS_PER_SEC / 2);
85  pRti->clocks[GRDP_CLKS_PROGINCR] = clock();
86  ++pRti->progComplete;
87  if (DELAY <= GRDP_RT_CLKS_DIFF(pRti, GRDP_CLKS_PROGUPDATE,
89  ret = PwuProgressStatus (pRti->pApiData->apiInfo.name,
90  pRti->progComplete, pRti->progTotal);
91  pRti->clocks[GRDP_CLKS_PROGUPDATE] =
92  pRti->clocks[GRDP_CLKS_PROGINCR];
93  pRti->opAborted |= !ret;
94  }
95  else {
96  ret = PWP_TRUE;
97  }
98  }
99  return ret;
100 }
101 
102 /*------------------------------------*/
103 static void
104 sendDiffTimeMsg(GRDP_RTITEM *pRti, const char txt[], clock_t diff)
105 {
106  if (pRti) {
107  PWP_INT32 hours;
108  PWP_INT32 minutes;
109  PWP_INT32 seconds;
110  char msg[512];
111  char *p = msg;
112  if (txt && txt[0]) {
113  strcpy(p, txt);
114  strcat(p, ": ");
115  p += strlen(p);
116  }
117  GRDP_CLKS_TO_HMS(diff, hours, minutes, seconds);
118  sprintf(p, "%ld:%02ld:%02ld (h:mm:ss) / %ld msec", (long)hours,
119  (long)minutes, (long)seconds, (long)GRDP_CLKS_TO_MSECS(diff));
120  grdpSendDebugMsg(pRti, msg, 0);
121  }
122 }
123 
124 /*------------------------------------*/
125 static void
126 sendClkDiffTimeMsg(GRDP_RTITEM *pRti, const char txt[],
127  GRDP_ENUM_CLOCKS startId, GRDP_ENUM_CLOCKS endId)
128 {
129  if (pRti) {
130  sendDiffTimeMsg(pRti, txt,
131  GRDP_RT_CLKS_DIFF(pRti, startId, endId));
132  }
133 }
134 
135 
136 PWP_BOOL
138 {
139  PWP_BOOL ret = PWP_FALSE;
140  if (pRti) {
141  pRti->clocks[GRDP_CLKS_ENDSTEP] = clock();
142  pRti->progComplete = 0;
143  pRti->progTotal = 0;
145  pRti->opAborted |= !ret;
146  sendClkDiffTimeMsg(pRti, "Step time", GRDP_CLKS_BEGSTEP,
148  }
149  return ret;
150 }
151 
152 
153 PWP_BOOL
155 {
156  if (pRti) {
157  pRti->clocks[GRDP_CLKS_PROGEND] = clock();
158  pRti->progTotal = 0;
159  pRti->progComplete = 0;
160  pRti->clocks[GRDP_CLKS_PROGUPDATE] = 0;
161  PwuProgressEnd(pRti->pApiData->apiInfo.name, ok);
162  sendClkDiffTimeMsg(pRti, "Export time", GRDP_CLKS_PROGINIT,
164  }
165  return ok;
166 }
167 
168 
169 void
170 grdpSendDebugMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
171 {
172  if (0 != pRti) {
173  PwuSendDebugMsg(pRti->pApiData->apiInfo.name, txt, code);
174  }
175 }
176 
177 
178 void
179 grdpSendInfoMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
180 {
181  if (0 != pRti) {
182  PwuSendInfoMsg(pRti->pApiData->apiInfo.name, txt, code);
183  }
184 }
185 
186 
187 void
188 grdpSendWarningMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
189 {
190  if (0 != pRti) {
191  PwuSendWarningMsg(pRti->pApiData->apiInfo.name, txt, code);
192  }
193 }
194 
195 
196 void
197 grdpSendErrorMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
198 {
199  if (0 != pRti) {
200  PwuSendErrorMsg(pRti->pApiData->apiInfo.name, txt, code);
201  }
202 }
203 
204 
205 
206 PWP_BOOL
207 grdpPublishValueDefinition(const char name[], PWP_ENUM_VALTYPE type, const char value[],
208  const char access[], const char desc[], const char range[])
209 {
210  PWP_BOOL ret = PWP_FALSE;
211  ret = PwuPublishValueDefinition(GRDP_VALUE_GROUP, name, type, value, access, desc,
212  range);
213  return ret;
214 }
215 
216 
217 PWP_BOOL
218 grdpAssignInfoValue(const char name[], const char value[], const bool create)
219 {
220  return PwuAssignValue(GRDP_INFO_GROUP, name, value, create);
221 }
222 
223 
224 PWP_BOOL
225 grdpAssignInfoValueInt(const char name[], const PWP_INT value, const bool create)
226 {
227  return PwuAssignValueInt(GRDP_INFO_GROUP, name, value, create);
228 }
229 
230 
231 PWP_BOOL
232 grdpAssignInfoValueUInt(const char name[], const PWP_UINT value, const bool create)
233 {
234  return PwuAssignValueUInt(GRDP_INFO_GROUP, name, value, create);
235 }
236 
237 
238 PWP_BOOL
239 grdpAssignInfoValueReal(const char name[], const PWP_REAL value, const bool create)
240 {
241  return PwuAssignValueReal(GRDP_INFO_GROUP, name, value, create);
242 }
243 
244 
245 PWP_BOOL
246 grdpAssignInfoValueBool(const char name[], const bool value, const bool create)
247 {
248  return PwuAssignValueUInt(GRDP_INFO_GROUP, name, (value ? 1 : 0), create);
249 }
250 
251 
252 PWP_BOOL
253 grdpAssignInfoValueEnum(const char name[], const char value[], const bool create)
254 {
255  return PwuAssignValueEnum(GRDP_INFO_GROUP, name, value, create);
256 }
GRDP_CLKS_PROGUPDATE
@ GRDP_CLKS_PROGUPDATE
Definition: apiGRDPUtils.h:96
grdpSendDebugMsg
void grdpSendDebugMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
Send a debug text message (PWP_MSGID_DEBUG) to the framework.
Definition: apiGRDPUtils.cxx:170
grdpRtItem
GRDP_RTITEM grdpRtItem[]
The runtime array of GRDP_RTITEM items.
Definition: apiGRDP.cxx:27
GRDP_CLKS_ENDSTEP
@ GRDP_CLKS_ENDSTEP
Definition: apiGRDPUtils.h:100
PwuProgressEnd
void PwuProgressEnd(const char api[], PWP_BOOL ok)
Send a progress end message (PWP_MSGID_PROGEND) to the framework.
Definition: apiPWPUtils.cxx:163
PWP_ENUM_VALTYPE
PWP_ENUM_VALTYPE
Supported PWP-API getValue() transfer types.
Definition: apiPWP.h:696
PWP_UINT32
unsigned int PWP_UINT32
32-bit unsigned integer
Definition: apiPWP.h:210
PwuAssignValue
PWP_BOOL PwuAssignValue(const char group[], const char name[], const char value[], bool createIfNotExists)
Assign or create a value.
Definition: apiPWPUtils.cxx:856
GRDP_CLKS_TO_HMS
#define GRDP_CLKS_TO_HMS(c, h, m, s)
Returns the clock value c decomposed into hours, minutes, and seconds (PWP_INT32)....
Definition: apiGRDPUtils.h:713
GRDP_CLKS_PROGEND
@ GRDP_CLKS_PROGEND
Definition: apiGRDPUtils.h:101
PwuAssignValueInt
PWP_BOOL PwuAssignValueInt(const char group[], const char name[], PWP_INT value, bool createIfNotExists)
Definition: apiPWPUtils.cxx:875
grdpAssignInfoValueReal
PWP_BOOL grdpAssignInfoValueReal(const char name[], const PWP_REAL value, const bool create)
Creates a key/PWP_REAL-value pair that defines a GRDP info attribute.
Definition: apiGRDPUtils.cxx:239
GRDP_CLKS_BEGSTEP
@ GRDP_CLKS_BEGSTEP
Definition: apiGRDPUtils.h:98
grdpFindFormatByName
GRDP_RTITEM * grdpFindFormatByName(const char name[])
Find an item in grdpRtItem[] by it's name.
Definition: apiGRDPUtils.cxx:33
PWP_INT32
int PWP_INT32
32-bit integer
Definition: apiPWP.h:207
PwuProgressStatus
PWP_BOOL PwuProgressStatus(const char api[], PWP_UINT32 complete, PWP_UINT32 total)
Send a progress status message (PWP_MSGID_PROGSTATUS, value >= 0) to the framework.
Definition: apiPWPUtils.cxx:173
PwuPublishValueDefinition
PWP_BOOL PwuPublishValueDefinition(const char group[], const char name[], PWP_ENUM_VALTYPE type, const char value[], const char access[], const char desc[], const char range[])
Create a value.
Definition: apiPWPUtils.cxx:909
grdpSendInfoMsg
void grdpSendInfoMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
Send an info text message (PWP_MSGID_INFO) to the framework.
Definition: apiGRDPUtils.cxx:179
PwuProgressNextStep
PWP_BOOL PwuProgressNextStep(const char api[])
Send a progress "next step" message (PWP_MSGID_PROGSTATUS, value = -1) to the framework.
Definition: apiPWPUtils.cxx:189
PWP_UINT
PWP_UINT32 PWP_UINT
unsigned integer same size as void*
Definition: apiPWP.h:285
grdpPublishValueDefinition
PWP_BOOL grdpPublishValueDefinition(const char name[], PWP_ENUM_VALTYPE type, const char value[], const char access[], const char desc[], const char range[])
Creates a collection of key/value pairs that represent a published grid import attribute definition.
Definition: apiGRDPUtils.cxx:207
grdpProgressEnd
PWP_BOOL grdpProgressEnd(GRDP_RTITEM *pRti, const PWP_BOOL ok)
Ends all progress tracking.
Definition: apiGRDPUtils.cxx:154
PwuSendWarningMsg
void PwuSendWarningMsg(const char api[], const char txt[], PWP_UINT32 code)
Send a warning text message (PWP_MSGID_WARNING) to the framework.
Definition: apiPWPUtils.cxx:123
GRDP_RT_CLKS_DIFF
#define GRDP_RT_CLKS_DIFF(rti, startId, endId)
Returns the clock time difference between startId and endId as clocks[endId] - clocks[startId]....
Definition: apiGRDPUtils.h:645
apiGridModel.h
Pointwise Grid Model API Specification (PWGM-API)
GRDP_INFO_GROUP
#define GRDP_INFO_GROUP
Definition: apiGRDP.h:53
PwuSendInfoMsg
void PwuSendInfoMsg(const char api[], const char txt[], PWP_UINT32 code)
Send an info text message (PWP_MSGID_INFO) to the framework.
Definition: apiPWPUtils.cxx:116
sendDiffTimeMsg
static void sendDiffTimeMsg(GRDP_RTITEM *pRti, const char txt[], clock_t diff)
Definition: apiGRDPUtils.cxx:104
GRDP_ENUM_CLOCKS
GRDP_ENUM_CLOCKS
Supported GRDP clock id values.
Definition: apiGRDPUtils.h:95
pwpPlatform.h
Cross Platform Functions.
grdpAssignInfoValue
PWP_BOOL grdpAssignInfoValue(const char name[], const char value[], const bool create)
Creates a key/string-value pair that defines a GRDP info attribute.
Definition: apiGRDPUtils.cxx:218
GRDP_RTITEM
The data representing a grid importer instance.
Definition: apiGRDPUtils.h:117
PwuSendErrorMsg
void PwuSendErrorMsg(const char api[], const char txt[], PWP_UINT32 code)
Send an error text message (PWP_MSGID_ERROR) to the framework.
Definition: apiPWPUtils.cxx:130
grdpSendWarningMsg
void grdpSendWarningMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
Send a warning text message (PWP_MSGID_WARNING) to the framework.
Definition: apiGRDPUtils.cxx:188
PWP_REAL
double PWP_REAL
64-bit real
Definition: apiPWP.h:264
PwuAssignValueUInt
PWP_BOOL PwuAssignValueUInt(const char group[], const char name[], PWP_UINT value, bool createIfNotExists)
Definition: apiPWPUtils.cxx:884
GRDP_CLKS_TO_MSECS
#define GRDP_CLKS_TO_MSECS(c)
Returns the clock value c as milli seconds (PWP_INT32). Only whole ms values are possible.
Definition: apiGRDPUtils.h:688
grdpFindFormatById
GRDP_RTITEM * grdpFindFormatById(PWP_UINT32 id)
Find an item in grdpRtItem[] by it's id.
Definition: apiGRDPUtils.cxx:18
GRDP_CLKS_PROGINCR
@ GRDP_CLKS_PROGINCR
Definition: apiGRDPUtils.h:99
grdpAssignInfoValueEnum
PWP_BOOL grdpAssignInfoValueEnum(const char name[], const char value[], const bool create)
Creates a key/enum-value pair that defines a GRDP info attribute.
Definition: apiGRDPUtils.cxx:253
PWP_FALSE
#define PWP_FALSE
PWP_BOOL logical "false" value.
Definition: apiPWP.h:306
grdpAssignInfoValueInt
PWP_BOOL grdpAssignInfoValueInt(const char name[], const PWP_INT value, const bool create)
Creates a key/PWP_INT-value pair that defines a GRDP info attribute.
Definition: apiGRDPUtils.cxx:225
GRDP_RTITEM::pApiData
PWU_RTITEM * pApiData
Pointer to the associated PWU_RTITEM structure.
Definition: apiGRDPUtils.h:126
grdpAssignInfoValueUInt
PWP_BOOL grdpAssignInfoValueUInt(const char name[], const PWP_UINT value, const bool create)
Creates a key/PWP_UINT-value pair that defines a GRDP info attribute.
Definition: apiGRDPUtils.cxx:232
PWP_INT
PWP_INT32 PWP_INT
integer same size as void*
Definition: apiPWP.h:282
apiGRDPUtils.h
GRDP utilities.
grdpProgressBeginStep
PWP_BOOL grdpProgressBeginStep(GRDP_RTITEM *pRti, PWP_UINT32 total)
Begins a progress tracking step.
Definition: apiGRDPUtils.cxx:65
PWP_BOOL
int PWP_BOOL
logical value
Definition: apiPWP.h:303
sendClkDiffTimeMsg
static void sendClkDiffTimeMsg(GRDP_RTITEM *pRti, const char txt[], GRDP_ENUM_CLOCKS startId, GRDP_ENUM_CLOCKS endId)
Definition: apiGRDPUtils.cxx:126
grdpProgressInit
PWP_BOOL grdpProgressInit(GRDP_RTITEM *pRti, PWP_UINT32 cnt)
Initializes a progress tracking session.
Definition: apiGRDPUtils.cxx:48
PWP_TRUE
#define PWP_TRUE
PWP_BOOL logical "true" value.
Definition: apiPWP.h:309
PWU_RTITEM::apiInfo
PWP_APIINFO apiInfo
The PWP-API instance information.
Definition: apiPWPUtils.h:48
PwuAssignValueReal
PWP_BOOL PwuAssignValueReal(const char group[], const char name[], PWP_REAL value, bool createIfNotExists)
Definition: apiPWPUtils.cxx:893
grdpAssignInfoValueBool
PWP_BOOL grdpAssignInfoValueBool(const char name[], const bool value, const bool create)
Creates a key/bool-value pair that defines a GRDP info attribute.
Definition: apiGRDPUtils.cxx:246
grdpSendErrorMsg
void grdpSendErrorMsg(GRDP_RTITEM *pRti, const char txt[], PWP_UINT32 code)
Send an error text message (PWP_MSGID_ERROR) to the framework.
Definition: apiGRDPUtils.cxx:197
PwuSendDebugMsg
void PwuSendDebugMsg(const char api[], const char txt[], PWP_UINT32 code)
Send a debug text message (PWP_MSGID_DEBUG) to the framework.
Definition: apiPWPUtils.cxx:109
grdpProgressIncr
PWP_BOOL grdpProgressIncr(GRDP_RTITEM *pRti)
Completes a progress tracking sub-step.
Definition: apiGRDPUtils.cxx:79
apiPWP.h
Pointwise Plugin API (PWP-API)
GRDP_VALUE_GROUP
#define GRDP_VALUE_GROUP
Definition: apiGRDP.h:49
grdpProgressEndStep
PWP_BOOL grdpProgressEndStep(GRDP_RTITEM *pRti)
Completes a progress tracking major step.
Definition: apiGRDPUtils.cxx:137
PwuAssignValueEnum
PWP_BOOL PwuAssignValueEnum(const char group[], const char name[], const char value[], bool createIfNotExists)
Definition: apiPWPUtils.cxx:902
grdpFormatCnt
PWP_UINT32 grdpFormatCnt
The number of entries in grdpRtItem[] array.
Definition: apiGRDP.cxx:33
GRDP_CLKS_PROGINIT
@ GRDP_CLKS_PROGINIT
Definition: apiGRDPUtils.h:97
PWP_APIINFO::name
const char * name
full API spec name
Definition: apiPWP.h:655
PwuProgressBegin
PWP_BOOL PwuProgressBegin(const char api[], PWP_UINT32 totalSteps)
Send a progress begin message (PWP_MSGID_PROGBEGIN) to the framework.
Definition: apiPWPUtils.cxx:152