Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
ServiceMonitor.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2016 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19/*
20 * File: ServiceMonitor.h
21 *
22 */
23#ifndef SERVICEMONITOR_H
24#define SERVICEMONITOR_H
25
26#include <IDobbyIPCUtils.h>
27#include <IDobbyUtils.h>
28
29#include <mutex>
30#include <memory>
31
32// -----------------------------------------------------------------------------
55{
56public:
57 enum class State
58 {
60 Running,
62 Ready
63 };
64
65public:
66 ServiceMonitor(const std::shared_ptr<IDobbyIPCUtils> &ipcUtils,
67 const std::shared_ptr<IDobbyUtils> &utils,
68 const IDobbyIPCUtils::BusType &bus,
69 const std::string &serviceName,
70 const AI_IPC::Signal &readySignal,
71 const AI_IPC::Method &queryMethod,
72 const std::function<void(State)> &stateChangeHandler);
74
75public:
76 State state() const;
77
78 void forceReadyCheck();
79
80private:
81 void onServiceNotification(bool added);
82 void onReadyNotification(const AI_IPC::VariantList &args);
83
84 bool onTimer();
85
86 void sendIsReadyRequest() const;
87
88private:
89 const std::shared_ptr<IDobbyUtils> mUtilities;
90 const std::shared_ptr<IDobbyIPCUtils> mIPCUtilities;
91 const IDobbyIPCUtils::BusType mBusType;
92 const std::string mServiceName;
93 const AI_IPC::Signal mReadySignal;
94 const AI_IPC::Method mQueryMethod;
95 const std::function<void(State)> mStateChangeHandler;
96
97private:
98 mutable std::mutex mLock;
99 State mState;
100
101 int mServiceHandlerId;
102 int mSignalHandlerId;
103 int mTimerId;
104};
105
106#endif // !defined(SERVICEMONITOR_H)
BusType
The type of dbus to call methods on / emit signals.
Definition IDobbyIPCUtils.h:60
Utility class to actively monitor the status of a dbus service.
Definition ServiceMonitor.h:55
void onReadyNotification(const AI_IPC::VariantList &args)
Callback function called when the service daemon has sent a signal saying it's ready to process reque...
Definition ServiceMonitor.cpp:190
State state() const
Returns the current state of the service.
Definition ServiceMonitor.cpp:117
State
Definition ServiceMonitor.h:58
@ NotRunning
dbus service not detected on the bus
@ Ready
ready signal received
void onServiceNotification(bool added)
Callback function called when the daemon service has been added or removed from the bus.
Definition ServiceMonitor.cpp:147
bool onTimer()
Timer handler called every second, it sends out a ping request to the daemon if we think it is not al...
Definition ServiceMonitor.cpp:216
void sendIsReadyRequest() const
Sends a method call over dbus asking the service daemon to reply with a ready notification / signal i...
Definition ServiceMonitor.cpp:238
void forceReadyCheck()
Sends out an 'is ready' method request to the service.
Definition ServiceMonitor.cpp:129
Method identified by a service, object, interface and method name itself.
Definition IpcCommon.h:90
Method identified by object, interface and signal name itself.
Definition IpcCommon.h:105