2019-05-08 19:15:44 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// apps/graphics/twm4nx/src/cwindow.hxx
|
|
|
|
// NxTerm window
|
|
|
|
//
|
|
|
|
// Copyright (C) 2019 Gregory Nutt. All rights reserved.
|
|
|
|
// Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions
|
|
|
|
// are met:
|
|
|
|
//
|
|
|
|
// 1. Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer in
|
|
|
|
// the documentation and/or other materials provided with the
|
|
|
|
// distribution.
|
|
|
|
// 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef __APPS_INCLUDE_GRAPHICS_TWM4NX_CNXTERM_HXX
|
|
|
|
#define __APPS_INCLUDE_GRAPHICS_TWM4NX_CNXTERM_HXX
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Included Files
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <nuttx/nx/nxtk.h>
|
|
|
|
#include <nuttx/nx/nxterm.h>
|
|
|
|
|
|
|
|
#include "graphics/twm4nx/ctwm4nx.hxx"
|
2019-05-11 23:48:46 +02:00
|
|
|
#include "graphics/twm4nx/ctwm4nxevent.hxx"
|
2019-05-12 19:57:45 +02:00
|
|
|
#include "graphics/twm4nx/twm4nx_widgetevents.hxx"
|
2019-05-11 21:17:19 +02:00
|
|
|
#include "graphics/twm4nx/iapplication.hxx"
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-12 19:57:45 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Pre-processor Definitions
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// CNxTerm application events
|
|
|
|
// Window Events
|
|
|
|
|
|
|
|
#define EVENT_NXTERM_REDRAW (EVENT_RECIPIENT_APP | 0x0000)
|
|
|
|
#define EVENT_NXTERM_XYINPUT EVENT_SYSTEM_NOP
|
|
|
|
#define EVENT_NXTERM_KBDINPUT EVENT_SYSTEM_NOP
|
|
|
|
|
|
|
|
// Button Events
|
|
|
|
|
|
|
|
#define EVENT_NXTERM_CLOSE (EVENT_RECIPIENT_APP | 0x0001)
|
|
|
|
|
2019-05-08 19:15:44 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Implementation Classes
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace Twm4Nx
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* This class implements the NxTerm application.
|
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
class CNxTerm : public CTwm4NxEvent
|
2019-05-08 19:15:44 +02:00
|
|
|
{
|
2019-05-11 21:17:19 +02:00
|
|
|
private:
|
2019-05-12 19:57:45 +02:00
|
|
|
CTwm4Nx *m_twm4nx; /**< Reference to the Twm4Nx session instance */
|
|
|
|
CWindow *m_nxtermWindow; /**< Reference to the NxTerm application window */
|
|
|
|
NXTERM m_NxTerm; /**< NxTerm handle */
|
|
|
|
pid_t m_pid; /**< Task ID of the NxTerm thread */
|
|
|
|
int m_minor; /**< Terminal device minor number */
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-11 21:17:19 +02:00
|
|
|
/**
|
|
|
|
* This is the NxTerm task. This function first redirects output to the
|
|
|
|
* console window then calls to start the NSH logic.
|
|
|
|
*/
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-11 21:17:19 +02:00
|
|
|
static int nxterm(int argc, char *argv[]);
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2019-05-11 21:17:19 +02:00
|
|
|
/**
|
2019-05-12 19:57:45 +02:00
|
|
|
* Handle the NxTerm redraw event.
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-12 19:57:45 +02:00
|
|
|
void redraw(void);
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-11 21:17:19 +02:00
|
|
|
/**
|
2019-05-12 19:57:45 +02:00
|
|
|
* This is the close window event handler. It will stop the NxTerm
|
|
|
|
* application trhead.
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-12 19:57:45 +02:00
|
|
|
void stop(void);
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-12 19:57:45 +02:00
|
|
|
public:
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-11 21:17:19 +02:00
|
|
|
/**
|
2019-05-12 19:57:45 +02:00
|
|
|
* CNxTerm constructor
|
2019-05-11 21:17:19 +02:00
|
|
|
*
|
2019-05-12 19:57:45 +02:00
|
|
|
* @param twm4nx. The Twm4Nx session instance
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-12 19:57:45 +02:00
|
|
|
CNxTerm(FAR CTwm4Nx *twm4nx);
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-11 21:17:19 +02:00
|
|
|
/**
|
2019-05-12 19:57:45 +02:00
|
|
|
* CNxTerm destructor
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-12 19:57:45 +02:00
|
|
|
~CNxTerm(void);
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-11 21:17:19 +02:00
|
|
|
/**
|
2019-05-12 19:57:45 +02:00
|
|
|
* CNxTerm initializers. Perform miscellaneous post-construction
|
|
|
|
* initialization that may fail (and hence is not appropriate to be
|
|
|
|
* done in the constructor)
|
|
|
|
*
|
|
|
|
* @return True if the NxTerm application was successfully initialized.
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-12 19:57:45 +02:00
|
|
|
bool initialize(void);
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-11 21:17:19 +02:00
|
|
|
/**
|
2019-05-12 19:57:45 +02:00
|
|
|
* Start the NxTerm.
|
2019-05-11 21:17:19 +02:00
|
|
|
*
|
2019-05-12 19:57:45 +02:00
|
|
|
* @return True if the NxTerm application was successfully started.
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-12 19:57:45 +02:00
|
|
|
bool run(void);
|
2019-05-11 21:17:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CNxTermFactory : public IApplication, public IApplicationFactory
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
2019-05-11 23:48:46 +02:00
|
|
|
* One time NSH initialization. This function must be called exactly
|
|
|
|
* once during the boot-up sequence to initialize the NSH library.
|
2019-05-11 21:17:19 +02:00
|
|
|
*
|
2019-05-11 23:48:46 +02:00
|
|
|
* @return True on successful initialization
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
bool nshlibInitialize(void);
|
2019-05-11 21:17:19 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-11 23:48:46 +02:00
|
|
|
* Create and start a new instance of an CNxTerm.
|
|
|
|
*
|
|
|
|
* @param twm4nx. The Twm4Nx session instance
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
static bool startFunction(CTwm4Nx *twm4n);
|
2019-05-11 21:17:19 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-11 23:48:46 +02:00
|
|
|
* Return the Main Menu item string. This overrides the method from
|
|
|
|
* IApplication
|
|
|
|
*
|
|
|
|
* @param name The name of the application.
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
inline NXWidgets::CNxString getName(void)
|
|
|
|
{
|
|
|
|
return NXWidgets::CNxString("NuttShell");
|
|
|
|
}
|
2019-05-11 21:17:19 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-11 23:48:46 +02:00
|
|
|
* There is no sub-menu for this Main Menu item. This overrides
|
|
|
|
* the method from IApplication.
|
2019-05-11 21:17:19 +02:00
|
|
|
*
|
2019-05-11 23:48:46 +02:00
|
|
|
* @return This implementation will always return a null value.
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
inline FAR CMenus *getSubMenu(void)
|
|
|
|
{
|
|
|
|
return (FAR CMenus *)0;
|
|
|
|
}
|
2019-05-11 21:17:19 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-11 23:48:46 +02:00
|
|
|
* There is no application start-up function. This function will not
|
|
|
|
* be called in this implementation
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
inline TStartFunction getStartFunction(void)
|
|
|
|
{
|
|
|
|
return (TStartFunction)startFunction;
|
|
|
|
}
|
2019-05-11 21:17:19 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-11 23:48:46 +02:00
|
|
|
* There is no custom event handler. We use the common event handler.
|
2019-05-11 21:17:19 +02:00
|
|
|
*
|
2019-05-11 23:48:46 +02:00
|
|
|
* @return. null is always returned in this impementation.
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
inline FAR CTwm4NxEvent *getEventHandler(void)
|
|
|
|
{
|
|
|
|
return (FAR CTwm4NxEvent *)0;
|
|
|
|
}
|
2019-05-11 21:17:19 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-11 23:48:46 +02:00
|
|
|
* Return the Twm4Nx event that will be generated when the Main Menu
|
|
|
|
* item is selected.
|
|
|
|
*
|
|
|
|
* @return. This function always returns EVENT_SYSTEM_NOP.
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
inline uint16_t getEvent(void)
|
|
|
|
{
|
|
|
|
return EVENT_SYSTEM_NOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2019-05-11 21:17:19 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-11 23:48:46 +02:00
|
|
|
* CNxTermFactory Constructor
|
2019-05-11 21:17:19 +02:00
|
|
|
*
|
2019-05-11 23:48:46 +02:00
|
|
|
* @param twm4nx. The twm4nx instance used to terminate calibration
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
inline CNxTermFactory(void)
|
|
|
|
{
|
|
|
|
}
|
2019-05-11 21:17:19 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-11 23:48:46 +02:00
|
|
|
* CNxTermFactory Destructor
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
inline ~CNxTermFactory(void)
|
|
|
|
{
|
|
|
|
// REVISIT: Would need to remove Main Menu item
|
|
|
|
}
|
2019-05-11 21:17:19 +02:00
|
|
|
|
|
|
|
/**
|
2019-05-11 23:48:46 +02:00
|
|
|
* 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.
|
2019-05-11 21:17:19 +02:00
|
|
|
*
|
2019-05-11 23:48:46 +02:00
|
|
|
* @param twm4nx. The Twm4Nx session instance
|
2019-05-11 21:17:19 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-12 19:57:45 +02:00
|
|
|
bool initialize(FAR CTwm4Nx *twm4nx);
|
2019-05-08 19:15:44 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __APPS_INCLUDE_GRAPHICS_TWM4NX_CNXTERM_HXX
|