home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / nettos11.zip / QMS / XQJOB.PRG < prev   
Text File  |  1993-02-23  |  11KB  |  286 lines

  1. /*
  2.  * File......: XQJOB.PRG
  3.  * Author....: Glenn Scott
  4.  * CIS ID....: 71620,1521
  5.  * Date......: $Date$
  6.  * Revision..: $Revision$
  7.  * Log file..: $Logfile$
  8.  *
  9.  * This is an original work by Glenn Scott and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log$
  16.  *
  17.  */
  18.  
  19. #include "netto.ch"
  20.  
  21.  
  22. /* -----------------------------------------------------------------
  23.    _fnJs2Pkt( <aJob> ) -> cPkt
  24.    -----------------------------------------------------------------
  25.  
  26.    Converts a queue job structure to a valid packet suitable for
  27.    sending to a NetWare API call like CreateQueueJobAndFile().
  28.    Does some special translations as follows:
  29.  
  30.      -  Converts all the logical flags like AutoStart and Restart
  31.         to a one byte "flags" variable by setting the various bits
  32.      -  Converts date/time pairs to 6 byte NetWare date/time strings
  33.  
  34. */
  35.  
  36. /* ------------------------------------------------------------------ */
  37.  
  38. function _fnJs2pkt( aJob )
  39.    local cPkt, cFlags := chr(0)
  40.  
  41.    /* This could probably use some optimizing: */
  42.  
  43.    cFlags := iif( aJob[ QJ_AUTOSTART ],    ft_bitset( cFlags, 3 ), cFlags )
  44.    cFlags := iif( aJob[ QJ_RESTART   ],    ft_bitset( cFlags, 4 ), cFlags )
  45.    cFlags := iif( aJob[ QJ_ENTRYOPEN ],    ft_bitset( cFlags, 5 ), cFlags )
  46.    cFlags := iif( aJob[ QJ_USERHOLD  ],    ft_bitset( cFlags, 6 ), cFlags )
  47.    cFlags := iif( aJob[ QJ_OPERATORHOLD ], ft_bitset( cFlags, 7 ), cFlags )
  48.  
  49.    cPkt :=    I2BYTE(    aJob[ QJ_CLIENT_STATION     ]   ) +   ;
  50.               I2BYTE(    aJob[ QJ_CLIENT_TASK        ]   ) +   ;
  51.               L2HILO(    aJob[ QJ_CLIENT_ID          ]   ) +   ;
  52.               L2HILO(    aJob[ QJ_TARGET_SERVER      ]   ) +   ;
  53.            _fnDt2Str(    aJob[ QJ_TARGET_EXEC_DATE   ],        ;
  54.                          aJob[ QJ_TARGET_EXEC_TIME   ]         ;
  55.                     )                                      +   ;
  56.            _fnDt2Str(    aJob[ QJ_JOB_ENTRY_DATE     ],        ;
  57.                          aJob[ QJ_JOB_ENTRY_TIME     ]         ;
  58.                     )                                      +   ;
  59.               W2HILO(    aJob[ QJ_JOB_NUMBER         ]   ) +   ;
  60.               W2HILO(    aJob[ QJ_JOB_TYPE           ]   ) +   ;
  61.               I2BYTE(    aJob[ QJ_JOB_POSITION       ]   ) +   ;
  62.               cFlags                                       +   ;
  63.               padr(      aJob[ QJ_JOB_FILE_NAME      ],14) +   ;
  64.                          aJob[ QJ_JOB_FILE_HANDLE    ]     +   ;
  65.               I2BYTE(    aJob[ QJ_SERVER_STATION     ]   ) +   ;
  66.               I2BYTE(    aJob[ QJ_SERVER_TASK        ]   ) +   ;
  67.               L2HILO(    aJob[ QJ_SERVER_ID          ]   ) +   ;
  68.                 padr(    aJob[ QJ_JOB_DESCRIPTION    ],50) +   ;
  69.                          aJob[ QJ_CLIENT_RECORD_AREA ]
  70.  
  71.    return cPkt
  72.  
  73.  
  74. /* -----------------------------------------------------------------
  75.    _fnPkt2Js( <cPkt> ) -> aJob
  76.    -----------------------------------------------------------------
  77.  
  78.    Converts a queue job entry structure from it's native NetWare
  79.    format (a long character string) to the NetWare toolkit
  80.    standard JOBSTRUCT array.
  81.  
  82.    Does some special translations as follows:
  83.  
  84.      -  Converts the one-byte "flags" variable to a series of
  85.         five logicals
  86.      -  Converts 6 byte NetWare date/time strings to date/time pairs
  87.  
  88. */
  89.  
  90. /* ------------------------------------------------------------------ */
  91.  
  92. function _fnpkt2js( cPkt )
  93.    local aJob, aDtEx, aDtEn, cFlags
  94.  
  95.    aDtEx  := _fnStr2Dt( subs( cPkt, 11, 6 ) )
  96.    aDtEn  := _fnStr2Dt( subs( cPkt, 17, 6 ) )
  97.    cFlags := subs( cPkt, 28, 1 )
  98.  
  99.    aJob := _fnqjob( BYTE2I( subs( cPkt,  1,  1 ) ) , ;
  100.                     BYTE2I( subs( cPkt,  2,  1 ) ) , ;
  101.                     HILO2L( subs( cPkt,  3,  4 ) ) , ;
  102.                     HILO2L( subs( cPkt,  7,  4 ) ) , ;
  103.                     aDtEx[1]                       , ;
  104.                     aDtEx[2]                       , ;
  105.                     aDtEn[1]                       , ;
  106.                     aDtEn[2]                       , ;
  107.                     HILO2W( subs( cPkt, 23,  2 ) ) , ;
  108.                     HILO2W( subs( cPkt, 25,  2 ) ) , ;
  109.                     BYTE2I( subs( cPkt, 27,  1 ) ) , ;
  110.                     subs( cPkt, 29, 14 )           , ;
  111.                     subs( cPkt, 43,  6 )           , ;
  112.                     BYTE2I( subs( cPkt, 49,  1 ) ) , ;
  113.                     BYTE2I( subs( cPkt, 50,  1 ) ) , ;
  114.                     HILO2L( subs( cPkt, 51,  4 ) ) , ;
  115.                     subs( cPkt, 55, 50 )           , ;
  116.                     subs( cPkt, 105    )             ;
  117.                   )
  118.  
  119.    aJob[ QJ_AUTOSTART    ] := ft_isbit( cFlags, 3 )
  120.    aJob[ QJ_RESTART      ] := ft_isbit( cFlags, 4 )
  121.    aJob[ QJ_ENTRYOPEN    ] := ft_isbit( cFlags, 5 )
  122.    aJob[ QJ_USERHOLD     ] := ft_isbit( cFlags, 6 )
  123.    aJob[ QJ_OPERATORHOLD ] := ft_isbit( cFlags, 7 )
  124.  
  125.    return aJob
  126.  
  127. /* ------------------------------------------------------------------ */
  128.  
  129. /*  $DOC$
  130.  *  $FUNCNAME$
  131.  *     CREATE JOBSTRUCT
  132.  *  $CATEGORY$
  133.  *     Queue
  134.  *  $ONELINER$
  135.  *     Create a QMS Job Structure (array) the easy way
  136.  *  $SYNTAX$
  137.  *
  138.  *     CREATE JOBSTRUCT <aJob>               ;
  139.  *       [ QUEUE SERVER          <nTarg>   ] ;
  140.  *       [ STARTDATE             <dXdate>  ] ;
  141.  *       [ STARTTIME             <cXtime>  ] ;
  142.  *       [ JOB TYPE              <nType>   ] ;
  143.  *       [ AUTOSTART                       ] ;
  144.  *       [ RESTART                         ] ;
  145.  *       [ USERHOLD                        ] ;
  146.  *       [ OPERATORHOLD                    ] ;
  147.  *       [ JOB DESCRIPTION       <cDesc>   ] ;
  148.  *       [ CLIENT RECORD AREA    <cCliRec> ]
  149.  *
  150.  *
  151.  *  $ARGUMENTS$
  152.  *
  153.  *       QUEUE SERVER         <nTarg>
  154.  *
  155.  *         Queue Server Binder ObjectID, or -1 if any server.
  156.  *         Defaults to -1 (any server).
  157.  *
  158.  *       STARTDATE            <dXdate>
  159.  *
  160.  *         Date you want job serviced.  Defaults to ASAP.
  161.  *
  162.  *       STARTTIME            <cXtime>
  163.  *
  164.  *         Time you want job serviced.  Defaults to ASAP.
  165.  *
  166.  *       JOB TYPE              <nType>
  167.  *
  168.  *         Job type.  Up to queue servers to determine valid job types.
  169.  *         Defaults to 0.
  170.  *
  171.  *       AUTOSTART
  172.  *
  173.  *         If specified, the job will start upon a break to the job server
  174.  *         connection, even if you have not explicitly started the job.  If
  175.  *         AUTOSTART is omitted and there is a connection break before you
  176.  *         have release the job to the queue, the job will be removed from
  177.  *         the queue.  Defaults to no AUTOSTART.
  178.  *
  179.  *       RESTART
  180.  *
  181.  *         If specified and the queue server for some reason aborts the job,
  182.  *         the job will remain in the queue.  Otherwise the job is removed
  183.  *         from the queue.  Defaults to no RESTART.
  184.  *
  185.  *       USERHOLD
  186.  *
  187.  *         If specified the job will continue the advance in the queue but
  188.  *         will not be serviced until the user releases this flag.  Defaults
  189.  *         to no USERHOLD
  190.  *
  191.  *       OPERATORHOLD
  192.  *
  193.  *         Same as for USERHOLD, however only queue operators may clear or
  194.  *         set this flag.  Defaults to no OPERATORHOLD
  195.  *
  196.  *       JOB DESCRIPTION       <cDesc>
  197.  *
  198.  *         Text job description.  Max len=50 char.
  199.  *
  200.  *       CLIENT RECORD AREA    <cCliRec>
  201.  *
  202.  *         Free area for queue servers to define.  You may use this area
  203.  *         to send information to custom queue servers that you devise.
  204.  *         NetWare Print Servers require a specially formatted client area;
  205.  *         use CREATE PRINTJOB to make it.  Max Len=152 char.
  206.  *
  207.  *  $RETURNS$
  208.  *
  209.  *      <aJob>, an array that should be considered a "queue job entry
  210.  *      structure."  You will pass this to other QMS API calls that
  211.  *      require such a structure.
  212.  *
  213.  *      The elements of the array are referenced with the QJ_ constants
  214.  *      in netto.CH
  215.  *
  216.  *  $DESCRIPTION$
  217.  *
  218.  *      There are several steps involved when using the Novell QMS system,
  219.  *      a very important one of which is setting up a proper job
  220.  *      structure.
  221.  *
  222.  *      This command helps you create the front end of a queue job entry
  223.  *      structure.  Use it in conjuction with CREATE PRINTJOB to create
  224.  *      jobs for a Novell Print Server.
  225.  *
  226.  *      For people who are writing client-server applications, you will
  227.  *      want to define your own Client Record Area.  See a Novell API
  228.  *      reference manual for a complete description of the queue job
  229.  *      entry structure.
  230.  *
  231.  *  $EXAMPLES$
  232.  *
  233.  *  $SEEALSO$
  234.  *      "CREATE PRINTJOB"
  235.  *  $INCLUDE$
  236.  *
  237.  *  $END$
  238.  */
  239.  
  240. function  _fnqjob( nClient,  nTask,   nCliID, nTarg,  dXdate, cXtime,     ;
  241.                    dEdate,   cEtime,  nNum,   nType,  nPos,   lAutoStart, ;
  242.                    lReStart, lOpen,   lUHold, lOHold, cFile,  cHandle,    ;
  243.                    nSerSta,  nSerTsk, nSerID, cDesc,  cCliRec )
  244.  
  245.   /*
  246.    *      Note that _fnQjob() doesn't validate what the user sends in;
  247.    *      i.e,. he could really screw it up with invalid types.
  248.    *      Caveat emptor.
  249.    */
  250.  
  251.   default nClient    to 0,;
  252.           nTask      to 0,;
  253.           nCliID     to 0,;
  254.           nTarg      to -1,;
  255.           dXdate     to ctod("  /  /  "),;   // is this getting converted?
  256.           cXtime     to "99:99:99",;
  257.           dEdate     to ctod("  /  /  "),;
  258.           cEtime     to "99:99:99",;
  259.           nNum       to 0,;
  260.           nType      to 0,;
  261.           nPos       to 0,;
  262.           lAutostart to .f.,;              // What should these defaults be?
  263.           lReStart   to .f.,;
  264.           lOpen      to .f.,;
  265.           lUHold     to .f.,;
  266.           lOHold     to .f.,;
  267.           cFile      to REPLICATE( CHR(0), 14 ),;
  268.           cHandle    to REPLICATE( CHR(0), 6 ),;
  269.           nSerSta    to 0,;
  270.           nSerTsk    to 0,;
  271.           nSerID     to 0,;
  272.           cDesc      to REPLICATE( CHR(0),  50 ),;
  273.           cCliRec    to REPLICATE( CHR(0), 152 )
  274.  
  275.   cDesc    := padr( subs( cDesc,   1,  49 ),  50, CHR(0) )
  276.   cCliRec  := padr( subs( cCliRec, 1, 151 ), 152, CHR(0) )
  277.  
  278.  
  279.   return { nClient,  nTask,   nCliID, nTarg,  dXdate, cXtime, ;
  280.            dEdate,   cEtime,  nNum,   nType,  nPos,   lAutoStart, ;
  281.            lReStart, lOpen,   lUHold, lOHold, cFile,  cHandle,    ;
  282.            nSerSta,  nSerTsk, nSerID, cDesc,  cCliRec ;
  283.          }
  284.  
  285. /* ------------------------------------------------------------------ */
  286.