Class: OmfRcShm::App::Definition
- Inherits:
-
Object
- Object
- OmfRcShm::App::Definition
- Defined in:
- lib/omf_rc_shm/app/definition.rb
Overview
Application Definition used in experiment script
Instance Attribute Summary collapse
-
#name ⇒ Object
TODO: eventually this call would mirror all the properties of the App Proxy right now we just have name, binary_path, parameters.
-
#properties ⇒ Object
TODO: eventually this call would mirror all the properties of the App Proxy right now we just have name, binary_path, parameters.
Instance Method Summary collapse
- #define_measurement_point(mp) ⇒ Object
-
#define_parameter(params) ⇒ Object
Add new parameter(s) to this Application Definition.
-
#defMeasurement(name, &block) ⇒ Object
XXX: This should be provided by the omf-oml glue.
-
#defMetric(name, type, opts = {}) ⇒ Object
Define metrics to measure.
-
#defProperty(name = :mandatory, description = nil, parameter = nil, options = {}) ⇒ Object
Add a new parameter to this Application Definition.
-
#initialize(name) ⇒ Definition
constructor
A new instance of Definition.
- #method_missing(method_name, *args) ⇒ Object
- #path=(arg) ⇒ Object
- #shortDescription=(arg) ⇒ Object
Constructor Details
#initialize(name) ⇒ Definition
Returns a new instance of Definition.
15 16 17 18 |
# File 'lib/omf_rc_shm/app/definition.rb', line 15 def initialize(name) self.name = name self.properties = Hashie::Mash.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/omf_rc_shm/app/definition.rb', line 57 def method_missing(method_name, *args) k = method_name.to_sym return @properties[k] if @properties.key?(k) m = method_name.to_s.match(/(.*?)([=]?)$/) if m[2] == '=' @properties[m[1].to_sym] = args.first else super end end |
Instance Attribute Details
#name ⇒ Object
TODO: eventually this call would mirror all the properties of the App Proxy right now we just have name, binary_path, parameters
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/omf_rc_shm/app/definition.rb', line 8 class Definition # TODO: eventually this call would mirror all the properties of the App Proxy # right now we just have name, binary_path, parameters attr_accessor :name, :properties # @param [String] name name of the application to define def initialize(name) self.name = name self.properties = Hashie::Mash.new end # Add new parameter(s) to this Application Definition # # @param [Hash] params a hash with the parameters to add # def define_parameter(params) @properties[:parameters] = Hashie::Mash.new unless @properties.key?(:parameters) if params.kind_of? Hash @properties[:parameters].merge!(params) else error "Cannot define parameter for app '#{self.name}'! Parameter "+ "not passed as a Hash ('#{params.inspect}')" end end def define_measurement_point(mp) @properties[:oml] = Hashie::Mash.new unless @properties.key?(:oml) if mp.kind_of? Hash @properties[:oml][:available_mps] = Array.new unless @properties[:oml].key?(:available_mps) @properties[:oml][:available_mps] << mp else error "Cannot define Measurement Point for app '#{self.name}'! MP "+ "not passed as a Hash ('#{mp.inspect}')" end end warn_removed :version def path=(arg) @properties[:binary_path] = arg warn_deprecation :path=, :binary_path= end def shortDescription=(arg) @properties[:description] = arg warn_deprecation :shortDescription=, :description= end def method_missing(method_name, *args) k = method_name.to_sym return @properties[k] if @properties.key?(k) m = method_name.to_s.match(/(.*?)([=]?)$/) if m[2] == '=' @properties[m[1].to_sym] = args.first else super end end # The following are OEDL 5 methods # Add a new parameter to this Application Definition. # This method is for backward compatibility with previous OEDL 5. # # @param [String] name name of the property to define (mandatory) # @param [String] description description of this property; oml2-scaffold uses this for the help message (popt: descrip) # @param [String] parameter command-line parameter to introduce this property, including dashes if needed (can be nil) # @param [Hash] options list of options associated with this property # @option options [String] :type type of the property: :integer, :string and :boolean are supported; oml2-scaffold extends this with :int and :double (popt: argInfo) # @option options [Boolean] :dynamic true if the property can be changed at run-time # @option options [Fixnum] :order used to order properties when creating the command line # # The OML code-generation tool, oml2-scaffold extends the range of # options supported in the options hash to support generation of # popt(3) command line parsing code. As for the parameters, depending # on the number of dashes (two/one) in parameter, it is used as the # longName/shortName for popt(3), otherwise the former defaults to # name, and the latter defaults to either :mnemonic or nothing. # # @option options [String] :mnemonic one-letter mnemonic for the option (also returned by poptGetNextOpt as val) # @option options [String] :unit unit in which this property is expressed; oml2-scaffold uses this for the help message (popt: argDescrip) # @option options [String] :default default value if argument unspecified (optional; defaults to something sane for the :type) # @option options [String] :var_name name of the C variable for popt(3) to store the property value into (optional; popt: arg; defaults to name, after sanitisation) # # @see http://oml.mytestbed.net/doc/oml/latest/oml2-scaffold.1.html # @see http://linux.die.net/man/3/popt # def defProperty(name = :mandatory, description = nil, parameter = nil, = {}) opts = {:description => description, :cmd => parameter} # Map old OMF5 types to OMF6 [:type] = 'Numeric' if [:type] == :integer [:type] = 'String' if [:type] == :string [:type] = 'Boolean' if [:type] == :boolean opts = opts.merge() define_parameter(Hash[name,opts]) end # Define metrics to measure # # @param [String] name of the metric # @param [Symbol] type of the metric data. For all supporting metric data types, refers to http://oml.mytestbed.net/doc/oml/latest/oml2-scaffold.1.html#_mp_defmetric_name_type # @param [Hash] opts additional options # # @option opts [String] :unit unit of measure of the metric # @option opts [String] :description of the metric # @option opts [Float] :precision precision of the metric value # @option opts [Range] :range value range of the metric # # @example OEDL # app.defMeasurement("power") do |mp| # mp.defMetric('power', :double, :unit => "W", :precision => 0.1, :description => 'Power') # end def defMetric(name,type, opts = {}) # the third parameter used to be a description string opts = {:description => opts} if opts.class!=Hash @fields << {:field => name, :type => type}.merge(opts) end # XXX: This should be provided by the omf-oml glue. def defMeasurement(name,&block) mp = {:mp => name, :fields => []} @fields = [] # call the block with ourserlves to process its 'defMetric' statements block.call(self) if block @fields.each { |f| mp[:fields] << f } define_measurement_point(mp) end end |
#properties ⇒ Object
TODO: eventually this call would mirror all the properties of the App Proxy right now we just have name, binary_path, parameters
12 13 14 |
# File 'lib/omf_rc_shm/app/definition.rb', line 12 def properties @properties end |
Instance Method Details
#define_measurement_point(mp) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/omf_rc_shm/app/definition.rb', line 34 def define_measurement_point(mp) @properties[:oml] = Hashie::Mash.new unless @properties.key?(:oml) if mp.kind_of? Hash @properties[:oml][:available_mps] = Array.new unless @properties[:oml].key?(:available_mps) @properties[:oml][:available_mps] << mp else error "Cannot define Measurement Point for app '#{self.name}'! MP "+ "not passed as a Hash ('#{mp.inspect}')" end end |
#define_parameter(params) ⇒ Object
Add new parameter(s) to this Application Definition
24 25 26 27 28 29 30 31 32 |
# File 'lib/omf_rc_shm/app/definition.rb', line 24 def define_parameter(params) @properties[:parameters] = Hashie::Mash.new unless @properties.key?(:parameters) if params.kind_of? Hash @properties[:parameters].merge!(params) else error "Cannot define parameter for app '#{self.name}'! Parameter "+ "not passed as a Hash ('#{params.inspect}')" end end |
#defMeasurement(name, &block) ⇒ Object
XXX: This should be provided by the omf-oml glue.
128 129 130 131 132 133 134 135 |
# File 'lib/omf_rc_shm/app/definition.rb', line 128 def defMeasurement(name,&block) mp = {:mp => name, :fields => []} @fields = [] # call the block with ourserlves to process its 'defMetric' statements block.call(self) if block @fields.each { |f| mp[:fields] << f } define_measurement_point(mp) end |
#defMetric(name, type, opts = {}) ⇒ Object
Define metrics to measure
121 122 123 124 125 |
# File 'lib/omf_rc_shm/app/definition.rb', line 121 def defMetric(name,type, opts = {}) # the third parameter used to be a description string opts = {:description => opts} if opts.class!=Hash @fields << {:field => name, :type => type}.merge(opts) end |
#defProperty(name = :mandatory, description = nil, parameter = nil, options = {}) ⇒ Object
Add a new parameter to this Application Definition. This method is for backward compatibility with previous OEDL 5.
The OML code-generation tool, oml2-scaffold extends the range of options supported in the options hash to support generation of popt(3) command line parsing code. As for the parameters, depending on the number of dashes (two/one) in parameter, it is used as the longName/shortName for popt(3), otherwise the former defaults to name, and the latter defaults to either :mnemonic or nothing.
96 97 98 99 100 101 102 103 104 |
# File 'lib/omf_rc_shm/app/definition.rb', line 96 def defProperty(name = :mandatory, description = nil, parameter = nil, = {}) opts = {:description => description, :cmd => parameter} # Map old OMF5 types to OMF6 [:type] = 'Numeric' if [:type] == :integer [:type] = 'String' if [:type] == :string [:type] = 'Boolean' if [:type] == :boolean opts = opts.merge() define_parameter(Hash[name,opts]) end |
#path=(arg) ⇒ Object
47 48 49 50 |
# File 'lib/omf_rc_shm/app/definition.rb', line 47 def path=(arg) @properties[:binary_path] = arg warn_deprecation :path=, :binary_path= end |
#shortDescription=(arg) ⇒ Object
52 53 54 55 |
# File 'lib/omf_rc_shm/app/definition.rb', line 52 def shortDescription=(arg) @properties[:description] = arg warn_deprecation :shortDescription=, :description= end |