Debian Codegraph @

test/dapltest/cmd/dapl_server_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 void DT_Server_Cmd_Init(Server_Cmd_t * Server_Cmd)
34 {
35 DT_dapltest_debug = 0;
36 Server_Cmd->debug = false;
37 Server_Cmd->port = SERVER_PORT_NUMBER;
38 Server_Cmd->dapl_name[0] = '\0';
39 Server_Cmd->ReliabilityLevel = DAT_QOS_BEST_EFFORT;
40 }
41
42 bool
43 DT_Server_Cmd_Parse(Server_Cmd_t * Server_Cmd,
44 int my_argc, char **my_argv, mygetopt_t * opts)
45 {
46 int c;
47 for (;;) {
48 c = DT_mygetopt_r(my_argc, my_argv, "dD:R:n:", opts);
49 if (c == EOF) {
50 break;
51 }
52 switch (c) {
53 case 'D':
54 {
55 strcpy(Server_Cmd->dapl_name, opts->optarg);
56 break;
57 }
58 case 'd':
59 {
60 DT_dapltest_debug++;
61 Server_Cmd->debug = true;
62 break;
63 }
64 case 'R': /* Service Reliability Level */
65 {
66 Server_Cmd->ReliabilityLevel =
67 DT_ParseQoS(opts->optarg);
68 if (0 == Server_Cmd->ReliabilityLevel) {
69 return (false);
70 }
71 break;
72 }
73 case 'n':
74 {
75 Server_Cmd->port = atoi(opts->optarg);
76 break;
77 }
78 case '?':
79 default:
80 {
81 DT_Mdep_printf("Invalid Server option: %c\n",
82 opts->optopt);
83 DT_Server_Cmd_Usage();
84 return (false);
85 }
86 }
87 }
88 if (Server_Cmd->dapl_name == '\0') {
89 if (!DT_Mdep_GetDefaultDeviceName(Server_Cmd->dapl_name)) {
90 DT_Mdep_printf("can't get default device name\n");
91 DT_Server_Cmd_Usage();
92 return (false);
93 }
94 }
95 return (true);
96 }
97
98 void DT_Server_Cmd_Usage(void)
99 {
100 DT_Mdep_printf("USAGE: ---- SERVER MODE ----\n");
101 DT_Mdep_printf("USAGE: dapltest -T S\n");
102 DT_Mdep_printf("USAGE: [-D <device Name>]\n");
103 DT_Mdep_printf("USAGE: [-d] : debug (zero)\n");
104 DT_Mdep_printf("USAGE: [-R <service reliability>]\n");
105 DT_Mdep_printf("USAGE: [-n <server port number>]\n");
106 DT_Mdep_printf("USAGE: (BE == QOS_BEST_EFFORT - Default)\n");
107 DT_Mdep_printf("USAGE: (HT == QOS_HIGH_THROUGHPUT)\n");
108 DT_Mdep_printf("USAGE: (LL == QOS_LOW_LATENCY)\n");
109 DT_Mdep_printf("USAGE: (EC == QOS_ECONOMY)\n");
110 DT_Mdep_printf("USAGE: (PM == QOS_PREMIUM)\n");
111 DT_Mdep_printf("USAGE: Run as server using default parameters\n");
112 DT_Mdep_printf("USAGE: dapltest\n");
113 DT_Mdep_printf("USAGE:\n");
114 }
115
116 void DT_Server_Cmd_Print(Server_Cmd_t * Server_Cmd)
117 {
118 DT_Mdep_printf("Server_Cmd.debug: %d\n", Server_Cmd->debug);
119 DT_Mdep_printf("Server_Cmd.dapl_name: %s\n", Server_Cmd->dapl_name);
120 DT_Mdep_printf("Server_Cmd.port: %lu\n", Server_Cmd->port);
121 }