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 <evgenii.smirnov@here.com>
- Loading branch information
Eugene Smirnov
committed
Jul 26, 2019
1 parent
8c8877f
commit c9e90c1
Showing
6 changed files
with
175 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
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,10 @@ | ||
SET(TARGET_NAME aktualizr-c) | ||
SET(SOURCES libaktualizr-c.cc) | ||
|
||
add_library(${TARGET_NAME} SHARED ${SOURCES}) | ||
target_include_directories(${TARGET_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include) | ||
target_link_libraries(${TARGET_NAME} PRIVATE aktualizr_static_lib ${AKTUALIZR_EXTERNAL_LIBS}) | ||
|
||
aktualizr_source_file_checks(${SOURCES}) | ||
|
||
add_subdirectory(test) |
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,81 @@ | ||
#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 << "Aktualizr_create exception: " << e.what() << std::endl; | ||
return NULL; | ||
} | ||
return a; | ||
} | ||
|
||
int Aktualizr_initialize(Aktualizr *a) { | ||
try { | ||
a->Initialize(); | ||
} catch (const std::exception &e) { | ||
std::cerr << "Aktualizr_initialize 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()) { | ||
// We don't support multiple campaigns at the moment | ||
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).get(); | ||
} 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).get(); | ||
} 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).get(); | ||
} 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,8 @@ | ||
SET(TARGET_NAME api-test) | ||
SET(SOURCES api-test.c) | ||
|
||
add_executable(${TARGET_NAME} EXCLUDE_FROM_ALL ${SOURCES}) | ||
add_dependencies(build_tests ${TEST_TARGET}) | ||
target_link_libraries(${TARGET_NAME} aktualizr-c) | ||
|
||
aktualizr_source_file_checks(${SOURCES}) |
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,45 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "libaktualizr-c.h" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
Aktualizr *a; | ||
Campaign *c; | ||
int err; | ||
|
||
if (argc != 2) { | ||
fprintf(stderr, "Missing config file\nUsage:\n\t%s CONFIG_FILE\n", argv[0]); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
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) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
Aktualizr_destroy(a); | ||
|
||
return EXIT_SUCCESS; | ||
} |