Browse Source

Added attaching to console and limited debug options. Code from rev. b9d31f7bd564 and rev. d767ac1e60fa.

COM-121
Jorg Knobloch 1 year ago
parent
commit
a66a03f013
3 changed files with 58 additions and 0 deletions
  1. +55
    -0
      pEpCOMServerAdapter.cpp
  2. +2
    -0
      pEpCOMServerAdapter.vcxproj
  3. +1
    -0
      packages.config

+ 55
- 0
pEpCOMServerAdapter.cpp View File

@ -12,6 +12,14 @@
using namespace ATL;
using namespace std;
#ifndef NDEBUG
// Stuff for the JSON server follows.
#include <boost/filesystem/path.hpp>
#include <boost/program_options.hpp>
namespace po = boost::program_options;
std::string logfile = "";
#endif
void CpEpCOMServerAdapterModule::gatekeeper(CpEpCOMServerAdapterModule * self)
{
pEp::GateKeeper keeper(self);
@ -25,6 +33,53 @@ pEp::PassphraseCache cache;
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/,
LPTSTR lpCmdLine, int nShowCmd)
{
#ifndef NDEBUG
std::ios::sync_with_stdio(false);
// Command line options and console output are for debug only.
// Some Windows acrobatics so we can use this even with a command line
// and get some output onto the console.
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
FILE *f;
freopen_s(&f, "conout$", "w", stdout);
freopen_s(&f, "conout$", "w", stderr);
}
po::options_description desc("Program options for the JSON Server Adapter");
desc.add_options()
("help,h", "print this help messages")
("debug,d", "debug,d ignored, only works in JSON mini adapter")
("logfile,l", po::value<std::string>(&logfile)->default_value(logfile),
"Name of the logfile. Can be \"stderr\" for log to stderr or empty for no log.")
;
po::variables_map vm;
try {
std::vector<std::wstring> args = po::split_winmain(lpCmdLine);
po::store(po::wcommand_line_parser(args).options(desc).run(), vm);
po::notify(vm);
} catch (const po::error& e) {
std::cerr << "Cannot parse command line: " << e.what() << "\n\n" << desc << std::endl;
return 2;
}
if (vm.count("help")) {
std::cout << desc << "\n";
return 0;
}
if (logfile.empty()) {
Logger::setDefaultTarget(Logger::Target::None);
} else if (logfile == "stderr") {
Logger::setDefaultTarget(Logger::Target::Console);
} else {
Logger::setDefaultTarget(Logger::Target::File);
}
Logger::start("JsonAdapter", logfile);
#endif
_AtlModule.hModule(hInstance);
_AtlModule.start_gatekeeper();


+ 2
- 0
pEpCOMServerAdapter.vcxproj View File

@ -215,6 +215,7 @@ xcopy /y "..\Dependencies\zlib\zlib1.dll" "$(OutDir)"
<Import Project="..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets" Condition="Exists('..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets')" />
<Import Project="..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets" Condition="Exists('..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets')" />
<Import Project="..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets" Condition="Exists('..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets')" />
<Import Project="..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets" Condition="Exists('..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
@ -226,5 +227,6 @@ xcopy /y "..\Dependencies\zlib\zlib1.dll" "$(OutDir)"
<Error Condition="!Exists('..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_filesystem-vc142.1.72.0.0\build\boost_filesystem-vc142.targets'))" />
<Error Condition="!Exists('..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_thread-vc142.1.72.0.0\build\boost_thread-vc142.targets'))" />
<Error Condition="!Exists('..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_chrono-vc142.1.72.0.0\build\boost_chrono-vc142.targets'))" />
<Error Condition="!Exists('..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\boost_program_options-vc142.1.72.0.0\build\boost_program_options-vc142.targets'))" />
</Target>
</Project>

+ 1
- 0
packages.config View File

@ -4,6 +4,7 @@
<package id="boost_chrono-vc142" version="1.72.0.0" targetFramework="native" />
<package id="boost_date_time-vc142" version="1.72.0.0" targetFramework="native" />
<package id="boost_filesystem-vc142" version="1.72.0.0" targetFramework="native" />
<package id="boost_program_options-vc142" version="1.72.0.0" targetFramework="native" />
<package id="boost_regex-vc142" version="1.72.0.0" targetFramework="native" />
<package id="boost_thread-vc142" version="1.72.0.0" targetFramework="native" />
</packages>

Loading…
Cancel
Save