gentl_wrapper_win32.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 <Windows.h>
45 
46 namespace rcg
47 {
48 
49 std::vector<std::string> getAvailableGenTLs(const char *paths)
50 {
51  std::vector<std::string> ret;
52 
53  if (paths != 0)
54  {
55  // split path list into individual paths
56 
57  std::stringstream in(paths);
58  std::string path;
59 
60  while (getline(in, path, ';'))
61  {
62  if (path.size() > 0)
63  {
64  if (path.size() > 4 && path.compare(path.size()-4, 4, ".cti") == 0)
65  {
66  // the given path points to one file ending with .cti
67 
68  ret.push_back(path);
69  }
70  else
71  {
72  // get all files with suffix .cti
73 
74  HANDLE p;
75  WIN32_FIND_DATA data;
76 
77  std::string dir=path;
78 
79  if (dir.size() > 0 && dir[dir.size()-1] != '\\')
80  {
81  dir+="\\";
82  }
83 
84  p=FindFirstFileA((dir+"*.cti").c_str(), &data);
85 
86  if (p != INVALID_HANDLE_VALUE)
87  {
88  do
89  {
90  ret.push_back(dir+data.cFileName);
91  }
92  while (FindNextFileA(p, &data));
93 
94  FindClose(p);
95  }
96  }
97  }
98  }
99  }
100 
101  return ret;
102 }
103 
104 namespace
105 {
106 
107 inline FARPROC getFunction(HMODULE lib, const char *name)
108 {
109  FARPROC ret=GetProcAddress(lib, name);
110 
111  if (ret == 0)
112  {
113  DWORD err=GetLastError();
114 
115  FreeLibrary(lib);
116 
117  std::ostringstream out;
118  out << "Cannot resolve GenTL symbol. Error code: " << err;
119 
120  throw std::invalid_argument(out.str());
121  }
122 
123  return ret;
124 }
125 
126 }
127 
128 GenTLWrapper::GenTLWrapper(const std::string &filename)
129 {
130  // open library
131 
132  HMODULE lp=LoadLibrary(filename.c_str());
133 
134  if (lp == 0)
135  {
136  DWORD err=GetLastError();
137 
138  std::ostringstream out;
139  out << "Cannot open GenTL library. Error code: " << err;
140 
141  throw std::invalid_argument(out.str());
142  }
143 
144  // resolve function calls that will only be used privately
145 
146  *reinterpret_cast<void**>(&GCInitLib)=getFunction(lp, "GCInitLib");
147  *reinterpret_cast<void**>(&GCCloseLib)=getFunction(lp, "GCCloseLib");
148 
149  // resolve public symbols
150 
151  *reinterpret_cast<void**>(&GCGetInfo)=getFunction(lp, "GCGetInfo");
152  *reinterpret_cast<void**>(&GCGetLastError)=getFunction(lp, "GCGetLastError");
153  *reinterpret_cast<void**>(&GCReadPort)=getFunction(lp, "GCReadPort");
154  *reinterpret_cast<void**>(&GCWritePort)=getFunction(lp, "GCWritePort");
155  *reinterpret_cast<void**>(&GCGetPortURL)=getFunction(lp, "GCGetPortURL");
156  *reinterpret_cast<void**>(&GCGetPortInfo)=getFunction(lp, "GCGetPortInfo");
157 
158  *reinterpret_cast<void**>(&GCRegisterEvent)=getFunction(lp, "GCRegisterEvent");
159  *reinterpret_cast<void**>(&GCUnregisterEvent)=getFunction(lp, "GCUnregisterEvent");
160  *reinterpret_cast<void**>(&EventGetData)=getFunction(lp, "EventGetData");
161  *reinterpret_cast<void**>(&EventGetDataInfo)=getFunction(lp, "EventGetDataInfo");
162  *reinterpret_cast<void**>(&EventGetInfo)=getFunction(lp, "EventGetInfo");
163  *reinterpret_cast<void**>(&EventFlush)=getFunction(lp, "EventFlush");
164  *reinterpret_cast<void**>(&EventKill)=getFunction(lp, "EventKill");
165  *reinterpret_cast<void**>(&TLOpen)=getFunction(lp, "TLOpen");
166  *reinterpret_cast<void**>(&TLClose)=getFunction(lp, "TLClose");
167  *reinterpret_cast<void**>(&TLGetInfo)=getFunction(lp, "TLGetInfo");
168  *reinterpret_cast<void**>(&TLGetNumInterfaces)=getFunction(lp, "TLGetNumInterfaces");
169  *reinterpret_cast<void**>(&TLGetInterfaceID)=getFunction(lp, "TLGetInterfaceID");
170  *reinterpret_cast<void**>(&TLGetInterfaceInfo)=getFunction(lp, "TLGetInterfaceInfo");
171  *reinterpret_cast<void**>(&TLOpenInterface)=getFunction(lp, "TLOpenInterface");
172  *reinterpret_cast<void**>(&TLUpdateInterfaceList)=getFunction(lp, "TLUpdateInterfaceList");
173  *reinterpret_cast<void**>(&IFClose)=getFunction(lp, "IFClose");
174  *reinterpret_cast<void**>(&IFGetInfo)=getFunction(lp, "IFGetInfo");
175  *reinterpret_cast<void**>(&IFGetNumDevices)=getFunction(lp, "IFGetNumDevices");
176  *reinterpret_cast<void**>(&IFGetDeviceID)=getFunction(lp, "IFGetDeviceID");
177  *reinterpret_cast<void**>(&IFUpdateDeviceList)=getFunction(lp, "IFUpdateDeviceList");
178  *reinterpret_cast<void**>(&IFGetDeviceInfo)=getFunction(lp, "IFGetDeviceInfo");
179  *reinterpret_cast<void**>(&IFOpenDevice)=getFunction(lp, "IFOpenDevice");
180 
181  *reinterpret_cast<void**>(&DevGetPort)=getFunction(lp, "DevGetPort");
182  *reinterpret_cast<void**>(&DevGetNumDataStreams)=getFunction(lp, "DevGetNumDataStreams");
183  *reinterpret_cast<void**>(&DevGetDataStreamID)=getFunction(lp, "DevGetDataStreamID");
184  *reinterpret_cast<void**>(&DevOpenDataStream)=getFunction(lp, "DevOpenDataStream");
185  *reinterpret_cast<void**>(&DevGetInfo)=getFunction(lp, "DevGetInfo");
186  *reinterpret_cast<void**>(&DevClose)=getFunction(lp, "DevClose");
187 
188  *reinterpret_cast<void**>(&DSAnnounceBuffer)=getFunction(lp, "DSAnnounceBuffer");
189  *reinterpret_cast<void**>(&DSAllocAndAnnounceBuffer)=getFunction(lp, "DSAllocAndAnnounceBuffer");
190  *reinterpret_cast<void**>(&DSFlushQueue)=getFunction(lp, "DSFlushQueue");
191  *reinterpret_cast<void**>(&DSStartAcquisition)=getFunction(lp, "DSStartAcquisition");
192  *reinterpret_cast<void**>(&DSStopAcquisition)=getFunction(lp, "DSStopAcquisition");
193  *reinterpret_cast<void**>(&DSGetInfo)=getFunction(lp, "DSGetInfo");
194  *reinterpret_cast<void**>(&DSGetBufferID)=getFunction(lp, "DSGetBufferID");
195  *reinterpret_cast<void**>(&DSClose)=getFunction(lp, "DSClose");
196  *reinterpret_cast<void**>(&DSRevokeBuffer)=getFunction(lp, "DSRevokeBuffer");
197  *reinterpret_cast<void**>(&DSQueueBuffer)=getFunction(lp, "DSQueueBuffer");
198  *reinterpret_cast<void**>(&DSGetBufferInfo)=getFunction(lp, "DSGetBufferInfo");
199 
200  *reinterpret_cast<void**>(&GCGetNumPortURLs)=getFunction(lp, "GCGetNumPortURLs");
201  *reinterpret_cast<void**>(&GCGetPortURLInfo)=getFunction(lp, "GCGetPortURLInfo");
202  *reinterpret_cast<void**>(&GCReadPortStacked)=getFunction(lp, "GCReadPortStacked");
203  *reinterpret_cast<void**>(&GCWritePortStacked)=getFunction(lp, "GCWritePortStacked");
204 
205  *reinterpret_cast<void**>(&DSGetBufferChunkData)=getFunction(lp, "DSGetBufferChunkData");
206 
207  *reinterpret_cast<void**>(&IFGetParentTL)=getFunction(lp, "IFGetParentTL");
208  *reinterpret_cast<void**>(&DevGetParentIF)=getFunction(lp, "DevGetParentIF");
209  *reinterpret_cast<void**>(&DSGetParentDev)=getFunction(lp, "DSGetParentDev");
210 
211  *reinterpret_cast<void**>(&DSGetNumBufferParts)=getFunction(lp, "DSGetNumBufferParts");
212  *reinterpret_cast<void**>(&DSGetBufferPartInfo)=getFunction(lp, "DSGetBufferPartInfo");
213 
214  lib=static_cast<void *>(lp);
215 }
216 
218 {
219  FreeLibrary(static_cast<HMODULE>(lib));
220 }
221 
222 }
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
std::string str()
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