| 1 | /* |
| 2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
| 5 | * and proprietary rights in and to this software, related documentation |
| 6 | * and any modifications thereto. Any use, reproduction, disclosure or |
| 7 | * distribution of this software and related documentation without an express |
| 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
| 9 | */ |
| 10 | #ifndef PVD_NETWORK_STREAMS_H |
| 11 | #define PVD_NETWORK_STREAMS_H |
| 12 | #include "foundation/PxSimpleTypes.h" |
| 13 | #include "physxvisualdebuggersdk/PvdErrorCodes.h" |
| 14 | |
| 15 | namespace physx { namespace debugger { |
| 16 | |
| 17 | /** |
| 18 | * Implementations don't need to implement a caching layer nor do they need |
| 19 | * to worry about threadsafe implementations; that is all built on top of |
| 20 | * this interface. |
| 21 | */ |
| 22 | class PvdNetworkOutStream |
| 23 | { |
| 24 | protected: |
| 25 | virtual ~PvdNetworkOutStream(){} |
| 26 | |
| 27 | public: |
| 28 | /** |
| 29 | * write bytes to the other endpoint of the connection. If an error occurs |
| 30 | * this connection will assume to be dead. |
| 31 | * |
| 32 | * Errors - |
| 33 | * |
| 34 | * NetworkError - Some failure to write data either to buffer or over network. |
| 35 | */ |
| 36 | virtual PvdError write( const PxU8* inBytes, PxU32 inLength ) = 0; |
| 37 | template<typename TDataType> |
| 38 | PvdError write( const TDataType* data, PxU32 numItems ) |
| 39 | { |
| 40 | return write( reinterpret_cast<const PxU8*>( data ), numItems * sizeof( TDataType ) ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Return true if this stream is still connected. |
| 45 | */ |
| 46 | virtual bool isConnected() const = 0; |
| 47 | /** |
| 48 | * Close the in stream. |
| 49 | */ |
| 50 | virtual void disconnect() = 0; |
| 51 | /** |
| 52 | * release any resources related to this stream. |
| 53 | */ |
| 54 | virtual void release() = 0; |
| 55 | |
| 56 | /** |
| 57 | * send any data and block until we know it is at least on the wire. |
| 58 | */ |
| 59 | virtual PvdError flush() = 0; |
| 60 | |
| 61 | /** |
| 62 | * Return the size of data have been written to target |
| 63 | */ |
| 64 | virtual PxU64 getWrittenDataSize() = 0; |
| 65 | |
| 66 | static PvdNetworkOutStream& createDoubleBuffered( PxAllocatorCallback& alloc, PvdNetworkOutStream& stream, PxU32 bufSize ); |
| 67 | static PvdNetworkOutStream* createFromFile( PxAllocatorCallback& alloc, const char* fname ); |
| 68 | }; |
| 69 | |
| 70 | /** |
| 71 | * Implementations don't need to implement a caching layer nor do they need |
| 72 | * to worry about threadsafe implementations; that is all built on top of |
| 73 | * this interface. |
| 74 | */ |
| 75 | class PvdNetworkInStream |
| 76 | { |
| 77 | protected: |
| 78 | virtual ~PvdNetworkInStream(){} |
| 79 | |
| 80 | public: |
| 81 | /** |
| 82 | * Read the requested number of bytes from the socket. Block until that number |
| 83 | * of bytes is returned. |
| 84 | * |
| 85 | * Errors - |
| 86 | * NetworkError - If call cannot complete. |
| 87 | */ |
| 88 | virtual PvdError readBytes( PxU8* outBytes, PxU32 ioRequested ) = 0; |
| 89 | |
| 90 | /** |
| 91 | * Return true if this stream is still connected. |
| 92 | */ |
| 93 | virtual bool isConnected() const = 0; |
| 94 | /** |
| 95 | * Close the in stream. |
| 96 | */ |
| 97 | virtual void disconnect() = 0; |
| 98 | /** |
| 99 | * release any resources related to this stream. |
| 100 | */ |
| 101 | virtual void release() = 0; |
| 102 | |
| 103 | /** |
| 104 | * Return the number of bytes the stream has read. |
| 105 | */ |
| 106 | virtual PxU64 getLoadedDataSize() = 0; |
| 107 | }; |
| 108 | |
| 109 | //Create an object responsible for a pair of instream/outstream |
| 110 | //where instream may or may not exist. |
| 111 | class PvdNetworkStreamOwner |
| 112 | { |
| 113 | protected: |
| 114 | virtual ~PvdNetworkStreamOwner(){} |
| 115 | public: |
| 116 | virtual void addRef() = 0; |
| 117 | virtual void release() = 0; |
| 118 | //Calling destroy on these streams is equivalent to calling |
| 119 | //release on this object. |
| 120 | virtual PvdNetworkOutStream& lock() = 0; |
| 121 | virtual void unlock() = 0; |
| 122 | virtual PvdNetworkInStream* getInStream() = 0; |
| 123 | |
| 124 | static PvdNetworkStreamOwner& create( PxAllocatorCallback& alloc, PvdNetworkOutStream& outStream, PvdNetworkInStream* inStream ); |
| 125 | }; |
| 126 | |
| 127 | class PvdNetworkStreams |
| 128 | { |
| 129 | public: |
| 130 | static bool connect( PxAllocatorCallback& allocator |
| 131 | , const char* inHost |
| 132 | , int inPort |
| 133 | , unsigned int inTimeoutInMilliseconds |
| 134 | , PvdNetworkInStream*& outInStream |
| 135 | , PvdNetworkOutStream*& outOutStream ); |
| 136 | }; |
| 137 | }} |
| 138 | |
| 139 | #endif |
| 140 | |