f7358a9e9e8a6674794c77bcb989f74d343ef121
[msc-thesis1617.git] / results.itasks.tex
1 The server side of the system is written in \gls{iTasks}. Functions for
2 managing devices, \glspl{Task} and \glspl{SDS} have been created to support the
3 functionality. An interactive application has been created that allows an
4 interactive management console for the \gls{mTask} system. This interface
5 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 needs to keep track of the \glspl{SDS} stored on
43 the client. \glspl{SDS} can be stored on only one device at the same time.
44 that also stores the of devices. This means that if a \gls{SDS} updates,
45 everyone watching it will be notified. This would result in to a lot of
46 notifications that are not ment to be for the listener. Moreover, when a client
47 updates the \gls{SDS} this is processed by the connection handler and results
48 in an update of the real \gls{SDS}.
49 Finally, the \gls{SDS} of a client must be synchronized with the actual device.
50 There are several ways of tackling this problem each with their own pros and
51 cons and their own level of abstraction.
52
53 \begin{itemize}
54 \item Instantiate an actual \gls{iTasks}-\gls{SDS} for every \gls{SDS} used
55 in a client.
56
57
58 \item Instantiate a \gls{iTasks}-\gls{SDS} for every device that stores all
59 their \glspl{SDS}.
60
61 \item Use only one \gls{iTasks}-\gls{SDS} for all devices.
62 \end{itemize}
63
64 \begin{lstlisting}[label={lst:actualdev},%
65 caption={Real types for the device \gls{SDS}}]
66 deviceStoreNP :: Shared [MTaskDevice]
67 deviceStore :: RWShared (Maybe (MTaskDevice, Int)) [MTaskDevice] [MTaskDevice]
68 \end{lstlisting}
69
70 \subsection{Parametric Lens}
71 The type of the parametric lens is \CI{Maybe (MTaskDevice, Int)}. The \gls{SDS}
72 can either be focussed on the entire share, from now on global. Moreover, the
73 \gls{SDS} can focus on a single device, from now on local. A local \gls{SDS}
74 can also specifically focus on a single \gls{SDS} on a single device.
75
76 The implementation for the share is shown in Listing~\ref{lst:shareimpl}. The
77 \CI{realDeviceStore} \gls{SDS} is not exported through the header files. This
78 \gls{SDS} contains the actual \gls{SDS} that writes to disk or memory.
79 \CI{Int} is the identifier of the \gls{SDS}. The \gls{iTasks} way of applying
80 lenses is through the \CI{sdsFocus} function and through the \CI{sdsLens}
81 functions. \CI{sdsFocus} allows the programmer to fix the parameter.
82 \CI{sdsLens} is basically a \CI{mapReadWrite} that has access to the parameter.
83 This allows the programmer to create filters and lenses. Both of the methods
84 are not good enough for the device \gls{SDS} because they do not achieve the
85 writing to the actual device. Writing to a device requires being able to write
86 to \glspl{SDS}. To solve this problem, a real base \gls{SDS} is created. All
87 the details are visible in Listing~\ref{shareimpl}.
88 \todo{elaborate}
89
90 \begin{lstlisting}[label={lst:shareimpl},%
91 caption={Base share implementation}]
92 realDeviceStore :: Shared [MTaskDevice]
93 realDeviceStore = memoryShare "mTaskDevices" []
94
95 deviceStore :: RWShared (Maybe (MTaskDevice, Int)) [MTaskDevice] [MTaskDevice]
96 deviceStore = SDSSource {SDSSource | name="deviceStore", read=realRead, write=realWrite}
97 where
98 realRead :: (Maybe (MTaskDevice,Int)) *IWorld -> (MaybeError TaskException [MTaskDevice], *IWorld)
99 realRead p iw = read realDeviceStore iw
100
101 realWrite :: (Maybe (MTaskDevice,Int)) [MTaskDevice] *IWorld
102 -> (MaybeError TaskException (SDSNotifyPred (Maybe (MTaskDevice,Int))), *IWorld)
103 realWrite mi w iw
104 # (merr, iw) = write w realDeviceStore iw
105 | isError merr || isNothing mi = (merr $> notifyPred mi, iw)
106 # (Just (dev, ident)) = mi
107 | ident == -1 = (merr $> notifyPred mi, iw)
108 = case find ((==)dev) w of
109 Nothing = (Error $ exception "Device doesn't exist anymore", iw)
110 Just {deviceShares} = case find (\d->d.identifier == ident) deviceShares of
111 Nothing = (Error $ exception $ "deviceStore: Share doesn't exist: " +++ toString ident, iw)
112 Just s = case sendMessagesIW [MTUpd ident s.MTaskShare.value] dev iw of
113 (Error e, iw) = (Error e, iw)
114 (Ok _, iw) = (Ok $ notifyPred mi, iw)
115
116 notifyPred :: (Maybe (MTaskDevice, Int)) (Maybe (MTaskDevice, Int)) -> Bool
117 notifyPred Nothing Nothing = True
118 notifyPred Nothing (Just _) = False
119 notifyPred (Just _) Nothing = False
120 notifyPred (Just (d1, -1)) (Just (d2, _)) = d1 == d2
121 notifyPred (Just (d1, i1)) (Just (d2, i2)) = d1 == d2 && i1 == i2
122 \end{lstlisting}