1/*
2 Hanoh Haim
3 Cisco Systems, Inc.
4*/
5
6/*
7Copyright (c) 2015-2015 Cisco Systems, Inc.
8
9Licensed under the Apache License, Version 2.0 (the "License");
10you may not use this file except in compliance with the License.
11You may obtain a copy of the License at
12
13    http://www.apache.org/licenses/LICENSE-2.0
14
15Unless required by applicable law or agreed to in writing, software
16distributed under the License is distributed on an "AS IS" BASIS,
17WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18See the License for the specific language governing permissions and
19limitations under the License.
20*/
21#include "global_io_mode.h"
22#include "utl_term_io.h"
23#include <stdlib.h>
24
25
26void CTrexGlobalIoMode::set_mode(CliDumpMode  mode){
27    switch (mode) {
28    case  cdDISABLE:
29        m_g_mode=gDISABLE;
30        m_g_disable_first=false;
31        break;
32    case  cdNORMAL:
33        Reset();
34        break;
35    case cdSHORT:
36        m_g_mode=gNORMAL;
37        m_pp_mode=ppDISABLE;
38        m_ap_mode=apENABLE;
39        m_l_mode=lDISABLE;
40        m_rc_mode=rcDISABLE;
41        break;
42    }
43}
44
45
46bool CTrexGlobalIoMode::handle_io_modes(void){
47    int c=utl_termio_try_getch();
48    if (c) {
49        if (c==3) {
50            return true;
51        }
52        switch (c)  {
53        case ccHELP:
54            if (m_g_mode==gHELP) {
55                m_g_mode=gNORMAL;
56            }else{
57                m_g_mode=gHELP;
58            }
59            break;
60        case ccGDISABLE:
61            if (m_g_mode==gDISABLE) {
62                m_g_mode=gNORMAL;
63            }else{
64                m_g_mode=gDISABLE;
65                m_g_disable_first=true;
66            }
67            break;
68        case ccGNORAML:
69            Reset();
70            break;
71        case ccGPP:
72            m_g_mode=gNORMAL;
73            m_pp_mode++;
74            if (m_pp_mode==ppLAST) {
75                m_pp_mode = ppDISABLE;
76            }
77            break;
78        case ccGAP:
79            m_g_mode=gNORMAL;
80            m_ap_mode++;
81            if (m_ap_mode == apLAST) {
82                m_ap_mode = apDISABLE;
83            }
84            break;
85        case ccGL:
86            m_g_mode=gNORMAL;
87            m_l_mode++;
88            if (m_l_mode == lLAST) {
89                m_l_mode = lDISABLE;
90            }
91            break;
92        case ccGRC:
93            m_g_mode=gNORMAL;
94            m_rc_mode++;
95            if (m_rc_mode == rcLAST) {
96                m_rc_mode = rcDISABLE;
97            }
98            break;
99        case ccMem:
100            if ( m_g_mode==gNORMAL ){
101                m_g_mode=gMem;
102            }else{
103                m_g_mode=gNORMAL;
104            }
105            break;
106        case ccNat:
107            m_g_mode=gNAT;
108            m_nat_mode++;
109            if (m_nat_mode==natLAST) {
110                m_nat_mode = natDISABLE;
111                m_g_mode = gNORMAL;
112            }
113            break;
114        }
115
116
117    }
118    return false;
119}
120
121void CTrexGlobalIoMode::Dump(FILE *fd){
122    fprintf(fd,"\033[2J");
123    fprintf(fd,"\033[2H");
124    fprintf(fd," global: %d \n",(int)m_g_mode);
125    fprintf(fd," pp    : %d \n",(int)m_pp_mode);
126    fprintf(fd," ap    : %d \n",(int)m_ap_mode);
127    fprintf(fd," l     : %d \n",(int)m_l_mode);
128    fprintf(fd," rc    : %d \n",(int)m_rc_mode);
129}
130
131void CTrexGlobalIoMode::DumpHelp(FILE *fd){
132        fprintf(fd, "Help for Interactive Commands\n" );
133        fprintf(fd, "  %c  : Toggle, Disable all/Default \n", ccGDISABLE);
134        fprintf(fd, "  %c  : Go back to default mode \n", ccGNORAML);
135        fprintf(fd, "  %c  : Toggle, Help/Default  \n", ccHELP);
136        fprintf(fd, "\n");
137        fprintf(fd, "  %c  : Per ports    toggle disable -> table -> normal \n", ccGPP);
138        fprintf(fd, "  %c  : Global ports toggle disable/enable \n", ccGAP);
139        fprintf(fd, "  %c  : Latency      toggle disable -> enable -> enhanced  \n", ccGL);
140        fprintf(fd, "  %c  : Rx check  toggle disable -> enable -> enhanced  \n", ccGRC);
141        fprintf(fd, "  %c  : Memory stats toggle disable/enable   \n", ccMem);
142        fprintf(fd, "  %c  : NAT pending flows toggle disable/enable   \n", ccNat);
143        fprintf(fd, "  Press %c or %c to go back to Normal mode \n", ccHELP, ccGNORAML);
144}
145
146
147
148