Class: ConcertoConfigServer

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/bandshell/application/app.rb

Constant Summary collapse

CONNECTION_METHODS =

push these over to netconfig.rb? Our list of available physical-layer connection methods…

[ 
  Bandshell::WiredConnection, 
  Bandshell::WirelessConnection 
]
ADDRESSING_METHODS =

… and available layer-3 addressing methods.

[ 
  Bandshell::DHCPAddressing, 
  Bandshell::StaticAddressing 
]
LOCALHOSTS =

Hosts we allow to access configuration without authenticating.

[ 
  IPAddress.parse("127.0.0.1"),    # ipv4 
  IPAddress.parse("::ffff:127.0.0.1"),  # ipv6-mapped ipv4
  IPAddress.parse("::1")      # ipv6
]
@@player_data_updated =

TODO: Refactor player settings management into a separate class

Time.new(0)
@@screen_on_off =

default to always-on

[{:action=>"on"}]

Instance Method Summary collapse

Instance Method Details

#do_assign(params, instance) ⇒ Object

Set the arguments on an instance of a given configuration class. This uses the safe_assign method that should be present in all configuration classes to determine which values are allowed to be passed via form fields (i.e. which ones are subject to validation)



314
315
316
317
318
319
320
321
322
# File 'lib/bandshell/application/app.rb', line 314

def do_assign(params, instance)
  safe = instance.safe_assign

  params.each do |param, value|
    if safe.include? param.intern
      instance.send((param + '=').intern, value)
    end
  end
end

#extract_class_args(params, target_class) ⇒ Object

Extract arguments from a set of form data that are intended to go to a specific network configuration class. These fields have names of the form ‘ClassName/field_name’; this function returns a hash in the form { ‘field_name’ => ‘value } containing the configuration arguments.



298
299
300
301
302
303
304
305
306
307
308
# File 'lib/bandshell/application/app.rb', line 298

def extract_class_args(params, target_class)
  result = { }
  params.each do |key, value|
    klass, arg = key.split('/', 2)
    if klass == target_class
      result[arg] = value
    end
  end

  result
end

#parse_screen_on_off(data) ⇒ Object



432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/bandshell/application/app.rb', line 432

def parse_screen_on_off(data)
  begin
    rules = JSON.parse(data)
    if rules.is_a? Array
      return rules
    else
      puts "parse_screen_on_off: Recieved something other than an aray."
      return nil
    end
  rescue
    puts "parse_screen_on_off: invalid JSON recieved"
    return nil
  end
end

#pick_class(name, list) ⇒ Object

Given the name of a class, pick a class out of a list of allowed classes. This is used for parsing the form input for network configuration.



290
291
292
# File 'lib/bandshell/application/app.rb', line 290

def pick_class(name, list)
  list.find { |klass| klass.basename == name }
end

#screen_scheduled_on?Boolean

Returns true if the screen should be turned on right now, according to the latest data recieved from concerto-hardware.

Returns:

  • (Boolean)


449
450
451
# File 'lib/bandshell/application/app.rb', line 449

def screen_scheduled_on?
  raise 'screen_scheduled_on?: TODO'
end

#update_player_info(force = false) ⇒ Object

Fetches the latest player settings from Concerto if the current settings are too old or an update is forced (force=true). TODO: Store settings in BandshellConfig (and update whenever they have changed) so that configs are immediately available at boot.



410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/bandshell/application/app.rb', line 410

def update_player_info(force=false)
  # TODO: Configurable update interval
  if force or (@@player_data_updated < Time.now - 60*5)
    data = Bandshell::HardwareApi::get_player_info
    if data.nil?
      puts "update_player_info: Error: Recieved null data from get_player_info!"
      false
    else
      new_rules = parse_screen_on_off(data['screen_on_off'])
      if new_rules.nil?
        false
      else
        puts "update_player_info: Updating the rules!"
        @@screen_on_off = new_rules
        @@player_data_updated = Time.now
      end
    end
  else
    true
  end
end