HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
Session Management

This module contains the classes that implement the Session Management functionality. More...

+ Collaboration diagram for Session Management:

Data Structures

struct  HF::Core::SessionManagement::StartResponse
 Start Read Session Command Message. More...
 
struct  HF::Core::SessionManagement::GetEntriesMessage
 Get Entries Command Message. More...
 
struct  HF::Core::SessionManagement::IServer
 Session Management API : Server side. More...
 
struct  HF::Core::SessionManagement::AbstractServer::Session
 Session database entry. More...
 
class  HF::Core::SessionManagement::AbstractServer
 Parent class for session management functionality - Server side. More...
 
class  HF::Core::SessionManagement::EntriesWrapper< Parent >
 Wrapper over persistent storage APIs to invalidate sessions on save and destroy. More...
 
struct  HF::Core::SessionManagement::Server< _Entries >
 Helper template to inject session management functionality into services requiring it - Server side. More...
 
class  HF::Core::SessionManagement::AbstractClient
 Parent class for session management functionality - Client side. More...
 
struct  HF::Core::SessionManagement::Client< _Entry >
 Helper template to inject session management functionality into services requiring it - Client side. More...
 

Enumerations

enum  HF::Core::SessionManagement::CMD { HF::Core::SessionManagement::START, HF::Core::SessionManagement::GET, HF::Core::SessionManagement::END }
 Available commands for session management. More...
 

Functions

 HF::Core::SessionManagement::StartResponse::StartResponse (uint16_t count=0)
 Constructor. More...
 
uint16_t HF::Core::SessionManagement::GetEntriesMessage::size () const
 Number bytes needed to serialize the message. More...
 
uint16_t HF::Core::SessionManagement::GetEntriesMessage::pack (Common::ByteArray &array, uint16_t offset=0) const
 Write the object on to a ByteArray so it can be sent over the network. More...
 
uint16_t HF::Core::SessionManagement::GetEntriesMessage::unpack (const Common::ByteArray &array, uint16_t offset=0)
 Read a message from a ByteArray. More...
 
virtual void HF::Core::SessionManagement::IServer::start_session (uint16_t address)=0
 Start a session for the device with the given address. More...
 
virtual void HF::Core::SessionManagement::IServer::end_session (uint16_t address)=0
 Terminate the session associated with the device with the given address. More...
 
virtual bool HF::Core::SessionManagement::IServer::exists (uint16_t address) const =0
 Check if a session for the device with the given address exists. More...
 
virtual bool HF::Core::SessionManagement::IServer::is_valid (uint16_t address) const =0
 Check if the session for the device with the given address is valid, i.e., the underling entries have not been modified since the start of the session. More...
 
 HF::Core::SessionManagement::AbstractServer::Session::Session (uint16_t _address=HF::Protocol::BROADCAST_ADDR, bool _valid=false)
 Constructor. More...
 
 HF::Core::SessionManagement::AbstractServer::AbstractServer ()
 Constructor.
 
void HF::Core::SessionManagement::AbstractServer::start_session (uint16_t address)
 Start a session for the device with the given address. More...
 
void HF::Core::SessionManagement::AbstractServer::end_session (uint16_t address)
 Terminate the session associated with the device with the given address. More...
 
bool HF::Core::SessionManagement::AbstractServer::exists (uint16_t address) const
 Check if a session for the device with the given address exists. More...
 
bool HF::Core::SessionManagement::AbstractServer::is_valid (uint16_t address) const
 Check if the session for the device with the given address is valid, i.e., the underling entries have not been modified since the start of the session. More...
 
void HF::Core::SessionManagement::AbstractServer::invalidate ()
 Invalidate all sessions.
 
Common::Result HF::Core::SessionManagement::AbstractServer::handle_command (CMD cmd, Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset=0)
 Handle command request/response messages. More...
 
iterator HF::Core::SessionManagement::AbstractServer::find (uint16_t address)
 Find the session associated with the given device address. More...
 
const_iterator HF::Core::SessionManagement::AbstractServer::find (uint16_t address) const
 Find the session associated with the given device address. More...
 
uint16_t HF::Core::SessionManagement::AbstractServer::payload_size (CMD cmd) const
 Get the minimum number of bytes necessary to pack/unpack a message of the given command. More...
 
Common::Result HF::Core::SessionManagement::AbstractServer::check_offset (uint16_t offset, uint8_t &count, uint16_t size) const
 Check if the given offset is valid and adjust the count value if necessary. More...
 
virtual void HF::Core::SessionManagement::AbstractServer::send (const Protocol::Address &addr, Protocol::Message &message)=0
 Send message msg to the network address given by addr. More...
 
virtual uint16_t HF::Core::SessionManagement::AbstractServer::entries_size () const =0
 Get the number of entries present in the container. More...
 
virtual Common::Result HF::Core::SessionManagement::AbstractServer::entries (uint16_t offset, uint8_t count, Common::ByteArray &payload)=0
 Create a GetEntriesResponse message message with, count entries starting from the given offset and serialize the created message into the given byte array in payload. More...
 
Common::Result HF::Core::SessionManagement::AbstractServer::check_session (uint16_t address, Common::ByteArray &payload) const
 Check if a session for the given device address exists and if it is valid. More...
 
 HF::Core::SessionManagement::EntriesWrapper< Parent >::EntriesWrapper (AbstractServer &_manager)
 Constructor. More...
 
 HF::Core::SessionManagement::EntriesWrapper< Parent >::EntriesWrapper (const EntriesWrapper &other, AbstractServer &_manager)
 Constructor. More...
 
Common::Result HF::Core::SessionManagement::EntriesWrapper< Parent >::save (const value_type &entry)
 Store the given entry to persistent storage. More...
 
Common::Result HF::Core::SessionManagement::EntriesWrapper< Parent >::destroy (const value_type &entry)
 Destroy the given entry in the persistent storage. More...
 
Container & HF::Core::SessionManagement::Server< _Entries >::entries () const
 Return the container for the service entries. More...
 
 HF::Core::SessionManagement::Server< _Entries >::Server (const Server &other)
 Copy-Constructor. More...
 
uint16_t HF::Core::SessionManagement::Server< _Entries >::entries_size () const
 Get the number of entries present in the container. More...
 
Common::Result HF::Core::SessionManagement::Server< _Entries >::entries (uint16_t offset, uint8_t count, Common::ByteArray &payload)
 Create a GetEntriesResponse message message with, count entries starting from the given offset and serialize the created message into the given byte array in payload. More...
 
Common::Result HF::Core::SessionManagement::AbstractClient::handle_command (CMD cmd, Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset=0)
 Handle command request/response messages. More...
 
uint16_t HF::Core::SessionManagement::AbstractClient::payload_size (CMD cmd) const
 Get the minimum number of bytes necessary to pack/unpack a message of the given command. More...
 
template<uint8_t _role, uint16_t _uid, uint8_t _member>
void HF::Core::SessionManagement::AbstractClient::get_entries (uint16_t offset, uint8_t count=0) const
 Helper method to send a message to read, count entries starting at offset from the server. More...
 
template<uint8_t _role, uint16_t _uid, uint8_t _member>
void HF::Core::SessionManagement::AbstractClient::request () const
 Helper method to create a session management request. More...
 
virtual void HF::Core::SessionManagement::AbstractClient::send (const Protocol::Address &addr, Protocol::Message &message)=0
 Send message msg to the network address given by addr. More...
 

Variables

uint16_t HF::Core::SessionManagement::StartResponse::count
 Number of device entries. More...
 
static constexpr uint16_t HF::Core::SessionManagement::StartResponse::min_size = Protocol::Response::min_size + sizeof(uint16_t)
 Minimum pack/unpack required data size.
 
uint16_t HF::Core::SessionManagement::GetEntriesMessage::offset
 Start index for the first entry to be provided. More...
 
uint8_t HF::Core::SessionManagement::GetEntriesMessage::count
 Number of entries to be sent in the response. More...
 
static constexpr uint16_t HF::Core::SessionManagement::GetEntriesMessage::min_size = sizeof(offset) + sizeof(count)
 Minimum pack/unpack required data size.
 
static constexpr uint16_t HF::Core::SessionManagement::GetEntriesResponse< _Entry >::min_size
 Minimum pack/unpack required data size.
 
static constexpr uint16_t HF::Core::SessionManagement::GetEntriesResponse< void >::min_size
 Minimum pack/unpack required data size.
 
uint16_t HF::Core::SessionManagement::AbstractServer::Session::address
 Device address for session. More...
 
bool HF::Core::SessionManagement::AbstractServer::Session::valid
 Indicate if the session is still valid. More...
 
Container HF::Core::SessionManagement::AbstractServer::sessions
 Session's database.
 

Events

virtual void HF::Core::SessionManagement::Client< _Entry >::entries (const GetEntriesResponse< _Entry > &response)
 This event is called when a response to a get entries is received. More...
 

Detailed Description

This module contains the classes that implement the Session Management functionality.

Enumeration Type Documentation

◆ CMD

Available commands for session management.

Enumerator
START 

Start a new session for a device.

GET 

Retrieve information.

END 

End the session for device.

Definition at line 42 of file session_management.h.

43  {
44  START,
45  GET,
46  END,
47  } CMD;
End the session for device.
CMD
Available commands for session management.
Start a new session for a device.

Function Documentation

◆ EntriesWrapper() [1/2]

template<typename Parent>
HF::Core::SessionManagement::EntriesWrapper< Parent >::EntriesWrapper ( AbstractServer _manager)
inline

Constructor.

Parameters
[in]_managersession manager the entries are associated to.

Definition at line 557 of file session_management.h.

557  : Parent(),
558  manager(_manager)
559  {}

◆ EntriesWrapper() [2/2]

template<typename Parent>
HF::Core::SessionManagement::EntriesWrapper< Parent >::EntriesWrapper ( const EntriesWrapper< Parent > &  other,
AbstractServer _manager 
)
inline

Constructor.

Parameters
[in]otherentries container to wrap.
[in]_managersession manager the entries are associated to.

Definition at line 567 of file session_management.h.

567  :
568  Parent(other), manager(_manager)
569  {}

◆ Server()

template<typename _Entries>
HF::Core::SessionManagement::Server< _Entries >::Server ( const Server< _Entries > &  other)
inlineprotected

Copy-Constructor.

Make sure that the entries are copied maintaining this object as the session manager.

Parameters
[in]otherreference to the object to copy from.

Definition at line 627 of file session_management.h.

627  :
628  AbstractServer(other), _entries(other._entries, *this)
629  {}

◆ Session()

HF::Core::SessionManagement::AbstractServer::Session::Session ( uint16_t  _address = HF::Protocol::BROADCAST_ADDR,
bool  _valid = false 
)
inline

Constructor.

Parameters
[in]_addressdevice address this session belongs to.
[in]_validtrue if the session is valid, false otherwise.

Definition at line 330 of file session_management.h.

330  :
331  address(_address), valid(_valid)
332  {}
bool valid
Indicate if the session is still valid.

◆ StartResponse()

HF::Core::SessionManagement::StartResponse::StartResponse ( uint16_t  count = 0)
inline

Constructor.

Parameters
[in]countnumber of entries available.

Definition at line 65 of file session_management.h.

65  :
66  count(count)
67  {}
uint16_t count
Number of device entries.

◆ check_offset()

Common::Result HF::Core::SessionManagement::AbstractServer::check_offset ( uint16_t  offset,
uint8_t &  count,
uint16_t  size 
) const
protected

Check if the given offset is valid and adjust the count value if necessary.

Parameters
[in]offsetoffset to start reading the entries from.
[in,out]countnumber of entries to read.
[in]sizenumber of entries present in the underling container.
Return values
HF::Common::Result::OKif entries can be read.
HF::Common::Result::FAIL_ARGif the offset value is invalid.

Referenced by HF::Core::SessionManagement::Server< Entries >::entries().

+ Here is the caller graph for this function:

◆ check_session()

Common::Result HF::Core::SessionManagement::AbstractServer::check_session ( uint16_t  address,
Common::ByteArray payload 
) const
protected

Check if a session for the given device address exists and if it is valid.

In case a session does not exist or is invalid, place an GetEntriesEmptyResponse into the byte array given by payload to be sent to the remote device.

Parameters
[in]addressdevice address to check the session for.
[out]payloadthe byte array to place the response in case of error.
Return values
Common::Result::FAIL_READ_SESSIONif the session does not exist;
Common::Result::FAIL_FAIL_MODIFIEDif the session is not valid;
Common::Result::OKa session exists an is valid.

◆ destroy()

template<typename Parent>
Common::Result HF::Core::SessionManagement::EntriesWrapper< Parent >::destroy ( const value_type &  entry)
inline

Destroy the given entry in the persistent storage.

Parameters
[in]entryreference to the entry to erase.
Return values
Common::Result::OK,ifthe entry was destroyed.
Common::Result::FAIL_ARGotherwise.

Definition at line 584 of file session_management.h.

585  {
586  auto res = Parent::destroy(entry);
587 
588  manager.invalidate();
589  return res;
590  }
Protocol::Message * destroy(Type type, uint8_t report_id)
Remove the rule with the given type and the given report_id.
void invalidate()
Invalidate all sessions.

◆ end_session() [1/2]

virtual void HF::Core::SessionManagement::IServer::end_session ( uint16_t  address)
pure virtual

Terminate the session associated with the device with the given address.

Parameters
[in]addressdevice address to end the session for.

Implemented in HF::Core::SessionManagement::AbstractServer.

◆ end_session() [2/2]

void HF::Core::SessionManagement::AbstractServer::end_session ( uint16_t  address)
inlinevirtual

Terminate the session associated with the device with the given address.

Parameters
[in]addressdevice address to end the session for.

Implements HF::Core::SessionManagement::IServer.

Definition at line 369 of file session_management.h.

References HF::Core::SessionManagement::AbstractServer::find(), and HF::Core::SessionManagement::AbstractServer::sessions.

370  {
371  auto it = find(address);
372 
373  if (it != sessions.end())
374  {
375  sessions.erase(it);
376  }
377  }
Container sessions
Session&#39;s database.
iterator find(uint16_t address)
Find the session associated with the given device address.
+ Here is the call graph for this function:

◆ entries() [1/4]

virtual Common::Result HF::Core::SessionManagement::AbstractServer::entries ( uint16_t  offset,
uint8_t  count,
Common::ByteArray payload 
)
protectedpure virtual

Create a GetEntriesResponse message message with, count entries starting from the given offset and serialize the created message into the given byte array in payload.

Remarks
if offset + count > [number of entries], the message will truncated to the available entries starting from the given offset.
Parameters
[in]offsetthe offset to start reading the entries.
[in]countnumber of entries to read.
[out]payloadbyte array to serialize the entries to.
Return values
Common::Result::OKmessage created successfully;
Common::Result::FAIL_ARGif offset is bigger than the number of entries.

Implemented in HF::Core::SessionManagement::Server< _Entries >, and HF::Core::SessionManagement::Server< Entries >.

◆ entries() [2/4]

template<typename _Entries>
Container& HF::Core::SessionManagement::Server< _Entries >::entries ( ) const
inline

Return the container for the service entries.

Returns
reference to the object containing the wrapped service entries.

Definition at line 607 of file session_management.h.

Referenced by HF::Core::BindManagement::Server< Entries >::entries(), and HF::Core::DeviceManagement::Server< Entries >::entries().

608  {
609  return const_cast<Container &>(_entries);
610  }
+ Here is the caller graph for this function:

◆ entries() [3/4]

template<typename _Entries>
Common::Result HF::Core::SessionManagement::Server< _Entries >::entries ( uint16_t  offset,
uint8_t  count,
Common::ByteArray payload 
)
inlineprotectedvirtual

Create a GetEntriesResponse message message with, count entries starting from the given offset and serialize the created message into the given byte array in payload.

Remarks
if offset + count > [number of entries], the message will truncated to the available entries starting from the given offset.
Parameters
[in]offsetthe offset to start reading the entries.
[in]countnumber of entries to read.
[out]payloadbyte array to serialize the entries to.
Return values
Common::Result::OKmessage created successfully;
Common::Result::FAIL_ARGif offset is bigger than the number of entries.

Implements HF::Core::SessionManagement::AbstractServer.

Definition at line 642 of file session_management.h.

643  {
644  GetEntriesResponse<value_type> response;
645 
646  response.code = check_offset(offset, count, entries_size());
647 
648  if (response.code == Common::Result::OK)
649  {
650  auto start = _entries.begin();
651  std::advance(start, offset);
652 
653  auto end = start;
654  std::advance(end, count);
655  std::copy(start, end, std::back_inserter(response.entries));
656  }
657 
658  payload = Common::ByteArray(response.size());
659 
660  response.pack(payload);
661 
662  return response.code;
663  }
bool response(Message::Type type)
Check if message is a response.
Common::Result check_offset(uint16_t offset, uint8_t &count, uint16_t size) const
Check if the given offset is valid and adjust the count value if necessary.
uint16_t entries_size() const
Get the number of entries present in the container.

◆ entries() [4/4]

template<typename _Entry>
virtual void HF::Core::SessionManagement::Client< _Entry >::entries ( const GetEntriesResponse< _Entry > &  response)
inlinevirtual

This event is called when a response to a get entries is received.

Parameters
[in]responsethe response received.

Definition at line 837 of file session_management.h.

838  {
839  UNUSED(response);
840  }
bool response(Message::Type type)
Check if message is a response.
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.

◆ entries_size() [1/2]

virtual uint16_t HF::Core::SessionManagement::AbstractServer::entries_size ( ) const
protectedpure virtual

Get the number of entries present in the container.

Returns
number of entries in the wrapped service.

Implemented in HF::Core::SessionManagement::Server< _Entries >, and HF::Core::SessionManagement::Server< Entries >.

◆ entries_size() [2/2]

template<typename _Entries>
uint16_t HF::Core::SessionManagement::Server< _Entries >::entries_size ( ) const
inlineprotectedvirtual

Get the number of entries present in the container.

Returns
number of entries in the wrapped service.

Implements HF::Core::SessionManagement::AbstractServer.

Definition at line 635 of file session_management.h.

Referenced by HF::Core::SessionManagement::Server< Entries >::entries().

636  {
637  return static_cast<uint16_t>(_entries.size());
638  }
+ Here is the caller graph for this function:

◆ exists() [1/2]

virtual bool HF::Core::SessionManagement::IServer::exists ( uint16_t  address) const
pure virtual

Check if a session for the device with the given address exists.

Parameters
[in]addressdevice address to check is a session exists.
Return values
trueif a session exists,
falseotherwise.

Implemented in HF::Core::SessionManagement::AbstractServer.

◆ exists() [2/2]

bool HF::Core::SessionManagement::AbstractServer::exists ( uint16_t  address) const
inlinevirtual

Check if a session for the device with the given address exists.

Parameters
[in]addressdevice address to check is a session exists.
Return values
trueif a session exists,
falseotherwise.

Implements HF::Core::SessionManagement::IServer.

Definition at line 379 of file session_management.h.

References HF::Core::SessionManagement::AbstractServer::find(), and HF::Core::SessionManagement::AbstractServer::sessions.

380  {
381  return find(address) != sessions.end();
382  }
Container sessions
Session&#39;s database.
iterator find(uint16_t address)
Find the session associated with the given device address.
+ Here is the call graph for this function:

◆ find() [1/2]

iterator HF::Core::SessionManagement::AbstractServer::find ( uint16_t  address)
inlineprotected

Find the session associated with the given device address.

Parameters
[in]addressdevice address to search a session for.
Returns
an iterator to the session found or Container::end() otherwise.

Definition at line 438 of file session_management.h.

References HF::Core::SessionManagement::AbstractServer::sessions.

Referenced by HF::Core::SessionManagement::AbstractServer::end_session(), HF::Core::SessionManagement::AbstractServer::exists(), HF::Core::SessionManagement::AbstractServer::is_valid(), and HF::Core::SessionManagement::AbstractServer::start_session().

439  {
440  /* *INDENT-OFF* */
441  return std::find_if (sessions.begin (), sessions.end (),
442  [address](const Session &session)
443  {
444  return address == session.address;
445  });
446  /* *INDENT-ON* */
447  }
Container sessions
Session&#39;s database.
+ Here is the caller graph for this function:

◆ find() [2/2]

const_iterator HF::Core::SessionManagement::AbstractServer::find ( uint16_t  address) const
inlineprotected

Find the session associated with the given device address.

Parameters
[in]addressdevice address to search a session for.
Returns
a constant iterator to the session found or Container::end() otherwise.

Definition at line 456 of file session_management.h.

References HF::Core::SessionManagement::AbstractServer::sessions.

457  {
458  /* *INDENT-OFF* */
459  return std::find_if (sessions.cbegin (), sessions.cend (),
460  [address](const Session &session)
461  {
462  return address == session.address;
463  });
464  /* *INDENT-ON* */
465  }
Container sessions
Session&#39;s database.

◆ get_entries()

template<uint8_t _role, uint16_t _uid, uint8_t _member>
void HF::Core::SessionManagement::AbstractClient::get_entries ( uint16_t  offset,
uint8_t  count = 0 
) const
inlineprotected

Helper method to send a message to read, count entries starting at offset from the server.

Parameters
[in]offsetindex to start reading the entries from.
[in]countnumber of entries to read.

Definition at line 776 of file session_management.h.

References HF::Common::Interface::id, HF::Protocol::Message::itf, HF::Protocol::Message::Interface::member, HF::Core::SessionManagement::GetEntriesMessage::pack(), HF::Protocol::Message::payload, HF::Common::Interface::role, HF::Core::SessionManagement::AbstractClient::send(), and HF::Core::SessionManagement::GetEntriesMessage::size().

777  {
778  SessionManagement::GetEntriesMessage msg(offset, count);
779 
780  Protocol::Address addr(0, 0);
781  Protocol::Message message;
782 
783  message.itf.role = _role;
784  message.itf.id = _uid;
785  message.itf.member = _member;
786 
787  message.payload = Common::ByteArray(msg.size());
788 
789  msg.pack(message.payload);
790 
791  const_cast<AbstractClient *>(this)->send(addr, message);
792  }
virtual void send(const Protocol::Address &addr, Protocol::Message &message)=0
Send message msg to the network address given by addr.
+ Here is the call graph for this function:

◆ handle_command() [1/2]

Common::Result HF::Core::SessionManagement::AbstractServer::handle_command ( CMD  cmd,
Protocol::Packet packet,
Common::ByteArray payload,
uint16_t  offset = 0 
)
protected

Handle command request/response messages.

  • Protocol::Message:Type::COMMAND_REQ;
  • Protocol::Message:Type::COMMAND_RESP_REQ;
  • Protocol::Message:Type::COMMAND_RES;
Parameters
[in]cmdthe session operation to process.
[in]packetthe packet receive from the network.
[in]payloadthe byte array containing the data received from the network.
[in]offsetthe offset the payload start at in the byte array.
Returns
the result of the message processing.

◆ handle_command() [2/2]

Common::Result HF::Core::SessionManagement::AbstractClient::handle_command ( CMD  cmd,
Protocol::Packet packet,
Common::ByteArray payload,
uint16_t  offset = 0 
)
protected

Handle command request/response messages.

  • Protocol::Message:Type::COMMAND_REQ;
  • Protocol::Message:Type::COMMAND_RESP_REQ;
  • Protocol::Message:Type::COMMAND_RES;
Parameters
[in]cmdthe session operation to process.
[in]packetthe packet receive from the network.
[in]payloadthe byte array containing the data received from the network.
[in]offsetthe offset the payload start at in the byte array.
Returns
the result of the message processing.

◆ is_valid() [1/2]

virtual bool HF::Core::SessionManagement::IServer::is_valid ( uint16_t  address) const
pure virtual

Check if the session for the device with the given address is valid, i.e., the underling entries have not been modified since the start of the session.

Parameters
[in]addressdevice address to check is the session is valid.
Return values
trueif the session exists and is valid,
falseotherwise.

Implemented in HF::Core::SessionManagement::AbstractServer.

◆ is_valid() [2/2]

bool HF::Core::SessionManagement::AbstractServer::is_valid ( uint16_t  address) const
inlinevirtual

Check if the session for the device with the given address is valid, i.e., the underling entries have not been modified since the start of the session.

Parameters
[in]addressdevice address to check is the session is valid.
Return values
trueif the session exists and is valid,
falseotherwise.

Implements HF::Core::SessionManagement::IServer.

Definition at line 384 of file session_management.h.

References HF::Core::SessionManagement::AbstractServer::find(), and HF::Core::SessionManagement::AbstractServer::sessions.

385  {
386  auto it = find(address);
387 
388  if (it != sessions.end())
389  {
390  return it->valid;
391  }
392 
393  return false;
394  }
Container sessions
Session&#39;s database.
iterator find(uint16_t address)
Find the session associated with the given device address.
+ Here is the call graph for this function:

◆ pack()

uint16_t HF::Core::SessionManagement::GetEntriesMessage::pack ( Common::ByteArray array,
uint16_t  offset = 0 
) const
inline

Write the object on to a ByteArray so it can be sent over the network.

The buffer passed in MUST have enough size to hold the serialized object, e.g.,

Serializable obj;
ByteArray payload(obj.size());
obj.pack(payload);
Parameters
[in,out]arrayByteArray reference to write the object to.
[in]offsetoffset to start writing to.
Returns
the number of bytes written.

Definition at line 121 of file session_management.h.

References HF_SERIALIZABLE_CHECK, HF::Core::SessionManagement::GetEntriesMessage::min_size, HF::Core::SessionManagement::GetEntriesMessage::offset, and HF::Common::ByteArray::write().

Referenced by HF::Core::SessionManagement::AbstractClient::get_entries().

122  {
124 
125  offset += array.write(offset, this->offset);
126  array.write(offset, this->count);
127 
128  return min_size;
129  }
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
uint16_t offset
Start index for the first entry to be provided.
#define HF_SERIALIZABLE_CHECK(__array, __offset, __size)
Helper macro to check if the given __array has enough size so __size bytes can be written/read from t...
uint8_t count
Number of entries to be sent in the response.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ payload_size() [1/2]

uint16_t HF::Core::SessionManagement::AbstractServer::payload_size ( CMD  cmd) const
protected

Get the minimum number of bytes necessary to pack/unpack a message of the given command.

Parameters
[in]cmdthe command to get the number of bytes for.
Returns
number of bytes required.

◆ payload_size() [2/2]

uint16_t HF::Core::SessionManagement::AbstractClient::payload_size ( CMD  cmd) const
protected

Get the minimum number of bytes necessary to pack/unpack a message of the given command.

Parameters
[in]cmdthe command to get the number of bytes for.
Returns
number of bytes required.

◆ request()

template<uint8_t _role, uint16_t _uid, uint8_t _member>
void HF::Core::SessionManagement::AbstractClient::request ( ) const
inlineprotected

Helper method to create a session management request.

Template Parameters
_rolerole to use in the created message.
_uidinterface UID to use in the message.
_memberinterface member ID to use.

Definition at line 803 of file session_management.h.

References HF::Common::Interface::id, HF::Protocol::Message::itf, HF::Protocol::Message::Interface::member, HF::Common::Interface::role, and HF::Core::SessionManagement::AbstractClient::send().

Referenced by HF::Core::BindManagement::Client::end_session(), HF::Core::DeviceManagement::Client::end_session(), HF::Core::BindManagement::Client::start_session(), and HF::Core::DeviceManagement::Client::start_session().

804  {
805  Protocol::Address addr(0, 0);
806  Protocol::Message message;
807 
808  message.itf.role = _role;
809  message.itf.id = _uid;
810  message.itf.member = _member;
811 
812  const_cast<AbstractClient *>(this)->send(addr, message);
813  }
virtual void send(const Protocol::Address &addr, Protocol::Message &message)=0
Send message msg to the network address given by addr.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

template<typename Parent>
Common::Result HF::Core::SessionManagement::EntriesWrapper< Parent >::save ( const value_type &  entry)
inline

Store the given entry to persistent storage.

Parameters
[in]entrythe entry to save to storage.
Return values
Common::Result::OKif the entry was saved,
Common::Result::FAIL_UNKNOWNotherwise.

Definition at line 575 of file session_management.h.

576  {
577  auto res = Parent::save(entry);
578 
579  manager.invalidate();
580  return res;
581  }
void invalidate()
Invalidate all sessions.

◆ send() [1/2]

virtual void HF::Core::SessionManagement::AbstractServer::send ( const Protocol::Address addr,
Protocol::Message message 
)
protectedpure virtual

Send message msg to the network address given by addr.

Parameters
[in]addrHF network address.
[in]messagepointer to the message to be sent to the network.

Implemented in HF::Core::DeviceManagement::Server< _Entries >, HF::Core::DeviceManagement::Server< Entries >, HF::Core::BindManagement::Server< _Entries >, and HF::Core::BindManagement::Server< Entries >.

◆ send() [2/2]

virtual void HF::Core::SessionManagement::AbstractClient::send ( const Protocol::Address addr,
Protocol::Message message 
)
protectedpure virtual

Send message msg to the network address given by addr.

Parameters
[in]addrHF network address.
[in]messagepointer to the message to be sent to the network.

Implemented in HF::Core::DeviceManagement::Client, and HF::Core::BindManagement::Client.

Referenced by HF::Core::SessionManagement::AbstractClient::get_entries(), and HF::Core::SessionManagement::AbstractClient::request().

+ Here is the caller graph for this function:

◆ size()

uint16_t HF::Core::SessionManagement::GetEntriesMessage::size ( ) const
inline

Number bytes needed to serialize the message.

Returns
number of bytes the message requires to be serialized.

Definition at line 115 of file session_management.h.

References HF::Core::SessionManagement::GetEntriesMessage::min_size.

Referenced by HF::Core::SessionManagement::AbstractClient::get_entries().

116  {
117  return min_size;
118  }
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
+ Here is the caller graph for this function:

◆ start_session() [1/2]

virtual void HF::Core::SessionManagement::IServer::start_session ( uint16_t  address)
pure virtual

Start a session for the device with the given address.

Only one session is associated with any given device at any time.

Parameters
[in]addressdevice address to start the session for.

Implemented in HF::Core::SessionManagement::AbstractServer.

◆ start_session() [2/2]

void HF::Core::SessionManagement::AbstractServer::start_session ( uint16_t  address)
inlinevirtual

Start a session for the device with the given address.

Only one session is associated with any given device at any time.

Parameters
[in]addressdevice address to start the session for.

Implements HF::Core::SessionManagement::IServer.

Definition at line 355 of file session_management.h.

References HF::Core::SessionManagement::AbstractServer::find(), and HF::Core::SessionManagement::AbstractServer::sessions.

356  {
357  auto it = find(address);
358 
359  if (it == sessions.end()) // Session does not exist.
360  {
361  sessions.push_back(Session(address, true));
362  }
363  else // Session already exists. Update state.
364  {
365  it->valid = true;
366  }
367  }
Container sessions
Session&#39;s database.
iterator find(uint16_t address)
Find the session associated with the given device address.
+ Here is the call graph for this function:

◆ unpack()

uint16_t HF::Core::SessionManagement::GetEntriesMessage::unpack ( const Common::ByteArray array,
uint16_t  offset = 0 
)
inline

Read a message from a ByteArray.

Parameters
[in]arrayByteArray reference to read the message from.
[in]offsetoffset to start reading from.
Returns
the number of bytes read.

Definition at line 132 of file session_management.h.

References HF_SERIALIZABLE_CHECK, HF::Core::SessionManagement::GetEntriesMessage::min_size, HF::Core::SessionManagement::GetEntriesMessage::offset, and HF::Common::ByteArray::read().

133  {
135 
136  offset += array.read(offset, this->offset);
137  array.read(offset, this->count);
138 
139  return min_size;
140  }
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
uint16_t offset
Start index for the first entry to be provided.
#define HF_SERIALIZABLE_CHECK(__array, __offset, __size)
Helper macro to check if the given __array has enough size so __size bytes can be written/read from t...
uint8_t count
Number of entries to be sent in the response.
+ Here is the call graph for this function:

Variable Documentation

◆ address

uint16_t HF::Core::SessionManagement::AbstractServer::Session::address

Device address for session.

Definition at line 321 of file session_management.h.

◆ count [1/2]

uint16_t HF::Core::SessionManagement::StartResponse::count

Number of device entries.

Definition at line 58 of file session_management.h.

◆ count [2/2]

uint8_t HF::Core::SessionManagement::GetEntriesMessage::count

Number of entries to be sent in the response.

Definition at line 104 of file session_management.h.

◆ offset

uint16_t HF::Core::SessionManagement::GetEntriesMessage::offset

Start index for the first entry to be provided.

Definition at line 103 of file session_management.h.

Referenced by HF::Core::SessionManagement::GetEntriesMessage::pack(), and HF::Core::SessionManagement::GetEntriesMessage::unpack().

◆ valid

bool HF::Core::SessionManagement::AbstractServer::Session::valid

Indicate if the session is still valid.

Definition at line 322 of file session_management.h.