| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: BackupStoreDaemon.h |
|---|
| 5 | // Purpose: Backup store daemon |
|---|
| 6 | // Created: 2003/08/20 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef BACKUPSTOREDAEMON__H |
|---|
| 11 | #define BACKUPSTOREDAEMON__H |
|---|
| 12 | |
|---|
| 13 | #include "ServerTLS.h" |
|---|
| 14 | #include "BoxPortsAndFiles.h" |
|---|
| 15 | #include "BackupConstants.h" |
|---|
| 16 | #include "BackupStoreContext.h" |
|---|
| 17 | #include "HousekeepStoreAccount.h" |
|---|
| 18 | #include "IOStreamGetLine.h" |
|---|
| 19 | |
|---|
| 20 | class BackupStoreAccounts; |
|---|
| 21 | class BackupStoreAccountDatabase; |
|---|
| 22 | |
|---|
| 23 | // -------------------------------------------------------------------------- |
|---|
| 24 | // |
|---|
| 25 | // Class |
|---|
| 26 | // Name: BackupStoreDaemon |
|---|
| 27 | // Purpose: Backup store daemon implementation |
|---|
| 28 | // Created: 2003/08/20 |
|---|
| 29 | // |
|---|
| 30 | // -------------------------------------------------------------------------- |
|---|
| 31 | class BackupStoreDaemon : public ServerTLS<BOX_PORT_BBSTORED>, |
|---|
| 32 | HousekeepingInterface, HousekeepingCallback |
|---|
| 33 | { |
|---|
| 34 | public: |
|---|
| 35 | BackupStoreDaemon(); |
|---|
| 36 | ~BackupStoreDaemon(); |
|---|
| 37 | private: |
|---|
| 38 | BackupStoreDaemon(const BackupStoreDaemon &rToCopy); |
|---|
| 39 | public: |
|---|
| 40 | |
|---|
| 41 | // For BackupStoreContext to communicate with housekeeping process |
|---|
| 42 | void SendMessageToHousekeepingProcess(const void *Msg, int MsgLen) |
|---|
| 43 | { |
|---|
| 44 | #ifndef WIN32 |
|---|
| 45 | mInterProcessCommsSocket.Write(Msg, MsgLen); |
|---|
| 46 | #endif |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | protected: |
|---|
| 50 | |
|---|
| 51 | virtual void SetupInInitialProcess(); |
|---|
| 52 | |
|---|
| 53 | virtual void Run(); |
|---|
| 54 | |
|---|
| 55 | virtual void Connection(SocketStreamTLS &rStream); |
|---|
| 56 | void Connection2(SocketStreamTLS &rStream); |
|---|
| 57 | |
|---|
| 58 | virtual const char *DaemonName() const; |
|---|
| 59 | virtual std::string DaemonBanner() const; |
|---|
| 60 | |
|---|
| 61 | const ConfigurationVerify *GetConfigVerify() const; |
|---|
| 62 | |
|---|
| 63 | // Housekeeping functions |
|---|
| 64 | void HousekeepingProcess(); |
|---|
| 65 | |
|---|
| 66 | void LogConnectionStats(uint32_t accountId, |
|---|
| 67 | const std::string& accountName, const SocketStreamTLS &s); |
|---|
| 68 | |
|---|
| 69 | public: |
|---|
| 70 | // HousekeepingInterface implementation |
|---|
| 71 | virtual bool CheckForInterProcessMsg(int AccountNum = 0, int MaximumWaitTime = 0); |
|---|
| 72 | void RunHousekeepingIfNeeded(); |
|---|
| 73 | |
|---|
| 74 | private: |
|---|
| 75 | BackupStoreAccountDatabase *mpAccountDatabase; |
|---|
| 76 | BackupStoreAccounts *mpAccounts; |
|---|
| 77 | bool mExtendedLogging; |
|---|
| 78 | bool mHaveForkedHousekeeping; |
|---|
| 79 | bool mIsHousekeepingProcess; |
|---|
| 80 | bool mHousekeepingInited; |
|---|
| 81 | |
|---|
| 82 | SocketStream mInterProcessCommsSocket; |
|---|
| 83 | IOStreamGetLine mInterProcessComms; |
|---|
| 84 | |
|---|
| 85 | virtual void OnIdle(); |
|---|
| 86 | void HousekeepingInit(); |
|---|
| 87 | int64_t mLastHousekeepingRun; |
|---|
| 88 | |
|---|
| 89 | public: |
|---|
| 90 | void SetTestHook(BackupStoreContext::TestHook& rTestHook) |
|---|
| 91 | { |
|---|
| 92 | mpTestHook = &rTestHook; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | private: |
|---|
| 96 | BackupStoreContext::TestHook* mpTestHook; |
|---|
| 97 | }; |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | #endif // BACKUPSTOREDAEMON__H |
|---|
| 101 | |
|---|