feat:replace boost library with C++11 std library
This commit is contained in:
@@ -25,8 +25,8 @@
|
||||
#ifndef LIVOX_COMMAND_CALLBACK_H
|
||||
#define LIVOX_COMMAND_CALLBACK_H
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include "livox_sdk.h"
|
||||
|
||||
namespace livox {
|
||||
@@ -76,9 +76,9 @@ class MemberFunctionCallback<T, uint8_t> : public CommandCallback {
|
||||
};
|
||||
|
||||
template <class T, class ResponseType>
|
||||
boost::shared_ptr<CommandCallback> MakeCommandCallback(T *cls,
|
||||
std::shared_ptr<CommandCallback> MakeCommandCallback(T *cls,
|
||||
typename MemberFunctionCallback<T, ResponseType>::MemFn func) {
|
||||
boost::shared_ptr<CommandCallback> cb(new MemberFunctionCallback<T, ResponseType>(cls, func));
|
||||
std::shared_ptr<CommandCallback> cb(new MemberFunctionCallback<T, ResponseType>(cls, func));
|
||||
return cb;
|
||||
}
|
||||
|
||||
@@ -123,8 +123,8 @@ class FunctionStatusCallback<uint8_t> : public CommandCallback {
|
||||
};
|
||||
|
||||
template <class T>
|
||||
boost::shared_ptr<CommandCallback> MakeCommandCallback(typename FunctionStatusCallback<T>::Fn func, void *client_data) {
|
||||
boost::shared_ptr<CommandCallback> cb(new FunctionStatusCallback<T>(func, client_data));
|
||||
std::shared_ptr<CommandCallback> MakeCommandCallback(typename FunctionStatusCallback<T>::Fn func, void *client_data) {
|
||||
std::shared_ptr<CommandCallback> cb(new FunctionStatusCallback<T>(func, client_data));
|
||||
return cb;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class MessageCallback : public CommandCallback {
|
||||
template <class ResponseType>
|
||||
class BoostFunctionMessageCallback : public CommandCallback {
|
||||
public:
|
||||
typedef boost::function<void(livox_status, uint8_t, ResponseType *)> Fn;
|
||||
typedef std::function<void(livox_status, uint8_t, ResponseType *)> Fn;
|
||||
|
||||
public:
|
||||
BoostFunctionMessageCallback(const Fn &func) : func_(func) {}
|
||||
@@ -163,14 +163,14 @@ class BoostFunctionMessageCallback : public CommandCallback {
|
||||
};
|
||||
|
||||
template <class T>
|
||||
boost::shared_ptr<CommandCallback> MakeMessageCallback(typename MessageCallback<T>::Fn func) {
|
||||
boost::shared_ptr<CommandCallback> cb(new MessageCallback<T>(func));
|
||||
std::shared_ptr<CommandCallback> MakeMessageCallback(typename MessageCallback<T>::Fn func) {
|
||||
std::shared_ptr<CommandCallback> cb(new MessageCallback<T>(func));
|
||||
return cb;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
boost::shared_ptr<CommandCallback> MakeMessageCallback(typename BoostFunctionMessageCallback<T>::Fn func) {
|
||||
boost::shared_ptr<CommandCallback> cb(new BoostFunctionMessageCallback<T>(func));
|
||||
std::shared_ptr<CommandCallback> MakeMessageCallback(typename BoostFunctionMessageCallback<T>::Fn func) {
|
||||
std::shared_ptr<CommandCallback> cb(new BoostFunctionMessageCallback<T>(func));
|
||||
return cb;
|
||||
}
|
||||
|
||||
@@ -192,17 +192,17 @@ class MemberMessageCallback : public CommandCallback {
|
||||
};
|
||||
|
||||
template <class T, class ResponseType>
|
||||
boost::shared_ptr<CommandCallback> MakeMemberMessageCallback(
|
||||
std::shared_ptr<CommandCallback> MakeMemberMessageCallback(
|
||||
T *_this,
|
||||
typename MemberMessageCallback<T, ResponseType>::MemFn func) {
|
||||
boost::shared_ptr<CommandCallback> cb(new MemberMessageCallback<T, ResponseType>(_this, func));
|
||||
std::shared_ptr<CommandCallback> cb(new MemberMessageCallback<T, ResponseType>(_this, func));
|
||||
return cb;
|
||||
}
|
||||
|
||||
template <class ResponseType>
|
||||
class BoostFunctionCallback : public CommandCallback {
|
||||
public:
|
||||
typedef boost::function<void(uint8_t, uint8_t, ResponseType *)> Fn;
|
||||
typedef std::function<void(uint8_t, uint8_t, ResponseType *)> Fn;
|
||||
BoostFunctionCallback(const Fn &func) : func_(func) {}
|
||||
void operator()(livox_status status,uint8_t handle, void *data) {
|
||||
if (func_) {
|
||||
@@ -221,7 +221,7 @@ class BoostFunctionCallback : public CommandCallback {
|
||||
template <>
|
||||
class BoostFunctionCallback<uint8_t> : public CommandCallback {
|
||||
public:
|
||||
typedef boost::function<void(uint8_t, uint8_t, uint8_t)> Fn;
|
||||
typedef std::function<void(uint8_t, uint8_t, uint8_t)> Fn;
|
||||
BoostFunctionCallback(const Fn &func) : func_(func) {}
|
||||
void operator()(livox_status status,uint8_t handle, void *data) {
|
||||
if (func_) {
|
||||
@@ -238,8 +238,8 @@ class BoostFunctionCallback<uint8_t> : public CommandCallback {
|
||||
};
|
||||
|
||||
template <class ResponseType>
|
||||
boost::shared_ptr<CommandCallback> MakeCommandCallback(const typename BoostFunctionCallback<ResponseType>::Fn &func) {
|
||||
boost::shared_ptr<CommandCallback> cb(new BoostFunctionCallback<ResponseType>(func));
|
||||
std::shared_ptr<CommandCallback> MakeCommandCallback(const typename BoostFunctionCallback<ResponseType>::Fn &func) {
|
||||
std::shared_ptr<CommandCallback> cb(new BoostFunctionCallback<ResponseType>(func));
|
||||
return cb;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,14 +23,13 @@
|
||||
//
|
||||
|
||||
#include "io_loop.h"
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/thread/lock_guard.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
#include "logging.h"
|
||||
|
||||
using boost::lock_guard;
|
||||
using boost::mutex;
|
||||
using std::lock_guard;
|
||||
using std::mutex;
|
||||
using std::vector;
|
||||
|
||||
namespace livox {
|
||||
@@ -40,13 +39,8 @@ bool IOLoop::Init() {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
apr_status_t rv =
|
||||
apr_pollset_create(&pollset_, kMaxPollCount, mem_pool_, APR_POLLSET_WAKEABLE);
|
||||
#else
|
||||
apr_status_t rv =
|
||||
apr_pollset_create(&pollset_, kMaxPollCount, mem_pool_, APR_POLLSET_THREADSAFE | APR_POLLSET_WAKEABLE);
|
||||
#endif
|
||||
|
||||
if (rv != APR_SUCCESS) {
|
||||
LOG_ERROR(PrintAPRStatus(rv));
|
||||
@@ -74,11 +68,11 @@ void IOLoop::Uninit() {
|
||||
}
|
||||
|
||||
void IOLoop::AddDelegate(apr_socket_t *sock, IOLoop::IOLoopDelegate *delegate, void *data) {
|
||||
PostTask(boost::bind(&IOLoop::AddDelegateAsync, this, sock, delegate, data));
|
||||
PostTask(std::bind(&IOLoop::AddDelegateAsync, this, sock, delegate, data));
|
||||
}
|
||||
|
||||
void IOLoop::RemoveDelegate(apr_socket_t *sock, IOLoopDelegate *) {
|
||||
PostTask(boost::bind(&IOLoop::RemoveDelegateAsync, this, sock));
|
||||
PostTask(std::bind(&IOLoop::RemoveDelegateAsync, this, sock));
|
||||
}
|
||||
|
||||
void IOLoop::RemoveDelegateSync(apr_socket_t *sock) {
|
||||
@@ -97,7 +91,7 @@ void IOLoop::Loop() {
|
||||
if (data) {
|
||||
IOLoopDelegate *delegate = data->first;
|
||||
if (delegate) {
|
||||
delegate->OnData(ret_pfd->desc.s, data->second);
|
||||
delegate->OnData(ret_pfd[i].desc.s, data->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
#ifndef LIVOX_IO_LOOP_H_
|
||||
#define LIVOX_IO_LOOP_H_
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "apr_general.h"
|
||||
@@ -50,7 +50,7 @@ class IOLoop : public noncopyable {
|
||||
virtual void OnWake() {}
|
||||
};
|
||||
|
||||
typedef boost::function<void(void)> IOLoopTask;
|
||||
typedef std::function<void(void)> IOLoopTask;
|
||||
|
||||
public:
|
||||
explicit IOLoop(apr_pool_t *mem_pool, bool enable_timer = true, bool enable_wake = true)
|
||||
@@ -74,12 +74,12 @@ class IOLoop : public noncopyable {
|
||||
private:
|
||||
static const apr_uint32_t kMaxPollCount = 48;
|
||||
typedef std::pair<IOLoopDelegate *, void *> ClientData;
|
||||
typedef boost::unordered_map<apr_socket_t *, ClientData *> DelegatesType;
|
||||
typedef std::unordered_map<apr_socket_t *, ClientData *> DelegatesType;
|
||||
DelegatesType delegates_;
|
||||
apr_pollset_t *pollset_;
|
||||
apr_pool_t *mem_pool_;
|
||||
apr_time_t last_timeout_;
|
||||
boost::mutex mutex_;
|
||||
std::mutex mutex_;
|
||||
bool enable_timer_;
|
||||
bool enable_wake_;
|
||||
std::vector<IOLoopTask> pending_tasks_;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#ifndef LIVOX_IO_THREAD_H_
|
||||
#define LIVOX_IO_THREAD_H_
|
||||
#include <boost/smart_ptr.hpp>
|
||||
#include <memory>
|
||||
#include "io_loop.h"
|
||||
#include "thread_base.h"
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace livox {
|
||||
|
||||
class IOThread : public ThreadBase {
|
||||
public:
|
||||
IOThread() : loop_(NULL) {}
|
||||
IOThread() : loop_(nullptr) {}
|
||||
bool Init(bool enable_timer = true, bool enable_wake = true);
|
||||
void Join();
|
||||
void Uninit();
|
||||
@@ -41,7 +41,7 @@ class IOThread : public ThreadBase {
|
||||
void ThreadFunc();
|
||||
|
||||
private:
|
||||
boost::scoped_ptr<IOLoop> loop_;
|
||||
std::unique_ptr<IOLoop> loop_;
|
||||
};
|
||||
} // namespace livox
|
||||
#endif // LIVOX_IO_THREAD_H_
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
std::shared_ptr<spdlog::logger> logger = NULL;
|
||||
bool is_save_log_file = false;
|
||||
bool is_console_log_enable = true;
|
||||
|
||||
void InitLogger() {
|
||||
|
||||
@@ -35,9 +36,11 @@ void InitLogger() {
|
||||
}
|
||||
|
||||
std::vector<spdlog::sink_ptr> sinkList;
|
||||
auto consoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||
consoleSink->set_level(spdlog::level::debug);
|
||||
sinkList.push_back(consoleSink);
|
||||
if (is_console_log_enable) {
|
||||
auto consoleSink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||
consoleSink->set_level(spdlog::level::debug);
|
||||
sinkList.push_back(consoleSink);
|
||||
}
|
||||
|
||||
if (is_save_log_file) {
|
||||
auto rotateSink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("livox_log.txt", 1024 * 1024 * 5, 2);
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
|
||||
extern std::shared_ptr<spdlog::logger> logger;
|
||||
extern bool is_save_log_file;
|
||||
extern bool is_console_log_enable;
|
||||
|
||||
void InitLogger();
|
||||
void UninitLogger();
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "network_util.h"
|
||||
#ifdef WIN32
|
||||
#include <boost/scoped_array.hpp>
|
||||
#include <memory>
|
||||
#include <Winsock2.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <string>
|
||||
@@ -101,7 +101,7 @@ bool GetAdapterState(const IP_ADAPTER_INFO *pAdapter)
|
||||
bool FindLocalIp(const struct sockaddr_in &client_addr, uint32_t &local_ip) {
|
||||
bool found = false;
|
||||
ULONG ulOutbufLen = sizeof(IP_ADAPTER_INFO);
|
||||
boost::scoped_array<uint8_t> pAdapterInfo(new uint8_t[ulOutbufLen]);
|
||||
std::unique_ptr<uint8_t[]> pAdapterInfo(new uint8_t[ulOutbufLen]);
|
||||
DWORD dlRetVal = GetAdaptersInfo(reinterpret_cast<IP_ADAPTER_INFO *>(pAdapterInfo.get()), &ulOutbufLen);
|
||||
if (dlRetVal == ERROR_BUFFER_OVERFLOW) {
|
||||
pAdapterInfo.reset(new uint8_t[ulOutbufLen]);
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <apr_general.h>
|
||||
#include <apr_thread_proc.h>
|
||||
#include <apr_portable.h>
|
||||
#include <boost/atomic/atomic.hpp>
|
||||
#include <atomic>
|
||||
#include "noncopyable.h"
|
||||
|
||||
namespace livox {
|
||||
@@ -46,7 +46,7 @@ class ThreadBase : public noncopyable {
|
||||
|
||||
protected:
|
||||
apr_thread_t *thread_;
|
||||
boost::atomic_bool quit_;
|
||||
std::atomic_bool quit_;
|
||||
apr_pool_t *pool_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user