~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to proxy/mgmt2/cli/CLIeventHandler.h

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
7
  Licensed to the Apache Software Foundation (ASF) under one
 
8
  or more contributor license agreements.  See the NOTICE file
 
9
  distributed with this work for additional information
 
10
  regarding copyright ownership.  The ASF licenses this file
 
11
  to you under the Apache License, Version 2.0 (the
 
12
  "License"); you may not use this file except in compliance
 
13
  with the License.  You may obtain a copy of the License at
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
  Unless required by applicable law or agreed to in writing, software
 
18
  distributed under the License is distributed on an "AS IS" BASIS,
 
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
  See the License for the specific language governing permissions and
 
21
  limitations under the License.
 
22
 */
 
23
 
 
24
/***************************************/
 
25
/****************************************************************************
 
26
 *
 
27
 *  Module: concrete class for comand line interface event handling
 
28
 *
 
29
 *
 
30
 ****************************************************************************/
 
31
 
 
32
#ifndef _CMDLINE_EVENTHANDLER_H
 
33
#define _CMDLINE_EVENTHANDLER_H
 
34
 
 
35
#include <stdio.h>
 
36
#include "AbsEventHandler.h"    /* Abstract base class for event handler */
 
37
#include "TextBuffer.h"
 
38
 
 
39
/* Define list of possible command line states */
 
40
enum cmdline_states
 
41
{
 
42
  CL_BASE = 0,                  /* 1. Base command line */
 
43
  CL_MONITOR,                   /* 2. Monitor mode */
 
44
  CL_CONFIGURE,                 /* 3. Configuration mode */
 
45
  CL_MON_DASHBOARD,             /* 4. Monitor->Dashboard */
 
46
  CL_MON_NODE,                  /* 5. Monitor->Node */
 
47
  CL_MON_PROTOCOLS,             /* 6. Monitor->Protocols */
 
48
  CL_MON_CACHE,                 /* 7. Monitor->Cache */
 
49
  CL_MON_OTHER,                 /* 8. Monitor->Other */
 
50
  CL_CONF_SERVER,               /* 9. Configure->Server */
 
51
  CL_CONF_PROTOCOLS,            /* 10. Configure->Protocols */
 
52
  CL_CONF_CACHE,                /* 11. Configure->Cache */
 
53
  CL_CONF_SECURITY,             /* 12. Configure->Security */
 
54
  CL_CONF_HOSTDB,               /* 13. Configure->Hostdb */
 
55
  CL_CONF_LOGGING,              /* 14. Configure->logging */
 
56
  CL_CONF_SNAPSHOTS,            /* 15. Configure->snapshots */
 
57
  CL_CONF_ROUTING               /* 16. Configure->routing */
 
58
};
 
59
 
 
60
 
 
61
/* Define list of possible events to command line */
 
62
enum cmdline_events             /* 20 events */
 
63
{
 
64
  /* INTERNAL_ERROR = 0, for unhandled events */
 
65
  /* all levels  - 8 */
 
66
  CL_EV_ERROR = 1,
 
67
  CL_EV_HELP,                   /* all levels */
 
68
  CL_EV_EXIT,                   /* all levels */
 
69
  CL_EV_PREV,                   /* all levels, BaseLevel should ignore */
 
70
  CL_EV_GET,                    /* ?all levels? , only really used in batch mode */
 
71
  CL_EV_SET,                    /* ?all levels? */
 
72
  CL_EV_DISPLAY,                /* ?all levels? */
 
73
  CL_EV_CHANGE,
 
74
  CL_EV_QUERY_DEADHOSTS,        /* only base level */
 
75
  /* generic events based on option number - 11 */
 
76
  CL_EV_ADD_ALARM,              /* OEM_SUN custom alarm feature */
 
77
  CL_EV_ONE,
 
78
  CL_EV_TWO,
 
79
  CL_EV_THREE,
 
80
  CL_EV_FOUR,
 
81
  CL_EV_FIVE,
 
82
  CL_EV_SIX,
 
83
  CL_EV_SEVEN,
 
84
  CL_EV_EIGHT,
 
85
  CL_EV_NINE,
 
86
  CL_EV_TEN,
 
87
  CL_EV_ELEVEN
 
88
};
 
89
 
 
90
/* Event handlers indexes i.e. each state handles events  */
 
91
enum Handler_indexes
 
92
{
 
93
  Ind_InternalError,            /* handle Internal Errors e.g. unhandled events */
 
94
  Ind_BaseLevel,
 
95
  Ind_MonitorLevel,
 
96
  Ind_MonitorDashboardLevel,
 
97
  Ind_MonitorNodeLevel,
 
98
  Ind_MonitorProtocolsLevel,
 
99
  Ind_MonitorCacheLevel,
 
100
  Ind_MonitorOtherLevel,
 
101
  Ind_ConfigureLevel,
 
102
  Ind_ConfigureServerLevel,
 
103
  Ind_ConfigureProtocolsLevel,
 
104
  Ind_ConfigureCacheLevel,
 
105
  Ind_ConfigureSecurityLevel,
 
106
  Ind_ConfigureHostDBLevel,
 
107
  Ind_ConfigureLoggingLevel,
 
108
  Ind_ConfigureSnapshotsLevel,
 
109
  Ind_ConfigureRoutingLevel
 
110
};
 
111
 
 
112
 
 
113
/* data structure used to pass data to event handlers */
 
114
typedef struct CLIdata
 
115
{
 
116
  char *cmdmode;                /* command mode i.e. batch(b) or interactive(i) */
 
117
  char *cmdprompt;              /* what prompt should look like e.g '->' */
 
118
  char *command;                /* command string itself */
 
119
  char *args;                   /* arugments passed to 'command' */
 
120
  textBuffer *output;           /* output buffer */
 
121
  cmdline_events cevent;        /* event */
 
122
  int advui;                    /* which UI */
 
123
  int featset;                  /* feature set */
 
124
} CLI_DATA;
 
125
 
 
126
/* Command Line event handling  class derived from an abstract event handler class */
 
127
class CmdLine_EventHandler:public AbsEventHandler
 
128
{
 
129
private:
 
130
  /* variables */
 
131
  char *cmdmode;                /* command mode i.e. batch(b) or interactive(i) */
 
132
  const char *cmdprompt;              /* what prompt should look like e.g '->' */
 
133
  const char *dcmdprompt;             /* default prompt */
 
134
  char *args;                   /* arugments passed to this level */
 
135
  cmdline_states curr_state;    /* current command line state */
 
136
 
 
137
  /* Redefinition of the abstract base class's pure virtual function
 
138
   * ref: AbsEvenhandler.h   */
 
139
  void FillHandlersArray(void);
 
140
 
 
141
  /*  Event handlers - make some actions associated with a transition */
 
142
  bool handleInternalError(void *cdata);
 
143
  bool BaseLevel(void *cdata);
 
144
  bool MonitorLevel(void *cdata);
 
145
  bool MonitorDashboardLevel(void *cdata);
 
146
  bool MonitorProtocolsLevel(void *cdata);
 
147
  bool MonitorNodeLevel(void *cdata);
 
148
  bool MonitorCacheLevel(void *cdata);
 
149
  bool MonitorOtherLevel(void *cdata);
 
150
  bool ConfigureLevel(void *cdata);
 
151
  bool ConfigureServerLevel(void *cdata);
 
152
  bool ConfigureProtocolsLevel(void *cdata);
 
153
  bool ConfigureCacheLevel(void *cdata);
 
154
  bool ConfigureSecurityLevel(void *cdata);
 
155
  bool ConfigureRoutingLevel(void *cdata);
 
156
  bool ConfigureHostDBLevel(void *cdata);
 
157
  bool ConfigureLoggingLevel(void *cdata);
 
158
  bool ConfigureSnapshotsLevel(void *cdata);
 
159
 
 
160
  /* copy constructor and assignment operator are private
 
161
   *  to prevent their use */
 
162
    CmdLine_EventHandler(const CmdLine_EventHandler & rhs);
 
163
    CmdLine_EventHandler & operator=(const CmdLine_EventHandler & rhs);
 
164
 
 
165
  /* no default constructor */
 
166
    CmdLine_EventHandler();
 
167
 
 
168
public:
 
169
  /* Constructor */
 
170
    CmdLine_EventHandler(int inNumberTransitions, char *cmdm = NULL, char *cmdp = NULL, char *largs = NULL);
 
171
 
 
172
  /* Destructor */
 
173
   ~CmdLine_EventHandler(void);
 
174
 
 
175
  /* Member fcns */
 
176
  const char *command_prompt();       /* get prompt */
 
177
  void command_prompt(const char *new_prompt);        /* set prompt */
 
178
  char *arguments();            /* get args */
 
179
  void arguments(char *new_args);       /* set args */
 
180
  char *command_mode();         /* get command mode */
 
181
  void command_mode(char *new_cmode);   /* set command mode */
 
182
  cmdline_states current_state();       /* get current state */
 
183
  void current_state(cmdline_states new_state); /* set current state */
 
184
};
 
185
 
 
186
#endif /* _CMDLINE_EVENTHANDLER_H */