cnxterm.hxx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /////////////////////////////////////////////////////////////////////////////
  2. // apps/include/graphics/twm4nx/apps/cnxterm.hxx
  3. //
  4. // Licensed to the Apache Software Foundation (ASF) under one or more
  5. // contributor license agreements. See the NOTICE file distributed with
  6. // this work for additional information regarding copyright ownership. The
  7. // ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. // "License"); you may not use this file except in compliance with the
  9. // License. You may obtain a copy of the License at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. // License for the specific language governing permissions and limitations
  17. // under the License.
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #ifndef __APPS_INCLUDE_GRAPHICS_TWM4NX_APPS_CNXTERM_HXX
  21. #define __APPS_INCLUDE_GRAPHICS_TWM4NX_APPS_CNXTERM_HXX
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Included Files
  24. /////////////////////////////////////////////////////////////////////////////
  25. #include <nuttx/config.h>
  26. #include <sys/types.h>
  27. #include <nuttx/nx/nxtk.h>
  28. #include <nuttx/nx/nxterm.h>
  29. #include "graphics/twm4nx/ctwm4nx.hxx"
  30. #include "graphics/twm4nx/ctwm4nxevent.hxx"
  31. #include "graphics/twm4nx/twm4nx_events.hxx"
  32. #include "graphics/twm4nx/iapplication.hxx"
  33. /////////////////////////////////////////////////////////////////////////////
  34. // Pre-processor Definitions
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CNxTerm application events
  37. // Window Events
  38. #define EVENT_NXTERM_REDRAW (EVENT_RECIPIENT_APP | EVENT_CRITICAL | 0x0000)
  39. #define EVENT_NXTERM_RESIZE (EVENT_RECIPIENT_APP | EVENT_CRITICAL | 0x0001)
  40. #define EVENT_NXTERM_XYINPUT EVENT_SYSTEM_NOP
  41. #define EVENT_NXTERM_KBDINPUT EVENT_SYSTEM_NOP
  42. #define EVENT_NXTERM_DELETE EVENT_WINDOW_DELETE
  43. // Button Events
  44. #define EVENT_NXTERM_CLOSE (EVENT_RECIPIENT_APP | 0x0002)
  45. // Menu Events
  46. #define EVENT_NXTERM_START (EVENT_RECIPIENT_APP | 0x0003)
  47. /////////////////////////////////////////////////////////////////////////////
  48. // Implementation Classes
  49. /////////////////////////////////////////////////////////////////////////////
  50. namespace Twm4Nx
  51. {
  52. /**
  53. * This class implements the NxTerm application.
  54. */
  55. class CNxTerm : public CTwm4NxEvent
  56. {
  57. private:
  58. FAR CTwm4Nx *m_twm4nx; /**< Reference to the Twm4Nx session instance */
  59. FAR CWindow *m_nxtermWindow; /**< Reference to the NxTerm application window */
  60. NXTERM m_NxTerm; /**< NxTerm handle */
  61. pid_t m_pid; /**< Task ID of the NxTerm thread */
  62. int m_minor; /**< Terminal device minor number */
  63. /**
  64. * This is the NxTerm task. This function first redirects output to the
  65. * console window then calls to start the NSH logic.
  66. */
  67. static int nxterm(int argc, char *argv[]);
  68. /**
  69. * Handle Twm4Nx events. This overrides a method from CTwm4NXEvent
  70. *
  71. * @param eventmsg. The received NxWidget WINDOW event message.
  72. * @return True if the message was properly handled. false is
  73. * return on any failure.
  74. */
  75. bool event(FAR struct SEventMsg *eventmsg);
  76. /**
  77. * Handle the NxTerm redraw event.
  78. */
  79. void redraw(void);
  80. /**
  81. * inform NxTerm of a new window size.
  82. */
  83. void resize(void);
  84. /**
  85. * This is the close window event handler. It will stop the NxTerm
  86. * application thread.
  87. */
  88. void stop(void);
  89. public:
  90. /**
  91. * CNxTerm constructor
  92. *
  93. * @param twm4nx. The Twm4Nx session instance
  94. */
  95. CNxTerm(FAR CTwm4Nx *twm4nx);
  96. /**
  97. * CNxTerm destructor
  98. */
  99. ~CNxTerm(void);
  100. /**
  101. * CNxTerm initializers. Perform miscellaneous post-construction
  102. * initialization that may fail (and hence is not appropriate to be
  103. * done in the constructor)
  104. *
  105. * @return True if the NxTerm application was successfully initialized.
  106. */
  107. bool initialize(void);
  108. /**
  109. * Start the NxTerm.
  110. *
  111. * @return True if the NxTerm application was successfully started.
  112. */
  113. bool run(void);
  114. };
  115. class CNxTermFactory : public IApplication,
  116. public IApplicationFactory,
  117. public CTwm4NxEvent
  118. {
  119. private:
  120. FAR CTwm4Nx *m_twm4nx; /**< Twm4Nx session instance */
  121. /**
  122. * One time NSH initialization. This function must be called exactly
  123. * once during the boot-up sequence to initialize the NSH library.
  124. *
  125. * @return True on successful initialization
  126. */
  127. bool nshlibInitialize(void);
  128. /**
  129. * Handle CNxTermFactory events. This overrides a method from
  130. * CTwm4NXEvent
  131. *
  132. * @param eventmsg. The received NxWidget WINDOW event message.
  133. * @return True if the message was properly handled. false is
  134. * return on any failure.
  135. */
  136. bool event(FAR struct SEventMsg *eventmsg);
  137. /**
  138. * Create and start a new instance of an CNxTerm.
  139. */
  140. bool startFunction(void);
  141. /**
  142. * Return the Main Menu item string. This overrides the method from
  143. * IApplication
  144. *
  145. * @param name The name of the application.
  146. */
  147. inline NXWidgets::CNxString getName(void)
  148. {
  149. return NXWidgets::CNxString("NuttShell");
  150. }
  151. /**
  152. * There is no sub-menu for this Main Menu item. This overrides
  153. * the method from IApplication.
  154. *
  155. * @return This implementation will always return a null value.
  156. */
  157. inline FAR CMenus *getSubMenu(void)
  158. {
  159. return (FAR CMenus *)0;
  160. }
  161. /**
  162. * There is no custom event handler. We use the common event handler.
  163. *
  164. * @return. null is always returned in this implementation.
  165. */
  166. inline FAR CTwm4NxEvent *getEventHandler(void)
  167. {
  168. return (FAR CTwm4NxEvent *)this;
  169. }
  170. /**
  171. * Return the Twm4Nx event that will be generated when the Main Menu
  172. * item is selected.
  173. *
  174. * @return. This function always returns EVENT_SYSTEM_NOP.
  175. */
  176. inline uint16_t getEvent(void)
  177. {
  178. return EVENT_NXTERM_START;
  179. }
  180. public:
  181. /**
  182. * CNxTermFactory Constructor
  183. *
  184. * @param twm4nx. The Twm4Nx session instance
  185. */
  186. inline CNxTermFactory(void)
  187. {
  188. m_twm4nx = (FAR CTwm4Nx *)0;
  189. }
  190. /**
  191. * CNxTermFactory Destructor
  192. */
  193. inline ~CNxTermFactory(void)
  194. {
  195. // REVISIT: Would need to remove Main Menu item
  196. }
  197. /**
  198. * CNxTermFactory Initializer. Performs parts of the instance
  199. * construction that may fail. In this implementation, it will
  200. * initialize the NSH library and register an menu item in the
  201. * Main Menu.
  202. */
  203. bool initialize(FAR CTwm4Nx *twm4nx);
  204. };
  205. }
  206. #endif // __APPS_INCLUDE_GRAPHICS_TWM4NX_APPS_CNXTERM_HXX