RavEngine
Loading...
Searching...
No Matches
OmniPvdLoader.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26
27#ifndef OMNI_PVD_LOADER_H
28#define OMNI_PVD_LOADER_H
29
30#include "OmniPvdWriter.h"
31#include "OmniPvdReader.h"
32#include "OmniPvdLibraryFunctions.h"
33
34#include <stdio.h>
35
36#ifdef OMNI_PVD_WIN
37 #include <windows.h>
38#elif defined(__linux__)
39 #include <dlfcn.h>
40#endif
41
43{
44public:
47 bool loadOmniPvd(const char *libFile);
48 void unloadOmniPvd();
49 void* mLibraryHandle;
50
51 createOmniPvdWriterFp mCreateOmniPvdWriter;
52 destroyOmniPvdWriterFp mDestroyOmniPvdWriter;
53
54 createOmniPvdReaderFp mCreateOmniPvdReader;
55 destroyOmniPvdReaderFp mDestroyOmniPvdReader;
56
57 createOmniPvdFileReadStreamFp mCreateOmniPvdFileReadStream;
58 destroyOmniPvdFileReadStreamFp mDestroyOmniPvdFileReadStream;
59
60 createOmniPvdFileWriteStreamFp mCreateOmniPvdFileWriteStream;
61 destroyOmniPvdFileWriteStreamFp mDestroyOmniPvdFileWriteStream;
62
63 createOmniPvdMemoryStreamFp mCreateOmniPvdMemoryStream;
64 destroyOmniPvdMemoryStreamFp mDestroyOmniPvdMemoryStream;
65};
66
67inline OmniPvdLoader::OmniPvdLoader()
68{
69 mLibraryHandle = 0;
70
71 mCreateOmniPvdWriter = 0;
72 mDestroyOmniPvdWriter = 0;
73
74 mCreateOmniPvdReader = 0;
75 mDestroyOmniPvdReader = 0;
76
77 mCreateOmniPvdFileReadStream = 0;
78 mDestroyOmniPvdFileReadStream = 0;
79
80 mCreateOmniPvdFileWriteStream = 0;
81 mDestroyOmniPvdFileWriteStream = 0;
82
83 mCreateOmniPvdMemoryStream = 0;
84 mDestroyOmniPvdMemoryStream = 0;
85}
86
87inline OmniPvdLoader::~OmniPvdLoader()
88{
89 unloadOmniPvd();
90}
91
92inline bool OmniPvdLoader::loadOmniPvd(const char *libFile)
93{
94
95#ifdef OMNI_PVD_WIN
96 mLibraryHandle = LoadLibraryA(libFile);
97#elif defined(__linux__)
98 mLibraryHandle = dlopen(libFile, RTLD_NOW);
99#endif
100
101 if (mLibraryHandle)
102 {
103#ifdef OMNI_PVD_WIN
104 mCreateOmniPvdWriter = (createOmniPvdWriterFp)GetProcAddress((HINSTANCE)mLibraryHandle, "createOmniPvdWriter");
105 mDestroyOmniPvdWriter = (destroyOmniPvdWriterFp)GetProcAddress((HINSTANCE)mLibraryHandle, "destroyOmniPvdWriter");
106
107 mCreateOmniPvdReader = (createOmniPvdReaderFp)GetProcAddress((HINSTANCE)mLibraryHandle, "createOmniPvdReader");
108 mDestroyOmniPvdReader = (destroyOmniPvdReaderFp)GetProcAddress((HINSTANCE)mLibraryHandle, "destroyOmniPvdReader");
109
110 mCreateOmniPvdFileReadStream = (createOmniPvdFileReadStreamFp)GetProcAddress((HINSTANCE)mLibraryHandle, "createOmniPvdFileReadStream");
111 mDestroyOmniPvdFileReadStream = (destroyOmniPvdFileReadStreamFp)GetProcAddress((HINSTANCE)mLibraryHandle, "destroyOmniPvdFileReadStream");
112
113 mCreateOmniPvdFileWriteStream = (createOmniPvdFileWriteStreamFp)GetProcAddress((HINSTANCE)mLibraryHandle, "createOmniPvdFileWriteStream");
114 mDestroyOmniPvdFileWriteStream = (destroyOmniPvdFileWriteStreamFp)GetProcAddress((HINSTANCE)mLibraryHandle, "destroyOmniPvdFileWriteStream");
115
116 mCreateOmniPvdMemoryStream = (createOmniPvdMemoryStreamFp)GetProcAddress((HINSTANCE)mLibraryHandle, "createOmniPvdMemoryStream");
117 mDestroyOmniPvdMemoryStream = (destroyOmniPvdMemoryStreamFp)GetProcAddress((HINSTANCE)mLibraryHandle, "destroyOmniPvdMemoryStream");
118#elif defined(__linux__)
119 mCreateOmniPvdWriter = (createOmniPvdWriterFp)dlsym(mLibraryHandle, "createOmniPvdWriter");
120 mDestroyOmniPvdWriter = (destroyOmniPvdWriterFp)dlsym(mLibraryHandle, "destroyOmniPvdWriter");
121
122 mCreateOmniPvdReader = (createOmniPvdReaderFp)dlsym(mLibraryHandle, "createOmniPvdReader");
123 mDestroyOmniPvdReader = (destroyOmniPvdReaderFp)dlsym(mLibraryHandle, "destroyOmniPvdReader");
124
125 mCreateOmniPvdFileReadStream = (createOmniPvdFileReadStreamFp)dlsym(mLibraryHandle, "createOmniPvdFileReadStream");
126 mDestroyOmniPvdFileReadStream = (destroyOmniPvdFileReadStreamFp)dlsym(mLibraryHandle, "destroyOmniPvdFileReadStream");
127
128 mCreateOmniPvdFileWriteStream = (createOmniPvdFileWriteStreamFp)dlsym(mLibraryHandle, "createOmniPvdFileWriteStream");
129 mDestroyOmniPvdFileWriteStream = (destroyOmniPvdFileWriteStreamFp)dlsym(mLibraryHandle, "destroyOmniPvdFileWriteStream");
130
131 mCreateOmniPvdMemoryStream = (createOmniPvdMemoryStreamFp)dlsym(mLibraryHandle, "createOmniPvdMemoryStream");
132 mDestroyOmniPvdMemoryStream = (destroyOmniPvdMemoryStreamFp)dlsym(mLibraryHandle, "destroyOmniPvdMemoryStream");
133
134#endif
135
136 if ((!mCreateOmniPvdWriter) ||
137 (!mDestroyOmniPvdWriter) ||
138 (!mCreateOmniPvdReader) ||
139 (!mDestroyOmniPvdReader) ||
140 (!mCreateOmniPvdFileReadStream) ||
141 (!mDestroyOmniPvdFileReadStream) ||
142 (!mCreateOmniPvdFileWriteStream) ||
143 (!mDestroyOmniPvdFileWriteStream) ||
144 (!mCreateOmniPvdMemoryStream) ||
145 (!mDestroyOmniPvdMemoryStream)
146 )
147 {
148#ifdef OMNI_PVD_WIN
149 FreeLibrary((HINSTANCE)mLibraryHandle);
150#elif defined(__linux__)
151 dlclose(mLibraryHandle);
152#endif
153 mLibraryHandle = 0;
154 return false;
155 }
156 }
157 else {
158 return false;
159 }
160 return true;
161}
162
163inline void OmniPvdLoader::unloadOmniPvd()
164{
165 if (mLibraryHandle)
166 {
167#ifdef OMNI_PVD_WIN
168 FreeLibrary((HINSTANCE)mLibraryHandle);
169#elif defined(__linux__)
170 dlclose(mLibraryHandle);
171#endif
172 mLibraryHandle = 0;
173 }
174}
175
176#endif
Definition OmniPvdLoader.h:43