From 77d10f9028e078546d8a931a0a0741af156c05dc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 11 May 2019 15:48:46 -0600 Subject: [PATCH] apps/graphics/twm4nx: Add an IApplicationFactory interface. --- graphics/twm4nx/src/cnxterm.cxx | 198 ++++++++-------- include/graphics/twm4nx/cnxterm.hxx | 211 +++++++---------- include/graphics/twm4nx/iapplication.hxx | 290 +++++++++++++---------- 3 files changed, 355 insertions(+), 344 deletions(-) diff --git a/graphics/twm4nx/src/cnxterm.cxx b/graphics/twm4nx/src/cnxterm.cxx index abb3d0785..5af852a9e 100644 --- a/graphics/twm4nx/src/cnxterm.cxx +++ b/graphics/twm4nx/src/cnxterm.cxx @@ -125,35 +125,33 @@ using namespace Twm4Nx; /** * CNxTerm constructor * - * @param window. The application window + * @param cwin. The application window */ -CNxTerm::CNxTerm(CTwm4Nx *twm4nx, CApplicationWindow *window) +CNxTerm::CNxTerm(CTwm4Nx *twm4nx, CWindow *cwin) { // Save the constructor data - m_twm4nx = twm4nx; - m_window = window; + m_twm4nx = twm4nx; + m_appWindow = cwin; // The NxTerm is not runing - m_pid = -1; - m_nxterm = 0; + m_pid = -1; + m_nxterm = 0; // Add our personalized window label NXWidgets::CNxString myName = getName(); - window->setWindowLabel(myName); + cwin->setWindowLabel(myName); // Add our callbacks with the application window - window->registerCallbacks(static_cast(this)); + cwin->registerCallbacks(static_cast(this)); } /** * CNxTerm destructor - * - * @param window. The application window */ CNxTerm::~CNxTerm(void) @@ -166,17 +164,17 @@ CNxTerm::~CNxTerm(void) // Although we didn't create it, we are responsible for deleting the // application window - delete m_window; + delete m_appWindow; } /** * Each implementation of IApplication must provide a method to recover - * the contained CApplicationWindow instance. + * the contained CWindow instance. */ IApplicationWindow *CNxTerm::getWindow(void) const { - return static_cast(m_window); + return static_cast(m_appWindow); } /** @@ -223,11 +221,11 @@ bool CNxTerm::run(void) // Recover the NXTK window instance contained in the application window - NXWidgets::INxWindow *window = m_window->getWindow(); + NXWidgets::INxWindow *inxWindow = m_appWindow->getWindow(); // Get the widget control associated with the NXTK window - NXWidgets::CWidgetControl *control = window->getWidgetControl(); + NXWidgets::CWidgetControl *control = inxWindow->getWidgetControl(); // Get the window handle from the widget control @@ -245,7 +243,7 @@ bool CNxTerm::run(void) // Get the size of the window - (void)window->getSize(&g_nxtermvars.wndo.wsize); + (void)inxWindow->getSize(&g_nxtermvars.wndo.wsize); // Start the NxTerm task @@ -283,7 +281,7 @@ bool CNxTerm::run(void) DEBUGASSERT(g_nxtermvars.nxterm != 0); #ifdef CONFIG_NXTERM_NXKBDIN - window->redirectNxTerm(g_nxtermvars.nxterm); + inxWindow->redirectNxTerm(g_nxtermvars.nxterm); #endif // Save the handle to use in the stop method @@ -336,8 +334,8 @@ void CNxTerm::stop(void) // Re-store NX keyboard input routing #ifdef CONFIG_NXTERM_NXKBDIN - NXWidgets::INxWindow *window = m_window->getWindow(); - window->redirectNxTerm((NXTERM)0); + NXWidgets::INxWindow *inxWindow = m_appWindow->getWindow(); + inxWindow->redirectNxTerm((NXTERM)0); #endif // Unlink the NxTerm driver @@ -364,7 +362,7 @@ void CNxTerm::destroy(void) { // Block any further window messages - m_window->block(this); + m_appWindow->block(this); // Make sure that the application is stopped @@ -391,12 +389,12 @@ void CNxTerm::redraw(void) { // Recover the NXTK window instance contained in the application window - NXWidgets::INxWindow *window = m_window->getWindow(); + NXWidgets::INxWindow *inxWindow = m_appWindow->getWindow(); // Get the size of the window struct nxgl_size_s windowSize; - (void)window->getSize(&windowSize); + (void)inxWindow->getSize(&windowSize); // Redraw the entire NxTerm window @@ -422,7 +420,7 @@ void CNxTerm::redraw(void) bool CNxTerm::isFullScreen(void) const { - return m_window->isFullScreen(); + return m_appWindow->isFullScreen(); } /** @@ -546,6 +544,28 @@ errout: return EXIT_FAILURE; } +/** + * Handle Twm4Nx events. This overrides a method from CTwm4NXEvent + * + * @param eventmsg. The received NxWidget WINDOW event message. + * @return True if the message was properly handled. false is + * return on any failure. + */ + +bool CNxTerm::event(FAR struct SEventMsg *eventmsg) +{ + bool success = true; + + switch (eventmsg->eventID) + { + default: + success = false; + break; + } + + return success; +} + /** * This is the NxTerm task exit handler. It registered with on_exit() * and called automatically when the nxterm task exits. @@ -590,87 +610,36 @@ void CNxTerm::close(void) m_twm4nx->stopApplication(static_cast(this)); } -/** - * CNxTermFactory Constructor - * - * @param twm4nx. The twm4nx instance used to terminate the console - */ - -CNxTermFactory::CNxTermFactory(CTwm4Nx *twm4nx) -{ - m_twm4nx = twm4nx; -} +///////////////////////////////////////////////////////////////////////////// +// CNxTermFactory Method Implementations +///////////////////////////////////////////////////////////////////////////// /** - * CNxTermFactory Initializer. Performs parts of the instance construction - * that may fail + * CNxTermFactory Initializer. Performs parts of the instance + * construction that may fail. In this implemenation, it will + * initialize the NSH library and register an menu item in the + * Main Menu. * - * @param twm4nx. The twm4nx instance used to terminate the console + * @param twm4nx. The Twm4Nx session instance */ -bool CNxTermFactory::initialize(void) +bool CNxTermFactory::initialize(FAR CTwm4Nx *twm4nx) { + // Initialize the NSH library + + if (!nshlibInitialize()) + { + twmerr("ERROR: Failed to initialize the NSH library\n"); + return false; + } + // Register an entry with the Main menu. When selected, this will + // Case the start - FAR CMainMenu *cmain = m_twm4nx->getMainMenu(); + FAR CMainMenu *cmain = twm4nx->getMainMenu(); return cmain->addApplication(this); } -/** - * Create and start a new instance of an CNxTerm. - */ - -bool *CNxTermFactory::startFunction(CTwm4Nx *twm4n) -{ - // Call CTaskBar::openFullScreenWindow to create a full screen window for - // the NxTerm application - - CApplicationWindow *window = m_twm4nx->openApplicationWindow(); - if (!window) - { - twmerr("ERROR: Failed to create CApplicationWindow\n"); - return (IApplication *)0; - } - - // Open the window (it is hot in here) - - if (!window->open()) - { - twmerr("ERROR: Failed to open CApplicationWindow\n"); - delete window; - return (IApplication *)0; - } - - // Instantiate the application, providing the window to the application's - // constructor - - CNxTerm *nxterm = new CNxTerm(m_twm4nx, window); - if (!nxterm) - { - twmerr("ERROR: Failed to instantiate CNxTerm\n"); - delete window; - return (IApplication *)0; - } - - return true; -} - -/** - * Get the icon associated with the application - * - * @return An instance if IBitmap that may be used to rend the - * application's icon. This is an new IBitmap instance that must - * be deleted by the caller when it is no long needed. - */ - -NXWidgets::IBitmap *CNxTermFactory::getIcon(void) -{ - NXWidgets::CRlePaletteBitmap *bitmap = - new NXWidgets::CRlePaletteBitmap(&CONFIG_TWM4NX_NXTERM_ICON); - - return bitmap; -} - /** * One time NSH initialization. This function must be called exactly * once during the boot-up sequence to initialize the NSH library. @@ -678,7 +647,7 @@ NXWidgets::IBitmap *CNxTermFactory::getIcon(void) * @return True on successful initialization */ -bool Twm4Nx::nshlibInitialize(void) +bool CNxTermFactory::nshlibInitialize(void) { // Initialize the global data structure @@ -705,3 +674,44 @@ bool Twm4Nx::nshlibInitialize(void) return true; } +/** + * Create and start a new instance of CNxTerm. + * + * @param twm4nx. The Twm4Nx session instance + */ + +bool CNxTermFactory::startFunction(FAR CTwm4Nx *twm4nx) +{ + // Call CTaskBar::openFullScreenWindow to create a full screen window for + // the NxTerm application + + FAR CWindowFactory *factory = twm4nx->getWindowFactory(); + CWindow *cwin = factory->createWindow(twm4nx); + if (!cwin ) + { + twmerr("ERROR: Failed to create CWindow\n"); + return false; + } + + // Initialize the window + + if (!cwin->initialize(..arguments...)) + { + twmerr("ERROR: Failed to open CWindow\n"); + delete cwin; + return false; + } + + // Instantiate the application, providing the session and the window to + // the application's constructor + + CNxTerm *nxterm = new CNxTerm(twm4nx, cwin); + if (!nxterm) + { + twmerr("ERROR: Failed to instantiate CNxTerm\n"); + delete cwin; + return (IApplication *)0; + } + + return true; +} diff --git a/include/graphics/twm4nx/cnxterm.hxx b/include/graphics/twm4nx/cnxterm.hxx index 9a4a14b37..8dc116ac9 100644 --- a/include/graphics/twm4nx/cnxterm.hxx +++ b/include/graphics/twm4nx/cnxterm.hxx @@ -48,6 +48,7 @@ #include #include "graphics/twm4nx/ctwm4nx.hxx" +#include "graphics/twm4nx/ctwm4nxevent.hxx" #include "graphics/twm4nx/iapplication.hxx" ///////////////////////////////////////////////////////////////////////////// @@ -56,23 +57,14 @@ namespace Twm4Nx { - /** - * One time NSH initialization. This function must be called exactly - * once during the boot-up sequence to initialize the NSH library. - * - * @return True on successful initialization - */ - - bool nshlibInitialize(void); - /** * This class implements the NxTerm application. */ - class CNxTerm + class CNxTerm : public CTwm4NxEvent { private: - CTaskbar *m_twm4nx; /**< Reference to the "parent" twm4nx */ + CTaskbar *m_twm4nx; /**< Reference to the Twm4Nx session instance */ CApplicationWindow *m_window; /**< Reference to the application window */ NXTERM m_nxterm; /**< NxTerm handle */ pid_t m_pid; /**< Task ID of the NxTerm thread */ @@ -85,6 +77,16 @@ namespace Twm4Nx static int nxterm(int argc, char *argv[]); + /** + * Handle Twm4Nx events. This overrides a method from CTwm4NXEvent + * + * @param eventmsg. The received NxWidget WINDOW event message. + * @return True if the message was properly handled. false is + * return on any failure. + */ + + bool event(FAR struct SEventMsg *eventmsg); + /** * This is the NxTerm task exit handler. It is registered with on_exit() * and called automatically when the nxterm task exits. @@ -158,147 +160,112 @@ namespace Twm4Nx class CNxTermFactory : public IApplication, public IApplicationFactory { private: - CTaskbar *m_twm4nx; /**< The twm4nx */ - /** - * Return the Main Menu item string. This overrides the method from - * IApplication - * - * @param name The name of the application. - */ + /** + * One time NSH initialization. This function must be called exactly + * once during the boot-up sequence to initialize the NSH library. + * + * @return True on successful initialization + */ - inline NXWidgets::CNxString getName(void) - { - return NXWidgets::CNxString("NxTerm"); - } + bool nshlibInitialize(void); - /** - * There is no sub-menu for this Main Menu item. This overrides - * the method from IApplication. - * - * @return This implementation will always return a null value. - */ + /** + * Create and start a new instance of an CNxTerm. + * + * @param twm4nx. The Twm4Nx session instance + */ - inline FAR CMenus *getSubMenu(void) - { - return (FAR CMenus *)0; - } + static bool startFunction(CTwm4Nx *twm4n); - /** - * There is no application start-up function. This function will not - * be called in this implementation - */ + /** + * Return the Main Menu item string. This overrides the method from + * IApplication + * + * @param name The name of the application. + */ - inline TStartFunction getStartFunction(void) - { - return (TStartFunction)startFunction; - } + inline NXWidgets::CNxString getName(void) + { + return NXWidgets::CNxString("NuttShell"); + } - /** - * There is no custom event handler. We use the common event handler. - * - * @return. null is always returned in this impementation. - */ + /** + * There is no sub-menu for this Main Menu item. This overrides + * the method from IApplication. + * + * @return This implementation will always return a null value. + */ - inline FAR CTwm4NxEvent *getEventHandler(void) - { - return (FAR CTwm4NxEvent *)0; - } + inline FAR CMenus *getSubMenu(void) + { + return (FAR CMenus *)0; + } - /** - * Return the Twm4Nx event that will be generated when the Main Menu - * item is selected. - * - * @return. This function always returns EVENT_SYSTEM_NOP. - */ + /** + * There is no application start-up function. This function will not + * be called in this implementation + */ - inline uint16_t getEvent(void) - { - return EVENT_SYSTEM_NOP; - } + inline TStartFunction getStartFunction(void) + { + return (TStartFunction)startFunction; + } + + /** + * There is no custom event handler. We use the common event handler. + * + * @return. null is always returned in this impementation. + */ + + inline FAR CTwm4NxEvent *getEventHandler(void) + { + return (FAR CTwm4NxEvent *)0; + } + + /** + * Return the Twm4Nx event that will be generated when the Main Menu + * item is selected. + * + * @return. This function always returns EVENT_SYSTEM_NOP. + */ + + inline uint16_t getEvent(void) + { + return EVENT_SYSTEM_NOP; + } public: - /** - * CNxTerm constructor - * - * @param window. The application window - * - * @param twm4nx. A pointer to the parent task bar instance - * @param window. The window to be used by this application. - */ - CNxTerm(CTaskbar *twm4nx, CApplicationWindow *window); - - /** - * CNxTerm destructor - */ - - ~CNxTerm(void); - - /** - * Each implementation of IApplication must provide a method to recover - * the contained CApplicationWindow instance. - */ - - IApplicationWindow *getWindow(void) const; - - /** - * Get the icon associated with the application - * - * @return An instance if IBitmap that may be used to rend the - * application's icon. This is an new IBitmap instance that must - * be deleted by the caller when it is no long needed. - */ - - NXWidgets::IBitmap *getIcon(void); - - /** - * Get the name string associated with the application - * - * @return A copy if CNxString that contains the name of the application. - */ - - NXWidgets::CNxString getName(void); - - public: /** * CNxTermFactory Constructor * * @param twm4nx. The twm4nx instance used to terminate calibration */ - CNxTermFactory(CTaskbar *twm4nx); + inline CNxTermFactory(void) + { + } /** * CNxTermFactory Destructor */ - inline ~CNxTermFactory(void) { } + inline ~CNxTermFactory(void) + { + // REVISIT: Would need to remove Main Menu item + } /** * CNxTermFactory Initializer. Performs parts of the instance - * construction that may fail + * construction that may fail. In this implemenation, it will + * initialize the NSH library and register an menu item in the + * Main Menu. * - * @param twm4nx. The twm4nx instance used to terminate the console + * @param twm4nx. The Twm4Nx session instance */ - bool CNxTermFactory::initialize(void); - - /** - * Create a new instance of an CNxTerm (as IApplication). - */ - - IApplication *create(void); - - /** - * Get the icon associated with the application - * - * @return An instance if IBitmap that may be used to rend the - * application's icon. This is an new IBitmap instance that must - * be deleted by the caller when it is no long needed. - */ - - NXWidgets::IBitmap *getIcon(void); + bool CNxTermFactory::initialize(FAR CTwm4Nx *twm4nx); }; } diff --git a/include/graphics/twm4nx/iapplication.hxx b/include/graphics/twm4nx/iapplication.hxx index 8b720530c..79b3c342e 100644 --- a/include/graphics/twm4nx/iapplication.hxx +++ b/include/graphics/twm4nx/iapplication.hxx @@ -79,145 +79,179 @@ namespace Twm4Nx class IApplication { public: - /** - * A virtual destructor is required in order to override the - * IApplication destructor. We do this because if we delete - * IApplication, we want the destructor of the class that inherits from - * IApplication to run, not this one. - */ - virtual ~IApplication(void) - { - } + /** + * A virtual destructor is required in order to override the + * IApplication destructor. We do this because if we delete + * IApplication, we want the destructor of the class that inherits from + * IApplication to run, not this one. + */ - /** - * Return the name of the application. This is the string that will - * appear in the Main Menu item. - * - * @return The name of the application. - */ + virtual ~IApplication(void) + { + } - virtual NXWidgets::CNxString getName(void) = 0; + /** + * Return the name of the application. This is the string that will + * appear in the Main Menu item. + * + * @return The name of the application. + */ - /** - * Return any submenu item associated with the menu entry. If a non- - * null value is returned, then this sub-menu will be brought up when - * the menu entry is selected. Otherwise, the start() method will be - * called. These two behaviors are mutually exlusive. - * - * NOTEs: - * * Both the start() and getSubMenu() methods are ignoredif the event() - * method returns an event with recipient = EVENT_RECIPIENT_APP. In - * that case, the application will be fully responsible for handling - * the menu selection event. - * * Otherwise, the sub-menu or start-up take precedence over - * the event. - * * If getSubMenu() returns a non-NULL CMenu instance, then the - * subMenu is used and the start() is not called. - * - * Precedence: - * 1. Event with recipient == EVENT_RECIPIENT_APP. getEventHandler() - * must return a non-NULL instance in this case. - * 2. Sub-menu - * 3. Task start-up - * 4. Event with other recipients - * - * @return. A reference to any sub-menu that should be brought up if - * the menu item is selected. This must be null if the menu item - * does not bring up a sub-menu - */ + virtual NXWidgets::CNxString getName(void) = 0; - virtual FAR CMenus *getSubMenu(void) = 0; + /** + * Return any submenu item associated with the menu entry. If a non- + * null value is returned, then this sub-menu will be brought up when + * the menu entry is selected. Otherwise, the start() method will be + * called. These two behaviors are mutually exlusive. + * + * NOTEs: + * * Both the start() and getSubMenu() methods are ignoredif the event() + * method returns an event with recipient = EVENT_RECIPIENT_APP. In + * that case, the application will be fully responsible for handling + * the menu selection event. + * * Otherwise, the sub-menu or start-up take precedence over + * the event. + * * If getSubMenu() returns a non-NULL CMenu instance, then the + * subMenu is used and the start() is not called. + * + * Precedence: + * 1. Event with recipient == EVENT_RECIPIENT_APP. getEventHandler() + * must return a non-NULL instance in this case. + * 2. Sub-menu + * 3. Task start-up + * 4. Event with other recipients + * + * @return. A reference to any sub-menu that should be brought up if + * the menu item is selected. This must be null if the menu item + * does not bring up a sub-menu + */ - /** - * This is the application start up function. This function will be - * called when its menu entry has been selected in order to start the - * application unless the behavior of the menu item is to bring up a - * sub-menu. In that case, this start-up function is never called. - * - * The Main Menu runs on the main Twm4Nx thread so this function will, - * typically, create a new thread to host the application. - * - * NOTEs: - * * Both the start() and getSubMenu() methods are ignoredif the event() - * method returns an event with recipient = EVENT_RECIPIENT_APP. In - * that case, the application will be fully responsible for handling - * the menu selection event. - * * Otherwise, the sub-menu or start-up take precedence over - * the event. - * * If getSubMenu() returns a non-NULL CMenu instance, then the - * subMenu is used and the start() is not called. - * - * Precedence: - * 1. Event with recipient == EVENT_RECIPIENT_APP. getEventHandler() - * must return a non-NULL instance in this case. - * 2. Sub-menu - * 3. Task start-up - * 4. Event with other recipients - * - * @return The start-up function entry point. A null value is returned - * if there is no startup function. - */ + virtual FAR CMenus *getSubMenu(void) = 0; - virtual TStartFunction getStartFunction(void) = 0; + /** + * This is the application start up function. This function will be + * called when its menu entry has been selected in order to start the + * application unless the behavior of the menu item is to bring up a + * sub-menu. In that case, this start-up function is never called. + * + * The Main Menu runs on the main Twm4Nx thread so this function will, + * typically, create a new thread to host the application. + * + * NOTEs: + * * Both the start() and getSubMenu() methods are ignoredif the event() + * method returns an event with recipient = EVENT_RECIPIENT_APP. In + * that case, the application will be fully responsible for handling + * the menu selection event. + * * Otherwise, the sub-menu or start-up take precedence over + * the event. + * * If getSubMenu() returns a non-NULL CMenu instance, then the + * subMenu is used and the start() is not called. + * + * Precedence: + * 1. Event with recipient == EVENT_RECIPIENT_APP. getEventHandler() + * must return a non-NULL instance in this case. + * 2. Sub-menu + * 3. Task start-up + * 4. Event with other recipients + * + * @return The start-up function entry point. A null value is returned + * if there is no startup function. + */ - /** - * External applications may provide their own event handler that runs - * when the the menu item is selection. If so, then this method will - * return the instance of CTwm4NxEvent that will handle the event. - * - * NOTE: This handler is only used if the event returned by getEvent is - * destined for recipient EVENT_RECIPIENT_APP. Otherwise, the event - * handling is handling internally by Twm4Nx and this method will never - * be called. - * - * This method may return null in that case. It would be an error if - * this method returned null but the event() method returned a event - * destined for EVENT_RECIPIENT_APP. - * - * @return. A reference to an instance of the CTwm4NxWevent handler - * class or NULL if the event will be handled by Twm4Nx (i.e., the - * recipient is not EVENT_RECIPIENT_APP). - */ + virtual TStartFunction getStartFunction(void) = 0; - virtual FAR CTwm4NxEvent *getEventHandler(void) = 0; + /** + * External applications may provide their own event handler that runs + * when the the menu item is selection. If so, then this method will + * return the instance of CTwm4NxEvent that will handle the event. + * + * NOTE: This handler is only used if the event returned by getEvent is + * destined for recipient EVENT_RECIPIENT_APP. Otherwise, the event + * handling is handling internally by Twm4Nx and this method will never + * be called. + * + * This method may return null in that case. It would be an error if + * this method returned null but the event() method returned a event + * destined for EVENT_RECIPIENT_APP. + * + * @return. A reference to an instance of the CTwm4NxWevent handler + * class or NULL if the event will be handled by Twm4Nx (i.e., the + * recipient is not EVENT_RECIPIENT_APP). + */ - /** - * Get the Twm4Nx event that will be generated when the menu item is - * selected. If the returned value has the event recipient of - * EVENT_RECIPIENT_APP, then getEventHandler() must return the event - * handling instance. Otherwise, the event will be handled by internal - * Twm4Nx logic based on the internal recipient. - * - * This method may return EVENT_SYSTEM_NOP if a subMenu or task start-up - * function should be executed. It would be an error if this method - * returned an event with EVENT_RECIPIENT_APP but the - * getEventHandler() method returned null. - * - * NOTEs: - * * Both the start() and getSubMenu() methods are ignoredif the event() - * method returns an event with recipient = EVENT_RECIPIENT_APP. In - * that case, the application will be fully responsible for handling - * the menu selection event. - * * Otherwise, the sub-menu or start-up take precedence over - * the event. - * * If getSubMenu() returns a non-NULL CMenu instance, then the - * subMenu is used and the start() is not called. - * - * Precedence: - * 1. Event with recipient == EVENT_RECIPIENT_APP. getEventHandler() - * must return a non-NULL instance in this case. - * 2. Sub-menu - * 3. Task start-up - * 4. Event with other recipients - * - * @return. Either, (1) an event with recipient = EVENT_RECIPIENT_APP - * that will be generated when menu item is selected, or (2) any other - * value (preferabley zero) that indicates that standard, built-in - * event handling should be used. - */ + virtual FAR CTwm4NxEvent *getEventHandler(void) = 0; - virtual uint16_t getEvent(void) = 0; + /** + * Get the Twm4Nx event that will be generated when the menu item is + * selected. If the returned value has the event recipient of + * EVENT_RECIPIENT_APP, then getEventHandler() must return the event + * handling instance. Otherwise, the event will be handled by internal + * Twm4Nx logic based on the internal recipient. + * + * This method may return EVENT_SYSTEM_NOP if a subMenu or task start-up + * function should be executed. It would be an error if this method + * returned an event with EVENT_RECIPIENT_APP but the + * getEventHandler() method returned null. + * + * NOTEs: + * * Both the start() and getSubMenu() methods are ignoredif the event() + * method returns an event with recipient = EVENT_RECIPIENT_APP. In + * that case, the application will be fully responsible for handling + * the menu selection event. + * * Otherwise, the sub-menu or start-up take precedence over + * the event. + * * If getSubMenu() returns a non-NULL CMenu instance, then the + * subMenu is used and the start() is not called. + * + * Precedence: + * 1. Event with recipient == EVENT_RECIPIENT_APP. getEventHandler() + * must return a non-NULL instance in this case. + * 2. Sub-menu + * 3. Task start-up + * 4. Event with other recipients + * + * @return. Either, (1) an event with recipient = EVENT_RECIPIENT_APP + * that will be generated when menu item is selected, or (2) any other + * value (preferabley zero) that indicates that standard, built-in + * event handling should be used. + */ + + virtual uint16_t getEvent(void) = 0; + }; + + /** + * IAppliation Factory provides a standard interface for adding multiple + * copies of an application. + */ + + class IApplicationFactory + { + public: + + /** + * A virtual destructor is required in order to override the + * IApplication destructor. We do this because if we delete + * IApplication, we want the destructor of the class that inherits from + * IApplication to run, not this one. + */ + + virtual ~IApplicationFactory(void) + { + } + + /** + * CNxTermFactory Initializer. Performs parts of the instance + * construction that may fail. Aside from general initialization, the + * main responsibility of this function is to register the factory + * IApplication interface with the Main Menu by calling the + * CMainMenu::addApplication() method. + * + * @param twm4nx. The Twm4Nx session instance. + */ + + virtual bool initialize(FAR CTwm4Nx *twm4nx) = 0; }; }