usrWindview.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:8k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* usrWindview.c - configuration file for Windview on the target */
  2. /* Copyright 1997 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01a,13may98,pr   taken from src/config/usrWindview.c version 01g
  7. */
  8. /*
  9. DESCRIPTION
  10. */
  11. /* defines */
  12. #define WV_FILE         1               /* file upload-path type */
  13. #define WV_SOCK         2               /* socket upload-path type */
  14. #define WV_TSFSSOCK     3               /* tsfs socket upload-path type */
  15. /* globals */
  16. int wvDefaultBufSize; /* default size of a buffer */
  17. int wvDefaultBufMax; /* default max number of buffers */
  18. int wvDefaultBufMin; /* default min number of buffers */
  19. int wvDefaultBufThresh; /* default threshold for uploading, in bytes */
  20. int wvDefaultBufOptions; /* default rBuff options */
  21. rBuffCreateParamsType   wvDefaultRBuffParams;  /* contains the above values */
  22. BUFFER_ID   wvBufId; /* event-buffer id used by wvOn/Off */
  23. UPLOAD_ID   wvUpPathId; /* upload-path id used by wvOn/Off */
  24. WV_UPLOADTASK_ID  wvUpTaskId; /* upload-task id used by wvOn/Off */
  25. WV_LOG_HEADER_ID  wvLogHeader; /* the event-log header */
  26. FUNCPTR _func_wvOnUploadPathCreate;
  27. FUNCPTR _func_wvOnUploadPathClose;
  28. int wvArgHtons;
  29. char * wvLogMsgString1;
  30. char * wvLogMsgString2;
  31. /* forward declarations */
  32. int wvRBuffErrorHandler (void);
  33. /******************************************************************************
  34. *
  35. * windviewConfig - configure and initialize Windview components
  36. *
  37. * NOMANUAL
  38. *
  39. */
  40. STATUS windviewConfig (void)
  41.     {
  42.     /*
  43.      * This is not mandatory at this point, but by setting these global 
  44.      * variables to the default values here, they can be changed from the
  45.      * shell before wvOn/wvOff use them.
  46.      */
  47.     wvDefaultBufSize      = WV_DEFAULT_BUF_SIZE;
  48.     wvDefaultBufMax   = WV_DEFAULT_BUF_MAX;
  49.     wvDefaultBufMin   = WV_DEFAULT_BUF_MIN;
  50.     wvDefaultBufThresh   = WV_DEFAULT_BUF_THRESH;
  51.     wvDefaultBufOptions   = WV_DEFAULT_BUF_OPTIONS;
  52.     wvDefaultRBuffParams.minimum   = wvDefaultBufMin;
  53.     wvDefaultRBuffParams.maximum   = wvDefaultBufMax;
  54.     wvDefaultRBuffParams.buffSize   = wvDefaultBufSize;
  55.     wvDefaultRBuffParams.threshold   = wvDefaultBufThresh;
  56.     wvDefaultRBuffParams.options   = wvDefaultBufOptions;
  57.     wvDefaultRBuffParams.sourcePartition  = memSysPartId;
  58.     wvDefaultRBuffParams.errorHandler   = wvRBuffErrorHandler;
  59.     /*
  60.      * Include and complete initialization for wvLib.
  61.      */
  62.     wvLibInit2 ();
  63.     return (OK);
  64.     }
  65. /******************************************************************************
  66. *
  67. * wvOn - start typical instance of event logging and upload (Windview)
  68. *
  69. * This routine starts a typical instance of WindView event logging and event
  70. * upload.  rBuff buffers are used to store events.  The file upload path is
  71. * TSFS-socket, socket, or file.  Event data is uploaded to the path 
  72. * continuously.
  73. *
  74. * Event logging is started for events belonging to <class>.  The rBuff buffer
  75. * is created using the values in 'wvDefaultRBuffParams', which are taken from
  76. * the globals 'wvDefaultBufxxx', configurable from usrWindview.c.  The upload
  77. * path used to transfer events away from the event buffer is determined by
  78. * the value of WV_DEFAULT_UPLOAD_TYPE, also set in usrWindview.c to one 
  79. * of WV_FILE, WV_TSFSSOCK or WV_SOCK.  The upload path is opened using the 
  80. * remaining parameters as follows:
  81. *
  82. * .TS
  83. * tab(|)
  84. * lf3 lf3 lf3
  85. * l l l.
  86. *         | WV_FILE        | WV_TSFSOCK / WV_SOCK
  87. * _
  88. * arg2    | char *filename | char *hostIp
  89. * arg3    | openFlags      | short port
  90. * arg4    | not used       | not used
  91. * .TE
  92. *
  93. * The arguments are of generic type and name to allow the addition of new
  94. * types of upload paths or customization of wvOn().
  95. *
  96. * RETURNS: OK, or ERROR if the upload path can not be created, the upload task 
  97. * can not be created, or the rBuff buffer can not be created.
  98. *
  99. * SEE ALSO: wvOff()
  100. *
  101. */
  102. STATUS wvOn 
  103.     (
  104.     int class, /* class of events to be logged */
  105.     int arg2, /* filename, hostIp, etc. */
  106.     int arg3, /* port number, openFlags etc. */
  107.     int arg4 /* for future expansion */
  108.     )
  109.     {
  110.     short pathArg;
  111.     /* Create a buffer. */
  112.     if ((wvBufId = rBuffCreate (& wvDefaultRBuffParams)) == NULL)
  113.         {
  114.         logMsg ("wvOn: error creating buffer.n",0,0,0,0,0,0);
  115.         return (ERROR);
  116.         }
  117.     /* 
  118.      * Create a path for events to be uploaded to the host.  If more than
  119.      * one UploadPath library is compiled into vxWorks, the fileUploadPath
  120.      * will be the one used.
  121.      */
  122.     if (wvArgHtons == 1)
  123.         pathArg = (short)(htons (arg3));
  124.     else
  125.         pathArg = arg3;
  126.     if (_func_wvOnUploadPathCreate != NULL)
  127. if ((wvUpPathId = (UPLOAD_ID)_func_wvOnUploadPathCreate ((char *) arg2, 
  128.                (short)pathArg)) == NULL)
  129.         {
  130.         logMsg ("wvOn: error creating upload path(%s%d %s%d).n",
  131.                 (int)wvLogMsgString1,arg2, (int)wvLogMsgString2, pathArg,0,0);
  132.         rBuffDestroy (wvBufId);
  133.         return (ERROR);
  134.         }
  135.     /*
  136.      * Initialize the event log, and let event logging routines know which
  137.      * buffer to log events to.
  138.      */
  139.     wvEvtLogInit (wvBufId);
  140.     /*
  141.      * Start the upload task.  Uploading will be continuous after this
  142.      * is started.
  143.      */
  144.     logMsg ("wvOn: wvBufId %d wvUpPathId %d.n",(int)wvBufId, 
  145. (int)wvUpPathId, 0,0,0,0);
  146.     if ((wvUpTaskId = wvUploadStart (wvBufId, wvUpPathId, TRUE)) == NULL)
  147.         {
  148.         logMsg ("wvOn: error launching upload.n",0,0,0,0,0,0);
  149.         rBuffDestroy (wvBufId);
  150.     if (_func_wvOnUploadPathClose != NULL)
  151.         _func_wvOnUploadPathClose (wvUpPathId);
  152.         return (ERROR);
  153.         }
  154.     /*
  155.      * Capture a log header, including task names active in the system.
  156.      */
  157.     if ((wvLogHeader = wvLogHeaderCreate (memSysPartId)) == NULL)
  158.         {
  159.         logMsg ("wvOn: error creating log header.n",0,0,0,0,0,0);
  160. wvUploadStop (wvUpTaskId);
  161.         rBuffDestroy (wvBufId);
  162.     if (_func_wvOnUploadPathClose != NULL)
  163.         _func_wvOnUploadPathClose (wvUpPathId);
  164.         return (ERROR);
  165.         }
  166.     /*
  167.      * Upload the header immediately, because we are uploading continuously.
  168.      */
  169.     if (wvLogHeaderUpload (wvLogHeader, wvUpPathId) != OK)
  170.         {
  171.         logMsg ("wvOn: error uploading log header.n",0,0,0,0,0,0);
  172. wvUploadStop (wvUpTaskId);
  173.         rBuffDestroy (wvBufId);
  174.     if (_func_wvOnUploadPathClose != NULL)
  175.         _func_wvOnUploadPathClose (wvUpPathId);
  176.         return (ERROR);
  177. }
  178.     /*
  179.      * Turn on event logging.
  180.      */
  181.     wvEvtClassSet (class);
  182.     wvEvtLogStart ();
  183.     return (OK);
  184.     }
  185. /******************************************************************************
  186. *
  187. * wvOff - stop a typical instance of event logging and upload (Windview)
  188. *
  189. * This routine stops event logging and uploading of events that was started
  190. * with wvOn().  First, event logging is stopped.  Next the event upload task 
  191. * flushes the buffers and is then deleted.  Finally, the upload path is 
  192. * closed and the event buffer is deleted.
  193. *
  194. * The type of upload path is determined by the value of WV_DEFUALT_UPLOAD_TYPE,
  195. * set in usrWindview.c.  The upload task ID, buffer ID, and upload path ID are 
  196. * stored in the 'wvUpTaskId', 'wvBufId', and 'wvUpPathId' globals, respectively.
  197. *
  198. * RETURNS: N/A 
  199. *
  200. * SEE ALSO: wvOn()
  201. *
  202. */
  203. void wvOff (void)
  204.     {
  205.     /* Stop event logging. */
  206.     wvEvtLogStop ();
  207.     /* 
  208.      * Stop continuous upload of events.  This will block until the buffer
  209.      * is emptied.
  210.      */
  211.     if (wvUploadStop (wvUpTaskId) == ERROR)
  212. {
  213. logMsg ("wvOff: error killing upload task.n", 0,0,0,0,0,0);
  214. }
  215.     /* Close the upload path. */
  216.     if (_func_wvOnUploadPathClose != NULL)
  217.         _func_wvOnUploadPathClose (wvUpPathId);
  218.     /* Destroy the event buffer. */
  219.     if (wvBufId != NULL)
  220.         rBuffDestroy (wvBufId);
  221.     }
  222. /*******************************************************************************
  223. * wvRBuffErrorHandler - error handler for the rBuffer created by  wvOn,wvOff
  224. *
  225. * NOMANUAL
  226. *
  227. */
  228. int wvRBuffErrorHandler (void)
  229.     {
  230.     logMsg ("wvRBuffErrorHandler: error occurred.n", 0,0,0,0,0,0);
  231.     return OK;
  232.     }