Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency to UI, use RAII to handle resources #1678

Merged
merged 7 commits into from
Oct 9, 2023
Merged
1 change: 1 addition & 0 deletions src/analyzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ INSTALL(EXPORT antares-analyzer
target_link_libraries(antares-${ANTARES_PRG_VERSION}-analyzer
PRIVATE
yuni-static-core
Antares::args_helper
${CMAKE_THREADS_LIBS_INIT}
antares-core #local.h
PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <yuni/yuni.h>
#include <antares/logs/logs.h>
#include <yuni/core/getopt.h>
#include "../ui/common/winmain.hxx"
#include <antares/args/args_to_utf8.h>
#include <antares/version.h>
#include "atsp/atsp.h"
#include <antares/logs/hostinfo.h>
Expand Down
1 change: 1 addition & 0 deletions src/libs/antares/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

OMESSAGE("Antares Core library")

add_subdirectory(args)
add_subdirectory(writer)
add_subdirectory(memory)

Expand Down
22 changes: 22 additions & 0 deletions src/libs/antares/args/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set(SRC_ARGS_HELPER
args_to_utf8.h
args_to_utf8.cpp
)

source_group("misc\\args_helper" FILES ${SRC_ARGS_HELPER})

add_library(args_helper
${SRC_ARGS_HELPER}
)

add_library(Antares::args_helper ALIAS args_helper)

target_link_libraries(args_helper
PRIVATE
yuni-static-core
)

target_include_directories(args_helper
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
51 changes: 51 additions & 0 deletions src/libs/antares/args/args_to_utf8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#include <yuni/yuni.h>
#include "args_to_utf8.h"


#ifdef YUNI_OS_WINDOWS
#include <string.h>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <windows.h>
#include <shellapi.h>
flomnes marked this conversation as resolved.
Show resolved Hide resolved
#include <stdlib.h>
#include <stdio.h>
flomnes marked this conversation as resolved.
Show resolved Hide resolved
#endif

#ifdef YUNI_OS_WINDOWS
char** AntaresGetUTF8Arguments(int argc, char**)
{
wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
char** argvUTF8 = (char**)malloc(argc * sizeof(char*));
for (int i = 0; i != argc; ++i)
{
const uint len = (uint)wcslen(wargv[i]);
const uint newLen = WideCharToMultiByte(CP_UTF8, 0, wargv[i], len, NULL, 0, NULL, NULL);
argvUTF8[i] = (char*)malloc((newLen + 1) * sizeof(char));
memset(argvUTF8[i], 0, (newLen + 1) * sizeof(char));
WideCharToMultiByte(CP_UTF8, 0, wargv[i], len, argvUTF8[i], newLen, NULL, NULL);
flomnes marked this conversation as resolved.
Show resolved Hide resolved
argvUTF8[i][newLen] = '\0';
}
return argvUTF8;
}

void FreeUTF8Arguments(int argc, char** argv)
{
for (int i = 0; i != argc; ++i)
free(argv[i]);
free(argv);
}

#else

char** AntaresGetUTF8Arguments(int argc, char** argv)
{
return argv;
}

void FreeUTF8Arguments(int argc, char** argv)
{}

#endif
4 changes: 4 additions & 0 deletions src/libs/antares/args/args_to_utf8.h
flomnes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

char** AntaresGetUTF8Arguments(int argc, char** argv);
void FreeUTF8Arguments(int argc, char** argv);
1 change: 1 addition & 0 deletions src/solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ add_executable(antares-solver
set_target_properties(antares-solver PROPERTIES OUTPUT_NAME ${exec_name})

set(ANTARES_SOLVER_LIBS
Antares::args_helper
Antares::date
Antares::benchmarking
Antares::result_writer
Expand Down
2 changes: 1 addition & 1 deletion src/solver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include <antares/logs/logs.h>
#include "application.h"
#include "../ui/common/winmain.hxx" //TODO: remove that reverse dependency to UI
#include <antares/args/args_to_utf8.h>

#include <antares/fatal-error.h>
#include <antares/memory/memory.h>
Expand Down
71 changes: 0 additions & 71 deletions src/ui/common/winmain.hxx

This file was deleted.

5 changes: 2 additions & 3 deletions src/ui/simulator/cmake/application.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ SET(SRC_APPLICATION
application/study.h
application/study.cpp

# The main
../common/winmain.hxx
main.cpp
)

Expand All @@ -72,7 +70,8 @@ target_link_libraries(antares-ui-application
PRIVATE
${wxWidgets_LIBRARIES}
antares-ui-common
antares-core
antares-core
Antares::args_helper
Antares::sys
Antares::study
)
Expand Down
2 changes: 1 addition & 1 deletion src/ui/simulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "application/application.h"
#include "application/main.h"
#include <yuni/core/getopt.h>
#include "../common/winmain.hxx"
#include <antares/args/args_to_utf8.h>
#include <antares/resources/resources.h>
#include <antares/sys/policy.h>
#include <antares/logs/logs.h>
Expand Down