aboutsummaryrefslogtreecommitdiffstats
path: root/configd/src/apps/sentinel/output-connection.cpp
blob: 55fac5e2cf532ba9d560201f6fe99f652acfe23f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <unistd.h>
#include <stdarg.h>
#include <cstdio>
#include <cstring>

#include <vespa/log/log.h>
LOG_SETUP(".sentinel.output-connection");
#include <vespa/log/llparser.h>

#include "output-connection.h"
#include "line-splitter.h"

namespace config {
namespace sentinel {

OutputConnection::OutputConnection(int f, ns_log::LLParser *p)
    : _fd(f),
      _lines(f),
      _parser(p)
{
}

bool
OutputConnection::isFinished() const
{
    return _lines.eof();
}

void
OutputConnection::handleOutput()
{
    while (1) {
	char *line =  _lines.getLine();
	if (!line) {
	    return;
	}
	LOG(spam, "Got Output from connection: '%s'", line);
	_parser->doInput(line);
    }
}

OutputConnection::~OutputConnection()
{
    close(_fd);
    delete _parser;
}

} // end namespace config::sentinel
} // end namespace config