2019-05-08 19:15:44 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2019-05-10 23:22:27 +02:00
|
|
|
// apps/graphics/twm4nx/src/cnxterm.cxx
|
2019-05-08 19:15:44 +02:00
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Included Files
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cunistd>
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
#include <sys/boardctl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include "nshlib/nshlib.h"
|
|
|
|
|
|
|
|
#include "graphics/nxwidgets/cwidgetcontrol.hxx"
|
|
|
|
|
|
|
|
#include "graphics/nxglyphs.hxx"
|
|
|
|
#include "graphics/twm4nx/twm4nx_config.hxx"
|
2019-05-11 21:17:19 +02:00
|
|
|
#include "graphics/twm4nx/twm4nx.hxx"
|
2019-05-08 19:15:44 +02:00
|
|
|
#include "graphics/twm4nx/cnxterm.hxx"
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Pre-Processor Definitions
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Configuration ////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef CONFIG_NSH_USBKBD
|
2019-05-11 21:17:19 +02:00
|
|
|
# warning You probably do not really want CONFIG_NSH_USBKBD, try CONFIG_TWM4NX_KEYBOARD_USBHOST
|
2019-05-08 19:15:44 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If Telnet is used and both IPv6 and IPv4 are enabled, then we need to
|
|
|
|
* pick one.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
# define ADDR_FAMILY AF_INET6
|
|
|
|
#else
|
|
|
|
# define ADDR_FAMILY AF_INET
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private Types
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace Twm4Nx
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* This structure is used to pass start up parameters to the NxTerm task and to assure the
|
|
|
|
* the NxTerm is successfully started.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct SNxTerm
|
|
|
|
{
|
|
|
|
FAR void *console; /**< The console 'this' pointer use with on_exit() */
|
|
|
|
sem_t exclSem; /**< Sem that gives exclusive access to this structure */
|
|
|
|
sem_t waitSem; /**< Sem that posted when the task is initialized */
|
|
|
|
NXTKWINDOW hwnd; /**< Window handle */
|
|
|
|
NXTERM nxterm; /**< NxTerm handle */
|
|
|
|
int minor; /**< Next device minor number */
|
|
|
|
struct nxterm_window_s wndo; /**< Describes the NxTerm window */
|
|
|
|
bool result; /**< True if successfully initialized */
|
|
|
|
};
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Private Data
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This global data structure is used to pass start parameters to NxTerm task and to
|
|
|
|
* assure that the NxTerm is successfully started.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct SNxTerm g_nxtermvars;
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CNxTerm Method Implementations
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
using namespace Twm4Nx;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CNxTerm constructor
|
|
|
|
*
|
2019-05-11 23:48:46 +02:00
|
|
|
* @param cwin. The application window
|
2019-05-08 19:15:44 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
CNxTerm::CNxTerm(CTwm4Nx *twm4nx, CWindow *cwin)
|
2019-05-08 19:15:44 +02:00
|
|
|
{
|
|
|
|
// Save the constructor data
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
m_twm4nx = twm4nx;
|
|
|
|
m_appWindow = cwin;
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
// The NxTerm is not runing
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
m_pid = -1;
|
|
|
|
m_nxterm = 0;
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
// Add our personalized window label
|
|
|
|
|
|
|
|
NXWidgets::CNxString myName = getName();
|
2019-05-11 23:48:46 +02:00
|
|
|
cwin->setWindowLabel(myName);
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
// Add our callbacks with the application window
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
cwin->registerCallbacks(static_cast<IApplicationCallback *>(this));
|
2019-05-08 19:15:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CNxTerm destructor
|
|
|
|
*/
|
|
|
|
|
|
|
|
CNxTerm::~CNxTerm(void)
|
|
|
|
{
|
|
|
|
// There would be a problem if we were stopped with the NxTerm task
|
|
|
|
// running... that should never happen but we'll check anyway:
|
|
|
|
|
|
|
|
stop();
|
|
|
|
|
|
|
|
// Although we didn't create it, we are responsible for deleting the
|
|
|
|
// application window
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
delete m_appWindow;
|
2019-05-08 19:15:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Each implementation of IApplication must provide a method to recover
|
2019-05-11 23:48:46 +02:00
|
|
|
* the contained CWindow instance.
|
2019-05-08 19:15:44 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
IApplicationWindow *CNxTerm::getWindow(void) const
|
|
|
|
{
|
2019-05-11 23:48:46 +02:00
|
|
|
return static_cast<IApplicationWindow*>(m_appWindow);
|
2019-05-08 19:15:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 *CNxTerm::getIcon(void)
|
|
|
|
{
|
|
|
|
NXWidgets::CRlePaletteBitmap *bitmap =
|
2019-05-11 21:17:19 +02:00
|
|
|
new NXWidgets::CRlePaletteBitmap(&CONFIG_TWM4NX_NXTERM_ICON);
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the application (perhaps in the minimized state).
|
|
|
|
*
|
|
|
|
* @return True if the application was successfully started.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool CNxTerm::run(void)
|
|
|
|
{
|
|
|
|
// Some sanity checking
|
|
|
|
|
|
|
|
if (m_pid >= 0 || m_nxterm != 0)
|
|
|
|
{
|
2019-05-09 21:31:12 +02:00
|
|
|
twmerr("ERROR: All ready running or connected\n");
|
2019-05-08 19:15:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get exclusive access to the global data structure
|
|
|
|
|
|
|
|
if (sem_wait(&g_nxtermvars.exclSem) != 0)
|
|
|
|
{
|
|
|
|
// This might fail if a signal is received while we are waiting.
|
|
|
|
|
2019-05-09 21:31:12 +02:00
|
|
|
twmerr("ERROR: Failed to get semaphore\n");
|
2019-05-08 19:15:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recover the NXTK window instance contained in the application window
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
NXWidgets::INxWindow *inxWindow = m_appWindow->getWindow();
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
// Get the widget control associated with the NXTK window
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
NXWidgets::CWidgetControl *control = inxWindow->getWidgetControl();
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
// Get the window handle from the widget control
|
|
|
|
|
|
|
|
g_nxtermvars.hwnd = control->getWindowHandle();
|
|
|
|
|
|
|
|
// Describe the NxTerm
|
|
|
|
|
2019-05-11 21:17:19 +02:00
|
|
|
g_nxtermvars.wndo.wcolor[0] = CONFIG_TWM4NX_NXTERM_WCOLOR;
|
|
|
|
g_nxtermvars.wndo.fcolor[0] = CONFIG_TWM4NX_NXTERM_FONTCOLOR;
|
|
|
|
g_nxtermvars.wndo.fontid = CONFIG_TWM4NX_NXTERM_FONTID;
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
// Remember the device minor number (before it is incremented)
|
|
|
|
|
|
|
|
m_minor = g_nxtermvars.minor;
|
|
|
|
|
|
|
|
// Get the size of the window
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
(void)inxWindow->getSize(&g_nxtermvars.wndo.wsize);
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
// Start the NxTerm task
|
|
|
|
|
|
|
|
g_nxtermvars.console = (FAR void *)this;
|
|
|
|
g_nxtermvars.result = false;
|
|
|
|
g_nxtermvars.nxterm = 0;
|
|
|
|
|
|
|
|
sched_lock();
|
2019-05-11 21:17:19 +02:00
|
|
|
m_pid = task_create("NxTerm", CONFIG_TWM4NX_NXTERM_PRIO,
|
|
|
|
CONFIG_TWM4NX_NXTERM_STACKSIZE, nxterm,
|
2019-05-08 19:15:44 +02:00
|
|
|
(FAR char * const *)0);
|
|
|
|
|
|
|
|
// Did we successfully start the NxTerm task?
|
|
|
|
|
|
|
|
bool result = true;
|
|
|
|
if (m_pid < 0)
|
|
|
|
{
|
2019-05-09 21:31:12 +02:00
|
|
|
twmerr("ERROR: Failed to create the NxTerm task\n");
|
2019-05-08 19:15:44 +02:00
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Wait for up to two seconds for the task to initialize
|
|
|
|
|
|
|
|
struct timespec abstime;
|
|
|
|
clock_gettime(CLOCK_REALTIME, &abstime);
|
|
|
|
abstime.tv_sec += 2;
|
|
|
|
|
|
|
|
int ret = sem_timedwait(&g_nxtermvars.waitSem, &abstime);
|
|
|
|
sched_unlock();
|
|
|
|
|
|
|
|
if (ret == OK && g_nxtermvars.result)
|
|
|
|
{
|
|
|
|
// Re-direct NX keyboard input to the new NxTerm driver
|
|
|
|
|
|
|
|
DEBUGASSERT(g_nxtermvars.nxterm != 0);
|
|
|
|
#ifdef CONFIG_NXTERM_NXKBDIN
|
2019-05-11 23:48:46 +02:00
|
|
|
inxWindow->redirectNxTerm(g_nxtermvars.nxterm);
|
2019-05-08 19:15:44 +02:00
|
|
|
#endif
|
|
|
|
// Save the handle to use in the stop method
|
|
|
|
|
|
|
|
m_nxterm = g_nxtermvars.nxterm;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// sem_timedwait failed OR the NxTerm task reported a
|
|
|
|
// failure. Stop the application
|
|
|
|
|
2019-05-09 21:31:12 +02:00
|
|
|
twmerr("ERROR: Failed start the NxTerm task\n");
|
2019-05-08 19:15:44 +02:00
|
|
|
stop();
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sem_post(&g_nxtermvars.exclSem);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the application.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void CNxTerm::stop(void)
|
|
|
|
{
|
|
|
|
// Delete the NxTerm task if it is still running (this could strand
|
2019-05-11 21:17:19 +02:00
|
|
|
// resources). If we get here due to CTwm4Nx::stopApplication() processing
|
2019-05-08 19:15:44 +02:00
|
|
|
// initialed by CNxTerm::exitHandler, then do *not* delete the task (it
|
|
|
|
// is already being deleted).
|
|
|
|
|
|
|
|
if (m_pid >= 0)
|
|
|
|
{
|
|
|
|
// Calling task_delete() will also invoke the on_exit() handler. We se
|
|
|
|
// m_pid = -1 before calling task_delete() to let the on_exit() handler,
|
|
|
|
// CNxTerm::exitHandler(), know that it should not do anything
|
|
|
|
|
|
|
|
pid_t pid = m_pid;
|
|
|
|
m_pid = -1;
|
|
|
|
|
|
|
|
// Then delete the NSH task, possibly stranding resources
|
|
|
|
|
|
|
|
task_delete(pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy the NX console device
|
|
|
|
|
|
|
|
if (m_nxterm)
|
|
|
|
{
|
|
|
|
// Re-store NX keyboard input routing
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXTERM_NXKBDIN
|
2019-05-11 23:48:46 +02:00
|
|
|
NXWidgets::INxWindow *inxWindow = m_appWindow->getWindow();
|
|
|
|
inxWindow->redirectNxTerm((NXTERM)0);
|
2019-05-08 19:15:44 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Unlink the NxTerm driver
|
|
|
|
// Construct the driver name using this minor number
|
|
|
|
|
|
|
|
char devname[32];
|
|
|
|
snprintf(devname, 32, "/dev/nxterm%d", m_minor);
|
|
|
|
|
|
|
|
(void)unlink(devname);
|
|
|
|
m_nxterm = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the application and free all of its resources. This method
|
|
|
|
* will initiate blocking of messages from the NX server. The server
|
|
|
|
* will flush the window message queue and reply with the blocked
|
|
|
|
* message. When the block message is received by CWindowMessenger,
|
|
|
|
* it will send the destroy message to the start window task which
|
|
|
|
* will, finally, safely delete the application.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void CNxTerm::destroy(void)
|
|
|
|
{
|
|
|
|
// Block any further window messages
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
m_appWindow->block(this);
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
// Make sure that the application is stopped
|
|
|
|
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The application window is hidden (either it is minimized or it is
|
|
|
|
* maximized, but not at the top of the hierarchy
|
|
|
|
*/
|
|
|
|
|
|
|
|
void CNxTerm::hide(void)
|
|
|
|
{
|
|
|
|
// Disable drawing and events
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redraw the entire window. The application has been maximized or
|
|
|
|
* otherwise moved to the top of the hierarchy. This method is call from
|
2019-05-11 21:17:19 +02:00
|
|
|
* CTwm4Nx when the application window must be displayed
|
2019-05-08 19:15:44 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
void CNxTerm::redraw(void)
|
|
|
|
{
|
|
|
|
// Recover the NXTK window instance contained in the application window
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
NXWidgets::INxWindow *inxWindow = m_appWindow->getWindow();
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
// Get the size of the window
|
|
|
|
|
|
|
|
struct nxgl_size_s windowSize;
|
2019-05-11 23:48:46 +02:00
|
|
|
(void)inxWindow->getSize(&windowSize);
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
// Redraw the entire NxTerm window
|
|
|
|
|
|
|
|
struct boardioc_nxterm_redraw_s redraw;
|
|
|
|
|
|
|
|
redraw.handle = m_nxterm;
|
|
|
|
redraw.rect.pt1.x = 0;
|
|
|
|
redraw.rect.pt1.y = 0;
|
|
|
|
redraw.rect.pt2.x = windowSize.w - 1;
|
|
|
|
redraw.rect.pt2.y = windowSize.h - 1;
|
|
|
|
redraw.more = false;
|
|
|
|
|
|
|
|
(void)boardctl(BOARDIOC_NXTERM_KBDIN, (uintptr_t)&redraw);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Report of this is a "normal" window or a full screen window. The
|
|
|
|
* primary purpose of this method is so that window manager will know
|
|
|
|
* whether or not it show draw the task bar.
|
|
|
|
*
|
|
|
|
* @return True if this is a full screen window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool CNxTerm::isFullScreen(void) const
|
|
|
|
{
|
2019-05-11 23:48:46 +02:00
|
|
|
return m_appWindow->isFullScreen();
|
2019-05-08 19:15:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the NxTerm task. This function first redirects output to the
|
|
|
|
* console window then calls to start the NSH logic.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int CNxTerm::nxterm(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
// To stop compiler complaining about "jump to label crosses initialization
|
|
|
|
// of 'int fd'
|
|
|
|
|
|
|
|
int fd = -1;
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
// Set up an on_exit() event that will be called when this task exits
|
|
|
|
|
|
|
|
if (on_exit(exitHandler, g_nxtermvars.console) != 0)
|
|
|
|
{
|
2019-05-09 21:31:12 +02:00
|
|
|
twmerr("ERROR: on_exit failed\n");
|
2019-05-08 19:15:44 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the window handle to create the NX console
|
|
|
|
|
|
|
|
struct boardioc_nxterm_create_s nxcreate;
|
|
|
|
|
|
|
|
nxcreate.nxterm = (FAR void *)0;
|
|
|
|
nxcreate.hwnd = g_nxtermvars.hwnd;
|
|
|
|
nxcreate.wndo = g_nxtermvars.wndo;
|
|
|
|
nxcreate.type = BOARDIOC_XTERM_FRAMED;
|
|
|
|
nxcreate.minor = g_nxtermvars.minor;
|
|
|
|
|
|
|
|
ret = boardctl(BOARDIOC_NXTERM, (uintptr_t)&nxcreate);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-05-09 21:31:12 +02:00
|
|
|
twmerr("ERROR: boardctl(BOARDIOC_NXTERM) failed: %d\n", errno);
|
2019-05-08 19:15:44 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_nxtermvars.nxterm = nxcreate.nxterm;
|
|
|
|
DEBUGASSERT(g_nxtermvars.nxterm != NULL);
|
|
|
|
|
|
|
|
// Construct the driver name using this minor number
|
|
|
|
|
|
|
|
char devname[32];
|
|
|
|
snprintf(devname, 32, "/dev/nxterm%d", g_nxtermvars.minor);
|
|
|
|
|
|
|
|
// Increment the minor number while it is protect by the semaphore
|
|
|
|
|
|
|
|
g_nxtermvars.minor++;
|
|
|
|
|
|
|
|
// Open the NxTerm driver
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXTERM_NXKBDIN
|
|
|
|
fd = open(devname, O_RDWR);
|
|
|
|
#else
|
|
|
|
fd = open(devname, O_WRONLY);
|
|
|
|
#endif
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
2019-05-09 21:31:12 +02:00
|
|
|
twmerr("ERROR: Failed open the console device\n");
|
2019-05-08 19:15:44 +02:00
|
|
|
(void)unlink(devname);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now re-direct stdout and stderr so that they use the NX console driver.
|
|
|
|
// Notes: (1) stdin is retained (file descriptor 0, probably the the serial
|
|
|
|
// console). (2) Don't bother trying to put debug instrumentation in the
|
|
|
|
// following becaue it will end up in the NxTerm window.
|
|
|
|
|
|
|
|
(void)std::fflush(stdout);
|
|
|
|
(void)std::fflush(stderr);
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXTERM_NXKBDIN
|
|
|
|
(void)std::fclose(stdin);
|
|
|
|
#endif
|
|
|
|
(void)std::fclose(stdout);
|
|
|
|
(void)std::fclose(stderr);
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXTERM_NXKBDIN
|
|
|
|
(void)std::dup2(fd, 0);
|
|
|
|
#endif
|
|
|
|
(void)std::dup2(fd, 1);
|
|
|
|
(void)std::dup2(fd, 2);
|
|
|
|
|
|
|
|
#ifdef CONFIG_NXTERM_NXKBDIN
|
|
|
|
(void)std::fdopen(0, "r");
|
|
|
|
#endif
|
|
|
|
(void)std::fdopen(1, "w");
|
|
|
|
(void)std::fdopen(2, "w");
|
|
|
|
|
|
|
|
// And we can close our original driver file descriptor
|
|
|
|
|
|
|
|
if (fd > 2)
|
|
|
|
{
|
|
|
|
std::close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inform the parent thread that we successfully initialized
|
|
|
|
|
|
|
|
g_nxtermvars.result = true;
|
|
|
|
sem_post(&g_nxtermvars.waitSem);
|
|
|
|
|
|
|
|
// Run the NSH console
|
|
|
|
|
|
|
|
#ifdef CONFIG_NSH_CONSOLE
|
|
|
|
(void)nsh_consolemain(argc, argv);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// We get here if the NSH console should exits. nsh_consolemain() ALWAYS
|
|
|
|
// exits by calling nsh_exit() (which is a pointer to nsh_consoleexit())
|
|
|
|
// which, in turn, calls exit()
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
|
|
|
errout:
|
|
|
|
g_nxtermvars.nxterm = 0;
|
|
|
|
g_nxtermvars.result = false;
|
|
|
|
sem_post(&g_nxtermvars.waitSem);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
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 CNxTerm::event(FAR struct SEventMsg *eventmsg)
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
switch (eventmsg->eventID)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2019-05-08 19:15:44 +02:00
|
|
|
/**
|
|
|
|
* This is the NxTerm task exit handler. It registered with on_exit()
|
|
|
|
* and called automatically when the nxterm task exits.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void CNxTerm::exitHandler(int code, FAR void *arg)
|
|
|
|
{
|
|
|
|
CNxTerm *This = (CNxTerm *)arg;
|
|
|
|
|
|
|
|
// If we got here because of the task_delete() call in CNxTerm::stop(),
|
|
|
|
// then m_pid will be set to -1 to let us know that we do not need to do
|
|
|
|
// anything
|
|
|
|
|
|
|
|
if (This->m_pid >= 0)
|
|
|
|
{
|
|
|
|
// Set m_pid to -1 to prevent calling detlete_task() in CNxTerm::stop().
|
|
|
|
// CNxTerm::stop() is called by the processing initiated by the following
|
2019-05-11 21:17:19 +02:00
|
|
|
// call to CTwm4Nx::stopApplication()
|
2019-05-08 19:15:44 +02:00
|
|
|
|
|
|
|
This->m_pid = -1;
|
|
|
|
|
|
|
|
// Remove the NxTerm application from the Start Menu
|
|
|
|
#warning Missing logic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the window minimize button is pressed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void CNxTerm::minimize(void)
|
|
|
|
{
|
|
|
|
m_twm4nx->minimizeApplication(static_cast<IApplication*>(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the window close button is pressed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void CNxTerm::close(void)
|
|
|
|
{
|
|
|
|
m_twm4nx->stopApplication(static_cast<IApplication*>(this));
|
|
|
|
}
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CNxTermFactory Method Implementations
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2019-05-08 19:15:44 +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-08 19:15:44 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
bool CNxTermFactory::initialize(FAR CTwm4Nx *twm4nx)
|
2019-05-11 21:17:19 +02:00
|
|
|
{
|
2019-05-11 23:48:46 +02:00
|
|
|
// Initialize the NSH library
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
if (!nshlibInitialize())
|
2019-05-08 19:15:44 +02:00
|
|
|
{
|
2019-05-11 23:48:46 +02:00
|
|
|
twmerr("ERROR: Failed to initialize the NSH library\n");
|
|
|
|
return false;
|
2019-05-08 19:15:44 +02:00
|
|
|
}
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
// Register an entry with the Main menu. When selected, this will
|
|
|
|
// Case the start
|
2019-05-08 19:15:44 +02:00
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
FAR CMainMenu *cmain = twm4nx->getMainMenu();
|
|
|
|
return cmain->addApplication(this);
|
2019-05-08 19:15:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
bool CNxTermFactory::nshlibInitialize(void)
|
2019-05-08 19:15:44 +02:00
|
|
|
{
|
|
|
|
// Initialize the global data structure
|
|
|
|
|
|
|
|
sem_init(&g_nxtermvars.exclSem, 0, 1);
|
|
|
|
sem_init(&g_nxtermvars.waitSem, 0, 0);
|
|
|
|
|
|
|
|
// Initialize the NSH library
|
|
|
|
|
|
|
|
nsh_initialize();
|
|
|
|
|
|
|
|
// If the Telnet console is selected as a front-end, then start the
|
|
|
|
// Telnet daemon.
|
|
|
|
|
|
|
|
#ifdef CONFIG_NSH_TELNET
|
|
|
|
int ret = nsh_telnetstart(ADDR_FAMILY);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
// The daemon is NOT running!
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-11 23:48:46 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|