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