Skip to content

Commit

Permalink
Merge pull request #179 from zd-double/no-boost
Browse files Browse the repository at this point in the history
Update smart_ptr
  • Loading branch information
zd-double authored Jan 18, 2017
2 parents f9877d6 + 09effe7 commit d601229
Show file tree
Hide file tree
Showing 40 changed files with 104 additions and 102 deletions.
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,10 @@ build: $(LIB) $(BIN)
install: $(LIB) $(BIN)
mkdir -p $(PREFIX)/include/sofa/pbrpc
cp -r $(PUB_INC) $(TARGET_DIRECTORY) $(PREFIX)/include/sofa/pbrpc/
mkdir -p $(PREFIX)/include/sofa/pbrpc/boost/smart_ptr
cp src/sofa/pbrpc/boost/smart_ptr/*.hpp $(PREFIX)/include/sofa/pbrpc/boost/smart_ptr
mkdir -p $(PREFIX)/include/sofa/pbrpc/boost/smart_ptr/detail
cp src/sofa/pbrpc/boost/smart_ptr/detail/*.hpp $(PREFIX)/include/sofa/pbrpc/boost/smart_ptr/detail
cp src/sofa/pbrpc/boost/smart_ptr.hpp $(PREFIX)/include/sofa/pbrpc/boost
mkdir -p $(PREFIX)/include/sofa/pbrpc/smart_ptr
cp src/sofa/pbrpc/smart_ptr/*.hpp $(PREFIX)/include/sofa/pbrpc/smart_ptr
mkdir -p $(PREFIX)/include/sofa/pbrpc/smart_ptr/detail
cp src/sofa/pbrpc/smart_ptr/detail/*.hpp $(PREFIX)/include/sofa/pbrpc/smart_ptr/detail
mkdir -p $(PREFIX)/lib
cp $(LIB) $(PREFIX)/lib/
mkdir -p $(PREFIX)/bin
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ For more details, please refer to the wiki [Build Guide](https://github.com/baid
### Sample
For sample code, please refer to ['./sample'](https://github.com/baidu/sofa-pbrpc/tree/master/sample) and the wiki [Quick Start](https://github.com/baidu/sofa-pbrpc/wiki/%E5%BF%AB%E9%80%9F%E4%BD%BF%E7%94%A8).

### Profiling
For Profiling feature, please refer to the wiki [Profiling](https://github.com/baidu/sofa-pbrpc/wiki/Profiling%E5%8A%9F%E8%83%BD).

### Performance
For performace details, please refer to the wiki [Performance](https://github.com/baidu/sofa-pbrpc/wiki/%E6%80%A7%E8%83%BD).

Expand Down
4 changes: 2 additions & 2 deletions src/sofa/pbrpc/binary_rpc_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void BinaryRpcRequest::ProcessRequest(
}
else
{
sofa::pbrpc::boost::scoped_ptr<AbstractCompressedInputStream> is(
sofa::pbrpc::scoped_ptr<AbstractCompressedInputStream> is(
get_compressed_input_stream(_req_body.get(), compress_type));
parse_request_return = request->ParseFromZeroCopyStream(is.get());
}
Expand Down Expand Up @@ -157,7 +157,7 @@ ReadBufferPtr BinaryRpcRequest::AssembleSucceedResponse(
}
else
{
sofa::pbrpc::boost::scoped_ptr<AbstractCompressedOutputStream> os(
sofa::pbrpc::scoped_ptr<AbstractCompressedOutputStream> os(
get_compressed_output_stream(&write_buffer, meta.compress_type()));
ser_ret = response->SerializeToZeroCopyStream(os.get());
os->Flush();
Expand Down
2 changes: 1 addition & 1 deletion src/sofa/pbrpc/binary_rpc_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace pbrpc {
class BinaryRpcRequestParser;

class BinaryRpcRequest;
typedef sofa::pbrpc::boost::shared_ptr<BinaryRpcRequest> BinaryRpcRequestPtr;
typedef sofa::pbrpc::shared_ptr<BinaryRpcRequest> BinaryRpcRequestPtr;

class BinaryRpcRequest : public RpcRequest
{
Expand Down
4 changes: 2 additions & 2 deletions src/sofa/pbrpc/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace pbrpc {

// Defined in this file.
class ReadBuffer;
typedef sofa::pbrpc::boost::shared_ptr<ReadBuffer> ReadBufferPtr;
typedef sofa::pbrpc::shared_ptr<ReadBuffer> ReadBufferPtr;
class WriteBuffer;
typedef sofa::pbrpc::boost::shared_ptr<WriteBuffer> WriteBufferPtr;
typedef sofa::pbrpc::shared_ptr<WriteBuffer> WriteBufferPtr;

typedef std::deque<BufHandle> BufHandleList;
typedef std::deque<BufHandle>::iterator BufHandleListIterator;
Expand Down
6 changes: 3 additions & 3 deletions src/sofa/pbrpc/closure.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// 3, Support pass argument by reference, though bind
// always by value.
// 4, When bind class method, support use
// "sofa::pbrpc::boost::shared_ptr" as this pointer of class.
// "sofa::pbrpc::shared_ptr" as this pointer of class.
// 5, Support create temporary and permanent closure:
// Temporary closure (self destoryed after call):
// NewClosure();
Expand All @@ -47,7 +47,7 @@
// Closure* c3 = NewClosure(&obj, &ClassA::m1, 1, 2.0);
// c3->Run();
//
// class ClassB : public sofa::pbrpc::boost::enable_shared_from_this<ClassB>
// class ClassB : public sofa::pbrpc::enable_shared_from_this<ClassB>
// {
// public:
// int m1(int pre_arg, double post_arg);
Expand All @@ -58,7 +58,7 @@
// c4->Run(2.0);
// }
// };
// sofa::pbrpc::boost::shared_ptr<ClassB> ptr(new ClassB);
// sofa::pbrpc::shared_ptr<ClassB> ptr(new ClassB);
// Closure* c5 = NewClosure(ptr, &ClassB::m1, 1, 2.0);
// c5->Run();
//
Expand Down
6 changes: 3 additions & 3 deletions src/sofa/pbrpc/closure_gen.pl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ()
print "// 3, Support pass argument by reference, though bind\n";
print "// always by value.\n";
print "// 4, When bind class method, support use\n";
print "// \"sofa::pbrpc::boost::shared_ptr\" as this pointer of class.\n";
print "// \"sofa::pbrpc::shared_ptr\" as this pointer of class.\n";
print "// 5, Support create temporary and permanent closure:\n";
print "// Temporary closure (self destoryed after call):\n";
print "// NewClosure();\n";
Expand All @@ -58,7 +58,7 @@ ()
print "// Closure* c3 = NewClosure(&obj, &ClassA::m1, 1, 2.0);\n";
print "// c3->Run();\n";
print "// \n";
print "// class ClassB : public sofa::pbrpc::boost::enable_shared_from_this<ClassB>\n";
print "// class ClassB : public sofa::pbrpc::enable_shared_from_this<ClassB>\n";
print "// {\n";
print "// public:\n";
print "// int m1(int pre_arg, double post_arg);\n";
Expand All @@ -69,7 +69,7 @@ ()
print "// c4->Run(2.0);\n";
print "// }\n";
print "// };\n";
print "// sofa::pbrpc::boost::shared_ptr<ClassB> ptr(new ClassB);\n";
print "// sofa::pbrpc::shared_ptr<ClassB> ptr(new ClassB);\n";
print "// Closure* c5 = NewClosure(ptr, &ClassB::m1, 1, 2.0);\n";
print "// c5->Run();\n";
print "// \n";
Expand Down
2 changes: 1 addition & 1 deletion src/sofa/pbrpc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdarg.h>
#include <google/protobuf/stubs/common.h>

#include <sofa/pbrpc/boost/smart_ptr.hpp>
#include <sofa/pbrpc/smart_ptr/smart_ptr.hpp>

namespace std {}

Expand Down
40 changes: 20 additions & 20 deletions src/sofa/pbrpc/common_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,54 @@ namespace sofa {
namespace pbrpc {

class RpcControllerImpl;
typedef sofa::pbrpc::boost::shared_ptr<RpcControllerImpl> RpcControllerImplPtr;
typedef sofa::pbrpc::boost::weak_ptr<RpcControllerImpl> RpcControllerImplWPtr;
typedef sofa::pbrpc::shared_ptr<RpcControllerImpl> RpcControllerImplPtr;
typedef sofa::pbrpc::weak_ptr<RpcControllerImpl> RpcControllerImplWPtr;

class RpcChannelImpl;
typedef sofa::pbrpc::boost::shared_ptr<RpcChannelImpl> RpcChannelImplPtr;
typedef sofa::pbrpc::shared_ptr<RpcChannelImpl> RpcChannelImplPtr;

class RpcClientImpl;
typedef sofa::pbrpc::boost::shared_ptr<RpcClientImpl> RpcClientImplPtr;
typedef sofa::pbrpc::shared_ptr<RpcClientImpl> RpcClientImplPtr;

class RpcServerImpl;
typedef sofa::pbrpc::boost::shared_ptr<RpcServerImpl> RpcServerImplPtr;
typedef sofa::pbrpc::boost::weak_ptr<RpcServerImpl> RpcServerImplWPtr;
typedef sofa::pbrpc::shared_ptr<RpcServerImpl> RpcServerImplPtr;
typedef sofa::pbrpc::weak_ptr<RpcServerImpl> RpcServerImplWPtr;

class RpcClientStream;
typedef sofa::pbrpc::boost::shared_ptr<RpcClientStream> RpcClientStreamPtr;
typedef sofa::pbrpc::boost::weak_ptr<RpcClientStream> RpcClientStreamWPtr;
typedef sofa::pbrpc::shared_ptr<RpcClientStream> RpcClientStreamPtr;
typedef sofa::pbrpc::weak_ptr<RpcClientStream> RpcClientStreamWPtr;

class RpcServerStream;
typedef sofa::pbrpc::boost::shared_ptr<RpcServerStream> RpcServerStreamPtr;
typedef sofa::pbrpc::boost::weak_ptr<RpcServerStream> RpcServerStreamWPtr;
typedef sofa::pbrpc::shared_ptr<RpcServerStream> RpcServerStreamPtr;
typedef sofa::pbrpc::weak_ptr<RpcServerStream> RpcServerStreamWPtr;

class RpcListener;
typedef sofa::pbrpc::boost::shared_ptr<RpcListener> RpcListenerPtr;
typedef sofa::pbrpc::shared_ptr<RpcListener> RpcListenerPtr;

class TimerWorker;
typedef sofa::pbrpc::boost::shared_ptr<TimerWorker> TimerWorkerPtr;
typedef sofa::pbrpc::shared_ptr<TimerWorker> TimerWorkerPtr;

class RpcTimeoutManager;
typedef sofa::pbrpc::boost::shared_ptr<RpcTimeoutManager> RpcTimeoutManagerPtr;
typedef sofa::pbrpc::shared_ptr<RpcTimeoutManager> RpcTimeoutManagerPtr;

class ThreadGroup;
typedef sofa::pbrpc::boost::shared_ptr<ThreadGroup> ThreadGroupPtr;
typedef sofa::pbrpc::shared_ptr<ThreadGroup> ThreadGroupPtr;

class ServicePool;
typedef sofa::pbrpc::boost::shared_ptr<ServicePool> ServicePoolPtr;
typedef sofa::pbrpc::boost::weak_ptr<ServicePool> ServicePoolWPtr;
typedef sofa::pbrpc::shared_ptr<ServicePool> ServicePoolPtr;
typedef sofa::pbrpc::weak_ptr<ServicePool> ServicePoolWPtr;

class FlowController;
typedef sofa::pbrpc::boost::shared_ptr<FlowController> FlowControllerPtr;
typedef sofa::pbrpc::shared_ptr<FlowController> FlowControllerPtr;

class WaitEvent;
typedef sofa::pbrpc::boost::shared_ptr<WaitEvent> WaitEventPtr;
typedef sofa::pbrpc::shared_ptr<WaitEvent> WaitEventPtr;

class IOServicePool;
typedef sofa::pbrpc::boost::shared_ptr<IOServicePool> IOServicePoolPtr;
typedef sofa::pbrpc::shared_ptr<IOServicePool> IOServicePoolPtr;

class WebService;
typedef sofa::pbrpc::boost::shared_ptr<WebService> WebServicePtr;
typedef sofa::pbrpc::shared_ptr<WebService> WebServicePtr;

#define SOFA_PBRPC_DECLARE_RESOURCE_COUNTER(name_) \
extern sofa::pbrpc::AtomicCounter g_sofa_counter_##name_
Expand Down
8 changes: 4 additions & 4 deletions src/sofa/pbrpc/dynamic_rpc_channel_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ namespace pbrpc {
class EventHandlerImp : public RpcChannel::EventHandler
{
public:
EventHandlerImp(::sofa::pbrpc::boost::weak_ptr<DynamicRpcChannelImpl> channel) : _channel(channel) {}
EventHandlerImp(::sofa::pbrpc::weak_ptr<DynamicRpcChannelImpl> channel) : _channel(channel) {}
virtual ~EventHandlerImp() {}
virtual void OnAddressAdded(const std::vector<std::string>& address_list)
{
::sofa::pbrpc::boost::shared_ptr<DynamicRpcChannelImpl> channel = _channel.lock();
::sofa::pbrpc::shared_ptr<DynamicRpcChannelImpl> channel = _channel.lock();
if (channel) {
channel->OnAddressAdded(address_list);
}
}
virtual void OnAddressRemoved(const std::vector<std::string>& address_list)
{
::sofa::pbrpc::boost::shared_ptr<DynamicRpcChannelImpl> channel = _channel.lock();
::sofa::pbrpc::shared_ptr<DynamicRpcChannelImpl> channel = _channel.lock();
if (channel) {
channel->OnAddressRemoved(address_list);
}
}
private:
::sofa::pbrpc::boost::weak_ptr<DynamicRpcChannelImpl> _channel;
::sofa::pbrpc::weak_ptr<DynamicRpcChannelImpl> _channel;
};

DynamicRpcChannelImpl::DynamicRpcChannelImpl(
Expand Down
10 changes: 5 additions & 5 deletions src/sofa/pbrpc/dynamic_rpc_channel_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#include <sofa/pbrpc/timeout_manager.h>
#include <sofa/pbrpc/counter.h>
#include <sofa/pbrpc/builtin_service.pb.h>
#include <sofa/pbrpc/boost/enable_shared_from_this.hpp>
#include <sofa/pbrpc/smart_ptr/enable_shared_from_this.hpp>

namespace sofa {
namespace pbrpc {

class DynamicRpcChannelImpl : public RpcChannelImpl,
public ::sofa::pbrpc::boost::enable_shared_from_this<DynamicRpcChannelImpl>
public ::sofa::pbrpc::enable_shared_from_this<DynamicRpcChannelImpl>
{
public:
// Detect timeout, 3 second.
Expand All @@ -46,18 +46,18 @@ class DynamicRpcChannelImpl : public RpcChannelImpl,
volatile bool is_removed; // if this address is already removed.
volatile bool is_channel_inited; // if the channel is already inited.
LockType channel_init_lock;
::sofa::pbrpc::boost::shared_ptr<SimpleRpcChannelImpl> channel;
::sofa::pbrpc::shared_ptr<SimpleRpcChannelImpl> channel;
volatile bool is_builtin_service_inited; // if the builtin service is already inited.
LockType builtin_service_init_lock;
::sofa::pbrpc::boost::scoped_ptr<builtin::BuiltinService_Stub> builtin_service;
::sofa::pbrpc::scoped_ptr<builtin::BuiltinService_Stub> builtin_service;
uint64 last_request_seq; // the last request sequence number sent by this channel.

ServerContext(const std::string& server_address_);
~ServerContext();
bool InitChannel(const RpcClientImplPtr& client_impl, const RpcChannelOptions& options);
bool InitBuiltinService(const RpcChannelOptions& options);
};
typedef ::sofa::pbrpc::boost::shared_ptr<ServerContext> ServerContextPtr;
typedef ::sofa::pbrpc::shared_ptr<ServerContext> ServerContextPtr;
typedef std::map<std::string, ServerContextPtr> ServerContextMap;

struct AddResult {
Expand Down
4 changes: 2 additions & 2 deletions src/sofa/pbrpc/ext_closure.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 2, Support pass argument by reference, though bind
// always by value.
// 3, When bind class method, support use
// "sofa::pbrpc::boost::shared_ptr" as this pointer of class.
// "sofa::pbrpc::shared_ptr" as this pointer of class.
// 4, Support create temporary and permanent closure:
// Temporary closure (self destoryed after call):
// NewExtClosure();
Expand Down Expand Up @@ -50,7 +50,7 @@
// ExtClosure<int(double)>* c4 = NewPermanentExtClosure(&obj, &C1::m1, 1);
// c4->Run(2.0);
//
// class C2 : public sofa::pbrpc::boost::enable_shared_from_this<C2>
// class C2 : public sofa::pbrpc::enable_shared_from_this<C2>
// {
// public:
// int m1(int pre_arg, double post_arg);
Expand Down
4 changes: 2 additions & 2 deletions src/sofa/pbrpc/ext_closure_gen.pl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ()
print "// 2, Support pass argument by reference, though bind\n";
print "// always by value.\n";
print "// 3, When bind class method, support use\n";
print "// \"sofa::pbrpc::boost::shared_ptr\" as this pointer of class.\n";
print "// \"sofa::pbrpc::shared_ptr\" as this pointer of class.\n";
print "// 4, Support create temporary and permanent closure:\n";
print "// Temporary closure (self destoryed after call):\n";
print "// NewExtClosure();\n";
Expand Down Expand Up @@ -62,7 +62,7 @@ ()
print "// ExtClosure<int(double)>* c4 = NewPermanentExtClosure(&obj, &C1::m1, 1);\n";
print "// c4->Run(2.0);\n";
print "// \n";
print "// class C2 : public sofa::pbrpc::boost::enable_shared_from_this<C2>\n";
print "// class C2 : public sofa::pbrpc::enable_shared_from_this<C2>\n";
print "// {\n";
print "// public:\n";
print "// int m1(int pre_arg, double post_arg);\n";
Expand Down
2 changes: 1 addition & 1 deletion src/sofa/pbrpc/http-agent/http_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class HttpAgent
::google::protobuf::Closure* done);

private:
static void CallMethodDone(const sofa::pbrpc::boost::shared_ptr<RpcControllerImpl>& cntl,
static void CallMethodDone(const sofa::pbrpc::shared_ptr<RpcControllerImpl>& cntl,
std::string* response,
::google::protobuf::Message* request_message,
::google::protobuf::Message* response_message,
Expand Down
2 changes: 1 addition & 1 deletion src/sofa/pbrpc/http_rpc_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace pbrpc {
class HTTPRpcRequestParser;

class HTTPRpcRequest;
typedef sofa::pbrpc::boost::shared_ptr<HTTPRpcRequest> HTTPRpcRequestPtr;
typedef sofa::pbrpc::shared_ptr<HTTPRpcRequest> HTTPRpcRequestPtr;

struct HTTPResponse;

Expand Down
8 changes: 4 additions & 4 deletions src/sofa/pbrpc/io_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ namespace sofa {
namespace pbrpc {

typedef sofa::pbrpc::boost::asio::io_service IOService;
typedef sofa::pbrpc::boost::shared_ptr<IOService> IOServicePtr;
typedef sofa::pbrpc::shared_ptr<IOService> IOServicePtr;

typedef sofa::pbrpc::boost::asio::io_service::work IOServiceWork;
typedef sofa::pbrpc::boost::shared_ptr<IOServiceWork> IOServiceWorkPtr;
typedef sofa::pbrpc::shared_ptr<IOServiceWork> IOServiceWorkPtr;

typedef sofa::pbrpc::boost::asio::io_service::strand IOServiceStrand;
typedef sofa::pbrpc::boost::shared_ptr<IOServiceStrand> IOServiceStrandPtr;
typedef sofa::pbrpc::shared_ptr<IOServiceStrand> IOServiceStrandPtr;

typedef sofa::pbrpc::boost::asio::deadline_timer IOServiceTimer;
typedef sofa::pbrpc::boost::shared_ptr<IOServiceTimer> IOServiceTimerPtr;
typedef sofa::pbrpc::shared_ptr<IOServiceTimer> IOServiceTimerPtr;

} // namespace pbrpc
} // namespace sofa
Expand Down
2 changes: 1 addition & 1 deletion src/sofa/pbrpc/rpc_byte_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace pbrpc {
using sofa::pbrpc::boost::asio::ip::tcp;
using namespace sofa::pbrpc::boost::asio;

class RpcByteStream : public sofa::pbrpc::boost::enable_shared_from_this<RpcByteStream>
class RpcByteStream : public sofa::pbrpc::enable_shared_from_this<RpcByteStream>
{
public:
RpcByteStream(IOService& io_service, const RpcEndpoint& endpoint)
Expand Down
4 changes: 2 additions & 2 deletions src/sofa/pbrpc/rpc_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ class RpcChannel : public google::protobuf::RpcChannel
::google::protobuf::Closure* done);

public:
const sofa::pbrpc::boost::shared_ptr<RpcChannelImpl>& impl() const
const sofa::pbrpc::shared_ptr<RpcChannelImpl>& impl() const
{
return _impl;
}

private:
sofa::pbrpc::boost::shared_ptr<RpcChannelImpl> _impl;
sofa::pbrpc::shared_ptr<RpcChannelImpl> _impl;

SOFA_PBRPC_DISALLOW_EVIL_CONSTRUCTORS(RpcChannel);
}; // class RpcChannel
Expand Down
4 changes: 2 additions & 2 deletions src/sofa/pbrpc/rpc_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ class RpcClient
void Shutdown();

public:
const sofa::pbrpc::boost::shared_ptr<RpcClientImpl>& impl() const
const sofa::pbrpc::shared_ptr<RpcClientImpl>& impl() const
{
return _impl;
}

private:
sofa::pbrpc::boost::shared_ptr<RpcClientImpl> _impl;
sofa::pbrpc::shared_ptr<RpcClientImpl> _impl;

SOFA_PBRPC_DISALLOW_EVIL_CONSTRUCTORS(RpcClient);
}; // class RpcClient
Expand Down
Loading

0 comments on commit d601229

Please sign in to comment.