#ifndef _DCAPP_SERVICE_H_ #define _DCAPP_SERVICE_H_ #include #include class IService{ public: /** * 服务初始化 */ virtual int Init(void *pData) = 0; /** * 执行业务(业务循环) while(1){doSomeThings...} */ virtual void Exec() = 0; /** * 获取服务名称 * @return */ virtual const char* getServiceName() = 0; }; class ServiceFactovy{ public: static std::map& getServiceMap(){ static std::map serviceMap; return serviceMap; } }; #define REGISTER_SERVICE(className) \ struct className##Register { \ className##Register() { \ ServiceFactovy::getServiceMap()[#className] = new className(); \ } \ } className##RegisterInstance; #endif // _DCAPP_SERVICE_H_