diff options
Diffstat (limited to 'dev/ZKAKit/NetworkKit')
| -rw-r--r-- | dev/ZKAKit/NetworkKit/IPC.h | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/dev/ZKAKit/NetworkKit/IPC.h b/dev/ZKAKit/NetworkKit/IPC.h index 05748e3a..991e3fcd 100644 --- a/dev/ZKAKit/NetworkKit/IPC.h +++ b/dev/ZKAKit/NetworkKit/IPC.h @@ -7,8 +7,8 @@ ------------------------------------------- */ -#ifndef _INC_IPC_ENDPOINT_H_ -#define _INC_IPC_ENDPOINT_H_ +#ifndef INC_IPC_H +#define INC_IPC_H #include <NewKit/Defines.h> #include <NewKit/KString.h> @@ -16,23 +16,23 @@ #include <CompressKit/RLE.h> /// @file IPC.h -/// @brief IPC EP protocol. +/// @brief IPC comm. protocol. /// IA separator. -#define cXPCOMRemoteSeparator ":" +#define kIPCRemoteSeparator ":" /// Interchange address, consists of PID:TEAM. -#define cXPCOMRemoteInvalid "00:00" +#define kIPCRemoteInvalid "00:00" -#define cXPCOMHeaderMagic (0x4950434) +#define kIPCHeaderMagic (0x4950434) namespace Kernel { - struct IPC_ADDRESS_STRUCT; - struct IPC_MESSAGE_STRUCT; + struct IPCAddress; + struct IPCMessage; /// @brief 128-bit IPC address. - struct PACKED IPC_ADDRESS_STRUCT final + struct PACKED IPCAddress final { UInt64 UserProcessID; UInt64 UserProcessTeam; @@ -41,30 +41,30 @@ namespace Kernel // some operators. //////////////////////////////////// - bool operator==(const IPC_ADDRESS_STRUCT& addr) noexcept + bool operator==(const IPCAddress& addr) noexcept { return addr.UserProcessID == this->UserProcessID && addr.UserProcessTeam == this->UserProcessTeam; } - bool operator==(IPC_ADDRESS_STRUCT& addr) noexcept + bool operator==(IPCAddress& addr) noexcept { return addr.UserProcessID == this->UserProcessID && addr.UserProcessTeam == this->UserProcessTeam; } }; - typedef struct IPC_ADDRESS_STRUCT IPCEPAddressKind; + typedef struct IPCAddress IPCEPAddressKind; enum { - eIPCEPLittleEndian = 0, - eIPCEPBigEndian = 1, - eIPCEPMixedEndian = 2, + kIPCLittleEndian = 0, + kIPCBigEndian = 1, + kIPCMixedEndian = 2, }; - constexpr auto cXPCOMMsgSize = 6094U; + constexpr inline auto kIPCMsgSize = 6094U; /// @brief IPC connection header, message cannot be greater than 6K. - typedef struct IPC_MESSAGE_STRUCT final + typedef struct IPCMessage final { UInt32 IpcHeaderMagic; // cRemoteHeaderMagic UInt8 IpcEndianess; // 0 : LE, 1 : BE @@ -74,18 +74,34 @@ namespace Kernel UInt32 IpcCRC32; UInt32 IpcMsg; UInt32 IpcMsgSz; - UInt8 IpcData[cXPCOMMsgSize]; - } PACKED IPC_MESSAGE_STRUCT; + UInt8 IpcData[kIPCMsgSize]; + + /// @brief Passes the message to target, could be anything, HTTP packet, JSON or whatever. + Bool Pass(IPCMessage* target) noexcept + { + if (target && target->IpcFrom == this->IpcTo) + { + if (this->IpcMsgSz > target->IpcMsgSz) + return No; + + rt_copy_memory(this->IpcData, target->IpcData, this->IpcMsgSz); + + return Yes; + } + + return No; + } + } PACKED IPCMessage; /// @brief Sanitize packet function /// @retval true packet is correct. /// @retval false packet is incorrect and process has crashed. - Bool ipc_sanitize_packet(_Input IPC_MESSAGE_STRUCT* pckt_in); + Bool ipc_sanitize_packet(_Input IPCMessage* 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 IPC_MESSAGE_STRUCT** pckt_in); + Bool ipc_construct_packet(_Output _Input IPCMessage** pckt_in); } // namespace Kernel -#endif // _INC_IPC_ENDPOINT_H_ +#endif // INC_IPC_H |
