@@ -113,6 +113,42 @@ int main() {
113113}
114114` ` `
115115
116+ # #### Error Handling in C++
117+
118+ Starting from v1.1.0, C++ interface supports error callbacks for detailed error reporting:
119+
120+ ` ` ` cpp
121+ # include <ccap.h>
122+ # include <iostream>
123+
124+ int main () {
125+ ccap::Provider provider;
126+
127+ // Set error callback to receive detailed error information
128+ provider.setErrorCallback([](ccap::ErrorCode errorCode, const std::string& description) {
129+ std::cerr << "Camera Error - Code: " << static_cast<int>(errorCode)
130+ << ", Description: " << description << std::endl;
131+ });
132+
133+ // Camera operations - errors will trigger the callback
134+ if (!provider.open("", true)) {
135+ std::cerr << "Failed to open camera" << std::endl;
136+ }
137+
138+ return 0;
139+ }
140+ ` ` `
141+
142+ Available error codes include:
143+ - ` ErrorCode::NoDeviceFound` - No camera device found
144+ - ` ErrorCode::InvalidDevice` - Invalid device name or index
145+ - ` ErrorCode::DeviceOpenFailed` - Camera open failed
146+ - ` ErrorCode::DeviceStartFailed` - Camera start failed
147+ - ` ErrorCode::UnsupportedResolution` - Unsupported resolution
148+ - ` ErrorCode::UnsupportedPixelFormat` - Unsupported pixel format
149+ - ` ErrorCode::FrameCaptureTimeout` - Frame capture timeout
150+ - ` ErrorCode::FrameCaptureFailed` - Frame capture failed
151+
116152# ### Pure C Interface
117153
118154` ` ` c
@@ -458,6 +494,54 @@ typedef enum {
458494} CcapPixelFormat;
459495` ` `
460496
497+ # #### Error Handling
498+
499+ Starting from v1.1.0, ccap supports error callbacks for detailed error reporting:
500+
501+ ` ` ` c
502+ // Error codes
503+ typedef enum {
504+ CCAP_ERROR_NONE = 0,
505+ CCAP_ERROR_NO_DEVICE_FOUND = 0x1001, // No camera device found
506+ CCAP_ERROR_INVALID_DEVICE = 0x1002, // Invalid device name or index
507+ CCAP_ERROR_DEVICE_OPEN_FAILED = 0x1003, // Camera open failed
508+ CCAP_ERROR_DEVICE_START_FAILED = 0x1004, // Camera start failed
509+ CCAP_ERROR_UNSUPPORTED_RESOLUTION = 0x2001, // Unsupported resolution
510+ CCAP_ERROR_UNSUPPORTED_PIXEL_FORMAT = 0x2002, // Unsupported pixel format
511+ CCAP_ERROR_FRAME_CAPTURE_TIMEOUT = 0x3001, // Frame capture timeout
512+ CCAP_ERROR_FRAME_CAPTURE_FAILED = 0x3002, // Frame capture failed
513+ // More error codes...
514+ } CcapErrorCode;
515+
516+ // Error callback function
517+ typedef void (*CcapErrorCallback)(CcapErrorCode errorCode, const char* errorDescription, void* userData);
518+
519+ // Set error callback
520+ bool ccap_provider_set_error_callback(CcapProvider* provider, CcapErrorCallback callback, void* userData);
521+
522+ // Get error description
523+ const char* ccap_error_code_to_string(CcapErrorCode errorCode);
524+
525+ // Usage example
526+ void error_callback(CcapErrorCode errorCode, const char* errorDescription, void* userData) {
527+ printf("Camera Error - Code: %d, Description: %s\n", (int)errorCode, errorDescription);
528+ }
529+
530+ int main() {
531+ CcapProvider* provider = ccap_provider_create();
532+
533+ // Set error callback to receive error notifications
534+ ccap_provider_set_error_callback(provider, error_callback, NULL);
535+
536+ if (!ccap_provider_open_by_index(provider, 0, true)) {
537+ printf("Failed to open camera\n"); // Error callback will also be called
538+ }
539+
540+ ccap_provider_destroy(provider);
541+ return 0;
542+ }
543+ ` ` `
544+
461545# ### Compilation and Linking
462546
463547# #### macOS
0 commit comments