libsigrokcxx  unreleased development snapshot
C++ bindings for libsigrok
API Reference

Introduction

The libsigrokcxx API provides an object-oriented C++ interface to the functionality in libsigrok, including automatic memory and resource management.

It is built on top of the public libsigrok C API, and is designed to be used as a standalone alternative API. Programs should not mix usage of the C and C++ APIs; the C++ interface code needs to have full control of all C API calls for resources to be managed correctly.

Memory management

All runtime objects created through the C++ API are passed and accessed via shared pointers, using the C++11 std::shared_ptr implementation. This means that a reference count is kept for each object.

Shared pointers can be copied and assigned in a user's program, automatically updating their reference count and deleting objects when they are no longer in use. The C++ interface code also keeps track of internal dependencies between libsigrok resources, and ensures that objects are not prematurely deleted when their resources are in use by other objects.

This means that management of libsigrokcxx objects and their underlying libsigrok resources can be treated as fully automatic. As long as all shared pointers to objects are deleted or reassigned when no longer in use, all underlying resources will be released at the right time.

Getting started

Usage of the C++ API needs to begin with a call to sigrok::Context::create(). This will create the global libsigrok context and returns a shared pointer to the sigrok::Context object. Methods on this object provide access to the hardware drivers, input and output formats supported by the library, as well as means of creating other objects such as sessions and triggers.

Error handling

When any libsigrok C API call returns an error, a sigrok::Error exception is raised, which provides access to the error code and description.