Class: WMIRef
- Inherits:
-
Object
- Object
- WMIRef
- Defined in:
- lib/monitor/client/wmi/wmi_ref.rb
Constant Summary collapse
- TABLENAME =
'wmi_ref'
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.add_wmi_ref(n, descr, calc) ⇒ Object
add an wmi_ref arg n for uniq name, descr the description and calc the calcul to do return true if deleted otherwise false.
-
.del_wmi_ref(n) ⇒ Object
delete an wmi_ref return true is entry delete otherwise false.
-
.get_wmi_refs_name ⇒ Object
return a table of all wmirefs name.
- .read_db_wmiref ⇒ Object
- .read_wmiref_conf_file(fic = WMIREFS_CONF_FILE) ⇒ Object
-
.wmi_ref_exist?(name) ⇒ Boolean
check if a given wmi ref name is defined.
-
.wmi_ref_nb_entry ⇒ Object
return number of wmi ref.
- .write_db_wmiref ⇒ Object
- .write_wmiref_conf_file(fic_name = WMIREFS_CONF_FILE) ⇒ Object
Instance Method Summary collapse
- #add_use ⇒ Object
- #del_use ⇒ Object
-
#initialize(n, descr, calc) ⇒ WMIRef
constructor
A new instance of WMIRef.
- #to_str ⇒ Object
- #used? ⇒ Boolean
Constructor Details
#initialize(n, descr, calc) ⇒ WMIRef
Returns a new instance of WMIRef.
116 117 118 119 120 121 122 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 116 def initialize (n, descr, calc) #name is the identifier, it must be uniq @name=n @description=descr @value=calc @nb_use=0 end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 2 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 2 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
2 3 4 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 2 def value @value end |
Class Method Details
.add_wmi_ref(n, descr, calc) ⇒ Object
add an wmi_ref arg n for uniq name, descr the description and calc the calcul to do return true if deleted otherwise false
12 13 14 15 16 17 18 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 12 def WMIRef::add_wmi_ref(n, descr, calc) if $wmi_refs[n] == nil $wmi_refs[n] = WMIRef.new(n, descr, calc) return true end return false end |
.del_wmi_ref(n) ⇒ Object
delete an wmi_ref return true is entry delete otherwise false
25 26 27 28 29 30 31 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 25 def WMIRef::del_wmi_ref(n) if !$wmi_refs[n].used?() $wmi_refs.delete(n) return true end return false end |
.get_wmi_refs_name ⇒ Object
return a table of all wmirefs name
91 92 93 94 95 96 97 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 91 def WMIRef::get_wmi_refs_name() name_t=[] $wmi_refs.each_key {|name| name_t.push name } return name_t end |
.read_db_wmiref ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 60 def WMIRef::read_db_wmiref() if defined?($db) && ($db !=nil) db_select_all_prp(TABLENAME).execute do |rs| rs.each do |name, description, value| add_wmi_ref(name,description,value) end end end end |
.read_wmiref_conf_file(fic = WMIREFS_CONF_FILE) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 70 def WMIRef::read_wmiref_conf_file(fic=WMIREFS_CONF_FILE) field_separator='~' if FileTest.exist?(fic) fic = File.new(fic,'r') lign=fic.gets while lign lign_t = lign.split(field_separator) if lign_t.size() == 3 add_wmi_ref(lign_t[0],lign_t[1],lign_t[2].chomp()) end lign=fic.gets end fic.close else puts "wmirefs conf file not found" end end |
.wmi_ref_exist?(name) ⇒ Boolean
check if a given wmi ref name is defined
102 103 104 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 102 def WMIRef::wmi_ref_exist?(name) return $wmi_refs[name] != nil end |
.wmi_ref_nb_entry ⇒ Object
return number of wmi ref
109 110 111 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 109 def WMIRef::wmi_ref_nb_entry() return $wmi_refs.size end |
.write_db_wmiref ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 33 def WMIRef::write_db_wmiref() if defined?($db) && ($db !=nil) $db.transaction ps=db_delete_all_prp(TABLENAME) if ps ps.execute() stmt=db_insert_ref_prp(TABLENAME) $wmi_refs.each_value do |wmi_ref| stmt.execute(wmi_ref.name, wmi_ref.description, wmi_ref.value) end $db.commit else $db.rollback end end end |
.write_wmiref_conf_file(fic_name = WMIREFS_CONF_FILE) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 50 def WMIRef::write_wmiref_conf_file(fic_name=WMIREFS_CONF_FILE) field_separator='~' fic=Tempfile.new(File.basename(fic_name)) $wmi_refs.each_value do |wmi_ref| fic.puts "#{wmi_ref.name}#{field_separator}#{wmi_ref.description}#{field_separator}#{wmi_ref.value}" end fic.close() FileUtils.move(fic.path, fic_name) end |
Instance Method Details
#add_use ⇒ Object
124 125 126 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 124 def add_use() @nb_use+=1 end |
#del_use ⇒ Object
128 129 130 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 128 def del_use() @nb_use-=1 end |
#to_str ⇒ Object
136 137 138 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 136 def to_str() print "WMIRef: ", @name, " ", @description, " ", @value end |
#used? ⇒ Boolean
132 133 134 |
# File 'lib/monitor/client/wmi/wmi_ref.rb', line 132 def used?() return @nb_use>0 end |