You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.3 KiB
C
79 lines
2.3 KiB
C
|
5 years ago
|
/*!
|
||
|
|
* \file CyclopsModules.h
|
||
|
|
* \date 2019/11/05
|
||
|
|
*
|
||
|
|
* \author Lin, Chi
|
||
|
|
* Contact: lin.chi@hzleaper.com
|
||
|
|
*
|
||
|
|
*
|
||
|
|
* \note
|
||
|
|
*/
|
||
|
|
|
||
|
|
#ifndef __CyclopsModules_h_
|
||
|
|
#define __CyclopsModules_h_
|
||
|
|
|
||
|
|
#include "CyclopsCommon.h"
|
||
|
|
#include "CyclopsVersion.h"
|
||
|
|
#include <memory>
|
||
|
|
class ICyclopsModule;
|
||
|
|
|
||
|
|
class ICyclopsModuleInstance
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
virtual ~ICyclopsModuleInstance() = 0;
|
||
|
|
typedef std::shared_ptr<ICyclopsModuleInstance> Ptr;
|
||
|
|
};
|
||
|
|
|
||
|
|
class CyclopsModules
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
static bool registerModule(const char* moduleName, ICyclopsModule* moduleFactory);
|
||
|
|
static ICyclopsModule* getModule(const char* moduleName);
|
||
|
|
static CYCLOPS_DLLSPEC ICyclopsModuleInstance::Ptr getManagedInstance(const char* moduleName, const char* instanceName);
|
||
|
|
static CYCLOPS_DLLSPEC bool deleteManagedInstance(const char* moduleName, const char* instanceName);
|
||
|
|
static CYCLOPS_DLLSPEC bool updateManagedInstance(const char* moduleName, const char* instanceName, ICyclopsModuleInstance::Ptr newInstance);
|
||
|
|
static CYCLOPS_DLLSPEC ICyclopsModuleInstance::Ptr getStandaloneInstance(const char* moduleName);
|
||
|
|
};
|
||
|
|
|
||
|
|
#include <string>
|
||
|
|
template<typename T>
|
||
|
|
inline std::shared_ptr<T> GetModuleInstance(const std::string& instanceName) {
|
||
|
|
#ifdef CYCLOPS_LIB
|
||
|
|
return T::getInstance(instanceName);
|
||
|
|
#else
|
||
|
|
return std::dynamic_pointer_cast<T, ICyclopsModuleInstance>(CyclopsModules::getManagedInstance(
|
||
|
|
typeid(T).name(), instanceName.c_str()));
|
||
|
|
#endif // CYCLOPS_LIB
|
||
|
|
}
|
||
|
|
|
||
|
|
template<typename T>
|
||
|
|
inline bool DeleteModuleInstance(const std::string& instanceName) {
|
||
|
|
#ifdef CYCLOPS_LIB
|
||
|
|
return T::deleteInstance(instanceName);
|
||
|
|
#else
|
||
|
|
return CyclopsModules::deleteManagedInstance(typeid(T).name(), instanceName.c_str());
|
||
|
|
#endif // CYCLOPS_LIB
|
||
|
|
}
|
||
|
|
|
||
|
|
template<typename T>
|
||
|
|
inline bool UpdateModuleInstance(const std::string& instanceName, std::shared_ptr<T> newInstance) {
|
||
|
|
#ifdef CYCLOPS_LIB
|
||
|
|
return T::updateInstance(instanceName);
|
||
|
|
#else
|
||
|
|
return CyclopsModules::updateManagedInstance(typeid(T).name(), instanceName.c_str(),
|
||
|
|
std::static_pointer_cast<ICyclopsModuleInstance, T>(newInstance));
|
||
|
|
#endif // CYCLOPS_LIB
|
||
|
|
}
|
||
|
|
|
||
|
|
template<typename T>
|
||
|
|
inline std::shared_ptr<T> GetModuleInstance() {
|
||
|
|
#ifdef CYCLOPS_LIB
|
||
|
|
return std::make_shared<T>();
|
||
|
|
#else
|
||
|
|
return std::dynamic_pointer_cast<T, ICyclopsModuleInstance>(CyclopsModules::getStandaloneInstance(typeid(T).name()));
|
||
|
|
#endif // CYCLOPS_LIB
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif // CyclopsModules_h_
|
||
|
|
|