VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/SUPLoggerCtl.cpp@ 26943

Last change on this file since 26943 was 26517, checked in by vboxsync, 15 years ago

*: RTGetOpt cleanup related to --help and --version (now standard option). Use RTGetOptPrintError.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1/* $Id: SUPLoggerCtl.cpp 26517 2010-02-14 21:39:00Z vboxsync $ */
2/** @file
3 * SUPLoggerCtl - Support Driver Logger Control.
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#include <VBox/sup.h>
35#include <iprt/buildconfig.h>
36#include <iprt/initterm.h>
37#include <iprt/getopt.h>
38#include <iprt/stream.h>
39#include <iprt/string.h>
40#include <iprt/ctype.h>
41#include <iprt/err.h>
42
43
44/**
45 * Prints the usage.
46 * @returns 1.
47 */
48static int usage(void)
49{
50 RTPrintf("usage: SUPLoggerCtl [-f|--flags <flags-settings>] \\\n"
51 " [-g|--groups <groups-settings>] \\\n"
52 " [-d|--dest <destination-specifiers>] \\\n"
53 " [-l|--which <release|debug>] \\\n"
54 " [-o|--what <set|create|destroy>]\n"
55 " or: SUPLoggerCtl <-h|--help>\n"
56 "\n"
57 );
58 return 1;
59}
60
61
62int main(int argc, char **argv)
63{
64 RTR3InitAndSUPLib();
65
66 /*
67 * Options are mandatory.
68 */
69 if (argc <= 1)
70 return usage();
71
72 /*
73 * Parse the options.
74 */
75 static const RTGETOPTDEF s_aOptions[] =
76 {
77 { "--flags", 'f', RTGETOPT_REQ_STRING },
78 { "--groups", 'g', RTGETOPT_REQ_STRING },
79 { "--dest", 'd', RTGETOPT_REQ_STRING },
80 { "--what", 'o', RTGETOPT_REQ_STRING },
81 { "--which", 'l', RTGETOPT_REQ_STRING },
82 };
83
84 const char *pszFlags = "";
85 const char *pszGroups = "";
86 const char *pszDest = "";
87 SUPLOGGER enmWhich = SUPLOGGER_DEBUG;
88 enum
89 {
90 kSupLoggerCtl_Set, kSupLoggerCtl_Create, kSupLoggerCtl_Destroy
91 } enmWhat = kSupLoggerCtl_Set;
92
93 int ch;
94 int i = 1;
95 RTGETOPTUNION Val;
96 RTGETOPTSTATE GetState;
97 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
98 while ((ch = RTGetOpt(&GetState, &Val)))
99 {
100 switch (ch)
101 {
102 case 'f':
103 pszFlags = Val.psz;
104 break;
105
106 case 'g':
107 pszGroups = Val.psz;
108 break;
109
110 case 'd':
111 pszDest = Val.psz;
112 break;
113
114 case 'o':
115 if (!strcmp(Val.psz, "set"))
116 enmWhat = kSupLoggerCtl_Set;
117 else if (!strcmp(Val.psz, "create"))
118 enmWhat = kSupLoggerCtl_Create;
119 else if (!strcmp(Val.psz, "destroy"))
120 enmWhat = kSupLoggerCtl_Destroy;
121 else
122 {
123 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unknown operation '%s'.\n", Val.psz);
124 return 1;
125 }
126 break;
127
128 case 'l':
129 if (!strcmp(Val.psz, "debug"))
130 enmWhich = SUPLOGGER_DEBUG;
131 else if (!strcmp(Val.psz, "release"))
132 enmWhich = SUPLOGGER_RELEASE;
133 else
134 {
135 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unknown logger '%s'.\n", Val.psz);
136 return 1;
137 }
138 break;
139
140 case 'h':
141 return usage();
142
143 case 'V':
144 RTPrintf("%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr());
145 return 0;
146
147 case VINF_GETOPT_NOT_OPTION:
148 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unexpected argument '%s'.\n", Val.psz);
149 return 1;
150
151 default:
152 return RTGetOptPrintError(ch, &Val);
153 }
154 }
155
156 /*
157 * Do the requested job.
158 */
159 int rc;
160 switch (enmWhat)
161 {
162 case kSupLoggerCtl_Set:
163 rc = SUPR3LoggerSettings(enmWhich, pszFlags, pszGroups, pszDest);
164 break;
165 case kSupLoggerCtl_Create:
166 rc = SUPR3LoggerCreate(enmWhich, pszFlags, pszGroups, pszDest);
167 break;
168 case kSupLoggerCtl_Destroy:
169 rc = SUPR3LoggerDestroy(enmWhich);
170 break;
171 default:
172 rc = VERR_INTERNAL_ERROR;
173 break;
174 }
175 if (RT_SUCCESS(rc))
176 RTPrintf("SUPLoggerCtl: Success\n");
177 else
178 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: rc=%Rrc\n", rc);
179
180 return RT_SUCCESS(rc) ? 0 : 1;
181}
182
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette