#include <UI.h>
Inheritance diagram for UI:
Public Member Functions | |
UI (char *name, int stackSize, int priority, int id) | |
bool | spawn () |
void | initialize (void) |
Protected Member Functions | |
void | run (void) |
Static Protected Member Functions | |
void | staticRun (void) |
Private Attributes | |
int | state |
Keyboard | keyboard |
LCD | lcd |
Starter | starter |
Static Private Attributes | |
UI * | mes [NUMBER_OF_ROBOTS] |
const int | READY = 0 |
const int | RUNNING = 1 |
|
Constructor for UI. The parameters are passed to the Thread constructor
|
|
The simulator does not allow the usage of RoBIOS functions in class constructors. Therefore we use public initialize methods for classes that need RoBIOS functions for their initializations. |
|
The method is overwritten by the inheritor. When the thread starts the code in this run method is executed Reimplemented from Thread. |
|
According to C++ convention, methods cannot be static and virtual at once. In the initial design run was declared as virtual which results in dynamic binding. That means the program determines at run-time which run method to use, the one of the Thread base class or the one of the inheritor. Because we have to use staticRun, we cannot use the virtual keyword anymore. Without the virtual keyword the compiler determines at compile-time which run method is used, always the run method of the Thread base class. To ensure that the inheritor indeed uses its own run method, it is necessary to overwrite the thread initialization method (spawn) as well.
Reimplemented from Thread. |
|
Static wrapper method for run. It does nothing but to call run. That is necessary because the RoBIOS multi-tasking functions expect a pointer to a C-function (not a pointer to a C++ method) containing the code to be executed. Fortunately, pointer-to-static-C++-methods are compatible with regular pointer-to-C-functions. But the problem is that static methods can only use other static methods and variables. The reasons is that a static method, which is shared by all instances, would not know which non-static method or variable to use if there were multiple instances of the same class. Thus, the static property would have to be applied to all used (sub-)methods and (sub-) variables, and propagate through the whole class structure. By using staticRun, we can keep using our non-static run. If static methods cannot call non-static ones, how can staticRun call run? As aforementioned the reason why static method cannot use non-static members is because it is not clear which non-static member to use if there are multiple instances of the same class. That means staticRun needs a pointer to the instance whose run method is to be called. This pointer is stored in a static member variable called me.
|
|
The UI uses the Keyboard to receive user input |
|
The UI uses the LCD to display output for the user |
|
Stores pointers to instances of UI
|
|
Used by the class to keep track of its own state |
|
Used by the class to keep track of its own state |
|
The UI uses the Starter to control the clustering algorithm |
|
Used by the class to keep track of its current state. Possible states are UI::READY, UI::RUNNING |