Skip to main content
Version: 2.6.1

Packages

What are packages used for​

As explained in the architecture page, Luos is a platform that handles packages execution.

The traditional way of writing code is still monolithic: all functionalities are used in one big main() function and are tightly dependent with each other. This leads to complex development, debug, and maintainability needs when the code base grows bigger. It also leads to complex collaboration with other developers. Luos tries to separate this monolithic architecture into independant and weak-coupled blocks of code. It does so by giving to developers high-level APIs to create these blocks and make them communicate with each other.

Packages represent these blocks of code. They contain independent functionalities which will be run by Luos engine.

Relation with services​

From a logical view, a package handles one or a group of functionalities, independent from the rest of the system. Still, we don't have any information on how thess functionalities should be executed: it can be run either as a single task or as smaller tasks talking to each other. Services, however, give this control level: a package can initialize as much services as it needs to run its functionalities.

Note: Each package has to run at least one service.

How to properly organize your Luos projects​

How to add packages in your project​

A Luos node can host multiple packages, and a package has to be as portable as possible. In order to do that, packages have to be independent code folders that can be easily copied and pasted in another project.

You can find a view of complete product on Code organization page.

When we are designing a projects at Luos, we always use the same way to organize our code: we put the packages into a packages folder (sometimes called lib) on a node project, and every packages have their own folder allowing them to be easily copied and pasted into any other node project:

 Node
β”‚
β”œβ”€β”€β”€ Packages
β”‚ β”œβ”€β”€β”€ Package_1
β”‚ β”‚ β”œβ”€β”€β”€ package_1.c
β”‚ β”‚ └─── package_1.h
β”‚ └─── Package_2
β”‚ β”œβ”€β”€β”€ package_2.c
β”‚ └─── package_2.h
β”‚
└─── main.c

Basic packages functions​

We choose to put the public functions of our services in the package.h file. As said above, services are lightweight tasks that need to be run regularly. We choose to use the exact same strategy as presented for Luos engine's functions by providing a Package_Init() and a Package_Loop(): services are created in Package_Init(), and the application code is placed in Package_Loop() (see service creation page for more information).

Then packages are initialized and run in the main() function:

#include "luos_engine.h"
#include "package1.h"
#include "package2.h"

int main(void)
{
Luos_Init();
Package1_Init();
Package2_Init();
while(1)
{
Luos_Loop();
Package1_Loop();
Package2_Loop();
}
return 0;
}

This way, it is easy to manage all your services and add as many of them you want into main().

A feedback? Let's discuss onΒ DiscordΒ |Β Github