2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
* Author : Richard GAYRAUD - 04 Nov 2003
17
* From Hewlett Packard Company.
21
* Screen.cpp : Simple curses & logfile encapsulation
36
extern int twinSippSocket;
37
extern int localTwinSippSocket;
40
unsigned long screen_errors;
41
char screen_last_error[32768];
42
char _screen_err[32768];
43
FILE * screen_errorf = 0;
44
int screen_inited = 0;
45
char screen_logfile[255];
46
char screen_exename[255];
47
extern void releaseGlobalAllocations();
48
extern bool backgroundMode;
50
void (*screen_exit_handler)();
52
/* Clock must be a pointer to struct timeval */
53
#define GET_TIME(clock) \
55
struct timezone tzp; \
56
gettimeofday (clock, &tzp); \
64
void screen_exit(int rc)
66
unsigned long counter_value=0;
68
/* Some signals may be delivered twice during exit() execution,
69
* and we must prevent all this from beeing done twice */
72
static int already_exited = 0;
79
if( backgroundMode == false )
82
if(screen_exit_handler) {
83
screen_exit_handler();
87
fprintf(stderr, "%s", screen_last_error);
88
if(screen_errors > 1) {
89
if (screen_logfile[0] != (char)0) {
91
"%s: There were more errors, see scenarioname_ppid_errors.log file\n",
95
"%s: There were more errors, enable -trace_err to log them.\n",
104
close(twinSippSocket);
107
if(localTwinSippSocket) {
108
close(localTwinSippSocket);
112
// Get failed calls counter value before releasing objects
113
counter_value = CStat::instance()->GetStat (CStat::CPT_C_FailedCall);
115
releaseGlobalAllocations();
117
if (rc != EXIT_TEST_RES_UNKNOWN) {
118
// Exit is not a normal exit. Just use the passed exit code.
121
// Normal exit: we need to determine if the calls were all
122
// successful or not.
123
// In order to compute the return code, get the counter
124
// of failed calls. If there is 0 failed calls, then everything is OK!
125
if (counter_value == 0) {
128
exit(EXIT_TEST_FAILED);
133
/* Exit handler for Curses */
137
screen_exit(EXIT_TEST_RES_UNKNOWN);
145
void screen_set_exename(char * exe_name)
147
strcpy(screen_exename, exe_name);
150
void screen_init(char *logfile_name, void (*exit_handler)())
152
struct sigaction action_quit;
155
if (logfile_name == NULL) {
156
screen_logfile[0] = (char)0;
158
strcpy(screen_logfile, logfile_name);
160
screen_exit_handler = exit_handler;
162
/* Initializes curses and signals */
164
/* Enhance performances and display */
167
/* Map exit handlers to curses reset procedure */
168
memset(&action_quit, 0, sizeof(action_quit));
169
(*(void **)(&(action_quit.sa_handler)))=(void *)screen_quit;
170
sigaction(SIGTERM, &action_quit, NULL);
171
sigaction(SIGINT, &action_quit, NULL);
172
sigaction(SIGKILL, &action_quit, NULL);
177
void _screen_error(char *s, int fatal)
180
char * c = screen_last_error;
181
struct timeval currentTime;
183
GET_TIME (¤tTime);
185
c+= sprintf(c, "%s: ", CStat::instance()->formatTime(¤tTime));
186
c+= sprintf(c, "%s", s);
187
c+= sprintf(c, ".\n");
190
if(screen_inited && (!screen_errorf) && screen_logfile[0] != (char)0) {
191
screen_errorf = fopen(screen_logfile, "w");
193
c += sprintf(c, "%s: Unable to create '%s'.\n",
194
screen_exename, screen_logfile);
195
screen_exit(EXIT_FATAL_ERROR);
197
fprintf(screen_errorf, "%s: The following events occured:\n",
199
fflush(screen_errorf);
204
output = screen_errorf;
205
fprintf(output, "%s", screen_last_error);
209
fprintf(output, "%s", screen_last_error);
215
exit(EXIT_FATAL_ERROR);
217
screen_exit(EXIT_FATAL_ERROR);