winss
state_file.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2017 Morgan Stanley
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIB_WINSS_SUPERVISE_STATE_FILE_HPP_
18 #define LIB_WINSS_SUPERVISE_STATE_FILE_HPP_
19 
20 #include <filesystem>
21 #include <string>
22 #include "supervise.hpp"
23 
24 namespace fs = std::experimental::filesystem;
25 
26 namespace winss {
32  private:
33  fs::path state_file;
35  public:
36  static const char kStateFile[];
43  explicit SuperviseStateFile(fs::path service_dir);
44  SuperviseStateFile(const SuperviseStateFile&) = delete;
52  virtual const fs::path& GetPath() const;
53 
61  virtual bool Notify(winss::SuperviseNotification notification,
62  const winss::SuperviseState& state);
63 
70  virtual bool Read(winss::SuperviseState* state) const;
71 
79  virtual std::string Format(const winss::SuperviseState& state,
80  bool is_up) const;
81 
86 };
87 } // namespace winss
88 
89 #endif // LIB_WINSS_SUPERVISE_STATE_FILE_HPP_
Definition: case_ignore.hpp:23
virtual bool Read(winss::SuperviseState *state) const
Read the state of the supervisor from the file.
Definition: state_file.cpp:72
virtual const fs::path & GetPath() const
Gets the path of the state file.
Definition: state_file.cpp:37
static const char kStateFile[]
The state file name.
Definition: state_file.hpp:36
The state of the supervisor.
Definition: supervise.hpp:42
virtual bool Notify(winss::SuperviseNotification notification, const winss::SuperviseState &state)
Supervisor listener handler.
Definition: state_file.cpp:41
SuperviseStateFile(fs::path service_dir)
Supervise state file constructor.
Definition: state_file.cpp:33
The supervisor listener.
Definition: supervise.hpp:70
SuperviseNotification
The supervisor events which can occur.
Definition: supervise.hpp:57
Serializes the state file but can also read it as a human-readable message.
Definition: state_file.hpp:31
virtual std::string Format(const winss::SuperviseState &state, bool is_up) const
Format the state as a human-readable string.
Definition: state_file.cpp:125
SuperviseStateFile & operator=(const SuperviseStateFile &)=delete
No copy.