From Stepan Huber, "attached are my changes for the osc, zeroconf and resthttp-plugin to use the new event-class. I refactored the osgoscdevice-example so that it’s working again. "
This commit is contained in:
@@ -27,8 +27,7 @@ public:
|
||||
{
|
||||
OSG_INFO << "RestHttpDevice :: handling request " << full_request_path << " as user-event" << std::endl;
|
||||
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> event = new osgGA::GUIEventAdapter();
|
||||
event->setEventType(osgGA::GUIEventAdapter::USER);
|
||||
osg::ref_ptr<osgGA::Event> event = new osgGA::Event();
|
||||
event->setName(full_request_path);
|
||||
event->setTime(getDevice()->getEventQueue()->getTime());
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
return !(getEventQueue()->empty());
|
||||
}
|
||||
|
||||
virtual void sendEvent(const osgGA::GUIEventAdapter& event)
|
||||
virtual void sendEvent(const osgGA::Event& event)
|
||||
{
|
||||
if (event.getName() == "/zeroconf/advertise")
|
||||
{
|
||||
@@ -96,11 +96,10 @@ public:
|
||||
virtual bool ignoreIP6Addresses() { return true; }
|
||||
virtual void serviceAdded(const std::string& host, unsigned int port)
|
||||
{
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> event = new osgGA::GUIEventAdapter();
|
||||
osg::ref_ptr<osgGA::Event> event = new osgGA::Event();
|
||||
|
||||
OSG_NOTICE << "ZeroConfDevice :: serviceAdded: " << host << ":" << port << " event " << event << std::endl;
|
||||
|
||||
event->setEventType(osgGA::GUIEventAdapter::USER);
|
||||
|
||||
event->setName("/zeroconf/service-added");
|
||||
event->setUserValue("host", host);
|
||||
@@ -112,12 +111,10 @@ public:
|
||||
|
||||
virtual void serviceRemoved(const std::string& host, unsigned int port)
|
||||
{
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> event = new osgGA::GUIEventAdapter();
|
||||
osg::ref_ptr<osgGA::Event> event = new osgGA::Event();
|
||||
|
||||
OSG_NOTICE << "ZeroConfDevice :: serviceRemoved: " << host << ":" << port << " event " << event << std::endl;
|
||||
|
||||
event->setEventType(osgGA::GUIEventAdapter::USER);
|
||||
|
||||
event->setName("/zeroconf/service-removed");
|
||||
event->setUserValue("host", host);
|
||||
event->setUserValue("port", port);
|
||||
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
|
||||
virtual void describeTo(std::ostream& out) const
|
||||
{
|
||||
out << getRequestPath() << ": add all transmitted arguments as ValueObjects to an USER-event";
|
||||
out << getRequestPath() << ": add all transmitted arguments as ValueObjects to an event";
|
||||
if (_treatFirstArgumentAsValueName)
|
||||
out << ", the first argument is used as the name of the value, if it's a string";
|
||||
}
|
||||
@@ -142,7 +142,7 @@ bool StandardRequestHandler::operator()(const std::string& request_path, const s
|
||||
std::string path = osgDB::getFilePath(full_request_path);
|
||||
std::string last_elem = osgDB::getSimpleFileName(full_request_path);
|
||||
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> ea = getDevice()->getOrCreateUserDataEvent();
|
||||
osg::ref_ptr<osgGA::Event> ea = getDevice()->getOrCreateUserDataEvent();
|
||||
osg::UserDataContainer* udc = ea->getOrCreateUserDataContainer();
|
||||
|
||||
|
||||
|
||||
@@ -87,12 +87,11 @@ public:
|
||||
return out;
|
||||
}
|
||||
|
||||
osgGA::GUIEventAdapter* getOrCreateUserDataEvent()
|
||||
osgGA::Event* getOrCreateUserDataEvent()
|
||||
{
|
||||
if (!_userDataEvent.valid())
|
||||
{
|
||||
_userDataEvent = new osgGA::GUIEventAdapter();
|
||||
_userDataEvent->setEventType(osgGA::GUIEventAdapter::USER);
|
||||
_userDataEvent = new osgGA::Event();
|
||||
}
|
||||
return _userDataEvent.get();
|
||||
}
|
||||
@@ -104,7 +103,7 @@ private:
|
||||
unsigned int _listeningPort;
|
||||
UdpListeningReceiveSocket* _socket;
|
||||
RequestHandlerMap _map;
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> _userDataEvent;
|
||||
osg::ref_ptr<osgGA::Event> _userDataEvent;
|
||||
MsgIdType _lastMsgId;
|
||||
osg::Timer_t _lastMsgTimeStamp;
|
||||
|
||||
|
||||
@@ -47,17 +47,19 @@ OscSendingDevice::~OscSendingDevice()
|
||||
delete[] (_buffer);
|
||||
}
|
||||
|
||||
void OscSendingDevice::sendEvent(const osgGA::GUIEventAdapter &ea)
|
||||
void OscSendingDevice::sendEvent(const osgGA::Event &ea)
|
||||
{
|
||||
static osc::int64 msg_id(0);
|
||||
bool msg_sent(false);
|
||||
unsigned int num_messages = _numMessagesPerEvent;
|
||||
|
||||
if((ea.getEventType() == osgGA::GUIEventAdapter::DRAG) || (ea.getEventType() == osgGA::GUIEventAdapter::MOVE))
|
||||
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 = sendEventImpl(ea, msg_id);
|
||||
msg_sent = ui_event ? sendUIEventImpl(*ui_event, msg_id) : sendEventImpl(ea, msg_id);
|
||||
if ((_delayBetweenSendsInMilliSecs > 0) && (i < num_messages-1))
|
||||
OpenThreads::Thread::microSleep(1000 * _delayBetweenSendsInMilliSecs);
|
||||
}
|
||||
@@ -66,7 +68,34 @@ void OscSendingDevice::sendEvent(const osgGA::GUIEventAdapter &ea)
|
||||
}
|
||||
|
||||
|
||||
bool OscSendingDevice::sendEventImpl(const osgGA::GUIEventAdapter &ea, MsgIdType msg_id)
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool OscSendingDevice::sendUIEventImpl(const osgGA::GUIEventAdapter &ea, MsgIdType msg_id)
|
||||
{
|
||||
bool do_send(false);
|
||||
switch(ea.getEventType())
|
||||
@@ -189,7 +218,7 @@ bool OscSendingDevice::sendEventImpl(const osgGA::GUIEventAdapter &ea, MsgIdType
|
||||
|
||||
if (do_send)
|
||||
{
|
||||
OSG_INFO << "OscDevice :: sending event per OSC " << std::endl;
|
||||
OSG_INFO << "OscDevice :: sending ui-event per OSC " << std::endl;
|
||||
|
||||
_transmitSocket.Send( _oscStream.Data(), _oscStream.Size() );
|
||||
_oscStream.Clear();
|
||||
|
||||
@@ -25,11 +25,12 @@ public:
|
||||
typedef osc::int64 MsgIdType;
|
||||
OscSendingDevice(const std::string& address, int port, unsigned int numMessagesPerEvent = 1, unsigned int delay_between_sends_in_millisecs = 0);
|
||||
~OscSendingDevice();
|
||||
virtual void sendEvent(const osgGA::GUIEventAdapter &ea);
|
||||
virtual void sendEvent(const osgGA::Event &ea);
|
||||
virtual const char* className() const { return "OSC sending device"; }
|
||||
|
||||
private:
|
||||
bool sendEventImpl(const osgGA::GUIEventAdapter &ea,MsgIdType msg_id);
|
||||
bool sendEventImpl(const osgGA::Event &ea,MsgIdType msg_id);
|
||||
bool sendUIEventImpl(const osgGA::GUIEventAdapter &ea,MsgIdType msg_id);
|
||||
void beginBundle(MsgIdType msg_id);
|
||||
void beginSendInputRange(const osgGA::GUIEventAdapter& ea, MsgIdType msg_id);
|
||||
int getButtonNum(const osgGA::GUIEventAdapter& ea);
|
||||
|
||||
Reference in New Issue
Block a user