Debian Codegraph @

test/dapltest/cmd/dapl_quit_cmd.c

raw
1 /*
2 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
3 *
4 * This Software is licensed under one of the following licenses:
5 *
6 * 1) under the terms of the "Common Public License 1.0" a copy of which is
7 * in the file LICENSE.txt in the root directory. The license is also
8 * available from the Open Source Initiative, see
9 * http://www.opensource.org/licenses/cpl.php.
10 *
11 * 2) under the terms of the "The BSD License" a copy of which is in the file
12 * LICENSE2.txt in the root directory. The license is also available from
13 * the Open Source Initiative, see
14 * http://www.opensource.org/licenses/bsd-license.php.
15 *
16 * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
17 * copy of which is in the file LICENSE3.txt in the root directory. The
18 * license is also available from the Open Source Initiative, see
19 * http://www.opensource.org/licenses/gpl-license.php.
20 *
21 * Licensee has the right to choose one of the above licenses.
22 *
23 * Redistributions of source code must retain the above copyright
24 * notice and one of the license notices.
25 *
26 * Redistributions in binary form must reproduce both the above copyright
27 * notice, one of the license notices in the documentation
28 * and/or other materials provided with the distribution.
29 */
30
31 #include "dapl_proto.h"
32
33 /*--------------------------------------------------------- */
34 void DT_Quit_Cmd_Init(Quit_Cmd_t * cmd)
35 {
36 memset((void *)cmd, 0, sizeof(Quit_Cmd_t));
37 cmd->ReliabilityLevel = DAT_QOS_BEST_EFFORT;
38 cmd->port = SERVER_PORT_NUMBER;
39 }
40
41 /*--------------------------------------------------------- */
42 bool
43 DT_Quit_Cmd_Parse(Quit_Cmd_t * cmd,
44 int my_argc, char **my_argv, mygetopt_t * opts)
45 {
46 int c;
47
48 for (;;) {
49 c = DT_mygetopt_r(my_argc, my_argv, "ds:D:R:n:", opts);
50 if (c == EOF) {
51 break;
52 }
53 switch (c) {
54 case 'D':
55 {
56 strcpy(cmd->device_name, opts->optarg);
57 break;
58 }
59 case 's':
60 {
61 strcpy(cmd->server_name, opts->optarg);
62 break;
63 }
64 case 'd': /* print debug messages */
65 {
66 DT_dapltest_debug++;
67 cmd->debug = true;
68 break;
69 }
70 case 'R': /* Service Reliability Level */
71 {
72 cmd->ReliabilityLevel =
73 DT_ParseQoS(opts->optarg);
74 break;
75 }
76 case 'n':
77 {
78 cmd->port = atoi(opts->optarg);
79 break;
80 }
81 case '?':
82 default:
83 {
84 DT_Mdep_printf("Invalid Quit option: %c\n",
85 opts->optopt);
86 DT_Quit_Cmd_Usage();
87 return (false);
88 }
89 }
90 }
91 if (cmd->device_name[0] == '\0') {
92 if (!DT_Mdep_GetDefaultDeviceName(cmd->device_name)) {
93 DT_Mdep_printf("can't get default device name\n");
94 DT_Quit_Cmd_Usage();
95 return (false);
96 }
97 }
98 if (!DT_Quit_Cmd_Validate(cmd)) {
99 DT_Quit_Cmd_Usage();
100 return (false);
101 }
102 return (true);
103 }
104
105 /*------------------------------------------------------------------------------ */
106 bool DT_Quit_Cmd_Validate(Quit_Cmd_t * cmd)
107 {
108 if (cmd->server_name[0] == '\0') {
109 DT_Mdep_printf
110 ("Must specify server_name in command line or scriptfile\n");
111 return (false);
112 }
113 return (true);
114 }
115
116 /*--------------------------------------------------------- */
117 void DT_Quit_Cmd_Usage(void)
118 {
119 DT_Mdep_printf("USAGE: ---- QUIT TEST ----\n");
120 DT_Mdep_printf("USAGE: dapltest -T Q\n");
121 DT_Mdep_printf("USAGE: -s <server Name>\n");
122 DT_Mdep_printf("USAGE: -n <server port number>\n");
123 DT_Mdep_printf("USAGE: [-D <device Name>]\n");
124 DT_Mdep_printf("USAGE: [-d] : debug (zero)\n");
125 DT_Mdep_printf("USAGE: [-R <service reliability>]\n");
126 DT_Mdep_printf
127 ("USAGE: (BE == QOS_BEST_EFFORT - Default)\n");
128 DT_Mdep_printf("USAGE: (HT == QOS_HIGH_THROUGHPUT)\n");
129 DT_Mdep_printf("USAGE: (LL == QOS_LOW_LATENCY)\n");
130 DT_Mdep_printf("USAGE: (EC == QOS_ECONOMY)\n");
131 DT_Mdep_printf("USAGE: (PM == QOS_PREMIUM)\n");
132 }
133
134 /*--------------------------------------------------------- */
135 void DT_Quit_Cmd_Print(Quit_Cmd_t * cmd)
136 {
137 DT_Mdep_printf("Quit_Cmd.server_name: %s\n", cmd->server_name);
138 DT_Mdep_printf("Quit_Cmd.device_name: %s\n", cmd->device_name);
139 DT_Mdep_printf("Quit_Cmd.port: %lu\n", cmd->port);
140 }