Commit 36da01d0 authored by Steffen Michels's avatar Steffen Michels

- replaced showRPCWaitMessage by more general wait monitor-task

- made google maps reverse geocoding & ambulance examples work again with new RPC task

git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/trunk@1418 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent 3e87cf57
......@@ -27,7 +27,7 @@ import RPCExamples
//Crisis response examples
import AmbulanceDispatch
//import AmbulanceDispatchMap
import AmbulanceDispatchMap
//Change examples
import SimpleChanges
......@@ -70,7 +70,7 @@ where
, exceptionHandlingExample
, changeHandlingExample
, ambulanceDispatchExamples
//, ambulanceDispatchMapExamples
, ambulanceDispatchMapExamples
, changeExamples
, [ formEditor
, flowEditor
......
......@@ -3,7 +3,7 @@ implementation module AmbulanceDispatchMap
import iTasks
import GoogleMaps
import google_maps_services
import Base64
import Text
derive class iTask Incident, IncidentType
derive bimap (,), Maybe
......@@ -38,18 +38,15 @@ specifiyIncidents :: GoogleMap -> Task [Incident]
specifiyIncidents map = sequence "Specify individual incident details" [ (addressLookup m) >>= \addr -> (specifyIncident addr m) \\ m <- (reverse map.GoogleMap.markers) ]
addressLookup :: GoogleMapMarker -> Task String
addressLookup marker
# {lat,lng} = marker.position
= showStickyMessage ("Address lookup","Address is being retrieved for coordinates: ("+++toString lat+++", "+++toString lng+++")") Void
||- reverse_geocoding (toString lat+++","+++toString lng) "json" False GOOGLE_API_KEY parseJSON
addressLookup marker =
reverse_geocoding (toString lat+++","+++toString lng) "json" False GOOGLE_API_KEY parseJSON
>>= wait ("Address lookup","Address is being retrieved for coordinates: ("+++toString lat+++", "+++toString lng+++")") True
where
parseJSON info
= case fromString (base64Decode info) of
(obj =:(JSONObject f))
= case jsonQuery "Placemark/1/address" obj of
(Just addr) = addr
_ = "Address Unknown"
_ = "Address Unknown"
{lat,lng} = marker.position
parseJSON info = case jsonQuery "Placemark/0/address" (fromString info) of
(Just addr) = replaceSubString ", " "\n" addr
_ = "Address Unknown"
specifyIncident :: String GoogleMapMarker -> Task Incident
specifyIncident addr marker
......@@ -64,10 +61,9 @@ specifyIncident addr marker
}
= showStickyMessageAbout ("Location","Incident location:") smap ||- updateInformation ("Details","Specify incident details") incident
//====
showSources :: Task Void
showSources
= importDocument "Crisis Response\\AmbulanceDispatchMap.icl" >>=
\icl -> importDocument "Crisis Response\\AmbulanceDispatchMap.dcl" >>=
\dcl -> showStickyMessageAbout ("Sources","View the source code of this example") [icl,dcl] >>| stop
\ No newline at end of file
\dcl -> showStickyMessageAbout ("Sources","View the source code of this example") [icl,dcl] >>| stop
......@@ -2,5 +2,5 @@ definition module google_maps_services
import iTasks
reverse_geocoding :: String String Bool String (String -> String) -> Task String
reverse_geocoding :: !String !String !Bool !String !(String -> a) -> Task (ReadOnlyShared (Maybe a)) | iTask a
implementation module google_maps_services
import JSON
import RPC
import TSt
reverse_geocoding :: String String Bool String (String -> String) -> Task String
reverse_geocoding q output sensor api_key parsefun = mkRpcTask "Reverse Geocoding"
{ RPCExecute
| taskId = ""
, interface = { RPCInterface | protocol = HTTP GET, type = JSONRPC }
, operation = { RPCOperation | name = "Reverse Geocoding", parameters = [{ RPCParam | name = "q", type = RPCString }, { RPCParam | name = "output", type = RPCString }, { RPCParam | name = "sensor", type = RPCBool }, { RPCParam | name = "api_key", type = RPCString }], location = "http://maps.google.com/maps/geo", callType = RequestResponse, returnType = "String" }
, paramValues = [{ RPCParamValue | name="q", serializedValue = toString q},{ RPCParamValue | name="output", serializedValue = toString output},{ RPCParamValue | name="sensor", serializedValue = toString sensor},{ RPCParamValue | name="api_key", serializedValue = toString api_key}]
, status = ""
} parsefun
import RPCTasks
reverse_geocoding :: !String !String !Bool !String !(String -> a) -> Task (ReadOnlyShared (Maybe a)) | iTask a
reverse_geocoding q output sensor api_key parsefun = callRPCHTTP GET url args parsefun
where
url = "http://maps.google.com/maps/geo"
args = [ ("q",q)
, ("output",output)
, ("sensor",toString sensor)
, ("api_key",api_key)
]
......@@ -10,8 +10,8 @@ GOOGLE_API = "http://www.google.com/ig/api"
weatherExample :: Task Void
weatherExample =
try ( callRPCHTTP GET GOOGLE_API [("weather", "Nijmegen, Netherlands")]
>>= showRPCWaitMessage "Waiting for weather service"
try ( callRPCHTTP GET GOOGLE_API [("weather", "Nijmegen, Netherlands")] id
>>= wait "Waiting for weather service" True
>>= \weather -> showMessageAbout ("Weather", "Weather forecast is:") weather >>| stop
)
(\(RPCException message) -> showMessage ("RPC call failed", message) Void)
......@@ -7,7 +7,7 @@ from Shared import :: Shared
from InteractiveTasks import :: TaskAction, :: ActionEvent, :: AutoActionEvents, :: Verified
/**
* Monitor a shared state using a functional view.
* Monitors a shared state using a functional view.
* A predicate determines when to continue.
*
* @param A description of the task to display to the user
......@@ -20,7 +20,7 @@ from InteractiveTasks import :: TaskAction, :: ActionEvent, :: AutoActionEvents,
monitor :: !d !(m -> v) !(m -> Bool) !Bool !(Shared m w) -> Task m | descr d & iTask m & iTask v
/**
* Monitor a shared state using a functional view.
* Monitors a shared state using a functional view.
* A function generating automatically triggered action events and a list of actions can be provided.
*
* @param A description of the task to display to the user
......@@ -31,3 +31,13 @@ monitor :: !d !(m -> v) !(m -> Bool) !Bool !(Shared m w) -> Task m | descr d &
* @return The last value of the monitored state + the generated action event
*/
monitorA :: !d !(m -> v) ![TaskAction m] !(AutoActionEvents m) !(Shared m w) -> Task (!ActionEvent,!Maybe m) | descr d & iTask m & iTask v
/**
* Waits until a shared Maybe-state contains a value.
*
* @param A description of the task to display to the user
* @param A flag indicating if to finish the task automatically if condition is true or let the user press a continue-button
* @param A reference to the shared state
* @return The last value of the monitored state
*/
wait :: !d !Bool !(Shared (Maybe m) w) -> Task m | descr d & iTask m
......@@ -12,6 +12,10 @@ monitorA :: !d !(m -> v) ![TaskAction m] !(AutoActionEvents m) !(Shared m w) ->
monitorA d view actions autoEvents shared
= mkInteractiveTask d Monitor (makeMonitorTaskA shared view actions autoEvents)
wait :: !d !Bool !(Shared (Maybe m) w) -> Task m | descr d & iTask m
wait d autoContinue shared
= mapTask fromJust (mkInteractiveTask d Monitor (makeMonitorTask shared (const (Hidden Void)) isJust autoContinue))
makeMonitorTask :: !(Shared m w) !(m -> v) !(m -> Bool) !Bool -> TaskFunctions m | iTask m & iTask v
makeMonitorTask shared view pred autoContinue
= mapTaskFunctions (fromJust o snd) (makeMonitorTaskA shared view actions autoEvents)
......
......@@ -10,6 +10,4 @@ import JSON
::HTTPMethod = GET | POST
callRPCHTTP :: !HTTPMethod !String ![(String,String)] -> Task (ReadOnlyShared (Maybe String))
showRPCWaitMessage :: !message (ReadOnlyShared (Maybe a)) -> Task a | iTask message & iTask a
\ No newline at end of file
callRPCHTTP :: !HTTPMethod !String ![(String,String)] !(String -> a) -> Task (ReadOnlyShared (Maybe a)) | iTask a
......@@ -22,15 +22,15 @@ import TSt
from CoreCombinators import >>=
from CommonCombinators import transform
callRPCHTTP :: !HTTPMethod !String ![(String,String)] -> Task (ReadOnlyShared (Maybe String))
callRPCHTTP method url params
callRPCHTTP :: !HTTPMethod !String ![(String,String)] !(String -> a) -> Task (ReadOnlyShared (Maybe a)) | iTask a
callRPCHTTP method url params transformResult
# options = case method of
GET = "--get"
POST = ""
# args = urlEncodePairs params
= callRPC options url args id
= callRPC options url args transformResult
callRPC :: !String !String !String (String -> a) -> Task (ReadOnlyShared (Maybe a))
callRPC :: !String !String !String !(String -> a) -> Task (ReadOnlyShared (Maybe a))
callRPC options url args transformResult = mkInstantTask ("Call RPC","Calls a method from a remote server") callRPC`
where
callRPC` tst=:{taskNr}
......@@ -66,11 +66,6 @@ where
| isError out = (Error (toString (fromError out)), {iworld & world = world})
= (Ok (Just (transformResult (fromOk out))), {iworld & world = world})
showRPCWaitMessage :: !message (ReadOnlyShared (Maybe a)) -> Task a | iTask message & iTask a
showRPCWaitMessage msg shared =
monitor ("Call RPC", "Running method from remote server") (const msg) isJust True shared
>>= transform fromJust
getITasksPath :: *World -> (String, *World)
getITasksPath world
# (path, world) = getCurrentDirectory world
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment