Просмотр исходного кода

Add: tc_config add erase/eraseDomain, servant add doNoFunc

ruanshudong 2 лет назад
Родитель
Сommit
e8af8838ae

+ 2 - 3
servant/libservant/Current.cpp

@@ -351,8 +351,7 @@ void Current::sendResponse(int iRet, ResponsePacket &response,  const map<string
 
 }
 
-
-void Current::sendPushResponse(int iRet, const string &funcName, TarsOutputStream<BufferWriterVector>& oss)
+void Current::sendPushResponse(int iRet, const string &funcName, TarsOutputStream<BufferWriterVector>& oss, const map<string, string> &context)
 {
 	ResponsePacket response;
     oss.swap(response.sBuffer);
@@ -362,7 +361,7 @@ void Current::sendPushResponse(int iRet, const string &funcName, TarsOutputStrea
 	response.cPacketType    = TARSNORMAL;
 	response.iMessageType   = 0;
 	response.iVersion		= TARSVERSION;
-	response.context        = _responseContext;
+	response.context        = context;
 	response.status["TARS_FUNC"] = funcName;
 
     shared_ptr<TC_EpollServer::SendContext> send = _data->createSendContext();

+ 5 - 2
servant/libservant/ServantHandle.cpp

@@ -59,8 +59,6 @@ ServantHandle::~ServantHandle()
         }
         ++it;
     }
-
-
 }
 
 void ServantHandle::handleAsyncResponse()
@@ -741,6 +739,11 @@ void ServantHandle::handleTarsProtocol(const CurrentPtr &current)
         sResultDesc = "handleTarsProtocol unknown exception error";
     }
 
+	if(ret == TARSSERVERNOFUNCERR)
+	{
+		ret = sit->second->doNoFunc(current);
+	}
+	
     //单向调用或者业务不需要同步返回
     if (current->isResponse())
     {

+ 0 - 8
servant/libservant/ServantProxy.cpp

@@ -1085,7 +1085,6 @@ shared_ptr<ResponsePacket> ServantProxy::tars_invoke(char  cPacketType,
                               TarsOutputStream<BufferWriterVector>& buf,
                               const map<string, string>& context,
                               const map<string, string>& status)
-                            //   ResponsePacket& rsp)
 {
     ReqMessage * msg = new ReqMessage();
 
@@ -1101,19 +1100,12 @@ shared_ptr<ResponsePacket> ServantProxy::tars_invoke(char  cPacketType,
     msg->request.status       = status;
     msg->request.iTimeout     = _syncTimeout;
 
-//    // 在RequestPacket中的context设置主调信息
-//    if(_masterFlag)
-//    {
-//        msg->request.context.insert(std::make_pair(TARS_MASTER_KEY,ClientConfig::ModuleName));
-//    }
-
 	checkDye(msg->request);
 	checkTrace(msg->request);
 	checkCookie(msg->request);
 	servant_invoke(msg, false);
 
     shared_ptr<ResponsePacket> rsp = msg->response;
-    // rsp = msg->response;
 
 	delete msg;
 	msg = NULL;

+ 1 - 1
servant/servant/Current.h

@@ -257,7 +257,7 @@ public:
      * @param buff
      * @param len
      */
-    void sendPushResponse(int iRet, const string &funcName, TarsOutputStream<BufferWriterVector>& oss);
+    void sendPushResponse(int iRet, const string &funcName, TarsOutputStream<BufferWriterVector>& oss, const map<string, string> &context = tars::Current::TARS_STATUS());
     /**
      * 设置调用链追踪信息,服务端主动回包时用
      * @param traceCall

+ 7 - 0
servant/servant/Servant.h

@@ -165,6 +165,13 @@ public:
      */
 	virtual int doClose(CurrentPtr current){ return -1; }
 
+	/**
+	 * tars协议, 没有对应函数时会调用
+	 * @param current
+	 * @return
+	 */
+	virtual int doNoFunc(CurrentPtr current) {return  tars::TARSSERVERNOFUNCERR;}
+
     /**
      * 获得响应的数据队列
      * @return TC_ThreadQueue<ReqMessagePtr>& 

+ 2 - 1
tools/tars2cpp/tars2cpp.cpp

@@ -2619,6 +2619,7 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
 			s << ", ";
 			s << generateOutH(vParamDecl[i]);
 		}
+		s << ", const map<string, string> &_context = tars::Current::TARS_STATUS()";
 		s << ")" << endl;
 		s << TAB << "{" << endl;
 		INC_TAB;
@@ -2638,7 +2639,7 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
 
 			s << writeTo(vParamDecl[i]->getTypeIdPtr()) << endl;
 		}
-		s << TAB << "_current_->sendPushResponse( tars::TARSSERVERSUCCESS " << ",\"" << pPtr->getId() << "\"" << ", _os);" << endl;
+		s << TAB << "_current_->sendPushResponse( tars::TARSSERVERSUCCESS " << ",\"" << pPtr->getId() << "\"" << ", _os, _context);" << endl;
 
 		DEL_TAB;
 		s << TAB << "}" << endl;

+ 20 - 20
unit-test/server/Hello.h

@@ -3387,7 +3387,7 @@ namespace Test
             }
 
         }
-        static void async_response_push_testConHash(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &sOut)
+        static void async_response_push_testConHash(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &sOut, const map<string, string> &_context = tars::Current::TARS_STATUS())
         {
             {
                 tars::TarsOutputStream<tars::BufferWriterVector> _os;
@@ -3395,7 +3395,7 @@ namespace Test
 
                 _os.write(sOut, 1);
 
-                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testConHash", _os);
+                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testConHash", _os, _context);
             }
         }
 
@@ -3455,7 +3455,7 @@ namespace Test
             }
 
         }
-        static void async_response_push_testCoro(tars::CurrentPtr _current_, tars::Bool _ret, const std::string &sOut)
+        static void async_response_push_testCoro(tars::CurrentPtr _current_, tars::Bool _ret, const std::string &sOut, const map<string, string> &_context = tars::Current::TARS_STATUS())
         {
             {
                 tars::TarsOutputStream<tars::BufferWriterVector> _os;
@@ -3463,7 +3463,7 @@ namespace Test
 
                 _os.write(sOut, 2);
 
-                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testCoro", _os);
+                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testCoro", _os, _context);
             }
         }
 
@@ -3523,7 +3523,7 @@ namespace Test
             }
 
         }
-        static void async_response_push_testDyeing(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &strOut)
+        static void async_response_push_testDyeing(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &strOut, const map<string, string> &_context = tars::Current::TARS_STATUS())
         {
             {
                 tars::TarsOutputStream<tars::BufferWriterVector> _os;
@@ -3531,7 +3531,7 @@ namespace Test
 
                 _os.write(strOut, 2);
 
-                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testDyeing", _os);
+                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testDyeing", _os, _context);
             }
         }
 
@@ -3586,13 +3586,13 @@ namespace Test
             }
 
         }
-        static void async_response_push_testDyeingTrans(tars::CurrentPtr _current_, tars::Int32 _ret)
+        static void async_response_push_testDyeingTrans(tars::CurrentPtr _current_, tars::Int32 _ret, const map<string, string> &_context = tars::Current::TARS_STATUS())
         {
             {
                 tars::TarsOutputStream<tars::BufferWriterVector> _os;
                 _os.write(_ret, 0);
 
-                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testDyeingTrans", _os);
+                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testDyeingTrans", _os, _context);
             }
         }
 
@@ -3652,7 +3652,7 @@ namespace Test
             }
 
         }
-        static void async_response_push_testHello(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &r)
+        static void async_response_push_testHello(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &r, const map<string, string> &_context = tars::Current::TARS_STATUS())
         {
             {
                 tars::TarsOutputStream<tars::BufferWriterVector> _os;
@@ -3660,7 +3660,7 @@ namespace Test
 
                 _os.write(r, 3);
 
-                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testHello", _os);
+                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testHello", _os, _context);
             }
         }
 
@@ -3720,7 +3720,7 @@ namespace Test
             }
 
         }
-        static void async_response_push_testPid(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &r)
+        static void async_response_push_testPid(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &r, const map<string, string> &_context = tars::Current::TARS_STATUS())
         {
             {
                 tars::TarsOutputStream<tars::BufferWriterVector> _os;
@@ -3728,7 +3728,7 @@ namespace Test
 
                 _os.write(r, 1);
 
-                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testPid", _os);
+                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testPid", _os, _context);
             }
         }
 
@@ -3783,13 +3783,13 @@ namespace Test
             }
 
         }
-        static void async_response_push_testPushRegister(tars::CurrentPtr _current_, tars::Int32 _ret)
+        static void async_response_push_testPushRegister(tars::CurrentPtr _current_, tars::Int32 _ret, const map<string, string> &_context = tars::Current::TARS_STATUS())
         {
             {
                 tars::TarsOutputStream<tars::BufferWriterVector> _os;
                 _os.write(_ret, 0);
 
-                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testPushRegister", _os);
+                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testPushRegister", _os, _context);
             }
         }
 
@@ -3849,7 +3849,7 @@ namespace Test
             }
 
         }
-        static void async_response_push_testSyncTrans(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &r)
+        static void async_response_push_testSyncTrans(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &r, const map<string, string> &_context = tars::Current::TARS_STATUS())
         {
             {
                 tars::TarsOutputStream<tars::BufferWriterVector> _os;
@@ -3857,7 +3857,7 @@ namespace Test
 
                 _os.write(r, 3);
 
-                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testSyncTrans", _os);
+                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testSyncTrans", _os, _context);
             }
         }
 
@@ -3912,13 +3912,13 @@ namespace Test
             }
 
         }
-        static void async_response_push_testTimeout(tars::CurrentPtr _current_, tars::Int32 _ret)
+        static void async_response_push_testTimeout(tars::CurrentPtr _current_, tars::Int32 _ret, const map<string, string> &_context = tars::Current::TARS_STATUS())
         {
             {
                 tars::TarsOutputStream<tars::BufferWriterVector> _os;
                 _os.write(_ret, 0);
 
-                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testTimeout", _os);
+                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testTimeout", _os, _context);
             }
         }
 
@@ -3978,7 +3978,7 @@ namespace Test
             }
 
         }
-        static void async_response_push_testTrans(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &r)
+        static void async_response_push_testTrans(tars::CurrentPtr _current_, tars::Int32 _ret, const std::string &r, const map<string, string> &_context = tars::Current::TARS_STATUS())
         {
             {
                 tars::TarsOutputStream<tars::BufferWriterVector> _os;
@@ -3986,7 +3986,7 @@ namespace Test
 
                 _os.write(r, 3);
 
-                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testTrans", _os);
+                _current_->sendPushResponse( tars::TARSSERVERSUCCESS ,"testTrans", _os, _context);
             }
         }
 

+ 55 - 0
unit-test/util/test_tc_config.cpp

@@ -0,0 +1,55 @@
+#include "util/tc_config.h"
+#include "util/tc_common.h"
+#include <cmath>
+#include "gtest/gtest.h"
+
+#include <iostream>
+#include <vector>
+
+using namespace std;
+using namespace tars;
+
+class UtilConfigTest : public testing::Test
+{
+public:
+	//添加日志
+	static void SetUpTestCase()
+	{
+	}
+	static void TearDownTestCase()
+	{
+	}
+	virtual void SetUp()   //TEST跑之前会执行SetUp
+	{
+	}
+	virtual void TearDown() //TEST跑完之后会执行TearDown
+	{
+	}
+};
+
+#define CONFIG "<root>\r\n</root>"
+
+
+TEST_F(UtilConfigTest, config_test)
+{
+	TC_Config conf;
+	conf.parseString(CONFIG);
+
+	conf.set("/root<abc>", "def");
+
+	ASSERT_TRUE(conf.get("/root<abc>") == "def");
+
+	conf.set("/root/test<abc>", "defdef");
+
+	ASSERT_TRUE(conf.get("/root/test<abc>") == "defdef");
+
+	conf.erase("/root/test<abc>");
+
+	ASSERT_TRUE(conf.get("/root/test<abc>") == "");
+
+	conf.eraseDomain("/root/test");
+
+	auto v =conf.getDomainVector("/root");
+	ASSERT_TRUE(v.empty());
+
+}

+ 31 - 0
util/include/util/tc_config.h

@@ -159,6 +159,15 @@ public:
     */
     TC_ConfigDomain* addSubDomain(const string& name);
 
+	/**
+	 * @brief 删除子域
+	 * @brief Erase Subdomain Name
+    *
+    * @param domain               子域的指针
+    * @param domain               subdomain pointer
+	 */
+	void eraseSubTcConfigDomain(vector<string>::iterator itBegin, vector<string>::iterator itEnd);
+
     /**
     * @brief 递归搜索子域 Sub Domain. 
     * @brief Recursive search subdomain Sub Domain.
@@ -211,6 +220,12 @@ public:
     */
     void setParamValue(const string &sLine);
 
+	/**
+	 * @brief Delete Param, 删除参数
+	 * @param sName
+	 */
+	void eraseParamValue(const string &sName);
+
     /**
      * @brief 插入参数,把key里没有的配置项添加到最后 
      * @brief Insert a parameter to add a configuration item that is not in the key to the last
@@ -491,6 +506,22 @@ public:
      */
     void set(const string &sName, const string &value);
 
+	/**
+	 * @brief 删除值
+	 * @brief Delete value
+	 * @param sName, 参数名称,  例如: /Main/Domain<Param>
+	 * @param sName param name, like: /Main/Domain<Param>
+	 */
+	void erase(const string &sName);
+
+	/**
+	 * @brief 删除域
+	 * @brief Delete domain
+	 * @param sName, 参数名称,  例如: /Main/Domain
+	 * @param sName param name, like: /Main/Domain
+	 */
+	void eraseDomain(const string &sName);
+
     /**
     * @brief GetDomainParamMap获取域下面的参数值对. 
     * @brief GetDomainParamMap Get the parameter-value pair under the domain

Разница между файлами не показана из-за своего большого размера
+ 417 - 341
util/src/tc_config.cpp


Некоторые файлы не были показаны из-за большого количества измененных файлов