#include "../include/net.go.h"
#include "../include/net_cortex.h"
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define CHECK(expr, what) \
do { \
int _rc = (expr); \
if (_rc != 0) { \
fprintf(stderr, "%s failed: rc=%d\n", (what), _rc); \
return 1; \
} \
} while (0)
#define WF_DONE 4
int main(void) {
net_redex_t* redex = net_redex_new(NULL);
if (!redex) {
fprintf(stderr, "net_redex_new returned NULL\n");
return 1;
}
net_workflow_adapter_t* wf = NULL;
CHECK(net_workflow_adapter_open(redex, 0x0F105D01ULL, 0, &wf),
"net_workflow_adapter_open");
uint64_t seq = 0;
CHECK(net_workflow_submit(wf, 1, &seq), "submit");
CHECK(net_workflow_start(wf, 1, &seq), "start");
CHECK(net_workflow_advance(wf, 1, &seq), "advance");
CHECK(net_workflow_complete(wf, 1, &seq), "complete");
CHECK(net_workflow_wait_for_seq(wf, seq, 5000), "wait_for_seq");
int found = 0, status = -1;
uint32_t step = 0, attempts = 0;
CHECK(net_workflow_get(wf, 1, &found, &step, &status, &attempts), "get");
if (!found || status != WF_DONE) {
fprintf(stderr, "task 1 not done: found=%d status=%d\n", found, status);
return 1;
}
printf("task 1: step=%" PRIu32 " status=done(%d) attempts=%" PRIu32 "\n",
step, status, attempts);
net_workflow_status_counts_t counts;
CHECK(net_workflow_status_counts(wf, &counts), "status_counts");
printf("status counts: done=%" PRIu64 "\n", counts.done);
net_workflow_adapter_free(wf);
net_redex_free(redex);
net_meshnode_t* node = NULL;
const char* cfg =
"{\"bind_addr\":\"127.0.0.1:0\","
"\"psk_hex\":\"5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b"
"5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b5b\"}";
CHECK(net_mesh_new(cfg, &node), "net_mesh_new");
const uint64_t until = 1000000000000000000ULL;
int outcome = -1;
CHECK(net_mesh_reserve_island(node, 0xA0, until, &outcome), "reserve_island");
printf("reserve 0xA0: %s\n", outcome == 0 ? "won" : "lost");
CHECK(net_mesh_release_island(node, 0xA0, &outcome), "release_island");
printf("release 0xA0: %s\n", outcome == 0 ? "won" : "lost");
CHECK(net_mesh_release_island(node, 0xBEEF, &outcome), "release unheld");
printf("release 0xBEEF (unheld): %s\n", outcome == 0 ? "won" : "lost");
net_mesh_free(node);
printf("scheduler example OK\n");
return 0;
}