Repository navigation
Expand file tree
/
Copy pathcontrol_daemon.cpp
More file actions
79 lines (68 loc) · 2.9 KB
/
Copy pathcontrol_daemon.cpp
File metadata and controls
79 lines (68 loc) · 2.9 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/********************************************************************************
* Copyright (c) 2025 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#include <atomic>
#include <chrono>
#include <csignal>
#include <iostream>
#include <thread>
#include "control.hpp"
#include "ipc_dropin/socket.hpp"
#include <score/mw/lifecycle/ilm_control.hpp>
#include <score/mw/lifecycle/report_running.h>
std::atomic<bool> exitRequested{false};
void signalHandler(int)
{
exitRequested = true;
}
int main()
{
signal(SIGINT, signalHandler);
signal(SIGTERM, signalHandler);
score::mw::lifecycle::report_running();
ipc_dropin::Socket<static_cast<size_t>(sizeof(RunTargetInfo)), control_socket_capacity> sm_control_socket{};
if (sm_control_socket.create(control_socket_path, 600) != ipc_dropin::ReturnCode::kOk)
{
std::cerr << "Could not create control socket" << std::endl;
return EXIT_FAILURE;
}
auto client_result = score::mw::lifecycle::ILmControl::Create("StateManager/LaunchManager/Instance");
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD(client_result.has_value());
std::unique_ptr<score::mw::lifecycle::ILmControl> client = std::move(client_result).value();
const auto register_result = client->register_run_target_activation_callback(
[]([[maybe_unused]] score::mw::lifecycle::RunTargetActivationSource source,
score::mw::lifecycle::RunTargetName target) {
std::cerr << "Successfully activated Run Target " << target << std::endl;
});
SCORE_LANGUAGE_FUTURECPP_ASSERT_PRD_MESSAGE(register_result.has_value(), register_result.error().Message().data());
while (!exitRequested)
{
RunTargetInfo info{};
if (ipc_dropin::ReturnCode::kOk == sm_control_socket.tryReceive(info))
{
std::string runTargetName{info.runTargetName};
std::cerr << "Requesting Run Target: " << runTargetName << std::endl;
const auto result = client->activate_run_target(score::mw::lifecycle::RunTargetName{runTargetName}, true);
if (result.has_value())
{
std::cerr << "Successfully requested Run Target " << runTargetName << std::endl;
}
else
{
std::cerr << "Requesting Run Target " << runTargetName
<< " failed with error: " << result.error().Message() << std::endl;
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return EXIT_SUCCESS;
}