-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlueInterface.cpp
More file actions
187 lines (158 loc) · 4.86 KB
/
BlueInterface.cpp
File metadata and controls
187 lines (158 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright © 2026 CCP ehf.
#include "StdAfx.h"
#include "BlueInterface.h"
#if __APPLE__
#include <dlfcn.h>
#endif
BlueInterface::~BlueInterface()
{
if( m_module )
{
#if __APPLE__
dlclose( m_module );
#elif _WIN32
FreeLibrary( static_cast<HMODULE>( m_module ) );
#else
#error Unsupported platform
#endif
// Make invalid access obvious
memset( this, 0, sizeof( *this ) );
}
}
bool BlueInterface::LoadBlue( const std::wstring& buildFlavor )
{
if( m_module )
{
return true;
}
std::wstring name = L"blue" + ( buildFlavor.empty() ? L"" : L"_" + buildFlavor );
#if __APPLE__
std::string str = std::string( std::begin( name ), std::end( name ) ) + ".so";
m_module = dlopen( str.c_str(), RTLD_LAZY );
#elif _WIN32
name += L".pyd";
m_module = LoadLibraryW( name.c_str() );
#else
#error Unsupported platform
#endif
if( !m_module )
{
return false;
}
#if __APPLE__
#define LoadBlueRoutine( name ) \
if( !( m_blue##name##Routine = reinterpret_cast<Blue##name##Routine>( dlsym( m_module, CCP_STRINGIZE( Blue##name ) ) ) ) ) \
{ \
fprintf(stderr, "Failed to resolve %s\n", CCP_STRINGIZE( Blue##name ) ); \
return false; \
}
#elif _WIN32
#define LoadBlueRoutine( name ) \
if( !( m_blue##name##Routine = reinterpret_cast<Blue##name##Routine>( GetProcAddress( static_cast<HMODULE>( m_module ), CCP_STRINGIZE( Blue##name ) ) ) ) ) \
return false
#else
#error Unsupported platform
#endif
LoadBlueRoutine( SetCrashReporter );
LoadBlueRoutine( LogFuncChannel );
LoadBlueRoutine( ModuleStartup );
LoadBlueRoutine( InitializeSocketLogger );
LoadBlueRoutine( InitializePaths );
LoadBlueRoutine( ShowInvalidOSVersionError );
LoadBlueRoutine( ShutdownSocketLogger );
LoadBlueRoutine( InstallPythonMemoryHooks );
LoadBlueRoutine( LoadPythonExtension );
LoadBlueRoutine( ConstructPathListFromManifest );
LoadBlueRoutine( ResolvePathForWritingW );
LoadBlueRoutine( GetInitTab );
LoadBlueRoutine( SetStartupArgs );
LoadBlueRoutine( HasStartupArg );
LoadBlueRoutine( SetSearchPaths );
LoadBlueRoutine( IsPackaged );
LoadBlueRoutine( Terminate );
LoadBlueRoutine( RunStackless );
LoadBlueRoutine( ShowError );
#undef LoadBlueRoutine
return true;
}
void BlueInterface::SetCrashReporter( ICrashReporter* crashReporter ) const
{
m_blueSetCrashReporterRoutine( crashReporter );
}
void BlueInterface::LogFuncChannel( CcpLogChannel_t& logObject, CCP::LogType type, unsigned long userData, const char* format, ... ) const
{
va_list args;
va_start( args, format );
m_blueLogFuncChannelRoutine( logObject, type, userData, format, args );
va_end( args );
}
void BlueInterface::ModuleStartup() const
{
m_blueModuleStartupRoutine();
}
void BlueInterface::InitializeSocketLogger() const
{
m_blueInitializeSocketLoggerRoutine();
}
bool BlueInterface::InitializePaths( const std::wstring& initialPath ) const
{
return m_blueInitializePathsRoutine( initialPath );
}
void BlueInterface::ShowInvalidOSVersionError() const
{
m_blueShowInvalidOSVersionErrorRoutine();
}
void BlueInterface::ShutdownSocketLogger() const
{
m_blueShutdownSocketLoggerRoutine();
}
void BlueInterface::InstallPythonMemoryHooks() const
{
m_blueInstallPythonMemoryHooksRoutine();
}
PyObject* BlueInterface::LoadPythonExtension( const char* name ) const
{
return m_blueLoadPythonExtensionRoutine(name);
}
bool BlueInterface::ConstructPathListFromManifest( std::vector<std::wstring>& pathList, bool verifyManifest )
{
return m_blueConstructPathListFromManifestRoutine( pathList, verifyManifest );
}
void BlueInterface::GetInitTab( std::vector<_inittab>& inittab )
{
m_blueGetInitTabRoutine( inittab );
}
std::wstring BlueInterface::ResolvePathForWritingW( const std::wstring& path )
{
std::wstring resolved;
m_blueResolvePathForWritingWRoutine( path, resolved );
return resolved;
}
bool BlueInterface::IsPackaged()
{
return m_blueIsPackagedRoutine();
}
bool BlueInterface::RunStackless()
{
return m_blueRunStacklessRoutine();
}
bool BlueInterface::HasStartupArg( const std::wstring& name )
{
return m_blueHasStartupArgRoutine( name );
}
void BlueInterface::SetStartupArgs( const std::vector<std::wstring>& args )
{
m_blueSetStartupArgsRoutine( args );
}
bool BlueInterface::SetSearchPaths( const std::vector<std::wstring>& searchPaths )
{
return m_blueSetSearchPathsRoutine( searchPaths );
}
void BlueInterface::ShowError() const
{
m_blueShowErrorRoutine();
}
void BlueInterface::Terminate( int exitCode )
{
m_blueTerminateRoutine( exitCode );
}