gentl_wrapper_win32.cc
Go to the documentation of this file.
00001 /*
00002  * This file is part of the rc_genicam_api package.
00003  *
00004  * Copyright (c) 2017 Roboception GmbH
00005  * All rights reserved
00006  *
00007  * Author: Heiko Hirschmueller
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright notice,
00013  * this list of conditions and the following disclaimer.
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  * this list of conditions and the following disclaimer in the documentation
00017  * and/or other materials provided with the distribution.
00018  *
00019  * 3. Neither the name of the copyright holder nor the names of its contributors
00020  * may be used to endorse or promote products derived from this software without
00021  * specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  * POSSIBILITY OF SUCH DAMAGE.
00034  */
00035 
00036 #include "gentl_wrapper.h"
00037 
00038 #include <string>
00039 #include <sstream>
00040 #include <stdexcept>
00041 #include <cstdlib>
00042 #include <iostream>
00043 
00044 #include <Windows.h>
00045 
00046 namespace rcg
00047 {
00048 
00049 std::vector<std::string> getAvailableGenTLs(const char *paths)
00050 {
00051   std::vector<std::string> ret;
00052 
00053   if (paths != 0)
00054   {
00055     // split path list into individual paths
00056 
00057     std::stringstream in(paths);
00058     std::string path;
00059 
00060     while (getline(in, path, ';'))
00061     {
00062       if (path.size() > 0)
00063       {
00064         if (path.size() > 4 && path.compare(path.size()-4, 4, ".cti") == 0)
00065         {
00066           // the given path points to one file ending with .cti
00067 
00068           ret.push_back(path);
00069         }
00070         else
00071         {
00072           // get all files with suffix .cti
00073 
00074           HANDLE p;
00075           WIN32_FIND_DATA data;
00076 
00077           std::string dir=path;
00078 
00079           if (dir.size() > 0 && dir[dir.size()-1] != '\\')
00080           {
00081             dir+="\\";
00082           }
00083 
00084           p=FindFirstFileA((dir+"*.cti").c_str(), &data);
00085 
00086           if (p != INVALID_HANDLE_VALUE)
00087           {
00088             do
00089             {
00090               ret.push_back(dir+data.cFileName);
00091             }
00092             while (FindNextFileA(p, &data));
00093 
00094             FindClose(p);
00095           }
00096         }
00097       }
00098     }
00099   }
00100 
00101   return ret;
00102 }
00103 
00104 namespace
00105 {
00106 
00107 inline FARPROC getFunction(HMODULE lib, const char *name)
00108 {
00109   FARPROC ret=GetProcAddress(lib, name);
00110 
00111   if (ret == 0)
00112   {
00113     DWORD err=GetLastError();
00114 
00115     FreeLibrary(lib);
00116 
00117     std::ostringstream out;
00118     out << "Cannot resolve GenTL symbol. Error code: " << err;
00119 
00120     throw std::invalid_argument(out.str());
00121   }
00122 
00123   return ret;
00124 }
00125 
00126 }
00127 
00128 GenTLWrapper::GenTLWrapper(const std::string &filename)
00129 {
00130   // open library
00131 
00132   HMODULE lp=LoadLibrary(filename.c_str());
00133 
00134   if (lp == 0)
00135   {
00136     DWORD err=GetLastError();
00137 
00138     std::ostringstream out;
00139     out << "Cannot open GenTL library. Error code: " << err;
00140 
00141     throw std::invalid_argument(out.str());
00142   }
00143 
00144   // resolve function calls that will only be used privately
00145 
00146   *reinterpret_cast<void**>(&GCInitLib)=getFunction(lp, "GCInitLib");
00147   *reinterpret_cast<void**>(&GCCloseLib)=getFunction(lp, "GCCloseLib");
00148 
00149   // resolve public symbols
00150 
00151   *reinterpret_cast<void**>(&GCGetInfo)=getFunction(lp, "GCGetInfo");
00152   *reinterpret_cast<void**>(&GCGetLastError)=getFunction(lp, "GCGetLastError");
00153   *reinterpret_cast<void**>(&GCReadPort)=getFunction(lp, "GCReadPort");
00154   *reinterpret_cast<void**>(&GCWritePort)=getFunction(lp, "GCWritePort");
00155   *reinterpret_cast<void**>(&GCGetPortURL)=getFunction(lp, "GCGetPortURL");
00156   *reinterpret_cast<void**>(&GCGetPortInfo)=getFunction(lp, "GCGetPortInfo");
00157 
00158   *reinterpret_cast<void**>(&GCRegisterEvent)=getFunction(lp, "GCRegisterEvent");
00159   *reinterpret_cast<void**>(&GCUnregisterEvent)=getFunction(lp, "GCUnregisterEvent");
00160   *reinterpret_cast<void**>(&EventGetData)=getFunction(lp, "EventGetData");
00161   *reinterpret_cast<void**>(&EventGetDataInfo)=getFunction(lp, "EventGetDataInfo");
00162   *reinterpret_cast<void**>(&EventGetInfo)=getFunction(lp, "EventGetInfo");
00163   *reinterpret_cast<void**>(&EventFlush)=getFunction(lp, "EventFlush");
00164   *reinterpret_cast<void**>(&EventKill)=getFunction(lp, "EventKill");
00165   *reinterpret_cast<void**>(&TLOpen)=getFunction(lp, "TLOpen");
00166   *reinterpret_cast<void**>(&TLClose)=getFunction(lp, "TLClose");
00167   *reinterpret_cast<void**>(&TLGetInfo)=getFunction(lp, "TLGetInfo");
00168   *reinterpret_cast<void**>(&TLGetNumInterfaces)=getFunction(lp, "TLGetNumInterfaces");
00169   *reinterpret_cast<void**>(&TLGetInterfaceID)=getFunction(lp, "TLGetInterfaceID");
00170   *reinterpret_cast<void**>(&TLGetInterfaceInfo)=getFunction(lp, "TLGetInterfaceInfo");
00171   *reinterpret_cast<void**>(&TLOpenInterface)=getFunction(lp, "TLOpenInterface");
00172   *reinterpret_cast<void**>(&TLUpdateInterfaceList)=getFunction(lp, "TLUpdateInterfaceList");
00173   *reinterpret_cast<void**>(&IFClose)=getFunction(lp, "IFClose");
00174   *reinterpret_cast<void**>(&IFGetInfo)=getFunction(lp, "IFGetInfo");
00175   *reinterpret_cast<void**>(&IFGetNumDevices)=getFunction(lp, "IFGetNumDevices");
00176   *reinterpret_cast<void**>(&IFGetDeviceID)=getFunction(lp, "IFGetDeviceID");
00177   *reinterpret_cast<void**>(&IFUpdateDeviceList)=getFunction(lp, "IFUpdateDeviceList");
00178   *reinterpret_cast<void**>(&IFGetDeviceInfo)=getFunction(lp, "IFGetDeviceInfo");
00179   *reinterpret_cast<void**>(&IFOpenDevice)=getFunction(lp, "IFOpenDevice");
00180 
00181   *reinterpret_cast<void**>(&DevGetPort)=getFunction(lp, "DevGetPort");
00182   *reinterpret_cast<void**>(&DevGetNumDataStreams)=getFunction(lp, "DevGetNumDataStreams");
00183   *reinterpret_cast<void**>(&DevGetDataStreamID)=getFunction(lp, "DevGetDataStreamID");
00184   *reinterpret_cast<void**>(&DevOpenDataStream)=getFunction(lp, "DevOpenDataStream");
00185   *reinterpret_cast<void**>(&DevGetInfo)=getFunction(lp, "DevGetInfo");
00186   *reinterpret_cast<void**>(&DevClose)=getFunction(lp, "DevClose");
00187 
00188   *reinterpret_cast<void**>(&DSAnnounceBuffer)=getFunction(lp, "DSAnnounceBuffer");
00189   *reinterpret_cast<void**>(&DSAllocAndAnnounceBuffer)=getFunction(lp, "DSAllocAndAnnounceBuffer");
00190   *reinterpret_cast<void**>(&DSFlushQueue)=getFunction(lp, "DSFlushQueue");
00191   *reinterpret_cast<void**>(&DSStartAcquisition)=getFunction(lp, "DSStartAcquisition");
00192   *reinterpret_cast<void**>(&DSStopAcquisition)=getFunction(lp, "DSStopAcquisition");
00193   *reinterpret_cast<void**>(&DSGetInfo)=getFunction(lp, "DSGetInfo");
00194   *reinterpret_cast<void**>(&DSGetBufferID)=getFunction(lp, "DSGetBufferID");
00195   *reinterpret_cast<void**>(&DSClose)=getFunction(lp, "DSClose");
00196   *reinterpret_cast<void**>(&DSRevokeBuffer)=getFunction(lp, "DSRevokeBuffer");
00197   *reinterpret_cast<void**>(&DSQueueBuffer)=getFunction(lp, "DSQueueBuffer");
00198   *reinterpret_cast<void**>(&DSGetBufferInfo)=getFunction(lp, "DSGetBufferInfo");
00199 
00200   *reinterpret_cast<void**>(&GCGetNumPortURLs)=getFunction(lp, "GCGetNumPortURLs");
00201   *reinterpret_cast<void**>(&GCGetPortURLInfo)=getFunction(lp, "GCGetPortURLInfo");
00202   *reinterpret_cast<void**>(&GCReadPortStacked)=getFunction(lp, "GCReadPortStacked");
00203   *reinterpret_cast<void**>(&GCWritePortStacked)=getFunction(lp, "GCWritePortStacked");
00204 
00205   *reinterpret_cast<void**>(&DSGetBufferChunkData)=getFunction(lp, "DSGetBufferChunkData");
00206 
00207   *reinterpret_cast<void**>(&IFGetParentTL)=getFunction(lp, "IFGetParentTL");
00208   *reinterpret_cast<void**>(&DevGetParentIF)=getFunction(lp, "DevGetParentIF");
00209   *reinterpret_cast<void**>(&DSGetParentDev)=getFunction(lp, "DSGetParentDev");
00210 
00211   *reinterpret_cast<void**>(&DSGetNumBufferParts)=getFunction(lp, "DSGetNumBufferParts");
00212   *reinterpret_cast<void**>(&DSGetBufferPartInfo)=getFunction(lp, "DSGetBufferPartInfo");
00213 
00214   lib=static_cast<void *>(lp);
00215 }
00216 
00217 GenTLWrapper::~GenTLWrapper()
00218 {
00219   FreeLibrary(static_cast<HMODULE>(lib));
00220 }
00221 
00222 }


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 18:42:47