xme_status_t xme_core_directory_nodeRegistryController_addInterface ( xme_core_node_nodeId_t nodeId, xme_com_interface_address_t interfaceAddress ) { xme_hal_table_rowHandle_t handle; xme_core_node_nodeData_t* nodeItem; xme_com_interface_address_t* newInterfaceAddress; XME_CHECK(XME_CORE_NODE_INVALID_NODE_ID != nodeId, XME_STATUS_INVALID_PARAMETER); // Search for an existing item for this node handle = XME_HAL_TABLE_INVALID_ROW_HANDLE; nodeItem = NULL; XME_HAL_TABLE_GET_NEXT(xme_core_directory_nodeRegistryController_nodeTable, xme_hal_table_rowHandle_t, handle, xme_core_node_nodeData_t, nodeItem, nodeItem->nodeId == nodeId); // The node should already be registered XME_CHECK(XME_HAL_TABLE_INVALID_ROW_HANDLE != handle, XME_STATUS_NOT_FOUND); if (nodeItem != NULL) { if (0 != XME_HAL_TABLE_ITEM_COUNT(nodeItem->interfaces)) { xme_hal_table_rowHandle_t rh = XME_HAL_TABLE_INVALID_ROW_HANDLE; xme_com_interface_address_t *interfaceItem = NULL; XME_HAL_TABLE_GET_NEXT ( nodeItem->interfaces, xme_hal_table_rowHandle_t, rh, xme_com_interface_address_t, interfaceItem, interfaceItem->addressType == interfaceAddress.addressType ); while (NULL != interfaceItem) { if (0 == xme_hal_mem_compare(interfaceItem, &interfaceAddress, sizeof(xme_com_interface_address_t))) { return XME_STATUS_ALREADY_EXIST; } interfaceItem = NULL; XME_HAL_TABLE_GET_NEXT ( nodeItem->interfaces, xme_hal_table_rowHandle_t, rh, xme_com_interface_address_t, interfaceItem, interfaceItem->addressType == interfaceAddress.addressType ); } } handle = XME_HAL_TABLE_ADD_ITEM(nodeItem->interfaces); XME_CHECK(XME_HAL_TABLE_INVALID_ROW_HANDLE != handle, XME_STATUS_OUT_OF_RESOURCES); newInterfaceAddress = (xme_com_interface_address_t*) XME_HAL_TABLE_ITEM_FROM_HANDLE(nodeItem->interfaces, handle); XME_ASSERT(NULL != newInterfaceAddress); (void) xme_hal_mem_copy(newInterfaceAddress, &interfaceAddress, sizeof(xme_com_interface_address_t)); } return XME_STATUS_SUCCESS; }
xme_status_t reapplyManipulations ( xme_core_dataManager_dataStoreID_t dataStoreID ) { xme_core_dataHandler_database_manipulationItem_t* manipulationItem = NULL; xme_hal_table_rowHandle_t internalHandle = XME_HAL_TABLE_INVALID_ROW_HANDLE; do { void* returnAddress; // Obtain the next element. XME_HAL_TABLE_GET_NEXT ( manipulationsTable, xme_hal_table_rowHandle_t, internalHandle, xme_core_dataHandler_database_manipulationItem_t, manipulationItem, (manipulationItem->dataStoreID == dataStoreID) ); if (XME_HAL_TABLE_INVALID_ROW_HANDLE == internalHandle) continue; XME_ASSERT(NULL != manipulationItem); returnAddress = xme_hal_mem_copy((void*) manipulationItem->address, &(manipulationItem->value), sizeof(manipulationItem->value)); XME_CHECK(returnAddress == (void*) manipulationItem->address, XME_STATUS_INTERNAL_ERROR); } while(XME_HAL_TABLE_INVALID_ROW_HANDLE != internalHandle); return XME_STATUS_SUCCESS; }
xme_status_t removeManipulation ( xme_core_dataManager_dataStoreID_t dataStoreID, uintptr_t address ) { xme_core_dataHandler_database_manipulationItem_t* manipulationItem; xme_hal_table_rowHandle_t internalHandle = XME_HAL_TABLE_INVALID_ROW_HANDLE; xme_status_t status; // Obtain the next element. XME_HAL_TABLE_GET_NEXT ( manipulationsTable, xme_hal_table_rowHandle_t, internalHandle, xme_core_dataHandler_database_manipulationItem_t, manipulationItem, (manipulationItem->dataStoreID == dataStoreID && manipulationItem->address == address) ); if (XME_HAL_TABLE_INVALID_ROW_HANDLE == internalHandle) { return XME_STATUS_NOT_FOUND; } // Remove the element. status = XME_HAL_TABLE_REMOVE_ITEM(manipulationsTable, internalHandle); XME_CHECK(XME_STATUS_SUCCESS == status, XME_STATUS_INTERNAL_ERROR); return XME_STATUS_SUCCESS; }
uint32_t getNumberOfManipulationsForDataStore ( xme_core_dataManager_dataStoreID_t dataStoreID ) { xme_core_dataHandler_database_manipulationItem_t* manipulationItem; xme_hal_table_rowHandle_t internalHandle = XME_HAL_TABLE_INVALID_ROW_HANDLE; uint32_t numberOfRemainingManipulations = 0U; do { // Obtain the next element. XME_HAL_TABLE_GET_NEXT ( manipulationsTable, xme_hal_table_rowHandle_t, internalHandle, xme_core_dataHandler_database_manipulationItem_t, manipulationItem, (manipulationItem->dataStoreID == dataStoreID) ); if (XME_HAL_TABLE_INVALID_ROW_HANDLE == internalHandle) continue; numberOfRemainingManipulations++; } while(XME_HAL_TABLE_INVALID_ROW_HANDLE != internalHandle); return numberOfRemainingManipulations; }
xme_core_node_nodeId_t xme_core_directory_nodeRegistryController_nextNodeID ( xme_core_directory_nodeRegistryController_nodeIDIterator_t* const iterator ) { xme_core_node_nodeData_t* nodeData; xme_core_node_nodeId_t nextNodeID = XME_CORE_NODE_INVALID_NODE_ID; XME_CHECK(NULL != iterator, XME_CORE_NODE_INVALID_NODE_ID); XME_CHECK(XME_HAL_TABLE_INVALID_ROW_HANDLE != iterator->currentHandle, XME_CORE_NODE_INVALID_NODE_ID); nodeData = XME_HAL_TABLE_ITEM_FROM_HANDLE(xme_core_directory_nodeRegistryController_nodeTable, iterator->currentHandle); XME_CHECK(NULL != nodeData, XME_CORE_NODE_INVALID_NODE_ID); nextNodeID = nodeData->nodeId; XME_HAL_TABLE_GET_NEXT ( xme_core_directory_nodeRegistryController_nodeTable, xme_hal_table_rowHandle_t, iterator->currentHandle, xme_core_node_nodeData_t, nodeData, true ); return nextNodeID; }
xme_status_t xme_core_directory_nodeRegistryController_initNodeIDIterator ( xme_core_directory_nodeRegistryController_nodeIDIterator_t* iterator ) { xme_hal_table_rowHandle_t handle = XME_HAL_TABLE_INVALID_ROW_HANDLE; xme_core_node_nodeData_t* nodeData = NULL; XME_CHECK(NULL != iterator, XME_STATUS_INVALID_PARAMETER); iterator->currentHandle = XME_HAL_TABLE_INVALID_ROW_HANDLE; XME_HAL_TABLE_GET_NEXT ( xme_core_directory_nodeRegistryController_nodeTable, xme_hal_table_rowHandle_t, handle, xme_core_node_nodeData_t, nodeData, true ); iterator->currentHandle = handle; return XME_STATUS_SUCCESS; }
xme_status_t xme_core_directory_nodeRegistryController_getNodeName ( xme_core_node_nodeId_t nodeId, char* const nodeName, uint16_t size ) { xme_hal_table_rowHandle_t handle = XME_HAL_TABLE_INVALID_ROW_HANDLE; xme_core_node_nodeData_t* nodeData = NULL; XME_CHECK(XME_CORE_NODE_INVALID_NODE_ID != nodeId, XME_STATUS_INVALID_PARAMETER); XME_CHECK(NULL != nodeName, XME_STATUS_INVALID_PARAMETER); XME_HAL_TABLE_GET_NEXT ( xme_core_directory_nodeRegistryController_nodeTable, xme_hal_table_rowHandle_t, handle, xme_core_node_nodeData_t, nodeData, (nodeId == nodeData->nodeId) ); // The node is not yet registered if (XME_HAL_TABLE_INVALID_ROW_HANDLE == handle || NULL == nodeData) { return XME_STATUS_NOT_FOUND; } (void)xme_hal_safeString_strncpy(nodeName, nodeData->nodeName, size); return XME_STATUS_SUCCESS; }
xme_status_t xme_core_directory_nodeRegistryController_deregisterNode ( xme_core_node_nodeId_t nodeID ) { xme_hal_table_rowHandle_t handle; xme_core_node_nodeData_t* nodeItem; xme_status_t status; XME_CHECK(XME_CORE_NODE_INVALID_NODE_ID != nodeID, XME_STATUS_INVALID_PARAMETER); // Search for an existing item for this node handle = XME_HAL_TABLE_INVALID_ROW_HANDLE; nodeItem = NULL; XME_HAL_TABLE_GET_NEXT ( xme_core_directory_nodeRegistryController_nodeTable, xme_hal_table_rowHandle_t, handle, xme_core_node_nodeData_t, nodeItem, nodeItem->nodeId == nodeID ); // The node id is not registered XME_CHECK(XME_HAL_TABLE_INVALID_ROW_HANDLE != handle, XME_STATUS_NOT_FOUND); status = XME_HAL_TABLE_REMOVE_ITEM(xme_core_directory_nodeRegistryController_nodeTable, handle); XME_ASSERT(XME_STATUS_SUCCESS == status); return XME_STATUS_SUCCESS; }
xme_status_t xme_core_directory_nodeRegistryController_initNodeInterfaceIterator ( xme_core_node_nodeId_t nodeId, xme_com_interface_addressType_t addressType, xme_core_directory_nodeRegistryController_nodeInterfaceIterator_t **iterator ) { xme_hal_table_rowHandle_t handle = XME_HAL_TABLE_INVALID_ROW_HANDLE; xme_core_node_nodeData_t* nodeItem = NULL; XME_CHECK(NULL != iterator, XME_STATUS_INVALID_PARAMETER); XME_CHECK(XME_CORE_NODE_INVALID_NODE_ID != nodeId, XME_STATUS_INVALID_PARAMETER); XME_HAL_TABLE_GET_NEXT ( xme_core_directory_nodeRegistryController_nodeTable, xme_hal_table_rowHandle_t, handle, xme_core_node_nodeData_t, nodeItem, nodeItem->nodeId == nodeId ); // The node should already be registered XME_CHECK(XME_HAL_TABLE_INVALID_ROW_HANDLE != handle, XME_STATUS_NOT_FOUND); XME_ASSERT(NULL != nodeItem); *iterator = (xme_core_directory_nodeRegistryController_nodeInterfaceIterator_t*) xme_hal_mem_alloc(sizeof(xme_core_directory_nodeRegistryController_nodeInterfaceIterator_t)); XME_CHECK(NULL != iterator, XME_STATUS_OUT_OF_RESOURCES); (*iterator)->nodeId = nodeId; (*iterator)->nodeItem = nodeItem; (*iterator)->addressType = addressType; (*iterator)->currentHandle = XME_HAL_TABLE_INVALID_ROW_HANDLE; (*iterator)->interfaceItem = NULL; XME_HAL_TABLE_GET_NEXT ( (*iterator)->nodeItem->interfaces, xme_hal_table_rowHandle_t, (*iterator)->currentHandle, xme_com_interface_address_t, (*iterator)->interfaceItem, (*iterator)->interfaceItem->addressType == (*iterator)->addressType || XME_COM_INTERFACE_ADDRESS_TYPE_INVALID == (*iterator)->addressType ); return XME_STATUS_SUCCESS; }
xme_status_t xme_core_directory_nodeRegistryController_getInterface ( xme_core_node_nodeId_t nodeId, xme_com_interface_addressType_t addressType, xme_com_interface_address_t** outInterfaceAddress ) { xme_hal_table_rowHandle_t handle; xme_core_node_nodeData_t* nodeItem; xme_com_interface_address_t* interfaceItem; XME_CHECK(XME_CORE_NODE_INVALID_NODE_ID != nodeId, XME_STATUS_INVALID_PARAMETER); XME_CHECK(XME_COM_INTERFACE_ADDRESS_TYPE_INVALID != addressType, XME_STATUS_INVALID_PARAMETER); XME_CHECK(NULL != outInterfaceAddress, XME_STATUS_INVALID_PARAMETER); // Search for an existing item for this node handle = XME_HAL_TABLE_INVALID_ROW_HANDLE; nodeItem = NULL; XME_HAL_TABLE_GET_NEXT(xme_core_directory_nodeRegistryController_nodeTable, xme_hal_table_rowHandle_t, handle, xme_core_node_nodeData_t, nodeItem, nodeItem->nodeId == nodeId); // Return if the node is not yet registered XME_CHECK(XME_HAL_TABLE_INVALID_ROW_HANDLE != handle, XME_STATUS_NOT_FOUND); // FIXME: If nodeItem is NULL, we still return XME_STATUS_SUCCESS -- is this intended? if (nodeItem != NULL) { // Within the node item, look for the appropriate interface handle = XME_HAL_TABLE_INVALID_ROW_HANDLE; interfaceItem = NULL; XME_HAL_TABLE_GET_NEXT(nodeItem->interfaces, xme_hal_table_rowHandle_t, handle, xme_com_interface_address_t, interfaceItem, interfaceItem->addressType == addressType); // Return if no matching interface was found XME_CHECK(XME_HAL_TABLE_INVALID_ROW_HANDLE != handle, XME_STATUS_NOT_FOUND); XME_ASSERT(NULL != interfaceItem); *outInterfaceAddress = interfaceItem; } return XME_STATUS_SUCCESS; }
xme_status_t xme_core_directory_nodeRegistryController_registerNode ( xme_core_node_nodeId_t nodeId, const char* nodeName, xme_core_node_guid_t guid ) { xme_hal_table_rowHandle_t handle; xme_core_node_nodeData_t* nodeItem; XME_CHECK(XME_CORE_NODE_INVALID_NODE_ID != nodeId, XME_STATUS_INVALID_PARAMETER); XME_CHECK(NULL != nodeName, XME_STATUS_INVALID_PARAMETER); XME_CHECK(0 != guid, XME_STATUS_INVALID_PARAMETER); // Search for an existing item for this node handle = XME_HAL_TABLE_INVALID_ROW_HANDLE; nodeItem = NULL; XME_HAL_TABLE_GET_NEXT ( xme_core_directory_nodeRegistryController_nodeTable, xme_hal_table_rowHandle_t, handle, xme_core_node_nodeData_t, nodeItem, nodeItem->nodeId == nodeId ); { // The node should not yet be registered XME_CHECK(XME_HAL_TABLE_INVALID_ROW_HANDLE == handle, XME_STATUS_ALREADY_EXIST); // Insert the node handle = XME_HAL_TABLE_ADD_ITEM(xme_core_directory_nodeRegistryController_nodeTable); XME_CHECK(XME_HAL_TABLE_INVALID_ROW_HANDLE != handle, XME_STATUS_OUT_OF_RESOURCES); nodeItem = (xme_core_node_nodeData_t*) XME_HAL_TABLE_ITEM_FROM_HANDLE(xme_core_directory_nodeRegistryController_nodeTable, handle); XME_ASSERT(NULL != nodeItem); nodeItem->nodeId = nodeId; xme_hal_safeString_strncpy(nodeItem->nodeName, nodeName, sizeof(nodeItem->nodeName)); nodeItem->guid = guid; XME_HAL_TABLE_INIT(nodeItem->interfaces); } return XME_STATUS_SUCCESS; }
xme_status_t xme_wp_marshal_marshaler_getConfig ( xme_wp_waypoint_instanceId_t* instanceId, xme_core_topic_t* topic, xme_core_dataManager_dataPacketId_t* inputPort, xme_core_dataManager_dataPacketId_t* outputPort ) { xme_hal_table_rowHandle_t rowHandle = XME_HAL_TABLE_INVALID_ROW_HANDLE; configurationItem_t* configItem = NULL; // Check parameters in debug build only XME_ASSERT(NULL != instanceId); XME_ASSERT(NULL != topic); XME_ASSERT(NULL != inputPort); XME_ASSERT(NULL != outputPort); XME_HAL_TABLE_GET_NEXT ( configurationTable, xme_hal_table_rowHandle_t, rowHandle, configurationItem_t, configItem, ( (XME_WP_WAYPOINT_INSTANCEID_INVALID == *instanceId || rowHandle == (xme_hal_table_rowHandle_t)(*instanceId)) && (XME_CORE_TOPIC_INVALID_TOPIC == *topic || configItem->topic == *topic) && (XME_CORE_DATAMANAGER_DATAPACKETID_INVALID == *inputPort || configItem->inputPort == *inputPort) && (XME_CORE_DATAMANAGER_DATAPACKETID_INVALID == *outputPort || configItem->outputPort == *outputPort) ) ); if (XME_HAL_TABLE_INVALID_ROW_HANDLE != rowHandle) { *instanceId = (xme_wp_waypoint_instanceId_t)rowHandle; *topic = configItem->topic; *inputPort = configItem->inputPort; *outputPort = configItem->outputPort; return XME_STATUS_SUCCESS; } return XME_STATUS_NOT_FOUND; }
xme_com_interface_address_t* xme_core_directory_nodeRegistryController_nextInterface ( xme_core_directory_nodeRegistryController_nodeInterfaceIterator_t *iterator ) { xme_com_interface_address_t* interfaceItem = NULL; XME_CHECK(NULL != iterator, NULL); // Store the pointer to current interfaceItem in the iterator // This will be returned in this call interfaceItem = iterator->interfaceItem; // This check is added for wrap around of the iterator. // After the last item in the list the XME_HAL_TABLE_GET_NEXT sets the // row handle as INVALID_ROW_HANDLE and the pointer as NULL. // Then accordingly hasNextInterface returns false. // But if this function is called even when hasNextInterface has returned false // the iterator begins from the start and wraps around. // This happens because the XME_HAL_TABLE_GET_NEXT assumes INVALID_ROW_HANDLE as a parameter // for the table to start the iteration. // This is a safe check because the corresponding init function initializes the pointer to first value if it exists // Then this check will pass and return the correct value for nextInterface after the init. // And if it does not exist then this will fail and return NULL from here. XME_CHECK((XME_HAL_TABLE_INVALID_ROW_HANDLE != iterator->currentHandle && NULL != iterator->interfaceItem), NULL); iterator->interfaceItem = NULL; // Move the iterator to next item XME_HAL_TABLE_GET_NEXT ( iterator->nodeItem->interfaces, xme_hal_table_rowHandle_t, iterator->currentHandle, xme_com_interface_address_t, iterator->interfaceItem, iterator->interfaceItem->addressType == iterator->addressType || XME_COM_INTERFACE_ADDRESS_TYPE_INVALID == iterator->addressType ); return interfaceItem; }
xme_status_t xme_core_directory_nodeRegistryController_getGUIDFromNodeId ( xme_core_node_nodeId_t nodeId, xme_core_node_guid_t* outGuid ) { xme_hal_table_rowHandle_t handle; xme_core_node_nodeData_t* nodeItem; XME_CHECK(XME_CORE_NODE_INVALID_NODE_ID != nodeId, XME_STATUS_INVALID_PARAMETER); XME_CHECK(NULL != outGuid, XME_STATUS_INVALID_PARAMETER); // Search for an existing item for this node handle = XME_HAL_TABLE_INVALID_ROW_HANDLE; nodeItem = NULL; XME_HAL_TABLE_GET_NEXT ( xme_core_directory_nodeRegistryController_nodeTable, xme_hal_table_rowHandle_t, handle, xme_core_node_nodeData_t, nodeItem, nodeItem->nodeId == nodeId ); // The node is not yet registered if (XME_HAL_TABLE_INVALID_ROW_HANDLE == handle || NULL == nodeItem) { *outGuid = 0; return XME_STATUS_NOT_FOUND; } // The guid is registered *outGuid = nodeItem->guid; return XME_STATUS_SUCCESS; }
xme_status_t addManipulation ( xme_core_dataManager_dataStoreID_t dataStoreID, uintptr_t address, uint32_t value ) { xme_core_dataHandler_database_manipulationItem_t* manipulationItem = NULL; xme_hal_table_rowHandle_t internalHandle = XME_HAL_TABLE_INVALID_ROW_HANDLE; // Obtain the next element. XME_HAL_TABLE_GET_NEXT ( manipulationsTable, xme_hal_table_rowHandle_t, internalHandle, xme_core_dataHandler_database_manipulationItem_t, manipulationItem, (manipulationItem->dataStoreID == dataStoreID && manipulationItem->address == (uintptr_t) address) ); if (XME_HAL_TABLE_INVALID_ROW_HANDLE == internalHandle) { // Create a new element. internalHandle = XME_HAL_TABLE_ADD_ITEM(manipulationsTable); XME_CHECK(XME_HAL_TABLE_INVALID_ROW_HANDLE != internalHandle, XME_STATUS_OUT_OF_RESOURCES); manipulationItem = XME_HAL_TABLE_ITEM_FROM_HANDLE(manipulationsTable, internalHandle); XME_ASSERT(NULL != manipulationItem); manipulationItem->dataStoreID = dataStoreID; manipulationItem->address = address; manipulationItem->value = value; } else { // Use existing element. manipulationItem->value = value; } return XME_STATUS_SUCCESS; }
bool xme_core_directory_nodeRegistryController_isNodeGuidRegistered ( xme_core_node_guid_t guid, xme_core_node_nodeId_t* const outNodeID ) { xme_hal_table_rowHandle_t handle; xme_core_node_nodeData_t* nodeItem; XME_CHECK(0 != guid, false); // Search for an existing item for this node handle = XME_HAL_TABLE_INVALID_ROW_HANDLE; nodeItem = NULL; XME_HAL_TABLE_GET_NEXT ( xme_core_directory_nodeRegistryController_nodeTable, xme_hal_table_rowHandle_t, handle, xme_core_node_nodeData_t, nodeItem, nodeItem->guid == guid ); if (XME_HAL_TABLE_INVALID_ROW_HANDLE != handle) { if (NULL != outNodeID) { *outNodeID = nodeItem->nodeId; } return true; } return false; }