Skip to content

Commit d52fd85

Browse files
committed
feat(posix/supervisor): initial implementation
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
1 parent b99b4ce commit d52fd85

12 files changed

Lines changed: 650 additions & 185 deletions

File tree

src/samples/supervisor/posix/CMakeLists.txt

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ cmake_minimum_required(VERSION 3.20.0)
77

88
project (ocre_supervisor)
99

10+
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
11+
find_package(Threads)
12+
1013
add_executable(ocre_cli
1114
ocre.c
1215
download.c
@@ -22,6 +25,7 @@ add_library(OcreClient)
2225
target_sources(OcreClient
2326
PRIVATE
2427
client/client.c
28+
client/context.c
2529
zcbor_helpers.c
2630
zcbor/src/zcbor_encode.c
2731
zcbor/src/zcbor_decode.c
@@ -71,6 +75,7 @@ target_link_libraries(OcreClient
7175
target_link_libraries(ocre_cli
7276
PUBLIC
7377
OcreClient
78+
Threads::Threads
7479
)
7580

7681
# target_include_directories(ocre_cli PRIVATE ../../../ocre/include)
@@ -85,28 +90,10 @@ target_link_libraries(ocre_cli
8590
# OcreCore
8691
# )
8792

88-
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
89-
find_package(Threads)
90-
target_link_libraries(ocre_cli PRIVATE Threads::Threads)
93+
9194

9295

9396
# add_definitions(-DZCBOR_VERBOSE)
9497

9598
# add_definitions(-DZCBOR_CANONICAL)
96-
97-
add_executable(ocred
98-
ocred.c
99-
zcbor_helpers.c
100-
zcbor/src/zcbor_encode.c
101-
zcbor/src/zcbor_decode.c
102-
zcbor/src/zcbor_common.c
103-
)
104-
105-
target_link_libraries(ocred
106-
PRIVATE
107-
OcreCore
108-
)
109-
110-
target_include_directories(ocred
111-
PRIVATE zcbor/include
112-
)
99+
add_subdirectory(server)

src/samples/supervisor/posix/client/client.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <ctype.h>
1313

1414
#include <stdlib.h>
15-
#include <errno.h>
1615
#include <string.h>
1716
#include <sys/types.h>
1817
#include <sys/socket.h>
@@ -28,7 +27,7 @@
2827
#include "../ipc.h"
2928
#include "zcbor_helpers.h"
3029

31-
#define SOCK_PATH "ocre.sock"
30+
#define SOCK_PATH "/tmp/ocre.sock"
3231

3332
/* Buffer sizes for IPC communication */
3433
#define SMALL_PAYLOAD_SIZE 64
@@ -256,12 +255,15 @@ struct ocre_container *ocre_context_create_container(struct ocre_context *contex
256255

257256
struct ocre_container *ocre_context_get_container_by_id(struct ocre_context *context, const char *id)
258257
{
259-
(void)context; /* Context is not sent over IPC - server uses global context */
260258
int rc;
261259

262260
uint8_t payload[MEDIUM_PAYLOAD_SIZE];
263261
bool success;
264262

263+
if (!context) {
264+
return NULL;
265+
}
266+
265267
/* Encode the request - server expects only the ID string */
266268
ZCBOR_STATE_E(encoding_state, 0, payload, sizeof(payload), 0);
267269

@@ -328,13 +330,12 @@ struct ocre_container *ocre_context_get_container_by_id(struct ocre_context *con
328330

329331
int ocre_context_remove_container(struct ocre_context *context, struct ocre_container *container)
330332
{
331-
(void)context; /* Context is not sent over IPC - server uses global context */
332333
int rc;
333334

334335
uint8_t payload[MEDIUM_PAYLOAD_SIZE];
335336
bool success;
336337

337-
if (!container || !container->id) {
338+
if (!context || !container || !container->id) {
338339
return -1;
339340
}
340341

@@ -385,12 +386,14 @@ int ocre_context_remove_container(struct ocre_context *context, struct ocre_cont
385386

386387
int ocre_context_get_container_count(struct ocre_context *context)
387388
{
388-
(void)context; /* Context is not sent over IPC - server uses global context */
389389
int rc;
390390

391391
uint8_t payload[SMALL_PAYLOAD_SIZE];
392392
bool success;
393393

394+
if (!context) {
395+
return -1;
396+
}
394397
/* Encode the request - server takes no parameters */
395398
ZCBOR_STATE_E(encoding_state, 0, payload, sizeof(payload), 0);
396399

@@ -438,12 +441,15 @@ int ocre_context_get_container_count(struct ocre_context *context)
438441

439442
int ocre_context_get_containers(struct ocre_context *context, struct ocre_container **containers, int max_size)
440443
{
441-
(void)context; /* Context is not sent over IPC - server uses global context */
442444
int rc;
443445

444446
uint8_t payload[SMALL_PAYLOAD_SIZE];
445447
bool success;
446448

449+
if (!context || !containers) {
450+
return -1;
451+
}
452+
447453
/* Encode the request - server expects only max_size */
448454
ZCBOR_STATE_E(encoding_state, 0, payload, sizeof(payload), 0);
449455

@@ -533,13 +539,16 @@ int ocre_context_get_containers(struct ocre_context *context, struct ocre_contai
533539

534540
const char *ocre_context_get_working_directory(const struct ocre_context *context)
535541
{
536-
(void)context; /* Context is not sent over IPC - server uses global context */
537542
int rc;
538543
static char workdir_buffer[STRING_BUFFER_SIZE];
539544

540545
uint8_t payload[SMALL_PAYLOAD_SIZE];
541546
bool success;
542547

548+
if (!context) {
549+
return NULL;
550+
}
551+
543552
/* Encode the request - server takes no parameters */
544553
ZCBOR_STATE_E(encoding_state, 0, payload, sizeof(payload), 0);
545554

@@ -975,7 +984,7 @@ int ocre_container_kill(struct ocre_container *container)
975984
}
976985

977986
/* Decode the response */
978-
ZCBOR_STATE_D(decoding_state, 0, rx_buf, rc, 1, 0);
987+
ZCBOR_STATE_D(decoding_state, 0, rx_buf, rc, 2, 0);
979988

980989
uint32_t decoded_rsp;
981990
success = zcbor_uint32_decode(decoding_state, &decoded_rsp);
@@ -1031,7 +1040,7 @@ int ocre_container_wait(struct ocre_container *container, int *status)
10311040
}
10321041

10331042
/* Decode the response */
1034-
ZCBOR_STATE_D(decoding_state, 0, rx_buf, rc, 1, 0);
1043+
ZCBOR_STATE_D(decoding_state, 0, rx_buf, rc, 3, 0);
10351044

10361045
uint32_t decoded_rsp;
10371046
success = zcbor_uint32_decode(decoding_state, &decoded_rsp);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @copyright Copyright (c) contributors to Project Ocre,
3+
* which has been established as Project Ocre a Series of LF Projects, LLC
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include <ocre/ocre.h>
9+
10+
int ocre_initialize(const struct ocre_runtime_vtable *const vtable[])
11+
{
12+
return 0;
13+
}
14+
15+
void ocre_deinitialize(void)
16+
{
17+
return;
18+
}
19+
20+
struct ocre_context *ocre_create_context(const char *workdir)
21+
{
22+
return (struct ocre_context *)0x31337;
23+
}
24+
25+
int ocre_destroy_context(struct ocre_context *context)
26+
{
27+
if (!context) {
28+
return -1;
29+
}
30+
31+
return 0;
32+
}

src/samples/supervisor/posix/client/include/ocre/client.h

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# @copyright Copyright (c) contributors to Project Ocre,
2+
# which has been established as Project Ocre a Series of LF Projects, LLC
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
cmake_minimum_required(VERSION 3.20.0)
7+
8+
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
9+
find_package(Threads)
10+
11+
add_executable(ocred
12+
ocred.c
13+
handlers.c
14+
waiters.c
15+
../zcbor_helpers.c
16+
../zcbor/src/zcbor_encode.c
17+
../zcbor/src/zcbor_decode.c
18+
../zcbor/src/zcbor_common.c
19+
)
20+
21+
target_link_libraries(ocred
22+
PRIVATE
23+
OcreCore
24+
Threads::Threads
25+
)
26+
27+
target_include_directories(ocred
28+
PRIVATE ../zcbor/include
29+
)

0 commit comments

Comments
 (0)