#ifndef __UT_DDS_SERVICE_HPP__ #define __UT_DDS_SERVICE_HPP__ #include #include #include namespace unitree { namespace common { class DdsService : public ServiceBase { public: DdsService() { mLogger = GetLogger("/unitree/service/dds_service"); mQuit = false; } virtual ~DdsService() {} virtual void Register() {} virtual void Init() {} virtual void Start() {} virtual void Wait() { while (!mQuit) { sleep(1); } } virtual void Stop() { mQuit = true; } public: void Parse(const std::string& configFileName) { ServiceBase::Parse(configFileName); LOG_INFO(mLogger, "parse config success. filename:", configFileName); mModel.Init(AnyCast(GetGlobalParameter("DdsParameter"))); LOG_INFO(mLogger, "parse init dds model success."); } protected: template void RegistTopicMessageHandler(const std::string& topic, const DdsMessageHandler& handler) { mModel.SetTopic(topic, handler); LOG_INFO(mLogger, "regist topic reader callback. topic:", topic); } template void RegistTopic(const std::string& topic) { mModel.SetTopic(topic); LOG_INFO(mLogger, "regist topic. topic:", topic); } /* * Write message to topic */ template void WriteMessage(const std::string& topic, const MSG& message) { mModel.WriteMessage(topic, message); } private: bool mQuit; DdsEasyModel mModel; Logger* mLogger; }; } } #endif//__UT_DDS_SERVICE_HPP__