Hello App: HelloApp.h
Contents
HelloApp.h
/**
* HelloApp.h - class declaration for Hello interface
*
* Copyright (c) 2024 HanoverSoft
* Written by Anthony V. Edwards
* 820 Churchill Drive, Chapel Hill, NC 27517
* ave@hanoversoft.net
*/
/** The Hello app handles multiple user sessions, so this class holds session
* data for each user. There's not much data, but these are the methods for
* handling the messages/events from MAE. In particular, these events are
* triggered by user interactions for the Hello app.
* @see UserDevice
*/
class HelloApp : public UserDevice {
public:
/** Constructor for an instance of a user interacting with us.
* We are a simple program, so there's not much to initialize.
* @param id - user id
*/
HelloApp(DbRecNum id= 0);
/** Determine if the current instance is valid.
* If setDevice() has been called with a valid UserDevice, then HelloApp is valid.
* @return true if this instance is valid, false otherwise
*/
inline bool valid() const
{ return getUserId() > 0; }
/** Clear this instance of HelloApp
*/
inline void clear()
{ setUserId(0); params.clear(); }
// GET methods
/** Get this HelloApp instance's id
* @return current instance (user id)
*/
inline DbRecNum getId() const
{ return id; }
/** Get the UserDevice instance to talk to the user.
* (The device is our base class.)
*/
inline UserDevice & getDevice()
{ return *this; }
// SET mehtods
/** Record the UserDevice used to communicate with the user so we can use it again later (and not have to pass it as a parameter everywhere).
* @param newdevice - the value of UserDevice to communicate with this user
* @return the current HelloApp instance for further use
*/
inline HelloApp & setDevice(const UserDevice & newdevice)
{ *((UserDevice*)this)= newdevice; return *this; }
/** Initialize a user's connection. No user response will be received before this userstart().
* This is where we setup the screen/page for the user to start interacting with us.
* Note that /usr/mae/html/hello.html has already been delivered to the user and displayed.
* @param param - parameters (like argc/argv) to guide how we behave to the user
*/
void userstart(XMLData & param);
// Menu selections
/** Menu Display->From DB selected. So, query the user's name from the DB, then say hello.
*/
void menu_Display_FromDB();
/** Menu Display->Clear selected. So, clear the display.
*/
void menu_Display_Clear();
/** Menu Display->Help selected. So, show some help.
*/
void menu_Display_Help();
/** Menu Display->Quit selected. So, exit this MAE app.
* Note that this MAE app does not actually quit; it redirects the browser to another MAE app.
*/
void menu_Display_Quit();
// Menu support
/** Create a "Prompt" window and display our question in it.
* The layout of the question comes from /usr/mae/html/record/helloPrompt.html.
*/
void drawPromptWindow(const string & defaultName= "");
// UI user response callbacks
/** The user responded to the question asking them for their name.
* Respond in the UI to their provided data.
* @param name - the value provided by the user
*/
void inputName(const string & name);
// To make Cache class happy (if we saved our data, these would need to be fleshed out)
// A more advanced app would define these to do more than the dummy operations here
/** Save out our user session data. For now, do nothing.
* @return true if data save out, false if not
*/
inline bool save() const
{ return false; }
/** Convert our session data to a HashArray (key/value pairs). For now, do nothing.
* @return key/value pairs of our session data
*/
inline HashArray toHashArray() const
{ HashArray nada; return nada; }
/** Pull our session data from an external cache, such as directly from the data store. For now, do nothing.
* @param id - id of the record to retrieve (user id)
* @return a ready instance of HelloApp based upon the last saved state
*/
inline static HelloApp cache(DbRecNum id)
{ HelloApp newone; return newone; }
private:
DbRecNum id; // our record id - user id - used by the Cache class to manage multiple HelloApp instances
XMLData params; // the initial arguments provided to us to control this program's behavior (not used)
};