wvTsfsUploadPathLib.c
上传用户:nvosite88
上传日期:2007-01-17
资源大小:4983k
文件大小:6k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* wvTsfsUploadPathLib.c - target host connection library using TSFS */
  2. /* Copyright 1998 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 02i,28aug98,dgp  FCS man page edit
  7. 02h,08may98,dgp  clean up man pages for WV 2.0 beta release
  8. 02g,15apr98,cth  removed errno set
  9. 02f,02apr98,cjtc extended size of fname in tsfsUploadPathCreate.
  10.  Removed erroneous call to htons in tsfsUploadPathCreate
  11. 02e,20mar98,cth  removed debug print statements
  12. 02d,27jan98,cth  removed oob error indicators, removed tsfsUploadPathError
  13. 02c,18dec97,cth  renamed again to wvTsfsUploadPathLib.c from wvTsfsUploadPath.c,
  14.                  added tsfsUploadPathLibInit, updated included files
  15. 02b,16nov97,cth  renamed again to wvTsfsUploadPath.c from tsfsUploadPath.c
  16.                  changed include tsfsUploadPathP.h to wvTsfsUploadPathP.h
  17. 02a,16nov97,cth  rewritten for WV2.0, modhist restarted to 'a'
  18.  renamed from evtTsfsSockLib.c to tsfsUploadPath.c
  19. 01f,21aug97,cth  created, modified evtSockLib.c
  20. */
  21. /*
  22. DESCRIPTION
  23. This library contains routines that are used by wvLib to transfer event
  24. data from the target to the host.  This transfer mechanism uses the socket
  25. functionality of the Target Server File System (TSFS), and can therefore be
  26. used without including any socket or network facilities within the target.
  27. INTERNAL
  28. Each open connection is referenced by a pointer to a TSFS_UPLOAD_DESC.
  29. This pointer is returned by tsfsUploadPathCreate when the connection is
  30. created successfully. The TSFS_UPLOAD_DESC structure must begin  with the
  31. UPLOAD_DESC structure defined in wvUploadPath.h.  This is analagous to the
  32. DEV_HDR mechanism used in iosLib.  Information private to this library is
  33. maintained in the remainder of the TSFS_UPLOAD_DESC structure (e.g. the
  34. socket fd).  When an operation such as tsfsUploadPathRead is performed, it
  35. receives an UPLOAD_ID (a pointer to an UPLOAD_PATH) that must be cast into
  36. a TSFS_UPLOAD_DESC to see the private information.
  37. INCLUDE FILES:
  38. SEE ALSO: wvSockUploadPathLib, wvFileUploadPathLib
  39. */
  40. #include "vxWorks.h"
  41. #include "ioLib.h"
  42. #include "logLib.h"
  43. #include "string.h"
  44. #include "stdio.h"
  45. #include "stdlib.h"
  46. #include "wdb/wdbVioLib.h"
  47. #include "private/wvUploadPathP.h"
  48. #include "private/wvTsfsUploadPathLibP.h"
  49. typedef struct tsfsUploadPath /* TSFS_UPLOAD_DESC */
  50.     {
  51.     UPLOAD_DESC path; /* struct must begin with this descriptor */
  52.     int sockFd; /* private data for each open socket */
  53.     } TSFS_UPLOAD_DESC;
  54. /*******************************************************************************
  55. *
  56. * tsfsUploadPathLibInit - initialize wvTsfsUploadPathLib library (Windview)
  57. *
  58. * This routine initializes wvTsfsUploadPathLib by pulling in the
  59. * routines in this file for use with WindView.  It is called during system
  60. * configuration from usrWindview.c.
  61. *
  62. * RETURNS: OK.
  63. *
  64. */
  65. STATUS tsfsUploadPathLibInit (void)
  66.     {
  67.     return OK;
  68.     }
  69. /*******************************************************************************
  70. *
  71. * tsfsUploadPathCreate - open an upload path to the host using a TSFS socket (Windview)
  72. *
  73. * This routine opens a TSFS socket to the host to be used for uploading
  74. * event data.  After successfully establishing this connection, an UPLOAD_ID 
  75. * is returned which points to the TSFS_UPLOAD_DESC that is passed to 
  76. * open(), close(), read(), etc. for future operations.
  77. *
  78. * RETURNS: The UPLOAD_ID, or NULL if the connection cannot be completed or 
  79. * not enough memory is available.
  80. *
  81. * SEE ALSO: tsfsUploadPathClose()
  82. */
  83. UPLOAD_ID tsfsUploadPathCreate 
  84.     (
  85.     char *ipAddress,  /* server's IP address in .-notation */
  86.     short port /* port number to bind to */
  87.     )
  88.     {
  89.     char  fName[64];   /* holds tsfs path & file name */
  90.     TSFS_UPLOAD_DESC   *pTsfsUploadDesc; /* this socket's descriptor */
  91.     /* Allocate the upload path's descriptor. */
  92.     if ((pTsfsUploadDesc = (TSFS_UPLOAD_DESC *) 
  93.    malloc (sizeof (TSFS_UPLOAD_DESC))) == NULL)
  94.         {
  95. logMsg ("tsfsUploadPathCreate: failed to allocate upload descriptor.n",
  96. 0, 0, 0, 0, 0, 0);
  97. return (NULL);
  98. }
  99.     /*
  100.      * Open a socket through the target-server file system, with a file 
  101.      * name like "TCP:host:port".  Mode and permissions are ignored.
  102.      */
  103.     sprintf (fName, "/tgtsvr/TCP:%s:%d", ipAddress, port);
  104.     if ((pTsfsUploadDesc->sockFd = open (fName, 0, 0)) == ERROR)
  105. {
  106. logMsg ("tsfsUploadPathCreate: failed to open socket.n",
  107. 0, 0, 0, 0, 0, 0);
  108.         return (NULL);
  109. }
  110.     /* Fill in the tsfs upload routines so the uploader can access them. */
  111.     pTsfsUploadDesc->path.writeRtn = (FUNCPTR) tsfsUploadPathWrite;
  112.     pTsfsUploadDesc->path.errorRtn = (FUNCPTR) tsfsUploadPathClose;
  113.     /* Cast the TSFS_UPLOAD_DESC to a generic UPLOAD_DESC before returning */
  114.     return ((UPLOAD_ID) pTsfsUploadDesc);
  115.     }
  116. /*******************************************************************************
  117. *
  118. * tsfsUploadPathClose - close the TSFS-socket upload path (Windview)
  119. *
  120. * This routine closes the TSFS-socket connection to the event receiver on 
  121. * the host.
  122. *
  123. * RETURNS: N/A
  124. *
  125. * SEE ALSO: tsfsUploadPathCreate()
  126. */
  127. void tsfsUploadPathClose 
  128.     (
  129.     UPLOAD_ID upId /* generic upload-path descriptor */
  130.     )
  131.     {
  132.     TSFS_UPLOAD_DESC *pTsfsUploadDesc;  /* upId cast to see private data */
  133.     if (upId == NULL)
  134. return;
  135.     pTsfsUploadDesc = (TSFS_UPLOAD_DESC *) upId;
  136.     close (pTsfsUploadDesc->sockFd);
  137.     free (pTsfsUploadDesc);
  138.     }
  139. /*******************************************************************************
  140. *
  141. * tsfsUploadPathWrite - write to the TSFS upload path (Windview)
  142. *
  143. * This routine writes <size> bytes of data beginning at <pStart> to the upload
  144. * path connecting the target with the host receiver.
  145. * RETURNS: The number of bytes written, or ERROR.
  146. *
  147. * SEE ALSO: tsfsUploadPathCreate()
  148. */
  149. int tsfsUploadPathWrite
  150.     (
  151.     UPLOAD_ID upId, /* generic upload-path descriptor */
  152.     char * pStart, /* address of data to write */
  153.     size_t size /* number of bytes of data at pStart */
  154.     )
  155.     {
  156.     TSFS_UPLOAD_DESC  *pTsfsUploadDesc; /* upId cast to see private data */
  157.     if (upId == NULL)
  158. return (ERROR);
  159.     pTsfsUploadDesc = (TSFS_UPLOAD_DESC *)upId;
  160.     return (write (pTsfsUploadDesc->sockFd, pStart, size));
  161.     }