Class: Cwmp::Acs

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/cwmp/acs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAcs

Returns a new instance of Acs.



140
141
142
143
144
145
146
147
148
149
# File 'lib/cwmp/acs.rb', line 140

def initialize
    ac = self

    # @handler = Handler.new
    @app = HttpRouter.new do
        # add('/api').to(SocketApp.new)
        add('/acs').to(Handler.new(ac))
    end
    @cpes = {}
end

Instance Attribute Details

#cpesObject

Returns the value of attribute cpes.



138
139
140
# File 'lib/cwmp/acs.rb', line 138

def cpes
  @cpes
end

Instance Method Details

#start(port) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/cwmp/acs.rb', line 213

def start port
    trap("SIGINT") { puts "Bye"; exit! }
    @port = port
    puts "ACS #{Cwmp::VERSION} by Luca Cervasio <[email protected]>"
    puts "Daemon running on http://localhost:#{@port}/acs"

    Thread.new do
        start_cli
    end

    Thin::Logging.silent = true
    Rack::Handler::Thin.run @app, :Port => @port

end

#start_cliObject



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/cwmp/acs.rb', line 151

def start_cli
    list = [
        'GetParameterValues', 'SetParameterValues', 'Reboot', 'FactoryReset', 'Download', 'AddObject', 'DeleteObject',
        'help', 'list', 'quit', "waitMessage"
    ].sort

    comp = proc { |s| list.grep(/^#{Regexp.escape(s)}/) }

    ::Readline.completion_append_character = " "
    ::Readline.completion_proc = comp

    while line = ::Readline.readline('> ', true)
        case line
            when "quit", "exit"
                puts "Bye"
                exit(0)
            when "help"
                puts "help not available"
            when "list games"
                puts ["FALKEN'S MAZE", "BLACK JACK", "GIN RUMMY", "HEARTS", "BRIDGE", "CHECKERS", "CHESS", "POKER", "FIGHTER COMBAT", "GUERRILLA ENGAGEMENT", "DESERT WARFARE" "AIR-TO-GROUND ACTIONS", "THEATERWIDE TACTICAL WARFARE", "THEATERWIDE BIOTOXIC AND CHEMICAL WARFARE", "GLOBAL THERMONUCLEAR WAR"].join "\n"
            when "help games"
                puts "Games refers to models, simulations and games which have strategic applications"
            when "list"
                p @cpes
            when /send (\w+) (\w+) (.+)/
                message_type = $1
                serial = $2
                args = $3.split(" ")

                # allowed_messages = ["GetParameterValues", "GetParameterNames", "SetParameterValues", "AddObject", "DeleteObject", "Reboot", "FactoryReset"]
                # if !allowed_messages.include? message_type
                #     puts "cmd #{message_type} unknown"
                #     next
                # end

                cpe = @cpes[serial]
                if !cpe
                    puts "cpe #{serial} unknown"
                    next
                end

                mess = Object.const_get("Cwmp").const_get("Message").send(message_type, args)
                cpe.queue << Cwmp::Request.new(mess) do |resp|
                    puts "arrived #{resp}"
                end
                cpe.do_connection_request
            when "run"
                begin
                    require './examples/api_usage'
                rescue LoadError
                    puts "file not found"
                rescue SyntaxError => e
                    puts "file contains syntax errors: #{e.message}"
                rescue Exception => e
                    puts "runtime error: #{e.message}"
                end
            else
                puts "unknown command <#{line}>" if line != ""
        end
    end
end

#start_session(serial, &block) ⇒ Object



228
229
230
# File 'lib/cwmp/acs.rb', line 228

def start_session(serial, &block)

end