Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Checks:
- -misc-non-private-member-variables-in-classes
- -misc-use-internal-linkage
- -misc-use-anonymous-namespace
- -misc-include-cleaner
- -cppcoreguidelines-pro-type-vararg
- -cppcoreguidelines-non-private-member-variables-in-classes
- -cppcoreguidelines-special-member-functions
Expand Down
11 changes: 10 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
- Initialize variables and objects using `{}` to distinguish from function call.
- *Exception vector initialization*: In case vector must be created with size use `()` initialization to distinguish from initializer_list constructor.
- Use `auto` whenever possible for variables with respect for references `auto&` and pointers `auto*`.
- Check if pointer is null by comparing it to `nullptr` instead of using implicit conversion to `bool`.
- Check if raw pointer is null by comparing it to `nullptr` instead of using implicit conversion to `bool`. Smart pointers could be check with implicit bool conversion.
- If a function argument is not used, there are two options. If it's never used, just ommit the argument name. If it's used on some configurations use `[[maybe_unused]]` attribute.
- Immediate lambda call pattern should be implemented by using `std::invoke`.
- For each assert add comment like `assert(condition && "Comment")`.
- For *internal* namespaces use `file_name_internal` format.

## Architecture & Object System

Expand Down Expand Up @@ -90,6 +92,13 @@
Project build configured in `build-clang` (`<build-dir>`) with ninja.
To build the project go into `<build-dir>/` and run `cmake --build . --parallel` or `ninja`.

### Clang-tidy

- Use `build-clang/compile_commands.json` for `clang-tidy`.
- If `build-clang` exists but `compile_commands.json` is missing, report `clang-tidy` skipped because the compile database is missing, not because the build directory is missing.
- Do not claim the build directory is missing when `build-clang` exists.
- `compile_commands.json` may require configuring with `CMAKE_EXPORT_COMPILE_COMMANDS=ON`.

To run tests, go into `<build-dir>` and run `ctest . --progress -j -E "((sodium)|(hydro)|(bcrypt)).*" --output-on-failure`.
Or run specific test by name from `<build-dir>/tests/run/<test-name>`.

Expand Down
1 change: 1 addition & 0 deletions aether/ae_actions/ping.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

# include "aether/ae_context.h"
# include "aether/api_protocol/request_id.h"
# include "aether/clock.h"
# include "aether/events/event_subscription.h"
# include "aether/events/events.h"
# include "aether/tasks/details/task_subsctiption.h"
Expand Down
4 changes: 2 additions & 2 deletions aether/aether_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,11 @@ void AetherAppContext::InitComponentContext() {
#endif // AE_DISTILLATION
}

RcPtr<AetherApp> AetherApp::Construct(AetherAppContext context) {
std::unique_ptr<AetherApp> AetherApp::Construct(AetherAppContext context) {
// init all the components in context
context.InitComponentContext();

auto app = MakeRcPtr<AetherApp>();
auto app = std::unique_ptr<AetherApp>{new AetherApp()};
app->aether_ = context.aether();
#if AE_DISTILLATION
app->aether_->tele_statistics = context.tele_statistics_.Resolve(context);
Expand Down
6 changes: 2 additions & 4 deletions aether/aether_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

#include "aether/common.h"
#include "aether/config.h"
#include "aether/memory.h"
#include "aether/obj/domain.h"
#include "aether/ptr/ptr.h"
#include "aether/ptr/rc_ptr.h"

#include "aether/actions/action.h" // IWYU pragma: keep
#include "aether/events/events.h" // IWYU pragma: keep
Expand Down Expand Up @@ -145,10 +145,8 @@ class AetherAppContext {
* \brief The enter point to the Aethernet application world
*/
class AetherApp {
friend auto MakeRcPtr<AetherApp>() noexcept;

public:
static RcPtr<AetherApp> Construct(AetherAppContext context);
static std::unique_ptr<AetherApp> Construct(AetherAppContext context);

~AetherApp();

Expand Down
18 changes: 9 additions & 9 deletions aether/aether_c/aether_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@

#include <string_view>

#include "aether/aether_c/extern_c.h"
#include "aether/aether_c/c_errors.h"
#include "aether/aether_c/extern_c.h"

#include "aether/actions/actions_queue.h"
#include "aether/memory.h"
#include "aether/ptr/ptr.h"
#include "aether/obj/obj_ptr.h"
#include "aether/ptr/ptr.h"
#include "aether/types/data_buffer.h"
#include "aether/actions/actions_queue.h"

#include "aether/client.h"
#include "aether/aether_app.h"
#include "aether/client.h"

// IWYU pragma: begin_keeps
#include "aether/wifi/wifi_driver_types.h"

#include "aether/domain_storage/domain_storage_factory.h"
#include "aether/domain_storage/file_system_std_storage.h"
#include "aether/domain_storage/ram_domain_storage.h"
#include "aether/domain_storage/spifs_domain_storage.h"
#include "aether/domain_storage/file_system_std_storage.h"

#include "aether/adapter_registry.h"
#include "aether/adapters/ethernet.h"
#include "aether/adapters/wifi_adapter.h"
#include "aether/adapters/modem_adapter.h"
#include "aether/adapters/wifi_adapter.h"

#include "aether/client_messages/p2p_message_stream.h"
#include "aether/client_messages/p2p_message_stream_manager.h"
// IWYU pragma: end_keeps

static ae::RcPtr<ae::AetherApp> aether_app;
static std::shared_ptr<ae::AetherApp> aether_app;

struct AetherClient {
ClientConfig config{};
Expand Down Expand Up @@ -81,7 +81,7 @@ ae::SelectClientAction& SelectClientImpl(AetherClient* client,
void* user_data;
};

auto select_context = ae::MakeRcPtr<SelectContext>(
auto select_context = std::make_shared<SelectContext>(
SelectContext{client, config->client_selected_cb,
config->message_received_cb, config->user_data});

Expand Down Expand Up @@ -310,7 +310,7 @@ int AetherEnd() {
default_client.reset();
}
int exit_code = aether_app->IsExited() ? aether_app->ExitCode() : 0;
aether_app.Reset();
aether_app.reset();
return exit_code;
}

Expand Down
1 change: 0 additions & 1 deletion aether/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "aether/obj/registry.h"
#include "aether/ptr/ptr.h"
#include "aether/ptr/ptr_view.h"
#include "aether/ptr/rc_ptr.h"

#include "aether/domain_storage/domain_storage_factory.h"
#include "aether/domain_storage/file_system_std_storage.h"
Expand Down
10 changes: 5 additions & 5 deletions aether/cloud_connections/cloud_server_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void CloudServerConnection::SetPriority(std::size_t priority) {
}

void CloudServerConnection::Restream() {
if (client_connection_.get() != nullptr) {
if (client_connection_) {
client_connection_->Restream();
}
}
Expand All @@ -44,15 +44,15 @@ void CloudServerConnection::SetQuarantine(bool value) {
}

bool CloudServerConnection::Connect() {
client_connection_.Reset();
client_connection_.reset();
client_connection_ = connection_factory_->CreateConnection(server());
return client_connection_.get() != nullptr;
return static_cast<bool>(client_connection_);
}

void CloudServerConnection::Disconnect() { client_connection_.Reset(); }
void CloudServerConnection::Disconnect() { client_connection_.reset(); }

ClientServerConnection* CloudServerConnection::client_connection() {
if (client_connection_.get() != nullptr) {
if (client_connection_) {
return client_connection_.get();
}
return nullptr;
Expand Down
5 changes: 3 additions & 2 deletions aether/cloud_connections/cloud_server_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#ifndef AETHER_CLOUD_CONNECTIONS_CLOUD_SERVER_CONNECTION_H_
#define AETHER_CLOUD_CONNECTIONS_CLOUD_SERVER_CONNECTION_H_

#include <memory>

#include "aether/ptr/ptr_view.h"
#include "aether/ptr/rc_ptr.h"

#include "aether/server_connections/client_server_connection.h"
#include "aether/server_connections/iserver_connection_factory.h"
Expand Down Expand Up @@ -49,7 +50,7 @@ class CloudServerConnection {
private:
PtrView<Server> server_;
IServerConnectionFactory* connection_factory_;
RcPtr<ClientServerConnection> client_connection_;
std::shared_ptr<ClientServerConnection> client_connection_;
std::size_t priority_;
bool is_quarantined_;
};
Expand Down
2 changes: 1 addition & 1 deletion aether/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

// Maximum size in bytes for a single pending response pool element.
#ifndef AE_API_PROTOCOL_PENDING_RESPONSE_MAX_SIZE
# define AE_API_PROTOCOL_PENDING_RESPONSE_MAX_SIZE 2 * sizeof(void*)
# define AE_API_PROTOCOL_PENDING_RESPONSE_MAX_SIZE 4 * sizeof(void*)
#endif

#ifndef AE_API_PROTOCOL_PENDING_RESPONSE_ALIGN
Expand Down
13 changes: 6 additions & 7 deletions aether/connection_manager/server_connection_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ ServerConnectionManager::ServerConnectionFactory::ServerConnectionFactory(
ServerConnectionManager& server_connection_manager)
: server_connection_manager_{&server_connection_manager} {}

RcPtr<ClientServerConnection>
ServerConnectionManager::ServerConnectionFactory::CreateConnection(
Ptr<Server> const& server) {
auto ServerConnectionManager::ServerConnectionFactory::CreateConnection(
Ptr<Server> const& server) -> std::shared_ptr<ClientServerConnection> {
return server_connection_manager_->CreateConnection(server);
}

Expand All @@ -39,8 +38,8 @@ ServerConnectionManager::GetServerConnectionFactory() {
return std::make_unique<ServerConnectionFactory>(*this);
}

RcPtr<ClientServerConnection> ServerConnectionManager::CreateConnection(
Ptr<Server> const& server) {
auto ServerConnectionManager::CreateConnection(Ptr<Server> const& server)
-> std::shared_ptr<ClientServerConnection> {
auto in_cache = FindInCache(server->server_id);
if (in_cache) {
return in_cache;
Expand All @@ -51,7 +50,7 @@ RcPtr<ClientServerConnection> ServerConnectionManager::CreateConnection(
assert(client);

auto connection =
MakeRcPtr<ClientServerConnection>(ae_context_, client, server);
std::make_shared<ClientServerConnection>(ae_context_, client, server);

// check updates
server_update_subs_ += connection->stream_update_event().Subscribe(
Expand All @@ -62,7 +61,7 @@ RcPtr<ClientServerConnection> ServerConnectionManager::CreateConnection(
return connection;
}

RcPtr<ClientServerConnection> ServerConnectionManager::FindInCache(
std::shared_ptr<ClientServerConnection> ServerConnectionManager::FindInCache(
ServerId server_id) const {
auto it = cached_connections_.find(server_id);
if (it != cached_connections_.end()) {
Expand Down
13 changes: 7 additions & 6 deletions aether/connection_manager/server_connection_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#define AETHER_CONNECTION_MANAGER_SERVER_CONNECTION_MANAGER_H_

#include <map>
#include <memory>

#include "aether/ptr/ptr.h"
#include "aether/ptr/rc_ptr.h"
#include "aether/ae_context.h"
#include "aether/ptr/ptr.h"
#include "aether/ptr/ptr_view.h"
#include "aether/server_connections/client_server_connection.h"
#include "aether/server_connections/iserver_connection_factory.h"
Expand All @@ -35,7 +35,7 @@ class ServerConnectionManager {
explicit ServerConnectionFactory(
ServerConnectionManager& server_connection_manager);

RcPtr<ClientServerConnection> CreateConnection(
std::shared_ptr<ClientServerConnection> CreateConnection(
Ptr<Server> const& server) override;

private:
Expand All @@ -48,16 +48,17 @@ class ServerConnectionManager {

std::unique_ptr<IServerConnectionFactory> GetServerConnectionFactory();

RcPtr<ClientServerConnection> CreateConnection(Ptr<Server> const& server);
std::shared_ptr<ClientServerConnection> CreateConnection(
Ptr<Server> const& server);

RcPtr<ClientServerConnection> FindInCache(ServerId server_id) const;
std::shared_ptr<ClientServerConnection> FindInCache(ServerId server_id) const;

private:
void ServerUpdate(ServerId server_id);

AeContext ae_context_;
PtrView<Client> client_;
std::map<ServerId, RcPtrView<ClientServerConnection>> cached_connections_;
std::map<ServerId, std::weak_ptr<ClientServerConnection>> cached_connections_;
MultiSubscription server_update_subs_;
};
} // namespace ae
Expand Down
28 changes: 15 additions & 13 deletions aether/domain_storage/file_system_std_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

#if defined AE_FILE_SYSTEM_STD_ENABLED

# include <filesystem>
# include <fstream>
# include <ios>
# include <set>
# include <string>
# include <fstream>
# include <filesystem>
# include <system_error>

# include "aether/domain_storage/domain_storage_tele.h"
Expand All @@ -38,8 +38,8 @@ class FstreamStorageWriter final : public IDomainStorageWriter {
file.close();
AE_TELE_DEBUG(kFileSystemDsObjSaved,
"Saved object id={}, class id={}, version={}, size={}",
query.id.ToString(), query.class_id,
static_cast<int>(query.version), written_size);
query.id, query.class_id, static_cast<int>(query.version),
written_size);
}

void write(void const* data, std::size_t size) override {
Expand Down Expand Up @@ -77,7 +77,8 @@ FileSystemStdStorage::~FileSystemStdStorage() = default;

std::unique_ptr<IDomainStorageWriter> FileSystemStdStorage::Store(
DomainQuery const& query) {
auto class_dir = std::filesystem::path("state") / query.id.ToString() /
auto class_dir = std::filesystem::path("state") /
std::to_string(query.id.id()) /
std::to_string(query.class_id);

std::filesystem::create_directories(class_dir);
Expand All @@ -94,7 +95,7 @@ ClassList FileSystemStdStorage::Enumerate(const ae::ObjId& obj_id) {

auto state_dir = std::filesystem::path{"state"};
auto ec = std::error_code{};
auto obj_dir = state_dir / obj_id.ToString();
auto obj_dir = state_dir / std::to_string(obj_id.id());
for (auto const& class_dir :
std::filesystem::directory_iterator(obj_dir, ec)) {
auto file_name = class_dir.path().filename().string();
Expand All @@ -111,7 +112,8 @@ ClassList FileSystemStdStorage::Enumerate(const ae::ObjId& obj_id) {
}

DomainLoad FileSystemStdStorage::Load(DomainQuery const& query) {
auto object_dir = std::filesystem::path("state") / query.id.ToString();
auto object_dir =
std::filesystem::path("state") / std::to_string(query.id.id());
auto ec = std::error_code{};
if (!std::filesystem::exists(object_dir, ec)) {
return {DomainLoadResult::kEmpty, {}};
Expand All @@ -134,16 +136,17 @@ DomainLoad FileSystemStdStorage::Load(DomainQuery const& query) {
return DomainLoad{DomainLoadResult::kEmpty, {}};
}

AE_TELE_DEBUG(
kFileSystemDsObjLoaded, "Loaded object id={}, class id={}, version={}",
query.id.ToString(), query.class_id, static_cast<int>(query.version));
AE_TELE_DEBUG(kFileSystemDsObjLoaded,
"Loaded object id={}, class id={}, version={}", query.id,
query.class_id, static_cast<int>(query.version));

return {DomainLoadResult::kLoaded,
std::make_unique<FstreamStorageReader>(std::move(f))};
}

void FileSystemStdStorage::Remove(ae::ObjId const& obj_id) {
auto object_dir = std::filesystem::path("state") / obj_id.ToString();
auto object_dir =
std::filesystem::path("state") / std::to_string(obj_id.id());
auto ec = std::error_code{};
if (!std::filesystem::exists(object_dir, ec)) {
std::filesystem::create_directory(object_dir);
Expand All @@ -164,8 +167,7 @@ void FileSystemStdStorage::Remove(ae::ObjId const& obj_id) {
class_dir.path().string(), ec2.message());
continue;
}
AE_TELE_DEBUG(kFileSystemDsObjRemoved, "Object removed {}",
obj_id.ToString());
AE_TELE_DEBUG(kFileSystemDsObjRemoved, "Object removed {}", obj_id);
}
if (ec) {
AE_TELE_ERROR(kFileSystemDsRemoveObjError,
Expand Down
Loading
Loading