home *** CD-ROM | disk | FTP | other *** search
/ CDUTIL 13 / CDUTIL #13 Julio 1995.iso / windows / acadcom / acrx / sample / appmngr.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  12.9 KB  |  389 lines

  1. /* Next available MSG number is  33 */
  2.  
  3. /***************************************************************************
  4.    Module Name:  appmngr.cc
  5.  
  6.    Copyright (C) 1994 by Autodesk, Inc.
  7.  
  8.    Permission to use, copy, modify, and distribute this software in 
  9.    object code form for any purpose and without fee is hereby granted, 
  10.    provided that the above copyright notice appears in all copies and 
  11.    that both that copyright notice and the limited warranty and 
  12.    restricted rights notice below appear in all supporting 
  13.    documentation.
  14.  
  15.    AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  
  16.    AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF 
  17.    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC.
  18.    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE 
  19.    UNINTERRUPTED OR ERROR FREE.
  20.  
  21.    Use, duplication, or disclosure by the U.S. Government is subject to 
  22.    restrictions set forth in FAR 52.227-19 (Commercial Computer 
  23.    Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) 
  24.    (Rights in Technical Data and Computer Software), as applicable.
  25.     
  26.    .
  27.  
  28.    Description:  App loads and unloads a series of ADS apps, and displays
  29.                  The currently loaded ADS and RXADS applications.
  30.  
  31.    Author     :
  32.                  Autodesk, Inc.
  33.                  2320 Marinship Way
  34.                  Sausalito, CA. 94965
  35.                  (415)332-2344
  36.  
  37.     This Arx application is a conversion from the original sample ADS app
  38.     appmngr.c.
  39.  
  40.     CREATED BY:  William Howison, January 1994
  41.  
  42.     What it tests :
  43.  
  44.     - Loading of old style ADS applications.
  45.       ads_xload
  46.  
  47.     - Unloading of old style ADS applications.
  48.       ads_xunload
  49.  
  50.     - Listing currently loaded old and new style ADS applications.
  51.       ads_loaded
  52.  
  53.     Function Entry Points:
  54.       AcRx::AppRetCode
  55.         acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt);
  56.  
  57.     Exported ADS Functions
  58.         TESTXLOAD                 [Test ADS_ XLOAD/XUNLOAD/LOADED functions]
  59.  
  60.     Modification History:
  61.         Jan 27 1994 - bch - original creation
  62.  
  63.     Notes and restrictions on use:
  64.  
  65.  
  66. ***************************************************************************/
  67.  
  68. /**************************************************************************/
  69. /*  MODULE NAME  */
  70. /**************************************************************************/
  71. #define    APPMNGR
  72.  
  73. /****************************************************************************/
  74. /*  DEFINES  */
  75. /****************************************************************************/
  76. #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
  77.  
  78. /**************************************************************************/
  79. /*  TYPEDEFS  */
  80. /**************************************************************************/
  81. /* ADS Function Table */
  82. typedef struct {
  83.     char    *name;
  84.     int     (*fptr)();
  85. } ftblent;
  86.  
  87. typedef struct resbuf rbtype;
  88.  
  89. /**************************************************************************/
  90. /*  INCLUDES  */
  91. /**************************************************************************/
  92.  
  93. #include <math.h>
  94. #include <stdio.h>
  95. #include <string.h>
  96. #include "adslib.h"
  97. #include "rxdefs.h"
  98. #include "adesk.h"
  99. #include "ol_errno.h"
  100.  
  101. /****************************************************************************/
  102. /*  LOCALLY DEFINED ENTRY POINTS INVOKED BY Arx                              */
  103. /****************************************************************************/
  104. extern "C" {
  105. void acrxAnalyzeSystem();
  106. AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt);
  107.  
  108. }
  109.  
  110. /****************************************************************************/
  111. /*  LOCAL FUNCTION FORWARD DECLARATIONS  */
  112. /****************************************************************************/
  113. int     testappmngr();
  114.  
  115. /**************************************************************************/
  116. /*  GLOBAL VARIABLES  */
  117. /**************************************************************************/
  118. /* Table of ADS functions */
  119. ftblent exfun[] = {
  120.             {/*MSG0*/"C:TESTAPPMNGR", testappmngr},
  121.         };
  122.  
  123. /* Table of ADS applications */
  124. char    *AppTable[] = {
  125.             /*MSG0*/"ads_perr",
  126. #if 0
  127.             /*MSG0*/"appmngr",
  128. #endif
  129.             /*MSG0*/"arbmat",
  130.             /*MSG0*/"asctext",
  131.             /*MSG0*/"colext",
  132.             /*MSG0*/"dlgtest",
  133.             /*MSG0*/"dragger",
  134.             /*MSG0*/"fact",
  135.             /*MSG0*/"gpalsym",
  136.             /*MSG0*/"gravity",
  137.             /*MSG0*/"magnets",
  138.             /*MSG0*/"project",
  139.             /*MSG0*/"ptext",
  140.             /*MSG0*/"sld2ps",
  141.             /*MSG0*/"sqr",
  142.             /*MSG0*/"tower",
  143.         };
  144.  
  145. /**************************************************************************/
  146. /*  EXTERNAL FUNCTION DECLARATIONS  */
  147. /**************************************************************************/
  148.  
  149. /**************************************************************************/
  150. /*  EXTERNAL VARIABLE DECLARATIONS  */
  151. /**************************************************************************/
  152.  
  153. /****************************************************************************/
  154. /*  LOCAL FUNCTION DECLARATIONS  */
  155. /****************************************************************************/
  156.  
  157. int funcload   _((void));
  158. int funcunload _((void));
  159. int dofun      _((void));
  160. int geterrno   _((void));
  161.  
  162. /******************************************************************************/
  163. /*.doc geterrno(internal) */
  164. /*+
  165.     This function is called to obtain the value of the AutoCAD system
  166.     variable ERRNO and return it as a result.
  167. -*/
  168. /******************************************************************************/
  169. int
  170. /*FCN*/geterrno()
  171. {
  172.     rbtype errval;
  173.  
  174.     ads_getvar(/*MSG0*/"ERRNO", &errval);
  175.  
  176.     return errval.resval.rint;
  177. }
  178.  
  179. /******************************************************************************/
  180. /*.doc funcload(internal) */
  181. /*+
  182.     This function is called to define all function names in the ADS
  183.     function table.  Each named function will be callable from lisp or
  184.     invokable from another ADS application.
  185. -*/
  186. /******************************************************************************/
  187. int
  188. /*FCN*/funcload()
  189. {
  190.     int i;
  191.  
  192.     for (i = 0; i < ELEMENTS(exfun); i++) {
  193.         if (!ads_defun(exfun[i].name, i))
  194.             return RTERROR;
  195.     }
  196.  
  197.     return RTNORM;
  198. }
  199.  
  200. /******************************************************************************/
  201. /*.doc funclunoad(internal) */
  202. /*+
  203.     This function is called to undefine all function names in the ADS
  204.     function table.  Each named function will be removed from the
  205.     AutoLISP hash table.
  206. -*/
  207. /******************************************************************************/
  208. int
  209. /*FCN*/funcunload()
  210. {
  211.     int i;
  212.  
  213.     /* Undefine each function we defined */
  214.  
  215.     for (i = 0; i < ELEMENTS(exfun); i++) {
  216.         ads_undef(exfun[i].name,i);
  217.     }
  218.  
  219.     return RTNORM;
  220. }
  221. /******************************************************************************/
  222. /*.doc dofun(internal) */
  223. /*+
  224.     This function is called to invoke the function which has the
  225.     registerd function code that is obtained from  ads_getfuncode.  The
  226.     function will return RTERROR if the function code is invalid, or
  227.     RSERR if the invoked function fails to return RTNORM.  The value
  228.     RSRSLT will be returned if the function code is valid and the
  229.     invoked subroutine returns RTNORM.
  230. -*/
  231. /******************************************************************************/
  232. int
  233. /*FCN*/dofun()
  234. {
  235.     int    val;
  236.     int    rc;
  237.  
  238.     ads_retvoid();
  239.         
  240.     if ((val = ads_getfuncode()) < 0 || val > ELEMENTS(exfun))
  241.         return RTERROR;
  242.  
  243.     rc = (*exfun[val].fptr)();
  244.  
  245.     return ((rc == RTNORM) ? RSRSLT:RSERR);
  246. }
  247.  
  248. /******************************************************************************/
  249. /*.doc testappmngr(internal) */
  250. /*+
  251.     This function is called from dofun function as a result of RQSUBR
  252.     request being sent to the main dispatch loop.
  253.  
  254.     The function will walk thru the AppTable and perform an ADS_XLOAD
  255.     on each application.  The message Loading apname... will be printed
  256.     before each application is attempted to be loaded.  If the load
  257.     fails, then the message will be followed by the messaged FAILED..
  258.  
  259.     The next phase of the test will make a call to the function
  260.     ADS_LOADED to obtain the list of currently loaded applications.  It
  261.     will then walk thu the list and perform an ADS_XUNLOAD on each
  262.     application.  The message Unloading appname... will be printed
  263.     before each application is attempted to be unloaded.  Note, that
  264.     some applications may generate messages of their own, so the output
  265.     may not be exactly as described.  If an application fails to be
  266.     unloaded, then the message FAILED will follow the unloading
  267.     message.
  268.  
  269.     This function always returns RTNORM.
  270. -*/
  271. /******************************************************************************/
  272. int
  273. /*FCN*/testappmngr()
  274. {
  275.     rbtype      *args;
  276.     rbtype      *tapl;
  277.     rbtype      *applist;
  278.     int         x;
  279.     int         i;
  280.     int         pcount;
  281.  
  282.     args = ads_getargs();
  283.     ads_printf(/*MSG3*/"\nPerforming ads_xload, ads_xunload, and ads_loaded test\n");
  284.     pcount = 5;
  285.     if (args != NULL) {
  286.         if (args->restype == RTSHORT)
  287.             pcount = args->resval.rint;
  288.     }
  289.  
  290.     for (i = 1; i <= pcount; i++) {
  291.         ads_printf(/*MSG4*/"\n\n\nPass %d.\n\n\n", i);
  292.         for (x = 0; x < ELEMENTS(AppTable); x++) {
  293.             ads_printf(/*MSG5*/"Loading %s...\n", AppTable[x]);
  294.             if (ads_xload(AppTable[x]) != RTNORM)
  295.                 switch(geterrno()) {
  296.                 case OL_ENULLPTR:
  297.                     ads_printf(/*MSG6*/"Filename argument was a NULL pointer.\n");
  298.                     break;
  299.                 case OL_EOPEN:
  300.                     ads_printf(/*MSG7*/"Specified file could not be opened.\n");
  301.                     break;
  302.                 case OL_ELOADED:
  303.                     ads_printf(/*MSG8*/"Specified file is already loaded.\n");
  304.                     break;
  305.                 case OL_ENOMEM:
  306.                     ads_printf(/*MSG9*/"No room for app control block.\n");
  307.                     break;
  308.                 case OL_EMAXAPP:
  309.                     ads_printf(/*MSG10*/"Max number of ADS apps loaded.\n");
  310.                     break;
  311.                 case OL_EEXEC:
  312.                     ads_printf(/*MSG11*/"App could not be executed.\n");
  313.                     break;
  314.                 case OL_EVERSION:
  315.                     ads_printf(/*MSG12*/"App contains wrong ADS version #.\n");
  316.                     break;
  317.                 }
  318.         }
  319.  
  320.         for (tapl = applist = ads_loaded(); tapl != NULL; tapl = tapl->rbnext) {
  321.             if (tapl->restype == RTSTR && tapl->resval.rstring != NULL) {
  322.                 ads_printf(/*MSG13*/"Unloading %s...\n", tapl->resval.rstring);
  323.                 if (ads_xunload(tapl->resval.rstring) != RTNORM)
  324.                     switch(geterrno()) {
  325.                     case OL_ENULLPTR:
  326.                         ads_printf(/*MSG14*/"Filename argument was a NULL pointer.\n");
  327.                         break;
  328.                     case OL_EDENIED:
  329.                         ads_printf(/*MSG15*/"An app cannot unload itself this way,\n");
  330.                         ads_printf(/*MSG16*/"and nested apps cannot be unloaded.\n");
  331.                         break;
  332.                     case OL_EREFUSE:
  333.                         ads_printf(/*MSG17*/"App refused to unload.\n");
  334.                         break;
  335.                     case OL_ENOTLOADED:
  336.                         ads_printf(/*MSG18*/"App is not loaded, so it\n");
  337.                         ads_printf(/*MSG19*/"cannot be unloaded.\n");
  338.                         break;
  339.                     }
  340.             }
  341.         }
  342.  
  343.         if (applist != NULL)
  344.             ads_relrb(applist);
  345.     }
  346.     return RTNORM;
  347. }
  348.  
  349. /* =================== Arx Module Interface Functions ================ */
  350.  
  351. // System Analysis Function.
  352.  
  353. void 
  354. /*FCN*/acrxAnalyzeSystem()
  355. {
  356.     // If you have dependencies on other applications, this function is
  357.     // called whenever an application is loaded or unloaded, or for that
  358.     // matter, whenever a service is registered or removed.
  359. }
  360.  
  361. AcRx::AppRetCode 
  362. /*FCN*/acrxEntryPoint(AcRx::AppMsgCode msg, void * ptr)
  363. {
  364.  
  365.     if (ptr != NULL) {
  366.         // We have been handed some kind of object
  367.         // but we aren't going to do anything with it.
  368.     }
  369.  
  370.     switch(msg) {
  371.     case AcRx::kInitAppMsg:
  372.         break;
  373.         case AcRx::kInvkSubrMsg:
  374.             dofun();
  375.             break;
  376.         case AcRx::kLoadADSMsg:
  377.             funcload();
  378.             break;
  379.         case AcRx::kUnloadADSMsg:
  380.             funcunload();
  381.             ads_printf(/*MSG2*/"Unloading.\n");
  382.             break;
  383.     case AcRx::kUnloadAppMsg:
  384.         default:
  385.         break;
  386.     }
  387.     return AcRx::kRetOK;
  388. }
  389.