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  dlclose(lib);
197  throw std::invalid_argument(std::string("Cannot resolve GenTL symbol: ")+err);
198  }
199 }
200 
202 {
203  dlclose(lib);
204 }
205 
206 }
GenTLWrapper(const std::string &filename)
GenTL::PGCWritePort GCWritePort
Definition: gentl_wrapper.h:89
GenTL::PEventFlush EventFlush
Definition: gentl_wrapper.h:98
GenTL::PGCUnregisterEvent GCUnregisterEvent
Definition: gentl_wrapper.h:94
GenTL::PIFOpenDevice IFOpenDevice
GenTL::PIFGetNumDevices IFGetNumDevices
GenTL::PDSGetInfo DSGetInfo
GenTL::PTLGetNumInterfaces TLGetNumInterfaces
GenTL::PDSAnnounceBuffer DSAnnounceBuffer
std::istream & getline(std::istream &is, GENICAM_NAMESPACE::gcstring &str)
STL getline.
Definition: GCString.h:188
GenTL::PGCGetPortURL GCGetPortURL
Definition: gentl_wrapper.h:90
GenTL::PDevGetInfo DevGetInfo
GenTL::PDevGetNumDataStreams DevGetNumDataStreams
GenTL::PIFGetDeviceID IFGetDeviceID
GenTL::PIFUpdateDeviceList IFUpdateDeviceList
GenTL::PDSAllocAndAnnounceBuffer DSAllocAndAnnounceBuffer
GenTL::PIFClose IFClose
GenTL::PDSGetNumBufferParts DSGetNumBufferParts
GenTL::PEventGetInfo EventGetInfo
Definition: gentl_wrapper.h:97
GenTL::PTLGetInfo TLGetInfo
GenTL::PDSGetBufferID DSGetBufferID
GenTL::PDevOpenDataStream DevOpenDataStream
GenTL::PTLGetInterfaceID TLGetInterfaceID
GenTL::PGCReadPortStacked GCReadPortStacked
GenTL::PTLGetInterfaceInfo TLGetInterfaceInfo
GenTL::PGCCloseLib GCCloseLib
Definition: gentl_wrapper.h:87
GenTL::PTLClose TLClose
GenTL::PGCGetNumPortURLs GCGetNumPortURLs
GenTL::PDSQueueBuffer DSQueueBuffer
GenTL::PIFGetParentTL IFGetParentTL
GenTL::PTLOpenInterface TLOpenInterface
GenTL::PTLUpdateInterfaceList TLUpdateInterfaceList
GenTL::PEventGetDataInfo EventGetDataInfo
Definition: gentl_wrapper.h:96
GenTL::PDevGetParentIF DevGetParentIF
GenTL::PTLOpen TLOpen
GenTL::PDevClose DevClose
GenTL::PDevGetDataStreamID DevGetDataStreamID
GenTL::PGCReadPort GCReadPort
Definition: gentl_wrapper.h:88
GenTL::PGCWritePortStacked GCWritePortStacked
std::vector< std::string > getAvailableGenTLs(const char *paths)
The function uses the given list files of paths that is separated by colons or semicolons, depending on the used operating system, and returns all files with the suffix .cti.
GenTL::PGCGetInfo GCGetInfo
Definition: gentl_wrapper.h:84
GenTL::PIFGetDeviceInfo IFGetDeviceInfo
GenTL::PDSRevokeBuffer DSRevokeBuffer
GenTL::PGCGetPortInfo GCGetPortInfo
Definition: gentl_wrapper.h:91
GenTL::PDSStopAcquisition DSStopAcquisition
GenTL::PDevGetPort DevGetPort
GenTL::PEventKill EventKill
Definition: gentl_wrapper.h:99
GenTL::PGCGetLastError GCGetLastError
Definition: gentl_wrapper.h:85
GenTL::PDSGetParentDev DSGetParentDev
GenTL::PGCInitLib GCInitLib
Definition: gentl_wrapper.h:86
Definition: buffer.cc:42
GenTL::PDSGetBufferPartInfo DSGetBufferPartInfo
GenTL::PIFGetInfo IFGetInfo
GenTL::PDSClose DSClose
GenTL::PGCRegisterEvent GCRegisterEvent
Definition: gentl_wrapper.h:93
GenTL::PEventGetData EventGetData
Definition: gentl_wrapper.h:95
GenTL::PDSStartAcquisition DSStartAcquisition
GenTL::PDSGetBufferInfo DSGetBufferInfo
GenTL::PDSGetBufferChunkData DSGetBufferChunkData
GenTL::PGCGetPortURLInfo GCGetPortURLInfo
GenTL::PDSFlushQueue DSFlushQueue


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 19:10:54