home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / desktop / t / utils / !Logger_C_PMFE < prev    next >
Encoding:
Text File  |  1992-10-24  |  5.3 KB  |  271 lines

  1. /*
  2.  *
  3.  *      Title     : Presentation Manager Front End
  4.  *      System    : Logger */
  5. #define Version     "1.0"
  6. /*      Copyright : John H. Winters
  7.  *      Date      : 18th October, 1992
  8.  *      Author    : John H. Winters
  9.  *
  10.  *      Function  : Handles the Presentation Manager front end.
  11.  *
  12.  *
  13.  *      Modification history.
  14.  *
  15.  *      Version   :
  16.  *      Date      :
  17.  *      Author    :
  18.  *      Changes   :
  19.  *
  20.  */
  21.  
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include <time.h>
  26. #include <process.h>
  27. #define INCL_WINFRAMEMGR
  28. #define INCL_WINPOINTERS
  29. #include <os2.h>
  30.  
  31. #include "global.h"
  32. #include "logging.h"
  33. #include "fe.h"
  34. #include "text.h"
  35.  
  36. /*
  37.  *============================================================================
  38.  *
  39.  *  Hash defines.
  40.  *
  41.  *============================================================================
  42.  */
  43.  
  44. #define STACK_SIZE 2048
  45.  
  46. /*
  47.  *============================================================================
  48.  *
  49.  *  Local data.
  50.  *
  51.  *============================================================================
  52.  */
  53.  
  54. static uint         AutoDisplay   = FALSE ;
  55. static t_TXT_Handle TextHandle    = NULL ;
  56. static uint         ThreadLooping = FALSE ;
  57. static uint         WindowReady   = FALSE ;
  58.  
  59. /*
  60.  *============================================================================
  61.  *
  62.  *  Forward declarations.
  63.  *
  64.  *============================================================================
  65.  */
  66.  
  67. static void PM_Thread (
  68.     void *reference) ;
  69.  
  70. /*
  71.  *============================================================================
  72.  *
  73.  *  Externally visible routines.
  74.  *
  75.  *============================================================================
  76.  */
  77.  
  78. uint FE_BeginProcessing (void)
  79.  
  80. /*
  81.  *  Function :
  82.  *                  Start PM processing.
  83.  *
  84.  *  Parameters :
  85.  *                  None.
  86.  *
  87.  *  Returns :
  88.  *                  TRUE for success, FALSE for failure.
  89.  *
  90.  */
  91.  
  92. {
  93.     sint thread ;
  94.  
  95.     thread = _beginthread (PM_Thread,
  96.                            NULL,
  97.                            STACK_SIZE,
  98.                            NULL) ;
  99.     if (thread == -1)
  100.     {
  101.         LOG_Error ("Failed to start PM thread.\n") ;
  102.         return (FALSE) ;
  103.     }
  104.     else
  105.     {
  106.         return (TRUE) ;
  107.     }
  108. }
  109.  
  110.  
  111. uint FE_LoadResources (void)
  112.  
  113. /*
  114.  *  Function :
  115.  *                  Null routine for now.
  116.  *
  117.  *  Parameters :
  118.  *                  None.
  119.  *
  120.  *  Returns :
  121.  *                  TRUE.
  122.  *
  123.  */
  124.  
  125. {
  126.     return (TRUE) ;
  127. }
  128.  
  129.  
  130. void FE_PutText (
  131.     const U8 *text)
  132.  
  133. /*
  134.  *  Function :
  135.  *                  Put text to our window.  May be called recursively and
  136.  *                  must cope.  Will not be called simultaneously from
  137.  *                  separate threads.
  138.  *
  139.  *  Parameters :
  140.  *                  text    The text to put.
  141.  *
  142.  *  Returns :
  143.  *                  None.
  144.  *
  145.  */
  146.  
  147. {
  148.     static uint WindowInUse = FALSE ;
  149.  
  150.     if ((WindowReady) &&
  151.         (!WindowInUse))
  152.     {
  153.         WindowInUse = TRUE ;
  154.         if (AutoDisplay)
  155.         {
  156.             TXT_DisplayWindow (TextHandle) ;
  157.         }
  158.         TXT_PutText (TextHandle, text) ;
  159.         WindowInUse = FALSE ;
  160.     }
  161.     else
  162.     {
  163.         /*
  164.          *  Need to pop up a PM error box.
  165.          */
  166.         WinMessageBox (HWND_DESKTOP,
  167.                        HWND_DESKTOP,
  168.                        (u8 *) text,
  169.                        NULL,
  170.                        0,
  171.                        MB_NOICON | MB_OK) ;
  172.     }
  173. }
  174.  
  175.  
  176. void FE_WindDown (void)
  177.  
  178. /*
  179.  *  Function :
  180.  *                  Instructs the front end to close itself down.
  181.  *
  182.  *  Parameters :
  183.  *                  None.
  184.  *
  185.  *  Returns :
  186.  *                  None.
  187.  *
  188.  */
  189.  
  190. {
  191.     /*
  192.      *  What we do is send a message to the front end telling it the
  193.      *  user has clicked on Close.
  194.      */
  195.     if (ThreadLooping)
  196.     {
  197.         TXT_HideWindow (TextHandle) ;
  198.     }
  199. }
  200.  
  201. /*
  202.  *============================================================================
  203.  *
  204.  *  Local routines.
  205.  *
  206.  *============================================================================
  207.  */
  208.  
  209. static void PM_Thread (
  210.     void *reference)
  211.  
  212. /*
  213.  *  Function :
  214.  *                  Presentation Manager polling thread.
  215.  *
  216.  *  Parameters :
  217.  *                  reference   Ignored.
  218.  *
  219.  *  Returns :
  220.  *                  None.
  221.  *
  222.  */
  223.  
  224. {
  225.     HAB  hab ;
  226.     HMQ  hmq ;
  227.     QMSG qmsg ;
  228.  
  229.     reference = reference ;
  230.     hab = WinInitialize (0) ;
  231.     if (hab == NULL)
  232.     {
  233.         LOG_Error ("Failed to initialize PM.\n") ;
  234.     }
  235.     else
  236.     {
  237.         hmq = WinCreateMsgQueue (hab, DEFAULT_QUEUE_SIZE) ;
  238.         if (hmq == NULL)
  239.         {
  240.             LOG_Error ("Failed to create message queue.\n") ;
  241.         }
  242.         else
  243.         {
  244.             TextHandle = TXT_CreateWindow (hab,
  245.                                            20,
  246.                                            128) ;
  247.             if (TextHandle == NULL)
  248.             {
  249.                 LOG_Error ("Failed to create a text window.\n") ;
  250.             }
  251.             else
  252.             {
  253.                 if (TXT_DisplayWindow (TextHandle))
  254.                 {
  255.                     ThreadLooping = TRUE ;
  256.                     while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  257.                     {
  258.                         WinDispatchMsg (hab, &qmsg) ;
  259.                     }
  260.                     ThreadLooping = FALSE ;
  261.                 }
  262.                 TXT_HideWindow (TextHandle) ;
  263.             }
  264.             WinDestroyMsgQueue (hmq) ;
  265.         }
  266.         WinTerminate (hab) ;
  267.     }
  268.     exit (0) ;
  269. }
  270.  
  271.