zxs пре 2 недеља
родитељ
комит
ddb3bebaa6

+ 4 - 4
CMakeLists.txt

@@ -21,8 +21,8 @@ elseif(UNIX)
     add_definitions(-DLINUX_BUILD)
 endif()
 # 包含子项目。
-# add_subdirectory ("robot")
-# add_subdirectory ("logger")
-# add_subdirectory ("drivers")
-# add_subdirectory ("generator")
+add_subdirectory ("robot")
+add_subdirectory ("logger")
+add_subdirectory ("drivers")
+add_subdirectory ("generator")
 add_subdirectory ("message_bus")

BIN
lib/windows/logger/logger.dll


BIN
lib/windows/logger/logger.lib


+ 1 - 0
logger/CMakeLists.txt

@@ -25,6 +25,7 @@ endif()
 
 if (WIN32)
     target_link_libraries(logger rttr_core libcrypto libssl Crypt32)
+    add_definitions(-DLOGGER_EXPORTS)
 elseif(IOS)
 elseif(UNIX)
     target_link_libraries(logger pthread rttr_core)

+ 8 - 13
logger/logger_impl.h

@@ -1,10 +1,12 @@
 #pragma once
 #ifdef WINDOWS_BUILD
-#ifdef LOGGERIMPL_EXPORTS
-#define LOGGER_IMPL _declspec(dllexport)
+#ifdef LOGGER_EXPORTS
+#define LOGGER_API _declspec(dllexport)
 #else
-#define LOGGER_IMPL _declspec(dllimport)
+#define LOGGER_API _declspec(dllimport)
 #endif
+#elif LINUX_BUILD
+#define LOGGER_API
 #endif
 //stl
 #include <iostream>
@@ -18,11 +20,7 @@
 #include "../robot/robotics/config.hpp"
 
 namespace robotics::v3 {
-#ifdef WINDOWS_BUILD
-	class LOGGER_IMPL logger_impl {
-#elif LINUX_BUILD
-	class logger_impl {
-#endif
+	class LOGGER_API logger_impl {
 	public:
 		~logger_impl();
 		void write(int color, std::string const& type, std::string const& time, std::string const& file, std::string const& func, int line, std::thread::id thread_id, std::string const& text);
@@ -38,11 +36,8 @@ namespace robotics::v3 {
 		std::set<std::string> save_;
 		asio::thread_pool thread_pool_;
 	};
-#ifdef WINDOWS_BUILD
-	class LOGGER_IMPL logger_stream {
-#elif LINUX_BUILD
-	class logger_stream {
-#endif
+
+	class LOGGER_API logger_stream {
 	public:
 		explicit logger_stream(int color, std::string const& type, std::string const& time, std::string const& file, std::string const& func, int line, std::thread::id thread_id);
 		~logger_stream();

+ 1 - 0
message_bus/CMakeLists.txt

@@ -20,6 +20,7 @@ endif()
 
 if (WIN32)
     target_link_libraries(message_bus)
+    add_definitions(-DMESSAGE_BUS_EXPORTS)
 elseif(IOS)
 elseif(UNIX)
     target_link_libraries(message_bus pthread)

+ 5 - 7
message_bus/message_bus_impl.h

@@ -1,10 +1,12 @@
 #pragma once
 #ifdef WINDOWS_BUILD
 #ifdef MESSAGE_BUS_EXPORTS
-#define MESSAGE_BUS_IMPL _declspec(dllexport)
+#define MESSAGE_BUS_API _declspec(dllexport)
 #else
-#define MESSAGE_BUS_IMPL _declspec(dllimport)
+#define MESSAGE_BUS_API _declspec(dllimport)
 #endif
+#elif LINUX_BUILD
+#define MESSAGE_BUS_API
 #endif
 //stl
 #include <map>
@@ -13,11 +15,7 @@
 #include <functional>
 
 namespace robotics::v3 {
-#ifdef WINDOWS_BUILD
-	class MESSAGE_BUS_IMPL message_bus_impl {
-#elif LINUX_BUILD
-	class message_bus_impl {
-#endif
+	class MESSAGE_BUS_API message_bus_impl {
 	public:
 		/**
 		 * @brief µ¥Àý

+ 37 - 46
robot/robotics/logger_impl.h

@@ -1,10 +1,12 @@
 #pragma once
 #ifdef WINDOWS_BUILD
-#ifdef LOGGERIMPL_EXPORTS
-#define LOGGER_IMPL _declspec(dllexport)
+#ifdef LOGGER_EXPORTS
+#define LOGGER_API _declspec(dllexport)
 #else
-#define LOGGER_IMPL _declspec(dllimport)
+#define LOGGER_API _declspec(dllimport)
 #endif
+#elif LINUX_BUILD
+#define LOGGER_API
 #endif
 //stl
 #include <iostream>
@@ -13,49 +15,38 @@
 //boost
 #include <asio.hpp>
 //robotics
-#include "datetime.hpp"
 #include "text_stream.hpp"
-#include "config.hpp"
 
-namespace robotics {
-	namespace v3 {
-#ifdef WINDOWS_BUILD
-		class LOGGER_IMPL logger_impl {
-#elif LINUX_BUILD
-		class logger_impl {
-#endif
-		public:
-			~logger_impl();
-			void write(int color, std::string const& type, std::string const& time, std::string const& file, std::string const& func, int line, std::thread::id thread_id, std::string const& text);
-			static logger_impl& instance();
-			static void install(std::string const& filename = "./config/config.ini");
-		private:
-			explicit logger_impl();
-			void backup(std::string const& filename);
-			void remove();
-		private:
-			int max_time_ = 30;
-			int max_size_ = 10;
-			std::set<std::string> save_;
-			asio::thread_pool thread_pool_;
-		};
-#ifdef WINDOWS_BUILD
-		class LOGGER_IMPL logger_stream {
-#elif LINUX_BUILD
-		class logger_stream {
-#endif
-		public:
-			explicit logger_stream(int color, std::string const& type, std::string const& time, std::string const& file, std::string const& func, int line, std::thread::id thread_id);
-			~logger_stream();
-			text_stream stream;
-		private:
-			std::string type_;
-			std::string time_;
-			std::string file_;
-			std::string func_;
-			int line_ = 0;
-			int color_ = 37;
-			std::thread::id thread_id_;
-		};
-	}
+namespace robotics::v3 {
+	class LOGGER_API logger_impl {
+	public:
+		~logger_impl();
+		void write(int color, std::string const& type, std::string const& time, std::string const& file, std::string const& func, int line, std::thread::id thread_id, std::string const& text);
+		static logger_impl& instance();
+		static void install(std::string const& filename = "./config/config.ini");
+	private:
+		explicit logger_impl();
+		void backup(std::string const& filename);
+		void remove();
+	private:
+		int max_time_ = 30;
+		int max_size_ = 10;
+		std::set<std::string> save_;
+		asio::thread_pool thread_pool_;
+	};
+
+	class LOGGER_API logger_stream {
+	public:
+		explicit logger_stream(int color, std::string const& type, std::string const& time, std::string const& file, std::string const& func, int line, std::thread::id thread_id);
+		~logger_stream();
+		text_stream stream;
+	private:
+		std::string type_;
+		std::string time_;
+		std::string file_;
+		std::string func_;
+		int line_ = 0;
+		int color_ = 37;
+		std::thread::id thread_id_;
+	};
 }

+ 79 - 8
robot/robotics/message_bus.hpp

@@ -47,6 +47,19 @@ namespace robotics {
 				auto func = v3::to_function(std::forward<_Fn>(f));
 				return add(str_topic, observer, std::move(func));
 			}
+			/**
+			 * @brief 注册消息
+			 * @tparam _Fn 
+			 * @param str_app 
+			 * @param str_topic 
+			 * @param observer 
+			 * @param f 
+			 * @return 
+			 */
+			template<typename _Fn>
+			bool bind(std::string const& str_app, std::string const& str_topic, bool observer, _Fn&& f) {
+				return bind<_Fn>(str_app + "_" + str_topic, observer, std::forward<_Fn>(f));
+			}
 			/**
 			 * @brief 注册消息
 			 * @tparam _Fn 
@@ -58,13 +71,31 @@ namespace robotics {
 			 * @return 
 			 */
 			template<typename _Fn, typename _Obj>
-			bool bind(const std::string& str_topic, bool observer, _Fn&& f, _Obj&& obj) {
+			bool bind(std::string const& str_topic, bool observer, _Fn&& f, _Obj&& obj) {
 				auto func = v3::to_function((v3::function_traits<_Fn>::stl_function_type)(std::bind_front(std::forward<_Fn>(f), std::forward<_Obj>(obj))));
 				return add(str_topic, observer, std::move(func));
 			}
+			/**
+			 * @brief 注册消息
+			 * @tparam _Fn 
+			 * @tparam _Obj 
+			 * @param str_app 
+			 * @param str_topic 
+			 * @param observer 
+			 * @param f 
+			 * @param obj 
+			 * @return 
+			 */
+			template<typename _Fn, typename _Obj>
+			bool bind(std::string const& str_app, std::string const& str_topic, bool observer, _Fn&& f, _Obj&& obj) {
+				return bind<_Fn, _Obj>(str_app + "_" + str_topic, observer, std::forward<_Fn>(f), std::forward<_Obj>(obj));
+			}
 			/**
 			 * @brief 发送消息
-			 * @param str_topic
+			 * @tparam _Ret 
+			 * @tparam _BCast 
+			 * @param str_topic 
+			 * @return 
 			 */
 			template<typename _Ret,bool _BCast = false>
 			_Ret invoke(const std::string& str_topic) {
@@ -96,9 +127,24 @@ namespace robotics {
 			}
 			/**
 			 * @brief 发送消息
-			 * @tparam ..._Args
-			 * @param str_topic
-			 * @param ...args
+			 * @tparam _Ret 
+			 * @tparam _BCast 
+			 * @param str_app 
+			 * @param str_topic 
+			 * @return 
+			 */
+			template<typename _Ret, bool _BCast = false>
+			_Ret call(std::string const& str_app, std::string const& str_topic) {
+				return invoke<_Ret, _BCast>(str_app + "_" + str_topic);
+			}
+			/**
+			 * @brief 发送消息
+			 * @tparam ..._Args 
+			 * @tparam _Ret 
+			 * @tparam _BCast 
+			 * @param str_topic 
+			 * @param ...args 
+			 * @return 
 			 */
 			template<typename _Ret, bool _BCast = false,typename... _Args>
 			_Ret invoke(const std::string& str_topic, _Args ...args) {
@@ -128,17 +174,42 @@ namespace robotics {
 					return result;
 				}
 			}
+			/**
+			 * @brief 发送消息
+			 * @tparam _Ret 
+			 * @tparam ..._Args 
+			 * @tparam _BCast 
+			 * @param str_app 
+			 * @param str_topic 
+			 * @param ...args 
+			 * @return 
+			 */
+			template<typename _Ret, bool _BCast = false, typename... _Args>
+			_Ret call(std::string const& str_app, std::string const& str_topic, _Args ...args) {
+				return invoke<_Ret, _BCast, _Args...>(str_app + "_" + str_topic, std::forward<_Args>(args)...);
+			}
 			/**
 			 * @brief 移除某个主题,需要主题和消息类型
 			 * @tparam ...Args
 			 * @param strTopic
 			 */
-			template<typename..._Args>
-			void remove(const std::string& str_topic) {
-				using function_type = std::function<void(_Args...)>;
+			template<typename _Ret,typename..._Args>
+			void remove(std::string const& str_topic) {
+				using function_type = std::function<_Ret(_Args...)>;
 				std::string str_msg_type = str_topic + typeid(function_type).name();
 				message_bus_impl_->remove(str_msg_type);
 			}
+			/**
+			 * @brief 移除某个主题,需要主题和消息类型
+			 * @tparam _Ret 
+			 * @tparam ..._Args 
+			 * @param str_app 
+			 * @param str_topic 
+			 */
+			template<typename _Ret, typename..._Args>
+			void remove(std::string const& str_app, std::string const& str_topic) {
+				remove<_Ret, _Args...>(str_app + "_" + str_topic);
+			}
 		private:
 			/**
 			 * @brief 单个添加

+ 5 - 7
robot/robotics/message_bus_impl.h

@@ -1,10 +1,12 @@
 #pragma once
 #ifdef WINDOWS_BUILD
 #ifdef MESSAGE_BUS_EXPORTS
-#define MESSAGE_BUS_IMPL _declspec(dllexport)
+#define MESSAGE_BUS_API _declspec(dllexport)
 #else
-#define MESSAGE_BUS_IMPL _declspec(dllimport)
+#define MESSAGE_BUS_API _declspec(dllimport)
 #endif
+#elif LINUX_BUILD
+#define MESSAGE_BUS_API
 #endif
 //stl
 #include <map>
@@ -13,11 +15,7 @@
 #include <functional>
 
 namespace robotics::v3 {
-#ifdef WINDOWS_BUILD
-	class MESSAGE_BUS_IMPL message_bus_impl {
-#elif LINUX_BUILD
-	class message_bus_impl {
-#endif
+	class MESSAGE_BUS_API message_bus_impl {
 	public:
 		/**
 		 * @brief µ¥Àý