home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / JUMP.ZIP / JUMP.C < prev    next >
Text File  |  1991-08-16  |  8KB  |  238 lines

  1. /*---------------------------------------------------------------------
  2.  
  3.   This program does the maximizing and minimizing of the 3270 sessions.
  4.   It waits on a JUMP semaphore and when cleared it checks to see if it
  5.   should die.  It tries to request the DIE semaphore with a timeout
  6.   if 1ms.  If the request fails then it waits 1ms and returns with an
  7.   non-zero error code. If the error code is non-zero then that means
  8.   it should not die and do the jump.  If the error code is zero then
  9.   clear the DIE semaphore and close it and end.  The DIE semaphore is
  10.   set in JUMPLDR.EXE and when that exits, it clears the DIE semaphore
  11.   and then clears the JUMP semaphore.
  12.  
  13. ---------------------------------------------------------------------*/
  14. #define INCL_DOS
  15. #define NUL '\0'
  16.  
  17. /* 3270 EHLLAPI bit settings */
  18. #define SETWINDOW 0x01
  19. #define STATUS 0x02
  20. #define ACTIVATE 0x0080
  21. #define MAX 0x0800
  22. #define MIN 0x0400
  23.  
  24. #include <os2.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28.  
  29. #include "jump.h"
  30.  
  31.  
  32. void main()
  33. {
  34.   static char        szSession[26];
  35.   static  char cSelectedSession=NUL;
  36.   static  char cPrevSession=NUL;
  37.   HSYSSEM  hsemJump;
  38.   HSYSSEM  hsemDie;
  39.  
  40.       GetSessions(szSession);
  41.       DosOpenSem(&hsemJump,JUMP_SEM_NAME);
  42.       DosOpenSem(&hsemDie,DIE_SEM_NAME);
  43.       do
  44.       {
  45.          DosSemWait(hsemJump,SEM_INDEFINITE_WAIT);
  46.          if((DosSemRequest(hsemDie,1)))
  47.          {
  48.             SelectSession(szSession,&cSelectedSession,&cPrevSession);
  49.             MinimizePreviousSession(cPrevSession);
  50.             MaximizeNextSession(cSelectedSession);
  51.             DosSemSet(hsemJump);
  52.          }
  53.          else
  54.          {
  55.             DosSemClear( hsemDie );
  56.             DosCloseSem( hsemDie );
  57.             break;
  58.          }
  59.       }
  60.       while (TRUE);
  61. }
  62.  
  63.  
  64. /*---------------------------------------------------------------------
  65.  
  66.  GetSessions puts the active sessions (A-Z) into a null-terminated
  67.  string
  68.  
  69. ---------------------------------------------------------------------*/
  70. void GetSessions(
  71.   PSZ       szSession)
  72. {
  73.    int i;
  74.           strcpy(hll_str," ");
  75.           i=0;
  76.         for ( hll_str[0]='A'; hll_str[0] <= 'Z'; hll_str[0]++ )
  77.         {
  78.           function = 1;
  79.           hll_rtc=0;
  80.           hllapi(&function,hll_str,&str_len,&hll_rtc);
  81.           if (hll_rtc == 0)
  82.           {
  83.              szSession[i] = hll_str[0];
  84.              i++;
  85.              function = 2;
  86.              hll_rtc=0;
  87.              hllapi(&function,hll_str,&str_len,&hll_rtc);
  88.           }
  89.         }
  90.         szSession[i]=NUL;
  91. }
  92.  
  93. /*---------------------------------------------------------------------
  94.  
  95.  SelectSession determines the session to be maximized based on what
  96.  was the last session to be maximized.
  97.  
  98. ---------------------------------------------------------------------*/
  99. void SelectSession(
  100.   PSZ       szSession,
  101.   char *    cSelectedSession,
  102.   char *    cPrevSession)
  103. {
  104.    static int i;
  105.          if (*cPrevSession == NUL)
  106.          {
  107.             i=0;
  108.             *cSelectedSession = szSession[i];
  109.             *cPrevSession = szSession[i];
  110.          }
  111.          else
  112.          {
  113.             *cPrevSession = szSession[i];
  114.             i++;
  115.             if (!szSession[i])
  116.                 i=0;
  117.             *cSelectedSession = szSession[i];
  118.          }
  119.  
  120. }
  121.  
  122. /*---------------------------------------------------------------------
  123.  
  124.  MinimizeSession minimizes the session that most recently maximized
  125.  by this program.  This does not check to see if is already maximized.
  126.  
  127. ---------------------------------------------------------------------*/
  128. void MinimizePreviousSession(
  129.   char  cPrevSession)
  130. {
  131.           /* this never changes */
  132. (struct ServiceData *)fptr = (struct ServiceData *) hdata_str;
  133.           fptr-> xwinpos  =0;
  134.           fptr-> ywinpos  =0;
  135.           fptr-> xwinsize =0;
  136.           fptr-> ywinsize =0;
  137.           fptr-> placement=0;
  138.  
  139.           /* connect to Prev session using connect PM window services*/
  140.           function = 101;
  141.           hll_rtc=0;
  142.           hll_str[1]=0;
  143.           hll_str[0] = cPrevSession;
  144.           str_len = 1;
  145.           hllapi(&function,hll_str,&str_len,&hll_rtc);
  146.           if (hll_rtc != 0)
  147.               printf ("PM Services connection error - session  %c \n",cPrevSession);
  148.  
  149.           /* activate session using PM window services*/
  150.           fptr->session = cPrevSession;
  151.           fptr->option = SETWINDOW;
  152.           fptr->request = ACTIVATE;
  153.           function = 104;
  154.           hll_rtc=0;
  155.           str_len = 16;
  156.           hllapi(&function,(PSZ)fptr,&str_len,&hll_rtc);
  157.           if (hll_rtc != 0)
  158.               printf ("Error Code %i  - activate session %c\n",hll_rtc,cPrevSession);
  159.  
  160.           /* minimize the prev session using PM window services*/
  161.           fptr->session = cPrevSession;
  162.           fptr->option = SETWINDOW;
  163.           fptr->request = MIN;
  164.           function = 104;
  165.           hll_rtc=0;
  166.           str_len = 16;
  167.           hllapi(&function,(PSZ)fptr,&str_len,&hll_rtc);
  168.           if (hll_rtc != 0)
  169.               printf ("Error Code %i  - minimize session \n",hll_rtc,cPrevSession);
  170.  
  171.           /* disconnect PM window services*/
  172.           function = 102;
  173.           hll_str[0] = cPrevSession;
  174.           hll_str[1]=0;
  175.           hll_rtc=0;
  176.           hllapi(&function,hll_str,&str_len,&hll_rtc);
  177.           if (hll_rtc != 0)
  178.               printf ("Error Code %i  - disconnect session %c \n",hll_rtc,cPrevSession);
  179. }
  180.  
  181. /*---------------------------------------------------------------------
  182.  
  183.  MaximizeSession maximizes the session.
  184.  
  185. ---------------------------------------------------------------------*/
  186. void MaximizeNextSession(
  187.   char  cWindow)
  188. {
  189.           /* this never changes */
  190. (struct ServiceData *)fptr = (struct ServiceData *) hdata_str;
  191.           fptr-> xwinpos  =0;
  192.           fptr-> ywinpos  =0;
  193.           fptr-> xwinsize =0;
  194.           fptr-> ywinsize =0;
  195.           fptr-> placement=0;
  196.  
  197.           /* connect to  session using connect PM window services*/
  198.           function = 101;
  199.           hll_rtc=0;
  200.           hll_str[1]=0;
  201.           hll_str[0] = cWindow;
  202.           str_len = 1;
  203.           hllapi(&function,hll_str,&str_len,&hll_rtc);
  204.           if (hll_rtc != 0)
  205.               printf ("PM Services connection error - session  %c \n",cWindow);
  206.  
  207.           /* activate session using PM window services*/
  208.           fptr->session = cWindow;
  209.           fptr->option = SETWINDOW;
  210.           fptr->request = ACTIVATE;
  211.           function = 104;
  212.           hll_rtc=0;
  213.           str_len = 16;
  214.           hllapi(&function,(PSZ)fptr,&str_len,&hll_rtc);
  215.           if (hll_rtc != 0)
  216.               printf ("Error Code %i  - activate session %c\n",hll_rtc,cWindow);
  217.  
  218.           /* minimize the prev session using PM window services*/
  219.           fptr->session = cWindow;
  220.           fptr->option = SETWINDOW;
  221.           fptr->request = MAX;
  222.           function = 104;
  223.           hll_rtc=0;
  224.           str_len = 16;
  225.           hllapi(&function,(PSZ)fptr,&str_len,&hll_rtc);
  226.           if (hll_rtc != 0)
  227.               printf ("Error Code %i  - minimize session \n",hll_rtc,cWindow);
  228.  
  229.           /* disconnect PM window services*/
  230.           function = 102;
  231.           hll_str[0] = cWindow;
  232.           hll_str[1]=0;
  233.           hll_rtc=0;
  234.           hllapi(&function,hll_str,&str_len,&hll_rtc);
  235.           if (hll_rtc != 0)
  236.               printf ("Error Code %i  - disconnect session %c \n",hll_rtc,cWindow);
  237. }
  238.