All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
gentl_wrapper_linux.cc
Go to the documentation of this file.
1 /*
2  * This file is part of the rc_genicam_api package.
3  *
4  * Copyright (c) 2017 Roboception GmbH
5  * All rights reserved
6  *
7  * Author: Heiko Hirschmueller
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include "gentl_wrapper.h"
37 
38 #include <string>
39 #include <sstream>
40 #include <stdexcept>
41 #include <cstdlib>
42 #include <iostream>
43 
44 #include <dlfcn.h>
45 #include <dirent.h>
46 
47 namespace rcg
48 {
49 
50 std::vector<std::string> getAvailableGenTLs(const char *paths)
51 {
52  std::vector<std::string> ret;
53 
54  if (paths != 0)
55  {
56  // split path list into individual paths
57 
58  std::stringstream in(paths);
59  std::string path;
60 
61  while (getline(in, path, ':'))
62  {
63  if (path.size() > 0)
64  {
65  if (path.size() > 4 && path.compare(path.size()-4, 4, ".cti") == 0)
66  {
67  // the given path points to one file ending with .cti
68 
69  ret.push_back(path);
70  }
71  else
72  {
73  // try to instantiate GenTLWrapper for all files in the given path that
74  // end with .cti
75 
76  DIR *p=opendir(path.c_str());
77 
78  if (p != 0)
79  {
80  struct dirent *entry=readdir(p);
81 
82  while (entry != 0)
83  {
84  std::string name=entry->d_name;
85 
86  if (name.size() >= 4 && name.compare(name.size()-4, 4, ".cti") == 0)
87  {
88  ret.push_back(path+"/"+name);
89  }
90 
91  entry=readdir(p);
92  }
93 
94  closedir(p);
95  }
96  }
97  }
98  }
99  }
100 
101  return ret;
102 }
103 
104 GenTLWrapper::GenTLWrapper(const std::string &filename)
105 {
106  // open library
107 
108  // NOTE: RTLD_DEEPBIND is necessary for resolving symbols of the loaded
109  // library locally before using global symbols. This is for example needed
110  // if rc_genicam_api is used in a ROS node or nodelet and a transport layer
111  // library internally uses boost in a different version as in ROS.
112 
113  lib=dlopen(filename.c_str(), RTLD_NOW | RTLD_DEEPBIND);
114 
115  if (lib == 0)
116  {
117  throw std::invalid_argument(std::string("Cannot open GenTL library: ")+dlerror());
118  }
119 
120  dlerror(); // clear possible existing error
121 
122  // resolve function calls that will only be used privately
123 
124  *reinterpret_cast<void**>(&GCInitLib)=dlsym(lib, "GCInitLib");
125  *reinterpret_cast<void**>(&GCCloseLib)=dlsym(lib, "GCCloseLib");
126 
127  // resolve public symbols
128 
129  *reinterpret_cast<void**>(&GCGetInfo)=dlsym(lib, "GCGetInfo");
130  *reinterpret_cast<void**>(&GCGetLastError)=dlsym(lib, "GCGetLastError");
131  *reinterpret_cast<void**>(&GCReadPort)=dlsym(lib, "GCReadPort");
132  *reinterpret_cast<void**>(&GCWritePort)=dlsym(lib, "GCWritePort");
133  *reinterpret_cast<void**>(&GCGetPortURL)=dlsym(lib, "GCGetPortURL");
134  *reinterpret_cast<void**>(&GCGetPortInfo)=dlsym(lib, "GCGetPortInfo");
135 
136  *reinterpret_cast<void**>(&GCRegisterEvent)=dlsym(lib, "GCRegisterEvent");
137  *reinterpret_cast<void**>(&GCUnregisterEvent)=dlsym(lib, "GCUnregisterEvent");
138  *reinterpret_cast<void**>(&EventGetData)=dlsym(lib, "EventGetData");
139  *reinterpret_cast<void**>(&EventGetDataInfo)=dlsym(lib, "EventGetDataInfo");
140  *reinterpret_cast<void**>(&EventGetInfo)=dlsym(lib, "EventGetInfo");
141  *reinterpret_cast<void**>(&EventFlush)=dlsym(lib, "EventFlush");
142  *reinterpret_cast<void**>(&EventKill)=dlsym(lib, "EventKill");
143  *reinterpret_cast<void**>(&TLOpen)=dlsym(lib, "TLOpen");
144  *reinterpret_cast<void**>(&TLClose)=dlsym(lib, "TLClose");
145  *reinterpret_cast<void**>(&TLGetInfo)=dlsym(lib, "TLGetInfo");
146  *reinterpret_cast<void**>(&TLGetNumInterfaces)=dlsym(lib, "TLGetNumInterfaces");
147  *reinterpret_cast<void**>(&TLGetInterfaceID)=dlsym(lib, "TLGetInterfaceID");
148  *reinterpret_cast<void**>(&TLGetInterfaceInfo)=dlsym(lib, "TLGetInterfaceInfo");
149  *reinterpret_cast<void**>(&TLOpenInterface)=dlsym(lib, "TLOpenInterface");
150  *reinterpret_cast<void**>(&TLUpdateInterfaceList)=dlsym(lib, "TLUpdateInterfaceList");
151  *reinterpret_cast<void**>(&IFClose)=dlsym(lib, "IFClose");
152  *reinterpret_cast<void**>(&IFGetInfo)=dlsym(lib, "IFGetInfo");
153  *reinterpret_cast<void**>(&IFGetNumDevices)=dlsym(lib, "IFGetNumDevices");
154  *reinterpret_cast<void**>(&IFGetDeviceID)=dlsym(lib, "IFGetDeviceID");
155  *reinterpret_cast<void**>(&IFUpdateDeviceList)=dlsym(lib, "IFUpdateDeviceList");
156  *reinterpret_cast<void**>(&IFGetDeviceInfo)=dlsym(lib, "IFGetDeviceInfo");
157  *reinterpret_cast<void**>(&IFOpenDevice)=dlsym(lib, "IFOpenDevice");
158 
159  *reinterpret_cast<void**>(&DevGetPort)=dlsym(lib, "DevGetPort");
160  *reinterpret_cast<void**>(&DevGetNumDataStreams)=dlsym(lib, "DevGetNumDataStreams");
161  *reinterpret_cast<void**>(&DevGetDataStreamID)=dlsym(lib, "DevGetDataStreamID");
162  *reinterpret_cast<void**>(&DevOpenDataStream)=dlsym(lib, "DevOpenDataStream");
163  *reinterpret_cast<void**>(&DevGetInfo)=dlsym(lib, "DevGetInfo");
164  *reinterpret_cast<void**>(&DevClose)=dlsym(lib, "DevClose");
165 
166  *reinterpret_cast<void**>(&DSAnnounceBuffer)=dlsym(lib, "DSAnnounceBuffer");
167  *reinterpret_cast<void**>(&DSAllocAndAnnounceBuffer)=dlsym(lib, "DSAllocAndAnnounceBuffer");
168  *reinterpret_cast<void**>(&DSFlushQueue)=dlsym(lib, "DSFlushQueue");
169  *reinterpret_cast<void**>(&DSStartAcquisition)=dlsym(lib, "DSStartAcquisition");
170  *reinterpret_cast<void**>(&DSStopAcquisition)=dlsym(lib, "DSStopAcquisition");
171  *reinterpret_cast<void**>(&DSGetInfo)=dlsym(lib, "DSGetInfo");
172  *reinterpret_cast<void**>(&DSGetBufferID)=dlsym(lib, "DSGetBufferID");
173  *reinterpret_cast<void**>(&DSClose)=dlsym(lib, "DSClose");
174  *reinterpret_cast<void**>(&DSRevokeBuffer)=dlsym(lib, "DSRevokeBuffer");
175  *reinterpret_cast<void**>(&DSQueueBuffer)=dlsym(lib, "DSQueueBuffer");
176  *reinterpret_cast<void**>(&DSGetBufferInfo)=dlsym(lib, "DSGetBufferInfo");
177 
178  *reinterpret_cast<void**>(&GCGetNumPortURLs)=dlsym(lib, "GCGetNumPortURLs");
179  *reinterpret_cast<void**>(&GCGetPortURLInfo)=dlsym(lib, "GCGetPortURLInfo");
180  *reinterpret_cast<void**>(&GCReadPortStacked)=dlsym(lib, "GCReadPortStacked");
181  *reinterpret_cast<void**>(&GCWritePortStacked)=dlsym(lib, "GCWritePortStacked");
182 
183  *reinterpret_cast<void**>(&DSGetBufferChunkData)=dlsym(lib, "DSGetBufferChunkData");
184 
185  *reinterpret_cast<void**>(&IFGetParentTL)=dlsym(lib, "IFGetParentTL");
186  *reinterpret_cast<void**>(&DevGetParentIF)=dlsym(lib, "DevGetParentIF");
187  *reinterpret_cast<void**>(&DSGetParentDev)=dlsym(lib, "DSGetParentDev");
188 
189  *reinterpret_cast<void**>(&DSGetNumBufferParts)=dlsym(lib, "DSGetNumBufferParts");
190  *reinterpret_cast<void**>(&DSGetBufferPartInfo)=dlsym(lib, "DSGetBufferPartInfo");
191 
192  const char *err=dlerror();
193 
194  if (err != 0)
195  {
196  std::string tmp=err;
197  dlclose(lib);
198  throw std::invalid_argument(std::string("Cannot resolve GenTL symbol: ")+tmp);
199  }
200 }
201 
203 {
204  dlclose(lib);
205 }
206 
207 }
rcg::getAvailableGenTLs
std::vector< std::string > getAvailableGenTLs(const char *paths)
The function uses the given list files of paths that is separated by colons or semicolons,...
Definition: gentl_wrapper_linux.cc:50
rcg::GenTLWrapper::DSClose
GenTL::PDSClose DSClose
Definition: gentl_wrapper.h:130
rcg::GenTLWrapper::TLClose
GenTL::PTLClose TLClose
Definition: gentl_wrapper.h:101
rcg::GenTLWrapper::GCInitLib
GenTL::PGCInitLib GCInitLib
Definition: gentl_wrapper.h:86
rcg::GenTLWrapper::DSGetBufferPartInfo
GenTL::PDSGetBufferPartInfo DSGetBufferPartInfo
Definition: gentl_wrapper.h:155
rcg::GenTLWrapper::EventGetInfo
GenTL::PEventGetInfo EventGetInfo
Definition: gentl_wrapper.h:97
rcg::GenTLWrapper::DSGetParentDev
GenTL::PDSGetParentDev DSGetParentDev
Definition: gentl_wrapper.h:150
rcg::GenTLWrapper::GCRegisterEvent
GenTL::PGCRegisterEvent GCRegisterEvent
Definition: gentl_wrapper.h:93
rcg::GenTLWrapper::DevClose
GenTL::PDevClose DevClose
Definition: gentl_wrapper.h:121
rcg::GenTLWrapper::TLGetInfo
GenTL::PTLGetInfo TLGetInfo
Definition: gentl_wrapper.h:102
rcg::GenTLWrapper::lib
void * lib
Definition: gentl_wrapper.h:162
rcg::GenTLWrapper::DSGetBufferInfo
GenTL::PDSGetBufferInfo DSGetBufferInfo
Definition: gentl_wrapper.h:133
rcg::GenTLWrapper::TLGetInterfaceID
GenTL::PTLGetInterfaceID TLGetInterfaceID
Definition: gentl_wrapper.h:104
rcg
Definition: buffer.cc:47
rcg::GenTLWrapper::EventKill
GenTL::PEventKill EventKill
Definition: gentl_wrapper.h:99
rcg::GenTLWrapper::DevOpenDataStream
GenTL::PDevOpenDataStream DevOpenDataStream
Definition: gentl_wrapper.h:119
rcg::GenTLWrapper::GCCloseLib
GenTL::PGCCloseLib GCCloseLib
Definition: gentl_wrapper.h:87
rcg::GenTLWrapper::DSGetBufferID
GenTL::PDSGetBufferID DSGetBufferID
Definition: gentl_wrapper.h:129
rcg::GenTLWrapper::IFClose
GenTL::PIFClose IFClose
Definition: gentl_wrapper.h:108
rcg::GenTLWrapper::GCWritePortStacked
GenTL::PGCWritePortStacked GCWritePortStacked
Definition: gentl_wrapper.h:140
rcg::GenTLWrapper::IFGetDeviceInfo
GenTL::PIFGetDeviceInfo IFGetDeviceInfo
Definition: gentl_wrapper.h:113
rcg::GenTLWrapper::GCUnregisterEvent
GenTL::PGCUnregisterEvent GCUnregisterEvent
Definition: gentl_wrapper.h:94
rcg::GenTLWrapper::DSRevokeBuffer
GenTL::PDSRevokeBuffer DSRevokeBuffer
Definition: gentl_wrapper.h:131
rcg::GenTLWrapper::DevGetDataStreamID
GenTL::PDevGetDataStreamID DevGetDataStreamID
Definition: gentl_wrapper.h:118
rcg::GenTLWrapper::GCReadPort
GenTL::PGCReadPort GCReadPort
Definition: gentl_wrapper.h:88
rcg::GenTLWrapper::EventFlush
GenTL::PEventFlush EventFlush
Definition: gentl_wrapper.h:98
rcg::GenTLWrapper::GCGetPortInfo
GenTL::PGCGetPortInfo GCGetPortInfo
Definition: gentl_wrapper.h:91
rcg::GenTLWrapper::EventGetData
GenTL::PEventGetData EventGetData
Definition: gentl_wrapper.h:95
rcg::GenTLWrapper::GCWritePort
GenTL::PGCWritePort GCWritePort
Definition: gentl_wrapper.h:89
GENICAM_NAMESPACE::getline
std::istream & getline(std::istream &is, GENICAM_NAMESPACE::gcstring &str)
STL getline.
Definition: GCString.h:194
rcg::GenTLWrapper::TLOpenInterface
GenTL::PTLOpenInterface TLOpenInterface
Definition: gentl_wrapper.h:106
rcg::GenTLWrapper::GCReadPortStacked
GenTL::PGCReadPortStacked GCReadPortStacked
Definition: gentl_wrapper.h:139
rcg::GenTLWrapper::TLGetInterfaceInfo
GenTL::PTLGetInterfaceInfo TLGetInterfaceInfo
Definition: gentl_wrapper.h:105
rcg::GenTLWrapper::DSGetNumBufferParts
GenTL::PDSGetNumBufferParts DSGetNumBufferParts
Definition: gentl_wrapper.h:154
rcg::GenTLWrapper::DSGetInfo
GenTL::PDSGetInfo DSGetInfo
Definition: gentl_wrapper.h:128
rcg::GenTLWrapper::IFGetNumDevices
GenTL::PIFGetNumDevices IFGetNumDevices
Definition: gentl_wrapper.h:110
rcg::GenTLWrapper::GCGetPortURL
GenTL::PGCGetPortURL GCGetPortURL
Definition: gentl_wrapper.h:90
rcg::GenTLWrapper::GCGetInfo
GenTL::PGCGetInfo GCGetInfo
Definition: gentl_wrapper.h:84
rcg::GenTLWrapper::DSGetBufferChunkData
GenTL::PDSGetBufferChunkData DSGetBufferChunkData
Definition: gentl_wrapper.h:144
rcg::GenTLWrapper::GCGetPortURLInfo
GenTL::PGCGetPortURLInfo GCGetPortURLInfo
Definition: gentl_wrapper.h:138
rcg::GenTLWrapper::DevGetPort
GenTL::PDevGetPort DevGetPort
Definition: gentl_wrapper.h:116
rcg::GenTLWrapper::DSFlushQueue
GenTL::PDSFlushQueue DSFlushQueue
Definition: gentl_wrapper.h:125
rcg::GenTLWrapper::DevGetNumDataStreams
GenTL::PDevGetNumDataStreams DevGetNumDataStreams
Definition: gentl_wrapper.h:117
rcg::GenTLWrapper::DevGetInfo
GenTL::PDevGetInfo DevGetInfo
Definition: gentl_wrapper.h:120
rcg::GenTLWrapper::GCGetLastError
GenTL::PGCGetLastError GCGetLastError
Definition: gentl_wrapper.h:85
rcg::GenTLWrapper::IFGetParentTL
GenTL::PIFGetParentTL IFGetParentTL
Definition: gentl_wrapper.h:148
rcg::GenTLWrapper::~GenTLWrapper
~GenTLWrapper()
Definition: gentl_wrapper_linux.cc:202
rcg::GenTLWrapper::DSAllocAndAnnounceBuffer
GenTL::PDSAllocAndAnnounceBuffer DSAllocAndAnnounceBuffer
Definition: gentl_wrapper.h:124
rcg::GenTLWrapper::DSQueueBuffer
GenTL::PDSQueueBuffer DSQueueBuffer
Definition: gentl_wrapper.h:132
rcg::GenTLWrapper::TLUpdateInterfaceList
GenTL::PTLUpdateInterfaceList TLUpdateInterfaceList
Definition: gentl_wrapper.h:107
rcg::GenTLWrapper::TLOpen
GenTL::PTLOpen TLOpen
Definition: gentl_wrapper.h:100
rcg::GenTLWrapper::TLGetNumInterfaces
GenTL::PTLGetNumInterfaces TLGetNumInterfaces
Definition: gentl_wrapper.h:103
rcg::GenTLWrapper::IFOpenDevice
GenTL::PIFOpenDevice IFOpenDevice
Definition: gentl_wrapper.h:114
rcg::GenTLWrapper::GCGetNumPortURLs
GenTL::PGCGetNumPortURLs GCGetNumPortURLs
Definition: gentl_wrapper.h:137
rcg::GenTLWrapper::IFGetDeviceID
GenTL::PIFGetDeviceID IFGetDeviceID
Definition: gentl_wrapper.h:111
rcg::GenTLWrapper::DSStartAcquisition
GenTL::PDSStartAcquisition DSStartAcquisition
Definition: gentl_wrapper.h:126
rcg::GenTLWrapper::GenTLWrapper
GenTLWrapper(const std::string &filename)
Definition: gentl_wrapper_linux.cc:104
rcg::GenTLWrapper::DevGetParentIF
GenTL::PDevGetParentIF DevGetParentIF
Definition: gentl_wrapper.h:149
rcg::GenTLWrapper::IFGetInfo
GenTL::PIFGetInfo IFGetInfo
Definition: gentl_wrapper.h:109
rcg::GenTLWrapper::EventGetDataInfo
GenTL::PEventGetDataInfo EventGetDataInfo
Definition: gentl_wrapper.h:96
rcg::GenTLWrapper::DSAnnounceBuffer
GenTL::PDSAnnounceBuffer DSAnnounceBuffer
Definition: gentl_wrapper.h:123
gentl_wrapper.h
rcg::GenTLWrapper::IFUpdateDeviceList
GenTL::PIFUpdateDeviceList IFUpdateDeviceList
Definition: gentl_wrapper.h:112
rcg::GenTLWrapper::DSStopAcquisition
GenTL::PDSStopAcquisition DSStopAcquisition
Definition: gentl_wrapper.h:127


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Dec 4 2024 03:10:11