From bb53728564ea716fd709f06a677cb9a01f55bdda Mon Sep 17 00:00:00 2001
From: Mark Winter <mwinter@drexel.edu>
Date: Sun, 1 Mar 2020 16:32:20 +0100
Subject: [PATCH] Debugging script command to test HydraConfig loader

---
 src/c/CudaMex.vcxproj                         |  1 +
 src/c/CudaMex.vcxproj.filters                 |  3 +++
 src/c/CudaPy3DLL.vcxproj                      |  1 +
 src/c/CudaPy3DLL.vcxproj.filters              |  5 +++-
 src/c/ScriptCmds/Commands/ScrCmdCheckConfig.h | 23 +++++++++++++++++++
 src/c/ScriptCmds/ScriptCommand.h              |  1 -
 src/c/ScriptCmds/ScriptCommandModule.h        |  3 +++
 src/c/ScriptCmds/ScriptCommands.h             |  2 ++
 8 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 src/c/ScriptCmds/Commands/ScrCmdCheckConfig.h

diff --git a/src/c/CudaMex.vcxproj b/src/c/CudaMex.vcxproj
index d70e3a1c..64897e6e 100644
--- a/src/c/CudaMex.vcxproj
+++ b/src/c/CudaMex.vcxproj
@@ -103,6 +103,7 @@ copy $(OutDir)CudaMex.dll "$(ProjectDir)Mex.mexw64"</Command>
     <ClInclude Include="mph\qualifier_helpers.h" />
     <ClInclude Include="mph\tuple_helpers.h" />
     <ClInclude Include="ScriptCmds\ArgConverter.h" />
+    <ClInclude Include="ScriptCmds\Commands\ScrCmdCheckConfig.h" />
     <ClInclude Include="ScriptCmds\Commands\ScrCmdClosure.h" />
     <ClInclude Include="ScriptCmds\Commands\ScrCmdDeviceCount.h" />
     <ClInclude Include="ScriptCmds\Commands\ScrCmdDeviceStats.h" />
diff --git a/src/c/CudaMex.vcxproj.filters b/src/c/CudaMex.vcxproj.filters
index e7285431..37705fd3 100644
--- a/src/c/CudaMex.vcxproj.filters
+++ b/src/c/CudaMex.vcxproj.filters
@@ -159,6 +159,9 @@
     <ClInclude Include="ScriptCmds\HydraConfig.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="ScriptCmds\Commands\ScrCmdCheckConfig.h">
+      <Filter>Header Files\Commands</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Mex\CudaMex.cpp">
diff --git a/src/c/CudaPy3DLL.vcxproj b/src/c/CudaPy3DLL.vcxproj
index 6801ec44..5a606514 100644
--- a/src/c/CudaPy3DLL.vcxproj
+++ b/src/c/CudaPy3DLL.vcxproj
@@ -33,6 +33,7 @@
     <ClInclude Include="Python\PyIncludes.h" />
     <ClInclude Include="Python\PyTypes.h" />
     <ClInclude Include="ScriptCmds\ArgConverter.h" />
+    <ClInclude Include="ScriptCmds\Commands\ScrCmdCheckConfig.h" />
     <ClInclude Include="ScriptCmds\Commands\ScrCmdClosure.h" />
     <ClInclude Include="ScriptCmds\Commands\ScrCmdDeviceCount.h" />
     <ClInclude Include="ScriptCmds\Commands\ScrCmdDeviceStats.h" />
diff --git a/src/c/CudaPy3DLL.vcxproj.filters b/src/c/CudaPy3DLL.vcxproj.filters
index f8a085fc..5d1f3a16 100644
--- a/src/c/CudaPy3DLL.vcxproj.filters
+++ b/src/c/CudaPy3DLL.vcxproj.filters
@@ -170,5 +170,8 @@
     <ClInclude Include="ScriptCmds\HydraConfig.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="ScriptCmds\Commands\ScrCmdCheckConfig.h">
+      <Filter>Header Files\Commands</Filter>
+    </ClInclude>
   </ItemGroup>
-</Project>
+</Project>
\ No newline at end of file
diff --git a/src/c/ScriptCmds/Commands/ScrCmdCheckConfig.h b/src/c/ScriptCmds/Commands/ScrCmdCheckConfig.h
new file mode 100644
index 00000000..b4546dfe
--- /dev/null
+++ b/src/c/ScriptCmds/Commands/ScrCmdCheckConfig.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "ScriptCommandImpl.h"
+#include "ScriptCommandDefines.h"
+
+#include "HydraConfig.h"
+
+SCR_COMMAND_CLASSDEF(CheckConfig)
+{
+public:
+	SCR_HELP_STRING("Get Hydra library configuration information.\n"
+		"Returns hydraConfig structure with configuration information.\n");
+
+
+	static void execute(Script::ObjectType*& hydraConfig)
+	{
+		if ( !HydraConfig::validConfig() )
+			Script::errorMsg("Hydra Library configuration was not initialized correctly!");
+
+		hydraConfig = Script::Struct::create(1, {"UseProcessMutex"});
+		Script::Struct::setVal(hydraConfig, 0, "UseProcessMutex", Script::Converter::fromNumeric(HydraConfig::useProcessMutex()));
+	}
+};
diff --git a/src/c/ScriptCmds/ScriptCommand.h b/src/c/ScriptCmds/ScriptCommand.h
index 084fed70..5fc68f98 100644
--- a/src/c/ScriptCmds/ScriptCommand.h
+++ b/src/c/ScriptCmds/ScriptCommand.h
@@ -47,7 +47,6 @@ public:
 
 	using CommandList = std::unordered_map<std::string, FuncPtrs>;
 
-	// TODO: Module initialization routines (and matlab dispatch)
 	inline static const FuncPtrs* findCommand(const std::string& command)
 	{
 		if ( m_commands.count(command) < 1 )
diff --git a/src/c/ScriptCmds/ScriptCommandModule.h b/src/c/ScriptCmds/ScriptCommandModule.h
index ac65959c..66ede905 100644
--- a/src/c/ScriptCmds/ScriptCommandModule.h
+++ b/src/c/ScriptCmds/ScriptCommandModule.h
@@ -36,6 +36,9 @@
 #include "Commands/ScrCmdDeviceCount.h"
 #include "Commands/ScrCmdDeviceStats.h"
 
+// Debugging: Check Hydra library config from script
+#include "Commands/ScrCmdCheckConfig.h"
+
 // Cuda processing commands
 #include "Commands/ScrCmdClosure.h"
 #include "Commands/ScrCmdElementWiseDifference.h"
diff --git a/src/c/ScriptCmds/ScriptCommands.h b/src/c/ScriptCmds/ScriptCommands.h
index 0d9a10e1..9f12a1ee 100644
--- a/src/c/ScriptCmds/ScriptCommands.h
+++ b/src/c/ScriptCmds/ScriptCommands.h
@@ -25,6 +25,8 @@ SCR_BEGIN_COMMANDS
 												SCR_OUTPUT(SCR_STRUCT, memStats)))
 	SCR_CMD_NOPROC(DeviceStats, SCR_PARAMS(SCR_OUTPUT(SCR_STRUCT, deviceStatsArray)))
 
+	SCR_CMD_NOPROC(CheckConfig, SCR_PARAMS(SCR_OUTPUT(SCR_STRUCT, hydraConfig)))
+
 	SCR_CMD(Closure, SCR_PARAMS
 		(
 			SCR_INPUT(SCR_IMAGE(SCR_DYNAMIC), imageIn),
-- 
GitLab