Skip to content

Commit

Permalink
Merge pull request #277 from zivid/ZIVID-8484-wrapper-platform-metrics
Browse files Browse the repository at this point in the history
Pass wrapper name when constructing Zivid::Application
  • Loading branch information
johningve authored Jun 28, 2024
2 parents ffadc2b + 157af0d commit 93667fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/SingletonApplication.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <Zivid/CameraInfo.h>
#include <Zivid/Detail/ToolchainDetector.h>

#include <ZividPython/SingletonApplication.h>

Expand All @@ -10,7 +11,13 @@ namespace ZividPython
{
void wrapClass(pybind11::class_<SingletonApplication> pyClass)
{
pyClass.def(py::init())
pyClass
.def(py::init([] {
// This method constructs a Zivid::Application and identifies the wrapper as the Zivid Python wrapper.
// For users of the SDK: please do not use this method and construct the Zivid::Application directly instead.
return SingletonApplication{ Zivid::Detail::createApplicationForWrapper(
Zivid::Detail::EnvironmentInfo::Wrapper::python) };
}))
.def("cameras", &SingletonApplication::cameras)
.def("connect_camera", [](SingletonApplication &application) { return application.connectCamera(); })
.def(
Expand Down
12 changes: 9 additions & 3 deletions src/include/ZividPython/Releasable.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#pragma once

#include <ZividPython/Traits.h>

#include <pybind11/pybind11.h>

#include <cstddef>
#include <memory>
#include <optional>
#include <pybind11/pybind11.h>
#include <stdexcept>
#include <type_traits>

#define WITH_GIL_UNLOCKED(...) \
[&, this] { \
Expand Down Expand Up @@ -129,12 +134,13 @@ namespace ZividPython
class Singleton
{
public:
Singleton()
template<typename... Args, typename std::enable_if_t<(std::is_constructible_v<T, Args...>), int> = 0>
Singleton(Args &&...args)
{
// Keep the singleton alive forever to avoid races with
// static variables that the singleton may need during destruction
// This should be fixed a more elegant way!
if(!globalImpl) globalImpl = std::make_shared<T>();
if(!globalImpl) globalImpl = std::make_shared<T>(std::forward<Args>(args)...);
}

decltype(auto) toString() const
Expand Down

0 comments on commit 93667fd

Please sign in to comment.