IDS peak genericC++ v1.16.0
Loading...
Searching...
No Matches
peak_producer_library.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13
15#include <peak/dll_interface/peak_dll_interface_util.hpp>
18
19#include <cstdint>
20#include <memory>
21#include <string>
22#include <vector>
23
24
25namespace peak
26{
27namespace core
28{
29
38 : public InitOnce
39 , public std::enable_shared_from_this<ProducerLibrary>
40{
41public:
42 ProducerLibrary() = delete;
43 ~ProducerLibrary() override;
44 ProducerLibrary(const ProducerLibrary& other) = delete;
45 ProducerLibrary& operator=(const ProducerLibrary& other) = delete;
48
61 static std::shared_ptr<ProducerLibrary> Open(const std::string& ctiPath);
62
74 std::string Key() const;
75
88 std::shared_ptr<SystemDescriptor> System() const;
89
90private:
91 friend ClassCreator<ProducerLibrary>;
92 explicit ProducerLibrary(PEAK_PRODUCER_LIBRARY_HANDLE producerLibraryHandle);
93 PEAK_PRODUCER_LIBRARY_HANDLE m_backendHandle;
94
95 void Initialize() const override;
96 mutable std::shared_ptr<SystemDescriptor> m_system;
97
98 std::string m_key;
99};
100
101} /* namespace core */
102} /* namespace peak */
103
104/* Implementation */
105namespace peak
106{
107namespace core
108{
109
110inline std::shared_ptr<ProducerLibrary> ProducerLibrary::Open(const std::string& ctiPath)
111{
112 auto producerLibraryHandle = QueryNumericFromCInterfaceFunction<PEAK_PRODUCER_LIBRARY_HANDLE>(
113 [&](PEAK_PRODUCER_LIBRARY_HANDLE* _producerLibraryHandle) {
115 ctiPath.c_str(), ctiPath.size() + 1, _producerLibraryHandle);
116 });
117
118 return std::make_shared<ClassCreator<ProducerLibrary>>(producerLibraryHandle);
119}
120
122 : m_backendHandle(producerLibraryHandle)
123 , m_system()
124 , m_key(QueryStringFromCInterfaceFunction([&](char* key, size_t* keySize) {
125 return PEAK_C_ABI_PREFIX PEAK_ProducerLibrary_GetKey(producerLibraryHandle, key, keySize);
126 }))
127{}
128
133
134inline std::string ProducerLibrary::Key() const
135{
136 return m_key;
137}
138
139inline std::shared_ptr<SystemDescriptor> ProducerLibrary::System() const
140{
141 InitializeIfNecessary();
142
143 return m_system;
144}
145
146inline void ProducerLibrary::Initialize() const
147{
148 auto systemDescriptorHandle = QueryNumericFromCInterfaceFunction<PEAK_SYSTEM_DESCRIPTOR_HANDLE>(
149 [&](PEAK_SYSTEM_DESCRIPTOR_HANDLE* _systemDescriptorHandle) {
150 return PEAK_C_ABI_PREFIX PEAK_ProducerLibrary_GetSystem(m_backendHandle, _systemDescriptorHandle);
151 });
152
153 m_system = std::make_shared<ClassCreator<SystemDescriptor>>(
154 systemDescriptorHandle, std::const_pointer_cast<ProducerLibrary>(shared_from_this()));
155}
156
157} /* namespace core */
158} /* namespace peak */
ProducerLibrary(const ProducerLibrary &other)=delete
ProducerLibrary & operator=(ProducerLibrary &&other)=delete
~ProducerLibrary() override
Definition peak_producer_library.hpp:129
std::string Key() const
Returns the unique key.
Definition peak_producer_library.hpp:134
ProducerLibrary & operator=(const ProducerLibrary &other)=delete
ProducerLibrary(ProducerLibrary &&other)=delete
static std::shared_ptr< ProducerLibrary > Open(const std::string &ctiPath)
Opens the given producer library (CTI).
Definition peak_producer_library.hpp:110
std::shared_ptr< SystemDescriptor > System() const
Returns the system descriptor.
Definition peak_producer_library.hpp:139
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:34
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:35
struct PEAK_SYSTEM_DESCRIPTOR * PEAK_SYSTEM_DESCRIPTOR_HANDLE
Definition peak_backend.h:369
struct PEAK_PRODUCER_LIBRARY * PEAK_PRODUCER_LIBRARY_HANDLE
Definition peak_backend.h:365
PEAK_C_API PEAK_ProducerLibrary_GetSystem(PEAK_PRODUCER_LIBRARY_HANDLE producerLibraryHandle, PEAK_SYSTEM_DESCRIPTOR_HANDLE *systemDescriptorHandle)
Asks the given producer library for its system descriptor.
PEAK_C_API PEAK_ProducerLibrary_GetKey(PEAK_PRODUCER_LIBRARY_HANDLE producerLibraryHandle, char *key, size_t *keySize)
Asks the given producer library for its key.
PEAK_C_API PEAK_ProducerLibrary_Construct(const char *ctiPath, size_t ctiPathSize, PEAK_PRODUCER_LIBRARY_HANDLE *producerLibraryHandle)
Creates a producer library.
PEAK_C_API PEAK_ProducerLibrary_Destruct(PEAK_PRODUCER_LIBRARY_HANDLE producerLibraryHandle)
Destroys the given producer library.
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:16