All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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_DATAA 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=LoadLibraryA(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 }
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
std::ostringstream::str
std::string str()
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
std::ostringstream
Definition: Portability.hh:42
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