-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGS_ERROR.CPP
554 lines (438 loc) · 18 KB
/
GS_ERROR.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
/**********************************************************
Name: GS_ERROR.CPP
Module description: File funzioni di per la gestione
delle situazioni di errore.
Author: Poltini Roberto
(c) Copyright 1995-2014 by IREN ACQUA GAS
**********************************************************/
/*********************************************************/
/* INCLUDE */
/*********************************************************/
#include "stdafx.h" // MFC core and standard components
#define INITGUID
#import "msado15.dll" no_namespace rename ("EOF", "EndOfFile") rename ("EOS", "ADOEOS")
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "adslib.h"
#include "adsdlg.h"
#include "..\gs_def.h" // definizioni globali
#include "gs_error.h"
#include "gs_list.h"
#include "gs_utily.h"
#include "gs_resbf.h"
#include "gs_ade.h"
#include "gs_init.h"
/*********************************************************/
/* GLOBAL VARIABILES */
/*********************************************************/
int GS_ERR_COD = eGSNoError; // Codice ultimo errore verificatosi
static TCHAR GS_MSG[MAX_LEN_MSG]= GS_EMPTYSTR;
/*+
-------------------------------------------------------------
TCHAR *gsc_msg(int code)
Funzione che ritorna il putatore alla stringa globale
GS_MSG in cui ricopia la traduzione corrente del messagio
corrispondente a 'code'.
Richiama funzione "gs_traduction" del modulo "GEOLAN.ARX".
-------------------------------------------------------------
-*/
TCHAR *gsc_msg(int code)
{
resbuf *command = NULL,*ret = NULL;
int rc = RTERROR;
TCHAR *punt;
GS_MSG[0] = _T('\0');
command = acutBuildList(RTSTR, _T("GS_TRADUCTION"), RTSHORT, code, 0);
if (command)
{
if ((rc = acedInvoke(command,&ret))==RTERROR)
acutPrintf(_T("\nGEOLAN.ARX module not found.\n"));
acutRelRb(command);
if (ret)
{
gsc_strcpy(GS_MSG, ret->resval.rstring, MAX_LEN_MSG);
acutRelRb(ret);
}
}
punt = GS_MSG;
return punt;
}
/*+
-------------------------------------------------------------
TCHAR *gsc_err(int code)
Funzione che ritorna il putatore alla stringa globale
GS_MSG in cui ricopia la traduzione corrente del messagio
di errore corrispondente a 'code'.
Richiama funzione "gs_error_msg" del modulo "GEOLAN.ARX".
-------------------------------------------------------------
-*/
TCHAR *gsc_err(int code)
{
resbuf *command = NULL, *ret = NULL;
int rc = RTERROR;
GS_MSG[0] = _T('\0');
command = acutBuildList(RTSTR, _T("GS_ERROR_MSG"), RTSHORT, code, 0);
if (command)
{
if ((rc = acedInvoke(command, &ret)) == RTERROR)
acutPrintf(_T("\nGEOLAN.ARX module not found.\n"));
acutRelRb(command);
if(ret)
{
gsc_strcpy(GS_MSG, ret->resval.rstring, MAX_LEN_MSG);
acutRelRb(ret);
}
}
return GS_MSG;
}
/*+
-------------------------------------------------------------
int gsc_print_error(void)
Stampa il messagio di errore relativo al valore GS_ERR_COD.
Richiama funzione "gs_error_msg" del modulo "GEOLAN.ARX".
-------------------------------------------------------------
-*/
int gsc_print_error(void)
{
TCHAR msg1[MAX_LEN_MSG];
gsc_strcpy(msg1, gsc_msg(133), MAX_LEN_MSG); // "\nErrore GEOsim:"
acutPrintf(_T("%s [%d] - %s\n"), msg1, GS_ERR_COD, gsc_err(GS_ERR_COD));
return GS_GOOD;
}
/*+
-------------------------------------------------------------
Definite per renderle DllExport
-------------------------------------------------------------
-*/
int get_GS_ERR_COD()
{
return GS_ERR_COD;
}
void set_GS_ERR_COD(int err)
{
GS_ERR_COD = err;
}
/**********************************************************************/
/*.doc (mod 2) gsc_get_GEOdiag */
/*+
Restituisce una lista di resbuf contenente le informazioni diagnostiche
nel seguente formato:
((<message 1> (<param 1><param 2>...))(<message 2> (<param 1><param 2>...)) ...)
Restituisce la lista in caso di successo altrimenti restituisce NULL.
-*/
/*********************************************************/
presbuf gsc_get_GEOdiag(void)
{
int jj = 0;
TCHAR message[512];
C_RB_LIST list;
if (list << acutBuildList(RTLB, 0) == NULL) return NULL;
if (errno) // se è un errore segnalato da errno
{
// Store messages
swprintf(message, 512, _T("%-5d %-12s"), jj, strerror(errno));
if ((list += acutBuildList(RTLB, RTSTR, message, RTLB, 0)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
swprintf(message, 512, _T("%s OPERATING SYSTEM"), gsc_msg(613)); // Tipo errore:
if ((list += acutBuildList(RTSTR, message, 0)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
swprintf(message, 512, _T("%s %d"), gsc_msg(614), errno); // Codice errore:
if ((list += acutBuildList(RTSTR, message, 0)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
TCHAR SysMessage[256];
_wcserror_s(SysMessage, 256, errno);
swprintf(message, 512, _T("%s %s"), gsc_msg(615), SysMessage); // Messaggio:
if ((list += acutBuildList(RTSTR, message, RTLE, RTLE, 0)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
jj++;
}
// Store messages
swprintf(message, 512, _T("%-5d %-12s"), jj, gsc_err(GS_ERR_COD));
if ((list += acutBuildList(RTLB, RTSTR, message, RTLB, 0)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
swprintf(message, 512, _T("%s GEOsim"), gsc_msg(613)); // Tipo errore:
if ((list += acutBuildList(RTSTR, message, 0)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
swprintf(message, 512, _T("%s %d"), gsc_msg(614), GS_ERR_COD); // Codice errore:
if ((list += acutBuildList(RTSTR, message, 0)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
// su 2 righe distinte perchè gsc_msg e gsc_err utilizzando la stessa stringa
swprintf(message, 512, _T("%s "), gsc_msg(615)); // Messaggio:
wcscat(message, gsc_err(GS_ERR_COD));
if ((list += acutBuildList(RTSTR, message, 0)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
if ((list += acutBuildList(RTLE, RTLE, RTLE, 0)) == NULL)
{ GS_ERR_COD = eGSOutOfMem; return NULL; }
list.ReleaseAllAtDistruction(GS_BAD);
return list.get_head();
}
//-----------------------------------------------------------------------//
// INIZIO GESTIONE DCL PER ERRORI DI RETE //
//-----------------------------------------------------------------------//
/*************************************************************************/
/*.doc (new 2) redraw_ErrorList() <internal> */
/*+
Parametri:
ads_hdlg dcl_id; handle DCL attiva
Visualizza nella DCL la lista dei parametri diagnostici
-*/
/*************************************************************************/
int redraw_ErrorList(ads_hdlg dcl_id, presbuf ErrorList)
{
presbuf p;
int i = 0, n, PrevPos;
TCHAR offset[5], *pStr;
// posizione della riga corrente
ads_get_tile(dcl_id, _T("error_list"), offset, 4);
PrevPos = _wtoi(offset);
// offset di spostamento dello slider
ads_get_tile(dcl_id, _T("error_slid"), offset, 4);
n = _wtoi(offset);
// creazione lista messaggi di errore per listbox
if ((ads_start_list(dcl_id, _T("error_list"), LIST_NEW, 0))!=RTNORM)
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
while ((p = gsc_nth(i++, ErrorList)) != NULL)
{
pStr = gsc_nth(0, p)->resval.rstring;
if (wcslen(pStr) > (unsigned int) n) gsc_add_list(pStr + n);
else gsc_add_list(GS_EMPTYSTR);
}
if (ads_end_list() != RTNORM) { GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
// riposiziono la riga che era corrente
_itow_s(PrevPos, offset, 5, 10);
ads_set_tile(dcl_id, _T("error_list"), offset);
ads_set_tile(dcl_id, _T("error"), GS_EMPTYSTR);
return GS_GOOD;
}
// ACTION TILE : slider orizzontale lista errori
static void CALLB error_slid(ads_callback_packet *dcl)
{
redraw_ErrorList(dcl->dialog, (presbuf) dcl->client_data);
ads_set_tile(dcl->dialog, _T("error"), GS_EMPTYSTR);
return;
}
/*************************************************************************/
/*.doc (new 2) redraw_DiagList() <internal> */
/*+
Parametri:
ads_hdlg dcl_id; handle DCL attiva
int message; Codice messaggio
Visualizza nella DCL la lista dei parametri diagnostici
-*/
/*************************************************************************/
int redraw_DiagList(ads_hdlg dcl_id, int message, presbuf ErrorList)
{
presbuf p, q;
int i = 0, n, PrevPos;
TCHAR offset[5], *pStr;
// posizione della riga corrente
ads_get_tile(dcl_id, _T("diag_list"), offset, 4);
PrevPos = _wtoi(offset);
// offset di spostamento dello slider
ads_get_tile(dcl_id, _T("diag_slid"), offset, 4);
n = _wtoi(offset);
// creazione lista parametri di diagnosi per listbox
if ((ads_start_list(dcl_id, _T("diag_list"), LIST_NEW, 0))!=RTNORM)
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
if ((p = gsc_nth(message, ErrorList)) != NULL &&
(p = gsc_nth(1, p)) != NULL)
while ((q = gsc_nth(i++, p)) != NULL)
{
pStr = q->resval.rstring;
if (pStr && wcslen(pStr) > (unsigned int) n) gsc_add_list(pStr + n);
else gsc_add_list(GS_EMPTYSTR);
}
if (ads_end_list() != RTNORM) { GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
// riposiziono la riga che era corrente
_itow_s(PrevPos, offset, 5, 10);
ads_set_tile(dcl_id, _T("error_list"), offset);
ads_set_tile(dcl_id, _T("error"), GS_EMPTYSTR);
return GS_GOOD;
}
// ACTION TILE : slider orizzontale lista errori
static void CALLB diag_slid(ads_callback_packet *dcl)
{
TCHAR message[5];
ads_get_tile(dcl->dialog, _T("error_list"), message, 4);
redraw_DiagList(dcl->dialog, _wtoi(message), (presbuf) dcl->client_data);
ads_set_tile(dcl->dialog, _T("error"), GS_EMPTYSTR);
return;
}
// ACTION TILE : click su tasto n. tentativi... //
static void CALLB error_attempts_num(ads_callback_packet *dcl)
{
TCHAR new_value[5];
if ((ads_get_tile(dcl->dialog, _T("attempts_num"), new_value, 4)) != RTNORM) return;
if (_wtoi(new_value) <= 0)
{
ads_set_tile(dcl->dialog, _T("error"), gsc_msg(287)); // "*Errore* Valore non valido."
_itow_s(GEOsimAppl::GLOBALVARS.get_NumTest(), new_value, 5, 10);
ads_set_tile(dcl->dialog, _T("attempts_num"), new_value);
}
else
{
ads_set_tile(dcl->dialog, _T("error"), GS_EMPTYSTR);
if (GEOsimAppl::GLOBALVARS.set_NumTest(_wtoi(new_value)) == GS_GOOD)
{
C_STRING pathfile;
// scrivo variabili globali
pathfile = GEOsimAppl::CURRUSRDIR; // Directory locale dell'utente corrente
pathfile += _T('\\');
pathfile += GS_INI_FILE;
if (GEOsimAppl::GLOBALVARS.Save(pathfile.get_name()) == GS_BAD) return;
}
}
return;
}
// ACTION TILE : click su tasto tempo di attesa //
static void CALLB error_wait_time(ads_callback_packet *dcl)
{
TCHAR new_value[5];
if ((ads_get_tile(dcl->dialog, _T("wait_time"), new_value, 4)) != RTNORM)
{ ads_done_dialog(dcl->dialog, DLGOK); }
if (_wtoi(new_value) < 0)
{
ads_set_tile(dcl->dialog, _T("error"), gsc_msg(287)); // "*Errore* Valore non valido."
_itow_s(GEOsimAppl::GLOBALVARS.get_WaitTime(), new_value, 5, 10);
ads_set_tile(dcl->dialog, _T("wait_time"), new_value);
}
else
{
ads_set_tile(dcl->dialog, _T("error"), GS_EMPTYSTR);
if (GEOsimAppl::GLOBALVARS.set_WaitTime(_wtoi(new_value)) == GS_GOOD)
{
C_STRING pathfile;
// scrivo variabili globali
pathfile = GEOsimAppl::CURRUSRDIR; // Directory locale dell'utente corrente
pathfile += _T('\\');
pathfile += GS_INI_FILE;
if (GEOsimAppl::GLOBALVARS.Save(pathfile.get_name()) == GS_BAD) return;
}
}
return;
}
// ACTION TILE : click su riga lista errori //
static void CALLB error_msg_list(ads_callback_packet *dcl)
{
TCHAR message[5];
if (dcl->reason == 1)
{
ads_get_tile(dcl->dialog, _T("error_list"), message, 4);
redraw_DiagList(dcl->dialog, _wtoi(message), (presbuf) dcl->client_data);
ads_set_tile(dcl->dialog, _T("error"), GS_EMPTYSTR);
}
return;
}
// ACTION TILE : click su tasto Ritenta... //
static void CALLB error_retry(ads_callback_packet *dcl)
{
ads_done_dialog(dcl->dialog, DLGOK);
return;
}
// ACTION TILE : click su tasto Annulla //
static void CALLB error_abort(ads_callback_packet *dcl)
{
ads_done_dialog(dcl->dialog, DLGCANCEL);
return;
}
/*************************************************************************/
/*.doc (new 2) gsc_dderrordmin() <external> */
/*+
Gestisce gli errori di rete con interfaccia DCL
Parametri:
const TCHAR *ErrType; "ADE" per errore ADE, "GEOSIM" per errore gestito da GEOsim
const TCHAR *OptionalDescr; Descrizione opzionale (default = NULL)
Ritorna GS_GOOD se si vuole ritentare, GS_CAN se si vuole abortire,
GS_BAD in caso di errore.
-*/
/*************************************************************************/
int gsc_dderroradmin(const TCHAR *ErrType, const TCHAR *OptionalDescr)
{
C_RB_LIST ErrorList;
if (!ErrType) { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
if (gsc_strcmp(ErrType, _T("ADE"), FALSE) == 0) // è un errore di ADE (no sensitive)
{
if ((ErrorList << gsc_get_ADEdiag()) == NULL || ErrorList.GetCount() <= 0)
return GS_BAD;
}
else
if (gsc_strcmp(ErrType, _T("GEOSIM"), FALSE) == 0) // è un errore gestito da GEOsim (no sensitive)
{
if ((ErrorList << gsc_get_GEOdiag()) == NULL || ErrorList.GetCount() <= 0)
{ GS_ERR_COD = eGSOutOfMem; return GS_BAD; }
}
else { GS_ERR_COD = eGSInvalidArg; return GS_BAD; }
return gsc_dderroradmin(ErrorList, OptionalDescr);
}
int gsc_dderroradmin(C_RB_LIST &ErrorList, const TCHAR *OptionalDescr)
{
ads_hdlg dcl_id;
int status, i = 0, DclFile; // usata per la dcl che gestisce gli errori
TCHAR new_value[5];
C_STRING pathfile;
// CARICA IL FILE DCL E INIZIALIZZA LA DIALOG-BOX
pathfile = GEOsimAppl::WORKDIR + _T("\\") + GEODCLDIR + _T("\\") + GS_GENERIC_DCL;
if (gsc_load_dialog(pathfile.get_name(), &DclFile) != RTNORM) return GS_BAD;
if (ads_new_dialog(_T("ErrorAdmin"), DclFile, (CLIENTFUNC)NULLCB, &dcl_id) != RTNORM ||
dcl_id == NULL)
{ GS_ERR_COD = eGSAbortDCL; ads_unload_dialog(DclFile); return GS_BAD; }
// se esiste inserisco una descrizione opzionale
if (OptionalDescr)
{
TCHAR _OptionalDescr[80]; // vedi in "gs.dcl" nella dialog "ErrorAdmin" la width del tile "OptionalDescr"
gsc_strcpy(_OptionalDescr, OptionalDescr, 80);
ads_set_tile(dcl_id, _T("OptionalDescr"), _OptionalDescr);
}
if (redraw_ErrorList(dcl_id, ErrorList.get_head()) == GS_BAD)
{ ads_unload_dialog(DclFile); return GS_BAD; }
ads_set_tile(dcl_id, _T("error_list"), _T("0"));
redraw_DiagList(dcl_id, 0, ErrorList.get_head());
_itow_s(GEOsimAppl::GLOBALVARS.get_NumTest(), new_value, 5, 10);
ads_set_tile(dcl_id, _T("attempts_num"), new_value);
_itow_s(GEOsimAppl::GLOBALVARS.get_WaitTime(), new_value, 5, 10);
ads_set_tile(dcl_id, _T("wait_time"), new_value);
if (ads_action_tile(dcl_id, _T("error_list"), error_msg_list) != RTNORM || // lista errori
ads_client_data_tile(dcl_id, _T("error_list"), ErrorList.get_head()) != RTNORM ||
ads_action_tile(dcl_id, _T("error_slid"), error_slid) != RTNORM || // slider orizzontale
ads_client_data_tile(dcl_id, _T("error_slid"), ErrorList.get_head()) != RTNORM ||
ads_action_tile(dcl_id, _T("diag_slid"), diag_slid) != RTNORM || // slider orizzontale
ads_client_data_tile(dcl_id, _T("diag_slid"), ErrorList.get_head()) != RTNORM ||
ads_action_tile(dcl_id, _T("attempts_num"), error_attempts_num) != RTNORM || // n. tentativi
ads_action_tile(dcl_id, _T("wait_time"), error_wait_time) != RTNORM || // tempo tra 2 tentativi
ads_action_tile(dcl_id, _T("retry"), error_retry) != RTNORM || // tasto Ritenta...
ads_action_tile(dcl_id, _T("abort"), error_abort) != RTNORM) // tasto Annulla
{ ads_unload_dialog(DclFile); GS_ERR_COD = eGSAbortDCL; return GS_BAD; }
if (ads_start_dialog(dcl_id, &status) != RTNORM)
{ ads_unload_dialog(DclFile); GS_ERR_COD = eGSAbortDCL; return GS_BAD; }
ads_unload_dialog(DclFile);
if (status == DLGCANCEL) return GS_CAN;
return GS_GOOD;
}
/**********************************************************************/
/*.doc printDBErrs <internal> */
/*+
Stampa gli errori sulla riga di comando.
Parametri:
C_RB_LIST &ErrorList;
-*/
/*********************************************************/
void gsc_PrintError(C_RB_LIST &ErrorList)
{
presbuf pMsg, pDiag;
int ii, jj = 0;
while ((pMsg = ErrorList.nth(jj++)) != NULL)
{
acutPrintf(_T("\n--------------------\n%s"), gsc_nth(0, pMsg)->resval.rstring);
if ((pMsg = gsc_nth(1, pMsg)) != NULL)
{
ii = 0;
// Print diagnostics parameters
while ((pDiag = gsc_nth(ii++, pMsg)) != NULL)
acutPrintf(_T("\n%s"), pDiag->resval.rstring);
}
}
}
//-----------------------------------------------------------------------//
// FINE GESTIONE DCL PER ERRORI IN RETE //
//-----------------------------------------------------------------------//