void OscSendingDevice::sendEvent(const osgGA::Event &ea)
{
    bool msg_sent(false);
    unsigned int num_messages = _numMessagesPerEvent;
    
    const osgGA::GUIEventAdapter* ui_event(ea.asGUIEventAdapter());
    
    if(ui_event && ((ui_event->getEventType() == osgGA::GUIEventAdapter::DRAG) || (ui_event->getEventType() == osgGA::GUIEventAdapter::MOVE)))
        num_messages = 1;
    
    for(unsigned int i = 0; i < num_messages; ++i) {
        msg_sent = ui_event ? sendUIEventImpl(*ui_event, _msgId) : sendEventImpl(ea, _msgId);
        if ((_delayBetweenSendsInMilliSecs > 0) && (i < num_messages-1))
            OpenThreads::Thread::microSleep(1000 * _delayBetweenSendsInMilliSecs);
    }
    if (_finishMultiTouchSequence)
    {
        // if the last touch-point ended we'll need to send an empty tuio-bundle, so the receiver gets a chance to clean up
        
        _msgId++;
        for(unsigned int i = 0; i < num_messages; ++i) {
            beginBundle(_msgId);
            beginMultiTouchSequence();
            _oscStream << osc::EndBundle;
            _transmitSocket.Send( _oscStream.Data(), _oscStream.Size() );
            _oscStream.Clear();
        }
        _finishMultiTouchSequence = false;
    }

    if (msg_sent)
        _msgId++;
}
virtual void sendEvent(const osgGA::Event &event)
{
    if (event.getName() == "/zeroconf/advertise")
    {
        std::string  type;
        unsigned int port = 0;
        event.getUserValue("type", type);
        event.getUserValue("port", port);
        if (type.empty() || (port == 0))
        {
            OSG_WARN << "ZeroConfRegisterDevice :: could not advertise service, missing type/port " << std::endl;
        }
        else
        {
            advertise(type, port);
        }
    }
}
bool OscSendingDevice::sendEventImpl(const osgGA::Event &ea, MsgIdType msg_id)
{
    bool do_send(false);
    if (ea.getUserDataContainer())
    {
        std::string key = ea.getUserDataContainer()->getName();
        if (key.empty()) key = ea.getName();
        if (key.empty()) key = "user_data";
        
        sendUserDataContainer(transliterateKey(key), ea.getUserDataContainer(), true, msg_id);
        
        do_send = true;
    }
    
    if (do_send)
    {
        OSG_INFO << "OscDevice :: sending event per OSC " << std::endl;
        
        _transmitSocket.Send( _oscStream.Data(), _oscStream.Size() );
        _oscStream.Clear();
    }
    
    return do_send;
}
示例#4
0
void OscSendingDevice::sendEvent(const osgGA::Event &ea)
{
    bool msg_sent(false);
    unsigned int num_messages = _numMessagesPerEvent;
    
    const osgGA::GUIEventAdapter* ui_event(ea.asGUIEventAdapter());
    
    if(ui_event && ((ui_event->getEventType() == osgGA::GUIEventAdapter::DRAG) || (ui_event->getEventType() == osgGA::GUIEventAdapter::MOVE)))
        num_messages = 1;
    
    for(unsigned int i = 0; i < num_messages; ++i) {
        msg_sent = ui_event ? sendUIEventImpl(*ui_event, _msgId) : sendEventImpl(ea, _msgId);
        if ((_delayBetweenSendsInMilliSecs > 0) && (i < num_messages-1))
            OpenThreads::Thread::microSleep(1000 * _delayBetweenSendsInMilliSecs);
    }
    if (msg_sent)
        _msgId++;
}