blob: ec5db413817b2a8359f2f941272c31e0378c5fef [file] [log] [blame]
Matt Spinlerf60ac272019-12-11 13:47:50 -06001/**
2 * Copyright © 2019 IBM Corporation
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#include "host_notifier.hpp"
17
18#include <phosphor-logging/log.hpp>
19
20namespace openpower::pels
21{
22
23const auto subscriptionName = "PELHostNotifier";
24
25using namespace phosphor::logging;
26
27HostNotifier::HostNotifier(Repository& repo, DataInterfaceBase& dataIface,
28 std::unique_ptr<HostInterface> hostIface) :
29 _repo(repo),
30 _dataIface(dataIface), _hostIface(std::move(hostIface))
31{
32 // Subscribe to be told about new PELs.
33 _repo.subscribeToAdds(subscriptionName,
34 std::bind(std::mem_fn(&HostNotifier::newLogCallback),
35 this, std::placeholders::_1));
36
37 // Add any existing PELs to the queue to send them if necessary.
38 _repo.for_each(std::bind(std::mem_fn(&HostNotifier::addPELToQueue), this,
39 std::placeholders::_1));
40
41 // Subscribe to be told about host state changes.
42 _dataIface.subscribeToHostStateChange(
43 subscriptionName,
44 std::bind(std::mem_fun(&HostNotifier::hostStateChange), this,
45 std::placeholders::_1));
46
47 // Set the function to call when the async reponse is received.
48 _hostIface->setResponseFunction(
49 std::bind(std::mem_fn(&HostNotifier::commandResponse), this,
50 std::placeholders::_1));
51
52 // Start sending logs if the host is running
53 if (!_pelQueue.empty() && _dataIface.isHostUp())
54 {
55 doNewLogNotify();
56 }
57}
58
59HostNotifier::~HostNotifier()
60{
61 _repo.unsubscribeFromAdds(subscriptionName);
62 _dataIface.unsubscribeFromHostStateChange(subscriptionName);
63}
64
65bool HostNotifier::addPELToQueue(const PEL& pel)
66{
67 if (enqueueRequired(pel.id()))
68 {
69 _pelQueue.push_back(pel.id());
70 }
71
72 // Return false so that Repo::for_each keeps going.
73 return false;
74}
75
76bool HostNotifier::enqueueRequired(uint32_t id) const
77{
78 bool required = true;
79
80 return required;
81}
82
83void HostNotifier::newLogCallback(const PEL& pel)
84{
85 if (!enqueueRequired(pel.id()))
86 {
87 return;
88 }
89
90 _pelQueue.push_back(pel.id());
91
92 // TODO: Check if a send is needed now
93}
94
95void HostNotifier::doNewLogNotify()
96{
97}
98
99void HostNotifier::hostStateChange(bool hostUp)
100{
101}
102
103void HostNotifier::commandResponse(ResponseStatus status)
104{
105}
106
107} // namespace openpower::pels