Bläddra i källkod

将windows换行符转换成unix换行符

Tang Hai 14 år sedan
förälder
incheckning
e829d671df

+ 24 - 24
Src/Egametang/Base/Typedef.h

@@ -1,24 +1,24 @@
-#ifndef BASE_TYPEDEFS_H
-#define BASE_TYPEDEFS_H
-#include <boost/cstdint.hpp>
-#include <boost/shared_ptr.hpp>
-
-namespace Egametang {
-
-typedef boost::int8_t   int8;
-typedef boost::int16_t  int16;
-typedef boost::int32_t  int32;
-typedef boost::int64_t  int64;
-typedef boost::uint8_t  uint8;
-typedef boost::uint16_t uint16;
-typedef boost::uint32_t uint32;
-typedef boost::uint64_t uint64;
-
-// smart_ptr typedef
-
-typedef boost::shared_ptr<int> IntPtr;
-typedef boost::shared_ptr<std::string> StringPtr;
-
-} // namespace Egametang
-
-#endif // BASE_TYPEDEFS_H
+#ifndef BASE_TYPEDEFS_H
+#define BASE_TYPEDEFS_H
+#include <boost/cstdint.hpp>
+#include <boost/shared_ptr.hpp>
+
+namespace Egametang {
+
+typedef boost::int8_t   int8;
+typedef boost::int16_t  int16;
+typedef boost::int32_t  int32;
+typedef boost::int64_t  int64;
+typedef boost::uint8_t  uint8;
+typedef boost::uint16_t uint16;
+typedef boost::uint32_t uint32;
+typedef boost::uint64_t uint64;
+
+// smart_ptr typedef
+
+typedef boost::shared_ptr<int> IntPtr;
+typedef boost::shared_ptr<std::string> StringPtr;
+
+} // namespace Egametang
+
+#endif // BASE_TYPEDEFS_H

+ 30 - 30
Src/Egametang/Python/PythonInit.h

@@ -1,30 +1,30 @@
-#ifndef PYTHON_PYTHON_INIT_H
-#define PYTHON_PYTHON_INIT_H
-
-#include <boost/noncopyable.hpp>
-#include <boost/python.hpp>
-
-namespace Egametang {
-
-class PythonInit: private boost::noncopyable
-{
-public:
-	PythonInit()
-	{
-		Py_InitializeEx(0);
-	}
-
-	~PythonInit()
-	{
-		Py_Finalize();
-	}
-
-	bool IsInitialized()
-	{
-		return Py_IsInitialized();
-	}
-};
-
-} // namespace Egametang
-
-#endif // PYTHON_PYTHON_INIT_H
+#ifndef PYTHON_PYTHON_INIT_H
+#define PYTHON_PYTHON_INIT_H
+
+#include <boost/noncopyable.hpp>
+#include <boost/python.hpp>
+
+namespace Egametang {
+
+class PythonInit: private boost::noncopyable
+{
+public:
+	PythonInit()
+	{
+		Py_InitializeEx(0);
+	}
+
+	~PythonInit()
+	{
+		Py_Finalize();
+	}
+
+	bool IsInitialized()
+	{
+		return Py_IsInitialized();
+	}
+};
+
+} // namespace Egametang
+
+#endif // PYTHON_PYTHON_INIT_H

+ 41 - 41
Src/Egametang/Python/PythonInitTest.cc

@@ -1,41 +1,41 @@
-#include <gtest/gtest.h>
-#include <gflags/gflags.h>
-#include <glog/logging.h>
-#include "Python/PythonInit.h"
-
-namespace Egametang {
-
-class PythonInitTest: public testing::Test
-{
-public:
-	PythonInitTest(): python_init()
-	{}
-
-protected:
-	PythonInit python_init;
-};
-
-TEST_F(PythonInitTest, Int)
-{
-	boost::python::object i(10);
-	i = 10 * i;
-	ASSERT_EQ(100, boost::python::extract<int>(i));
-}
-
-TEST_F(PythonInitTest, String)
-{
-	boost::python::object i("ab");
-	std::string str = boost::python::extract<std::string>(i * 5);
-	ASSERT_EQ("ababababab", str);
-}
-
-} // namespace Egametang
-
-int main(int argc, char* argv[])
-{
-	FLAGS_logtostderr = true;
-	testing::InitGoogleTest(&argc, argv);
-	google::ParseCommandLineFlags(&argc, &argv, true);
-	google::InitGoogleLogging(argv[0]);
-	return RUN_ALL_TESTS();
-}
+#include <gtest/gtest.h>
+#include <gflags/gflags.h>
+#include <glog/logging.h>
+#include "Python/PythonInit.h"
+
+namespace Egametang {
+
+class PythonInitTest: public testing::Test
+{
+public:
+	PythonInitTest(): python_init()
+	{}
+
+protected:
+	PythonInit python_init;
+};
+
+TEST_F(PythonInitTest, Int)
+{
+	boost::python::object i(10);
+	i = 10 * i;
+	ASSERT_EQ(100, boost::python::extract<int>(i));
+}
+
+TEST_F(PythonInitTest, String)
+{
+	boost::python::object i("ab");
+	std::string str = boost::python::extract<std::string>(i * 5);
+	ASSERT_EQ("ababababab", str);
+}
+
+} // namespace Egametang
+
+int main(int argc, char* argv[])
+{
+	FLAGS_logtostderr = true;
+	testing::InitGoogleTest(&argc, argv);
+	google::ParseCommandLineFlags(&argc, &argv, true);
+	google::InitGoogleLogging(argv[0]);
+	return RUN_ALL_TESTS();
+}

+ 130 - 130
Src/Egametang/Rpc/RpcChannel.cc

@@ -1,130 +1,130 @@
-#include <boost/asio.hpp>
-#include <boost/make_shared.hpp>
-#include <google/protobuf/message.h>
-#include "Rpc/RpcChannel.h"
-
-namespace Egametang {
-
-RpcChannel::RpcChannel(
-		boost::asio::io_service& io_service, std::string& host, int port):
-		io_service_(io_service)
-{
-	// another thread?
-	boost::asio::ip::address address;
-	address.from_string(host);
-	boost::asio::ip::tcp::endpoint endpoint(address, port);
-	socket_.async_connect(endpoint,
-			boost::bind(&RpcChannel::AsyncConnectHandler, this,
-					boost::asio::placeholders::error));
-}
-
-void RpcChannel::AsyncConnectHandler(const boost::system::error_code& err)
-{
-	if (err)
-	{
-		LOG(ERROR) << "async connect failed";
-		return;
-	}
-	RecvMessegeSize();
-}
-
-void RpcChannel::RecvMessegeSize()
-{
-	IntPtr size(new int);
-	boost::asio::async_read(socket_,
-			boost::asio::buffer(
-					reinterpret_cast<char*>(size.get()), sizeof(int)),
-			boost::bind(&RpcChannel::RecvMessage, this, size,
-					boost::asio::placeholders::error));
-}
-
-void RpcChannel::RecvMessage(IntPtr size, const boost::system::error_code& err)
-{
-	if (err)
-	{
-		LOG(ERROR) << "receive response size failed";
-		return;
-	}
-	StringPtr ss;
-	boost::asio::async_read(socket_,
-			boost::asio::buffer(*ss, *size),
-			boost::bind(&RpcChannel::RecvMessageHandler, this, ss,
-					boost::asio::placeholders::error));
-}
-
-void RpcChannel::RecvMessageHandler(
-		StringPtr ss, const boost::system::error_code& err)
-{
-	if (err)
-	{
-		LOG(ERROR) << "receive response failed";
-		return;
-	}
-
-	RpcResponse response;
-	Response->ParseFromString(*ss);
-	RpcHandlerPtr handler = handlers_[response.id()];
-	handler->GetResponse()->ParseFromString(response.response());
-
-	if (handler->done_ != NULL)
-	{
-		handler->done_->Run();
-	}
-
-	handlers_.erase(response.id());
-
-	// read size
-	RecvMessegeSize();
-}
-
-void RpcChannel::SendMessageHandler(int32 id, RpcHandlerPtr handler,
-		const boost::system::error_code& err)
-{
-	if (err)
-	{
-		LOG(ERROR) << "SendMessage error:";
-		return;
-	}
-	handlers_[id] = handler;
-}
-
-void RpcChannel::SendMessage(const RpcRequestPtr request,
-		RpcHandlerPtr handler, const boost::system::error_code& err)
-{
-	if (err)
-	{
-		LOG(ERROR) << "SendRequestSize error:";
-		return;
-	}
-	std::string ss = request->SerializeAsString();
-	boost::asio::async_write(socket_, boost::asio::buffer(ss),
-			boost::bind(&RpcChannel::SendMessageHandler, this, request->id(),
-					handler, boost::asio::placeholders::error));
-}
-
-void RpcChannel::SendMessageSize(
-		const RpcRequestPtr request, RpcHandlerPtr handler)
-{
-	int size = request->ByteSize();
-	std::string ss = boost::lexical_cast(size);
-	boost::asio::async_write(socket_, boost::asio::buffer(ss),
-			boost::bind(&RpcChannel::SendMessage, this, request,
-					handler, boost::asio::placeholders::error));
-}
-
-void RpcChannel::CallMethod(
-		const google::protobuf::MethodDescriptor* method,
-		google::protobuf::RpcController* controller,
-		const google::protobuf::Message* request,
-		google::protobuf::Message* response,
-		google::protobuf::Closure* done)
-{
-	RpcRequestPtr req(new RpcRequest);
-	req->set_id(++id_);
-	req->set_method(method->full_name());
-	req->set_request(request->SerializeAsString());
-	RpcHandlerPtr handler(new RpcHandler(controller, response, done));
-	SendMessageSize(req, handler);
-}
-
-} // namespace Egametang
+#include <boost/asio.hpp>
+#include <boost/make_shared.hpp>
+#include <google/protobuf/message.h>
+#include "Rpc/RpcChannel.h"
+
+namespace Egametang {
+
+RpcChannel::RpcChannel(
+		boost::asio::io_service& io_service, std::string& host, int port):
+		io_service_(io_service)
+{
+	// another thread?
+	boost::asio::ip::address address;
+	address.from_string(host);
+	boost::asio::ip::tcp::endpoint endpoint(address, port);
+	socket_.async_connect(endpoint,
+			boost::bind(&RpcChannel::AsyncConnectHandler, this,
+					boost::asio::placeholders::error));
+}
+
+void RpcChannel::AsyncConnectHandler(const boost::system::error_code& err)
+{
+	if (err)
+	{
+		LOG(ERROR) << "async connect failed";
+		return;
+	}
+	RecvMessegeSize();
+}
+
+void RpcChannel::RecvMessegeSize()
+{
+	IntPtr size(new int);
+	boost::asio::async_read(socket_,
+			boost::asio::buffer(
+					reinterpret_cast<char*>(size.get()), sizeof(int)),
+			boost::bind(&RpcChannel::RecvMessage, this, size,
+					boost::asio::placeholders::error));
+}
+
+void RpcChannel::RecvMessage(IntPtr size, const boost::system::error_code& err)
+{
+	if (err)
+	{
+		LOG(ERROR) << "receive response size failed";
+		return;
+	}
+	StringPtr ss;
+	boost::asio::async_read(socket_,
+			boost::asio::buffer(*ss, *size),
+			boost::bind(&RpcChannel::RecvMessageHandler, this, ss,
+					boost::asio::placeholders::error));
+}
+
+void RpcChannel::RecvMessageHandler(
+		StringPtr ss, const boost::system::error_code& err)
+{
+	if (err)
+	{
+		LOG(ERROR) << "receive response failed";
+		return;
+	}
+
+	RpcResponse response;
+	Response->ParseFromString(*ss);
+	RpcHandlerPtr handler = handlers_[response.id()];
+	handler->GetResponse()->ParseFromString(response.response());
+
+	if (handler->done_ != NULL)
+	{
+		handler->done_->Run();
+	}
+
+	handlers_.erase(response.id());
+
+	// read size
+	RecvMessegeSize();
+}
+
+void RpcChannel::SendMessageHandler(int32 id, RpcHandlerPtr handler,
+		const boost::system::error_code& err)
+{
+	if (err)
+	{
+		LOG(ERROR) << "SendMessage error:";
+		return;
+	}
+	handlers_[id] = handler;
+}
+
+void RpcChannel::SendMessage(const RpcRequestPtr request,
+		RpcHandlerPtr handler, const boost::system::error_code& err)
+{
+	if (err)
+	{
+		LOG(ERROR) << "SendRequestSize error:";
+		return;
+	}
+	std::string ss = request->SerializeAsString();
+	boost::asio::async_write(socket_, boost::asio::buffer(ss),
+			boost::bind(&RpcChannel::SendMessageHandler, this, request->id(),
+					handler, boost::asio::placeholders::error));
+}
+
+void RpcChannel::SendMessageSize(
+		const RpcRequestPtr request, RpcHandlerPtr handler)
+{
+	int size = request->ByteSize();
+	std::string ss = boost::lexical_cast(size);
+	boost::asio::async_write(socket_, boost::asio::buffer(ss),
+			boost::bind(&RpcChannel::SendMessage, this, request,
+					handler, boost::asio::placeholders::error));
+}
+
+void RpcChannel::CallMethod(
+		const google::protobuf::MethodDescriptor* method,
+		google::protobuf::RpcController* controller,
+		const google::protobuf::Message* request,
+		google::protobuf::Message* response,
+		google::protobuf::Closure* done)
+{
+	RpcRequestPtr req(new RpcRequest);
+	req->set_id(++id_);
+	req->set_method(method->full_name());
+	req->set_request(request->SerializeAsString());
+	RpcHandlerPtr handler(new RpcHandler(controller, response, done));
+	SendMessageSize(req, handler);
+}
+
+} // namespace Egametang

+ 51 - 51
Src/Egametang/Rpc/RpcChannel.h

@@ -1,51 +1,51 @@
-#ifndef RPC_RPC_CHANNEL_H
-#define RPC_RPC_CHANNEL_H
-
-#include <google/protobuf/service.h>
-#include <boost/unordered_map.hpp>
-#include <boost/asio.hpp>
-#include "Base/Typedef.h"
-#include "Rpc/RpcTypedef.h"
-
-namespace Egametang {
-
-class RpcHandler;
-
-class RpcChannel: public google::protobuf::RpcChannel
-{
-private:
-	typedef boost::unordered_map<int32, RpcHandlerPtr> RpcCallbackMap;
-
-	int32 id_;
-	RpcCallbackMap handlers_;
-	boost::asio::io_service& io_service_;
-	boost::asio::ip::tcp::socket socket_;
-
-	void AsyncConnectHandler(const boost::system::error_code& err);
-
-	// recieve response
-	void RecvMessegeSize();
-	void RecvMessage(IntPtr size, const boost::system::error_code& err);
-	void RecvMessageHandler(StringPtr ss, const boost::system::error_code& err);
-
-	// send request
-	void SendMessageSize(const RpcRequestPtr request, RpcHandlerPtr handler);
-	void SendMessage(const RpcRequestPtr request,
-			RpcHandlerPtr handler, const boost::system::error_code& err);
-	void SendMessageHandler(int32 id, RpcHandlerPtr handler,
-			const boost::system::error_code& err);
-
-public:
-	RpcChannel(boost::asio::io_service& service, std::string& host, int port);
-	~RpcChannel();
-	virtual void CallMethod(
-			const google::protobuf::MethodDescriptor* method,
-			google::protobuf::RpcController* controller,
-			const google::protobuf::Message* request,
-			google::protobuf::Message* response,
-			google::protobuf::Closure* done);
-};
-
-} // namespace Egametang
-
-#endif // RPC_RPC_CHANNEL_H
+#ifndef RPC_RPC_CHANNEL_H
+#define RPC_RPC_CHANNEL_H
+
+#include <google/protobuf/service.h>
+#include <boost/unordered_map.hpp>
+#include <boost/asio.hpp>
+#include "Base/Typedef.h"
+#include "Rpc/RpcTypedef.h"
+
+namespace Egametang {
+
+class RpcHandler;
+
+class RpcChannel: public google::protobuf::RpcChannel
+{
+private:
+	typedef boost::unordered_map<int32, RpcHandlerPtr> RpcCallbackMap;
+
+	int32 id_;
+	RpcCallbackMap handlers_;
+	boost::asio::io_service& io_service_;
+	boost::asio::ip::tcp::socket socket_;
+
+	void AsyncConnectHandler(const boost::system::error_code& err);
+
+	// recieve response
+	void RecvMessegeSize();
+	void RecvMessage(IntPtr size, const boost::system::error_code& err);
+	void RecvMessageHandler(StringPtr ss, const boost::system::error_code& err);
+
+	// send request
+	void SendMessageSize(const RpcRequestPtr request, RpcHandlerPtr handler);
+	void SendMessage(const RpcRequestPtr request,
+			RpcHandlerPtr handler, const boost::system::error_code& err);
+	void SendMessageHandler(int32 id, RpcHandlerPtr handler,
+			const boost::system::error_code& err);
+
+public:
+	RpcChannel(boost::asio::io_service& service, std::string& host, int port);
+	~RpcChannel();
+	virtual void CallMethod(
+			const google::protobuf::MethodDescriptor* method,
+			google::protobuf::RpcController* controller,
+			const google::protobuf::Message* request,
+			google::protobuf::Message* response,
+			google::protobuf::Closure* done);
+};
+
+} // namespace Egametang
+
+#endif // RPC_RPC_CHANNEL_H

+ 72 - 72
Src/Egametang/Rpc/RpcChannelTest.cc

@@ -1,72 +1,72 @@
-#include <gtest/gtest.h>
-#include <gflags/gflags.h>
-#include <glog/logging.h>
-#include "Rpc/RpcChannel.h"
-
-namespace Egametang {
-
-static int port = 10001;
-
-class RpcServerTest
-{
-public:
-	boost::asio::io_service io_service_;
-	boost::asio::ip::tcp::acceptor acceptor_;
-	boost::asio::ip::tcp::socket socket_;
-
-	int size;
-
-public:
-	RpcServerTest(boost::asio::io_service& service, int port):
-		io_service_(service), size(0)
-	{
-		boost::asio::ip::address address;
-		address.from_string("localhost");
-		boost::asio::ip::tcp::endpoint endpoint(address, port);
-		boost::asio::ip::tcp::acceptor acceptor;
-		acceptor.open(endpoint.protocol());
-		acceptor.set_option(
-		boost::asio::ip::tcp::acceptor::reuse_address(true));
-		acceptor.bind(endpoint);
-		acceptor.listen();
-		acceptor.async_accept(socket_);
-	}
-	~RpcServerTest();
-
-	void RecvMessageSize()
-	{
-	}
-};
-
-class RpcChannelTest: public testing::Test
-{
-private:
-	int port;
-public:
-	RpcChannelTest()
-	{
-	}
-
-	void SetUp()
-	{
-		port = 10001;
-	}
-
-	void TearDown()
-	{
-	}
-};
-
-
-TEST_F(RpcChannelTest, CallMethod)
-{
-	RpcServerTest server(io_service_, port);
-	ASSERT_EQ(0, server.size);
-
-	RpcChannel channel(io_service_, "localhost", port);
-	channel.CallMethod(NULL, NULL, request, response_, done_);
-
-	ASSERT_EQ(request.ByteSize(), server.size);
-}
-
-} // namespace Egametang
+#include <gtest/gtest.h>
+#include <gflags/gflags.h>
+#include <glog/logging.h>
+#include "Rpc/RpcChannel.h"
+
+namespace Egametang {
+
+static int port = 10001;
+
+class RpcServerTest
+{
+public:
+	boost::asio::io_service io_service_;
+	boost::asio::ip::tcp::acceptor acceptor_;
+	boost::asio::ip::tcp::socket socket_;
+
+	int size;
+
+public:
+	RpcServerTest(boost::asio::io_service& service, int port):
+		io_service_(service), size(0)
+	{
+		boost::asio::ip::address address;
+		address.from_string("localhost");
+		boost::asio::ip::tcp::endpoint endpoint(address, port);
+		boost::asio::ip::tcp::acceptor acceptor;
+		acceptor.open(endpoint.protocol());
+		acceptor.set_option(
+		boost::asio::ip::tcp::acceptor::reuse_address(true));
+		acceptor.bind(endpoint);
+		acceptor.listen();
+		acceptor.async_accept(socket_);
+	}
+	~RpcServerTest();
+
+	void RecvMessageSize()
+	{
+	}
+};
+
+class RpcChannelTest: public testing::Test
+{
+private:
+	int port;
+public:
+	RpcChannelTest()
+	{
+	}
+
+	void SetUp()
+	{
+		port = 10001;
+	}
+
+	void TearDown()
+	{
+	}
+};
+
+
+TEST_F(RpcChannelTest, CallMethod)
+{
+	RpcServerTest server(io_service_, port);
+	ASSERT_EQ(0, server.size);
+
+	RpcChannel channel(io_service_, "localhost", port);
+	channel.CallMethod(NULL, NULL, request, response_, done_);
+
+	ASSERT_EQ(request.ByteSize(), server.size);
+}
+
+} // namespace Egametang

+ 46 - 46
Src/Egametang/Rpc/RpcController.cc

@@ -1,46 +1,46 @@
-#include "Rpc/RpcController.h"
-
-namespace Egametang {
-
-RpcController::RpcController()
-{
-}
-
-RpcController::~RpcController()
-{
-}
-
-void RpcController::Reset()
-{
-	failed_ = false;
-	reason_ = "";
-	canceled_ = false;
-}
-
-bool RpcController::Failed() const
-{
-	return failed_;
-}
-
-std::string RpcController::ErrorText() const
-{
-	return reason_;
-}
-
-void RpcController::StartCancel()
-{
-}
-
-void RpcController::SetFailed(const string & reason)
-{
-}
-
-bool RpcController::IsCanceled() const
-{
-}
-
-void RpcController::NotifyOnCancel(Closure *callback)
-{
-}
-
-} // namespace Egametang
+#include "Rpc/RpcController.h"
+
+namespace Egametang {
+
+RpcController::RpcController()
+{
+}
+
+RpcController::~RpcController()
+{
+}
+
+void RpcController::Reset()
+{
+	failed_ = false;
+	reason_ = "";
+	canceled_ = false;
+}
+
+bool RpcController::Failed() const
+{
+	return failed_;
+}
+
+std::string RpcController::ErrorText() const
+{
+	return reason_;
+}
+
+void RpcController::StartCancel()
+{
+}
+
+void RpcController::SetFailed(const string & reason)
+{
+}
+
+bool RpcController::IsCanceled() const
+{
+}
+
+void RpcController::NotifyOnCancel(Closure *callback)
+{
+}
+
+} // namespace Egametang

+ 33 - 33
Src/Egametang/Rpc/RpcController.h

@@ -1,33 +1,33 @@
-#ifndef RPC_RPC_CONTROLLER_H
-#define RPC_RPC_CONTROLLER_H
-
-#include <google/protobuf/service.h>
-
-namespace Egametang {
-
-class RpcController: public google::protobuf::RpcController
-{
-private:
-	bool failed_;
-	std::string reason_;
-	bool canceled_;
-
-public:
-	RpcController();
-	~RpcController();
-
-	// client
-	virtual void Reset();
-	virtual bool Failed() const;
-	virtual std::string ErrorText() const;
-	virtual void StartCancel();
-
-	// server
-	virtual void SetFailed(const string& reason);
-	virtual bool IsCanceled() const;
-	virtual void NotifyOnCancel(Closure* callback);
-};
-
-} // namespace Egametang
-
-#endif // RPC_RPC_CONTROLLER_H
+#ifndef RPC_RPC_CONTROLLER_H
+#define RPC_RPC_CONTROLLER_H
+
+#include <google/protobuf/service.h>
+
+namespace Egametang {
+
+class RpcController: public google::protobuf::RpcController
+{
+private:
+	bool failed_;
+	std::string reason_;
+	bool canceled_;
+
+public:
+	RpcController();
+	~RpcController();
+
+	// client
+	virtual void Reset();
+	virtual bool Failed() const;
+	virtual std::string ErrorText() const;
+	virtual void StartCancel();
+
+	// server
+	virtual void SetFailed(const string& reason);
+	virtual bool IsCanceled() const;
+	virtual void NotifyOnCancel(Closure* callback);
+};
+
+} // namespace Egametang
+
+#endif // RPC_RPC_CONTROLLER_H

+ 27 - 27
Src/Egametang/Rpc/RpcHandler.cc

@@ -1,27 +1,27 @@
-#include "Rpc/RpcHandler.h"
-
-namespace Egametang {
-
-RpcHandler::RpcHandler(google::protobuf::RpcController* controller,
-		google::protobuf::Message* response,
-		google::protobuf::Closure* done):
-		controller_(controller), response_(response), done_(done)
-{
-}
-
-google::protobuf::RpcController *RpcHandler::GetController() const
-{
-    return controller_;
-}
-
-google::protobuf::Closure *RpcHandler::GetDone() const
-{
-    return done_;
-}
-
-google::protobuf::Message *RpcHandler::GetResponse() const
-{
-    return response_;
-}
-
-} // namespace Egametang
+#include "Rpc/RpcHandler.h"
+
+namespace Egametang {
+
+RpcHandler::RpcHandler(google::protobuf::RpcController* controller,
+		google::protobuf::Message* response,
+		google::protobuf::Closure* done):
+		controller_(controller), response_(response), done_(done)
+{
+}
+
+google::protobuf::RpcController *RpcHandler::GetController() const
+{
+    return controller_;
+}
+
+google::protobuf::Closure *RpcHandler::GetDone() const
+{
+    return done_;
+}
+
+google::protobuf::Message *RpcHandler::GetResponse() const
+{
+    return response_;
+}
+
+} // namespace Egametang

+ 27 - 27
Src/Egametang/Rpc/RpcHandler.h

@@ -1,27 +1,27 @@
-#ifndef RPC_RPC_HANDLER_H
-#define RPC_RPC_HANDLER_H
-
-namespace Egametang {
-
-class google::protobuf::RpcController;
-class google::protobuf::Message;
-class google::protobuf::Closure;
-
-class RpcHandler
-{
-private:
-	google::protobuf::RpcController* controller_;
-	google::protobuf::Message* response_;
-	google::protobuf::Closure* done_;
-public:
-	RpcHandler(google::protobuf::RpcController* controller,
-			google::protobuf::Message* response,
-			google::protobuf::Closure* done);
-    google::protobuf::RpcController *GetController() const;
-    google::protobuf::Closure *GetDone() const;
-    google::protobuf::Message *GetResponse() const;
-};
-
-} // namespace Egametang
-
-#endif // RPC_RPC_HANDLER_H
+#ifndef RPC_RPC_HANDLER_H
+#define RPC_RPC_HANDLER_H
+
+namespace Egametang {
+
+class google::protobuf::RpcController;
+class google::protobuf::Message;
+class google::protobuf::Closure;
+
+class RpcHandler
+{
+private:
+	google::protobuf::RpcController* controller_;
+	google::protobuf::Message* response_;
+	google::protobuf::Closure* done_;
+public:
+	RpcHandler(google::protobuf::RpcController* controller,
+			google::protobuf::Message* response,
+			google::protobuf::Closure* done);
+    google::protobuf::RpcController *GetController() const;
+    google::protobuf::Closure *GetDone() const;
+    google::protobuf::Message *GetResponse() const;
+};
+
+} // namespace Egametang
+
+#endif // RPC_RPC_HANDLER_H

+ 78 - 78
Src/Egametang/Rpc/RpcServer.cc

@@ -1,78 +1,78 @@
-#include <boost/asio.hpp>
-#include <boost/foreach.hpp>
-#include <google/protobuf/service.h>
-#include "Rpc/RpcTypedef.h"
-#include "Rpc/RpcServer.h"
-#include "Rpc/RpcSession.h"
-#include "Thread/ThreadPool.h"
-#include "Base/Marcos.h"
-
-namespace Egametang {
-
-RpcServer::RpcServer(boost::asio::io_service& io_service, int port, ThreadPool& thread_pool):
-		io_service_(io_service), thread_pool_(thread_pool)
-{
-	boost::asio::ip::address address;
-	address.from_string("localhost");
-	boost::asio::ip::tcp::endpoint endpoint(address, port);
-	acceptor_.open(endpoint.protocol());
-	acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
-	acceptor_.bind(endpoint);
-	acceptor_.listen();
-	RpcSessionPtr new_session(new RpcSession(sessions_));
-	acceptor_.async_accept(new_session->socket(),
-			boost::bind(&RpcServer::HandleAsyncAccept, this,
-					boost::asio::placeholders::error));
-}
-
-void RpcServer::HandleAsyncAccept(RpcSessionPtr session, const boost::system::error_code& err)
-{
-	if (err)
-	{
-		return;
-	}
-	session->Start();
-	sessions_.insert(session);
-	RpcSessionPtr new_session(new RpcSession(*this));
-	acceptor_.async_accept(new_session->socket(),
-			boost::bind(&RpcServer::HandleAsyncAccept, this,
-					boost::asio::placeholders::error));
-}
-
-void RpcServer::Callback(RpcSessionPtr session,
-		boost::function<void (RpcSessionPtr, RpcResponsePtr)> handler)
-{
-	session->socket.get_io_service().post(handler);
-}
-
-void RpcServer::Stop()
-{
-	acceptor_.close();
-	foreach(RpcSessionPtr session, sessions_)
-	{
-		session->Stop();
-	}
-	sessions_.clear();
-}
-
-void RpcServer::RunService(RpcSessionPtr session, RpcRequestPtr request,
-		boost::function<void (RpcSessionPtr, RpcResponsePtr)> handler)
-{
-	google::protobuf::Closure* done = google::protobuf::NewCallback(
-			this, &RpcServer::Callback, session, handler);
-	thread_pool_.PushTask(
-			boost::bind(&google::protobuf::Service::CallMethod, &service_,
-					method, NULL, request.get(), done));
-}
-
-void RpcServer::RegisterService(ProtobufServicePtr service)
-{
-
-}
-
-void RpcServer::Start()
-{
-	io_service_.run();
-}
-
-} // namespace Egametang
+#include <boost/asio.hpp>
+#include <boost/foreach.hpp>
+#include <google/protobuf/service.h>
+#include "Rpc/RpcTypedef.h"
+#include "Rpc/RpcServer.h"
+#include "Rpc/RpcSession.h"
+#include "Thread/ThreadPool.h"
+#include "Base/Marcos.h"
+
+namespace Egametang {
+
+RpcServer::RpcServer(boost::asio::io_service& io_service, int port, ThreadPool& thread_pool):
+		io_service_(io_service), thread_pool_(thread_pool)
+{
+	boost::asio::ip::address address;
+	address.from_string("localhost");
+	boost::asio::ip::tcp::endpoint endpoint(address, port);
+	acceptor_.open(endpoint.protocol());
+	acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
+	acceptor_.bind(endpoint);
+	acceptor_.listen();
+	RpcSessionPtr new_session(new RpcSession(sessions_));
+	acceptor_.async_accept(new_session->socket(),
+			boost::bind(&RpcServer::HandleAsyncAccept, this,
+					boost::asio::placeholders::error));
+}
+
+void RpcServer::HandleAsyncAccept(RpcSessionPtr session, const boost::system::error_code& err)
+{
+	if (err)
+	{
+		return;
+	}
+	session->Start();
+	sessions_.insert(session);
+	RpcSessionPtr new_session(new RpcSession(*this));
+	acceptor_.async_accept(new_session->socket(),
+			boost::bind(&RpcServer::HandleAsyncAccept, this,
+					boost::asio::placeholders::error));
+}
+
+void RpcServer::Callback(RpcSessionPtr session,
+		boost::function<void (RpcSessionPtr, RpcResponsePtr)> handler)
+{
+	session->socket.get_io_service().post(handler);
+}
+
+void RpcServer::Stop()
+{
+	acceptor_.close();
+	foreach(RpcSessionPtr session, sessions_)
+	{
+		session->Stop();
+	}
+	sessions_.clear();
+}
+
+void RpcServer::RunService(RpcSessionPtr session, RpcRequestPtr request,
+		boost::function<void (RpcSessionPtr, RpcResponsePtr)> handler)
+{
+	google::protobuf::Closure* done = google::protobuf::NewCallback(
+			this, &RpcServer::Callback, session, handler);
+	thread_pool_.PushTask(
+			boost::bind(&google::protobuf::Service::CallMethod, &service_,
+					method, NULL, request.get(), done));
+}
+
+void RpcServer::RegisterService(ProtobufServicePtr service)
+{
+
+}
+
+void RpcServer::Start()
+{
+	io_service_.run();
+}
+
+} // namespace Egametang

+ 36 - 36
Src/Egametang/Rpc/RpcServer.h

@@ -1,36 +1,36 @@
-#ifndef RPC_RPC_SERVER_H
-#define RPC_RPC_SERVER_H
-#include <boost/asio.hpp>
-#include "Rpc/RpcTypedef.h"
-
-namespace Egametang {
-
-class RpcServer: public boost::enable_shared_from_this<RpcServer>
-{
-private:
-	typedef boost::unordered_set<RpcSessionPtr> RpcSessionSet;
-
-	google::protobuf::Service& service_;
-	boost::asio::io_service& io_service_;
-	boost::asio::ip::tcp::acceptor acceptor_;
-	ThreadPool& thread_pool_;
-	RpcSessionSet sessions_;
-
-	void HandleAsyncAccept(RpcSessionPtr session, const boost::system::error_code& err);
-	void Callback(RpcSessionPtr session,
-			boost::function<void (RpcSessionPtr, RpcResponsePtr)> handler);
-
-public:
-	RpcServer(boost::asio::io_service& io_service, int port, ThreadPool& thread_pool);
-	~RpcServer();
-	void Start();
-	void Stop();
-
-	void RunService(RpcSessionPtr session, RpcRequestPtr request,
-			boost::function<void (RpcSessionPtr, RpcResponsePtr)> handler);
-	void RegisterService(ProtobufServicePtr service);
-};
-
-} // namespace Egametang
-
-#endif // RPC_RPC_SERVER_H
+#ifndef RPC_RPC_SERVER_H
+#define RPC_RPC_SERVER_H
+#include <boost/asio.hpp>
+#include "Rpc/RpcTypedef.h"
+
+namespace Egametang {
+
+class RpcServer: public boost::enable_shared_from_this<RpcServer>
+{
+private:
+	typedef boost::unordered_set<RpcSessionPtr> RpcSessionSet;
+
+	google::protobuf::Service& service_;
+	boost::asio::io_service& io_service_;
+	boost::asio::ip::tcp::acceptor acceptor_;
+	ThreadPool& thread_pool_;
+	RpcSessionSet sessions_;
+
+	void HandleAsyncAccept(RpcSessionPtr session, const boost::system::error_code& err);
+	void Callback(RpcSessionPtr session,
+			boost::function<void (RpcSessionPtr, RpcResponsePtr)> handler);
+
+public:
+	RpcServer(boost::asio::io_service& io_service, int port, ThreadPool& thread_pool);
+	~RpcServer();
+	void Start();
+	void Stop();
+
+	void RunService(RpcSessionPtr session, RpcRequestPtr request,
+			boost::function<void (RpcSessionPtr, RpcResponsePtr)> handler);
+	void RegisterService(ProtobufServicePtr service);
+};
+
+} // namespace Egametang
+
+#endif // RPC_RPC_SERVER_H

+ 102 - 102
Src/Egametang/Rpc/RpcSession.cc

@@ -1,102 +1,102 @@
-#include "Rpc/RpcSession.h"
-
-namespace Egametang {
-
-RpcSession::RpcSession(RpcServer& rpc_server): rpc_server_(rpc_server)
-{
-}
-
-boost::asio::ip::tcp::socket& RpcSession::Socket()
-{
-	return socket_;
-}
-
-void RpcSession::SendMessageHandler(int32 id, RpcHandlerPtr handler,
-		const boost::system::error_code& err)
-{
-	if (err)
-	{
-		LOG(ERROR) << "SendMessage error:";
-		return;
-	}
-}
-
-void RpcSession::SendMessage(const RpcResponsePtr response, const boost::system::error_code& err)
-{
-	if (err)
-	{
-		return;
-	}
-	std::string ss = response->SerializeAsString();
-	boost::asio::async_write(socket_, boost::asio::buffer(ss),
-			boost::bind(&RpcSession::SendMessageHandler, this,
-					response->id(), boost::asio::placeholders::error));
-}
-
-void RpcSession::SendMessageSize(RpcResponsePtr response)
-{
-	int size = response->ByteSize();
-	std::string ss = boost::lexical_cast(size);
-	boost::asio::async_write(socket_, boost::asio::buffer(ss),
-			boost::bind(&RpcSession::SendMessage, this,
-					response, boost::asio::placeholders::error));
-}
-///////////////////////////
-
-void RpcSession::RecvMessegeSize()
-{
-	IntPtr size(new int);
-	boost::asio::async_read(socket_,
-			boost::asio::buffer(
-					reinterpret_cast<char*>(size.get()), sizeof(int)),
-			boost::bind(&RpcSession::RecvMessage, this, size,
-					boost::asio::placeholders::error));
-}
-
-void RpcSession::RecvMessage(IntPtr size, const boost::system::error_code& err)
-{
-	if (err)
-	{
-		LOG(ERROR) << "receive request size failed";
-		return;
-	}
-	StringPtr ss(new std::string);
-	boost::asio::async_read(socket_,
-			boost::asio::buffer(*ss, *size),
-			boost::bind(&RpcSession::RecvMessageHandler, this, ss,
-					boost::asio::placeholders::error));
-}
-
-void RpcSession::RecvMessageHandler(StringPtr ss, const boost::system::error_code& err)
-{
-	if (err)
-	{
-		LOG(ERROR) << "receive request message failed";
-		return;
-	}
-
-	RpcRequestPtr request(new RpcRequest);
-	request->ParseFromString(*ss);
-
-	RpcResponsePtr response(new RpcResponse);
-	response->set_id(request->id_());
-
-	rpc_server_.RunService(shared_from_this(), request,
-			boost::bind(&RpcSession::SendMessegeSize, shared_from_this(), response));
-
-	// read size
-	RecvMessegeSize();
-}
-
-void RpcSession::Start()
-{
-	RecvMessegeSize();
-}
-
-void RpcSession::Stop()
-{
-	socket_.close();
-	sessions_.erase(shared_from_this());
-}
-
-}
+#include "Rpc/RpcSession.h"
+
+namespace Egametang {
+
+RpcSession::RpcSession(RpcServer& rpc_server): rpc_server_(rpc_server)
+{
+}
+
+boost::asio::ip::tcp::socket& RpcSession::Socket()
+{
+	return socket_;
+}
+
+void RpcSession::SendMessageHandler(int32 id, RpcHandlerPtr handler,
+		const boost::system::error_code& err)
+{
+	if (err)
+	{
+		LOG(ERROR) << "SendMessage error:";
+		return;
+	}
+}
+
+void RpcSession::SendMessage(const RpcResponsePtr response, const boost::system::error_code& err)
+{
+	if (err)
+	{
+		return;
+	}
+	std::string ss = response->SerializeAsString();
+	boost::asio::async_write(socket_, boost::asio::buffer(ss),
+			boost::bind(&RpcSession::SendMessageHandler, this,
+					response->id(), boost::asio::placeholders::error));
+}
+
+void RpcSession::SendMessageSize(RpcResponsePtr response)
+{
+	int size = response->ByteSize();
+	std::string ss = boost::lexical_cast(size);
+	boost::asio::async_write(socket_, boost::asio::buffer(ss),
+			boost::bind(&RpcSession::SendMessage, this,
+					response, boost::asio::placeholders::error));
+}
+///////////////////////////
+
+void RpcSession::RecvMessegeSize()
+{
+	IntPtr size(new int);
+	boost::asio::async_read(socket_,
+			boost::asio::buffer(
+					reinterpret_cast<char*>(size.get()), sizeof(int)),
+			boost::bind(&RpcSession::RecvMessage, this, size,
+					boost::asio::placeholders::error));
+}
+
+void RpcSession::RecvMessage(IntPtr size, const boost::system::error_code& err)
+{
+	if (err)
+	{
+		LOG(ERROR) << "receive request size failed";
+		return;
+	}
+	StringPtr ss(new std::string);
+	boost::asio::async_read(socket_,
+			boost::asio::buffer(*ss, *size),
+			boost::bind(&RpcSession::RecvMessageHandler, this, ss,
+					boost::asio::placeholders::error));
+}
+
+void RpcSession::RecvMessageHandler(StringPtr ss, const boost::system::error_code& err)
+{
+	if (err)
+	{
+		LOG(ERROR) << "receive request message failed";
+		return;
+	}
+
+	RpcRequestPtr request(new RpcRequest);
+	request->ParseFromString(*ss);
+
+	RpcResponsePtr response(new RpcResponse);
+	response->set_id(request->id_());
+
+	rpc_server_.RunService(shared_from_this(), request,
+			boost::bind(&RpcSession::SendMessegeSize, shared_from_this(), response));
+
+	// read size
+	RecvMessegeSize();
+}
+
+void RpcSession::Start()
+{
+	RecvMessegeSize();
+}
+
+void RpcSession::Stop()
+{
+	socket_.close();
+	sessions_.erase(shared_from_this());
+}
+
+}

+ 37 - 37
Src/Egametang/Rpc/RpcSession.h

@@ -1,37 +1,37 @@
-#ifndef RPC_RPC_SESSION_H
-#define RPC_RPC_SESSION_H
-
-#include <boost/asio.hpp>
-#include <boost/noncopyable.hpp>
-#include <boost/enable_shared_from_this.hpp>
-#include "Rpc/RpcTypedef.h"
-
-namespace Egametang {
-
-class RpcServer;
-
-class RpcSession: private boost::noncopyable, public boost::enable_shared_from_this<RpcSession>
-{
-private:
-	boost::asio::ip::tcp::socket socket_;
-	RpcServer& rpc_server_;
-
-	void RecvMessegeSize();
-	void RecvMessage(IntPtr size, const boost::system::error_code& err);
-	void RecvMessageHandler(StringPtr ss, const boost::system::error_code& err);
-
-	void SendMessageSize(RpcResponsePtr response);
-	void SendMessage(const RpcResponsePtr response, const boost::system::error_code& err);
-	void SendMessageHandler(int32 id, RpcHandlerPtr handler, const boost::system::error_code& err);
-
-public:
-	RpcSession(RpcServer& server);
-	~RpcSession();
-	boost::asio::ip::tcp::socket& Socket();
-	void Start();
-	void Stop();
-};
-
-} // namespace Egametang
-
-#endif // RPC_RPC_SESSION_H
+#ifndef RPC_RPC_SESSION_H
+#define RPC_RPC_SESSION_H
+
+#include <boost/asio.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/enable_shared_from_this.hpp>
+#include "Rpc/RpcTypedef.h"
+
+namespace Egametang {
+
+class RpcServer;
+
+class RpcSession: private boost::noncopyable, public boost::enable_shared_from_this<RpcSession>
+{
+private:
+	boost::asio::ip::tcp::socket socket_;
+	RpcServer& rpc_server_;
+
+	void RecvMessegeSize();
+	void RecvMessage(IntPtr size, const boost::system::error_code& err);
+	void RecvMessageHandler(StringPtr ss, const boost::system::error_code& err);
+
+	void SendMessageSize(RpcResponsePtr response);
+	void SendMessage(const RpcResponsePtr response, const boost::system::error_code& err);
+	void SendMessageHandler(int32 id, RpcHandlerPtr handler, const boost::system::error_code& err);
+
+public:
+	RpcSession(RpcServer& server);
+	~RpcSession();
+	boost::asio::ip::tcp::socket& Socket();
+	void Start();
+	void Stop();
+};
+
+} // namespace Egametang
+
+#endif // RPC_RPC_SESSION_H

+ 102 - 102
Src/Egametang/Thread/ThreadPool.cc

@@ -1,102 +1,102 @@
-#include <glog/logging.h>
-#include "Thread/ThreadPool.h"
-
-namespace Egametang {
-
-ThreadPool::ThreadPool(int num) :
-	thread_num_(num), running_(false), work_num_(0)
-{
-	if (num == 0)
-	{
-		thread_num_ = boost::thread::hardware_concurrency();
-	}
-}
-
-ThreadPool::~ThreadPool()
-{
-}
-
-void ThreadPool::Start()
-{
-	running_ = true;
-	for (int i = 0; i < thread_num_; ++i)
-	{
-		ThreadPtr t(new boost::thread(
-				boost::bind(&ThreadPool::Runner, this)));
-		threads_.push_back(t);
-		t->detach();
-		++work_num_;
-	}
-}
-
-void ThreadPool::Stop()
-{
-	VLOG(3)<< "Stop";
-	boost::mutex::scoped_lock lock(mutex_);
-	running_ = false;
-	cond_.notify_all();
-	while (work_num_ > 0)
-	{
-		VLOG(3) << "done tasks size = " << tasks_.size();
-		done_.wait(lock);
-	}
-}
-
-void ThreadPool::Runner()
-{
-	VLOG(3) << "thread start";
-	bool continued = true;
-	while (continued)
-	{
-		boost::function<void (void)> task;
-		{
-			VLOG(3) << "loop lock";
-			boost::mutex::scoped_lock lock(mutex_);
-			VLOG(3) << "loop lock ok";
-			while (running_ && tasks_.empty())
-			{
-				cond_.wait(lock);
-				VLOG(3) << "cond";
-			}
-			if (!tasks_.empty())
-			{
-				VLOG(3) << "fetch task";
-				task = tasks_.front();
-				tasks_.pop_front();
-			}
-			continued = running_ || !tasks_.empty();
-			VLOG(3) << "continued = " << continued
-					<< "running = " << running_
-					<< " tasks size = " << tasks_.size();
-			VLOG(3) << "loop unlock";
-		}
-
-		if (task)
-		{
-			task();
-		}
-	}
-	if (--work_num_ == 0)
-	{
-		VLOG(3) << "work_num = " << work_num_;
-		done_.notify_one();
-	}
-}
-
-bool ThreadPool::PushTask(boost::function<void (void)> task)
-{
-	VLOG(3) << "push task";
-	{
-		boost::mutex::scoped_lock lock(mutex_);
-		if (!running_)
-		{
-			return false;
-		}
-		tasks_.push_back(task);
-	}
-	VLOG(3) << "push task unlock";
-	cond_.notify_one();
-	return true;
-}
-
-} // namespace Egametang
+#include <glog/logging.h>
+#include "Thread/ThreadPool.h"
+
+namespace Egametang {
+
+ThreadPool::ThreadPool(int num) :
+	thread_num_(num), running_(false), work_num_(0)
+{
+	if (num == 0)
+	{
+		thread_num_ = boost::thread::hardware_concurrency();
+	}
+}
+
+ThreadPool::~ThreadPool()
+{
+}
+
+void ThreadPool::Start()
+{
+	running_ = true;
+	for (int i = 0; i < thread_num_; ++i)
+	{
+		ThreadPtr t(new boost::thread(
+				boost::bind(&ThreadPool::Runner, this)));
+		threads_.push_back(t);
+		t->detach();
+		++work_num_;
+	}
+}
+
+void ThreadPool::Stop()
+{
+	VLOG(3)<< "Stop";
+	boost::mutex::scoped_lock lock(mutex_);
+	running_ = false;
+	cond_.notify_all();
+	while (work_num_ > 0)
+	{
+		VLOG(3) << "done tasks size = " << tasks_.size();
+		done_.wait(lock);
+	}
+}
+
+void ThreadPool::Runner()
+{
+	VLOG(3) << "thread start";
+	bool continued = true;
+	while (continued)
+	{
+		boost::function<void (void)> task;
+		{
+			VLOG(3) << "loop lock";
+			boost::mutex::scoped_lock lock(mutex_);
+			VLOG(3) << "loop lock ok";
+			while (running_ && tasks_.empty())
+			{
+				cond_.wait(lock);
+				VLOG(3) << "cond";
+			}
+			if (!tasks_.empty())
+			{
+				VLOG(3) << "fetch task";
+				task = tasks_.front();
+				tasks_.pop_front();
+			}
+			continued = running_ || !tasks_.empty();
+			VLOG(3) << "continued = " << continued
+					<< "running = " << running_
+					<< " tasks size = " << tasks_.size();
+			VLOG(3) << "loop unlock";
+		}
+
+		if (task)
+		{
+			task();
+		}
+	}
+	if (--work_num_ == 0)
+	{
+		VLOG(3) << "work_num = " << work_num_;
+		done_.notify_one();
+	}
+}
+
+bool ThreadPool::PushTask(boost::function<void (void)> task)
+{
+	VLOG(3) << "push task";
+	{
+		boost::mutex::scoped_lock lock(mutex_);
+		if (!running_)
+		{
+			return false;
+		}
+		tasks_.push_back(task);
+	}
+	VLOG(3) << "push task unlock";
+	cond_.notify_one();
+	return true;
+}
+
+} // namespace Egametang

+ 35 - 35
Src/Egametang/Thread/ThreadPool.h

@@ -1,35 +1,35 @@
-#ifndef THREAD_THREAD_POOL_H
-#define THREAD_THREAD_POOL_H
-
-#include <list>
-#include <boost/thread.hpp>
-#include <boost/function.hpp>
-#include <boost/detail/atomic_count.hpp>
-#include "Thread/ThreadTypedef.h"
-
-namespace Egametang {
-
-class ThreadPool: private boost::noncopyable
-{
-private:
-	int thread_num_;
-	boost::detail::atomic_count work_num_;
-	volatile bool running_;
-	boost::mutex mutex_;
-	boost::condition_variable cond_;
-	boost::condition_variable done_;
-	std::list<ThreadPtr> threads_;
-	std::list<boost::function<void (void)> > tasks_;
-
-	void Runner();
-public:
-	ThreadPool(int num = 0);
-	~ThreadPool();
-
-	virtual void Start();
-	virtual void Stop();
-	virtual bool PushTask(boost::function<void (void)> task);
-};
-
-} // namespace Egametang
-#endif // THREAD_THREAD_POOL_H
+#ifndef THREAD_THREAD_POOL_H
+#define THREAD_THREAD_POOL_H
+
+#include <list>
+#include <boost/thread.hpp>
+#include <boost/function.hpp>
+#include <boost/detail/atomic_count.hpp>
+#include "Thread/ThreadTypedef.h"
+
+namespace Egametang {
+
+class ThreadPool: private boost::noncopyable
+{
+private:
+	int thread_num_;
+	boost::detail::atomic_count work_num_;
+	volatile bool running_;
+	boost::mutex mutex_;
+	boost::condition_variable cond_;
+	boost::condition_variable done_;
+	std::list<ThreadPtr> threads_;
+	std::list<boost::function<void (void)> > tasks_;
+
+	void Runner();
+public:
+	ThreadPool(int num = 0);
+	~ThreadPool();
+
+	virtual void Start();
+	virtual void Stop();
+	virtual bool PushTask(boost::function<void (void)> task);
+};
+
+} // namespace Egametang
+#endif // THREAD_THREAD_POOL_H

+ 12 - 12
Src/Egametang/Thread/ThreadPoolMock.h

@@ -1,12 +1,12 @@
-#ifndef THREAD_THREAD_POOL_MOCK_H
-#define THREAD_THREAD_POOL_MOCK_H
-
-namespace Egametang {
-
-class ThreadPoolMock
-{
-};
-
-} // namespace Egametang
-
-#endif // THREAD_THREAD_POOL_MOCK_H
+#ifndef THREAD_THREAD_POOL_MOCK_H
+#define THREAD_THREAD_POOL_MOCK_H
+
+namespace Egametang {
+
+class ThreadPoolMock
+{
+};
+
+} // namespace Egametang
+
+#endif // THREAD_THREAD_POOL_MOCK_H

+ 50 - 50
Src/Egametang/Thread/ThreadPoolTest.cc

@@ -1,50 +1,50 @@
-#include <boost/function.hpp>
-#include <boost/bind.hpp>
-#include <gtest/gtest.h>
-#include <gflags/gflags.h>
-#include <glog/logging.h>
-#include "Thread/ThreadPool.h"
-
-namespace Egametang {
-
-class ThreadPoolTest: public testing::Test
-{
-protected:
-	ThreadPool pool_;
-public:
-	ThreadPoolTest() : pool_(10)
-	{
-	}
-	void Max(int a, int b, int* z)
-	{
-		*z = a > b? a : b;
-	}
-};
-
-TEST_F(ThreadPoolTest, Test1)
-{
-	pool_.Start();
-	std::vector<int> x(100, 8);
-	std::vector<int> y(100, 9);
-	std::vector<int> z(100, 0);
-	for (int i = 0; i < 100; ++i)
-	{
-		pool_.PushTask(
-				boost::bind(&ThreadPoolTest::Max, this, x[i], y[i], &z[i]));
-	}
-	pool_.Stop();
-	for (int i = 0; i < 100; ++i)
-	{
-		ASSERT_EQ(9, z[i]) << "i = " << i;
-	}
-}
-} // namespace Egametang
-
-int main(int argc, char* argv[])
-{
-	FLAGS_logtostderr = true;
-	testing::InitGoogleTest(&argc, argv);
-	google::ParseCommandLineFlags(&argc, &argv, true);
-	google::InitGoogleLogging(argv[0]);
-	return RUN_ALL_TESTS();
-}
+#include <boost/function.hpp>
+#include <boost/bind.hpp>
+#include <gtest/gtest.h>
+#include <gflags/gflags.h>
+#include <glog/logging.h>
+#include "Thread/ThreadPool.h"
+
+namespace Egametang {
+
+class ThreadPoolTest: public testing::Test
+{
+protected:
+	ThreadPool pool_;
+public:
+	ThreadPoolTest() : pool_(10)
+	{
+	}
+	void Max(int a, int b, int* z)
+	{
+		*z = a > b? a : b;
+	}
+};
+
+TEST_F(ThreadPoolTest, Test1)
+{
+	pool_.Start();
+	std::vector<int> x(100, 8);
+	std::vector<int> y(100, 9);
+	std::vector<int> z(100, 0);
+	for (int i = 0; i < 100; ++i)
+	{
+		pool_.PushTask(
+				boost::bind(&ThreadPoolTest::Max, this, x[i], y[i], &z[i]));
+	}
+	pool_.Stop();
+	for (int i = 0; i < 100; ++i)
+	{
+		ASSERT_EQ(9, z[i]) << "i = " << i;
+	}
+}
+} // namespace Egametang
+
+int main(int argc, char* argv[])
+{
+	FLAGS_logtostderr = true;
+	testing::InitGoogleTest(&argc, argv);
+	google::ParseCommandLineFlags(&argc, &argv, true);
+	google::InitGoogleLogging(argv[0]);
+	return RUN_ALL_TESTS();
+}

+ 44 - 44
Src/Experimental/BoostFunctionTest.cc

@@ -1,44 +1,44 @@
-//  Created on: 2010-6-28
-//      Author: tanghai
-
-#include <boost/function.hpp>
-#include <boost/bind.hpp>
-#include <gtest/gtest.h>
-#include <gflags/gflags.h>
-#include <glog/logging.h>
-
-namespace Egametang {
-class BoostTest: public testing::Test
-{
-	void SetUp()
-	{
-		a = 6;
-	}
-protected:
-	int a;
-	boost::function<int(int)> func;
-public:
-	int Max(int a, int b)
-	{
-		LOG(INFO) << a << " " << b;
-		return a > b? a : b;
-	}
-};
-
-TEST_F(BoostTest, Test1)
-{
-	int x = 5;
-	func = boost::bind(&BoostTest::Max, this, _1, x);
-	int b = func(a);
-	LOG(INFO) << b;
-}
-}
-
-int main(int argc, char* argv[])
-{
-	FLAGS_logtostderr = true;
-	testing::InitGoogleTest(&argc, argv);
-	google::ParseCommandLineFlags(&argc, &argv, true);
-	google::InitGoogleLogging(argv[0]);
-	return RUN_ALL_TESTS();
-}
+//  Created on: 2010-6-28
+//      Author: tanghai
+
+#include <boost/function.hpp>
+#include <boost/bind.hpp>
+#include <gtest/gtest.h>
+#include <gflags/gflags.h>
+#include <glog/logging.h>
+
+namespace Egametang {
+class BoostTest: public testing::Test
+{
+	void SetUp()
+	{
+		a = 6;
+	}
+protected:
+	int a;
+	boost::function<int(int)> func;
+public:
+	int Max(int a, int b)
+	{
+		LOG(INFO) << a << " " << b;
+		return a > b? a : b;
+	}
+};
+
+TEST_F(BoostTest, Test1)
+{
+	int x = 5;
+	func = boost::bind(&BoostTest::Max, this, _1, x);
+	int b = func(a);
+	LOG(INFO) << b;
+}
+}
+
+int main(int argc, char* argv[])
+{
+	FLAGS_logtostderr = true;
+	testing::InitGoogleTest(&argc, argv);
+	google::ParseCommandLineFlags(&argc, &argv, true);
+	google::InitGoogleLogging(argv[0]);
+	return RUN_ALL_TESTS();
+}