From: Mart Lubbers Date: Fri, 16 Jun 2017 17:33:20 +0000 (+0200) Subject: share details X-Git-Tag: hand-in~82 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=f51f8bb08edd8fb7cd0be5ba3955ad9e27cfdbe1;p=msc-thesis1617.git share details --- diff --git a/results.itasks.tex b/results.itasks.tex index 7a87936..a2200c7 100644 --- a/results.itasks.tex +++ b/results.itasks.tex @@ -50,7 +50,7 @@ Listing~\ref{lst:actualdev} shows the actual types for the device storage. Programmers wanting to access the entire \gls{SDS} use the \CI{deviceStoreNP}. Programmers wanting to access a single \gls{SDS} on a device can use the \CI{getRealShare} function which is a wrapper around the \CI{deviceStore} which -applies a parametric lens. +applies a parametric lens to the \gls{SDS}. \begin{lstlisting}[label={lst:actualdev},% caption={Real types for the device \gls{SDS}}] @@ -63,5 +63,48 @@ getRealShare :: MTaskDevice MTaskShare -> Shared BCValue \end{lstlisting} \subsection{Parametric Lens} -Therefore the main device store -\todo{Semantiek van shares, hoe ze in iTasks zijn, hoe typering} +The type of the parametric lens is \CI{Maybe (MTaskDevice, Int)} where the +\CI{Int} is the identifier of the \gls{SDS}. The \gls{iTasks} way of applying +lenses is through the \CI{sdsFocus} function and through the \CI{sdsLens} +functions. \CI{sdsFocus} allows the programmer to fix the parameter. +\CI{sdsLens} is basically a \CI{mapReadWrite} that has access to the parameter. +This allows the programmer to create filters and lenses. Both of the methods +are not good enough for the device \gls{SDS} because they do not achieve the +writing to the actual device. Writing to a device requires being able to write +to shares. To solve this problem, a real base \gls{SDS} is created. All the +details are visible in Listing~\ref{shareimpl}. +\todo{elaborate} + +\begin{lstlisting}[label={lst:shareimpl},% + caption={Base share implementation}] +realDeviceStore :: Shared [MTaskDevice] +realDeviceStore = memoryShare "mTaskDevices" [] + +deviceStore :: RWShared (Maybe (MTaskDevice, Int)) [MTaskDevice] [MTaskDevice] +deviceStore = SDSSource {SDSSource | name="deviceStore", read=realRead, write=realWrite} +where + realRead :: (Maybe (MTaskDevice,Int)) *IWorld -> (MaybeError TaskException [MTaskDevice], *IWorld) + realRead p iw = read realDeviceStore iw + + realWrite :: (Maybe (MTaskDevice,Int)) [MTaskDevice] *IWorld + -> (MaybeError TaskException (SDSNotifyPred (Maybe (MTaskDevice,Int))), *IWorld) + realWrite mi w iw + # (merr, iw) = write w realDeviceStore iw + | isError merr || isNothing mi = (merr $> notifyPred mi, iw) + # (Just (dev, ident)) = mi + | ident == -1 = (merr $> notifyPred mi, iw) + = case find ((==)dev) w of + Nothing = (Error $ exception "Device doesn't exist anymore", iw) + Just {deviceShares} = case find (\d->d.identifier == ident) deviceShares of + Nothing = (Error $ exception $ "deviceStore: Share doesn't exist: " +++ toString ident, iw) + Just s = case sendMessagesIW [MTUpd ident s.MTaskShare.value] dev iw of + (Error e, iw) = (Error e, iw) + (Ok _, iw) = (Ok $ notifyPred mi, iw) + + notifyPred :: (Maybe (MTaskDevice, Int)) (Maybe (MTaskDevice, Int)) -> Bool + notifyPred Nothing Nothing = True + notifyPred Nothing (Just _) = False + notifyPred (Just _) Nothing = False + notifyPred (Just (d1, -1)) (Just (d2, _)) = d1 == d2 + notifyPred (Just (d1, i1)) (Just (d2, i2)) = d1 == d2 && i1 == i2 +\end{lstlisting}