2 * Copyright (c) 1999 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * i4b daemon - curses fullscreen output
28 * -------------------------------------
30 * $Id: curses.c,v 1.7 2009/04/16 05:56:33 lukem Exp $
34 * last edit-date: [Mon Dec 13 21:51:47 1999]
36 *---------------------------------------------------------------------------*/
38 #include "monprivate.h"
42 static void display_bell(void);
43 static void display_chans(void);
45 /*---------------------------------------------------------------------------*
47 *---------------------------------------------------------------------------*/
56 /*---------------------------------------------------------------------------*
57 * init curses fullscreen display
58 *---------------------------------------------------------------------------*/
66 initscr(); /* curses init */
68 if ((COLS
< 80) || (LINES
< 24))
71 fprintf(stderr
, "ERROR, minimal screensize must be 80x24, is %dx%d, terminating!",COLS
, LINES
);
78 uheight
= nctrl
* 2; /* cards * b-channels */
79 lheight
= LINES
- uheight
- 6 + 1; /* rest of display */
81 if ((upper_w
= newwin(uheight
, COLS
, UPPER_B
, 0)) == NULL
)
84 fprintf(stderr
, "ERROR, curses init upper window, terminating!");
88 if ((mid_w
= newwin(1, COLS
, UPPER_B
+uheight
+1, 0)) == NULL
)
91 fprintf(stderr
, "ERROR, curses init mid window, terminating!");
95 if ((lower_w
= newwin(lheight
, COLS
, UPPER_B
+uheight
+3, 0)) == NULL
)
98 fprintf(stderr
, "ERROR, curses init lower window, LINES = %d, lheight = %d, uheight = %d, terminating!", LINES
, lheight
, uheight
);
102 scrollok(lower_w
, 1);
104 snprintf(buffer
, sizeof(buffer
), "----- isdn controller channel state ------------- isdnmonitor %02d.%02d.%d -", VERSION
, REL
, STEP
);
106 while((int)strlen(buffer
) < COLS
)
107 strlcat(buffer
, "-", sizeof(buffer
));
115 /* 01234567890123456789012345678901234567890123456789012345678901234567890123456789 */
116 addstr("# tei b remote iface dir outbytes obps inbytes ibps units");
119 snprintf(buffer
, sizeof(buffer
), "----- isdn userland interface state ------------- %s:%d -", hostname
, portno
);
121 snprintf(buffer
, sizeof(buffer
), "----- isdn userland interface state ------------- %s -", sockpath
);
123 while((int)strlen(buffer
) < COLS
)
124 strlcat(buffer
, "-", sizeof(buffer
));
131 snprintf(buffer
, sizeof(buffer
), "----- isdnd logfile display --------------------------------------------------");
132 while((int)strlen(buffer
) < COLS
)
133 strlcat(buffer
, "-", sizeof(buffer
));
142 for (i
=0, j
=0; i
<= nctrl
; i
++, j
+=2)
144 mvwprintw(upper_w
, j
, H_CNTL
, "%d --- 1 ", i
); /*TEI*/
145 mvwprintw(upper_w
, j
+1, H_CNTL
, " L12 2 ");
150 for (i
=0, j
=0; i
< nentries
; i
++) /* walk thru all entries */
152 p
= &cfg_entry_tab
[i
]; /* get ptr to enry */
154 mvwprintw(mid_w
, 0, j
, "%s%d ", bdrivername(p
->usrdevicename
), p
->usrdeviceunit
);
158 j
+= ((strlen(bdrivername(p
->usrdevicename
)) + (p
->usrdeviceunit
> 9 ? 2 : 1) + 1));
161 mvwprintw(mid_w
, 0, 0, "%s", devbuf
);
165 wmove(lower_w
, 0, 0);
171 /*---------------------------------------------------------------------------*
172 * display the charge in units
173 *---------------------------------------------------------------------------*/
175 display_charge(int pos
, int charge
)
177 mvwprintw(upper_w
, pos
, H_UNITS
, "%d", charge
);
182 /*---------------------------------------------------------------------------*
183 * display the calculated charge in units
184 *---------------------------------------------------------------------------*/
186 display_ccharge(int pos
, int units
)
188 mvwprintw(upper_w
, pos
, H_UNITS
, "(%d)", units
);
193 /*---------------------------------------------------------------------------*
194 * display accounting information
195 *---------------------------------------------------------------------------*/
197 display_acct(int pos
, int obyte
, int obps
, int ibyte
, int ibps
)
199 mvwprintw(upper_w
, pos
, H_OUT
, "%-10d", obyte
);
200 mvwprintw(upper_w
, pos
, H_OUTBPS
, "%-4d", obps
);
201 mvwprintw(upper_w
, pos
, H_IN
, "%-10d", ibyte
);
202 mvwprintw(upper_w
, pos
, H_INBPS
, "%-4d", ibps
);
206 /*---------------------------------------------------------------------------*
207 * erase line at disconnect time
208 *---------------------------------------------------------------------------*/
210 display_disconnect(int pos
)
212 wmove(upper_w
, pos
, H_TELN
);
220 /*---------------------------------------------------------------------------*
221 * display interface up/down information
222 *---------------------------------------------------------------------------*/
224 display_updown(int pos
, int updown
, char *device
)
231 mvwprintw(mid_w
, 0, pos
, "%s ", device
);
237 /*---------------------------------------------------------------------------*
238 * display interface up/down information
239 *---------------------------------------------------------------------------*/
241 display_l12stat(int controller
, int layer
, int state
)
243 if (controller
> nctrl
)
246 if (!(layer
== 1 || layer
== 2))
256 mvwprintw(upper_w
, (controller
*2)+1, H_TEI
+1, "1");
259 mvwprintw(upper_w
, (controller
*2)+1, H_TEI
+2, "2");
263 mvwprintw(upper_w
, (controller
*2)+1, H_TEI
+2, "2");
265 mvwprintw(upper_w
, (controller
*2)+1, H_TEI
+1, "1");
272 /*---------------------------------------------------------------------------*
274 *---------------------------------------------------------------------------*/
276 display_tei(int controller
, int tei
)
278 if (controller
> nctrl
)
282 mvwprintw(upper_w
, controller
*2, H_TEI
, "---");
284 mvwprintw(upper_w
, controller
*2, H_TEI
, "%3d", tei
);
289 /*---------------------------------------------------------------------------*
291 *---------------------------------------------------------------------------*/
295 static char bell
[1] = { 0x07 };
296 write(STDOUT_FILENO
, &bell
[0], 1);
299 /*---------------------------------------------------------------------------*
300 * curses menu for fullscreen command mode
301 *---------------------------------------------------------------------------*/
305 static const char *menu
[WMITEMS
] =
307 "1 - (D)isplay refresh",
308 "2 - (H)angup (choose a channel)",
309 "3 - (R)eread config file",
310 "4 - (Q)uit the program",
316 struct pollfd set
[1];
318 /* create a new window in the lower screen area */
320 if ((menu_w
= newwin(WMENU_HGT
, WMENU_LEN
, WMENU_POSLN
, WMENU_POSCO
)) == NULL
)
325 /* create a border around the window */
327 box(menu_w
, '|', '-');
332 mvwaddstr(menu_w
, 0, (WMENU_LEN
/ 2) - (strlen(WMENU_TITLE
) / 2), WMENU_TITLE
);
335 /* fill the window with the menu options */
337 for (mpos
=0; mpos
<= (WMITEMS
-1); mpos
++)
338 mvwaddstr(menu_w
, mpos
+ 2, 2, menu
[mpos
]);
340 /* highlight the first menu option */
344 mvwaddstr(menu_w
, mpos
+ 2, 2, menu
[mpos
]);
349 set
[0].fd
= STDIN_FILENO
;
350 set
[0].events
= POLLIN
;
355 /* if no char is available within timeout, exit menu*/
357 if ((poll(set
, 1, WMTIMEOUT
* 1000)) <= 0)
365 case '\t': /* hilite next option */
366 mvwaddstr(menu_w
, mpos
+ 2, 2, menu
[mpos
]);
371 mvwaddstr(menu_w
, mpos
+ 2, 2, menu
[mpos
]);
375 case ('0'+WREFRESH
+1): /* display refresh */
381 case ('0'+WQUIT
+1): /* quit program */
388 case ('0'+WHANGUP
+1): /* hangup connection */
394 case ('0'+WREREAD
+1): /* reread config file */
401 case '\r': /* exec highlighted option */
430 /* delete the menu window */
434 /* re-display the original lower window contents */
440 /*---------------------------------------------------------------------------*
441 * display connect information
442 *---------------------------------------------------------------------------*/
444 display_connect(int pos
, int dir
, char *name
, char *remtel
, char *dev
)
448 /* remote telephone number */
450 snprintf(buffer
, sizeof(buffer
), "%s/%s", name
, remtel
);
452 buffer
[H_IFN
- H_TELN
- 1] = '\0';
454 mvwprintw(upper_w
, pos
, H_TELN
, "%s", buffer
);
458 mvwprintw(upper_w
, pos
, H_IFN
, "%s ", dev
);
460 mvwprintw(upper_w
, pos
, H_IO
, dir
? "out" : "in");
462 mvwprintw(upper_w
, pos
, H_OUT
, "-");
463 mvwprintw(upper_w
, pos
, H_OUTBPS
, "-");
464 mvwprintw(upper_w
, pos
, H_IN
, "-");
465 mvwprintw(upper_w
, pos
, H_INBPS
, "-");
473 /*---------------------------------------------------------------------------*
474 * display channel information for shutdown
475 *---------------------------------------------------------------------------*/
483 int nlines
, ncols
, pos_x
, pos_y
;
484 struct pollfd set
[1];
486 /* need this later to close the connection */
492 for (i
= 0; i
< nctrl
; i
++)
494 if (remstate
[i
].ch1state
)
496 if (remstate
[i
].ch2state
)
502 if ((cc
= (struct ctlr_chan
*)malloc (cnt
*
503 sizeof (struct ctlr_chan
))) == NULL
)
516 pos_y
= WMENU_POSLN
+ 4;
517 pos_x
= WMENU_POSCO
+ 10;
519 /* create a new window in the lower screen area */
521 if ((chan_w
= newwin(nlines
, ncols
, pos_y
, pos_x
)) == NULL
)
528 /* create a border around the window */
530 box(chan_w
, '|', '-');
535 mvwaddstr(chan_w
, 0, (ncols
/ 2) - (strlen("Channels") / 2), "Channels");
538 /* no active channels */
541 mvwaddstr(chan_w
, 2, 2, "No active channels");
545 /* delete the channels window */
554 for (i
= 0; i
< nctrl
; i
++)
556 if (remstate
[i
].ch1state
)
558 snprintf(buffer
, sizeof(buffer
),
559 "%d - Controller %d channel %s", ncols
, i
, "B1");
560 mvwaddstr(chan_w
, nlines
, 2, buffer
);
561 cc
[ncols
- 1].cntl
= i
;
562 cc
[ncols
- 1].chn
= CHAN_B1
;
566 if (remstate
[i
].ch2state
)
568 snprintf(buffer
, sizeof(buffer
),
569 "%d - Controller %d channel %s", ncols
, i
, "B2");
570 mvwaddstr(chan_w
, nlines
, 2, buffer
);
571 cc
[ncols
- 1].cntl
= i
;
572 cc
[ncols
- 1].chn
= CHAN_B2
;
578 set
[0].fd
= STDIN_FILENO
;
579 set
[0].events
= POLLIN
;
584 /* if no char is available within timeout, exit menu*/
586 if ((poll(set
, 1, WMTIMEOUT
* 1000)) <= 0)
589 ncols
= wgetch(chan_w
);
591 if (!(isdigit(ncols
)))
597 nlines
= ncols
- '0';
599 if ((nlines
== 0) || (nlines
> cnt
))
605 hangup(cc
[nlines
-1].cntl
, cc
[nlines
-1].chn
);
611 /* delete the channels window */