Skip to content

Commit cdd5db5

Browse files
drop RPC
1 parent b6fbd4c commit cdd5db5

File tree

4 files changed

+0
-845
lines changed

4 files changed

+0
-845
lines changed

libudpard/udpard.c

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,22 +1639,6 @@ static void rxPortFree(struct UdpardRxPort* const self, const struct UdpardRxMem
16391639
self->sessions = NULL;
16401640
}
16411641

1642-
static int_fast8_t rxRPCSearch(void* const user_reference, // NOSONAR Cavl API requires non-const.
1643-
const struct UdpardTreeNode* node)
1644-
{
1645-
UDPARD_ASSERT((user_reference != NULL) && (node != NULL));
1646-
return compare32(((const struct UdpardRxRPCPort*) user_reference)->service_id,
1647-
((const struct UdpardRxRPCPort*) (const void*) node)->service_id);
1648-
}
1649-
1650-
static int_fast8_t rxRPCSearchByServiceID(void* const user_reference, // NOSONAR Cavl API requires non-const.
1651-
const struct UdpardTreeNode* node)
1652-
{
1653-
UDPARD_ASSERT((user_reference != NULL) && (node != NULL));
1654-
return compare32(*(const UdpardPortID*) user_reference,
1655-
((const struct UdpardRxRPCPort*) (const void*) node)->service_id);
1656-
}
1657-
16581642
// -------------------------------------------------- RX API --------------------------------------------------
16591643

16601644
void udpardRxFragmentFree(const struct UdpardFragment head,
@@ -1720,143 +1704,6 @@ int_fast8_t udpardRxSubscriptionReceive(struct UdpardRxSubscription* const self,
17201704
return result;
17211705
}
17221706

1723-
int_fast8_t udpardRxRPCDispatcherInit(struct UdpardRxRPCDispatcher* const self,
1724-
const struct UdpardRxMemoryResources memory)
1725-
{
1726-
int_fast8_t result = -UDPARD_ERROR_ARGUMENT;
1727-
if ((self != NULL) && rxValidateMemoryResources(memory))
1728-
{
1729-
memZero(sizeof(*self), self);
1730-
self->local_node_id = UDPARD_NODE_ID_UNSET;
1731-
self->memory = memory;
1732-
self->request_ports = NULL;
1733-
self->response_ports = NULL;
1734-
result = 0;
1735-
}
1736-
return result;
1737-
}
1738-
1739-
int_fast8_t udpardRxRPCDispatcherStart(struct UdpardRxRPCDispatcher* const self,
1740-
const UdpardNodeID local_node_id,
1741-
struct UdpardUDPIPEndpoint* const out_udp_ip_endpoint)
1742-
{
1743-
int_fast8_t result = -UDPARD_ERROR_ARGUMENT;
1744-
if ((self != NULL) && (out_udp_ip_endpoint != NULL) && (local_node_id <= UDPARD_NODE_ID_MAX) &&
1745-
(self->local_node_id > UDPARD_NODE_ID_MAX))
1746-
{
1747-
self->local_node_id = local_node_id;
1748-
*out_udp_ip_endpoint = makeServiceUDPIPEndpoint(local_node_id);
1749-
result = 0;
1750-
}
1751-
return result;
1752-
}
1753-
1754-
int_fast8_t udpardRxRPCDispatcherListen(struct UdpardRxRPCDispatcher* const self,
1755-
struct UdpardRxRPCPort* const port,
1756-
const UdpardPortID service_id,
1757-
const bool is_request,
1758-
const size_t extent)
1759-
{
1760-
int_fast8_t result = -UDPARD_ERROR_ARGUMENT;
1761-
if ((self != NULL) && (port != NULL) && (service_id <= UDPARD_SERVICE_ID_MAX))
1762-
{
1763-
const int_fast8_t cancel_result = udpardRxRPCDispatcherCancel(self, service_id, is_request);
1764-
UDPARD_ASSERT((cancel_result == 0) || (cancel_result == 1)); // We already checked the arguments.
1765-
memZero(sizeof(*port), port);
1766-
port->service_id = service_id;
1767-
rxPortInit(&port->port);
1768-
port->port.extent = extent;
1769-
port->user_reference = NULL;
1770-
// Insert the newly initialized service into the tree.
1771-
const struct UdpardTreeNode* const item = cavlSearch(is_request ? &self->request_ports : &self->response_ports,
1772-
port,
1773-
&rxRPCSearch,
1774-
&avlTrivialFactory);
1775-
UDPARD_ASSERT((item != NULL) && (item == &port->base));
1776-
(void) item;
1777-
result = (cancel_result > 0) ? 0 : 1;
1778-
}
1779-
return result;
1780-
}
1781-
1782-
int_fast8_t udpardRxRPCDispatcherCancel(struct UdpardRxRPCDispatcher* const self,
1783-
const UdpardPortID service_id,
1784-
const bool is_request)
1785-
{
1786-
int_fast8_t result = -UDPARD_ERROR_ARGUMENT;
1787-
if ((self != NULL) && (service_id <= UDPARD_SERVICE_ID_MAX))
1788-
{
1789-
UdpardPortID service_id_mutable = service_id;
1790-
struct UdpardTreeNode** const root = is_request ? &self->request_ports : &self->response_ports;
1791-
struct UdpardRxRPCPort* const item =
1792-
(struct UdpardRxRPCPort*) (void*) cavlSearch(root, &service_id_mutable, &rxRPCSearchByServiceID, NULL);
1793-
if (item != NULL)
1794-
{
1795-
cavlRemove(root, &item->base);
1796-
rxPortFree(&item->port, self->memory);
1797-
}
1798-
result = (item == NULL) ? 0 : 1;
1799-
}
1800-
return result;
1801-
}
1802-
1803-
int_fast8_t udpardRxRPCDispatcherReceive(struct UdpardRxRPCDispatcher* const self,
1804-
const UdpardMicrosecond timestamp_usec,
1805-
const struct UdpardMutablePayload datagram_payload,
1806-
const uint_fast8_t redundant_iface_index,
1807-
struct UdpardRxRPCPort** const out_port,
1808-
struct UdpardRxRPCTransfer* const out_transfer)
1809-
{
1810-
bool release = true;
1811-
int_fast8_t result = -UDPARD_ERROR_ARGUMENT;
1812-
if ((self != NULL) && (timestamp_usec != TIMESTAMP_UNSET) && (datagram_payload.data != NULL) &&
1813-
(redundant_iface_index < UDPARD_NETWORK_INTERFACE_COUNT_MAX) && (out_transfer != NULL))
1814-
{
1815-
result = 0; // Invalid frames cannot complete a transfer, so zero is the new default.
1816-
RxFrame frame = {0};
1817-
const bool accept = rxParseFrame(datagram_payload, &frame) &&
1818-
((frame.meta.data_specifier & DATA_SPECIFIER_SERVICE_NOT_MESSAGE_MASK) != 0) &&
1819-
(frame.meta.dst_node_id == self->local_node_id);
1820-
if (accept)
1821-
{
1822-
// Service transfers cannot be anonymous. This is enforced by the rxParseFrame function; we re-check this.
1823-
UDPARD_ASSERT(frame.meta.src_node_id != UDPARD_NODE_ID_UNSET);
1824-
// Parse the data specifier in the frame.
1825-
out_transfer->is_request =
1826-
(frame.meta.data_specifier & DATA_SPECIFIER_SERVICE_REQUEST_NOT_RESPONSE_MASK) != 0;
1827-
out_transfer->service_id = frame.meta.data_specifier & DATA_SPECIFIER_SERVICE_ID_MASK;
1828-
// Search for the RPC-port that is registered for this service transfer in the tree.
1829-
struct UdpardRxRPCPort* const item =
1830-
(struct UdpardRxRPCPort*) (void*) cavlSearch(out_transfer->is_request ? &self->request_ports
1831-
: &self->response_ports,
1832-
&out_transfer->service_id,
1833-
&rxRPCSearchByServiceID,
1834-
NULL);
1835-
// If such a port is found, accept the frame on it.
1836-
if (item != NULL)
1837-
{
1838-
result = rxPortAccept(&item->port,
1839-
redundant_iface_index,
1840-
timestamp_usec,
1841-
frame,
1842-
self->memory,
1843-
&out_transfer->base);
1844-
release = false;
1845-
} // else, the application is not interested in this service-ID (does not know how to handle it).
1846-
// Expose the port instance to the caller if requested.
1847-
if (out_port != NULL)
1848-
{
1849-
*out_port = item;
1850-
}
1851-
} // else, we didn't accept so we just ignore this frame
1852-
}
1853-
if ((self != NULL) && release)
1854-
{
1855-
memFreePayload(self->memory.payload, datagram_payload);
1856-
}
1857-
return result;
1858-
}
1859-
18601707
// =====================================================================================================================
18611708
// ==================================================== MISC =====================================================
18621709
// =====================================================================================================================

libudpard/udpard.h

Lines changed: 0 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -928,172 +928,6 @@ int_fast8_t udpardRxSubscriptionReceive(struct UdpardRxSubscription* const self,
928928
const uint_fast8_t redundant_iface_index,
929929
struct UdpardRxTransfer* const out_transfer);
930930

931-
// --------------------------------------------- RPC-SERVICES ---------------------------------------------
932-
933-
/// An RPC-service RX port models the interest of the application in receiving RPC-service transfers of
934-
/// a particular kind (request or response) and a particular service-ID.
935-
struct UdpardRxRPCPort
936-
{
937-
/// READ-ONLY
938-
struct UdpardTreeNode base;
939-
940-
/// READ-ONLY
941-
UdpardPortID service_id;
942-
943-
/// See UdpardRxPort.
944-
/// Use this to change the transfer-ID timeout value for this RPC-service port.
945-
struct UdpardRxPort port;
946-
947-
/// This field can be arbitrarily mutated by the user. It is never accessed by the library.
948-
/// Its purpose is to simplify integration with OOP interfaces.
949-
void* user_reference;
950-
};
951-
952-
/// A service dispatcher is a collection of RPC-service RX ports.
953-
/// Anonymous nodes (nodes without a node-ID of their own) cannot use RPC-services.
954-
struct UdpardRxRPCDispatcher
955-
{
956-
/// The local node-ID has to be stored to facilitate correctness checking of incoming transfers.
957-
/// This value shall not be modified.
958-
/// READ-ONLY
959-
UdpardNodeID local_node_id;
960-
961-
/// Refer to UdpardRxMemoryResources.
962-
struct UdpardRxMemoryResources memory;
963-
964-
/// READ-ONLY
965-
struct UdpardTreeNode* request_ports;
966-
struct UdpardTreeNode* response_ports;
967-
};
968-
969-
/// Represents a received Cyphal RPC-service transfer -- either request or response.
970-
struct UdpardRxRPCTransfer
971-
{
972-
struct UdpardRxTransfer base;
973-
UdpardPortID service_id;
974-
bool is_request;
975-
};
976-
977-
/// To begin receiving RPC-service requests and/or responses, the application should do this:
978-
///
979-
/// 1. Create a new UdpardRxRPCDispatcher instance and initialize it by calling udpardRxRPCDispatcherInit.
980-
///
981-
/// 2. Announce its interest in specific RPC-services (requests and/or responses) by calling
982-
/// udpardRxRPCDispatcherListen per each. This can be done at any later point as well.
983-
///
984-
/// 3. When the local node-ID is known, invoke udpardRxRPCDispatcherStart to inform the library of the
985-
/// node-ID value of the local node, and at the same time obtain the address of the UDP/IP multicast group
986-
/// to bind the socket(s) to. This step can be taken before or after the RPC-service port registration.
987-
/// If the application has to perform a plug-and-play node-ID allocation, it has to complete that beforehand
988-
/// (the dispatcher is not needed for PnP node-ID allocation).
989-
///
990-
/// 4. Having obtained the UDP/IP endpoint in the previous step, do per redundant network interface:
991-
/// - Create a new socket bound to the IP multicast group address and UDP port number obtained earlier.
992-
/// The multicast group address depends on the local node-ID.
993-
///
994-
/// 5. Read data from the sockets continuously and forward each received UDP datagram to
995-
/// udpardRxRPCDispatcherReceive, along with the index of the redundant interface
996-
/// the datagram was received on. Only those services that were announced in step 3 will be processed.
997-
///
998-
/// The reason the local node-ID has to be specified via a separate call is to allow the application to set up the
999-
/// RPC ports early, without having to be aware of its own node-ID. This is useful for applications that perform
1000-
/// plug-and-play node-ID allocation. Applications where PnP is not needed will simply call both functions
1001-
/// at the same time during early initialization.
1002-
///
1003-
/// There is no resource deallocation function ("free") for the RPC dispatcher. This is because the dispatcher
1004-
/// does not own any resources. To dispose of a dispatcher safely, the application shall invoke
1005-
/// udpardRxRPCDispatcherCancel for each RPC-service port on that dispatcher.
1006-
///
1007-
/// The return value is 0 on success.
1008-
/// The return value is a negated UDPARD_ERROR_ARGUMENT if any of the input arguments are invalid.
1009-
///
1010-
/// The time complexity is constant. This function does not invoke the dynamic memory manager.
1011-
int_fast8_t udpardRxRPCDispatcherInit(struct UdpardRxRPCDispatcher* const self,
1012-
const struct UdpardRxMemoryResources memory);
1013-
1014-
/// This function must be called exactly once to complete the initialization of the RPC dispatcher.
1015-
/// It takes the node-ID of the local node, which is used to derive the UDP/IP multicast group address
1016-
/// to bind the sockets to, which is returned via the out parameter.
1017-
///
1018-
/// In Cyphal/UDP, each node has a specific IP multicast group address where RPC-service transfers destined to that
1019-
/// node are sent to. This is similar to subject (topic) multicast group addressed except that the node-ID takes
1020-
/// the place of the subject-ID. The IP multicast group address is derived from the local node-ID.
1021-
///
1022-
/// The application is expected to open a separate socket bound to that endpoint per redundant interface,
1023-
/// and then feed the UDP datagrams received from these sockets into udpardRxRPCDispatcherReceive,
1024-
/// collecting UdpardRxRPCTransfer instances at the output.
1025-
///
1026-
/// This function shall not be called more than once per dispatcher. If the local node needs to change its node-ID,
1027-
/// this dispatcher instance must be destroyed and a new one created instead.
1028-
///
1029-
/// The return value is 0 on success.
1030-
/// The return value is a negated UDPARD_ERROR_ARGUMENT if any of the input arguments are invalid.
1031-
///
1032-
/// The time complexity is constant. This function does not invoke the dynamic memory manager.
1033-
int_fast8_t udpardRxRPCDispatcherStart(struct UdpardRxRPCDispatcher* const self,
1034-
const UdpardNodeID local_node_id,
1035-
struct UdpardUDPIPEndpoint* const out_udp_ip_endpoint);
1036-
1037-
/// This function lets the application register its interest in a particular service-ID and kind (request/response)
1038-
/// by creating an RPC-service RX port. The port pointer shall retain validity until its unregistration or until
1039-
/// the dispatcher is destroyed. The service instance shall not be moved or destroyed.
1040-
///
1041-
/// If such registration already exists, it will be unregistered first as if udpardRxRPCDispatcherCancel was
1042-
/// invoked by the application, and then re-created anew with the new parameters.
1043-
///
1044-
/// For the meaning of extent, please refer to the documentation of the subscription pipeline.
1045-
///
1046-
/// By default, the transfer-ID timeout value is set to UDPARD_DEFAULT_TRANSFER_ID_TIMEOUT_USEC.
1047-
/// It can be changed by the user at any time by modifying the corresponding field in the registration instance.
1048-
///
1049-
/// The return value is 1 if a new registration has been created as requested.
1050-
/// The return value is 0 if such registration existed at the time the function was invoked. In this case,
1051-
/// the existing registration is terminated and then a new one is created in its place. Pending transfers may be lost.
1052-
/// The return value is a negated UDPARD_ERROR_ARGUMENT if any of the input arguments are invalid.
1053-
///
1054-
/// The time complexity is logarithmic from the number of current registrations under the specified transfer kind
1055-
/// (request or response).
1056-
/// This function does not allocate new memory. The function may deallocate memory if such registration already
1057-
/// existed; the deallocation behavior is specified in the documentation for udpardRxRPCDispatcherCancel.
1058-
int_fast8_t udpardRxRPCDispatcherListen(struct UdpardRxRPCDispatcher* const self,
1059-
struct UdpardRxRPCPort* const port,
1060-
const UdpardPortID service_id,
1061-
const bool is_request,
1062-
const size_t extent);
1063-
1064-
/// This function reverses the effect of udpardRxRPCDispatcherListen.
1065-
/// If the registration is found, all its memory is de-allocated (session states and payload buffers).
1066-
/// Please refer to the UdpardRxPort session description for detailed information on the amount of memory freed.
1067-
///
1068-
/// The return value is 1 if such registration existed (and, therefore, it was removed).
1069-
/// The return value is 0 if such registration does not exist. In this case, the function has no effect.
1070-
/// The return value is a negated UDPARD_ERROR_ARGUMENT if any of the input arguments are invalid.
1071-
///
1072-
/// The time complexity is logarithmic from the number of current registration under the specified transfer kind.
1073-
/// This function does not allocate new memory.
1074-
int_fast8_t udpardRxRPCDispatcherCancel(struct UdpardRxRPCDispatcher* const self,
1075-
const UdpardPortID service_id,
1076-
const bool is_request);
1077-
1078-
/// Datagrams received from the sockets of this RPC service dispatcher are fed into this function.
1079-
/// It is the analog of udpardRxSubscriptionReceive for RPC-service transfers.
1080-
/// Please refer to the documentation of udpardRxSubscriptionReceive for the usage information.
1081-
///
1082-
/// Frames (datagrams) that belong to transfers for which there is no active RX RPC port are ignored.
1083-
///
1084-
/// The "out_port" pointer-to-pointer can be used to retrieve the specific UdpardRxRPCPort instance that was used to
1085-
/// process the received transfer. Remember that each UdpardRxRPCPort instance has a user reference field,
1086-
/// which in combination with this feature can be used to construct OOP interfaces on top of the library.
1087-
/// If this is not needed, the pointer-to-pointer can be NULL.
1088-
///
1089-
/// The memory pointed to by out_transfer may be mutated arbitrarily if no transfer is completed.
1090-
int_fast8_t udpardRxRPCDispatcherReceive(struct UdpardRxRPCDispatcher* const self,
1091-
const UdpardMicrosecond timestamp_usec,
1092-
const struct UdpardMutablePayload datagram_payload,
1093-
const uint_fast8_t redundant_iface_index,
1094-
struct UdpardRxRPCPort** const out_port,
1095-
struct UdpardRxRPCTransfer* const out_transfer);
1096-
1097931
// =====================================================================================================================
1098932
// ==================================================== MISC =====================================================
1099933
// =====================================================================================================================

0 commit comments

Comments
 (0)