### libcurl Example Usage Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Command to run the libcurl-based ONVIF client demo. This example requires building the examples with `BUILD_EXAMPLES=ON` and assumes libcurl is available. ```bash cd build ./examples/onvif_client_curl_demo http://192.168.1.100/onvif/device_service admin password ``` -------------------------------- ### Build and Run ONVIF Client Examples Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/examples/README.md Instructions for configuring CMake, building the examples, and running them with either Drogon or libcurl HTTP clients. Requires device URL, username, and password. ```bash mkdir build && cd build cmake .. -DBUILD_EXAMPLES=ON cmake --build . ``` ```bash # 使用 Drogon HTTP 客户端 ./examples/onvif_client_demo <设备URL> <用户名> <密码> # 使用 libcurl HTTP 客户端 ./examples/onvif_client_curl_demo <设备URL> <用户名> <密码> ``` -------------------------------- ### Drogon Example Usage Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Command to run the Drogon-based ONVIF client demo. This example requires building the examples with `BUILD_EXAMPLES=ON` and assumes Drogon is available. ```bash cd build ./examples/onvif_client_demo http://192.168.1.100/onvif/device_service admin password ``` -------------------------------- ### Build Examples and Tools with CMake Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Build the example programs and code generation tools by enabling the respective CMake options. This requires creating a build directory and running CMake. ```bash mkdir build && cd build cmake .. -DBUILD_TOOLS=ON -DBUILD_EXAMPLES=ON make -j$(nproc) ``` -------------------------------- ### Install libxml2 on Windows with vcpkg Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Command to install libxml2 for x64 Windows using the vcpkg package manager. ```bash # Windows (vcpkg) vcpkg install libxml2:x64-windows ``` -------------------------------- ### Basic ONVIF Client Usage Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Demonstrates the basic setup and usage of the ONVifClient. This includes creating an HTTP client, initializing the ONVifClient, and making a GetDeviceInformation request. Ensure you implement the IHttpClient interface. ```cpp #include #include #include // 实现 IHttpClient 接口(或使用提供的实现) #include "your_http_client.h" using namespace libonvif_client; int main() { // 创建 HTTP 客户端 auto http_client = std::make_shared(); // 创建 ONVIF 客户端 OnvifClient client( "http://192.168.1.100/onvif/device_service", "admin", "password", http_client ); // 初始化(发现服务) client.initialize([](OnvifResult&& result) { if (result.is_success()) { std::cout << "连接成功!" << std::endl; } }); // 获取设备信息 auto device_client = client.create_device_client(); tds_GetDeviceInformationRequest request; device_client->GetDeviceInformation(request, [](OnvifResult&& result) { if (result.is_success()) { std::cout << "制造商: " << result.data->Manufacturer << std::endl; } }); } ``` -------------------------------- ### Configure libcurl HTTP Client Example with CMake Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/examples/curl/CMakeLists.txt This CMake script configures the build for an ONVIF client example using libcurl. It finds the libcurl package, adds an executable, sets include directories and link libraries, and optionally applies optimizations for release builds. ```cmake find_package(CURL QUIET) # 只有找到 libcurl 时才构建示例 if(CURL_FOUND OR TARGET CURL::libcurl) add_executable(onvif_client_curl_demo curl_demo.cpp curl_http_client.cpp ) # 包含目录 target_include_directories(onvif_client_curl_demo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ) # 链接库 target_link_libraries(onvif_client_curl_demo PRIVATE onvif_demo_common onvif_client CURL::libcurl ) # header-only 模板库优化 if(CMAKE_BUILD_TYPE STREQUAL "Release") # 链接时优化(对模板库特别有效) target_compile_options(onvif_client_curl_demo PRIVATE -flto ) target_link_options(onvif_client_curl_demo PRIVATE -flto ) # 更积极的内联 target_compile_options(onvif_client_curl_demo PRIVATE $<$:-finline-functions> ) endif() # 安装(可选) install(TARGETS onvif_client_curl_demo RUNTIME DESTINATION bin ) message(STATUS "Curl example: enabled") else() message(STATUS "Curl example: disabled - libcurl not found") endif() ``` -------------------------------- ### libcurl HTTP Client Integration Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Example of initializing the libonvif_client with a libcurl-based HTTP client, including SSL verification settings. ```cpp #include "curl_http_client.h" auto http_client = std::make_shared(true, 4); http_client->set_ssl_verify(false); OnvifClient client(url, username, password, http_client); ``` -------------------------------- ### Release Build Optimization Example Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Example CMake compile options for optimizing release builds, including Link-Time Optimization (LTO) and inlining functions. ```cmake # Release 构建 target_compile_options(my_app PRIVATE -flto -finline-functions) ``` -------------------------------- ### Install libxml2 on macOS Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Command to install libxml2 using Homebrew on macOS. ```bash # macOS brew install libxml2 ``` -------------------------------- ### Install libxml2-dev on Ubuntu/Debian Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Command to install the libxml2 development package on Ubuntu or Debian-based systems, required for XML parsing. ```bash # Ubuntu/Debian sudo apt-get install libxml2-dev ``` -------------------------------- ### Generate ONVIF Device Management Client Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Example of generating ONVIF client code for device management. This involves preparing a configuration file and running the wsdl_parser2 tool. ```bash # 1. 准备配置文件 config.json cat > config.json << EOF { "output_types_header_dir": "./include/types", "output_client_header_dir": "./include/client", "output_client_source_dir": "./src/client", "generate_types": true, "generate_clients": true, "schema_configs": [ { "ns_url": "http://www.onvif.org/ver10/schema", "ns_prefix": "tt", "output_name": "common" }, { "ns_url": "http://www.onvif.org/ver10/device/wsdl", "ns_prefix": "tds", "output_name": "device" } ] } EOF # 2. 运行解析器 ./wsdl_parser2 -c config.json devicemgmt.wsdl # 3. 输出 # ✅ 生成了 2 个类型文件 # - include/types/common.h # - include/types/device.h # ✅ 生成了 1 个客户端 # - include/client/DeviceClient.h # - src/client/DeviceClient.cpp ``` -------------------------------- ### CMake Configuration for Generated Code Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Example CMake configuration to include generated header files and link against the onvif_client library, and set the C++ standard. ```cmake # CMakeLists.txt target_include_directories(your_target PRIVATE ${CMAKE_SOURCE_DIR}/generated/include) target_link_libraries(your_target PRIVATE onvif_client) set_target_properties(your_target PROPERTIES CXX_STANDARD 17) ``` -------------------------------- ### OnvifResult Usage Example Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Demonstrates how to check the success or failure of an ONVIF operation that does not return data. ```cpp OnvifResult result; if (result.is_success()) { // 操作成功 } else { std::cout << result.get_error_message() << std::endl; } ``` -------------------------------- ### Using Generated ONVIF Client Code Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Example of how to use the generated DeviceClient in a C++ application. It shows creating an HTTP client, instantiating the DeviceClient, and calling the GetDeviceInformation method. ```cpp // main.cpp - 使用生成的客户端代码 #include "client/DeviceClient.h" #include "transport/drogon_http_client.h" #include using namespace libonvif_client; int main() { // 1. 创建 HTTP 客户端 auto http_client = std::make_unique(); // 2. 创建设备客户端 DeviceClient device_client( "http://192.168.1.100/onvif/device_service", *http_client, "admin", "password" ); // 3. 调用 GetDeviceInformation tds_GetDeviceInformation request; device_client.GetDeviceInformation(request, [](const tds_GetDeviceInformationResponse* response, const OnvifError* error) { if (error) { std::cerr << "Error: " << error->message << std::endl; return; } std::cout << "Manufacturer: " << response->Manufacturer << std::endl; std::cout << "Model: " << response->Model << std::endl; std::cout << "Serial Number: " << response->SerialNumber << std::endl; }); return 0; } ``` -------------------------------- ### CMake for Header-Only Library Usage Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Include the header-only library by specifying its path and linking against libxml2. This setup is for using the library without compiling it. ```cmake find_package(LibXml2 REQUIRED) add_executable(my_app main.cpp) target_link_libraries(my_app PRIVATE LibXml2::LibXml2) target_include_directories(my_app PRIVATE /path/to/libonvif_client/include) ``` -------------------------------- ### Scenario 1: Initial ONVIF Code Generation Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Steps to set up directories, create a configuration file, and run the parser for initial ONVIF code generation. ```bash # 1. 准备工作目录 mkdir -p onvif_gen/{include,src,cache} cd onvif_gen # 2. 创建配置文件 cat > config.json << 'EOF' { "output_types_header_dir": "./include/types", "output_client_header_dir": "./include/client", "output_client_source_dir": "./src/client", "cache_dir": "./cache", "schema_configs": [ { "ns_url": "http://www.onvif.org/ver10/schema", "ns_prefix": "tt", "output_name": "common" }, { "ns_url": "http://www.onvif.org/ver10/device/wsdl", "ns_prefix": "tds", "output_name": "device" } ] } EOF # 3. 运行解析器 wsdl_parser2 -c config.json -v \ https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl # 4. 查看生成的文件 tree include src # 5. libonvif_client ./wsdl_parser2 \ https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl \ http://www.onvif.org/onvif/ver10/analyticsdevice.wsdl \ http://www.onvif.org/onvif/ver10/replay.wsdl \ http://www.onvif.org/onvif/ver10/search.wsdl \ http://www.onvif.org/onvif/ver10/recording.wsdl \ http://www.onvif.org/onvif/ver20/ptz/wsdl/ptz.wsdl \ http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl \ http://www.onvif.org/onvif/ver20/media/wsdl/media.wsdl \ http://www.onvif.org/onvif/ver20/imaging/wsdl/imaging.wsdl \ http://www.onvif.org/onvif/ver20/analytics/wsdl/analytics.wsdl \ https://www.onvif.org/onvif/ver10/events/wsdl/event.wsdl ``` -------------------------------- ### Display Help Information Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Use the -h or --help option to display all available command-line options and their descriptions. ```bash ./wsdl_parser2 --help ``` -------------------------------- ### Scenario 2: Incrementally Add Services Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Instructions for adding new services to an existing project by updating the configuration and re-running the parser. ```bash # 已有 Device 服务,现在添加 Media 服务 # 1. 更新配置文件,添加 Media 配置 # 2. 运行解析器 wsdl_parser2 -c config.json \ https://www.onvif.org/ver10/media/wsdl/media.wsdl # 工具会自动跳过已生成的类型,仅生成新的 MediaClient ``` -------------------------------- ### Initialize DrogonHttpClient Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/examples/README.md Demonstrates how to initialize and configure the DrogonHttpClient for use with the libonvif_client library. SSL verification can be disabled. ```cpp #include "http_clients/drogon_http_client.h" auto http_client = std::make_shared(true); http_client->set_ssl_verify(false); ``` -------------------------------- ### Minimum Configuration Template Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md A minimal JSON configuration file specifying output directories and schema mappings. ```json { "output_types_header_dir": "./include/types", "output_client_header_dir": "./include/client", "output_client_source_dir": "./src/client", "schema_configs": [ { "ns_url": "http://www.onvif.org/ver10/device/wsdl", "ns_prefix": "tds", "output_name": "device" } ] } ``` -------------------------------- ### Full Configuration Template Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md A comprehensive JSON configuration file with all available options for detailed control over code generation. ```json { "output_types_header_dir": "./include/types", "output_client_header_dir": "./include/client", "output_client_source_dir": "./src/client", "cache_dir": "./cache", "generate_types": true, "generate_clients": true, "verbose": false, "ignore_missing_deps": false, "detect_duplicates": true, "smart_merge": true, "client_namespace": "libonvif_client", "schema_configs": [ { "comment": "配置说明(可选)", "ns_url": "命名空间URL(必需)", "ns_prefix": "命名空间前缀(必需)", "output_name": "输出文件名(必需)", "source_files": ["源文件列表(可选)"], "priority": 10, "dependencies": ["依赖列表(可选)"] } ] } ``` -------------------------------- ### Scenario 4: Batch Generate All ONVIF Services Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md A bash script to automate the generation of all ONVIF services by listing their WSDL URLs. ```bash #!/bin/bash # generate_all_onvif.sh BASE_URL="https://www.onvif.org" wsdl_parser2 -c config.json -v \ ${BASE_URL}/ver10/device/wsdl/devicemgmt.wsdl \ ${BASE_URL}/ver10/media/wsdl/media.wsdl \ ${BASE_URL}/ver20/ptz/wsdl/ptz.wsdl \ ${BASE_URL}/ver20/imaging/wsdl/imaging.wsdl \ ${BASE_URL}/ver20/analytics/wsdl/analytics.wsdl \ ${BASE_URL}/ver10/recording/wsdl/recording.wsdl \ ${BASE_URL}/ver10/replay/wsdl/replay.wsdl \ ${BASE_URL}/ver10/search/wsdl/search.wsdl ``` -------------------------------- ### Parse WSDL with Configuration File Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Specify a configuration file using the -c option for custom parsing settings. ```bash ./wsdl_parser2 -c config.json file.wsdl ``` -------------------------------- ### Define onvif_demo_common Static Library Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/examples/common/CMakeLists.txt Configures a static library named 'onvif_demo_common' with specified source files. ```cmake add_library(onvif_demo_common STATIC onvif_demo_printers.cpp onvif_demo_custom_types.cpp onvif_demo_common.cpp ) ``` -------------------------------- ### Create Test Executable Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/tests/CMakeLists.txt Defines the test executable 'test_basic' and includes the specified source files. ```cmake # 创建测试可执行文件 add_executable(test_basic test_basic.cpp ${TEST_SOURCES} ) ``` -------------------------------- ### Include Directories Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/tests/CMakeLists.txt Specifies the include directories for the 'test_basic' target, including a project-specific include and libxml2 headers. ```cmake # 包含目录 target_include_directories(test_basic PRIVATE ../include ${LIBXML2_INCLUDE_DIRS} ) ``` -------------------------------- ### Link onvif_demo_common with onvif_client Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/examples/common/CMakeLists.txt Links the 'onvif_demo_common' library against the 'onvif_client' library, making its functionality available. ```cmake target_link_libraries(onvif_demo_common PUBLIC onvif_client ) ``` -------------------------------- ### Basic CMake Configuration Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/tests/CMakeLists.txt Sets the minimum CMake version required and defines the source files for the test executable, excluding the main.cpp file. ```cmake cmake_minimum_required(VERSION 3.16) # 测试源文件(排除main.cpp) set(TEST_SOURCES ../src/config.cpp ../src/file_info.cpp ../src/downloader.cpp ../src/wsdl_parser.cpp ../src/type_generator.cpp ../src/client_generator.cpp ) ``` -------------------------------- ### Link Libraries Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/tests/CMakeLists.txt Links the 'test_basic' executable against the libxml2 libraries. ```cmake # 链接库 target_link_libraries(test_basic ${LIBXML2_LIBRARIES} ) ``` -------------------------------- ### Compile Options Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/tests/CMakeLists.txt Applies libxml2-specific compile options to the 'test_basic' target. ```cmake # 编译选项 target_compile_options(test_basic PRIVATE ${LIBXML2_CFLAGS_OTHER}) ``` -------------------------------- ### Set Public Include Directories for onvif_demo_common Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/examples/common/CMakeLists.txt Specifies public include directories for the 'onvif_demo_common' library, making them available to targets that link against it. ```cmake target_include_directories(onvif_demo_common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/include ) ``` -------------------------------- ### HTTP Digest Authentication Client Implementation Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Implement the `IHttpClient` interface to handle HTTP Digest Authentication. This involves making an initial request to obtain authentication challenges (realm, nonce, qop), calculating the digest response, and re-sending the request with the `Authorization` header. ```cpp class DigestHttpClient : public IHttpClient { public: DigestHttpClient(const std::string& username, const std::string& password) : username_(username), password_(password) {} void request_async(Request request, Callback callback) override { // 第一次请求,获取 401 响应和 WWW-Authenticate 头 // 解析 realm、nonce、qop 等参数 // 计算摘要响应 // 重新发送带 Authorization 头的请求 // ... } private: std::string username_; std::string password_; }; ``` -------------------------------- ### Generate Only Clients for Testing Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Command to generate only client code, useful for testing client generation independently after types have been verified. ```bash # 确认无误后再生成客户端 ./wsdl_parser2 --clients-only devicemgmt.wsdl ``` -------------------------------- ### Batch Generate All ONVIF Services Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Command to generate clients for multiple ONVIF services by providing a list of WSDL URLs to the wsdl_parser2 tool. ```bash # 从 ONVIF 官网下载所有 WSDL 文件 WSDL_BASE="https://www.onvif.org/ver10" ./wsdl_parser2 -c config.json \ ${WSDL_BASE}/device/wsdl/devicemgmt.wsdl \ ${WSDL_BASE}/media/wsdl/media.wsdl \ ${WSDL_BASE}/ptz/wsdl/ptz.wsdl \ ${WSDL_BASE}/imaging/wsdl/imaging.wsdl \ ${WSDL_BASE}/analytics/wsdl/analytics.wsdl \ ${WSDL_BASE}/recording/wsdl/recording.wsdl ``` -------------------------------- ### Build Completion Message Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/tests/CMakeLists.txt Prints a status message indicating that the test configuration is complete. ```cmake message(STATUS "测试配置完成") ``` -------------------------------- ### Configure CurlHttpClient Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/examples/README.md Initializes and configures the CurlHttpClient for making HTTP requests. Set SSL verification to false and connection timeout to 10 seconds. ```cpp #include "http_clients/curl_http_client.h" auto http_client = std::make_shared(true, 4); http_client->set_ssl_verify(false); http_client->set_connect_timeout(10); ``` -------------------------------- ### Set Output Directory Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/tests/CMakeLists.txt Configures the 'test_basic' target to place its runtime output in a 'tests' subdirectory within the CMAKE_BINARY_DIR. ```cmake # 设置输出目录 set_target_properties(test_basic PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests ) ``` -------------------------------- ### Code Generation with wsdl_parser2 Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Commands to build the code generator tool and use it to generate ONVIF client code from a WSDL file. ```bash # 构建代码生成器 cmake .. -DBUILD_TOOLS=ON make wsdl_parser2 # 从 WSDL 生成代码 ./wsdl_parser2 input.wsdl output_dir ``` -------------------------------- ### Enable Verbose Output for wsdl_parser2 Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Command to run the wsdl_parser2 tool with verbose output enabled, useful for debugging parsing and generation processes. ```bash ./wsdl_parser2 -v devicemgmt.wsdl ``` -------------------------------- ### Automatic ServiceClient Registration Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Demonstrates how the generated DeviceClient is automatically registered with the ServiceClientFactory using a ServiceClientRegistrar. ```cpp // DeviceClient.cpp static ServiceClientRegistrar tds_service_registrar( "http://www.onvif.org/ver10/device/wsdl", "tds", [](const std::string& endpoint, const std::shared_ptr &http_client, const std::string& username, const std::string& password) -> std::shared_ptr { return std::make_shared( endpoint, http_client, username, password); } ); ``` -------------------------------- ### Smart Pointer Usage for Callback Safety Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Demonstrates the correct way to capture smart pointers in C++ callbacks to ensure object lifetime, contrasting it with the incorrect use of raw pointers. ```cpp // 正确:捕获 shared_ptr auto device = client.create_device_client(); device->GetInfo([device](auto&& result) { /* device 仍然有效 */ }); // 错误:捕获可能被销毁的原始指针 DeviceClient* raw_ptr = device.get(); device->GetInfo([raw_ptr](auto&& result) { /* 未定义行为 */ }); ``` -------------------------------- ### Error Handling with OnvifResult Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Shows how to handle errors returned by ONVIF operations using the OnvifResult structure, including accessing SOAP faults and raw XML. ```cpp client->GetDeviceInformation(request, [](OnvifResult&& result) { if (result.is_error()) { // 检查错误类型 auto& fault = result.soap_fault; std::cout << "SOAP Fault: " << fault->code << "\n"; std::cout << "Reason: " << fault->reason << "\n"; // 获取原始 XML 用于调试 std::cout << "Raw XML:\n" << result.get_raw_xml() << "\n"; } }); ``` -------------------------------- ### WS-UsernameToken Authentication Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Configure the ONVifClient with a username and password to enable WS-UsernameToken authentication. The library automatically handles nonce generation, timestamping, and SHA1 hashing for the SOAP header. ```cpp OnvifClient client( "http://192.168.1.100/onvif/device_service", "admin", // 用户名 "password123", // 密码 http_client ); ``` -------------------------------- ### DeviceClient Header Definition Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Defines the DeviceClient class, which inherits from OnvifServiceBase and provides methods for interacting with ONVIF device services. ```cpp // DeviceClient.h class DeviceClient : public OnvifServiceBase { publicpublic: DeviceClient(const std::string& service_url, const std::shared_ptr &http_client, const std::string& username = "", const std::string& password = ""); void GetDeviceInformation( const tds_GetDeviceInformation& request, OnvifCallback callback); // ... 其他操作方法 }; ``` -------------------------------- ### Add Test Case Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/tests/CMakeLists.txt Enables testing and defines a test case named 'BasicFunctionality' that executes the 'test_basic' command. ```cmake # 添加测试 enable_testing() add_test(NAME BasicFunctionality COMMAND test_basic) ``` -------------------------------- ### Parse Multiple WSDL Files Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Parse multiple WSDL files simultaneously by listing them after the command. ```bash ./wsdl_parser2 file1.wsdl file2.wsdl file3.wsdl ``` -------------------------------- ### ONVIF Client Without Authentication Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Instantiate the ONVifClient without providing username and password credentials. This bypasses WS-Security authentication and is suitable for devices that do not require authentication or are secured by other means. ```cpp // 方式1:使用空字符串 OnvifClient client( "http://192.168.1.100/onvif/device_service", "", // 无用户名 "", // 无密码 http_client ); // 方式2:不传递认证参数 OnvifClient client( "http://192.168.1.100/onvif/device_service", http_client ); ``` -------------------------------- ### Generate Clients Only Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Use the --clients-only option to generate only client code from WSDL files. ```bash ./wsdl_parser2 --clients-only file.wsdl ``` -------------------------------- ### Parse WSDL with Verbose Output Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Enable detailed output during parsing using the -v option for debugging. ```bash ./wsdl_parser2 -v file.wsdl ``` -------------------------------- ### Scenario 3: Debugging Parsing Issues Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Use verbose mode and log redirection to capture detailed parsing information for debugging. Filter logs for warnings and errors. ```bash # 使用详细模式查看详细信息 wsdl_parser2 -v -c config.json file.wsdl 2>&1 | tee parse.log # 查看警告和错误 grep -E "警告|错误|Warning|Error" parse.log # 检查生成的文件数量 find include src -type f | wc -l ``` -------------------------------- ### Parse Single WSDL File Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Use this command to parse a single WSDL file and generate code. ```bash ./wsdl_parser2 file.wsdl ``` -------------------------------- ### Set Cache Directory Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Specify a directory for caching parsed WSDL data using the --cache-dir option. ```bash ./wsdl_parser2 --cache-dir ./cache file.wsdl ``` -------------------------------- ### Ignore Missing Dependencies Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Use the --ignore-missing-deps option to continue parsing even if some dependencies are not found. ```bash ./wsdl_parser2 --ignore-missing-deps file.wsdl ``` -------------------------------- ### Generate Only Types for Testing Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Command to first generate only type definitions, allowing for verification before proceeding to client generation. ```bash # 先只生成类型定义 ./wsdl_parser2 --types-only common.xsd ``` -------------------------------- ### Validate JSON Configuration Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Command to validate the JSON format of the configuration file using jq. ```bash # 验证 JSON 格式 jq . config.json ``` -------------------------------- ### IHttpClient Interface Definition Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Defines the `IHttpClient` interface that must be implemented by users to provide custom HTTP client functionality. It includes structures for `Request` and `Response`, and an asynchronous `request_async` method. ```cpp class IHttpClient { public: struct Request { std::string url; std::string action; std::shared_ptr xml_doc; int timeout_ms = 5000; }; struct Response { int status_code = 0; bool timeout = false; std::string_view body; std::string error; bool is_success() const; bool has_http_error() const; }; using Callback = std::function; virtual void request_async(Request request, Callback callback) = 0; virtual ~IHttpClient() = default; }; ``` -------------------------------- ### Generate Types Only Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/USER_MANUAL.md Use the --types-only option to generate only type definitions from XSD files. ```bash ./wsdl_parser2 --types-only file.xsd ``` -------------------------------- ### Generate Only Type Definitions Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/tools/wsdl_parser2/README.md Instructs the wsdl_parser2 tool to only generate type definitions (XSD parsing) without generating client code. ```bash # 仅解析 XSD 文件,不生成客户端 ./wsdl_parser2 --types-only \ common.xsd \ onvif.xsd \ metadatastream.xsd ``` -------------------------------- ### OnvifResult Structure Definition Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/README.md Defines the structure for handling ONVIF operation results, including success data, SOAP faults, and raw XML. ```cpp template struct OnvifResult { std::unique_ptr data; std::unique_ptr soap_fault; std::shared_ptr xml_doc; xmlNodePtr response_node; bool is_success() const; bool is_error() const; operator bool() const; std::string get_error_message() const; std::string get_raw_xml() const; }; ``` -------------------------------- ### Disable SSL Certificate Verification Source: https://github.com/chengxiaosheng/libonvif_client/blob/main/examples/README.md This code snippet disables SSL certificate verification, which is often necessary for ONVIF devices using self-signed certificates. Use with caution. ```cpp http_client_ptr->set_ssl_verify(false); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.