73 lines
1.7 KiB
C++
73 lines
1.7 KiB
C++
/**
|
|
* @file Application.h
|
|
* @brief Generic application interface
|
|
* @date Oct 1, 2015
|
|
* @author R.W.A. van der Heijden
|
|
* @copyright 2015 Dual Inventive Technology Centre B.V.
|
|
*
|
|
* Generic application interface. Applications must inherit from this application template
|
|
*/
|
|
#ifndef INCLUDE_DI_APPLICATION_H_
|
|
#define INCLUDE_DI_APPLICATION_H_
|
|
|
|
#include <string>
|
|
#include <memory>
|
|
#include <thread>
|
|
#include <di/Configuration.h>
|
|
|
|
#ifdef DEBUG_BUILD
|
|
#define DI_APPLICATION_DECL(classname) \
|
|
static classname appCls; \
|
|
Di::Application *Application__getInstance(void) { \
|
|
appCls.enableTesting = true; \
|
|
return dynamic_cast<Di::Application *>(&appCls); \
|
|
}
|
|
#else
|
|
#define DI_APPLICATION_DECL(classname) \
|
|
static classname appCls; \
|
|
Di::Application *Application__getInstance(void) { \
|
|
appCls.enableTesting = false; \
|
|
return dynamic_cast<Di::Application *>(&appCls); \
|
|
}
|
|
#endif
|
|
|
|
namespace Di {
|
|
|
|
/**
|
|
* @class Application
|
|
*
|
|
* Generic application interface
|
|
*/
|
|
class Application {
|
|
public:
|
|
virtual ~Application();
|
|
|
|
std::shared_ptr<Di::Configuration> getConfiguration(int argc, char *argv[]);
|
|
void globalInit(int argc, char *argv[]);
|
|
int runner(void);
|
|
|
|
virtual void loadDefaultConfig(void) = 0;
|
|
virtual int init(void) = 0;
|
|
virtual int run(void) = 0;
|
|
virtual void stop(void) = 0;
|
|
virtual std::string getApplicationName(void) = 0;
|
|
virtual std::string getApplicationVersion(void) = 0;
|
|
|
|
bool enableTesting;
|
|
|
|
protected:
|
|
std::shared_ptr<Configuration> _cfg;
|
|
|
|
private:
|
|
void __childRunner(void);
|
|
|
|
pid_t __parentPid;
|
|
int __childExitCode;
|
|
std::string __childApplicationName;
|
|
std::shared_ptr<std::thread> __childApplication;
|
|
};
|
|
|
|
} // namespace Di
|
|
|
|
#endif // INCLUDE_DI_APPLICATION_H_
|