Please disable Adblockers and enable JavaScript for domain CEWebS.cs.univie.ac.at! We have NO ADS, but they may interfere with some of our course material.

Name: server/server.rb 
1:
#!/usr/bin/ruby
2:
require 'rubygems'
3:
require 'pp'
4:
require 'fileutils'
5:
require 'riddl/server'
6:
require 'riddl/client'
7:
require 'riddl/utils/notifications_producer'
8:
require 'riddl/utils/properties'
9:
require 'riddl/utils/fileserve'
10:
require File.expand_path(File.dirname(__FILE__) + '/engine/implementation')
11:
 
12:
### construct and run server
13:
Riddl::Server.new(::File.dirname(__FILE__) + '/server.declaration.xml', :host => 'cpee.org', :port => 9399) do
14:
  accessible_description true
15:
  cross_site_xhr true
16:
 
17:
  @riddl_opts[:topics]                     ||= File.expand_path(File.dirname(__FILE__) + '/resources/topics.xml')
18:
  @riddl_opts[:properties_init]            ||= File.expand_path(File.dirname(__FILE__) + '/resources/properties.init')
19:
  @riddl_opts[:instances]                  ||= File.expand_path(File.dirname(__FILE__) + '/instances')
20:
  @riddl_opts[:properties_schema_active]   ||= File.expand_path(File.dirname(__FILE__) + '/resources/properties.schema.active')
21:
  @riddl_opts[:properties_schema_inactive] ||= File.expand_path(File.dirname(__FILE__) + '/resources/properties.schema.inactive')
22:
 
23:
  controller = {}
24:
  Dir[@riddl_opts[:instances] + '/*/properties.xml'].map{|e|::File::basename(::File::dirname(e))}.each do |id|
25:
    controller[id.to_i] = Controller.new(id,@riddl_opts)
26:
  end
27:
 
28:
  interface 'properties' do |r|
29:
    id = r[:h]['RIDDL_DECLARATION_PATH'].split('/')[1].to_i
30:
    use Riddl::Utils::Properties::implementation(controller[id].properties, PropertiesHandler.new(controller[id]), @riddl_opts[:mode]) if controller[id]
31:
  end
32:
 
33:
  interface 'notifications' do |r|
34:
    id = r[:h]['RIDDL_DECLARATION_PATH'].split('/')[1].to_i
35:
    p 'r'
36:
    use Riddl::Utils::Notifications::Producer::implementation(controller[id].notifications, NotificationsHandler.new(controller[id]), @riddl_opts[:mode]) if controller[id]
37:
  end
38:
 
39:
  interface 'main' do
40:
    begin
41:
    run Instances, controller if get '*'
42:
    run NewInstance, controller, @riddl_opts if post 'instance-name'
43:
    on resource do
44:
      run Info, controller if get
45:
      run DeleteInstance, controller if delete
46:
      on resource 'events' do
47:
        run Event, controller if post
48:
      end
49:
      on resource 'callbacks' do
50:
        run Callbacks, controller if get
51:
        on resource do
52:
          run ExCallback, controller if get || put || post || delete
53:
        end
54:
      end
55:
    end
56:
    on resource 'xsls' do
57:
      on resource do
58:
        run Riddl::Utils::FileServe, "xsls" if get
59:
      end
60:
    end
61:
    rescue => e
62:
      puts e
63:
      puts e.backtrace
64:
    end
65:
  end
66:
end.loop!