This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Eugene Smirnov <[email protected]>
- Loading branch information
Eugene Smirnov
committed
Jul 23, 2019
1 parent
383dfc3
commit 7176368
Showing
7 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef AKTUALIZR_LIBAKTUALIZRC_H | ||
#define AKTUALIZR_LIBAKTUALIZRC_H | ||
|
||
#ifdef __cplusplus | ||
#include "primary/aktualizr.h" | ||
|
||
using Campaign = campaign::Campaign; | ||
|
||
extern "C" { | ||
#else | ||
typedef struct Aktualizr Aktualizr; | ||
typedef struct Campaign Campaign; | ||
#endif | ||
|
||
Aktualizr *Aktualizr_create(const char *config_path); | ||
int Aktualizr_initialize(Aktualizr *a); | ||
int Aktualizr_uptane_cycle(Aktualizr *a); | ||
void Aktualizr_destroy(Aktualizr *a); | ||
|
||
Campaign *Aktualizr_campaign_check(Aktualizr *a); | ||
int Aktualizr_campaign_accept(Aktualizr *a, Campaign *c); | ||
int Aktualizr_campaign_postpone(Aktualizr *a, Campaign *c); | ||
int Aktualizr_campaign_decline(Aktualizr *a, Campaign *c); | ||
void Aktualizr_campaign_free(Campaign *c); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif //AKTUALIZR_LIBAKTUALIZR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
SET(TARGET_NAME aktualizr-c) | ||
|
||
add_library(${TARGET_NAME} SHARED libaktualizr-c.cc) | ||
target_link_libraries(${TARGET_NAME} aktualizr_static_lib ${AKTUALIZR_EXTERNAL_LIBS}) | ||
|
||
aktualizr_source_file_checks(libaktualizr-c.cc test/api-test.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "libaktualizr-c.h" | ||
|
||
Aktualizr *Aktualizr_create(const char *config_path) { | ||
Aktualizr *a; | ||
try { | ||
Config cfg(config_path); | ||
a = new Aktualizr(cfg); | ||
} catch (const std::exception &e) { | ||
std::cerr << "Creating exception: " << e.what() << std::endl; | ||
return NULL; | ||
} | ||
return a; | ||
} | ||
|
||
int Aktualizr_initialize(Aktualizr *a) { | ||
try { | ||
a->Initialize(); | ||
} catch (const std::exception &e) { | ||
std::cerr << "Initializing exception: " << e.what() << std::endl; | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
int Aktualizr_uptane_cycle(Aktualizr *a) { | ||
try { | ||
a->UptaneCycle(); | ||
} catch (const std::exception &e) { | ||
std::cerr << "Uptane cycle exception: " << e.what() << std::endl; | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
void Aktualizr_destroy(Aktualizr *a) { | ||
delete a; | ||
} | ||
|
||
Campaign *Aktualizr_campaign_check(Aktualizr *a) { | ||
try { | ||
auto r = a->CampaignCheck().get(); | ||
if (!r.campaigns.empty()) { | ||
return new Campaign(r.campaigns[0]); | ||
} | ||
} catch (const std::exception &e) { | ||
std::cerr << "Campaign check exception: " << e.what() << std::endl; | ||
return NULL; | ||
} | ||
return NULL; | ||
} | ||
int Aktualizr_campaign_accept(Aktualizr *a, Campaign *c) { | ||
try { | ||
a->CampaignControl(c->id, campaign::Cmd::Accept); | ||
} catch (const std::exception &e) { | ||
std::cerr << "Campaign accept exception: " << e.what() << std::endl; | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
int Aktualizr_campaign_postpone(Aktualizr *a, Campaign *c) { | ||
try { | ||
a->CampaignControl(c->id, campaign::Cmd::Postpone); | ||
} catch (const std::exception &e) { | ||
std::cerr << "Campaign postpone exception: " << e.what() << std::endl; | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
int Aktualizr_campaign_decline(Aktualizr *a, Campaign *c) { | ||
try { | ||
a->CampaignControl(c->id, campaign::Cmd::Decline); | ||
} catch (const std::exception &e) { | ||
std::cerr << "Campaign decline exception: " << e.what() << std::endl; | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
void Aktualizr_campaign_free(Campaign *c) { | ||
delete c; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CC=gcc | ||
CFLAGS=-I/home/esm/projects/aktualizr/include -g -O0 | ||
# Run application with LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/esm/projects/aktualizr/build/src/libaktualizr-c | ||
LIBS=-L/home/esm/projects/aktualizr/build/src/libaktualizr-c -laktualizr-c | ||
OBJ=api-test.o | ||
|
||
%.o: %.c | ||
$(CC) -c -o $@ $< $(CFLAGS) | ||
|
||
api-test: $(OBJ) | ||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "libaktualizr-c.h" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
Aktualizr *a; | ||
Campaign *c; | ||
int err; | ||
|
||
a = Aktualizr_create(argv[1]); | ||
if (a == NULL) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
err = Aktualizr_initialize(a); | ||
if (err) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
c = Aktualizr_campaign_check(a); | ||
if (c != NULL) { | ||
printf("Accepting running campaign\n"); | ||
err = Aktualizr_campaign_accept(a, c); | ||
Aktualizr_campaign_free(c); | ||
if (err) { | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
|
||
err = Aktualizr_uptane_cycle(a); | ||
if (err) { | ||
fprintf(stderr, "Failed to perform uptane cycle\n"); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
Aktualizr_destroy(a); | ||
|
||
return EXIT_SUCCESS; | ||
} |