From eee77a3cd6bb8f7baeca5eaf3aae40d8df1a6cce Mon Sep 17 00:00:00 2001 From: Grzegorz Rychlik Date: Wed, 23 Oct 2019 16:53:42 +0200 Subject: [PATCH] Create stub for C3 channel linter --- Src/C3.sln | 15 ++ Src/ChannelLinter/ChannelLinter.cpp | 51 ++++ Src/ChannelLinter/ChannelLinter.vcxproj | 320 ++++++++++++++++++++++++ Src/ChannelLinter/InputContext.cpp | 23 ++ Src/ChannelLinter/InputContext.h | 23 ++ Src/ChannelLinter/StdAfx.h | 11 + Src/ChannelLinter/Stdafx.cpp | 1 + 7 files changed, 444 insertions(+) create mode 100644 Src/ChannelLinter/ChannelLinter.cpp create mode 100644 Src/ChannelLinter/ChannelLinter.vcxproj create mode 100644 Src/ChannelLinter/InputContext.cpp create mode 100644 Src/ChannelLinter/InputContext.h create mode 100644 Src/ChannelLinter/StdAfx.h create mode 100644 Src/ChannelLinter/Stdafx.cpp diff --git a/Src/C3.sln b/Src/C3.sln index 23e4835..6e2c93b 100644 --- a/Src/C3.sln +++ b/Src/C3.sln @@ -23,12 +23,15 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Core", "Core\Core.vcxproj", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebController", "WebController\Backend\WebController.csproj", "{023B2DB0-6DA4-4F0D-988B-4D9BF522DA37}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ChannelLinter", "ChannelLinter\ChannelLinter.vcxproj", "{F2EC73D1-D533-4EE4-955A-A62E306472CC}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution Common\Common.vcxitems*{5cc52339-4b11-47df-b1db-18fbcf057123}*SharedItemsImports = 9 Common\Common.vcxitems*{946619c2-5959-4c0c-bc7c-1c27d825b042}*SharedItemsImports = 4 Common\Common.vcxitems*{b7c64002-5002-410f-868c-826073afa924}*SharedItemsImports = 4 Common\Common.vcxitems*{d00c849b-4fa5-4e84-b9ef-b1c8c338647a}*SharedItemsImports = 4 + Common\Common.vcxitems*{f2ec73d1-d533-4ee4-955a-a62e306472cc}*SharedItemsImports = 4 EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -99,6 +102,18 @@ Global {023B2DB0-6DA4-4F0D-988B-4D9BF522DA37}.ReleaseWithDebInfo|x64.Build.0 = ReleaseWithDebInfo|Any CPU {023B2DB0-6DA4-4F0D-988B-4D9BF522DA37}.ReleaseWithDebInfo|x86.ActiveCfg = ReleaseWithDebInfo|Any CPU {023B2DB0-6DA4-4F0D-988B-4D9BF522DA37}.ReleaseWithDebInfo|x86.Build.0 = ReleaseWithDebInfo|Any CPU + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.Debug|x64.ActiveCfg = Debug|x64 + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.Debug|x64.Build.0 = Debug|x64 + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.Debug|x86.ActiveCfg = Debug|Win32 + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.Debug|x86.Build.0 = Debug|Win32 + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.Release|x64.ActiveCfg = Release|x64 + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.Release|x64.Build.0 = Release|x64 + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.Release|x86.ActiveCfg = Release|Win32 + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.Release|x86.Build.0 = Release|Win32 + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.ReleaseWithDebInfo|x64.ActiveCfg = Release|x64 + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.ReleaseWithDebInfo|x64.Build.0 = Release|x64 + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.ReleaseWithDebInfo|x86.ActiveCfg = Release|Win32 + {F2EC73D1-D533-4EE4-955A-A62E306472CC}.ReleaseWithDebInfo|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Src/ChannelLinter/ChannelLinter.cpp b/Src/ChannelLinter/ChannelLinter.cpp new file mode 100644 index 0000000..97882cd --- /dev/null +++ b/Src/ChannelLinter/ChannelLinter.cpp @@ -0,0 +1,51 @@ +#include "StdAfx.h" +#include "InputContext.h" + +namespace MWR::C3::Linter +{ + void OutputDebug(std::string_view output) + { +#ifdef _DEBUG + std::cout << output << std::endl; +#endif // _DEBUG + } + + /// @throws std::runtime_error if channel with given name was not registered + auto const& GetChannelInfo(std::string_view channelName) + { + return InterfaceFactory::Instance().Find(channelName)->second; + } +} + + +/// Entry point of the application. +/// @param argc number of program arguments. +/// @param argv vector of program arguments. +int main(DWORD argc, char* argv[]) +try +{ + using namespace MWR; + using json = nlohmann::json; + + std::cout << "Custom Command and Control - Channel linter. BUILD: " << C3_BUILD_VERSION << std::endl; + C3::Linter::InputContext context(argc, argv); + + // select channel + auto const& chInfo = C3::Linter::GetChannelInfo(context.GetChannelName()); + + // read create and prompt for arguments + auto capability = json::parse(chInfo.m_Capability); + C3::Linter::OutputDebug(capability.dump(4)); + return 0; +} +catch (MWR::C3::Linter::InputError & e) +{ + std::cerr << e.what() << std::endl; + std::cerr << MWR::C3::Linter::InputContext::GetUsage() << std::endl; + return 1; +} +catch (std::exception & e) +{ + std::cerr << "Error occurred: " << e.what() << std::endl; + return 1; +} diff --git a/Src/ChannelLinter/ChannelLinter.vcxproj b/Src/ChannelLinter/ChannelLinter.vcxproj new file mode 100644 index 0000000..e5ee38a --- /dev/null +++ b/Src/ChannelLinter/ChannelLinter.vcxproj @@ -0,0 +1,320 @@ + + + + + Debug + Win32 + + + ReleaseWithDebInfo + Win32 + + + ReleaseWithDebInfo + x64 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {F2EC73D1-D533-4EE4-955A-A62E306472CC} + Win32Proj + CableTester + 8.1 + ChannelLinter + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)..\Tmp\$(ProjectName)\$(Configuration)\ + $(SolutionDir)..\Bin\ + $(ProjectName)_d86 + + + true + $(SolutionDir)..\Tmp\$(ProjectName)\$(Configuration)\ + $(SolutionDir)..\Bin\ + $(ProjectName)_d64 + + + false + $(SolutionDir)..\Tmp\$(ProjectName)\$(Configuration)\ + $(SolutionDir)..\Bin\ + $(ProjectName)_r86 + + + false + $(SolutionDir)..\Tmp\$(ProjectName)\$(Configuration)\ + $(SolutionDir)..\Bin\ + $(ProjectName)_rwdi86 + + + false + $(SolutionDir)..\Tmp\$(ProjectName)\$(Configuration)\ + $(SolutionDir)..\Bin\ + $(ProjectName)_r64 + + + false + $(SolutionDir)..\Tmp\$(ProjectName)\$(Configuration)\ + $(SolutionDir)..\Bin\ + $(ProjectName)_rwdi64 + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions); + true + + + MultiThreadedDebug + stdcpp17 + $(SolutionDir);$(ProjectDir);$(SolutionDir)/Common + false + + + Console + true + $(SolutionDir);$(ProjectDir) + /ignore:4099 %(AdditionalOptions) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Netapi32.lib;%(AdditionalDependencies) + + + + + Use + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions); + true + + + MultiThreadedDebug + stdcpp17 + $(SolutionDir);$(ProjectDir);$(SolutionDir)/Common + false + + + Console + true + $(SolutionDir);$(ProjectDir) + /ignore:4099 %(AdditionalOptions) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Netapi32.lib;%(AdditionalDependencies) + + + + + Level3 + Use + MinSpace + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions); + true + + + MultiThreaded + ProgramDatabase + Size + stdcpp17 + true + $(SolutionDir);$(ProjectDir);$(SolutionDir)/Common + false + + + Console + true + true + false + $(SolutionDir);$(ProjectDir) + /ignore:4099 %(AdditionalOptions) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Netapi32.lib;%(AdditionalDependencies) + + + + + Level3 + Use + MinSpace + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions); + true + + + MultiThreaded + ProgramDatabase + Size + stdcpp17 + true + $(SolutionDir);$(ProjectDir);$(SolutionDir)/Common + false + + + Console + true + true + true + $(SolutionDir);$(ProjectDir) + /ignore:4099 %(AdditionalOptions) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Netapi32.lib;%(AdditionalDependencies) + + + + + Level3 + Use + MinSpace + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions); + true + + + MultiThreaded + ProgramDatabase + Size + stdcpp17 + true + $(SolutionDir);$(ProjectDir);$(SolutionDir)/Common + false + + + Console + true + true + false + $(SolutionDir);$(ProjectDir) + /ignore:4099 %(AdditionalOptions) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Netapi32.lib;%(AdditionalDependencies) + + + + + Level3 + Use + MinSpace + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions); + true + + + MultiThreaded + ProgramDatabase + Size + stdcpp17 + true + $(SolutionDir);$(ProjectDir);$(SolutionDir)/Common + false + + + Console + true + true + true + $(SolutionDir);$(ProjectDir) + /ignore:4099 %(AdditionalOptions) + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Netapi32.lib;%(AdditionalDependencies) + + + + + + + + + + + Create + Create + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/Src/ChannelLinter/InputContext.cpp b/Src/ChannelLinter/InputContext.cpp new file mode 100644 index 0000000..151e326 --- /dev/null +++ b/Src/ChannelLinter/InputContext.cpp @@ -0,0 +1,23 @@ +#include "stdafx.h" +#include "InputContext.h" + +namespace MWR::C3::Linter +{ + InputContext::InputContext(int argc, char* argv[]) + { + if (argc < 2) + throw InputError("No channel name specified"); + + m_ChannelName = argv[1]; + } + + std::string_view InputContext::GetChannelName() const + { + return m_ChannelName; + } + + std::string_view InputContext::GetUsage() + { + return "TODO"; + } +} diff --git a/Src/ChannelLinter/InputContext.h b/Src/ChannelLinter/InputContext.h new file mode 100644 index 0000000..ac97be3 --- /dev/null +++ b/Src/ChannelLinter/InputContext.h @@ -0,0 +1,23 @@ +#pragma once + +namespace MWR::C3::Linter +{ + struct InputError : public std::exception + { + using std::exception::exception; + using std::exception::what; + }; + + class InputContext { + public: + InputContext(int argc, char* argv[]); + + std::string_view GetChannelName() const; + + static std::string_view GetUsage(); + + private: + std::string m_ChannelName; + }; +} + diff --git a/Src/ChannelLinter/StdAfx.h b/Src/ChannelLinter/StdAfx.h new file mode 100644 index 0000000..63b6d9c --- /dev/null +++ b/Src/ChannelLinter/StdAfx.h @@ -0,0 +1,11 @@ +#pragma once + +/// Compile C3 channel tester as Gateway (Include interface metadata) +#define C3_IS_GATEWAY + +// Standard library includes. +#include + +// C3 inclusion. +#include "Common/MWR/C3/Sdk.hpp" +#include "Common/C3_BUILD_VERSION_HASH_PART.hxx" \ No newline at end of file diff --git a/Src/ChannelLinter/Stdafx.cpp b/Src/ChannelLinter/Stdafx.cpp new file mode 100644 index 0000000..e717491 --- /dev/null +++ b/Src/ChannelLinter/Stdafx.cpp @@ -0,0 +1 @@ +#include "StdAfx.h"