Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform Abstraction Layer #208

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ncvicchi
Copy link
Member

@ncvicchi ncvicchi commented Oct 8, 2024

Related issue
#167

NOTE: Currently the PAL proposed and described in this PR will be moved and restricted to the Inventory module only.

Platform Abstraction Layer (PAL)

The aim of this module is to provide a the tools necessary to independize wazuh agent's code from the platform it will be compile for.
Since we are currently using GNU C for Linux. AppleClang for MacOS and MSVC for Windows, this will be used to identify the correspoding platform during compile time.

Hierarchy

pal
 ├── README.md
 ├── CMakeLists.txt
 ├── include 
 │   ├── Linux
 │   │    ├── pal_file.h
 │   │    ├── pal_thread.h
 │   │    ├── pal_time.h
 │   │    └── pal.h
 │   ├── macos
 │   │    ├── pal_file.h
 │   │    ├── pal_thread.h
 │   │    ├── pal_time.h
 │   │    └── pal.h
 │   └── windows
 │        ├── pal_file.h
 │        ├── pal_thread.h
 │        ├── pal_time.h
 │        └── pal.h
 └── src
     ├── Linux
     │    ├── pal_file.c
     │    ├── pal_thread.c
     │    ├── pal_time.c
     │    └── pal.c
     ├── macos
     │    ├── pal_file.c
     │    ├── pal_thread.c
     │    ├── pal_time.c
     │    └── pal.c
     └── windows
          ├── pal_file.c
          ├── pal_thread.c
          ├── pal_time.c
          └── pal.c

Usage

A commom public file named "pal.h" should be included in every file that will be platform dependant. No more includes should be necessary.
Thos definitions, prototypes, etc, provided by the PAL should be used in Wazuh agent's code, avoiding whenever possible the usage of pre-processor in higher level code.
If situations not considered in the PAL are found during development, it should be prioritized to extend the PAL than taking shortcuts as ad-hoc solutions, except if this option is no available for implementation reasons.

@ncvicchi ncvicchi self-assigned this Oct 9, 2024
@cborla cborla linked an issue Oct 9, 2024 that may be closed by this pull request
5 tasks
@vikman90
Copy link
Member

@ncvicchi, thanks for the suggestion. There are some files that, perhaps because they are still empty, I did not fully understand. For example, "priv_pal_time.h" and "priv_pal_thread.h".

If what we need is to provide an abstraction of time management, threads, etc., we had in mind to build small helper components, which would present a common interface (header) and an implementation for each platform.

Greetings!

@ncvicchi ncvicchi force-pushed the enhancement/167-platform-abstraction-layer branch from 5909139 to 22c281e Compare November 7, 2024 18:39
@ncvicchi ncvicchi force-pushed the enhancement/167-platform-abstraction-layer branch 3 times, most recently from 4ec30fa to 23397ea Compare November 26, 2024 14:45
@ncvicchi ncvicchi closed this Nov 26, 2024
@ncvicchi ncvicchi reopened this Nov 26, 2024
@ncvicchi
Copy link
Member Author

ncvicchi commented Nov 26, 2024

@ncvicchi, thanks for the suggestion. There are some files that, perhaps because they are still empty, I did not fully understand. For example, "priv_pal_time.h" and "priv_pal_thread.h".

If what we need is to provide an abstraction of time management, threads, etc., we had in mind to build small helper components, which would present a common interface (header) and an implementation for each platform.

Greetings!

Here is an example of why I think a platform abstraction layer is way better than helpers:

We can avoid almost all #ifdef in source codes if we centralize them in a PAL.

Helpers (IMHO) are useful to enclose several repetitive functionalities, not to avoid platform differences. A PAL seems to me a better way to keep tidier the code and simplifying debugging and testing.

@cborla

@ncvicchi ncvicchi force-pushed the enhancement/167-platform-abstraction-layer branch from 23397ea to 946b787 Compare November 29, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Compilation for Inventory Module on Windows Using MSVC
2 participants