-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a C++17 API to the library. Implemented as a single header without dependencies. It simplifies usage of the library when a modern C++ compiler is available. Signed-off-by: Tilman Blumhagen <[email protected]>
- Loading branch information
Showing
11 changed files
with
956 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
if (CPP_BINDINGS) | ||
add_subdirectory(cpp) | ||
endif() | ||
|
||
if (CSHARP_BINDINGS) | ||
add_subdirectory(csharp) | ||
endif() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 2.8.12) | ||
|
||
project(iiopp-enum CXX) | ||
add_executable(iiopp-enum examples/iiopp-enum.cpp iiopp.h ${LIBIIO_RC}) | ||
target_include_directories(iiopp-enum PRIVATE ./) | ||
set_target_properties(iiopp-enum PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON) | ||
target_link_libraries(iiopp-enum iio) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* libiio - C++ API usage | ||
* | ||
* This example libiio program shows the usage of the C++ API for enumerating | ||
* devices, channels and attributes. | ||
* | ||
* Copyright (c) 2023, DIFITEC GmbH | ||
* Author: Tilman Blumhagen <[email protected]> | ||
*/ | ||
|
||
#include <iiopp.h> | ||
|
||
#include <iostream> | ||
#include <iomanip> | ||
|
||
using namespace iiopp; | ||
using namespace std; | ||
|
||
string get(IAttr const & att) | ||
{ | ||
char value[1024] = {0}; // Flawfinder: ignore | ||
att.read(value, sizeof(value)); // Flawfinder: ignore | ||
return value; | ||
} | ||
|
||
void enumerateIioEntities() | ||
{ | ||
cout << boolalpha; | ||
|
||
shared_ptr<Context> context = create_default_context(); | ||
|
||
for (Device device : *context) | ||
{ | ||
cout << "Device:" << endl; | ||
cout << " id: " << quoted(string(device.id())) << endl; | ||
|
||
cout << " name: "; | ||
if (auto name = device.name()) | ||
cout << quoted(string(*name)); | ||
cout << endl; | ||
|
||
cout << " is trigger: " << device.is_trigger() << endl; | ||
|
||
for (auto att : device.attrs) | ||
cout << " attribute " << att.name() << " = " << quoted(get(att)) << endl; | ||
|
||
for (auto att : device.debug_attrs) | ||
cout << " debug attribute " << att.name() << " = " << quoted(get(att)) << endl; | ||
|
||
for (auto att : device.buffer_attrs) | ||
cout << " buffer attribute " << att.name() << " = " << quoted(get(att)) << endl; | ||
|
||
for (Channel channel : device) | ||
{ | ||
cout << " Channel: " << channel.id() << endl; | ||
|
||
cout << " name: "; | ||
if (auto name = channel.name()) | ||
cout << quoted(string(*name)); | ||
cout << endl; | ||
|
||
cout << " is output: " << channel.is_output() << endl; | ||
cout << " is enabled: " << channel.is_enabled() << endl; | ||
|
||
for (auto att : channel.attrs) | ||
cout << " attribute " << quoted(att.name().c_str()) << " = " << quoted(get(att)) << endl; | ||
} | ||
} | ||
|
||
shared_ptr<ScanContext> scanCtx = create_scan_context({}, 0); | ||
shared_ptr<ScanContext::InfoList> infoList = scanCtx->info_list(); | ||
|
||
cout << "scan context info list:" << endl; | ||
for (ContextInfo info : *infoList) | ||
{ | ||
cout << " uri: " << quoted(info.uri().c_str()) << endl; | ||
cout << " description: " << quoted(info.desciption().c_str()) << endl; | ||
} | ||
|
||
cout << "scan block:" << endl; | ||
shared_ptr<ScanBlock> blk = create_scan_block({}, 0); | ||
for (ContextInfo info : *blk) | ||
{ | ||
cout << " uri: " << quoted(info.uri().c_str()) << endl; | ||
cout << " description: " << quoted(info.desciption().c_str()) << endl; | ||
} | ||
} | ||
|
||
int main(int argc, char ** argv) | ||
{ | ||
try | ||
{ | ||
enumerateIioEntities(); | ||
} | ||
catch (std::exception & e) | ||
{ | ||
cerr << "ERROR: " << e.what() << endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
} |
Oops, something went wrong.