Skip to content
20 changes: 20 additions & 0 deletions include/ggl/attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@
#define NULL_TERMINATED_STRING_ARG(pos)
#endif

#ifdef __has_attribute
#if __has_attribute(access)
#define ACCESS(...) __attribute__((access(__VA_ARGS__)))
#endif
#endif

#ifndef ACCESS
#define ACCESS(...)
#endif

#ifdef __has_attribute
#if __has_attribute(cold)
#define COLD __attribute__((cold))
Expand All @@ -116,4 +126,14 @@
#define CONST
#endif

#ifdef __has_attribute
#if __has_attribute(flag_enum)
#define FLAG_ENUM __attribute__((flag_enum))
#endif
#endif

#ifndef FLAG_ENUM
#define FLAG_ENUM
#endif

#endif
2 changes: 2 additions & 0 deletions include/ggl/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ typedef enum NODISCARD GglError {
GGL_ERR_REMOTE,
/// Expected non-ok status
GGL_ERR_EXPECTED,
/// Request timed out
GGL_ERR_TIMEOUT,
} GglError;

const char *ggl_strerror(GglError err);
Expand Down
12 changes: 0 additions & 12 deletions include/ggl/ipc/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define GGL_IPC_CLIENT_H

#include <ggl/arena.h>
#include <ggl/attr.h>
#include <ggl/buffer.h>
#include <ggl/error.h>
#include <ggl/ipc/error.h>
Expand All @@ -18,13 +17,6 @@ struct timespec;

#define GGL_IPC_SVCUID_STR_LEN (16)

/// Connect to GG-IPC server using component name.
/// If svcuid is non-null, it will be filled with the component's identity
/// token. Buffer must be able to hold at least GGL_IPC_SVCUID_STR_LEN.
GglError ggipc_connect_by_name(
GglBuffer socket_path, GglBuffer component_name, int *fd, GglBuffer *svcuid
) NONNULL(3);

GglError ggipc_call(
int conn,
GglBuffer operation,
Expand All @@ -35,10 +27,6 @@ GglError ggipc_call(
GglIpcError *remote_err
);

GglError ggipc_private_get_system_config(
int conn, GglBuffer key, GglBuffer *value
);

GglError ggipc_get_config_str(
int conn, GglBufList key_path, GglBuffer *component_name, GglBuffer *value
);
Expand Down
13 changes: 13 additions & 0 deletions include/ggl/sdk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// aws-greengrass-sdk-lite - Lightweight AWS IoT Greengrass SDK
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#ifndef GGL_SDK_H
#define GGL_SDK_H

/// Initializes the sdk, including starting necessary threads.
/// Unused portions of sdk may not be initialized.
/// Exits on error.
void ggl_sdk_init(void);

#endif
2 changes: 1 addition & 1 deletion priv_include/ggl/eventstream/rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef enum {
} EventStreamMessageType;

/// `:message-flags` header flags
typedef enum {
typedef enum FLAG_ENUM {
EVENTSTREAM_CONNECTION_ACCEPTED = 1,
EVENTSTREAM_TERMINATE_STREAM = 2,
} EventStreamMessageFlags;
Expand Down
21 changes: 21 additions & 0 deletions priv_include/ggl/init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// aws-greengrass-sdk-lite - Lightweight AWS IoT Greengrass SDK
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#ifndef GGL_INIT_H
#define GGL_INIT_H

#include <ggl/attr.h>
#include <ggl/error.h>

typedef struct GglInitEntry {
GglError (*fn)(void);
struct GglInitEntry *next;
} GglInitEntry;

/// Initializes the sdk, including starting necessary threads.
/// Unused portions of sdk may not be initialized.
/// Not thread-safe
void ggl_register_init_fn(GglInitEntry *entry) NONNULL(1);

#endif
22 changes: 18 additions & 4 deletions priv_include/ggl/ipc/client_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@
#include <ggl/attr.h>
#include <ggl/buffer.h>
#include <ggl/error.h>
#include <ggl/object.h>

/// Connect to GG-IPC server with the given payload.
/// Maximum size of eventstream packet.
/// Can be configured with `-D GGL_IPC_MAX_MSG_LEN=<N>`.
#ifndef GGL_IPC_MAX_MSG_LEN
#define GGL_IPC_MAX_MSG_LEN 10000
#endif

/// Maximum size IPC functions will wait for server response
#ifndef GGL_IPC_RESPONSE_TIMEOUT
#define GGL_IPC_RESPONSE_TIMEOUT 10
#endif

/// Connect to GG-IPC server using component name.
/// If svcuid is non-null, it will be filled with the component's identity
/// token. Buffer must be able to hold at least GGL_IPC_SVCUID_STR_LEN.
GglError ggipc_connect_with_payload(
GglBuffer socket_path, GglMap payload, int *fd, GglBuffer *svcuid
GglError ggipc_connect_by_name(
GglBuffer socket_path, GglBuffer component_name, int *fd, GglBuffer *svcuid
) NONNULL(3);

GglError ggipc_private_get_system_config(
int conn, GglBuffer key, GglBuffer *value
);

#endif
89 changes: 0 additions & 89 deletions priv_include/ggl/socket_handle.h

This file was deleted.

33 changes: 0 additions & 33 deletions priv_include/ggl/socket_server.h

This file was deleted.

17 changes: 0 additions & 17 deletions priv_include/ggl/version.h

This file was deleted.

3 changes: 3 additions & 0 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ GglBuffer ggl_buffer_from_null_term(char *str) {

bool ggl_buffer_eq(GglBuffer buf1, GglBuffer buf2) {
if (buf1.len == buf2.len) {
if (buf1.len == 0) {
return true;
}
return memcmp(buf1.data, buf2.data, buf1.len) == 0;
}
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const char *ggl_strerror(GglError err) {
return "REMOTE";
case GGL_ERR_EXPECTED:
return "EXPECTED";
case GGL_ERR_TIMEOUT:
return "TIMEOUT";
}

assert(false);
Expand Down
31 changes: 31 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// aws-greengrass-sdk-lite - Lightweight AWS IoT Greengrass SDK
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

#include <ggl/error.h>
#include <ggl/init.h>
#include <ggl/log.h>
#include <ggl/sdk.h>
#include <stdlib.h>

static GglInitEntry *init_list = NULL;

void ggl_register_init_fn(GglInitEntry *entry) {
entry->next = init_list;
init_list = entry;
}

void ggl_sdk_init(void) {
GglInitEntry *list = init_list;
init_list = NULL;

while (list != NULL) {
GglError ret = list->fn();
if (ret != GGL_ERR_OK) {
GGL_LOGE("Failed to initialize (%u).", (unsigned) ret);
_Exit(1);
}

list = list->next;
}
}
Loading