tahoma2d/toonz/sources/toonzfarm/include/service.h

89 lines
1.8 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef SERVICE_H
#define SERVICE_H
2016-04-14 22:15:09 +12:00
#include <memory>
2016-03-19 06:57:51 +13:00
class TFilePath;
#include <string>
#include <QString>
//------------------------------------------------------------------------------
#ifdef TFARMAPI
#undef TFARMAPI
#endif
2016-04-15 17:11:23 +12:00
#ifdef _WIN32
2016-03-19 06:57:51 +13:00
#ifdef TFARM_EXPORTS
#define TFARMAPI __declspec(dllexport)
#else
#define TFARMAPI __declspec(dllimport)
#endif
#else
#define TFARMAPI
#endif
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
bool ReportStatusToSCMgr(long currentState, long win32ExitCode, long WaitHint);
2016-03-19 06:57:51 +13:00
void AddToMessageLog(char *msg);
//------------------------------------------------------------------------------
TFARMAPI std::string getLastErrorText();
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class TFARMAPI TService {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TService(const std::string &name, const std::string &displayName);
virtual ~TService();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static TService *instance();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
enum Status {
Stopped = 1,
StartPending,
StopPending,
Running,
ContinuePending,
PausePending,
Paused
};
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setStatus(Status status, long exitCode, long waitHint);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
std::string getName() const;
std::string getDisplayName() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void run(int argc, char *argv[], bool console = false);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual void onStart(int argc, char *argv[]) = 0;
virtual void onStop() = 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isRunningAsConsoleApp() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static void start(const std::string &name);
static void stop(const std::string &name);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static void install(const std::string &name, const std::string &displayName,
const TFilePath &appPath);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static void remove(const std::string &name);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static void addToMessageLog(const std::string &msg);
static void addToMessageLog(const QString &msg);
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
class Imp;
std::unique_ptr<Imp> m_imp;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static TService *m_instance;
2016-03-19 06:57:51 +13:00
};
#endif