server/handlerwrappers/default.rb in cpee-1.3.175 vs server/handlerwrappers/default.rb in cpee-1.3.176
- old
+ new
@@ -21,12 +21,13 @@
@handler_passthrough = nil
@handler_returnValue = nil
end # }}}
def activity_handle(passthrough, parameters) # {{{
- @controller.notify("running/activity_calling", :instance => @controller.instance, :activity => @handler_position, :passthrough => passthrough, :endpoint => @handler_endpoint, :parameters => parameters)
+ @controller.notify("activity/calling", :instance => @controller.instance, :activity => @handler_position, :passthrough => passthrough, :endpoint => @handler_endpoint, :parameters => parameters)
+ result = []
if passthrough.nil?
params = []
callback = Digest::MD5.hexdigest(Kernel::rand().to_s)
(parameters[:parameters] || {}).each do |k,v|
if v.is_a?(Struct)
@@ -51,25 +52,21 @@
type = parameters[:method] || 'post'
client = Riddl::Client.new(@handler_endpoint)
status, result, headers = client.request type => params
raise "Could not #{parameters[:method] || 'post'} #{@handler_endpoint}" if status != 200
- result = simplify_result(result)
if headers["CPEE_CALLBACK"] && headers["CPEE_CALLBACK"] == 'true'
@controller.callbacks[callback] = CPEE::Callback.new("callback activity: #{@handler_position}",self,:callback,nil,nil,:http)
@handler_passthrough = callback
- return
+ else
+ callback result
end
else
@controller.callbacks[passthrough] = CPEE::Callback.new("callback activity: #{@handler_position}",self,:callback,nil,nil,:http)
@handler_passthrough = passthrough
- return
end
-
- @handler_returnValue = result
- @handler_continue.continue
end # }}}
def activity_result_status # {{{
WEEL::Status.new(1, "everything okay")
end # }}}
@@ -90,55 +87,55 @@
def activity_no_longer_necessary # {{{
true
end # }}}
def inform_activity_done # {{{
- @controller.notify("running/activity_done", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
+ @controller.notify("activity/done", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
end # }}}
def inform_activity_manipulate # {{{
- @controller.notify("running/activity_manipulating", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
+ @controller.notify("activity/manipulating", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
end # }}}
def inform_activity_failed(err) # {{{
puts err.message
puts err.backtrace
- @controller.notify("running/activity_failed", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :message => err.message, :line => err.backtrace[0].match(/(.*?):(\d+):/)[2], :where => err.backtrace[0].match(/(.*?):(\d+):/)[1])
+ @controller.notify("activity/failed", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :message => err.message, :line => err.backtrace[0].match(/(.*?):(\d+):/)[2], :where => err.backtrace[0].match(/(.*?):(\d+):/)[1])
end # }}}
def inform_syntax_error(err,code)# {{{
- @controller.notify("properties/description/error", :instance => @controller.instance, :message => err.message)
+ @controller.notify("description/error", :instance => @controller.instance, :message => err.message)
end# }}}
def inform_manipulate_change(status,changed_dataelements,changed_endpoints,dataelements,endpoints) # {{{
unless status.nil?
@controller.serialize_status!
- @controller.notify("properties/status/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :id => status.id, :message => status.message)
+ @controller.notify("status/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :id => status.id, :message => status.message)
end
- unless dataelements.nil?
+ unless changed_dataelements.nil?
@controller.serialize_dataelements!
- @controller.notify("properties/dataelements/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :changed => changed_dataelements)
+ @controller.notify("dataelements/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :changed => changed_dataelements)
end
- unless endpoints.nil?
+ unless changed_endpoints.nil?
@controller.serialize_endpoints!
- @controller.notify("properties/endpoints/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :changed => changed_endpoints)
+ @controller.notify("endpoints/change", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position, :changed => changed_endpoints)
end
end # }}}
def inform_position_change(ipc={}) # {{{
@controller.serialize_positions!
ipc[:instance] = @controller.instance
- @controller.notify("properties/position/change", ipc)
+ @controller.notify("position/change", ipc)
end # }}}
def inform_state_change(newstate) # {{{
if @controller
@controller.serialize_state!
- @controller.notify("properties/state/change", :instance => @controller.instance, :state => newstate)
+ @controller.notify("state/change", :instance => @controller.instance, :state => newstate)
end
end # }}}
def vote_sync_after # {{{
- @controller.call_vote("running/syncing_after", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
+ @controller.call_vote("activity/syncing_after", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
end # }}}
def vote_sync_before(parameters=nil) # {{{
- @controller.call_vote("running/syncing_before", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
+ @controller.call_vote("activity/syncing_before", :endpoint => @handler_endpoint, :instance => @controller.instance, :activity => @handler_position)
end # }}}
def simplify_result(result)
if result.length == 1
if result[0].is_a? Riddl::Parameter::Simple
@@ -156,15 +153,23 @@
end
end
result
end
- def callback(result)
+ def callback(result=nil,options={})
result = simplify_result(result)
- @handler_returnValue = result
- @controller.callbacks.delete(@handler_passthrough)
- @handler_passthrough = nil
- @handler_continue.continue
+ if options['CPEE_UPDATE']
+ @handler_returnValue = result
+ if options['CPEE_UPDATE_STATUS']
+ @controller.notify("activity/status", :instance => @controller.instance, :activity => @handler_position, :endpoint => @handler_endpoint, :status => options['CPEE_UPDATE_STATUS'])
+ end
+ @handler_continue.continue WEEL::Signal::Again
+ else
+ @controller.callbacks.delete(@handler_passthrough)
+ @handler_returnValue = result
+ @handler_passthrough = nil
+ @handler_continue.continue
+ end
end
def simulate(type,nesting,tid,parent,parameters={}) #{{{
pp "#{type} - #{nesting} - #{tid} - #{parent} - #{parameters.inspect}"