diff options
author | Arne Juul <arnej@yahoo-inc.com> | 2019-02-04 12:38:00 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahoo-inc.com> | 2019-02-05 10:52:53 +0000 |
commit | d716dcfb1906e3dbe1b245a5458f9855e4e6845a (patch) | |
tree | ae5a7bdd41d64675d5ba983ff593358a995cb782 /configd/src/apps/sentinel/cmdq.h | |
parent | 5bb268bee55c36935c134320e905b6cf3daccc00 (diff) |
add RPC server for start/stop of services
Diffstat (limited to 'configd/src/apps/sentinel/cmdq.h')
-rw-r--r-- | configd/src/apps/sentinel/cmdq.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/configd/src/apps/sentinel/cmdq.h b/configd/src/apps/sentinel/cmdq.h new file mode 100644 index 00000000000..df7dc9f241d --- /dev/null +++ b/configd/src/apps/sentinel/cmdq.h @@ -0,0 +1,58 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <memory> +#include <mutex> +#include <vector> + +class FRT_RPCRequest; + +namespace config::sentinel { + +class Cmd { +public: + using UP = std::unique_ptr<Cmd>; + enum CmdType { LIST, START, STOP }; + + Cmd(FRT_RPCRequest *req, CmdType cmdType, const char *service = "") + : _req(req), _cmdType(cmdType), _serviceName(service) + {} + + CmdType type() const { return _cmdType; } + const char *serviceName() const { return _serviceName; } + + void retError(const char *errorString) const; + void retValue(const char *valueString) const; + + ~Cmd(); +private: + FRT_RPCRequest *_req; + CmdType _cmdType; + const char *_serviceName; +}; + +class CommandQueue +{ +private: + std::mutex _lock; + std::vector<Cmd::UP> _queue; +public: + CommandQueue() = default; + ~CommandQueue() = default; + + void enqueue(Cmd::UP cmd) { + std::lock_guard guard(_lock); + _queue.push_back(std::move(cmd)); + } + + std::vector<Cmd::UP> drain() { + std::vector<Cmd::UP> r; + std::lock_guard guard(_lock); + r.swap(_queue); + return r; + } + +}; + +} // namespace config::sentinel |