Bläddra i källkod

Revert "Revert "Z991239-1017 #comment fea 添加guitask,在测试模式提供获取session功能""

This reverts commit f8d51ca55dbc59e0ff61055eb94847cb8004bc39.
陈良瑜80374463 4 år sedan
förälder
incheckning
c3d748d0ec

+ 6 - 3
Module/mod_chromium/CMakeLists.txt

@@ -2,6 +2,8 @@
 define_module("chromium")
 
 file(GLOB REQUESTS_CPP_SRCS ${ThirdPartyHeadRoot}/requests/requests/*.cpp)
+file(GLOB PORTCHECK_SRCS portCheck/*)
+file(GLOB GUITASK_SRCS guitask/*)
 
 MESSAGE( STATUS "REQUESTS_CPP_SRCS = ${REQUESTS_CPP_SRCS}")
 
@@ -40,8 +42,8 @@ set(${MODULE_PREFIX}_SRCS
 	mod_chromium.h
 	processControl.cpp
 	processControl.h
-	portCheck/portCheck.h
-	portCheck/portCheck.cpp
+	${PORTCHECK_SRCS}
+	${GUITASK_SRCS}
 	${ThirdPartyHeadRoot}/CJson/cJSON.c
 	${ThirdPartyHeadRoot}/modp_b64/modp_b64.cc
 	${ThirdPartyHeadRoot}/tinyxml2/tinyxml2.cpp
@@ -68,7 +70,6 @@ BASIC_SETUP CMAKE_TARGETS
 BUILD missing)
 
 MESSAGE( STATUS "BOOST_ROOT = ${CONAN_BOOST_ROOT}")
-#set(BOOST_ROOT /home/pcacc/Desktop/boost_1_69_0)
 set(BOOST_ROOT ${CONAN_BOOST_ROOT})
 
 set(Boost_DEBUG ON)
@@ -102,6 +103,8 @@ target_include_directories(${MODULE_NAME} PRIVATE
 	${ThirdPartyHeadRoot}/modp_b64
 	${ThirdPartyHeadRoot}/requests/include
 	${CONAN_RVCFRAMEWORK_ROOT}/include
+	${ThirdPartyHeadRoot}/rpcServer
+	${ThirdPartyHeadRoot}/msgpack
 	
 )
 # 添加实体需要依赖的其他共享库(包括系统库):连接器包含的包

+ 28 - 25
Module/mod_chromium/CWSCodec.cpp

@@ -825,6 +825,26 @@ void CWSCodec::SerializeGetVarReq(cJSON* js, char* data, int* wpos, int* capacit
 void CWSCodec::GeneralSerialize(cJSON* js, char* data, int* wpos, int* capacity, CMedthodInterface* pI, char* errmsg){
 	std::list<CMethodParam>::iterator it = pI->mRequestInterpreter.mParamList.begin();
 
+	auto dealBlob = [](CSimpleString src, char* bin)->std::pair <int, std::string> {
+		if (!is_base64(src))
+			return std::make_pair(-1, "base64 decode failed!");
+
+		int binlen = modp_b64_decode_len(src.GetLength()) - 1;//二进制流,不需要结束
+
+		if (binlen > 0)
+		{
+			bin = new char[binlen + 1];
+			ZeroMemory(bin, binlen + 1);
+			modp_b64_decode(bin, src.GetData(), src.GetLength());//binlen有可能比bin长
+			short objectNum = *((short*)bin);
+			int extendLen = 2 + objectNum * 2;
+			int dstLen = binlen - (binlen - extendLen) % 4;
+			return std::make_pair(dstLen, "");
+		}
+		else
+			return std::make_pair(-1, "error binlen");
+	};
+
 	while(it != pI->mRequestInterpreter.mParamList.end()){
 		if (it->mType == "int")
 		{
@@ -950,28 +970,11 @@ void CWSCodec::GeneralSerialize(cJSON* js, char* data, int* wpos, int* capacity,
 		}
 		else if (it->mType == "blob")
 		{
-			CSimpleStringA d = "";
-			GetCJsonObjectValue(js, it->mName.c_str(), d, errmsg);
-
-			auto dealBlob = [](CSimpleString src, char* bin)->std::pair <int, std::string> {
-				if (!is_base64(src))
-					return std::make_pair(-1, "base64 decode failed!");
+		CSimpleStringA d = "";
+		GetCJsonObjectValue(js, it->mName.c_str(), d, errmsg);
+		/*
 
-				int binlen = modp_b64_decode_len(src.GetLength()) - 1;//二进制流,不需要结束
-
-				if (binlen > 0)
-				{
-					bin = new char[binlen + 1];
-					ZeroMemory(bin, binlen + 1);
-					modp_b64_decode(bin, src.GetData(), src.GetLength());//binlen有可能比bin长
-					short objectNum = *((short*)bin);
-					int extendLen = 2 + objectNum * 2;
-					int dstLen = binlen - (binlen - extendLen) % 4;
-					return std::make_pair(dstLen, "");
-				}
-				else
-					return std::make_pair(-1, "error binlen");
-			};
+			
 
 			char* bin = NULL;
 			auto dealret = dealBlob(d, bin);
@@ -982,8 +985,8 @@ void CWSCodec::GeneralSerialize(cJSON* js, char* data, int* wpos, int* capacity,
 			}
 			else
 				DbgEx("Blob:dealBlob error:%d, %s", dealret.first, dealret.second.c_str());
-
-			/*
+				*/
+			
 			if(!is_base64(d)){
 				strcat(errmsg, "base64 decode failed!");
 				++it;
@@ -1013,8 +1016,8 @@ void CWSCodec::GeneralSerialize(cJSON* js, char* data, int* wpos, int* capacity,
 				
 				delete[]bin;
 				bin = NULL;
-			}	
-			*/
+			}
+			
 		}
 		else if (it->mType == "array_blob") {
 			int len = 0;

+ 2 - 2
Module/mod_chromium/EntitySessionManager.h

@@ -54,10 +54,10 @@ public:
 	bool checkBeginSession(std::string entityName);
 	void StoreSessionReq(int transid, std::string entityname);
 	std::vector<std::string> queryUnLinkSession();
-	std::map<std::string, int> queryAllSessionInfo();
+	static std::map<std::string, int> queryAllSessionInfo();
 private:
 	
-	std::map<std::string, int> m_session_map;	// entity name -> session id
+	static std::map<std::string, int> m_session_map;	// entity name -> session id
 	std::map<int, WSClientReqInfo> m_trans_map;	// real trans id -> client trans id & client ws connection handler	
 	std::map<int, std::string> m_session_ack_map;	// trans id -> entity name	
 	std::map<std::string, int> m_broadcast_map;	// broadcast list

+ 23 - 0
Module/mod_chromium/guitask/format.hpp

@@ -0,0 +1,23 @@
+#include "boost/format.hpp"
+#include <iostream>
+
+template<class TFirst>
+void string_format(boost::format& fmt, TFirst&& first)
+{
+    fmt% first;
+}
+
+template<class TFirst, class... TOther>
+void string_format(boost::format& fmt, TFirst&& first, TOther&&... other)
+{
+    fmt% first;
+    string_format(fmt, other...);
+}
+
+template<class TFirst, class... TOther>
+std::string string_format(const char* format, TFirst&& first, TOther&&... other)
+{
+    boost::format fmt(format);
+    string_format(fmt, first, other...);
+    return fmt.str();
+}

+ 68 - 0
Module/mod_chromium/guitask/guitask.cpp

@@ -0,0 +1,68 @@
+
+#include "SpBase.h"
+#include "guitask.h"
+#include "EntitySessionManager.h"
+
+struct callback_entry : public IReleasable
+{
+	virtual ~callback_entry() {}
+
+	CSimpleStringA EntityName;
+	union {
+		void* pRawData;
+		int state;
+	};
+	int op;
+	ErrorCodeEnum ErrorResult;
+};
+
+#define OP_START_ENTITY		1
+#define OP_STOP_ENTITY		0
+#define OP_PAUSE_ENTITY		2
+#define OP_TERMINATE_ENTITY 3
+#define OP_CONTINUE_ENTITY	4
+#define OP_FIRE_ENTITY_STATE		5
+
+chromiumRpcTask::chromiumRpcTask()
+{
+}
+
+chromiumRpcTask::~chromiumRpcTask()
+{
+}
+chromiumRpcTask g_task;
+
+namespace rpcFunc
+{
+	AllSessionMap GetAllSessionInfo(rpc_conn conn)
+	{
+		auto sessionMap = Chromium::EntitySessionManager::queryAllSessionInfo();
+		AllSessionMap ret;
+		ret.sessionMap = sessionMap;
+	}
+
+
+}
+
+using namespace rpcFunc;
+
+
+
+bool chromiumRpcTask::openrpcServer(int port)
+{
+	std::thread thd([&] {
+		m_server.reset(new rpc_server(port, std::thread::hardware_concurrency()));
+
+		m_server->register_handler("GetAllSessionInfo", GetAllSessionInfo);
+
+		m_server->run();
+	});
+
+	thd.detach();
+	Dbg("rpc start, async run");
+
+	return true;
+}
+
+
+

+ 38 - 0
Module/mod_chromium/guitask/guitask.h

@@ -0,0 +1,38 @@
+#ifndef __GUI_TASK_H
+#define __GUI_TASK_H
+
+#pragma once
+
+#include "rpc_server.h"
+using namespace rest_rpc;
+using namespace rpc_service;
+#include <fstream>
+#include <memory>
+#include <vector>
+
+#define DEFAULT_CHROMIUM_RPCPORT 9000
+
+struct AllSessionMap {
+	std::map<std::string, int> sessionMap;
+
+	MSGPACK_DEFINE(sessionMap);
+};
+
+
+
+class chromiumRpcTask
+{
+public:
+	chromiumRpcTask();
+	virtual ~chromiumRpcTask();
+
+	//rpc call function
+	bool openrpcServer(int port);
+
+private:
+	std::unique_ptr<rpc_server> m_server;
+};
+
+extern chromiumRpcTask g_task;
+
+#endif // __GUI_TASK_H

+ 31 - 0
Module/mod_chromium/guitask/qps.h

@@ -0,0 +1,31 @@
+#pragma once
+#include <atomic>
+#include <thread>
+#include <chrono>
+
+class qps {
+public:
+	void increase() {
+		counter_.fetch_add(1, std::memory_order_release);
+	}
+
+	qps() : counter_(0) {
+		thd_ = std::thread([this] {
+			while (!stop_) {
+				std::cout << "qps: " << counter_.load(std::memory_order_acquire) << '\n';
+				std::this_thread::sleep_for(std::chrono::seconds(1));
+				//counter_.store(0, std::memory_order_release);
+			}
+		});
+	}
+
+	~qps() {
+		stop_ = true;
+		thd_.join();
+	}
+
+private:
+	bool stop_ = false;
+	std::thread thd_;
+	std::atomic<uint32_t> counter_;
+};

+ 3 - 0
Module/mod_chromium/mod_chromium.cpp

@@ -16,6 +16,7 @@
 #include <boost/chrono.hpp>
 #include <boost/bind.hpp>
 #include "path.h"
+#include "guitask/guitask.h"
 
 
 #define COMPKEY_TERMINATE ((UINT_PTR) 0)
@@ -145,6 +146,8 @@ void CChromiumEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointe
 
 	if (sysruninfo.dwBootOption != SystemBootOptionEnum::BootOption_Test)
 		generateCefclientTimer();//非--test时,才会打开浏览器
+	else
+		g_task.openrpcServer(DEFAULT_CHROMIUM_RPCPORT);
 
 	// 按照单屏方式
 	pTransactionContext->SendAnswer(Error_Succeed);