Skip to content

Commit

Permalink
Add config file handling and improve error logging
Browse files Browse the repository at this point in the history
Updated CMakeLists.txt to configure and install ChatGPTIPAProvider.json.
Reorganized and cleaned up installation commands. Removed unnecessary
PROJECT_CONFIG_DIR commands. Enhanced ChatGPTIPAProvider.cpp to use
std::filesystem::path for config file path construction and improved
error handling with std::error_code. Parsed config file using
nlohmann::json for provider settings initialization.
  • Loading branch information
schnelle committed Jan 10, 2025
1 parent 0409311 commit 6b49183
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
9 changes: 9 additions & 0 deletions source/w3cipa/w3cipachatgptipaprovider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ target_link_libraries(${PROJECT_NAME} w3cipareferenceimplementation)
target_link_libraries(${PROJECT_NAME} w3cipaframework)
target_include_directories(${PROJECT_NAME} PUBLIC include)

#
# Add configuration files
#
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ChatGPTIPAProvider.json
${PROJECT_CONFIG_DIR}/ChatGPTIPAProvider.json COPYONLY)

#
# Installation
#
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/ChatGPTIPAProvider.json DESTINATION config)
install(TARGETS ${PROJECT_NAME} FILE_SET HEADERS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,18 @@ ChatGPTIPAProvider::ChatGPTIPAProvider() {
}

void ChatGPTIPAProvider::initialize() {
std::string configFile = "config";
configFile += std::filesystem::path::preferred_separator;
configFile += "ChatGPTIPAProvider.json";
if (!std::filesystem::exists(configFile)) {
std::filesystem::path configFile{"config/ChatGPTIPAProvider.json"};
// Check if the configuration file exists
std::error_code ec;
if (!std::filesystem::exists(configFile, ec)) {
LOG4CPLUS_ERROR_FMT(
LOGGER,
LOG4CPLUS_TEXT(
"ChatGPT IPA provider configuration file %s not found"),
configFile.c_str());
"ChatGPT IPA provider configuration file %s not found. %s (%d)"),
configFile.c_str(), ec.message().c_str(), ec.value());
return;
}
// Parse the configuration file and initialize this provider
std::ifstream file(configFile);
nlohmann::json json = nlohmann::json::parse(file);
ChatGPTConfiguration configuration = json;
Expand Down
14 changes: 8 additions & 6 deletions source/w3cipa/w3cipademo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/log4cplus.properties
DESTINATION config)
install(DIRECTORY ${W3CIPA_OPEN_SOURCE_SRC}/bin/
DESTINATION bin)

#
# Add configuration files
#
set(PROJECT_CONFIG_DIR ${CMAKE_CURRENT_BINARY_DIR}/config)
file(MAKE_DIRECTORY ${PROJECT_CONFIG_DIR})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/log4cplus.properties
${PROJECT_CONFIG_DIR}/log4cplus.properties COPYONLY)

#
# Installation
#
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/log4cplus.properties
DESTINATION config)
install(DIRECTORY ${W3CIPA_OPEN_SOURCE_SRC}/bin/
DESTINATION bin)

0 comments on commit 6b49183

Please sign in to comment.