From fb790b07aeba8e22e4190cf3e1834d11ecde6c96 Mon Sep 17 00:00:00 2001 From: Amlal Date: Fri, 25 Apr 2025 13:08:33 +0200 Subject: dev: better .clang-format, ran format command. Signed-off-by: Amlal --- dev/kernel/NetworkKit/IP.h | 137 +++++++++++++++----------------- dev/kernel/NetworkKit/IPC.h | 130 +++++++++++++++--------------- dev/kernel/NetworkKit/LTE.h | 8 +- dev/kernel/NetworkKit/MAC.h | 34 ++++---- dev/kernel/NetworkKit/NetworkDevice.h | 101 ++++++++++++----------- dev/kernel/NetworkKit/NetworkDevice.inl | 37 ++++----- 6 files changed, 214 insertions(+), 233 deletions(-) (limited to 'dev/kernel/NetworkKit') diff --git a/dev/kernel/NetworkKit/IP.h b/dev/kernel/NetworkKit/IP.h index 5df23dc3..bf3b24ff 100644 --- a/dev/kernel/NetworkKit/IP.h +++ b/dev/kernel/NetworkKit/IP.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -8,76 +8,69 @@ #include #include -#include #include +#include + +namespace Kernel { +class RawIPAddress6; +class RawIPAddress; +class IPFactory; + +class RawIPAddress final { + private: + explicit RawIPAddress(char bytes[4]); + ~RawIPAddress() = default; + + RawIPAddress& operator=(const RawIPAddress&) = delete; + RawIPAddress(const RawIPAddress&) = default; + + public: + Char* Address(); + + Char& operator[](const Size& index); + + BOOL operator==(const RawIPAddress& ipv6); + BOOL operator!=(const RawIPAddress& ipv6); + + private: + Char fAddr[4]; + + friend IPFactory; // it is the one creating these addresses, thus this + // is why the constructors are private. +}; + +/** + * @brief IPv6 address. + */ +class RawIPAddress6 final { + private: + explicit RawIPAddress6(char Bytes[8]); + ~RawIPAddress6() = default; + + RawIPAddress6& operator=(const RawIPAddress6&) = delete; + RawIPAddress6(const RawIPAddress6&) = default; + + public: + char* Address() { return fAddr; } + + char& operator[](const Size& index); + + bool operator==(const RawIPAddress6& ipv6); + bool operator!=(const RawIPAddress6& ipv6); + + private: + char fAddr[8]; + + friend IPFactory; +}; -namespace Kernel -{ - class RawIPAddress6; - class RawIPAddress; - class IPFactory; - - class RawIPAddress final - { - private: - explicit RawIPAddress(char bytes[4]); - ~RawIPAddress() = default; - - RawIPAddress& operator=(const RawIPAddress&) = delete; - RawIPAddress(const RawIPAddress&) = default; - - public: - Char* Address(); - - Char& operator[](const Size& index); - - BOOL operator==(const RawIPAddress& ipv6); - BOOL operator!=(const RawIPAddress& ipv6); - - private: - Char fAddr[4]; - - friend IPFactory; // it is the one creating these addresses, thus this - // is why the constructors are private. - }; - - /** - * @brief IPv6 address. - */ - class RawIPAddress6 final - { - private: - explicit RawIPAddress6(char Bytes[8]); - ~RawIPAddress6() = default; - - RawIPAddress6& operator=(const RawIPAddress6&) = delete; - RawIPAddress6(const RawIPAddress6&) = default; - - public: - char* Address() - { - return fAddr; - } - - char& operator[](const Size& index); - - bool operator==(const RawIPAddress6& ipv6); - bool operator!=(const RawIPAddress6& ipv6); - - private: - char fAddr[8]; - - friend IPFactory; - }; - - /** - * @brief IP Creation helpers - */ - class IPFactory final - { - public: - static ErrorOr ToKString(Ref& ipv6); - static ErrorOr ToKString(Ref& ipv4); - static bool IpCheckVersion4(const Char* ip); - }; -} // namespace Kernel +/** + * @brief IP Creation helpers + */ +class IPFactory final { + public: + static ErrorOr ToKString(Ref& ipv6); + static ErrorOr ToKString(Ref& ipv4); + static bool IpCheckVersion4(const Char* ip); +}; +} // namespace Kernel diff --git a/dev/kernel/NetworkKit/IPC.h b/dev/kernel/NetworkKit/IPC.h index 6de306b2..43b58d35 100644 --- a/dev/kernel/NetworkKit/IPC.h +++ b/dev/kernel/NetworkKit/IPC.h @@ -1,9 +1,9 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.. - File: IPC.h. - Purpose: IPC protocol. + File: IPC.h. + Purpose: IPC protocol. ------------------------------------------- */ @@ -25,67 +25,63 @@ #define kIPCHeaderMagic (0x4950434) -namespace Kernel -{ - struct IPC_ADDR; - struct IPC_MSG; - - /// @brief 128-bit IPC address. - struct PACKED IPC_ADDR final - { - UInt64 UserProcessID; - UInt64 UserProcessTeam; - - //////////////////////////////////// - // some operators. - //////////////////////////////////// - - bool operator==(const IPC_ADDR& addr) noexcept; - - bool operator==(IPC_ADDR& addr) noexcept; - - bool operator!=(const IPC_ADDR& addr) noexcept; - - bool operator!=(IPC_ADDR& addr) noexcept; - }; - - typedef struct IPC_ADDR IPC_ADDR; - - enum - { - kIPCLittleEndian = 0, - kIPCBigEndian = 1, - kIPCMixedEndian = 2, - }; - - constexpr inline auto kIPCMsgSize = 6094U; - - /// @brief IPC connection header, message cannot be greater than 6K. - typedef struct IPC_MSG final - { - UInt32 IpcHeaderMagic; // cRemoteHeaderMagic - UInt8 IpcEndianess; // 0 : LE, 1 : BE - SizeT IpcPacketSize; - IPC_ADDR IpcFrom; - IPC_ADDR IpcTo; - UInt32 IpcCRC32; - UInt32 IpcMsg; - UInt32 IpcMsgSz; - UInt8 IpcData[kIPCMsgSize]; - - /// @brief Passes the message to target, could be anything, HTTP packet, JSON or whatever. - static Bool Pass(IPC_MSG* self, IPC_MSG* target) noexcept; - } PACKED IPC_MSG; - - /// @brief Sanitize packet function - /// @retval true packet is correct. - /// @retval false packet is incorrect and process has crashed. - Bool ipc_sanitize_packet(_Input IPC_MSG* pckt_in); - - /// @brief Construct packet function - /// @retval true packet is correct. - /// @retval false packet is incorrect and process has crashed. - Bool ipc_construct_packet(_Output _Input IPC_MSG** pckt_in); -} // namespace Kernel - -#endif // INC_IPC_H +namespace Kernel { +struct IPC_ADDR; +struct IPC_MSG; + +/// @brief 128-bit IPC address. +struct PACKED IPC_ADDR final { + UInt64 UserProcessID; + UInt64 UserProcessTeam; + + //////////////////////////////////// + // some operators. + //////////////////////////////////// + + bool operator==(const IPC_ADDR& addr) noexcept; + + bool operator==(IPC_ADDR& addr) noexcept; + + bool operator!=(const IPC_ADDR& addr) noexcept; + + bool operator!=(IPC_ADDR& addr) noexcept; +}; + +typedef struct IPC_ADDR IPC_ADDR; + +enum { + kIPCLittleEndian = 0, + kIPCBigEndian = 1, + kIPCMixedEndian = 2, +}; + +constexpr inline auto kIPCMsgSize = 6094U; + +/// @brief IPC connection header, message cannot be greater than 6K. +typedef struct IPC_MSG final { + UInt32 IpcHeaderMagic; // cRemoteHeaderMagic + UInt8 IpcEndianess; // 0 : LE, 1 : BE + SizeT IpcPacketSize; + IPC_ADDR IpcFrom; + IPC_ADDR IpcTo; + UInt32 IpcCRC32; + UInt32 IpcMsg; + UInt32 IpcMsgSz; + UInt8 IpcData[kIPCMsgSize]; + + /// @brief Passes the message to target, could be anything, HTTP packet, JSON or whatever. + static Bool Pass(IPC_MSG* self, IPC_MSG* target) noexcept; +} PACKED IPC_MSG; + +/// @brief Sanitize packet function +/// @retval true packet is correct. +/// @retval false packet is incorrect and process has crashed. +Bool ipc_sanitize_packet(_Input IPC_MSG* pckt_in); + +/// @brief Construct packet function +/// @retval true packet is correct. +/// @retval false packet is incorrect and process has crashed. +Bool ipc_construct_packet(_Output _Input IPC_MSG** pckt_in); +} // namespace Kernel + +#endif // INC_IPC_H diff --git a/dev/kernel/NetworkKit/LTE.h b/dev/kernel/NetworkKit/LTE.h index c44841de..71254cbf 100644 --- a/dev/kernel/NetworkKit/LTE.h +++ b/dev/kernel/NetworkKit/LTE.h @@ -1,9 +1,9 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.. - File: LTE.h. - Purpose: LTE protocol classes. + File: LTE.h. + Purpose: LTE protocol classes. ------------------------------------------- */ @@ -13,4 +13,4 @@ #include #include -#endif // ifndef _INC_NETWORK_LTE_H_ +#endif // ifndef _INC_NETWORK_LTE_H_ diff --git a/dev/kernel/NetworkKit/MAC.h b/dev/kernel/NetworkKit/MAC.h index 0509fed4..8520037e 100644 --- a/dev/kernel/NetworkKit/MAC.h +++ b/dev/kernel/NetworkKit/MAC.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -12,25 +12,23 @@ #define kMACAddrLen (32) -namespace Kernel -{ - class MacAddressGetter; +namespace Kernel { +class MacAddressGetter; - /// \brief This retrieves the MAC address of the device. - /// \note Listens for the current NIC. - class MacAddressGetter final - { - public: - MacAddressGetter() = default; - ~MacAddressGetter() = default; +/// \brief This retrieves the MAC address of the device. +/// \note Listens for the current NIC. +class MacAddressGetter final { + public: + MacAddressGetter() = default; + ~MacAddressGetter() = default; - NE_COPY_DEFAULT(MacAddressGetter) + NE_COPY_DEFAULT(MacAddressGetter) - public: - Array& AsBytes(); + public: + Array& AsBytes(); - private: - Array fMacAddress; - }; + private: + Array fMacAddress; +}; -} // namespace Kernel +} // namespace Kernel diff --git a/dev/kernel/NetworkKit/NetworkDevice.h b/dev/kernel/NetworkKit/NetworkDevice.h index 48e4e883..7ed67bab 100644 --- a/dev/kernel/NetworkKit/NetworkDevice.h +++ b/dev/kernel/NetworkKit/NetworkDevice.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -12,72 +12,69 @@ /// @note Can either work with: Ethernet, GPRS, WiFi -namespace Kernel -{ - struct NetworkDeviceCommand; - class NetworkDevice; +namespace Kernel { +struct NetworkDeviceCommand; +class NetworkDevice; - /** - * \brief Network device interface, establishes a connection to the NIC. - */ - class NetworkDevice final : public IDeviceObject - { - public: - NetworkDevice(void (*out)(IDeviceObject*, NetworkDeviceCommand), - void (*in)(IDeviceObject*, NetworkDeviceCommand), - void (*onCleanup)(void) = nullptr); +/** + * \brief Network device interface, establishes a connection to the NIC. + */ +class NetworkDevice final : public IDeviceObject { + public: + NetworkDevice(void (*out)(IDeviceObject*, NetworkDeviceCommand), + void (*in)(IDeviceObject*, NetworkDeviceCommand), + void (*onCleanup)(void) = nullptr); - ~NetworkDevice() override; + ~NetworkDevice() override; - public: - NetworkDevice& operator=(const NetworkDevice&) = default; - NetworkDevice(const NetworkDevice&) = default; + public: + NetworkDevice& operator=(const NetworkDevice&) = default; + NetworkDevice(const NetworkDevice&) = default; - public: - const Char* Name() const override; - Boolean Name(const Char* newStr); + public: + const Char* Name() const override; + Boolean Name(const Char* newStr); - private: - static constexpr auto cNetworkNameLen = 512; + private: + static constexpr auto cNetworkNameLen = 512; - Void (*fCleanup)(void); - Char fNetworkName[cNetworkNameLen]; - }; + Void (*fCleanup)(void); + Char fNetworkName[cNetworkNameLen]; +}; - struct NetworkDeviceCommand final - { - UInt32 CommandName; - UInt32 CommandType; - UInt32 CommandFlags; - VoidPtr CommandBuffer; - SizeT CommandSizeBuffer; - }; +struct NetworkDeviceCommand final { + UInt32 CommandName; + UInt32 CommandType; + UInt32 CommandFlags; + VoidPtr CommandBuffer; + SizeT CommandSizeBuffer; +}; - /// @brief TCP device. - using TCPNetworkDevice = NetworkDevice; +/// @brief TCP device. +using TCPNetworkDevice = NetworkDevice; - /// @brief UDP device. - using UDPNetworkDevice = NetworkDevice; +/// @brief UDP device. +using UDPNetworkDevice = NetworkDevice; - /// @brief PPP device. - using PPPNetworkDevice = NetworkDevice; +/// @brief PPP device. +using PPPNetworkDevice = NetworkDevice; - /// @brief IPC device. - using IPCNetworkDevice = NetworkDevice; +/// @brief IPC device. +using IPCNetworkDevice = NetworkDevice; - /// @brief GRPS device. - using GPRSNetworkDevice = NetworkDevice; +/// @brief GRPS device. +using GPRSNetworkDevice = NetworkDevice; - /// @brief GSM device. - using GSMNetworkDevice = NetworkDevice; +/// @brief GSM device. +using GSMNetworkDevice = NetworkDevice; - /// @brief Bluetooth device. - using BTNetworkDevice = NetworkDevice; +/// @brief Bluetooth device. +using BTNetworkDevice = NetworkDevice; - /// @brief LTE device. - using LTENetworkDevice = NetworkDevice; -} // namespace Kernel +/// @brief LTE device. +using LTENetworkDevice = NetworkDevice; +} // namespace Kernel #include -#endif // !__INC_NETWORK_DEVICE_H__ +#endif // !__INC_NETWORK_DEVICE_H__ diff --git a/dev/kernel/NetworkKit/NetworkDevice.inl b/dev/kernel/NetworkKit/NetworkDevice.inl index c16756b1..797b8adc 100644 --- a/dev/kernel/NetworkKit/NetworkDevice.inl +++ b/dev/kernel/NetworkKit/NetworkDevice.inl @@ -1,32 +1,29 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ /*** - Dtor and ctors. + Dtor and ctors. */ -namespace Kernel -{ - NetworkDevice::NetworkDevice(void (*out)(IDeviceObject*, NetworkDeviceCommand), - void (*in)(IDeviceObject*, NetworkDeviceCommand), - void (*on_cleanup)(void)) - : IDeviceObject(out, in), fCleanup(on_cleanup) - { - kout << "NetworkDevice initialized.\r"; +namespace Kernel { +NetworkDevice::NetworkDevice(void (*out)(IDeviceObject*, + NetworkDeviceCommand), + void (*in)(IDeviceObject*, NetworkDeviceCommand), + void (*on_cleanup)(void)) + : IDeviceObject(out, in), fCleanup(on_cleanup) { + kout << "NetworkDevice initialized.\r"; - MUST_PASS(out && in && on_cleanup); - } + MUST_PASS(out && in && on_cleanup); +} - NetworkDevice::~NetworkDevice() - { - MUST_PASS(fCleanup); +NetworkDevice::~NetworkDevice() { + MUST_PASS(fCleanup); - kout << "NetworkDevice cleanup.\r"; + kout << "NetworkDevice cleanup.\r"; - if (fCleanup) - fCleanup(); - } -} // namespace Kernel + if (fCleanup) fCleanup(); +} +} // namespace Kernel -- cgit v1.2.3