VirtualBox

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

Last change on this file since 18499 was 18246, checked in by vboxsync, 15 years ago

license header updates from filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: SUPLoggerCtl.cpp 18246 2009-03-25 11:36:34Z 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/initterm.h>
36#include <iprt/getopt.h>
37#include <iprt/stream.h>
38#include <iprt/string.h>
39#include <iprt/ctype.h>
40#include <iprt/err.h>
41
42
43/**
44 * Prints the usage.
45 * @returns 1.
46 */
47static int usage(void)
48{
49 RTPrintf("usage: SUPLoggerCtl [-f|--flags <flags-settings>] \\\n"
50 " [-g|--groups <groups-settings>] \\\n"
51 " [-d|--dest <destination-specifiers>] \\\n"
52 " [-l|--which <release|debug>] \\\n"
53 " [-o|--what <set|create|destroy>]\n"
54 " or: SUPLoggerCtl <-h|--help>\n"
55 "\n"
56 );
57 return 1;
58}
59
60
61int main(int argc, char **argv)
62{
63 RTR3InitAndSUPLib();
64
65 /*
66 * Options are mandatory.
67 */
68 if (argc <= 1)
69 return usage();
70
71 /*
72 * Parse the options.
73 */
74 static const RTGETOPTDEF s_aOptions[] =
75 {
76 { "--flags", 'f', RTGETOPT_REQ_STRING },
77 { "--groups", 'g', RTGETOPT_REQ_STRING },
78 { "--dest", 'd', RTGETOPT_REQ_STRING },
79 { "--what", 'o', RTGETOPT_REQ_STRING },
80 { "--which", 'l', RTGETOPT_REQ_STRING },
81 { "--help", 'h', 0 },
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 VINF_GETOPT_NOT_OPTION:
144 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: Unexpected argument '%s'.\n", Val.psz);
145 return 1;
146
147 default:
148 if (ch > 0)
149 {
150 if (RT_C_IS_GRAPH(ch))
151 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: unhandled option: -%c\n", ch);
152 else
153 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: unhandled option: %i\n", ch);
154 }
155 else if (ch == VERR_GETOPT_UNKNOWN_OPTION)
156 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: unknown option: %s\n", Val.psz);
157 else if (Val.pDef)
158 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: %s: %Rrs\n", Val.pDef->pszLong, ch);
159 else
160 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: %Rrs\n", ch);
161 return 1;
162 }
163 }
164
165 /*
166 * Do the requested job.
167 */
168 int rc;
169 switch (enmWhat)
170 {
171 case kSupLoggerCtl_Set:
172 rc = SUPR3LoggerSettings(enmWhich, pszFlags, pszGroups, pszDest);
173 break;
174 case kSupLoggerCtl_Create:
175 rc = SUPR3LoggerCreate(enmWhich, pszFlags, pszGroups, pszDest);
176 break;
177 case kSupLoggerCtl_Destroy:
178 rc = SUPR3LoggerDestroy(enmWhich);
179 break;
180 default:
181 rc = VERR_INTERNAL_ERROR;
182 break;
183 }
184 if (RT_SUCCESS(rc))
185 RTPrintf("SUPLoggerCtl: Success\n");
186 else
187 RTStrmPrintf(g_pStdErr, "SUPLoggerCtl: error: rc=%Rrc\n", rc);
188
189 return RT_SUCCESS(rc) ? 0 : 1;
190}
191
192
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use