From 2276e615a9cd98d34150999a969766ae511e012c Mon Sep 17 00:00:00 2001 From: paragi Date: Sun, 21 Apr 2019 17:55:08 +0200 Subject: [PATCH 1/5] Adapted for linux. Added Makefile --- .gitignore | 3 +- Makefile | 103 ++++++++++++++++++++++++++++++++++++++ src/ConfigurationImpl.hpp | 6 ++- src/DeviceImpl.cpp | 10 ++-- src/DeviceImpl.hpp | 6 ++- src/EndpointImpl.hpp | 6 ++- src/Exception.cpp | 6 ++- src/Interface.cpp | 7 ++- src/InterfaceImpl.cpp | 2 +- src/InterfaceImpl.hpp | 8 ++- src/LibusbImpl.hpp | 6 ++- src/Transfer.cpp | 2 +- src/TransferImpl.cpp | 2 +- src/TransferImpl.hpp | 6 ++- src/Wideconvert.cpp | 2 +- 15 files changed, 157 insertions(+), 18 deletions(-) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 17db614..d8a88d9 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ # Application Generated Files # ############################### *.cfg +.* # Logs and databases # ###################### @@ -78,4 +79,4 @@ CVS # Folders starting with underscore. # ##################################### -_* \ No newline at end of file +_* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..50fbd36 --- /dev/null +++ b/Makefile @@ -0,0 +1,103 @@ +# +# Makefile template +# +# This is an example Makefile that can be used by anyone who is building +# his or her own PHP extensions using the PHP-CPP library. +# +# In the top part of this file we have included variables that can be +# altered to fit your configuration, near the bottom the instructions and +# dependencies for the compiler are defined. The deeper you get into this +# file, the less likely it is that you will have to change anything in it. +# + +# +# Name of your extension +# +# This is the name of your extension. Based on this extension name, the +# name of the library file (name.so) and the name of the config file (name.ini) +# are automatically generated +# + +NAME = libusbpp +INCLUDE_PATH = ./headers + +# +# Compiler +# +# By default, the GNU C++ compiler is used. If you want to use a different +# compiler, you can change that here. You can change this for both the +# compiler (the program that turns the c++ files into object files) and for +# the linker (the program that links all object files into the single .so +# library file. By default, g++ (the GNU C++ compiler) is used for both. +# + +COMPILER = g++ +LINKER = g++ + +# +# Compiler and linker flags +# +# This variable holds the flags that are passed to the compiler. By default, +# we include the -O2 flag. This flag tells the compiler to optimize the code, +# but it makes debugging more difficult. So if you're debugging your application, +# you probably want to remove this -O2 flag. At the same time, you can then +# add the -g flag to instruct the compiler to include debug information in +# the library (but this will make the final libphpcpp.so file much bigger, so +# you want to leave that flag out on production servers). +# +# If your extension depends on other libraries (and it does at least depend on +# one: the PHP-CPP library), you should update the LINKER_DEPENDENCIES variable +# with a list of all flags that should be passed to the linker. +# +COMPILER_DEBUG_FLAGS = -ggdb3 +COMPILER_FLAGS = -Wall -c -O2 -fpic -I${INCLUDE_PATH} -o +COMPILER_FLAGS = -Wall -c -O2 -fpic -I${INCLUDE_PATH} ${COMPILER_DEBUG_FLAGS} -o +LINKER_FLAGS = -lusb-1.0 -lpthread + +# +# Command to remove files, copy files and create directories. +# +# I've never encountered a *nix environment in which these commands do not work. +# So you can probably leave this as it is +# + +RM = rm -f +CP = cp -f +MKDIR = mkdir -p +LS = ls -1 + + +# +# All source files are simply all *.cpp files found in the current directory +# +# A builtin Makefile macro is used to scan the current directory and find +# all source files. The object files are all compiled versions of the source +# file, with the .cpp extension being replaced by .o. +# + +SOURCES = $(wildcard ./src/*.cpp) +HEARDERS = $(wildcard ./src/*.hpp) +EXAMPELS = $(wildcard ./examples/*.cpp) +OBJECTS = $(SOURCES:%.cpp=%.o) $(EXAMPELS:%.cpp=%.o) +EXECUTABLES = $(EXAMPELS:%.cpp=%) + +# +# From here the build instructions start +# +all: ${EXECUTABLES} ${OBJECTS} ${SOURCES} ${HEARDERS} ${EXAMPELS} + echo ${EXECUTABLES} ${OBJECTS} ${SOURCES} ${HEARDERS} ${EXAMPELS} + +${OBJECTS}: ${SOURCES} ${HEARDERS} ${EXAMPELS} + ${COMPILER} ${COMPILER_FLAGS} $@ ${@:%.o=%.cpp} + +${EXECUTABLES}: ${OBJECTS} + ${LINKER} -o $@ ${OBJECTS} ${LINKER_FLAGS} + +test: .TEST + +.TEST: + ./examples/LibusbTest + +clean: + echo ${RM} ${OBJECTS} + ${RM} ${OBJECTS} diff --git a/src/ConfigurationImpl.hpp b/src/ConfigurationImpl.hpp index d907b6a..553ac57 100644 --- a/src/ConfigurationImpl.hpp +++ b/src/ConfigurationImpl.hpp @@ -25,7 +25,11 @@ #include #include -#include +#ifdef __linux__ + #include +#elif _WIN32 + #include +#endif #include diff --git a/src/DeviceImpl.cpp b/src/DeviceImpl.cpp index 4ddbeab..1533488 100644 --- a/src/DeviceImpl.cpp +++ b/src/DeviceImpl.cpp @@ -22,7 +22,11 @@ #include #include -#include +#ifdef __linux__ + #include +#elif _WIN32 + #include +#endif #include #include @@ -155,7 +159,7 @@ std::wstring LibUSB::DeviceImpl::getStringDescriptorW( uint8_t index ) std::wstring strResult; strResult.resize((descSize-2)/2); - for (size_t i = 0; i < (descSize-2)/2; ++i) { + for (int i = 0; i < (descSize-2)/2; ++i) { unsigned char chr1 = (unsigned char)descStr[2 * i + 2]; unsigned char chr2 = (unsigned char)descStr[2 * i + 3]; @@ -186,7 +190,7 @@ uint16_t LibUSB::DeviceImpl::getLangId() } // First element is the size of the descriptor, in bytes - uint8_t descriptorSize = data[0]; + //uint8_t descriptorSize = data[0]; // Second element should be 0x03 if (data[1] != 0x03) diff --git a/src/DeviceImpl.hpp b/src/DeviceImpl.hpp index 78c2f3a..7a23e5c 100644 --- a/src/DeviceImpl.hpp +++ b/src/DeviceImpl.hpp @@ -25,7 +25,11 @@ #include #include -#include +#ifdef __linux__ + #include +#elif _WIN32 + #include +#endif #include diff --git a/src/EndpointImpl.hpp b/src/EndpointImpl.hpp index 62d7fe0..4233974 100644 --- a/src/EndpointImpl.hpp +++ b/src/EndpointImpl.hpp @@ -24,7 +24,11 @@ #include #include -#include +#ifdef __linux__ + #include +#elif _WIN32 + #include +#endif #include #include diff --git a/src/Exception.cpp b/src/Exception.cpp index 18d0e40..25521df 100644 --- a/src/Exception.cpp +++ b/src/Exception.cpp @@ -20,7 +20,11 @@ #include -#include +#ifdef __linux__ + #include +#elif _WIN32 + #include +#endif #include diff --git a/src/Interface.cpp b/src/Interface.cpp index f4cab21..a230a59 100644 --- a/src/Interface.cpp +++ b/src/Interface.cpp @@ -18,7 +18,11 @@ * along with libusbpp. If not, see . */ -#include +#ifdef __linux__ + #include +#elif _WIN32 + #include +#endif #include @@ -131,4 +135,3 @@ bool LibUSB::Interface::isClaimed() const return m_pInterfaceImpl->isClaimed(); } - diff --git a/src/InterfaceImpl.cpp b/src/InterfaceImpl.cpp index 0cd541e..d13ac86 100644 --- a/src/InterfaceImpl.cpp +++ b/src/InterfaceImpl.cpp @@ -29,7 +29,7 @@ LibUSB::InterfaceImpl::InterfaceImpl( const libusb_interface* pInterface, std::weak_ptr pDeviceImpl ) - : m_pInterface(pInterface), m_alternateSetting(0), m_bClaimed(false) + : m_alternateSetting(0), m_pInterface(pInterface), m_bClaimed(false) { if (!pDeviceImpl.expired()) diff --git a/src/InterfaceImpl.hpp b/src/InterfaceImpl.hpp index 2a627d9..627f295 100644 --- a/src/InterfaceImpl.hpp +++ b/src/InterfaceImpl.hpp @@ -25,7 +25,11 @@ #include #include -#include +#ifdef __linux__ + #include +#elif _WIN32 + #include +#endif #include @@ -74,7 +78,7 @@ namespace LibUSB /*! * \brief Selects an alternate interface setting. - * + * * * \param AlternateSetting (uint8_t): the index of the alternate setting to select/use. * \throws (std::logic_error) if the alternate setting is out-of-range. diff --git a/src/LibusbImpl.hpp b/src/LibusbImpl.hpp index 7433726..a0d2a6b 100644 --- a/src/LibusbImpl.hpp +++ b/src/LibusbImpl.hpp @@ -26,7 +26,11 @@ #include #include -#include +#ifdef __linux__ + #include +#elif _WIN32 + #include +#endif namespace LibUSB diff --git a/src/Transfer.cpp b/src/Transfer.cpp index 48566cb..d808e6f 100644 --- a/src/Transfer.cpp +++ b/src/Transfer.cpp @@ -233,7 +233,7 @@ void LibUSB::Transfer::AsyncStart() std::thread transferThread([=]() { - bool Result = false; + //bool Result = false; try { diff --git a/src/TransferImpl.cpp b/src/TransferImpl.cpp index e471350..82fbd47 100644 --- a/src/TransferImpl.cpp +++ b/src/TransferImpl.cpp @@ -32,7 +32,7 @@ LibUSB::TransferImpl::TransferImpl(std::weak_ptr pEndpointImpl) - : m_Timeout(0), m_Complete(false), m_Submitted(false), m_transferSize(0) + : m_Timeout(0), m_transferSize(0), m_Complete(false), m_Submitted(false) { if (pEndpointImpl.expired()) diff --git a/src/TransferImpl.hpp b/src/TransferImpl.hpp index bf71a6a..17f19ee 100644 --- a/src/TransferImpl.hpp +++ b/src/TransferImpl.hpp @@ -26,7 +26,11 @@ #include #include -#include +#ifdef __linux__ + #include +#elif _WIN32 + #include +#endif #include #include diff --git a/src/Wideconvert.cpp b/src/Wideconvert.cpp index 21b6ed2..88f5459 100644 --- a/src/Wideconvert.cpp +++ b/src/Wideconvert.cpp @@ -75,7 +75,7 @@ std::wstring LibUSB::Util::StringToWString( const std::string& ns ) std::string LibUSB::Util::WStringToString( const std::wstring& ws ) { -#if defined(__STDC_LIB_EXT1__) || defined(_WIN32) +#if defined(__zSTDC_LIB_EXT1__) || defined(_WIN32) size_t bufferSize; // first call to wcstombs_s to get the target buffer size From 577b83184159f8e56427c8e2625be5b5b140115e Mon Sep 17 00:00:00 2001 From: paragi Date: Sun, 21 Apr 2019 17:59:38 +0200 Subject: [PATCH 2/5] unintended extra char removed --- src/Wideconvert.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Wideconvert.cpp b/src/Wideconvert.cpp index 88f5459..21b6ed2 100644 --- a/src/Wideconvert.cpp +++ b/src/Wideconvert.cpp @@ -75,7 +75,7 @@ std::wstring LibUSB::Util::StringToWString( const std::string& ns ) std::string LibUSB::Util::WStringToString( const std::wstring& ws ) { -#if defined(__zSTDC_LIB_EXT1__) || defined(_WIN32) +#if defined(__STDC_LIB_EXT1__) || defined(_WIN32) size_t bufferSize; // first call to wcstombs_s to get the target buffer size From d3bcc82617ab754d9d06d77a94ad37847f5617c2 Mon Sep 17 00:00:00 2001 From: paragi Date: Sun, 21 Apr 2019 18:02:10 +0200 Subject: [PATCH 3/5] unremark --- src/DeviceImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DeviceImpl.cpp b/src/DeviceImpl.cpp index 1533488..7c6adc0 100644 --- a/src/DeviceImpl.cpp +++ b/src/DeviceImpl.cpp @@ -190,7 +190,7 @@ uint16_t LibUSB::DeviceImpl::getLangId() } // First element is the size of the descriptor, in bytes - //uint8_t descriptorSize = data[0]; + uint8_t descriptorSize = data[0]; // Second element should be 0x03 if (data[1] != 0x03) From 9e6efbb68616b0111fc8657c09c9264b267f9a8c Mon Sep 17 00:00:00 2001 From: paragi Date: Sun, 21 Apr 2019 18:07:18 +0200 Subject: [PATCH 4/5] Adapted for linux. Added Makefile --- Makefile | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 50fbd36..81626ee 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,5 @@ +# Makefile for Libusbpp # -# Makefile template -# -# This is an example Makefile that can be used by anyone who is building -# his or her own PHP extensions using the PHP-CPP library. -# -# In the top part of this file we have included variables that can be -# altered to fit your configuration, near the bottom the instructions and -# dependencies for the compiler are defined. The deeper you get into this -# file, the less likely it is that you will have to change anything in it. -# - -# -# Name of your extension -# -# This is the name of your extension. Based on this extension name, the -# name of the library file (name.so) and the name of the config file (name.ini) -# are automatically generated # NAME = libusbpp @@ -24,11 +8,7 @@ INCLUDE_PATH = ./headers # # Compiler # -# By default, the GNU C++ compiler is used. If you want to use a different -# compiler, you can change that here. You can change this for both the -# compiler (the program that turns the c++ files into object files) and for -# the linker (the program that links all object files into the single .so -# library file. By default, g++ (the GNU C++ compiler) is used for both. +# By default, the GNU C++ compiler is used. # COMPILER = g++ @@ -42,24 +22,16 @@ LINKER = g++ # but it makes debugging more difficult. So if you're debugging your application, # you probably want to remove this -O2 flag. At the same time, you can then # add the -g flag to instruct the compiler to include debug information in -# the library (but this will make the final libphpcpp.so file much bigger, so +# the library (but this will make the final file much bigger, so # you want to leave that flag out on production servers). # -# If your extension depends on other libraries (and it does at least depend on -# one: the PHP-CPP library), you should update the LINKER_DEPENDENCIES variable -# with a list of all flags that should be passed to the linker. -# -COMPILER_DEBUG_FLAGS = -ggdb3 +COMPILER_DEBUG_FLAGS = -Wall -c -ggdb3 -fpic -I${INCLUDE_PATH} -o COMPILER_FLAGS = -Wall -c -O2 -fpic -I${INCLUDE_PATH} -o -COMPILER_FLAGS = -Wall -c -O2 -fpic -I${INCLUDE_PATH} ${COMPILER_DEBUG_FLAGS} -o LINKER_FLAGS = -lusb-1.0 -lpthread # # Command to remove files, copy files and create directories. # -# I've never encountered a *nix environment in which these commands do not work. -# So you can probably leave this as it is -# RM = rm -f CP = cp -f From 7cd2215e4dcae90c83356df0bd1f1926b376a0fb Mon Sep 17 00:00:00 2001 From: paragi Date: Sun, 21 Apr 2019 18:18:43 +0200 Subject: [PATCH 5/5] Adapted for linux. Added Makefile --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 81626ee..9ef4971 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +# # Makefile for Libusbpp # # @@ -8,7 +9,7 @@ INCLUDE_PATH = ./headers # # Compiler # -# By default, the GNU C++ compiler is used. +# By default, the GNU C++ compiler is used. # COMPILER = g++ @@ -25,7 +26,7 @@ LINKER = g++ # the library (but this will make the final file much bigger, so # you want to leave that flag out on production servers). # -COMPILER_DEBUG_FLAGS = -Wall -c -ggdb3 -fpic -I${INCLUDE_PATH} -o +#COMPILER_FLAGS = -Wall -c -ggdb3 -fpic -I${INCLUDE_PATH} -o COMPILER_FLAGS = -Wall -c -O2 -fpic -I${INCLUDE_PATH} -o LINKER_FLAGS = -lusb-1.0 -lpthread @@ -38,7 +39,6 @@ CP = cp -f MKDIR = mkdir -p LS = ls -1 - # # All source files are simply all *.cpp files found in the current directory #