process the rest of george's comments
[msc-thesis1617.git] / results.itasks.tex
1 The glue in the system is written in \gls{iTasks}. Functions for managing
2 devices, \glspl{Task} and \glspl{SDS} are created. An interface is made that
3 allows an interactive management console for the \gls{mTask} system. This
4 interface provides functionality to list \glspl{SDS}, add \glspl{Task}, remove
5 \glspl{Task}, administrate devices and view the state of the system.
6
7 \section{Integration}
8 When the system starts up the devices residing in the \gls{SDS} must be cleaned
9 up. It might be the case that they contain \glspl{Task}, \glspl{SDS} or errors.
10 A user or programmer can then choose to reconnect some devices using the
11 \CI{connectDevice} function.
12
13 \begin{lstlisting}[caption={Starting up the devices},%
14 label={lst:startupdevs}]
15 startupDevices :: Task [MTaskDevice]
16 startupDevices = upd (map reset) deviceStoreNP
17 where reset d = {d & deviceTask=Nothing, deviceTasks=[], deviceError=Nothing}
18 \end{lstlisting}
19
20 An image of the management interface is shown in Figure~\ref{lst:manage}.
21 The system management is done by a single \gls{Task} called \CI{mTaskManager}.
22 To manage the system, a couple of different functionalities are needed and
23 are launched. The left sidebar of the interface shows the list of example
24 \glspl{Task} that are present in the system. When clicking a \gls{Task}, a
25 dialog opens in which you can select the device to send the \gls{Task} to. The
26 dialog might contain user specified variables. All example \glspl{mTask} are of
27 the type \CI{Task (Main (ByteCode () Stmt))} and can thus ask for user input
28 first.
29
30 The bottom panel shows the device information. In this panel, the devices can
31 be created and modified. Moreover, this panel allows the user to reconnect with
32 a device after a restart of the server application.
33
34 \begin{figure}[H]
35 \centering
36 \includegraphics[width=\linewidth]{manage}
37 \caption{The device management interface}\label{lst:management}
38 \end{figure}
39
40 \section{Shares}
41 The architecture of the system stores the \glspl{SDS} in the \gls{SDS} that
42 stores the list of devices. This means that if a \gls{SDS} updates, everyone
43 watching it will be notified. This would result in to a lot of notifications
44 that are not ment to be for the listener. Moreover, when a client updates the
45 \gls{SDS} this is processed by the connection handler and results in an update
46 of the real \gls{SDS}. When an \gls{iTasks}-\gls{Task} writes to a \gls{SDS}
47 this is not passed on to the device.
48
49 To solve the problem, parametric lenses are used on the device storage.
50 Listing~\ref{lst:actualdev} shows the actual types for the device storage.
51 Programmers wanting to access the entire \gls{SDS} use the \CI{deviceStoreNP}.
52 Programmers wanting to access a single \gls{SDS} on a device can use the
53 \CI{getRealShare} function which is a wrapper around the \CI{deviceStore} which
54 applies a parametric lens to the \gls{SDS}.
55
56 \begin{lstlisting}[label={lst:actualdev},%
57 caption={Real types for the device \gls{SDS}}]
58 deviceStoreNP :: Shared [MTaskDevice]
59 deviceStore :: RWShared (Maybe (MTaskDevice, Int)) [MTaskDevice] [MTaskDevice]
60
61 realDeviceStore :: Shared [MTaskDevice]
62
63 getRealShare :: MTaskDevice MTaskShare -> Shared BCValue
64 \end{lstlisting}
65
66 \subsection{Parametric Lens}
67 The type of the parametric lens is \CI{Maybe (MTaskDevice, Int)} where the
68 \CI{Int} is the identifier of the \gls{SDS}. The \gls{iTasks} way of applying
69 lenses is through the \CI{sdsFocus} function and through the \CI{sdsLens}
70 functions. \CI{sdsFocus} allows the programmer to fix the parameter.
71 \CI{sdsLens} is basically a \CI{mapReadWrite} that has access to the parameter.
72 This allows the programmer to create filters and lenses. Both of the methods
73 are not good enough for the device \gls{SDS} because they do not achieve the
74 writing to the actual device. Writing to a device requires being able to write
75 to \glspl{SDS}. To solve this problem, a real base \gls{SDS} is created. All
76 the details are visible in Listing~\ref{shareimpl}.
77 \todo{elaborate}
78
79 \begin{lstlisting}[label={lst:shareimpl},%
80 caption={Base share implementation}]
81 realDeviceStore :: Shared [MTaskDevice]
82 realDeviceStore = memoryShare "mTaskDevices" []
83
84 deviceStore :: RWShared (Maybe (MTaskDevice, Int)) [MTaskDevice] [MTaskDevice]
85 deviceStore = SDSSource {SDSSource | name="deviceStore", read=realRead, write=realWrite}
86 where
87 realRead :: (Maybe (MTaskDevice,Int)) *IWorld -> (MaybeError TaskException [MTaskDevice], *IWorld)
88 realRead p iw = read realDeviceStore iw
89
90 realWrite :: (Maybe (MTaskDevice,Int)) [MTaskDevice] *IWorld
91 -> (MaybeError TaskException (SDSNotifyPred (Maybe (MTaskDevice,Int))), *IWorld)
92 realWrite mi w iw
93 # (merr, iw) = write w realDeviceStore iw
94 | isError merr || isNothing mi = (merr $> notifyPred mi, iw)
95 # (Just (dev, ident)) = mi
96 | ident == -1 = (merr $> notifyPred mi, iw)
97 = case find ((==)dev) w of
98 Nothing = (Error $ exception "Device doesn't exist anymore", iw)
99 Just {deviceShares} = case find (\d->d.identifier == ident) deviceShares of
100 Nothing = (Error $ exception $ "deviceStore: Share doesn't exist: " +++ toString ident, iw)
101 Just s = case sendMessagesIW [MTUpd ident s.MTaskShare.value] dev iw of
102 (Error e, iw) = (Error e, iw)
103 (Ok _, iw) = (Ok $ notifyPred mi, iw)
104
105 notifyPred :: (Maybe (MTaskDevice, Int)) (Maybe (MTaskDevice, Int)) -> Bool
106 notifyPred Nothing Nothing = True
107 notifyPred Nothing (Just _) = False
108 notifyPred (Just _) Nothing = False
109 notifyPred (Just (d1, -1)) (Just (d2, _)) = d1 == d2
110 notifyPred (Just (d1, i1)) (Just (d2, i2)) = d1 == d2 && i1 == i2
111 \end{lstlisting}