Files
dcapp/service.h
2025-02-24 08:57:55 +08:00

42 lines
879 B
C++

#ifndef _DCAPP_SERVICE_H_
#define _DCAPP_SERVICE_H_
#include <map>
#include <string>
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<std::string, IService*>& getServiceMap(){
static std::map<std::string, IService*> serviceMap;
return serviceMap;
}
};
#define REGISTER_SERVICE(className) \
struct className##Register { \
className##Register() { \
ServiceFactovy::getServiceMap()[#className] = new className(); \
} \
} className##RegisterInstance;
#endif // _DCAPP_SERVICE_H_