summaryrefslogtreecommitdiff
path: root/source/slang-capture-replay/slang-filesystem.cpp
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-05-08 09:13:45 -0700
committerGitHub <noreply@github.com>2024-05-08 09:13:45 -0700
commit4f2330d059ab5943ddf33bfed37be6a0378d43a8 (patch)
tree9e3a0790deee6248343d49a644ab9f0be7909901 /source/slang-capture-replay/slang-filesystem.cpp
parenteb3970897049269602cc18cee644e437c0aff928 (diff)
capture/replay: interface implementation 1 (#4122)
* capture/replay: interface implementation 1 - Add global session, filesystem, and session capture interface classes: GlobalSessionCapture for IGlobalSession FileSystemCapture for ISlangFileSystemExt SessionCapture for ISession - Add environment variables to enable it The 2 variables are SLANG_CAPTURE_LAYER and SLANG_CAPTURE_LOG_LEVEL SLANG_CAPTURE_LAYER: In slang_createGlobalSession(), after the compiling/loading stdlib, we will check the capture environment variable, if it's set to 1, we will create a GlobalSessionCapture object and return to user code. SLANG_CAPTURE_LOG_LEVEL: This is to set the log level, user can choose the loglevel to debug. (We can remove this when the feature is fully implemented). - Update premake file and cmake file to add the capture/replay source folder * Fix Windows build error Fix windows build error by adding the "SLANG_MCALL" keyword. Change to use Slang::ComPtr for those captured object pointers to simplify the resource management. Use __func__ macro to print the function name in the log.
Diffstat (limited to 'source/slang-capture-replay/slang-filesystem.cpp')
-rw-r--r--source/slang-capture-replay/slang-filesystem.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/source/slang-capture-replay/slang-filesystem.cpp b/source/slang-capture-replay/slang-filesystem.cpp
new file mode 100644
index 000000000..10afbdf10
--- /dev/null
+++ b/source/slang-capture-replay/slang-filesystem.cpp
@@ -0,0 +1,100 @@
+#include "slang-filesystem.h"
+#include "capture_utility.h"
+
+namespace SlangCapture
+{
+ FileSystemCapture::FileSystemCapture(ISlangFileSystemExt* fileSystem)
+ : m_actualFileSystem(fileSystem)
+ {
+ assert(m_actualFileSystem);
+ slangCaptureLog(LogLevel::Verbose, "%s: %p\n", __func__, m_actualFileSystem.get());
+ }
+
+ FileSystemCapture::~FileSystemCapture()
+ {
+ m_actualFileSystem->release();
+ }
+
+ void* FileSystemCapture::castAs(const Slang::Guid& guid)
+ {
+ return getInterface(guid);
+ }
+
+ ISlangUnknown* FileSystemCapture::getInterface(const Slang::Guid& guid)
+ {
+ if(guid == ISlangUnknown::getTypeGuid() || guid == ISlangFileSystem::getTypeGuid())
+ return static_cast<ISlangFileSystem*>(this);
+ return nullptr;
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::loadFile(
+ char const* path,
+ ISlangBlob** outBlob)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s, :%s\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->loadFile(path, outBlob);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::getFileUniqueIdentity(
+ const char* path,
+ ISlangBlob** outUniqueIdentity)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s :\"%s\"\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->getFileUniqueIdentity(path, outUniqueIdentity);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::calcCombinedPath(
+ SlangPathType fromPathType,
+ const char* fromPath,
+ const char* path,
+ ISlangBlob** pathOut)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s, :%s\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->calcCombinedPath(fromPathType, fromPath, path, pathOut);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::getPathType(
+ const char* path,
+ SlangPathType* pathTypeOut)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s, :%s\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->getPathType(path, pathTypeOut);
+ return res;
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::getPath(
+ PathKind kind,
+ const char* path,
+ ISlangBlob** outPath)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s, :%s\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->getPath(kind, path, outPath);
+ return res;
+ }
+
+ SLANG_NO_THROW void FileSystemCapture::clearCache()
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualFileSystem.get(), __func__);
+ m_actualFileSystem->clearCache();
+ }
+
+ SLANG_NO_THROW SlangResult FileSystemCapture::enumeratePathContents(
+ const char* path,
+ FileSystemContentsCallBack callback,
+ void* userData)
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s, :%s\n", m_actualFileSystem.get(), __func__, path);
+ SlangResult res = m_actualFileSystem->enumeratePathContents(path, callback, userData);
+ return res;
+ }
+
+ SLANG_NO_THROW OSPathKind FileSystemCapture::getOSPathKind()
+ {
+ slangCaptureLog(LogLevel::Verbose, "%p: %s\n", m_actualFileSystem.get(), __func__);
+ OSPathKind pathKind = m_actualFileSystem->getOSPathKind();
+ return pathKind;
+ }
+}