~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to proxy/mgmt2/cli2/cliMain.cc

  • 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
#include "ink_config.h"
 
25
#include <stdlib.h>
 
26
//#include "tclExtend.h"
 
27
#include "tcl.h"
 
28
#include <string.h>
 
29
#include "ink_args.h"
 
30
#include "ink_file.h"
 
31
#include "I_Layout.h"
 
32
#include "I_Version.h"
 
33
#include "CliMgmtUtils.h"
 
34
#include "INKMgmtAPI.h"
 
35
 
 
36
extern int Tcl_AppInit(Tcl_Interp * interp);
 
37
extern int CliDisplayPrintf;
 
38
void eventCallbackFn(char *name, char *msg, int pri, void *data);
 
39
 
 
40
// default is that alarms appear in CLI as they occur
 
41
int AlarmCallbackPrint = 1;
 
42
 
 
43
// registers an event callback for all events in general
 
44
void register_event_callback(void);
 
45
 
 
46
AppVersionInfo appVersionInfo;
 
47
int version_flag = 0;
 
48
 
 
49
int
 
50
main(int argc, char *argv[])
 
51
{
 
52
  INKError status;
 
53
 
 
54
  // build the application information structure
 
55
  appVersionInfo.setup(PACKAGE_NAME,"traffic_shell", PACKAGE_VERSION, __DATE__,
 
56
                       __TIME__, BUILD_MACHINE, BUILD_PERSON, "");
 
57
 
 
58
  // Before accessing file system initialize Layout engine
 
59
  Layout::create();
 
60
 
 
61
  // Argument description table used to describe how to parse command line args,
 
62
  // see 'ink_args.h' for meanings of the various fields
 
63
  ArgumentDescription argument_descriptions[] = {
 
64
    {"version", 'V', "Print Version Id", "T", &version_flag, NULL, NULL}
 
65
  };
 
66
 
 
67
  int n_argument_descriptions = SIZE(argument_descriptions);
 
68
  NOWARN_UNUSED(argc);
 
69
 
 
70
  // Process command line arguments and dump into variables
 
71
  process_args(argument_descriptions, n_argument_descriptions, argv);
 
72
 
 
73
  // check for the version number request
 
74
  if (version_flag) {
 
75
    ink_fputln(stderr, appVersionInfo.FullVersionInfoStr);
 
76
    exit(0);
 
77
  }
 
78
 
 
79
  // traffic_shell binary should use printf to display information onscreen
 
80
  CliDisplayPrintf = 1;
 
81
 
 
82
  // initialize MgmtAPI using TS runtime directory
 
83
  status = INKInit(Layout::get()->runtimedir);
 
84
  if (status) {
 
85
    printf("INKInit %d: Failed to initialize MgmtAPI in %s\n",
 
86
           status, Layout::get()->runtimedir);
 
87
  } else {
 
88
    printf("Successfully Initialized MgmtAPI in %s \n",
 
89
          Layout::get()->runtimedir);
 
90
  }
 
91
 
 
92
  register_event_callback();
 
93
 
 
94
  Tcl_Main(argc, argv, Tcl_AppInit);
 
95
  exit(0);
 
96
}
 
97
 
 
98
void
 
99
eventCallbackFn(char *name, char *msg, int pri, void *data)
 
100
{
 
101
  NOWARN_UNUSED(msg);
 
102
  NOWARN_UNUSED(pri);
 
103
  NOWARN_UNUSED(data);
 
104
  if (AlarmCallbackPrint == 1) {
 
105
    printf("\n**********\n" "ALARM SIGNALLED: %s\n" "**********\n", name);
 
106
  }
 
107
 
 
108
  return;
 
109
}
 
110
 
 
111
// registers an event callback for all events in general
 
112
void
 
113
register_event_callback(void)
 
114
{
 
115
  // TODO: Check return code?
 
116
  INKEventSignalCbRegister(NULL, eventCallbackFn, NULL);
 
117
}