示例#1
0
void DummyDevDA::executeInputLoop() {

    int ac1 = 0;
    this->inputLoopRunning = true;
    while (this->inputLoopRunning) {

#ifndef _WIN32
    fd_set rfds;
    struct timeval tv;
    int retval;

    FD_ZERO(&rfds);
    FD_SET(0, &rfds);

    tv.tv_sec = 0;
    tv.tv_usec = 300000;
    retval = select(1, &rfds, 0, 0, &tv);
#endif

#ifdef _WIN32
        Sleep(1000);
#endif

        if (this->eventSink) {
            {
                AnalogChangedEvent * event = new AnalogChangedEvent();
                event->setAddress(EPAddress(this->entityID, this->deviceDescriptor.getNameChannelNrMap()["AO1"]));
                event->setPayload(static_cast<float>(rand())/static_cast<float>(RAND_MAX));
                eventSink->push(event);
            }

            if (ac1 % 4 == 0) {
                DigitalChangedEvent * event = new DigitalChangedEvent();
                event->setAddress(EPAddress(this->entityID, this->deviceDescriptor.getNameChannelNrMap()["DO1"]));
                event->setPayload(ac1 % 8 == 0);
                eventSink->push(event);
            }

            if (ac1 % 7 == 0) {
                DigitalChangedEvent * event = new DigitalChangedEvent();
                event->setAddress(EPAddress(this->entityID, this->deviceDescriptor.getNameChannelNrMap()["DO2"]));
                event->setPayload(ac1 % 14 == 0);
                eventSink->push(event);
            }            
            
            ac1++;
        }
    }
}
void DummyDevPackedVector4::executeInputLoop() {
    this->inputLoopRunning = true;
    while (this->inputLoopRunning) {
#ifndef _WIN32
        fd_set rfds;
        struct timeval tv;
        int retval;

        FD_ZERO(&rfds);
        FD_SET(0, &rfds);

        tv.tv_sec = 0;
        tv.tv_usec = 100000;
        retval = select(1, &rfds, 0, 0, &tv);
#endif
#ifdef _WIN32
        Sleep(100);
#endif
        if (this->eventSink) {
            {
                map<std::string, int>::iterator i = this->deviceDescriptor.getNameChannelNrMap().begin();
                map<std::string, int>::iterator e = this->deviceDescriptor.getNameChannelNrMap().end();
                while (i != e) {
                    PackedVector4Event * event = new PackedVector4Event();
                    event->setAddress(EPAddress(this->entityID, (*i).second));
                   
                    PackedType<Vector4<double> > pv;
                    vector<pair<int, Vector4<double> > > & v = pv.getItems();
                    for (int i2 = 0; i2 < 24; ++i2) {
                        v.push_back(pair<int, Vector4<double> >(101 + i2, getRandomVector4(1.0)));
                    }
                    event->setPayload(pv);
                    eventSink->push(event);
                    
                    ++i;
                }
            }
        }
    }
}
示例#3
0
void TUIServerApp::createEntityGraph(const map<string, TUIObjectInstance> & tuiObjectInstanceMap,
        const vector<Connector> & connectorVector) {
    try {
        vector<Connector>::const_iterator i = connectorVector.begin();
        vector<Connector>::const_iterator e = connectorVector.end();
        while (i != e) {

            TFINFO("Connector: " << "(from: " << (*i).getSrcAddress().getOwnerType() << " "
                    << (*i).getSrcAddress().getName() << " "
                    << (*i).getSrcAddress().getPortName() << ") "
                    << "(to: " << (*i).getDstAddress().getOwnerType()
                    << " " << (*i).getDstAddress().getName() << " "
                    << (*i).getDstAddress().getPortName() << ") ");

            IEventSink * sink;
            switch ((*i).getDstAddress().getOwnerType()) {
                case PortAddress::DEVICE: {

                    int dstDeviceID = this->deviceContainer.getEntityIDByName(
                            (*i).getDstAddress().getName());
                    int dstChannelNr = this->deviceContainer.getChannelIDByName(
                            dstDeviceID, (*i).getDstAddress().getPortName());

                    std::map<int, IEventSink *>::iterator iter =
                            this->eventSinkMap.find(dstDeviceID);
                    if (iter == this->eventSinkMap.end()) {
                        throw Exception(TFSTR(""), __FILE__, __LINE__);
                        // TODO Throw Exception
                        TFERROR("");
                    }
                    // int eID = -1, int chNr = -1, IEventSink * eventSink = 0
                    EPAddressTranslator * at = new EPAddressTranslator(
                            dstDeviceID, dstChannelNr, (*iter).second);
                    this->addressTranslatorVector.push_back(at);
                    sink = at;
                    break;
                }
                case PortAddress::MSP: {
                    sink = this->mspContainer.getEventSink(
                            (*i).getDstAddress().getName(),
                            (*i).getDstAddress().getPortName());
                    break;
                }
                case PortAddress::TUIOBJECT: {
                    std::map<std::string, TUIObjectInstance>::const_iterator iter =
                            tuiObjectInstanceMap.find((*i).getDstAddress().getName());
                    if (iter == tuiObjectInstanceMap.end()) {
                        // TODO throw Exception
                        TFERROR("");
                    }

                    int tuiObjectID = (*iter).second.getID();
                    //TFDEBUG("Searching port: " << (*i).getDstAddress().getPortName());
                    map<string, int>::const_iterator iter2 =
                            (*iter).second.getNameChannelNrMap().find(
                                    (*i).getDstAddress().getPortName());
                    if (iter2 == (*iter).second.getNameChannelNrMap().end()) {
                        // TODO throw Exception
                        TFERROR("Size: " << (*iter).second.getNameChannelNrMap().size());
                    }
                    int tuiChannelNr = (*iter2).second;

                    IEventSink * es;
                    if (this->usingMulticast) {
                        es = &this->mcEventQueue;
                    } else {
                        es = &this->outEventQueue;
                    }
                    
                    EPAddressTranslator * at = new EPAddressTranslator(
                            tuiObjectID, tuiChannelNr, es);
                    this->addressTranslatorVector.push_back(at);
                    sink = at;
                    break;
                }
                default: {
                    // TODO Throw Exception
                    TFERROR("");
                    break;
                }
            }

            switch ((*i).getSrcAddress().getOwnerType()) {
                case PortAddress::DEVICE: {
                    int srcDeviceID = this->deviceContainer.getEntityIDByName(
                                            (*i).getSrcAddress().getName());
                    int srcChannelNr = this->deviceContainer.getChannelIDByName(
                            srcDeviceID,
                            (*i).getSrcAddress().getPortName());

                    std::map<int, EventMsgRouter<EPAddress, IEventSink, EPAddress::CompareByChannelNr> *>::iterator iter =
                            this->deviceChannelRouterMap.find(srcDeviceID);
                    if (iter == this->deviceChannelRouterMap.end()) {
                        // TODO Throw Exception
                        TFERROR("");
                    }
                    (*iter).second->addRoutingTableEntry(EPAddress(-1, srcChannelNr), sink);
                    break;
                }
                case PortAddress::MSP: {
                    this->mspContainer.registerEventSink((*i).getSrcAddress().getName(), (*i).getSrcAddress().getPortName(), sink);
                    break;
                }
                case PortAddress::TUIOBJECT: {

                    std::map<std::string, TUIObjectInstance>::const_iterator iter =
                            tuiObjectInstanceMap.find((*i).getSrcAddress().getName());
                    if (iter == tuiObjectInstanceMap.end()) {
                        // TODO throw Exception
                        TFERROR("");
                    }

                    int tuiObjectID = (*iter).second.getID();
                    map<string, int>::const_iterator iter2 =
                            (*iter).second.getNameChannelNrMap().find(
                                    (*i).getSrcAddress().getPortName());
                    if (iter2 == (*iter).second.getNameChannelNrMap().end()) {
                        // TODO throw Exception
                        TFERROR("");
                    }
                    int tuiChannelNr = (*iter2).second;

                    std::map<int, EventMsgRouter<EPAddress, IEventSink, EPAddress::CompareByChannelNr> *>::iterator iter3 =
                            this->tuiChannelRouterMap.find(tuiObjectID);
                    if (iter3 == this->tuiChannelRouterMap.end()) {
                        // TODO Throw Exception
                        TFERROR("");
                    }
                   (*iter3).second->addRoutingTableEntry(EPAddress(-1, tuiChannelNr), sink);
                    break;
                }
                default: {
                    // TODO Throw Exception
                    TFERROR("");
                    break;
                }
            }

            ++i;
        }
    }
    catch (Exception & e) {
        TFERROR(e.getFormattedString());
        //this->tuiServerExit();
    }

}
示例#4
0
void TUIServerApp::init(const ServerConfig & serverConfig) {

    cout << serverConfig << endl;

    deviceContainer.createDeviceInstances(serverConfig.getDeviceInstanceMap());
    deviceContainer.connectDevices(*this);
    mspContainer.createInstances(serverConfig.getMSPInstanceMap());

    map<string, TUIObjectInstance> tuiObjectInstanceMap = serverConfig.getTUIObjectInstanceMap();

    // it follows the filtering of not used tui object types
    // initialization of the tuiRouterMap
    vector<TUIObjectType> tuiObjectTypeVector;
    vector<TUIObjectInstance> tuiObjectInstanceVector;
    map<string, TUIObjectType> tuiObjectTypeMap;
        // fills the tuiObjectTypeVector only with TUIObjectType objects,
        // which are used by TUIObjectInstance objects.
    int tuiID = 1;
    {
        map<string, TUIObjectInstance>::iterator i = tuiObjectInstanceMap.begin();
        map<string, TUIObjectInstance>::iterator e = tuiObjectInstanceMap.end();
        while (i != e) {
            //TFDEBUG((*i).first);
            EventMsgRouter<EPAddress, IEventSink, EPAddress::CompareByChannelNr> * tuiChannelRouter =
                        new EventMsgRouter<EPAddress, IEventSink, EPAddress::CompareByChannelNr>();
            this->tuiChannelRouterMap[tuiID] = tuiChannelRouter;
            this->tuiRouter.addRoutingTableEntry(EPAddress(tuiID, -1), tuiChannelRouter);
            map<string, TUIObjectType>::const_iterator iter = tuiObjectTypeMap.find((*i).second.getTypeName());
            if (iter == tuiObjectTypeMap.end()) {
                iter = serverConfig.getTUIObjectTypeMap().find((*i).second.getTypeName());
                tuiObjectTypeMap[(*i).second.getName()] = (*iter).second;
                tuiObjectTypeVector.push_back((*iter).second);
            }

            map<string, int> nameChannelNrMap;
            int curChannelNr = 1;
            map<string, Port>::const_iterator i2 = (*iter).second.getPortMap().begin();
            map<string, Port>::const_iterator e2 = (*iter).second.getPortMap().end();
            while (i2 != e2) {
                //TFDEBUG((*i2).first << " has port number: " << curChannelNr);
                nameChannelNrMap[(*i2).first] = curChannelNr;
                ++curChannelNr;
                ++i2;
            }

            (*i).second.setID(tuiID);
            (*i).second.setNameChannelNrMap(nameChannelNrMap);
            tuiObjectInstanceVector.push_back((*i).second);
            //TFDEBUG((*i).second)

        ++tuiID;
        ++i;
        }
    }

    this->createEntityGraph(tuiObjectInstanceMap, serverConfig.getConnectorVector());

   // cout << "SIZE OF tuiObjectTypeMap: " << this->tuiObjectTypeMap.size();
    //cout << "SIZE OF tuiObjectTypeMap: " << this->tuiObjectTypeMap.size();
    //this->attachedObjects.setDeviceDescriptorVector(deviceContainer.getDeviceDescriptorVector());
    this->attachedObjects.setTUIObjectTypeVector(tuiObjectTypeVector);
    this->attachedObjects.setTUIObjectInstanceVector(tuiObjectInstanceVector);
    
    /*
    {
        vector<pair<string, int> > gv;
        map<string, int>::iterator i = guidEventTypeIDMap.begin();
        map<string, int>::iterator e = guidEventTypeIDMap.end();
        while (i != e) {
            gv.push_back(*i);
            ++i;
        }
        this->guidEventTypeIDVector.setGUIDEventTypeIDVector(gv);
    }
    */
    
    //TFDEBUG(this->attachedObjects)
}