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_DATA_STREAM_H
11#define PVD_DATA_STREAM_H
12#include "PvdErrorCodes.h"
13#include "PvdObjectModelBaseTypes.h"
14
15namespace physx { namespace debugger {
16 class PvdObjectModelMetaData;
17 struct PropertyMessageArg;
18 struct NamespacedName;
19}}
20
21namespace physx { namespace debugger { namespace comm {
22
23 class PvdConnection;
24 class PvdCommStreamEventSink;
25 class PvdOMMetaDataProvider;
26 class PvdPropertyDefinitionHelper;
27
28 class PvdMetaDataStream
29 {
30 protected:
31 virtual ~PvdMetaDataStream(){}
32 public:
33
34 virtual PvdError createClass( const NamespacedName& nm ) = 0;
35 template<typename TDataType>
36 PvdError createClass()
37 {
38 return createClass( getPvdNamespacedNameForType<TDataType>() );
39 }
40 virtual PvdError deriveClass( const NamespacedName& parent, const NamespacedName& child ) = 0;
41 template<typename TParentType, typename TChildType>
42 PvdError deriveClass()
43 {
44 return deriveClass( getPvdNamespacedNameForType<TParentType>(), getPvdNamespacedNameForType<TChildType>() );
45 }
46 virtual PvdError createProperty( const NamespacedName& clsName, String name, String semantic
47 , const NamespacedName& dtypeName, PropertyType::Enum propertyType
48 , DataRef<NamedValue> values = DataRef<NamedValue>() ) = 0;
49 template<typename TClsType, typename TDataType>
50 PvdError createProperty( String name, String semantic = "", PropertyType::Enum propertyType = PropertyType::Scalar, DataRef<NamedValue> values = DataRef<NamedValue>() )
51 {
52 return createProperty( getPvdNamespacedNameForType<TClsType>(), name, semantic,
53 getPvdNamespacedNameForType<TDataType>(), propertyType, values );
54 }
55
56 virtual PvdError createPropertyMessage( const NamespacedName& cls, const NamespacedName& msgName
57 , DataRef<PropertyMessageArg> entries, PxU32 messageSizeInBytes ) = 0;
58
59 template<typename TClsType, typename TMsgType>
60 PvdError createPropertyMessage( DataRef<PropertyMessageArg> entries )
61 {
62 return createPropertyMessage( getPvdNamespacedNameForType<TClsType>(), getPvdNamespacedNameForType<TMsgType>(), entries, sizeof( TMsgType ) );
63 }
64 };
65
66 class PvdInstanceDataStream
67 {
68 protected:
69 virtual ~PvdInstanceDataStream(){}
70 public:
71
72 virtual PvdError createInstance( const NamespacedName& cls, const void* instance ) = 0;
73
74 template<typename TDataType>
75 PvdError createInstance( const TDataType* inst )
76 {
77 return createInstance( getPvdNamespacedNameForType<TDataType>(), inst );
78 }
79 virtual bool isInstanceValid( const void* instance ) = 0;
80
81 //If the property will fit or is already completely in memory
82 virtual PvdError setPropertyValue( const void* instance, String name, DataRef<const PxU8> data, const NamespacedName& incomingTypeName ) = 0;
83 template<typename TDataType>
84 PvdError setPropertyValue( const void* instance, String name, const TDataType& value )
85 {
86 const PxU8* dataStart = reinterpret_cast<const PxU8*>( &value );
87 return setPropertyValue( instance, name, DataRef<const PxU8>( dataStart, dataStart + sizeof( TDataType ) ), getPvdNamespacedNameForType<TDataType>() );
88 }
89
90 template<typename TDataType>
91 PvdError setPropertyValue( const void* instance, String name, const TDataType* value, PxU32 numItems )
92 {
93 const PxU8* dataStart = reinterpret_cast<const PxU8*>( value );
94 return setPropertyValue( instance, name, DataRef<const PxU8>( dataStart, dataStart + sizeof( TDataType ) * numItems ), getPvdNamespacedNameForType<TDataType>() );
95 }
96
97 //Else if the property is very large (contact reports) you can send it in chunks.
98 virtual PvdError beginSetPropertyValue( const void* instance, String name, const NamespacedName& incomingTypeName ) = 0;
99
100 template<typename TDataType>
101 PvdError beginSetPropertyValue( const void* instance, String name )
102 {
103 return beginSetPropertyValue( instance, name, getPvdNamespacedNameForType<TDataType>() );
104 }
105 virtual PvdError appendPropertyValueData( DataRef<const PxU8> data ) = 0;
106
107 template<typename TDataType>
108 PvdError appendPropertyValueData( const TDataType* value, PxU32 numItems )
109 {
110 const PxU8* dataStart = reinterpret_cast<const PxU8*>( value );
111 return appendPropertyValueData( DataRef<const PxU8>( dataStart, dataStart + numItems * sizeof( TDataType ) ) );
112 }
113
114 virtual PvdError endSetPropertyValue() = 0;
115
116 //Set a set of properties to various values on an object.
117
118 virtual PvdError setPropertyMessage( const void* instance, const NamespacedName& msgName, DataRef<const PxU8> data ) = 0;
119
120 template<typename TDataType>
121 PvdError setPropertyMessage( const void* instance, const TDataType& value )
122 {
123 const PxU8* dataStart = reinterpret_cast<const PxU8*>( &value );
124 return setPropertyMessage( instance, getPvdNamespacedNameForType<TDataType>(), DataRef<const PxU8>( dataStart, sizeof( TDataType ) ) );
125 }
126 //If you need to send of lot of identical messages, this avoids a hashtable lookup per message.
127 virtual PvdError beginPropertyMessageGroup( const NamespacedName& msgName ) = 0;
128
129 template<typename TDataType>
130 PvdError beginPropertyMessageGroup()
131 {
132 return beginPropertyMessageGroup( getPvdNamespacedNameForType<TDataType>() );
133 }
134 virtual PvdError sendPropertyMessageFromGroup( const void* instance, DataRef<const PxU8> data ) = 0;
135
136 template<typename TDataType>
137 PvdError sendPropertyMessageFromGroup( const void* instance, const TDataType& value )
138 {
139 const PxU8* dataStart = reinterpret_cast<const PxU8*>( &value );
140 return sendPropertyMessageFromGroup( instance, DataRef<const PxU8>( dataStart, sizeof( TDataType ) ) );
141 }
142
143 virtual PvdError endPropertyMessageGroup() = 0;
144
145 //These functions ensure the target array doesn't contain duplicates
146 virtual PvdError pushBackObjectRef( const void* instId, String propName, const void* objRef ) = 0;
147 virtual PvdError removeObjectRef( const void* instId, String propName, const void* objRef ) = 0;
148
149 //Instance elimination.
150 virtual PvdError destroyInstance( const void* key ) = 0;
151
152
153 //Profiling hooks
154 virtual PvdError beginSection( const void* instance, String name ) = 0;
155 virtual PvdError endSection( const void* instance, String name ) = 0;
156
157 //Origin Shift
158 virtual PvdError originShift( const void* scene, PxVec3 shift ) = 0;
159
160 public:
161 /*For some cases, pvd command cannot be run immediately. For example, when create joints, while the actors may still pending for insert,
162 *the joints update commands can be run deffered.
163 */
164 class PvdCommand
165 {
166 public:
167 //Assigned is needed for copying
168 PvdCommand(const PvdCommand &){}
169 PvdCommand &operator=(const PvdCommand &){return *this;}
170 public:
171 PvdCommand(){}
172 virtual ~PvdCommand(){}
173
174 //Not pure virtual so can have default PvdCommand obj
175 virtual bool canRun(PvdInstanceDataStream & ){return false;}
176 virtual void run(PvdInstanceDataStream&){}
177 };
178
179 //PVD SDK provide this helper function to allocate cmd's memory and release them at after flush the command queue
180 virtual void* allocateMemForCmd( PxU32 length ) = 0;
181
182 //PVD will call the destructor of PvdCommand object at the end fo flushPvdCommand
183 virtual void pushPvdCommand( PvdCommand& cmd ) = 0;
184 virtual void flushPvdCommand() = 0;
185 };
186
187 class PvdDataStream : public PvdInstanceDataStream, public PvdMetaDataStream
188 {
189 protected:
190 virtual ~PvdDataStream(){}
191
192 public:
193 virtual void addRef() = 0;
194 virtual void release() = 0;
195 virtual bool isConnected() = 0;
196
197 virtual PvdPropertyDefinitionHelper& getPropertyDefinitionHelper() = 0;
198 //flushes the data to the connections socket layer which may have further caching.
199 //This stream is meant to be used on a per-thread basis, and thus buffers its messages
200 //before grabbing the socket mutex and sending them.
201 virtual PvdError flush() = 0;
202 };
203}}}
204
205#endif
206