summaryrefslogtreecommitdiffstats
path: root/src/event
diff options
context:
space:
mode:
Diffstat (limited to 'src/event')
-rw-r--r--src/event/EventFactory.cpp143
-rw-r--r--src/event/EventFactory.h87
-rw-r--r--src/event/EventPoller.cpp375
-rw-r--r--src/event/EventPoller.h103
-rw-r--r--src/event/EventPollingSystem.h87
-rw-r--r--src/event/EventSystem.h73
-rw-r--r--src/event/EventSystemC.cpp34
-rw-r--r--src/event/EventSystemC.h139
-rw-r--r--src/event/test/CanProviderDemo.cpp259
-rw-r--r--src/event/test/CanProviderDemo.h56
10 files changed, 1356 insertions, 0 deletions
diff --git a/src/event/EventFactory.cpp b/src/event/EventFactory.cpp
new file mode 100644
index 0000000..4bf776c
--- /dev/null
+++ b/src/event/EventFactory.cpp
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 NVIDIA Corporation.
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "EventFactory.h"
+#include "foundation/Qt3DSFoundation.h"
+#include "foundation/Qt3DSBroadcastingAllocator.h"
+#include "foundation/StringTable.h"
+#include "foundation/Utils.h"
+
+using namespace qt3ds::evt;
+
+typedef char TEventChar;
+using qt3ds::QT3DSU32;
+
+class CInitableRegisteredStr : public Qt3DSEventSystemRegisteredStr
+{
+public:
+ CInitableRegisteredStr(const TEventStr inString) { m_Data = inString; }
+};
+
+CFactory &CFactory::Create(qt3ds::NVFoundationBase &inFoundation)
+{
+ return *QT3DS_NEW(inFoundation.getAllocator(), CFactory)(inFoundation);
+}
+
+CFactory::CFactory(qt3ds::NVFoundationBase &inFoundation)
+ : m_Foundation(inFoundation)
+ , m_Allocator(inFoundation.getAllocator(), "event factory allocator")
+ , m_StringTable(qt3ds::foundation::IStringTable::CreateStringTable(inFoundation.getAllocator()))
+{
+}
+
+CFactory::~CFactory()
+{
+}
+
+Qt3DSEventSystemEvent &CFactory::CreateEvent(int inNumData)
+{
+ // Ensure num data is in range
+ inNumData = qt3ds::NVMax(0, inNumData);
+ // Ensure we can actually allocate something that big
+ QT3DSU32 dataSize = static_cast<QT3DSU32>(
+ qt3ds::NVMin((size_t)inNumData * sizeof(Qt3DSEventSystemEventData),
+ TEventAllocator::getSlabSize() - sizeof(Qt3DSEventSystemEvent)));
+ // get the actual num data after safety checks.
+ inNumData = (int)(dataSize / sizeof(Qt3DSEventSystemEventData));
+
+ QT3DSU32 allocSize = sizeof(Qt3DSEventSystemEvent) + inNumData * sizeof(Qt3DSEventSystemEventData);
+
+ Qt3DSEventSystemEvent *theEvent = (Qt3DSEventSystemEvent *)m_Allocator.allocate(
+ allocSize, "Event allocation", __FILE__, __LINE__);
+ theEvent->m_NumData = inNumData;
+ theEvent->m_Data = reinterpret_cast<Qt3DSEventSystemEventData *>(((qt3ds::QT3DSU8 *)theEvent)
+ + sizeof(Qt3DSEventSystemEvent));
+
+ // Initialize the event data to zero so that a free event won't cause a calamity.
+ qt3ds::intrinsics::memZero(theEvent->m_Data, dataSize);
+
+ return *theEvent;
+}
+
+size_t CFactory::GetMaxNumEventData()
+{
+ return m_Allocator.getSlabSize() - sizeof(Qt3DSEventSystemEvent);
+}
+
+size_t CFactory::GetMaxStrLength()
+{
+ return m_Allocator.getSlabSize();
+}
+
+void CFactory::ReleaseOutstandingEvents()
+{
+ m_Allocator.reset();
+}
+
+Qt3DSEventSystemRegisteredStr CFactory::RegisterStr(TEventStr inSrc)
+{
+ return CInitableRegisteredStr(m_StringTable->RegisterStr(inSrc));
+}
+
+TEventStr CFactory::AllocateStr(TEventStr inSrc)
+{
+ size_t theSizeInByte = sizeof(TEventChar) * (strlen(qt3ds::foundation::nonNull(inSrc)) + 1);
+ theSizeInByte = qt3ds::NVMin(theSizeInByte, TEventAllocator::getSlabSize());
+
+ TEventChar *theNewString = (TEventChar *)m_Allocator.allocate(
+ theSizeInByte, "Qt3DS::evt::CFactory::UnManagedString", __FILE__, __LINE__);
+
+ if (theNewString)
+ memcpy(theNewString, inSrc, theSizeInByte);
+
+ theNewString[theSizeInByte - 1] = 0;
+
+ return theNewString;
+}
+
+TEventStr CFactory::AllocateStr(int inLength)
+{
+ ++inLength;
+ int safeLen = (int)qt3ds::NVMin((size_t)inLength, TEventAllocator::getSlabSize());
+ // Either give the users what they ask for or return nothing.
+ if (safeLen != inLength)
+ return NULL;
+
+ void *retval = m_Allocator.allocate(inLength * sizeof(TEventChar),
+ "Qt3DS::evt::CFactory::UnManagedString", __FILE__, __LINE__);
+ qt3ds::intrinsics::memZero(retval, inLength);
+ return (TEventStr)retval;
+}
+
+void CFactory::Release()
+{
+ this->~CFactory();
+ QT3DS_FREE(m_Foundation.getAllocator(), this);
+}
diff --git a/src/event/EventFactory.h b/src/event/EventFactory.h
new file mode 100644
index 0000000..10fe6b7
--- /dev/null
+++ b/src/event/EventFactory.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 NVIDIA Corporation.
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef EVENT_FACTORY_H
+#define EVENT_FACTORY_H
+
+#include "EventSystem.h"
+#include "EventPollingSystem.h"
+
+#include "foundation/Qt3DSRefCounted.h"
+#include "foundation/FastAllocator.h"
+
+namespace qt3ds {
+class NVFoundationBase;
+namespace foundation {
+ class IStringTable;
+}
+}
+
+namespace qt3ds {
+namespace evt {
+
+ class CEventProviderRefCounted;
+
+ class CFactory : public IEventFactory
+ {
+ private:
+ explicit CFactory(qt3ds::NVFoundationBase &inFoundation);
+ virtual ~CFactory();
+
+ CFactory &operator=(const CFactory &) { return *this; }
+ public:
+ // Interfaces from IEventFactory
+ Qt3DSEventSystemEvent &CreateEvent(int inNumData) override;
+ size_t GetMaxNumEventData() override;
+ size_t GetMaxStrLength() override;
+
+ Qt3DSEventSystemRegisteredStr RegisterStr(TEventStr inSrc) override;
+ // Null terminates if strlen(inSrc) > getMaxStrLength
+ TEventStr AllocateStr(TEventStr inSrc) override;
+
+ // Returns null if inLength > getMaxStrLength
+ TEventStr AllocateStr(int inLength) override;
+
+ void ReleaseOutstandingEvents();
+ void Release();
+
+ static CFactory &Create(qt3ds::NVFoundationBase &inFoundation);
+
+ private:
+ typedef qt3ds::foundation::SFastAllocator<> TEventAllocator;
+
+ qt3ds::NVFoundationBase &m_Foundation;
+ TEventAllocator m_Allocator;
+ qt3ds::foundation::NVScopedRefCounted<qt3ds::foundation::IStringTable> m_StringTable;
+ };
+}
+}
+
+#endif // EVENT_FACTORY_H
diff --git a/src/event/EventPoller.cpp b/src/event/EventPoller.cpp
new file mode 100644
index 0000000..a811595
--- /dev/null
+++ b/src/event/EventPoller.cpp
@@ -0,0 +1,375 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 NVIDIA Corporation.
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <EASTL/algorithm.h>
+
+#include "foundation/Qt3DSAtomic.h"
+#include "foundation/Qt3DSFoundation.h"
+#include "foundation/Qt3DSBroadcastingAllocator.h"
+#include "foundation/Qt3DSAllocator.h"
+
+#include "EventPoller.h"
+#include "EventFactory.h"
+
+#define MAX_EVENTS 256
+
+using namespace qt3ds::evt;
+using qt3ds::QT3DSU32;
+
+IEventSystem &IEventSystem::Create(qt3ds::NVFoundationBase &inFoundation)
+{
+ return CPoller::Create(inFoundation);
+}
+
+CPoller &CPoller::Create(qt3ds::NVFoundationBase &inFoundation)
+{
+ return *QT3DS_NEW(inFoundation.getAllocator(), CPoller)(inFoundation);
+}
+
+CPoller::~CPoller()
+{
+ for (QT3DSU32 idx = 0, end = m_Providers.size(); idx < end; ++idx)
+ m_Providers[idx].first->Release();
+ m_Providers.clear();
+ ReleaseEvents();
+ m_EventFactory.Release();
+}
+
+void CPoller::ReleaseEvents()
+{
+ m_EventFactory.ReleaseOutstandingEvents();
+
+ m_EventList.clear();
+ m_EventIndex = 0;
+}
+
+static void AddProviderFn(void *inPoller, Qt3DSEventSystemEventProvider inProvider)
+{
+ CPoller *thePoller = reinterpret_cast<CPoller *>(inPoller);
+ thePoller->AddProvider(*thePoller->GetOrCreateEventProviderWrapper(inProvider));
+}
+
+static void RemoveProviderFn(void *inPoller, Qt3DSEventSystemEventProvider inProvider)
+{
+ CPoller *thePoller = reinterpret_cast<CPoller *>(inPoller);
+ CPoller::TProvider theProvider = thePoller->GetEventProviderWrapper(inProvider);
+ if (theProvider)
+ thePoller->RemoveProvider(*theProvider);
+ thePoller->ReleaseEventProviderWrapper(inProvider);
+}
+
+static int IgnoreProviderFn(void *inPoller, Qt3DSEventSystemEventProvider inProvider)
+{
+ CPoller *thePoller = reinterpret_cast<CPoller *>(inPoller);
+ CPoller::TProvider theProvider = thePoller->GetEventProviderWrapper(inProvider);
+ if (theProvider)
+ return thePoller->IgnoreProvider(*theProvider);
+ return 0;
+}
+
+static int ActivateProviderFn(void *inPoller, Qt3DSEventSystemEventProvider inProvider)
+{
+ CPoller *thePoller = reinterpret_cast<CPoller *>(inPoller);
+ CPoller::TProvider theProvider = thePoller->GetEventProviderWrapper(inProvider);
+ if (theProvider)
+ return thePoller->ActivateProvider(*theProvider);
+ return 0;
+}
+
+CPoller::CPoller(qt3ds::NVFoundationBase &inFoundation)
+ : mRefCount(0)
+ , m_Foundation(inFoundation)
+ , m_EventFactory(CFactory::Create(inFoundation))
+ , m_Providers(inFoundation.getAllocator(), "CPoller::m_Providers")
+ , m_EventList(inFoundation.getAllocator(), "CPoller::m_EventList")
+ , m_EventIndex(0)
+ , m_EventFetched(false)
+{
+ m_CInterface.m_Poller = this;
+ m_CInterface.addProvider = AddProviderFn;
+ m_CInterface.removeProvider = RemoveProviderFn;
+ m_CInterface.ignoreProvider = IgnoreProviderFn;
+ m_CInterface.activateProvider = ActivateProviderFn;
+}
+
+struct SProviderSearch
+{
+ IEventProvider *m_Provider;
+ SProviderSearch(IEventProvider &inProvider)
+ : m_Provider(&inProvider)
+ {
+ }
+ bool operator()(const eastl::pair<CPoller::TProvider, bool> &item)
+ {
+ return item.first == m_Provider;
+ }
+};
+
+void CPoller::AddProvider(IEventProvider &inProvider)
+{
+ TProviderList::iterator iter =
+ eastl::find_if(m_Providers.begin(), m_Providers.end(), SProviderSearch(inProvider));
+ if (iter == m_Providers.end())
+ m_Providers.push_back(eastl::make_pair(&inProvider, true));
+}
+
+void CPoller::RemoveProvider(IEventProvider &inProvider)
+{
+ TProviderList::iterator thePos =
+ eastl::find_if(m_Providers.begin(), m_Providers.end(), SProviderSearch(inProvider));
+ if (thePos != m_Providers.end())
+ m_Providers.erase(thePos);
+}
+
+bool CPoller::IgnoreProvider(IEventProvider &inProvider)
+{
+ TProviderList::iterator thePos =
+ eastl::find_if(m_Providers.begin(), m_Providers.end(), SProviderSearch(inProvider));
+ if (thePos != m_Providers.end()) {
+ thePos->second = false;
+ return true;
+ }
+ return false;
+}
+
+bool CPoller::ActivateProvider(IEventProvider &inProvider)
+{
+ TProviderList::iterator thePos =
+ eastl::find_if(m_Providers.begin(), m_Providers.end(), SProviderSearch(inProvider));
+ if (thePos != m_Providers.end()) {
+ thePos->second = true;
+ return true;
+ }
+ return false;
+}
+
+Qt3DSEventSystemEvent *CPoller::GetNextEvent(bool inAllowResetBuffer)
+{
+ if (m_EventIndex < m_EventList.size()) {
+ Qt3DSEventSystemEvent *retval = m_EventList[m_EventIndex];
+ ++m_EventIndex;
+ return retval;
+ }
+ if (inAllowResetBuffer) {
+ ReleaseEvents();
+ }
+ size_t theNewEventCount = 0;
+ for (QT3DSU32 idx = 0, end = m_Providers.size(); idx < end; ++idx) {
+ if (m_Providers[idx].second) {
+ Qt3DSEventSystemEvent *evtBuffer[MAX_EVENTS];
+ for (QT3DSU32 numEvents = (QT3DSU32)(m_Providers[idx].first)
+ ->GetNextEvents(m_EventFactory, evtBuffer, MAX_EVENTS);
+ numEvents;
+ numEvents = (QT3DSU32)(m_Providers[idx].first)
+ ->GetNextEvents(m_EventFactory, evtBuffer, MAX_EVENTS)) {
+ m_EventList.insert(m_EventList.end(), evtBuffer, evtBuffer + numEvents);
+ ++theNewEventCount;
+ }
+ }
+ }
+ if (theNewEventCount)
+ return GetNextEvent(inAllowResetBuffer);
+
+ return NULL;
+}
+
+size_t CPoller::GetNextEvents(Qt3DSEventSystemEvent **outBuffer, size_t bufLen)
+{
+ m_EventFetched = true;
+ size_t bufIdx = 0;
+ bool theAllowResetBuffer = true;
+ for (; bufIdx < bufLen; ++bufIdx) {
+ Qt3DSEventSystemEvent *evt = GetNextEvent(theAllowResetBuffer);
+ if (!evt)
+ break;
+ theAllowResetBuffer = false;
+ outBuffer[bufIdx] = evt;
+ }
+ return bufIdx;
+}
+
+IEventFactory &CPoller::GetEventFactory()
+{
+ return m_EventFactory;
+}
+
+Qt3DSEventSystemEventPoller *CPoller::GetCInterface()
+{
+ return &m_CInterface;
+}
+
+bool CPoller::GetAndClearEventFetchedFlag()
+{
+ bool theOld = m_EventFetched;
+ m_EventFetched = false;
+ return theOld;
+}
+
+void CPoller::PurgeEvents()
+{
+ // Get events from providers and drop,
+ // so the providers need not to provide an additional interface for clear events
+ static const size_t EVENTS_NUM_ONCE_CLEAR = 512;
+ Qt3DSEventSystemEvent *theEvents[EVENTS_NUM_ONCE_CLEAR];
+ GetNextEvents(theEvents, EVENTS_NUM_ONCE_CLEAR);
+ ReleaseEvents();
+}
+
+void CPoller::addRef()
+{
+ qt3ds::foundation::atomicIncrement(&mRefCount);
+}
+
+void CPoller::release()
+{
+ qt3ds::QT3DSI32 value = qt3ds::foundation::atomicDecrement(&mRefCount);
+ if (value <= 0) {
+ qt3ds::NVAllocatorCallback &alloc(m_Foundation.getAllocator());
+ this->~CPoller();
+ QT3DS_FREE(alloc, this);
+ }
+}
+
+struct SProviderFinder
+{
+ void *m_Key;
+ SProviderFinder(void *k)
+ : m_Key(k)
+ {
+ }
+ bool operator()(const CPoller::TCEventProviderPair &inPair)
+ {
+ if (inPair.first == m_Key)
+ return true;
+ return false;
+ }
+};
+
+static Qt3DSEventSystemEvent *CreateEventFn(void *inFactory, int numData)
+{
+ IEventFactory *theFactory = reinterpret_cast<IEventFactory *>(inFactory);
+ return &theFactory->CreateEvent(numData);
+}
+
+static size_t MaxNumEventDataFn(void *inFactory)
+{
+ IEventFactory *theFactory = reinterpret_cast<IEventFactory *>(inFactory);
+ return theFactory->GetMaxNumEventData();
+}
+
+static size_t MaxStrLenFn(void *inFactory)
+{
+ IEventFactory *theFactory = reinterpret_cast<IEventFactory *>(inFactory);
+ return theFactory->GetMaxStrLength();
+}
+
+static Qt3DSEventSystemRegisteredStr RegisterStrFn(void *inFactory, Qt3DSEventSystemStr inStr)
+{
+ IEventFactory *theFactory = reinterpret_cast<IEventFactory *>(inFactory);
+ return theFactory->RegisterStr(inStr);
+}
+
+static Qt3DSEventSystemStr AllocateStrFn(void *inFactory, Qt3DSEventSystemStr inStr)
+{
+ IEventFactory *theFactory = reinterpret_cast<IEventFactory *>(inFactory);
+ return theFactory->AllocateStr(inStr);
+}
+
+static Qt3DSEventSystemStr AllocateStrLenFn(void *inFactory, int len)
+{
+ IEventFactory *theFactory = reinterpret_cast<IEventFactory *>(inFactory);
+ return theFactory->AllocateStr(len);
+}
+
+struct SWrappedProvider : public IEventProvider
+{
+ Qt3DSEventSystemEventProvider m_Provider;
+ SWrappedProvider(Qt3DSEventSystemEventProvider prov)
+ : m_Provider(prov)
+ {
+ }
+
+ size_t GetNextEvents(IEventFactory &inFactory, Qt3DSEventSystemEvent **outBuffer,
+ size_t bufLen) override
+ {
+ if (m_Provider.m_Provider) {
+ Qt3DSEventSystemEventFactory theFactory;
+ theFactory.m_Factory = &inFactory;
+ theFactory.createEvent = CreateEventFn;
+ theFactory.getMaxNumEventData = MaxNumEventDataFn;
+ theFactory.getMaxStrLength = MaxStrLenFn;
+ theFactory.registerStr = RegisterStrFn;
+ theFactory.allocateStr = AllocateStrFn;
+ theFactory.allocateStrLen = AllocateStrLenFn;
+ return m_Provider.getNextEvents(m_Provider.m_Provider, theFactory, outBuffer, bufLen);
+ }
+ return 0;
+ }
+
+ void Release() override
+ {
+ if (m_Provider.m_Provider)
+ m_Provider.release(m_Provider.m_Provider);
+ delete this;
+ }
+};
+
+CPoller::TProvider CPoller::GetEventProviderWrapper(Qt3DSEventSystemEventProvider inProvider)
+{
+ TCEventProviderList::iterator iter = eastl::find_if(
+ m_CEventProviders.begin(), m_CEventProviders.end(), SProviderFinder(inProvider.m_Provider));
+ if (iter != m_CEventProviders.end())
+ return iter->second;
+ return TProvider();
+}
+
+CPoller::TProvider CPoller::GetOrCreateEventProviderWrapper(Qt3DSEventSystemEventProvider inProvider)
+{
+ TCEventProviderList::iterator iter = eastl::find_if(
+ m_CEventProviders.begin(), m_CEventProviders.end(), SProviderFinder(inProvider.m_Provider));
+ if (iter == m_CEventProviders.end()) {
+ TProvider retval = new SWrappedProvider(inProvider);
+ m_CEventProviders.push_back(eastl::make_pair(inProvider.m_Provider, retval));
+ return retval;
+ }
+ return iter->second;
+}
+
+void CPoller::ReleaseEventProviderWrapper(Qt3DSEventSystemEventProvider inProvider)
+{
+ TCEventProviderList::iterator iter = eastl::find_if(
+ m_CEventProviders.begin(), m_CEventProviders.end(), SProviderFinder(inProvider.m_Provider));
+ if (iter != m_CEventProviders.end()) {
+ SWrappedProvider &wrappedProvider = static_cast<SWrappedProvider &>(*iter->second);
+ wrappedProvider.m_Provider.m_Provider = NULL;
+ m_CEventProviders.erase(
+ iter); // deletes the wrapper but does not release the wrapped provider.
+ }
+}
diff --git a/src/event/EventPoller.h b/src/event/EventPoller.h
new file mode 100644
index 0000000..99ac27d
--- /dev/null
+++ b/src/event/EventPoller.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 NVIDIA Corporation.
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef EVENT_POLLER_H
+#define EVENT_POLLER_H
+
+#include <EASTL/vector.h>
+
+#include "foundation/Qt3DSRefCounted.h"
+#include "foundation/Qt3DSContainers.h"
+
+#include "EventSystem.h"
+#include "EventPollingSystem.h"
+
+namespace qt3ds {
+class NVFoundationBase;
+}
+
+namespace qt3ds {
+namespace evt {
+
+ class CFactory;
+
+ class CPoller : public IEventSystem
+ {
+ public:
+ typedef IEventProvider *TProvider;
+ typedef qt3ds::foundation::nvvector<eastl::pair<TProvider, bool>> TProviderList;
+ typedef qt3ds::foundation::nvvector<Qt3DSEventSystemEvent *> TEventList;
+ typedef eastl::pair<void *, TProvider> TCEventProviderPair;
+ typedef eastl::vector<TCEventProviderPair> TCEventProviderList;
+
+ private:
+ explicit CPoller(qt3ds::NVFoundationBase &inFoundation);
+ virtual ~CPoller();
+
+ public:
+ // Providers once added are released if the poller goes out of scope.
+ void AddProvider(IEventProvider &inProvider) override;
+ void RemoveProvider(IEventProvider &inProvider) override;
+ bool IgnoreProvider(IEventProvider &inProvider) override;
+ bool ActivateProvider(IEventProvider &inProvider) override;
+ size_t GetNextEvents(Qt3DSEventSystemEvent **outBuffer, size_t bufLen) override;
+ IEventFactory &GetEventFactory() override;
+ Qt3DSEventSystemEventPoller *GetCInterface() override;
+ bool GetAndClearEventFetchedFlag() override;
+ void PurgeEvents() override;
+
+ void ReleaseEvents();
+
+ void addRef() override;
+ void release() override;
+
+ TProvider GetEventProviderWrapper(Qt3DSEventSystemEventProvider inProvider);
+ TProvider GetOrCreateEventProviderWrapper(Qt3DSEventSystemEventProvider inProvider);
+ void ReleaseEventProviderWrapper(Qt3DSEventSystemEventProvider inProvider);
+
+ static CPoller &Create(qt3ds::NVFoundationBase &inFoundation);
+
+ private:
+ Qt3DSEventSystemEvent *GetNextEvent(bool inAllowResetBuffer /* = true*/);
+
+ qt3ds::QT3DSI32 mRefCount;
+ qt3ds::NVFoundationBase &m_Foundation;
+ CFactory &m_EventFactory;
+ TProviderList m_Providers;
+ TEventList m_EventList;
+ qt3ds::QT3DSU32 m_EventIndex;
+ Qt3DSEventSystemEventPoller m_CInterface;
+ TCEventProviderList m_CEventProviders;
+ bool m_EventFetched;
+ };
+}
+}
+
+#endif // EVENT_POLLER_H
diff --git a/src/event/EventPollingSystem.h b/src/event/EventPollingSystem.h
new file mode 100644
index 0000000..4d41406
--- /dev/null
+++ b/src/event/EventPollingSystem.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 NVIDIA Corporation.
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef EVENT_SYSTEM_H
+#define EVENT_SYSTEM_H
+
+#include "foundation/Qt3DSFoundation.h"
+#include "foundation/Qt3DSRefCounted.h"
+#include "EventSystem.h"
+
+namespace qt3ds {
+namespace evt {
+
+ class CEventProviderRefCounted;
+
+ class IEventSystem : public qt3ds::foundation::NVRefCounted
+ {
+ protected:
+ virtual ~IEventSystem() {}
+ public:
+ // Providers once added are released if the poller goes out of scope.
+ // Adding the same provider twice has no effect.
+ virtual void AddProvider(IEventProvider &inProvider) = 0;
+
+ // removeProvider does not release the provider; callers are expected to release the
+ // provider themselves after calling remove provider. Calling remove provider
+ // with a provider that isn't in the system has no effect.
+ virtual void RemoveProvider(IEventProvider &inProvider) = 0;
+
+ // Ignore events from this provider. Returns true if provider is added.
+ virtual bool IgnoreProvider(IEventProvider &inProvider) = 0;
+
+ // Listen on this provider. Returns true if provider is added.
+ virtual bool ActivateProvider(IEventProvider &inProvider) = 0;
+
+ // Get a set of events from the poller. The poller will simply run through and ask each
+ // provider
+ // for events and then begin returning the set of events.
+ // Note: this interface needs to set the event fetched flag.
+ virtual size_t GetNextEvents(Qt3DSEventSystemEvent **outBuffer, size_t bufLen) = 0;
+
+ // Get the event factory used for this poller.
+ virtual IEventFactory &GetEventFactory() = 0;
+
+ virtual Qt3DSEventSystemEventPoller *GetCInterface() = 0;
+
+ // Get and clear the flag indicates whether GetNextEvents has been called after last call of
+ // this interface
+ // Note: the event fetched flag is set by GetNextEvents
+ virtual bool GetAndClearEventFetchedFlag() = 0;
+
+ // Clear events in event system and events in all providers
+ virtual void PurgeEvents() = 0;
+
+ static IEventSystem &Create(qt3ds::NVFoundationBase &inFoundation);
+ };
+}
+}
+
+#endif // EVENT_SYSTEM_H
diff --git a/src/event/EventSystem.h b/src/event/EventSystem.h
new file mode 100644
index 0000000..a9e3dbc
--- /dev/null
+++ b/src/event/EventSystem.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 NVIDIA Corporation.
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MESSAGE_SYSTEM_H
+#define MESSAGE_SYSTEM_H
+#include <cstdlib>
+#include "EventSystemC.h"
+
+namespace qt3ds {
+namespace evt {
+
+ typedef Qt3DSEventSystemStr TEventStr;
+
+ // Factory from the provider's perspective.
+ class IEventFactory
+ {
+ protected:
+ virtual ~IEventFactory() {}
+ public:
+ virtual Qt3DSEventSystemEvent &CreateEvent(int numData) = 0;
+ // Guaranteed to be at least 4K - sizeof(Qt3DSEventSystemEvent)
+ virtual size_t GetMaxNumEventData() = 0;
+ // Guaranteed to be at least 4K
+ virtual size_t GetMaxStrLength() = 0;
+
+ virtual Qt3DSEventSystemRegisteredStr RegisterStr(TEventStr inSrc) = 0;
+ // Null terminates if strlen(inSrc) > getMaxStrLength
+ virtual TEventStr AllocateStr(TEventStr inSrc) = 0;
+ // Returns null if inLength > getMaxStrLength
+ virtual TEventStr AllocateStr(int inLength) = 0;
+ };
+
+ class IEventProvider
+ {
+ protected:
+ virtual ~IEventProvider() {}
+ public:
+ // Return the next N events, placed into the event buffer.
+ virtual size_t GetNextEvents(IEventFactory &inFactory, Qt3DSEventSystemEvent **outBuffer,
+ size_t bufLen) = 0;
+ virtual void Release() = 0;
+ };
+}
+}
+
+#endif
diff --git a/src/event/EventSystemC.cpp b/src/event/EventSystemC.cpp
new file mode 100644
index 0000000..8bfdb81
--- /dev/null
+++ b/src/event/EventSystemC.cpp
@@ -0,0 +1,34 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 NVIDIA Corporation.
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "EventSystemC.h"
+
+const char *PROVIDER_TABLE_ENTRY = "__provider_impl";
+const char *POLLER_TABLE_ENTRY = "__poller_impl"; \ No newline at end of file
diff --git a/src/event/EventSystemC.h b/src/event/EventSystemC.h
new file mode 100644
index 0000000..2517eae
--- /dev/null
+++ b/src/event/EventSystemC.h
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 NVIDIA Corporation.
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QT3DS_EVENT_SYSTEM_C_H
+#define QT3DS_EVENT_SYSTEM_C_H
+#include <stddef.h> //size_t
+
+// Interface we expect plugins to use in order to interace with the event system.
+// This interface is design to avoid using c++ vtables and the C++ abi isn't stable
+// across compilers.
+
+#ifdef _cplusplus
+extern "C" {
+#endif
+
+// Obnoxious long names to void namespace conflicts
+enum QT3DSEventSystemEventTypes {
+ QT3DSEventSystemEventTypesNoData = 0,
+ QT3DSEventSystemEventTypesString = 1,
+ QT3DSEventSystemEventTypesNumber = 2,
+};
+
+typedef const char *Qt3DSEventSystemStr;
+
+typedef struct _Qt3DSEventSystemEventValue
+{
+ QT3DSEventSystemEventTypes m_Type;
+ double m_Number;
+ Qt3DSEventSystemStr m_String;
+} Qt3DSEventSystemEventValue;
+
+typedef struct _Qt3DSEventSystemRegisteredStr
+{
+ Qt3DSEventSystemStr m_Data;
+} Qt3DSEventSystemRegisteredStr;
+
+typedef struct _Qt3DSEventSystemEventData
+{
+ Qt3DSEventSystemRegisteredStr m_Name;
+ Qt3DSEventSystemEventValue m_Value;
+} Qt3DSEventSystemEventData;
+
+typedef struct _Qt3DSEventSystemEvent
+{
+ Qt3DSEventSystemEventData *m_Data; // contiguous block of event data.
+ int m_NumData;
+} Qt3DSEventSystemEvent;
+
+typedef Qt3DSEventSystemEvent *(*Qt3DSEventSystemEventFactoryCreateEventFn)(void *inFactory,
+ int numData);
+typedef size_t (*Qt3DSEventSystemEventFactoryMaxNumEventDataFn)(void *inFactory);
+typedef size_t (*Qt3DSEventSystemEventFactoryMaxStrLenFn)(void *inFactory);
+typedef Qt3DSEventSystemRegisteredStr (*Qt3DSEventSystemEventFactoryRegisterStrFn)(
+ void *inFactory, Qt3DSEventSystemStr inStr);
+typedef Qt3DSEventSystemStr (*Qt3DSEventSystemEventFactoryAllocateStrFn)(void *inFactory,
+ Qt3DSEventSystemStr inStr);
+typedef Qt3DSEventSystemStr (*Qt3DSEventSystemEventFactoryAllocateStrLenFn)(void *inFactory, int len);
+
+// Factory from the provider's perspective.
+typedef struct _Qt3DSEventSystemEventFactory
+{
+ void *m_Factory;
+ Qt3DSEventSystemEventFactoryCreateEventFn createEvent;
+ Qt3DSEventSystemEventFactoryMaxNumEventDataFn getMaxNumEventData;
+ Qt3DSEventSystemEventFactoryMaxStrLenFn getMaxStrLength;
+ Qt3DSEventSystemEventFactoryRegisterStrFn registerStr;
+ Qt3DSEventSystemEventFactoryAllocateStrFn allocateStr;
+ Qt3DSEventSystemEventFactoryAllocateStrLenFn allocateStrLen;
+
+} Qt3DSEventSystemEventFactory;
+
+typedef size_t (*Qt3DSEventSystemProviderGetNextEventsFn)(void *inProvider,
+ Qt3DSEventSystemEventFactory inFactory,
+ Qt3DSEventSystemEvent **outBuffer,
+ size_t outBufLen);
+typedef void (*Qt3DSEventSystemProviderReleaseFn)(void *inProvider);
+
+typedef struct _Qt3DSEventSystemEventProvider
+{
+ void *m_Provider;
+ Qt3DSEventSystemProviderGetNextEventsFn getNextEvents;
+ Qt3DSEventSystemProviderReleaseFn release;
+} Qt3DSEventSystemEventProvider;
+
+typedef void (*Qt3DSEventSystemPollerAddProviderFn)(void *inPoller,
+ Qt3DSEventSystemEventProvider inProvider);
+typedef void (*Qt3DSEventSystemPollerRemoveProviderFn)(void *inPoller,
+ Qt3DSEventSystemEventProvider inProvider);
+typedef int (*Qt3DSEventSystemPollerignoreProviderFn)(void *inPoller,
+ Qt3DSEventSystemEventProvider inProvider);
+typedef int (*Qt3DSEventSystemPolleractivateProviderFn)(void *inPoller,
+ Qt3DSEventSystemEventProvider inProvider);
+
+typedef struct _Qt3DSEventSystemEventPoller
+{
+ void *m_Poller;
+ // Providers, once added, will be released by the event poller unless removed
+ Qt3DSEventSystemPollerAddProviderFn addProvider;
+ // Callers are responsible for releasing removed providers.
+ Qt3DSEventSystemPollerRemoveProviderFn removeProvider;
+ Qt3DSEventSystemPollerignoreProviderFn ignoreProvider;
+ Qt3DSEventSystemPolleractivateProviderFn activateProvider;
+
+} Qt3DSEventSystemEventPoller;
+
+extern const char *PROVIDER_TABLE_ENTRY;
+extern const char *POLLER_TABLE_ENTRY;
+
+#ifdef _cplusplus
+}
+#endif
+
+#endif \ No newline at end of file
diff --git a/src/event/test/CanProviderDemo.cpp b/src/event/test/CanProviderDemo.cpp
new file mode 100644
index 0000000..dc51e9d
--- /dev/null
+++ b/src/event/test/CanProviderDemo.cpp
@@ -0,0 +1,259 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 NVIDIA Corporation.
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <time.h>
+#include <math.h>
+
+#include "CanProviderDemo.h"
+
+CCanProviderDemo::CCanProviderDemo()
+ : m_Frame(0)
+ , m_LastClock(0)
+{
+}
+
+CCanProviderDemo::~CCanProviderDemo()
+{
+}
+
+unsigned short g_VehicleSpeedData[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 6, 8, 10, 12, 14, 16,
+ 18, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136,
+ 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 256, 264,
+ 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384, 392,
+ 400, 408, 416, 424, 432, 440, 448, 456, 462, 468, 474, 480, 486, 492, 498, 504,
+ 510, 516, 522, 528, 534, 540, 546, 552, 558, 564, 570, 576, 582, 588, 594, 600,
+ 606, 612, 618, 624, 630, 636, 642, 648, 654, 660, 666, 672, 678, 684, 690, 696,
+ 702, 708, 714, 720, 726, 732, 738, 744, 750, 756, 762, 768, 774, 780, 786, 792,
+ 798, 804, 810, 816, 820, 824, 828, 832, 836, 840, 844, 848, 852, 856, 860, 864,
+ 868, 872, 876, 880, 884, 888, 892, 896, 900, 904, 908, 912, 916, 920, 924, 928,
+ 932, 936, 940, 944, 948, 952, 956, 960, 964, 968, 972, 976, 980, 984, 988, 992,
+ 996, 1000, 1004, 1008, 1012, 1016, 1020, 1024, 1028, 1032, 1036, 1040, 1044, 1048, 1052, 1056,
+ 1054, 1052, 1050, 1048, 1046, 1044, 1042, 1040, 1038, 1036, 1034, 1032, 1030, 1028, 1026, 1024,
+ 1022, 1020, 1018, 1016, 1014, 1012, 1010, 1008, 1006, 1004, 1002, 1000, 998, 996, 994, 992,
+ 990, 988, 986, 984, 982, 980, 978, 976, 974, 972, 970, 968, 966, 964, 962, 960,
+ 958, 956, 954, 952, 950, 948, 946, 944, 942, 940, 938, 936, 934, 932, 930, 928,
+ 926, 924, 922, 920, 918, 916, 914, 912, 910, 908, 906, 904, 902, 900, 898, 896,
+ 894, 892, 890, 888, 886, 884, 882, 880, 878, 876, 874, 872, 870, 868, 866, 864,
+ 862, 860, 858, 856, 854, 852, 850, 848, 846, 844, 842, 840, 838, 836, 834, 832,
+ 830, 828, 826, 824, 822, 820, 818, 816, 823, 830, 837, 844, 851, 858, 865, 872,
+ 879, 886, 893, 900, 907, 914, 921, 928, 935, 942, 949, 956, 963, 970, 977, 984,
+ 991, 998, 1005, 1012, 1019, 1026, 1033, 1040, 1047, 1054, 1061, 1068, 1075, 1082, 1089, 1096,
+ 1103, 1110, 1117, 1124, 1131, 1138, 1145, 1152, 1159, 1166, 1173, 1180, 1187, 1194, 1201, 1208,
+ 1215, 1222, 1229, 1236, 1246, 1256, 1266, 1276, 1286, 1296, 1306, 1316, 1326, 1336, 1346, 1356,
+ 1366, 1376, 1386, 1396, 1406, 1416, 1426, 1436, 1446, 1456, 1466, 1476, 1486, 1496, 1506, 1516,
+ 1526, 1536, 1546, 1556, 1566, 1576, 1586, 1596, 1606, 1616, 1626, 1636, 1646, 1656, 1666, 1676,
+ 1686, 1696, 1706, 1716, 1726, 1736, 1746, 1756, 1766, 1776, 1786, 1796, 1806, 1816, 1826, 1836,
+ 1836, 1836, 1836, 1834, 1832, 1830, 1828, 1826, 1824, 1822, 1820, 1818, 1816, 1814, 1812, 1810,
+ 1808, 1806, 1804, 1802, 1800, 1798, 1796, 1794, 1792, 1790, 1788, 1786, 1784, 1782, 1780, 1778,
+ 1776, 1774, 1772, 1770, 1768, 1766, 1764, 1762, 1760, 1758, 1756, 1754, 1752, 1750, 1748, 1746,
+ 1744, 1742, 1740, 1738, 1736, 1734, 1732, 1730, 1728, 1726, 1724, 1722, 1723, 1724, 1725, 1726,
+ 1728, 1730, 1732, 1734, 1736, 1738, 1740, 1742, 1744, 1746, 1748, 1750, 1753, 1756, 1759, 1762,
+ 1765, 1768, 1771, 1774, 1777, 1780, 1783, 1786, 1789, 1792, 1795, 1798, 1801, 1804, 1807, 1810,
+ 1813, 1816, 1819, 1822, 1825, 1828, 1831, 1834, 1837, 1840, 1843, 1846, 1849, 1852, 1855, 1858,
+ 1861, 1864, 1867, 1870, 1873, 1876, 1879, 1882, 1885, 1888, 1891, 1894, 1897, 1900, 1903, 1906,
+ 1909, 1912, 1915, 1918, 1921, 1924, 1927, 1930, 1933, 1936, 1939, 1942, 1945, 1948, 1951, 1954,
+ 1957, 1960, 1963, 1966, 1969, 1972, 1975, 1978, 1981, 1984, 1987, 1990, 1993, 1996, 1999, 2002,
+ 2005, 2008, 2011, 2014, 2017, 2020, 2023, 2026, 2029, 2032, 2035, 2038, 2041, 2044, 2047, 2050,
+ 2053, 2056, 2059, 2062, 2064, 2066, 2068, 2070, 2072, 2074, 2076, 2078, 2080, 2082, 2084, 2086,
+ 2088, 2090, 2092, 2094, 2096, 2098, 2100, 2102, 2104, 2106, 2108, 2110, 2112, 2114, 2116, 2118,
+ 2120, 2122, 2124, 2126, 2128, 2130, 2132, 2134, 2136, 2138, 2140, 2142, 2144, 2146, 2148, 2150,
+ 2152, 2154, 2156, 2158, 2160, 2162, 2164, 2166, 2168, 2170, 2172, 2174, 2176, 2178, 2180, 2182,
+ 2184, 2186, 2188, 2190, 2192, 2194, 2196, 2198, 2200, 2202, 2204, 2206, 2208, 2210, 2212, 2214,
+ 2216, 2218, 2220, 2222, 2224, 2226, 2228, 2230, 2232, 2234, 2236, 2238, 2240, 2242, 2244, 2246,
+ 2248, 2250, 2252, 2254, 2256, 2258, 2260, 2262, 2264, 2266, 2268, 2270, 2272, 2274, 2276, 2278,
+ 2280, 2282, 2284, 2286, 2288, 2290, 2292, 2294, 2296, 2298, 2300, 2302, 2301, 2300, 2299, 2298,
+ 2297, 2296, 2295, 2294, 2293, 2292, 2291, 2290, 2289, 2288, 2287, 2286, 2285, 2284, 2283, 2282,
+ 2281, 2280, 2279, 2278, 2277, 2276, 2275, 2274, 2273, 2272, 2271, 2270, 2269, 2268, 2267, 2266,
+ 2265, 2264, 2263, 2262, 2261, 2260, 2259, 2258, 2257, 2256, 2255, 2254, 2253, 2252, 2251, 2250,
+ 2249, 2248, 2247, 2246, 2245, 2244, 2243, 2242, 2239, 2236, 2233, 2230, 2227, 2224, 2221, 2218,
+ 2215, 2212, 2209, 2206, 2203, 2200, 2197, 2194, 2191, 2188, 2185, 2182, 2179, 2176, 2173, 2170,
+ 2167, 2164, 2161, 2158, 2155, 2152, 2149, 2146, 2143, 2140, 2137, 2134, 2131, 2128, 2125, 2122,
+ 2119, 2116, 2113, 2110, 2107, 2104, 2101, 2098, 2095, 2092, 2089, 2086, 2083, 2080, 2077, 2074,
+ 2071, 2068, 2065, 2062, 2058, 2054, 2050, 2046, 2042, 2038, 2034, 2030, 2026, 2022, 2018, 2014,
+ 2010, 2006, 2001, 1996, 1991, 1986, 1981, 1976, 1971, 1966, 1961, 1956, 1951, 1946, 1941, 1936,
+ 1931, 1926, 1921, 1916, 1911, 1906, 1901, 1896, 1891, 1886, 1881, 1876, 1871, 1866, 1861, 1856,
+ 1851, 1846, 1841, 1836, 1831, 1826, 1821, 1816, 1811, 1806, 1801, 1796, 1791, 1786, 1781, 1776,
+ 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776,
+ 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776,
+ 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776,
+ 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1776, 1779, 1782, 1785, 1788,
+ 1791, 1794, 1797, 1800, 1803, 1806, 1809, 1812, 1815, 1818, 1821, 1824, 1827, 1830, 1833, 1836,
+ 1839, 1842, 1845, 1848, 1851, 1854, 1857, 1860, 1863, 1866, 1869, 1872, 1875, 1878, 1881, 1884,
+ 1887, 1890, 1893, 1896, 1899, 1902, 1905, 1908, 1911, 1914, 1917, 1920, 1923, 1926, 1929, 1932,
+ 1935, 1938, 1941, 1944, 1947, 1950, 1953, 1956, 1958, 1960, 1962, 1964, 1966, 1968, 1970, 1972,
+ 1974, 1976, 1978, 1980, 1982, 1984, 1986, 1988, 1990, 1992, 1994, 1996, 1998, 2000, 2002, 2004,
+ 2006, 2008, 2010, 2012, 2014, 2016, 2018, 2020, 2022, 2024, 2026, 2028, 2030, 2032, 2034, 2036,
+ 2038, 2040, 2042, 2044, 2046, 2048, 2050, 2052, 2054, 2056, 2058, 2060, 2062, 2064, 2066, 2068,
+ 2070, 2072, 2074, 2076, 2078, 2080, 2082, 2084, 2086, 2088, 2090, 2092, 2094, 2096, 2098, 2100,
+ 2102, 2104, 2106, 2108, 2110, 2112, 2114, 2116, 2118, 2120, 2122, 2124, 2126, 2128, 2130, 2132,
+ 2134, 2136, 2138, 2140, 2142, 2144, 2146, 2148, 2150, 2152, 2154, 2156, 2158, 2160, 2162, 2164,
+ 2166, 2168, 2170, 2172, 2174, 2176, 2178, 2180, 2182, 2184, 2186, 2188, 2190, 2192, 2194, 2196,
+ 2198, 2200, 2202, 2204, 2206, 2208, 2210, 2212, 2214, 2216, 2218, 2220, 2222, 2224, 2226, 2228,
+ 2230, 2232, 2234, 2236, 2238, 2240, 2242, 2244, 2246, 2248, 2250, 2252, 2254, 2256, 2258, 2260,
+ 2262, 2264, 2266, 2268, 2270, 2272, 2274, 2276, 2278, 2280, 2282, 2284, 2286, 2288, 2290, 2292,
+ 2294, 2296, 2298, 2300, 2301, 2302, 2303, 2304, 2305, 2306, 2307, 2308, 2309, 2310, 2311, 2312,
+ 2313, 2314, 2315, 2316, 2317, 2318, 2319, 2320, 2321, 2322, 2323, 2324, 2325, 2326, 2327, 2328,
+ 2329, 2330, 2331, 2332, 2333, 2334, 2335, 2336, 2337, 2338, 2339, 2340, 2341, 2342, 2343, 2344,
+ 2345, 2346, 2347, 2348, 2349, 2350, 2351, 2352, 2353, 2354, 2355, 2356, 2357, 2358, 2359, 2360,
+ 2361, 2362, 2363, 2364, 2365, 2366, 2367, 2368, 2366, 2364, 2362, 2360, 2358, 2356, 2354, 2352,
+ 2350, 2348, 2346, 2344, 2342, 2340, 2338, 2336, 2334, 2332, 2330, 2328, 2326, 2324, 2322, 2320,
+ 2318, 2316, 2314, 2312, 2310, 2308, 2306, 2304, 2302, 2300, 2298, 2296, 2294, 2292, 2290, 2288,
+ 2286, 2284, 2282, 2280, 2278, 2276, 2274, 2272, 2270, 2268, 2266, 2264, 2262, 2260, 2258, 2256,
+ 2254, 2252, 2250, 2248, 2240, 2230, 2220, 2210, 2200, 2190, 2180, 2170, 2160, 2150, 2140, 2130,
+ 2120, 2110, 2100, 2090, 2080, 2070, 2060, 2050, 2040, 2030, 2020, 2010, 2000, 1990, 1980, 1970,
+ 1960, 1950, 1940, 1930, 1920, 1910, 1900, 1890, 1880, 1870, 1860, 1850, 1840, 1830, 1820, 1810,
+ 1800, 1790, 1780, 1770, 1760, 1750, 1740, 1730, 1720, 1710, 1700, 1690, 1680, 1670, 1660, 1650,
+ 1645, 1640, 1635, 1630, 1625, 1620, 1615, 1610, 1605, 1600, 1595, 1590, 1585, 1580, 1575, 1570,
+ 1565, 1560, 1555, 1550, 1545, 1540, 1535, 1530, 1525, 1520, 1515, 1510, 1505, 1500, 1495, 1490,
+ 1485, 1480, 1475, 1470, 1465, 1460, 1455, 1450, 1445, 1440, 1435, 1430, 1425, 1420, 1415, 1410,
+ 1405, 1400, 1395, 1390, 1385, 1380, 1375, 1370, 1365, 1360, 1355, 1350, 1345, 1340, 1335, 1330,
+ 1325, 1320, 1315, 1310, 1305, 1300, 1295, 1290, 1285, 1280, 1275, 1270, 1265, 1260, 1255, 1250,
+ 1245, 1240, 1235, 1230, 1225, 1220, 1215, 1210, 1205, 1200, 1195, 1190, 1185, 1180, 1175, 1170,
+ 1165, 1160, 1155, 1150, 1145, 1140, 1135, 1130, 1125, 1120, 1115, 1110, 1105, 1100, 1090, 1088,
+ 1086, 1084, 1082, 1080, 1078, 1076, 1074, 1072, 1070, 1065, 1060, 1055, 1050, 1045, 1040, 1035,
+ 1030, 1025, 1020, 1015, 1010, 1005, 1000, 995, 990, 985, 980, 975, 970, 965, 960, 955,
+ 950, 945, 940, 935, 930, 925, 920, 915, 910, 905, 900, 895, 890, 885, 880, 875,
+ 870, 865, 860, 855, 850, 845, 840, 835, 830, 825, 820, 815, 810, 805, 800, 795,
+ 790, 785, 780, 775, 772, 769, 766, 763, 760, 757, 754, 751, 748, 745, 742, 739,
+ 736, 733, 730, 727, 724, 721, 718, 715, 712, 709, 706, 703, 700, 697, 694, 691,
+ 688, 685, 682, 679, 676, 673, 670, 667, 664, 661, 658, 655, 652, 649, 646, 643,
+ 640, 637, 634, 631, 628, 625, 622, 619, 616, 613, 610, 607, 604, 601, 598, 595,
+ 597, 599, 601, 603, 605, 607, 609, 611, 613, 615, 617, 619, 621, 623, 625, 627,
+ 629, 631, 633, 635, 637, 639, 641, 643, 645, 647, 649, 651, 653, 655, 657, 659,
+ 661, 663, 665, 667, 669, 671, 673, 675, 677, 679, 681, 683, 685, 687, 689, 691,
+ 693, 695, 697, 699, 701, 703, 705, 707, 709, 711, 713, 715, 715, 715, 715, 715,
+ 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715,
+ 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715,
+ 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715, 715,
+ 715, 715, 715, 715, 715, 715, 715, 715, 710, 705, 700, 695, 690, 685, 680, 675,
+ 670, 665, 660, 655, 650, 645, 640, 635, 630, 625, 620, 615, 610, 605, 600, 595,
+ 590, 585, 580, 575, 570, 565, 560, 555, 550, 545, 540, 535, 530, 525, 520, 515,
+ 510, 505, 500, 495, 490, 485, 480, 475, 470, 465, 460, 455, 450, 445, 440, 435,
+ 430, 425, 420, 415, 417, 419, 421, 423, 425, 427, 429, 431, 433, 435, 437, 439,
+ 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 469, 471,
+ 473, 475, 477, 479, 481, 483, 485, 487, 489, 491, 493, 495, 497, 499, 501, 503,
+ 505, 507, 509, 511, 513, 515, 517, 519, 521, 523, 525, 527, 529, 531, 533, 535,
+ 536, 532, 528, 524, 520, 516, 512, 508, 504, 500, 496, 492, 488, 484, 480, 476,
+ 472, 468, 464, 460, 456, 452, 448, 444, 440, 436, 432, 428, 424, 420, 416, 412,
+ 408, 404, 400, 396, 392, 388, 384, 380, 376, 372, 368, 364, 360, 356, 352, 348,
+ 344, 340, 336, 332, 328, 324, 320, 316, 312, 308, 304, 300, 295, 290, 285, 280,
+ 275, 270, 265, 260, 255, 250, 245, 240, 235, 230, 225, 220, 215, 210, 205, 200,
+ 195, 190, 185, 180, 175, 170, 165, 160, 155, 150, 145, 140, 135, 130, 125, 120,
+ 115, 110, 105, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40,
+ 35, 30, 25, 20, 15, 10, 5, 0
+};
+
+Qt3DSEventSystemEvent *CCanProviderDemo::GetNextEvent(IEventFactory &inFactory)
+{
+ clock_t theCurClock = clock();
+ if (theCurClock > m_LastClock
+ && (theCurClock - m_LastClock) / (CLOCKS_PER_SEC / 1000) < 1000 / 6)
+ return 0;
+ m_LastClock = theCurClock;
+ unsigned char theLength = 0;
+ unsigned char theData[8];
+ theData[0] = 81;
+#define SIN_SAMPLE(s, m) ((sin((float)s) / 2 + 0.5) * m)
+ switch (rand() % 2) {
+ case 0:
+ theData[1] = 1;
+ { // Vehicle speed
+ int theIndex = m_Frame % (sizeof(g_VehicleSpeedData) / sizeof(g_VehicleSpeedData[0]));
+ theData[2] = (unsigned short)(g_VehicleSpeedData[theIndex] * 0.06) >> 8;
+ theData[3] = (unsigned char)(g_VehicleSpeedData[theIndex] * 0.06);
+ }
+ {
+ unsigned short theOdo = m_Frame;
+ theData[4] = theOdo >> 8;
+ theData[5] = (unsigned char)theOdo;
+ }
+ theLength = 6;
+ break;
+ case 1:
+ theData[1] = 2;
+ {
+ unsigned short theTrip = m_Frame;
+ theData[2] = theTrip >> 8;
+ theData[3] = (unsigned char)theTrip;
+ }
+ {
+ unsigned short theCoolant = (unsigned char)SIN_SAMPLE(m_Frame / 170, 300);
+ theData[4] = theCoolant >> 8;
+ theData[5] = (unsigned char)theCoolant;
+ }
+ theLength = 6;
+ break;
+ default:
+ return 0;
+ }
+ ++m_Frame;
+ Qt3DSEventSystemEvent &theEvent = inFactory.CreateEvent(9);
+ Qt3DSEventSystemEventData *theCurrentData = theEvent.m_Data;
+ theCurrentData->m_Name = inFactory.RegisterStr("device_type");
+ theCurrentData->m_Value.m_Type = QT3DSEventSystemEventTypesString;
+ theCurrentData->m_Value.m_String = inFactory.AllocateStr("CAN");
+ ++theCurrentData;
+ theCurrentData->m_Name = inFactory.RegisterStr("id");
+ theCurrentData->m_Value.m_Type = QT3DSEventSystemEventTypesNumber;
+ theCurrentData->m_Value.m_Number = 101;
+ ++theCurrentData;
+ theCurrentData->m_Name = inFactory.RegisterStr("length");
+ theCurrentData->m_Value.m_Type = QT3DSEventSystemEventTypesNumber;
+ theCurrentData->m_Value.m_Number = 6;
+ ++theCurrentData;
+ for (int i = 0; i < theLength; ++i) {
+ theCurrentData->m_Name = inFactory.RegisterStr("data");
+ theCurrentData->m_Value.m_Type = QT3DSEventSystemEventTypesNumber;
+ theCurrentData->m_Value.m_Number = theData[i];
+ ++theCurrentData;
+ }
+
+ return &theEvent;
+}
+
+size_t CCanProviderDemo::GetNextEvents(IEventFactory &inFactory, Qt3DSEventSystemEvent **outBuffer,
+ size_t bufLen)
+{
+ size_t bufIdx = 0;
+ Qt3DSEventSystemEvent *evt = NULL;
+ for (evt = GetNextEvent(inFactory); evt && bufIdx < bufLen;
+ evt = GetNextEvent(inFactory), ++bufIdx)
+ outBuffer[bufIdx] = evt;
+ return bufIdx;
+}
+
+void CCanProviderDemo::Release()
+{
+ delete this;
+}
diff --git a/src/event/test/CanProviderDemo.h b/src/event/test/CanProviderDemo.h
new file mode 100644
index 0000000..7d6788b
--- /dev/null
+++ b/src/event/test/CanProviderDemo.h
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 NVIDIA Corporation.
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CAN_PROVIDER_DEMO_H
+#define CAN_PROVIDER_DEMO_H
+
+#include <ctime>
+
+#include <EventSystem.h>
+
+using namespace qt3ds::evt;
+
+class CCanProviderDemo : public IEventProvider
+{
+public:
+ CCanProviderDemo();
+ virtual ~CCanProviderDemo();
+
+ Qt3DSEventSystemEvent *GetNextEvent(IEventFactory &inFactory);
+ virtual size_t GetNextEvents(IEventFactory &inFactory, Qt3DSEventSystemEvent **outBuffer,
+ size_t bufLen);
+ virtual void Release();
+
+private:
+ unsigned int m_Frame;
+ clock_t m_LastClock;
+};
+
+#endif // CAN_PROVIDER_DEMO_H