Class: AgentXmpp::BaseController
- Defined in:
- lib/agent_xmpp/client/controller.rb
Overview
Direct Known Subclasses
Class Attribute Summary collapse
-
.before_filters ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.commands_list ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.commands_list_mutex ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.routes ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#params_list ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#pipe ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#route ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#submits ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
Class Method Summary collapse
-
.add_before_filter(msg_type, nodes) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.add_command_to_list(session_id, controller) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.before(args = nil, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.chat(opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.command(node, opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.command_nodes(jid = nil) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.event(jid, node, opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.event_domains ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.include_module(mod) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.remove_command_from_list(session_id) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.route(msg_type, nroute) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.subscriptions(service) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
Instance Method Summary collapse
-
#apply_before_filters(msg_type, node = nil) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#command_completed ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#command_request(args, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#delegate_methods ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#delegate_to(methods) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#error(err, *args) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#flush_messages ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#initialize(pipe, params) ⇒ BaseController
constructor
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#invoke_chat ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#invoke_command ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#invoke_command_next ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#invoke_event ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#messages ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#next(params) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#on(action, opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#on_submit ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#xmpp_msg(msg) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
Constructor Details
#initialize(pipe, params) ⇒ BaseController
.….….….….….….….….….….….….….….….….….….….….….….….….….….
101 102 103 104 |
# File 'lib/agent_xmpp/client/controller.rb', line 101 def initialize(pipe, params) @params, @pipe = params, pipe @params_list, @submits = [params], [] end |
Class Attribute Details
.before_filters ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
17 18 19 |
# File 'lib/agent_xmpp/client/controller.rb', line 17 def before_filters @before_filters end |
.commands_list ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
17 18 19 |
# File 'lib/agent_xmpp/client/controller.rb', line 17 def commands_list @commands_list end |
.commands_list_mutex ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
17 18 19 |
# File 'lib/agent_xmpp/client/controller.rb', line 17 def commands_list_mutex @commands_list_mutex end |
.routes ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
17 18 19 |
# File 'lib/agent_xmpp/client/controller.rb', line 17 def routes @routes end |
Instance Attribute Details
#params ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
98 99 100 |
# File 'lib/agent_xmpp/client/controller.rb', line 98 def params @params end |
#params_list ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
98 99 100 |
# File 'lib/agent_xmpp/client/controller.rb', line 98 def params_list @params_list end |
#pipe ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
98 99 100 |
# File 'lib/agent_xmpp/client/controller.rb', line 98 def pipe @pipe end |
#route ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
98 99 100 |
# File 'lib/agent_xmpp/client/controller.rb', line 98 def route @route end |
#submits ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
98 99 100 |
# File 'lib/agent_xmpp/client/controller.rb', line 98 def submits @submits end |
Class Method Details
.add_before_filter(msg_type, nodes) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
56 57 58 |
# File 'lib/agent_xmpp/client/controller.rb', line 56 def add_before_filter(msg_type, nodes) (before_filters[msg_type] ||= []).push(nodes).last end |
.add_command_to_list(session_id, controller) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
81 82 83 84 85 |
# File 'lib/agent_xmpp/client/controller.rb', line 81 def add_command_to_list(session_id, controller) commands_list_mutex.synchronize do commands_list[session_id] = {:controller=>controller, :created_at=>Time.now} end end |
.before(args = nil, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
38 39 40 41 |
# File 'lib/agent_xmpp/client/controller.rb', line 38 def before(args=nil, &blk) args = {:command => :all, :event => :all, :chat => :all} if args.nil? or args.eql?(:all) args.each {|(msg_type, nodes)| add_before_filter(msg_type, {:nodes => nodes, :blk => blk})} end |
.chat(opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
33 34 35 |
# File 'lib/agent_xmpp/client/controller.rb', line 33 def chat(opts = {}, &blk) route(:chat, {:opts => opts, :blk => blk}) end |
.command(node, opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….…. application interface .….….….….….….….….….….….….….….….….….….….….….….….….….….
22 23 24 |
# File 'lib/agent_xmpp/client/controller.rb', line 22 def command(node, opts = {}, &blk) route(:command, {:node => node, :opts => opts, :blk => blk}) end |
.command_nodes(jid = nil) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
61 62 63 64 65 66 67 68 |
# File 'lib/agent_xmpp/client/controller.rb', line 61 def command_nodes(jid=nil) (routes[:command] ||= []).inject([]) do |nodes, route| if jid and not AgentXmpp.is_account_jid?(jid) groups, access = Contact.find_by_jid(jid)[:groups], [route[:opts][:access] || []].flatten (access.empty? or access.any?{|a| groups.include?(a)}) ? nodes << route[:node] : nodes else; nodes << route[:node]; end end end |
.event(jid, node, opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
27 28 29 30 |
# File 'lib/agent_xmpp/client/controller.rb', line 27 def event(jid, node, opts = {}, &blk) j = Xmpp::Jid.new(jid) route(:event, {:node => "/home/#{j.domain}/#{j.node}/#{node}", :domain => j.domain, :opts => opts, :blk => blk}) end |
.event_domains ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
76 77 78 |
# File 'lib/agent_xmpp/client/controller.rb', line 76 def event_domains (routes[:event] ||= []).map{|r| r[:domain]}.uniq end |
.include_module(mod) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
44 45 46 |
# File 'lib/agent_xmpp/client/controller.rb', line 44 def include_module(mod) include(mod) end |
.remove_command_from_list(session_id) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
88 89 90 91 92 |
# File 'lib/agent_xmpp/client/controller.rb', line 88 def remove_command_from_list(session_id) if commands_list[session_id] commands_list_mutex.synchronize{commands_list.delete(session_id)} end end |
.route(msg_type, nroute) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….…. managment .….….….….….….….….….….….….….….….….….….….….….….….….….….
51 52 53 |
# File 'lib/agent_xmpp/client/controller.rb', line 51 def route(msg_type, nroute) (routes[msg_type] ||= []).push(nroute).last end |
.subscriptions(service) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
71 72 73 |
# File 'lib/agent_xmpp/client/controller.rb', line 71 def subscriptions(service) (routes[:event] ||= []).inject([]){|s,r| /#{r[:domain]}/.match(service) ? s << r[:node] : s} end |
Instance Method Details
#apply_before_filters(msg_type, node = nil) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….…. filters .….….….….….….….….….….….….….….….….….….….….….….….….….….
368 369 370 371 372 373 374 375 376 |
# File 'lib/agent_xmpp/client/controller.rb', line 368 def apply_before_filters(msg_type, node=nil) (BaseController.before_filters[msg_type] || []).inject([]) do |fs, f| nodes = [f[:nodes]].flatten (nodes.include?(node) or nodes.include?(:all)) ? fs << f : fs end.inject(true) do |r,f| (:filter, &f[:blk]) r and filter end end |
#command_completed ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
215 216 217 218 |
# File 'lib/agent_xmpp/client/controller.rb', line 215 def command_completed Xmpp::IqCommand.send_command(:to=>params[:from], :node=>params[:node], :iq_type=>:result, :status=>:completed, :id => params[:id], :sessionid => params[:sessionid]) end |
#command_request(args, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
221 222 223 224 |
# File 'lib/agent_xmpp/client/controller.rb', line 221 def command_request(args, &blk) raise ArgmentError ':to and :node are required' unless args[:to] and args[:node] Xmpp::IqCommand.send_command(:to=>args[:to], :node=>args[:node], :iq_type=>:set, :action=>:execute, :payload=>args[:payload], &blk) end |
#delegate_methods ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
174 175 176 |
# File 'lib/agent_xmpp/client/controller.rb', line 174 def delegate_methods @delegate_methods ||= AgentXmpp::Delegate.new end |
#delegate_to(methods) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
210 211 212 |
# File 'lib/agent_xmpp/client/controller.rb', line 210 def delegate_to(methods) delegate_methods.add_delegate_methods(methods); delegate_methods end |
#error(err, *args) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….…. application interface .….….….….….….….….….….….….….….….….….….….….….….….….……
191 192 193 |
# File 'lib/agent_xmpp/client/controller.rb', line 191 def error(err, *args) AgentXmpp::Error.new(err, *args) end |
#flush_messages ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
184 185 186 |
# File 'lib/agent_xmpp/client/controller.rb', line 184 def pipe.send_resp(); .clear end |
#invoke_chat ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/agent_xmpp/client/controller.rb', line 158 def invoke_chat @route = chat_route unless route.nil? (:request_handler, &route[:blk]) else (:request_handler) do "#{AgentXmpp::AGENT_XMPP_NAME} #{AgentXmpp::VERSION}, #{AgentXmpp::OS_VERSION}" end end (:request_callback) do |result| add_payload_to_container(result) if result.kind_of?(String) end process_request end |
#invoke_command ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….…. internal interface .….….….….….….….….….….….….….….….….….….….….….….….….……
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/agent_xmpp/client/controller.rb', line 116 def invoke_command params[:sessionid] ||= Xmpp::IdGenerator.generate_id invoke_command_on_route do (:request, &route[:blk]) (:request_handler) do run_command(request) end (:request_callback) do |*resp| resp = resp.length.eql?(1) ? resp.first : resp add_payload_to_container(resp) end process_request end end |
#invoke_command_next ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/agent_xmpp/client/controller.rb', line 132 def invoke_command_next invoke_command_on_route do (:request_handler) do if params[:x_data_type].eql?(:submit) on_submit end end process_request end end |
#invoke_event ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/agent_xmpp/client/controller.rb', line 144 def invoke_event @route = get_route(:event) unless route.nil? (:request, &route[:blk]) (:request_handler) do request; delegate_methods.delegate(pipe, self); end process_request else AgentXmpp.logger.error "ROUTING ERROR: no route for {:node => '#{params[:node]}'}." end end |
#messages ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
179 180 181 |
# File 'lib/agent_xmpp/client/controller.rb', line 179 def @messages ||= [] end |
#next(params) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
107 108 109 110 111 |
# File 'lib/agent_xmpp/client/controller.rb', line 107 def next(params) @params = params @params_list << params self end |
#on(action, opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
196 197 198 199 200 201 202 |
# File 'lib/agent_xmpp/client/controller.rb', line 196 def on(action, opts= {}, &blk) if action.eql?(:submit) @submits << {:opts=>opts, :blk=>blk} else (("on_"+action.to_s).to_sym, &blk) end end |
#on_submit ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….…. managment .….….….….….….….….….….….….….….….….….….….….….….….….……
229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/agent_xmpp/client/controller.rb', line 229 def on_submit unless(sub = submits.shift).nil? update_command_list blk, guard = sub[:blk], sub[:opts][:guard] call_blk = lambda{|| blk.arity.eql?(1) ? blk.call(Xmpp::XData.new('form')) : blk.call} result = if guard.nil? call_blk[] else (guard.arity.eql?(1) ? guard.call(self) : guard.call) ? call_blk[] : on_submit end result.nil? ? on_submit : result end end |
#xmpp_msg(msg) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
205 206 207 |
# File 'lib/agent_xmpp/client/controller.rb', line 205 def xmpp_msg(msg) << msg end |