home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OApp.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  4KB  |  201 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OApp.cpp
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30. // $Header: W:/Projects/OCL/Source/rcs/OApp.cpp 1.50 1996/08/11 23:49:06 B.STEIN Release $
  31.  
  32. #define __OCL_SOURCE__
  33.  
  34. #define OINCL_OSTRING
  35. #define OINCL_BASE
  36.  
  37. #include <ocl.hpp>
  38. #include <OCommand.hpp>
  39. #include <OApp.hpp>
  40.  
  41.  
  42. // OApp
  43.  
  44.  
  45. pOApp OApp::currentOApp = (pOApp)NULL;
  46.  
  47.  
  48. OApp::OApp(ULONG queueSize) 
  49.   : init(queueSize)
  50. {
  51.  if (!OApp::currentOApp)
  52.    OApp::currentOApp = this;
  53. }
  54.  
  55.  
  56. OApp::OApp(const ULONG num, CHAR *Parms[], ULONG queueSize)
  57.   : OAppBase(num, Parms),
  58.     init(queueSize)
  59. {
  60.  if (!OApp::currentOApp)
  61.    OApp::currentOApp = this;
  62. }
  63.  
  64.  
  65. OApp::~OApp() 
  66. {
  67.  if (OApp::currentOApp == this)
  68.    OApp::currentOApp = NULL;
  69. }
  70.  
  71.  
  72. PSZ OApp::isOfType() const
  73.  return("OApp"); 
  74. }
  75.  
  76.  
  77. OApp& OApp::current()
  78. {
  79.  if(OApp::currentOApp)
  80.    return(*OApp::currentOApp);
  81.  else
  82.    throw OVioException(OCL::error(131), 0);
  83. }
  84.  
  85.  
  86. HAB OApp::anchor()
  87. {
  88.  return(init.anchor());
  89. }
  90.  
  91.  
  92. HMQ OApp::mqueue()
  93. {
  94.  return(init.anchor());
  95. }
  96.  
  97.  
  98. BOOL OApp::OCMDTrace(const HWND hwnd,
  99.                      const ULONG msg,
  100.                      const MPARAM mp1,
  101.                      const MPARAM mp2)
  102. {
  103.  pOCommandHandler pcm = (pOCommandHandler) WinQueryWindowULong(hwnd, QWL_USER);
  104.  
  105.  if (pcm) {
  106.    pcm->hwnd = hwnd;
  107.    return(pcm->OCommand(msg, mp1, mp2)); }
  108.  else
  109.    return(FALSE);
  110. }
  111.  
  112.  
  113. BOOL OApp::QuitPosted() 
  114. {
  115.  return(FALSE); 
  116.  
  117. BOOL OApp::TasklistKill() 
  118. {
  119.  return(FALSE); 
  120. }
  121.  
  122.  
  123. BOOL OApp::ShutdownPosted() 
  124. {
  125.  return(FALSE); 
  126. }
  127.  
  128.  
  129. // message loop
  130.  
  131. void OApp::run()
  132. {
  133.  BOOL dispatched = FALSE;
  134.  
  135.  while(TRUE)
  136.    {
  137.     if (!WinGetMsg(init.anchor(), &qmsg, NULLHANDLE, 0, 0))
  138.      {
  139.       if (qmsg.hwnd == NULLHANDLE) {
  140.         if (!ShutdownPosted()) return; }
  141.       else if (qmsg.hwnd == HWNDFROMMP(qmsg.mp2)) {
  142.         if (!TasklistKill()) return; }
  143.       else if (!QuitPosted())
  144.         return;
  145.       else
  146.         dispatched = TRUE;
  147.      }
  148.     else 
  149.       dispatched = FALSE;
  150.  
  151.     if (!dispatched) 
  152.       WinDispatchMsg(init.anchor(), &qmsg);    // default processing
  153.    }
  154. }
  155.  
  156. void OApp::forceQuit()
  157. {
  158.  WinPostMsg(NULLHANDLE, WM_QUIT, NULL, NULL);
  159. }
  160.  
  161.  
  162. pOCommandHandler OApp::NullHandler()
  163. {
  164.  return(&OCMD_NullHandler);
  165. }
  166.  
  167.  
  168. void OApp::Shutdown()
  169. {
  170.  WinShutdownSystem(init.anchor(), init.mqueue());
  171. }
  172.  
  173.  
  174. void OApp::Reboot()
  175. {
  176.  HFILE  hf;
  177.  ULONG  dummy;
  178.  
  179.  if (!DosOpen("DOS$", &hf, &dummy, 0L, FILE_NORMAL, FILE_OPEN,
  180.               OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE | OPEN_FLAGS_FAIL_ON_ERROR, 0L))
  181.   {
  182.    ULONG ulParmLength = 0;
  183.    ULONG ulDataLength = 0;
  184.  
  185.    WinBroadcastMsg(HWND_DESKTOP, WM_CLOSE, NULL, NULL, BMSG_SEND | BMSG_DESCENDANTS);
  186.    SyncDisks();
  187.    DosSleep(2000);
  188.    DosBeep(100, 1000);
  189.    DosShutdown(0L);
  190.    DosDevIOCtl(hf, 0xd5, 0xab,           // Reboot
  191.                NULL, 0L, &ulParmLength,
  192.                NULL, 0L, &ulDataLength );
  193.    DosClose(hf);
  194.   }
  195. }
  196.  
  197.  
  198. // end of source
  199.