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