19#include <unordered_map>
37 typedef std::function<void(std::shared_ptr<DeviceList> removedList, std::shared_ptr<DeviceList> addedList)>
DeviceChangedCallback;
55 std::mutex callbackMtx_;
57 std::mutex legacyCallbackMtx_;
60 std::unordered_map<OBCallbackId, std::unique_ptr<DeviceChangedCallbackContext>> devChangedCallbacks_;
72 explicit Context(
const char *configPath =
"") {
97 return std::make_shared<DeviceList>(list);
148 return std::make_shared<Device>(device);
161 std::lock_guard<std::mutex> lock(legacyCallbackMtx_);
176 cbCtxHolder->callbackId = id;
177 cbCtxHolder->callback = callback;
179 std::unique_lock<std::mutex> lock(callbackMtx_);
180 devChangedCallbacks_[id] = std::move(cbCtxHolder);
189 std::unique_lock<std::mutex> lock(callbackMtx_);
190 if(devChangedCallbacks_.count(
id)) {
191 devChangedCallbacks_.erase(
id);
289 Context::getLogCallback() = callback;
305 const std::string &func,
int line) {
327 auto cbCtx =
static_cast<DeviceChangedCallbackContext *
>(userData);
332 std::unique_lock<std::mutex> lock(cbCtx->ctx->callbackMtx_);
333 if(cbCtx->ctx->devChangedCallbacks_.count(cbCtx->callbackId)) {
334 callbackCopy = cbCtx->callback;
337 auto removed = std::make_shared<DeviceList>(removedList);
338 auto added = std::make_shared<DeviceList>(addedList);
339 callbackCopy(removed, added);
343 static void logCallback(
OBLogSeverity severity,
const char *logMsg,
void *userData) {
346 (*cb)(severity, logMsg);
357#define enableMultiDeviceSync enableDeviceClockSync
Context is a management class that describes the runtime of the SDK and is responsible for resource a...
OB_EXPORT void ob_enable_device_clock_sync(ob_context *context, uint64_t repeat_interval_msec, ob_error **error)
Activates device clock synchronization to synchronize the clock of the host and all created devices (...
OB_EXPORT void ob_set_logger_to_callback(ob_log_severity severity, ob_log_callback callback, void *user_data, ob_error **error)
Set the log callback function.
OB_EXPORT bool ob_force_ip_config(const char *macAddress, ob_net_ip_config config, ob_error **error)
"Force" a static IP address configuration in a device identified by its MAC Address.
OB_EXPORT void ob_set_uvc_backend_type(ob_context *context, ob_uvc_backend_type backend_type, ob_error **error)
For linux, there are two ways to enable the UVC backend: libuvc and v4l2. This function is used to se...
OB_EXPORT ob_context * ob_create_context_with_config(const char *config_file_path, ob_error **error)
Create a context object with a specified configuration file.
OB_EXPORT ob_device * ob_create_net_device_ex(ob_context *context, const char *address, uint16_t port, ob_device_access_mode accessMode, ob_error **error)
Create a network device object.
OB_EXPORT void ob_free_idle_memory(ob_context *context, ob_error **error)
Free idle memory from the internal frame memory pool.
OB_EXPORT void ob_set_logger_to_file(ob_log_severity severity, const char *directory, ob_error **error)
Set the log output to a file.
OB_EXPORT void ob_set_logger_severity(ob_log_severity severity, ob_error **error)
Set the global log level.
OB_EXPORT void ob_unregister_device_changed_callback(ob_context *context, ob_callback_id callback_id, ob_error **error)
Unregister a previously registered device plug-in callback function.
OB_EXPORT void ob_set_logger_to_console(ob_log_severity severity, ob_error **error)
Set the log output to the console.
OB_EXPORT void ob_log_external_message(ob_log_severity severity, const char *module, const char *message, const char *file, const char *func, int line, ob_error **error)
Logs a message with severity, file, function, and line info.
OB_EXPORT ob_callback_id ob_register_device_changed_callback(ob_context *context, ob_device_changed_callback callback, void *user_data, ob_error **error)
Register a device plug-in callback function.
OB_EXPORT ob_device_list * ob_query_device_list(ob_context *context, ob_error **error)
Get a list of enumerated devices.
OB_EXPORT void ob_delete_context(ob_context *context, ob_error **error)
Delete a context object.
OB_EXPORT void ob_enable_net_device_enumeration(ob_context *context, bool enable, ob_error **error)
Enable or disable network device enumeration.
OB_EXPORT void ob_set_logger_file_name(const char *file_name, ob_error **error)
Set the log file name for file output.
OB_EXPORT void ob_set_extensions_directory(const char *directory, ob_error **error)
Set the extensions directory.
This file defines the Error class, which describes abnormal errors within the SDK....
@ OB_DEVICE_DEFAULT_ACCESS
Default access: control access for capable devices, ignored otherwise.
struct ob_context_t ob_context
enum ob_device_access_mode OBDeviceAccessMode
enum ob_uvc_backend_type OBUvcBackendType
#define INVALID_CALLBACK_ID
struct ob_device_list_t ob_device_list
uint64_t OBCallbackId
Callback Id.
OBLogSeverity
log level, the higher the level, the stronger the log filter
void enableNetDeviceEnumeration(bool enable) const
enable or disable net device enumeration.
std::function< void(std::shared_ptr< DeviceList > removedList, std::shared_ptr< DeviceList > addedList)> DeviceChangedCallback
Type definition for the device changed callback function.
static void setLoggerSeverity(OBLogSeverity severity)
Set the level of the global log, which affects both the log level output to the console,...
static void setLoggerToConsole(OBLogSeverity severity)
Set log output to the console.
void setDeviceChangedCallback(DeviceChangedCallback callback)
Set the device plug-in callback function.
static void setLoggerFileName(const std::string &fileName)
Set the log file name for file output.
bool forceIp(const char *macAddress, const OBNetIpConfig &config)
"Force" a static IP address configuration in a device identified by its MAC Address.
std::function< void(OBLogSeverity severity, const char *logMsg)> LogCallback
Type definition for the log output callback function.
void enableDeviceClockSync(uint64_t repeatIntervalMsec) const
Activates device clock synchronization to synchronize the clock of the host and all created devices (...
static void logExternalMessage(OBLogSeverity severity, const std::string &module, const std::string &message, const std::string &file, const std::string &func, int line)
Logs a message with severity, file, function, and line info.
static void setLoggerToCallback(OBLogSeverity severity, LogCallback callback)
Set the logger to callback.
~Context() noexcept
Context destructor.
void unregisterDeviceChangedCallback(OBCallbackId id)
void setUvcBackendType(OBUvcBackendType type) const
For linux, there are two ways to enable the UVC backend: libuvc and v4l2. This function is used to se...
OBCallbackId registerDeviceChangedCallback(DeviceChangedCallback callback)
static void setExtensionsDirectory(const char *directory)
Set the extensions directory.
void freeIdleMemory() const
Frees idle memory from the internal frame memory pool.
Context(const char *configPath="")
Context constructor.
std::shared_ptr< Device > createNetDevice(const char *address, uint16_t port, OBDeviceAccessMode accessMode=OB_DEVICE_DEFAULT_ACCESS) const
Creates a network device with the specified IP address and port.
std::shared_ptr< DeviceList > queryDeviceList() const
Queries the enumerated device list.
static void setLoggerToFile(OBLogSeverity severity, const char *directory)
Set log output to a file.
A class describing device information, representing the name, id, serial number and other basic infor...
Class representing a list of devices.
static void handle(ob_error **error, bool throw_exception=true)
A static function to handle the ob_error and throw an exception if needed.
IP address configuration for network devices (IPv4)
DeviceChangedCallback callback
The error class exposed by the SDK, users can get detailed error information according to the error.