📄 cimop.cpp
字号:
{ pDef=cldef.getProperty(n); cout << n+1 << ": "; cout << cimTypeToString(pDef.getType()) << " "; cout << pDef.getName().getString(); if (pDef.isArray()) cout << "[]"; cout << endl; } cout << "Property (1.." << cldef.getPropertyCount() << ")? " << flush; cin >> n; pDef = cldef.getProperty(n-1); } // else use last arg as property to get else { int pos = cldef.findProperty(argv[2]); if (pos == PEG_NOT_FOUND) { cerr << argv[2] << ": not found." << endl; return 1; } pDef = cldef.getProperty(pos); } // Now we can call getProperty() and display result CIMValue v; try { v = _c.getProperty( _nameSpace, ref, pDef.getName().getString() ); } catch (Exception &e) { cerr << /* "getProperty: " << */ e.getMessage() << endl; return 1; } cout << " " << pDef.getName().getString(); if (v.isArray()) cout << "[" << v.getArraySize() << "]"; if (v.isNull()) cout << "=NULL"; else cout << "=" << "\"" << v.toString() << "\""; cout << endl; return 0;}// ===============================================================// setProperty// ===============================================================int _setProperty(const int argc, const char **argv){#if 0 cerr << "Not yet implemented" << endl; return 1;#endif if (argc < 2) { _spUsage(); return 1; } // need to get class definition to find keys // first arg is name of class CIMClass cldef; try { cldef = _c.getClass( _nameSpace, argv[0] ); } catch(Exception& e) { cerr << /* "getProperty: " << */ e.getMessage() << endl; return 1; } CIMObjectPath ref; CIMInstance inst; // If next arg is "ask", prompt user for keys if (String::equalNoCase("ask",argv[1])) ref = CIMObjectPath(String::EMPTY, _nameSpace, argv[0], _inputInstanceKeys(cldef) ); // else if the next arg is "list", do enumInstNames and print // a list from which user will select else if (String::equalNoCase("list",argv[1])) { ref = _selectInstance( argv[0] ); // Exit if a null reference was returned if (ref.identical(CIMObjectPath())) return 0; } // else the arg is invalid else { _spUsage(); return 1; } CIMProperty pDef; // if no more args, display property names and ask which to set if (argc < 3) { Uint32 n; for (n=0; n<cldef.getPropertyCount(); n++) { cout << n+1 << ": "; cout << cimTypeToString(cldef.getProperty(n).getType()); cout << cldef.getProperty(n).getName().getString(); if (cldef.getProperty(n).isArray()) cout << "[]"; cout << endl; } cout << "Property (1.." << cldef.getPropertyCount() << ")? " << flush; cin >> n; pDef = cldef.getProperty(n-1); } // else use next arg as name of property to set else { int pos = cldef.findProperty(argv[2]); if (pos == PEG_NOT_FOUND) { cerr << argv[2] << ": not found." << endl; return 1; } pDef = cldef.getProperty(pos); } if (pDef.isArray()) { cout << "setProperty for arrays not yet implemented" << endl; return 1; } char v[1024]; // If value was not specified, ask for one if (argc < 4) { cout << "Value? " << flush; gets(v); } else strcpy(v,argv[3]);cout << "namespace: " << _nameSpace << endl;cout << "reference: " << ref.toString() << endl;cout << "propName: " << pDef.getName().getString() << endl;cout << "value: " << _makeValue(v,pDef).toString() << endl; // Now we can call setProperty() try { _c.setProperty( _nameSpace, ref, pDef.getName().getString(), _makeValue(v,pDef) ); } catch (Exception &e) { cerr << /* "setProperty: " << */ e.getMessage() << endl; return 1; } return 0;}// ===============================================================// invokeMethod// ===============================================================int _invokeMethod(const int argc, const char **argv){ cerr << "Not yet implemented" << endl; return 1;}// ===============================================================// createClass// ===============================================================int _createClass(const int argc, const char **argv){ cerr << "Not yet implemented" << endl; return 1;}// ===============================================================// modifyClass// ===============================================================int _modifyClass(const int argc, const char **argv){ cerr << "Not yet implemented" << endl; return 1;}// ===============================================================// deleteClass// ===============================================================int _deleteClass(const int argc, const char **argv){ if (argv[0]==0) { cerr << "Usage: cimop deleteClass|dc <class>" << endl; return 1; } CIMClass cldef; try { _c.deleteClass( _nameSpace, argv[0] ); } catch (Exception& e) { cerr << /* "deleteClass: " << */ e.getMessage() << endl; return 1; } return 0;}// ===============================================================// createInstance// ===============================================================int _createInstance(const int argc, const char **argv){ if (argc < 1) { _ciUsage(); return 1; } // get class definition CIMClass cldef; // Handle special case of __Namespace if (String::equalNoCase(argv[0],"__namespace")) cldef = _makeNamespaceClass(); else { try { cldef = _c.getClass( _nameSpace, argv[0] ); } catch(Exception& e) { cerr << /* "getProperty: " << */ e.getMessage() << endl; return 1; } } CIMInstance tmpInst(cldef.getClassName()); Array<CIMKeyBinding> keys; // prompt user for property values for (Uint32 i=0; i<cldef.getPropertyCount(); i++) { // display the property CIMProperty pDef(cldef.getProperty(i)); if (_isKey(pDef)) cout << "[ key ] "; cout << cimTypeToString(pDef.getType()) << " " << pDef.getName().getString(); if (pDef.isArray()) cout << "[]"; if (pDef.isArray()) { cerr << ": Array properties not yet implemented" << endl; continue; } cout << "? " << flush; // ask for a value char v[1024]; gets(v); // insert thusly specified property in instance pDef.setValue(_makeValue(v,pDef)); tmpInst.addProperty(pDef); // And in a CIMKeyBinding array if it's a key if (_isKey(pDef)) keys.append(_makeKey(pDef)); } // Set the object path try { tmpInst.setPath(CIMObjectPath(String::EMPTY, // host _nameSpace, // namespace cldef.getClassName(), // classname keys)); // keybindings } catch (Exception &e) { cerr << e.getMessage() << endl; return 1; } // Submit the create operation to the cimserver try { _c.createInstance( _nameSpace, tmpInst); } catch (Exception &e) { cerr << e.getMessage() << endl; return 1; } return 0;}// ===============================================================// modifyInstance// ===============================================================int _modifyInstance(const int argc, const char **argv){ if (argc < 1) { _miUsage(); return 1; } // need to get class definition to find keys // first arg is name of class CIMClass cldef; try { cldef = _c.getClass( _nameSpace, argv[0] ); } catch(Exception& e) { cerr << /* "getProperty: " << */ e.getMessage() << endl; return 1; } CIMObjectPath ref; CIMInstance inst; // If no more args, prompt user for keys if (argc < 2) ref = CIMObjectPath( String::EMPTY, _nameSpace, argv[0], _inputInstanceKeys(cldef) ); // if the next arg is "list", do enumInstNames and print // a list from which user will select else if (String::equalNoCase("list",argv[1])) { ref = _selectInstance( argv[0] ); // Exit if a null reference was returned if (ref.identical(CIMObjectPath())) return 0; } // else the arg is invalid else { _miUsage(); return 1; } // get a copy of existing instance for display try { inst = _c.getInstance(_nameSpace, ref); } catch (Exception &e) { cerr << e.getMessage() << endl; return 1; } // display property names and ask which to modify Uint32 n; for (n=0; n<cldef.getPropertyCount(); n++) { cout << n+1 << ": "; Uint32 p = inst.findProperty(cldef.getProperty(n).getName()); if (p!=PEG_NOT_FOUND) cout << _displayProperty(inst.getProperty(p)) << endl; else cout << cldef.getProperty(n).getName().getString() << " <absent>" << endl; } CIMInstance tmpInst(cldef.getClassName()); Array<CIMName> pNames; while (true) // break when user enters escape value { cout << "Property (1.." << cldef.getPropertyCount() << ", 0=quit, 999=all)? " << flush; cin >> n; if (n==0 || n==999) break; if (n>cldef.getPropertyCount() || n<0) continue; CIMProperty pDef(cldef.getProperty(n-1)); if (pDef.isArray()) { cerr << "Array properties not yet implemented" << endl; continue; } // Ask for value cout << cimTypeToString(pDef.getType()) << " " << pDef.getName().getString() << "? " << flush; char v[1024]; gets(v); // remove property if one of same name exists Uint32 p=tmpInst.findProperty(pDef.getName().getString()); if (p!=PEG_NOT_FOUND) tmpInst.removeProperty(p); // insert a property with this value in the instance pDef.setValue(_makeValue(v,pDef)); tmpInst.addProperty(pDef); // add to array of names if not already there for (p=0; p<pNames.size(); p++) if (pNames[p]==pDef.getName()) break; if (p==pNames.size()) pNames.append(pDef.getName()); } CIMPropertyList pList; // need to re-ask if n=999, and use null propertyList if (n==999) for (Uint32 i=0; i<cldef.getPropertyCount(); i++) { CIMProperty pDef(cldef.getProperty(i)); cout << cimTypeToString(pDef.getType()) << " " << pDef.getName().getString(); if (pDef.isArray()) cout << "[]"; if (pDef.isArray()) { cerr << ": Array properties not yet implemented" << endl; continue; } cout << "? " << flush; char v[1024]; gets(v); pDef.setValue(_makeValue(v,pDef)); int j = tmpInst.findProperty(pDef.getName()); if (j!=PEG_NOT_FOUND) tmpInst.removeProperty(j); tmpInst.addProperty(pDef); // don't bother with pNames array } else pList = CIMPropertyList(pNames); // Don't forget to set the object path in this instance tmpInst.setPath(ref); // Now we can call modifyInstance() try { _c.modifyInstance(_nameSpace,tmpInst,false,pList); } catch (Exception &e) { cerr << /* "modifyInstance: " << */ e.getMessage() << endl; return 1; } return 0;}// ===============================================================// deleteInstance// ===============================================================int _deleteInstance(const int argc, const char **argv){ if (argv[0] == 0) { _diUsage(); return 1; } // need to get class definition to find keys // first arg is name of class CIMClass cldef; // Handle special case of __Namespace if (String::equalNoCase(argv[0],"__namespace")) cldef = _makeNamespaceClass(); else { try { cldef = _c.getClass( _nameSpace, argv[0] ); } catch(Exception& e) { cerr << /* "deleteInstance: " << */ e.getMessage() << endl; return 1; } } CIMObjectPath ref; CIMInstance inst; // If there are no more args, prompt user for keys if (argv[1] == 0) ref = CIMObjectPath(String::EMPTY, // hostname left blank _nameSpace, argv[0], _inputInstanceKeys(cldef)); // else if there's another arg and it's "list", enumInstNames and print // a list from which user will select (return if none) else if (String::equalNoCase("list",argv[1])) { ref = _selectInstance(argv[0]); // An empty ObjectPath means nothing was selected if (ref.identical(CIMObjectPath())) return 0; } // else there's another arg but it's invalid else { _diUsage(); return 1; } // delete the specified instance try { _c.deleteInstance(_nameSpace,ref); } catch(Exception& e) { cerr << /* "deleteInstance: " << */ e.getMessage() << endl; return 1; } return 0;}// ===============================================================// associators// ===============================================================int _associators(const int argc, const char **argv){ cerr << "Not yet implemented" << endl; return 1;}// ===============================================================// associatorNames// ===============================================================int _associatorNames(const int argc, const char **argv){ cerr << "Not yet implemented" << endl; return 1;}// ===============================================================// references// ===============================================================int _references(const int argc, const char **argv){ cerr << "Not yet implemented" << endl; return 1;}// ===============================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -