Esempio n. 1
0
void Network::subscribeToPort(MicroFlo::NodeId nodeId, MicroFlo::PortId portId, bool enable) {
    MICROFLO_RETURN_IF_FAIL(MICROFLO_VALID_NODEID(nodeId),
                            notificationHandler, DebugLevelError, DebugSubscribePortInvalidNode);
    Component *c = nodes[nodeId];
    MICROFLO_RETURN_IF_FAIL(portId >= 0 && portId < c->nPorts,
                            notificationHandler, DebugLevelError, DebugSubscribePortInvalidPort);

    c->connections[portId].subscribed = enable;
    if (notificationHandler) {
        notificationHandler->portSubscriptionChanged(nodeId, portId, enable);
    }
}
Esempio n. 2
0
void Network::connectSubgraph(bool isOutput,
                              MicroFlo::NodeId subgraphNode, MicroFlo::PortId subgraphPort,
                              MicroFlo::NodeId childNode, MicroFlo::PortId childPort) {
#ifdef MICROFLO_ENABLE_SUBGRAPHS

    MICROFLO_RETURN_IF_FAIL(MICROFLO_VALID_NODEID(subgraphNode) && MICROFLO_VALID_NODEID(childNode),
                    notificationHandler, DebugLevelError, DebugSubGraphConnectInvalidNodes);

    Component *comp = nodes[subgraphNode];
    Component *child = nodes[childNode];
    MICROFLO_ASSERT(comp->component() == MicroFlo::IdSubGraph && child->parentNodeId >= Network::firstNodeId,
                    notificationHandler, DebugLevelError, DebugSubGraphConnectNotASubgraph);

    SubGraph *subgraph = (SubGraph *)comp;
    if (isOutput) {
        subgraph->connectOutport(subgraphPort, child, childPort);
    } else {
        subgraph->connectInport(subgraphPort, child, childPort);
    }
    if (notificationHandler) {
        notificationHandler->subgraphConnected(isOutput, subgraphNode, subgraphPort, childNode, childPort);
    }
#else
    MICROFLO_DEBUG(this, DebugLevelError, DebugNotSupported);
#endif
}
Esempio n. 3
0
void Network::connect(MicroFlo::NodeId srcId, MicroFlo::PortId srcPort,
                      MicroFlo::NodeId targetId,MicroFlo::PortId targetPort) {
    MICROFLO_RETURN_IF_FAIL(MICROFLO_VALID_NODEID(srcId) && MICROFLO_VALID_NODEID(targetId),
                            notificationHandler, DebugLevelError, DebugNetworkConnectInvalidNodes);

    connect(nodes[srcId], srcPort, nodes[targetId], targetPort);
}
Esempio n. 4
0
void Component::send(Packet out, MicroFlo::PortId port) {
    MICROFLO_RETURN_IF_FAIL(port < nPorts,
                            network->notificationHandler, DebugLevelError, DebugComponentSendInvalidPort);

    if (connections[port].target && connections[port].targetPort >= 0) {
        network->sendMessage(connections[port].target, connections[port].targetPort, out,
                             this, port);
    }
}
Esempio n. 5
0
void Network::deliverMessages(MicroFlo::MessageId firstIndex, MicroFlo::MessageId lastIndex) {
#ifndef HOST_BUILD
    // complains that the check can never hit
    MICROFLO_RETURN_IF_FAIL(firstIndex < MICROFLO_MAX_MESSAGES && lastIndex < MICROFLO_MAX_MESSAGES,
                            notificationHandler, DebugLevelError, DebugDeliverMessagesInvalidMessageId);
#endif
    for (MicroFlo::MessageId i=firstIndex; i<=lastIndex; i++) {
        Component *target = messages[i].target;
        if (!target) {
            // FIXME: this should not happen
            continue;
        }
        target->process(messages[i].pkg, messages[i].targetPort);
        if (notificationHandler) {
            notificationHandler->packetDelivered(i, messages[i]);
        }
    }
}
Esempio n. 6
0
void Network::deliverMessages(MicroFlo::MessageId firstIndex, MicroFlo::MessageId lastIndex) {
#ifndef HOST_BUILD
    // complains that the check can never hit
    // FIXME: sometimes triggers. Off-by-one?
    MICROFLO_RETURN_IF_FAIL(firstIndex < MICROFLO_MAX_MESSAGES && lastIndex < MICROFLO_MAX_MESSAGES,
                            notificationHandler, DebugLevelError, DebugDeliverMessagesInvalidMessageId);
#endif
    for (MicroFlo::MessageId i=firstIndex; i<=lastIndex; i++) {
        Component *target = messages[i].target;
        if (!target) {
            // FIXME: this should not happen
            continue;
        }

        const Message &msg = messages[i];
        const Component *sender = msg.sender;
        const bool sendNotification = sender ? sender->connections[msg.senderPort].subscribed : false;
        if (sendNotification && notificationHandler) {
            notificationHandler->packetSent(i, msg);
        }

        target->process(msg.pkg, msg.targetPort);
    }
}
Esempio n. 7
0
void Network::sendMessageId(MicroFlo::NodeId targetId, MicroFlo::PortId targetPort, const Packet &pkg) {
    MICROFLO_RETURN_IF_FAIL(MICROFLO_VALID_NODEID(targetId),
                            notificationHandler, DebugLevelError, DebugSendMessageInvalidNode);

    sendMessage(nodes[targetId], targetPort, pkg);
}