Skip to content

Commit

Permalink
Do not use boost::thread anymore, and clean a little bit our cmake usage
Browse files Browse the repository at this point in the history
  • Loading branch information
aguinet committed Feb 26, 2019
1 parent 71f1014 commit 17fa276
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ set (VERSION_MINOR 1)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)

## Libraries

# PCAP
find_package(PCAP REQUIRED)

# Boost thread
find_package(Boost REQUIRED COMPONENTS thread)

##

include_directories(include)

add_subdirectory(src)
8 changes: 1 addition & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
include_directories(${PCAP_INCLUDE_DIRS})
add_definitions("-std=c++0x -Wall -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64")

IF(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]")
add_definitions("-g")
else()
add_definitions("-O3")
endif()

set(SRC_FILES
buses.cpp
console_output.cpp
Expand All @@ -20,6 +14,6 @@ usb_stats.cpp
)

add_executable(usbtop ${SRC_FILES})
target_link_libraries(usbtop ${PCAP_LIBRARIES} Boost::thread)
target_link_libraries(usbtop ${PCAP_LIBRARIES} Boost::thread)

install(TARGETS usbtop DESTINATION sbin)
27 changes: 11 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <cstdlib>
#include <errno.h>
#include <getopt.h>
#include <iostream>
#include <pcap/pcap.h>
#include <signal.h>
#include <string.h>
#include <strings.h>

#include <cstdlib>
#include <thread>
#include <iostream>

#include <pcap/pcap.h>

#include <usbtop/buses.h>
#include <usbtop/console_output.h>
#include <usbtop/pcap_compat.h>
Expand All @@ -47,8 +50,6 @@
#include <utility>
#endif

#include <boost/thread.hpp>

#include <vector>

struct pcap_bus
Expand Down Expand Up @@ -160,7 +161,7 @@ int main(int argc, char** argv)
{0, 0, 0, 0}
};

char* bus_filter = NULL;
std::unique_ptr<char, decltype(free)*> bus_filter(nullptr, &free);
int longindex;
while (1)
{
Expand All @@ -170,7 +171,7 @@ int main(int argc, char** argv)
switch (opt)
{
case 'b':
bus_filter = strdup(optarg);
bus_filter.reset(strdup(optarg));
break;
case '?':
std::cerr << "Unrecognized option : " << argv[optind-1] << std::endl;
Expand All @@ -180,8 +181,7 @@ int main(int argc, char** argv)
}

if (show_list) {
usbtop::UsbBuses::show(bus_filter);
if (bus_filter) free(bus_filter);
usbtop::UsbBuses::show(bus_filter.get());
return 0;
}

Expand All @@ -192,10 +192,9 @@ int main(int argc, char** argv)
signal(SIGKILL, &quit_handler);

// Populate USB buses
usbtop::UsbBuses::populate(bus_filter);
usbtop::UsbBuses::populate(bus_filter.get());
if (usbtop::UsbBuses::size() == 0) {
std::cerr << "No USB bus can be captured thanks to libpcap. Check your name filter and make sure relevent permissions are set !" << std::endl;
if (bus_filter) free(bus_filter);
return 1;
}

Expand Down Expand Up @@ -230,7 +229,7 @@ int main(int argc, char** argv)
}

// Launch capturing thread
boost::thread capturing_th(boost::bind(pcap_usb_async_loop, pcap_hs));
std::thread capturing_th(std::bind(pcap_usb_async_loop, pcap_hs));

// Current thread will output on the main console
usbtop::ConsoleOutput::main();
Expand All @@ -240,9 +239,5 @@ int main(int argc, char** argv)

clean_pcap_live(pcap_hs);

if (bus_filter) {
free(bus_filter);
}

return 0;
}

0 comments on commit 17fa276

Please sign in to comment.