1 //%2003////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 //==============================================================================
26 // Author: Karl Schopmeyer (k.schopmeyer@opengroup.org)
28 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
29 // (carolann_graves@hp.com)
31 //%/////////////////////////////////////////////////////////////////////////////
39 #include <Pegasus/Repository/CIMRepository.h>
40 //#include <Pegasus/Client/CIMClient.h>
41 //#include <Pegasus/Common/Selector.h>
42 #include <Pegasus/Common/OptionManager.h>
43 #include <Pegasus/Common/FileSystem.h>
46 using namespace Pegasus;
50 /** RegisterProvider - Sets Registration for Provider
51 This executable sets the appropriate registration parameters
52 to register a provider or unregister a provider.
53 It can be used to register a provider against a single class and
54 define it as a property, method, or instance provider.
56 It can be used either to register or unregister the provider.
58 The parameters of the call are
61 -U - If set, tries to unregister the provider (default is register)
62 -D - Simply show the current state of registration
63 -M - Method provider registraion
64 -P - Property provider registration
65 -V - View all current provider registrations
67 Class - CIMReference with the Namespace and classname to register.
69 Method or property name.
71 Registration type is defined through the CIMReference.
72 If the reference is a class name only, the registration is on the
73 class. If it includes a method name, it is on the method, etc.
76 /** ErrorExit - Print out the error message as an
78 @param - Text for error message
79 @return - None, Terminates the program
80 @execption - This function terminates the program
81 ATTN: Should write to stderr
83 void ErrorExit(const String& message)
86 cout << message << endl;
94 const String& pegasusHome)
96 static struct OptionRow options[] =
98 {"unregister", "false", false, Option::BOOLEAN, 0, 0, "u"},
99 {"display", "false", false, Option::BOOLEAN, 0, 0, "d"},
100 {"method", "false", false, Option::BOOLEAN, 0, 0, "m"},
101 {"property", "false", false, Option::BOOLEAN, 0, 0, "p"},
102 {"version", "false", false, Option::BOOLEAN, 0, 0, "v"},
103 {"help", "false", false, Option::BOOLEAN, 0, 0, "h"}
105 const Uint32 NUM_OPTIONS = sizeof(options) / sizeof(options[0]);
107 om.registerOptions(options, NUM_OPTIONS);
109 String configFile = pegasusHome + "/cimserver.conf";
111 if (FileSystem::exists(configFile))
112 om.mergeFile(configFile);
114 om.mergeCommandLine(argc, argv);
116 om.checkRequiredOptions();
119 void PrintHelp(const char* arg0)
121 Uint32 PROGRAM_VERSION = 1;
123 cout << "Provider Registration Version " << PROGRAM_VERSION << endl;
125 cout << "Usage: " << arg0 << " [options] [namespace] [class]";
126 cout << " [providerID]\n" << '\n';
127 cout << " Registers ProviderIDs for classes in repository\n\n";
128 cout << " -h prints this help message\n";
129 cout << " -u unregister the class defined from the provider\n";
130 cout << " -m method registration (Not Enabled)\n";
131 cout << " -p property registration provider (Not Enabled)\n";
132 cout << " -v print out the program version number\n";
133 cout << " Parameters required are\n";
134 cout << " Namespace ClassName ProviderID\n";
135 cout << "\n providerreg root/cimv2 process MyProvider\n";
136 cout << " registers class process to provider MyProvider \n";
137 cout << "\n providerreg -u root/cimv2 process\n";
138 cout << " unregisters class process\n";
139 cout << " NOTE: unregistration does not require providerID param\n";
146 void registerInstanceProvider(
151 String& providerName)
155 // Create the new qualifier
160 nameSpace, className, false, false, true);
162 virtual CIMClass getClass(
163 const String& nameSpace,
164 const String& className,
165 Boolean localOnly = true,
166 Boolean includeQualifiers = true,
167 Boolean includeClassOrigin = false,
168 const Array<String>& propertyList = EmptyStringArray());
170 // CIMClass c2 = client.getClass(NAMESPACE, "SubClass", false);
173 cc1 = r.getClass(NAMESPACE, "MyClass");
179 // Catch when class does not exist.
180 cout << "Class does not exist " << e.getMessage() << endl;
185 //test if already registered
187 cout << "registering " << className << " for "
188 << providerName << endl;
189 Uint32 pos = c1.findQualifier("Provider");
190 if (pos != PEG_NOT_FOUND)
192 // NOTE that we should modify
193 cout << "Provider exists" << endl;
194 c1.removeQualifier(pos);
196 c1.addQualifier(CIMQualifier("Provider", providerName));
197 cout << "Provider " << providerName << " changed." << endl;
198 r.modifyClass(nameSpace, c1);
201 else // Here we deregister
203 // test not registered
204 cout << "unregistering "<< endl;
205 Uint32 qualifierIndex;
206 qualifierIndex = c1.findQualifier("Provider");
207 if (qualifierIndex != PEG_NOT_FOUND)
209 c1.removeQualifier(qualifierIndex);
213 // Does not exist. Issue message
214 cout << "Not Registered" << endl;
220 void registerMethodProvider(
225 String& providerName)
228 CIMClass c = r.getClass(
229 nameSpace, "CIM_ComputerSystem", false, false, true);
234 void registerPropertyProvider(
239 String& providerName)
242 CIMClass c = r.getClass(
243 nameSpace, "CIM_ComputerSystem", false, false, true);
248 void showOneProviderRegistration(
252 String& providerName)
257 pos = c1.findQualifier("provider");
258 if (pos != PEG_NOT_FOUND)
260 // Display the qualifier.
261 CIMQualifier q1 = c1.getQualifier(pos);
264 q1.getValue().get(providerId);
266 String name = c1.getClassName();
268 << fill.subString(0, 20-name.size())
275 // Catch when class does not exist.
276 cout << "Class does not exist " << e.getMessage() << endl;
282 void showProviderRegistrations (
286 String& providerName)
289 cout << "Show Provider Registrations for Namespace "
290 << nameSpace << endl;
295 virtual Array<CIMClass> enumerateClasses(
296 const String& nameSpace,
297 const String& className = String::EMPTY,
298 Boolean deepInheritance = false,
299 Boolean localOnly = true,
300 Boolean includeQualifiers = true,
301 Boolean includeClassOrigin = false);
303 cout << "Class Provider" << endl;
304 cout << "----------------------------" << endl;
307 Uint32 providerCount = 0;
308 Array<CIMClass> classList = r.enumerateClasses(
309 nameSpace, className, true, false, true);
312 for (Uint32 i = 0, n = classList.size(); i < n; i++)
314 if (classList[i].findQualifier("provider") != PEG_NOT_FOUND)
316 showOneProviderRegistration(
324 cout << endl << providerCount << " Classes found" << endl;
329 // Catch when class does not exist.
330 cout << "Class does not exist " << e.getMessage() << endl;
336 // Questions: if registered already for class, do we have to
337 // register for property or method?
340 int main(int argc, char** argv)
343 // Get the parameters from the command line
344 // arg2 is objectpath
346 // make - parameter to deregister -d
348 ErrorExit("unexpected command line arguments");
349 Boolean toRegister = true;
351 className = "Process";
353 providerName = "MyProvider";
355 nameSpace = "root/cimv2";
362 GetOptions(om, argc, argv, pegasusHome);
367 cerr << argv[0] << ": " << e.getMessage() << endl;
371 String versionOption;
372 if (om.lookupValue("version", versionOption) && versionOption == "true")
374 cerr << "Registration Version 1.0" << endl;
378 // Check to see if user asked for help (-h otpion):
382 if (om.lookupValue("help", helpOption) && helpOption == "true")
387 // At this point, all options should have been extracted; print an
388 // error if there are any remaining:
392 // cerr << argv[0] << ": unrecognized options: ";
394 // for (int i = 1; i < argc; i++)
395 // cerr << argv[i] << ' ';
402 const char *tmp = getenv("PEGASUS_HOME");
404 ErrorExit("PEGASUS_HOME environment variable missing");
407 FileSystem::translateSlashes(pegasusHome);
409 String repositoryDir = pegasusHome;
410 repositoryDir += "/repository";
412 // Test for legal repository here.
414 CIMRepository r(repositoryDir);
416 // Process the display option
417 if (om.valueEquals("display", "true"))
424 showProviderRegistrations (
425 r, nameSpace, className,providerName);
430 ErrorExit("Namespace and classname required");
433 if (om.lookupValue("unregister", helpOption) && helpOption ==
436 // if registering, get the provider name parameter
438 ErrorExit("Provider name parameter required");
441 providerName = argv[3];
444 else // set to unregister
447 cout << (toRegister ? "Registering " : "Unregistering ")
448 << "Class " << nameSpace << ":" <<className
449 << " for Provider " << providerName << endl;
451 registerInstanceProvider(r,
462 std::cerr << "Error: " << e.getMessage() << std::endl;
466 std::cout << "OK" << std::endl;