XROAD
xroad_node.h File Reference
#include "xroad_system.h"
#include "xroad_node_types.h"
#include <cache/xroad_objects_types.h>
#include <cache/xroad_cache.h>
#include <cache/xroad_storage_fwd.h>
#include <common/xroad_xml.h>
#include <common/xroad_string.h>
#include <common/xroad_aux.h>
#include <tracing/xroad_tracing_fwd.h>
#include <reactor/xroad_reactor_types.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/epoll.h>
Include dependency graph for xroad_node.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  xroad_node_callback_t
 

Macros

#define xroad_node_is_offline()
 
#define xroad_node_trace_init_writer(_enabled, _trace_var, _trace_rec_struct, ...)
 
#define xroad_node_trace_close(_trace_var)   xroad_node_trace_close_ex(&_trace_var.stream)
 Helper macro to close a trace writer by trace variable.
 
#define xroad_node_find_object(type, fun, ...)
 

Typedefs

typedef xroad_epoll_callback_t xroad_node_epoll_callback_t
 
typedef xroad_reactor_timestamps_t xroad_epoll_timestamps
 Timestamps associated with epoll.
 
typedef struct xroad_lock_by_pid_s xroad_lock_by_pid_t
 
typedef struct xroad_cache_s xroad_cache_t
 Forward declaration of xroad_cache_t (from xroad_cache)
 

Functions

xroad_errno_t xroad_node_create (xroad_str_t node_name, uint16_t major_version, uint16_t minor_version, uint16_t patch_version, xroad_str_t git_hash, xroad_node_callback_t callback)
 
void xroad_node_destroy (void)
 
xroad_errno_t xroad_node_reconfig (void)
 
xroad_xml_doc_t * xroad_node_get_config (void)
 
const xroad_epoll_timestamps * xroad_node_get_epoll_timestamps (void) __attribute_const__
 
int32_t xroad_node_receive (void)
 
int32_t xroad_node_receive_ex (int32_t timeout)
 
xroad_errno_t xroad_node_add_epoll (uint32_t events, xroad_node_epoll_callback_t *cback)
 
xroad_errno_t xroad_node_mod_epoll (uint32_t events, xroad_node_epoll_callback_t *cback)
 
xroad_errno_t xroad_node_del_epoll (xroad_node_epoll_callback_t *cback)
 
int32_t xroad_node_get_epoll_fd (void)
 
void * xroad_node_create_object (xroad_object_type_t type)
 
void * xroad_node_clone_object (const void *obj)
 
xroad_errno_t xroad_node_send_object (void *obj, xroad_node_id_t id)
 
xroad_errno_t xroad_node_route_object (void *obj,...)
 
xroad_errno_t xroad_node_route_object_va (void *obj, va_list ap)
 
void * xroad_node_get_fun (xroad_str_t fname)
 
void * xroad_node_get_object (xroad_object_type_t type, xroad_object_id_t id)
 
xroad_lock_by_pid_t * xroad_node_get_used_lock (void)
 
xroad_node_data_t * xroad_node_get_data (void) __attribute_const__
 
void xroad_node_reset_statistic (void)
 
xroad_str_t xroad_node_get_working_dir (void)
 
void xroad_node_set_flags (uint32_t flags)
 
xroad_cursor_t * xroad_node_create_cursor (xroad_object_type_t type)
 
void xroad_node_destroy_cursor (xroad_cursor_t *cursor)
 
void * xroad_node_cursor_get_next (xroad_cursor_t *cursor)
 
void * xroad_node_cursor_get_prev (xroad_cursor_t *cursor)
 
void * xroad_node_cursor_get_first (xroad_cursor_t *cursor)
 
void * xroad_node_cursor_get_last (xroad_cursor_t *cursor)
 
void * xroad_node_cursor_offset (xroad_cursor_t *cursor, int64_t offset)
 
void xroad_node_cursor_refresh (xroad_cursor_t *cursor)
 
xroad_errno_t xroad_node_clear_cache (xroad_object_type_t type, bool force)
 
xroad_cache_t * xroad_node_get_cache () __attribute_const__
 
size_t xroad_node_get_object_count (xroad_object_type_t type)
 
const xroad_version_t * xroad_node_get_version (void) __attribute_const__
 
bool xroad_node_is_initialized (void)
 
xroad_errno_t xroad_node_subscribe (xroad_domain_t group, xroad_node_callback_t cback)
 
xroad_errno_t xroad_node_unsubscribe (xroad_domain_t group, xroad_node_callback_t cback)
 
xroad_str_t xroad_node_get_env_param (xroad_str_t param)
 
void xroad_node_renamed ()
 
void xroad_node_enable_alarm ()
 
void xroad_node_disable_alarm ()
 
bool xroad_node_has_mtt (void)
 Returns true if the node has maintenance thread.
 
bool xroad_node_is_busypolling (void)
 Return true if the node is in busy-poll mode (wait_timeout == 0)
 
xroad_tracing_t * xroad_node_get_tracing (void)
 Return a tracing subsystem instance (it could lazy constructed)
 
xroad_errno_t xroad_node_trace_init_writer_ex (bool enabled, const xroad_traces_ctl_param_t *params, xroad_trace_stream_t *writer)
 
xroad_errno_t xroad_node_trace_close_ex (xroad_trace_stream_t *writer)
 

Detailed Description

Macro Definition Documentation

◆ xroad_node_find_object

#define xroad_node_find_object (   type,
  fun,
  ... 
)
Value:
({ \
xroad_cursor_t* cur __xroad_cursor_dtor__ = xroad_node_create_cursor(type); \
void* obj = xroad_node_cursor_get_first(cur); \
while(obj) \
{ \
if (fun(obj, __VA_ARGS__)) \
{ \
break; \
} \
} \
obj; \
})
#define __xroad_cursor_dtor__
Definition: xroad_cache.h:117
void * xroad_node_cursor_get_next(xroad_cursor_t *cursor)
void * xroad_node_cursor_get_first(xroad_cursor_t *cursor)
xroad_cursor_t * xroad_node_create_cursor(xroad_object_type_t type)

find object using functor

Parameters
[in]type- object type
[in]fun- functor like bool fun(....) @oaram[in] ... - functor params
Returns
found object, NULL nothing found

◆ xroad_node_is_offline

#define xroad_node_is_offline ( )
Value:
xroad_node_get_data()->status == xroad_node_status_sleep)
xroad_node_status_t status
node status
Definition: xroad_system.h:146
xroad_node_data_t * xroad_node_get_data(void) __attribute_const__
@ xroad_node_status_sleep
node is sleeping
Definition: xroad_system.h:34
@ xroad_node_status_offline
node started, but is not active
Definition: xroad_system.h:31

◆ xroad_node_trace_init_writer

#define xroad_node_trace_init_writer (   _enabled,
  _trace_var,
  _trace_rec_struct,
  ... 
)
Value:
({ \
xroad_traces_ctl_param_t params = {.size = sizeof(xroad_traces_ctl_param_t), ##__VA_ARGS__}; \
params.fields = _trace_rec_struct##_get_field_descr(); \
xroad_node_trace_init_writer_ex(_enabled, &params, &_trace_var.stream); \
})
struct xroad_traces_ctl_param_s xroad_traces_ctl_param_t
Parameters structure for opening trace series controller.

Init trace writer shortcut without returning a control object

Parameters
enabled- if tracing is not enabed, writer is initialized with a stub
_trace_var- trace variable name (see xroad_traces_writer_decl macro)
...- xroad_traces_ctl_param_t fields (use designated initializers syntax).

Typedef Documentation

◆ xroad_node_epoll_callback_t

Function Documentation

◆ xroad_node_add_epoll()

xroad_errno_t xroad_node_add_epoll ( uint32_t  events,
xroad_node_epoll_callback_t *  cback 
)

add descriptor to epoll

Parameters
[in]events- fd events
[in]cback- pointer to epoll callback
Returns
XROAD_ERROR_OK - done

◆ xroad_node_clear_cache()

xroad_errno_t xroad_node_clear_cache ( xroad_object_type_t  type,
bool  force 
)

clear object cache

Parameters
[in]type- type of objects to clear
[in]force- force clear
Returns
XROAD_OK - cleared, else failed

◆ xroad_node_clone_object()

void* xroad_node_clone_object ( const void *  obj)

clone object

Parameters
[in]obj- object to clone
Returns
cloned object

◆ xroad_node_create()

xroad_errno_t xroad_node_create ( xroad_str_t  node_name,
uint16_t  major_version,
uint16_t  minor_version,
uint16_t  patch_version,
xroad_str_t  git_hash,
xroad_node_callback_t  callback 
)

create new node and registers in system

Parameters
[in]node_name- name of new node. Can be NULL.
[in]major_version- marjor version. Override value from xroad_version.c
[in]minor_version- minor version. Override value from xroad_version.c
[in]patch_version- patch version. Override value from xroad_version.c
[in]git_hash- git hash. Override value from xroad_version.c
[in]callback- callback method for objects
Returns
XROAD_OK - created, XROAD_ERROR_ALREADY_EXISTS - node already created

◆ xroad_node_create_cursor()

xroad_cursor_t* xroad_node_create_cursor ( xroad_object_type_t  type)

create new cache cursor

Parameters
[in]type- type of cursor
Returns
pointer to new cursor

◆ xroad_node_create_object()

void* xroad_node_create_object ( xroad_object_type_t  type)

create new object

Parameters
[in]type- type of object to create
Returns
created object

◆ xroad_node_cursor_get_first()

void* xroad_node_cursor_get_first ( xroad_cursor_t *  cursor)

return first object from cache

Parameters
[in]cursor- cache cursor
Returns
object from cache

◆ xroad_node_cursor_get_last()

void* xroad_node_cursor_get_last ( xroad_cursor_t *  cursor)

return last object from cache

Parameters
[in]cursor- cache cursor
Returns
object from cache

◆ xroad_node_cursor_get_next()

void* xroad_node_cursor_get_next ( xroad_cursor_t *  cursor)

return next object from cache

Parameters
[in]cursor- cache cursor
Returns
object from cache

◆ xroad_node_cursor_get_prev()

void* xroad_node_cursor_get_prev ( xroad_cursor_t *  cursor)

return previous object from cache

Parameters
[in]cursor- cache cursor
Returns
object from cache

◆ xroad_node_cursor_offset()

void* xroad_node_cursor_offset ( xroad_cursor_t *  cursor,
int64_t  offset 
)

offset cursor

Parameters
[in]cursor- cache cursor
[in]offset- offset value. Can be negative for offset back
Returns
object from cache, or NULL

◆ xroad_node_cursor_refresh()

void xroad_node_cursor_refresh ( xroad_cursor_t *  cursor)

extends cursor, if possible

Parameters
[in]cursor- cursor to extend

◆ xroad_node_del_epoll()

xroad_errno_t xroad_node_del_epoll ( xroad_node_epoll_callback_t *  cback)

remove descriptor from epoll

Parameters
[in]cback- callback to remove
Returns
XROAD_ERROR_OK - done

◆ xroad_node_destroy()

void xroad_node_destroy ( void  )

destroy node and free resources

◆ xroad_node_destroy_cursor()

void xroad_node_destroy_cursor ( xroad_cursor_t *  cursor)

destroy cursor

Parameters
[in]cursor- cursor to destroy

◆ xroad_node_disable_alarm()

void xroad_node_disable_alarm ( )

disable alarm sending

◆ xroad_node_enable_alarm()

void xroad_node_enable_alarm ( )

enable alarm senging

◆ xroad_node_get_cache()

xroad_cache_t* xroad_node_get_cache ( ) const

returns pointer to cache

Returns
pointer to cache

◆ xroad_node_get_config()

xroad_xml_doc_t* xroad_node_get_config ( void  )

return pointer to configuration

Returns
pointer to configuration

◆ xroad_node_get_data()

xroad_node_data_t* xroad_node_get_data ( void  ) const
Returns
node system slot

◆ xroad_node_get_env_param()

xroad_str_t xroad_node_get_env_param ( xroad_str_t  param)

get node environment parameter

Parameters
[in]param- paramenter name
Returns
environment paramenter value

◆ xroad_node_get_epoll_fd()

int32_t xroad_node_get_epoll_fd ( void  )

return epoll file descriptor

◆ xroad_node_get_epoll_timestamps()

const xroad_epoll_timestamps* xroad_node_get_epoll_timestamps ( void  ) const

Returns timestamps associated with epoll

Returns
pointer to timestamps

◆ xroad_node_get_fun()

void* xroad_node_get_fun ( xroad_str_t  fname)

get function from dll by name

Parameters
[in]fname- name of function
Returns
pointer function

◆ xroad_node_get_object()

void* xroad_node_get_object ( xroad_object_type_t  type,
xroad_object_id_t  id 
)

return object from cache

Parameters
[in]type- type of object
[in]id- id of object
Returns
pointer of object of any

◆ xroad_node_get_object_count()

size_t xroad_node_get_object_count ( xroad_object_type_t  type)

return count of objects of desired type

Parameters
[in]type- type of objects to count
Returns
count of objects

◆ xroad_node_get_used_lock()

xroad_lock_by_pid_t* xroad_node_get_used_lock ( void  )
Returns
lock used by node

◆ xroad_node_get_version()

const xroad_version_t* xroad_node_get_version ( void  ) const

return node version

Returns
node version

◆ xroad_node_get_working_dir()

xroad_str_t xroad_node_get_working_dir ( void  )

get node home dir

Returns
node home dir

◆ xroad_node_is_initialized()

bool xroad_node_is_initialized ( void  )

check if node already created

Returns
1 - node is initialized, 0 - not yet

◆ xroad_node_mod_epoll()

xroad_errno_t xroad_node_mod_epoll ( uint32_t  events,
xroad_node_epoll_callback_t *  cback 
)

modify events of already added to epoll descriptor

Parameters
[in]events- new fd events
[in]cback- pointer to epoll callback
Returns
XROAD_ERROR_OK - done

◆ xroad_node_receive()

int32_t xroad_node_receive ( void  )

receive and dispatch events

Returns
>= 0 number of dispatched messages, < 0 - error happened

◆ xroad_node_receive_ex()

int32_t xroad_node_receive_ex ( int32_t  timeout)

receive and dispatch events

Parameters
[in]timeout- wait millisec for received message
Returns
1 - message(s) dispatched, < 0 - error happened

◆ xroad_node_reconfig()

xroad_errno_t xroad_node_reconfig ( void  )

reconfigure node

Returns
XROAD_ERROR_OK - reconfiguration complete successfully

◆ xroad_node_renamed()

void xroad_node_renamed ( )

must be called when node is renamed

◆ xroad_node_reset_statistic()

void xroad_node_reset_statistic ( void  )

reset node statistic

◆ xroad_node_route_object()

xroad_errno_t xroad_node_route_object ( void *  obj,
  ... 
)

route object

Parameters
[in]obj- object to send
Returns
XROAD_ERROR_OK - object was sent

◆ xroad_node_route_object_va()

xroad_errno_t xroad_node_route_object_va ( void *  obj,
va_list  ap 
)

route object

Parameters
[in]obj- object to send
[in]ap- argument list
Returns
XROAD_ERROR_OK - object was sent

◆ xroad_node_send_object()

xroad_errno_t xroad_node_send_object ( void *  obj,
xroad_node_id_t  id 
)

send object directly to node

Parameters
[in]obj- object to send
[in]id- id of destination node
Returns
XROAD_ERROR_OK - object was sent

◆ xroad_node_set_flags()

void xroad_node_set_flags ( uint32_t  flags)

set node flags

Parameters
[in]flags- new node flags

◆ xroad_node_subscribe()

xroad_errno_t xroad_node_subscribe ( xroad_domain_t  group,
xroad_node_callback_t  cback 
)

subscribe to objects of concrete group

Parameters
[in]domain- object domain to subscribe
[in]cback- callback
Returns
XROAD_OK, else failed

◆ xroad_node_trace_close_ex()

xroad_errno_t xroad_node_trace_close_ex ( xroad_trace_stream_t *  writer)

Close a trace control by stream writer.

Unclosed trace streams are safely destroyed at node destruction. However they may still consume some CPU cycles for polling.

Parameters
writer- writer structure to close.
Returns
XROAD_OK on success or error code otherwise (error description is logged)

◆ xroad_node_trace_init_writer_ex()

xroad_errno_t xroad_node_trace_init_writer_ex ( bool  enabled,
const xroad_traces_ctl_param_t *  params,
xroad_trace_stream_t *  writer 
)

Init trace writer shortcut without returning a control

The writer is initialized with a stub if tracing is disabled or any error happened

Parameters
[in]name- trace name (and file prefix). Empty means default node trace
[in]enabled- if tracing is not enabed, writer is initialized with a stub
[in]corr_tag- correlation tag
[in]type_mask- trace type mask. It must be a combination of xroad_trace_rec_flag_t
[out]writer- writer structure to initialize.
Returns
- XROAD_OK on success or error code otherwise (error description is logged)

◆ xroad_node_unsubscribe()

xroad_errno_t xroad_node_unsubscribe ( xroad_domain_t  group,
xroad_node_callback_t  cback 
)

unsubscribe from group objects

Parameters
[in]domain- object domain to usubscribe
[in]cback- callback
Returns
XROAD_OK, else failed