1 #include "libaktualizr-c.h"
8 }
catch (
const std::exception &e) {
9 std::cerr <<
"Aktualizr_create exception: " << e.what() << std::endl;
15 Aktualizr *Aktualizr_create_from_path(
const char *config_path) {
18 return Aktualizr_create_from_cfg(&cfg);
19 }
catch (
const std::exception &e) {
20 std::cerr <<
"Aktualizr_create exception: " << e.what() << std::endl;
28 }
catch (
const std::exception &e) {
29 std::cerr <<
"Aktualizr_initialize exception: " << e.what() << std::endl;
35 int Aktualizr_uptane_cycle(
Aktualizr *a) {
38 }
catch (
const std::exception &e) {
39 std::cerr <<
"Uptane cycle exception: " << e.what() << std::endl;
45 void Aktualizr_destroy(
Aktualizr *a) {
delete a; }
47 static void handler_wrapper(
const std::shared_ptr<event::BaseEvent> &
event,
void (*handler)(
const char *)) {
48 if (handler ==
nullptr) {
49 std::cerr <<
"handler_wrapper error: no external handler" << std::endl;
53 (*handler)(
event->variant.c_str());
56 int Aktualizr_set_signal_handler(
Aktualizr *a,
void (*handler)(
const char *event_name)) {
58 auto functor = std::bind(handler_wrapper, std::placeholders::_1, handler);
61 }
catch (
const std::exception &e) {
62 std::cerr <<
"Aktualizr_set_signal_handler exception: " << e.what() << std::endl;
68 Campaign *Aktualizr_campaigns_check(
Aktualizr *a) {
71 if (!r.campaigns.empty()) {
73 return new Campaign(r.campaigns[0]);
75 }
catch (
const std::exception &e) {
76 std::cerr <<
"Campaign check exception: " << e.what() << std::endl;
82 int Aktualizr_campaign_accept(
Aktualizr *a, Campaign *c) {
85 }
catch (
const std::exception &e) {
86 std::cerr <<
"Campaign accept exception: " << e.what() << std::endl;
92 int Aktualizr_campaign_postpone(
Aktualizr *a, Campaign *c) {
95 }
catch (
const std::exception &e) {
96 std::cerr <<
"Campaign postpone exception: " << e.what() << std::endl;
102 int Aktualizr_campaign_decline(
Aktualizr *a, Campaign *c) {
105 }
catch (
const std::exception &e) {
106 std::cerr <<
"Campaign decline exception: " << e.what() << std::endl;
112 void Aktualizr_campaign_free(Campaign *c) {
delete c; }
114 Updates *Aktualizr_updates_check(
Aktualizr *a) {
117 return (r.updates.size() > 0) ?
new Updates(std::move(r.updates)) :
nullptr;
118 }
catch (
const std::exception &e) {
119 std::cerr <<
"Campaign decline exception: " << e.what() << std::endl;
124 void Aktualizr_updates_free(Updates *u) {
delete u; }
126 size_t Aktualizr_get_targets_num(Updates *u) {
return (u ==
nullptr) ? 0 : u->size(); }
128 Target *Aktualizr_get_nth_target(Updates *u,
size_t n) {
135 }
catch (
const std::exception &e) {
136 std::cerr <<
"Exception: " << e.what() << std::endl;
142 const char *Aktualizr_get_target_name(Target *t) {
144 auto length = t->filename().length();
145 auto *name =
new char[length + 1];
146 strncpy(name, t->filename().c_str(), length + 1);
153 void Aktualizr_free_target_name(
const char *n) {
delete[] n; }
155 int Aktualizr_download_target(
Aktualizr *a, Target *t) {
157 a->
Download(std::vector<Uptane::Target>({*t})).get();
158 }
catch (
const std::exception &e) {
159 std::cerr <<
"Campaign decline exception: " << e.what() << std::endl;
165 int Aktualizr_install_target(
Aktualizr *a, Target *t) {
167 a->
Install(std::vector<Uptane::Target>({*t})).get();
168 }
catch (
const std::exception &e) {
169 std::cerr <<
"Campaign decline exception: " << e.what() << std::endl;
175 int Aktualizr_send_manifest(
Aktualizr *a,
const char *manifest) {
177 Json::Value custom = Utils::parseJSON(manifest);
180 }
catch (
const std::exception &e) {
181 std::cerr <<
"Aktualizr_send_manifest exception: " << e.what() << std::endl;
186 int Aktualizr_send_device_data(
Aktualizr *a) {
190 }
catch (
const std::exception &e) {
191 std::cerr <<
"Aktualizr_send_device_data exception: " << e.what() << std::endl;
196 StorageTargetHandle *Aktualizr_open_stored_target(
Aktualizr *a,
const Target *t) {
198 std::cerr <<
"Aktualizr_open_stored_target failed: invalid input" << std::endl;
204 return handle.release();
205 }
catch (
const std::exception &e) {
206 std::cerr <<
"Aktualizr_open_stored_target exception: " << e.what() << std::endl;
211 size_t Aktualizr_read_stored_target(StorageTargetHandle *handle, uint8_t *buf,
size_t size) {
212 if (handle !=
nullptr && buf !=
nullptr) {
213 return handle->rread(buf, size);
215 std::cerr <<
"Aktualizr_read_stored_target failed: invalid input " << (handle ==
nullptr ?
"handle" :
"buffer")
221 int Aktualizr_close_stored_target(StorageTargetHandle *handle) {
222 if (handle !=
nullptr) {
227 std::cerr <<
"Aktualizr_close_stored_target failed: no input handle" << std::endl;
234 case result::PauseStatus::kSuccess: {
235 return Pause_Status_C::kSuccess;
237 case result::PauseStatus::kAlreadyPaused: {
238 return Pause_Status_C::kAlreadyPaused;
240 case result::PauseStatus::kAlreadyRunning: {
241 return Pause_Status_C::kAlreadyRunning;
243 case result::PauseStatus::kError: {
244 return Pause_Status_C::kError;
248 return Pause_Status_C::kError;
253 Pause_Status_C Aktualizr_pause(
Aktualizr *a) {
255 return ::get_Pause_Status_C(pause.status);
258 Pause_Status_C Aktualizr_resume(
Aktualizr *a) {
260 return ::get_Pause_Status_C(pause.status);