Choco OS  V.0.16.9.0
Join to the chocolate world
PortMan - Port Manager

Helps to managing network ports in different protocols. More...

Data Structures

struct  oC_PortMan_Config_t
 stores configuration of the module More...
 

Typedefs

typedef uint32_t oC_PortMan_Port_t
 stores the port number
 

Functions

oC_ErrorCode_t oC_PortMan_TurnOn (void)
 turns on the module More...
 
oC_ErrorCode_t oC_PortMan_TurnOff (void)
 turns off the module More...
 
oC_ErrorCode_t oC_PortMan_RegisterModule (oC_Module_t Module, const oC_PortMan_Config_t *Config, oC_Time_t Timeout)
 registers module in the port manager More...
 
oC_ErrorCode_t oC_PortMan_UnregisterModule (oC_Module_t Module, oC_Time_t Timeout)
 unregisters module in the port manager More...
 
oC_ErrorCode_t oC_PortMan_ReservePort (oC_Module_t Module, oC_PortMan_Port_t *Port, oC_Time_t Timeout)
 reserves a port of the given module More...
 
oC_ErrorCode_t oC_PortMan_ReleasePort (oC_Module_t Module, oC_PortMan_Port_t Port, oC_Time_t Timeout)
 releases port More...
 
oC_ErrorCode_t oC_PortMan_ReleaseAllPortsOf (oC_Module_t Module, oC_Process_t Process, oC_Time_t Timeout)
 releases all ports reserved by a given process More...
 
bool oC_PortMan_IsPortReserved (oC_Module_t Module, oC_PortMan_Port_t Port)
 returns true if port is reserved More...
 
bool oC_PortMan_IsPortReservedBy (oC_Module_t Module, oC_PortMan_Port_t Port, oC_Process_t Process)
 checks if the given port is reserved by the given process More...
 

Detailed Description

Function Documentation

bool oC_PortMan_IsPortReserved ( oC_Module_t  Module,
oC_PortMan_Port_t  Port 
)

The function checks if the given port is reserved at the given module. '

Parameters
ModuleModule registered earlier
PortPort to check
Returns
true if the port is reserved

Definition at line 567 of file oc_portman.c.

bool oC_PortMan_IsPortReservedBy ( oC_Module_t  Module,
oC_PortMan_Port_t  Port,
oC_Process_t  Process 
)

The function is for checking if the given port is reserved by the given process.

Parameters
ModuleRegistered module
PortPort of the module to check
ProcessProcess object to check
Returns
true if port is reserved by the given process

Definition at line 602 of file oc_portman.c.

oC_ErrorCode_t oC_PortMan_RegisterModule ( oC_Module_t  Module,
const oC_PortMan_Config_t Config,
oC_Time_t  Timeout 
)

Each module, that uses the Port Manager for ports reservations has to register itself by using this function. It allocates memory required for handling reservations, creates required objects and puts the registration into the registrations list.

Warning
Only root user can register modules!
Parameters
ModuleID of the module to register
ConfigPointer to the structure with configuration of the module to register.
TimeoutMaximum time to wait for the registration

Here is an example of usage:

static const oC_PortMan_Config_t config = {
.FirstDynamicPortNumber = 1024 , // The first port number, that can be used as random port
.LastDynamicPortNumber = 2048 // The last port number, that can be used as random port
};
oC_SaveIfErrorOccur("Example module registration ", oC_PortMan_RegisterModule(oC_Module_ExampleModule, &config, s(1)));
Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet The module has not been turned on earlier
oC_ErrorCode_PermissionDenied Only root user can register modules
oC_ErrorCode_ModuleNotCorrect The given Module is not correct (please check if it is defined in the oc_module.h file
oC_ErrorCode_WrongAddress Address of the Config parameter is not correct
oC_ErrorCode_MaximumValueNotCorrect Config->MaximumPortNumber cannot be 0!
oC_ErrorCode_PortNotCorrect Config->FirstDynamicPortNumber or Config->LastDynamicPortNumber is incorrect
oC_ErrorCode_TimeNotCorrect Timeout is below 0
oC_ErrorCode_ModuleAlreadyRegistered The given module has been registered before
oC_ErrorCode_ModuleIsBusy Maximum time for the operation has expired and the module is still busy
oC_ErrorCode_AllocationError There is a problem with memory allocation

Definition at line 257 of file oc_portman.c.

oC_ErrorCode_t oC_PortMan_ReleaseAllPortsOf ( oC_Module_t  Module,
oC_Process_t  Process,
oC_Time_t  Timeout 
)

The function releases all ports that has been reserved by the given process. It is designed to provide a possibility to quickly and easy close a process by the kernel.

Parameters
ModuleIndex of the module registered earlier
ProcessProcess to release
TimeoutMaximum time for the operation
Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet The module has not been turned on earlier
oC_ErrorCode_ModuleNotCorrect The given Module is not correct (please check if it is defined in the oc_module.h file
oC_ErrorCode_TimeNotCorrect Timeout is below 0
oC_ErrorCode_ModuleNotRegistered The given module has not been registered before
oC_ErrorCode_ModuleIsBusy Maximum time for the operation has expired and the module is still busy
oC_ErrorCode_ReleaseError There is a problem with memory releasing
oC_ErrorCode_CannotRemoveObjectFromList Internal error related with removing port reservation from list

The function can also return an error code from the function oC_PortMan_ReleasePort

Definition at line 522 of file oc_portman.c.

oC_ErrorCode_t oC_PortMan_ReleasePort ( oC_Module_t  Module,
oC_PortMan_Port_t  Port,
oC_Time_t  Timeout 
)

The function is for releasing a port that has been reserved by the function oC_PortMan_ReservePort.

Parameters
ModuleModule of the port to release
PortPort to release
TimeoutMaximum time to wait for the port manager
Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet The module has not been turned on earlier
oC_ErrorCode_ModuleNotCorrect The given Module is not correct (please check if it is defined in the oc_module.h file
oC_ErrorCode_TimeNotCorrect Timeout is below 0
oC_ErrorCode_ModuleNotRegistered The given module has not been registered before
oC_ErrorCode_ModuleIsBusy Maximum time for the operation has expired and the module is still busy
oC_ErrorCode_ReleaseError There is a problem with memory releasing
oC_ErrorCode_CannotRemoveObjectFromList Internal error related with removing port reservation from list
oC_ErrorCode_PortNotCorrect The given port is too big for the given module
oC_ErrorCode_PortNotReserved The specified port has not been reserved

Definition at line 457 of file oc_portman.c.

oC_ErrorCode_t oC_PortMan_ReservePort ( oC_Module_t  Module,
oC_PortMan_Port_t Port,
oC_Time_t  Timeout 
)

The function reserves a port of the given module. The module has to be registered before by the function oC_PortMan_RegisterModule. If the Port argument will point to 0, then the port manager will try to find a first available dynamic port of the given module, that matches ID from the configuration of module registration (value between FirstDynamicPortNumber and LastDynamicPortNumber)

Parameters
ModuleRegistered module ID
PortAddress to the port on input or address to zero if you want to find a first free port
TimeoutMaximum time for operation
Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet The module has not been turned on earlier
oC_ErrorCode_ModuleNotCorrect The given Module is not correct (please check if it is defined in the oc_module.h file
oC_ErrorCode_TimeNotCorrect Timeout is below 0
oC_ErrorCode_ModuleNotRegistered The given module has not been registered before
oC_ErrorCode_ModuleIsBusy Maximum time for the operation has expired and the module is still busy
oC_ErrorCode_AllocationError There is a problem with memory allocation
oC_ErrorCode_PortNotCorrect The given port is too big for the given module
oC_ErrorCode_PortBusy The specified port or all ports (if the Port points to 0) are reserved

Definition at line 389 of file oc_portman.c.

oC_ErrorCode_t oC_PortMan_TurnOff ( void  )

The function is for turning off the module.

Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet The module has not been turned on earlier
oC_ErrorCode_PermissionDenied Only root user can turn off the module
oC_ErrorCode_ReleaseError There was a problem with releasing the memory

Definition at line 180 of file oc_portman.c.

oC_ErrorCode_t oC_PortMan_TurnOn ( void  )

The function turns on the module and initialize it to work.

Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleIsTurnedOn The module is already turned on
oC_ErrorCode_PermissionDenied Only root user can enable the module
oC_ErrorCode_AllocationError There was a problem with memory allocation

Definition at line 126 of file oc_portman.c.

oC_ErrorCode_t oC_PortMan_UnregisterModule ( oC_Module_t  Module,
oC_Time_t  Timeout 
)

Each module, that uses the Port Manager for ports reservations has to register itself by using oC_PortMan_RegisterModule function. When the module is not needed anymore, it should unregister itself in the Port Manager by using this function.

Warning
Only root user can register modules!
Parameters
ModuleID of the module to unregister
TimeoutMaximum time to wait for the unregistration
Returns
code of error or oC_ErrorCode_None if success

List of standard error codes, that can be returned by the function:

Code of error Description
oC_ErrorCode_ModuleNotStartedYet The module has not been turned on earlier
oC_ErrorCode_PermissionDenied Only root user can unregister modules
oC_ErrorCode_ModuleNotCorrect The given Module is not correct (please check if it is defined in the oc_module.h file
oC_ErrorCode_TimeNotCorrect Timeout is below 0
oC_ErrorCode_ModuleNotRegistered The given module has not been registered before
oC_ErrorCode_ModuleIsBusy Maximum time for the operation has expired and the module is still busy
oC_ErrorCode_ReleaseError There is a problem with memory releasing

Definition at line 328 of file oc_portman.c.